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