+/*
+ * 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;
+}