Doxyfy ircd_reply.h and ircd_reply.c.
[ircu2.10.12-pk.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$
26  */
27 #include "config.h"
28
29 #include "ircd_reply.h"
30 #include "client.h"
31 #include "ircd.h"
32 #include "ircd_snprintf.h"
33 #include "msg.h"
34 #include "msgq.h"
35 #include "numeric.h"
36 #include "s_conf.h"
37 #include "s_debug.h"
38 #include "send.h"
39
40 #include <assert.h>
41 #include <string.h>
42
43 /** Report a protocol violation warning to anyone listening.  This can
44  * be easily used to clean up the last couple of parts of the code.
45  * @param[in] cptr Client that violated the protocol.
46  * @param[in] pattern Description of how the protocol was violated.
47  * @return Zero.
48  */
49 int protocol_violation(struct Client* cptr, const char* pattern, ...)
50 {
51   struct VarData vd;
52
53   assert(pattern);
54   assert(cptr);
55
56   vd.vd_format = pattern;
57   va_start(vd.vd_args, pattern);
58
59   sendwallto_group_butone(&me, WALL_DESYNCH, NULL,
60                         "Protocol Violation from %s: %v", cli_name(cptr), &vd);
61
62   va_end(vd.vd_args);
63   return 0;
64 }
65
66 /** Inform a client that they need to provide more parameters.
67  * @param[in] cptr Taciturn client.
68  * @param[in] cmd Command name.
69  * @return Zero.
70  */
71 int need_more_params(struct Client* cptr, const char* cmd)
72 {
73   send_reply(cptr, ERR_NEEDMOREPARAMS, cmd);
74   return 0;
75 }
76
77 /** Send a generic reply to a user.
78  * @param[in] to Client that wants a reply.
79  * @param[in] reply Numeric of message to send.
80  * @return Zero.
81  */
82 int send_reply(struct Client *to, int reply, ...)
83 {
84   struct VarData vd;
85   struct MsgBuf *mb;
86   const struct Numeric *num;
87
88   assert(0 != to);
89   assert(0 != reply);
90
91   num = get_error_numeric(reply & ~SND_EXPLICIT); /* get reply... */
92
93   va_start(vd.vd_args, reply);
94
95   if (reply & SND_EXPLICIT) /* get right pattern */
96     vd.vd_format = (const char *) va_arg(vd.vd_args, char *);
97   else
98     vd.vd_format = num->format;
99
100   assert(0 != vd.vd_format);
101
102   /* build buffer */
103   mb = msgq_make(cli_from(to), "%:#C %s %C %v", &me, num->str, to, &vd);
104
105   va_end(vd.vd_args);
106
107   /* send it to the user */
108   send_buffer(to, mb, 0);
109
110   msgq_clean(mb);
111
112   return 0; /* convenience return */
113 }
114
115
116