]> jfr.im git - irc/quakenet/snircd.git/blob - ircd/ircd_reply.c
Update my e-mail address.
[irc/quakenet/snircd.git] / ircd / ircd_reply.c
1 /*
2 * IRC - Internet Relay Chat, ircd/m_proto.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
5 *
6 * See file AUTHORS in IRC package for additional names of
7 * the programmers.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23 /** @file
24 * @brief Implementation of functions to send common replies to users.
25 * @version $Id: ircd_reply.c,v 1.22.2.1 2007/02/04 04:16:16 entrope Exp $
26 */
27 #include "config.h"
28
29 #include "ircd_reply.h"
30 #include "client.h"
31 #include "ircd.h"
32 #include "ircd_log.h"
33 #include "ircd_snprintf.h"
34 #include "msg.h"
35 #include "msgq.h"
36 #include "numeric.h"
37 #include "s_conf.h"
38 #include "s_debug.h"
39 #include "send.h"
40
41 /* #include <assert.h> -- Now using assert in ircd_log.h */
42 #include <string.h>
43
44 /** Report a protocol violation warning to anyone listening. This can
45 * be easily used to clean up the last couple of parts of the code.
46 * @param[in] cptr Client that violated the protocol.
47 * @param[in] pattern Description of how the protocol was violated.
48 * @return Zero.
49 */
50 int protocol_violation(struct Client* cptr, const char* pattern, ...)
51 {
52 struct VarData vd;
53 char message[BUFSIZE];
54
55 assert(pattern);
56 assert(cptr);
57
58 vd.vd_format = pattern;
59 va_start(vd.vd_args, pattern);
60 ircd_snprintf(NULL, message, sizeof(message),
61 "Protocol Violation from %s: %v", cli_name(cptr), &vd);
62 va_end(vd.vd_args);
63
64 sendwallto_group_butone(&me, WALL_DESYNCH, NULL, "%s", message);
65 return 0;
66 }
67
68 /** Inform a client that they need to provide more parameters.
69 * @param[in] cptr Taciturn client.
70 * @param[in] cmd Command name.
71 * @return Zero.
72 */
73 int need_more_params(struct Client* cptr, const char* cmd)
74 {
75 send_reply(cptr, ERR_NEEDMOREPARAMS, cmd);
76 return 0;
77 }
78
79 /** Send a generic reply to a user.
80 * @param[in] to Client that wants a reply.
81 * @param[in] reply Numeric of message to send.
82 * @return Zero.
83 */
84 int send_reply(struct Client *to, int reply, ...)
85 {
86 struct VarData vd;
87 struct MsgBuf *mb;
88 const struct Numeric *num;
89
90 assert(0 != to);
91 assert(0 != reply);
92
93 num = get_error_numeric(reply & ~SND_EXPLICIT); /* get reply... */
94
95 va_start(vd.vd_args, reply);
96
97 if (reply & SND_EXPLICIT) /* get right pattern */
98 vd.vd_format = (const char *) va_arg(vd.vd_args, char *);
99 else
100 vd.vd_format = num->format;
101
102 assert(0 != vd.vd_format);
103
104 /* build buffer */
105 mb = msgq_make(cli_from(to), "%:#C %s %C %v", &me, num->str, to, &vd);
106
107 va_end(vd.vd_args);
108
109 /* send it to the user */
110 send_buffer(to, mb, 0);
111
112 msgq_clean(mb);
113
114 return 0; /* convenience return */
115 }
116
117
118