ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/delete.C
Revision: 1.5
Committed: Thu Aug 30 19:56:22 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.4: +8 -8 lines
Log Message:
- put faultcodes into their own namespace
- removed old files
- limited header garbage in atheme.h
- macros to inline bools for connection_t::is_*
- put some connection_t functions into the connection_t class

File Contents

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