]> jfr.im git - irc/quakenet/snircd.git/blob - ircd/m_proto.c
Should be unsigned long for A
[irc/quakenet/snircd.git] / ircd / m_proto.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: m_proto.c,v 1.6 2004/12/11 05:13:48 klmitch Exp $
24 */
25 #include "config.h"
26
27 #include "client.h"
28 #include "ircd.h"
29 #include "ircd_alloc.h"
30 #include "ircd_chattr.h"
31 #include "ircd_log.h"
32 #include "ircd_reply.h"
33 #include "ircd_string.h"
34 #include "msg.h"
35 #include "numeric.h"
36 #include "numnicks.h"
37 #include "s_debug.h"
38 #include "s_misc.h"
39 #include "send.h"
40 #include "supported.h"
41 #include "version.h"
42
43 /* #include <assert.h> -- Now using assert in ircd_log.h */
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47
48 /*
49 * m_functions execute protocol messages on this server:
50 *
51 * cptr is always NON-NULL, pointing to a *LOCAL* client
52 * structure (with an open socket connected!). This
53 * identifies the physical socket where the message
54 * originated (or which caused the m_function to be
55 * executed--some m_functions may call others...).
56 *
57 * sptr is the source of the message, defined by the
58 * prefix part of the message if present. If not
59 * or prefix not found, then sptr==cptr.
60 *
61 * (!IsServer(cptr)) => (cptr == sptr), because
62 * prefixes are taken *only* from servers...
63 *
64 * (IsServer(cptr))
65 * (sptr == cptr) => the message didn't
66 * have the prefix.
67 *
68 * (sptr != cptr && IsServer(sptr) means
69 * the prefix specified servername. (?)
70 *
71 * (sptr != cptr && !IsServer(sptr) means
72 * that message originated from a remote
73 * user (not local).
74 *
75 * combining
76 *
77 * (!IsServer(sptr)) means that, sptr can safely
78 * taken as defining the target structure of the
79 * message in this server.
80 *
81 * *Always* true (if 'parse' and others are working correct):
82 *
83 * 1) sptr->from == cptr (note: cptr->from == cptr)
84 *
85 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
86 * *cannot* be a local connection, unless it's
87 * actually cptr!). [MyConnect(x) should probably
88 * be defined as (x == x->from) --msa ]
89 *
90 * parc number of variable parameter strings (if zero,
91 * parv is allowed to be NULL)
92 *
93 * parv a NULL terminated list of parameter pointers,
94 *
95 * parv[0], sender (prefix string), if not present
96 * this points to an empty string.
97 * parv[1]...parv[parc-1]
98 * pointers to additional parameters
99 * parv[parc] == NULL, *always*
100 *
101 * note: it is guaranteed that parv[0]..parv[parc-1] are all
102 * non-NULL pointers.
103 */
104
105 static const char* const PROTO_REQ = "REQ";
106 static const char* const PROTO_ACK = "ACK";
107 static const char* const PROTO_SUP = "SUP";
108
109 int proto_handle_ack(struct Client* cptr, const char* msg)
110 {
111 /*
112 * handle ack here, if option and args supported
113 * start option
114 */
115 return 0;
116 }
117
118 int proto_handle_req(struct Client* cptr, const char* msg)
119 {
120 /*
121 * handle request here if not supported args send
122 * option info. otherwise send ack
123 */
124 return 0;
125 }
126
127 int proto_send_supported(struct Client* cptr)
128 {
129 /*
130 * send_reply(cptr, RPL_PROTOLIST, "stuff");
131 */
132 sendcmdto_one(&me,CMD_PROTO,cptr,"%s unet1 1 1",PROTO_SUP);
133 return 0;
134 }
135
136 int m_proto(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
137 {
138 if (0 == parc)
139 return proto_send_supported(cptr);
140
141 if (parc < 3)
142 return need_more_params(sptr, "PROTO");
143
144 if (0 == ircd_strcmp(PROTO_REQ, parv[1]))
145 return proto_handle_req(cptr, parv[2]);
146
147 else if (0 == ircd_strcmp(PROTO_ACK, parv[1]))
148 return proto_handle_ack(cptr, parv[2]);
149
150 else if (0 == ircd_strcmp(PROTO_SUP, parv[1]))
151 return 0; /* ignore it */
152
153 return 0;
154 }
155
156