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