1 diff -burNp dillo-2.0/dpi/file.c dillo-2.0-dud/dpi/file.c
2 --- dillo-2.0/dpi/file.c 2008-09-30 17:43:43.000000000 +0200
3 +++ dillo-2.0-dud/dpi/file.c 2009-03-24 10:39:52.201842188 +0100
5 * With new HTML layout.
11 #include <ctype.h> /* for tolower */
13 #include "../dpip/dpip.h"
20 @@ -77,7 +79,7 @@ typedef struct {
24 -static const char *File_content_type(const char *filename);
25 +static const char *File_content_type(const char *filename, int *gzipped);
26 static int File_get_file(ClientInfo *Client,
29 @@ -344,6 +346,7 @@ static void File_info2html(ClientInfo *C
30 filecont = "Executable";
32 filecont = File_content_type(finfo->full_path);
33 + filecont = File_content_type(finfo->full_path, NULL);
34 if (!filecont || !strcmp(filecont, "application/octet-stream"))
37 @@ -467,13 +470,21 @@ static void File_transfer_dir(ClientInfo
39 * Return a content type based on the extension of the filename.
41 -static const char *File_ext(const char *filename)
42 +static const char *File_ext(const char *filename, int *gzipped)
47 if (!(e = strrchr(filename, '.')))
50 + if ((e > filename) && !strcasecmp(e+1, "gz") && ((e2 = memrchr(filename, '.', e-filename)) != NULL)) {
52 + if (!strncasecmp(e2, "html.", 5) || !strncasecmp(e2, "htm.", 4) || !strncasecmp(e2, "shtml.", 6)) {
53 + if(gzipped != NULL) *gzipped = 1;
59 if (!dStrcasecmp(e, "gif")) {
60 @@ -496,7 +507,7 @@ static const char *File_ext(const char *
61 * Based on the extension, return the content_type for the file.
62 * (if there's no extension, analyze the data and try to figure it out)
64 -static const char *File_content_type(const char *filename)
65 +static const char *File_content_type(const char *filename, int *gzipped)
69 @@ -504,7 +515,7 @@ static const char *File_content_type(con
73 - if (!(ct = File_ext(filename))) {
74 + if (!(ct = File_ext(filename, gzipped))) {
75 /* everything failed, let's analyze the data... */
76 if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) != -1) {
77 if ((buf_size = read(fd, buf, 256)) == 256 ) {
78 @@ -530,28 +541,40 @@ static void File_get(ClientInfo *Client,
82 + char *tmp_filename = (char*)filename, *p;
85 if (stat(filename, &sb) != 0) {
86 + char *e = strrchr(filename, '.');
87 + if ((e == NULL) || strcasecmp(e + 1, "gz")) {
88 + if ((p = malloc(strlen(filename) + 4)) != NULL) {
90 + strcpy(tmp_filename, filename);
91 + strcat(tmp_filename, ".gz");
92 + filename = tmp_filename;
96 + if (stat(tmp_filename, &sb) != 0) {
97 /* stat failed, prepare a file-not-found error. */
99 } else if (S_ISDIR(sb.st_mode)) {
100 /* set up for reading directory */
101 - res = File_get_dir(Client, filename, orig_url);
102 + res = File_get_dir(Client, tmp_filename, orig_url);
104 /* set up for reading a file */
105 - res = File_get_file(Client, filename, &sb, orig_url);
106 + res = File_get_file(Client, tmp_filename, &sb, orig_url);
109 if (res == FILE_NOT_FOUND) {
110 ds = dStr_sized_new(128);
111 - dStr_sprintf(ds, "%s Not Found: %s",
112 - S_ISDIR(sb.st_mode) ? "Directory" : "File", filename);
113 + dStr_sprintf(ds, "%s Not Found: %s", S_ISDIR(sb.st_mode) ? "Directory" : "File", tmp_filename);
114 } else if (res == FILE_NO_ACCESS) {
115 ds = dStr_sized_new(128);
116 - dStr_sprintf(ds, "Access denied to %s: %s",
117 - S_ISDIR(sb.st_mode) ? "Directory" : "File", filename);
118 + dStr_sprintf(ds, "Access denied to %s: %s", S_ISDIR(sb.st_mode) ? "Directory" : "File", tmp_filename);
120 + if(tmp_filename != filename)
121 + free(tmp_filename);
123 d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s","send_status_message",ds->str);
124 sock_handler_write_str(Client->sh, 1, d_cmd);
125 @@ -599,7 +622,8 @@ static int File_get_file(ClientInfo *Cli
126 const char *unknown_type = "application/octet-stream";
127 char buf[LBUF], *d_cmd, *name;
129 - bool_t gzipped = FALSE;
133 if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0)
134 return FILE_NO_ACCESS;
135 @@ -628,6 +652,18 @@ static int File_get_file(ClientInfo *Cli
136 /* Send HTTP headers */
138 sock_handler_write_str(Client->sh, 0, "Content-Encoding: gzip\n");
139 + gzdata = gzdopen(fd, "r");
141 + if ((st = gzread(gzdata, buf, LBUF)) > 0) {
142 + if (sock_handler_write(Client->sh, buf, st, 0) != 0)
144 + } else if (st < 0) {
146 + if (errno == EINTR || errno == EAGAIN)
152 if (!gzipped || strcmp(ct, unknown_type)) {
153 sock_handler_printf(Client->sh, 0, "Content-Type: %s\n", ct);
154 diff -burNp dillo-2.0/dpi/Makefile.am dillo-2.0-dud/dpi/Makefile.am
155 --- dillo-2.0/dpi/Makefile.am 2008-04-26 23:29:10.000000000 +0200
156 +++ dillo-2.0-dud/dpi/Makefile.am 2009-03-24 10:40:40.881837317 +0100
157 @@ -20,7 +20,7 @@ downloads_dpi_LDADD = @LIBFLTK_LIBS@ ../
158 ftp_filter_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a
159 https_filter_dpi_LDADD = @LIBSSL_LIBS@ ../dpip/libDpip.a ../dlib/libDlib.a
160 hello_filter_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a
161 -file_dpi_LDADD = @LIBPTHREAD_LIBS@ ../dpip/libDpip.a ../dlib/libDlib.a
162 +file_dpi_LDADD = @GLIB_LIBS@ @LIBPTHREAD_LIBS@ ../dpip/libDpip.a -lz
163 cookies_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a
164 datauri_filter_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a