- g_print ("Connected callback\n");
- lm_connection_authenticate (connection,
- info->name, info->passwd, "TestLM",
- authentication_cb, info, FALSE, NULL);
- g_print ("Sent auth message\n");
+ g_print ("Connected callback\n");
+ lm_connection_authenticate (connection,
+ info->name, info->passwd, "TestLM",
+ authentication_cb, info, FALSE, NULL);
+ g_print ("Sent auth message\n");
+}
+
+static void
+send_reply (LmConnection *connection,
+ const char *peer,
+ const char *message)
+{
+ LmMessage *reply;
+ gboolean result;
+ GError *error = NULL;
+
+ reply = lm_message_new (peer, LM_MESSAGE_TYPE_MESSAGE);
+
+ lm_message_node_add_child (reply->node, "body", message);
+
+ result = lm_connection_send (connection, reply, &error);
+ lm_message_unref (reply);
+
+ if (! result) {
+ g_error ("lm_connection_send failed");
+ }
+}
+
+static void
+handle_command (LmConnection *connection,
+ const char *peer,
+ const char *command,
+ gpointer closure)
+{
+ msg_data_t *data = closure;
+ char *error;
+
+ if (strcmp (command, "quit") == 0) {
+ g_main_loop_quit (data->main_loop);
+ return;
+ }
+
+ error = g_strdup_printf ("Unknown command: '%s'", command);
+ send_reply (connection, peer, error);
+ free (error);