0a25fe54e6e1e2d7022cf95185f0af133e14c3c0
[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  * $Id$
24  */
25 #include "config.h"
26
27 #include "ircd_reply.h"
28 #include "client.h"
29 #include "ircd.h"
30 #include "ircd_snprintf.h"
31 #include "msg.h"
32 #include "msgq.h"
33 #include "numeric.h"
34 #include "s_conf.h"
35 #include "s_debug.h"
36 #include "send.h"
37
38 #include <assert.h>
39 #include <string.h>
40
41 /* Report a protocol violation warning to anyone listening.  This can be
42  * easily used to cleanup the last couple of parts of the code up.
43  */
44  
45 int protocol_violation(struct Client* cptr, const char* pattern, ...)
46 {
47   struct VarData vd;
48
49   assert(pattern);
50   assert(cptr);
51
52   vd.vd_format = pattern;
53   va_start(vd.vd_args, pattern);
54
55   sendcmdto_flag_butone(&me, CMD_DESYNCH, NULL, FLAGS_DEBUG,
56                         ":Protocol Violation from %s: %v", cli_name(cptr), &vd);
57
58   va_end(vd.vd_args);
59   return 0;
60 }
61
62 int need_more_params(struct Client* cptr, const char* cmd)
63 {
64 #if 0
65   /*
66    * XXX - bug
67    * shouldn't try to do more than one thing at a time,
68    * call protocol_violation explicitly where it's needed and
69    * context is available.
70    */
71   if (!MyUser(cptr))
72     protocol_violation(cptr, "Not enough parameters for %s",cmd);
73 #endif
74   send_reply(cptr, ERR_NEEDMOREPARAMS, cmd);
75   return 0;
76 }
77
78 int send_reply(struct Client *to, int reply, ...)
79 {
80   struct VarData vd;
81   struct MsgBuf *mb;
82   const struct Numeric *num;
83
84   assert(0 != to);
85   assert(0 != reply);
86
87   num = get_error_numeric(reply & ~SND_EXPLICIT); /* get reply... */
88
89   va_start(vd.vd_args, reply);
90
91   if (reply & SND_EXPLICIT) /* get right pattern */
92     vd.vd_format = (const char *) va_arg(vd.vd_args, char *);
93   else
94     vd.vd_format = num->format;
95
96   assert(0 != vd.vd_format);
97
98   /* build buffer */
99   mb = msgq_make(cli_from(to), "%:#C %s %C %v", &me, num->str, to, &vd);
100
101   va_end(vd.vd_args);
102
103   /* send it to the user */
104   send_buffer(to, mb, 0);
105
106   msgq_clean(mb);
107
108   return 0; /* convenience return */
109 }
110
111
112