dragonmtn-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dragonmtn-commits] Changes to icequeen/src/irc.c


From: Tony Vroon
Subject: [Dragonmtn-commits] Changes to icequeen/src/irc.c
Date: Sat, 09 Apr 2005 14:44:17 -0400

Index: icequeen/src/irc.c
diff -u icequeen/src/irc.c:1.2 icequeen/src/irc.c:1.3
--- icequeen/src/irc.c:1.2      Sat Apr  9 14:20:13 2005
+++ icequeen/src/irc.c  Sat Apr  9 18:44:17 2005
@@ -72,7 +72,7 @@
 #include "malloc.h"
 #include "main.h"
 
-RCSID("$Id: irc.c,v 1.2 2005/04/09 14:20:13 chainsaw Exp $");
+RCSID("$Id: irc.c,v 1.3 2005/04/09 18:44:17 chainsaw Exp $");
 
 static void irc_init(void);
 static void irc_connect(void);
@@ -1019,15 +1019,15 @@
 
 static void m_notice(char **parv, unsigned int parc, char *msg, struct 
UserInfo *source_p)
 {
-
-
-   static regex_t *preg = NULL;
+   static regex_t *connregex = NULL;
+   static regex_t *locopsregex = NULL;
    regmatch_t pmatch[5];
 
    static char errmsg[256];
    int errnum, i;
 
    char *user[4];
+   char *command;
 
    if(parc < 4)
       return;
@@ -1036,27 +1036,27 @@
    if(source_p != NULL)
       return;
 
-   /* Compile the regular expression if it has not been already */
-   if(preg == NULL)
+   /* Compile the connect regex if it has not been already */
+   if(connregex == NULL)
    {
-      preg = MyMalloc(sizeof *preg);
+      connregex = MyMalloc(sizeof *connregex);
 
-      if((errnum = regcomp(preg, IRCItem->connregex, REG_ICASE | 
REG_EXTENDED)) != 0)
+      if((errnum = regcomp(connregex, IRCItem->connregex, REG_ICASE | 
REG_EXTENDED)) != 0)
       {
 
-         regerror(errnum, preg, errmsg, 256);
-         log_printf("IRC REGEX -> Error when compiling regular expression");
+         regerror(errnum, connregex, errmsg, 256);
+         log_printf("IRC REGEX -> Error when compiling connection regex");
          log_printf("IRC REGEX -> %s", errmsg);
 
-         MyFree(preg);
-         preg = NULL;
+         MyFree(connregex);
+         connregex = NULL;
          return;
       }
    }
 
-   /* Match the expression against the possible connection notice */
-   if(regexec(preg, parv[3], 5, pmatch, 0) != 0)
-      return;
+   /* If this is not a connection notice, try parsing it as locops instead */
+   if(regexec(connregex, parv[3], 5, pmatch, 0) != 0)
+      goto parse_locops;
 
    if(OPT_DEBUG > 0)
       log_printf("IRC REGEX -> Regular expression caught connection notice. 
Parsing.");
@@ -1087,14 +1087,68 @@
       log_printf("IRC REGEX -> Parsed address@hidden [%s] from connection 
notice.",
           user[0], user[1], user[2], user[3]);
 
-   /*FIXME (reminder) In the case of any rehash to the regex, preg MUST be 
freed first.
-       regfree(preg);
+   /*FIXME (reminder) In the case of any rehash to the regex, connregex MUST 
be freed first.
+       regfree(connregex);
    */
 
    /* Pass this information off to scan.c */
    scan_connect(user, msg);
    /* Record the connect for stats purposes */
    stats_connect();
+   return;
+
+parse_locops:
+   /* Compile the locops regex if it has not been already */
+   if(locopsregex == NULL)
+   {
+      locopsregex = MyMalloc(sizeof *locopsregex);
+
+      if((errnum = regcomp(locopsregex, IRCItem->locopsregex, REG_ICASE | 
REG_EXTENDED)) != 0)
+      {
+
+         regerror(errnum, locopsregex, errmsg, 256);
+         log_printf("IRC REGEX -> Error when compiling locops regex");
+         log_printf("IRC REGEX -> %s", errmsg);
+
+         MyFree(locopsregex);
+         locopsregex = NULL;
+         return;
+      }
+   }
+
+   if(regexec(locopsregex, parv[3], 2, pmatch, 0) != 0)
+      return;
+
+   if(OPT_DEBUG > 0)
+      log_printf("IRC REGEX -> Locops regex caught locops command. Parsing.");
+
+   if(pmatch[1].rm_so == -1)
+   {
+      log_printf("IRC REGEX -> pmatch[1].rm_so is -1 while parsing??? 
Aborting.");
+      return;
+   }
+
+   /*
+       Offsets for data in the locops notice:
+
+       COMMAND: pmatch[1].rm_so  TO  pmatch[1].rm_eo
+
+    */
+
+   command = (parv[3] + pmatch[i + 1].rm_so);
+   *(parv[3] + pmatch[i + 1].rm_eo) = '\0';
+
+   if(OPT_DEBUG > 0)
+      log_printf("IRC REGEX -> Parsed command [%s] from locops notice.",
+          command);
+
+   /*FIXME (reminder) In the case of any rehash to the regex, locopsregex MUST 
be freed first.
+       regfree(locopsregex);
+   */
+
+   /* FIXME Do something meaningful with acquired data; parse_command_locops 
comes to mind */
+
+   return;
 }
 
 /* m_userhost




reply via email to

[Prev in Thread] Current Thread [Next in Thread]