Added a hook on top of the SSL layer, allowing to filter data.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 10 Jun 2009 17:31:56 +0000 (14:31 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Wed, 10 Jun 2009 17:31:56 +0000 (14:31 -0300)
Makefile.am
pop.c [new file with mode: 0644]
pop.h [new file with mode: 0644]
popproxy.c

index 83c80ab..b958097 100644 (file)
@@ -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 (file)
index 0000000..f286056
--- /dev/null
+++ b/pop.c
@@ -0,0 +1,57 @@
+/*
+** Copyright (C) 2006 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
+** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**  
+*/
+
+#include <gnet.h>
+#include <glib.h>
+#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 (file)
index 0000000..02873ff
--- /dev/null
+++ b/pop.h
@@ -0,0 +1,30 @@
+/*
+** Copyright (C) 2006 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
+** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**  
+*/
+
+#ifndef POPPROXY_POP_H
+#define POPPROXY_POP_H
+
+#include <gnet.h>
+#include "nethook.h"
+
+net_hook_t* pop_hook_new (net_hook_t *);
+void pop_destroy (net_hook_t*);
+
+#endif
index fb1a8c1..23b17ba 100644 (file)
@@ -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);
 }