From b876533df5b7932bf07155750cfb048518745121 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 6 Dec 2014 14:15:29 +0100 Subject: [PATCH 01/18] Extended messages cannot have required fields (must be optional). Signed-off-by: Roland Haeder --- src/plugins/query_capture/db_query_record_msg.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/query_capture/db_query_record_msg.proto b/src/plugins/query_capture/db_query_record_msg.proto index c57eee99..31c6a290 100644 --- a/src/plugins/query_capture/db_query_record_msg.proto +++ b/src/plugins/query_capture/db_query_record_msg.proto @@ -33,5 +33,5 @@ message related_query extend sp.db.record { - required related_queries queries = 20; /* original queries */ + optional related_queries queries = 20; /* original queries */ } From 7501b2385f1b0f5877bcfac1964bc920e5e2c1ee Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 19 May 2015 13:06:54 +0200 Subject: [PATCH 02/18] Please use full PHP header --- resources/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/search.php b/resources/search.php index ca703e24..90fb605a 100644 --- a/resources/search.php +++ b/resources/search.php @@ -1,4 +1,4 @@ - Date: Tue, 19 May 2015 13:17:41 +0200 Subject: [PATCH 03/18] Heavy improvements: - header('Location: bla-blub'); does *NOT* abort the script, *ALWAYS* use an explicit exit() call! - Check for $_SERVER array elements, not all browsers may send it causing E_NOTICE (bad code style) - Converted double-quotes to single-quotes - if() and else conditions are now in one line + curly braces are always explicitly set - Other small cleanups Signed-off-by: Roland Haeder --- resources/search.php | 88 ++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/resources/search.php b/resources/search.php index 90fb605a..c8401227 100644 --- a/resources/search.php +++ b/resources/search.php @@ -15,18 +15,40 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.fsf.org/licensing/licenses/agpl-3.0.html. */ -if($_SERVER['HTTPS']) $scheme = 'https://'; -else $scheme= 'http://'; +// Default is HTTP +$scheme = 'http://'; + +if (isset($_SERVER['HTTPS'])) { + $scheme = 'https://'; +} $seeks_uri = 'http://s.s'; $proxy = 'localhost:8250'; $base_script = $_SERVER['SCRIPT_NAME']; $base_url = $scheme.$_SERVER['HTTP_HOST'].$base_script; -if ($_SERVER['REQUEST_URI'] == '/search.php') { header('Location: '.$base_url.'/websearch-hp'); } -else $url = $seeks_uri.str_replace($base_script, '', $_SERVER['REQUEST_URI']); -$lang_head = $_SERVER['HTTP_ACCEPT_LANGUAGE']; -$referer = $_SERVER['HTTP_REFERER']; +if ($_SERVER['REQUEST_URI'] == '/search.php') { + header('Location: '.$base_url.'/websearch-hp'); + + // Don't miss exit() as the server redirect doesn't abort the script + exit(); +} else { + $url = $seeks_uri . str_replace($base_script, '', $_SERVER['REQUEST_URI']); +} + +// Avoid E_NOTICE by initializing variables and checking on array elements +$lang_head = ''; +$referer = ''; + +// Not all browsers are sending this header +if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + $lang_head = $_SERVER['HTTP_ACCEPT_LANGUAGE']; +} + +// Not all browsers are sending this header +if (isset($_SERVER['HTTP_REFERER'])) { + $referer = $_SERVER['HTTP_REFERER']; +} $qc_redir = array(); preg_match('/qc_redir/', $url, $qc_redir); @@ -39,42 +61,46 @@ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); -if ($qc_redir[0] == "qc_redir" - || $tbd[0] == "tbd") -{ - curl_setopt($curl, CURLOPT_HEADER, true); + +if ($qc_redir[0] == 'qc_redir' || $tbd[0] == 'tbd') { + curl_setopt($curl, CURLOPT_HEADER, true); } + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']); -if ($bqc[0] == "find_bqc") -{ - $postdata = file_get_contents("php://input"); - curl_setopt($curl, CURLOPT_POST, 1); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); + +if ($bqc[0] == 'find_bqc') { + $postdata = file_get_contents('php://input'); + curl_setopt($curl, CURLOPT_POST, 1); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); } + curl_setopt($curl, CURLOPT_PROXY, $proxy); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1) ; -curl_setopt($curl, CURLOPT_HTTPHEADER, array("Seeks-Remote-Location: ".$base_url,"Accept-Language: ".$lang_head,"Referer: " .$referer)); +curl_setopt($curl, CURLOPT_HTTPHEADER, array('Seeks-Remote-Location: '.$base_url, 'Accept-Language: '.$lang_head, 'Referer: '.$referer)); $result = curl_exec($curl); $result_info = curl_getinfo($curl); -if(curl_errno($curl)) echo 'CURL ERROR: '.curl_error($curl); + +if(curl_errno($curl)) { + echo 'CURL ERROR: '.curl_error($curl); +} + curl_close($curl); header('Content-Type: '.$result_info['content_type']); -if ($qc_redir[0] == "qc_redir" - || $tbd[0] == "tbd") -{ - $status_code = array(); - preg_match('/\d\d\d/', $result, $status_code); - switch( $status_code[0] ) { - case 302: - $location = array(); - preg_match('/Location: (.*)/', $result, $location); - $location[0] = substr($location[0],10); - header("Location: ". $location[0]); - break; - default: - } +if ($qc_redir[0] == 'qc_redir' || $tbd[0] == 'tbd') { + preg_match('/\d\d\d/', $result, $status_code); + + switch( $status_code[0] ) { + case 302: + $location = array(); + preg_match('/Location: (.*)/', $result, $location); + $location[0] = substr($location[0],10); + header('Location: '. $location[0]); + + // Don't miss exit() as the server redirect doesn't abort the script + exit(); + } } echo $result; From 8d728ed7bee990702627b9a973f93a8d6caadd66 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 19 May 2015 13:44:29 +0200 Subject: [PATCH 04/18] More cleanups Signed-off-by: Roland Haeder --- resources/search.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/resources/search.php b/resources/search.php index c8401227..c1501dcb 100644 --- a/resources/search.php +++ b/resources/search.php @@ -18,22 +18,24 @@ // Default is HTTP $scheme = 'http://'; +// Is HTTPS set? if (isset($_SERVER['HTTPS'])) { + // Then assume https:// shall be used $scheme = 'https://'; } $seeks_uri = 'http://s.s'; $proxy = 'localhost:8250'; -$base_script = $_SERVER['SCRIPT_NAME']; -$base_url = $scheme.$_SERVER['HTTP_HOST'].$base_script; + +$base_url = $scheme . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']; if ($_SERVER['REQUEST_URI'] == '/search.php') { - header('Location: '.$base_url.'/websearch-hp'); + header('Location: ' . $base_url . '/websearch-hp'); // Don't miss exit() as the server redirect doesn't abort the script exit(); } else { - $url = $seeks_uri . str_replace($base_script, '', $_SERVER['REQUEST_URI']); + $url = $seeks_uri . str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI']); } // Avoid E_NOTICE by initializing variables and checking on array elements @@ -76,7 +78,10 @@ curl_setopt($curl, CURLOPT_PROXY, $proxy); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1) ; -curl_setopt($curl, CURLOPT_HTTPHEADER, array('Seeks-Remote-Location: '.$base_url, 'Accept-Language: '.$lang_head, 'Referer: '.$referer)); + +// @TODO Seeks-Remote-Location is NO default header, always prefix with X-!!! +curl_setopt($curl, CURLOPT_HTTPHEADER, array('Seeks-Remote-Location: ' . $base_url, 'Accept-Language: ' . $lang_head, 'Referer: ' . $referer)); + $result = curl_exec($curl); $result_info = curl_getinfo($curl); From fe8e51b2a15f78265e516a32723adb8298001f4b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 19 May 2015 13:50:40 +0200 Subject: [PATCH 05/18] 'Seeks-Remote-Location' is a custom HTTP header and according to specification it *MUST* be prefixed with 'X-'. Signed-off-by: Roland Haeder --- resources/search.php | 3 +-- src/plugins/query_capture/query_capture.cpp | 2 +- src/plugins/websearch/query_context.cpp | 2 +- src/plugins/websearch/static_renderer.cpp | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/resources/search.php b/resources/search.php index c1501dcb..ab38bfbb 100644 --- a/resources/search.php +++ b/resources/search.php @@ -79,8 +79,7 @@ curl_setopt($curl, CURLOPT_PROXY, $proxy); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1) ; -// @TODO Seeks-Remote-Location is NO default header, always prefix with X-!!! -curl_setopt($curl, CURLOPT_HTTPHEADER, array('Seeks-Remote-Location: ' . $base_url, 'Accept-Language: ' . $lang_head, 'Referer: ' . $referer)); +curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Seeks-Remote-Location: ' . $base_url, 'Accept-Language: ' . $lang_head, 'Referer: ' . $referer)); $result = curl_exec($curl); $result_info = curl_getinfo($curl); diff --git a/src/plugins/query_capture/query_capture.cpp b/src/plugins/query_capture/query_capture.cpp index 0c0b6cad..856be7b1 100644 --- a/src/plugins/query_capture/query_capture.cpp +++ b/src/plugins/query_capture/query_capture.cpp @@ -650,7 +650,7 @@ namespace seeks_plugins referer = ""; } } - else if (miscutil::strncmpic((*lit),"Seeks-Remote-Location:",22) == 0) + else if (miscutil::strncmpic((*lit),"X-Seeks-Remote-Location:",22) == 0) { base_url = (*lit); try diff --git a/src/plugins/websearch/query_context.cpp b/src/plugins/websearch/query_context.cpp index 4542d3ae..2098c29e 100644 --- a/src/plugins/websearch/query_context.cpp +++ b/src/plugins/websearch/query_context.cpp @@ -597,7 +597,7 @@ namespace seeks_plugins std::list::const_iterator sit = headers.begin(); while (sit!=headers.end()) { - if (miscutil::strncmpic((*sit),"Seeks-Remote-Location:",22) == 0) + if (miscutil::strncmpic((*sit),"X-Seeks-Remote-Location:",22) == 0) { base_url = (*sit); size_t pos = base_url.find_first_of(" "); diff --git a/src/plugins/websearch/static_renderer.cpp b/src/plugins/websearch/static_renderer.cpp index b26165b6..df508f44 100644 --- a/src/plugins/websearch/static_renderer.cpp +++ b/src/plugins/websearch/static_renderer.cpp @@ -677,7 +677,7 @@ namespace seeks_plugins = cgi::default_exports(csp,""); // we need to inject a remote base location for remote web access. - // the injected header, if it exists is Seeks-Remote-Location + // the injected header, if it exists is X-Seeks-Remote-Location std::string base_url = query_context::detect_base_url_http(csp); miscutil::add_map_entry(exports,"base-url",1,base_url.c_str(),1); From ce9134e635c850f79586a75cb429323d676b0c1a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 19 May 2015 14:01:28 +0200 Subject: [PATCH 06/18] Temporary hide-out ... ;-) Signed-off-by: Roland Haeder --- src/plugins/cf/tests/ut-cf-sre.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/cf/tests/ut-cf-sre.cpp b/src/plugins/cf/tests/ut-cf-sre.cpp index 1381cc06..0a93e8c5 100644 --- a/src/plugins/cf/tests/ut-cf-sre.cpp +++ b/src/plugins/cf/tests/ut-cf-sre.cpp @@ -563,7 +563,7 @@ TEST_F(SRETest,recommendation_post_url_check_retrieve) http_response rsp; hash_map,eqstr> *parameters = new hash_map,eqstr>(); - miscutil::add_map_entry(parameters,"url",1,"http://www.seeks.fr/",1); + miscutil::add_map_entry(parameters,"url",1,"http://seeks.mxchange.org/",1); miscutil::add_map_entry(parameters,"url-check",1,"0",1); miscutil::add_map_entry(parameters,"radius",1,"5",1); miscutil::add_map_entry(parameters,"output",1,"json",1); From be9601e4e0c97cba6ab612fd440394af4970abfe Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 19 May 2015 14:18:27 +0200 Subject: [PATCH 07/18] No, better let Beniz change this ... ;-) Signed-off-by: Roland Haeder --- src/plugins/cf/tests/ut-cf-sre.cpp | 2 +- src/plugins/cf/tests/ut-peer-list.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/plugins/cf/tests/ut-cf-sre.cpp b/src/plugins/cf/tests/ut-cf-sre.cpp index 0a93e8c5..a0fcd470 100644 --- a/src/plugins/cf/tests/ut-cf-sre.cpp +++ b/src/plugins/cf/tests/ut-cf-sre.cpp @@ -563,7 +563,7 @@ TEST_F(SRETest,recommendation_post_url_check_retrieve) http_response rsp; hash_map,eqstr> *parameters = new hash_map,eqstr>(); - miscutil::add_map_entry(parameters,"url",1,"http://seeks.mxchange.org/",1); + miscutil::add_map_entry(parameters,"url",1,"http://seeks-project.info/",1); miscutil::add_map_entry(parameters,"url-check",1,"0",1); miscutil::add_map_entry(parameters,"radius",1,"5",1); miscutil::add_map_entry(parameters,"output",1,"json",1); diff --git a/src/plugins/cf/tests/ut-peer-list.cpp b/src/plugins/cf/tests/ut-peer-list.cpp index c0eb5466..75bee4d5 100644 --- a/src/plugins/cf/tests/ut-peer-list.cpp +++ b/src/plugins/cf/tests/ut-peer-list.cpp @@ -81,6 +81,7 @@ TEST(WCFTest,cgi_peers) cf_configuration::_config = new cf_configuration(""); cf_configuration::_config->_pl->add("seeks.fr",-1,"","bsn"); cf_configuration::_config->_pl->add("seeks-project.info",-1,"/search.php","bsn"); + // @TODO Wont' work, as search_exp.php is not available? cf_configuration::_config->_pl->add("seeks-project.info",-1,"/search_exp.php","bsn"); client_state csp; http_response rsp; From 3af11e5b46960bcd10a6af576656306daceefdc8 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 19 May 2015 14:26:36 +0200 Subject: [PATCH 08/18] Better check these arrays. Signed-off-by: Roland Haeder --- resources/search.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/search.php b/resources/search.php index ab38bfbb..e970a9e8 100644 --- a/resources/search.php +++ b/resources/search.php @@ -64,13 +64,13 @@ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); -if ($qc_redir[0] == 'qc_redir' || $tbd[0] == 'tbd') { +if ((isset($qc_redir[0]) && $qc_redir[0] == 'qc_redir') || (isset($tbd[0]) && $tbd[0] == 'tbd')) { curl_setopt($curl, CURLOPT_HEADER, true); } curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']); -if ($bqc[0] == 'find_bqc') { +if (isset($bqc[0]) && $bqc[0] == 'find_bqc') { $postdata = file_get_contents('php://input'); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); @@ -92,14 +92,14 @@ header('Content-Type: '.$result_info['content_type']); -if ($qc_redir[0] == 'qc_redir' || $tbd[0] == 'tbd') { +if ((isset($qc_redir[0]) && $qc_redir[0] == 'qc_redir') || (isset($tbd[0]) && $tbd[0] == 'tbd')) { preg_match('/\d\d\d/', $result, $status_code); switch( $status_code[0] ) { case 302: $location = array(); preg_match('/Location: (.*)/', $result, $location); - $location[0] = substr($location[0],10); + $location[0] = substr($location[0], 10); header('Location: '. $location[0]); // Don't miss exit() as the server redirect doesn't abort the script From be51137a9d492292612616563a894a709b70b224 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 19 May 2015 15:21:18 +0200 Subject: [PATCH 09/18] Is it HOME_PAGE_URL that needs to be changed? Signed-off-by: Roland Haeder --- src/proxy/cgi.cpp | 2 +- src/proxy/proxy_dts.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/proxy/cgi.cpp b/src/proxy/cgi.cpp index 6f425a36..116d6b26 100644 --- a/src/proxy/cgi.cpp +++ b/src/proxy/cgi.cpp @@ -2287,7 +2287,7 @@ namespace sp if (hostname) freez(hostname); hostname = NULL; - if (!err) err = miscutil::add_map_entry(exports, "homepage", 1, encode::html_encode(HOME_PAGE_URL), 0); + if (!err) err = miscutil::add_map_entry(exports, "homepage", 1, encode::html_encode(SEARCH_PHP_URL), 0); if (!err) err = miscutil::add_map_entry(exports, "default-cgi", 1, encode::html_encode(CGI_PREFIX), 0); if (!err) err = miscutil::add_map_entry(exports, "menu", 1, cgi::make_menu(caller, csp->_config->_feature_flags), 0); diff --git a/src/proxy/proxy_dts.h b/src/proxy/proxy_dts.h index f6c43d02..064af816 100644 --- a/src/proxy/proxy_dts.h +++ b/src/proxy/proxy_dts.h @@ -1114,6 +1114,9 @@ namespace sp /** URL for the Seeks home page. */ #define HOME_PAGE_URL "http://www.seeks-project.info/" + /** URL for search.php calls */ +#define SEARCH_PHP_URL "https://seeks.mxchange.org/" + /** URL for the Seeks user manual. */ #define USER_MANUAL_URL HOME_PAGE_URL VERSION "/user-manual/" From aca3c86b31f4e7b05f49bf6a8b9598c392e48eb0 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 20 May 2015 21:00:38 +0200 Subject: [PATCH 10/18] Some changes Signed-off-by: Roland Haeder --- resources/search.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/search.php b/resources/search.php index e970a9e8..cd4630b9 100644 --- a/resources/search.php +++ b/resources/search.php @@ -84,13 +84,15 @@ $result = curl_exec($curl); $result_info = curl_getinfo($curl); +syslog(LOG_INFO, 'result_info=' . json_encode($result_info)); + if(curl_errno($curl)) { echo 'CURL ERROR: '.curl_error($curl); } curl_close($curl); -header('Content-Type: '.$result_info['content_type']); +header('Content-Type: ' . $result_info['content_type']); if ((isset($qc_redir[0]) && $qc_redir[0] == 'qc_redir') || (isset($tbd[0]) && $tbd[0] == 'tbd')) { preg_match('/\d\d\d/', $result, $status_code); @@ -104,6 +106,10 @@ // Don't miss exit() as the server redirect doesn't abort the script exit(); + + default: + syslog(LOG_WARNING, 'Status code ' . $status_code[0] . ' found.'); + break; } } From 5c888725bc73ad92b68111152e5c1bc6181d6eb1 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 20 May 2015 23:54:21 +0200 Subject: [PATCH 11/18] Added missing template Signed-off-by: Roland Haeder --- src/proxy/templates/cgi-error-forbidden | 132 ++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 src/proxy/templates/cgi-error-forbidden diff --git a/src/proxy/templates/cgi-error-forbidden b/src/proxy/templates/cgi-error-forbidden new file mode 100644 index 00000000..986767e7 --- /dev/null +++ b/src/proxy/templates/cgi-error-forbidden @@ -0,0 +1,132 @@ +########################################################## +# +# Forbidden Error Output template for Privoxy. +# +# +# USING HTML TEMPLATES: +# --------------------- +# +# Template files are written win plain HTML, with a few +# additions: +# +# - Lines that start with a '#' character like this one +# are ignored +# +# - Each item in the below list of exported symbols will +# be replaced by dynamically generated text, if they +# are enclosed in '@'-characters. E.g. The string @version@ +# will be replaced by the version number of Privoxy. +# +# - One special application of this is to make whole blocks +# of the HTML template disappear if the condition +# is not given. Simply enclose the block between the two +# strings @if-start and if--end@. The strings +# should be placed in HTML comments (), so the +# html structure won't be messed when the magic happens. +# +# USABLE SYMBOLS IN THIS TEMPLATE: +# -------------------------------- +# +# my-ip-addr: +# The IP-address that the client used to reach this proxy +# my-hostname: +# The hostname associated with my-ip-addr +# admin-address: +# The email address of the pxoxy's administrator, as configured +# in the config file +# default-cgi: +# The URL for the "main menu" builtin CGI of this proxy +# menu: +# List of
  • elements linking to the other available CGIs +# version: +# The version number of the proxy software +# code-status: +# The development status of the proxy software: "alpha", "beta", +# or "stable". +# homepage: +# The URL of the SourceForge ijbswa project, who maintains this +# software. +# +# CONDITIONAL SYMBOLS FOR THIS TEMPLATE AND THEIR DEPANDANT SYMBOLS: +# ------------------------------------------------------------------ +# +# unstable: +# this is an alpha or beta release of the proxy software +# have-adminaddr-info: +# An e-mail address for the local Privoxy adminstrator has +# been specified and is available through the "admin-address" +# symbol +# have-proxy-info: +# A URL for online documentation about this proxy has been +# specified and is available through the "proxy-info-url" +# symbol +# have-help-info: +# If either have-proxy-info is true or have-adminaddr-info is +# true, have-help-info is true. Used to conditionally include +# a grey box for any and all help info. +# + + + + + 403 - Seeks Forbidden + + + + + + + + + + + + + + + + + +# This will only appear if CODE_STATUS is "alpha" or "beta". See configure.in + + + + + + + + + + + + + + + + +
    + 403 + + +#include mod-title + +
    + +#include mod-unstable-warning + +
    +

    Seeks forbidden

    +

    You don't have access to the page you have requested.

    +

    If you got here by clicking a link in the + interface, please file a bug report!

    +
    +

    More:

    + +
    + +#include mod-support-and-service + +
    + + + From 54df1c32b8b679cb89bfd22628608c041ad94999 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 21 May 2015 01:25:48 +0200 Subject: [PATCH 12/18] Attempt to identify this one: Error: 1 (Out of memory) in plugin websearch-api-compat caught in top-level handler This only happens on my LAN instance, not the one at https://seeks.mxchange.org/search.php ... Signed-off-by: Roland Haeder --- .../websearch_api_compat.cpp | 94 +++++++++++++++---- src/proxy/cgi.cpp | 4 +- 2 files changed, 77 insertions(+), 21 deletions(-) diff --git a/src/plugins/websearch_api_compat/websearch_api_compat.cpp b/src/plugins/websearch_api_compat/websearch_api_compat.cpp index 2fc8b4f6..e8ff85b1 100644 --- a/src/plugins/websearch_api_compat/websearch_api_compat.cpp +++ b/src/plugins/websearch_api_compat/websearch_api_compat.cpp @@ -21,6 +21,7 @@ #include "urlmatch.h" #include "encode.h" #include "mrf.h" +#include "errlog.h" #ifdef FEATURE_IMG_WEBSEARCH_PLUGIN #include "img_websearch.h" @@ -79,8 +80,11 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) + if (!query_str || strlen(query_str) == 0) { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: Parameter 'q' is not set or empty."); return SP_ERR_CGI_PARAMS; + } + // cgi decodes the parameters, need to re-encode before passing it to websearch plugin. char *enc_query = encode::url_encode(query_str); std::string query = enc_query; @@ -122,9 +126,17 @@ namespace seeks_plugins csp->_http._path = strdup(path.c_str()); return websearch::cgi_websearch_similarity(csp,rsp,parameters); } - else return SP_ERR_CGI_PARAMS; + else + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: No 'action' given."); + return SP_ERR_CGI_PARAMS; + } + } + else + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: No parameters given."); + return SP_ERR_CGI_PARAMS; } - else return SP_ERR_CGI_PARAMS; } sp_err websearch_api_compat::cgi_search_cache_compat(client_state *csp, @@ -135,8 +147,10 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) + if (!query_str || strlen(query_str) == 0) { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'q' is not set or empty."); return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -144,8 +158,10 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); - if (!url_str) + if (!url_str) { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'url' is not set or empty."); return SP_ERR_CGI_PARAMS; + } std::string url = url_str; std::transform(url.begin(),url.end(),url.begin(),tolower); std::string surl = urlmatch::strip_url(url); @@ -159,7 +175,11 @@ namespace seeks_plugins csp->_http._path = strdup(path.c_str()); return websearch::cgi_websearch_search_cache(csp,rsp,parameters); } - else return SP_ERR_CGI_PARAMS; + else + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: No parameters given."); + return SP_ERR_CGI_PARAMS; + } } sp_err websearch_api_compat::cgi_qc_redir_compat(client_state *csp, @@ -170,8 +190,10 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) + if (!query_str || strlen(query_str) == 0) { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'q' is not set or empty."); return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -183,8 +205,10 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); - if (!url_str) + if (!url_str) { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'url' is not set or empty."); return SP_ERR_CGI_PARAMS; + } std::string url = url_str; std::transform(url.begin(),url.end(),url.begin(),tolower); std::string surl = urlmatch::strip_url(url); @@ -200,7 +224,11 @@ namespace seeks_plugins csp->_http._gpc = strdup("post"); return websearch::cgi_websearch_search(csp,rsp,parameters); } - else return SP_ERR_CGI_PARAMS; + else + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: No parameters given."); + return SP_ERR_CGI_PARAMS; + } } sp_err websearch_api_compat::cgi_tbd_compat(client_state *csp, @@ -211,8 +239,10 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) + if (!query_str || strlen(query_str) == 0) { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'q' not given."); return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -220,8 +250,10 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); - if (!url_str) + if (!url_str) { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'url' not given."); return SP_ERR_CGI_PARAMS; + } std::string url = url_str; std::transform(url.begin(),url.end(),url.begin(),tolower); std::string surl = urlmatch::strip_url(url); @@ -236,8 +268,10 @@ namespace seeks_plugins free(csp->_http._gpc); csp->_http._gpc = strdup("delete"); sp_err err = websearch::cgi_websearch_search(csp,rsp,parameters); - if (err != SP_ERR_OK) + if (err != SP_ERR_OK) { + errlog::log_error(LOG_LEVEL_ERROR, "Returning err=%s", err); return err; + } miscutil::unmap(const_cast,eqstr>*>(parameters),"q"); miscutil::unmap(const_cast,eqstr>*>(parameters),"url"); miscutil::unmap(const_cast,eqstr>*>(parameters),"action"); @@ -252,7 +286,11 @@ namespace seeks_plugins csp->_http._path = strdup(path.c_str()); return websearch::cgi_websearch_search(csp,rsp,parameters); } - else return SP_ERR_CGI_PARAMS; + else + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: No parameters given."); + return SP_ERR_CGI_PARAMS; + } } #ifdef FEATURE_IMG_WEBSEARCH_PLUGIN @@ -264,8 +302,10 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) + if (!query_str || strlen(query_str) == 0) { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'q' not given."); return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -292,9 +332,17 @@ namespace seeks_plugins return img_websearch::cgi_img_websearch_similarity(csp,rsp,parameters); } #endif - else return SP_ERR_CGI_PARAMS; + else + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'action' not given."); + return SP_ERR_CGI_PARAMS; + } + } + else + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: No paramters given."); + return SP_ERR_CGI_PARAMS; } - else return SP_ERR_CGI_PARAMS; } sp_err websearch_api_compat::cgi_img_qc_redir_compat(client_state *csp, @@ -305,8 +353,10 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) + if (!query_str || strlen(query_str) == 0) { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'q' not given."); return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -318,8 +368,10 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); - if (!url_str) + if (!url_str) { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'url' not given."); return SP_ERR_CGI_PARAMS; + } std::string url = url_str; std::transform(url.begin(),url.end(),url.begin(),tolower); std::string surl = urlmatch::strip_url(url); @@ -335,7 +387,11 @@ namespace seeks_plugins csp->_http._gpc = strdup("post"); return img_websearch::cgi_img_websearch_search(csp,rsp,parameters); } - else return SP_ERR_CGI_PARAMS; + else + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: No parameter given."); + return SP_ERR_CGI_PARAMS; + } } #endif diff --git a/src/proxy/cgi.cpp b/src/proxy/cgi.cpp index 116d6b26..e37d0f5b 100644 --- a/src/proxy/cgi.cpp +++ b/src/proxy/cgi.cpp @@ -584,8 +584,8 @@ namespace sp { /* internal plugin error. */ errlog::log_error(LOG_LEVEL_ERROR, - "%d in plugin %s caught in top-level handler", - err, d->_plugin_name.c_str()); + "%d (%s) in plugin %s caught in top-level handler", + err, errlog::sp_err_to_string(err), d->_plugin_name.c_str()); err = cgi::cgi_error_plugin(csp, rsp, err, d->_plugin_name, param_list); } } From 1abda9bd256790fa300ca331e367f8bab32e092a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 21 May 2015 01:37:10 +0200 Subject: [PATCH 13/18] Add 'forbidden' template here as well. Signed-off-by: Roland Haeder --- src/proxy/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/proxy/Makefile.am b/src/proxy/Makefile.am index d47fdab1..1a1fb53f 100644 --- a/src/proxy/Makefile.am +++ b/src/proxy/Makefile.am @@ -136,6 +136,7 @@ EXTRA_DIST = \ templates/cgi-error-disabled \ templates/cgi-error-file \ templates/cgi-error-file-read-only \ + templates/cgi-error-forbidden \ templates/cgi-error-modified \ templates/cgi-error-parse \ templates/cgi-error-plugin \ From 0d145caba19eb570f209fe12cd58fa0a00b836bf Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 21 May 2015 18:13:39 +0200 Subject: [PATCH 14/18] Let also solve errors from udb_service in errlog::sp_err_to_string() Signed-off-by: Roland Haeder --- src/proxy/Makefile.am | 3 ++- src/proxy/errlog.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/proxy/Makefile.am b/src/proxy/Makefile.am index 1a1fb53f..f3da71c7 100644 --- a/src/proxy/Makefile.am +++ b/src/proxy/Makefile.am @@ -16,7 +16,8 @@ endif lib_LTLIBRARIES += libseeksproxy.la libseeksplugins.la libseeksproxy_la_CXXFLAGS=-Wall -Wno-deprecated -g -pipe \ - -I${srcdir} -I${srcdir}/../utils -I${srcdir}/../lsh + -I${srcdir} -I${srcdir}/../utils -I${srcdir}/../lsh \ + -I${srcdir}/../plugins/udb_service libseeksproxy_la_SOURCES=seeks_proxy.cpp proxy_dts.cpp errlog.cpp \ cgi.cpp encode.cpp spsockets.cpp filters.cpp gateway.cpp\ parsers.cpp pcrs.cpp cgisimple.cpp loaders.cpp \ diff --git a/src/proxy/errlog.cpp b/src/proxy/errlog.cpp index d1f6dedc..e8524406 100644 --- a/src/proxy/errlog.cpp +++ b/src/proxy/errlog.cpp @@ -64,6 +64,7 @@ #endif /* def _MSC_VER */ #include "errlog.h" +#include "udbs_err.h" //#include "seeks_proxy.h" namespace sp @@ -876,6 +877,12 @@ namespace sp return "File has been modified outside of the CGI actions editor."; case SP_ERR_COMPRESS: return "(De)compression failure"; + case UDBS_ERR_SERIALIZE: + return "msg serialization error."; + case UDBS_ERR_DESERIALIZE: + return "msg deserialization error."; + case UDBS_ERR_CONNECT: + return "peer connection error."; default: assert(0); return "Unknown error"; From 890fc00718116cf680942367a544887b9622ba36 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 21 May 2015 18:17:18 +0200 Subject: [PATCH 15/18] Also need to add include search path here. Signed-off-by: Roland Haeder --- src/cli/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index 6ae18849..a0e65893 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -5,7 +5,7 @@ seeksclidatadir = $(datadir)/seeks/cli AM_CXXFLAGS=-Wall -g -pipe AM_CPPFLAGS=-I${srcdir} -I${srcdir}/../proxy -I${srcdir}/../utils -I${srcdir}/../lsh \ - @CURL_CFLAGS@ + -I${srcdir}/../plugins/udb_service @CURL_CFLAGS@ seeksclilib_LIBRARIES=libseekscli.a libseekscli_a_SOURCES=cli.cpp ../proxy/encode.cpp ../utils/miscutil.cpp cli.h From 4314520cb0ac4af5f6797642527f13a291bc762f Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 22 May 2015 05:25:52 +0200 Subject: [PATCH 16/18] Use URL-encoding for binary data to safe-guard it + a lot (!) debug lines added. Signed-off-by: Roland Haeder --- resources/search.php | 35 ++++++++++-- src/plugins/httpserv/httpserv.cpp | 4 ++ src/plugins/udb_service/halo_msg_wrapper.cpp | 10 +++- src/plugins/udb_service/udb_client.cpp | 4 +- src/plugins/udb_service/udb_server.cpp | 11 +++- src/plugins/udb_service/udb_service.cpp | 14 ++++- src/plugins/websearch/query_context.cpp | 8 ++- src/proxy/cgi.cpp | 10 +++- src/proxy/curl_mget.cpp | 58 +++++++++++++++++++- src/proxy/parsers.cpp | 4 +- src/proxy/seeks_proxy.cpp | 11 ++++ 11 files changed, 154 insertions(+), 15 deletions(-) diff --git a/resources/search.php b/resources/search.php index cd4630b9..d10452d0 100644 --- a/resources/search.php +++ b/resources/search.php @@ -15,6 +15,20 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.fsf.org/licensing/licenses/agpl-3.0.html. */ +/***************************************************************************** + * Important change to php.ini: * + ***************************************************************************** + * You MUST set always_populate_raw_post_data=1 in your php.ini to get this * + * working!). E.g. I had to set this in FPM's seeks.conf: * + * php_admin_value[always_populate_raw_post_data] = 1 * + ***************************************************************************** + * My file is located at /etc/php5/fpm/pool.d/seeks.conf. * + ***************************************************************************** + */ + +// Let's fix all of them +error_reporting(E_ALL | E_STRICT); + // Default is HTTP $scheme = 'http://'; @@ -72,26 +86,36 @@ if (isset($bqc[0]) && $bqc[0] == 'find_bqc') { $postdata = file_get_contents('php://input'); + + // For debugging purposes + //* DEBUG: */ file_put_contents('/tmp/foo', ini_get('always_populate_raw_post_data') . ':' . $postdata); + curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); } curl_setopt($curl, CURLOPT_PROXY, $proxy); -curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1) ; +curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); -curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Seeks-Remote-Location: ' . $base_url, 'Accept-Language: ' . $lang_head, 'Referer: ' . $referer)); +curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Seeks-Remote-Location: ' . $base_url, 'Accept-Language: ' . $lang_head, 'Proxy-Connection: Close', 'Expect:', 'Referer: ' . $referer)); $result = curl_exec($curl); $result_info = curl_getinfo($curl); -syslog(LOG_INFO, 'result_info=' . json_encode($result_info)); +// Very noisy in syslog: +//* NOISY-DEBUG: */ syslog(LOG_INFO, 'result_info=' . json_encode($result_info)); -if(curl_errno($curl)) { +if (curl_errno($curl)) { echo 'CURL ERROR: '.curl_error($curl); } curl_close($curl); +if (headers_sent()) { + // Headers are already sent, cannot continue, maybe error? + exit(); +} + header('Content-Type: ' . $result_info['content_type']); if ((isset($qc_redir[0]) && $qc_redir[0] == 'qc_redir') || (isset($tbd[0]) && $tbd[0] == 'tbd')) { @@ -113,5 +137,8 @@ } } +// Very noisy in syslog: +//* NOISY-DEBUG: */ syslog(LOG_INFO, 'result=' . json_encode($result)); echo $result; + ?> diff --git a/src/plugins/httpserv/httpserv.cpp b/src/plugins/httpserv/httpserv.cpp index e837764c..9a93fb00 100644 --- a/src/plugins/httpserv/httpserv.cpp +++ b/src/plugins/httpserv/httpserv.cpp @@ -1110,6 +1110,8 @@ t.dtd\">408 - Seeks fail connection to background search engi void httpserv::find_bqc(struct evhttp_request *r, void *arg) { + errlog::log_error(LOG_LEVEL_DEBUG, "httpserv::find_bqc(): CALLED!"); + client_state csp; csp._config = seeks_proxy::_config; http_response *rsp = new http_response(); @@ -1171,6 +1173,7 @@ t.dtd\"><html><head><title>408 - Seeks fail connection to background search engi input_buffer->off / sizeof(u_char)); #endif + errlog::log_error(LOG_LEVEL_DEBUG, "httpserv::find_bqc(): post_content=%s,length()=%d", post_content.c_str(), post_content.length()); if (post_content.empty()) { httpserv::reply_with_error_400(r); //TODO: proper error type. @@ -1191,6 +1194,7 @@ t.dtd\"><html><head><title>408 - Seeks fail connection to background search engi miscutil::enlist_unique_header(&csp._headers,"host",host); // call to find_bqc callback. + errlog::log_error(LOG_LEVEL_DEBUG, "httpserv::find_bqc(): csp._iob._cur=%s", csp._iob._cur); sp_err serr = udb_service::cgi_find_bqc(&csp,rsp,parameters); miscutil::list_remove_all(&csp._headers); delete[] csp._iob._cur; diff --git a/src/plugins/udb_service/halo_msg_wrapper.cpp b/src/plugins/udb_service/halo_msg_wrapper.cpp index 2867def3..8901e587 100644 --- a/src/plugins/udb_service/halo_msg_wrapper.cpp +++ b/src/plugins/udb_service/halo_msg_wrapper.cpp @@ -29,6 +29,8 @@ namespace seeks_plugins uint32_t &expansion, std::vector<std::string> &hashes) throw (sp_exception) { + errlog::log_error(LOG_LEVEL_DEBUG, "halo_msg_wrapper::deserialize(): msg=%s,expansion=%d - CALLED!", msg.c_str(), expansion); + hash_halo h; if (!h.ParseFromString(msg)) { @@ -39,14 +41,19 @@ namespace seeks_plugins expansion = h.expansion(); for (int i=0; i<h.key_size(); i++) hashes.push_back(h.key(i)); + + errlog::log_error(LOG_LEVEL_DEBUG, "halo_msg_wrapper::deserialize(): msg=%s,expansion=%d - EXIT!", msg.c_str(), expansion); } void halo_msg_wrapper::serialize(const uint32_t &expansion, const hash_multimap<uint32_t,DHTKey,id_hash_uint> &qhashes, std::string &msg) throw (sp_exception) { + errlog::log_error(LOG_LEVEL_DEBUG, "halo_msg_wrapper::serialize(): msg=%s,expansion=%d - CALLED!", msg.c_str(), expansion); + hash_halo h; h.set_expansion(expansion); + errlog::log_error(LOG_LEVEL_DEBUG, "halo_msg_wrapper::serialize(): h.expansion()=%d", h.expansion()); hash_multimap<uint32_t,DHTKey,id_hash_uint>::const_iterator hit = qhashes.begin(); while(hit!=qhashes.end()) { @@ -60,6 +67,7 @@ namespace seeks_plugins errlog::log_error(LOG_LEVEL_ERROR,msg.c_str()); throw sp_exception(UDBS_ERR_SERIALIZE,msg); } - } + errlog::log_error(LOG_LEVEL_DEBUG, "halo_msg_wrapper::serialize(): msg=%s,expansion=%d - EXIT!", msg.c_str(), expansion); + } } /* end of namespace. */ diff --git a/src/plugins/udb_service/udb_client.cpp b/src/plugins/udb_service/udb_client.cpp index 5c6da63c..3c3b826e 100644 --- a/src/plugins/udb_service/udb_client.cpp +++ b/src/plugins/udb_service/udb_client.cpp @@ -118,6 +118,7 @@ namespace seeks_plugins std::string msg; try { + errlog::log_error(LOG_LEVEL_DEBUG, "udb_client::find_bqc(): Calling halo_msg_wrapper::serialize(%d,???,%s) ...", expansion, msg.c_str()); halo_msg_wrapper::serialize(expansion,qhashes,msg); } catch(sp_exception &e) @@ -135,7 +136,7 @@ namespace seeks_plugins std::vector<std::string> urls; urls.reserve(1); urls.push_back(url); - errlog::log_error(LOG_LEVEL_DEBUG,"call: %s",url.c_str()); + errlog::log_error(LOG_LEVEL_DEBUG, "udb_client::find_bqc(): url=%s,msg=%s,msg.length()=%d", url.c_str(), msg.c_str(), msg.length()); std::vector<int> status; if (udb_service_configuration::_config->_p2p_proxy_addr.empty()) cmg.www_mget(urls,1,NULL,"",0,status, @@ -145,6 +146,7 @@ namespace seeks_plugins udb_service_configuration::_config->_p2p_proxy_addr, udb_service_configuration::_config->_p2p_proxy_port, status,NULL,NULL,"POST",&msg,msg.length()*sizeof(char)); + errlog::log_error(LOG_LEVEL_DEBUG, "udb_client::find_bqc(): status[0]=%d", status[0]); if (status[0] !=0) { // failed connection. diff --git a/src/plugins/udb_service/udb_server.cpp b/src/plugins/udb_service/udb_server.cpp index 2cce3296..2722d75a 100644 --- a/src/plugins/udb_service/udb_server.cpp +++ b/src/plugins/udb_service/udb_server.cpp @@ -21,6 +21,7 @@ #include "db_query_record.h" #include "cf.h" #include "seeks_proxy.h" +#include "encode.h" #include "errlog.h" #include <string.h> @@ -67,6 +68,8 @@ namespace seeks_plugins uint32_t expansion = 0; std::vector<std::string> qhashes; + errlog::log_error(LOG_LEVEL_DEBUG, "udb_server::find_bqc_cb(): content=%s", content.c_str()); + try { halo_msg_wrapper::deserialize(content, @@ -94,12 +97,14 @@ namespace seeks_plugins dbr->print(std::cerr);*/ // fill up response. - size_t body_size = str.length() * sizeof(char); + std::string* encoded = new std::string(encode::url_encode(str.c_str())); + errlog::log_error(LOG_LEVEL_DEBUG, "udb_server::find_bqc_cb(): encoded=%s(%d)", encoded->c_str(), encoded->length()); + size_t body_size = encoded->length() * sizeof(char); if (!rsp->_body) rsp->_body = (char*)std::malloc(body_size); rsp->_content_length = body_size; - for (size_t i=0; i<str.length(); i++) - rsp->_body[i] = str[i]; + for (size_t i=0; i<encoded->length(); i++) + rsp->_body[i] = encoded->at(i); delete dbr; return SP_ERR_OK; } diff --git a/src/plugins/udb_service/udb_service.cpp b/src/plugins/udb_service/udb_service.cpp index 47609860..9670e71f 100644 --- a/src/plugins/udb_service/udb_service.cpp +++ b/src/plugins/udb_service/udb_service.cpp @@ -21,7 +21,9 @@ #include "udb_client.h" #include "udb_service_configuration.h" #include "seeks_proxy.h" +#include "encode.h" #include "miscutil.h" +#include "errlog.h" #include <string.h> #include <sys/stat.h> @@ -97,11 +99,21 @@ namespace seeks_plugins http_response *rsp, const hash_map<const char*,const char*,hash<const char*>,eqstr> *parameters) { + errlog::log_error(LOG_LEVEL_DEBUG, "udb_service::cgi_find_bqc(): CALLED!"); if (!seeks_proxy::_user_db) { return SP_ERR_FILE; // no user db. } - std::string content = std::string(csp->_iob._cur);//,csp->_iob._size); // XXX: beware... + errlog::log_error(LOG_LEVEL_DEBUG, "udb_service::cgi_find_bqc(): Calling udb_server::find_bqc_cb(): _buf=%s", csp->_iob._buf); + char *decoded = encode::url_decode(csp->_iob._cur); + if (!decoded) + { + // Decoding didn't work + errlog::log_error(LOG_LEVEL_ERROR, "udb_service::cgi_find_bqc(): Decoding didn't work."); + return SP_ERR_CGI_PARAMS; + } + std::string content = std::string(decoded);//,csp->_iob._size); // XXX: beware... + errlog::log_error(LOG_LEVEL_DEBUG, "udb_service::cgi_find_bqc(): Calling udb_server::find_bqc_cb(): content=%s,length()=%d,_size=%d,%E", content.c_str(), content.length(), csp->_iob._size, sizeof(csp->_iob)); return udb_server::find_bqc_cb(content,rsp); } diff --git a/src/plugins/websearch/query_context.cpp b/src/plugins/websearch/query_context.cpp index 2098c29e..ea89a0a7 100644 --- a/src/plugins/websearch/query_context.cpp +++ b/src/plugins/websearch/query_context.cpp @@ -590,6 +590,8 @@ namespace seeks_plugins std::string query_context::detect_base_url_http(client_state *csp) { + errlog::log_error(LOG_LEVEL_DEBUG, "query_context::detect_base_url_http(): CALLED!"); + std::list<const char*> headers = csp->_headers; // first we try to get base_url from a custom header @@ -597,13 +599,14 @@ namespace seeks_plugins std::list<const char*>::const_iterator sit = headers.begin(); while (sit!=headers.end()) { - if (miscutil::strncmpic((*sit),"X-Seeks-Remote-Location:",22) == 0) + if (miscutil::strncmpic((*sit),"X-Seeks-Remote-Location:",24) == 0) { base_url = (*sit); size_t pos = base_url.find_first_of(" "); try { base_url = base_url.substr(pos+1); + errlog::log_error(LOG_LEVEL_DEBUG, "query_context::detect_base_url_http(): base_url=%s found in headers", base_url.c_str()); } catch (std::exception &e) { @@ -638,7 +641,10 @@ namespace seeks_plugins ++sit; } base_url = csp->_http._ssl ? "https://" : "http://" + base_url; + errlog::log_error(LOG_LEVEL_DEBUG, "query_context::detect_base_url_http(): base_url=%s with no custom header", base_url.c_str()); } + + errlog::log_error(LOG_LEVEL_DEBUG, "query_context::detect_base_url_http(): base_url=%s - EXIT!", base_url.c_str()); return base_url; } diff --git a/src/proxy/cgi.cpp b/src/proxy/cgi.cpp index e37d0f5b..087a5ec9 100644 --- a/src/proxy/cgi.cpp +++ b/src/proxy/cgi.cpp @@ -234,6 +234,8 @@ namespace sp *********************************************************************/ http_response* cgi::dispatch_cgi(client_state *csp) { + errlog::log_error(LOG_LEVEL_DEBUG, "cgi::dispatch_cgi(): CALLED!"); + const char *host = csp->_http._host; const char *path = csp->_http._path; @@ -276,6 +278,7 @@ namespace sp /* * This is a CGI call. */ + errlog::log_error(LOG_LEVEL_DEBUG, "cgi::dispatch_cgi(): Calling cgi::dispatch_known_cgi() with path %s", path); return cgi::dispatch_known_cgi(csp, path); } @@ -494,6 +497,7 @@ namespace sp if ((strcmp(path_copy, d->_name) == 0)) { + errlog::log_error(LOG_LEVEL_DEBUG, "cgi::dispatch_known_cgi(): Calling generic cgi::dispatch() for %s ...", d->_name); return cgi::dispatch(d, path_copy, csp, param_list, rsp); } @@ -506,6 +510,8 @@ namespace sp d = plugin_manager::find_plugin_cgi_dispatcher(path_copy); if (d) { + errlog::log_error(LOG_LEVEL_DEBUG, "cgi::dispatch_known_cgi(): csp->_iob._cur=%s,_buf=%s", csp->_iob._cur, csp->_iob._buf); + errlog::log_error(LOG_LEVEL_DEBUG, "cgi::dispatch_known_cgi(): Calling cgi::dispatch() for %s ...", d->_name); return cgi::dispatch(d, path_copy, csp, param_list, rsp); } @@ -534,7 +540,9 @@ namespace sp */ if (d->_harmless || cgi::referrer_is_safe(csp)) { + errlog::log_error(LOG_LEVEL_DEBUG, "cgi::dispatch(): Calling handler for %s ...", d->_name); err = (d->_handler)(csp, rsp, param_list); + errlog::log_error(LOG_LEVEL_DEBUG, "cgi::dispatch(): Handler returned err=%d", err); } else { @@ -1257,7 +1265,7 @@ namespace sp } if (output == "json") { - rsp->_status = strdup("500"); + rsp->_status = strdup("500 Internal Server Error"); rsp->_body = strdup("{\"error\":\"internal plugin error\"}"); rsp->_content_length = strlen(rsp->_body); return SP_ERR_OK; diff --git a/src/proxy/curl_mget.cpp b/src/proxy/curl_mget.cpp index 4bf999be..16962666 100644 --- a/src/proxy/curl_mget.cpp +++ b/src/proxy/curl_mget.cpp @@ -72,9 +72,12 @@ namespace sp cbget *arg = static_cast<cbget*>(arg_cbget); CURL *curl = NULL; + char* encoded = NULL; + char* decoded = NULL; if (!arg->_handler) { + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): Setting default (curl_easy_init()) CURL handler for %s", arg->_url); curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_MAXREDIRS,5); @@ -102,10 +105,25 @@ namespace sp { if (arg->_content) { + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): Enabling POST request ..."); curl_easy_setopt(curl, CURLOPT_POST, 1); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (void*)arg->_content->c_str()); + encoded = curl_easy_escape(curl, arg->_content->c_str(), 0); + if (!encoded) + { + errlog::log_error(LOG_LEVEL_ERROR, "pull_one_url(): @TODO curl_easy_escape() failed"); + } + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): Before: %s(%d)", arg->_content->c_str(), arg->_content->length()); + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): After: %s(%d)", encoded, strlen(encoded)); + // Fix encoded length to URL-encoded + arg->_content_size = strlen(encoded); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, encoded); + // OLD: curl_easy_setopt(curl, CURLOPT_POSTFIELDS, (void*)arg->_content->c_str()); + if (arg->_content_size >= 0) - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, arg->_content_size); + { + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): Setting CURLOPT_POSTFIELDSIZE=%d", arg->_content_size); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, arg->_content_size); + } /*std::cerr << "curl_mget POST size: " << arg->_content_size << std::endl << "content: " << *arg->_content << std::endl;*/ } @@ -119,6 +137,7 @@ namespace sp struct curl_slist *slist=NULL; // useful headers. + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): Checking arg->_headers=%s ...", arg->_headers); if (arg->_headers) { std::list<const char*>::const_iterator sit = arg->_headers->begin(); @@ -127,12 +146,16 @@ namespace sp slist = curl_slist_append(slist,(*sit)); ++sit; } + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): Checking arg->_content=%s", arg->_content); if (arg->_content) { + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): Adding content-type=%s and Expect: header", arg->_content_type.c_str()); slist = curl_slist_append(slist,strdup(arg->_content_type.c_str())); slist = curl_slist_append(slist,strdup("Expect:")); } } + + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); char errorbuffer[CURL_ERROR_SIZE]; @@ -152,6 +175,21 @@ namespace sp arg->_output = NULL; } } + else + { + // "Transparent" URL decoding + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): Before: %s(%d)", arg->_output->c_str(), arg->_output->length()); + decoded = curl_easy_unescape(curl, arg->_output->c_str(), 0, NULL); + if (!decoded) + { + errlog::log_error(LOG_LEVEL_ERROR, "pull_one_url(): URL decoding failed."); + delete arg->_output; + arg->_status = 500; + arg->_output = NULL; + } + errlog::log_error(LOG_LEVEL_DEBUG, "pull_one_url(): After: %s(%d)", decoded, strlen(decoded)); + arg->_output = new std::string(decoded); + } } catch (std::exception &e) { @@ -173,6 +211,12 @@ namespace sp } } + // Free memory + curl_free(decoded); + + // Free memory + curl_free(encoded); + if (!arg->_handler) curl_easy_cleanup(curl); @@ -217,8 +261,14 @@ namespace sp arg_cbget->_http_method = http_method; if (content) { + errlog::log_error(LOG_LEVEL_DEBUG, "curl_mget::www_mget(): Setting content of length %d bytes", content_size); arg_cbget->_content = content; arg_cbget->_content_size = content_size; + if (content_type.length() > 0) + { + errlog::log_error(LOG_LEVEL_DEBUG, "curl_mget::www_mget(): Setting content type %s", content_type.c_str()); + arg_cbget->_content_type = content_type; + } } _cbgets[i] = arg_cbget; @@ -235,11 +285,15 @@ namespace sp for (int i=0; i<nrequests; i++) { int error = pthread_join(tid[i], NULL); + + if (error != 0) + errlog::log_error(LOG_LEVEL_ERROR,"Couldn't join thread number %g",i,", errno %g",error); } for (int i=0; i<nrequests; i++) { _outputs[i] = _cbgets[i]->_output; + errlog::log_error(LOG_LEVEL_DEBUG, "curl_mget::www_mget(): i=%d,_output=%s", i, _outputs[i]->c_str()); status.push_back(_cbgets[i]->_status); delete _cbgets[i]; } diff --git a/src/proxy/parsers.cpp b/src/proxy/parsers.cpp index 05545f31..9e6e8e58 100644 --- a/src/proxy/parsers.cpp +++ b/src/proxy/parsers.cpp @@ -228,6 +228,7 @@ namespace sp *********************************************************************/ sp_err parsers::add_to_iob(client_state *csp, char *buf, long n) { + errlog::log_error(LOG_LEVEL_DEBUG, "parsers::add_to_iob(): buf=%s, n=%d - CALLED!", buf, n); iob *iob = &csp->_iob; size_t used, offset, need, want; char *p; @@ -610,6 +611,7 @@ namespace sp csp->_iob._buf = NULL; /* Now, update the iob to use the new buffer. */ + errlog::log_error(LOG_LEVEL_DEBUG, "parsers::decompress_iob(): Reached!"); csp->_iob._buf = buf; csp->_iob._cur = csp->_iob._buf + skip_size; csp->_iob._eod = (char *)zstr.next_out; @@ -3543,7 +3545,7 @@ namespace sp *********************************************************************/ sp_err parsers::server_proxy_connection_adder(client_state *csp) { - static const char proxy_connection_header[] = "Proxy-Connection: keep-alive"; + static const char proxy_connection_header[] = "Proxy-Connection: Keep-Alive"; sp_err err = SP_ERR_OK; if ((csp->_flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE) diff --git a/src/proxy/seeks_proxy.cpp b/src/proxy/seeks_proxy.cpp index 4dda0978..76996dfd 100644 --- a/src/proxy/seeks_proxy.cpp +++ b/src/proxy/seeks_proxy.cpp @@ -966,6 +966,7 @@ namespace sp * If there is no memory left for buffering the * request, there is nothing we can do but hang up */ + errlog::log_error(LOG_LEVEL_DEBUG, "seeks_proxy::get_request_line(): Calling parsers::add_to_iob(???,%s,%d) ...", buf, len); if (parsers::add_to_iob(csp, buf, len)) { return NULL; @@ -1066,6 +1067,8 @@ namespace sp errlog::log_error(LOG_LEVEL_ERROR, "read from client failed: %E"); return SP_ERR_PARSE; } + + errlog::log_error(LOG_LEVEL_DEBUG, "seeks_proxy::receive_client_request(): Calling parsers::add_to_iob(???,%s,%d) ...", buf, len); if (parsers::add_to_iob(csp, buf, len)) { /* @@ -1348,6 +1351,8 @@ namespace sp * */ + errlog::log_error(LOG_LEVEL_DEBUG, "seeks_proxy::chat(): _cur=%s,_eod=%s,%E", csp->_iob._cur, csp->_iob._eod, sizeof(csp->_iob)); + if (http->_ssl == 0) { free_const((*csp->_headers.begin())); // beware !!! @@ -1812,6 +1817,7 @@ namespace sp * has been reached, switch to non-filtering mode, i.e. make & write the * header, flush the iob and buf, and get out of the way. */ + errlog::log_error(LOG_LEVEL_DEBUG, "seeks_proxy::chat(): Calling parsers::add_to_iob(???,%s,%d) ...", buf, len); if (parsers::add_to_iob(csp, buf, len)) { size_t hdrlen; @@ -1878,6 +1884,7 @@ namespace sp * Buffer up the data we just read. If that fails, there's * little we can do but send our static out-of-memory page. */ + errlog::log_error(LOG_LEVEL_DEBUG, "seeks_proxy::chat(): Calling parsers::add_to_iob(???,%s,%d) ... #2", buf, len); if (parsers::add_to_iob(csp, buf, len)) { errlog::log_error(LOG_LEVEL_ERROR, "Out of memory while looking for end of server headers."); @@ -2135,6 +2142,7 @@ namespace sp do { + errlog::log_error(LOG_LEVEL_DEBUG, "seeks_proxy::serve(): Calling seeks_proxy::chat(csp) for defined FEATURE_CONNECTION_KEEP_ALIVE ..."); seeks_proxy::chat(csp); if ((csp->_flags & CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE) @@ -2226,6 +2234,7 @@ namespace sp gateway::mark_connection_closed(&csp->_server_connection); #else + errlog::log_error(LOG_LEVEL_DEBUG, "seeks_proxy::serve(): Calling seeks_proxy::chat(csp) for undefined FEATURE_CONNECTION_KEEP_ALIVE."); seeks_proxy::chat(csp); #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ @@ -2578,6 +2587,7 @@ namespace sp #ifdef FEATURE_TOGGLE int inherited_toggle_state = seeks_proxy::_global_toggle_state; # endif /* def FEATURE_TOGGLE */ + errlog::log_error(LOG_LEVEL_DEBUG, "seeks_proxy::listen_loop(): Calling seeks_proxy::serve(csp) ..."); seeks_proxy::serve(csp); /* @@ -2655,6 +2665,7 @@ namespace sp } else { + errlog::log_error(LOG_LEVEL_DEBUG, "seeks_proxy::listen_loop(): Calling seeks_proxy::serve(csp) in else block"); seeks_proxy::serve(csp); } } From bc8cb1ffa74a7cf9f9d4a43a4a5db610f2da72d3 Mon Sep 17 00:00:00 2001 From: Roland Haeder <roland@mxchange.org> Date: Fri, 22 May 2015 05:53:22 +0200 Subject: [PATCH 17/18] Some cosmetics applied Signed-off-by: Roland Haeder <roland@mxchange.org> --- .../websearch_api_compat.cpp | 99 ++++++++++--------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/src/plugins/websearch_api_compat/websearch_api_compat.cpp b/src/plugins/websearch_api_compat/websearch_api_compat.cpp index e8ff85b1..9f29511c 100644 --- a/src/plugins/websearch_api_compat/websearch_api_compat.cpp +++ b/src/plugins/websearch_api_compat/websearch_api_compat.cpp @@ -80,10 +80,11 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) { - errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: Parameter 'q' is not set or empty."); - return SP_ERR_CGI_PARAMS; - } + if (!query_str || strlen(query_str) == 0) + { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: Parameter 'q' is not set or empty."); + return SP_ERR_CGI_PARAMS; + } // cgi decodes the parameters, need to re-encode before passing it to websearch plugin. char *enc_query = encode::url_encode(query_str); @@ -147,10 +148,11 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) { - errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'q' is not set or empty."); - return SP_ERR_CGI_PARAMS; - } + if (!query_str || strlen(query_str) == 0) + { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'q' is not set or empty."); + return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -158,10 +160,11 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); - if (!url_str) { - errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'url' is not set or empty."); - return SP_ERR_CGI_PARAMS; - } + if (!url_str) + { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'url' is not set or empty."); + return SP_ERR_CGI_PARAMS; + } std::string url = url_str; std::transform(url.begin(),url.end(),url.begin(),tolower); std::string surl = urlmatch::strip_url(url); @@ -190,10 +193,11 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) { - errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'q' is not set or empty."); - return SP_ERR_CGI_PARAMS; - } + if (!query_str || strlen(query_str) == 0) + { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'q' is not set or empty."); + return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -205,10 +209,11 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); - if (!url_str) { - errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'url' is not set or empty."); - return SP_ERR_CGI_PARAMS; - } + if (!url_str) + { + errlog::log_error(LOG_LEVEL_ERROR, "Error SP_ERR_CGI_PARAMS: 'url' is not set or empty."); + return SP_ERR_CGI_PARAMS; + } std::string url = url_str; std::transform(url.begin(),url.end(),url.begin(),tolower); std::string surl = urlmatch::strip_url(url); @@ -239,10 +244,11 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) { - errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'q' not given."); - return SP_ERR_CGI_PARAMS; - } + if (!query_str || strlen(query_str) == 0) + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'q' not given."); + return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -250,10 +256,11 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); - if (!url_str) { - errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'url' not given."); - return SP_ERR_CGI_PARAMS; - } + if (!url_str) + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'url' not given."); + return SP_ERR_CGI_PARAMS; + } std::string url = url_str; std::transform(url.begin(),url.end(),url.begin(),tolower); std::string surl = urlmatch::strip_url(url); @@ -268,10 +275,11 @@ namespace seeks_plugins free(csp->_http._gpc); csp->_http._gpc = strdup("delete"); sp_err err = websearch::cgi_websearch_search(csp,rsp,parameters); - if (err != SP_ERR_OK) { - errlog::log_error(LOG_LEVEL_ERROR, "Returning err=%s", err); - return err; - } + if (err != SP_ERR_OK) + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning err=%s", err); + return err; + } miscutil::unmap(const_cast<hash_map<const char*,const char*,hash<const char*>,eqstr>*>(parameters),"q"); miscutil::unmap(const_cast<hash_map<const char*,const char*,hash<const char*>,eqstr>*>(parameters),"url"); miscutil::unmap(const_cast<hash_map<const char*,const char*,hash<const char*>,eqstr>*>(parameters),"action"); @@ -302,10 +310,11 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) { - errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'q' not given."); - return SP_ERR_CGI_PARAMS; - } + if (!query_str || strlen(query_str) == 0) + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'q' not given."); + return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -353,10 +362,11 @@ namespace seeks_plugins { // check for query. const char *query_str = miscutil::lookup(parameters,"q"); - if (!query_str || strlen(query_str) == 0) { - errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'q' not given."); - return SP_ERR_CGI_PARAMS; - } + if (!query_str || strlen(query_str) == 0) + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'q' not given."); + return SP_ERR_CGI_PARAMS; + } char *enc_query = encode::url_encode(query_str); std::string query = enc_query; free(enc_query); @@ -368,10 +378,11 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); - if (!url_str) { - errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'url' not given."); - return SP_ERR_CGI_PARAMS; - } + if (!url_str) + { + errlog::log_error(LOG_LEVEL_ERROR, "Returning SP_ERR_CGI_PARAMS: Parameter 'url' not given."); + return SP_ERR_CGI_PARAMS; + } std::string url = url_str; std::transform(url.begin(),url.end(),url.begin(),tolower); std::string surl = urlmatch::strip_url(url); From 153127ac4097653eae17129da2851c8a5d86257c Mon Sep 17 00:00:00 2001 From: Roland Haeder <roland@mxchange.org> Date: Sat, 23 May 2015 20:14:14 +0200 Subject: [PATCH 18/18] "X-" has been deprecated: http://tools.ietf.org/html/rfc6648 Signed-off-by: Roland Haeder <roland@mxchange.org> --- resources/search.php | 2 +- src/plugins/query_capture/query_capture.cpp | 2 +- src/plugins/websearch/query_context.cpp | 2 +- src/plugins/websearch/static_renderer.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/search.php b/resources/search.php index d10452d0..c368b2b1 100644 --- a/resources/search.php +++ b/resources/search.php @@ -97,7 +97,7 @@ curl_setopt($curl, CURLOPT_PROXY, $proxy); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); -curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-Seeks-Remote-Location: ' . $base_url, 'Accept-Language: ' . $lang_head, 'Proxy-Connection: Close', 'Expect:', 'Referer: ' . $referer)); +curl_setopt($curl, CURLOPT_HTTPHEADER, array('Seeks-Remote-Location: ' . $base_url, 'Accept-Language: ' . $lang_head, 'Proxy-Connection: Close', 'Expect:', 'Referer: ' . $referer)); $result = curl_exec($curl); $result_info = curl_getinfo($curl); diff --git a/src/plugins/query_capture/query_capture.cpp b/src/plugins/query_capture/query_capture.cpp index 856be7b1..59f72a1a 100644 --- a/src/plugins/query_capture/query_capture.cpp +++ b/src/plugins/query_capture/query_capture.cpp @@ -650,7 +650,7 @@ namespace seeks_plugins referer = ""; } } - else if (miscutil::strncmpic((*lit),"X-Seeks-Remote-Location:",22) == 0) + else if (miscutil::strncmpic((*lit),"-Seeks-Remote-Location:",22) == 0) { base_url = (*lit); try diff --git a/src/plugins/websearch/query_context.cpp b/src/plugins/websearch/query_context.cpp index ea89a0a7..9724a8aa 100644 --- a/src/plugins/websearch/query_context.cpp +++ b/src/plugins/websearch/query_context.cpp @@ -599,7 +599,7 @@ namespace seeks_plugins std::list<const char*>::const_iterator sit = headers.begin(); while (sit!=headers.end()) { - if (miscutil::strncmpic((*sit),"X-Seeks-Remote-Location:",24) == 0) + if (miscutil::strncmpic((*sit),"Seeks-Remote-Location:",22) == 0) { base_url = (*sit); size_t pos = base_url.find_first_of(" "); diff --git a/src/plugins/websearch/static_renderer.cpp b/src/plugins/websearch/static_renderer.cpp index df508f44..b26165b6 100644 --- a/src/plugins/websearch/static_renderer.cpp +++ b/src/plugins/websearch/static_renderer.cpp @@ -677,7 +677,7 @@ namespace seeks_plugins = cgi::default_exports(csp,""); // we need to inject a remote base location for remote web access. - // the injected header, if it exists is X-Seeks-Remote-Location + // the injected header, if it exists is Seeks-Remote-Location std::string base_url = query_context::detect_base_url_http(csp); miscutil::add_map_entry(exports,"base-url",1,base_url.c_str(),1);