]> git.pld-linux.org Git - packages/dillo.git/blame - dillo-gzip_fallback.patch
- up to fit 2.0
[packages/dillo.git] / dillo-gzip_fallback.patch
CommitLineData
fabd671e 1diff -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
5532115f 4@@ -15,6 +15,7 @@
92c13459
JB
5 * With new HTML layout.
6 */
5532115f 7
92c13459 8+#define _GNU_SOURCE
5532115f
JB
9 #include <pthread.h>
10
92c13459 11 #include <ctype.h> /* for tolower */
fabd671e 12@@ -36,6 +37,7 @@
4eaa7222 13 #include "../dpip/dpip.h"
92c13459 14 #include "dpiutil.h"
fabd671e 15 #include "d_size.h"
16+#include <zlib.h>
17
18 /*
19 * Debugging macros
20@@ -77,7 +79,7 @@ typedef struct {
76d70ef3 21 /*
92c13459
JB
22 * Forward references
23 */
24-static const char *File_content_type(const char *filename);
25+static const char *File_content_type(const char *filename, int *gzipped);
fabd671e 26 static int File_get_file(ClientInfo *Client,
27 const char *filename,
28 struct stat *sb,
29@@ -344,6 +346,7 @@ static void File_info2html(ClientInfo *C
92c13459
JB
30 filecont = "Executable";
31 } else {
fabd671e 32 filecont = File_content_type(finfo->full_path);
4eaa7222 33+ filecont = File_content_type(finfo->full_path, NULL);
92c13459
JB
34 if (!filecont || !strcmp(filecont, "application/octet-stream"))
35 filecont = "unknown";
36 }
fabd671e 37@@ -467,13 +470,21 @@ static void File_transfer_dir(ClientInfo
92c13459
JB
38 /*
39 * Return a content type based on the extension of the filename.
40 */
41-static const char *File_ext(const char *filename)
42+static const char *File_ext(const char *filename, int *gzipped)
e1210af3 43 {
fabd671e 44 char *e;
92c13459 45+ char *e, *e2;
76d70ef3 46
fabd671e 47 if (!(e = strrchr(filename, '.')))
76d70ef3 48 return NULL;
92c13459 49
fabd671e 50+ if ((e > filename) && !strcasecmp(e+1, "gz") && ((e2 = memrchr(filename, '.', e-filename)) != NULL)) {
92c13459 51+ e2++;
fabd671e 52+ if (!strncasecmp(e2, "html.", 5) || !strncasecmp(e2, "htm.", 4) || !strncasecmp(e2, "shtml.", 6)) {
53+ if(gzipped != NULL) *gzipped = 1;
92c13459
JB
54+ return "text/html";
55+ }
76d70ef3 56+ }
92c13459
JB
57 e++;
58
fabd671e 59 if (!dStrcasecmp(e, "gif")) {
60@@ -496,7 +507,7 @@ static const char *File_ext(const char *
92c13459
JB
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)
63 */
64-static const char *File_content_type(const char *filename)
65+static const char *File_content_type(const char *filename, int *gzipped)
66 {
fabd671e 67 int fd;
4eaa7222 68 struct stat sb;
fabd671e 69@@ -504,7 +515,7 @@ static const char *File_content_type(con
70 char buf[256];
4eaa7222 71 ssize_t buf_size;
92c13459
JB
72
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) {
4eaa7222 77 if ((buf_size = read(fd, buf, 256)) == 256 ) {
fabd671e 78@@ -530,28 +541,40 @@ static void File_get(ClientInfo *Client,
92c13459
JB
79 int res;
80 struct stat sb;
fabd671e 81 char *d_cmd;
92c13459 82+ char *tmp_filename = (char*)filename, *p;
fabd671e 83 Dstr *ds = NULL;
92c13459
JB
84
85 if (stat(filename, &sb) != 0) {
fabd671e 86+ char *e = strrchr(filename, '.');
87+ if ((e == NULL) || strcasecmp(e + 1, "gz")) {
88+ if ((p = malloc(strlen(filename) + 4)) != NULL) {
89+ tmp_filename = p;
90+ strcpy(tmp_filename, filename);
91+ strcat(tmp_filename, ".gz");
92+ filename = tmp_filename;
93+ }
94+ }
76d70ef3 95+ }
92c13459
JB
96+ if (stat(tmp_filename, &sb) != 0) {
97 /* stat failed, prepare a file-not-found error. */
98 res = FILE_NOT_FOUND;
99 } else if (S_ISDIR(sb.st_mode)) {
100 /* set up for reading directory */
5532115f
JB
101- res = File_get_dir(Client, filename, orig_url);
102+ res = File_get_dir(Client, tmp_filename, orig_url);
92c13459
JB
103 } else {
104 /* set up for reading a file */
5532115f
JB
105- res = File_get_file(Client, filename, &sb, orig_url);
106+ res = File_get_file(Client, tmp_filename, &sb, orig_url);
92c13459 107 }
f8889be6 108
92c13459 109 if (res == FILE_NOT_FOUND) {
fabd671e 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);
4eaa7222 114 } else if (res == FILE_NO_ACCESS) {
fabd671e 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);
92c13459
JB
119 }
120+ if(tmp_filename != filename)
fabd671e 121+ free(tmp_filename);
122 if (ds) {
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;
128 int fd, st, namelen;
129- bool_t gzipped = FALSE;
92c13459 130+ int gzipped = 0;
76d70ef3 131+ gzFile gzdata;
132
fabd671e 133 if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0)
92c13459 134 return FILE_NO_ACCESS;
fabd671e 135@@ -628,6 +652,18 @@ static int File_get_file(ClientInfo *Cli
136 /* Send HTTP headers */
137 if (gzipped) {
138 sock_handler_write_str(Client->sh, 0, "Content-Encoding: gzip\n");
139+ gzdata = gzdopen(fd, "r");
140+ do {
141+ if ((st = gzread(gzdata, buf, LBUF)) > 0) {
142+ if (sock_handler_write(Client->sh, buf, st, 0) != 0)
143+ break;
144+ } else if (st < 0) {
145+ perror("[read]");
146+ if (errno == EINTR || errno == EAGAIN)
147+ continue;
148+ }
149+ } while (st > 0);
150+ gzclose(gzdata);
151 }
152 if (!gzipped || strcmp(ct, unknown_type)) {
153 sock_handler_printf(Client->sh, 0, "Content-Type: %s\n", ct);
154diff -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
4eaa7222 162+file_dpi_LDADD = @GLIB_LIBS@ @LIBPTHREAD_LIBS@ ../dpip/libDpip.a -lz
fabd671e 163 cookies_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a
164 datauri_filter_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a
92c13459 165
This page took 0.099126 seconds and 4 git commands to generate.