Author: Isomer <isomer@coders.net>
[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 "numeric.h"
30 #include "s_conf.h"
31 #include "s_debug.h"
32 #include "send.h"
33
34 #include <assert.h>
35 #include <string.h>
36
37 int need_more_params(struct Client* cptr, const char* cmd)
38 {
39   send_reply(cptr, ERR_NEEDMOREPARAMS, cmd);
40   return 0;
41 }
42
43 /*
44  * send_error_to_client - send an error message to a client
45  * I don't know if this function is any faster than the other version
46  * but it is a bit easier to use. It's reentrant until it hits vsendto_one
47  * at least :) --Bleep
48  */
49 int send_error_to_client(struct Client* cptr, int error, ...)
50 {
51   va_list               vl;
52   char                  buf[BUFSIZE];
53   char*                 dest = buf;
54   const char*           src  = me.name;
55   const struct Numeric* num  = get_error_numeric(error);
56
57   assert(0 != cptr);
58   assert(0 != num);
59   /*
60    * prefix
61    */
62   *dest++ = ':';
63   while ((*dest = *src++))
64     ++dest;
65   *dest++ = ' ';
66   /*
67    * numeric
68    */
69   src = num->str;
70   while ((*dest = *src++))
71     ++dest;
72   *dest++ = ' ';
73   /*
74    * client name (nick)
75    */
76   src = cptr->name;
77   while ((*dest = *src++))
78     ++dest;
79   *dest++ = ' ';
80   /*
81    * reply format
82    */
83   strcpy(dest, num->format);
84
85 #if 0
86   Debug((DEBUG_INFO, "send_error_to_client: format: ->%s<-", buf));
87 #endif
88
89   va_start(vl, error);
90   vsendto_one(cptr, buf, vl);
91   va_end(vl);
92   return 0;
93 }
94
95
96 int send_reply(struct Client *to, int reply, ...)
97 {
98   struct VarData vd;
99   char sndbuf[IRC_BUFSIZE];
100   const struct Numeric *num;
101
102   assert(0 != to);
103   assert(0 != reply);
104
105   num = get_error_numeric(reply & ~SND_EXPLICIT); /* get reply... */
106
107   va_start(vd.vd_args, reply);
108
109   if (reply & SND_EXPLICIT) /* get right pattern */
110     vd.vd_format = (const char *) va_arg(vd.vd_args, char *);
111   else
112     vd.vd_format = num->format;
113
114   assert(0 != vd.vd_format);
115
116   /* build buffer */
117   ircd_snprintf(to->from, sndbuf, sizeof(sndbuf) - 2, "%:#C %s %C %v", &me,
118                 num->str, to, &vd);
119
120   va_end(vd.vd_args);
121
122   /* send it to the user */
123   send_buffer(to, sndbuf);
124
125   return 0; /* convenience return */
126 }
127
128 int send_admin_info(struct Client* sptr, const struct ConfItem* admin)
129 {
130   assert(0 != sptr);
131   if (admin) {
132     send_reply(sptr, RPL_ADMINME,    me.name);
133     send_reply(sptr, RPL_ADMINLOC1,  admin->host);
134     send_reply(sptr, RPL_ADMINLOC2,  admin->passwd);
135     send_reply(sptr, RPL_ADMINEMAIL, admin->name);
136   }
137   else
138     send_reply(sptr, ERR_NOADMININFO, me.name);
139   return 0;
140 }
141
142