1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-25 01:05:37 +00:00

Patch 3: Further fixes including strcasestr and convert_to_lowercase

This commit is contained in:
M. Vefa Bicakci 2008-11-01 18:18:06 +01:00 committed by Kalle Olavi Niemitalo
parent 1ba7d5a260
commit 20a7a6c460
17 changed files with 56 additions and 33 deletions

View File

@ -556,7 +556,7 @@ test_search(struct listbox_item *item, void *data_, int *offset)
assert(ctx->title && ctx->url);
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;
}

4
src/cache/dialogs.c vendored
View File

@ -175,8 +175,8 @@ match_cache_entry(struct listbox_item *item, struct terminal *term,
{
struct cache_entry *cached = item->udata;
if (strcasestr(struri(cached->uri), text)
|| (cached->head && strcasestr(cached->head, text)))
if (c_strcasestr(struri(cached->uri), text)
|| (cached->head && c_strcasestr(cached->head, text)))
return LISTBOX_MATCH_OK;
return LISTBOX_MATCH_NO;

View File

@ -18,6 +18,7 @@
#include "main/event.h"
#include "main/module.h"
#include "terminal/kbd.h"
#include "util/conv.h"
#include "util/memory.h"
#include "util/string.h"

View File

@ -337,7 +337,7 @@ search_for_url_param(unsigned char *str, unsigned char **ret)
/* Returns now if string @str is empty. */
if (!*str) return HEADER_PARAM_NOT_FOUND;
p = strcasestr(str, "url");
p = c_strcasestr(str, "url");
if (!p) return HEADER_PARAM_NOT_FOUND;
p += 3;

View File

@ -762,21 +762,21 @@ html_link_parse(struct html_context *html_context, unsigned char *a,
return 1;
}
if (strcasestr(link->name, "icon") ||
(link->content_type && strcasestr(link->content_type, "icon"))) {
if (c_strcasestr(link->name, "icon") ||
(link->content_type && c_strcasestr(link->content_type, "icon"))) {
link->type = LT_ICON;
} else if (strcasestr(link->name, "alternate")) {
} else if (c_strcasestr(link->name, "alternate")) {
link->type = LT_ALTERNATE;
if (link->lang)
link->type = LT_ALTERNATE_LANG;
else if (strcasestr(link->name, "stylesheet") ||
(link->content_type && strcasestr(link->content_type, "css")))
else if (c_strcasestr(link->name, "stylesheet") ||
(link->content_type && c_strcasestr(link->content_type, "css")))
link->type = LT_ALTERNATE_STYLESHEET;
else if (link->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;
}

View File

@ -152,7 +152,7 @@ document_get(struct SEE_interpreter *interp, struct SEE_object *o,
if (!string) return;
foreach (form, document->forms) {
if (!form->name || strcasecmp(string, form->name))
if (!form->name || c_strcasecmp(string, form->name))
continue;
form_view = find_form_view(doc_view, form);
form_object = js_get_form_object(interp, doc, form_view);

View File

@ -689,7 +689,7 @@ js_form_elems_namedItem(struct SEE_interpreter *interp, struct SEE_object *self,
return;
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);
if (fs) {
@ -815,7 +815,7 @@ js_forms_namedItem(struct SEE_interpreter *interp, struct SEE_object *self,
if (!string)
return;
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 js_form *obj = js_get_form_object(interp,
doc, fv);
@ -952,7 +952,7 @@ form_get(struct SEE_interpreter *interp, struct SEE_object *o,
struct js_input *fcobj = NULL;
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;
fs = find_form_state(doc_view, fc);
if (fs) {
@ -989,19 +989,19 @@ form_put(struct SEE_interpreter *interp, struct SEE_object *o,
mem_free_set(&form->action, string);
}
} 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_POST;
} else if (!strcasecmp(string, "multipart/form-data")) {
} else if (!c_strcasecmp(string, "multipart/form-data")) {
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;
}
mem_free(string);
} else if (p == s_method) {
if (!strcasecmp(string, "GET")) {
if (!c_strcasecmp(string, "GET")) {
form->method = FORM_METHOD_GET;
} else if (!strcasecmp(string, "POST")) {
} else if (!c_strcasecmp(string, "POST")) {
form->method = FORM_METHOD_POST;
}
mem_free(string);

View File

@ -304,7 +304,7 @@ js_window_open(struct SEE_interpreter *interp, struct SEE_object *self,
return;
}
if (frame && *frame && strcasecmp(frame, "_blank")) {
if (frame && *frame && c_strcasecmp(frame, "_blank")) {
struct delayed_open *deo = mem_calloc(1, sizeof(*deo));
if (deo) {

View File

@ -318,7 +318,7 @@ globhist_simple_search(unsigned char *search_url, unsigned char *search_title)
if ((*search_title
&& strcasestr(history_item->title, search_title))
|| (*search_url
&& strcasestr(history_item->url, search_url))) {
&& c_strcasestr(history_item->url, search_url))) {
history_item->box_item->visible = 1;
} else {
history_item->box_item->visible = 0;

View File

@ -249,7 +249,7 @@ get_fragment_content_type(struct cache_entry *cached)
if (!sample)
return NULL;
if (strcasestr(sample, "<html>"))
if (c_strcasestr(sample, "<html>"))
ctype = stracpy("text/html");
mem_free(sample);
@ -291,7 +291,7 @@ get_content_type(struct cache_entry *cached)
* is with default (via option system) and mimetypes resolving
* doing that option and hash lookup will not be easy to
* convert. --jonas */
convert_to_lowercase(extension, strlen(extension));
convert_to_lowercase_locale_indep(extension, strlen(extension));
ctype = get_extension_content_type(extension);
mem_free(extension);

View File

@ -1424,13 +1424,13 @@ check_http_authentication(struct connection *conn, struct uri *uri,
break;
}
#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)
ret = 1;
mem_free(d);
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)
ret = 1;
mem_free(d);
@ -1874,7 +1874,7 @@ again:
if (file_encoding != ENCODING_GZIP
&& (!c_strcasecmp(d, "gzip") || !c_strcasecmp(d, "x-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;
#endif
@ -1886,7 +1886,7 @@ again:
#ifdef CONFIG_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;
#endif
mem_free(d);

View File

@ -37,7 +37,7 @@ proxy_probe_no_proxy(unsigned char *url, unsigned char *no_proxy)
skip_space(no_proxy);
if (jumper) *jumper = '\0';
if (strcasestr(url, no_proxy)) {
if (c_strcasestr(url, no_proxy)) {
if (jumper) *jumper = ',';
if (slash) *slash = '/';
return 1;

View File

@ -274,7 +274,7 @@ parse_uri(struct uri *uri, unsigned char *uristring)
/* A bit of a special case, but using the "normal" host
* 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;
datalen -= 9;
}
@ -711,8 +711,8 @@ normalize_uri(struct uri *uri, unsigned char *uristring)
* get_translated_uri() through translate_url() calls this
* function and then it already works on and modifies an
* allocated copy. */
convert_to_lowercase(uri->string, uri->protocollen);
if (uri->hostlen) convert_to_lowercase(uri->host, uri->hostlen);
convert_to_lowercase_locale_indep(uri->string, uri->protocollen);
if (uri->hostlen) convert_to_lowercase_locale_indep(uri->host, uri->hostlen);
parse = 1;
parse_string = uri->data;

View File

@ -104,7 +104,7 @@ get_user_program(struct terminal *term, unsigned char *progid, int progidlen)
/* Now add lowercased progid part. Delicious. */
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_to_string(&name, get_system_str(xwin));

View File

@ -411,7 +411,7 @@ strtolx(unsigned char *str, unsigned char **end)
if (errno) return 0;
if (!*end) return num;
postfix = toupper(**end);
postfix = c_toupper(**end);
if (postfix == 'K') {
(*end)++;
if (num < -INT_MAX / 1024) return -INT_MAX;

View File

@ -320,6 +320,25 @@ int c_strncasecmp (const char *s1, const char *s2, size_t n)
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: */
/* TODO Currently most of the functions use add_bytes_to_string() as a backend

View File

@ -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_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);
/** @} */