bin_PROGRAMS = popproxy ppmanager
popproxy_SOURCES = popproxy.c log.c log.h nethook.c nethook.h \
+ iochannel.c iochannel.h tcp_connect.h tcp_connect.c tcp_server.c \
null.c null.h ssl.c ssl.h \
ssl_server.c pop.c pop.h usermap.c usermap.h
dist_sysconf_DATA = popproxy.conf
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME,AC_PACKAGE_VERSION)
AC_PROG_CC
AC_PROG_INSTALL
-AM_PATH_GNET_2_0(,,AC_MSG_ERROR(GNet not found))
+AM_PATH_GLIB_2_0(,,AC_MSG_ERROR(GLib not found))
PKG_CHECK_MODULES(GNUTLS, gnutls >= 1.4.0, , AC_MSG_ERROR(Could not find gnutls))
PKG_CHECK_MODULES(QDBM, qdbm, , AC_MSG_ERROR(Could not find qdbm))
-LIBS="$GNUTLS_LIBS $GNET_LIBS $QDBM_LIBS $LIBS"
-CFLAGS="$GNUTLS_CFLAGS $GNET_CFLAGS $QDBM_CFLAGS $CFLAGS"
+LIBS="$GLIB_LIBS $GNUTLS_LIBS $QDBM_LIBS $LIBS"
+CFLAGS="$GLIB_CFLAGS $GNUTLS_CFLAGS $QDBM_CFLAGS $CFLAGS"
if test "${sysconfdir}x" = '${prefix}/etcx'; then
if test "${prefix}x" = 'NONEx'; then
AC_DEFINE_UNQUOTED(SYSCONFDIR, "${ac_default_prefix}/etc")
**
*/
-#include <gnet.h>
#include "nethook.h"
-void nethook_event (GConn* conn, GConnEvent* event, gpointer data)
+void
+nethook_event (HCConn* conn, HCEvent event, gpointer data)
{
+ char buffer[4096];
+ int r;
net_hook_t* hook;
hook = (net_hook_t*) data;
- switch (event->type)
+ switch (event)
{
- case GNET_CONN_CONNECT:
+ case HC_EVENT_CONNECT:
hook->connect (hook);
break;
- case GNET_CONN_READ:
- hook->read (hook, event->buffer, event->length);
- gnet_conn_read (conn);
+ case HC_EVENT_READ:
+ while ((r = hc_conn_read (conn, buffer, sizeof (buffer))) > 0)
+ hook->read (hook, buffer, r);
break;
- case GNET_CONN_WRITE:
- hook->write (hook);
- break;
- case GNET_CONN_CLOSE:
+ case HC_EVENT_CLOSE:
hook->close (hook);
break;
default:
#ifndef NET_HOOK_H
#define NET_HOOK_H
-#include <gnet.h>
+#include <glib.h>
+#include "iochannel.h"
typedef struct _net_hook_t net_hook_t;
typedef void (*net_connect) (net_hook_t*);
struct _net_hook_t
{
- GConn* conn;
+ HCConn* conn;
net_hook_t* peer;
gboolean server;
net_connect connect;
gpointer data;
};
-void nethook_event (GConn*, GConnEvent*, gpointer);
+void nethook_event (HCConn*, HCEvent, gpointer);
#endif
**
*/
-#include <gnet.h>
#include <glib.h>
#include "null.h"
if (hook->peer)
{
hook->peer->peer = NULL;
- gnet_conn_disconnect (hook->peer->conn);
+ hc_conn_close (hook->peer->conn);
}
- gnet_conn_delete (hook->conn);
+ hc_conn_close (hook->conn);
g_slice_free (net_hook_t, hook);
}
static void null_read (net_hook_t* hook, gchar* buffer, size_t len)
{
- gnet_conn_write (hook->peer->conn, buffer, len);
+ hc_conn_write (hook->peer->conn, buffer, len);
}
static void null_error (net_hook_t* hook)
{
net_hook_t* hook;
hook = g_slice_new (net_hook_t);
- hook->conn = gnet_conn_new (server, 110, nethook_event, hook);
hook->peer = client_hook;
hook->server = TRUE;
hook->connect = null_connect;
hook->write = null_write;
hook->read = null_read;
hook->data = NULL;
- gnet_conn_connect (hook->conn);
- gnet_conn_read (hook->conn);
+ hook->conn = hc_conn_new (hc_tcp_connect (server, "110"), nethook_event, hook);
return hook;
}
-net_hook_t* null_hook_new (GConn* conn, char *server)
+net_hook_t* null_hook_new (HCConn* conn, char *server)
{
net_hook_t* hook;
hook = g_slice_new (net_hook_t);
hook->read = null_read;
hook->data = server;
hook->peer = null_server_hook_new (hook, server);
- gnet_conn_set_callback (hook->conn, nethook_event, hook);
+ hc_conn_set_callback (hook->conn, nethook_event, hook);
return hook;
}
#ifndef NULL_H
#define NULL_H
-#include <gnet.h>
#include "nethook.h"
+#include "iochannel.h"
-net_hook_t* null_hook_new (GConn*, char*);
+net_hook_t* null_hook_new (HCConn*, char*);
void null_destroy (net_hook_t*);
#endif
**
*/
-#include <gnet.h>
#include <glib.h>
#include <string.h>
#include "nethook.h"
{
g_message ("Denying access to user %s.", pop->user);
pop_destroy (hook);
- gnet_conn_disconnect (hook->conn);
- hook->close (hook);
+ hc_conn_close (hook->conn);
return;
}
}
#ifndef POPPROXY_POP_H
#define POPPROXY_POP_H
-#include <gnet.h>
#include "nethook.h"
net_hook_t* pop_hook_new (net_hook_t *);
*/
#include <glib.h>
-#include <gnet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gnutls/gnutls.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include "log.h"
#include "nethook.h"
#include "null.h"
#include "ssl.h"
#include "pop.h"
+#include "iochannel.h"
+#include "tcp_connect.h"
+
#define CONFFILE SYSCONFDIR "/popproxy.conf"
struct pop_address
{
char *server;
- int port;
+ char *port;
};
-void new_client (GServer* server, GConn* conn, gpointer data)
+void new_client (int fd, struct sockaddr* addr, socklen_t saddr, gpointer data)
{
+ HCConn *conn;
net_hook_t* hook;
struct pop_address *address = data;
- if (conn == NULL)
+ if (fd < 0)
{
g_critical ("Server has received an error event.");
return;
}
- g_message ("Received connection from %s.", conn->hostname);
+ g_message ("Received connection from %s.",
+ inet_ntoa (((struct sockaddr_in *) addr)->sin_addr));
+ conn = hc_conn_new (fd, NULL, NULL);
hook = ssl_hook_new (conn, address->server, address->port);
pop_hook_new (hook);
- gnet_conn_read (conn);
}
static gchar* configfile;
GOptionContext* opt_ctx;
GKeyFile *keyfile;
- GInetAddr* inetaddr;
GError *error;
+ int server_fd;
gchar* conf_address;
- gint port;
+ gchar* port;
gchar *server_address;
- gint server_port;
+ gchar *server_port;
struct pop_address pop_address;
gnutls_global_init ();
- gnet_init ();
pop_log_init ();
configfile = CONFFILE;
g_error_free (error);
}
error = NULL;
- port = g_key_file_get_integer (keyfile, "global", "port", &error);
- if (port == 0 && error != NULL)
+ port = g_key_file_get_string (keyfile, "global", "port", &error);
+ if (port == NULL && error != NULL)
{
- port = 110;
+ port = g_strdup ("110");
g_error_free (error);
}
error = NULL;
g_error_free (error);
}
- server_port = g_key_file_get_integer (keyfile, "global", "server_port",
- &error);
- if (server_port == 0 && error != NULL)
+ server_port = g_key_file_get_string (keyfile, "global", "server_port",
+ &error);
+ if (server_port == NULL && error != NULL)
{
- port = 995;
+ server_port = g_strdup ("995");
g_error_free (error);
}
pop_address.server = server_address;
pop_address.port = server_port;
- inetaddr = gnet_inetaddr_new_nonblock (conf_address, port);
- if (gnet_server_new (inetaddr, port,
- new_client, &pop_address) == NULL)
+ server_fd = hc_tcp_server (port);
+ if (server_fd < 0)
{
fprintf (stderr, "Could not create server.\n");
exit (1);
}
+ hc_server_add_watch (server_fd, new_client, &pop_address);
- g_message ("Listening at %s:%d.", conf_address, port);
+ g_message ("Listening at %s:%s.", conf_address, port);
daemon (0, 0);
g_free (conf_address);
+ g_free (port);
g_main_loop_run (g_main_loop_new (g_main_context_default (), TRUE));
gnutls_global_deinit ();
g_free (server_address);
+ g_free (server_port);
return 0;
[global]
address = 0.0.0.0
-port = 110
+port = 1100
server = 127.0.0.1
*/
#include <gnutls/gnutls.h>
-#include <gnet.h>
#include <glib.h>
#include <string.h>
#include <errno.h>
if (hook->peer)
{
hook->peer->peer = NULL;
- gnet_conn_disconnect (hook->peer->conn);
+ hc_conn_close (hook->peer->conn);
}
- gnet_conn_delete (hook->conn);
+ hc_conn_close (hook->conn);
g_slice_free (net_hook_t, hook);
}
}
net_hook_t *
-ssl_hook_new (GConn *conn, char *server, int port)
+ssl_hook_new (HCConn *conn, char *server, char *port)
{
net_hook_t *hook;
hook = g_slice_new (net_hook_t);
hook->read = ssl_read;
hook->data = NULL;
hook->peer = ssl_server_hook_new (hook, server, port);
- gnet_conn_set_callback (hook->conn, nethook_event, hook);
+ hc_conn_set_callback (hook->conn, nethook_event, hook);
return hook;
}
#ifndef POPPROXY_SSL_H
#define POPPROXY_SSL_H
-#include <gnet.h>
#include "nethook.h"
+#include "iochannel.h"
struct ssl_data
{
gboolean handshaking;
};
-net_hook_t* ssl_hook_new (GConn*, char*, int);
+net_hook_t* ssl_hook_new (HCConn*, char*, char *);
void ssl_destroy (net_hook_t*);
-net_hook_t * ssl_server_hook_new (net_hook_t *, char *, int);
+net_hook_t * ssl_server_hook_new (net_hook_t *, char *, char *);
#endif
*/
#include <gnutls/gnutls.h>
-#include <gnet.h>
#include <glib.h>
#include <string.h>
#include <errno.h>
int r;
if (ssl->handshaking == TRUE)
{
- g_io_channel_write_chars (hook->conn->iochannel, buffer, len,
- &r, NULL);
+ r = hc_conn_read (hook->conn, buffer, len);
return r;
}
- gnet_conn_write (hook->conn, (void *) buffer, len);
+ hc_conn_write (hook->conn, (void *) buffer, len);
return len;
}
int r;
if (ssl->handshaking == TRUE)
{
- g_io_channel_read_chars (hook->conn->iochannel, buffer, len,
- &r, NULL);
+ r = hc_conn_read (hook->conn, buffer, len);
return r;
}
if (len > ssl->buffer->len)
if (hook->peer)
{
hook->peer->peer = NULL;
- gnet_conn_disconnect (hook->peer->conn);
+ hc_conn_close (hook->peer->conn);
}
- gnet_conn_delete (hook->conn);
+ hc_conn_close (hook->conn);
if (ssl != NULL)
{
gnutls_bye (ssl->session, GNUTLS_SHUT_RDWR);
{
r = gnutls_record_recv (ssl->session, buffer, len);
if (r > 0)
- gnet_conn_write (hook->peer->conn, buffer, r);
+ hc_conn_write (hook->peer->conn, buffer, r);
} while (r > 0);
}
}
net_hook_t *
-ssl_server_hook_new (net_hook_t *client_hook, char *server, int port)
+ssl_server_hook_new (net_hook_t *client_hook, char *server, char *port)
{
net_hook_t *hook;
hook = g_slice_new (net_hook_t);
- hook->conn = gnet_conn_new (server, port, nethook_event, hook);
hook->peer = client_hook;
hook->server = TRUE;
hook->connect = ssl_server_connect;
hook->write = ssl_server_write;
hook->read = ssl_server_read;
hook->data = ssl_data_new (server);
- gnet_conn_connect (hook->conn);
- gnet_conn_read (hook->conn);
+ hook->conn = hc_conn_new (hc_tcp_connect (server, port), nethook_event, hook);
return hook;
}