X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/354b14ea09f3b6c5c4edab5b4fd0553415787196..211567363bd8bfbd70cef81e4208ea02d49ebb55:/newsearch/ns-kill.c diff --git a/newsearch/ns-kill.c b/newsearch/ns-kill.c index 2c8a059e..f0cb2dea 100644 --- a/newsearch/ns-kill.c +++ b/newsearch/ns-kill.c @@ -23,40 +23,42 @@ static const char *defaultreason = "You (%n) have been disconnected for violatin struct kill_localdata { unsigned int marker; int count; - int type; char reason[NSMAX_REASON_LEN]; }; -struct searchNode *kill_parse(searchCtx *ctx, int type, int argc, char **argv) { +struct searchNode *kill_parse(searchCtx *ctx, int argc, char **argv) { struct kill_localdata *localdata; struct searchNode *thenode; - int len; if (!(localdata = (struct kill_localdata *) malloc(sizeof(struct kill_localdata)))) { parseError = "malloc: could not allocate memory for this search."; return NULL; } localdata->count = 0; - localdata->type = type; - if (type == SEARCHTYPE_CHANNEL) + if (ctx->searchcmd == reg_chansearch) localdata->marker = nextchanmarker(); - else + else if (ctx->searchcmd == reg_nicksearch) localdata->marker = nextnickmarker(); + else { + free(localdata); + parseError = "kill: invalid search type"; + return NULL; + } if (argc==1) { - char *p = argv[0]; - if(*p == '\"') - p++; - len = strlcpy(localdata->reason, p, sizeof(localdata->reason)); - if(len >= sizeof(localdata->reason)) { - localdata->reason[sizeof(localdata->reason)-1] = '\0'; - } else { - localdata->reason[len-1] = '\0'; + struct searchNode *reasonstr; + char *p; + if (!(reasonstr=argtoconststr("kill", ctx, argv[0], &p))) { + free(localdata); + return NULL; } - } - else + + strlcpy(localdata->reason, p, sizeof(localdata->reason)); + reasonstr->free(ctx, reasonstr); + } else { strlcpy(localdata->reason, defaultreason, sizeof(localdata->reason)); - + } + if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */ parseError = "malloc: could not allocate memory for this search."; @@ -79,12 +81,11 @@ void *kill_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { localdata = thenode->localdata; - if (localdata->type == SEARCHTYPE_CHANNEL) { + if (ctx->searchcmd == reg_chansearch) { cip = (chanindex *)theinput; cip->marker = localdata->marker; localdata->count += cip->channel->users->totalusers; - } - else { + } else { np = (nick *)theinput; np->marker = localdata->marker; localdata->count++; @@ -112,7 +113,7 @@ void kill_free(searchCtx *ctx, struct searchNode *thenode) { } /* For channel searches, mark up all the nicks in the relevant channels first */ - if (localdata->type == SEARCHTYPE_CHANNEL) { + if (ctx->searchcmd == reg_chansearch) { nickmarker=nextnickmarker(); for (i=0;inext) { @@ -156,7 +157,7 @@ void kill_free(searchCtx *ctx, struct searchNode *thenode) { ctx->reply(senderNSExtern, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe); /* notify opers of the action */ ctx->wall(NL_KICKKILLS, "%s/%s killed %d %s via %s [%d untouched].", senderNSExtern->nick, senderNSExtern->authname, (localdata->count - safe), - (localdata->count - safe) != 1 ? "users" : "user", (localdata->type == SEARCHTYPE_CHANNEL) ? "chansearch" : "nicksearch", safe); + (localdata->count - safe) != 1 ? "users" : "user", (ctx->searchcmd == reg_chansearch) ? "chansearch" : "nicksearch", safe); free(localdata); free(thenode); }