Now, we use our own implementation of TCP connection and server, instead
of using GNet. There is some missing pieces and it doesn't work right
now, but it's easier to hack on and we don't depend on this library
anymore.
13 files changed:
bin_PROGRAMS = popproxy ppmanager
popproxy_SOURCES = popproxy.c log.c log.h nethook.c nethook.h \
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
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_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))
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")
if test "${sysconfdir}x" = '${prefix}/etcx'; then
if test "${prefix}x" = 'NONEx'; then
AC_DEFINE_UNQUOTED(SYSCONFDIR, "${ac_default_prefix}/etc")
-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;
net_hook_t* hook;
hook = (net_hook_t*) data;
- case GNET_CONN_CONNECT:
hook->connect (hook);
break;
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);
- case GNET_CONN_WRITE:
- hook->write (hook);
- break;
- case GNET_CONN_CLOSE:
hook->close (hook);
break;
default:
hook->close (hook);
break;
default:
#ifndef NET_HOOK_H
#define NET_HOOK_H
#ifndef NET_HOOK_H
#define NET_HOOK_H
+#include <glib.h>
+#include "iochannel.h"
typedef struct _net_hook_t net_hook_t;
typedef void (*net_connect) (net_hook_t*);
typedef struct _net_hook_t net_hook_t;
typedef void (*net_connect) (net_hook_t*);
net_hook_t* peer;
gboolean server;
net_connect connect;
net_hook_t* peer;
gboolean server;
net_connect connect;
-void nethook_event (GConn*, GConnEvent*, gpointer);
+void nethook_event (HCConn*, HCEvent, gpointer);
#include <glib.h>
#include "null.h"
#include <glib.h>
#include "null.h"
if (hook->peer)
{
hook->peer->peer = NULL;
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);
}
g_slice_free (net_hook_t, hook);
}
static void null_read (net_hook_t* hook, gchar* buffer, size_t len)
{
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)
}
static void null_error (net_hook_t* hook)
{
net_hook_t* hook;
hook = g_slice_new (net_hook_t);
{
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->peer = client_hook;
hook->server = TRUE;
hook->connect = null_connect;
hook->write = null_write;
hook->read = null_read;
hook->data = NULL;
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);
-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);
{
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);
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);
#ifndef NULL_H
#define NULL_H
#ifndef NULL_H
#define NULL_H
-net_hook_t* null_hook_new (GConn*, char*);
+net_hook_t* null_hook_new (HCConn*, char*);
void null_destroy (net_hook_t*);
#endif
void null_destroy (net_hook_t*);
#endif
#include <glib.h>
#include <string.h>
#include "nethook.h"
#include <glib.h>
#include <string.h>
#include "nethook.h"
{
g_message ("Denying access to user %s.", pop->user);
pop_destroy (hook);
{
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);
#ifndef POPPROXY_POP_H
#define POPPROXY_POP_H
#ifndef POPPROXY_POP_H
#define POPPROXY_POP_H
#include "nethook.h"
net_hook_t* pop_hook_new (net_hook_t *);
#include "nethook.h"
net_hook_t* pop_hook_new (net_hook_t *);
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <gnutls/gnutls.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 "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;
#define CONFFILE SYSCONFDIR "/popproxy.conf"
struct pop_address
{
char *server;
-void new_client (GServer* server, GConn* conn, gpointer data)
+void new_client (int fd, struct sockaddr* addr, socklen_t saddr, gpointer data)
net_hook_t* hook;
struct pop_address *address = data;
net_hook_t* hook;
struct pop_address *address = data;
{
g_critical ("Server has received an error event.");
return;
}
{
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);
hook = ssl_hook_new (conn, address->server, address->port);
pop_hook_new (hook);
}
static gchar* configfile;
}
static gchar* configfile;
GOptionContext* opt_ctx;
GKeyFile *keyfile;
GOptionContext* opt_ctx;
GKeyFile *keyfile;
struct pop_address pop_address;
gnutls_global_init ();
struct pop_address pop_address;
gnutls_global_init ();
pop_log_init ();
configfile = CONFFILE;
pop_log_init ();
configfile = CONFFILE;
g_error_free (error);
}
error = NULL;
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 = g_strdup ("110");
g_error_free (error);
}
error = NULL;
g_error_free (error);
}
error = NULL;
- 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)
+ server_port = g_strdup ("995");
g_error_free (error);
}
pop_address.server = server_address;
pop_address.port = server_port;
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);
}
{
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);
daemon (0, 0);
g_free (conf_address);
g_main_loop_run (g_main_loop_new (g_main_context_default (), TRUE));
gnutls_global_deinit ();
g_free (server_address);
g_main_loop_run (g_main_loop_new (g_main_context_default (), TRUE));
gnutls_global_deinit ();
g_free (server_address);
[global]
address = 0.0.0.0
[global]
address = 0.0.0.0
*/
#include <gnutls/gnutls.h>
*/
#include <gnutls/gnutls.h>
#include <glib.h>
#include <string.h>
#include <errno.h>
#include <glib.h>
#include <string.h>
#include <errno.h>
if (hook->peer)
{
hook->peer->peer = NULL;
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);
}
g_slice_free (net_hook_t, hook);
}
-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);
{
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);
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);
#ifndef POPPROXY_SSL_H
#define POPPROXY_SSL_H
#ifndef POPPROXY_SSL_H
#define POPPROXY_SSL_H
-net_hook_t* ssl_hook_new (GConn*, char*, int);
+net_hook_t* ssl_hook_new (HCConn*, char*, char *);
void ssl_destroy (net_hook_t*);
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 *);
*/
#include <gnutls/gnutls.h>
*/
#include <gnutls/gnutls.h>
#include <glib.h>
#include <string.h>
#include <errno.h>
#include <glib.h>
#include <string.h>
#include <errno.h>
int r;
if (ssl->handshaking == TRUE)
{
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);
- gnet_conn_write (hook->conn, (void *) buffer, len);
+ hc_conn_write (hook->conn, (void *) buffer, len);
int r;
if (ssl->handshaking == TRUE)
{
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)
return r;
}
if (len > ssl->buffer->len)
if (hook->peer)
{
hook->peer->peer = NULL;
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);
if (ssl != NULL)
{
gnutls_bye (ssl->session, GNUTLS_SHUT_RDWR);
{
r = gnutls_record_recv (ssl->session, buffer, len);
if (r > 0)
{
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);
-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);
{
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->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);
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);