# HG changeset patch # User Nicolas Cornu # Date 1281759101 -7200 # Node ID bd54d1dba1ad06a2c9048e7842f250865837e4d2 # Parent 7dbd5e5e7a7c360e8719ce20839b5158859ade22 JS5: Finish the check function diff -r 7dbd5e5e7a7c -r bd54d1dba1ad jingle-socks5/socks5.c --- a/jingle-socks5/socks5.c Sat Aug 14 03:31:51 2010 +0200 +++ b/jingle-socks5/socks5.c Sat Aug 14 06:11:41 2010 +0200 @@ -46,6 +46,7 @@ static void jingle_socks5_init(void); static void jingle_socks5_uninit(void); + const gchar *deps[] = { "jingle", NULL }; static JingleTransportFuncs funcs = { @@ -68,6 +69,31 @@ .next = NULL, }; +static const gchar *jingle_s5b_types[] = { + "assisted", + "direct", + "proxy", + "tunnel", + NULL +}; + +static const gchar *jingle_s5b_modes[] = { + "tcp", + "udp", + NULL +}; + + +gint index_in_array(const gchar *str, const gchar **array) +{ + gint i; + for (i = 0; array[i]; i++) { + if (!g_strcmp0(array[i], str)) { + return i; + } + } + return -1; +} const gchar* jingle_socks5_xmlns(void) { @@ -76,39 +102,51 @@ gconstpointer jingle_socks5_check(JingleContent *cn, GError **err) { - JingleSocks5 *js5b = NULL; - JingleCandidate *jc; - + JingleSocks5 *js5b; LmMessageNode *node = cn->transport, *node2; + const gchar *modestr; js5b = g_new0(JingleSocks5, 1); - - js5b->mode = lm_message_node_get_attribute(node, "mode"); + modestr = lm_message_node_get_attribute(node, "mode"); + js5b->mode = index_in_array(modestr, jingle_s5b_modes); js5b->sid = lm_message_node_get_attribute(node, "sid"); - + if (!js5b->sid) { g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING, "an attribute of the transport element is missing"); g_free(js5b); return NULL; } - + for (node2 = node->children; node2; node2 = node2->next) { if (!g_strcmp0(node->name, "candidate")) { - jc = g_new0(JingleCandidate, 1); + const gchar *portstr, *prioritystr, *typestr; + JingleS5BCandidate *jc = g_new0(JingleS5BCandidate, 1); jc->cid = lm_message_node_get_attribute(node2, "cid"); jc->host = lm_message_node_get_attribute(node2, "host"); jc->jid = lm_message_node_get_attribute(node2, "jid"); - jc->port = g_ascii_strtoull(lm_message_node_get_attribute(node2, "port"), NULL, 10); - jc->priority = g_ascii_strtoull(lm_message_node_get_attribute(node2, "priority"), NULL, 10); - //jc->type = - + portstr = lm_message_node_get_attribute(node2, "port"); + prioritystr = lm_message_node_get_attribute(node2, "priority"); + typestr = lm_message_node_get_attribute(node2, "type"); + + if (!jc->cid || !jc->host || !jc->jid || !prioritystr) { + g_free(jc); + continue; + } + jc->port = g_ascii_strtoull(portstr, NULL, 10); + jc->priority = g_ascii_strtoull(prioritystr, NULL, 10); + jc->type = index_in_array(typestr, jingle_s5b_types); + + if (jc->type == -1) { + g_free(jc); + continue; + } + js5b->candidates = g_slist_append(js5b->candidates, jc); } } - + return (gconstpointer) js5b; - } diff -r 7dbd5e5e7a7c -r bd54d1dba1ad jingle-socks5/socks5.h --- a/jingle-socks5/socks5.h Sat Aug 14 03:31:51 2010 +0200 +++ b/jingle-socks5/socks5.h Sat Aug 14 06:11:41 2010 +0200 @@ -10,9 +10,13 @@ JINGLE_S5B_TUNNEL } JingleS5BType; +typedef enum { + JINGLE_S5B_TCP, + JINGLE_S5B_UDP +} JingleS5BModes; + typedef struct { - // optional, default: tcp. useful ?? - const gchar *mode; + JingleS5BModes mode; const gchar *sid; @@ -26,11 +30,11 @@ const gchar *jid; - guint port; + guint16 port; guint64 priority; JingleS5BType type; -} JingleCandidate; +} JingleS5BCandidate; #endif