1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

Merge branch 'master' into getlementbyid

This commit is contained in:
Witold Filipczyk 2021-05-26 08:29:47 +02:00
commit d6df9584c9
5 changed files with 89 additions and 19 deletions

View File

@ -5,6 +5,7 @@
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
@ -15,6 +16,10 @@
#include <netdb.h>
#endif
#ifdef HAVE_IDNA_H
#include <idna.h>
#endif
/* We need to have it here. Stupid BSD. */
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
@ -153,17 +158,36 @@ lookup_cmd(struct option *o, char ***argv, int *argc)
{
struct sockaddr_storage *addrs = NULL;
int addrno, i;
char *idname, *idname2;
int allocated = 0;
if (!*argc) return gettext("Parameter expected");
if (*argc > 1) return gettext("Too many parameters");
(*argv)++; (*argc)--;
if (do_real_lookup(*(*argv - 1), &addrs, &addrno, 0) == DNS_ERROR) {
idname = *(*argv - 1);
#ifdef CONFIG_IDN
if (idname) {
int code = idna_to_ascii_lz(idname, &idname2, 0);
if (code == IDNA_SUCCESS) {
idname = idname2;
allocated = 1;
}
}
#endif
if (do_real_lookup(idname, &addrs, &addrno, 0) == DNS_ERROR) {
#ifdef HAVE_HERROR
herror(gettext("error"));
#else
usrerror(gettext("Host not found"));
#endif
if (allocated) {
free(idname2);
}
return "";
}
@ -192,6 +216,10 @@ lookup_cmd(struct option *o, char ***argv, int *argc)
fflush(stdout);
if (allocated) {
free(idname2);
}
return "";
}

View File

@ -10,6 +10,10 @@
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_IDNA_H
#include <idna.h>
#endif
#include <sys/types.h>
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h> /* OS/2 needs this after sys/types.h */
@ -99,13 +103,22 @@ get_ip(struct document *document)
{
#ifdef HAVE_INET_NTOP
struct uri *uri = document->uri;
char tmp;
char *host = memacpy(uri->host, uri->hostlen);
if (!uri || !uri->host || !uri->hostlen) return;
tmp = uri->host[uri->hostlen];
uri->host[uri->hostlen] = 0;
find_host(uri->host, &document->querydns, found_dns, &document->ip, 0);
uri->host[uri->hostlen] = tmp;
if (host) {
#ifdef CONFIG_IDN
char *idname;
int code = idna_to_ascii_lz(host, &idname, 0);
if (code == IDNA_SUCCESS) {
find_host(idname, &document->querydns, found_dns, &document->ip, 0);
free(idname);
}
#else
find_host(host, &document->querydns, found_dns, &document->ip, 0);
#endif
mem_free(host);
}
#endif
}

View File

@ -74,6 +74,7 @@ static union option_info ecmascript_options[] = {
static int interpreter_count;
static INIT_LIST_OF(struct string_list_item, allowed_urls);
static INIT_LIST_OF(struct string_list_item, disallowed_urls);
char *console_log_filename;
@ -100,19 +101,33 @@ read_url_list(void)
filename = straconcat(elinks_home, STRING_DIR_SEP, ALLOWED_ECMASCRIPT_URL_PREFIXES, NULL);
if (!filename) {
return;
}
if (filename) {
f = fopen(filename, "r");
f = fopen(filename, "r");
if (f) {
while (fgets(line, 4096, f)) {
add_to_string_list(&allowed_urls, line, strlen(line) - 1);
if (f) {
while (fgets(line, 4096, f)) {
add_to_string_list(&allowed_urls, line, strlen(line) - 1);
}
fclose(f);
}
fclose(f);
mem_free(filename);
}
filename = straconcat(elinks_home, STRING_DIR_SEP, DISALLOWED_ECMASCRIPT_URL_PREFIXES, NULL);
if (filename) {
f = fopen(filename, "r");
if (f) {
while (fgets(line, 4096, f)) {
add_to_string_list(&disallowed_urls, line, strlen(line) - 1);
}
fclose(f);
}
mem_free(filename);
}
mem_free(filename);
}
int
@ -127,7 +142,7 @@ get_ecmascript_enable(struct ecmascript_interpreter *interpreter)
return 0;
}
if (list_empty(allowed_urls)) {
if (list_empty(allowed_urls) && list_empty(disallowed_urls)) {
return 1;
}
@ -136,6 +151,19 @@ get_ecmascript_enable(struct ecmascript_interpreter *interpreter)
return 0;
}
foreach(item, disallowed_urls) {
struct string *string = &item->string;
if (string->length <= 0) {
continue;
}
if (!is_prefix(string->source, url, string->length)) {
mem_free(url);
move_to_top_of_list(disallowed_urls, item);
return 0;
}
}
foreach(item, allowed_urls) {
struct string *string = &item->string;
@ -150,7 +178,7 @@ get_ecmascript_enable(struct ecmascript_interpreter *interpreter)
}
mem_free(url);
return 0;
return list_empty(allowed_urls);
}

View File

@ -1323,7 +1323,7 @@ convert_string(struct conv_table *convert_table,
size_t before, to_copy;
char *outp, *inp;
if (iconv_cd >= 0) {
if (iconv_cd >= (iconv_t)0) {
if (cp != iconv_cp) {
iconv_close(iconv_cd);
iconv_cd = (iconv_t)-1;

View File

@ -25,6 +25,7 @@
#define ELINKS_TEMPNAME_PREFIX "elinks"
#define ALLOWED_ECMASCRIPT_URL_PREFIXES "allow.txt"
#define DISALLOWED_ECMASCRIPT_URL_PREFIXES "disallow.txt"
#define DNS_CACHE_TIMEOUT 3600 /* in seconds */