Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / fe-common / core / fe-ignore.c
index 3523d527d6db7c98b3d3748212c4ff30d46d2b22..d2f48f20d0e520e6dcc931bd58f2246cd02dec16 100644 (file)
@@ -53,16 +53,33 @@ static void ignore_print(int index, IGNORE_REC *rec)
        levels = bits2level(rec->level);
 
        options = g_string_new(NULL);
-       if (rec->exception) g_string_sprintfa(options, "-except ");
-       if (rec->regexp) g_string_sprintfa(options, "-regexp ");
-       if (rec->fullword) g_string_sprintfa(options, "-full ");
-       if (rec->replies) g_string_sprintfa(options, "-replies ");
+       if (rec->exception) g_string_append(options, "-except ");
+       if (rec->regexp) {
+               g_string_append(options, "-regexp ");
+#ifdef HAVE_REGEX_H
+               if (!rec->regexp_compiled)
+                       g_string_append(options, "[INVALID!] ");
+#endif
+       }
+       if (rec->fullword) g_string_append(options, "-full ");
+       if (rec->replies) g_string_append(options, "-replies ");
+       if (rec->servertag != NULL) 
+               g_string_sprintfa(options, "-network %s ", rec->servertag);
+       if (rec->pattern != NULL)
+               g_string_sprintfa(options, "-pattern %s ", rec->pattern);
+
        if (options->len > 1) g_string_truncate(options, options->len-1);
 
-       printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
-                   TXT_IGNORE_LINE, index,
-                   key != NULL ? key : "",
-                   levels != NULL ? levels : "", options->str);
+       if (index >= 0) {
+               printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
+                           TXT_IGNORE_LINE, index, key != NULL ? key : "",
+                           levels != NULL ? levels : "", options->str);
+       } else {
+               printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
+                           options->len > 0 ? TXT_IGNORED_OPTIONS : TXT_IGNORED,
+                           key != NULL ? key : "",
+                           levels != NULL ? levels : "", options->str);
+       }
        g_string_free(options, TRUE);
         g_free(key);
        g_free(levels);
@@ -73,6 +90,12 @@ static void cmd_ignore_show(void)
        GSList *tmp;
        int index;
 
+       if (ignores == NULL) {
+               printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
+                           TXT_IGNORE_NO_IGNORES);
+                return;
+       }
+
        printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_IGNORE_HEADER);
        index = 1;
        for (tmp = ignores; tmp != NULL; tmp = tmp->next, index++) {
@@ -84,17 +107,18 @@ static void cmd_ignore_show(void)
 }
 
 /* SYNTAX: IGNORE [-regexp | -full] [-pattern <pattern>] [-except] [-replies]
-                  [-channels <channel>] [-time <secs>] <mask> [<levels>]
+                  [-network <network>] [-channels <channel>] [-time <secs>] <mask> [<levels>]
            IGNORE [-regexp | -full] [-pattern <pattern>] [-except] [-replies]
-                 [-time <secs>] <channels> [<levels>] */
+                 [-network <network>] [-time <secs>] <channels> [<levels>] */
+/* NOTE: -network replaces the old -ircnet flag. */
 static void cmd_ignore(const char *data)
 {
        GHashTable *optlist;
        IGNORE_REC *rec;
-       char *patternarg, *chanarg, *mask, *levels, *timestr;
+       char *patternarg, *chanarg, *mask, *levels, *timestr, *servertag;
        char **channels;
        void *free_arg;
-       int new_ignore;
+       int new_ignore, msecs;
 
        if (*data == '\0') {
                cmd_ignore_show();
@@ -107,19 +131,30 @@ static void cmd_ignore(const char *data)
 
        patternarg = g_hash_table_lookup(optlist, "pattern");
         chanarg = g_hash_table_lookup(optlist, "channels");
-
+       servertag = g_hash_table_lookup(optlist, "network");
+       /* Allow -ircnet for backwards compatibility */
+       if (!servertag)
+               servertag = g_hash_table_lookup(optlist, "ircnet");
+       
        if (*mask == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
         if (*levels == '\0') levels = "ALL";
 
+       msecs = 0;
+       timestr = g_hash_table_lookup(optlist, "time");
+       if (timestr != NULL) {
+               if (!parse_time_interval(timestr, &msecs))
+                       cmd_param_error(CMDERR_INVALID_TIME);
+       }
+
        if (active_win->active_server != NULL &&
-           active_win->active_server->ischannel(mask)) {
+           server_ischannel(active_win->active_server, mask)) {
                chanarg = mask;
                mask = NULL;
        }
        channels = (chanarg == NULL || *chanarg == '\0') ? NULL :
                g_strsplit(replace_chars(chanarg, ',', ' '), " ", -1);
 
-       rec = ignore_find(NULL, mask, channels);
+       rec = patternarg != NULL ? NULL: ignore_find(NULL, mask, channels);
        new_ignore = rec == NULL;
 
        if (rec == NULL) {
@@ -134,20 +169,27 @@ static void cmd_ignore(const char *data)
        }
 
        rec->level = combine_level(rec->level, levels);
+
+       if (new_ignore && rec->level == 0) {
+               /* tried to unignore levels from nonexisting ignore */
+               printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
+                           TXT_IGNORE_NOT_FOUND, rec->mask);
+               g_free(rec->mask);
+               g_strfreev(rec->channels);
+               g_free(rec);
+               cmd_params_free(free_arg);
+                return;
+       }
+       rec->servertag = (servertag == NULL || *servertag == '\0') ?
+               NULL : g_strdup(servertag);
        rec->pattern = (patternarg == NULL || *patternarg == '\0') ?
                NULL : g_strdup(patternarg);
        rec->exception = g_hash_table_lookup(optlist, "except") != NULL;
        rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;
        rec->fullword = g_hash_table_lookup(optlist, "full") != NULL;
        rec->replies = g_hash_table_lookup(optlist, "replies") != NULL;
-       timestr = g_hash_table_lookup(optlist, "time");
-        if (timestr != NULL)
-               rec->unignore_time = time(NULL)+atoi(timestr);
-
-       if (rec->level == 0) {
-               printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_UNIGNORED,
-                           rec->mask == NULL ? "*" : rec->mask);
-       }
+       if (msecs != 0)
+               rec->unignore_time = time(NULL)+msecs/1000;
 
        if (new_ignore)
                ignore_add_rec(rec);
@@ -162,24 +204,29 @@ static void cmd_unignore(const char *data)
 {
        IGNORE_REC *rec;
        GSList *tmp;
+        char *mask;
+       void *free_arg;
+
+       if (!cmd_get_params(data, &free_arg, 1, &mask))
+               return;
 
-       if (*data == '\0')
-                cmd_return_error(CMDERR_NOT_ENOUGH_PARAMS);
+       if (*mask == '\0')
+                cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
 
-       if (is_numeric(data, ' ')) {
+       if (is_numeric(mask, ' ')) {
                /* with index number */
-               tmp = g_slist_nth(ignores, atoi(data)-1);
+               tmp = g_slist_nth(ignores, atoi(mask)-1);
                rec = tmp == NULL ? NULL : tmp->data;
        } else {
                /* with mask */
                const char *chans[2] = { "*", NULL };
 
                if (active_win->active_server != NULL &&
-                   active_win->active_server->ischannel(data)) {
-                       chans[0] = data;
-                       data = NULL;
+                   server_ischannel(active_win->active_server, mask)) {
+                       chans[0] = mask;
+                       mask = NULL;
                }
-               rec = ignore_find("*", data, (char **) chans);
+               rec = ignore_find("*", mask, (char **) chans);
        }
 
        if (rec != NULL) {
@@ -187,20 +234,14 @@ static void cmd_unignore(const char *data)
                ignore_update_rec(rec);
        } else {
                printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
-                           TXT_IGNORE_NOT_FOUND, data);
+                           TXT_IGNORE_NOT_FOUND, mask);
        }
+       cmd_params_free(free_arg);
 }
 
 static void sig_ignore_created(IGNORE_REC *rec)
 {
-       char *key, *levels;
-
-       key = ignore_get_key(rec);
-        levels = bits2level(rec->level);
-       printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
-                   TXT_IGNORED, key, levels);
-       g_free(key);
-       g_free(levels);
+        ignore_print(-1, rec);
 }
 
 static void sig_ignore_destroyed(IGNORE_REC *rec)
@@ -221,7 +262,7 @@ void fe_ignore_init(void)
        signal_add("ignore created", (SIGNAL_FUNC) sig_ignore_created);
        signal_add("ignore changed", (SIGNAL_FUNC) sig_ignore_created);
 
-       command_set_options("ignore", "regexp full except replies -time -pattern -channels");
+       command_set_options("ignore", "regexp full except replies -network -ircnet -time -pattern -channels");
 }
 
 void fe_ignore_deinit(void)