From: Jakub Skoczen Date: Fri, 10 May 2013 14:53:20 +0000 (+0200) Subject: Merge branch 'rewrite-filter' of ssh://git.indexdata.com/home/git/pub/metaproxy into... X-Git-Tag: v1.3.59~57^2~13 X-Git-Url: http://jsfdemo.indexdata.com/?a=commitdiff_plain;h=327c0b4339d90ee73a9dac0d692bc94bf7f05ea1;hp=a258482a3b53b90b0932f4a789ba66e8e1576c05;p=metaproxy-moved-to-github.git Merge branch 'rewrite-filter' of ssh://git.indexdata.com/home/git/pub/metaproxy into rewrite-filter --- diff --git a/doc/metaproxy.xml b/doc/metaproxy.xml index a41b625..d3a94d7 100644 --- a/doc/metaproxy.xml +++ b/doc/metaproxy.xml @@ -29,6 +29,7 @@ metaproxy + @@ -67,6 +68,13 @@ + -v loglevel + + Specify YAZ log level (all, debug, log) + + + + --config config Specify the configuration. diff --git a/example-module/Makefile b/example-module/Makefile index 63810a2..a352aed 100644 --- a/example-module/Makefile +++ b/example-module/Makefile @@ -1,10 +1,12 @@ -CONFIG=../../yazpp/yazpp-config +CONFIG=../metaproxy-config SO=metaproxy_filter_myfilter.so all: $(SO) $(SO): filter_myfilter.cpp - $(CXX) -shared `$(CONFIG) --cflags` -fPIC -I ../src $< -o $(SO) ../src/.libs/libmetaproxy.so -ldl + echo $(LIBS) + $(CXX) -shared `$(CONFIG) --cflags` -fPIC -I ../src $< \ + -o $(SO) `$(CONFIG) --libs` clean: rm -f *.so diff --git a/metaproxy-config.in b/metaproxy-config.in index d9e7f03..7d90136 100644 --- a/metaproxy-config.in +++ b/metaproxy-config.in @@ -12,7 +12,7 @@ echo_lalibs=no src_root=@abs_top_srcdir@ build_root=@abs_top_builddir@ -libs="@YAZPPLIB@ @LIBS@" +libs="@BOOST_LIB@ @BOOST_REGEX_LIB@ @BOOST_THREAD_LIB@ @YAZPPLIB@ @LIBS@" lalibs="@YAZPPLALIB@ @LIBS@" VERSION=@VERSION@ diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index 6f48973..bfa1b77 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -124,7 +124,7 @@ static int sc_main( set_log_prefix(); - while ((ret = options("c{config}:Dh{help}l:m:p:tu:V{version}w:X", + while ((ret = options("c{config}:Dh{help}l:m:p:tu:v:V{version}w:X", argv, argc, &arg)) != -2) { switch (ret) @@ -139,6 +139,7 @@ static int sc_main( std::cerr << "metaproxy\n" " -h|--help help\n" " -V|--version version\n" + " -v level\n" " -c|--config f config filename\n" " -D daemon and keepalive operation\n" " -l f log file f\n" @@ -170,6 +171,9 @@ static int sc_main( case 'u': uid = arg; break; + case 'v': + yaz_log_init_level(yaz_log_mask_str(arg)); + break; case 'V': std::cout << VERSION; #ifdef VERSION_SHA1 diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index 7753f0e..430e784 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -57,21 +57,11 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) { try { - mp::filter::HttpRewrite fhr; - } - catch ( ... ) { - BOOST_CHECK (false); - } -} - -BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 ) -{ - try - { + std::cout << "Running non-xml config test case" << std::endl; mp::RouterChain router; - mp::filter::HttpRewrite fhr; + //configure the filter mp::filter::HttpRewrite::spair_vec vec_req; vec_req.push_back(std::make_pair( "(?http\\:\\/\\/s?)(?[^\\/?#]+)\\/(?[^\\/]+)" @@ -80,42 +70,125 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 ) )); vec_req.push_back(std::make_pair( "(?:Host\\: )(.*)", - "Host: localhost" + "Host: ${host}" )); mp::filter::HttpRewrite::spair_vec vec_res; vec_res.push_back(std::make_pair( - "(?http\\:\\/\\/s?)(?[^\\/?#]+)\\/(?[^ >]+)", - "THAT WAS MATCHED" + "(?http\\:\\/\\/s?)(?[^\\/?# \"'>]+)\\/(?[^ \"'>]+)", + "${proto}${pxhost}/${pxpath}/${host}/${path}" )); fhr.configure(vec_req, vec_res); - - mp::filter::HTTPClient hc; router.append(fhr); - router.append(hc); // create an http request mp::Package pack; mp::odr odr; Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, - "http://proxyhost/proxypath/localhost:80/~jakub/targetsite.php", 0, 1); + "http://proxyhost/proxypath/targetsite/page1.html", 0, 1); pack.request() = gdu_req; + //create the http response + + const char *resp_buf = + "HTTP/1.1 200 OK\r\n" + "Content-Length: 441\r\n" + "Content-Type: text/html\r\n" + "Link: ; rel=absolute\r\n" + "Link: ; rel=relative\r\n" + "\r\n" + "Hello proxy!" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "\n" "\n" " \n" " https?://)(?<pxhost>[^ /?#]+)/(?<pxpath>[^ /]+)" + "/(?<host>[^ /]+)(?<path>[^ ]*)'\n" " to='${proto}${host}${path}' />\n" - " \n" + " \n" " \n" " \n" " \n" + "(?<proto>https?://)(?<host>[^/?# "'>]+)/(?<path>[^ "'>]+)'\n" + " to='${proto}${pxhost}/${pxpath}/${host}/${path}' />\n" " \n" "\n" - ; + ; std::cout << xmlconf; @@ -154,36 +232,100 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_3 ) xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(), xmlconf.size()); BOOST_CHECK(doc); xmlNode *root_element = xmlDocGetRootElement(doc); - mp::filter::HttpRewrite fhr; fhr.configure(root_element, true, ""); xmlFreeDoc(doc); - - mp::filter::HTTPClient hc; - mp::RouterChain router; router.append(fhr); - router.append(hc); // create an http request mp::Package pack; mp::odr odr; Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, - "http://proxyhost/proxypath/localhost:80/~jakub/targetsite.php", 0, 1); + "http://proxyhost/proxypath/targetsite/page1.html", 0, 1); pack.request() = gdu_req; + //create the http response + + const char *resp_buf = + "HTTP/1.1 200 OK\r\n" + "Content-Length: 50\r\n" + "Content-Type: text/html\r\n" + "Link: ; rel=absolute\r\n" + "Link: ; rel=relative\r\n" + "\r\n" + "Hello proxy!" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "