Implement pretty simple bypass client-server hook.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Thu, 4 Jun 2009 14:50:02 +0000 (11:50 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Thu, 4 Jun 2009 14:50:02 +0000 (11:50 -0300)
We no longer do any protocol detection. Instead, we assume that we have
a POP3 connection. We may use different server sockets for different
protocols in the future. This simple null hook always connect to a given
server and passes all bytes from one connection to the other.

Makefile.am
null.c [new file with mode: 0644]
null.h [new file with mode: 0644]
popproxy.c
popproxy.conf

index bf751e7..1c20643 100644 (file)
@@ -1,3 +1,3 @@
 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
+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
 sysconf_DATA = popproxy.conf
diff --git a/null.c b/null.c
new file mode 100644 (file)
index 0000000..fd4de84
--- /dev/null
+++ b/null.c
@@ -0,0 +1,91 @@
+/*
+** 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 "null.h"
+
+static void null_connect (net_hook_t* hook)
+{
+}
+
+static void null_close (net_hook_t* hook)
+{
+  if (hook->peer)
+    {
+      hook->peer->peer = NULL;
+      gnet_conn_disconnect (hook->peer->conn);
+    }
+  gnet_conn_delete (hook->conn);
+  g_slice_free (net_hook_t, hook);
+}
+
+static void null_write (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);
+}
+
+static void null_error (net_hook_t* hook)
+{
+  g_message ("Error in POP3 client connection.");
+}
+
+static net_hook_t* null_server_hook_new (net_hook_t* client_hook, char *server)
+{
+  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->close = null_close;
+  hook->write = null_write;
+  hook->read = null_read;
+  hook->data = NULL;
+  gnet_conn_connect (hook->conn);
+  gnet_conn_read (hook->conn);
+  return hook;
+}
+
+net_hook_t* null_hook_new (GConn* conn, char *server)
+{
+  net_hook_t* hook;
+  hook = g_slice_new (net_hook_t);
+  hook->conn = conn;
+  hook->peer = NULL;
+  hook->server = FALSE;
+  hook->connect = null_connect;
+  hook->close = null_close;
+  hook->write = null_write;
+  hook->read = null_read;
+  hook->data = server;
+  hook->peer = null_server_hook_new (hook, server);
+  gnet_conn_set_callback (hook->conn, nethook_event, hook);
+  return hook;
+}
+
+void null_destroy (net_hook_t* hook)
+{
+  g_slice_free (net_hook_t, hook);
+}
diff --git a/null.h b/null.h
new file mode 100644 (file)
index 0000000..0f463f5
--- /dev/null
+++ b/null.h
@@ -0,0 +1,29 @@
+/*
+** Copyright (C) 2006 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
+**  
+** 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 NULL_H
+#define NULL_H
+
+#include <gnet.h>
+#include "nethook.h"
+
+net_hook_t* null_hook_new (GConn*, char*);
+void null_destroy (net_hook_t*);
+
+#endif
index d43c9d6..f6c4b57 100644 (file)
@@ -24,7 +24,7 @@
 #include <unistd.h>
 #include "log.h"
 #include "nethook.h"
-#include "proto_detect.h"
+#include "null.h"
 
 #define CONFFILE SYSCONFDIR "/popproxy.conf"
 
@@ -37,7 +37,7 @@ void new_client (GServer* server, GConn* conn, gpointer data)
       return;
     }
   g_message ("Received connection from %s.", conn->hostname);
-  hook = proto_detect_new (conn);
+  hook = null_hook_new (conn, data);
   gnet_conn_read (conn);
 }
 
@@ -58,6 +58,7 @@ int main (int argc, char** argv)
   GInetAddr* inetaddr;
   gchar* conf_address;
   gint port;
+  gchar *server_address;
 
   gnet_init ();
   pop_log_init ();
@@ -78,11 +79,12 @@ int main (int argc, char** argv)
 
   conf_address = g_key_file_get_string (keyfile, "global", "address", NULL);
   port = g_key_file_get_integer (keyfile, "global", "port", NULL);
+  server_address = g_key_file_get_string (keyfile, "global", "server", NULL);
 
   g_message ("Listen address is %s:%d.", conf_address, port);
 
   inetaddr = gnet_inetaddr_new_nonblock (conf_address, port);
-  gnet_server_new (inetaddr, port, new_client, NULL);
+  gnet_server_new (inetaddr, port, new_client, server_address);
 
   daemon (0, 0);
 
index b75282b..e61a0f8 100644 (file)
@@ -2,3 +2,4 @@
 
 address = 0.0.0.0
 port = 110
+server = 127.0.0.1