/** * delete.C: This file contains code for the Memoserv DELETE function * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2005 Atheme Development Group * Rights to this code are as documented in doc/pod/license.pod. * * $Id: delete.C,v 1.7 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: delete.C,v 1.7 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("memoserv/delete", false, "The Ermyth Team "); static void ms_cmd_delete (sourceinfo_t *si, int parc, char *parv[]); command_t const ms_delete = { "DELETE", N_("Deletes memos."), AC_NONE, 1, ms_cmd_delete }; command_t const ms_del = { "DEL", N_("Alias for DELETE"), AC_NONE, 1, ms_cmd_delete }; E cmdvec ms_cmdtree; E helpvec ms_helptree; bool _modinit (module *m) { ms_cmdtree << ms_delete; ms_cmdtree << ms_del; help_addentry (ms_helptree, "DELETE", "help/memoserv/delete", NULL); return true; } void _moddeinit () { ms_cmdtree >> ms_delete; ms_cmdtree >> ms_del; help_delentry (ms_helptree, "DELETE"); } static void ms_cmd_delete (sourceinfo_t *si, int parc, char *parv[]) { /* Misc structs etc */ unsigned memonum = 0, deleteall = 0; mymemo_t *memo; std::vector mortals; /* We only take 1 arg, and we ignore all others */ char *arg1 = parv[0]; /* Does the arg exist? */ if (!arg1) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "DELETE"); command_fail (si, fault::needmoreparams, _("Syntax: DELETE ALL|message id")); return; } /* user logged in? */ if (si->smu == NULL) { command_fail (si, fault::noprivs, _("You are not logged in.")); return; } /* Do we have any memos? */ if (si->smu->memos.empty ()) { command_fail (si, fault::nochange, _("You have no memos to delete.")); return; } /* Do we want to delete all memos? */ if (!strcasecmp ("all", arg1)) deleteall = 1; else { memonum = atoi (arg1); /* Make sure they didn't slip us an alphabetic index */ if (!memonum) { command_fail (si, fault::badparams, _("Invalid message index.")); return; } /* If int, does that index exist? And do we have something to delete? */ if (memonum > si->smu->memos.size ()) { command_fail (si, fault::nosuch_key, _("The specified memo doesn't exist.")); return; } } /* Iterate through memos, doing deletion */ if (deleteall) { int delcount = 0; while (!si->smu->memos.empty ()) { memo = si->smu->memos.back (); si->smu->memos.erase (memo); delete memo; ++delcount; } command_success_nodata (si, ngettext (N_("%d memo deleted."), N_("%d memos deleted."), delcount), delcount); return; } memo = si->smu->memos[memonum - 1]; if (!(memo->status & MEMO_READ)) si->smu->memoct_new--; si->smu->memos.erase (memo); delete memo; command_success_nodata (si, _("%d memo deleted."), 1); return; }