diff --git a/ChangeLog b/ChangeLog index e8839f0c..f5714ea8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,13 @@ highlights. The full CVS log is available at www.xchat.org/cvslog/ ------------------------------------------------------------------------------ - Emit the Topic Change event before setting the topic internally so plugins can access the old topic inside the callback. + - Add two options url_grabber and url_grabber_limit. + * url_grabber is a boolean for enabling/disabling the url grabber + * url_grabber_limit is an integer controlling the number of URLs the + URL Grabber will keep around. Setting it to 0 leaves it unlimited as in + previous versions. + - Fixed a bug with the URL Grabber where it fails to grab a URL if the URL + is the first thing in the message. - Perl (Lian Wan Situ) * Added two new options to hook_print, run_after_event and filter. See documentation for details. diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c index 8bb2a61b..83f50e37 100644 --- a/src/common/cfgfiles.c +++ b/src/common/cfgfiles.c @@ -564,6 +564,8 @@ const struct prefs vars[] = { {"text_transparent", P_OFFINT (transparent), TYPE_BOOL}, {"text_wordwrap", P_OFFINT (wordwrap), TYPE_BOOL}, + {"url_grabber", P_OFFINT (url_grabber), TYPE_BOOL}, + {"url_grabber_limit", P_OFFINT (url_grabber_limit), TYPE_INT}, {0, 0, 0}, }; @@ -680,6 +682,8 @@ load_config (void) prefs.input_flash_priv = prefs.input_flash_hilight = 1; prefs.input_tray_priv = prefs.input_tray_hilight = 1; prefs.autodccsend = 2; /* browse mode */ + prefs.url_grabber = 1; + prefs.url_grabber_limit = 0; /* 0 means unlimited for backcompat */ #ifdef WIN32 prefs.identd = 1; #endif diff --git a/src/common/proto-irc.c b/src/common/proto-irc.c index f1df6ccd..338a3b18 100644 --- a/src/common/proto-irc.c +++ b/src/common/proto-irc.c @@ -1156,6 +1156,8 @@ irc_inline (server *serv, char *buf, int len) char pdibuf_static[522]; /* 1 line can potentially be 512*6 in utf8 */ char *pdibuf = pdibuf_static; + url_check_line (buf, len); + /* need more than 522? fall back to malloc */ if (len >= sizeof (pdibuf_static)) pdibuf = malloc (len + 1); diff --git a/src/common/server.c b/src/common/server.c index 99894687..db0af9ca 100644 --- a/src/common/server.c +++ b/src/common/server.c @@ -397,7 +397,6 @@ server_inline (server *serv, char *line, int len) } fe_add_rawlog (serv, line, len, FALSE); - url_check_line (line, len); /* let proto-irc.c handle it */ serv->p_inline (serv, line, len); diff --git a/src/common/tree.c b/src/common/tree.c index 1627bd98..0a459779 100644 --- a/src/common/tree.c +++ b/src/common/tree.c @@ -150,7 +150,7 @@ tree_find (tree *t, void *key, tree_cmp_func *cmp, void *data, int *pos) return mybsearch (key, &t->array[0], t->elements, cmp, data, pos); } -static void +void tree_remove_at_pos (tree *t, int pos) { int post_bytes; @@ -191,14 +191,9 @@ tree_foreach (tree *t, tree_traverse_func *func, void *data) } } -int -tree_insert (tree *t, void *key) +static void +tree_grow (tree *t) { - int pos, done; - - if (!t) - return -1; - if (t->array_size < t->elements + 1) { int new_size = t->array_size + ARRAY_GROW; @@ -207,9 +202,33 @@ tree_insert (tree *t, void *key) t->array_size = new_size; } +} + +int +tree_insert (tree *t, void *key) +{ + int pos, done; + + if (!t) + return -1; + + tree_grow (t); pos = tree_find_insertion_pos (t, key, &done); if (!done && pos != -1) tree_insert_at_pos (t, key, pos); return pos; } + +void +tree_append (tree *t, void *key) +{ + tree_grow (t); + tree_insert_at_pos (t, key, t->elements); +} + +int tree_size (tree *t) +{ + return t->elements; +} + diff --git a/src/common/tree.h b/src/common/tree.h index b1b66aa9..96ab6cdb 100644 --- a/src/common/tree.h +++ b/src/common/tree.h @@ -10,7 +10,10 @@ tree *tree_new (tree_cmp_func *cmp, void *data); void tree_destroy (tree *t); void *tree_find (tree *t, void *key, tree_cmp_func *cmp, void *data, int *pos); int tree_remove (tree *t, void *key, int *pos); +void tree_remove_at_pos (tree *t, int pos); void tree_foreach (tree *t, tree_traverse_func *func, void *data); int tree_insert (tree *t, void *key); +void tree_append (tree* t, void *key); +int tree_size (tree *t); #endif diff --git a/src/common/url.c b/src/common/url.c index 92aeab0a..b83732d1 100644 --- a/src/common/url.c +++ b/src/common/url.c @@ -21,6 +21,7 @@ #include #include #include "xchat.h" +#include "xchatc.h" #include "cfgfiles.h" #include "fe.h" #include "tree.h" @@ -89,7 +90,13 @@ url_find (char *urltext) static void url_add (char *urltext, int len) { - char *data = malloc (len + 1); + char *data; + int size; + + if (!prefs.url_grabber) + return; + + data = malloc (len + 1); if (!data) return; memcpy (data, urltext, len); @@ -112,7 +119,18 @@ url_add (char *urltext, int len) if (!url_tree) url_tree = tree_new ((tree_cmp_func *)strcasecmp, NULL); - tree_insert (url_tree, data); + size = tree_size (url_tree); + /* 0 is unlimited */ + if (prefs.url_grabber_limit > 0 && size >= prefs.url_grabber_limit) + { + /* the loop is necessary to handle having the limit lowered while + xchat is running */ + size -= prefs.url_grabber_limit; + for(; size > 0; size--) + tree_remove_at_pos (url_tree, 0); + } + + tree_append (url_tree, data); fe_url_add (data); } @@ -259,10 +277,25 @@ url_check_line (char *buf, int len) { case 0: case ' ': + wlen = po - start; if (wlen > 2) { - if (url_check_word (start, wlen) == WORD_URL) + /* HACK! :( */ + /* This is to work around not being able to detect URLs that are at + the start of messages. */ + if (start[0] == ':') + { + start++; + wlen--; + } + if (start[0] == '+' || start[0] == '-') + { + start++; + wlen--; + } + + if (wlen > 2 && url_check_word (start, wlen) == WORD_URL) { url_add (start, wlen); } diff --git a/src/common/xchat.h b/src/common/xchat.h index 10f1067e..6e31d7c5 100644 --- a/src/common/xchat.h +++ b/src/common/xchat.h @@ -300,6 +300,8 @@ struct xchatprefs unsigned int msg_number_limit; /*same deal */ unsigned int msg_time_limit; + unsigned int url_grabber; + unsigned int url_grabber_limit; /* Tells us if we need to save, only when they've been edited. This is so that we continue using internal defaults (which can change in the next release) until the user edits them. */ diff --git a/src/fe-gtk/urlgrab.c b/src/fe-gtk/urlgrab.c index 6e5f1e0d..7f23af92 100644 --- a/src/fe-gtk/urlgrab.c +++ b/src/fe-gtk/urlgrab.c @@ -33,6 +33,7 @@ #include #include "../common/xchat.h" +#include "../common/xchatc.h" #include "../common/cfgfiles.h" #include "../common/fe.h" #include "../common/url.h" @@ -152,6 +153,7 @@ fe_url_add (const char *urltext) { GtkListStore *store; GtkTreeIter iter; + gboolean valid; if (urlgrabberwindow) { @@ -161,6 +163,15 @@ fe_url_add (const char *urltext) gtk_list_store_set (store, &iter, URL_COLUMN, urltext, -1); + + /* remove any overflow */ + if (prefs.url_grabber_limit > 0) + { + valid = gtk_tree_model_iter_nth_child ( + GTK_TREE_MODEL (store), &iter, NULL, prefs.url_grabber_limit); + while (valid) + valid = gtk_list_store_remove (store, &iter); + } } } @@ -204,5 +215,11 @@ url_opengui () gtk_widget_show (urlgrabberwindow); - tree_foreach (url_tree, (tree_traverse_func *)populate_cb, NULL); + if (prefs.url_grabber) + tree_foreach (url_tree, (tree_traverse_func *)populate_cb, NULL); + else + { + gtk_list_store_clear (GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (view)))); + fe_url_add ("URL Grabber is disabled."); + } }