[asterisk-commits] russell: branch russell/http_filetxfer r72699 - /team/russell/http_filetxfer/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jun 29 15:23:50 CDT 2007
Author: russell
Date: Fri Jun 29 15:23:49 2007
New Revision: 72699
URL: http://svn.digium.com/view/asterisk?view=rev&rev=72699
Log:
allow transfers of large files
Modified:
team/russell/http_filetxfer/main/http.c
Modified: team/russell/http_filetxfer/main/http.c
URL: http://svn.digium.com/view/asterisk/team/russell/http_filetxfer/main/http.c?view=diff&rev=72699&r1=72698&r2=72699
==============================================================================
--- team/russell/http_filetxfer/main/http.c (original)
+++ team/russell/http_filetxfer/main/http.c Fri Jun 29 15:23:49 2007
@@ -48,6 +48,10 @@
#include <fcntl.h>
#include <pthread.h>
+#ifdef HAVE_SENDFILE
+#include <sys/sendfile.h>
+#endif
+
#include "minimime/mm.h"
#include "asterisk/cli.h"
@@ -147,7 +151,6 @@
static struct ast_str *static_callback(struct server_instance *ser, const char *uri, struct ast_variable *vars, int *status, char **title, int *contentlength)
{
- struct ast_str *result;
char *path;
char *ftype;
const char *mtype;
@@ -155,6 +158,8 @@
struct stat st;
int len;
int fd;
+ time_t t;
+ char buf[256];
/* Yuck. I'm not really sold on this, but if you don't deliver static content it makes your configuration
substantially more challenging, but this seems like a rather irritating feature creep on Asterisk. */
@@ -185,21 +190,28 @@
if (fd < 0)
goto out403;
- len = st.st_size + strlen(mtype) + 40;
- result = ast_str_create(len);
- if (result == NULL) /* XXX not really but... */
- goto out403;
-
- ast_str_append(&result, 0, "Content-type: %s\r\n\r\n", mtype);
- *contentlength = read(fd, result->str + result->used, st.st_size);
- if (*contentlength < 0) {
- close(fd);
- ast_free(result);
- goto out403;
- }
- result->used += *contentlength;
+ time(&t);
+ strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
+ fprintf(ser->f, "HTTP/1.1 200 OK\r\n"
+ "Server: Asterisk/%s\r\n"
+ "Date: %s\r\n"
+ "Connection: close\r\n"
+ "Cache-Control: no-cache, no-store\r\n"
+ "Content-Length: %d\r\n"
+ "Content-type: %s\r\n\r\n",
+ ASTERISK_VERSION, buf, (int) st.st_size, mtype);
+
+ fflush(ser->f);
+
+#ifdef HAVE_SENDFILE
+ sendfile(ser->fd, fd, NULL, st.st_size);
+#else
+ while ((len = read(fd, buf, sizeof(buf))) > 0)
+ write(ser->fd, buf, len);
+#endif
+
close(fd);
- return result;
+ return NULL;
out404:
*status = 404;
More information about the asterisk-commits
mailing list