Correctly generate WLM2009 username
[sipe-libnice.git] / tests / test-fallback.c
blobef9141610ee674de253effba4a269fdee351f9c0
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...");
83 static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, guint len, gchar *buf, gpointer user_data)
85 g_debug ("test-fallback:%s: %p", G_STRFUNC, user_data);
87 /* XXX: dear compiler, these are for you: */
88 (void)agent; (void)stream_id; (void)component_id; (void)buf;
91 * Lets ignore stun packets that got through
93 if (len != 16 || strncmp ("1234567812345678", buf, 16)) {
94 if (global_accept_non_data)
95 return;
96 else
97 g_error ("Got non-data packet of lenght %u", len);
100 if ((intptr_t)user_data == 2) {
101 global_ragent_read += len;
103 if (global_ragent_read == global_ragent_read_exit)
104 g_main_loop_quit (global_mainloop);
108 static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer data)
110 g_debug ("test-fallback:%s: %p", G_STRFUNC, data);
112 if ((intptr_t)data == 1)
113 global_lagent_gathering_done = TRUE;
114 else if ((intptr_t)data == 2)
115 global_ragent_gathering_done = TRUE;
117 if (global_lagent_gathering_done &&
118 global_ragent_gathering_done)
119 g_main_loop_quit (global_mainloop);
121 /* XXX: dear compiler, these are for you: */
122 (void)agent;
125 static void cb_component_state_changed (NiceAgent *agent, guint stream_id, guint component_id, guint state, gpointer data)
127 g_debug ("test-fallback:%s: %p", __func__, data);
129 if ((intptr_t)data == 1)
130 global_lagent_state = state;
131 else if ((intptr_t)data == 2)
132 global_ragent_state = state;
134 if (state == NICE_COMPONENT_STATE_READY)
135 global_components_ready++;
136 if (state == NICE_COMPONENT_STATE_FAILED)
137 global_components_failed++;
139 g_debug ("test-fallback: READY %u exit at %u.", global_components_ready, global_components_ready_exit);
141 /* signal status via a global variable */
142 if (global_components_ready == global_components_ready_exit) {
143 g_main_loop_quit (global_mainloop);
144 return;
147 /* signal status via a global variable */
148 if (global_components_failed == global_components_failed_exit) {
149 g_main_loop_quit (global_mainloop);
150 return;
153 /* XXX: dear compiler, these are for you: */
154 (void)agent; (void)stream_id; (void)data; (void)component_id;
157 static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint component_id,
158 gchar *lfoundation, gchar* rfoundation, gpointer data)
160 g_debug ("test-fallback:%s: %p", __func__, data);
162 if ((intptr_t)data == 1)
163 ++global_lagent_cands;
164 else if ((intptr_t)data == 2)
165 ++global_ragent_cands;
167 /* XXX: dear compiler, these are for you: */
168 (void)agent; (void)stream_id; (void)component_id; (void)lfoundation; (void)rfoundation;
171 static void cb_new_candidate(NiceAgent *agent, guint stream_id, guint component_id,
172 gchar *foundation, gpointer data)
174 g_debug ("test-fallback:%s: %p", __func__, data);
176 /* XXX: dear compiler, these are for you: */
177 (void)agent; (void)stream_id; (void)data; (void)component_id; (void)foundation;
180 static void cb_initial_binding_request_received(NiceAgent *agent, guint stream_id, gpointer data)
182 g_debug ("test-fallback:%s: %p", __func__, data);
184 if ((intptr_t)data == 1)
185 global_lagent_ibr_received = TRUE;
186 else if ((intptr_t)data == 2)
187 global_ragent_ibr_received = TRUE;
189 /* XXX: dear compiler, these are for you: */
190 (void)agent; (void)stream_id; (void)data;
193 static void priv_get_local_addr (NiceAgent *agent, guint stream_id, guint component_id, NiceAddress *dstaddr)
195 GSList *cands, *i;
196 cands = nice_agent_get_local_candidates(agent, stream_id, component_id);
197 for (i = cands; i; i = i->next) {
198 NiceCandidate *cand = i->data;
199 if (cand) {
200 g_assert (dstaddr);
201 *dstaddr = cand->addr;
202 break;
205 for (i = cands; i; i = i->next)
206 nice_candidate_free ((NiceCandidate *) i->data);
207 g_slist_free (cands);
210 static int run_fallback_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr)
212 NiceAddress laddr, raddr, laddr_rtcp, raddr_rtcp;
213 NiceCandidate cdes;
214 GSList *cands;
215 guint ls_id, rs_id;
217 memset (&cdes, 0, sizeof(NiceCandidate));
218 cdes.priority = 100000;
219 strcpy (cdes.foundation, "1");
220 cdes.type = NICE_CANDIDATE_TYPE_HOST;
221 cdes.transport = NICE_CANDIDATE_TRANSPORT_UDP;
222 cdes.base_addr = *baseaddr;
224 /* step: initialize variables modified by the callbacks */
225 global_components_ready = 0;
226 global_components_ready_exit = 4;
227 global_components_failed = 0;
228 global_components_failed_exit = 4;
229 global_lagent_gathering_done = FALSE;
230 global_ragent_gathering_done = FALSE;
231 global_lagent_ibr_received =
232 global_ragent_ibr_received = FALSE;
233 global_lagent_cands =
234 global_ragent_cands = 0;
235 global_ragent_read_exit = -1;
237 g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
238 g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);
240 /* step: add one stream, with RTP+RTCP components, to each agent */
241 ls_id = nice_agent_add_stream (lagent, 2);
242 rs_id = nice_agent_add_stream (ragent, 2);
243 g_assert (ls_id > 0);
244 g_assert (rs_id > 0);
246 nice_agent_gather_candidates (lagent, ls_id);
247 nice_agent_gather_candidates (ragent, rs_id);
249 /* step: attach to mainloop (needed to register the fds) */
250 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
251 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)1);
252 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP,
253 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)1);
254 nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
255 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)2);
256 nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP,
257 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)2);
259 /* step: run mainloop until local candidates are ready
260 * (see timer_cb() above) */
261 if (global_lagent_gathering_done != TRUE ||
262 global_ragent_gathering_done != TRUE) {
263 g_debug ("test-fallback: Added streams, running mainloop until 'candidate-gathering-done'...");
264 g_main_loop_run (global_mainloop);
265 g_assert (global_lagent_gathering_done == TRUE);
266 g_assert (global_ragent_gathering_done == TRUE);
269 /* step: find out the local candidates of each agent */
271 priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &raddr);
272 g_debug ("test-fallback: local RTP port R %u",
273 nice_address_get_port (&raddr));
275 priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &laddr);
276 g_debug ("test-fallback: local RTP port L %u",
277 nice_address_get_port (&laddr));
279 priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &raddr_rtcp);
280 g_debug ("test-fallback: local RTCP port R %u",
281 nice_address_get_port (&raddr_rtcp));
283 priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &laddr_rtcp);
284 g_debug ("test-fallback: local RTCP port L %u",
285 nice_address_get_port (&laddr_rtcp));
287 /* step: exchange candidate information but not the credentials */
289 cands = g_slist_append (NULL, &cdes);
290 cdes.component_id = NICE_COMPONENT_TYPE_RTP;
291 cdes.addr = raddr;
292 nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, cands);
293 cdes.addr = laddr;
294 nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, cands);
295 cdes.component_id = NICE_COMPONENT_TYPE_RTCP;
296 cdes.addr = raddr_rtcp;
297 nice_agent_set_remote_candidates (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, cands);
298 cdes.addr = laddr_rtcp;
299 nice_agent_set_remote_candidates (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, cands);
301 /* step: fall back to non-ICE mode on both sides */
302 g_assert (nice_agent_set_selected_pair (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, "1", "1") == TRUE);
303 g_assert (nice_agent_set_selected_pair (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, "1", "1") == TRUE);
304 g_assert (nice_agent_set_selected_pair (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, "1", "1") == TRUE);
305 g_assert (nice_agent_set_selected_pair (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, "1", "1") == TRUE);
307 g_debug ("test-fallback: Requested for fallback, running mainloop until component state change is completed...");
309 /* step: run the mainloop until connectivity checks succeed
310 * (see timer_cb() above) */
311 if (global_components_ready < global_components_ready_exit)
312 g_main_loop_run (global_mainloop);
314 /* note: verify that agents are in correct state */
315 g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
316 g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
318 /* step: next send a packet -> should work even if no ICE processing
319 * has been done */
321 g_debug ("test-fallback: Sent a payload packet, run mainloop until packet received.");
323 /* step: send a new test packet from L ot R */
324 global_ragent_read = 0;
325 g_assert (nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678") == 16);
326 global_ragent_read_exit = 16;
327 g_main_loop_run (global_mainloop);
329 /* note: verify that payload was succesfully received */
330 g_assert (global_ragent_read == 16);
332 g_debug ("test-fallback: Ran mainloop, removing streams...");
334 /* step: clean up resources and exit */
336 g_slist_free (cands);
337 nice_agent_remove_stream (lagent, ls_id);
338 nice_agent_remove_stream (ragent, rs_id);
340 g_debug ("test-fallback: test COMPLETED");
342 return 0;
346 static int run_safe_fallback_test (NiceAgent *lagent, NiceAgent *ragent, NiceAddress *baseaddr)
348 NiceAddress laddr, raddr, laddr_rtcp, raddr_rtcp;
349 NiceCandidate cdes;
350 guint ls_id, rs_id;
352 memset (&cdes, 0, sizeof(NiceCandidate));
353 cdes.priority = 100000;
354 strcpy (cdes.foundation, "1");
355 cdes.type = NICE_CANDIDATE_TYPE_HOST;
356 cdes.transport = NICE_CANDIDATE_TRANSPORT_UDP;
357 cdes.base_addr = *baseaddr;
359 /* step: initialize variables modified by the callbacks */
360 global_components_ready = 0;
361 global_components_ready_exit = 4;
362 global_components_failed = 0;
363 global_components_failed_exit = 4;
364 global_lagent_gathering_done = FALSE;
365 global_ragent_gathering_done = FALSE;
366 global_lagent_ibr_received =
367 global_ragent_ibr_received = FALSE;
368 global_lagent_cands =
369 global_ragent_cands = 0;
370 global_ragent_read_exit = -1;
371 global_accept_non_data = FALSE;
373 g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
374 g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);
376 /* step: add one stream, with RTP+RTCP components, to each agent */
377 ls_id = nice_agent_add_stream (lagent, 2);
378 rs_id = nice_agent_add_stream (ragent, 2);
379 g_assert (ls_id > 0);
380 g_assert (rs_id > 0);
382 nice_agent_gather_candidates (lagent, ls_id);
383 nice_agent_gather_candidates (ragent, rs_id);
385 /* step: attach to mainloop (needed to register the fds) */
386 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTP,
387 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)1);
388 nice_agent_attach_recv (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP,
389 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)1);
390 nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTP,
391 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)2);
392 nice_agent_attach_recv (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP,
393 g_main_loop_get_context (global_mainloop), cb_nice_recv, (gpointer)2);
395 /* step: run mainloop until local candidates are ready
396 * (see timer_cb() above) */
397 if (global_lagent_gathering_done != TRUE ||
398 global_ragent_gathering_done != TRUE) {
399 g_debug ("test-fallback: Added streams, running mainloop until 'candidate-gathering-done'...");
400 g_main_loop_run (global_mainloop);
401 g_assert (global_lagent_gathering_done == TRUE);
402 g_assert (global_ragent_gathering_done == TRUE);
405 /* step: find out the local candidates of each agent */
407 priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &raddr);
408 g_debug ("test-fallback: local RTP port R %u",
409 nice_address_get_port (&raddr));
411 priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &laddr);
412 g_debug ("test-fallback: local RTP port L %u",
413 nice_address_get_port (&laddr));
415 priv_get_local_addr (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &raddr_rtcp);
416 g_debug ("test-fallback: local RTCP port R %u",
417 nice_address_get_port (&raddr_rtcp));
419 priv_get_local_addr (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &laddr_rtcp);
420 g_debug ("test-fallback: local RTCP port L %u",
421 nice_address_get_port (&laddr_rtcp));
423 /* step: exchange candidate information but not the credentials */
425 cdes.component_id = NICE_COMPONENT_TYPE_RTP;
426 cdes.addr = raddr;
427 g_assert (nice_agent_set_selected_remote_candidate (lagent, ls_id, NICE_COMPONENT_TYPE_RTP, &cdes));
429 cdes.addr = laddr;
430 g_assert (nice_agent_set_selected_remote_candidate (ragent, rs_id, NICE_COMPONENT_TYPE_RTP, &cdes));
432 cdes.component_id = NICE_COMPONENT_TYPE_RTCP;
433 cdes.addr = raddr_rtcp;
434 g_assert (nice_agent_set_selected_remote_candidate (lagent, ls_id, NICE_COMPONENT_TYPE_RTCP, &cdes));
436 cdes.addr = laddr_rtcp;
437 g_assert (nice_agent_set_selected_remote_candidate (ragent, rs_id, NICE_COMPONENT_TYPE_RTCP, &cdes));
439 g_debug ("test-fallback: Requested for fallback, running mainloop until component state change is completed...");
441 /* step: run the mainloop until connectivity checks succeed
442 * (see timer_cb() above) */
443 if (global_components_ready < global_components_ready_exit)
444 g_main_loop_run (global_mainloop);
446 /* note: verify that agents are in correct state */
447 g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
448 g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
450 /* step: next send a packet -> should work even if no ICE processing
451 * has been done */
453 g_debug ("test-fallback: Sent a payload packet, run mainloop until packet received.");
455 /* step: send a new test packet from L ot R */
456 global_ragent_read = 0;
457 g_assert (nice_agent_send (lagent, ls_id, 1, 16, "1234567812345678") == 16);
458 global_ragent_read_exit = 16;
459 g_main_loop_run (global_mainloop);
461 /* note: verify that payload was succesfully received */
462 g_assert (global_ragent_read == 16);
464 g_debug ("test-fallback: Ran mainloop, removing streams...");
466 /* step: clean up resources and exit */
468 nice_agent_remove_stream (lagent, ls_id);
469 nice_agent_remove_stream (ragent, rs_id);
471 g_debug ("test-fallback: test COMPLETED");
473 return 0;
476 int main (void)
478 NiceAgent *lagent, *ragent; /* agent's L and R */
479 NiceAddress baseaddr;
480 int result;
481 guint timer_id;
482 const char *stun_server = NULL, *stun_server_port = NULL;
484 g_type_init ();
485 g_thread_init (NULL);
486 global_mainloop = g_main_loop_new (NULL, FALSE);
488 /* Note: impl limits ...
489 * - no multi-stream support
490 * - no IPv6 support
493 /* step: create the agents L and R */
494 lagent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_DRAFT19);
495 ragent = nice_agent_new (g_main_loop_get_context (global_mainloop), NICE_COMPATIBILITY_DRAFT19);
499 /* step: add a timer to catch state changes triggered by signals */
500 timer_id = g_timeout_add (30000, timer_cb, NULL);
502 /* step: specify which local interface to use */
503 if (!nice_address_set_from_string (&baseaddr, "127.0.0.1"))
504 g_assert_not_reached ();
505 nice_agent_add_local_address (lagent, &baseaddr);
506 nice_agent_add_local_address (ragent, &baseaddr);
508 g_signal_connect (G_OBJECT (lagent), "candidate-gathering-done",
509 G_CALLBACK (cb_candidate_gathering_done), (gpointer)1);
510 g_signal_connect (G_OBJECT (ragent), "candidate-gathering-done",
511 G_CALLBACK (cb_candidate_gathering_done), (gpointer)2);
512 g_signal_connect (G_OBJECT (lagent), "component-state-changed",
513 G_CALLBACK (cb_component_state_changed), (gpointer)1);
514 g_signal_connect (G_OBJECT (ragent), "component-state-changed",
515 G_CALLBACK (cb_component_state_changed), (gpointer)2);
516 g_signal_connect (G_OBJECT (lagent), "new-selected-pair",
517 G_CALLBACK (cb_new_selected_pair), (gpointer)1);
518 g_signal_connect (G_OBJECT (ragent), "new-selected-pair",
519 G_CALLBACK (cb_new_selected_pair), (gpointer)2);
520 g_signal_connect (G_OBJECT (lagent), "new-candidate",
521 G_CALLBACK (cb_new_candidate), (gpointer)1);
522 g_signal_connect (G_OBJECT (ragent), "new-candidate",
523 G_CALLBACK (cb_new_candidate), (gpointer)2);
524 g_signal_connect (G_OBJECT (lagent), "initial-binding-request-received",
525 G_CALLBACK (cb_initial_binding_request_received), (gpointer)1);
526 g_signal_connect (G_OBJECT (ragent), "initial-binding-request-received",
527 G_CALLBACK (cb_initial_binding_request_received), (gpointer)2);
529 stun_server = getenv ("NICE_STUN_SERVER");
530 stun_server_port = getenv ("NICE_STUN_SERVER_PORT");
531 if (stun_server) {
532 g_object_set (G_OBJECT (lagent), "stun-server", stun_server, NULL);
533 g_object_set (G_OBJECT (lagent), "stun-server-port", atoi (stun_server_port), NULL);
534 g_object_set (G_OBJECT (ragent), "stun-server", stun_server, NULL);
535 g_object_set (G_OBJECT (ragent), "stun-server-port", atoi (stun_server_port), NULL);
538 /* step: run test the first time */
539 g_debug ("test-fallback: TEST STARTS / fallback test");
540 result = run_fallback_test (lagent, ragent, &baseaddr);
541 priv_print_global_status ();
542 g_assert (result == 0);
543 g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
544 g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
546 /* step: run the safe test without sending any stnu */
547 g_debug ("test-fallback: TEST STARTS / safe fallback test");
548 result = run_safe_fallback_test (lagent, ragent, &baseaddr);
549 priv_print_global_status ();
550 g_assert (result == 0);
551 g_assert (global_lagent_state == NICE_COMPONENT_STATE_READY);
552 g_assert (global_ragent_state == NICE_COMPONENT_STATE_READY);
554 g_object_unref (lagent);
555 g_object_unref (ragent);
557 g_main_loop_unref (global_mainloop);
558 global_mainloop = NULL;
560 g_source_remove (timer_id);
562 return result;