From 8d71c982795260ba2451de05e28193241387fcb0 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Wed, 10 Jun 2009 14:31:56 -0300 Subject: [PATCH] Added a hook on top of the SSL layer, allowing to filter data. --- Makefile.am | 5 ++++- pop.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ pop.h | 30 ++++++++++++++++++++++++++++ popproxy.c | 2 ++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 pop.c create mode 100644 pop.h diff --git a/Makefile.am b/Makefile.am index 83c80ab..b958097 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,6 @@ bin_PROGRAMS = popproxy -popproxy_SOURCES = popproxy.c log.c log.h nethook.c nethook.h proto_detect.c proto_detect.h jabber.c jabber.h jabber_server.c iksemel_extra.c iksemel_extra.h null.c null.h ssl.c ssl.h ssl_server.c +popproxy_SOURCES = popproxy.c log.c log.h nethook.c nethook.h \ + proto_detect.c proto_detect.h jabber.c jabber.h jabber_server.c \ + iksemel_extra.c iksemel_extra.h null.c null.h ssl.c ssl.h \ + ssl_server.c pop.c pop.h sysconf_DATA = popproxy.conf diff --git a/pop.c b/pop.c new file mode 100644 index 0000000..f286056 --- /dev/null +++ b/pop.c @@ -0,0 +1,57 @@ +/* +** Copyright (C) 2006 Thadeu Lima de Souza Cascardo +** Copyright (C) 2009 Thadeu Lima de Souza Cascardo +** +** 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. +** +*/ + +#include +#include +#include "nethook.h" +#include "pop.h" + +typedef struct +{ + net_read orig_read; + gpointer orig_data; +} pop_t; + +static void +pop_read (net_hook_t *hook, gchar *buffer, size_t len) +{ + pop_t *pop = hook->data; + hook->data = pop->orig_data; + pop->orig_read (hook, buffer, len); + hook->data = pop; +} + +net_hook_t * +pop_hook_new (net_hook_t *layer) +{ + pop_t *pop; + pop = g_slice_new (pop_t); + pop->orig_read = layer->read; + pop->orig_data = layer->data; + layer->read = pop_read; + layer->data = pop; + return layer; +} + +void +pop_destroy (net_hook_t *hook) +{ + g_slice_free (net_hook_t, hook->data); +} diff --git a/pop.h b/pop.h new file mode 100644 index 0000000..02873ff --- /dev/null +++ b/pop.h @@ -0,0 +1,30 @@ +/* +** Copyright (C) 2006 Thadeu Lima de Souza Cascardo +** Copyright (C) 2009 Thadeu Lima de Souza Cascardo +** +** 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. +** +*/ + +#ifndef POPPROXY_POP_H +#define POPPROXY_POP_H + +#include +#include "nethook.h" + +net_hook_t* pop_hook_new (net_hook_t *); +void pop_destroy (net_hook_t*); + +#endif diff --git a/popproxy.c b/popproxy.c index fb1a8c1..23b17ba 100644 --- a/popproxy.c +++ b/popproxy.c @@ -28,6 +28,7 @@ #include "nethook.h" #include "null.h" #include "ssl.h" +#include "pop.h" #define CONFFILE SYSCONFDIR "/popproxy.conf" @@ -41,6 +42,7 @@ void new_client (GServer* server, GConn* conn, gpointer data) } g_message ("Received connection from %s.", conn->hostname); hook = ssl_hook_new (conn, data); + pop_hook_new (hook); gnet_conn_read (conn); } -- 2.20.1