diff options
| -rw-r--r-- | protocols/Makefile | 2 | ||||
| -rw-r--r-- | protocols/events.h | 56 | ||||
| -rw-r--r-- | protocols/events_glib.c | 100 | ||||
| -rw-r--r-- | protocols/nogaim.c | 4 | ||||
| -rw-r--r-- | protocols/proxy.c | 62 | ||||
| -rw-r--r-- | protocols/proxy.h | 13 | 
6 files changed, 161 insertions, 76 deletions
| diff --git a/protocols/Makefile b/protocols/Makefile index 4016e7fd..886f010b 100644 --- a/protocols/Makefile +++ b/protocols/Makefile @@ -9,7 +9,7 @@  -include ../Makefile.settings  # [SH] Program variables -objects = http_client.o md5.o nogaim.o proxy.o sha.o $(SSL_CLIENT) +objects = events_glib.o http_client.o md5.o nogaim.o proxy.o sha.o $(SSL_CLIENT)  # [SH] The next two lines should contain the directory name (in $(subdirs))  #      and the name of the object file, which should be linked into diff --git a/protocols/events.h b/protocols/events.h new file mode 100644 index 00000000..682a9c23 --- /dev/null +++ b/protocols/events.h @@ -0,0 +1,56 @@ +/* + * nogaim + * + * Copyright (C) 2006 Wilmer van der Gaast and others + * + * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA + * + */ + +/* + * Split off the event handling things from proxy.[ch] (and adding timer + * stuff. This to allow BitlBee to use other libs than GLib for event + * handling. + */ + + +#ifndef _EVENTS_H_ +#define _EVENTS_H_ + +#include <sys/types.h> +#ifndef _WIN32 +#include <sys/socket.h> +#include <netdb.h> +#include <netinet/in.h> +#endif +#include <glib.h> +#include <gmodule.h> + +typedef enum { +	GAIM_INPUT_READ = 1 << 0, +	GAIM_INPUT_WRITE = 1 << 1 +} GaimInputCondition; +typedef void (*GaimInputFunction)(gpointer, gint, GaimInputCondition); + +#define GAIM_READ_COND  (G_IO_IN | G_IO_HUP | G_IO_ERR) +#define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) +#define GAIM_ERR_COND   (G_IO_HUP | G_IO_ERR | G_IO_NVAL) + +G_MODULE_EXPORT gint gaim_input_add(int fd, GaimInputCondition cond, GaimInputFunction func, gpointer data); +G_MODULE_EXPORT void gaim_input_remove(gint id); + +G_MODULE_EXPORT gint bee_timeout_add(gint timeout, GaimInputFunction func, gpointer data, gint priority); + +#endif /* _EVENTS_H_ */ diff --git a/protocols/events_glib.c b/protocols/events_glib.c new file mode 100644 index 00000000..f3b27565 --- /dev/null +++ b/protocols/events_glib.c @@ -0,0 +1,100 @@ +  /********************************************************************\ +  * BitlBee -- An IRC to other IM-networks gateway                     * +  *                                                                    * +  * Copyright 2002-2006 Wilmer van der Gaast and others                * +  \********************************************************************/ + +/* + * Event handling (using GLib) + */ + +/* +  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 with +  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; +  if not, write to the Free Software Foundation, Inc., 59 Temple Place, +  Suite 330, Boston, MA  02111-1307  USA +*/ + +#define BITLBEE_CORE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#ifndef _WIN32 +#include <sys/socket.h> +#include <netdb.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <unistd.h> +#else +#include "sock.h" +#define ETIMEDOUT WSAETIMEDOUT +#define EINPROGRESS WSAEINPROGRESS +#endif +#include <fcntl.h> +#include <errno.h> +#include "proxy.h" + +typedef struct _GaimIOClosure { +	GaimInputFunction function; +	guint result; +	gpointer data; +} GaimIOClosure; + +static gboolean gaim_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data) +{ +	GaimIOClosure *closure = data; +	GaimInputCondition gaim_cond = 0; + +	if (condition & GAIM_READ_COND) +		gaim_cond |= GAIM_INPUT_READ; +	if (condition & GAIM_WRITE_COND) +		gaim_cond |= GAIM_INPUT_WRITE; + +	closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond); + +	return TRUE; +} + +static void gaim_io_destroy(gpointer data) +{ +	g_free(data); +} + +gint gaim_input_add(gint source, GaimInputCondition condition, GaimInputFunction function, gpointer data) +{ +	GaimIOClosure *closure = g_new0(GaimIOClosure, 1); +	GIOChannel *channel; +	GIOCondition cond = 0; +	 +	closure->function = function; +	closure->data = data; +	 +	if (condition & GAIM_INPUT_READ) +		cond |= GAIM_READ_COND; +	if (condition & GAIM_INPUT_WRITE) +		cond |= GAIM_WRITE_COND; +	 +	channel = g_io_channel_unix_new(source); +	closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, +					      gaim_io_invoke, closure, gaim_io_destroy); +	 +	g_io_channel_unref(channel); +	return closure->result; +} + +void gaim_input_remove(gint tag) +{ +	if (tag > 0) +		g_source_remove(tag); +} diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 51d08e5a..4c2a3bb4 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -1,7 +1,7 @@    /********************************************************************\    * BitlBee -- An IRC to other IM-networks gateway                     *    *                                                                    * -  * Copyright 2002-2004 Wilmer van der Gaast and others                * +  * Copyright 2002-2006 Wilmer van der Gaast and others                *    \********************************************************************/  /* @@ -12,8 +12,6 @@   * This file contains functions called by the Gaim IM-modules. It's written   * from scratch for BitlBee and doesn't contain any code from Gaim anymore   * (except for the function names). - * - * Copyright 2002-2006 Wilmer van der Gaast <wilmer@gaast.net> and others   */  /* diff --git a/protocols/proxy.c b/protocols/proxy.c index 1ca35dfe..57d804c6 100644 --- a/protocols/proxy.c +++ b/protocols/proxy.c @@ -20,10 +20,6 @@   *   */ -/* this is a little piece of code to handle proxy connection */ -/* it is intended to : 1st handle http proxy, using the CONNECT command - , 2nd provide an easy way to add socks support */ -  #define BITLBEE_CORE  #include <stdio.h>  #include <stdlib.h> @@ -45,10 +41,6 @@  #include "nogaim.h"  #include "proxy.h" -#define GAIM_READ_COND  (G_IO_IN | G_IO_HUP | G_IO_ERR) -#define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) -#define GAIM_ERR_COND   (G_IO_HUP | G_IO_ERR | G_IO_NVAL) -  char proxyhost[128] = "";  int proxyport = 0;  int proxytype = PROXY_NONE; @@ -64,12 +56,6 @@ struct PHB {  	gint inpa;  }; -typedef struct _GaimIOClosure { -	GaimInputFunction function; -	guint result; -	gpointer data; -} GaimIOClosure; -  static struct sockaddr_in *gaim_gethostbyname(const char *host, int port) @@ -91,26 +77,6 @@ static struct sockaddr_in *gaim_gethostbyname(const char *host, int port)  	return &sin;  } -static void gaim_io_destroy(gpointer data) -{ -	g_free(data); -} - -static gboolean gaim_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data) -{ -	GaimIOClosure *closure = data; -	GaimInputCondition gaim_cond = 0; - -	if (condition & GAIM_READ_COND) -		gaim_cond |= GAIM_INPUT_READ; -	if (condition & GAIM_WRITE_COND) -		gaim_cond |= GAIM_INPUT_WRITE; - -	closure->function(closure->data, g_io_channel_unix_get_fd(source), gaim_cond); - -	return TRUE; -} -  static void gaim_io_connected(gpointer data, gint source, GaimInputCondition cond)  {  	struct PHB *phb = data; @@ -541,34 +507,6 @@ static int proxy_connect_socks5(const char *host, unsigned short port, struct PH  /* Export functions */ -gint gaim_input_add(gint source, GaimInputCondition condition, GaimInputFunction function, gpointer data) -{ -	GaimIOClosure *closure = g_new0(GaimIOClosure, 1); -	GIOChannel *channel; -	GIOCondition cond = 0; -	 -	closure->function = function; -	closure->data = data; -	 -	if (condition & GAIM_INPUT_READ) -		cond |= GAIM_READ_COND; -	if (condition & GAIM_INPUT_WRITE) -		cond |= GAIM_WRITE_COND; -	 -	channel = g_io_channel_unix_new(source); -	closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, -					      gaim_io_invoke, closure, gaim_io_destroy); -	 -	g_io_channel_unref(channel); -	return closure->result; -} - -void gaim_input_remove(gint tag) -{ -	if (tag > 0) -		g_source_remove(tag); -} -  int proxy_connect(const char *host, int port, GaimInputFunction func, gpointer data)  {  	struct PHB *phb; diff --git a/protocols/proxy.h b/protocols/proxy.h index 47c966d2..7094b334 100644 --- a/protocols/proxy.h +++ b/protocols/proxy.h @@ -1,5 +1,5 @@  /* - * gaim + * nogaim   *   * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>   * @@ -35,6 +35,8 @@  #include <glib.h>  #include <gmodule.h> +#include "events.h" +  #define PROXY_NONE 0  #define PROXY_HTTP 1  #define PROXY_SOCKS4 2 @@ -46,15 +48,6 @@ extern int  proxytype;  extern char proxyuser[128];  extern char proxypass[128]; -typedef enum { -	GAIM_INPUT_READ = 1 << 0, -	GAIM_INPUT_WRITE = 1 << 1 -} GaimInputCondition; -typedef void (*GaimInputFunction)(gpointer, gint, GaimInputCondition); - -G_MODULE_EXPORT gint gaim_input_add(int, GaimInputCondition, GaimInputFunction, gpointer); -G_MODULE_EXPORT void gaim_input_remove(gint); -  G_MODULE_EXPORT int proxy_connect(const char *host, int port, GaimInputFunction func, gpointer data);  #endif /* _PROXY_H_ */ | 
