5 FUTURE: natural (sort of) language parsing
8 PPA: if multiple users match the same user@host or *@host it'll send multiple glines?!
11 #include "regexgline.h"
13 typedef struct rg_glinenode
{
15 struct rg_struct
*reason
;
17 struct rg_glinenode
*next
;
20 typedef struct rg_glinelist
{
21 struct rg_glinenode
*start
;
22 struct rg_glinenode
*end
;
25 void rg_dogline(struct rg_glinelist
*gll
, nick
*np
, struct rg_struct
*rp
, char *matched
);
28 sstring
*max_casualties
, *max_spew
, *expiry_time
, *max_per_gline
;
30 max_casualties
= getcopyconfigitem("regexgline", "maxcasualties", RGStringise(RG_MAX_CASUALTIES_DEFAULT
), 8);
31 if(!protectedatoi(max_casualties
->content
, &rg_max_casualties
))
32 rg_max_casualties
= RG_MAX_CASUALTIES_DEFAULT
;
34 freesstring(max_casualties
);
36 max_spew
= getcopyconfigitem("regexgline", "maxspew", RGStringise(RG_MAX_SPEW_DEFAULT
), 8);
37 if(!protectedatoi(max_spew
->content
, &rg_max_spew
))
38 rg_max_spew
= RG_MAX_SPEW_DEFAULT
;
40 freesstring(max_spew
);
42 expiry_time
= getcopyconfigitem("regexgline", "expirytime", RGStringise(RG_EXPIRY_TIME_DEFAULT
), 8);
43 if(!protectedatoi(expiry_time
->content
, &rg_expiry_time
))
44 rg_expiry_time
= RG_EXPIRY_TIME_DEFAULT
;
46 freesstring(expiry_time
);
48 max_per_gline
= getcopyconfigitem("regexgline", "maxpergline", RGStringise(RG_MAX_PER_GLINE_DEFAULT
), 8);
49 if(!protectedatoi(max_per_gline
->content
, &rg_max_per_gline
))
50 rg_max_per_gline
= RG_MAX_PER_GLINE_DEFAULT
;
52 freesstring(max_per_gline
);
57 registercontrolcmd("regexgline", 10, 4, rg_gline
);
58 registercontrolcmd("regexdelgline", 10, 1, rg_delgline
);
59 registercontrolcmd("regexglist", 10, 1, rg_glist
);
60 registercontrolcmd("regexspew", 10, 1, rg_spew
);
61 registercontrolcmd("regexidlookup", 10, 1, rg_idlist
);
63 registerhook(HOOK_NICK_NEWNICK
, &rg_nick
);
64 registerhook(HOOK_NICK_RENAME
, &rg_nick
);
67 rg_schedule
= schedulerecurring(time(NULL
) + 1, 0, 1, rg_checkexpiry
, NULL
);
72 struct rg_struct
*gp
= rg_list
, *oldgp
;
74 deregisterhook(HOOK_NICK_NEWNICK
, &rg_nick
);
75 deregisterhook(HOOK_NICK_RENAME
, &rg_nick
);
76 deregistercontrolcmd("regexspew", rg_spew
);
77 deregistercontrolcmd("regexglist", rg_glist
);
78 deregistercontrolcmd("regexdelgline", rg_delgline
);
79 deregistercontrolcmd("regexgline", rg_gline
);
80 deregistercontrolcmd("regexidlookup", rg_idlist
);
83 deleteschedule(rg_schedule
, &rg_checkexpiry
, NULL
);
97 void rg_checkexpiry(void *arg
) {
98 struct rg_struct
*rp
= rg_list
, *lp
= NULL
;
99 time_t current
= time(NULL
);
102 if (current
>= rp
->expires
) {
119 void rg_initglinelist(struct rg_glinelist
*gll
) {
124 void rg_flushglines(struct rg_glinelist
*gll
) {
125 struct rg_glinenode
*nn
, *pn
;
126 for(nn
=gll
->start
;nn
;nn
=pn
) {
129 killuser(NULL
, nn
->np
, "%s (ID: %08lx)", nn
->reason
->reason
->content
, nn
->reason
->glineid
);
133 rg_initglinelist(gll
);
136 int rg_dbconnect(void) {
137 sstring
*dbhost
, *dbusername
, *dbpassword
, *dbdatabase
, *dbport
;
139 dbhost
= getcopyconfigitem("regexgline", "dbhost", "localhost", HOSTLEN
);
140 dbusername
= getcopyconfigitem("regexgline", "dbusername", "regexgline", 20);
141 dbpassword
= getcopyconfigitem("regexgline", "dbpassword", "moo", 20);
142 dbdatabase
= getcopyconfigitem("regexgline", "dbdatabase", "regexgline", 20);
143 dbport
= getcopyconfigitem("regexgline", "dbport", "3306", 8);
145 if(rg_sqlconnect(dbhost
->content
, dbusername
->content
, dbpassword
->content
, dbdatabase
->content
, strtol(dbport
->content
, NULL
, 10))) {
146 Error("regexgline", ERR_FATAL
, "Cannot connect to database host!");
147 return 1; /* PPA: splidge: do something here 8]! */
153 freesstring(dbusername
);
154 freesstring(dbpassword
);
155 freesstring(dbdatabase
);
161 int rg_dbload(void) {
162 rg_sqlquery("CREATE TABLE regexglines (id INT(10) PRIMARY KEY AUTO_INCREMENT, gline TEXT NOT NULL, setby VARCHAR(%d) NOT NULL, reason VARCHAR(%d) NOT NULL, expires BIGINT NOT NULL, type TINYINT(4) NOT NULL DEFAULT 1)", ACCOUNTLEN
, RG_REASON_MAX
);
163 rg_sqlquery("CREATE TABLE regexlogs (id INT(10) PRIMARY KEY AUTO_INCREMENT, host VARCHAR(%d) NOT NULL, account VARCHAR(%d) NOT NULL, event TEXT NOT NULL, arg TEXT NOT NULL, ts TIMESTAMP)", RG_MASKLEN
- 1, ACCOUNTLEN
);
164 rg_sqlquery("CREATE TABLE regexglinelog (id INT(10) PRIMARY KEY AUTO_INCREMENT, glineid INT(10) NOT NULL, ts TIMESTAMP, nickname VARCHAR(%d) NOT NULL, username VARCHAR(%d) NOT NULL, hostname VARCHAR(%d) NOT NULL, realname VARCHAR(%d))", NICKLEN
, USERLEN
, HOSTLEN
, REALLEN
);
166 if(!rg_sqlquery("SELECT id, gline, setby, reason, expires, type FROM regexglines")) {
168 if((res
= rg_sqlstoreresult())) {
170 while((row
= rg_sqlgetrow(res
))) {
171 if (!rg_newsstruct(row
[0], row
[1], row
[2], row
[3], row
[4], row
[5], 0, 0))
172 rg_sqlquery("DELETE FROM regexglines WHERE id = %s", row
[0]);
181 void rg_nick(int hooknum
, void *arg
) {
182 nick
*np
= (nick
*)arg
;
183 struct rg_struct
*rp
;
184 char hostname
[RG_MASKLEN
];
186 struct rg_glinelist gll
;
188 rg_initglinelist(&gll
);
190 hostlen
= RGBuildHostname(hostname
, np
);
192 for(rp
=rg_list
;rp
;rp
=rp
->next
) {
193 if(pcre_exec(rp
->regex
, rp
->hint
, hostname
, hostlen
, 0, 0, NULL
, 0) >= 0) {
194 rg_dogline(&gll
, np
, rp
, hostname
);
199 rg_flushglines(&gll
);
202 int rg_gline(void *source
, int cargc
, char **cargv
) {
203 nick
*np
= (nick
*)source
, *tnp
;
205 const char *expirybuf
;
206 int expiry
, count
, j
, hostlen
;
207 struct rg_struct
*rp
;
208 struct rg_glinelist gll
;
210 char eemask
[RG_QUERY_BUF_SIZE
], eesetby
[RG_QUERY_BUF_SIZE
], eereason
[RG_QUERY_BUF_SIZE
];
211 char hostname
[RG_MASKLEN
];
214 controlreply(np
, "syntax: regexgline [mask] [duration] [type: 1: gline user@host 2: gline *@host 3: KILL] [reason]");
218 if ((strlen(cargv
[2]) != 1) || ((cargv
[2][0] != '1') && (cargv
[2][0] != '2') && (cargv
[2][0] != '3'))) {
219 controlreply(np
, "Invalid type specified!");
223 if (!(expiry
= durationtolong(cargv
[1]))) {
224 controlreply(np
, "Invalid duration specified!");
228 for(rp
=rg_list
;rp
;rp
=rp
->next
) {
229 if (RGMasksEqual(rp
->mask
->content
, cargv
[0])) {
230 controlreply(np
, "That regexp gline already exists!");
235 if (rg_sanitycheck(cargv
[0], &count
)) {
236 controlreply(np
, "Error in expression.");
238 } else if (count
< 0) {
239 controlreply(np
, "That expression would hit too many users (%d)!", -count
);
243 realexpiry
= expiry
+ time(NULL
);
245 rg_sqlescape_string(eemask
, cargv
[0], strlen(cargv
[0]));
246 rg_sqlescape_string(eesetby
, np
->nick
, strlen(np
->nick
));
247 rg_sqlescape_string(eereason
, cargv
[3], strlen(cargv
[3]));
249 rg_sqlquery("INSERT INTO regexglines (gline, setby, reason, expires, type) VALUES ('%s', '%s', '%s', %d, %s)", eemask
, eesetby
, eereason
, realexpiry
, cargv
[2]);
250 if (!rg_sqlquery("SELECT id FROM regexglines WHERE gline = '%s' AND setby = '%s' AND reason = '%s' AND expires = %d AND type = %s ORDER BY ID DESC LIMIT 1", eemask
, eesetby
, eereason
, realexpiry
, cargv
[2])) {
252 if((res
= rg_sqlstoreresult())) {
254 row
= rg_sqlgetrow(res
);
256 rp
= rg_newsstruct(row
[0], cargv
[0], np
->nick
, cargv
[3], "", cargv
[2], realexpiry
, 0);
259 rg_sqlquery("DELETE FROM regexglines WHERE gline = '%s' AND setby = '%s' AND reason = '%s' AND expires = %d AND type = %s ORDER BY ID DESC LIMIT 1", eemask
, eesetby
, eereason
, realexpiry
, cargv
[2]);
260 controlreply(np
, "Error allocating - regexgline NOT ADDED.");
265 rg_sqlquery("DELETE FROM regexglines WHERE gline = '%s' AND setby = '%s' AND reason = '%s' AND expires = %d AND type = %s ORDER BY ID DESC LIMIT 1", eemask
, eesetby
, eereason
, realexpiry
, cargv
[2]);
266 controlreply(np
, "Error selecting ID from database - regexgline NOT ADDED.");
270 rg_sqlquery("DELETE FROM regexglines WHERE gline = '%s' AND setby = '%s' AND reason = '%s' AND expires = %d AND type = %s ORDER BY ID DESC LIMIT 1", eemask
, eesetby
, eereason
, realexpiry
, cargv
[2]);
271 controlreply(np
, "Error fetching ID from database - regexgline NOT ADDED.");
275 rg_sqlquery("DELETE FROM regexglines WHERE gline = '%s' AND setby = '%s' AND reason = '%s' AND expires = %d AND type = %s ORDER BY ID DESC LIMIT 1", eemask
, eesetby
, eereason
, realexpiry
, cargv
[2]);
276 controlreply(np
, "Error executing query - regexgline NOT ADDED.");
280 rg_initglinelist(&gll
);
282 for(j
=0;j
<NICKHASHSIZE
;j
++) {
283 for(tnp
=nicktable
[j
];tnp
;tnp
=tnp
->next
) {
284 hostlen
= RGBuildHostname(hostname
, tnp
);
285 if(pcre_exec(rp
->regex
, rp
->hint
, hostname
, hostlen
, 0, 0, NULL
, 0) >= 0)
286 rg_dogline(&gll
, tnp
, rp
, hostname
);
290 rg_flushglines(&gll
);
292 expirybuf
= longtoduration(expiry
, 0);
294 rg_logevent(np
, "regexgline", "%s %d %d %s", cargv
[0], expiry
, count
, cargv
[3]);
295 controlreply(np
, "Added regexgline: %s (expires in: %s, hit %d user%s): %s", cargv
[0], expirybuf
, count
, (count
!=1)?"s":"", cargv
[3]);
296 controlnoticeopers("%s added regexgline: %s (expires in: %s, hit %d user%s): %s", np
->nick
, cargv
[0], expirybuf
, count
, (count
!=1)?"s":"", cargv
[3]);
301 int rg_sanitycheck(char *mask
, int *count
) {
303 char hostname
[RG_MASKLEN
];
304 int erroroffset
, hostlen
, j
, masklen
= strlen(mask
);
309 if((masklen
< RG_MIN_MASK_LEN
) || (masklen
> RG_REGEXGLINE_MAX
))
312 if(!(regex
= pcre_compile(mask
, RG_PCREFLAGS
, &error
, &erroroffset
, NULL
))) {
313 Error("regexgline", ERR_WARNING
, "Error compiling expression %s at offset %d: %s", mask
, erroroffset
, error
);
316 hint
= pcre_study(regex
, 0, &error
);
318 Error("regexgline", ERR_WARNING
, "Error studying expression %s: %s", mask
, error
);
325 for(j
=0;j
<NICKHASHSIZE
;j
++) {
326 for(np
=nicktable
[j
];np
;np
=np
->next
) {
327 hostlen
= RGBuildHostname(hostname
, np
);
328 if(pcre_exec(regex
, hint
, hostname
, hostlen
, 0, 0, NULL
, 0) >= 0) {
338 if(*count
>= rg_max_casualties
)
344 int rg_delgline(void *source
, int cargc
, char **cargv
) {
345 nick
*np
= (nick
*)source
;
346 struct rg_struct
*rp
= rg_list
, *last
= NULL
;
350 controlreply(np
, "syntax: regexdelgline [mask]");
354 rg_logevent(np
, "regexdelgline", "%s", cargv
[0]);
356 if(RGMasksEqual(rp
->mask
->content
, cargv
[0])) {
358 rg_sqlquery("DELETE FROM regexglines WHERE id = %d", rp
->id
);
360 last
->next
= rp
->next
;
374 controlreply(np
, "Deleted (matched: %d).", count
);
375 controlnoticeopers("%s removed regexgline: %s (matches: %d)", np
->nick
, cargv
[0], count
);
377 controlreply(np
, "No glines matched: %s", cargv
[0]);
382 int rg_idlist(void *source
, int cargc
, char **cargv
) {
383 nick
*np
= (nick
*)source
;
386 controlreply(np
, "syntax: regexidlookup [gline id]");
388 } else if (strlen(cargv
[0]) != 8) {
389 controlreply(np
, "Invalid gline id!");
392 struct rg_struct
*rp
;
393 unsigned long id
= 0;
397 if(0xff == rc_hexlookup
[(int)cargv
[0][i
]]) {
398 controlreply(np
, "Invalid gline id!");
401 id
= (id
<< 4) | rc_hexlookup
[(int)cargv
[0][i
]];
405 controlreply(np
, "Mask Expires Set by Type Reason");
406 for(rp
=rg_list
;rp
;rp
=rp
->next
)
407 if(id
== rp
->glineid
)
408 rg_displaygline(np
, rp
);
409 controlreply(np
, "Done.");
415 int rg_glist(void *source
, int cargc
, char **cargv
) {
416 nick
*np
= (nick
*)source
;
417 struct rg_struct
*rp
;
425 if(!(regex
= pcre_compile(cargv
[0], RG_PCREFLAGS
, &error
, &erroroffset
, NULL
))) {
426 controlreply(np
, "Error compiling expression %s at offset %d: %s", cargv
[0], erroroffset
, error
);
429 hint
= pcre_study(regex
, 0, &error
);
431 controlreply(np
, "Error studying expression %s: %s", cargv
[0], error
);
437 rg_logevent(np
, "regexglist", "%s", cargv
[0]);
438 controlreply(np
, "Mask Expires Set by Type Reason");
439 for(rp
=rg_list
;rp
;rp
=rp
->next
)
440 if(pcre_exec(regex
, hint
, rp
->mask
->content
, rp
->mask
->length
, 0, 0, NULL
, 0) >= 0)
441 rg_displaygline(np
, rp
);
448 rg_logevent(np
, "regexglist", "");
449 controlreply(np
, "Mask Expires Set by Type Reason");
450 for(rp
=rg_list
;rp
;rp
=rp
->next
)
451 rg_displaygline(np
, rp
);
454 controlreply(np
, "Done.");
458 void rg_displaygline(nick
*np
, struct rg_struct
*rp
) { /* could be a macro? I'll assume the C compiler inlines it */
459 controlreply(np
, "%-25s %-20s %-15s %-4d %s", rp
->mask
->content
, longtoduration(rp
->expires
- time(NULL
), 0), rp
->setby
->content
, rp
->type
, rp
->reason
->content
);
462 int rg_spew(void *source
, int cargc
, char **cargv
) {
463 nick
*np
= (nick
*)source
, *tnp
;
464 int counter
= 0, erroroffset
, hostlen
, j
;
468 char hostname
[RG_MASKLEN
];
473 controlreply(np
, "syntax: regexspew [mask]");
477 if(!(regex
= pcre_compile(cargv
[0], RG_PCREFLAGS
, &error
, &erroroffset
, NULL
))) {
478 controlreply(np
, "Error compiling expression %s at offset %d: %s", cargv
[0], erroroffset
, error
);
481 hint
= pcre_study(regex
, 0, &error
);
483 controlreply(np
, "Error studying expression %s: %s", cargv
[0], error
);
489 rg_logevent(np
, "regexspew", "%s", cargv
[0]);
491 for(j
=0;j
<NICKHASHSIZE
;j
++) {
492 for(tnp
=nicktable
[j
];tnp
;tnp
=tnp
->next
) {
493 hostlen
= RGBuildHostname(hostname
, tnp
);
494 pcreret
= pcre_exec(regex
, hint
, hostname
, hostlen
, 0, 0, ovector
, sizeof(ovector
) / sizeof(int));
496 if(counter
== rg_max_spew
) {
497 controlreply(np
, "Reached maximum spew count (%d) - aborting display.", rg_max_spew
);
498 } else if (counter
< rg_max_spew
) {
499 /* 15 should be number of bolds */
500 char boldbuf
[RG_MASKLEN
+ 15], *tp
, *fp
, *realname
= NULL
;
502 for(tp
=hostname
,fp
=boldbuf
;*tp
;) {
503 if(tp
- hostname
== ovector
[0]) {
507 if(tp
- hostname
== ovector
[1]) {
526 controlreply(np
, "%s (%s) (%dc)", boldbuf
, realname
, tnp
->channels
->cursi
);
532 controlreply(np
, "Done - %d matches.", counter
);
541 int rg_sqlconnect(char *dbhost
, char *dbuser
, char *dbpass
, char *db
, unsigned int port
) {
543 if(!mysql_real_connect(&rg_sql
, dbhost
, dbuser
, dbpass
, db
, port
, NULL
, 0))
548 void rg_sqldisconnect(void) {
549 mysql_close(&rg_sql
);
552 void rg_sqlescape_string(char *dest
, char *source
, size_t length
) {
553 if(length
>= RG_QUERY_BUF_SIZE
)
554 length
= RG_QUERY_BUF_SIZE
- 1;
556 mysql_escape_string(dest
, source
, length
);
559 int rg_sqlquery(char *format
, ...) {
560 char rg_sqlquery
[RG_QUERY_BUF_SIZE
];
563 va_start(va
, format
);
564 vsnprintf(rg_sqlquery
, sizeof(rg_sqlquery
), format
, va
);
567 return mysql_query(&rg_sql
, rg_sqlquery
);
570 rg_sqlresult
rg_sqlstoreresult(void) {
571 return mysql_store_result(&rg_sql
);
574 rg_sqlrow
rg_sqlgetrow(rg_sqlresult res
) {
575 return mysql_fetch_row(res
);
578 void rg_sqlfree(rg_sqlresult res
) {
579 mysql_free_result(res
);
582 void rg_startup(void) {
585 struct rg_struct
*rp
;
586 struct rg_glinelist gll
;
587 char hostname
[RG_MASKLEN
];
589 rg_initglinelist(&gll
);
591 for(j
=0;j
<NICKHASHSIZE
;j
++) {
592 for(np
=nicktable
[j
];np
;np
=np
->next
) {
593 hostlen
= RGBuildHostname(hostname
, np
);
594 for(rp
=rg_list
;rp
;rp
=rp
->next
) {
595 if(pcre_exec(rp
->regex
, rp
->hint
, hostname
, hostlen
, 0, 0, NULL
, 0) >= 0) {
596 rg_dogline(&gll
, np
, rp
, hostname
);
603 rg_flushglines(&gll
);
606 void rg_freestruct(struct rg_struct
*rp
) {
607 freesstring(rp
->mask
);
608 freesstring(rp
->setby
);
609 freesstring(rp
->reason
);
610 pcre_free(rp
->regex
);
616 struct rg_struct
*rg_newstruct(time_t expires
) {
617 struct rg_struct
*rp
;
619 if (time(NULL
) >= expires
)
622 rp
= (struct rg_struct
*)malloc(sizeof(struct rg_struct
));
624 struct rg_struct
*tp
, *lp
;
629 rp
->expires
= expires
;
634 for(lp
=NULL
,tp
=rg_list
;tp
;lp
=tp
,tp
=tp
->next
) {
635 if (expires
<= tp
->expires
) { /* <= possible, slight speed increase */
658 struct rg_struct
*rg_newsstruct(char *id
, char *mask
, char *setby
, char *reason
, char *expires
, char *type
, time_t iexpires
, int iid
) {
659 struct rg_struct
*newrow
, *lp
, *cp
;
661 char glineiddata
[1024];
663 if(!protectedatoi(expires
, &rexpires
))
669 newrow
= rg_newstruct(rexpires
);
675 if(!(newrow
->regex
= pcre_compile(mask
, RG_PCREFLAGS
, &error
, &erroroffset
, NULL
))) {
676 Error("regexgline", ERR_WARNING
, "Error compiling expression %s at offset %d: %s", mask
, erroroffset
, error
);
679 newrow
->hint
= pcre_study(newrow
->regex
, 0, &error
);
681 Error("regexgline", ERR_WARNING
, "Error studying expression %s: %s", mask
, error
);
682 pcre_free(newrow
->regex
);
688 if(!protectedatoi(id
, &newrow
->id
))
694 newrow
->mask
= getsstring(mask
, RG_REGEXGLINE_MAX
);
696 Error("regexgline", ERR_WARNING
, "Error allocating memory for mask!");
700 newrow
->setby
= getsstring(setby
, ACCOUNTLEN
);
702 Error("regexgline", ERR_WARNING
, "Error allocating memory for setby!");
706 newrow
->reason
= getsstring(reason
, RG_REASON_MAX
);
707 if(!newrow
->reason
) {
708 Error("regexgline", ERR_WARNING
, "Error allocating memory for reason!");
712 if(!protectedatoi(type
, &newrow
->type
))
713 newrow
->type
= 0; /* just in case */
715 snprintf(glineiddata
, sizeof(glineiddata
), "%s regexgline %s %s %s %d %d", mynumeric
->content
, mask
, setby
, reason
, iexpires
, newrow
->type
);
716 newrow
->glineid
= crc32(glineiddata
);
723 freesstring(newrow
->mask
);
725 freesstring(newrow
->setby
);
727 freesstring(newrow
->reason
);
728 pcre_free(newrow
->regex
);
730 pcre_free(newrow
->hint
);
733 for(lp
=NULL
,cp
=rg_list
;cp
;lp
=cp
,cp
=cp
->next
) {
747 void rg_dogline(struct rg_glinelist
*gll
, nick
*np
, struct rg_struct
*rp
, char *matched
) { /* PPA: if multiple users match the same user@host or *@host it'll send multiple glines?! */
748 char hostname
[RG_MASKLEN
];
756 for(usercount
=0,tnp
=np
->host
->nicks
;tnp
;tnp
=tnp
->nextbyhost
)
757 if(!ircd_strcmp(np
->ident
, tnp
->ident
))
760 snprintf(hostname
, sizeof(hostname
), "%s@%s", np
->ident
, IPtostr(np
->ipaddress
));
761 } else if (rp
->type
== 2) {
762 usercount
= np
->host
->clonecount
;
763 snprintf(hostname
, sizeof(hostname
), "*@%s", IPtostr(np
->ipaddress
));
766 if ((rp
->type
== 3) || (usercount
> rg_max_per_gline
)) {
767 struct rg_glinenode
*nn
= (struct rg_glinenode
*)malloc(sizeof(struct rg_glinenode
));
784 irc_send("%s GL * +%s %d :%s (ID: %08lx)\r\n", mynumeric
->content
, hostname
, rg_expiry_time
, rp
->reason
->content
, rp
->glineid
);
787 void rg_logevent(nick
*np
, char *event
, char *details
, ...) {
788 char eeevent
[RG_QUERY_BUF_SIZE
], eedetails
[RG_QUERY_BUF_SIZE
], eemask
[RG_QUERY_BUF_SIZE
], eeaccount
[RG_QUERY_BUF_SIZE
];
789 char buf
[513], account
[ACCOUNTLEN
+ 1], mask
[RG_MASKLEN
];
794 va_start(va
, details
);
795 vsnprintf(buf
, sizeof(buf
), details
, va
);
800 strncpy(account
, np
->authname
, sizeof(account
) - 1);
801 account
[sizeof(account
) - 1] = '\0';
805 masklen
= RGBuildHostname(mask
, np
);
811 rg_sqlescape_string(eeevent
, event
, strlen(event
));
812 rg_sqlescape_string(eedetails
, buf
, strlen(buf
));
813 rg_sqlescape_string(eeaccount
, event
, strlen(account
));
814 rg_sqlescape_string(eemask
, mask
, masklen
);
816 rg_sqlquery("INSERT INTO regexlogs (host, account, event, arg) VALUES ('%s', '%s', '%s', '%s')", eemask
, eeaccount
, eeevent
, eedetails
);
819 void rg_loggline(struct rg_struct
*rg
, nick
*np
) {
820 char eenick
[RG_QUERY_BUF_SIZE
], eeuser
[RG_QUERY_BUF_SIZE
], eehost
[RG_QUERY_BUF_SIZE
], eereal
[RG_QUERY_BUF_SIZE
];
822 rg_sqlescape_string(eenick
, np
->nick
, strlen(np
->nick
));
823 rg_sqlescape_string(eeuser
, np
->ident
, strlen(np
->ident
));
824 rg_sqlescape_string(eehost
, np
->host
->name
->content
, strlen(np
->host
->name
->content
));
825 rg_sqlescape_string(eereal
, np
->realname
->name
->content
, strlen(np
->realname
->name
->content
));
827 rg_sqlquery("INSERT INTO regexglinelog (glineid, nickname, username, hostname, realname) VALUES (%d, '%s', '%s', '%s', '%s')", rg
->id
, eenick
, eeuser
, eehost
, eereal
);