262 js5b->ourcandidates = get_our_candidates(get_port()); |
262 js5b->ourcandidates = get_our_candidates(get_port()); |
263 |
263 |
264 return js5b; |
264 return js5b; |
265 } |
265 } |
266 |
266 |
267 static JingleHandleStatus |
|
268 handle_session_accept(JingleS5B *js5b, LmMessageNode *node, GError **err) |
|
269 { |
|
270 js5b->candidates = parse_candidates(node); |
|
271 return JINGLE_STATUS_HANDLED; |
|
272 } |
|
273 |
|
274 static JingleHandleStatus handle(JingleAction action, gconstpointer data, |
267 static JingleHandleStatus handle(JingleAction action, gconstpointer data, |
275 LmMessageNode *node, GError **err) |
268 LmMessageNode *node, GError **err) |
276 { |
269 { |
277 JingleS5B *js5b = (JingleS5B *)data; |
270 JingleS5B *js5b = (JingleS5B *)data; |
278 |
271 |
279 if (action == JINGLE_SESSION_ACCEPT) { |
272 if (action == JINGLE_SESSION_ACCEPT) { |
280 return handle_session_accept(js5b, node, err); |
273 js5b->candidates = parse_candidates(node); |
|
274 return JINGLE_STATUS_HANDLED; |
|
275 } else if (action == JINGLE_TRANSPORT_INFO) { |
|
276 LmMessageNode *errorn, *usedn; |
|
277 if (g_strcmp0(lm_message_node_get_attribute(node, "sid"), js5b->sid)) |
|
278 return JINGLE_STATUS_HANDLED; // huh.. not the same socks5 sid ? |
|
279 |
|
280 errorn = lm_message_node_get_child(node, "candidate-error"); |
|
281 usedn = lm_message_node_get_child(node, "candidate-used"); |
|
282 if (errorn != FALSE) { |
|
283 //got_candidate_error |
|
284 } else if (usedn != FALSE) { |
|
285 //got_candidate_used |
|
286 } |
|
287 return JINGLE_STATUS_HANDLED; |
281 } |
288 } |
282 return JINGLE_STATUS_NOT_HANDLED; |
289 return JINGLE_STATUS_NOT_HANDLED; |
283 } |
290 } |
284 |
291 |
285 static void tomessage(gconstpointer data, LmMessageNode *node) |
292 static void tomessage(gconstpointer data, LmMessageNode *node) |
392 connect_candidate(js5b, cand); |
399 connect_candidate(js5b, cand); |
393 } |
400 } |
394 } |
401 } |
395 |
402 |
396 /** |
403 /** |
|
404 * @brief Called when a connection was established |
|
405 * |
|
406 * This function free/unref everything created by init like |
|
407 * the GSocketListener and GClientSocket objects. |
|
408 */ |
|
409 static void free_after_connection(JingleS5B *js5b) |
|
410 { |
|
411 g_socket_listener_close(js5b->listener); |
|
412 g_object_unref(js5b->listener); |
|
413 g_object_unref(js5b->client); |
|
414 } |
|
415 |
|
416 /** |
397 * @brief Cancel an ongoing connection after 5 seconds |
417 * @brief Cancel an ongoing connection after 5 seconds |
398 * @param data A GPtrArray |
418 * @param data A GPtrArray |
399 * |
419 * |
400 * "A client SHOULD NOT wait for a TCP timeout on connect. |
420 * "A client SHOULD NOT wait for a TCP timeout on connect. |
401 * If it is unable to connect to any candidate within 5 seconds |
421 * If it is unable to connect to any candidate within 5 seconds |
407 JingleS5B *js5b = g_ptr_array_index(args, 0); |
427 JingleS5B *js5b = g_ptr_array_index(args, 0); |
408 //S5BCandidate *cand = g_ptr_array_index(args, 1); |
428 //S5BCandidate *cand = g_ptr_array_index(args, 1); |
409 g_ptr_array_unref(args); |
429 g_ptr_array_unref(args); |
410 |
430 |
411 g_cancellable_cancel(js5b->cancelconnect); |
431 g_cancellable_cancel(js5b->cancelconnect); |
|
432 // we need to send a candidate-error in case we cannot connect. |
412 return FALSE; |
433 return FALSE; |
413 } |
434 } |
414 |
435 |
415 static void connect_candidate(JingleS5B *js5b, S5BCandidate *cand) |
436 static void connect_candidate(JingleS5B *js5b, S5BCandidate *cand) |
416 { |
437 { |
498 guint eventid = GPOINTER_TO_UINT(g_ptr_array_index(args, 2)); |
519 guint eventid = GPOINTER_TO_UINT(g_ptr_array_index(args, 2)); |
499 GSource *s = g_main_context_find_source_by_id(NULL, eventid); |
520 GSource *s = g_main_context_find_source_by_id(NULL, eventid); |
500 g_source_destroy(s); |
521 g_source_destroy(s); |
501 g_ptr_array_unref(args); |
522 g_ptr_array_unref(args); |
502 connect_next_candidate(js5b, cand); |
523 connect_next_candidate(js5b, cand); |
503 // we need to send a candidate-error in case we cannot connect. |
|
504 return; |
524 return; |
505 } |
525 } |
506 |
526 |
507 if (err != NULL) { |
527 if (err != NULL) { |
508 if (err->domain == G_IO_ERROR) |
528 if (err->domain == G_IO_ERROR) |