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;
else if (ctx->searchcmd == reg_nicksearch)
localdata->marker = nextnickmarker();
else {
+ free(localdata);
parseError = "notice: invalid search type";
return NULL;
}
- 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.";
+ 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.";