changeset 225:801ac37321f6

Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 01 Dec 2010 01:12:43 +0200
parents 7ae0719f7763
children f25d47398326
files nnchat.c
diffstat 1 files changed, 27 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/nnchat.c	Wed Dec 01 01:11:24 2010 +0200
+++ b/nnchat.c	Wed Dec 01 01:12:43 2010 +0200
@@ -404,10 +404,24 @@
         errorMessages = tmp;
 }
 
+
+BOOL checkIgnoreList(const char *name)
+{
+    qlist_t *node = nnIgnoreList;
+    while (node != NULL) {
+        if (strcasecmp(name, (char *) node->data) == 0)
+            return TRUE;
+        node = node->next;
+    }
+    return FALSE;
+}
+
+
 int handleUser(nn_conn_t *conn, const char *str)
 {
     const char *msg = "</USER><MESSAGE>", *p = str;
-    char *q, *s, *t, *h, *p2;
+    BOOL isMine, isIgnored = FALSE;;
+    char *q, *s, *t, *h, *userName;
     
     (void) conn;
     
@@ -423,12 +437,15 @@
     s = nn_decode_str1(s);
     if (!s) return -1;
         
-    p2 = nn_decode_str1(p);
-    if (!p2) {
+    userName = nn_decode_str1(p);
+    if (!userName) {
         th_free(s);
         return -2;
     }
     
+    isMine = strcmp(userName, optUserName) == 0;
+    if (setIgnoreMode && !isMine)
+        isIgnored = checkIgnoreList(userName);
 
     if (*s == '/') {
         /* Ignore room join/leave messages */
@@ -438,45 +455,28 @@
         t = nn_strip_tags(s + 1);
         if (!strncmp(t, "BPRV", 4)) {
             h = nn_decode_str2(t + 1);
-            if (setTarget == NULL && !strncmp(h, "PRV from ", 9)) {
-                char *end, *name = th_strdup(h + 9);
-                if (name != NULL && (end = strchr(name, ':')) != NULL) {
-                    *end = 0;
-                    setTarget = th_strdup(name);
-                    printMsg("PRV target autoset to '%s'\n", setTarget);
-                }
-                th_free(name);
+            if (!isIgnored && setTarget == NULL && !strncmp(h, "PRV from ", 9)) {
+                setTarget = th_strdup(userName);
+                printMsg("PRV target autoset to '%s'\n", setTarget);
             }
-            printMsg("½11½%s½0½\n", h);
+            printMsgQ(isIgnored, "½11½%s½0½\n", h);
         } else {
             h = nn_decode_str2(t);
-            printMsg("½9½* %s½0½\n", h);
+            printMsgQ(isIgnored, "½9½* %s½0½\n", h);
         }
         th_free(h);
         th_free(t);
     } else {
-        BOOL isMine = strcmp(p2, optUserName) == 0;
-        BOOL logOnly = FALSE;
         t = nn_strip_tags(s);
         h = nn_decode_str2(t);
-        if (setIgnoreMode) {
-            qlist_t *node = nnIgnoreList;
-            while (node != NULL) {
-                if (strcasecmp(p2, (char *) node->data) == 0) {
-                    logOnly = TRUE;
-                    break;
-                }
-                node = node->next;
-            }
-        }
-        printMsgQ(logOnly, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p2, h);
+        printMsgQ(isIgnored, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, userName, h);
         th_free(h);
         th_free(t);
     }
 
 error:
     th_free(s);
-    th_free(p2);
+    th_free(userName);
     return 0;
 }