diff --git a/resources/search.php b/resources/search.php index ca703e24..c368b2b1 100644 --- a/resources/search.php +++ b/resources/search.php @@ -1,4 +1,4 @@ - 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 diff --git a/src/plugins/cf/tests/ut-cf-sre.cpp b/src/plugins/cf/tests/ut-cf-sre.cpp index 1381cc06..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://www.seeks.fr/",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; 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/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 */ } diff --git a/src/plugins/query_capture/query_capture.cpp b/src/plugins/query_capture/query_capture.cpp index 0c0b6cad..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),"Seeks-Remote-Location:",22) == 0) + else if (miscutil::strncmpic((*lit),"-Seeks-Remote-Location:",22) == 0) { base_url = (*lit); try 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 4542d3ae..9724a8aa 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 @@ -604,6 +606,7 @@ namespace seeks_plugins 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/plugins/websearch_api_compat/websearch_api_compat.cpp b/src/plugins/websearch_api_compat/websearch_api_compat.cpp index 2fc8b4f6..9f29511c 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" @@ -80,7 +81,11 @@ namespace seeks_plugins // check for query. const char *query_str = miscutil::lookup(parameters,"q"); if (!query_str || strlen(query_str) == 0) - return SP_ERR_CGI_PARAMS; + { + 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 +127,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, @@ -136,7 +149,10 @@ namespace seeks_plugins // check for query. const char *query_str = miscutil::lookup(parameters,"q"); if (!query_str || strlen(query_str) == 0) - return SP_ERR_CGI_PARAMS; + { + 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); @@ -145,7 +161,10 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); if (!url_str) - return SP_ERR_CGI_PARAMS; + { + 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 +178,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, @@ -171,7 +194,10 @@ namespace seeks_plugins // check for query. const char *query_str = miscutil::lookup(parameters,"q"); if (!query_str || strlen(query_str) == 0) - return SP_ERR_CGI_PARAMS; + { + 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); @@ -184,7 +210,10 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); if (!url_str) - return SP_ERR_CGI_PARAMS; + { + 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 +229,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, @@ -212,7 +245,10 @@ namespace seeks_plugins // check for query. const char *query_str = miscutil::lookup(parameters,"q"); if (!query_str || strlen(query_str) == 0) - return SP_ERR_CGI_PARAMS; + { + 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); @@ -221,7 +257,10 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); if (!url_str) - return SP_ERR_CGI_PARAMS; + { + 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); @@ -237,7 +276,10 @@ namespace seeks_plugins csp->_http._gpc = strdup("delete"); sp_err err = websearch::cgi_websearch_search(csp,rsp,parameters); if (err != SP_ERR_OK) - return err; + { + 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"); @@ -252,7 +294,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 @@ -265,7 +311,10 @@ namespace seeks_plugins // check for query. const char *query_str = miscutil::lookup(parameters,"q"); if (!query_str || strlen(query_str) == 0) - return SP_ERR_CGI_PARAMS; + { + 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 +341,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, @@ -306,7 +363,10 @@ namespace seeks_plugins // check for query. const char *query_str = miscutil::lookup(parameters,"q"); if (!query_str || strlen(query_str) == 0) - return SP_ERR_CGI_PARAMS; + { + 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); @@ -319,7 +379,10 @@ namespace seeks_plugins // check for url. const char *url_str = miscutil::lookup(parameters,"url"); if (!url_str) - return SP_ERR_CGI_PARAMS; + { + 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 +398,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/Makefile.am b/src/proxy/Makefile.am index d47fdab1..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 \ @@ -136,6 +137,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 \ diff --git a/src/proxy/cgi.cpp b/src/proxy/cgi.cpp index 6f425a36..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 { @@ -584,8 +592,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); } } @@ -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; @@ -2287,7 +2295,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/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/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"; 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/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/" 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); } } 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 <name> +# is not given. Simply enclose the block between the two +# strings @if-<name>start and if-<name>-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 <li> 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. +# +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> + +<head> + <title>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 + +
+ + +