From 1b9383bc1758fa4b49ab029c730b7ba434b0f7ad Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 14 Jan 2008 20:51:21 -0800 Subject: [PATCH] Share loudgame_send code to reduce duplication. --- lg-echo.c | 16 +--------------- loudgame.c | 16 ++++++++-------- loudgame.h | 5 +++++ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/lg-echo.c b/lg-echo.c index b6a48e8..c153472 100644 --- a/lg-echo.c +++ b/lg-echo.c @@ -27,21 +27,7 @@ echo_handle_message (loudgame_t *lg, 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 (lg->connection, reply, &error); - lm_message_unref (reply); - - if (! result) { - g_error ("lm_connection_send failed: error->message"); - loudgame_quit (lg, 1); - } + loudgame_send (lg, peer, message); } int diff --git a/loudgame.c b/loudgame.c index 53b392b..e2f0af2 100644 --- a/loudgame.c +++ b/loudgame.c @@ -70,11 +70,10 @@ connection_open_cb (LmConnection *connection, gboolean result, loudgame_t *lg) authentication_cb, lg, FALSE, NULL); } -static void -send_reply (LmConnection *connection, - const char *peer, - const char *message, - loudgame_t *lg) +void +loudgame_send (loudgame_t *lg, + const char *peer, + const char *message) { LmMessage *reply; gboolean result; @@ -84,11 +83,12 @@ send_reply (LmConnection *connection, lm_message_node_add_child (reply->node, "body", message); - result = lm_connection_send (connection, reply, &error); + result = lm_connection_send (lg->connection, reply, &error); lm_message_unref (reply); if (! result) { - g_error ("lm_connection_send failed: error->message"); + g_error ("lm_connection_send failed: %s\n", + error->message); loudgame_quit (lg, 1); } } @@ -107,7 +107,7 @@ handle_command (LmConnection *connection, } error = g_strdup_printf ("Unknown command: '%s'", command); - send_reply (connection, peer, error, lg); + loudgame_send (lg, peer, error); free (error); } diff --git a/loudgame.h b/loudgame.h index 726394b..a65f5dd 100644 --- a/loudgame.h +++ b/loudgame.h @@ -46,6 +46,11 @@ loudgame_init (loudgame_t *lg, int argc, char **argv); int loudgame_run (loudgame_t *lg); +void +loudgame_send (loudgame_t *lg, + const char *peer, + const char *message); + void loudgame_quit (loudgame_t *lg, int return_value); -- 2.43.0