Commit: 3af77190cf0737de521882be1d619e4dce18f5b5
Parent: 3affe30743bcafa9ff37df44a12f1bd101d98043
Author: opask
Date: Thu, 23 Aug 2018 18:49:29 -0600
remove url and image blocking code
filtering urls is the job of a packet filter and
blocking images by hash is ineffective
Diffstat:
9 files changed, 0 insertions(+), 438 deletions(-)
diff --git a/Makefile b/Makefile
@@ -5,7 +5,6 @@ include config.mk
SRC = \
auth.c\
bfu.c\
- block.c\
bookmark.c\
cache.c\
charsets.c\
diff --git a/block.c b/block.c
@@ -1,365 +0,0 @@
-#include "links.h"
-
-static struct list *block_new_item(void *ignore);
-static void block_delete_item(struct list *data);
-static void block_copy_item(struct list *in, struct list *out);
-static unsigned char *block_type_item(struct terminal *term, struct list *data, int x);
-static void block_edit_item(struct dialog_data *dlg, struct list *data, void (*ok_fn)(struct dialog_data *, struct list *, struct list *, struct list_description *), struct list *ok_arg, unsigned char dlg_title);
-static struct list *block_find_item(struct list *start, unsigned char *str, int direction);
-
-static struct history block_search_histroy = { 0, {&block_search_histroy.items, &block_search_histroy.items} };
-
-struct list blocks = { init_list_1st(&blocks.list_entry) 0, -1, NULL, init_list_last(&blocks.list_entry) };
-
-static struct list_description blocks_ld = {
- 0, /* flat */
- &blocks, /* list head */
- block_new_item,
- block_edit_item,
- NULL,
- block_delete_item,
- block_copy_item,
- block_type_item,
- block_find_item,
- &block_search_histroy,
- 0, /* this is set in init_assoc function */
- 15, /* # of items in main window */
- T_BLOCKED_IMAGE, /* item title */
- T_BLOCK_LIST_IN_USE, /* Already open message */
- T_BLOCK_LIST_MANAGER, /* Window title */
- T_BLOCK_DELETE,
- 0, /* no button */
- NULL, /* no button */
- NULL, /* no save */
-
- NULL, NULL, 0, 0, /* internal vars */
- 0, /* modified */
- NULL,
- NULL,
- 0,
-};
-
-
-static struct list *block_new_item(void *ignore)
-{
- /*Default constructor*/
- struct block *neww;
-
- neww = xmalloc(sizeof(struct block));
- neww->url = stracpy(cast_uchar "");
- return &neww->head;
-}
-
-static void block_delete_item(struct list *data)
-{
- /*Destructor */
- struct block *del = get_struct(data, struct block, head);
- if (del->head.list_entry.next) del_from_list(&del->head);
- free(del->url);
- free(del);
-}
-
-static void block_copy_item(struct list *in, struct list *out)
-{
- /*Copy construction */
- struct block *item_in = get_struct(in, struct block, head);
- struct block *item_out = get_struct(out, struct block, head);
-
- free(item_out->url);
- item_out->url = stracpy(item_in->url);
-}
-
-/*This is used to display the items in the menu*/
-static unsigned char *block_type_item(struct terminal *term, struct list *data, int x)
-{
- unsigned char *txt, *txt1;
- struct block *item;
-
- if (data == &blocks) return stracpy(get_text_translation(TEXT_(T_BLOCK_LIST), term));
-
- item = get_struct(data, struct block, head);
- txt = stracpy(item->url);
-
- /*I have no idea what this does, but it os copied from working code in types.c*/
- txt1 = convert(blocks_ld.codepage, term_charset(term), txt, NULL);
- free(txt);
-
- return txt1;
-}
-
-struct assoc_ok_struct {
- void (*fn)(struct dialog_data *, struct list *, struct list *, struct list_description *);
- struct list *data;
- struct dialog_data *dlg;
-};
-
-/* destroys an item, this function is called when edit window is aborted */
-static void block_edit_abort(struct dialog_data *data)
-{
- struct block *item = (struct block *)data->dlg->udata;
- struct dialog *dlg = data->dlg;
-
- free(dlg->udata2);
- if (item)
- block_delete_item(&item->head);
-}
-
-/* Puts url into the block list */
-static void block_edit_done(void *data)
-{
- /*Copied from types.c*/
- struct dialog *d = (struct dialog *)data;
- struct block *item = (struct block *)d->udata;
- struct assoc_ok_struct *s = (struct assoc_ok_struct *)d->udata2;
- unsigned char *txt;
- unsigned char *url;
-
- /*See block_edit_item*/
- url = (unsigned char *)&d->items[4];
-
- txt = convert(term_charset(s->dlg->win->term), blocks_ld.codepage, url, NULL);
- free(item->url);
- item->url = txt;
-
- s->fn(s->dlg, s->data, &item->head, &blocks_ld);
- d->udata = NULL; /* for abort function */
-}
-
-static void block_edit_item_fn(struct dialog_data *dlg)
-{
- /*Copied from input_field. I don't know how most of it works.*/
-#define LL gf_val(1, G_BFU_FONT_SIZE)
- struct terminal *term = dlg->win->term;
- int max = 0, min = 0;
- int w, rw;
- int y = gf_val(-1, -G_BFU_FONT_SIZE);
- unsigned char *text = TEXT_(T_ENTER_URL);
-
-
- max_text_width(term, text, &max, AL_LEFT);
- min_text_width(term, text, &min, AL_LEFT);
- max_buttons_width(term, dlg->items + 1, 2, &max);
- min_buttons_width(term, dlg->items + 1, 2, &min);
- if (max < dlg->dlg->items->dlen)
- max = dlg->dlg->items->dlen;
- w = term->x * 9 / 10 - 2 * DIALOG_LB;
- if (w > max)
- w = max;
- if (w < min)
- w = min;
- rw = w;
- dlg_format_text_and_field(dlg, NULL, text, dlg->items, 0, &y, w, &rw, COLOR_DIALOG_TEXT, AL_LEFT);
- y += LL;
- dlg_format_buttons(dlg, NULL, dlg->items + 1, 2, 0, &y, w, &rw, AL_CENTER);
- w = rw;
- dlg->xw = rw + 2 * DIALOG_LB;
- dlg->yw = y + 2 * DIALOG_TB;
- center_dlg(dlg);
- draw_dlg(dlg);
- y = dlg->y + DIALOG_TB;
- dlg_format_text_and_field(dlg, term, text, dlg->items, dlg->x + DIALOG_LB, &y, w, NULL, COLOR_DIALOG_TEXT, AL_LEFT);
- y += LL;
- dlg_format_buttons(dlg, term, dlg->items + 1, 2, dlg->x + DIALOG_LB, &y, w, NULL, AL_CENTER);
-}
-
-static void block_edit_item(struct dialog_data *dlg, struct list *data, void (*ok_fn)(struct dialog_data *, struct list *, struct list *, struct list_description *), struct list *ok_arg, unsigned char dlg_title)
-{
- /*Copied from types.c */
- /*Data is a new item generated by the "default" function*/
- struct block *neww = get_struct(data, struct block, head);
-
- struct terminal *term = dlg->win->term;
- struct dialog *d;
- struct assoc_ok_struct *s;
- unsigned char *url, *txt;
-
- /*Allocate space for dialog, 4 items followed by 1 string*/
- d = xmalloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item)
- + 1 * MAX_STR_LEN);
- memset(d, 0, sizeof(struct dialog) + 4 * sizeof(struct dialog_item)
- + 1 * MAX_STR_LEN);
-
- /*Set up this string */
- url = (unsigned char *)&d->items[4];
- txt = convert(blocks_ld.codepage, term_charset(dlg->win->term), neww->url, NULL);
- safe_strncpy(url, txt, MAX_STR_LEN);
- free(txt);
-
- /* Create the dialog */
- s = xmalloc(sizeof(struct assoc_ok_struct));
-
- s->fn = ok_fn;
- s->data = ok_arg;
- s->dlg = dlg;
-
- switch (dlg_title) {
- case TITLE_EDIT:
- d->title = TEXT_(T_BLOCK_EDIT);
- break;
-
- case TITLE_ADD:
- d->title = TEXT_(T_BLOCK_ADD);
- break;
-
- default:
- internal("Unsupported dialog title.\n");
- }
-
- d->udata = neww;
- d->udata2 = s;
- d->fn = block_edit_item_fn;
- d->abort = block_edit_abort;
- d->refresh = block_edit_done;
- d->refresh_data = d;
- d->items[0].type = D_FIELD;
- d->items[0].dlen = MAX_STR_LEN;
- d->items[0].data = url;
- d->items[0].fn = check_nonempty;
- d->items[1].type = D_BUTTON;
- d->items[1].gid = B_ENTER;
- d->items[1].fn = ok_dialog;
- d->items[1].text = TEXT_(T_OK);
- d->items[2].type = D_BUTTON;
- d->items[2].gid = B_ESC;
- d->items[2].text = TEXT_(T_CANCEL);
- d->items[2].fn = cancel_dialog;
- d->items[3].type = D_END;
- do_dialog(term, d, getml(d, NULL));
-}
-
-static int test_entry(struct list *e, unsigned char *str)
-{
- return casestrstr(get_struct(e, struct block, head)->url, str);
-}
-
-static struct list *block_find_item(struct list *s, unsigned char *str, int direction)
-{
- struct list *e;
-
- if (direction >= 0) {
- for (e = list_next(s); e != s; e = list_next(e)) {
- if (e->depth >= 0 && test_entry(e, str))
- return e;
- }
- } else {
- for (e = list_prev(s); e != s; e = list_prev(e)) {
- if (e->depth >= 0 && test_entry(e, str))
- return e;
- }
- }
-
- if (e->depth >= 0 && test_entry(e, str))
- return e;
-
- return NULL;
-}
-
-
-void block_manager(struct terminal *term, void *fcp, void *ses_)
-{
- struct session *ses = (struct session *)ses_;
- create_list_window(&blocks_ld, &blocks, term, ses);
-}
-
-
-void *block_url_add(void *ses_, unsigned char *url)
-{
- struct session *ses = (struct session *)ses_;
- /*Callback from the dialog box created from the link menu*/
- struct list *new_list;
- struct block *new_b;
- struct terminal *term = ses ? ses->term : NULL;
-
- if (test_list_window_in_use(&blocks_ld, term))
- return NULL;
-
- new_list = block_new_item(0);
- new_b = get_struct(new_list, struct block, head);
-
- free(new_b->url);
- new_b->url = stracpy(url);
- new_b->head.type = 0;
-
- add_to_list(blocks.list_entry, &new_b->head);
- return NULL;
-}
-
-void block_url_query(struct session *ses, unsigned char *u)
-{
- if (test_list_window_in_use(&blocks_ld, ses->term))
- return;
-
- input_field(ses->term, NULL, TEXT_(T_BLOCK_URL), TEXT_(T_BLOCK_ADD), ses, 0, MAX_INPUT_URL_LEN, u, 0, 0, NULL, 2, TEXT_(T_OK), block_url_add, TEXT_(T_CANCEL), input_field_null);
-
-}
-
-static unsigned char *find_first_match(unsigned char *s, unsigned char *p, unsigned *ii)
-{
- unsigned i;
- retry:
- for (i = 0; s[i] && p[i] && p[i] != '*'; i++) {
- if (s[i] != p[i] && p[i] != '?') {
- s++;
- goto retry;
- }
- }
- *ii = i;
- if (!p[i] || p[i] == '*')
- return s;
- return NULL;
-}
-
-static int simple_glob_match(unsigned char *s, unsigned char *p)
-{
- unsigned i;
- if (find_first_match(s, p, &i) != s)
- return 0;
- if (!p[i])
- return !s[i];
- while (1) {
- s += i;
- p += i + 1;
- if (!(s = find_first_match(s, p, &i)))
- return 0;
- if (!p[i]) {
- s += strlen(cast_const_char s) - i;
- return !!find_first_match(s, p, &i);
- }
- }
-}
-
-
-int is_url_blocked(unsigned char *url)
-{
- struct list *b;
- struct list_head *lb;
-
- foreach(struct list, b, lb, blocks.list_entry) {
- if (simple_glob_match(url, get_struct(b, struct block, head)->url))
- return 1;
- }
-
- return 0;
-}
-
-void init_blocks(void)
-{
- blocks_ld.codepage = 0;
-}
-
-void free_blocks(void)
-{
- /*List destructor */
- struct list *b;
- struct list_head *lb;
-
- foreach(struct list, b, lb, blocks.list_entry) {
- struct block *bm = get_struct(b, struct block, head);
- free(bm->url);
- lb = lb->prev;
- del_from_list(b);
- free(bm);
- }
-
- free_history(block_search_histroy);
-}
diff --git a/default.c b/default.c
@@ -597,32 +597,6 @@ static unsigned char *type_rd(struct option *o, unsigned char *c)
goto err;
}
-static unsigned char *block_rd(struct option *o, unsigned char *c)
-{
- unsigned char *err = cast_uchar "Error reading image block specification";
- unsigned char* url;
-
- if (!(url = get_token(&c)))
- return err;
-
- block_url_add(NULL, url);
-
- free(url);
-
- return NULL;
-}
-
-static void block_wr(struct option *o, unsigned char **s, int *l)
-{
- struct list *a;
- struct list_head *la;
- foreachback(struct list, a, la, blocks.list_entry) {
- struct block *b = get_struct(a, struct block, head);
- add_nm(o, s, l);
- add_quoted_to_str(s, l, b->url);
- }
-}
-
static void type_wr(struct option *o, unsigned char **s, int *l)
{
struct list *a;
@@ -1627,7 +1601,6 @@ static struct option links_options[] = {
{1, NULL, term2_rd, NULL, 0, 0, NULL, "terminal2", NULL},
{1, NULL, type_rd, type_wr, 0, 0, NULL, "association", NULL},
{1, NULL, ext_rd, ext_wr, 0, 0, NULL, "extension", NULL},
- {1, NULL, block_rd, block_wr, 0, 0, NULL, "imageblock", NULL},
{1, NULL, dp_rd, dp_wr, 0, 0, NULL, "video_driver", NULL},
{0, NULL, NULL, NULL, 0, 0, NULL, NULL, NULL},
};
diff --git a/links.h b/links.h
@@ -692,7 +692,6 @@ extern struct list_head keepalive_connections;
#define S_STATE (-2000000014)
#define S_CYCLIC_REDIRECT (-2000000015)
#define S_LARGE_FILE (-2000000016)
-#define S_BLOCKED_URL (-2000000017)
#define S_SMB_NOT_ALLOWED (-2000000018)
#define S_FILE_NOT_ALLOWED (-2000000019)
#define S_NO_PROXY (-2000000020)
@@ -3734,23 +3733,6 @@ void create_initial_extensions(void);
void free_types(void);
-/* block.c */
-
-/* URL blocking calls */
-struct block {
- list_head_1st
- unsigned char *url;
- list_head_last
-};
-
-extern struct list blocks;
-int is_url_blocked(unsigned char* url);
-void block_url_query(struct session *ses, unsigned char *u);
-void* block_url_add(void *ses_, unsigned char *url);
-void block_manager(struct terminal *term, void *fcp, void *ses_);
-void init_blocks(void);
-void free_blocks(void);
-
/* bookmark.c */
/* Where all bookmarks are kept */
diff --git a/main.c b/main.c
@@ -427,7 +427,6 @@ static void initialize_all_subsystems(void)
init_dns();
init_session_cache();
init_cache();
- init_blocks();
memset(&dd_opt, 0, sizeof dd_opt);
}
@@ -462,7 +461,6 @@ static void terminate_all_subsystems(void)
free_history_lists();
free_term_specs();
free_types();
- free_blocks();
finalize_bookmarks();
free_conv_table();
free_blacklist();
diff --git a/menu.c b/menu.c
@@ -2832,7 +2832,6 @@ static const struct menu_item setup_menu_7[] = {
{ TEXT_(T_MAIL_AND_TELNEL), cast_uchar "", TEXT_(T_HK_MAIL_AND_TELNEL), net_programs, NULL, 0, 1 },
{ TEXT_(T_ASSOCIATIONS), cast_uchar "", TEXT_(T_HK_ASSOCIATIONS), menu_assoc_manager, NULL, 0, 1 },
{ TEXT_(T_FILE_EXTENSIONS), cast_uchar "", TEXT_(T_HK_FILE_EXTENSIONS), menu_ext_manager, NULL, 0, 1 },
- { TEXT_(T_BLOCK_LIST), cast_uchar "", TEXT_(T_HK_BLOCK_LIST), block_manager, NULL, 0, 0 },
{ cast_uchar "", cast_uchar "", M_BAR, NULL, NULL, 0, 1 },
{ TEXT_(T_SAVE_OPTIONS), cast_uchar "", TEXT_(T_HK_SAVE_OPTIONS), menu_write_config, NULL, 0, 1 },
};
diff --git a/sched.c b/sched.c
@@ -724,14 +724,6 @@ void load_url(unsigned char *url, unsigned char *prev_url, struct status *stat,
stat->prev_error = 0;
stat->pri = pri;
}
- if (is_url_blocked(url)) {
- if (stat) {
- stat->state = S_BLOCKED_URL;
- if (stat->end)
- stat->end(stat, stat->data);
- }
- goto ret;
- }
if (err) {
if (stat) {
stat->state = err;
diff --git a/session.c b/session.c
@@ -90,7 +90,6 @@ static const struct s_msg_dsc msg_dsc[] = {
{S_NO_SMB_CLIENT, TEXT_(T_NO_SMB_CLIENT)},
- {S_BLOCKED_URL, TEXT_(T_BLOCKED_URL)},
{S_NO_PROXY, TEXT_(T_NO_PROXY)},
{S_SMB_NOT_ALLOWED, TEXT_(T_SMB_NOT_ALLOWED)},
{S_FILE_NOT_ALLOWED, TEXT_(T_FILE_NOT_ALLOWED)},
diff --git a/view.c b/view.c
@@ -2983,18 +2983,6 @@ static void send_download_image(struct terminal *term, void *xxx, void *ses_)
}
}
-#ifdef G
-static void send_block_image(struct terminal *term, void *xxx, void *ses_)
-{
- struct session *ses = (struct session *)ses_;
- struct f_data_c *fd = current_frame(ses);
- struct link *link = get_current_link(fd);
- if (!link) return;
- if (!link->where_img) return;
- block_url_query(ses, link->where_img);
-}
-#endif
-
static void send_download(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = (struct session *)ses_;
@@ -3312,9 +3300,6 @@ void link_menu(struct terminal *term, void *xxx, void *ses_)
else add_to_menu(&mi, TEXT_(T_SCALE_IMAGE_TO_FULL_SCREEN), cast_uchar "Enter", TEXT_(T_HK_SCALE_IMAGE_TO_FULL_SCREEN), send_scale, NULL, 0, -1);
#endif
if (!anonymous) add_to_menu(&mi, TEXT_(T_DOWNLOAD_IMAGE), cast_uchar "I", TEXT_(T_HK_DOWNLOAD_IMAGE), send_download_image, NULL, 0, -1);
-#ifdef G
- if (F && !anonymous) add_to_menu(&mi, TEXT_(T_BLOCK_URL), cast_uchar "", TEXT_(T_HK_BLOCK_URL), send_block_image, NULL, 0, -1);
-#endif
}
no_l:
if (!mi->text) add_to_menu(&mi, TEXT_(T_NO_LINK_SELECTED), cast_uchar "", M_BAR, NULL, NULL, 0, -1);