From 2ba16182c4d0f9e08cc1427587701de04090df08 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sun, 2 Nov 2008 00:58:12 -0200 Subject: [PATCH] Added a test program to connect to a XMPP server and send a client stream --- Makefile | 13 ++++++---- tictactoe.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 tictactoe.c diff --git a/Makefile b/Makefile index 33f423a..d855658 100644 --- 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 index 0000000..5c7e599 --- /dev/null +++ b/tictactoe.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2008 Thadeu Lima de Souza Cascardo + * + * 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 +#include +#include +#include +#include +#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, "", 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; +} -- 2.20.1