diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/cfgfiles.c | 4 | ||||
-rw-r--r-- | src/common/proto-irc.c | 2 | ||||
-rw-r--r-- | src/common/server.c | 1 | ||||
-rw-r--r-- | src/common/tree.c | 35 | ||||
-rw-r--r-- | src/common/tree.h | 3 | ||||
-rw-r--r-- | src/common/url.c | 39 | ||||
-rw-r--r-- | src/common/xchat.h | 2 |
7 files changed, 74 insertions, 12 deletions
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 <string.h> #include <ctype.h> #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. */ |