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