ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/memoserv/send.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 SEND function
6     *
7     * $Id: send.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_send_listeners : callback::has_listeners
17     {
18     };
19    
20     ms_send_listeners listeners;
21    
22     DECLARE_MODULE_V1 ("memoserv/send", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
23    
24     static void ms_cmd_send (sourceinfo_t *si, int parc, char *parv[]);
25    
26     command_t ms_send = { "SEND", N_("Sends a memo to a user."),
27     AC_NONE, 2, ms_cmd_send
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_send;
40     help_addentry (ms_helptree, "SEND", "help/memoserv/send", NULL);
41     }
42    
43     void
44     _moddeinit ()
45     {
46     ms_cmdtree >> ms_send;
47     help_delentry (ms_helptree, "SEND");
48     }
49    
50     static void
51     ms_cmd_send (sourceinfo_t *si, int parc, char *parv[])
52     {
53     /* misc structs etc */
54     user_t *tu;
55     myuser_t *tmu;
56     node_t *n;
57     mymemo_t *memo;
58     command_t const *cmd;
59     myuser_t::mzignore_vector::iterator miit, miit_end;
60    
61     /* Grab args */
62     char *target = parv[0];
63     char *m = parv[1];
64    
65     /* Arg validation */
66     if (!target || !m)
67     {
68     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SEND");
69    
70     command_fail (si, fault_needmoreparams, "Syntax: SEND <user> <memo>");
71    
72     return;
73     }
74    
75     /* user logged in? */
76     if (!si->smu)
77     {
78     command_fail (si, fault_noprivs, _("You are not logged in."));
79     return;
80     }
81    
82     if (si->smu->flags & MU_WAITAUTH)
83     {
84     command_fail (si, fault_notverified, _("You need to verify your email address before you may send memos."));
85     return;
86     }
87    
88     /* rate limit it -- jilles */
89     if (NOW - si->smu->memo_ratelimit_time > MEMO_MAX_TIME)
90     si->smu->memo_ratelimit_num = 0;
91     if (si->smu->memo_ratelimit_num > MEMO_MAX_NUM && !has_priv (si, PRIV_FLOOD))
92     {
93     command_fail (si, fault_toomany, _("You have used this command too many times; please wait a while and try again."));
94     return;
95     }
96     si->smu->memo_ratelimit_num++;
97     si->smu->memo_ratelimit_time = NOW;
98    
99     /* Check for memo text length -- includes/common.h */
100     if (strlen (m) >= MEMOLEN)
101     {
102     command_fail (si, fault_badparams, "Please make sure your memo is less than %d characters", MEMOLEN);
103    
104     return;
105     }
106    
107     /* Check to make sure the memo doesn't contain hostile CTCP responses.
108     * realistically, we'll probably want to check the _entire_ message for this... --nenolod
109     */
110     if (*m == '\001')
111     {
112     command_fail (si, fault_badparams, _("Your memo contains invalid characters."));
113     return;
114     }
115    
116     if (*target != '#')
117     {
118     /* See if target is valid */
119     if (!(tmu = myuser_find_ext (target)))
120     {
121     command_fail (si, fault_nosuch_target, "\2%s\2 is not registered.", target);
122    
123     return;
124     }
125    
126     /* Does the user allow memos? --pfish */
127     if (tmu->flags & MU_NOMEMO)
128     {
129     command_fail (si, fault_noprivs, "\2%s\2 does not wish to receive memos.", target);
130    
131     return;
132     }
133    
134     /* Check to make sure target inbox not full */
135     if (tmu->memos.size () >= me.mdlimit)
136     {
137     command_fail (si, fault_toomany, _("%s's inbox is full"), target);
138     logcommand (si, CMDLOG_SET, "failed SEND to %s (target inbox full)", tmu->name);
139     return;
140     }
141    
142    
143     /* Make sure we're not on ignore */
144     for (miit = tmu->memo_ignores.begin (), miit_end = tmu->memo_ignores.end (); miit != miit_end; ++miit)
145     {
146     if (!strcasecmp (*miit, si->smu->name))
147     {
148     logcommand (si, CMDLOG_SET, "failed SEND to %s (on ignore list)", tmu->name);
149     command_success_nodata (si, _("The memo has been successfully sent to \2%s\2."), target);
150     return;
151     }
152     }
153     logcommand (si, CMDLOG_SET, "SEND to %s", tmu->name);
154    
155     /* Malloc and populate struct */
156     memo = static_cast<mymemo_t *> (smalloc (sizeof (mymemo_t)));
157     memo->sent = NOW;
158     memo->status = 0;
159     strlcpy (memo->sender, si->smu->name, NICKLEN);
160     strlcpy (memo->text, m, MEMOLEN);
161    
162     /* Create a linked list node and add to memos */
163     tmu->memos.insert (memo);
164     tmu->memoct_new++;
165    
166     /* Should we email this? */
167     if (tmu->flags & MU_EMAILMEMOS)
168     {
169     if (sendemail (si->su, EMAIL_MEMO, tmu, memo->text))
170     {
171     command_success_nodata (si, _("Your memo has been emailed to \2%s\2."), target);
172     return;
173     }
174     }
175    
176     /* Is the user online? If so, tell them about the new memo. */
177     /* Note: do not disclose other nicks they're logged in with
178     * -- jilles
179     *
180     * Actually, I don't see the point in this at all. If they want this information,
181     * they should use WHOIS. --nenolod
182     */
183     tu = user_find_named (target);
184     if (tu != NULL && tu->myuser == tmu)
185     command_success_nodata (si, _("%s is currently online, and you may talk directly, by sending a private message."), target);
186    
187     if (si->su == NULL || !irccasecmp (si->su->nick, si->smu->name))
188     myuser_notice (memosvs.nick, tmu, "You have a new memo from %s.", si->smu->name);
189     else
190     myuser_notice (memosvs.nick, tmu, "You have a new memo from %s (nick: %s).", si->smu->name, si->su->nick);
191    
192     /* Tell user memo sent */
193     command_success_nodata (si, _("The memo has been successfully sent to \2%s\2."), target);
194     }
195     else
196     {
197     cmd = si->service->cmdtree->find ("SENDOPS");
198     if (cmd != NULL)
199     cmd->exec (si->service, si, parc, parv);
200     else
201     command_fail (si, fault_nosuch_target, _("Channel memos are administratively disabled."));
202     }
203    
204     return;
205     }