2 ctrlproxy: A modular IRC proxy
3 (c) 2005 Jelmer Vernooij <jelmer@nl.linux.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "internals.h"
22 #define DEFAULT_PREFIX "(ov)@+"
23 #define DEFAULT_CHANTYPES "#&"
24 #define DEFAULT_CHARSET "iso8859-15"
26 void handle_005(struct network_state *s, struct line *l)
34 g_assert(l->argc >= 1);
36 for(i = 3; i < l->argc-1; i++) {
42 sep = strchr(l->args[i], '=');
45 key = g_strdup(l->args[i]);
48 key = g_strndup(l->args[i], sep - l->args[i]);
49 val = g_strdup(sep+1);
52 g_hash_table_replace(s->info->features, key, val);
54 if(!g_strcasecmp(key, "CASEMAPPING")) {
55 if(!g_strcasecmp(val, "rfc1459")) {
56 s->info->casemapping = CASEMAP_RFC1459;
57 } else if(!g_strcasecmp(val, "strict-rfc1459")) {
58 s->info->casemapping = CASEMAP_STRICT_RFC1459;
59 } else if(!g_strcasecmp(val, "ascii")) {
60 s->info->casemapping = CASEMAP_ASCII;
62 s->info->casemapping = CASEMAP_UNKNOWN;
63 log_network_state(NULL, LOG_WARNING, s, "Unknown CASEMAPPING value '%s'", val);
65 } else if(!g_strcasecmp(key, "NETWORK")) {
66 g_free(s->info->name);
67 s->info->name = g_strdup(val);
72 gboolean network_supports(const struct network_info *n, const char *fe)
76 g_assert(n->features);
77 return g_hash_table_lookup_extended (n->features, fe, &k, &v);
80 int irccmp(const struct network_info *n, const char *a, const char *b)
82 switch(n?n->casemapping:CASEMAP_UNKNOWN) {
86 return str_rfc1459cmp(a,b);
88 return str_asciicmp(a,b);
89 case CASEMAP_STRICT_RFC1459:
90 return str_strictrfc1459cmp(a,b);
96 gboolean is_channelname(const char *name, const struct network_info *n)
98 const char *chantypes = NULL;
103 g_assert(n->features);
105 chantypes = g_hash_table_lookup(n->features, "CHANTYPES");
108 if(chantypes == NULL)
109 chantypes = DEFAULT_CHANTYPES;
111 if(strchr(chantypes, name[0]))
117 gboolean is_prefix(char p, const struct network_info *n)
119 const char *prefix = NULL;
120 const char *pref_end;
123 g_assert(n->features);
124 prefix = g_hash_table_lookup(n->features, "PREFIX");
128 prefix = DEFAULT_PREFIX;
130 pref_end = strchr(prefix, ')');
131 if (!pref_end)pref_end = prefix; else pref_end++;
133 if(strchr(pref_end, p)) return TRUE;
137 const char *get_charset(const struct network_info *n)
139 char *ret = g_hash_table_lookup(n->features, "CHARSET");
144 return DEFAULT_CHARSET;
147 char get_prefix_by_mode(char mode, const struct network_info *n)
149 const char *prefix = NULL;
154 g_assert(n->features);
156 prefix = g_hash_table_lookup(n->features, "PREFIX");
160 prefix = DEFAULT_PREFIX;
162 pref_end = strchr(prefix, ')');
163 if(prefix[0] != '(' || !pref_end) {
164 log_global(NULL, LOG_WARNING, "Malformed PREFIX data `%s'", prefix);
170 for(i = 0; pref_end[i]; i++) {
171 if(prefix[i] == mode) return pref_end[i];