83
|
1 |
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
|
2 |
/* |
|
3 |
* Copyright (C) 2003 Imendio HB |
|
4 |
* Copyright (C) 2003 Mikael Hallendal <micke@imendio.com> |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU Lesser General Public License as |
|
8 |
* published by the Free Software Foundation; either version 2 of the |
|
9 |
* License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
* Lesser General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU Lesser General Public |
|
17 |
* License along with this program; if not, write to the |
|
18 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
19 |
* Boston, MA 02111-1307, USA. |
|
20 |
*/ |
|
21 |
|
|
22 |
#include <config.h> |
|
23 |
|
|
24 |
#include <glib.h> |
|
25 |
#include <string.h> |
|
26 |
#include <stdlib.h> |
|
27 |
#include <loudmouth/loudmouth.h> |
|
28 |
#ifdef __WIN32__ |
|
29 |
#include <winsock2.h> |
|
30 |
#endif |
|
31 |
|
|
32 |
typedef struct { |
|
33 |
gchar *name; |
|
34 |
gchar *passwd; |
|
35 |
} UserInfo; |
|
36 |
|
|
37 |
static void |
|
38 |
free_user_info (UserInfo *info) |
|
39 |
{ |
|
40 |
g_free (info->name); |
|
41 |
g_free (info->passwd); |
|
42 |
|
|
43 |
g_free (info); |
|
44 |
} |
|
45 |
|
|
46 |
|
|
47 |
static void |
|
48 |
authentication_cb (LmConnection *connection, gboolean result, gpointer ud) |
|
49 |
{ |
|
50 |
g_print ("Auth: %d\n", result); |
|
51 |
free_user_info ((UserInfo *) ud); |
|
52 |
|
|
53 |
if (result == TRUE) { |
|
54 |
LmMessage *m; |
|
55 |
|
|
56 |
m = lm_message_new_with_sub_type (NULL, |
|
57 |
LM_MESSAGE_TYPE_PRESENCE, |
|
58 |
LM_MESSAGE_SUB_TYPE_AVAILABLE); |
|
59 |
g_print (":: %s\n", lm_message_node_to_string (m->node)); |
|
60 |
|
|
61 |
lm_connection_send (connection, m, NULL); |
|
62 |
lm_message_unref (m); |
|
63 |
} |
|
64 |
|
|
65 |
} |
|
66 |
|
|
67 |
static void |
|
68 |
connection_open_cb (LmConnection *connection, gboolean result, UserInfo *info) |
|
69 |
{ |
|
70 |
g_print ("Connected callback\n"); |
|
71 |
lm_connection_authenticate (connection, |
|
72 |
info->name, info->passwd, "TestLM", |
|
73 |
authentication_cb, info, FALSE, NULL); |
|
74 |
g_print ("Sent auth message\n"); |
|
75 |
} |
|
76 |
|
|
77 |
static LmHandlerResult |
|
78 |
handle_messages (LmMessageHandler *handler, |
|
79 |
LmConnection *connection, |
|
80 |
LmMessage *m, |
|
81 |
gpointer user_data) |
|
82 |
{ |
|
83 |
g_print ("Incoming message from: %s\n", |
|
84 |
lm_message_node_get_attribute (m->node, "from")); |
|
85 |
|
|
86 |
return LM_HANDLER_RESULT_REMOVE_MESSAGE; |
|
87 |
} |
|
88 |
int |
|
89 |
main (int argc, char **argv) |
|
90 |
{ |
|
91 |
GMainLoop *main_loop; |
|
92 |
LmConnection *connection; |
|
93 |
LmMessageHandler *handler; |
|
94 |
gboolean result; |
|
95 |
UserInfo *info; |
|
96 |
LmProxy *proxy; |
|
97 |
guint proxy_port; |
|
98 |
|
|
99 |
if (argc < 6) { |
|
100 |
g_print ("Usage: test-lm <server> <username> <password> <proxyserver> <proxyport>\n"); |
|
101 |
return 1; |
|
102 |
} |
|
103 |
|
|
104 |
connection = lm_connection_new (argv[1]); |
|
105 |
|
|
106 |
proxy = lm_proxy_new (LM_PROXY_TYPE_HTTP); |
|
107 |
lm_proxy_set_server (proxy, argv[4]); |
|
108 |
|
|
109 |
proxy_port = strtol (argv[5], (char **) NULL, 10); |
|
110 |
lm_proxy_set_port (proxy, proxy_port); |
|
111 |
lm_connection_set_proxy (connection, proxy); |
|
112 |
lm_proxy_unref (proxy); |
|
113 |
|
|
114 |
handler = lm_message_handler_new (handle_messages, NULL, NULL); |
|
115 |
lm_connection_register_message_handler (connection, handler, |
|
116 |
LM_MESSAGE_TYPE_MESSAGE, |
|
117 |
LM_HANDLER_PRIORITY_NORMAL); |
|
118 |
|
|
119 |
lm_message_handler_unref (handler); |
|
120 |
|
|
121 |
info = g_new0 (UserInfo, 1); |
|
122 |
info->name = g_strdup (argv[2]); |
|
123 |
info->passwd = g_strdup (argv[3]); |
|
124 |
|
|
125 |
result = lm_connection_open (connection, |
|
126 |
(LmResultFunction) connection_open_cb, |
|
127 |
info, NULL, NULL); |
|
128 |
|
|
129 |
if (!result) { |
|
130 |
g_print ("Opening connection failed: %d\n", result); |
|
131 |
} else { |
|
132 |
g_print ("Returned from the connection_open\n"); |
|
133 |
} |
|
134 |
|
|
135 |
main_loop = g_main_loop_new (NULL, FALSE); |
|
136 |
g_main_loop_run (main_loop); |
|
137 |
|
|
138 |
return 0; |
|
139 |
} |
|
140 |
|