Index: protocols/Makefile
===================================================================
--- protocols/Makefile	(revision a0d04d6253cf70877a11156059209e1f9a2efe31)
+++ protocols/Makefile	(revision ecf8fa820aa8fa3592bdf96ed3bdeec4ec94f036)
@@ -10,5 +10,5 @@
 
 # [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))
Index: protocols/events.h
===================================================================
--- protocols/events.h	(revision ecf8fa820aa8fa3592bdf96ed3bdeec4ec94f036)
+++ protocols/events.h	(revision ecf8fa820aa8fa3592bdf96ed3bdeec4ec94f036)
@@ -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_ */
Index: protocols/events_glib.c
===================================================================
--- protocols/events_glib.c	(revision ecf8fa820aa8fa3592bdf96ed3bdeec4ec94f036)
+++ protocols/events_glib.c	(revision ecf8fa820aa8fa3592bdf96ed3bdeec4ec94f036)
@@ -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);
+}
Index: protocols/nogaim.c
===================================================================
--- protocols/nogaim.c	(revision a0d04d6253cf70877a11156059209e1f9a2efe31)
+++ protocols/nogaim.c	(revision ecf8fa820aa8fa3592bdf96ed3bdeec4ec94f036)
@@ -2,5 +2,5 @@
   * 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                *
   \********************************************************************/
 
@@ -13,6 +13,4 @@
  * 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
  */
 
Index: protocols/proxy.c
===================================================================
--- protocols/proxy.c	(revision a0d04d6253cf70877a11156059209e1f9a2efe31)
+++ protocols/proxy.c	(revision ecf8fa820aa8fa3592bdf96ed3bdeec4ec94f036)
@@ -21,8 +21,4 @@
  */
 
-/* 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>
@@ -46,8 +42,4 @@
 #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;
@@ -64,10 +56,4 @@
 	gint inpa;
 };
-
-typedef struct _GaimIOClosure {
-	GaimInputFunction function;
-	guint result;
-	gpointer data;
-} GaimIOClosure;
 
 
@@ -90,24 +76,4 @@
 
 	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;
 }
 
@@ -542,32 +508,4 @@
 /* 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)
 {
Index: protocols/proxy.h
===================================================================
--- protocols/proxy.h	(revision a0d04d6253cf70877a11156059209e1f9a2efe31)
+++ protocols/proxy.h	(revision ecf8fa820aa8fa3592bdf96ed3bdeec4ec94f036)
@@ -1,4 +1,4 @@
 /*
- * gaim
+ * nogaim
  *
  * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
@@ -36,4 +36,6 @@
 #include <gmodule.h>
 
+#include "events.h"
+
 #define PROXY_NONE 0
 #define PROXY_HTTP 1
@@ -47,13 +49,4 @@
 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);
 
