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