static void url_add (char *urltext, int len) { char *data = malloc (len + 1); if (!data) return; memcpy (data, urltext, len); data[len] = 0; if (data[len - 1] == '.') /* chop trailing dot */ { len--; data[len] = 0; } if (data[len - 1] == ')') /* chop trailing ) */ data[len - 1] = 0; if (url_find (data)) { free (data); return; } if (!url_tree) url_tree = tree_new ((tree_cmp_func *)strcasecmp, NULL); tree_insert (url_tree, data); fe_url_add (data); }
static void url_add (char *urltext, int len) { char *data; int size; if (!prefs.url_grabber) return; data = malloc (len + 1); if (!data) return; memcpy (data, urltext, len); data[len] = 0; if (data[len - 1] == '.') /* chop trailing dot */ { len--; data[len] = 0; } if (data[len - 1] == ')') /* chop trailing ) */ data[len - 1] = 0; if (url_find (data)) { free (data); return; } if (!url_tree) url_tree = tree_new ((tree_cmp_func *)g_ascii_strcasecmp, NULL); 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); }
static void url_add (char *urltext, int len) { char *data; int size; /* we don't need any URLs if we have neither URL grabbing nor URL logging enabled */ if (!prefs.hex_url_grabber && !prefs.hex_url_logging) { return; } data = malloc (len + 1); if (!data) { return; } memcpy (data, urltext, len); data[len] = 0; if (data[len - 1] == '.') /* chop trailing dot */ { len--; data[len] = 0; } /* chop trailing ) but only if there's no counterpart */ if (data[len - 1] == ')' && strchr (data, '(') == NULL) { data[len - 1] = 0; } if (prefs.hex_url_logging) { url_save_node (data); } /* the URL is saved already, only continue if we need the URL grabber too */ if (!prefs.hex_url_grabber) { free (data); return; } if (!url_tree) { url_tree = tree_new ((tree_cmp_func *)strcasecmp, NULL); url_btree = g_tree_new ((GCompareFunc)strcasecmp); } if (url_find (data)) { free (data); return; } size = tree_size (url_tree); /* 0 is unlimited */ if (prefs.hex_url_grabber_limit > 0 && size >= prefs.hex_url_grabber_limit) { /* the loop is necessary to handle having the limit lowered while HexChat is running */ size -= prefs.hex_url_grabber_limit; for(; size > 0; size--) { char *pos; pos = tree_remove_at_pos (url_tree, 0); g_tree_remove (url_btree, pos); free (pos); } } tree_append (url_tree, data); g_tree_insert (url_btree, data, GINT_TO_POINTER (tree_size (url_tree) - 1)); fe_url_add (data); }