rewrote IRC cache parser to be (hopefully) more stable
[NeonServV5.git] / src / tools.c
index bd1715e951124f9eb70fc2affceb913df2ea8121..093ed80b03618803c579b327e829e9767d32ecce 100644 (file)
@@ -1,5 +1,5 @@
-/* tools.c - NeonServ v5.3
- * Copyright (C) 2011  Philipp Kreil (pk910)
+/* tools.c - NeonServ v5.4
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 #include "ChanNode.h"
 #include "lang.h"
 #include "ClientSocket.h"
+#include "IPNode.h"
 
 static const struct default_language_entry msgtab[] = {
     {"TIME_MASK_2_ITEMS", "%s and %s"}, /* {ARGS: "2 days", "1 hour"} */
@@ -211,7 +212,8 @@ char **table_end(struct Table *table) {
                         }
                     }
                 }
-            }
+            } else if(table->col_flags[col] & TABLE_FLAG_COL_SKIP_NULL)
+                continue;
             i -= j;
             if(col < table->width-1) {
                 for(;i < table->maxwidth[col]; i++) {
@@ -415,6 +417,8 @@ void flushModeBuffer(struct ModeBuffer *modeBuf) {
             modeStr[modePos++] = modeBuf->addModes[i];
             if(modeBuf->addModesParams[i]) {
                 paramPos += sprintf(paramStr + paramPos, " %s", modeBuf->addModesParams[i]);
+                free(modeBuf->addModesParams[i]);
+                modeBuf->addModesParams[i] = NULL;
             }
         }
         modeBuf->addCount = 0;
@@ -425,6 +429,8 @@ void flushModeBuffer(struct ModeBuffer *modeBuf) {
             modeStr[modePos++] = modeBuf->delModes[i];
             if(modeBuf->delModesParams[i]) {
                 paramPos += sprintf(paramStr + paramPos, " %s", modeBuf->delModesParams[i]);
+                free(modeBuf->delModesParams[i]);
+                modeBuf->delModesParams[i] = NULL;
             }
         }
         modeBuf->delCount = 0;
@@ -487,7 +493,7 @@ char* make_banmask(char *input, char* buffer) {
         ident = input;
         *p = '\0';
         host = p+1;
-    } else if((p = strstr(input, "."))) {
+    } else if((p = strstr(input, ".")) || (p = strstr(input, ":"))) {
         host = input;
     } else if(*input == '*' && input[1] != '\0' && !strstr(input+1, "*")) {
         //AUTH MASK
@@ -516,7 +522,7 @@ int isFakeHost(char *host) {
     char *p1, *p2 = host;
     
     //find the last dot to identify if the hostmask is a fake host
-    while((p1 = strstr(p2, "."))) {
+    while((p1 = strchr(p2, '.'))) {
         p2 = p1 + 1;
     }
     //TLD database: http://www.iana.org/domains/root/db/
@@ -525,6 +531,26 @@ int isFakeHost(char *host) {
     return (strlen(p2+1) > 4);
 }
 
+int mask_match(char *mask, struct UserNode *user) {
+    char usermask[NICKLEN+USERLEN+HOSTLEN+3];
+    char matchmask[strlen(mask)+3];
+    strcpy(matchmask, mask);
+    char *host = strchr(mask, '@');
+    if(host) {
+        struct IPNode *ip = createIPNode(host);
+        int bits = (ip->flags & IPNODE_IS_IPV6 ? 128 : 32);
+        if((host = strchr(host, '/'))) {
+            bits = atoi(host+1);
+        }
+        if(ip && user->ip&& !ipmatch(user->ip, ip, bits)) {
+            host[1] = '*';
+            host[2] = '\0';
+        }
+    }
+    sprintf(usermask, "%s!%s@%s", user->nick, user->ident, user->host);
+    return match(matchmask, usermask);
+}
+
 static unsigned long crc_table[256];
 
 static void crc32_init() {