ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_encap.c
Revision: 470
Committed: Fri Feb 17 05:07:43 2006 UTC (20 years, 5 months ago) by db
Content type: text/x-csrc
File size: 3976 byte(s)
Log Message:
- fix compile errors with moved modules.h
- fix a few missing includes, msg.h and parse.h


File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_encap.c: encapsulated command propagation and parsing
4     *
5     * Copyright (C) 2003 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "handlers.h"
27     #include "client.h"
28     #include "msg.h"
29     #include "parse.h"
30     #include "s_serv.h"
31     #include "send.h"
32 db 470 #include "conf/modules.h"
33 adx 30
34     static void ms_encap(struct Client *, struct Client *, int, char *[]);
35    
36     struct Message encap_msgtab = {
37     "ENCAP", 0, 0, 3, 0, MFLG_SLOW, 0,
38 michael 350 { m_ignore, m_ignore, ms_encap, m_ignore, m_ignore, m_ignore }
39 adx 30 };
40    
41 adx 442 INIT_MODULE(m_encap, "$Revision$")
42 adx 30 {
43     mod_add_cmd(&encap_msgtab);
44     add_capability("ENCAP", CAP_ENCAP, 1);
45     }
46    
47 adx 442 CLEANUP_MODULE
48 adx 30 {
49 adx 442 delete_capability("ENCAP");
50 adx 30 mod_del_cmd(&encap_msgtab);
51     }
52    
53 michael 350 /*! \brief ENCAP command handler (called for servers only)
54 adx 30 *
55 michael 350 * propagates subcommand to locally connected servers
56     *
57     * \param client_p Pointer to allocated Client struct with physical connection
58     * to this server, i.e. with an open socket connected.
59     * \param source_p Pointer to allocated Client struct from which the message
60     * originally comes from. This can be a local or remote client.
61     * \param parc Integer holding the number of supplied arguments.
62     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
63     * pointers.
64     * \note Valid arguments for this command are:
65     * - parv[0] = sender prefix
66     * - parv[1] = target server
67     * - parv[2] = subcommand
68     * - parv[3] .. parv[parc-1] = parameters
69 adx 30 */
70     static void
71     ms_encap(struct Client *client_p, struct Client *source_p,
72     int parc, char *parv[])
73     {
74     char buffer[IRCD_BUFSIZE], *ptr = buffer;
75     unsigned int cur_len = 0, len, i;
76     int paramcount, mpara = 0;
77     struct Message *mptr = NULL;
78     MessageHandler handler = 0;
79    
80     for (i = 1; i < (unsigned int)parc - 1; i++)
81     {
82     len = strlen(parv[i]) + 1;
83    
84     if ((cur_len + len) >= sizeof(buffer))
85     return;
86    
87     ircsprintf(ptr, "%s ", parv[i]);
88     cur_len += len;
89     ptr += len;
90     }
91    
92     len = strlen(parv[i]);
93    
94     /*
95     * if the final parameter crosses our buffer size, should we bail,
96     * like the rest, or should we truncate? ratbox seems to think truncate,
97     * so i'll do that for now until i can talk to lee. -bill
98     */
99     if (parc == 3)
100     ircsprintf(ptr, "%s", parv[2]);
101     else
102     ircsprintf(ptr, ":%s", parv[parc-1]);
103    
104     if ((cur_len + len) >= sizeof(buffer))
105     buffer[sizeof(buffer)-1] = '\0';
106    
107     sendto_match_servs(source_p, parv[1], CAP_ENCAP,
108     "ENCAP %s", buffer);
109    
110     if (!match(parv[1], me.name))
111     return;
112    
113     if ((mptr = find_command(parv[2])) == NULL)
114     return;
115    
116     paramcount = mptr->parameters;
117     mpara = mptr->maxpara;
118    
119     mptr->bytes += strlen(buffer);
120    
121     /*
122     * yes this is an ugly hack, but it is quicker than copying the entire array again
123     * note: this hack wouldnt be needed if parv[0] were set to the command name, rather
124     * than being derived from the prefix, as it should have been from the beginning.
125     */
126     ptr = parv[0];
127     parv += 2;
128     parc -= 2;
129     parv[0] = ptr;
130    
131     if ((handler = mptr->handlers[ENCAP_HANDLER]) == NULL)
132     return;
133    
134     (*handler)(client_p, source_p, parc, parv);
135     }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision