+static NICKSERV_FUNC(cmd_addnote)
+{
+ struct handle_info *hi;
+ unsigned long duration;
+ char text[MAXLEN];
+ unsigned int id;
+ struct handle_note *prev;
+ struct handle_note *note;
+
+ /* Parse parameters and figure out values for note's fields. */
+ NICKSERV_MIN_PARMS(4);
+ hi = get_victim_oper(user, argv[1]);
+ if (!hi)
+ return 0;
+ if(!strcmp(argv[2], "0"))
+ duration = 0;
+ else if(!(duration = ParseInterval(argv[2])))
+ {
+ reply("MSG_INVALID_DURATION", argv[2]);
+ return 0;
+ }
+ if (duration > 2*365*86400) {
+ reply("NSMSG_EXCESSIVE_DURATION", argv[2]);
+ return 0;
+ }
+ unsplit_string(argv + 3, argc - 3, text);
+ WALK_NOTES(hi, prev, note) {}
+ id = prev ? (prev->id + 1) : 1;
+
+ /* Create the new note structure. */
+ note = calloc(1, sizeof(*note) + strlen(text));
+ note->next = NULL;
+ note->expires = duration ? (now + duration) : 0;
+ note->set = now;
+ note->id = id;
+ safestrncpy(note->setter, user->handle_info->handle, sizeof(note->setter));
+ strcpy(note->note, text);
+ if (prev)
+ prev->next = note;
+ else
+ hi->notes = note;
+ reply("NSMSG_NOTE_ADDED", id, hi->handle);
+ return 1;
+}
+
+static NICKSERV_FUNC(cmd_delnote)
+{
+ struct handle_info *hi;
+ struct handle_note *prev;
+ struct handle_note *note;
+ int id;
+
+ NICKSERV_MIN_PARMS(3);
+ hi = get_victim_oper(user, argv[1]);
+ if (!hi)
+ return 0;
+ id = strtoul(argv[2], NULL, 10);
+ WALK_NOTES(hi, prev, note) {
+ if (id == note->id) {
+ if (prev)
+ prev->next = note->next;
+ else
+ hi->notes = note->next;
+ free(note);
+ reply("NSMSG_NOTE_REMOVED", id, hi->handle);
+ return 1;
+ }
+ }
+ reply("NSMSG_NO_SUCH_NOTE", hi->handle, id);
+ return 0;
+}
+