]> git.cworth.org Git - loudgame/commitdiff
Add actual echo-ing capability to lm-echo
authorCarl Worth <cworth@cworth.org>
Sat, 5 Jan 2008 23:20:36 +0000 (15:20 -0800)
committerCarl Worth <cworth@cworth.org>
Sat, 5 Jan 2008 23:20:36 +0000 (15:20 -0800)
lm-echo.c

index 074f4c5289c3a148b1ffe2e2aae95505ad14b1bf..312e6fee7bf2728f2abcd5b2c452b68528b7114a 100644 (file)
--- a/lm-echo.c
+++ b/lm-echo.c
@@ -77,8 +77,26 @@ handle_messages (LmMessageHandler *handler,
                  LmMessage        *m,
                  gpointer          user_data)
 {
+       LmMessage *reply;
+       gboolean result;
+       GError *error = NULL;
+       LmMessageNode *body;
+
         g_print ("Incoming message from: %s\n",
                  lm_message_node_get_attribute (m->node, "from"));
+
+       reply = lm_message_new (lm_message_node_get_attribute (m->node, "from"),
+                               LM_MESSAGE_TYPE_MESSAGE);
+       body = lm_message_node_get_child (m->node, "body");
+       lm_message_node_add_child (reply->node, "body",
+                                  lm_message_node_get_value (body));
+
+       result = lm_connection_send (connection, reply, &error);
+       lm_message_unref (reply);
+
+       if (! result) {
+               g_error ("lm_connection_send failed");
+       }
  
         return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 }