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
5 * With new HTML layout.
11 #include <ctype.h> /* for tolower */
18 #include "../dpip/dpip.h"
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,
30 } else if (finfo->mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
31 filecont = "Executable";
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"))
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)
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 ) {
86 char *msg = NULL, *d_cmd;
87 + char *tmp_filename = (char*)filename, *p;
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) {
94 + strcpy(tmp_filename, filename);
95 + strcat(tmp_filename, ".gz");
96 + filename = tmp_filename;
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);
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);
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);
122 + if(tmp_filename != filename)
123 + free(tmp_filename);
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);
129 char buf[LBUF], *d_cmd;
134 if ( (fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0)
135 return FILE_NO_ACCESS;
137 * known extension, then we do data sniffing. If this doesn't lead
138 * to a conclusion, "application/octet-stream" is sent.
140 - if (!(ct = File_content_type(filename)))
141 + ct = File_content_type(filename, &gzipped);
142 ct = "application/octet-stream";
144 /* Send DPI command */
146 sock_handler_write_str(Client->sh, d_cmd, 1);
150 + /* Send HTTP stream */
151 + sock_handler_printf(Client->sh, 0,
152 + "Content-Type: %s\n\n", ct);
154 + gzdata = gzdopen(fd, "r");
156 + if ((st = gzread(gzdata, buf, LBUF)) > 0) {
157 + if (sock_handler_write(Client->sh, buf, st, 0) != 0)
159 + } else if (st < 0) {
161 + if (errno == EINTR || errno == EAGAIN)
167 /* Send HTTP stream */
168 sock_handler_printf(Client->sh, 0,
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
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