diff options
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTAnchor.h | 3 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTMIME.c | 4 | ||||
-rw-r--r-- | src/GridText.c | 6 | ||||
-rw-r--r-- | src/HTFWriter.c | 90 |
5 files changed, 102 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES index 6c3d5308..d5efd153 100644 --- a/CHANGES +++ b/CHANGES @@ -1,9 +1,12 @@ --- $LynxId: CHANGES,v 1.877 2017/02/07 10:10:04 tom Exp $ +-- $LynxId: CHANGES,v 1.878 2017/02/10 22:41:32 tom Exp $ =============================================================================== Changes since Lynx 2.8 release =============================================================================== -2017-02-07 (2.8.9dev.12) +2017-02-10 (2.8.9dev.12) +* refine special case of server Content-Type from 2.8.7dev.11 changes to + decompress files offered for download when the server has gzip'd them + (report by TH) -TD * amend comparision from 2.8.8dev.10 changes to handle slang specially (report/testcase by TH) -TD * minor cleanup of UCDomap.c -TD diff --git a/WWW/Library/Implementation/HTAnchor.h b/WWW/Library/Implementation/HTAnchor.h index c804aff5..e06ed017 100644 --- a/WWW/Library/Implementation/HTAnchor.h +++ b/WWW/Library/Implementation/HTAnchor.h @@ -1,5 +1,5 @@ /* - * $LynxId: HTAnchor.h,v 1.37 2013/10/02 23:21:55 tom Exp $ + * $LynxId: HTAnchor.h,v 1.38 2017/02/10 22:26:48 tom Exp $ * * Hypertext "Anchor" Object HTAnchor.h * ========================== @@ -104,6 +104,7 @@ extern "C" { #ifdef EXP_HTTP_HEADERS HTChunk http_headers; #endif + BOOL no_content_encoding; /* server did not use C-T? */ char *content_type_params; /* Content-Type (with parameters if any) */ char *content_type; /* Content-Type */ char *content_language; /* Content-Language */ diff --git a/WWW/Library/Implementation/HTMIME.c b/WWW/Library/Implementation/HTMIME.c index 77775660..909fbb5e 100644 --- a/WWW/Library/Implementation/HTMIME.c +++ b/WWW/Library/Implementation/HTMIME.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTMIME.c,v 1.92 2016/11/24 18:16:23 tom Exp $ + * $LynxId: HTMIME.c,v 1.93 2017/02/10 22:27:42 tom Exp $ * * MIME Message Parse HTMIME.c * ================== @@ -261,6 +261,8 @@ static int pumpData(HTStream *me) */ CTRACE((tfp, "...address{%s}\n", me->anchor->address)); method = HTContentTypeToCompressType(me->anchor->content_type_params); + if (isEmpty(me->anchor->content_encoding)) + me->anchor->no_content_encoding = TRUE; if ((method != cftNone) && isEmpty(me->anchor->content_encoding) && (new_content = UncompressedContentType(me, method)) != 0) { diff --git a/src/GridText.c b/src/GridText.c index 14ddf093..a3abbe79 100644 --- a/src/GridText.c +++ b/src/GridText.c @@ -1,5 +1,5 @@ /* - * $LynxId: GridText.c,v 1.292 2017/02/07 10:10:45 tom Exp $ + * $LynxId: GridText.c,v 1.294 2017/02/11 00:50:00 tom Exp $ * * Character grid hypertext object * =============================== @@ -4449,7 +4449,7 @@ void HText_appendCharacter(HText *text, int ch) case SJIS: if ((text->kcode == EUC) || (text->kcode == JIS)) { if (!conv_jisx0201kana && IS_EUC_X0201KANA(hi, lo)) - line->data[line->size++] = lo; + line->data[line->size++] = (char) lo; else { EUC_TO_SJIS1(hi, lo, tmp); line->data[line->size++] = (char) tmp[0]; @@ -4543,7 +4543,7 @@ void _internal_HTC(HText *text, int style, int dir) if ((int) line->styles[line->numstyles].sc_horizpos >= ctrl_chars_on_this_line) { line->styles[line->numstyles].sc_horizpos -= ctrl_chars_on_this_line; } - line->styles[line->numstyles].sc_style = style; + line->styles[line->numstyles].sc_style = (unsigned short) style; line->styles[line->numstyles].sc_direction = dir; CTRACE_STYLE((tfp, "internal_HTC %d:style[%d] %d (dir=%d)\n", line->size, diff --git a/src/HTFWriter.c b/src/HTFWriter.c index ee1817d0..6f04ea0c 100644 --- a/src/HTFWriter.c +++ b/src/HTFWriter.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTFWriter.c,v 1.107 2016/11/24 15:35:29 tom Exp $ + * $LynxId: HTFWriter.c,v 1.111 2017/02/11 00:28:32 tom Exp $ * * FILE WRITER HTFWrite.h * =========== @@ -143,6 +143,81 @@ static void HTFWriter_write(HTStream *me, const char *s, int l) } } +static void decompress_gzip(HTStream *me) +{ + char *in_name = me->anchor->FileCache; + char copied[LY_MAXPATH]; + FILE *fp = LYOpenTemp(copied, ".tmp.gz", BIN_W); + + if (fp != 0) { +#ifdef USE_ZLIB + char buffer[BUFSIZ]; + gzFile gzfp; + int status; + + CTRACE((tfp, "decompressing '%s'\n", in_name)); + if ((gzfp = gzopen(in_name, BIN_R)) != 0) { + BOOL success = TRUE; + size_t actual = 0; + + CTRACE((tfp, "...opened '%s'\n", copied)); + while ((status = gzread(gzfp, buffer, sizeof(buffer))) > 0) { + size_t want = (size_t) status; + size_t have = fwrite(buffer, sizeof(char), want, fp); + + actual += have; + if (want != have) { + success = FALSE; + break; + } + } + gzclose(gzfp); + LYCloseTempFP(fp); + CTRACE((tfp, "...decompress %ld to %ld\n", + me->anchor->actual_length, + actual)); + if (success) { + if (rename(copied, in_name) == 0) + me->anchor->actual_length = (off_t) actual; + LYRemoveTemp(copied); + } + } +#else +#define FMT "%s %s" + const char *program; + + if (LYCopyFile(in_name, copied) == 0) { + char expanded[LY_MAXPATH]; + char *command = NULL; + + if ((program = HTGetProgramPath(ppUNCOMPRESS)) != NULL) { + HTAddParam(&command, FMT, 1, program); + HTAddParam(&command, FMT, 2, copied); + HTEndParam(&command, FMT, 2); + } + if (LYSystem(command) == 0) { + struct stat stat_buf; + + strcpy(expanded, copied); + *strrchr(expanded, '.') = '\0'; + if (rename(expanded, in_name) != 0) { + CTRACE((tfp, "rename failed %s to %s\n", expanded, in_name)); + } else if (stat(in_name, &stat_buf) != 0) { + CTRACE((tfp, "stat failed for %s\n", in_name)); + } else { + me->anchor->actual_length = stat_buf.st_size; + } + } else { + CTRACE((tfp, "command failed: %s\n", command)); + } + free(command); + LYRemoveTemp(copied); + } +#undef FMT +#endif + } +} + /* Free an HTML object * ------------------- * @@ -168,6 +243,19 @@ static void HTFWriter_free(HTStream *me) fflush(me->fp); if (me->end_command) { /* Temp file */ LYCloseTempFP(me->fp); + /* + * Handle a special case where the server used "Content-Type: gzip". + * Normally that feeds into the presentation stages, but if the link + * happens to point to something that will not be presented, but + * instead offered as a download, it comes here. In that case, ungzip + * the content before prompting the user for the place to store it. + */ + if (me->anchor->FileCache != NULL + && me->anchor->no_content_encoding == FALSE + && me->input_format == HTAtom_for("application/x-gzip") + && !strcmp(me->anchor->content_encoding, "gzip")) { + decompress_gzip(me); + } #ifdef VMS if (0 == strcmp(me->end_command, "SaveVMSBinaryFile")) { /* |