]> git.pld-linux.org Git - packages/dillo.git/blame - dillo-gzip_fallback.patch
- added missing dir (/etc/dillo)
[packages/dillo.git] / dillo-gzip_fallback.patch
CommitLineData
76d70ef3 1--- dillo-0.6.6/src/IO/file.c.old Wed Jul 3 11:15:13 2002
2+++ dillo-0.6.6/src/IO/file.c Wed Jul 3 13:36:12 2002
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@@ -61,10 +62,12 @@
12 char *Filename;
13 const char *ContentType;
14 glong FileSize;
15+ gint ContentEncoding; /* 0 normal, 1 gzipped */
16
17 pthread_t th1; /* This transfer's thread id. */
18 } DilloFile;
19
20+#define GZIP_ENCODING 1
21
22
23 /*
24@@ -90,18 +93,30 @@
25 gint fds[2], fd;
26 struct stat sb;
27 DilloFile *Dfile;
28+ gint ContentEncoding = 0;
29
30- if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) )
31+ if ( (fd = open(filename, O_RDONLY)) < 0 || pipe(fds) ) {
32 return NULL;
33-
34+ }
35+ if (strncmp(strrchr(filename, '.'), ".gz", 3) == 0)
36+ ContentEncoding = GZIP_ENCODING;
37+
38 Dfile = g_new(DilloFile, 1);
39 Dfile->FD_Read = fds[0];
40 Dfile->FD_Write = fds[1];
41 Dfile->FD = fd;
42 Dfile->Filename = g_strdup(filename);
43- Dfile->ContentType = File_content_type(filename);
44- Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size;
45-
46+ if (ContentEncoding == GZIP_ENCODING) {
47+ gchar *tmp_filename = g_strndup(filename, strlen(filename) - 3);
48+ Dfile->ContentType = File_content_type(tmp_filename);
49+ g_free(tmp_filename);
50+ Dfile->FileSize = -1;
51+ }
52+ else {
53+ Dfile->ContentType = File_content_type(filename);
54+ Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size;
55+ }
56+ Dfile->ContentEncoding = ContentEncoding;
57 return Dfile;
58 }
59
60@@ -162,6 +177,7 @@
61 char buf[8192];
62 DilloFile *Dfile = data;
63 ssize_t nbytes;
64+ gzFile gzdata;
65
66 /* Set this thread to detached state */
67 pthread_detach(Dfile->th1);
68@@ -179,13 +195,22 @@
69 strcpy(buf, "\n");
70 write(Dfile->FD_Write, buf, strlen(buf));
71
72-
73- /* Append raw file contents */
74- while ( (nbytes = read(Dfile->FD, buf, 8192)) != 0 ) {
75- write(Dfile->FD_Write, buf, nbytes);
76+ /* decompress gzipped file */
77+ if (Dfile->ContentEncoding == GZIP_ENCODING) {
78+ gzdata = gzdopen(Dfile->FD, "r");
79+ while ((nbytes = gzread(gzdata, buf, 8192)) != 0 ) {
80+ write(Dfile->FD_Write, buf, nbytes);
81+ }
82+ gzclose(gzdata);
83 }
84+ else {
85+ /* Append raw file contents */
86+ while ( (nbytes = read(Dfile->FD, buf, 8192)) != 0 ) {
87+ write(Dfile->FD_Write, buf, nbytes);
88+ }
89
90- close(Dfile->FD);
91+ close(Dfile->FD);
92+ }
93 close(Dfile->FD_Write);
94 File_dillofile_free(Dfile);
95 return NULL;
96@@ -270,7 +295,7 @@
97 static void File_get(ChainLink *Info, void *Data, void *ExtraData)
98 {
99 const gchar *path;
100- gchar *filename;
101+ gchar *filename, *tmp_filename;
102 gint fd;
103 struct stat sb;
104 IOData_t *io;
105@@ -286,7 +311,15 @@
106 else
107 filename = a_Url_parse_hex_path(Url);
108
109+stat_point:
110 if ( stat(filename, &sb) != 0 ) {
111+ char *ext = strrchr(filename, '.');
112+ if (ext && strcmp(ext, ".gz") != 0) {
113+ tmp_filename = filename;
114+ filename = g_strconcat(tmp_filename, ".gz", NULL);
115+ g_free(tmp_filename);
116+ goto stat_point;
117+ }
118 /* stat failed, prepare a file-not-found error. */
119 fd = -2;
120 } else if (S_ISDIR(sb.st_mode)) {
This page took 0.043121 seconds and 4 git commands to generate.