Added a test program to connect to a XMPP server and send a client stream
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 2 Nov 2008 02:58:12 +0000 (00:58 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 2 Nov 2008 02:58:12 +0000 (00:58 -0200)
Makefile
tictactoe.c [new file with mode: 0644]

index 33f423a..d855658 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,15 @@
-OBJECTS = sort_udns.o tcp_connect.o
+OBJECTS = sort_udns.o tcp_connect.o iksemel_extra.o tictactoe.o
 CC = gcc
-CFLAGS = -g -Wall
-LIBS = -ludns
+CFLAGS = -g -Wall `pkg-config --cflags iksemel`
+LIBS = -ludns `pkg-config --libs iksemel`
 
-all: $(OBJECTS)
+all: tictactoe
+
+tictactoe: $(OBJECTS)
+       $(CC) $(CFLAGS) $(LIBS) -o tictactoe $(OBJECTS)
 
 .c.o:
        $(CC) $(CFLAGS) -c $< -o $@
 
 clean:
-       rm -f $(OBJECTS)
+       rm -f $(OBJECTS) tictactoe
diff --git a/tictactoe.c b/tictactoe.c
new file mode 100644 (file)
index 0000000..5c7e599
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ *  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.
+ */
+
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <udns.h>
+#include <unistd.h>
+#include <string.h>
+#include "tcp_connect.h"
+#include "iksemel_extra.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)
+{
+  char buffer[4096];
+  int r;
+  while ((r = read (fd, buffer, sizeof (buffer))) > 0)
+    iks_parse (parser, buffer, r, 0);
+}
+
+int
+main (int argc, char **argv)
+{
+  char *server = "jabber-br.org";
+  int fd;
+  iksparser *parser;
+  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);
+  return 0;
+}