]> git.pld-linux.org Git - packages/dillo.git/blob - dillo-gzip_fallback.patch
- updated for 0.8.6
[packages/dillo.git] / dillo-gzip_fallback.patch
1 diff -urN dillo-0.8.6.orig/dpi/file.c dillo-0.8.6/dpi/file.c
2 --- dillo-0.8.6.orig/dpi/file.c 2006-04-11 19:50:23.000000000 +0200
3 +++ dillo-0.8.6/dpi/file.c      2006-08-20 20:27:22.392356500 +0200
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 @@ -33,6 +34,7 @@
13  #include <time.h>
14  #include <signal.h>
15  #include <glib.h>
16 +#include <zlib.h>
17  
18  #include "../dpip/dpip.h"
19  #include "dpiutil.h"
20 @@ -73,7 +75,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(ClientInfo *Client,
27                            const gchar *filename,
28                            struct stat *sb,
29 @@ -343,7 +345,7 @@
30     } else if (finfo->mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
31        filecont = "Executable";
32     } else {
33 -      filecont = File_content_type(finfo->full_path);
34 +      filecont = File_content_type(finfo->full_path, NULL);
35        if (!filecont || !strcmp(filecont, "application/octet-stream"))
36           filecont = "unknown";
37     }
38 @@ -468,13 +470,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 @@ -497,7 +510,7 @@
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     struct stat sb;
74 @@ -505,7 +518,7 @@
75     gchar buf[256];
76     ssize_t buf_size;
77  
78 -   if (!(ct = File_ext(filename))) {
79 +   if (!(ct = File_ext(filename, gzipped))) {
80        /* everything failed, let's analyze the data... */
81        if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) != -1) {
82           if ((buf_size = read(fd, buf, 256)) == 256 ) {
83 @@ -531,25 +544,39 @@
84     int res;
85     struct stat sb;
86     char *msg = NULL, *d_cmd;
87 +   char *tmp_filename = (char*)filename, *p;
88  
89     if (stat(filename, &sb) != 0) {
90 +      char *e = strrchr(filename, '.');
91 +      if ((e == NULL) || strcasecmp(e + 1, "gz")) {
92 +       if ((p = malloc(strlen(filename) + 4)) != NULL) {
93 +          tmp_filename = p;
94 +          strcpy(tmp_filename, filename);
95 +          strcat(tmp_filename, ".gz");
96 +          filename = tmp_filename;
97 +       }
98 +      }
99 +   }
100 +   if (stat(tmp_filename, &sb) != 0) {
101        /* stat failed, prepare a file-not-found error. */
102        res = FILE_NOT_FOUND;
103     } else if (S_ISDIR(sb.st_mode)) {
104        /* set up for reading directory */
105 -      res = File_get_dir(Client, filename, orig_url);
106 +      res = File_get_dir(Client, tmp_filename, orig_url);
107     } else {
108        /* set up for reading a file */
109 -      res = File_get_file(Client, filename, &sb, orig_url);
110 +      res = File_get_file(Client, tmp_filename, &sb, orig_url);
111     }
112  
113     if (res == FILE_NOT_FOUND) {
114        msg = g_strdup_printf("%s Not Found: %s",
115 -               S_ISDIR(sb.st_mode) ? "Directory" : "File", filename);
116 +               S_ISDIR(sb.st_mode) ? "Directory" : "File", tmp_filename);
117     } else if (res == FILE_NO_ACCESS) {
118        msg = g_strdup_printf("Access denied to %s: %s",
119 -               S_ISDIR(sb.st_mode) ? "Directory" : "File", filename);
120 +               S_ISDIR(sb.st_mode) ? "Directory" : "File", tmp_filename);
121     }
122 +   if(tmp_filename != filename)
123 +      free(tmp_filename);
124     if (msg) {
125        d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s", "send_status_message", msg);
126        sock_handler_write_str(Client->sh, d_cmd, 1);
127 @@ -596,6 +623,8 @@
128     const gchar *ct;
129     char buf[LBUF], *d_cmd;
130     gint fd, st;
131 +   int gzipped = 0;
132 +   gzFile gzdata;
133  
134     if ( (fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0)
135        return FILE_NO_ACCESS;
136 @@ -604,7 +633,7 @@
137      * known extension, then we do data sniffing. If this doesn't lead
138      * to a conclusion, "application/octet-stream" is sent.
139      */
140 -   if (!(ct = File_content_type(filename)))
141 +   ct = File_content_type(filename, &gzipped);
142        ct = "application/octet-stream";
143  
144     /* Send DPI command */
145 @@ -612,6 +641,24 @@
146     sock_handler_write_str(Client->sh, d_cmd, 1);
147     g_free(d_cmd);
148  
149 +   if (gzipped) {
150 +       /* Send HTTP stream */
151 +       sock_handler_printf(Client->sh, 0,
152 +          "Content-Type: %s\n\n", ct);
153 +
154 +       gzdata = gzdopen(fd, "r");
155 +       do {
156 +           if ((st = gzread(gzdata, buf, LBUF)) > 0) {
157 +               if (sock_handler_write(Client->sh, buf, st, 0) != 0)
158 +                   break;
159 +           } else if (st < 0) {
160 +               perror("[read]");
161 +               if (errno == EINTR || errno == EAGAIN)
162 +                   continue;
163 +           }
164 +       } while (st > 0);
165 +       gzclose(gzdata);
166 +   } else {
167     /* Send HTTP stream */
168     sock_handler_printf(Client->sh, 0,
169        "Content-Type: %s\n"
170 @@ -629,6 +676,7 @@
171              continue;
172        }
173     } while (st > 0);
174 +   }
175  
176     /* todo: It may be better to send an error report to dillo instead of
177      * calling abort from g_error() */
178 diff -urN dillo-0.8.6.orig/dpi/Makefile.am dillo-0.8.6/dpi/Makefile.am
179 --- dillo-0.8.6.orig/dpi/Makefile.am    2006-01-03 21:16:10.000000000 +0100
180 +++ dillo-0.8.6/dpi/Makefile.am 2006-08-20 20:10:16.412236750 +0200
181 @@ -27,7 +27,7 @@
182  ftp_filter_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a
183  https_filter_dpi_LDADD = @GLIB_LIBS@ @LIBSSL_LIBS@ ../dpip/libDpip.a
184  hello_filter_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a
185 -file_dpi_LDADD = @GLIB_LIBS@ @LIBPTHREAD_LIBS@ ../dpip/libDpip.a
186 +file_dpi_LDADD = @GLIB_LIBS@ @LIBPTHREAD_LIBS@ ../dpip/libDpip.a -lz
187  cookies_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a
188  datauri_filter_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a
189  
This page took 0.501428 seconds and 3 git commands to generate.