Change glib dependency to >= 2.13 because of G_PARAM_STATIC_STRINGS
[sipe-libnice.git] / tests / test-fallback.c
blobe7437b6ec6e6458590be63550a26fc66a3a93691
1 /*
2 * This file is part of the Nice GLib ICE library.
4 * Contains a unit test for functionality to fallback to non-ICE
5 * operation if remote party does not support ICE.
7 * (C) 2007 Nokia Corporation. All rights reserved.
8 * Contact: Kai Vehmanen
10 * The contents of this file are subject to the Mozilla Public License Version
11 * 1.1 (the "License"); you may not use this file except in compliance with
12 * the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS" basis,
16 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 * for the specific language governing rights and limitations under the
18 * License.
20 * The Original Code is the Nice GLib ICE library.
22 * The Initial Developers of the Original Code are Collabora Ltd and Nokia
23 * Corporation. All Rights Reserved.
25 * Contributors:
26 * Kai Vehmanen, Nokia
28 * Alternatively, the contents of this file may be used under the terms of the
29 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
30 * case the provisions of LGPL are applicable instead of those above. If you
31 * wish to allow use of your version of this file only under the terms of the
32 * LGPL and not to allow others to use your version of this file under the
33 * MPL, indicate your decision by deleting the provisions above and replace
34 * them with the notice and other provisions required by the LGPL. If you do
35 * not delete the provisions above, a recipient may use your version of this
36 * file under either the MPL or the LGPL.
38 #ifdef HAVE_CONFIG_H
39 # include <config.h>
40 #endif
42 #include "agent.h"
43 #include "agent-priv.h" /* for testing purposes */
45 #include <stdlib.h>
46 #include <string.h>
49 static NiceComponentState global_lagent_state = NICE_COMPONENT_STATE_LAST;
50 static NiceComponentState global_ragent_state = NICE_COMPONENT_STATE_LAST;
51 static guint global_components_ready = 0;
52 static guint global_components_ready_exit = 0;
53 static guint global_components_failed = 0;
54 static guint global_components_failed_exit = 0;
55 static GMainLoop *global_mainloop = NULL;
56 static gboolean global_lagent_gathering_done = FALSE;
57 static gboolean global_ragent_gathering_done = FALSE;
58 static gboolean global_lagent_ibr_received = FALSE;
59 static gboolean global_ragent_ibr_received = FALSE;
60 static int global_lagent_cands = 0;
61 static int global_ragent_cands = 0;
62 static gint global_ragent_read = 0;
63 static gint global_ragent_read_exit = 0;
64 static gboolean global_accept_non_data = TRUE;
66 static void priv_print_global_status (void)
68 g_debug ("\tgathering_done=%d", global_lagent_gathering_done && global_ragent_gathering_done);
69 g_debug ("\tlstate=%d", global_lagent_state);
70 g_debug ("\trstate=%d", global_ragent_state);
73 static gboolean timer_cb (gpointer pointer)
75 g_debug ("test-fallback:%s: %p", G_STRFUNC, pointer);
77 /* signal status via a global variable */
79 /* note: should not be reached, abort */
80 g_error ("ERROR: test has got stuck, aborting...");
82 return FALSE;
85 static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, guint len, gchar *buf, gpointer user_data)
87 g_debug ("test-fallback:%s: %p", G_STRFUNC, user_data);
89 /* XXX: dear compiler, these are for you: */
90 (void)agent; (void)stream_id; (void)component_id; (void)buf;
93 * Lets ignore stun packets that got through
95 if (len != 16 || strncmp ("1234567812345678", buf, 16)) {
96 if (global_accept_non_data)
97 return;
98 else
99 g_error ("Got non-data packet of lenght %u", len);
102 if ((intptr_t)user_data == 2) {
103 global_ragent_read += len;
105 if (global_ragent_read == global_ragent_read_exit)
106 g_main_loop_quit (global_mainloop);
110 static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer data)
112 g_debug ("test-fallback:%s: %p", G_STRFUNC, data);
114 if ((intptr_t)data == 1)
115 global_lagent_gathering_done = TRUE;
116 else if ((intptr_t)data == 2)
117 global_ragent_gathering_done = TRUE;
119 if (global_lagent_gathering_done &&
120 global_ragent_gathering_done)
121 g_main_loop_quit (global_mainloop);
123 /* XXX: dear compiler, these are for you: */
124 (void)agent;
127 static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint component_id, guint state, gpointer data)
129 g_debug ("test-fallback:%s: %p", __func__, data);
131 if ((intptr_t)data == 1)
132 global_lagent_state = state;
133 else if ((intptr_t)data == 2)
134 global_ragent_state = state;
136 if (state == NICE_COMPONENT_STATE_READY)
137 global_components_ready++;
138 if (state == NICE_COMPONENT_STATE_FAILED)
139 global_components_failed++;
141 g_debug ("test-fallback: READY %u exit at %u.", global_components_ready, global_components_ready_exit);
143 /* signal status via a global variable */
144 if (global_components_ready == global_components_ready_exit) {
145 g_main_loop_quit (global_mainloop);
146 return;
149 /* signal status via a global variable */
150 if (global_components_failed == global_components_failed_exit) {
151 g_main_loop_quit (global_mainloop);
152 return;
155 /* XXX: dear compiler, these are for you: */
156 (void)agent; (void)stream_id; (void)data; (void)component_id;
159 static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint component_id,
160 gchar *lfoundation, gchar* rfoundation, gpointer data)
162 g_debug ("test-fallback:%s: %p", __func__, data);
164 if ((intptr_t)data == 1)
165 ++global_lagent_cands;
166 else if ((intptr_t)data == 2)
167 ++global_ragent_cands;
169 /* XXX: dear compiler, these are for you: */
170 (void)agent; (void)stream_id; (void)component_id; (void)lfoundation; (void)rfoundation;
173 static void cb_new_candidate(NiceAgent *agent, guint stream_id, guint component_id,
174 gchar *foundation, gpointer data)
176 g_debug ("test-fallback:%s: %p", __func__, data);
178 /* XXX: dear compiler, these are for you: */
179 (void)agent; (void)stream_id; (void)data; (void)component_id; (void)foundation;
182 static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_id, gpointer data)
184 g_debug ("test-fallback:%s: %p", __func__, data);
186 if ((intptr_t)data == 1)
187 global_lagent_ibr_received = TRUE;
188 else if ((intptr_t)data == 2)
189 global_ragent_ibr_received = TRUE;
191 /* XXX: dear compiler, these are for you: */
192 (void)agent; (void)stream_id; (void)data;
195 static void priv_get_local_addr (NiceAgent *agent, guint stream_id, guint component_id, NiceAddress *dstaddr)
197 GSList *cands, *i;
198 cands = nice_agent_get_local_candidates(agent, stream_id, component_id);
199 for (i = cands; i; i = i->next) {
200 NiceCandidate *cand = i->data;
201 if (cand) {
202 g_assert (dstaddr);
203 *dstaddr = cand->addr;
204 break;
207 for (i = cands; i; i = i->next)
208 nice_candidate_free ((NiceCandidate *) i->data);
209 g_slist_free (cands);
212 static int run_fallback_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr)
214 NiceAddress laddr, raddr, laddr_rtcp, raddr_rtcp;
215 NiceCandidate cdes;
216 GSList *cands;
217 guint ls_id, rs_id;
219 memset (&cdes, 0, sizeof(NiceCandidate));
220 cdes.priority = 100000;
221 strcpy (cdes.foundation, "1");
222 cdes.type = NICE_CANDIDATE_TYPE_HOST;
223 cdes.transport = NICE_CANDIDATE_TRANSPORT_UDP;
224 cdes.base_addr = *baseaddr;
226 /* step: initialize variables modified by the callbacks */
227 global_components_ready = 0;
228 global_components_ready_exit = 4;
229 global_components_failed = 0;
230 global_components_failed_exit = 4;
231 global_lagent_gathering_done = FALSE;
232 global_ragent_gathering_done = FALSE;
233 global_lagent_ibr_received =
234 global_ragent_ibr_received = FALSE;
235 global_lagent_cands =
236 global_ragent_cands = 0;
237 global_ragent_read_exit = -1;
239 g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
240 g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);
242 /* step: add one stream, with RTP+RTCP components, to each agent */
243 ls_id = nice_agent_add_stream (lagent, 2);
244 rs_id = nice_agent_add_stream (ragent, 2);
245 g_assert (ls_id > 0);
246 g_assert (rs_id > 0);
248 nice_agent_gather_candidates (lagent, ls_id);
249 nice_agent_gather_candidates (ragent, rs_id);
251 /* step: attach to mainloop (needed to register the fds) */
252 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
253 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)1);
254 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP,
255 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)1);
256 nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
257 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)2);
258 nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP,
259 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)2);
261 /* step: run mainloop until local candidates are ready
262 * (see timer_cb() above) */
263 if (global_lagent_gathering_done != TRUE ||
264 global_ragent_gathering_done != TRUE) {
265 g_debug ("test-fallback: Added streams, running mainloop until 'candidate-gathering-done'...");
266 g_main_loop_run (global_mainloop);
267 g_assert (global_lagent_gathering_done == TRUE);
268 g_assert (global_ragent_gathering_done == TRUE);
271 /* step: find out the local candidates of each agent */
273 priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &raddr);
274 g_debug ("test-fallback: local RTP port R %u",
275 nice_address_get_port (&raddr));
277 priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &laddr);
278 g_debug ("test-fallback: local RTP port L %u",
279 nice_address_get_port (&laddr));
281 priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &raddr_rtcp);
282 g_debug ("test-fallback: local RTCP port R %u",
283 nice_address_get_port (&raddr_rtcp));
285 priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &laddr_rtcp);
286 g_debug ("test-fallback: local RTCP port L %u",
287 nice_address_get_port (&laddr_rtcp));
289 /* step: exchange candidate information but not the credentials */
291 cands = g_slist_append (NULL, &cdes);
292 cdes.component_id = NICE_COMPONENT_TYPE_RTP;
293 cdes.addr = raddr;
294 nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, cands);
295 cdes.addr = laddr;
296 nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, cands);
297 cdes.component_id = NICE_COMPONENT_TYPE_RTCP;
298 cdes.addr = raddr_rtcp;
299 nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, cands);
300 cdes.addr = laddr_rtcp;
301 nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, cands);
303 /* step: fall back to non-ICE mode on both sides */
304 g_assert (nice_agent_set_selected_pair (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, "1", "1") == TRUE);
305 g_assert (nice_agent_set_selected_pair (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, "1", "1") == TRUE);
306 g_assert (nice_agent_set_selected_pair (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, "1", "1") == TRUE);
307 g_assert (nice_agent_set_selected_pair (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, "1", "1") == TRUE);
309 g_debug ("test-fallback: Requested for fallback, running mainloop until component state change is completed...");
311 /* step: run the mainloop until connectivity checks succeed
312 * (see timer_cb() above) */
313 if (global_components_ready < global_components_ready_exit)
314 g_main_loop_run (global_mainloop);
316 /* note: verify that agents are in correct state */
317 g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
318 g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
320 /* step: next send a packet -> should work even if no ICE processing
321 * has been done */
323 g_debug ("test-fallback: Sent a payload packet, run mainloop until packet received.");
325 /* step: send a new test packet from L ot R */
326 global_ragent_read = 0;
327 g_assert (nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678") == 16);
328 global_ragent_read_exit = 16;
329 g_main_loop_run (global_mainloop);
331 /* note: verify that payload was succesfully received */
332 g_assert (global_ragent_read == 16);
334 g_debug ("test-fallback: Ran mainloop, removing streams...");
336 /* step: clean up resources and exit */
338 g_slist_free (cands);
339 nice_agent_remove_stream (lagent, ls_id);
340 nice_agent_remove_stream (ragent, rs_id);
342 g_debug ("test-fallback: test COMPLETED");
344 return 0;
348 static int run_safe_fallback_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr)
350 NiceAddress laddr, raddr, laddr_rtcp, raddr_rtcp;
351 NiceCandidate cdes;
352 guint ls_id, rs_id;
354 memset (&cdes, 0, sizeof(NiceCandidate));
355 cdes.priority = 100000;
356 strcpy (cdes.foundation, "1");
357 cdes.type = NICE_CANDIDATE_TYPE_HOST;
358 cdes.transport = NICE_CANDIDATE_TRANSPORT_UDP;
359 cdes.base_addr = *baseaddr;
361 /* step: initialize variables modified by the callbacks */
362 global_components_ready = 0;
363 global_components_ready_exit = 4;
364 global_components_failed = 0;
365 global_components_failed_exit = 4;
366 global_lagent_gathering_done = FALSE;
367 global_ragent_gathering_done = FALSE;
368 global_lagent_ibr_received =
369 global_ragent_ibr_received = FALSE;
370 global_lagent_cands =
371 global_ragent_cands = 0;
372 global_ragent_read_exit = -1;
373 global_accept_non_data = FALSE;
375 g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
376 g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);
378 /* step: add one stream, with RTP+RTCP components, to each agent */
379 ls_id = nice_agent_add_stream (lagent, 2);
380 rs_id = nice_agent_add_stream (ragent, 2);
381 g_assert (ls_id > 0);
382 g_assert (rs_id > 0);
384 nice_agent_gather_candidates (lagent, ls_id);
385 nice_agent_gather_candidates (ragent, rs_id);
387 /* step: attach to mainloop (needed to register the fds) */
388 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
389 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)1);
390 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP,
391 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)1);
392 nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
393 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)2);
394 nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP,
395 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)2);
397 /* step: run mainloop until local candidates are ready
398 * (see timer_cb() above) */
399 if (global_lagent_gathering_done != TRUE ||
400 global_ragent_gathering_done != TRUE) {
401 g_debug ("test-fallback: Added streams, running mainloop until 'candidate-gathering-done'...");
402 g_main_loop_run (global_mainloop);
403 g_assert (global_lagent_gathering_done == TRUE);
404 g_assert (global_ragent_gathering_done == TRUE);
407 /* step: find out the local candidates of each agent */
409 priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &raddr);
410 g_debug ("test-fallback: local RTP port R %u",
411 nice_address_get_port (&raddr));
413 priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &laddr);
414 g_debug ("test-fallback: local RTP port L %u",
415 nice_address_get_port (&laddr));
417 priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &raddr_rtcp);
418 g_debug ("test-fallback: local RTCP port R %u",
419 nice_address_get_port (&raddr_rtcp));
421 priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &laddr_rtcp);
422 g_debug ("test-fallback: local RTCP port L %u",
423 nice_address_get_port (&laddr_rtcp));
425 /* step: exchange candidate information but not the credentials */
427 cdes.component_id = NICE_COMPONENT_TYPE_RTP;
428 cdes.addr = raddr;
429 g_assert (nice_agent_set_selected_remote_candidate (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &cdes));
431 cdes.addr = laddr;
432 g_assert (nice_agent_set_selected_remote_candidate (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &cdes));
434 cdes.component_id = NICE_COMPONENT_TYPE_RTCP;
435 cdes.addr = raddr_rtcp;
436 g_assert (nice_agent_set_selected_remote_candidate (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &cdes));
438 cdes.addr = laddr_rtcp;
439 g_assert (nice_agent_set_selected_remote_candidate (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &cdes));
441 g_debug ("test-fallback: Requested for fallback, running mainloop until component state change is completed...");
443 /* step: run the mainloop until connectivity checks succeed
444 * (see timer_cb() above) */
445 if (global_components_ready < global_components_ready_exit)
446 g_main_loop_run (global_mainloop);
448 /* note: verify that agents are in correct state */
449 g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
450 g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
452 /* step: next send a packet -> should work even if no ICE processing
453 * has been done */
455 g_debug ("test-fallback: Sent a payload packet, run mainloop until packet received.");
457 /* step: send a new test packet from L ot R */
458 global_ragent_read = 0;
459 g_assert (nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678") == 16);
460 global_ragent_read_exit = 16;
461 g_main_loop_run (global_mainloop);
463 /* note: verify that payload was succesfully received */
464 g_assert (global_ragent_read == 16);
466 g_debug ("test-fallback: Ran mainloop, removing streams...");
468 /* step: clean up resources and exit */
470 nice_agent_remove_stream (lagent, ls_id);
471 nice_agent_remove_stream (ragent, rs_id);
473 g_debug ("test-fallback: test COMPLETED");
475 return 0;
478 int main (void)
480 NiceAgent *lagent, *ragent; /* agent's L and R */
481 NiceAddress baseaddr;
482 int result;
483 guint timer_id;
484 const char *stun_server = NULL, *stun_server_port = NULL;
486 g_type_init ();
487 g_thread_init (NULL);
488 global_mainloop = g_main_loop_new (NULL, FALSE);
490 /* Note: impl limits ...
491 * - no multi-stream support
492 * - no IPv6 support
495 /* step: create the agents L and R */
496 lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_RFC5245);
497 ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_RFC5245);
501 /* step: add a timer to catch state changes triggered by signals */
502 timer_id = g_timeout_add (30000, timer_cb, NULL);
504 /* step: specify which local interface to use */
505 if (!nice_address_set_from_string (&baseaddr, "127.0.0.1"))
506 g_assert_not_reached ();
507 nice_agent_add_local_address (lagent, &baseaddr);
508 nice_agent_add_local_address (ragent, &baseaddr);
510 g_signal_connect (G_OBJECT (lagent), "candidate-gathering-done",
511 G_CALLBACK (cb_candidate_gathering_done), (gpointer)1);
512 g_signal_connect (G_OBJECT (ragent), "candidate-gathering-done",
513 G_CALLBACK (cb_candidate_gathering_done), (gpointer)2);
514 g_signal_connect (G_OBJECT (lagent), "component-state-changed",
515 G_CALLBACK (cb_component_state_changed), (gpointer)1);
516 g_signal_connect (G_OBJECT (ragent), "component-state-changed",
517 G_CALLBACK (cb_component_state_changed), (gpointer)2);
518 g_signal_connect (G_OBJECT (lagent), "new-selected-pair",
519 G_CALLBACK (cb_new_selected_pair), (gpointer)1);
520 g_signal_connect (G_OBJECT (ragent), "new-selected-pair",
521 G_CALLBACK (cb_new_selected_pair), (gpointer)2);
522 g_signal_connect (G_OBJECT (lagent), "new-candidate",
523 G_CALLBACK (cb_new_candidate), (gpointer)1);
524 g_signal_connect (G_OBJECT (ragent), "new-candidate",
525 G_CALLBACK (cb_new_candidate), (gpointer)2);
526 g_signal_connect (G_OBJECT (lagent), "initial-binding-request-received",
527 G_CALLBACK (cb_initial_binding_request_received), (gpointer)1);
528 g_signal_connect (G_OBJECT (ragent), "initial-binding-request-received",
529 G_CALLBACK (cb_initial_binding_request_received), (gpointer)2);
531 stun_server = getenv ("NICE_STUN_SERVER");
532 stun_server_port = getenv ("NICE_STUN_SERVER_PORT");
533 if (stun_server) {
534 g_object_set (G_OBJECT (lagent), "stun-server", stun_server, NULL);
535 g_object_set (G_OBJECT (lagent), "stun-server-port", atoi (stun_server_port), NULL);
536 g_object_set (G_OBJECT (ragent), "stun-server", stun_server, NULL);
537 g_object_set (G_OBJECT (ragent), "stun-server-port", atoi (stun_server_port), NULL);
540 /* step: run test the first time */
541 g_debug ("test-fallback: TEST STARTS / fallback test");
542 result = run_fallback_test (lagent, ragent, &baseaddr);
543 priv_print_global_status ();
544 g_assert (result == 0);
545 g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
546 g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
548 /* step: run the safe test without sending any stnu */
549 g_debug ("test-fallback: TEST STARTS / safe fallback test");
550 result = run_safe_fallback_test (lagent, ragent, &baseaddr);
551 priv_print_global_status ();
552 g_assert (result == 0);
553 g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
554 g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
556 g_object_unref (lagent);
557 g_object_unref (ragent);
559 g_main_loop_unref (global_mainloop);
560 global_mainloop = NULL;
562 g_source_remove (timer_id);
564 return result;