diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-07-13 18:09:39 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-07-15 16:21:03 +0100 |
commit | a7d1dc49cc27914be4457d70d7d92e9848124245 (patch) | |
tree | 8752b4142365f821a486dc81c4edc9fbc2646ee7 /src/protocol.c | |
parent | d83b8de4203820a4a5c2317ae321e669def1cb8d (diff) | |
download | telepathy-haze-a7d1dc49cc27914be4457d70d7d92e9848124245.tar.gz |
Move build_protocol_table() to protocol.c
No code changes, except renaming it to haze_protocol_build_protocol_table.
Diffstat (limited to 'src/protocol.c')
-rw-r--r-- | src/protocol.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/src/protocol.c b/src/protocol.c index f6f094d..0068cef 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -20,12 +20,139 @@ * */ +#include "config.h" #include "protocol.h" +#include <string.h> + #include <telepathy-glib/telepathy-glib.h> G_DEFINE_TYPE (HazeProtocol, haze_protocol, TP_TYPE_BASE_PROTOCOL) +/* For some protocols, removing the "prpl-" prefix from its name in libpurple + * doesn't give the right name for Telepathy. Other protocols need some + * parameters renaming to match well-known names in the spec, or to have + * hyphens rather than underscores for consistency. + */ + +static const HazeParameterMapping encoding_to_charset[] = { + { "encoding", "charset" }, + { NULL, NULL } +}; + +static const HazeParameterMapping jabber_mappings[] = { + { "connect_server", "server" }, + { "require_tls", "require-encryption" }, + { NULL, NULL } +}; + +static const HazeParameterMapping bonjour_mappings[] = { + { "first", "first-name" }, + { "last", "last-name" }, + { NULL, NULL } +}; + +static const HazeParameterMapping sipe_mappings[] = { + { "usersplit1", "login" }, + { NULL, NULL } +}; + +static const HazeParameterMapping yahoo_mappings[] = { + { "local_charset", "charset" }, + { NULL, NULL } +}; + +static HazeProtocolInfo known_protocol_info[] = { + { "aim", "prpl-aim", NULL, NULL }, + /* Seriously. */ + { "facebook", "prpl-bigbrownchunx-facebookim", NULL, NULL }, + { "gadugadu", "prpl-gg", NULL, NULL }, + { "groupwise", "prpl-novell", NULL, NULL }, + { "irc", "prpl-irc", NULL, encoding_to_charset }, + { "icq", "prpl-icq", NULL, encoding_to_charset }, + { "jabber", "prpl-jabber", NULL, jabber_mappings }, + { "local-xmpp", "prpl-bonjour", NULL, bonjour_mappings }, + { "msn", "prpl-msn", NULL, NULL }, + { "qq", "prpl-qq", NULL, NULL }, + { "sametime", "prpl-meanwhile", NULL, NULL }, + { "sipe", "prpl-sipe", NULL, sipe_mappings }, + { "yahoo", "prpl-yahoo", NULL, yahoo_mappings }, + { "yahoojp", "prpl-yahoojp", NULL, yahoo_mappings }, + { "zephyr", "prpl-zephyr", NULL, encoding_to_charset }, + { "mxit", "prpl-loubserp-mxit", NULL, NULL }, + { "sip", "prpl-simple", NULL, NULL }, + { NULL, NULL, NULL, NULL } +}; + +/** Predicate for g_hash_table_find to search on prpl_id. + * @param key (const gchar *)tp_protocol_name + * @param value (HazeProtocolInfo *)info + * @param data (const gchar *)prpl_id + * @return @c TRUE iff info->prpl_id eq prpl_id + */ +static gboolean +_compare_protocol_id (gpointer key, + gpointer value, + gpointer data) +{ + HazeProtocolInfo *info = (HazeProtocolInfo *)value; + const gchar *prpl_id = (const gchar *)data; + return (!strcmp (info->prpl_id, prpl_id)); +} + +GHashTable * +haze_protocol_build_protocol_table (void) +{ + GHashTable *table; + HazeProtocolInfo *i; + GList *iter; + + table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); + + for (i = known_protocol_info; i->prpl_id != NULL; i++) + { + PurplePlugin *plugin = purple_find_prpl (i->prpl_id); + + if (plugin == NULL) + continue; + + i->prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO (plugin); + + g_hash_table_insert (table, i->tp_protocol_name, i); + } + + for (iter = purple_plugins_get_protocols (); iter; iter = iter->next) + { + PurplePlugin *plugin = iter->data; + PurplePluginInfo *p_info = plugin->info; + PurplePluginProtocolInfo *prpl_info = + PURPLE_PLUGIN_PROTOCOL_INFO (plugin); + HazeProtocolInfo *info; + + if (g_hash_table_find (table, _compare_protocol_id, p_info->id)) + continue; /* already in the table from the previous loop */ + + info = g_slice_new (HazeProtocolInfo); + info->prpl_id = p_info->id; + info->prpl_info = prpl_info; + info->parameter_map = NULL; + + if (g_str_has_prefix (p_info->id, "prpl-")) + { + info->tp_protocol_name = (p_info->id + 5); + } + else + { + g_warning ("prpl '%s' has a dumb id; spank its author", p_info->id); + info->tp_protocol_name = p_info->id; + } + + g_hash_table_insert (table, info->tp_protocol_name, info); + } + + return table; +} + static void haze_protocol_init (HazeProtocol *self) { |