]> git.pld-linux.org Git - packages/dillo.git/blobdiff - dillo-gzip_fallback.patch
- release 2
[packages/dillo.git] / dillo-gzip_fallback.patch
index 17f318663d8a695887c92270e5d0831d2b09ef9a..667ead9e016b3b7a70ecb97fcb9ff3505eb20eb9 100644 (file)
---- dillo-0.6.6/src/IO/file.c.old      Wed Jul  3 11:15:13 2002
-+++ dillo-0.6.6/src/IO/file.c  Wed Jul  3 13:36:12 2002
-@@ -29,6 +29,7 @@
- #include <stdio.h>
- #include <signal.h>
- #include <math.h>            /* for rint */
+diff -burNp dillo-2.0/dpi/file.c dillo-2.0-dud/dpi/file.c
+--- dillo-2.0/dpi/file.c       2008-09-30 17:43:43.000000000 +0200
++++ dillo-2.0-dud/dpi/file.c   2009-03-24 10:39:52.201842188 +0100
+@@ -15,6 +15,7 @@
+  * With new HTML layout.
+  */
++#define _GNU_SOURCE
+ #include <pthread.h>
+ #include <ctype.h>           /* for tolower */
+@@ -36,6 +37,7 @@
+ #include "../dpip/dpip.h"
+ #include "dpiutil.h"
+ #include "d_size.h"
 +#include <zlib.h>
  
- #include <errno.h>           /* for errno */
- #include "Url.h"
-@@ -61,10 +62,12 @@
-    char *Filename;
-    const char *ContentType;
-    glong FileSize;
-+   gint ContentEncoding; /* 0 normal, 1 gzipped */ 
+ /*
+  * Debugging macros
+@@ -77,7 +79,7 @@ typedef struct {
+ /*
+  * Forward references
+  */
+-static const char *File_content_type(const char *filename);
++static const char *File_content_type(const char *filename, int *gzipped);
+ static int File_get_file(ClientInfo *Client,
+                          const char *filename,
+                          struct stat *sb,
+@@ -344,6 +346,7 @@ static void File_info2html(ClientInfo *C
+       filecont = "Executable";
+    } else {
+       filecont = File_content_type(finfo->full_path);
++      filecont = File_content_type(finfo->full_path, NULL);
+       if (!filecont || !strcmp(filecont, "application/octet-stream"))
+          filecont = "unknown";
+    }
+@@ -467,13 +470,21 @@ static void File_transfer_dir(ClientInfo
+ /*
+  * Return a content type based on the extension of the filename.
+  */
+-static const char *File_ext(const char *filename)
++static const char *File_ext(const char *filename, int *gzipped)
+ {
+    char *e;
++   char *e, *e2;
  
-    pthread_t th1;      /* This transfer's thread id. */
} DilloFile;
+    if (!(e = strrchr(filename, '.')))
      return NULL;
  
-+#define GZIP_ENCODING 1
++   if ((e > filename) && !strcasecmp(e+1, "gz") && ((e2 = memrchr(filename, '.', e-filename)) != NULL)) {
++         e2++;
++         if (!strncasecmp(e2, "html.", 5) || !strncasecmp(e2, "htm.", 4) || !strncasecmp(e2, "shtml.", 6)) {
++                 if(gzipped != NULL) *gzipped = 1;
++                 return "text/html";
++         }
++   }
+    e++;
  
+    if (!dStrcasecmp(e, "gif")) {
+@@ -496,7 +507,7 @@ static const char *File_ext(const char *
+  * Based on the extension, return the content_type for the file.
+  * (if there's no extension, analyze the data and try to figure it out)
+  */
+-static const char *File_content_type(const char *filename)
++static const char *File_content_type(const char *filename, int *gzipped)
+ {
+    int fd;
+    struct stat sb;
+@@ -504,7 +515,7 @@ static const char *File_content_type(con
+    char buf[256];
+    ssize_t buf_size;
  
- /*
-@@ -90,18 +93,30 @@
-    gint fds[2], fd;
+-   if (!(ct = File_ext(filename))) {
++   if (!(ct = File_ext(filename, gzipped))) {
+       /* everything failed, let's analyze the data... */
+       if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) != -1) {
+          if ((buf_size = read(fd, buf, 256)) == 256 ) {
+@@ -530,28 +541,40 @@ static void File_get(ClientInfo *Client,
+    int res;
     struct stat sb;
-    DilloFile *Dfile;
-+   gint ContentEncoding = 0;
+    char *d_cmd;
++   char *tmp_filename = (char*)filename, *p;
+    Dstr *ds = NULL;
  
--   if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) )
-+   if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) ) {
-       return NULL;
--
+    if (stat(filename, &sb) != 0) {
++      char *e = strrchr(filename, '.');
++      if ((e == NULL) || strcasecmp(e + 1, "gz")) {
++              if ((p = malloc(strlen(filename) + 4)) != NULL) {
++                      tmp_filename = p;
++                      strcpy(tmp_filename, filename);
++                      strcat(tmp_filename, ".gz");
++                      filename = tmp_filename;
++              }
++      }
 +   }
-+   if (strncmp(strrchr(filename, '.'), ".gz", 3) == 0)
-+      ContentEncoding = GZIP_ENCODING; 
-+         
-    Dfile = g_new(DilloFile, 1);
-    Dfile->FD_Read  = fds[0];
-    Dfile->FD_Write = fds[1];
-    Dfile->FD = fd;
-    Dfile->Filename = g_strdup(filename);
--   Dfile->ContentType = File_content_type(filename);
--   Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size;
--
-+   if (ContentEncoding == GZIP_ENCODING) {
-+      gchar *tmp_filename = g_strndup(filename, strlen(filename) - 3);
-+      Dfile->ContentType = File_content_type(tmp_filename);
-+      g_free(tmp_filename);
-+      Dfile->FileSize = -1;
-+   }
-+   else {
-+      Dfile->ContentType = File_content_type(filename);
-+      Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size;
-+   }
-+   Dfile->ContentEncoding = ContentEncoding;
-    return Dfile;
- }
++   if (stat(tmp_filename, &sb) != 0) {
+       /* stat failed, prepare a file-not-found error. */
+       res = FILE_NOT_FOUND;
+    } else if (S_ISDIR(sb.st_mode)) {
+       /* set up for reading directory */
+-      res = File_get_dir(Client, filename, orig_url);
++      res = File_get_dir(Client, tmp_filename, orig_url);
+    } else {
+       /* set up for reading a file */
+-      res = File_get_file(Client, filename, &sb, orig_url);
++      res = File_get_file(Client, tmp_filename, &sb, orig_url);
+    }
  
-@@ -162,6 +177,7 @@
-    char buf[8192];
-    DilloFile *Dfile = data;
-    ssize_t nbytes;
+    if (res == FILE_NOT_FOUND) {
+       ds = dStr_sized_new(128);
+-      dStr_sprintf(ds, "%s Not Found: %s",
+-                   S_ISDIR(sb.st_mode) ? "Directory" : "File", filename);
++      dStr_sprintf(ds, "%s Not Found: %s", S_ISDIR(sb.st_mode) ? "Directory" : "File", tmp_filename);
+    } else if (res == FILE_NO_ACCESS) {
+       ds = dStr_sized_new(128);
+-      dStr_sprintf(ds, "Access denied to %s: %s",
+-                   S_ISDIR(sb.st_mode) ? "Directory" : "File", filename);
++      dStr_sprintf(ds, "Access denied to %s: %s", S_ISDIR(sb.st_mode) ? "Directory" : "File", tmp_filename);
+    }
++   if(tmp_filename != filename)
++         free(tmp_filename);
+    if (ds) {
+       d_cmd = a_Dpip_build_cmd("cmd=%s msg=%s","send_status_message",ds->str);
+       sock_handler_write_str(Client->sh, 1, d_cmd);
+@@ -599,7 +622,8 @@ static int File_get_file(ClientInfo *Cli
+    const char *unknown_type = "application/octet-stream";
+    char buf[LBUF], *d_cmd, *name;
+    int fd, st, namelen;
+-   bool_t gzipped = FALSE;
++   int gzipped = 0;
 +   gzFile gzdata;
  
-    /* Set this thread to detached state */
-    pthread_detach(Dfile->th1);
-@@ -179,13 +195,22 @@
-    strcpy(buf, "\n");
-    write(Dfile->FD_Write, buf, strlen(buf));
--
--   /* Append raw file contents */
--   while ( (nbytes = read(Dfile->FD, buf, 8192)) != 0 ) {
--      write(Dfile->FD_Write, buf, nbytes);
-+   /* decompress gzipped file */
-+   if (Dfile->ContentEncoding == GZIP_ENCODING) {
-+      gzdata = gzdopen(Dfile->FD, "r");
-+      while ((nbytes = gzread(gzdata, buf, 8192)) != 0 ) {
-+         write(Dfile->FD_Write, buf, nbytes);
-+      }
+    if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) < 0)
+       return FILE_NO_ACCESS;
+@@ -628,6 +652,18 @@ static int File_get_file(ClientInfo *Cli
+    /* Send HTTP headers */
+    if (gzipped) {
+       sock_handler_write_str(Client->sh, 0, "Content-Encoding: gzip\n");
++      gzdata = gzdopen(fd, "r");
++      do {
++            if ((st = gzread(gzdata, buf, LBUF)) > 0) {
++                    if (sock_handler_write(Client->sh, buf, st, 0) != 0)
++                            break;
++            } else if (st < 0) {
++                    perror("[read]");
++                    if (errno == EINTR || errno == EAGAIN)
++                            continue;
++            }
++      } while (st > 0);
 +      gzclose(gzdata);
     }
-+   else {
-+   /* Append raw file contents */
-+      while ( (nbytes = read(Dfile->FD, buf, 8192)) != 0 ) {
-+         write(Dfile->FD_Write, buf, nbytes);
-+      }
+    if (!gzipped || strcmp(ct, unknown_type)) {
+       sock_handler_printf(Client->sh, 0, "Content-Type: %s\n", ct);
+diff -burNp dillo-2.0/dpi/Makefile.am dillo-2.0-dud/dpi/Makefile.am
+--- dillo-2.0/dpi/Makefile.am  2008-04-26 23:29:10.000000000 +0200
++++ dillo-2.0-dud/dpi/Makefile.am      2009-03-24 10:40:40.881837317 +0100
+@@ -20,7 +20,7 @@ downloads_dpi_LDADD = @LIBFLTK_LIBS@ ../
+ ftp_filter_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a
+ https_filter_dpi_LDADD = @LIBSSL_LIBS@ ../dpip/libDpip.a ../dlib/libDlib.a
+ hello_filter_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a
+-file_dpi_LDADD = @LIBPTHREAD_LIBS@ ../dpip/libDpip.a ../dlib/libDlib.a
++file_dpi_LDADD = @GLIB_LIBS@ @LIBPTHREAD_LIBS@ ../dpip/libDpip.a -lz
+ cookies_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a
+ datauri_filter_dpi_LDADD = ../dpip/libDpip.a ../dlib/libDlib.a
  
--   close(Dfile->FD);
-+      close(Dfile->FD);
-+   }
-    close(Dfile->FD_Write);
-    File_dillofile_free(Dfile);
-    return NULL;
-@@ -270,7 +295,7 @@
- static void File_get(ChainLink *Info, void *Data, void *ExtraData)
- {
-    const gchar *path;
--   gchar *filename;
-+   gchar *filename, *tmp_filename;
-    gint fd;
-    struct stat sb;
-    IOData_t *io;
-@@ -286,7 +311,15 @@
-    else
-       filename = a_Url_parse_hex_path(Url);
-+stat_point:
-    if ( stat(filename, &sb) != 0 ) {
-+      char *ext = strrchr(filename, '.');
-+      if (ext && strcmp(ext, ".gz") != 0) {
-+         tmp_filename = filename;
-+         filename = g_strconcat(tmp_filename, ".gz", NULL);
-+         g_free(tmp_filename);
-+         goto stat_point;
-+      }
-       /* stat failed, prepare a file-not-found error. */
-       fd = -2;
-    } else if (S_ISDIR(sb.st_mode)) {
This page took 0.049695 seconds and 4 git commands to generate.