Added GLib loop main program
[cascardo/chat.git] / ui.c
diff --git a/ui.c b/ui.c
new file mode 100644 (file)
index 0000000..7574652
--- /dev/null
+++ b/ui.c
@@ -0,0 +1,58 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+
+#include <stdio.h>
+#include <glib.h>
+#include <udns.h>
+#include "tcp_connect.h"
+#include "xmpp.h"
+
+static gboolean
+rploop (GIOChannel *src, GIOCondition cond, gpointer xmpp)
+{
+  hc_xmpp_read_and_parse (xmpp);
+  return TRUE;
+}
+
+int
+main (int argc, char **argv)
+{
+  GMainLoop *loop;
+  GIOChannel *channel;
+  char *server;
+  char *user;
+  char *password;
+  hc_xmpp_t *xmpp;
+  if (argc < 4)
+    {
+      printf ("tictactoe server user password\n");
+      return 1;
+    }
+  server = argv[1];
+  user = argv[2];
+  password = argv[3];
+  dns_init (NULL, 1);
+  xmpp = hc_xmpp_new (hc_xmpp_hook, server, user, password);
+  hc_xmpp_send_stream (xmpp);
+  channel = g_io_channel_unix_new (hc_xmpp_fd (xmpp));
+  loop = g_main_loop_new (g_main_context_default (), TRUE);
+  g_io_add_watch (channel, G_IO_IN, rploop, xmpp);
+  g_main_loop_run (loop);
+  return 0;
+}