]> git.pld-linux.org Git - packages/dillo.git/blob - dillo-gzip_fallback.patch
0dd88113a799d2d731d4f8a2372c6d63b152b6f7
[packages/dillo.git] / dillo-gzip_fallback.patch
1 --- dillo-0.7.2/src/IO/file.c.orig      Sun May  4 12:33:54 2003
2 +++ dillo-0.7.2/src/IO/file.c   Sun May  4 12:40:09 2003
3 @@ -29,6 +29,7 @@
4  #include <stdio.h>
5  #include <signal.h>
6  #include <math.h>            /* for rint */
7 +#include <zlib.h>
8  
9  #include <errno.h>           /* for errno */
10  #include "Url.h"
11 @@ -66,7 +67,7 @@
12     pthread_t th1;      /* This transfer's thread id. */
13  } DilloFile;
14  
15 -
16 +#define GZIP_ENCODING 1
17  
18  /*
19   * Local data
20 @@ -122,15 +123,27 @@
21     struct stat sb;
22     DilloFile *Dfile;
23  
24 -   if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) )
25 +   if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) ) {
26        return NULL;
27 -
28 +   }
29 +   if (strncmp(strrchr(filename, '.'), ".gz", 3) == 0)
30 +          ContentEncoding = GZIP_ENCODING;
31     Dfile = g_new(DilloFile, 1);
32     Dfile->FD_Read  = fds[0];
33     Dfile->FD_Write = fds[1];
34     Dfile->FD = fd;
35     Dfile->FileName = g_strdup(filename);
36 -   Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size;
37 +   if (ContentEncoding == GZIP_ENCODING) {
38 +      gchar *tmp_filename = g_strndup(filename, strlen(filename) - 3);
39 +      Dfile->ContentType = File_content_type(tmp_filename);
40 +      g_free(tmp_filename);
41 +      Dfile->FileSize = -1;
42 +   }
43 +   else {
44 +      Dfile->ContentType = File_content_type(filename);
45 +      Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size;
46 +   }
47 +   Dfile->ContentEncoding = ContentEncoding;
48  
49     return Dfile;
50  }
51 @@ -194,6 +207,7 @@
52     DilloFile *Dfile = data;
53     ssize_t nbytes;
54     const gchar *ct;
55 +   gzFile gzdata;
56  
57     /* Set this thread to detached state */
58     pthread_detach(Dfile->th1);
59 @@ -221,12 +235,23 @@
60     write(Dfile->FD_Write, buf, strlen(buf));
61  
62  
63 -   /* Append raw file contents */
64 -   while ( (nbytes = read(Dfile->FD, buf, 8192)) != 0 ) {
65 -      write(Dfile->FD_Write, buf, nbytes);
66 +   /* decompress gzipped file */
67 +   if (Dfile->ContentEncoding == GZIP_ENCODING) {
68 +      gzdata = gzdopen(Dfile->FD, "r");
69 +      while ((nbytes = gzread(gzdata, buf, 8192)) != 0 ) {
70 +         write(Dfile->FD_Write, buf, nbytes);
71 +      }
72 +      gzclose(gzdata);
73     }
74 +   else {
75 +   /* Append raw file contents */
76 +      while ( (nbytes = read(Dfile->FD, buf, 8192)) != 0 ) {
77 +         write(Dfile->FD_Write, buf, nbytes);
78 +      }
79 +
80  
81     close(Dfile->FD);
82 +   }
83     close(Dfile->FD_Write);
84     File_dillofile_free(Dfile);
85     return NULL;
86 @@ -339,7 +364,7 @@
87  static void File_get(ChainLink *Info, void *Data1, void *Data2)
88  {
89     const gchar *path;
90 -   gchar *filename;
91 +   gchar *filename, *tmp_filename;
92     gint fd;
93     struct stat sb;
94     const DilloUrl *Url = Data1;
95 @@ -353,8 +378,15 @@
96        filename = g_strdup(g_get_home_dir());
97     else
98        filename = a_Url_parse_hex_path(Url);
99 -
100 +stat_point:
101     if ( stat(filename, &sb) != 0 ) {
102 +      char *ext = strrchr(filename, '.');
103 +      if (ext && strcmp(ext, ".gz") != 0) {
104 +         tmp_filename = filename;
105 +         filename = g_strconcat(tmp_filename, ".gz", NULL);
106 +         g_free(tmp_filename);
107 +         goto stat_point;
108 +      }
109        /* stat failed, prepare a file-not-found error. */
110        fd = -2;
111     } else if (S_ISDIR(sb.st_mode)) {
This page took 0.025203 seconds and 2 git commands to generate.