parameters in 005 lines.
NICKLEN, MAXBANS, MODES, NICKLEN, MAXBANS, TOPICLEN, KICKLEN,
AWAYLEN, MAXTARGETS, WALLCHOPS, WALLVOICES, RFC2812, PENALTY,
FNC, SAFELIST, USERIP, CNOTICE, KNOCK, VCHANNELS, WHOX, CALLERID,
- ACCEPT.
+ ACCEPT, KEYLEN, USERLEN, HOSTLEN and SILENCE
PORTABILITY
val = g_strdup(sep+1);
}
- g_hash_table_replace(info->features, key, val);
-
if(!g_strcasecmp(key, "CASEMAPPING")) {
if(!g_strcasecmp(val, "rfc1459")) {
info->casemapping = CASEMAP_RFC1459;
info->name = g_strdup(val);
} else if(!g_strcasecmp(key, "NICKLEN")) {
info->nicklen = atoi(val);
+ } else if(!g_strcasecmp(key, "USERLEN")) {
+ info->userlen = atoi(val);
+ } else if(!g_strcasecmp(key, "HOSTLEN")) {
+ info->hostlen = atoi(val);
} else if(!g_strcasecmp(key, "CHANNELLEN")) {
info->channellen = atoi(val);
} else if(!g_strcasecmp(key, "AWAYLEN")) {
info->callerid = TRUE;
} else if(!g_strcasecmp(key, "ACCEPT")) {
info->accept = TRUE;
+ } else if(!g_strcasecmp(key, "KEYLEN")) {
+ info->keylen = atoi(val);
+ } else if(!g_strcasecmp(key, "SILENCE")) {
+ info->silence = atoi(val);
+ } else if(!g_strcasecmp(key, "CHANTYPES")) {
+ g_free(info->chantypes);
+ info->chantypes = g_strdup(val);
+ } else if(!g_strcasecmp(key, "PREFIX")) {
+ g_free(info->prefix);
+ info->prefix = g_strdup(val);
+ } else if(!g_strcasecmp(key, "CHARSET")) {
+ g_free(info->charset);
+ info->charset = g_strdup(val);
} else {
log_global(LOG_WARNING, "Unknown 005 parameter `%s'", key);
}
+ g_free(key);
+ g_free(val);
}
void handle_005(struct network_state *s, struct line *l)
network_info_parse(s->info, l->args[i]);
}
-gboolean network_supports(const struct network_info *n, const char *fe)
-{
- gpointer k, v;
- g_assert(n);
- g_assert(n->features);
- return g_hash_table_lookup_extended (n->features, fe, &k, &v);
-}
-
int irccmp(const struct network_info *n, const char *a, const char *b)
{
switch(n?n->casemapping:CASEMAP_UNKNOWN) {
g_assert(name);
if (n != NULL) {
- g_assert(n->features);
-
- chantypes = g_hash_table_lookup(n->features, "CHANTYPES");
+ chantypes = n->chantypes;
}
if(chantypes == NULL)
const char *pref_end;
if (n != NULL) {
- g_assert(n->features);
- prefix = g_hash_table_lookup(n->features, "PREFIX");
+ prefix = n->prefix;
}
if (prefix == NULL)
const char *get_charset(const struct network_info *n)
{
- char *ret = g_hash_table_lookup(n->features, "CHARSET");
-
- if (ret != NULL)
- return ret;
+ if (n != NULL && n->charset != NULL)
+ return n->charset;
return DEFAULT_CHARSET;
}
char *pref_end;
if (n != NULL) {
- g_assert(n->features);
-
- prefix = g_hash_table_lookup(n->features, "PREFIX");
+ prefix = n->prefix;
}
if (prefix == NULL)
s = g_new0(struct network, 1);
s->config = sc;
- s->info.features = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
s->name = g_strdup(s->config->name);
s->connection.pending_lines = g_queue_new();
s->global = global;
g_free(s->info.server);
g_free(s->info.name);
- g_hash_table_destroy(s->info.features);
-
#ifdef HAVE_GNUTLS
ssl_free_client_credentials(s->ssl_credentials);
#endif
{
char *name;
char *server;
- GHashTable *features;
char *supported_user_modes;
char *supported_channel_modes;
/* Case mapping used for nick- and channel name comparing */
enum casemapping casemapping;
+ /* A list of channel modes a person can get and the respective
+ * prefix a channel or nickname will get in case the person has it */
+ char *prefix;
+
+ /* The supported channel prefixes */
+ char *chantypes;
+
+ /* Server supported character set */
+ char *charset;
+
+ /* Maximum key length */
+ int keylen;
+
+ /* The server support the SILENCE command.
+ * The number is the maximum number of allowed entries in the list. */
+ int silence;
+
/* Maximum channel name length */
int channellen;
/* Maximum nickname length */
int nicklen;
+ /* Maximum username length */
+ int userlen;
+
+ /* Maximum hostname length */
+ int hostlen;
+
/* Maximum number of channels allowed to join */
int maxchannels;
G_MODULE_EXPORT gboolean is_prefix(char p, const struct network_info *n);
G_MODULE_EXPORT char get_prefix_by_mode(char p, const struct network_info *n);
G_MODULE_EXPORT int irccmp(const struct network_info *n, const char *a, const char *b);
-G_MODULE_EXPORT gboolean network_supports(const struct network_info *n, const char *fe);
G_MODULE_EXPORT const char *get_charset(const struct network_info *n);
G_MODULE_EXPORT void network_info_parse(struct network_info *info, const char *parameter);
START_TEST(isupport_info_parse_casemapping)
struct network_info *info = g_new0(struct network_info, 1);
- info->features = g_hash_table_new(NULL, NULL);
network_info_parse(info, "CASEMAPPING=ascii");
fail_unless (info->casemapping == CASEMAP_ASCII);
network_info_parse(info, "CASEMAPPING=strict-rfc1459");
START_TEST(isupport_info_parse_name)
struct network_info *info = g_new0(struct network_info, 1);
- info->features = g_hash_table_new(NULL, NULL);
network_info_parse(info, "NETWORK=bla");
fail_unless (strcmp(info->name, "bla") == 0);
END_TEST
return FALSE; \
}
-struct hash_data {
- GEqualFunc fn;
- GHashTable *hash2;
- gboolean success;
-};
-
-static void hash_traverse_equal(void *key, void *val1, void *userdata)
-{
- struct hash_data *hash = userdata;
- void *val2;
-
- val2 = g_hash_table_lookup(hash->hash2, key);
-
- hash->success &= hash->fn(val1, val2);
-}
-
-static gboolean hash_equal(GHashTable *hash1, GHashTable *hash2, GEqualFunc eqval)
-{
- struct hash_data userdata;
-
- null_equal(hash1, hash2);
-
- /* Traverse over all keys in hash1 and make sure they exist
- * with the same value in hash1 and hash2 */
-
- userdata.fn = eqval;
- userdata.hash2 = hash2;
- userdata.success = TRUE;
- g_hash_table_foreach(hash1, hash_traverse_equal, &userdata);
- if (!userdata.success)
- return FALSE;
-
- /* Traverse over all keys in hash2 and make sure
- * they exist in hash1 */
-
- userdata.fn = eqval;
- userdata.hash2 = hash1;
- g_hash_table_foreach(hash2, hash_traverse_equal, &userdata);
-
- return userdata.success;
-}
-
static gboolean list_equal(GList *list1, GList *list2, GEqualFunc eq)
{
GList *gl1, *gl2;
return str_equal(info1->name, info2->name) &&
str_equal(info1->server, info2->server) &&
- hash_equal(info1->features, info2->features, (GEqualFunc)str_equal) &&
str_equal(info1->supported_user_modes, info2->supported_user_modes) &&
str_equal(info1->supported_channel_modes, info2->supported_channel_modes) &&
- info1->casemapping == info2->casemapping &&
+ str_equal(info1->prefix, info2->prefix) &&
+ str_equal(info1->chantypes, info2->chantypes) &&
+ str_equal(info1->charset, info2->charset) &&
+ info1->keylen == info2->keylen &&
+ info1->silence == info2->silence &&
info1->channellen == info2->channellen &&
- info1->topiclen == info2->topiclen;
+ info1->awaylen == info2->awaylen &&
+ info1->maxtargets == info2->maxtargets &&
+ info1->nicklen == info2->nicklen &&
+ info1->userlen == info2->userlen &&
+ info1->hostlen == info2->hostlen &&
+ info1->maxchannels == info2->maxchannels &&
+ info1->topiclen == info2->topiclen &&
+ info1->maxbans == info2->maxbans &&
+ info1->maxmodes == info2->maxmodes &&
+ info1->wallchops == info2->wallchops &&
+ info1->wallvoices == info2->wallvoices &&
+ info1->rfc2812 == info2->rfc2812 &&
+ info1->penalty == info2->penalty &&
+ info1->forced_nick_changes == info2->forced_nick_changes &&
+ info1->safelist == info2->safelist &&
+ info1->userip == info2->userip &&
+ info1->cprivmsg == info2->cprivmsg &&
+ info1->cnotice == info2->cnotice &&
+ info1->knock == info2->knock &&
+ info1->vchannels == info2->vchannels &&
+ info1->whox == info2->whox &&
+ info1->callerid == info2->callerid &&
+ info1->accept == info2->accept &&
+ info1->casemapping == info2->casemapping;
}
static gboolean network_nick_equal(const struct network_nick *nick1, const struct network_nick *nick2)
#include "internals.h"
#include "torture.h"
-START_TEST(test_network_supports)
- struct network_info info;
- info.features = g_hash_table_new(NULL, NULL);
- g_hash_table_insert(info.features, "foo", "bla");
- fail_if(network_supports(&info, "foo") == false);
- fail_if(network_supports(&info, "foobar") == true);
-END_TEST
-
START_TEST(test_is_prefix)
struct network_info info;
- info.features = g_hash_table_new(NULL, NULL);
- g_hash_table_insert(info.features, "PREFIX", "(qaohv)~&@%+");
+ memset(&info, 0, sizeof(info));
+ network_info_parse(&info, "PREFIX=(qaohv)~&@%+");
fail_unless(is_prefix('&', &info));
fail_if(is_prefix(' ', &info));
- g_hash_table_replace(info.features, "PREFIX", "");
+ network_info_parse(&info, "PREFIX=");
fail_if(is_prefix('&', &info));
END_TEST
START_TEST(test_get_prefix_by_mode)
struct network_info info;
- info.features = g_hash_table_new(NULL, NULL);
- g_hash_table_insert(info.features, "PREFIX", "(qaohv)~&@%+");
+ memset(&info, 0, sizeof(info));
+ network_info_parse(&info, "PREFIX=(qaohv)~&@%+");
fail_unless(get_prefix_by_mode('a', &info) == '&');
fail_unless(get_prefix_by_mode('q', &info) == '~');
fail_unless(get_prefix_by_mode('h', &info) == '%');
fail_unless(get_prefix_by_mode('!', &info) == ' ');
- g_hash_table_replace(info.features, "PREFIX", "(qaohv~&@%+");
+ network_info_parse(&info, "PREFIX=(qaohv~&@%+");
fail_unless(get_prefix_by_mode('a', &info) == ' ');
END_TEST
START_TEST(test_get_charset)
struct network_info info;
- info.features = g_hash_table_new(NULL, NULL);
- g_hash_table_insert(info.features, "CHARSET", "ascii");
+ memset(&info, 0, sizeof(info));
+ network_info_parse(&info, "CHARSET=ascii");
fail_unless(!strcmp(get_charset(&info), "ascii"));
END_TEST
START_TEST(test_get_charset_default)
struct network_info info;
- info.features = g_hash_table_new(NULL, NULL);
+ memset(&info, 0, sizeof(info));
fail_unless(!strcmp(get_charset(&info), "iso8859-15"));
END_TEST
Suite *s = suite_create("networkinfo");
TCase *tc_core = tcase_create("core");
suite_add_tcase(s, tc_core);
- tcase_add_test(tc_core, test_network_supports);
tcase_add_test(tc_core, test_is_prefix);
tcase_add_test(tc_core, test_get_prefix_by_mode);
tcase_add_test(tc_core, test_get_charset);