Fix bug with uninitialized variable.
[cascardo/chat.git] / tictactoe.c
index 5c7e599..e929663 100644 (file)
 #include <string.h>
 #include "tcp_connect.h"
 #include "iksemel_extra.h"
+#include "xmpp.h"
+#include "disco.h"
 
-int
-myhook (void *data, int type, iks *stanza)
-{
-  char *s = iks_string (iks_stack (stanza), stanza);
-  write (1, s, strlen (s));
-  return IKS_OK;
-}
-
-void
-write_stream (int fd, char *server)
-{
-  char *buffer = NULL;
-  asprintf (&buffer, "<stream:stream xmlns='jabber:client' "
-                     "xmlns:stream='http://etherx.jabber.org/streams' "
-                     "version='1.0' to='%s'>", server);
-  write (fd, buffer, strlen (buffer));
-  free (buffer);
-}
-
-void
-loop (iksparser *parser, int fd)
+static void
+loop (hc_xmpp_t *xmpp)
 {
-  char buffer[4096];
-  int r;
-  while ((r = read (fd, buffer, sizeof (buffer))) > 0)
-    iks_parse (parser, buffer, r, 0);
+  while (1)
+    hc_xmpp_read_and_parse (xmpp);
 }
 
 int
 main (int argc, char **argv)
 {
-  char *server = "jabber-br.org";
-  int fd;
-  iksparser *parser;
+  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);
-  fd = hc_tcp_connect (server, "xmpp-client");
-  parser = iks_extra_stream_new (NULL, myhook);
-  write_stream (fd, server);
-  loop (parser, fd);
+  xmpp = hc_xmpp_new (hc_xmpp_hook, server, user, password);
+  hc_xmpp_send_stream (xmpp);
+  loop (xmpp);
   return 0;
 }