X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/16319f7c24f37e46b87e29c0fb5ac4f8a86cc2c2..78546f2b0f59b5c8fede1ce5535972716eb17041:/newsearch/ns-notice.c?ds=sidebyside diff --git a/newsearch/ns-notice.c b/newsearch/ns-notice.c index dfd0121f..00e9e035 100644 --- a/newsearch/ns-notice.c +++ b/newsearch/ns-notice.c @@ -16,50 +16,48 @@ extern nick *senderNSExtern; -void *notice_exe(struct searchNode *thenode, void *theinput); -void notice_free(struct searchNode *thenode); +void *notice_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput); +void notice_free(searchCtx *ctx, struct searchNode *thenode); struct notice_localdata { unsigned int marker; int count; - int type; char message[NSMAX_NOTICE_LEN]; }; -struct searchNode *notice_parse(int type, int argc, char **argv) { +struct searchNode *notice_parse(searchCtx *ctx, int argc, char **argv) { struct notice_localdata *localdata; - struct searchNode *thenode; - int len; - + struct searchNode *thenode, *message; + char *p; + if (!(localdata = (struct notice_localdata *) malloc(sizeof(struct notice_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(); - - if (argc==1) { - char *p = argv[0]; - if(*p == '\"') - p++; - len = strlcpy(localdata->message, p, sizeof(localdata->message)); - if(len >= sizeof(localdata->message)) { - localdata->message[sizeof(localdata->message)-1] = '\0'; - } else { - localdata->message[len-1] = '\0'; - } - } else { - /* no notice to send out ... */ - parseError = "Warning: you did not specify a message to notice out."; + free(localdata); + parseError = "notice: invalid search type"; + return NULL; + } + if (argc!=1) { + parseError = "notice: warning: you did not specify a message to notice out."; free(localdata); return NULL; } + if (!(message=argtoconststr("notice", ctx, argv[0], &p))) { + free(localdata); + return NULL; + } + + strlcpy(localdata->message, p, sizeof(localdata->message)); + (message->free)(ctx, message); + 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."; @@ -75,14 +73,14 @@ struct searchNode *notice_parse(int type, int argc, char **argv) { return thenode; } -void *notice_exe(struct searchNode *thenode, void *theinput) { +void *notice_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) { struct notice_localdata *localdata; nick *np; chanindex *cip; 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; @@ -96,7 +94,7 @@ void *notice_exe(struct searchNode *thenode, void *theinput) { return (void *)1; } -void notice_free(struct searchNode *thenode) { +void notice_free(searchCtx *ctx, struct searchNode *thenode) { struct notice_localdata *localdata; nick *np, *nnp; chanindex *cip, *ncip; @@ -105,7 +103,7 @@ void notice_free(struct searchNode *thenode) { localdata = thenode->localdata; - if (localdata->type == SEARCHTYPE_CHANNEL) { + if (ctx->searchcmd == reg_chansearch) { nickmarker=nextnickmarker(); for (i=0;inext; if (np->marker == nickmarker) - controlnotice(np, localdata->message); + controlnotice(np, "%s", localdata->message); } } } @@ -134,12 +132,12 @@ void notice_free(struct searchNode *thenode) { for (np=nicktable[i];np;np=nnp) { nnp = np->next; if (np->marker == localdata->marker) - controlnotice(np, localdata->message); + controlnotice(np, "%s", localdata->message); } } } /* notify opers of the action */ - controlwall(NO_OPER, NL_BROADCASTS, "%s/%s sent the following message to %d %s: %s", senderNSExtern->nick, senderNSExtern->authname, localdata->count, localdata->count != 1 ? "users" : "user", localdata->message); + ctx->wall(NL_BROADCASTS, "%s/%s sent the following message to %d %s: %s", senderNSExtern->nick, senderNSExtern->authname, localdata->count, localdata->count != 1 ? "users" : "user", localdata->message); free(localdata); free(thenode); }