From: splidge Date: Tue, 5 May 2009 14:01:01 +0000 (+0100) Subject: PARSER: Added "calls" field to allow tracking how many times each command is X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/commitdiff_plain/09285ac1755e7867dfdb6a10c9e727b208f6b20f PARSER: Added "calls" field to allow tracking how many times each command is called. Used this field to add partial "stats m" functionality to the IRC module (we don't count bytes so bytes is always returned as 0). --- diff --git a/irc/irc.c b/irc/irc.c index 4f3ae431..932d067e 100644 --- a/irc/irc.c +++ b/irc/irc.c @@ -448,6 +448,7 @@ int parseline() { return 0; } for (;c!=NULL;c=c->next) { + c->calls++; if (((c->handler)("INIT",cargc-1,&cargv[1]))==CMD_LAST) return 0; } @@ -457,6 +458,7 @@ int parseline() { long numeric = strtol(cargv[1], NULL, 0); if((numeric >= MIN_NUMERIC) && (numeric <= MAX_NUMERIC)) { for(c=numericcommands[numeric];c;c=c->next) { + c->calls++; if (((c->handler)((void *)numeric,cargc,cargv))==CMD_LAST) return 0; } @@ -467,6 +469,7 @@ int parseline() { return 0; } for (;c!=NULL;c=c->next) { + c->calls++; if (((c->handler)(cargv[0],cargc-2,cargv+2))==CMD_LAST) return 0; } @@ -602,3 +605,13 @@ void ircstats(int hooknum, void *arg) { triggerhook(HOOK_CORE_STATSREPLY,buf); } } +void stats_m(char *str1, char *str2) { + Command *cmds[500]; + unsigned int c,i; + + c=getcommandlist(servercommands,cmds,500); + + for (i=0;icommand->content, cmds[i]->calls); + } +} diff --git a/irc/irc.h b/irc/irc.h index 90b35654..9af90c4d 100644 --- a/irc/irc.h +++ b/irc/irc.h @@ -31,6 +31,7 @@ int deregisternumerichandler(const int numeric, CommandHandler handler); char *getmynumeric(); time_t getnettime(); void setnettime(time_t newtime); +void stats_m(char *, char *); /* Functions from irchandlers.c */ int handleping(void *sender, int cargc, char **cargv); diff --git a/nick/nickhandlers.c b/nick/nickhandlers.c index 4f208a48..86c35905 100644 --- a/nick/nickhandlers.c +++ b/nick/nickhandlers.c @@ -489,7 +489,10 @@ int handlestatsmsg(void *source, int cargc, char **cargv) { case 'P': irc_send(":%s 217 %s P none 0 :0x2000",fromstring,replytarget); break; - + + case 'm': + stats_m(fromstring, replytarget); + break; } irc_send(":%s 219 %s %c :End of /STATS report",fromstring,replytarget,cargv[0][0]); diff --git a/parser/parser.c b/parser/parser.c index 12e46c86..2a814761 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -130,6 +130,7 @@ Command *addcommandexttotree(CommandTree *ct, const char *cmdname, int level, in nc->handler=handler; nc->ext=NULL; nc->next=NULL; + nc->calls=0; nc->destroyext=NULL; if ((c=findcommandintree(ct,cmdname,1))!=NULL) { diff --git a/parser/parser.h b/parser/parser.h index 794d9686..870a9bf8 100644 --- a/parser/parser.h +++ b/parser/parser.h @@ -39,6 +39,7 @@ typedef struct Command { CommandHandler handler; /* Function to deal with the message */ void *ext; /* Pointer to some arbitrary other data */ DestroyExt destroyext; /* Function to destroy ->ext on destroycommandtree (if necessary) */ + unsigned int calls; /* How many times this command has been called */ struct Command *next; /* Next handler chained onto this command */ } Command;