66 .init = jingle_socks5_init, |
67 .init = jingle_socks5_init, |
67 .uninit = jingle_socks5_uninit, |
68 .uninit = jingle_socks5_uninit, |
68 .next = NULL, |
69 .next = NULL, |
69 }; |
70 }; |
70 |
71 |
|
72 static const gchar *jingle_s5b_types[] = { |
|
73 "assisted", |
|
74 "direct", |
|
75 "proxy", |
|
76 "tunnel", |
|
77 NULL |
|
78 }; |
|
79 |
|
80 static const gchar *jingle_s5b_modes[] = { |
|
81 "tcp", |
|
82 "udp", |
|
83 NULL |
|
84 }; |
|
85 |
|
86 |
|
87 gint index_in_array(const gchar *str, const gchar **array) |
|
88 { |
|
89 gint i; |
|
90 for (i = 0; array[i]; i++) { |
|
91 if (!g_strcmp0(array[i], str)) { |
|
92 return i; |
|
93 } |
|
94 } |
|
95 return -1; |
|
96 } |
71 |
97 |
72 const gchar* jingle_socks5_xmlns(void) |
98 const gchar* jingle_socks5_xmlns(void) |
73 { |
99 { |
74 return NS_JINGLE_TRANSPORT_SOCKS5; |
100 return NS_JINGLE_TRANSPORT_SOCKS5; |
75 } |
101 } |
76 |
102 |
77 gconstpointer jingle_socks5_check(JingleContent *cn, GError **err) |
103 gconstpointer jingle_socks5_check(JingleContent *cn, GError **err) |
78 { |
104 { |
79 JingleSocks5 *js5b = NULL; |
105 JingleSocks5 *js5b; |
80 JingleCandidate *jc; |
|
81 |
|
82 LmMessageNode *node = cn->transport, *node2; |
106 LmMessageNode *node = cn->transport, *node2; |
|
107 const gchar *modestr; |
83 |
108 |
84 js5b = g_new0(JingleSocks5, 1); |
109 js5b = g_new0(JingleSocks5, 1); |
85 |
110 modestr = lm_message_node_get_attribute(node, "mode"); |
86 js5b->mode = lm_message_node_get_attribute(node, "mode"); |
111 js5b->mode = index_in_array(modestr, jingle_s5b_modes); |
87 js5b->sid = lm_message_node_get_attribute(node, "sid"); |
112 js5b->sid = lm_message_node_get_attribute(node, "sid"); |
88 |
113 |
89 if (!js5b->sid) { |
114 if (!js5b->sid) { |
90 g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING, |
115 g_set_error(err, JINGLE_CHECK_ERROR, JINGLE_CHECK_ERROR_MISSING, |
91 "an attribute of the transport element is missing"); |
116 "an attribute of the transport element is missing"); |
92 g_free(js5b); |
117 g_free(js5b); |
93 return NULL; |
118 return NULL; |
94 } |
119 } |
95 |
120 |
96 for (node2 = node->children; node2; node2 = node2->next) { |
121 for (node2 = node->children; node2; node2 = node2->next) { |
97 if (!g_strcmp0(node->name, "candidate")) { |
122 if (!g_strcmp0(node->name, "candidate")) { |
98 jc = g_new0(JingleCandidate, 1); |
123 const gchar *portstr, *prioritystr, *typestr; |
|
124 JingleS5BCandidate *jc = g_new0(JingleS5BCandidate, 1); |
99 jc->cid = lm_message_node_get_attribute(node2, "cid"); |
125 jc->cid = lm_message_node_get_attribute(node2, "cid"); |
100 jc->host = lm_message_node_get_attribute(node2, "host"); |
126 jc->host = lm_message_node_get_attribute(node2, "host"); |
101 jc->jid = lm_message_node_get_attribute(node2, "jid"); |
127 jc->jid = lm_message_node_get_attribute(node2, "jid"); |
102 jc->port = g_ascii_strtoull(lm_message_node_get_attribute(node2, "port"), NULL, 10); |
128 portstr = lm_message_node_get_attribute(node2, "port"); |
103 jc->priority = g_ascii_strtoull(lm_message_node_get_attribute(node2, "priority"), NULL, 10); |
129 prioritystr = lm_message_node_get_attribute(node2, "priority"); |
104 //jc->type = |
130 typestr = lm_message_node_get_attribute(node2, "type"); |
105 |
131 |
|
132 if (!jc->cid || !jc->host || !jc->jid || !prioritystr) { |
|
133 g_free(jc); |
|
134 continue; |
|
135 } |
|
136 jc->port = g_ascii_strtoull(portstr, NULL, 10); |
|
137 jc->priority = g_ascii_strtoull(prioritystr, NULL, 10); |
|
138 jc->type = index_in_array(typestr, jingle_s5b_types); |
|
139 |
|
140 if (jc->type == -1) { |
|
141 g_free(jc); |
|
142 continue; |
|
143 } |
|
144 |
106 js5b->candidates = g_slist_append(js5b->candidates, jc); |
145 js5b->candidates = g_slist_append(js5b->candidates, jc); |
107 } |
146 } |
108 } |
147 } |
109 |
148 |
110 return (gconstpointer) js5b; |
149 return (gconstpointer) js5b; |
111 |
|
112 } |
150 } |
113 |
151 |
114 |
152 |
115 static void jingle_socks5_init(void) |
153 static void jingle_socks5_init(void) |
116 { |
154 { |