From 88df8242b18514398d9f5717d3d823f3b1be49a6 Mon Sep 17 00:00:00 2001 From: Teus Benschop Date: Fri, 5 Jan 2024 18:25:29 +0100 Subject: [PATCH] Clearer types in code rather than void pointers https://github.com/bibledit/cloud/issues/926 --- bootstrap/bootstrap.cpp | 64 +++++++++++++++---------------- developer/delay.cpp | 4 +- developer/delay.h | 4 +- editone2/save.cpp | 50 ++++++++++++------------ editone2/save.h | 4 +- editone2/update.cpp | 62 +++++++++++++++--------------- editone2/update.h | 4 +- editone2/verse.cpp | 24 +++++------- editone2/verse.h | 4 +- images/fetch.cpp | 12 +++--- images/fetch.h | 4 +- images/index.cpp | 19 +++++---- images/index.h | 4 +- images/view.cpp | 12 +++--- images/view.h | 4 +- menu/logic.cpp | 8 ++-- pkgdata/files.txt | 4 -- read/index.cpp | 49 ++++++++++++------------ read/index.h | 4 +- read/load.cpp | 27 +++++++------ read/load.h | 4 +- read/verse.cpp | 21 +++++----- read/verse.h | 4 +- resource/comparative1edit.cpp | 43 ++++++++++----------- resource/comparative1edit.h | 4 +- resource/comparative9edit.cpp | 23 +++++------ resource/comparative9edit.h | 4 +- resource/divider.cpp | 72 +++++++++++++++++------------------ resource/divider.h | 4 +- resource/translated1edit.cpp | 33 ++++++++-------- resource/translated1edit.h | 4 +- resource/translated9edit.cpp | 23 +++++------ resource/translated9edit.h | 4 +- session/confirm.cpp | 21 +++++----- session/confirm.h | 4 +- 35 files changed, 299 insertions(+), 336 deletions(-) diff --git a/bootstrap/bootstrap.cpp b/bootstrap/bootstrap.cpp index 882fc53ff..9e9a9a385 100644 --- a/bootstrap/bootstrap.cpp +++ b/bootstrap/bootstrap.cpp @@ -1160,83 +1160,83 @@ void bootstrap_index (Webserver_Request& webserver_request) return; } - if ((url == editone2_save_url ()) && browser_request_security_okay (webserver_request) && editone2_save_acl (std::addressof(webserver_request))) { - webserver_request.reply = editone2_save (std::addressof(webserver_request)); + if ((url == editone2_save_url ()) && browser_request_security_okay (webserver_request) && editone2_save_acl (webserver_request)) { + webserver_request.reply = editone2_save (webserver_request); return; } - if ((url == editone2_verse_url ()) && browser_request_security_okay (webserver_request) && editone2_verse_acl (std::addressof(webserver_request))) { - webserver_request.reply = editone2_verse (std::addressof(webserver_request)); + if ((url == editone2_verse_url ()) && browser_request_security_okay (webserver_request) && editone2_verse_acl (webserver_request)) { + webserver_request.reply = editone2_verse (webserver_request); return; } - if ((url == editone2_update_url ()) && browser_request_security_okay (webserver_request) && editone2_update_acl (std::addressof(webserver_request))) { - webserver_request.reply = editone2_update (std::addressof(webserver_request)); + if ((url == editone2_update_url ()) && browser_request_security_okay (webserver_request) && editone2_update_acl (webserver_request)) { + webserver_request.reply = editone2_update (webserver_request); return; } - if ((url == read_index_url ()) && browser_request_security_okay (webserver_request) && read_index_acl (std::addressof(webserver_request))) { - webserver_request.reply = read_index (std::addressof(webserver_request)); + if ((url == read_index_url ()) && browser_request_security_okay (webserver_request) && read_index_acl (webserver_request)) { + webserver_request.reply = read_index (webserver_request); return; } - if ((url == read_load_url ()) && browser_request_security_okay (webserver_request) && read_load_acl (std::addressof(webserver_request))) { - webserver_request.reply = read_load (std::addressof(webserver_request)); + if ((url == read_load_url ()) && browser_request_security_okay (webserver_request) && read_load_acl (webserver_request)) { + webserver_request.reply = read_load (webserver_request); return; } - if ((url == read_verse_url ()) && browser_request_security_okay (webserver_request) && read_verse_acl (std::addressof(webserver_request))) { - webserver_request.reply = read_verse (std::addressof(webserver_request)); + if ((url == read_verse_url ()) && browser_request_security_okay (webserver_request) && read_verse_acl (webserver_request)) { + webserver_request.reply = read_verse (webserver_request); return; } - if ((url == resource_divider_url ()) && browser_request_security_okay (webserver_request) && resource_divider_acl (std::addressof(webserver_request))) { - webserver_request.reply = resource_divider (std::addressof(webserver_request)); + if ((url == resource_divider_url ()) && browser_request_security_okay (webserver_request) && resource_divider_acl (webserver_request)) { + webserver_request.reply = resource_divider (webserver_request); return; } - if ((url == session_confirm_url ()) && browser_request_security_okay (webserver_request) && session_confirm_acl (std::addressof(webserver_request))) { - webserver_request.reply = session_confirm (std::addressof(webserver_request)); + if ((url == session_confirm_url ()) && browser_request_security_okay (webserver_request) && session_confirm_acl (webserver_request)) { + webserver_request.reply = session_confirm (webserver_request); return; } - if ((url == resource_comparative9edit_url ()) && browser_request_security_okay (webserver_request) && resource_comparative9edit_acl (std::addressof(webserver_request))) { - webserver_request.reply = resource_comparative9edit (std::addressof(webserver_request)); + if ((url == resource_comparative9edit_url ()) && browser_request_security_okay (webserver_request) && resource_comparative9edit_acl (webserver_request)) { + webserver_request.reply = resource_comparative9edit (webserver_request); return; } - if ((url == resource_comparative1edit_url ()) && browser_request_security_okay (webserver_request) && resource_comparative1edit_acl (std::addressof(webserver_request))) { - webserver_request.reply = resource_comparative1edit (std::addressof(webserver_request)); + if ((url == resource_comparative1edit_url ()) && browser_request_security_okay (webserver_request) && resource_comparative1edit_acl (webserver_request)) { + webserver_request.reply = resource_comparative1edit (webserver_request); return; } - if ((url == resource_translated9edit_url ()) && browser_request_security_okay (webserver_request) && resource_translated9edit_acl (std::addressof(webserver_request))) { - webserver_request.reply = resource_translated9edit (std::addressof(webserver_request)); + if ((url == resource_translated9edit_url ()) && browser_request_security_okay (webserver_request) && resource_translated9edit_acl (webserver_request)) { + webserver_request.reply = resource_translated9edit (webserver_request); return; } - if ((url == resource_translated1edit_url ()) && browser_request_security_okay (webserver_request) && resource_translated1edit_acl (std::addressof(webserver_request))) { - webserver_request.reply = resource_translated1edit (std::addressof(webserver_request)); + if ((url == resource_translated1edit_url ()) && browser_request_security_okay (webserver_request) && resource_translated1edit_acl (webserver_request)) { + webserver_request.reply = resource_translated1edit (webserver_request); return; } - if ((url == developer_delay_url ()) && developer_delay_acl (std::addressof(webserver_request))) { - webserver_request.reply = developer_delay (std::addressof(webserver_request)); + if ((url == developer_delay_url ()) && developer_delay_acl (webserver_request)) { + webserver_request.reply = developer_delay (webserver_request); return; } - if ((url == images_index_url ()) && browser_request_security_okay (webserver_request) && images_index_acl (std::addressof(webserver_request))) { - webserver_request.reply = images_index (std::addressof(webserver_request)); + if ((url == images_index_url ()) && browser_request_security_okay (webserver_request) && images_index_acl (webserver_request)) { + webserver_request.reply = images_index (webserver_request); return; } - if ((url == images_view_url ()) && browser_request_security_okay (webserver_request) && images_view_acl (std::addressof(webserver_request))) { - webserver_request.reply = images_view (std::addressof(webserver_request)); + if ((url == images_view_url ()) && browser_request_security_okay (webserver_request) && images_view_acl (webserver_request)) { + webserver_request.reply = images_view (webserver_request); return; } - if ((url == images_fetch_url ()) && browser_request_security_okay (webserver_request) && images_fetch_acl (std::addressof(webserver_request))) { - webserver_request.reply = images_fetch (std::addressof(webserver_request)); + if ((url == images_fetch_url ()) && browser_request_security_okay (webserver_request) && images_fetch_acl (webserver_request)) { + webserver_request.reply = images_fetch (webserver_request); return; } diff --git a/developer/delay.cpp b/developer/delay.cpp index 130b620d7..c126e0aeb 100644 --- a/developer/delay.cpp +++ b/developer/delay.cpp @@ -30,13 +30,13 @@ const char * developer_delay_url () } -bool developer_delay_acl ([[maybe_unused]] void * webserver_request) +bool developer_delay_acl ([[maybe_unused]] Webserver_Request& webserver_request) { return true; } -string developer_delay ([[maybe_unused]] void * webserver_request) +string developer_delay ([[maybe_unused]] Webserver_Request& webserver_request) { // Here is a delay routine that waits multiple seconds before sending the reponse. // The purpose is to test timeouts of the website live monitors. diff --git a/developer/delay.h b/developer/delay.h index 56bbc81da..edbfec1c1 100644 --- a/developer/delay.h +++ b/developer/delay.h @@ -24,5 +24,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. class Webserver_Request; const char * developer_delay_url (); -bool developer_delay_acl (void * webserver_request); -std::string developer_delay (void * webserver_request); +bool developer_delay_acl (Webserver_Request& webserver_request); +std::string developer_delay (Webserver_Request& webserver_request); diff --git a/editone2/save.cpp b/editone2/save.cpp index c9f595e39..d5a56e7a5 100644 --- a/editone2/save.cpp +++ b/editone2/save.cpp @@ -48,38 +48,36 @@ string editone2_save_url () } -bool editone2_save_acl (void * webserver_request) +bool editone2_save_acl (Webserver_Request& webserver_request) { - if (Filter_Roles::access_control (webserver_request, Filter_Roles::translator ())) return true; - auto [ read, write ] = access_bible::any (webserver_request); + if (Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::translator ())) + return true; + auto [ read, write ] = access_bible::any (std::addressof(webserver_request)); return read; } -string editone2_save (void * webserver_request) +string editone2_save (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - - // Check on information about where to save the verse. - bool save = (request->post.count ("bible") && request->post.count ("book") && request->post.count ("chapter") && request->post.count ("verse") && request->post.count ("html")); + bool save = (webserver_request.post.count ("bible") && webserver_request.post.count ("book") && webserver_request.post.count ("chapter") && webserver_request.post.count ("verse") && webserver_request.post.count ("html")); if (!save) { return translate("Don't know where to save"); } - string bible = request->post["bible"]; - int book = filter::strings::convert_to_int (request->post["book"]); - int chapter = filter::strings::convert_to_int (request->post["chapter"]); - int verse = filter::strings::convert_to_int (request->post["verse"]); - string html = request->post["html"]; - string checksum = request->post["checksum"]; - string unique_id = request->post ["id"]; + string bible = webserver_request.post["bible"]; + int book = filter::strings::convert_to_int (webserver_request.post["book"]); + int chapter = filter::strings::convert_to_int (webserver_request.post["chapter"]); + int verse = filter::strings::convert_to_int (webserver_request.post["verse"]); + string html = webserver_request.post["html"]; + string checksum = webserver_request.post["checksum"]; + string unique_id = webserver_request.post ["id"]; // Checksum. if (checksum_logic::get (html) != checksum) { - request->response_code = 409; + webserver_request.response_code = 409; return translate ("Checksum error"); } @@ -101,7 +99,7 @@ string editone2_save (void * webserver_request) } - if (!access_bible::book_write (request, string(), bible, book)) { + if (!access_bible::book_write (std::addressof(webserver_request), string(), bible, book)) { return translate ("No write access"); } @@ -113,11 +111,11 @@ string editone2_save (void * webserver_request) // Collect some data about the changes for this user. - string username = request->session_logic()->currentUser (); + string username = webserver_request.session_logic()->currentUser (); #ifdef HAVE_CLOUD - int oldID = request->database_bibles()->get_chapter_id (bible, book, chapter); + int oldID = webserver_request.database_bibles()->get_chapter_id (bible, book, chapter); #endif - string old_chapter_usfm = request->database_bibles()->get_chapter (bible, book, chapter); + string old_chapter_usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter); // If the most recent save operation on this chapter @@ -128,7 +126,7 @@ string editone2_save (void * webserver_request) // it's worth to check on this. // Because the user's editor may not yet have loaded this updated Bible text. // https://github.com/bibledit/cloud/issues/340 - string loaded_usfm = getLoadedUsfm2 (webserver_request, bible, book, chapter, unique_id); + string loaded_usfm = getLoadedUsfm2 (std::addressof(webserver_request), bible, book, chapter, unique_id); if (loaded_usfm != old_chapter_usfm) { bible_logic::recent_save_email (bible, book, chapter, username, loaded_usfm, old_chapter_usfm); } @@ -136,24 +134,24 @@ string editone2_save (void * webserver_request) // Safely store the verse. string explanation; - string message = filter::usfm::safely_store_verse (request, bible, book, chapter, verse, verse_usfm, explanation, true); + string message = filter::usfm::safely_store_verse (std::addressof(webserver_request), bible, book, chapter, verse, verse_usfm, explanation, true); bible_logic::unsafe_save_mail (message, explanation, username, verse_usfm, book, chapter); // If storing the verse worked out well, there's no message to display. if (message.empty ()) { // Get the chapter text now, that is, after the save operation completed. - string new_chapter_usfm = request->database_bibles()->get_chapter (bible, book, chapter); + string new_chapter_usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter); // Check whether the text on disk was changed while the user worked with the older copy. if (!loaded_usfm.empty () && (loaded_usfm != old_chapter_usfm)) { // Do a merge for better editing reliability. vector conflicts; // Prioritize the USFM already in the chapter. new_chapter_usfm = filter_merge_run (loaded_usfm, new_chapter_usfm, old_chapter_usfm, true, conflicts); - request->database_bibles()->store_chapter (bible, book, chapter, new_chapter_usfm); + webserver_request.database_bibles()->store_chapter (bible, book, chapter, new_chapter_usfm); Database_Logs::log (translate ("Merging chapter.")); } #ifdef HAVE_CLOUD // The Cloud stores details of the user's changes. - int newID = request->database_bibles()->get_chapter_id (bible, book, chapter); + int newID = webserver_request.database_bibles()->get_chapter_id (bible, book, chapter); Database_Modifications database_modifications; database_modifications.recordUserSave (username, bible, book, chapter, oldID, old_chapter_usfm, newID, new_chapter_usfm); if (sendreceive_git_repository_linked (bible)) { @@ -164,7 +162,7 @@ string editone2_save (void * webserver_request) // Store a copy of the USFM now saved as identical to what's loaded in the editor for later reference. - storeLoadedUsfm2 (webserver_request, bible, book, chapter, unique_id); + storeLoadedUsfm2 (std::addressof(webserver_request), bible, book, chapter, unique_id); return locale_logic_text_saved (); } diff --git a/editone2/save.h b/editone2/save.h index 81394b743..89d8c095a 100644 --- a/editone2/save.h +++ b/editone2/save.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string editone2_save_url (); -bool editone2_save_acl (void * webserver_request); -std::string editone2_save (void * webserver_request); +bool editone2_save_acl (Webserver_Request& webserver_request); +std::string editone2_save (Webserver_Request& webserver_request); diff --git a/editone2/update.cpp b/editone2/update.cpp index 3591241f6..e7df5ca80 100644 --- a/editone2/update.cpp +++ b/editone2/update.cpp @@ -49,19 +49,17 @@ string editone2_update_url () } -bool editone2_update_acl (void * webserver_request) +bool editone2_update_acl (Webserver_Request& webserver_request) { - if (Filter_Roles::access_control (webserver_request, Filter_Roles::translator ())) return true; - auto [ read, write ] = access_bible::any (webserver_request); + if (Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::translator ())) + return true; + auto [ read, write ] = access_bible::any (std::addressof(webserver_request)); return read; } -string editone2_update (void * webserver_request) +string editone2_update (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - - // Whether the update is good to go. bool good2go = true; @@ -73,12 +71,12 @@ string editone2_update (void * webserver_request) // Check the relevant bits of information. if (good2go) { bool parameters_ok = true; - if (!request->post.count ("bible")) parameters_ok = false; - if (!request->post.count ("book")) parameters_ok = false; - if (!request->post.count ("chapter")) parameters_ok = false; - if (!request->post.count ("verse")) parameters_ok = false; - if (!request->post.count ("loaded")) parameters_ok = false; - if (!request->post.count ("edited")) parameters_ok = false; + if (!webserver_request.post.count ("bible")) parameters_ok = false; + if (!webserver_request.post.count ("book")) parameters_ok = false; + if (!webserver_request.post.count ("chapter")) parameters_ok = false; + if (!webserver_request.post.count ("verse")) parameters_ok = false; + if (!webserver_request.post.count ("loaded")) parameters_ok = false; + if (!webserver_request.post.count ("edited")) parameters_ok = false; if (!parameters_ok) { messages.push_back (translate("Don't know what to update")); good2go = false; @@ -97,29 +95,29 @@ string editone2_update (void * webserver_request) string checksum2; string unique_id; if (good2go) { - bible = request->post["bible"]; - book = filter::strings::convert_to_int (request->post["book"]); - chapter = filter::strings::convert_to_int (request->post["chapter"]); - verse = filter::strings::convert_to_int (request->post["verse"]); - loaded_html = request->post["loaded"]; - edited_html = request->post["edited"]; - checksum1 = request->post["checksum1"]; - checksum2 = request->post["checksum2"]; - unique_id = request->post ["id"]; + bible = webserver_request.post["bible"]; + book = filter::strings::convert_to_int (webserver_request.post["book"]); + chapter = filter::strings::convert_to_int (webserver_request.post["chapter"]); + verse = filter::strings::convert_to_int (webserver_request.post["verse"]); + loaded_html = webserver_request.post["loaded"]; + edited_html = webserver_request.post["edited"]; + checksum1 = webserver_request.post["checksum1"]; + checksum2 = webserver_request.post["checksum2"]; + unique_id = webserver_request.post ["id"]; } // Checksums of the loaded and edited html. if (good2go) { if (checksum_logic::get (loaded_html) != checksum1) { - request->response_code = 409; + webserver_request.response_code = 409; messages.push_back (translate ("Checksum error")); good2go = false; } } if (good2go) { if (checksum_logic::get (edited_html) != checksum2) { - request->response_code = 409; + webserver_request.response_code = 409; messages.push_back (translate ("Checksum error")); good2go = false; } @@ -144,7 +142,7 @@ string editone2_update (void * webserver_request) bool bible_write_access = false; if (good2go) { - bible_write_access = access_bible::book_write (request, string(), bible, book); + bible_write_access = access_bible::book_write (std::addressof(webserver_request), string(), bible, book); } @@ -155,13 +153,13 @@ string editone2_update (void * webserver_request) // Collect some data about the changes for this user. - string username = request->session_logic()->currentUser (); + string username = webserver_request.session_logic()->currentUser (); #ifdef HAVE_CLOUD int oldID = 0; - if (good2go) oldID = request->database_bibles()->get_chapter_id (bible, book, chapter); + if (good2go) oldID = webserver_request.database_bibles()->get_chapter_id (bible, book, chapter); #endif string old_chapter_usfm; - if (good2go) old_chapter_usfm = request->database_bibles()->get_chapter (bible, book, chapter); + if (good2go) old_chapter_usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter); // Determine what (composed) version of USFM to save to the chapter. @@ -214,16 +212,16 @@ string editone2_update (void * webserver_request) string explanation; string message; if (good2go && bible_write_access && text_was_edited) { - message = filter::usfm::safely_store_verse (request, bible, book, chapter, verse, edited_verse_usfm, explanation, true); + message = filter::usfm::safely_store_verse (std::addressof(webserver_request), bible, book, chapter, verse, edited_verse_usfm, explanation, true); bible_logic::unsafe_save_mail (message, explanation, username, edited_verse_usfm, book, chapter); } // The new chapter identifier and new chapter USFM. - int newID = request->database_bibles()->get_chapter_id (bible, book, chapter); + int newID = webserver_request.database_bibles()->get_chapter_id (bible, book, chapter); string new_chapter_usfm; if (good2go) { - new_chapter_usfm = request->database_bibles()->get_chapter (bible, book, chapter); + new_chapter_usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter); } @@ -345,7 +343,7 @@ string editone2_update (void * webserver_request) // Test using the Cloud together with client devices with send and receive. - bool write = access_bible::book_write (webserver_request, username, bible, book); + bool write = access_bible::book_write (std::addressof(webserver_request), username, bible, book); response = checksum_logic::send (response, write); // Ready. diff --git a/editone2/update.h b/editone2/update.h index 0617a0037..b27969d43 100644 --- a/editone2/update.h +++ b/editone2/update.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string editone2_update_url (); -bool editone2_update_acl (void * webserver_request); -std::string editone2_update (void * webserver_request); +bool editone2_update_acl (Webserver_Request& webserver_request); +std::string editone2_update (Webserver_Request& webserver_request); diff --git a/editone2/verse.cpp b/editone2/verse.cpp index d30c3dfe1..f4f0a0baf 100644 --- a/editone2/verse.cpp +++ b/editone2/verse.cpp @@ -32,34 +32,30 @@ string editone2_verse_url () } -bool editone2_verse_acl (void * webserver_request) +bool editone2_verse_acl (Webserver_Request& webserver_request) { - if (Filter_Roles::access_control (webserver_request, Filter_Roles::translator ())) return true; - auto [ read, write ] = access_bible::any (webserver_request); + if (Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::translator ())) + return true; + auto [ read, write ] = access_bible::any (std::addressof(webserver_request)); return read; } -string editone2_verse (void * webserver_request) +string editone2_verse (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - - // Only act if a verse was found - string sverse = request->query ["verse"]; + string sverse = webserver_request.query ["verse"]; if (!sverse.empty ()) { // Only update navigation in case the verse changed. // This avoids unnecessary focus operations in the clients. int iverse = filter::strings::convert_to_int (sverse); - if (iverse != Ipc_Focus::getVerse (request)) { - int book = Ipc_Focus::getBook (request); - int chapter = Ipc_Focus::getChapter (request); - Ipc_Focus::set (request, book, chapter, iverse); + if (iverse != Ipc_Focus::getVerse (std::addressof(webserver_request))) { + int book = Ipc_Focus::getBook (std::addressof(webserver_request)); + int chapter = Ipc_Focus::getChapter (std::addressof(webserver_request)); + Ipc_Focus::set (std::addressof(webserver_request), book, chapter, iverse); } - - } diff --git a/editone2/verse.h b/editone2/verse.h index cde284796..01c8fb5fb 100644 --- a/editone2/verse.h +++ b/editone2/verse.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string editone2_verse_url (); -bool editone2_verse_acl (void * webserver_request); -std::string editone2_verse (void * webserver_request); +bool editone2_verse_acl (Webserver_Request& webserver_request); +std::string editone2_verse (Webserver_Request& webserver_request); diff --git a/images/fetch.cpp b/images/fetch.cpp index 071b701cd..3c28330bc 100644 --- a/images/fetch.cpp +++ b/images/fetch.cpp @@ -32,22 +32,20 @@ string images_fetch_url () } -bool images_fetch_acl (void * webserver_request) +bool images_fetch_acl (Webserver_Request& webserver_request) { - return Filter_Roles::access_control (webserver_request, Filter_Roles::consultant ()); + return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::consultant ()); } -string images_fetch (void * webserver_request) +string images_fetch (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - // Image name. - string image = request->query ["image"]; + string image = webserver_request.query ["image"]; // Set the HTTP GET parameter to the image name, // so the server will return the appropriate Mime type for this image. - request->get = image; + webserver_request.get = image; // Return the raw image data for sending off to the browser. Database_BibleImages database_bibleimages; diff --git a/images/fetch.h b/images/fetch.h index 6b79f3f0e..013a04a26 100644 --- a/images/fetch.h +++ b/images/fetch.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string images_fetch_url (); -bool images_fetch_acl (void * webserver_request); -std::string images_fetch (void * webserver_request); +bool images_fetch_acl (Webserver_Request& webserver_request); +std::string images_fetch (Webserver_Request& webserver_request); diff --git a/images/index.cpp b/images/index.cpp index 76bb860d9..ea499cbec 100644 --- a/images/index.cpp +++ b/images/index.cpp @@ -42,20 +42,19 @@ string images_index_url () } -bool images_index_acl (void * webserver_request) +bool images_index_acl (Webserver_Request& webserver_request) { - return Filter_Roles::access_control (webserver_request, Filter_Roles::translator ()); + return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::translator ()); } -string images_index (void * webserver_request) +string images_index (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); Database_BibleImages database_bibleimages; string page; - Assets_Header header = Assets_Header (translate("Bible images"), request); + Assets_Header header = Assets_Header (translate("Bible images"), std::addressof(webserver_request)); header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ()); header.add_bread_crumb (images_index_url (), menu_logic_images_index_text ()); page = header.run (); @@ -64,11 +63,11 @@ string images_index (void * webserver_request) // File upload. - if (request->post.count ("upload")) { + if (webserver_request.post.count ("upload")) { string folder = filter_url_tempfile (); filter_url_mkdir (folder); - string file = filter_url_create_path ({folder, request->post ["filename"]}); - string data = request->post ["data"]; + string file = filter_url_create_path ({folder, webserver_request.post ["filename"]}); + string data = webserver_request.post ["data"]; if (!data.empty ()) { filter_url_file_put_contents (file, data); bool background_import = filter_archive_is_archive (file); @@ -89,9 +88,9 @@ string images_index (void * webserver_request) // Delete image. - string remove = request->query ["delete"]; + string remove = webserver_request.query ["delete"]; if (!remove.empty()) { - string confirm = request->query ["confirm"]; + string confirm = webserver_request.query ["confirm"]; if (confirm.empty()) { Dialog_Yes dialog_yes = Dialog_Yes ("index", translate("Would you like to delete this image?")); dialog_yes.add_query ("delete", remove); diff --git a/images/index.h b/images/index.h index 7d4b53b0e..602e74a26 100644 --- a/images/index.h +++ b/images/index.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string images_index_url (); -bool images_index_acl (void * webserver_request); -std::string images_index (void * webserver_request); +bool images_index_acl (Webserver_Request& webserver_request); +std::string images_index (Webserver_Request& webserver_request); diff --git a/images/view.cpp b/images/view.cpp index 7715f7e7e..202ca3ccf 100644 --- a/images/view.cpp +++ b/images/view.cpp @@ -41,25 +41,23 @@ string images_view_url () } -bool images_view_acl (void * webserver_request) +bool images_view_acl (Webserver_Request& webserver_request) { - return Filter_Roles::access_control (webserver_request, Filter_Roles::translator ()); + return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::translator ()); } -string images_view (void * webserver_request) +string images_view (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - string page; - Assets_Header header = Assets_Header (translate("Bible image"), request); + Assets_Header header = Assets_Header (translate("Bible image"), std::addressof(webserver_request)); header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ()); header.add_bread_crumb (images_view_url (), menu_logic_images_index_text ()); page = header.run (); Assets_View view; string error, success; - string image = request->query ["image"]; + string image = webserver_request.query ["image"]; view.set_variable ("image", image); view.set_variable ("success", success); diff --git a/images/view.h b/images/view.h index 7bdba8a88..f596cf247 100644 --- a/images/view.h +++ b/images/view.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string images_view_url (); -bool images_view_acl (void * webserver_request); -std::string images_view (void * webserver_request); +bool images_view_acl (Webserver_Request& webserver_request); +std::string images_view (Webserver_Request& webserver_request); diff --git a/menu/logic.cpp b/menu/logic.cpp index 9edd3a7b1..49c9f47d3 100644 --- a/menu/logic.cpp +++ b/menu/logic.cpp @@ -298,7 +298,7 @@ string menu_logic_basic_categories (void * webserver_request) string filename = current_theme_filebased_cache_filename (request->session_identifier); string color = Filter_Css::theme_picker (current_theme_index, 1); - if (read_index_acl (webserver_request)) { + if (read_index_acl (*request)) { html.push_back (menu_logic_create_item (read_index_url (), translate ("Read"), true, "", color)); } @@ -903,7 +903,7 @@ string menu_logic_settings_category (void * webserver_request, string * tooltip) } if (label == images) { - if (images_index_acl (webserver_request)) { + if (images_index_acl (*request)) { html.push_back (menu_logic_create_item (images_index_url (), label, true, "", "")); tiplabels.push_back (label); } @@ -970,13 +970,13 @@ string menu_logic_settings_resources_category ([[maybe_unused]] void * webserver #endif #ifdef HAVE_CLOUD - if (resource_comparative9edit_acl (webserver_request)) { + if (resource_comparative9edit_acl (*request)) { html.push_back (menu_logic_create_item (resource_comparative9edit_url (), translate ("Comparative"), true, "", "")); } #endif #ifdef HAVE_CLOUD - if (resource_translated9edit_acl (webserver_request)) { + if (resource_translated9edit_acl (*request)) { html.push_back (menu_logic_create_item (resource_translated9edit_url (), translate ("Translated"), true, "", "")); } #endif diff --git a/pkgdata/files.txt b/pkgdata/files.txt index e47e280dc..944f38181 100644 --- a/pkgdata/files.txt +++ b/pkgdata/files.txt @@ -439,10 +439,6 @@ /jsonxx/LICENSE /ldap /lexicon -/libbibledit.a.LvituV -/libbibledit.a.MpBesj -/libbibledit.a.onYIWR -/libbibledit.a.YrUTw4 /library /livetest /livetest/initialize.sh diff --git a/read/index.cpp b/read/index.cpp index 355ada89c..856219bdc 100644 --- a/read/index.cpp +++ b/read/index.cpp @@ -52,38 +52,37 @@ string read_index_url () } -bool read_index_acl (void * webserver_request) +bool read_index_acl (Webserver_Request& webserver_request) { int role = Filter_Roles::translator (); - if (Filter_Roles::access_control (webserver_request, role)) return true; - auto [ read, write ] = access_bible::any (webserver_request); + if (Filter_Roles::access_control (std::addressof(webserver_request), role)) + return true; + auto [ read, write ] = access_bible::any (std::addressof(webserver_request)); return read; } -string read_index (void * webserver_request) +string read_index (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); + bool touch = webserver_request.session_logic ()->touchEnabled (); - bool touch = request->session_logic ()->touchEnabled (); - - if (request->query.count ("switchbook") && request->query.count ("switchchapter")) { - int switchbook = filter::strings::convert_to_int (request->query ["switchbook"]); - int switchchapter = filter::strings::convert_to_int (request->query ["switchchapter"]); - Ipc_Focus::set (request, switchbook, switchchapter, 1); - Navigation_Passage::record_history (request, switchbook, switchchapter, 1); + if (webserver_request.query.count ("switchbook") && webserver_request.query.count ("switchchapter")) { + int switchbook = filter::strings::convert_to_int (webserver_request.query ["switchbook"]); + int switchchapter = filter::strings::convert_to_int (webserver_request.query ["switchchapter"]); + Ipc_Focus::set (std::addressof(webserver_request), switchbook, switchchapter, 1); + Navigation_Passage::record_history (std::addressof(webserver_request), switchbook, switchchapter, 1); } // Set the user chosen Bible as the current Bible. - if (request->post.count ("bibleselect")) { - string bibleselect = request->post ["bibleselect"]; - request->database_config_user ()->setBible (bibleselect); + if (webserver_request.post.count ("bibleselect")) { + string bibleselect = webserver_request.post ["bibleselect"]; + webserver_request.database_config_user ()->setBible (bibleselect); return string(); } string page; - Assets_Header header = Assets_Header (translate("Edit verse"), request); + Assets_Header header = Assets_Header (translate("Edit verse"), std::addressof(webserver_request)); header.set_navigator (); header.set_editor_stylesheet (); if (touch) header.jquery_touch_on (); @@ -97,10 +96,10 @@ string read_index (void * webserver_request) // Or if the user have used query to preset the active Bible, get the preset Bible. // If needed, change Bible to one it has read access to. // Set the chosen Bible on the option HTML tag. - string bible = access_bible::clamp (request, request->database_config_user()->getBible ()); - if (request->query.count ("bible")) bible = access_bible::clamp (request, request->query ["bible"]); + string bible = access_bible::clamp (std::addressof(webserver_request), webserver_request.database_config_user()->getBible ()); + if (webserver_request.query.count ("bible")) bible = access_bible::clamp (std::addressof(webserver_request), webserver_request.query ["bible"]); string bible_html; - vector bibles = access_bible::bibles (request); + vector bibles = access_bible::bibles (std::addressof(webserver_request)); for (auto selectable_bible : bibles) { bible_html = Options_To_Select::add_selection (selectable_bible, selectable_bible, bible_html); } @@ -120,17 +119,17 @@ string read_index (void * webserver_request) script_stream << "var readchooseEditorVerseSaved = " << quoted(locale_logic_text_saved ()) << ";\n"; script_stream << "var readchooseEditorVerseRetrying = " << quoted(locale_logic_text_retrying ()) << ";\n"; script_stream << "var readchooseEditorVerseUpdatedLoaded = " << quoted(locale_logic_text_reload ()) << ";\n"; - int verticalCaretPosition = request->database_config_user ()->getVerticalCaretPosition (); + int verticalCaretPosition = webserver_request.database_config_user ()->getVerticalCaretPosition (); script_stream << "var verticalCaretPosition = " << verticalCaretPosition << ";\n"; script_stream << "var verseSeparator = " << quoted(Database_Config_General::getNotesVerseSeparator ()) << ";\n"; string script {script_stream.str()}; - config::logic::swipe_enabled (webserver_request, script); + config::logic::swipe_enabled (std::addressof(webserver_request), script); view.set_variable ("script", script); string cls = Filter_Css::getClass (bible); string font = fonts::logic::get_text_font (bible); - int current_theme_index = request->database_config_user ()->getCurrentTheme (); - string filename = current_theme_filebased_cache_filename (request->session_identifier); + int current_theme_index = webserver_request.database_config_user ()->getCurrentTheme (); + string filename = current_theme_filebased_cache_filename (webserver_request.session_identifier); int direction = Database_Config_Bible::getTextDirection (bible); int lineheight = Database_Config_Bible::getLineHeight (bible); int letterspacing = Database_Config_Bible::getLetterSpacing (bible); @@ -144,12 +143,12 @@ string read_index (void * webserver_request) letterspacing)); // Whether to enable fast Bible editor switching. - if (request->database_config_user ()->getFastEditorSwitchingAvailable ()) { + if (webserver_request.database_config_user ()->getFastEditorSwitchingAvailable ()) { view.enable_zone ("fastswitcheditor"); } // Whether to enable the styles button. - if (request->database_config_user ()->getEnableStylesButtonVisualEditors ()) { + if (webserver_request.database_config_user ()->getEnableStylesButtonVisualEditors ()) { view.enable_zone ("stylesbutton"); } diff --git a/read/index.h b/read/index.h index 7d0608cd9..489c1a17c 100644 --- a/read/index.h +++ b/read/index.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string read_index_url (); -bool read_index_acl (void * webserver_request); -std::string read_index (void * webserver_request); +bool read_index_acl (Webserver_Request& webserver_request); +std::string read_index (Webserver_Request& webserver_request); diff --git a/read/load.cpp b/read/load.cpp index 0c1991d70..e41e379d8 100644 --- a/read/load.cpp +++ b/read/load.cpp @@ -39,27 +39,26 @@ string read_load_url () } -bool read_load_acl (void * webserver_request) +bool read_load_acl (Webserver_Request& webserver_request) { - if (Filter_Roles::access_control (webserver_request, Filter_Roles::translator ())) return true; - auto [ read, write ] = access_bible::any (webserver_request); + if (Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::translator ())) + return true; + auto [ read, write ] = access_bible::any (std::addressof(webserver_request)); return read; } -string read_load (void * webserver_request) +string read_load (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - - string bible = request->query ["bible"]; - int book = filter::strings::convert_to_int (request->query ["book"]); - int chapter = filter::strings::convert_to_int (request->query ["chapter"]); - int verse = filter::strings::convert_to_int (request->query ["verse"]); - string unique_id = request->query ["id"]; + string bible = webserver_request.query ["bible"]; + int book = filter::strings::convert_to_int (webserver_request.query ["book"]); + int chapter = filter::strings::convert_to_int (webserver_request.query ["chapter"]); + int verse = filter::strings::convert_to_int (webserver_request.query ["verse"]); + string unique_id = webserver_request.query ["id"]; string stylesheet = Database_Config_Bible::getEditorStylesheet (bible); - string chapter_usfm = request->database_bibles()->get_chapter (bible, book, chapter); + string chapter_usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter); vector verses = filter::usfm::get_verse_numbers (chapter_usfm); int highest_verse = 0; @@ -80,7 +79,7 @@ string read_load (void * webserver_request) // 2. It updates the chapter snapshot. // 3. It loads the other verse. // 4. It updates the chapter snapshot. - storeLoadedUsfm2 (webserver_request, bible, book, chapter, unique_id); + storeLoadedUsfm2 (std::addressof(webserver_request), bible, book, chapter, unique_id); string prefix_html; string not_used; @@ -117,7 +116,7 @@ string read_load (void * webserver_request) data.append ("#_be_#"); data.append (suffix_html); - string user = request->session_logic ()->currentUser (); + string user = webserver_request.session_logic ()->currentUser (); bool write = false; data = checksum_logic::send (data, write); diff --git a/read/load.h b/read/load.h index 84190d95b..9d861aefe 100644 --- a/read/load.h +++ b/read/load.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string read_load_url (); -bool read_load_acl (void * webserver_request); -std::string read_load (void * webserver_request); +bool read_load_acl (Webserver_Request& webserver_request); +std::string read_load (Webserver_Request& webserver_request); diff --git a/read/verse.cpp b/read/verse.cpp index ab5c07ae7..0f5e663d5 100644 --- a/read/verse.cpp +++ b/read/verse.cpp @@ -32,29 +32,28 @@ string read_verse_url () } -bool read_verse_acl (void * webserver_request) +bool read_verse_acl (Webserver_Request& webserver_request) { - if (Filter_Roles::access_control (webserver_request, Filter_Roles::translator ())) return true; - auto [ read, write ] = access_bible::any (webserver_request); + if (Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::translator ())) + return true; + auto [ read, write ] = access_bible::any (std::addressof(webserver_request)); return read; } -string read_verse (void * webserver_request) +string read_verse (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - // Only act if a verse was found - string sverse = request->query ["verse"]; + string sverse = webserver_request.query ["verse"]; if (!sverse.empty ()) { // Only update navigation in case the verse changed. // This avoids unnecessary focus operations in the clients. int iverse = filter::strings::convert_to_int (sverse); - if (iverse != Ipc_Focus::getVerse (request)) { - int book = Ipc_Focus::getBook (request); - int chapter = Ipc_Focus::getChapter (request); - Ipc_Focus::set (request, book, chapter, iverse); + if (iverse != Ipc_Focus::getVerse (std::addressof(webserver_request))) { + int book = Ipc_Focus::getBook (std::addressof(webserver_request)); + int chapter = Ipc_Focus::getChapter (std::addressof(webserver_request)); + Ipc_Focus::set (std::addressof(webserver_request), book, chapter, iverse); } } diff --git a/read/verse.h b/read/verse.h index 9de6bcda1..11849725f 100644 --- a/read/verse.h +++ b/read/verse.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string read_verse_url (); -bool read_verse_acl (void * webserver_request); -std::string read_verse (void * webserver_request); +bool read_verse_acl (Webserver_Request& webserver_request); +std::string read_verse (Webserver_Request& webserver_request); diff --git a/resource/comparative1edit.cpp b/resource/comparative1edit.cpp index d736eaf0e..e3567065c 100644 --- a/resource/comparative1edit.cpp +++ b/resource/comparative1edit.cpp @@ -48,32 +48,29 @@ string resource_comparative1edit_url () } -bool resource_comparative1edit_acl (void * webserver_request) +bool resource_comparative1edit_acl (Webserver_Request& webserver_request) { - return access_logic::privilege_view_resources (webserver_request); + return access_logic::privilege_view_resources (std::addressof(webserver_request)); } -string resource_comparative1edit (void * webserver_request) +string resource_comparative1edit (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - - string page; - Assets_Header header = Assets_Header (translate("Comparative resource"), request); + Assets_Header header = Assets_Header (translate("Comparative resource"), std::addressof(webserver_request)); header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ()); page = header.run (); Assets_View view; string error, success; - string name = request->query ["name"]; - if (name.empty()) name = request->post ["val1"]; + string name = webserver_request.query ["name"]; + if (name.empty()) name = webserver_request.post ["val1"]; view.set_variable ("name", name); - string checkbox = request->post ["checkbox"]; - bool checked = filter::strings::convert_to_bool (request->post ["checked"]); + string checkbox = webserver_request.post ["checkbox"]; + bool checked = filter::strings::convert_to_bool (webserver_request.post ["checked"]); bool resource_edited = false; @@ -91,12 +88,12 @@ string resource_comparative1edit (void * webserver_request) // The comparative resource's base resource. - if (request->query.count ("base")) { - string value = request->query["base"]; + if (webserver_request.query.count ("base")) { + string value = webserver_request.query["base"]; if (value.empty()) { Dialog_List dialog_list = Dialog_List ("comparative1edit", translate("Select a resource to be used as a base resource"), translate ("The base resource is used as a starting point for the comparison."), ""); dialog_list.add_query ("name", name); - vector resources = resource_logic_get_names (webserver_request, true); + vector resources = resource_logic_get_names (std::addressof(webserver_request), true); for (auto & resource : resources) { dialog_list.add_row (resource, "base", resource); } @@ -110,12 +107,12 @@ string resource_comparative1edit (void * webserver_request) // The comparative resource's updated resource. - if (request->query.count ("update")) { - string value = request->query["update"]; + if (webserver_request.query.count ("update")) { + string value = webserver_request.query["update"]; if (value.empty()) { Dialog_List dialog_list = Dialog_List ("comparative1edit", translate("Select a resource to be used as the updated resource."), translate ("The updated resource will be compared with the base resource."), ""); dialog_list.add_query ("name", name); - vector resources = resource_logic_get_names (webserver_request, true); + vector resources = resource_logic_get_names (std::addressof(webserver_request), true); for (auto & resource : resources) { dialog_list.add_row (resource, "update", resource); } @@ -129,27 +126,27 @@ string resource_comparative1edit (void * webserver_request) // The characters to remove from both resources before doing a comparison. - if (request->query.count ("remove")) { + if (webserver_request.query.count ("remove")) { Dialog_Entry dialog_entry = Dialog_Entry ("comparative1edit", translate("Enter or edit the characters to remove from the resources"), remove, "remove", ""); dialog_entry.add_query ("name", name); page += dialog_entry.run (); return page; } - if (request->post.count ("remove")) { - remove = request->post ["entry"]; + if (webserver_request.post.count ("remove")) { + remove = webserver_request.post ["entry"]; resource_edited = true; } // The characters to search for and replace in both resources before doing a comparison. - if (request->query.count ("replace")) { + if (webserver_request.query.count ("replace")) { Dialog_Entry dialog_entry = Dialog_Entry ("comparative1edit", translate("Enter or edit the search and replace sets"), replace, "replace", ""); dialog_entry.add_query ("name", name); page += dialog_entry.run (); return page; } - if (request->post.count ("replace")) { - replace = request->post ["entry"]; + if (webserver_request.post.count ("replace")) { + replace = webserver_request.post ["entry"]; resource_edited = true; } diff --git a/resource/comparative1edit.h b/resource/comparative1edit.h index 6ddf8b72d..c2cfe50a7 100644 --- a/resource/comparative1edit.h +++ b/resource/comparative1edit.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string resource_comparative1edit_url (); -bool resource_comparative1edit_acl (void * webserver_request); -std::string resource_comparative1edit (void * webserver_request); +bool resource_comparative1edit_acl (Webserver_Request& webserver_request); +std::string resource_comparative1edit (Webserver_Request& webserver_request); diff --git a/resource/comparative9edit.cpp b/resource/comparative9edit.cpp index a6364b932..1a109a631 100644 --- a/resource/comparative9edit.cpp +++ b/resource/comparative9edit.cpp @@ -53,19 +53,16 @@ string resource_comparative9edit_url () } -bool resource_comparative9edit_acl (void * webserver_request) +bool resource_comparative9edit_acl (Webserver_Request& webserver_request) { - return Filter_Roles::access_control (webserver_request, Filter_Roles::manager ()); + return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::manager ()); } -string resource_comparative9edit (void * webserver_request) +string resource_comparative9edit (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - - string page; - Assets_Header header = Assets_Header (translate("Comparative resources"), request); + Assets_Header header = Assets_Header (translate("Comparative resources"), std::addressof(webserver_request)); header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ()); page = header.run (); Assets_View view; @@ -73,16 +70,16 @@ string resource_comparative9edit (void * webserver_request) // New comparative resource handler. - if (request->query.count ("new")) { + if (webserver_request.query.count ("new")) { Dialog_Entry dialog_entry = Dialog_Entry ("comparative9edit", translate("Please enter a name for the new comparative resource"), "", "new", ""); page += dialog_entry.run (); return page; } - if (request->post.count ("new")) { + if (webserver_request.post.count ("new")) { // The title for the new resource as entered by the user. // Clean the title up and ensure it always starts with "Comparative ". // This word flags the comparative resource as being one of that category. - string new_resource = request->post ["entry"]; + string new_resource = webserver_request.post ["entry"]; size_t pos = new_resource.find (resource_logic_comparative_resource ()); if (pos != std::string::npos) { new_resource.erase (pos, resource_logic_comparative_resource ().length()); @@ -111,16 +108,16 @@ string resource_comparative9edit (void * webserver_request) client_logic_no_cache_resource_add (new_resource); // Redirect the user to the place where to edit that new resource. string url = resource_comparative1edit_url () + "?name=" + new_resource; - redirect_browser (webserver_request, url); + redirect_browser (std::addressof(webserver_request), url); return ""; } } // Delete resource. - string title2remove = request->query ["delete"]; + string title2remove = webserver_request.query ["delete"]; if (!title2remove.empty()) { - string confirm = request->query ["confirm"]; + string confirm = webserver_request.query ["confirm"]; if (confirm == "") { Dialog_Yes dialog_yes = Dialog_Yes ("comparative9edit", translate("Would you like to delete this resource?")); dialog_yes.add_query ("delete", title2remove); diff --git a/resource/comparative9edit.h b/resource/comparative9edit.h index c3359397f..0c8455830 100644 --- a/resource/comparative9edit.h +++ b/resource/comparative9edit.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string resource_comparative9edit_url (); -bool resource_comparative9edit_acl (void * webserver_request); -std::string resource_comparative9edit (void * webserver_request); +bool resource_comparative9edit_acl (Webserver_Request& webserver_request); +std::string resource_comparative9edit (Webserver_Request& webserver_request); diff --git a/resource/divider.cpp b/resource/divider.cpp index 654ae479d..b4cf7a2da 100644 --- a/resource/divider.cpp +++ b/resource/divider.cpp @@ -52,46 +52,44 @@ string resource_divider_url () } -bool resource_divider_acl (void * webserver_request) +bool resource_divider_acl (Webserver_Request& webserver_request) { - return Filter_Roles::access_control (webserver_request, Filter_Roles::consultant ()); + return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::consultant ()); } -string resource_divider (void * webserver_request) +string resource_divider (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - string page; - Assets_Header header = Assets_Header (translate("Rich Divider"), webserver_request); + Assets_Header header = Assets_Header (translate("Rich Divider"), std::addressof(webserver_request)); header.add_bread_crumb (menu_logic_translate_menu (), menu_logic_translate_text ()); page = header.run (); Assets_View view; - int userid = filter::strings::user_identifier (webserver_request); + int userid = filter::strings::user_identifier (std::addressof(webserver_request)); string key = "rich divider"; // For administrator level default resource management purposes. bool is_def = false; - if (request->query["type"] == "def") is_def = true; + if (webserver_request.query["type"] == "def") is_def = true; if (is_def) view.set_variable("type", "def"); // Start off with default comparative resource. // Or keep the comparative resource now being constructed. bool clean_divider = true; - if (request->query.count ("title")) clean_divider = false; - if (request->query.count ("link")) clean_divider = false; - if (request->query.count ("foreground")) clean_divider = false; - if (request->query.count ("background")) clean_divider = false; - if (request->query.count ("foreground2")) clean_divider = false; - if (request->query.count ("background2")) clean_divider = false; - if (request->post.count ("entry")) clean_divider = false; - if (request->query.count ("add")) clean_divider = false; + if (webserver_request.query.count ("title")) clean_divider = false; + if (webserver_request.query.count ("link")) clean_divider = false; + if (webserver_request.query.count ("foreground")) clean_divider = false; + if (webserver_request.query.count ("background")) clean_divider = false; + if (webserver_request.query.count ("foreground2")) clean_divider = false; + if (webserver_request.query.count ("background2")) clean_divider = false; + if (webserver_request.post.count ("entry")) clean_divider = false; + if (webserver_request.query.count ("add")) clean_divider = false; if (clean_divider) Database_Volatile::setValue (userid, key, resource_logic_rich_divider()); @@ -113,41 +111,41 @@ string resource_divider (void * webserver_request) // The divider's title. - if (request->query.count ("title")) { + if (webserver_request.query.count ("title")) { Dialog_Entry dialog_entry = Dialog_Entry ("divider", translate("Please enter the title for the divider"), title, "title", ""); - if (is_def) dialog_entry.add_query ("type", request->query["type"]); + if (is_def) dialog_entry.add_query ("type", webserver_request.query["type"]); page += dialog_entry.run (); return page; } - if (request->post.count ("title")) { - title = request->post["entry"]; + if (webserver_request.post.count ("title")) { + title = webserver_request.post["entry"]; divider_edited = true; } // The divider's link. - if (request->query.count ("link")) { + if (webserver_request.query.count ("link")) { Dialog_Entry dialog_entry = Dialog_Entry ("divider", translate("Please enter the link for the divider"), link, "link", ""); - if (is_def) dialog_entry.add_query ("type", request->query["type"]); + if (is_def) dialog_entry.add_query ("type", webserver_request.query["type"]); page += dialog_entry.run (); return page; } - if (request->post.count ("link")) { - link = request->post["entry"]; + if (webserver_request.post.count ("link")) { + link = webserver_request.post["entry"]; divider_edited = true; } // The divider's text / foreground color. - if (request->query.count ("foreground")) { + if (webserver_request.query.count ("foreground")) { Dialog_Color dialog_color = Dialog_Color ("divider", translate("Please specify a new color")); dialog_color.add_query ("foreground2", "true"); - if (is_def) dialog_color.add_query ("type", request->query["type"]); + if (is_def) dialog_color.add_query ("type", webserver_request.query["type"]); page += dialog_color.run (); return page; } - if (request->query.count ("foreground2")) { - string color = request->query["color"]; + if (webserver_request.query.count ("foreground2")) { + string color = webserver_request.query["color"]; if (!color.empty()) { foreground = color; if (foreground.find ("#") == std::string::npos) foreground.insert (0, "#"); @@ -158,15 +156,15 @@ string resource_divider (void * webserver_request) // The divider's background color. - if (request->query.count ("background")) { + if (webserver_request.query.count ("background")) { Dialog_Color dialog_color = Dialog_Color ("divider", translate("Please specify a new color")); dialog_color.add_query ("background2", "true"); - if (is_def) dialog_color.add_query ("type", request->query["type"]); + if (is_def) dialog_color.add_query ("type", webserver_request.query["type"]); page += dialog_color.run (); return page; } - if (request->query.count ("background2")) { - string color = request->query["color"]; + if (webserver_request.query.count ("background2")) { + string color = webserver_request.query["color"]; if (!color.empty()) { background = color; if (background.find ("#") == std::string::npos) background.insert (0, "#"); @@ -184,14 +182,14 @@ string resource_divider (void * webserver_request) // Add it to the existing resources. - if (request->query.count ("add")) { - vector resources = request->database_config_user()->getActiveResources (); + if (webserver_request.query.count ("add")) { + vector resources = webserver_request.database_config_user()->getActiveResources (); if (is_def) resources = Database_Config_General::getDefaultActiveResources (); resources.push_back (divider); if (is_def) Database_Config_General::setDefaultActiveResources (resources); - else request->database_config_user()->setActiveResources (resources); - if (!is_def) request->database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization); - redirect_browser (request, resource_organize_url ()); + else webserver_request.database_config_user()->setActiveResources (resources); + if (!is_def) webserver_request.database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization); + redirect_browser (std::addressof(webserver_request), resource_organize_url ()); return ""; } diff --git a/resource/divider.h b/resource/divider.h index 11e1c2072..99197eab0 100644 --- a/resource/divider.h +++ b/resource/divider.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string resource_divider_url (); -bool resource_divider_acl (void * webserver_request); -std::string resource_divider (void * webserver_request); +bool resource_divider_acl (Webserver_Request& webserver_request); +std::string resource_divider (Webserver_Request& webserver_request); diff --git a/resource/translated1edit.cpp b/resource/translated1edit.cpp index e0972704e..1cea9d839 100644 --- a/resource/translated1edit.cpp +++ b/resource/translated1edit.cpp @@ -49,19 +49,16 @@ string resource_translated1edit_url () } -bool resource_translated1edit_acl (void * webserver_request) +bool resource_translated1edit_acl (Webserver_Request& webserver_request) { - return access_logic::privilege_view_resources (webserver_request); + return access_logic::privilege_view_resources (std::addressof(webserver_request)); } -string resource_translated1edit (void * webserver_request) +string resource_translated1edit (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - - string page {}; - Assets_Header header = Assets_Header (translate("Translated resource"), request); + Assets_Header header = Assets_Header (translate("Translated resource"), std::addressof(webserver_request)); header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ()); page = header.run (); Assets_View view {}; @@ -69,13 +66,13 @@ string resource_translated1edit (void * webserver_request) string success {}; - string name = request->query ["name"]; - if (name.empty()) name = request->post ["val1"]; + string name = webserver_request.query ["name"]; + if (name.empty()) name = webserver_request.post ["val1"]; view.set_variable ("name", name); - string checkbox = request->post ["checkbox"]; - bool checked = filter::strings::convert_to_bool (request->post ["checked"]); + string checkbox = webserver_request.post ["checkbox"]; + bool checked = filter::strings::convert_to_bool (webserver_request.post ["checked"]); bool resource_edited {false}; @@ -96,12 +93,12 @@ string resource_translated1edit (void * webserver_request) // The translated resource's original resource. - if (request->query.count ("original")) { - string value = request->query["original"]; + if (webserver_request.query.count ("original")) { + string value = webserver_request.query["original"]; if (value.empty()) { Dialog_List dialog_list = Dialog_List ("translated1edit", translate("Select a resource to be used as the original resource"), translate ("The original resource will be translated from the source language to the target language."), string()); dialog_list.add_query ("name", name); - vector resources = resource_logic_get_names (webserver_request, true); + vector resources = resource_logic_get_names (std::addressof(webserver_request), true); for (const auto & resource : resources) { dialog_list.add_row (resource, "original", resource); } @@ -115,8 +112,8 @@ string resource_translated1edit (void * webserver_request) // The language of the original resource. - if (request->query.count ("source")) { - string value = request->query["source"]; + if (webserver_request.query.count ("source")) { + string value = webserver_request.query["source"]; if (value.empty()) { Dialog_List dialog_list = Dialog_List ("translated1edit", translate("Select the language of the original resource"), translate ("The language the original resource is written in."), string()); dialog_list.add_query ("name", name); @@ -134,8 +131,8 @@ string resource_translated1edit (void * webserver_request) // The language to translate the resource into. - if (request->query.count ("target")) { - string value = request->query["target"]; + if (webserver_request.query.count ("target")) { + string value = webserver_request.query["target"]; if (value.empty()) { Dialog_List dialog_list = Dialog_List ("translated1edit", translate("Select the language to translate the resource into"), translate ("The language the resource will be translated into."), string()); dialog_list.add_query ("name", name); diff --git a/resource/translated1edit.h b/resource/translated1edit.h index c0ae8d6bf..563810203 100644 --- a/resource/translated1edit.h +++ b/resource/translated1edit.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string resource_translated1edit_url (); -bool resource_translated1edit_acl (void * webserver_request); -std::string resource_translated1edit (void * webserver_request); +bool resource_translated1edit_acl (Webserver_Request& webserver_request); +std::string resource_translated1edit (Webserver_Request& webserver_request); diff --git a/resource/translated9edit.cpp b/resource/translated9edit.cpp index 4920d32c7..42b7a4da0 100644 --- a/resource/translated9edit.cpp +++ b/resource/translated9edit.cpp @@ -54,19 +54,16 @@ string resource_translated9edit_url () } -bool resource_translated9edit_acl (void * webserver_request) +bool resource_translated9edit_acl (Webserver_Request& webserver_request) { - return Filter_Roles::access_control (webserver_request, Filter_Roles::manager ()); + return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::manager ()); } -string resource_translated9edit (void * webserver_request) +string resource_translated9edit (Webserver_Request& webserver_request) { - Webserver_Request * request = static_cast(webserver_request); - - string page; - Assets_Header header = Assets_Header (translate("Translated resources"), request); + Assets_Header header = Assets_Header (translate("Translated resources"), std::addressof(webserver_request)); header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ()); page = header.run (); Assets_View view; @@ -74,16 +71,16 @@ string resource_translated9edit (void * webserver_request) // New translated resource handler. - if (request->query.count ("new")) { + if (webserver_request.query.count ("new")) { Dialog_Entry dialog_entry = Dialog_Entry ("translated9edit", translate("Please enter a name for the new translated resource"), "", "new", ""); page += dialog_entry.run (); return page; } - if (request->post.count ("new")) { + if (webserver_request.post.count ("new")) { // The title for the new resource as entered by the user. // Clean the title up and ensure it always starts with "Translated ". // This word flags the translated resource as being one of that category. - string new_resource = request->post ["entry"]; + string new_resource = webserver_request.post ["entry"]; size_t pos = new_resource.find (resource_logic_translated_resource ()); if (pos != std::string::npos) { new_resource.erase (pos, resource_logic_translated_resource ().length()); @@ -112,16 +109,16 @@ string resource_translated9edit (void * webserver_request) client_logic_no_cache_resource_add (new_resource); // Redirect the user to the place where to edit that new resource. string url = resource_translated1edit_url () + "?name=" + new_resource; - redirect_browser (webserver_request, url); + redirect_browser (std::addressof(webserver_request), url); return string(); } } // Delete resource. - string title2remove = request->query ["delete"]; + string title2remove = webserver_request.query ["delete"]; if (!title2remove.empty()) { - string confirm = request->query ["confirm"]; + string confirm = webserver_request.query ["confirm"]; if (confirm.empty()) { Dialog_Yes dialog_yes = Dialog_Yes ("translated9edit", translate("Would you like to delete this resource?")); dialog_yes.add_query ("delete", title2remove); diff --git a/resource/translated9edit.h b/resource/translated9edit.h index 788ff75e9..3002ccda9 100644 --- a/resource/translated9edit.h +++ b/resource/translated9edit.h @@ -24,5 +24,5 @@ class Webserver_Request; std::string resource_translated9edit_url (); -bool resource_translated9edit_acl (void * webserver_request); -std::string resource_translated9edit (void * webserver_request); +bool resource_translated9edit_acl (Webserver_Request& webserver_request); +std::string resource_translated9edit (Webserver_Request& webserver_request); diff --git a/session/confirm.cpp b/session/confirm.cpp index a55d26a0f..2a1deaf60 100644 --- a/session/confirm.cpp +++ b/session/confirm.cpp @@ -51,47 +51,44 @@ const char * session_confirm_url () } -bool session_confirm_acl (void * webserver_request) +bool session_confirm_acl (Webserver_Request& webserver_request) { // Find the level of the user. // This confirmation page only allows access if the user is not yet logged in. // Such a situation produces level 1, that is the guest level. - Webserver_Request * request = static_cast(webserver_request); - int level = request->session_logic ()->currentLevel (); + int level = webserver_request.session_logic ()->currentLevel (); return (level == Filter_Roles::guest()); } -string session_confirm ([[maybe_unused]] void * webserver_request) +string session_confirm ([[maybe_unused]] Webserver_Request& webserver_request) { string page; #ifdef HAVE_CLOUD - Confirm_Worker confirm_worker = Confirm_Worker (webserver_request); + Confirm_Worker confirm_worker = Confirm_Worker (std::addressof(webserver_request)); string email; bool is_valid_confirmation = confirm_worker.handleLink (email); // Handle a valid confirmation. if (is_valid_confirmation) { - Webserver_Request * request = static_cast(webserver_request); - // Authenticate against local database, but skipping some checks. - if (request->session_logic()->attempt_login (email, "", true, true)) { + if (webserver_request.session_logic()->attempt_login (email, "", true, true)) { // Log the login. - Database_Logs::log (request->session_logic()->currentUser () + " confirmed account and logged in"); + Database_Logs::log (webserver_request.session_logic()->currentUser () + " confirmed account and logged in"); // Store web site's base URL. - string siteUrl = get_base_url (request); + string siteUrl = get_base_url (std::addressof(webserver_request)); Database_Config_General::setSiteURL (siteUrl); // Store account creation time. - user_logic_store_account_creation (request->session_logic()->currentUser ()); + user_logic_store_account_creation (webserver_request.session_logic()->currentUser ()); } } // In all cases, go to the home page. - redirect_browser (webserver_request, index_index_url()); + redirect_browser (std::addressof(webserver_request), index_index_url()); #endif diff --git a/session/confirm.h b/session/confirm.h index 2ea0a2e42..37b27f956 100644 --- a/session/confirm.h +++ b/session/confirm.h @@ -24,5 +24,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. class Webserver_Request; const char * session_confirm_url (); -bool session_confirm_acl (void * webserver_request); -std::string session_confirm (void * webserver_request); +bool session_confirm_acl (Webserver_Request& webserver_request); +std::string session_confirm (Webserver_Request& webserver_request);