ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/forward.C
Revision: 1.1
Committed: Thu Jul 19 08:24:54 2007 UTC (19 years, 3 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Log Message:
initial import. the most important changes since Atheme are:
- fixed many memory leaks
- fixed many bugs
- converted to C++ and use more STL containers
- added a (not very enhanced yet) perl module
- greatly improved XML-RPC speed
- added a JSON-RPC module with code from json-cpp
- added a valgrind memcheck module to operserv
- added a more object oriented base64 implementation
- added a specialised unit test framework
- improved stability
- use gettimeofday() if available
- reworked adding/removing commands
- MemoServ IGNORE DEL can now remove indices

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005 Atheme Development Group
3     * Rights to this code are as documented in doc/LICENSE.
4     *
5     * This file contains code for the Memoserv FORWARD function
6     *
7     * $Id: forward.c 8329 2007-05-27 13:31:59Z jilles $
8     */
9    
10     #include "atheme.h"
11     #include <account/myuser.h>
12     #include <account/mymemo.h>
13    
14     static char const rcsid[] = "$Id";
15    
16     struct ms_forward_listeners : callback::has_listeners
17     {
18     };
19    
20     ms_forward_listeners listeners;
21    
22     DECLARE_MODULE_V1 ("memoserv/forward", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
23    
24     static void ms_cmd_forward (sourceinfo_t *si, int parc, char *parv[]);
25    
26     command_t ms_forward = { "FORWARD", N_(N_("Forwards a memo.")),
27     AC_NONE, 2, ms_cmd_forward
28     };
29    
30     cmdvec *ms_cmdtree;
31     helpvec *ms_helptree;
32    
33     void
34     _modinit (module_t *m)
35     {
36     MODULE_USE_SYMBOL_T (ms_cmdtree, cmdvec, "memoserv/main", "ms_cmdtree");
37     MODULE_USE_SYMBOL_T (ms_helptree, helpvec, "memoserv/main", "ms_helptree");
38    
39     ms_cmdtree << ms_forward;
40     help_addentry (ms_helptree, "forward", "help/memoserv/forward", NULL);
41     }
42    
43     void
44     _moddeinit ()
45     {
46     ms_cmdtree >> ms_forward;
47     help_delentry (ms_helptree, "FORWARD");
48     }
49    
50     static void
51     ms_cmd_forward (sourceinfo_t *si, int parc, char *parv[])
52     {
53     /* Misc structs etc */
54     user_t *tu;
55     myuser_t *tmu;
56     mymemo_t *memo, *newmemo;
57     node_t *n;
58     unsigned memonum = 0;
59     myuser_t::mzignore_vector::iterator miit, miit_end;
60    
61     /* Grab args */
62     char *target = parv[0];
63     char *arg = parv[1];
64    
65     /* Arg validator */
66     if (!target || !arg)
67     {
68     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FORWARD");
69    
70     command_fail (si, fault_needmoreparams, "Syntax: FORWARD <account> <memo number>");
71    
72     return;
73     }
74     else
75     memonum = atoi (arg);
76    
77     /* user logged in? */
78     if (si->smu == NULL)
79     {
80     command_fail (si, fault_noprivs, _("You are not logged in."));
81     return;
82     }
83    
84     if (si->smu->flags & MU_WAITAUTH)
85     {
86     command_fail (si, fault_notverified, _("You need to verify your email address before you may send memos."));
87     return;
88     }
89    
90     /* Check to see if any memos */
91     if (si->smu->memos.empty ())
92     {
93     command_fail (si, fault_nosuch_key, _("You have no memos to forward."));
94     return;
95     }
96    
97     /* Check to see if target user exists */
98     if (!(tmu = myuser_find_ext (target)))
99     {
100     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), target);
101     return;
102     }
103    
104     /* Make sure target isn't sender */
105     if (si->smu == tmu)
106     {
107     command_fail (si, fault_noprivs, _("You cannot send yourself a memo."));
108     return;
109     }
110    
111     /* Make sure arg is an int */
112     if (!memonum)
113     {
114     command_fail (si, fault_badparams, _("Invalid message index."));
115     return;
116     }
117    
118     /* check if targetuser has nomemo set */
119     if (tmu->flags & MU_NOMEMO)
120     {
121     command_fail (si, fault_noprivs, "\2%s\2 does not wish to receive memos.", target);
122    
123     return;
124     }
125    
126     /* Check to see if memo n exists */
127     if (memonum > si->smu->memos.size ())
128     {
129     command_fail (si, fault_nosuch_key, _("Invalid memo number."));
130     return;
131     }
132    
133     /* Check to make sure target inbox not full */
134     if (tmu->memos.size () >= me.mdlimit)
135     {
136     command_fail (si, fault_toomany, _("Target inbox is full."));
137     logcommand (si, CMDLOG_SET, "failed FORWARD to %s (target inbox full)", tmu->name);
138     return;
139     }
140    
141     /* rate limit it -- jilles */
142     if (NOW - si->smu->memo_ratelimit_time > MEMO_MAX_TIME)
143     si->smu->memo_ratelimit_num = 0;
144     if (si->smu->memo_ratelimit_num > MEMO_MAX_NUM && !has_priv (si, PRIV_FLOOD))
145     {
146     command_fail (si, fault_toomany, _("Too many memos; please wait a while and try again"));
147     return;
148     }
149     si->smu->memo_ratelimit_num++;
150     si->smu->memo_ratelimit_time = NOW;
151    
152     /* Make sure we're not on ignore */
153     for (miit = tmu->memo_ignores.begin (), miit_end = tmu->memo_ignores.end (); miit != miit_end; ++miit)
154     {
155     if (!strcasecmp (*miit, si->smu->name))
156     {
157     /* Lie... change this if you want it to fail silent */
158     logcommand (si, CMDLOG_SET, "failed FORWARD to %s (on ignore list)", tmu->name);
159     command_success_nodata (si, _("The memo has been successfully forwarded to \2%s\2."), target);
160     return;
161     }
162     }
163     logcommand (si, CMDLOG_SET, "FORWARD to %s", tmu->name);
164    
165     /* Go to forwarding memos */
166     memo = si->smu->memos[memonum - 1];
167     newmemo = static_cast<mymemo_t *> (smalloc (sizeof (mymemo_t)));
168    
169     /* Create memo */
170     newmemo->sent = NOW;
171     newmemo->status = 0;
172     strlcpy (newmemo->sender, si->smu->name, NICKLEN);
173     strlcpy (newmemo->text, memo->text, MEMOLEN);
174    
175     /* Create node, add to their linked list of memos */
176     tmu->memos.insert (newmemo);
177     tmu->memoct_new++;
178    
179     /* Should we email this? */
180     if (tmu->flags & MU_EMAILMEMOS)
181     {
182     if (sendemail (si->su, EMAIL_MEMO, tmu, memo->text))
183     {
184     command_success_nodata (si, _("Your memo has been emailed to \2%s\2."), target);
185     return;
186     }
187     }
188    
189     /* Note: do not disclose other nicks they're logged in with
190     * -- jilles */
191     tu = user_find_named (target);
192     if (tu != NULL && tu->myuser == tmu)
193     command_success_nodata (si, _("%s is currently online, and you may talk directly, by sending a private message."), target);
194     if (si->su == NULL || !irccasecmp (si->su->nick, si->smu->name))
195     myuser_notice (memosvs.nick, tmu, "You have a new forwarded memo from %s.", si->smu->name);
196     else
197     myuser_notice (memosvs.nick, tmu, "You have a new forwarded memo from %s (nick: %s).", si->smu->name, si->su->nick);
198    
199     command_success_nodata (si, _("The memo has been successfully forwarded to \2%s\2."), target);
200     return;
201     }