From 118ea61dc79bf9b1c45bbf81b31361a749e32fdd Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 11 Aug 2021 03:06:47 -0400 Subject: spine search and configuration related --- sundry/spine_search_cgi/src/spine_search.d | 47 +++++++++++++++------------- sundry/spine_search_cgi/src/spine_search.d_ | 48 ++++++++++++++++------------- 2 files changed, 51 insertions(+), 44 deletions(-) (limited to 'sundry/spine_search_cgi/src') diff --git a/sundry/spine_search_cgi/src/spine_search.d b/sundry/spine_search_cgi/src/spine_search.d index 2ddc11b..a2d290a 100644 --- a/sundry/spine_search_cgi/src/spine_search.d +++ b/sundry/spine_search_cgi/src/spine_search.d @@ -71,26 +71,26 @@ void cgi_function_intro(Cgi cgi) { string web_doc_root_path; string doc_collection_sub_root; string cgi_root; - string cgi_script; + string cgi_script_name; string data_path_html; - string db_path; - string query_string; string http_url; + string query_base_url; + string query_string; string request_method; - string query_base; + string db_path; } auto conf = Config(); conf.http_request_type = environment.get("REQUEST_SCHEME", _cfg.http_request_type); - conf.http_host = environment.get("HTTP_HOST", _cfg.http_host); - conf.web_doc_root_path = environment.get("DOCUMENT_ROOT", _cfg.doc_root_www); + conf.http_host = environment.get("SERVER_NAME", _cfg.http_host); + conf.web_doc_root_path = environment.get("DOCUMENT_ROOT", _cfg.www_doc_root); conf.doc_collection_sub_root = "/spine/static"; // (output_path - web_doc_root_path) - conf.cgi_root = environment.get("CONTEXT_DOCUMENT_ROOT", _cfg.host_cgi_subpath); - conf.cgi_script = environment.get("SCRIPT_NAME", _cfg.filename_cgi); + conf.cgi_root = environment.get("CONTEXT_DOCUMENT_ROOT", _cfg.cgi_bin_subpath); + conf.cgi_script_name = environment.get("SCRIPT_NAME", _cfg.cgi_filename); + conf.query_base_url = conf.http_request_type ~ "://" ~ conf.http_host ~ "/" ~ conf.cgi_script_name ~ "?"; conf.query_string = environment.get("QUERY_STRING", ""); - conf.db_path = _cfg.doc_root_db; + conf.http_url = environment.get("HTTP_REFERER", conf.query_base_url ~ conf.query_string); conf.request_method = environment.get("REQUEST_METHOD", "POST"); - conf.query_base = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?"; - conf.http_url = environment.get("HTTP_REFERER", conf.query_base ~ conf.query_string); + conf.db_path = _cfg.db_sqlite_path; struct CGI_val { string db_selected = ""; string sql_match_limit = ""; // radio: ( 1000 | 2500 ) @@ -105,7 +105,7 @@ void cgi_function_intro(Cgi cgi) { bool checked_sql = false; } auto cv = CGI_val(); - cv.db_selected = _cfg.filename_db; + cv.db_selected = _cfg.db_sqlite_filename; auto text_fields() { string canned_query_str = environment.get("QUERY_STRING", ""); if ("query_string" in cgi.post) { @@ -444,9 +444,9 @@ void cgi_function_intro(Cgi cgi) { string canned_url () { string _url = ""; if (environment.get("REQUEST_METHOD", "POST") == "POST") { - _url = conf.query_base ~ tf.canned_query; + _url = conf.query_base_url ~ tf.canned_query; } else if (environment.get("REQUEST_METHOD", "POST") == "GET") { - _url = conf.query_base ~ environment.get("QUERY_STRING", ""); + _url = conf.query_base_url ~ environment.get("QUERY_STRING", ""); } return _url; } @@ -516,7 +516,7 @@ void cgi_function_intro(Cgi cgi) { _set_offset_previous = m.captures["offset_key"] ~ ((m.captures["offset_val"]).to!int - cv.sql_match_limit.to!int).to!string; _url_previous = _url.replace(rgx.track_offset, _set_offset_previous); } - } else {// _current_offset_value = 0; + } else { // _current_offset_value = 0; _url_next = _url ~= "&smo=" ~ cv.sql_match_limit.to!string; } if (_url_previous.empty) { @@ -1412,9 +1412,9 @@ void cgi_function_intro(Cgi cgi) { string _the_can = ""; if (show_the_can == "checked") { tf = text_fields; - string method_get_url = conf.query_base ~ environment.get("QUERY_STRING", ""); - string method_post_url_construct = conf.query_base ~ tf.canned_query; - // assert(method_get_url == environment.get("HTTP_REFERER", conf.query_base ~ conf.query_string)); + string method_get_url = conf.query_base_url ~ environment.get("QUERY_STRING", ""); + string method_post_url_construct = conf.query_base_url ~ tf.canned_query; + // assert(method_get_url == environment.get("HTTP_REFERER", conf.query_base_url ~ conf.query_string)); if (conf.request_method == "POST") { _the_can = "" @@ -1435,7 +1435,7 @@ void cgi_function_intro(Cgi cgi) { ~ method_get_url ~ ""; } - conf.http_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ tf.canned_query; + conf.http_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script_name ~ tf.canned_query; } return _the_can; } @@ -1501,7 +1501,7 @@ void cgi_function_intro(Cgi cgi) { ┃", - _cfg.filename_cgi, + _cfg.cgi_filename, (post_value("ec") == "checked") ? post_value("sf", "field") : "", provide_tip, search_note, @@ -1537,7 +1537,7 @@ void cgi_function_intro(Cgi cgi) { } else { val = false; } return val; } - cv.db_selected = set_value("selected_db", _cfg.filename_db); // selected_db_name == db (spine.search.db or whatever) + cv.db_selected = set_value("selected_db", _cfg.db_sqlite_filename); // selected_db_name == db (spine.search.db or whatever) cv.sql_match_limit = set_value("sml", "1000"); cv.sql_match_offset = set_value("smo", "0"); cv.search_text = set_value("sf", ""); @@ -1562,6 +1562,9 @@ void cgi_function_intro(Cgi cgi) { // } } { // debug cgi info: + // cgi.write("db with path: " ~ conf.db_path ~ "/" ~ cv.db_selected ~ "
\n"); + // cgi.write("http url: " ~ conf.http_url ~ "
\n"); + // cgi.write("query base url: " ~ conf.query_base_url ~ "
\n"); // cgi.write("db_selected: " ~ cv.db_selected ~ "
\n"); // cgi.write("search_text: " ~ cv.search_text ~ "
\n"); // cgi.write("sql_match_limit: " ~ cv.sql_match_limit ~ ";\n"); @@ -1575,7 +1578,7 @@ void cgi_function_intro(Cgi cgi) { // cgi.write("cv.checked_sql: " ~ (cv.checked_sql ? "checked" : "off") ~ "
\n"); } } - auto db = Database(conf.db_path ~ cv.db_selected); + auto db = Database(conf.db_path ~ "/" ~ cv.db_selected); { uint sql_match_offset_counter(T)(T cv) { sql_match_offset_count += cv.sql_match_limit.to!uint; diff --git a/sundry/spine_search_cgi/src/spine_search.d_ b/sundry/spine_search_cgi/src/spine_search.d_ index 5907b73..fca2b2b 100755 --- a/sundry/spine_search_cgi/src/spine_search.d_ +++ b/sundry/spine_search_cgi/src/spine_search.d_ @@ -72,26 +72,27 @@ void cgi_function_intro(Cgi cgi) { string web_doc_root_path; string doc_collection_sub_root; string cgi_root; - string cgi_script; + string cgi_script_name; string data_path_html; - string db_path; - string query_string; string http_url; + string query_base_url; + string query_string; string request_method; - string query_base; + string db_path; } auto conf = Config(); conf.http_request_type = environment.get("REQUEST_SCHEME", _cfg.http_request_type); - conf.http_host = environment.get("HTTP_HOST", _cfg.http_host); - conf.web_doc_root_path = environment.get("DOCUMENT_ROOT", _cfg.doc_root_www); + conf.http_host = environment.get("SERVER_NAME", _cfg.http_host); + // conf.http_host = environment.get("HTTP_HOST", _cfg.http_host); + conf.web_doc_root_path = environment.get("DOCUMENT_ROOT", _cfg.www_doc_root); conf.doc_collection_sub_root = "/spine/static"; // (output_path - web_doc_root_path) - conf.cgi_root = environment.get("CONTEXT_DOCUMENT_ROOT", _cfg.host_cgi_subpath); - conf.cgi_script = environment.get("SCRIPT_NAME", _cfg.filename_cgi); + conf.cgi_root = environment.get("CONTEXT_DOCUMENT_ROOT", _cfg.cgi_bin_subpath); + conf.cgi_script_name = environment.get("SCRIPT_NAME", _cfg.cgi_filename); + conf.query_base_url = conf.http_request_type ~ "://" ~ conf.http_host ~ "/" ~ conf.cgi_script_name ~ "?"; conf.query_string = environment.get("QUERY_STRING", ""); - conf.db_path = _cfg.doc_root_db; + conf.http_url = environment.get("HTTP_REFERER", conf.query_base_url ~ conf.query_string); conf.request_method = environment.get("REQUEST_METHOD", "POST"); - conf.query_base = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ "?"; - conf.http_url = environment.get("HTTP_REFERER", conf.query_base ~ conf.query_string); + conf.db_path = _cfg.db_sqlite_path; struct CGI_val { string db_selected = ""; string sql_match_limit = ""; // radio: ( 1000 | 2500 ) @@ -106,7 +107,7 @@ void cgi_function_intro(Cgi cgi) { bool checked_sql = false; } auto cv = CGI_val(); - cv.db_selected = _cfg.filename_db; + cv.db_selected = _cfg.db_sqlite_filename; auto text_fields() { string canned_query_str = environment.get("QUERY_STRING", ""); if ("query_string" in cgi.post) { @@ -445,9 +446,9 @@ void cgi_function_intro(Cgi cgi) { string canned_url () { string _url = ""; if (environment.get("REQUEST_METHOD", "POST") == "POST") { - _url = conf.query_base ~ tf.canned_query; + _url = conf.query_base_url ~ tf.canned_query; } else if (environment.get("REQUEST_METHOD", "POST") == "GET") { - _url = conf.query_base ~ environment.get("QUERY_STRING", ""); + _url = conf.query_base_url ~ environment.get("QUERY_STRING", ""); } return _url; } @@ -517,7 +518,7 @@ void cgi_function_intro(Cgi cgi) { _set_offset_previous = m.captures["offset_key"] ~ ((m.captures["offset_val"]).to!int - cv.sql_match_limit.to!int).to!string; _url_previous = _url.replace(rgx.track_offset, _set_offset_previous); } - } else {// _current_offset_value = 0; + } else { // _current_offset_value = 0; _url_next = _url ~= "&smo=" ~ cv.sql_match_limit.to!string; } if (_url_previous.empty) { @@ -1413,9 +1414,9 @@ void cgi_function_intro(Cgi cgi) { string _the_can = ""; if (show_the_can == "checked") { tf = text_fields; - string method_get_url = conf.query_base ~ environment.get("QUERY_STRING", ""); - string method_post_url_construct = conf.query_base ~ tf.canned_query; - // assert(method_get_url == environment.get("HTTP_REFERER", conf.query_base ~ conf.query_string)); + string method_get_url = conf.query_base_url ~ environment.get("QUERY_STRING", ""); + string method_post_url_construct = conf.query_base_url ~ tf.canned_query; + // assert(method_get_url == environment.get("HTTP_REFERER", conf.query_base_url ~ conf.query_string)); if (conf.request_method == "POST") { _the_can = "" @@ -1436,7 +1437,7 @@ void cgi_function_intro(Cgi cgi) { ~ method_get_url ~ ""; } - conf.http_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script ~ tf.canned_query; + conf.http_url = conf.http_request_type ~ "://" ~ conf.http_host ~ conf.cgi_script_name ~ tf.canned_query; } return _the_can; } @@ -1502,7 +1503,7 @@ void cgi_function_intro(Cgi cgi) { ┃", - _cfg.filename_cgi, + _cfg.cgi_filename, (post_value("ec") == "checked") ? post_value("sf", "field") : "", provide_tip, search_note, @@ -1538,7 +1539,7 @@ void cgi_function_intro(Cgi cgi) { } else { val = false; } return val; } - cv.db_selected = set_value("selected_db", _cfg.filename_db); // selected_db_name == db (spine.search.db or whatever) + cv.db_selected = set_value("selected_db", _cfg.db_sqlite_filename); // selected_db_name == db (spine.search.db or whatever) cv.sql_match_limit = set_value("sml", "1000"); cv.sql_match_offset = set_value("smo", "0"); cv.search_text = set_value("sf", ""); @@ -1563,6 +1564,9 @@ void cgi_function_intro(Cgi cgi) { // } } { // debug cgi info: + // cgi.write("db with path: " ~ conf.db_path ~ "/" ~ cv.db_selected ~ "
\n"); + // cgi.write("http url: " ~ conf.http_url ~ "
\n"); + // cgi.write("query base url: " ~ conf.query_base_url ~ "
\n"); // cgi.write("db_selected: " ~ cv.db_selected ~ "
\n"); // cgi.write("search_text: " ~ cv.search_text ~ "
\n"); // cgi.write("sql_match_limit: " ~ cv.sql_match_limit ~ ";\n"); @@ -1576,7 +1580,7 @@ void cgi_function_intro(Cgi cgi) { // cgi.write("cv.checked_sql: " ~ (cv.checked_sql ? "checked" : "off") ~ "
\n"); } } - auto db = Database(conf.db_path ~ cv.db_selected); + auto db = Database(conf.db_path ~ "/" ~ cv.db_selected); { uint sql_match_offset_counter(T)(T cv) { sql_match_offset_count += cv.sql_match_limit.to!uint; -- cgit v1.2.3