]> git.pld-linux.org Git - packages/dillo.git/blob - dillo-gzip_fallback.patch
- up to 3.0.5
[packages/dillo.git] / dillo-gzip_fallback.patch
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
4 @@ -15,6 +15,7 @@
5   * With new HTML layout.
6   */
7  
8 +#define _GNU_SOURCE
9  #include <pthread.h>
10  
11  #include <ctype.h>           /* for tolower */
12 @@ -36,6 +37,7 @@
13  #include "../dpip/dpip.h"
14  #include "dpiutil.h"
15  #include "d_size.h"
16 +#include <zlib.h>
17  
18  /*
19   * Debugging macros
20 @@ -77,7 +79,7 @@ typedef struct {
21  /*
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);
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
30        filecont = "Executable";
31     } else {
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"))
35           filecont = "unknown";
36     }
37 @@ -467,13 +470,21 @@ static void File_transfer_dir(ClientInfo
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)
43  {
44     char *e;
45 +   char *e, *e2;
46  
47     if (!(e = strrchr(filename, '.')))
48        return NULL;
49  
50 +   if ((e > filename) && !strcasecmp(e+1, "gz") && ((e2 = memrchr(filename, '.', e-filename)) != NULL)) {
51 +          e2++;
52 +          if (!strncasecmp(e2, "html.", 5) || !strncasecmp(e2, "htm.", 4) || !strncasecmp(e2, "shtml.", 6)) {
53 +                  if(gzipped != NULL) *gzipped = 1;
54 +                  return "text/html";
55 +          }
56 +   }
57     e++;
58  
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)
63   */
64 -static const char *File_content_type(const char *filename)
65 +static const char *File_content_type(const char *filename, int *gzipped)
66  {
67     int fd;
68     struct stat sb;
69 @@ -504,7 +515,7 @@ static const char *File_content_type(con
70     char buf[256];
71     ssize_t buf_size;
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) {
77           if ((buf_size = read(fd, buf, 256)) == 256 ) {
78 @@ -530,28 +541,40 @@ static void File_get(ClientInfo *Client,
79     int res;
80     struct stat sb;
81     char *d_cmd;
82 +   char *tmp_filename = (char*)filename, *p;
83     Dstr *ds = NULL;
84  
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) {
89 +                       tmp_filename = p;
90 +                       strcpy(tmp_filename, filename);
91 +                       strcat(tmp_filename, ".gz");
92 +                       filename = tmp_filename;
93 +               }
94 +       }
95 +   }
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 */
101 -      res = File_get_dir(Client, filename, orig_url);
102 +      res = File_get_dir(Client, tmp_filename, orig_url);
103     } else {
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);
107     }
108  
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);
119     }
120 +   if(tmp_filename != filename)
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;
130 +   int gzipped = 0;
131 +   gzFile gzdata;
132  
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 */
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);
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
165  
This page took 0.090425 seconds and 3 git commands to generate.