summaryrefslogtreecommitdiffstats
path: root/WWW/Library
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 05:26:01 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 05:26:01 +0000
commitd7c9bf8bdc78b40ec91f15300c9558a5f79e803c (patch)
treef31ad4ad244bf5932be8048b3ef9dc6eacca0b7c /WWW/Library
parentAdding upstream version 2.9.1. (diff)
downloadlynx-d7c9bf8bdc78b40ec91f15300c9558a5f79e803c.tar.xz
lynx-d7c9bf8bdc78b40ec91f15300c9558a5f79e803c.zip
Adding upstream version 2.9.2.upstream/2.9.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'WWW/Library')
-rw-r--r--WWW/Library/Implementation/HTFile.c129
-rw-r--r--WWW/Library/Implementation/HTFile.h6
-rw-r--r--WWW/Library/Implementation/HTTP.c8
3 files changed, 127 insertions, 16 deletions
diff --git a/WWW/Library/Implementation/HTFile.c b/WWW/Library/Implementation/HTFile.c
index e9a225d..9b6c54f 100644
--- a/WWW/Library/Implementation/HTFile.c
+++ b/WWW/Library/Implementation/HTFile.c
@@ -1,5 +1,5 @@
/*
- * $LynxId: HTFile.c,v 1.159 2024/04/11 20:19:06 tom Exp $
+ * $LynxId: HTFile.c,v 1.165 2024/05/28 00:35:41 tom Exp $
*
* File Access HTFile.c
* ===========
@@ -1384,6 +1384,9 @@ CompressFileType HTEncodingToCompressType(const char *coding)
if (coding == NULL) {
result = cftNone;
+ } else if (!strcasecomp(coding, "deflate") ||
+ !strcasecomp(coding, "x-deflate")) {
+ result = cftDeflate;
} else if (!strcasecomp(coding, "gzip") ||
!strcasecomp(coding, "x-gzip")) {
result = cftGzip;
@@ -1394,12 +1397,9 @@ CompressFileType HTEncodingToCompressType(const char *coding)
!strcasecomp(coding, "x-bzip2")) {
result = cftBzip2;
} else if (!strcasecomp(coding, "br") || /* actual */
- !strcasecomp(coding, "brotli") || /* expected */
- !strcasecomp(coding, "x-brotli")) {
+ !strcasecomp(coding, "x-br") ||
+ !strcasecomp(coding, "brotli")) { /* expected */
result = cftBrotli;
- } else if (!strcasecomp(coding, "deflate") ||
- !strcasecomp(coding, "x-deflate")) {
- result = cftDeflate;
}
return result;
}
@@ -1410,6 +1410,9 @@ CompressFileType HTContentTypeToCompressType(const char *ct)
if (ct == NULL) {
method = cftNone;
+ } else if (!strncasecomp(ct, "application/deflate", 19) ||
+ !strncasecomp(ct, "application/x-deflate", 21)) {
+ method = cftGzip;
} else if (!strncasecomp(ct, "application/gzip", 16) ||
!strncasecomp(ct, "application/x-gzip", 18)) {
method = cftGzip;
@@ -1420,14 +1423,49 @@ CompressFileType HTContentTypeToCompressType(const char *ct)
!strncasecomp(ct, "application/x-bzip2", 19)) {
method = cftBzip2;
} else if (!strncasecomp(ct, "application/br", 14) ||
- !strncasecomp(ct, "application/brotli", 18) ||
- !strncasecomp(ct, "application/x-brotli", 20)) {
+ !strncasecomp(ct, "application/x-br", 16) ||
+ !strncasecomp(ct, "application/brotli", 18)) {
method = cftBrotli;
}
return method;
}
/*
+ * "Encoding" is jargon for compression-type. Provide a reverse mapping.
+ */
+BOOL IsCompressionFormat(HTAtom *format, CompressFileType check)
+{
+ BOOL result = FALSE;
+
+ switch (check) {
+ case cftDeflate:
+ result = (format == HTAtom_for("application/deflate") ||
+ format == HTAtom_for("application/x-deflate"));
+ break;
+ case cftGzip:
+ result = (format == HTAtom_for("application/gzip") ||
+ format == HTAtom_for("application/x-gzip"));
+ break;
+ case cftCompress:
+ result = (format == HTAtom_for("application/compress") ||
+ format == HTAtom_for("application/x-compress"));
+ break;
+ case cftBzip2:
+ result = (format == HTAtom_for("application/bzip2") ||
+ format == HTAtom_for("application/x-bzip2"));
+ break;
+ case cftBrotli:
+ result = (format == HTAtom_for("application/br") ||
+ format == HTAtom_for("application/x-br") ||
+ format == HTAtom_for("application/brotli"));
+ break;
+ case cftNone:
+ break;
+ }
+ return result;
+}
+
+/*
* Check the anchor's content_type and content_encoding elements for a gzip or
* Unix compressed file -FM, TD
*/
@@ -3210,6 +3248,28 @@ int HTLoadFile(const char *addr,
static const char *program_paths[pp_Last];
+#if defined(UNIX) || defined(_WINDOWS)
+#ifndef X_OK
+#define X_OK 0
+#endif
+static int VerifyProgram(const char *path)
+{
+ int result = 0;
+ struct stat info;
+
+ if (stat(path, &info) == 0) {
+ if (S_ISREG(info.st_mode) &&
+ info.st_size != 0 &&
+ access(path, X_OK) == 0) {
+ result = 1;
+ } else {
+ result = -1;
+ }
+ }
+ return result;
+}
+#endif
+
/*
* Given a program number, return its path
*/
@@ -3217,8 +3277,59 @@ const char *HTGetProgramPath(ProgramPaths code)
{
const char *result = NULL;
- if (code > ppUnknown && code < pp_Last)
+ if (code > ppUnknown && code < pp_Last) {
result = program_paths[code];
+#if defined(UNIX) || defined(_WINDOWS)
+#define VERIFY_FMT "not a program: %s\n"
+#define EXISTS_FMT "no file found: %s\n"
+ if (result != NULL) {
+ char *path;
+
+ switch (VerifyProgram(result)) {
+ case -1:
+ CTRACE((tfp, VERIFY_FMT, result));
+ result = NULL;
+ break;
+ case 0:
+ if (*result == '/') {
+ CTRACE((tfp, EXISTS_FMT, result));
+ result = NULL;
+ } else if ((path = getenv("PATH")) != NULL) {
+ int check = 0;
+ char *list = NULL;
+
+ StrAllocCopy(list, path);
+ if (list != NULL) {
+ char *item;
+
+ path = list;
+ while ((item = strtok(path, PATH_SEPARATOR)) != NULL) {
+ path = NULL;
+ if (*item != '\0') {
+ char *full = NULL;
+
+ HTSprintf0(&full, "%s%s%s",
+ item, FILE_SEPARATOR, result);
+ check = VerifyProgram(full);
+ free(full);
+ if (check != 0)
+ break;
+ }
+ }
+ free(list);
+ }
+ if (check <= 0) {
+ CTRACE((tfp, check ? VERIFY_FMT : EXISTS_FMT, result));
+ result = NULL;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+#endif
+ }
return result;
}
diff --git a/WWW/Library/Implementation/HTFile.h b/WWW/Library/Implementation/HTFile.h
index 1209090..9340963 100644
--- a/WWW/Library/Implementation/HTFile.h
+++ b/WWW/Library/Implementation/HTFile.h
@@ -1,5 +1,5 @@
/*
- * $LynxId: HTFile.h,v 1.36 2023/10/24 08:07:39 tom Exp $
+ * $LynxId: HTFile.h,v 1.37 2024/05/27 10:08:57 tom Exp $
* File access in libwww
* FILE ACCESS
*
@@ -232,6 +232,10 @@ extern "C" {
*/
extern CompressFileType HTContentTypeToCompressType(const char *ct);
/*
+ * Check if a given content-encoding (format) matches something we support.
+ */
+ extern BOOL IsCompressionFormat(HTAtom *format, CompressFileType check);
+/*
* Determine compression type from the content-type and/or content-encoding.
*/
extern CompressFileType HTContentToCompressType(HTParentAnchor *anchor);
diff --git a/WWW/Library/Implementation/HTTP.c b/WWW/Library/Implementation/HTTP.c
index bbcdf5d..c47d446 100644
--- a/WWW/Library/Implementation/HTTP.c
+++ b/WWW/Library/Implementation/HTTP.c
@@ -1,5 +1,5 @@
/*
- * $LynxId: HTTP.c,v 1.184 2023/07/23 20:02:58 tom Exp $
+ * $LynxId: HTTP.c,v 1.185 2024/05/29 21:02:14 tom Exp $
*
* HyperText Transfer Protocol - Client implementation HTTP.c
* ===========================
@@ -716,11 +716,7 @@ static BOOL acceptEncoding(int code)
default:
break;
}
- /*
- * FIXME: if lynx did not rely upon external programs to decompress
- * files for external viewers, this check could be relaxed.
- */
- result = (BOOL) (program != 0);
+ result = (BOOL) (program != NULL);
}
return result;
}