From 282bba49cf4dcad9e844e61d70d0ab7ea1c7cb22 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Mon, 3 Nov 2008 08:52:50 -0200 Subject: [PATCH] Added GLib loop main program --- Makefile | 17 ++++++++++------- ui.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 ui.c diff --git a/Makefile b/Makefile index 6a87a8b..de2d9c2 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,19 @@ -OBJECTS = sort_udns.o tcp_connect.o iksemel_extra.o tictactoe.o \ +OBJECTS = sort_udns.o tcp_connect.o iksemel_extra.o \ xmpp.o features.o sasl.o bind.o disco.o hook.o CC = gcc -CFLAGS = -g -Wall `pkg-config --cflags iksemel libgsasl` -LIBS = -ludns `pkg-config --libs iksemel libgsasl` +CFLAGS = -g -Wall `pkg-config --cflags iksemel libgsasl glib-2.0` +LIBS = -ludns `pkg-config --libs iksemel libgsasl glib-2.0` -all: tictactoe +all: tictactoe ui -tictactoe: $(OBJECTS) - $(CC) $(CFLAGS) $(LIBS) -o tictactoe $(OBJECTS) +tictactoe: $(OBJECTS) tictactoe.o + $(CC) $(CFLAGS) $(LIBS) -o tictactoe $(OBJECTS) tictactoe.o + +ui: $(OBJECTS) ui.o + $(CC) $(CFLAGS) $(LIBS) -o ui $(OBJECTS) ui.o .c.o: $(CC) $(CFLAGS) -c $< -o $@ clean: - rm -f $(OBJECTS) tictactoe + rm -f $(OBJECTS) tictactoe.o tictactoe ui.o ui diff --git a/ui.c b/ui.c new file mode 100644 index 0000000..7574652 --- /dev/null +++ b/ui.c @@ -0,0 +1,58 @@ +/* + * 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. + */ + + +#include +#include +#include +#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; +} -- 2.20.1