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 \
+ hcconn.c hcconn.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
--- /dev/null
+/*
+ * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ * 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 "hcconn.h"
+#include <unistd.h>
+#include <fcntl.h>
+
+struct hc_server_cb
+{
+ GIOChannel *channel;
+ HCServerFunc func;
+ gpointer data;
+};
+
+static void
+hc_server_cb_destroy (gpointer cb)
+{
+ g_slice_free (struct hc_server_cb, cb);
+}
+
+static gboolean
+hc_server_watch (GIOChannel *channel, GIOCondition cond, gpointer data)
+{
+ struct hc_server_cb *cb = data;
+ int fd = g_io_channel_unix_get_fd (channel);
+ struct sockaddr addr;
+ socklen_t saddr = sizeof (addr);
+ int client = accept (fd, &addr, &saddr);
+ if (client >= 0 && cb->func)
+ cb->func (client, &addr, saddr, cb->data);
+ return TRUE;
+}
+
+void
+hc_server_add_watch (int fd,
+ HCServerFunc func,
+ gpointer data)
+{
+ struct hc_server_cb *cb;
+ cb = g_slice_new (struct hc_server_cb);
+ cb->channel = g_io_channel_unix_new (fd);
+ cb->func = func;
+ cb->data = data;
+ g_io_add_watch_full (cb->channel, G_PRIORITY_DEFAULT, G_IO_IN,
+ hc_server_watch, cb, hc_server_cb_destroy);
+}
+
+struct _hc_conn_t
+{
+ GIOChannel *channel;
+ HCClientFunc func;
+ gpointer data;
+ ssize_t (*read) (gpointer, char *, size_t);
+ ssize_t (*write) (gpointer, char *, size_t);
+ void (*close) (gpointer);
+ gpointer layer;
+ guint watch;
+};
+
+ssize_t
+hc_conn_channel_read (gpointer data, char *buffer, size_t len)
+{
+ int fd = g_io_channel_unix_get_fd ((GIOChannel *) data);
+ return read (fd, buffer, len);
+}
+
+ssize_t
+hc_conn_channel_write (gpointer data, char *buffer, size_t len)
+{
+ int fd = g_io_channel_unix_get_fd ((GIOChannel *) data);
+ return write (fd, buffer, len);
+}
+
+void
+hc_conn_channel_close (gpointer data)
+{
+ int fd = g_io_channel_unix_get_fd ((GIOChannel *) data);
+ shutdown (fd, SHUT_RDWR);
+}
+
+gboolean
+hc_conn_watch (GIOChannel *channel, GIOCondition cond, gpointer data)
+{
+ HCConn *conn = data;
+ HCEvent event = HC_EVENT_READ;
+ if (conn->func)
+ conn->func (conn, event, conn->data);
+ return TRUE;
+}
+
+HCConn *
+hc_conn_new (int fd, HCClientFunc func, gpointer data)
+{
+ HCConn *conn;
+ conn = g_slice_new (HCConn);
+ conn->channel = g_io_channel_unix_new (fd);
+ conn->func = func;
+ conn->data = data;
+ conn->layer = conn->channel;
+ conn->read = hc_conn_channel_read;
+ conn->write = hc_conn_channel_write;
+ conn->close = hc_conn_channel_close;
+ conn->watch = g_io_add_watch (conn->channel, G_IO_IN, hc_conn_watch, conn);
+ if (conn->func)
+ conn->func (conn, HC_EVENT_CONNECT, conn->data);
+ fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
+ return conn;
+}
+
+void
+hc_conn_set_callback (HCConn *conn, HCClientFunc func, gpointer data)
+{
+ conn->func = func;
+ conn->data = data;
+}
+
+ssize_t
+hc_conn_read (HCConn *conn, char *buffer, size_t len)
+{
+ return conn->read (conn->layer, buffer, len);
+}
+
+void
+hc_conn_write (HCConn *conn, char *buffer, size_t len)
+{
+ /* TODO: Do buffering or something like that */
+ conn->write (conn->layer, buffer, len);
+}
+
+void
+hc_conn_close (HCConn *conn)
+{
+ conn->close (conn->layer);
+ g_source_remove (conn->watch);
+ g_io_channel_unref (conn->channel);
+ g_slice_free (HCConn, conn);
+}
--- /dev/null
+/*
+ * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ * 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.
+ */
+
+
+#ifndef HC_IOCHANNEL_H
+#define HC_IOCHANNEL_H
+
+#include <glib.h>
+#include <sys/socket.h>
+
+typedef void (*HCServerFunc) (int, struct sockaddr*, socklen_t, gpointer);
+
+void hc_server_add_watch (int, HCServerFunc, gpointer);
+
+typedef struct _hc_conn_t HCConn;
+
+typedef enum
+{
+ HC_EVENT_NULL = 0,
+ HC_EVENT_CONNECT,
+ HC_EVENT_READ,
+ HC_EVENT_CLOSE
+} HCEvent;
+
+typedef void (*HCClientFunc) (HCConn *, HCEvent, gpointer);
+
+HCConn * hc_conn_new (int, HCClientFunc, gpointer);
+ssize_t hc_conn_read (HCConn *, char *, size_t);
+void hc_conn_write (HCConn *, char *, size_t);
+void hc_conn_close (HCConn *);
+void hc_conn_set_callback (HCConn *, HCClientFunc, gpointer);
+
+#endif
+++ /dev/null
-/*
- * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
- *
- * 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 "iochannel.h"
-#include <unistd.h>
-#include <fcntl.h>
-
-struct hc_server_cb
-{
- GIOChannel *channel;
- HCServerFunc func;
- gpointer data;
-};
-
-static void
-hc_server_cb_destroy (gpointer cb)
-{
- g_slice_free (struct hc_server_cb, cb);
-}
-
-static gboolean
-hc_server_watch (GIOChannel *channel, GIOCondition cond, gpointer data)
-{
- struct hc_server_cb *cb = data;
- int fd = g_io_channel_unix_get_fd (channel);
- struct sockaddr addr;
- socklen_t saddr = sizeof (addr);
- int client = accept (fd, &addr, &saddr);
- if (client >= 0 && cb->func)
- cb->func (client, &addr, saddr, cb->data);
- return TRUE;
-}
-
-void
-hc_server_add_watch (int fd,
- HCServerFunc func,
- gpointer data)
-{
- struct hc_server_cb *cb;
- cb = g_slice_new (struct hc_server_cb);
- cb->channel = g_io_channel_unix_new (fd);
- cb->func = func;
- cb->data = data;
- g_io_add_watch_full (cb->channel, G_PRIORITY_DEFAULT, G_IO_IN,
- hc_server_watch, cb, hc_server_cb_destroy);
-}
-
-struct _hc_conn_t
-{
- GIOChannel *channel;
- HCClientFunc func;
- gpointer data;
- ssize_t (*read) (gpointer, char *, size_t);
- ssize_t (*write) (gpointer, char *, size_t);
- void (*close) (gpointer);
- gpointer layer;
- guint watch;
-};
-
-ssize_t
-hc_conn_channel_read (gpointer data, char *buffer, size_t len)
-{
- int fd = g_io_channel_unix_get_fd ((GIOChannel *) data);
- return read (fd, buffer, len);
-}
-
-ssize_t
-hc_conn_channel_write (gpointer data, char *buffer, size_t len)
-{
- int fd = g_io_channel_unix_get_fd ((GIOChannel *) data);
- return write (fd, buffer, len);
-}
-
-void
-hc_conn_channel_close (gpointer data)
-{
- int fd = g_io_channel_unix_get_fd ((GIOChannel *) data);
- shutdown (fd, SHUT_RDWR);
-}
-
-gboolean
-hc_conn_watch (GIOChannel *channel, GIOCondition cond, gpointer data)
-{
- HCConn *conn = data;
- HCEvent event = HC_EVENT_READ;
- if (conn->func)
- conn->func (conn, event, conn->data);
- return TRUE;
-}
-
-HCConn *
-hc_conn_new (int fd, HCClientFunc func, gpointer data)
-{
- HCConn *conn;
- conn = g_slice_new (HCConn);
- conn->channel = g_io_channel_unix_new (fd);
- conn->func = func;
- conn->data = data;
- conn->layer = conn->channel;
- conn->read = hc_conn_channel_read;
- conn->write = hc_conn_channel_write;
- conn->close = hc_conn_channel_close;
- conn->watch = g_io_add_watch (conn->channel, G_IO_IN, hc_conn_watch, conn);
- if (conn->func)
- conn->func (conn, HC_EVENT_CONNECT, conn->data);
- fcntl (fd, F_SETFL, fcntl (fd, F_GETFL, 0) | O_NONBLOCK);
- return conn;
-}
-
-void
-hc_conn_set_callback (HCConn *conn, HCClientFunc func, gpointer data)
-{
- conn->func = func;
- conn->data = data;
-}
-
-ssize_t
-hc_conn_read (HCConn *conn, char *buffer, size_t len)
-{
- return conn->read (conn->layer, buffer, len);
-}
-
-void
-hc_conn_write (HCConn *conn, char *buffer, size_t len)
-{
- /* TODO: Do buffering or something like that */
- conn->write (conn->layer, buffer, len);
-}
-
-void
-hc_conn_close (HCConn *conn)
-{
- conn->close (conn->layer);
- g_source_remove (conn->watch);
- g_io_channel_unref (conn->channel);
- g_slice_free (HCConn, conn);
-}
+++ /dev/null
-/*
- * Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
- *
- * 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.
- */
-
-
-#ifndef HC_IOCHANNEL_H
-#define HC_IOCHANNEL_H
-
-#include <glib.h>
-#include <sys/socket.h>
-
-typedef void (*HCServerFunc) (int, struct sockaddr*, socklen_t, gpointer);
-
-void hc_server_add_watch (int, HCServerFunc, gpointer);
-
-typedef struct _hc_conn_t HCConn;
-
-typedef enum
-{
- HC_EVENT_NULL = 0,
- HC_EVENT_CONNECT,
- HC_EVENT_READ,
- HC_EVENT_CLOSE
-} HCEvent;
-
-typedef void (*HCClientFunc) (HCConn *, HCEvent, gpointer);
-
-HCConn * hc_conn_new (int, HCClientFunc, gpointer);
-ssize_t hc_conn_read (HCConn *, char *, size_t);
-void hc_conn_write (HCConn *, char *, size_t);
-void hc_conn_close (HCConn *);
-void hc_conn_set_callback (HCConn *, HCClientFunc, gpointer);
-
-#endif
#define NET_HOOK_H
#include <glib.h>
-#include "iochannel.h"
+#include "hcconn.h"
typedef struct _net_hook_t net_hook_t;
typedef void (*net_connect) (net_hook_t*);
#define NULL_H
#include "nethook.h"
-#include "iochannel.h"
+#include "hcconn.h"
net_hook_t* null_hook_new (HCConn*, char*);
void null_destroy (net_hook_t*);
#include "ssl.h"
#include "pop.h"
-#include "iochannel.h"
+#include "hcconn.h"
#include "tcp_connect.h"
#define CONFFILE SYSCONFDIR "/popproxy.conf"
#define POPPROXY_SSL_H
#include "nethook.h"
-#include "iochannel.h"
+#include "hcconn.h"
struct ssl_data
{