]>
Commit | Line | Data |
---|---|---|
132f8411 | 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 | |
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 */ |
132f8411 | 12 | @@ -33,6 +34,7 @@ |
13 | #include <time.h> | |
14 | #include <signal.h> | |
15 | #include <glib.h> | |
fabd671e | 16 | +#include <zlib.h> |
17 | ||
132f8411 | 18 | #include "../dpip/dpip.h" |
19 | #include "dpiutil.h" | |
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); | |
132f8411 | 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)) { | |
92c13459 JB |
31 | filecont = "Executable"; |
32 | } else { | |
132f8411 | 33 | - filecont = File_content_type(finfo->full_path); |
4eaa7222 | 34 | + filecont = File_content_type(finfo->full_path, NULL); |
92c13459 JB |
35 | if (!filecont || !strcmp(filecont, "application/octet-stream")) |
36 | filecont = "unknown"; | |
37 | } | |
132f8411 | 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 | { |
132f8411 | 45 | - char *e; |
92c13459 | 46 | + char *e, *e2; |
76d70ef3 | 47 | |
132f8411 | 48 | if ( !(e = strrchr(filename, '.')) ) |
76d70ef3 | 49 | return NULL; |
92c13459 | 50 | |
132f8411 | 51 | + if ((e > filename) && !strcasecmp(e+1, "gz") && |
52 | + ((e2 = memrchr(filename, '.', e-filename)) != NULL)) { | |
92c13459 | 53 | + e2++; |
132f8411 | 54 | + if (!strncasecmp(e2, "html.", 5) || |
55 | + !strncasecmp(e2, "htm.", 4) || | |
56 | + !strncasecmp(e2, "shtml.", 6)) { | |
57 | + if(gzipped != NULL) | |
58 | + *gzipped = 1; | |
92c13459 JB |
59 | + return "text/html"; |
60 | + } | |
76d70ef3 | 61 | + } |
92c13459 JB |
62 | e++; |
63 | ||
132f8411 | 64 | if (!strcasecmp(e, "gif")) { |
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 | { | |
132f8411 | 72 | gint fd; |
4eaa7222 | 73 | struct stat sb; |
132f8411 | 74 | @@ -505,7 +518,7 @@ |
75 | gchar buf[256]; | |
4eaa7222 | 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 ) { |
132f8411 | 83 | @@ -531,25 +544,39 @@ |
92c13459 JB |
84 | int res; |
85 | struct stat sb; | |
132f8411 | 86 | char *msg = NULL, *d_cmd; |
92c13459 JB |
87 | + char *tmp_filename = (char*)filename, *p; |
88 | ||
89 | if (stat(filename, &sb) != 0) { | |
132f8411 | 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 | + } | |
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) { |
132f8411 | 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); | |
4eaa7222 | 117 | } else if (res == FILE_NO_ACCESS) { |
132f8411 | 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) | |
132f8411 | 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; | |
92c13459 | 131 | + int gzipped = 0; |
76d70ef3 | 132 | + gzFile gzdata; |
133 | ||
132f8411 | 134 | if ( (fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0) |
92c13459 | 135 | return FILE_NO_ACCESS; |
132f8411 | 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 | |
4eaa7222 | 186 | +file_dpi_LDADD = @GLIB_LIBS@ @LIBPTHREAD_LIBS@ ../dpip/libDpip.a -lz |
132f8411 | 187 | cookies_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a |
188 | datauri_filter_dpi_LDADD = @GLIB_LIBS@ ../dpip/libDpip.a | |
92c13459 | 189 |