1019 |
|
|
1020 |
static void m_notice(char **parv, unsigned int parc, char *msg, struct UserInfo *source_p) |
static void m_notice(char **parv, unsigned int parc, char *msg, struct UserInfo *source_p) |
1021 |
{ |
{ |
1022 |
|
static regex_t *connregex = NULL; |
1023 |
|
static regex_t *locopsregex = NULL; |
|
static regex_t *preg = NULL; |
|
1024 |
regmatch_t pmatch[5]; |
regmatch_t pmatch[5]; |
1025 |
|
|
1026 |
static char errmsg[256]; |
static char errmsg[256]; |
1027 |
int errnum, i; |
int errnum, i; |
1028 |
|
|
1029 |
char *user[4]; |
char *user[4]; |
1030 |
|
char *command; |
1031 |
|
|
1032 |
if(parc < 4) |
if(parc < 4) |
1033 |
return; |
return; |
1036 |
if(source_p != NULL) |
if(source_p != NULL) |
1037 |
return; |
return; |
1038 |
|
|
1039 |
/* Compile the regular expression if it has not been already */ |
/* Compile the connect regex if it has not been already */ |
1040 |
if(preg == NULL) |
if(connregex == NULL) |
1041 |
{ |
{ |
1042 |
preg = MyMalloc(sizeof *preg); |
connregex = MyMalloc(sizeof *connregex); |
1043 |
|
|
1044 |
if((errnum = regcomp(preg, IRCItem->connregex, REG_ICASE | REG_EXTENDED)) != 0) |
if((errnum = regcomp(connregex, IRCItem->connregex, REG_ICASE | REG_EXTENDED)) != 0) |
1045 |
{ |
{ |
1046 |
|
|
1047 |
regerror(errnum, preg, errmsg, 256); |
regerror(errnum, connregex, errmsg, 256); |
1048 |
log_printf("IRC REGEX -> Error when compiling regular expression"); |
log_printf("IRC REGEX -> Error when compiling connection regex"); |
1049 |
log_printf("IRC REGEX -> %s", errmsg); |
log_printf("IRC REGEX -> %s", errmsg); |
1050 |
|
|
1051 |
MyFree(preg); |
MyFree(connregex); |
1052 |
preg = NULL; |
connregex = NULL; |
1053 |
return; |
return; |
1054 |
} |
} |
1055 |
} |
} |
1056 |
|
|
1057 |
/* Match the expression against the possible connection notice */ |
/* If this is not a connection notice, try parsing it as locops instead */ |
1058 |
if(regexec(preg, parv[3], 5, pmatch, 0) != 0) |
if(regexec(connregex, parv[3], 5, pmatch, 0) != 0) |
1059 |
return; |
goto parse_locops; |
1060 |
|
|
1061 |
if(OPT_DEBUG > 0) |
if(OPT_DEBUG > 0) |
1062 |
log_printf("IRC REGEX -> Regular expression caught connection notice. Parsing."); |
log_printf("IRC REGEX -> Regular expression caught connection notice. Parsing."); |
1087 |
log_printf("IRC REGEX -> Parsed %s!%s@%s [%s] from connection notice.", |
log_printf("IRC REGEX -> Parsed %s!%s@%s [%s] from connection notice.", |
1088 |
user[0], user[1], user[2], user[3]); |
user[0], user[1], user[2], user[3]); |
1089 |
|
|
1090 |
/*FIXME (reminder) In the case of any rehash to the regex, preg MUST be freed first. |
/*FIXME (reminder) In the case of any rehash to the regex, connregex MUST be freed first. |
1091 |
regfree(preg); |
regfree(connregex); |
1092 |
*/ |
*/ |
1093 |
|
|
1094 |
/* Pass this information off to scan.c */ |
/* Pass this information off to scan.c */ |
1095 |
scan_connect(user, msg); |
scan_connect(user, msg); |
1096 |
/* Record the connect for stats purposes */ |
/* Record the connect for stats purposes */ |
1097 |
stats_connect(); |
stats_connect(); |
1098 |
|
return; |
1099 |
|
|
1100 |
|
parse_locops: |
1101 |
|
/* Compile the locops regex if it has not been already */ |
1102 |
|
if(locopsregex == NULL) |
1103 |
|
{ |
1104 |
|
locopsregex = MyMalloc(sizeof *locopsregex); |
1105 |
|
|
1106 |
|
if((errnum = regcomp(locopsregex, IRCItem->locopsregex, REG_ICASE | REG_EXTENDED)) != 0) |
1107 |
|
{ |
1108 |
|
|
1109 |
|
regerror(errnum, locopsregex, errmsg, 256); |
1110 |
|
log_printf("IRC REGEX -> Error when compiling locops regex"); |
1111 |
|
log_printf("IRC REGEX -> %s", errmsg); |
1112 |
|
|
1113 |
|
MyFree(locopsregex); |
1114 |
|
locopsregex = NULL; |
1115 |
|
return; |
1116 |
|
} |
1117 |
|
} |
1118 |
|
|
1119 |
|
if(regexec(locopsregex, parv[3], 2, pmatch, 0) != 0) |
1120 |
|
return; |
1121 |
|
|
1122 |
|
if(OPT_DEBUG > 0) |
1123 |
|
log_printf("IRC REGEX -> Locops regex caught locops command. Parsing."); |
1124 |
|
|
1125 |
|
if(pmatch[1].rm_so == -1) |
1126 |
|
{ |
1127 |
|
log_printf("IRC REGEX -> pmatch[1].rm_so is -1 while parsing??? Aborting."); |
1128 |
|
return; |
1129 |
|
} |
1130 |
|
|
1131 |
|
/* |
1132 |
|
Offsets for data in the locops notice: |
1133 |
|
|
1134 |
|
COMMAND: pmatch[1].rm_so TO pmatch[1].rm_eo |
1135 |
|
|
1136 |
|
*/ |
1137 |
|
|
1138 |
|
command = (parv[3] + pmatch[i + 1].rm_so); |
1139 |
|
*(parv[3] + pmatch[i + 1].rm_eo) = '\0'; |
1140 |
|
|
1141 |
|
if(OPT_DEBUG > 0) |
1142 |
|
log_printf("IRC REGEX -> Parsed command [%s] from locops notice.", |
1143 |
|
command); |
1144 |
|
|
1145 |
|
/*FIXME (reminder) In the case of any rehash to the regex, locopsregex MUST be freed first. |
1146 |
|
regfree(locopsregex); |
1147 |
|
*/ |
1148 |
|
|
1149 |
|
/* FIXME Do something meaningful with acquired data; parse_command_locops comes to mind */ |
1150 |
|
|
1151 |
|
return; |
1152 |
} |
} |
1153 |
|
|
1154 |
/* m_userhost |
/* m_userhost |