summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorBerke Viktor <berkeviktor@aol.com>2012-03-16 00:08:01 +0100
committerBerke Viktor <berkeviktor@aol.com>2012-03-16 00:08:01 +0100
commit0452f9582eb1221bb44f9a078452a6b86c662c00 (patch)
treee60c602c36d32fc25b9f266cebc06f967064bad3 /src
parent3672db76c506f77e85e4cafdb031c37596599e31 (diff)
parent1012be5efbf01597d4edfd8071068286a77ff2dd (diff)
Merge branch 'master' into wdk
Diffstat (limited to 'src')
-rw-r--r--src/common/cfgfiles.c4
-rw-r--r--src/common/proto-irc.c2
-rw-r--r--src/common/server.c1
-rw-r--r--src/common/tree.c35
-rw-r--r--src/common/tree.h3
-rw-r--r--src/common/url.c39
-rw-r--r--src/common/xchat.h2
-rw-r--r--src/fe-gtk/urlgrab.c19
8 files changed, 92 insertions, 13 deletions
diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c
index da4adbd3..443538d2 100644
--- a/src/common/cfgfiles.c
+++ b/src/common/cfgfiles.c
@@ -600,6 +600,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},
 };
 
@@ -719,6 +721,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 91a57abe..a5ebc366 100644
--- a/src/common/proto-irc.c
+++ b/src/common/proto-irc.c
@@ -1159,6 +1159,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 657030ba..919d9119 100644
--- a/src/common/server.c
+++ b/src/common/server.c
@@ -410,7 +410,6 @@ server_inline (server *serv, char *line, int len)
 #endif
 
 	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 dbffb900..95fb1324 100644
--- a/src/common/xchat.h
+++ b/src/common/xchat.h
@@ -321,6 +321,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 <gtk/gtkcellrenderertext.h>
 
 #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.");
+	}
 }