#include <string.h>
#include <stdio.h>
#include <unistd.h>
+#include "../lib/version.h"
+
+MODULE_VERSION(QVERSION)
#define CSG_BUFSIZE 1024
-#define CSG_MAXSTARTPOINT 21
+#define CSG_MAXSTARTPOINT 30
pcre *csg_curpat; /* Compiled pattern from pcre */
int csg_curfile; /* Which logfile is being searched */
#endif
void _init() {
- chanservaddcommand("grep", QCMD_OPER, 1, csg_dogrep, "Searches the logs.","");
- chanservaddcommand("rgrep", QCMD_OPER, 1, csg_dorgrep, "Searches the logs in reverse order.","");
+ chanservaddcommand("grep", QCMD_OPER, 1, csg_dogrep, "Searches the logs.","Usage: GREP <regex>\nSearches the logs. The current logfile will be specified first, followed by\nall older logfiles found. This will shuffle the order of results slightly. Where:\nregex - regular expression to search for.\nNote: For a case insensitive search, prepend (?i) to the regex.");
+ chanservaddcommand("rgrep", QCMD_OPER, 2, csg_dorgrep, "Searches the logs in reverse order.","Usage: RGREP <days> <regex>\nSearches the logs. The oldest specified log will be specified first meaning\nthat all events returned will be in strict chronological order. Where:\ndays - number of days of history to search\nregex - regex to search for\nNote: For a case insensitive search, prepend (?i) to the regex.");
}
void _fini() {
int csg_dogrep(void *source, int cargc, char **cargv) {
nick *sender=source;
+ reguser *rup=getreguserfromnick(sender);
+
+ if (!rup)
+ return CMD_ERROR;
if (cargc<1) {
chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "grep");
csg_curfile=0;
csg_direction=0;
+
+ chanservwallmessage("%s (%s) used GREP %s", sender->nick, rup->username, cargv[0]);
+ cs_log(sender, "GREP %s", cargv[0]);
+
return csg_execgrep(sender, cargv[0]);
}
int csg_dorgrep(void *source, int cargc, char **cargv) {
int startpoint;
nick *sender=source;
+ reguser *rup=getreguserfromnick(sender);
+
+ if (!rup)
+ return CMD_ERROR;
if (cargc<2) {
chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "rgrep");
return CMD_ERROR;
}
+ chanservwallmessage("%s (%s) used RGREP %s %s", sender->nick, rup->username, cargv[0], cargv[1]);
+ cs_log(sender, "RGREP %s %s", cargv[0], cargv[1]);
+
csg_curfile=startpoint;
csg_direction=1;
return csg_execgrep(sender, cargv[1]);
csg_curfile--;
if (csg_curfile<0) {
chanservstdmessage(np, QM_ENDOFLIST);
+ free(csg_curpat);
+ csg_maxmatches=0;
return;
} else if (csg_curfile==0) {
sprintf(filename,"chanservlog");
if (!pcre_exec(csg_curpat, NULL, linestart, strlen(linestart), 0, 0, NULL, 0)) {
chanservsendmessage(np, "%s", linestart);
if (++csg_matches >= csg_maxmatches) {
+ chanservstdmessage(np, QM_TRUNCATED, csg_maxmatches);
chanservstdmessage(np, QM_ENDOFLIST);
free(csg_curpat);
deregisterhandler(fd, 1);