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