]>
Commit | Line | Data |
---|---|---|
f8889be6 | 1 | --- dillo-0.7.2/src/IO/file.c.orig Sun May 4 12:33:54 2003 |
e1210af3 | 2 | +++ dillo-0.7.2/src/IO/file.c Sun May 4 12:57:50 2003 |
76d70ef3 | 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" | |
e1210af3 | 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 | ||
76d70ef3 | 17 | pthread_t th1; /* This transfer's thread id. */ |
18 | } DilloFile; | |
19 | ||
f8889be6 | 20 | - |
76d70ef3 | 21 | +#define GZIP_ENCODING 1 |
22 | ||
76d70ef3 | 23 | /* |
f8889be6 | 24 | * Local data |
e1210af3 | 25 | @@ -120,17 +122,28 @@ |
26 | { | |
27 | gint fds[2], fd; | |
76d70ef3 | 28 | struct stat sb; |
e1210af3 | 29 | + gint ContentEncoding; /* 0 normal, 1 gzipped */ |
76d70ef3 | 30 | DilloFile *Dfile; |
76d70ef3 | 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) | |
f8889be6 | 38 | + ContentEncoding = GZIP_ENCODING; |
76d70ef3 | 39 | Dfile = g_new(DilloFile, 1); |
40 | Dfile->FD_Read = fds[0]; | |
41 | Dfile->FD_Write = fds[1]; | |
42 | Dfile->FD = fd; | |
f8889be6 | 43 | Dfile->FileName = g_strdup(filename); |
76d70ef3 | 44 | - Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size; |
76d70ef3 | 45 | + if (ContentEncoding == GZIP_ENCODING) { |
46 | + gchar *tmp_filename = g_strndup(filename, strlen(filename) - 3); | |
76d70ef3 | 47 | + g_free(tmp_filename); |
48 | + Dfile->FileSize = -1; | |
49 | + } | |
50 | + else { | |
76d70ef3 | 51 | + Dfile->FileSize = fstat(fd, &sb) ? -1 : (glong) sb.st_size; |
52 | + } | |
53 | + Dfile->ContentEncoding = ContentEncoding; | |
f8889be6 | 54 | |
76d70ef3 | 55 | return Dfile; |
56 | } | |
f8889be6 | 57 | @@ -194,6 +207,7 @@ |
76d70ef3 | 58 | DilloFile *Dfile = data; |
59 | ssize_t nbytes; | |
f8889be6 | 60 | const gchar *ct; |
76d70ef3 | 61 | + gzFile gzdata; |
62 | ||
63 | /* Set this thread to detached state */ | |
64 | pthread_detach(Dfile->th1); | |
f8889be6 | 65 | @@ -221,12 +235,23 @@ |
76d70ef3 | 66 | write(Dfile->FD_Write, buf, strlen(buf)); |
67 | ||
f8889be6 | 68 | |
76d70ef3 | 69 | - /* Append raw file contents */ |
70 | - while ( (nbytes = read(Dfile->FD, buf, 8192)) != 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, 8192)) != 0 ) { | |
83 | + write(Dfile->FD_Write, buf, nbytes); | |
84 | + } | |
f8889be6 | 85 | + |
76d70ef3 | 86 | |
f8889be6 | 87 | close(Dfile->FD); |
76d70ef3 | 88 | + } |
89 | close(Dfile->FD_Write); | |
90 | File_dillofile_free(Dfile); | |
91 | return NULL; | |
f8889be6 | 92 | @@ -339,7 +364,7 @@ |
93 | static void File_get(ChainLink *Info, void *Data1, void *Data2) | |
76d70ef3 | 94 | { |
95 | const gchar *path; | |
96 | - gchar *filename; | |
97 | + gchar *filename, *tmp_filename; | |
98 | gint fd; | |
99 | struct stat sb; | |
f8889be6 | 100 | const DilloUrl *Url = Data1; |
101 | @@ -353,8 +378,15 @@ | |
102 | filename = g_strdup(g_get_home_dir()); | |
76d70ef3 | 103 | else |
104 | filename = a_Url_parse_hex_path(Url); | |
f8889be6 | 105 | - |
76d70ef3 | 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)) { |