Check the invite/ban string whether we already have it before
authorPekka Riikonen <priikone@silcnet.org>
Thu, 9 Oct 2003 19:41:09 +0000 (19:41 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 9 Oct 2003 19:41:09 +0000 (19:41 +0000)
processing it.

CHANGES
TODO
apps/silcd/server_util.c

diff --git a/CHANGES b/CHANGES
index e70cca5a6c4b11009c7fcb3bf9f128928b6a267e..ab922b39a50f9667a39a2151be39251eeb04aa5c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+Thu Oct  9 20:24:09 EEST 2003  Pekka Riikonen <priikone@silcnet.org>
+
+       * Check that a string is not already part on invite/ban
+         string when processing it.  Affected file silcd/server_util.c.
+
 Thu Oct  9 12:06:40 CEST 2003  Pekka Riikonen <priikone@silcnet.org>
 
        * Fixed the CUMODE_CHANGE for founder mode changes to comply
diff --git a/TODO b/TODO
index ff8a28cb4eab148f09fc38a5718ec66d7a80dce3..7c7fa70902d4a1d2679edc1a7127b4654895467f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -14,14 +14,16 @@ TODO for SILC Server 1.0
    - test all resume error cases for backup router
    - test all resume error cases for normal server
    - test all resume error cases for primary router
-   - test communication
 
-   NOTIFYS (works)
-   
+   - Notifys (works)
    JOIN, TOPIC_SET, CMODE_CHANGE, CUMODE_CHANGE, CHANNEL_CHANGE,
    UMODE_CHANGE, INVITE, BAN (rest of the notifys does not apply, no 
    testing required)
 
+   - Communication
+    - Test communication during switching, after switching, during
+      resuming and after resuming.
+
  o Testing
 
 
index fd79ade6c64b95ba98f435a34e0e2b5396e80192..8e54086701f91b59b2dccd78b431f088f0e5c6b9 100644 (file)
@@ -1836,11 +1836,57 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
          tmp2 = silc_calloc(1, sizeof(*tmp2));
          silc_hash_table_add(list, (void *)1, tmp2);
        }
-       if (tmp[len - 1] == ',')
-         tmp[len - 1] = '\0';
-       if (len) {
-         silc_buffer_strformat(tmp2, tmp, SILC_STR_END);
-         silc_buffer_strformat(tmp2, ",", SILC_STR_END);
+
+       /* Check that the string is not part of invite string already */
+       if (action == 0x00) {
+         if (silc_string_match(tmp2->data, tmp))
+           break;
+
+         if (len) {
+           if (tmp[len - 1] == ',')
+             tmp[len - 1] = '\0';
+           silc_buffer_strformat(tmp2, tmp, SILC_STR_END);
+           silc_buffer_strformat(tmp2, ",", SILC_STR_END);
+         }
+       } else {
+         /* Announced list.  Check each entry in the list */
+         unsigned char e[256];
+         char *start, *end, *n, *rtmp;
+         int i, k;
+
+         rtmp = silc_memdup(tmp, len);
+         for (i = 0, k = 0; i < len; i++) {
+           if (tmp[i] != ',')
+             continue;
+
+           memset(e, 0, sizeof(e));
+           silc_strncat(e, sizeof(e), tmp + k, i - k);
+           if (!silc_string_match(tmp2->data, e)) {
+             k = i + 1;
+             continue;
+           }
+
+           /* Matches.  Delete it since we have it already */
+           start = strstr(rtmp, e);
+           if (start && strlen(start) >= (i - k)) {
+             end = start + (i - k);
+             n = silc_calloc(strlen(rtmp) - (i - k), sizeof(*n));
+             strncat(n, rtmp, start - rtmp);
+             if (strlen(end) > 1)
+               strncat(n, end + 1, ((rtmp + strlen(rtmp)) - end) - 1);
+             silc_free(rtmp);
+             rtmp = n;
+           }
+
+           k = i + 1;
+         }
+
+         /* Save the part that we didn't already have. */
+         if (strlen(rtmp) > 1) {
+           silc_buffer_strformat(tmp2, rtmp, SILC_STR_END);
+           silc_buffer_strformat(tmp2, ",", SILC_STR_END);
+         }
+         silc_free(rtmp);
        }
 
       } else if (type == 2) {
@@ -1911,7 +1957,8 @@ void silc_server_inviteban_process(SilcServer server, SilcHashTable list,
              end = start + len;
              n = silc_calloc(strlen(string) - len, sizeof(*n));
              strncat(n, string, start - string);
-             strncat(n, end + 1, ((string + strlen(string)) - end) - 1);
+             if (strlen(end) > 1)
+               strncat(n, end + 1, ((string + strlen(string)) - end) - 1);
              silc_free(tmp2->head);
              silc_buffer_set(tmp2, n, strlen(n));
            }