mirror of
https://github.com/rkd77/elinks.git
synced 2024-09-28 03:06:20 -04:00
Patch 3: Further fixes including strcasestr and convert_to_lowercase
This commit is contained in:
parent
1ba7d5a260
commit
20a7a6c460
@ -556,7 +556,7 @@ test_search(struct listbox_item *item, void *data_, int *offset)
|
|||||||
assert(ctx->title && ctx->url);
|
assert(ctx->title && ctx->url);
|
||||||
|
|
||||||
ctx->found = (*ctx->title && strcasestr(bm->title, ctx->title))
|
ctx->found = (*ctx->title && strcasestr(bm->title, ctx->title))
|
||||||
|| (*ctx->url && strcasestr(bm->url, ctx->url));
|
|| (*ctx->url && c_strcasestr(bm->url, ctx->url));
|
||||||
|
|
||||||
if (ctx->found) *offset = 0;
|
if (ctx->found) *offset = 0;
|
||||||
}
|
}
|
||||||
|
4
src/cache/dialogs.c
vendored
4
src/cache/dialogs.c
vendored
@ -175,8 +175,8 @@ match_cache_entry(struct listbox_item *item, struct terminal *term,
|
|||||||
{
|
{
|
||||||
struct cache_entry *cached = item->udata;
|
struct cache_entry *cached = item->udata;
|
||||||
|
|
||||||
if (strcasestr(struri(cached->uri), text)
|
if (c_strcasestr(struri(cached->uri), text)
|
||||||
|| (cached->head && strcasestr(cached->head, text)))
|
|| (cached->head && c_strcasestr(cached->head, text)))
|
||||||
return LISTBOX_MATCH_OK;
|
return LISTBOX_MATCH_OK;
|
||||||
|
|
||||||
return LISTBOX_MATCH_NO;
|
return LISTBOX_MATCH_NO;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "main/event.h"
|
#include "main/event.h"
|
||||||
#include "main/module.h"
|
#include "main/module.h"
|
||||||
#include "terminal/kbd.h"
|
#include "terminal/kbd.h"
|
||||||
|
#include "util/conv.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ search_for_url_param(unsigned char *str, unsigned char **ret)
|
|||||||
/* Returns now if string @str is empty. */
|
/* Returns now if string @str is empty. */
|
||||||
if (!*str) return HEADER_PARAM_NOT_FOUND;
|
if (!*str) return HEADER_PARAM_NOT_FOUND;
|
||||||
|
|
||||||
p = strcasestr(str, "url");
|
p = c_strcasestr(str, "url");
|
||||||
if (!p) return HEADER_PARAM_NOT_FOUND;
|
if (!p) return HEADER_PARAM_NOT_FOUND;
|
||||||
p += 3;
|
p += 3;
|
||||||
|
|
||||||
|
@ -762,21 +762,21 @@ html_link_parse(struct html_context *html_context, unsigned char *a,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcasestr(link->name, "icon") ||
|
if (c_strcasestr(link->name, "icon") ||
|
||||||
(link->content_type && strcasestr(link->content_type, "icon"))) {
|
(link->content_type && c_strcasestr(link->content_type, "icon"))) {
|
||||||
link->type = LT_ICON;
|
link->type = LT_ICON;
|
||||||
|
|
||||||
} else if (strcasestr(link->name, "alternate")) {
|
} else if (c_strcasestr(link->name, "alternate")) {
|
||||||
link->type = LT_ALTERNATE;
|
link->type = LT_ALTERNATE;
|
||||||
if (link->lang)
|
if (link->lang)
|
||||||
link->type = LT_ALTERNATE_LANG;
|
link->type = LT_ALTERNATE_LANG;
|
||||||
else if (strcasestr(link->name, "stylesheet") ||
|
else if (c_strcasestr(link->name, "stylesheet") ||
|
||||||
(link->content_type && strcasestr(link->content_type, "css")))
|
(link->content_type && c_strcasestr(link->content_type, "css")))
|
||||||
link->type = LT_ALTERNATE_STYLESHEET;
|
link->type = LT_ALTERNATE_STYLESHEET;
|
||||||
else if (link->media)
|
else if (link->media)
|
||||||
link->type = LT_ALTERNATE_MEDIA;
|
link->type = LT_ALTERNATE_MEDIA;
|
||||||
|
|
||||||
} else if (link->content_type && strcasestr(link->content_type, "css")) {
|
} else if (link->content_type && c_strcasestr(link->content_type, "css")) {
|
||||||
link->type = LT_STYLESHEET;
|
link->type = LT_STYLESHEET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ document_get(struct SEE_interpreter *interp, struct SEE_object *o,
|
|||||||
if (!string) return;
|
if (!string) return;
|
||||||
|
|
||||||
foreach (form, document->forms) {
|
foreach (form, document->forms) {
|
||||||
if (!form->name || strcasecmp(string, form->name))
|
if (!form->name || c_strcasecmp(string, form->name))
|
||||||
continue;
|
continue;
|
||||||
form_view = find_form_view(doc_view, form);
|
form_view = find_form_view(doc_view, form);
|
||||||
form_object = js_get_form_object(interp, doc, form_view);
|
form_object = js_get_form_object(interp, doc, form_view);
|
||||||
|
@ -689,7 +689,7 @@ js_form_elems_namedItem(struct SEE_interpreter *interp, struct SEE_object *self,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (fc, form->items) {
|
foreach (fc, form->items) {
|
||||||
if ((fc->id && !strcasecmp(string, fc->id)) || (fc->name && !strcasecmp(string, fc->name))) {
|
if ((fc->id && !c_strcasecmp(string, fc->id)) || (fc->name && !c_strcasecmp(string, fc->name))) {
|
||||||
struct form_state *fs = find_form_state(doc_view, fc);
|
struct form_state *fs = find_form_state(doc_view, fc);
|
||||||
|
|
||||||
if (fs) {
|
if (fs) {
|
||||||
@ -815,7 +815,7 @@ js_forms_namedItem(struct SEE_interpreter *interp, struct SEE_object *self,
|
|||||||
if (!string)
|
if (!string)
|
||||||
return;
|
return;
|
||||||
foreach (form, document->forms) {
|
foreach (form, document->forms) {
|
||||||
if (form->name && !strcasecmp(string, form->name)) {
|
if (form->name && !c_strcasecmp(string, form->name)) {
|
||||||
struct form_view *fv = find_form_view(doc_view, form);
|
struct form_view *fv = find_form_view(doc_view, form);
|
||||||
struct js_form *obj = js_get_form_object(interp,
|
struct js_form *obj = js_get_form_object(interp,
|
||||||
doc, fv);
|
doc, fv);
|
||||||
@ -952,7 +952,7 @@ form_get(struct SEE_interpreter *interp, struct SEE_object *o,
|
|||||||
struct js_input *fcobj = NULL;
|
struct js_input *fcobj = NULL;
|
||||||
struct form_state *fs;
|
struct form_state *fs;
|
||||||
|
|
||||||
if ((!fc->id || strcasecmp(string, fc->id)) && (!fc->name || strcasecmp(string, fc->name)))
|
if ((!fc->id || c_strcasecmp(string, fc->id)) && (!fc->name || c_strcasecmp(string, fc->name)))
|
||||||
continue;
|
continue;
|
||||||
fs = find_form_state(doc_view, fc);
|
fs = find_form_state(doc_view, fc);
|
||||||
if (fs) {
|
if (fs) {
|
||||||
@ -989,19 +989,19 @@ form_put(struct SEE_interpreter *interp, struct SEE_object *o,
|
|||||||
mem_free_set(&form->action, string);
|
mem_free_set(&form->action, string);
|
||||||
}
|
}
|
||||||
} else if (p == s_encoding) {
|
} else if (p == s_encoding) {
|
||||||
if (!strcasecmp(string, "application/x-www-form-urlencoded")) {
|
if (!c_strcasecmp(string, "application/x-www-form-urlencoded")) {
|
||||||
form->method = form->method == FORM_METHOD_GET ? FORM_METHOD_GET
|
form->method = form->method == FORM_METHOD_GET ? FORM_METHOD_GET
|
||||||
: FORM_METHOD_POST;
|
: FORM_METHOD_POST;
|
||||||
} else if (!strcasecmp(string, "multipart/form-data")) {
|
} else if (!c_strcasecmp(string, "multipart/form-data")) {
|
||||||
form->method = FORM_METHOD_POST_MP;
|
form->method = FORM_METHOD_POST_MP;
|
||||||
} else if (!strcasecmp(string, "text/plain")) {
|
} else if (!c_strcasecmp(string, "text/plain")) {
|
||||||
form->method = FORM_METHOD_POST_TEXT_PLAIN;
|
form->method = FORM_METHOD_POST_TEXT_PLAIN;
|
||||||
}
|
}
|
||||||
mem_free(string);
|
mem_free(string);
|
||||||
} else if (p == s_method) {
|
} else if (p == s_method) {
|
||||||
if (!strcasecmp(string, "GET")) {
|
if (!c_strcasecmp(string, "GET")) {
|
||||||
form->method = FORM_METHOD_GET;
|
form->method = FORM_METHOD_GET;
|
||||||
} else if (!strcasecmp(string, "POST")) {
|
} else if (!c_strcasecmp(string, "POST")) {
|
||||||
form->method = FORM_METHOD_POST;
|
form->method = FORM_METHOD_POST;
|
||||||
}
|
}
|
||||||
mem_free(string);
|
mem_free(string);
|
||||||
|
@ -304,7 +304,7 @@ js_window_open(struct SEE_interpreter *interp, struct SEE_object *self,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frame && *frame && strcasecmp(frame, "_blank")) {
|
if (frame && *frame && c_strcasecmp(frame, "_blank")) {
|
||||||
struct delayed_open *deo = mem_calloc(1, sizeof(*deo));
|
struct delayed_open *deo = mem_calloc(1, sizeof(*deo));
|
||||||
|
|
||||||
if (deo) {
|
if (deo) {
|
||||||
|
@ -318,7 +318,7 @@ globhist_simple_search(unsigned char *search_url, unsigned char *search_title)
|
|||||||
if ((*search_title
|
if ((*search_title
|
||||||
&& strcasestr(history_item->title, search_title))
|
&& strcasestr(history_item->title, search_title))
|
||||||
|| (*search_url
|
|| (*search_url
|
||||||
&& strcasestr(history_item->url, search_url))) {
|
&& c_strcasestr(history_item->url, search_url))) {
|
||||||
history_item->box_item->visible = 1;
|
history_item->box_item->visible = 1;
|
||||||
} else {
|
} else {
|
||||||
history_item->box_item->visible = 0;
|
history_item->box_item->visible = 0;
|
||||||
|
@ -249,7 +249,7 @@ get_fragment_content_type(struct cache_entry *cached)
|
|||||||
if (!sample)
|
if (!sample)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (strcasestr(sample, "<html>"))
|
if (c_strcasestr(sample, "<html>"))
|
||||||
ctype = stracpy("text/html");
|
ctype = stracpy("text/html");
|
||||||
|
|
||||||
mem_free(sample);
|
mem_free(sample);
|
||||||
@ -291,7 +291,7 @@ get_content_type(struct cache_entry *cached)
|
|||||||
* is with default (via option system) and mimetypes resolving
|
* is with default (via option system) and mimetypes resolving
|
||||||
* doing that option and hash lookup will not be easy to
|
* doing that option and hash lookup will not be easy to
|
||||||
* convert. --jonas */
|
* convert. --jonas */
|
||||||
convert_to_lowercase(extension, strlen(extension));
|
convert_to_lowercase_locale_indep(extension, strlen(extension));
|
||||||
|
|
||||||
ctype = get_extension_content_type(extension);
|
ctype = get_extension_content_type(extension);
|
||||||
mem_free(extension);
|
mem_free(extension);
|
||||||
|
@ -1424,13 +1424,13 @@ check_http_authentication(struct connection *conn, struct uri *uri,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_GSSAPI
|
#ifdef CONFIG_GSSAPI
|
||||||
else if (!strncasecmp(d, HTTPNEG_GSS_STR, HTTPNEG_GSS_STRLEN)) {
|
else if (!c_strncasecmp(d, HTTPNEG_GSS_STR, HTTPNEG_GSS_STRLEN)) {
|
||||||
if (http_negotiate_input(conn, uri, HTTPNEG_GSS, str)==0)
|
if (http_negotiate_input(conn, uri, HTTPNEG_GSS, str)==0)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
mem_free(d);
|
mem_free(d);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (!strncasecmp(d, HTTPNEG_NEG_STR, HTTPNEG_NEG_STRLEN)) {
|
else if (!c_strncasecmp(d, HTTPNEG_NEG_STR, HTTPNEG_NEG_STRLEN)) {
|
||||||
if (http_negotiate_input(conn, uri, HTTPNEG_NEG, str)==0)
|
if (http_negotiate_input(conn, uri, HTTPNEG_NEG, str)==0)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
mem_free(d);
|
mem_free(d);
|
||||||
@ -1874,7 +1874,7 @@ again:
|
|||||||
if (file_encoding != ENCODING_GZIP
|
if (file_encoding != ENCODING_GZIP
|
||||||
&& (!c_strcasecmp(d, "gzip") || !c_strcasecmp(d, "x-gzip")))
|
&& (!c_strcasecmp(d, "gzip") || !c_strcasecmp(d, "x-gzip")))
|
||||||
conn->content_encoding = ENCODING_GZIP;
|
conn->content_encoding = ENCODING_GZIP;
|
||||||
if (!strcasecmp(d, "deflate") || !strcasecmp(d, "x-deflate"))
|
if (!c_strcasecmp(d, "deflate") || !c_strcasecmp(d, "x-deflate"))
|
||||||
conn->content_encoding = ENCODING_DEFLATE;
|
conn->content_encoding = ENCODING_DEFLATE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1886,7 +1886,7 @@ again:
|
|||||||
|
|
||||||
#ifdef CONFIG_LZMA
|
#ifdef CONFIG_LZMA
|
||||||
if (file_encoding != ENCODING_LZMA
|
if (file_encoding != ENCODING_LZMA
|
||||||
&& (!strcasecmp(d, "lzma") || !strcasecmp(d, "x-lzma")))
|
&& (!c_strcasecmp(d, "lzma") || !c_strcasecmp(d, "x-lzma")))
|
||||||
conn->content_encoding = ENCODING_LZMA;
|
conn->content_encoding = ENCODING_LZMA;
|
||||||
#endif
|
#endif
|
||||||
mem_free(d);
|
mem_free(d);
|
||||||
|
@ -37,7 +37,7 @@ proxy_probe_no_proxy(unsigned char *url, unsigned char *no_proxy)
|
|||||||
skip_space(no_proxy);
|
skip_space(no_proxy);
|
||||||
if (jumper) *jumper = '\0';
|
if (jumper) *jumper = '\0';
|
||||||
|
|
||||||
if (strcasestr(url, no_proxy)) {
|
if (c_strcasestr(url, no_proxy)) {
|
||||||
if (jumper) *jumper = ',';
|
if (jumper) *jumper = ',';
|
||||||
if (slash) *slash = '/';
|
if (slash) *slash = '/';
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -274,7 +274,7 @@ parse_uri(struct uri *uri, unsigned char *uristring)
|
|||||||
|
|
||||||
/* A bit of a special case, but using the "normal" host
|
/* A bit of a special case, but using the "normal" host
|
||||||
* parsing seems a bit scary at this point. (see bug 107). */
|
* parsing seems a bit scary at this point. (see bug 107). */
|
||||||
if (datalen > 9 && !strncasecmp(prefix_end, "localhost/", 10)) {
|
if (datalen > 9 && !c_strncasecmp(prefix_end, "localhost/", 10)) {
|
||||||
prefix_end += 9;
|
prefix_end += 9;
|
||||||
datalen -= 9;
|
datalen -= 9;
|
||||||
}
|
}
|
||||||
@ -711,8 +711,8 @@ normalize_uri(struct uri *uri, unsigned char *uristring)
|
|||||||
* get_translated_uri() through translate_url() calls this
|
* get_translated_uri() through translate_url() calls this
|
||||||
* function and then it already works on and modifies an
|
* function and then it already works on and modifies an
|
||||||
* allocated copy. */
|
* allocated copy. */
|
||||||
convert_to_lowercase(uri->string, uri->protocollen);
|
convert_to_lowercase_locale_indep(uri->string, uri->protocollen);
|
||||||
if (uri->hostlen) convert_to_lowercase(uri->host, uri->hostlen);
|
if (uri->hostlen) convert_to_lowercase_locale_indep(uri->host, uri->hostlen);
|
||||||
|
|
||||||
parse = 1;
|
parse = 1;
|
||||||
parse_string = uri->data;
|
parse_string = uri->data;
|
||||||
|
@ -104,7 +104,7 @@ get_user_program(struct terminal *term, unsigned char *progid, int progidlen)
|
|||||||
|
|
||||||
/* Now add lowercased progid part. Delicious. */
|
/* Now add lowercased progid part. Delicious. */
|
||||||
add_bytes_to_string(&name, progid, progidlen);
|
add_bytes_to_string(&name, progid, progidlen);
|
||||||
convert_to_lowercase(&name.source[sizeof("protocol.user.") - 1], progidlen);
|
convert_to_lowercase_locale_indep(&name.source[sizeof("protocol.user.") - 1], progidlen);
|
||||||
|
|
||||||
add_char_to_string(&name, '.');
|
add_char_to_string(&name, '.');
|
||||||
add_to_string(&name, get_system_str(xwin));
|
add_to_string(&name, get_system_str(xwin));
|
||||||
|
@ -411,7 +411,7 @@ strtolx(unsigned char *str, unsigned char **end)
|
|||||||
if (errno) return 0;
|
if (errno) return 0;
|
||||||
if (!*end) return num;
|
if (!*end) return num;
|
||||||
|
|
||||||
postfix = toupper(**end);
|
postfix = c_toupper(**end);
|
||||||
if (postfix == 'K') {
|
if (postfix == 'K') {
|
||||||
(*end)++;
|
(*end)++;
|
||||||
if (num < -INT_MAX / 1024) return -INT_MAX;
|
if (num < -INT_MAX / 1024) return -INT_MAX;
|
||||||
|
@ -320,6 +320,25 @@ int c_strncasecmp (const char *s1, const char *s2, size_t n)
|
|||||||
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
|
return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* c_strcasestr - adapted from src/osdep/stub.c */
|
||||||
|
char * c_strcasestr(const char *haystack, const char *needle)
|
||||||
|
{
|
||||||
|
size_t haystack_length = strlen(haystack);
|
||||||
|
size_t needle_length = strlen(needle);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (haystack_length < needle_length)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = haystack_length - needle_length + 1; i; i--) {
|
||||||
|
if (!c_strncasecmp(haystack, needle, needle_length))
|
||||||
|
return (char *) haystack;
|
||||||
|
haystack++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* The new string utilities: */
|
/* The new string utilities: */
|
||||||
|
|
||||||
/* TODO Currently most of the functions use add_bytes_to_string() as a backend
|
/* TODO Currently most of the functions use add_bytes_to_string() as a backend
|
||||||
|
@ -111,6 +111,9 @@ int elinks_strlcasecmp(const unsigned char *s1, size_t n1,
|
|||||||
int c_strcasecmp(const char *s1, const char *s2);
|
int c_strcasecmp(const char *s1, const char *s2);
|
||||||
int c_strncasecmp(const char *s1, const char *s2, size_t n);
|
int c_strncasecmp(const char *s1, const char *s2, size_t n);
|
||||||
|
|
||||||
|
/* strcasestr function which works as if it is in the C locale. */
|
||||||
|
char * c_strcasestr(const char *haystack, const char *needle);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user