]> git.cworth.org Git - loudgame/blobdiff - lm-echo.c
Simplify command-line arguments
[loudgame] / lm-echo.c
index d92188bd14510e66de361b55ad92a660bbda0667..687ac3ce4b004a5e16151ec57f7ecbaced031460 100644 (file)
--- a/lm-echo.c
+++ b/lm-echo.c
@@ -34,22 +34,10 @@ typedef struct {
     GMainLoop  *main_loop;
 } msg_data_t;
  
-static void
-free_user_info (UserInfo *info)
-{
-    g_free (info->name);
-    g_free (info->passwd);
-    g_free (info);
-}
 static void
 authentication_cb (LmConnection *connection, gboolean result, gpointer ud)
 {
-    gchar *string;
-
     g_print ("Auth: %d\n", result);
-    free_user_info ((UserInfo *) ud);
  
     if (result == TRUE) {
        LmMessage *m;
@@ -57,9 +45,6 @@ authentication_cb (LmConnection *connection, gboolean result, gpointer ud)
        m = lm_message_new_with_sub_type (NULL,
                                          LM_MESSAGE_TYPE_PRESENCE,
                                          LM_MESSAGE_SUB_TYPE_AVAILABLE);
-       string = lm_message_node_to_string (m->node);
-       g_print (":: %s\n", string);
-       free (string);
                  
        lm_connection_send (connection, m, NULL);
        lm_message_unref (m);
@@ -70,11 +55,9 @@ authentication_cb (LmConnection *connection, gboolean result, gpointer ud)
 static void
 connection_open_cb (LmConnection *connection, gboolean result, UserInfo *info)
 {
-    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
@@ -129,9 +112,6 @@ handle_messages (LmMessageHandler *handler,
 
     peer = lm_message_node_get_attribute (m->node, "from");
 
-
-    g_print ("Incoming message from: %s\n", peer);
-
     body = lm_message_node_get_child (m->node, "body");
     if (body) {
        body_str = lm_message_node_get_value (body);
@@ -150,24 +130,22 @@ main (int argc, char **argv)
     LmConnection     *connection;
     LmMessageHandler *handler;
     gboolean          result;
-    UserInfo         *info;
+    UserInfo          info;
     gchar            *jid;
     msg_data_t       data;
     GError          *error;
 
-    if (argc < 6) {
-       g_print ("Usage: %s <server> <username> <password> <connectserver> <connectport>\n", argv[0]);
+    if (argc != 4) {
+       g_print ("Usage: %s <server> <username> <password>\n", argv[0]);
        return 1;
     }
                                                                                 
-    connection = lm_connection_new (argv[4]);
+    connection = lm_connection_new (argv[1]);
 
     jid = g_strdup_printf ("%s@%s", argv[2], argv[1]);
     lm_connection_set_jid (connection, jid);
     g_free (jid);
 
-    lm_connection_set_port (connection, strtol (argv[5], (char **) NULL, 10));
-
     data.main_loop = g_main_loop_new (NULL, FALSE);
 
     handler = lm_message_handler_new (handle_messages, &data, NULL);
@@ -177,18 +155,15 @@ main (int argc, char **argv)
                                                                                 
     lm_message_handler_unref (handler);
                                                                                 
-    info = g_new0 (UserInfo, 1);
-    info->name = g_strdup (argv[2]);
-    info->passwd = g_strdup (argv[3]);
+    info.name = argv[2];
+    info.passwd = argv[3];
                                                                                 
     result = lm_connection_open (connection,
                                 (LmResultFunction) connection_open_cb,
-                                info, NULL, NULL);
-                                                                                
+                                &info, NULL, NULL);
     if (!result) {
        g_print ("Opening connection failed: %d\n", result);
-    } else {
-       g_print ("Returned from the connection_open\n");
+       exit (1);
     }
                                                                                 
     g_main_loop_run (data.main_loop);