| 1 |
pippijn |
1.6 |
/** |
| 2 |
|
|
* delete.C: This file contains code for the Memoserv DELETE function |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 5 |
|
|
* Rights to this code are as documented in COPYING. |
| 6 |
|
|
* |
| 7 |
|
|
* |
| 8 |
|
|
* Portions of this file were derived from sources bearing the following license: |
| 9 |
pippijn |
1.4 |
* Copyright © 2005 Atheme Development Group |
| 10 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 11 |
pippijn |
1.1 |
* |
| 12 |
pippijn |
1.7 |
* $Id: delete.C,v 1.6 2007-09-16 18:54:43 pippijn Exp $ |
| 13 |
pippijn |
1.1 |
*/ |
| 14 |
|
|
|
| 15 |
|
|
#include "atheme.h" |
| 16 |
pippijn |
1.4 |
#include <ermyth/module.h> |
| 17 |
pippijn |
1.1 |
#include <account/myuser.h> |
| 18 |
|
|
#include <account/mymemo.h> |
| 19 |
|
|
|
| 20 |
pippijn |
1.7 |
static char const rcsid[] = "$Id: delete.C,v 1.6 2007-09-16 18:54:43 pippijn Exp $"; |
| 21 |
pippijn |
1.1 |
|
| 22 |
pippijn |
1.7 |
REGISTER_MODULE ("memoserv/delete", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
| 23 |
pippijn |
1.1 |
|
| 24 |
|
|
static void ms_cmd_delete (sourceinfo_t *si, int parc, char *parv[]); |
| 25 |
|
|
|
| 26 |
pippijn |
1.4 |
command_t const ms_delete = { "DELETE", N_("Deletes memos."), AC_NONE, 1, ms_cmd_delete }; |
| 27 |
|
|
command_t const ms_del = { "DEL", N_("Alias for DELETE"), AC_NONE, 1, ms_cmd_delete }; |
| 28 |
pippijn |
1.1 |
|
| 29 |
pippijn |
1.4 |
E cmdvec ms_cmdtree; |
| 30 |
|
|
E helpvec ms_helptree; |
| 31 |
pippijn |
1.1 |
|
| 32 |
pippijn |
1.4 |
bool |
| 33 |
|
|
_modinit (module *m) |
| 34 |
pippijn |
1.1 |
{ |
| 35 |
|
|
ms_cmdtree << ms_delete; |
| 36 |
|
|
ms_cmdtree << ms_del; |
| 37 |
|
|
help_addentry (ms_helptree, "DELETE", "help/memoserv/delete", NULL); |
| 38 |
pippijn |
1.4 |
|
| 39 |
|
|
return true; |
| 40 |
pippijn |
1.1 |
} |
| 41 |
|
|
|
| 42 |
|
|
void |
| 43 |
|
|
_moddeinit () |
| 44 |
|
|
{ |
| 45 |
|
|
ms_cmdtree >> ms_delete; |
| 46 |
|
|
ms_cmdtree >> ms_del; |
| 47 |
|
|
help_delentry (ms_helptree, "DELETE"); |
| 48 |
|
|
} |
| 49 |
|
|
|
| 50 |
|
|
static void |
| 51 |
|
|
ms_cmd_delete (sourceinfo_t *si, int parc, char *parv[]) |
| 52 |
|
|
{ |
| 53 |
|
|
/* Misc structs etc */ |
| 54 |
|
|
unsigned memonum = 0, deleteall = 0; |
| 55 |
|
|
mymemo_t *memo; |
| 56 |
|
|
std::vector<mymemo_t *> mortals; |
| 57 |
|
|
|
| 58 |
|
|
/* We only take 1 arg, and we ignore all others */ |
| 59 |
|
|
char *arg1 = parv[0]; |
| 60 |
|
|
|
| 61 |
|
|
/* Does the arg exist? */ |
| 62 |
|
|
if (!arg1) |
| 63 |
|
|
{ |
| 64 |
pippijn |
1.5 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "DELETE"); |
| 65 |
pippijn |
1.1 |
|
| 66 |
pippijn |
1.5 |
command_fail (si, fault::needmoreparams, _("Syntax: DELETE ALL|message id")); |
| 67 |
pippijn |
1.1 |
return; |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
|
|
/* user logged in? */ |
| 71 |
|
|
if (si->smu == NULL) |
| 72 |
|
|
{ |
| 73 |
pippijn |
1.5 |
command_fail (si, fault::noprivs, _("You are not logged in.")); |
| 74 |
pippijn |
1.1 |
return; |
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
|
|
/* Do we have any memos? */ |
| 78 |
|
|
if (si->smu->memos.empty ()) |
| 79 |
|
|
{ |
| 80 |
pippijn |
1.5 |
command_fail (si, fault::nochange, _("You have no memos to delete.")); |
| 81 |
pippijn |
1.1 |
return; |
| 82 |
|
|
} |
| 83 |
|
|
|
| 84 |
|
|
/* Do we want to delete all memos? */ |
| 85 |
|
|
if (!strcasecmp ("all", arg1)) |
| 86 |
|
|
deleteall = 1; |
| 87 |
|
|
else |
| 88 |
|
|
{ |
| 89 |
|
|
memonum = atoi (arg1); |
| 90 |
|
|
|
| 91 |
|
|
/* Make sure they didn't slip us an alphabetic index */ |
| 92 |
|
|
if (!memonum) |
| 93 |
|
|
{ |
| 94 |
pippijn |
1.5 |
command_fail (si, fault::badparams, _("Invalid message index.")); |
| 95 |
pippijn |
1.1 |
return; |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
/* If int, does that index exist? And do we have something to delete? */ |
| 99 |
|
|
if (memonum > si->smu->memos.size ()) |
| 100 |
|
|
{ |
| 101 |
pippijn |
1.5 |
command_fail (si, fault::nosuch_key, _("The specified memo doesn't exist.")); |
| 102 |
pippijn |
1.1 |
return; |
| 103 |
|
|
} |
| 104 |
|
|
} |
| 105 |
|
|
|
| 106 |
|
|
/* Iterate through memos, doing deletion */ |
| 107 |
|
|
if (deleteall) |
| 108 |
|
|
{ |
| 109 |
|
|
int delcount = 0; |
| 110 |
|
|
while (!si->smu->memos.empty ()) |
| 111 |
|
|
{ |
| 112 |
|
|
memo = si->smu->memos.back (); |
| 113 |
|
|
si->smu->memos.erase (memo); |
| 114 |
pippijn |
1.4 |
delete memo; |
| 115 |
pippijn |
1.1 |
|
| 116 |
|
|
++delcount; |
| 117 |
|
|
} |
| 118 |
|
|
|
| 119 |
|
|
command_success_nodata (si, ngettext (N_("%d memo deleted."), N_("%d memos deleted."), delcount), delcount); |
| 120 |
|
|
|
| 121 |
|
|
return; |
| 122 |
|
|
} |
| 123 |
|
|
|
| 124 |
|
|
memo = si->smu->memos[memonum - 1]; |
| 125 |
|
|
if (!(memo->status & MEMO_READ)) |
| 126 |
|
|
si->smu->memoct_new--; |
| 127 |
|
|
|
| 128 |
|
|
si->smu->memos.erase (memo); |
| 129 |
pippijn |
1.4 |
delete memo; |
| 130 |
pippijn |
1.1 |
|
| 131 |
|
|
command_success_nodata (si, _("%d memo deleted."), 1); |
| 132 |
|
|
|
| 133 |
|
|
return; |
| 134 |
|
|
} |