1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2003-2004 Imendio AB
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.
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.
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.
24 #include <loudmouth/loudmouth.h>
35 free_user_info (UserInfo *info)
38 g_free (info->passwd);
45 authentication_cb (LmConnection *connection, gboolean result, gpointer ud)
47 g_print ("Auth: %d\n", result);
48 free_user_info ((UserInfo *) ud);
53 m = lm_message_new_with_sub_type (NULL,
54 LM_MESSAGE_TYPE_PRESENCE,
55 LM_MESSAGE_SUB_TYPE_AVAILABLE);
56 g_print (":: %s\n", lm_message_node_to_string (m->node));
58 lm_connection_send (connection, m, NULL);
65 connection_open_cb (LmConnection *connection, gboolean result, UserInfo *info)
67 g_print ("Connected callback\n");
68 lm_connection_authenticate (connection,
69 info->name, info->passwd, "TestLM",
70 authentication_cb, info, FALSE, NULL);
71 g_print ("Sent auth message\n");
74 static LmHandlerResult
75 handle_messages (LmMessageHandler *handler,
76 LmConnection *connection,
80 g_print ("Incoming message from: %s\n",
81 lm_message_node_get_attribute (m->node, "from"));
83 return LM_HANDLER_RESULT_REMOVE_MESSAGE;
86 main (int argc, char **argv)
89 LmConnection *connection;
90 LmMessageHandler *handler;
96 g_print ("Usage: %s <server> <username> <password> <connectserver> <connectport>\n", argv[0]);
100 connection = lm_connection_new (argv[4]);
102 jid = g_strdup_printf ("%s@%s", argv[2], argv[1]);
103 lm_connection_set_jid (connection, jid);
106 lm_connection_set_port (connection, strtol (argv[5], (char **) NULL, 10));
108 handler = lm_message_handler_new (handle_messages, NULL, NULL);
109 lm_connection_register_message_handler (connection, handler,
110 LM_MESSAGE_TYPE_MESSAGE,
111 LM_HANDLER_PRIORITY_NORMAL);
113 lm_message_handler_unref (handler);
115 info = g_new0 (UserInfo, 1);
116 info->name = g_strdup (argv[2]);
117 info->passwd = g_strdup (argv[3]);
119 result = lm_connection_open (connection,
120 (LmResultFunction) connection_open_cb,
124 g_print ("Opening connection failed: %d\n", result);
126 g_print ("Returned from the connection_open\n");
129 main_loop = g_main_loop_new (NULL, FALSE);
130 g_main_loop_run (main_loop);