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
4 * Directory entries on top, files next.
5 * With new HTML layout.
9 #include <ctype.h> /* for tolower */
14 #include <errno.h> /* for errno */
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,
28 const char *orig_url);
30 cont = "application/executable";
31 filecont = "Executable";
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"))
40 * Return a content type based on the extension of the filename.
42 -static const char *File_ext(const char *filename)
43 +static const char *File_ext(const char *filename, int *gzipped)
48 if ( !(e = strrchr(filename, '.')) )
51 + if ((e > filename) && !strcasecmp(e+1, "gz") &&
52 + ((e2 = memrchr(filename, '.', e-filename)) != NULL)) {
54 + if (!strncasecmp(e2, "html.", 5) ||
55 + !strncasecmp(e2, "htm.", 4) ||
56 + !strncasecmp(e2, "shtml.", 6)) {
64 if (!strcasecmp(e, "gif")) {
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)
69 -static const char *File_content_type(const char *filename)
70 +static const char *File_content_type(const char *filename, int *gzipped)
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) {
84 + char *tmp_filename = (char*)filename, *p;
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) {
91 + strcpy(tmp_filename, filename);
92 + strcat(tmp_filename, ".gz");
93 + filename = tmp_filename;
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);
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);
111 if (res == FILE_NOT_FOUND) {
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);
119 + if(tmp_filename != filename)
120 + free(tmp_filename);
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)
137 - ct = File_content_type(filename);
138 + ct = File_content_type(filename, &gzipped);
139 if (!ct || !strcmp(ct, "application/octet-stream"))
143 /* Send DPI command */
144 sock_handler_printf(sh, 1,
145 "<dpi cmd='start_send_page' url='%s'>\n", orig_url);
148 + /* Send HTTP stream */
149 + sock_handler_printf(sh, 0,
150 + "Content-Type: %s\n\n", ct);
152 + gzdata = gzdopen(fd, "r");
154 + if ((st = gzread(gzdata, buf, LBUF)) > 0) {
155 + if (sock_handler_write(sh, buf, st, 0) != 0)
157 + } else if (st < 0) {
159 + if (errno == EINTR || errno == EAGAIN)
165 /* Send HTTP stream */
166 sock_handler_printf(sh, 0,
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
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
185 bookmarks_dpi_SOURCES = bookmarks.c dpiutil.c dpiutil.h
186 downloads_dpi_SOURCES = downloads.c dpiutil.c dpiutil.h