]> git.pld-linux.org Git - packages/dillo.git/blob - dillo-gzip_fallback.patch
9f2d3fa001552bcdead4861c7cf015cd0e67eb39
[packages/dillo.git] / dillo-gzip_fallback.patch
1 --- dillo-0.8.3/dpi/file.c.orig 2004-10-13 22:04:00.000000000 +0200
2 +++ dillo-0.8.3/dpi/file.c      2004-11-03 23:33:03.451400688 +0100
3 @@ -14,7 +14,7 @@
4   * Directory entries on top, files next.
5   * With new HTML layout.
6   */
7 -
8 +#define _GNU_SOURCE
9  #include <ctype.h>           /* for tolower */
10  #include <unistd.h>
11  #include <stdlib.h>
12 @@ -30,6 +30,7 @@
13  #include <signal.h>
14  #include <errno.h>           /* for errno */
15  #include <glib.h>
16 +#include <zlib.h>
17  
18  #include "dpiutil.h"
19  
20 @@ -61,7 +62,7 @@
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 gint File_get_file(const gchar *filename,
27                            struct stat *sb,
28                            const char *orig_url);
29 @@ -384,7 +385,7 @@
30        cont = "application/executable";
31        filecont = "Executable";
32     } else {
33 -      filecont = cont = File_content_type(finfo->full_path);
34 +      filecont = cont = File_content_type(finfo->full_path, NULL);
35        if (!filecont || !strcmp(filecont, "application/octet-stream"))
36           filecont = "unknown";
37     }
38 @@ -507,13 +508,24 @@
39  /*
40   * Return a content type based on the extension of the filename.
41   */
42 -static const char *File_ext(const char *filename)
43 +static const char *File_ext(const char *filename, int *gzipped)
44  {
45 -   char *e;
46 +   char *e, *e2;
47  
48     if ( !(e = strrchr(filename, '.')) )
49        return NULL;
50  
51 +   if ((e > filename) && !strcasecmp(e+1, "gz") &&
52 +       ((e2 = memrchr(filename, '.', e-filename)) != NULL)) {
53 +          e2++;
54 +          if (!strncasecmp(e2, "html.", 5) ||
55 +              !strncasecmp(e2, "htm.", 4) ||
56 +              !strncasecmp(e2, "shtml.", 6)) {
57 +                  if(gzipped != NULL)
58 +                       *gzipped = 1;
59 +                  return "text/html";
60 +          }
61 +   }
62     e++;
63  
64     if (!strcasecmp(e, "gif")) {
65 @@ -536,12 +548,12 @@
66   * Based on the extension, return the content_type for the file.
67   * (if there's no extension, analyze the data and try to figure it out)
68   */
69 -static const char *File_content_type(const char *filename)
70 +static const char *File_content_type(const char *filename, int *gzipped)
71  {
72     gint fd;
73     const gchar *ct;
74  
75 -   if (!(ct = File_ext(filename))) {
76 +   if (!(ct = File_ext(filename, gzipped))) {
77        /* everything failed, let's analyze the data... */
78        if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) != -1) {
79           gchar buf[256];
80 @@ -563,16 +575,29 @@
81  {
82     int res;
83     struct stat sb;
84 +   char *tmp_filename = (char*)filename, *p;
85  
86     if (stat(filename, &sb) != 0) {
87 +      char *e = strrchr(filename, '.');
88 +      if ((e == NULL) || strcasecmp(e + 1, "gz")) {
89 +        if ((p = malloc(strlen(filename) + 4)) != NULL) {
90 +           tmp_filename = p;
91 +           strcpy(tmp_filename, filename);
92 +           strcat(tmp_filename, ".gz");
93 +           filename = tmp_filename;
94 +        }
95 +      }
96 +   }
97 +
98 +   if (stat(tmp_filename, &sb) != 0) {
99        /* stat failed, prepare a file-not-found error. */
100        res = FILE_NOT_FOUND;
101     } else if (S_ISDIR(sb.st_mode)) {
102        /* set up for reading directory */
103 -      res = File_get_dir(filename, orig_url);
104 +      res = File_get_dir(tmp_filename, orig_url);
105     } else {
106        /* set up for reading a file */
107 -      res = File_get_file(filename, &sb, orig_url);
108 +      res = File_get_file(tmp_filename, &sb, orig_url);
109     }
110  
111     if (res == FILE_NOT_FOUND) {
112 @@ -583,8 +608,10 @@
113        sock_handler_printf(sh, 1,
114           "<dpi cmd='send_status_message' msg='"
115           "Failed to open the %s %s'>",
116 -         S_ISDIR(sb.st_mode) ? "directory" : "file", filename);
117 +         S_ISDIR(sb.st_mode) ? "directory" : "file", tmp_filename);
118     }
119 +   if(tmp_filename != filename)
120 +      free(tmp_filename);
121  }
122  
123  /*
124 @@ -623,6 +650,8 @@
125     const gchar *ct;
126     char buf[LBUF];
127     gint fd, st;
128 +   int gzipped = 0;
129 +   gzFile gzdata;
130  
131     if ( (fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0)
132        return FILE_NO_ACCESS;
133 @@ -632,15 +661,32 @@
134      * todo: a better approach could be to detect&reject those types we know
135      * for sure we don't handle (as gzip, bzip, ELF, etc)
136      */
137 -   ct = File_content_type(filename);
138 +   ct = File_content_type(filename, &gzipped);
139     if (!ct || !strcmp(ct, "application/octet-stream"))
140        ct = "text/plain";
141  
142 -
143     /* Send DPI command */
144     sock_handler_printf(sh, 1,
145        "<dpi cmd='start_send_page' url='%s'>\n", orig_url);
146  
147 +   if (gzipped) {
148 +       /* Send HTTP stream */
149 +       sock_handler_printf(sh, 0,
150 +          "Content-Type: %s\n\n", ct);
151 +
152 +       gzdata = gzdopen(fd, "r");
153 +       do {
154 +           if ((st = gzread(gzdata, buf, LBUF)) > 0) {
155 +               if (sock_handler_write(sh, buf, st, 0) != 0)
156 +                   break;
157 +           } else if (st < 0) {
158 +               perror("[read]");
159 +               if (errno == EINTR || errno == EAGAIN)
160 +                   continue;
161 +           }
162 +       } while (st > 0);
163 +       gzclose(gzdata);
164 +   } else {
165     /* Send HTTP stream */
166     sock_handler_printf(sh, 0,
167        "Content-Type: %s\n"
168 @@ -658,6 +704,7 @@
169              continue;
170        }
171     } while (st > 0);
172 +   }
173  
174     /* todo: It may be better to send an error report to dillo instead of
175      * calling abort from g_error() */
176 --- dillo-0.8.3/dpi/Makefile.am.orig    2004-10-08 17:40:43.000000000 +0200
177 +++ dillo-0.8.3/dpi/Makefile.am 2004-11-03 23:47:40.904007616 +0100
178 @@ -18,7 +18,7 @@
179  ftp_filter_dpi_LDADD = @GLIB_LIBS@
180  https_filter_dpi_LDADD = @GLIB_LIBS@ @LIBSSL_LIBS@
181  hello_filter_dpi_LDADD = @GLIB_LIBS@
182 -file_dpi_LDADD = @GLIB_LIBS@
183 +file_dpi_LDADD = @GLIB_LIBS@ -lz
184  
185  bookmarks_dpi_SOURCES = bookmarks.c dpiutil.c dpiutil.h
186  downloads_dpi_SOURCES = downloads.c dpiutil.c dpiutil.h
This page took 0.031471 seconds and 2 git commands to generate.