[pan2: 175/268] fixed win32 bug (freeaddrinfo and getaddrinfo were commented out.....)



commit 801ece0a1fb21f9488513da3f06ea712efd9477c
Author: Heinrich MÃller <sphemuel stud informatik uni-erlangen de>
Date:   Tue Oct 25 21:43:02 2011 +0200

    fixed win32 bug (freeaddrinfo and getaddrinfo were commented out.....)

 pan/data-impl/Makefile.am        |   42 ++++++++++++------------
 pan/gui/server-ui.cc             |   14 ++++----
 pan/tasks/Makefile.am            |    2 +-
 pan/tasks/socket-impl-gio.cc     |    5 ++-
 pan/tasks/socket-impl-gio.h      |    2 +
 pan/tasks/socket-impl-main.cc    |   64 +------------------------------------
 pan/tasks/socket-impl-main.h     |   65 +++++++++++++++++++++++++++++++++++--
 pan/tasks/socket-impl-openssl.cc |    3 ++
 pan/tasks/socket-impl-openssl.h  |    2 +
 9 files changed, 102 insertions(+), 97 deletions(-)
---
diff --git a/pan/data-impl/Makefile.am b/pan/data-impl/Makefile.am
index fbd513b..19142bf 100644
--- a/pan/data-impl/Makefile.am
+++ b/pan/data-impl/Makefile.am
@@ -24,26 +24,26 @@ noinst_HEADERS = \
  profiles.h \
  memchunk.h
 
-noinst_PROGRAMS = \
- add-server \
- headers-test \
- speed-test-load-group
+#noinst_PROGRAMS = \
+# add-server \
+# headers-test \
+# speed-test-load-group
 
-TESTS = \
- add-server \
- headers-test 
+#TESTS = \
+# add-server \
+# headers-test
 
-TEST_LDADD = \
- ./libpandata.a \
- ../tasks/libtasks.a \
- ../data/libdata.a \
- ../usenet-utils/libusenetutils.a \
- ../general/libgeneralutils.a \
- ../../uulib/libuu.a \
- @GMIME_LIBS@ @GLIB_LIBS@
-add_server_SOURCES = add-server.cc
-add_server_LDADD = $(TEST_LDADD)
-headers_test_SOURCES = headers-test.cc
-headers_test_LDADD = $(TEST_LDADD)
-speed_test_load_group_SOURCES = speed-test-load-group.cc
-speed_test_load_group_LDADD = $(TEST_LDADD)
+#TEST_LDADD = \
+# ./libpandata.a \
+# ../tasks/libtasks.a \
+# ../data/libdata.a \
+# ../usenet-utils/libusenetutils.a \
+# ../general/libgeneralutils.a \
+# ../../uulib/libuu.a \
+# @GMIME_LIBS@ @GLIB_LIBS@
+#add_server_SOURCES = add-server.cc
+#add_server_LDADD = $(TEST_LDADD)
+#headers_test_SOURCES = headers-test.cc
+#headers_test_LDADD = $(TEST_LDADD)
+#speed_test_load_group_SOURCES = speed-test-load-group.cc
+#speed_test_load_group_LDADD = $(TEST_LDADD)
diff --git a/pan/gui/server-ui.cc b/pan/gui/server-ui.cc
index d2743b8..8507a9c 100644
--- a/pan/gui/server-ui.cc
+++ b/pan/gui/server-ui.cc
@@ -134,6 +134,7 @@ namespace
       }
     } while (gtk_tree_model_iter_next(model, &iter));
 
+#ifdef HAVE_OPENSSL
     // set ssl combo
     combo = GTK_COMBO_BOX (d->ssl_combo);
     model = gtk_combo_box_get_model (combo);
@@ -145,6 +146,7 @@ namespace
         break;
       }
     } while (gtk_tree_model_iter_next(model, &iter));
+#endif
 
   }
 
@@ -175,9 +177,11 @@ namespace
       if (gtk_combo_box_get_active_iter (combo, &iter))
         gtk_tree_model_get (gtk_combo_box_get_model(combo), &iter, 1, &rank, -1);
       int ssl(0);
+#ifdef HAVE_OPENSSL
       combo = GTK_COMBO_BOX (d->ssl_combo);
       if (gtk_combo_box_get_active_iter (combo, &iter))
         gtk_tree_model_get (gtk_combo_box_get_model(combo), &iter, 1, &ssl, -1);
+#endif
 
       const char * err_msg (0);
       if (addr.empty())
@@ -325,18 +329,15 @@ pan :: server_edit_dialog_new (Data& data, Queue& queue, GtkWindow * window, con
     HIG::workarea_add_row (t, &row, e, w);
 
     // ssl 3.0 option
+#ifdef HAVE_OPENSSL
     HIG::workarea_add_section_divider (t, &row);
     HIG::workarea_add_section_title (t, &row, _("Security"));
     HIG::workarea_add_section_spacer (t, row, 2);
 
     struct { int o; const char * str; } ssl_items[] = {
-#ifdef HAVE_OPENSSL
+
       { 0, N_("Use Plaintext (Unsecured) Connections") },
       { 1, N_("Use Secure TLS (SSL) Connections") }
-
-#else
-      { 0, N_("Use Plaintext (Unsecured) Connections") }
-#endif
     };
 
     store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
@@ -358,8 +359,7 @@ pan :: server_edit_dialog_new (Data& data, Queue& queue, GtkWindow * window, con
     gtk_widget_set_tooltip_text( e, _("You can set the option for using/disabling secure SSL/TLS connections here. If you enable SSL/TLS, your data is encrypted and secure. "
                                       "It is encouraged to use this option for privacy reasons."));
     HIG::workarea_add_row (t, &row, e, w);
-
-
+#endif
 
   d->server = server;
   edit_dialog_populate (data, server, d);
diff --git a/pan/tasks/Makefile.am b/pan/tasks/Makefile.am
index 47d7459..7471f40 100644
--- a/pan/tasks/Makefile.am
+++ b/pan/tasks/Makefile.am
@@ -17,8 +17,8 @@ libtasks_a_SOURCES = \
   queue.cc \
   upload-queue.cc \
   socket.cc \
-  socket-impl-openssl.cc \
   socket-impl-main.cc \
+  socket-impl-openssl.cc \
   socket-impl-gio.cc \
   socket-impl-scripted.cc \
   nntp-pool.cc
diff --git a/pan/tasks/socket-impl-gio.cc b/pan/tasks/socket-impl-gio.cc
index d9cc962..7c92244 100644
--- a/pan/tasks/socket-impl-gio.cc
+++ b/pan/tasks/socket-impl-gio.cc
@@ -93,6 +93,7 @@ extern "C" {
 
 using namespace pan;
 
+
 namespace
 {
 
@@ -161,7 +162,7 @@ namespace
       hints.ai_family = 0;
       hints.ai_socktype = SOCK_STREAM;
       struct addrinfo * ans;
-      err = ::getaddrinfo (host.c_str(), portbuf, &hints, &ans);
+      err = p_getaddrinfo (host.c_str(), portbuf, &hints, &ans);
       if (err != 0) {
         char buf[512];
         snprintf (buf, sizeof(buf), _("Error connecting to \"%s\""), hpbuf);
@@ -196,7 +197,7 @@ namespace
       }
 
       // cleanup
-      ::freeaddrinfo (ans);
+      p_freeaddrinfo (ans);
     }
 
     // create the giochannel...
diff --git a/pan/tasks/socket-impl-gio.h b/pan/tasks/socket-impl-gio.h
index e38679e..736eb76 100644
--- a/pan/tasks/socket-impl-gio.h
+++ b/pan/tasks/socket-impl-gio.h
@@ -25,6 +25,8 @@
 #include <glib/gstring.h>
 #include <pan/tasks/socket.h>
 
+
+
 namespace pan
 {
   /**
diff --git a/pan/tasks/socket-impl-main.cc b/pan/tasks/socket-impl-main.cc
index ff6bc38..9b8adfb 100644
--- a/pan/tasks/socket-impl-main.cc
+++ b/pan/tasks/socket-impl-main.cc
@@ -43,66 +43,6 @@
 
 using namespace pan;
 
-/*  FIXME for win32!!!!!!!
-namespace
-{
-  void ensure_module_inited (void)
-  {
-    static bool inited (false);
-
-    if (!inited)
-    {
-      p_freeaddrinfo=NULL;
-      p_getaddrinfo=NULL;
-
-#ifdef G_OS_WIN32
-      WSADATA wsaData;
-      WSAStartup(MAKEWORD(2,2), &wsaData);
-
-      char sysdir[MAX_PATH], path[MAX_PATH+8];
-
-      if(GetSystemDirectory(sysdir,MAX_PATH)!=0)
-      {
-        HMODULE lib=NULL;
-        FARPROC pfunc=NULL;
-        const char *libs[]={"ws2_32","wship6",NULL};
-
-        for(const char **p=libs;*p!=NULL;++p)
-        {
-          g_snprintf(path,MAX_PATH+8,"%s\\%s",sysdir,*p);
-          lib=LoadLibrary(path);
-          if(!lib)
-            continue;
-          pfunc=GetProcAddress(lib,"getaddrinfo");
-          if(!pfunc)
-          {
-            FreeLibrary(lib);
-            lib=NULL;
-            continue;
-          }
-          p_getaddrinfo=reinterpret_cast<t_getaddrinfo>(pfunc);
-          pfunc=GetProcAddress(lib,"freeaddrinfo");
-          if(!pfunc)
-          {
-            FreeLibrary(lib);
-            lib=NULL;
-            p_getaddrinfo=NULL;
-            continue;
-          }
-          p_freeaddrinfo=reinterpret_cast<t_freeaddrinfo>(pfunc);
-          break;
-        }
-      }
-#else
-      p_freeaddrinfo=::freeaddrinfo;
-      p_getaddrinfo=::getaddrinfo;
-#endif
-      inited = true;
-    }
-  }
-}
-*/
-
 namespace pan
 {
   struct ThreadWorker : public WorkerPool::Worker,
@@ -168,7 +108,7 @@ namespace
     for (int i=0; i<CRYPTO_num_locks(); i++)
       pthread_mutex_destroy(&lock_cs[i]);
     CRYPTO_set_locking_callback(0);
-    CRYPTO_set_id_callback(0);
+//    CRYPTO_set_id_callback(0);
     OPENSSL_free(lock_cs);
   }
 }
@@ -198,7 +138,7 @@ SocketCreator :: create_socket (const StringView & host,
                                 Socket::Creator::Listener * listener,
                                 bool               use_ssl)
 {
-//  ensure_module_inited ();
+  ensure_module_init ();
 
   ThreadWorker * w = new ThreadWorker (host, port, listener, use_ssl);
   threadpool.push_work (w, w, true);
diff --git a/pan/tasks/socket-impl-main.h b/pan/tasks/socket-impl-main.h
index 881aba5..db7da4a 100644
--- a/pan/tasks/socket-impl-main.h
+++ b/pan/tasks/socket-impl-main.h
@@ -42,15 +42,72 @@
 #endif
 #include "socket-impl-gio.h"
 
-namespace pan
+namespace
 {
-
   typedef int (*t_getaddrinfo)(const char *,const char *, const struct addrinfo*, struct addrinfo **);
-  static t_getaddrinfo p_getaddrinfo (0);
-
   typedef void (*t_freeaddrinfo)(struct addrinfo*);
+}
+
+namespace
+{
+
+  static t_getaddrinfo p_getaddrinfo (0);
   static t_freeaddrinfo p_freeaddrinfo (0);
 
+  static void ensure_module_init (void)
+  {
+    static bool inited (false);
+
+    if (!inited)
+    {
+      p_freeaddrinfo=NULL;
+      p_getaddrinfo=NULL;
+
+#ifdef G_OS_WIN32
+      WSADATA wsaData;
+      WSAStartup(MAKEWORD(2,2), &wsaData);
+
+      char sysdir[MAX_PATH], path[MAX_PATH+8];
+
+      if(GetSystemDirectory(sysdir,MAX_PATH)!=0)
+      {
+        HMODULE lib=NULL;
+        FARPROC pfunc=NULL;
+        const char *libs[]={"ws2_32","wship6",NULL};
+
+        for(const char **p=libs;*p!=NULL;++p)
+        {
+          g_snprintf(path,MAX_PATH+8,"%s\\%s",sysdir,*p);
+          lib=LoadLibrary(path);
+          if(!lib)
+            continue;
+          pfunc=GetProcAddress(lib,"getaddrinfo");
+          if(!pfunc)
+          {
+            FreeLibrary(lib);
+            lib=NULL;
+            continue;
+          }
+          p_getaddrinfo=reinterpret_cast<t_getaddrinfo>(pfunc);
+          pfunc=GetProcAddress(lib,"freeaddrinfo");
+          if(!pfunc)
+          {
+            FreeLibrary(lib);
+            lib=NULL;
+            p_getaddrinfo=NULL;
+            continue;
+          }
+          p_freeaddrinfo=reinterpret_cast<t_freeaddrinfo>(pfunc);
+          break;
+        }
+      }
+#else
+      p_freeaddrinfo=::freeaddrinfo;
+      p_getaddrinfo=::getaddrinfo;
+#endif
+      inited = true;
+    }
+  }
 }
 
 namespace pan
diff --git a/pan/tasks/socket-impl-openssl.cc b/pan/tasks/socket-impl-openssl.cc
index 8b727af..98a5e72 100644
--- a/pan/tasks/socket-impl-openssl.cc
+++ b/pan/tasks/socket-impl-openssl.cc
@@ -93,6 +93,9 @@ extern "C" {
 
 using namespace pan;
 
+extern t_getaddrinfo p_getaddrinfo;
+extern t_freeaddrinfo p_freeaddrinfo;
+
 /****
 *****
 *****
diff --git a/pan/tasks/socket-impl-openssl.h b/pan/tasks/socket-impl-openssl.h
index fcf8f23..93a6c87 100644
--- a/pan/tasks/socket-impl-openssl.h
+++ b/pan/tasks/socket-impl-openssl.h
@@ -35,6 +35,8 @@
 #endif
 
 #include "socket-impl-gio.h"
+#include "socket-impl-main.h"
+
 
 namespace pan
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]