/[svn]/ircd-hybrid-8/modules/m_encap.c
ViewVC logotype

Annotation of /ircd-hybrid-8/modules/m_encap.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1233 - (hide annotations)
Thu Sep 22 20:53:07 2011 UTC (8 years, 8 months ago) by michael
File MIME type: text/x-chdr
File size: 3621 byte(s)
- replace bunch of ircsprintf with snprintf

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 "sprintf_irc.h"
31     #include "s_serv.h"
32     #include "send.h"
33     #include "modules.h"
34     #include "irc_string.h"
35    
36    
37     /*
38     * ms_encap()
39     *
40     * inputs - destination server, subcommand, parameters
41     * output - none
42     * side effects - propagates subcommand to locally connected servers
43     */
44     static void
45     ms_encap(struct Client *client_p, struct Client *source_p,
46     int parc, char *parv[])
47     {
48     char buffer[IRCD_BUFSIZE], *ptr = buffer;
49     unsigned int cur_len = 0, len, i;
50     int paramcount, mpara = 0;
51     struct Message *mptr = NULL;
52     MessageHandler handler = 0;
53    
54     for (i = 1; i < (unsigned int)parc - 1; i++)
55     {
56     len = strlen(parv[i]) + 1;
57    
58     if ((cur_len + len) >= sizeof(buffer))
59     return;
60    
61 michael 1233 snprintf(ptr, sizeof(buffer) - cur_len, "%s ", parv[i]);
62 adx 30 cur_len += len;
63     ptr += len;
64     }
65    
66     len = strlen(parv[i]);
67    
68     /*
69     * if the final parameter crosses our buffer size, should we bail,
70     * like the rest, or should we truncate? ratbox seems to think truncate,
71     * so i'll do that for now until i can talk to lee. -bill
72     */
73    
74     if (parc == 3)
75 michael 1233 snprintf(ptr, sizeof(buffer) - cur_len, "%s", parv[2]);
76 adx 30 else
77 michael 1233 snprintf(ptr, sizeof(buffer) - cur_len, ":%s", parv[parc - 1]);
78 adx 30
79     if ((cur_len + len) >= sizeof(buffer))
80 michael 1233 buffer[sizeof(buffer) - 1] = '\0';
81 adx 30
82     sendto_match_servs(source_p, parv[1], CAP_ENCAP,
83     "ENCAP %s", buffer);
84    
85     if (!match(parv[1], me.name))
86     return;
87    
88     if ((mptr = find_command(parv[2])) == NULL)
89     return;
90    
91 michael 1178 #ifdef NOT_USED_YET
92 adx 30 paramcount = mptr->parameters;
93     mpara = mptr->maxpara;
94 michael 1178 #endif
95 adx 30 mptr->bytes += strlen(buffer);
96    
97     /*
98     * yes this is an ugly hack, but it is quicker than copying the entire array again
99     * note: this hack wouldnt be needed if parv[0] were set to the command name, rather
100     * than being derived from the prefix, as it should have been from the beginning.
101     */
102     ptr = parv[0];
103     parv += 2;
104     parc -= 2;
105     parv[0] = ptr;
106    
107 michael 1233 if ((handler = mptr->handlers[ENCAP_HANDLER]))
108     (*handler)(client_p, source_p, parc, parv);
109 adx 30 }
110 michael 1230
111     static struct Message encap_msgtab = {
112     "ENCAP", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
113     {m_ignore, m_ignore, ms_encap, m_ignore, m_ignore, m_ignore}
114     };
115    
116     static void
117     module_init(void)
118     {
119     mod_add_cmd(&encap_msgtab);
120     add_capability("ENCAP", CAP_ENCAP, 1);
121     }
122    
123     static void
124     module_exit(void)
125     {
126     mod_del_cmd(&encap_msgtab);
127     delete_capability("ENCAP");
128     }
129    
130     struct module module_entry = {
131     .node = { NULL, NULL, NULL },
132     .name = NULL,
133     .version = "$Revision$",
134     .handle = NULL,
135     .modinit = module_init,
136     .modexit = module_exit,
137     .flags = 0
138     };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28