summaryrefslogtreecommitdiff
path: root/test.c
blob: 22684fafb7891edf7e89cbf1b8a39374f421d98e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "pn_core.h"
#include "pn_session.h"

#include <signal.h>

static GMainLoop *loop;

static void
error_cb(struct pn_session *session,
	 GError **error)
{
	g_message("error: %s", (*error)->message);
	g_clear_error(error);
	g_main_loop_quit(loop);
}

static void
signal_handler(int signal)
{
	g_main_loop_quit(loop);
}

int main(int argc, char *argv[])
{
	struct pn_session *session;
	gulong error_handler;

	g_type_init();
	pn_core_init();

	signal(SIGINT, signal_handler);

	loop = g_main_loop_new(NULL, FALSE);
	session = pn_session_new(argv[1], argv[2]);
	error_handler = g_signal_connect(session, "error", G_CALLBACK(error_cb), NULL);

	pn_session_connect(session, "messenger.hotmail.com", 1863);
	g_message("connecting");

	g_main_loop_run(loop);

	g_signal_handler_disconnect(session, error_handler);
	pn_session_free(session);
	g_main_loop_unref(loop);

	pn_core_deinit();

	return 0;
}