]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/kdparse.c
Complete the move of xlines and resvs from aconf->name to aconf->host.
[irc/rqf/shadowircd.git] / src / kdparse.c
index 7a150135723e37937bdf464097f6a719e89f9abe..b7614ce08331107d7221249fafdc10d824e76246 100644 (file)
  */
 
 #include "stdinc.h"
-#include "tools.h"
-#include "s_log.h"
+#include "logger.h"
 #include "s_conf.h"
 #include "s_newconf.h"
 #include "hostmask.h"
 #include "client.h"
-#include "irc_string.h"
-#include "memory.h"
+#include "match.h"
 #include "hash.h"
 
 /* conf_add_fields()
@@ -47,21 +45,21 @@ conf_add_fields(struct ConfItem *aconf,     const char *host_field,
                const char *operreason_field, const char *date_field)
 {
        if(host_field != NULL)
-               DupString(aconf->host, host_field);
+               aconf->host = rb_strdup(host_field);
        if(pass_field != NULL)
        {
                if(!EmptyString(date_field))
                {
-                       aconf->passwd = MyMalloc(strlen(pass_field) + strlen(date_field) + 4);
-                       ircsprintf(aconf->passwd, "%s (%s)", pass_field, date_field);
+                       aconf->passwd = rb_malloc(strlen(pass_field) + strlen(date_field) + 4);
+                       rb_sprintf(aconf->passwd, "%s (%s)", pass_field, date_field);
                }
                else
-                       DupString(aconf->passwd, pass_field);
+                       aconf->passwd = rb_strdup(pass_field);
        }
        if(user_field != NULL)
-               DupString(aconf->user, user_field);
+               aconf->user = rb_strdup(user_field);
        if(operreason_field != NULL)
-               DupString(aconf->spasswd, operreason_field);
+               aconf->spasswd = rb_strdup(operreason_field);
 }
 
 /*
@@ -112,7 +110,7 @@ parse_k_file(FILE * file)
                                user_field, operreason_field, date_field);
 
                if(aconf->host != NULL)
-                       add_conf_by_address(aconf->host, CONF_KILL, aconf->user, aconf);
+                       add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
        }
 }
 
@@ -160,6 +158,37 @@ parse_d_file(FILE * file)
        }
 }
 
+char *
+xline_encode_spaces(const char *mask)
+{
+       int i, j;
+       int spaces = 0;
+       int backslash = 0;
+       char *encoded;
+
+       for (i = 0; mask[i] != '\0'; i++)
+               if (mask[i] == ' ')
+                       spaces++;
+       encoded = rb_malloc(i + spaces + 1);
+       for (i = 0, j = 0; mask[i] != '\0'; i++)
+       {
+               if (mask[i] == '\\')
+                       backslash = !backslash;
+               else if (mask[i] == ' ')
+               {
+                       if (!backslash)
+                               encoded[j++] = '\\';
+                       encoded[j++] = 's';
+                       backslash = 0;
+                       continue;
+               }
+               else
+                       backslash = 0;
+               encoded[j++] = mask[i];
+       }
+       return encoded;
+}
+
 void
 parse_x_file(FILE * file)
 {
@@ -168,6 +197,7 @@ parse_x_file(FILE * file)
        char *reason_field = NULL;
        char line[BUFSIZE];
        char *p;
+       char *encoded;
 
        while (fgets(line, sizeof(line), file))
        {
@@ -193,13 +223,20 @@ parse_x_file(FILE * file)
                   (strchr(reason_field, ':') != NULL))
                        continue;
 
+               encoded = xline_encode_spaces(gecos_field);
+               if (find_xline_mask(encoded) != NULL)
+               {
+                       rb_free(encoded);
+                       continue;
+               }
+
                aconf = make_conf();
                aconf->status = CONF_XLINE;
 
-               DupString(aconf->name, gecos_field);
-               DupString(aconf->passwd, reason_field);
+               aconf->host = encoded;
+               aconf->passwd = rb_strdup(reason_field);
 
-               dlinkAddAlloc(aconf, &xline_conf_list);
+               rb_dlinkAddAlloc(aconf, &xline_conf_list);
        }
 }
 
@@ -237,9 +274,9 @@ parse_resv_file(FILE * file)
                        aconf->status = CONF_RESV_CHANNEL;
                        aconf->port = 0;
 
-                       DupString(aconf->name, host_field);
-                       DupString(aconf->passwd, reason_field);
-                       add_to_resv_hash(aconf->name, aconf);
+                       aconf->host = rb_strdup(host_field);
+                       aconf->passwd = rb_strdup(reason_field);
+                       add_to_resv_hash(aconf->host, aconf);
                }
                else if(clean_resv_nick(host_field))
                {
@@ -250,9 +287,9 @@ parse_resv_file(FILE * file)
                        aconf->status = CONF_RESV_NICK;
                        aconf->port = 0;
 
-                       DupString(aconf->name, host_field);
-                       DupString(aconf->passwd, reason_field);
-                       dlinkAddAlloc(aconf, &resv_conf_list);
+                       aconf->host = rb_strdup(host_field);
+                       aconf->passwd = rb_strdup(reason_field);
+                       rb_dlinkAddAlloc(aconf, &resv_conf_list);
                }
        }
 }