]> git.pld-linux.org Git - packages/dillo.git/blame - dillo-gzip_fallback.patch
- do not list %{_desktopdir}/* -- dangerous, could list directories unexpectedly
[packages/dillo.git] / dillo-gzip_fallback.patch
CommitLineData
4eaa7222 1diff -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
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 */
4eaa7222 12@@ -33,6 +34,7 @@
13 #include <time.h>
76d70ef3 14 #include <signal.h>
92c13459
JB
15 #include <glib.h>
16+#include <zlib.h>
76d70ef3 17
4eaa7222 18 #include "../dpip/dpip.h"
92c13459 19 #include "dpiutil.h"
4eaa7222 20@@ -73,7 +75,7 @@
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);
5532115f
JB
26 static gint File_get_file(ClientInfo *Client,
27 const gchar *filename,
92c13459 28 struct stat *sb,
4eaa7222 29@@ -343,7 +345,7 @@
30 } else if (finfo->mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
92c13459
JB
31 filecont = "Executable";
32 } else {
4eaa7222 33- filecont = File_content_type(finfo->full_path);
34+ filecont = File_content_type(finfo->full_path, NULL);
92c13459
JB
35 if (!filecont || !strcmp(filecont, "application/octet-stream"))
36 filecont = "unknown";
37 }
4eaa7222 38@@ -468,13 +470,24 @@
92c13459
JB
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)
e1210af3 44 {
92c13459
JB
45- char *e;
46+ char *e, *e2;
76d70ef3 47
92c13459 48 if ( !(e = strrchr(filename, '.')) )
76d70ef3 49 return NULL;
92c13459
JB
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+ }
76d70ef3 61+ }
92c13459
JB
62 e++;
63
64 if (!strcasecmp(e, "gif")) {
4eaa7222 65@@ -497,7 +510,7 @@
92c13459
JB
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;
4eaa7222 73 struct stat sb;
74@@ -505,7 +518,7 @@
75 gchar buf[256];
76 ssize_t buf_size;
92c13459
JB
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) {
4eaa7222 82 if ((buf_size = read(fd, buf, 256)) == 256 ) {
83@@ -531,25 +544,39 @@
92c13459
JB
84 int res;
85 struct stat sb;
4eaa7222 86 char *msg = NULL, *d_cmd;
92c13459
JB
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")) {
4eaa7222 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+ }
92c13459 98+ }
76d70ef3 99+ }
92c13459
JB
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 */
5532115f
JB
105- res = File_get_dir(Client, filename, orig_url);
106+ res = File_get_dir(Client, tmp_filename, orig_url);
92c13459
JB
107 } else {
108 /* set up for reading a file */
5532115f
JB
109- res = File_get_file(Client, filename, &sb, orig_url);
110+ res = File_get_file(Client, tmp_filename, &sb, orig_url);
92c13459 111 }
f8889be6 112
92c13459 113 if (res == FILE_NOT_FOUND) {
4eaa7222 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);
92c13459
JB
121 }
122+ if(tmp_filename != filename)
123+ free(tmp_filename);
4eaa7222 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 @@
f8889be6 128 const gchar *ct;
4eaa7222 129 char buf[LBUF], *d_cmd;
92c13459
JB
130 gint fd, st;
131+ int gzipped = 0;
76d70ef3 132+ gzFile gzdata;
133
92c13459
JB
134 if ( (fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0)
135 return FILE_NO_ACCESS;
4eaa7222 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.
92c13459 139 */
4eaa7222 140- if (!(ct = File_content_type(filename)))
92c13459 141+ ct = File_content_type(filename, &gzipped);
4eaa7222 142 ct = "application/octet-stream";
76d70ef3 143
92c13459 144 /* Send DPI command */
4eaa7222 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);
f8889be6 153+
4eaa7222 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 {
92c13459 167 /* Send HTTP stream */
5532115f 168 sock_handler_printf(Client->sh, 0,
92c13459 169 "Content-Type: %s\n"
4eaa7222 170@@ -629,6 +676,7 @@
92c13459
JB
171 continue;
172 }
173 } while (st > 0);
76d70ef3 174+ }
92c13459
JB
175
176 /* todo: It may be better to send an error report to dillo instead of
177 * calling abort from g_error() */
4eaa7222 178diff -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
92c13459 189
This page took 0.05202 seconds and 4 git commands to generate.