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