Use dlsym to load all filters
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 14 May 2013 09:17:51 +0000 (11:17 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 14 May 2013 09:17:51 +0000 (11:17 +0200)
Not on Windows, however, where dlsym is unavailable.

src/Makefile.am
src/factory_filter.cpp
src/factory_static.cpp

index 5fde070..e47daa8 100644 (file)
@@ -9,25 +9,14 @@ AM_CXXFLAGS = $(BOOST_CPPFLAGS)
 
 AM_CPPFLAGS = -I$(top_srcdir)/include $(USEMARCONINC)
 
-AM_LDFLAGS =
-
 bin_SCRIPTS = metaproxy-config
 
-# Rules for the library..
-
-lib_LTLIBRARIES = libmetaproxy.la
-libmetaproxy_la_LDFLAGS = -version-info 4:0:0 -export-dynamic
-
-libmetaproxy_la_SOURCES = \
-       factory_filter.cpp factory_filter.hpp \
-       factory_static.cpp factory_static.hpp \
-       filter.cpp \
+filter_src = \
        filter_auth_simple.cpp filter_auth_simple.hpp \
        filter_backend_test.cpp filter_backend_test.hpp \
        filter_bounce.cpp filter_bounce.hpp \
        filter_cgi.cpp filter_cgi.hpp \
        filter_cql_to_rpn.cpp filter_cql_to_rpn.hpp \
-       filter_frontend_net.cpp filter_frontend_net.hpp \
        filter_http_client.cpp filter_http_client.hpp \
        filter_http_file.cpp filter_http_file.hpp \
        filter_http_rewrite1.cpp filter_http_rewrite1.hpp \
@@ -45,6 +34,15 @@ libmetaproxy_la_SOURCES = \
        filter_z3950_client.cpp filter_z3950_client.hpp \
        filter_zeerex_explain.cpp  filter_zeerex_explain.hpp \
        filter_zoom.cpp filter_zoom.hpp \
+       filter_frontend_net.cpp filter_frontend_net.hpp
+
+lib_LTLIBRARIES = libmetaproxy.la
+libmetaproxy_la_LDFLAGS = -version-info 4:0:0 -export-dynamic
+
+libmetaproxy_la_SOURCES = \
+       factory_filter.cpp factory_filter.hpp \
+       factory_static.cpp factory_static.hpp \
+       filter.cpp \
        gduutil.cpp gduutil.hpp \
        origin.cpp \
        package.cpp \
@@ -58,26 +56,24 @@ libmetaproxy_la_SOURCES = \
        torus.cpp torus.hpp \
        url_recipe.cpp \
        util.cpp \
-       xmlutil.cpp 
-
+       xmlutil.cpp
 
 libmetaproxy_la_LIBADD = $(YAZPPLALIB) \
        $(BOOST_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_THREAD_LIB) \
        $(BOOST_REGEX_LIB)
 
-# Rules for lib
-
-LDADD = libmetaproxy.la $(YAZPPLALIB) \
+metaproxy_LDADD = libmetaproxy.la $(YAZPPLALIB) \
        $(BOOST_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_THREAD_LIB) \
        $(BOOST_REGEX_LIB) $(USEMARCONLALIB)
 
+LDADD = $(metaproxy_LDADD) $(BOOST_TEST_LIB)
+AM_LDFLAGS = -export-dynamic
+
 bin_PROGRAMS = metaproxy
-noinst_PROGRAMS = ex_filter_frontend_net ex_router_flexml tstdl
+noinst_PROGRAMS = tstdl
 
-ex_filter_frontend_net_SOURCES = ex_filter_frontend_net.cpp
-ex_router_flexml_SOURCES =  ex_router_flexml.cpp
 tstdl_SOURCES = tstdl.cpp
-metaproxy_SOURCES = metaproxy_prog.cpp
+metaproxy_SOURCES = metaproxy_prog.cpp $(filter_src)
 
 # Rules for dl programs
 pkglib_LTLIBRARIES = metaproxy_filter_dl.la
@@ -121,48 +117,23 @@ test_session1_SOURCES=test_session1.cpp
 test_session2_SOURCES=test_session2.cpp
 test_boost_threads_SOURCES=test_boost_threads.cpp
 test_thread_pool_observer_SOURCES = test_thread_pool_observer.cpp
-test_filter_auth_simple_SOURCES = test_filter_auth_simple.cpp
+test_filter_auth_simple_SOURCES = test_filter_auth_simple.cpp $(filter_src)
 test_filter_factory_SOURCES = test_filter_factory.cpp
-test_filter_frontend_net_SOURCES = test_filter_frontend_net.cpp
-test_filter_log_SOURCES = test_filter_log.cpp
-test_filter_multi_SOURCES = test_filter_multi.cpp
-test_filter_query_rewrite_SOURCES = test_filter_query_rewrite.cpp
-test_filter_z3950_client_SOURCES = test_filter_z3950_client.cpp
-test_filter_backend_test_SOURCES = test_filter_backend_test.cpp
-test_filter_bounce_SOURCES = test_filter_bounce.cpp
-test_filter_record_transform_SOURCES = test_filter_record_transform.cpp
-test_filter_sru_to_z3950_SOURCES = test_filter_sru_to_z3950.cpp
-test_filter_virt_db_SOURCES = test_filter_virt_db.cpp
+test_filter_frontend_net_SOURCES = test_filter_frontend_net.cpp $(filter_src)
+test_filter_log_SOURCES = test_filter_log.cpp $(filter_src)
+test_filter_multi_SOURCES = test_filter_multi.cpp $(filter_src)
+test_filter_query_rewrite_SOURCES = test_filter_query_rewrite.cpp $(filter_src)
+test_filter_z3950_client_SOURCES = test_filter_z3950_client.cpp $(filter_src)
+test_filter_backend_test_SOURCES = test_filter_backend_test.cpp $(filter_src)
+test_filter_bounce_SOURCES = test_filter_bounce.cpp $(filter_src)
+test_filter_record_transform_SOURCES = test_filter_record_transform.cpp \
+       $(filter_src)
+test_filter_sru_to_z3950_SOURCES = test_filter_sru_to_z3950.cpp $(filter_src)
+test_filter_virt_db_SOURCES = test_filter_virt_db.cpp $(filter_src)
 test_ses_map_SOURCES = test_ses_map.cpp
-test_router_flexml_SOURCES = test_router_flexml.cpp
+test_router_flexml_SOURCES = test_router_flexml.cpp $(filter_src)
 test_xmlutil_SOURCES = test_xmlutil.cpp
 
-TESTLDADD = $(LDADD) $(BOOST_TEST_LIB)
-
-test_package1_LDADD = $(TESTLDADD)
-test_pipe_LDADD = $(TESTLDADD)
-test_filter1_LDADD = $(TESTLDADD)
-test_filter2_LDADD = $(TESTLDADD)
-test_session1_LDADD = $(TESTLDADD)
-test_session2_LDADD = $(TESTLDADD)
-test_boost_threads_LDADD = $(TESTLDADD)
-test_filter_auth_simple_LDADD = $(TESTLDADD)
-test_filter_factory_LDADD = $(TESTLDADD)
-test_filter_frontend_net_LDADD = $(TESTLDADD)
-test_filter_log_LDADD = $(TESTLDADD)
-test_filter_multi_LDADD = $(TESTLDADD)
-test_filter_query_rewrite_LDADD = $(TESTLDADD)
-test_filter_z3950_client_LDADD = $(TESTLDADD)
-test_filter_backend_test_LDADD = $(TESTLDADD)
-test_filter_bounce_LDADD = $(TESTLDADD)
-test_filter_record_transform_LDADD = $(TESTLDADD)
-test_filter_sru_to_z3950_LDADD = $(TESTLDADD)
-test_filter_virt_db_LDADD = $(TESTLDADD)
-test_router_flexml_LDADD = $(TESTLDADD)
-test_ses_map_LDADD = $(TESTLDADD)
-test_thread_pool_observer_LDADD = $(TESTLDADD)
-test_xmlutil_LDADD = $(TESTLDADD)
-
 # doxygen target
 dox:
        (cd $(top_srcdir) ; make dox) 
index 071a7d1..7ea6d3a 100644 (file)
@@ -118,20 +118,24 @@ bool mp::FactoryFilter::add_creator_dl(const std::string &fi,
     {
         return true;
     }
-
-    std::string full_path = path + "/metaproxy_filter_" + fi + ".so";
-    void *dl_handle = dlopen(full_path.c_str(), RTLD_GLOBAL|RTLD_NOW);
-    if (!dl_handle)
-    {
-        const char *dl = dlerror();
-        std::cout << "dlopen " << full_path << " failed. dlerror=" << dl <<
-            std::endl;
-        return false;
-    }
-
     std::string full_name = "metaproxy_1_filter_" + fi;
 
+    void *dl_handle = dlopen(0, RTLD_GLOBAL|RTLD_NOW);
     void *dlsym_ptr = dlsym(dl_handle, full_name.c_str());
+
+    if (!dlsym_ptr)
+    {
+        std::string full_path = path + "/metaproxy_filter_" + fi + ".so";
+        dl_handle = dlopen(full_path.c_str(), RTLD_GLOBAL|RTLD_NOW);
+        if (!dl_handle)
+        {
+            const char *dl = dlerror();
+            std::cout << "dlopen " << full_path << " failed. dlerror=" << dl <<
+                std::endl;
+            return false;
+        }
+        dlsym_ptr = dlsym(dl_handle, full_name.c_str());
+    }
     if (!dlsym_ptr)
     {
         std::cout << "dlsym " << full_name << " failed\n";
index 57636d6..b3f6370 100644 (file)
@@ -57,6 +57,7 @@ namespace mp = metaproxy_1;
 
 mp::FactoryStatic::FactoryStatic()
 {
+#ifdef WIN32
     struct metaproxy_1_filter_struct *buildins[] = {
         &metaproxy_1_filter_auth_simple,
         &metaproxy_1_filter_backend_test,
@@ -89,6 +90,8 @@ mp::FactoryStatic::FactoryStatic()
 
     for (i = 0; buildins[i]; i++)
         add_creator(buildins[i]->type, buildins[i]->creator);
+// WIN32
+#endif
 }