diff --git a/checksum/logic.cpp b/checksum/logic.cpp index 21fceaf9f..b610684f1 100644 --- a/checksum/logic.cpp +++ b/checksum/logic.cpp @@ -62,20 +62,18 @@ string checksum_logic::get (const vector & data) // Returns a proper checksum for the USFM in the chapter. -string checksum_logic::get_chapter (void * webserver_request, const string & bible, int book, int chapter) +string checksum_logic::get_chapter (Webserver_Request& webserver_request, const string & bible, int book, int chapter) { - Webserver_Request * request = static_cast(webserver_request); - string usfm = request->database_bibles()->get_chapter (bible, book, chapter); + string usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter); string checksum = md5 (filter::strings::trim (usfm)); return checksum; } // Returns a proper checksum for the USFM in the book. -string checksum_logic::get_book (void * webserver_request, const string & bible, int book) +string checksum_logic::get_book (Webserver_Request& webserver_request, const string & bible, int book) { - Webserver_Request * request = static_cast(webserver_request); - vector chapters = request->database_bibles()->get_chapters (bible, book); + vector chapters = webserver_request.database_bibles()->get_chapters (bible, book); vector checksums; for (auto chapter : chapters) { checksums.push_back (get_chapter (webserver_request, bible, book, chapter)); @@ -87,10 +85,9 @@ string checksum_logic::get_book (void * webserver_request, const string & bible, // Returns a proper checksum for the USFM in the $bible. -string checksum_logic::get_bible (void * webserver_request, const string & bible) +string checksum_logic::get_bible (Webserver_Request& webserver_request, const string & bible) { - Webserver_Request * request = static_cast(webserver_request); - vector books = request->database_bibles()->get_books (bible); + vector books = webserver_request.database_bibles()->get_books (bible); vector checksums; for (auto book : books) { checksums.push_back (get_book (webserver_request, bible, book)); @@ -102,7 +99,7 @@ string checksum_logic::get_bible (void * webserver_request, const string & bible // Returns a proper checksum for the USFM in the array of $bibles. -string checksum_logic::get_bibles (void * webserver_request, const vector & bibles) +string checksum_logic::get_bibles (Webserver_Request& webserver_request, const vector & bibles) { vector checksums; for (const auto & bible : bibles) { diff --git a/checksum/logic.h b/checksum/logic.h index 8d13e2915..dbdc45035 100644 --- a/checksum/logic.h +++ b/checksum/logic.h @@ -21,14 +21,16 @@ #include +class Webserver_Request; + namespace checksum_logic { std::string send (const std::string & data, bool readwrite); std::string get (const std::string & data); std::string get (const std::vector & data); -std::string get_chapter (void * webserver_request, const std::string & bible, int book, int chapter); -std::string get_book (void * webserver_request, const std::string & bible, int book); -std::string get_bible (void * webserver_request, const std::string & bible); -std::string get_bibles (void * webserver_request, const std::vector & bibles); +std::string get_chapter (Webserver_Request& webserver_request, const std::string & bible, int book, int chapter); +std::string get_book (Webserver_Request& webserver_request, const std::string & bible, int book); +std::string get_bible (Webserver_Request& webserver_request, const std::string & bible); +std::string get_bibles (Webserver_Request& webserver_request, const std::vector & bibles); }; diff --git a/confirm/worker.cpp b/confirm/worker.cpp index cfbd2ad60..6d6db4a3c 100644 --- a/confirm/worker.cpp +++ b/confirm/worker.cpp @@ -45,9 +45,9 @@ using namespace pugi; #ifdef HAVE_CLOUD -Confirm_Worker::Confirm_Worker (void * webserver_request_in) +Confirm_Worker::Confirm_Worker (Webserver_Request& webserver_request): +m_webserver_request (webserver_request) { - webserver_request = webserver_request_in; } @@ -75,8 +75,7 @@ void Confirm_Worker::setup (string mailto, string username, } node.text ().set (information.c_str()); node = document.append_child ("p"); - Webserver_Request * request = static_cast(webserver_request); - string siteUrl = config::logic::site_url (*request); + string siteUrl = config::logic::site_url (m_webserver_request); string confirmation_url = filter_url_build_http_query (siteUrl + session_confirm_url (), "id", to_string(confirmation_id)); node.text ().set (confirmation_url.c_str()); stringstream output; @@ -100,8 +99,7 @@ bool Confirm_Worker::handleEmail ([[maybe_unused]]string from, string subject, s } // An active ID was found: Execute the associated database query. string query = database_confirm.get_query (id); - Webserver_Request * request = static_cast(webserver_request); - request->database_users()->execute (query); + m_webserver_request.database_users()->execute (query); // Send confirmation mail. string mailto = database_confirm.get_mail_to (id); subject = database_confirm.get_subject (id); @@ -121,8 +119,7 @@ bool Confirm_Worker::handleEmail ([[maybe_unused]]string from, string subject, s bool Confirm_Worker::handleLink (string & email) { // Get the confirmation identifier from the link that was clicked. - Webserver_Request * request = static_cast(webserver_request); - string web_id = request->query["id"]; + string web_id = m_webserver_request.query["id"]; // If the identifier was not given, the link was not handled successfully. if (web_id.empty()) return false; @@ -137,7 +134,7 @@ bool Confirm_Worker::handleLink (string & email) // An active ID was found: Execute the associated database query. string query = database_confirm.get_query (id); - request->database_users()->execute (query); + m_webserver_request.database_users()->execute (query); // Send confirmation mail. string mailto = database_confirm.get_mail_to (id); diff --git a/confirm/worker.h b/confirm/worker.h index 1634d116c..31be5bae6 100644 --- a/confirm/worker.h +++ b/confirm/worker.h @@ -21,12 +21,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include +class Webserver_Request; + #ifdef HAVE_CLOUD class Confirm_Worker { public: - Confirm_Worker (void * webserver_request_in); + Confirm_Worker (Webserver_Request& webserver_request); void setup (std::string mailto, std::string username, std::string initial_subject, std::string initial_body, std::string query, @@ -34,7 +36,7 @@ class Confirm_Worker bool handleEmail (std::string from, std::string subject, std::string body); bool handleLink (std::string & email); private: - void * webserver_request {nullptr}; + Webserver_Request& m_webserver_request; void informManagers (std::string email, std::string body); }; diff --git a/consistency/input.cpp b/consistency/input.cpp index d5796168d..5196b20d3 100644 --- a/consistency/input.cpp +++ b/consistency/input.cpp @@ -45,7 +45,7 @@ string consistency_input (Webserver_Request& webserver_request) const string translations = webserver_request.post ["translations"]; Database_Volatile::setValue (id, "passages", passages); Database_Volatile::setValue (id, "translations", translations); - Consistency_Logic consistency_logic (std::addressof(webserver_request), id); + Consistency_Logic consistency_logic (webserver_request, id); const string response = consistency_logic.response (); Database_Volatile::setValue (id, "response", response); return response; diff --git a/consistency/logic.cpp b/consistency/logic.cpp index 08a75b7ce..bb9600bd0 100644 --- a/consistency/logic.cpp +++ b/consistency/logic.cpp @@ -30,30 +30,26 @@ using namespace std; -Consistency_Logic::Consistency_Logic (void * webserver_request_in, int id_in) +Consistency_Logic::Consistency_Logic (Webserver_Request& webserver_request, int id) : +m_webserver_request (webserver_request), m_id (id) { - webserver_request = webserver_request_in; - id = id_in; } string Consistency_Logic::response () { - // The request. - Webserver_Request * request = static_cast(webserver_request); - // The resources to display in the Consistency tool. - vector resources = request->database_config_user()->getConsistencyResources (); - string bible = access_bible::clamp (*request, request->database_config_user()->getBible ()); + vector resources = m_webserver_request.database_config_user()->getConsistencyResources (); + string bible = access_bible::clamp (m_webserver_request, m_webserver_request.database_config_user()->getBible ()); resources.insert (resources.begin (), bible); // The passages entered in the Consistency tool. - string s_passages = Database_Volatile::getValue (id, "passages"); + string s_passages = Database_Volatile::getValue (m_id, "passages"); s_passages = filter::strings::trim (s_passages); vector passages = filter::strings::explode (s_passages, '\n'); // The translations entered in the Consistency tool. - string s_translations = Database_Volatile::getValue (id, "translations"); + string s_translations = Database_Volatile::getValue (m_id, "translations"); s_translations = filter::strings::trim (s_translations); vector translations = filter::strings::explode (s_translations, '\n'); @@ -88,10 +84,10 @@ string Consistency_Logic::response () // If there was no change, then the data can be fetched from the volatile database. bool redoPassage = false; string passageKey = filter::strings::convert_to_string (book) + "." + filter::strings::convert_to_string (chapter) + "." + verse; - int currentChapterId = request->database_bibles()->get_chapter_id (resources [0], book, chapter); - int storedChapterId = filter::strings::convert_to_int (Database_Volatile::getValue (id, passageKey + ".id")); + int currentChapterId = m_webserver_request.database_bibles()->get_chapter_id (resources [0], book, chapter); + int storedChapterId = filter::strings::convert_to_int (Database_Volatile::getValue (m_id, passageKey + ".id")); if (currentChapterId != storedChapterId) { - Database_Volatile::setValue (id, passageKey + ".id", filter::strings::convert_to_string (currentChapterId)); + Database_Volatile::setValue (m_id, passageKey + ".id", filter::strings::convert_to_string (currentChapterId)); redoPassage = true; } @@ -111,9 +107,9 @@ string Consistency_Logic::response () text.insert (0, R"(
)"); text.append ("
"); } - Database_Volatile::setValue (id, passageKey + "." + resource, text); + Database_Volatile::setValue (m_id, passageKey + "." + resource, text); } else { - text = Database_Volatile::getValue (id, passageKey + "." + resource); + text = Database_Volatile::getValue (m_id, passageKey + "." + resource); } // Formatting. @@ -140,7 +136,7 @@ string Consistency_Logic::response () string Consistency_Logic::verseText (string resource, int book, int chapter, int verse) { - return resource_logic_get_html (webserver_request, resource, book, chapter, verse, false); + return resource_logic_get_html (std::addressof(m_webserver_request), resource, book, chapter, verse, false); } diff --git a/consistency/logic.h b/consistency/logic.h index 92940b716..e0b2551f1 100644 --- a/consistency/logic.h +++ b/consistency/logic.h @@ -21,14 +21,16 @@ #include +class Webserver_Request; + class Consistency_Logic { public: - Consistency_Logic (void * webserver_request_in, int id_in); + Consistency_Logic (Webserver_Request& webserver_request, int id); std::string response (); private: - void * webserver_request {nullptr}; - int id {0}; + Webserver_Request& m_webserver_request; + int m_id {0}; std::string verseText (std::string resource, int book, int chapter, int verse); std::string omit_verse_text (std::string input); }; diff --git a/consistency/poll.cpp b/consistency/poll.cpp index bf962a811..404db0781 100644 --- a/consistency/poll.cpp +++ b/consistency/poll.cpp @@ -41,7 +41,7 @@ bool consistency_poll_acl (Webserver_Request& webserver_request) string consistency_poll (Webserver_Request& webserver_request) { const int id = filter::strings::convert_to_int (webserver_request.query ["id"]); - Consistency_Logic consistency_logic = Consistency_Logic (std::addressof(webserver_request), id); + Consistency_Logic consistency_logic = Consistency_Logic (webserver_request, id); const string response = consistency_logic.response (); if (response != Database_Volatile::getValue (id, "response")) { Database_Volatile::setValue (id, "response", response); diff --git a/database/config/user.cpp b/database/config/user.cpp index e3f38b3ab..75401860a 100644 --- a/database/config/user.cpp +++ b/database/config/user.cpp @@ -34,9 +34,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. using namespace std; -Database_Config_User::Database_Config_User (void * webserver_request_in) +Database_Config_User::Database_Config_User (Webserver_Request& webserver_request): +m_webserver_request (webserver_request) { - webserver_request = webserver_request_in; } @@ -70,8 +70,7 @@ string Database_Config_User::mapkey (string user, const char * key) string Database_Config_User::getValue (const char * key, const char * default_value) { - Webserver_Request * request = static_cast(webserver_request); - string user = request->session_logic ()->currentUser (); + string user = m_webserver_request.session_logic ()->currentUser (); return getValueForUser (user, key, default_value); } @@ -125,8 +124,7 @@ int Database_Config_User::getIValueForUser (string user, const char * key, int d void Database_Config_User::setValue (const char * key, string value) { - Webserver_Request * request = static_cast(webserver_request); - string user = request->session_logic ()->currentUser (); + string user = m_webserver_request.session_logic ()->currentUser (); setValueForUser (user, key, value); } @@ -163,8 +161,7 @@ void Database_Config_User::setBValueForUser (string user, const char * key, bool vector Database_Config_User::getList (const char * key) { - Webserver_Request * request = static_cast(webserver_request); - string user = request->session_logic ()->currentUser (); + string user = m_webserver_request.session_logic ()->currentUser (); return getListForUser (user, key); } @@ -193,8 +190,7 @@ vector Database_Config_User::getListForUser (string user, const char * void Database_Config_User::setList (const char * key, vector values) { - Webserver_Request * request = static_cast(webserver_request); - string user = request->session_logic ()->currentUser (); + string user = m_webserver_request.session_logic ()->currentUser (); setListForUser (user, key, values); } @@ -283,8 +279,7 @@ string Database_Config_User::getBible () { string bible = getValue ("bible", ""); // If the Bible does not exist, take the first one available. - Webserver_Request * request = static_cast(webserver_request); - Database_Bibles * database_bibles = request->database_bibles (); + Database_Bibles * database_bibles = m_webserver_request.database_bibles (); vector bibles = database_bibles->get_bibles (); if (find (bibles.begin (), bibles.end (), bible) == bibles.end ()) { // There may not even be a first Bible: Create sample Bible. @@ -550,8 +545,7 @@ bool Database_Config_User::defaultBibleChecksNotification () #ifdef HAVE_CLIENT return false; #else - Webserver_Request * request = static_cast(webserver_request); - int level = request->session_logic ()->currentLevel (); + int level = m_webserver_request.session_logic ()->currentLevel (); return (level >= Filter_Roles::translator () && level <= Filter_Roles::manager ()); #endif } @@ -1176,8 +1170,7 @@ bool Database_Config_User::getBasicInterfaceModeDefault () return true; #endif // The app running on a workspace or laptop have default to basic mode for a lower role. - Webserver_Request * request = static_cast(webserver_request); - int level = request->session_logic ()->currentLevel (); + int level = m_webserver_request.session_logic ()->currentLevel (); if (level <= Filter_Roles::manager ()) return true; // Higher role: default to advanced mode. return false; diff --git a/database/config/user.h b/database/config/user.h index 43106c389..3b6b3f39a 100644 --- a/database/config/user.h +++ b/database/config/user.h @@ -22,10 +22,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include +class Webserver_Request; + class Database_Config_User { public: - Database_Config_User (void * webserver_request_in); + Database_Config_User (Webserver_Request& webserver_request); void trim (); void remove (std::string username); void clear_cache (); @@ -245,7 +247,7 @@ class Database_Config_User std::vector getChangeNotificationsBiblesForUser (const std::string & user); void setChangeNotificationsBibles (const std::vector & values); private: - void * webserver_request {nullptr}; + Webserver_Request& m_webserver_request; std::string file (std::string user); std::string file (std::string user, const char * key); std::string mapkey (std::string user, const char * key); diff --git a/database/maintenance.cpp b/database/maintenance.cpp index 57b40d068..ce3981df0 100644 --- a/database/maintenance.cpp +++ b/database/maintenance.cpp @@ -121,7 +121,7 @@ void database_maintenance () database_jobs.optimize (); - Database_Config_User database_config_user = Database_Config_User (&webserver_request); + Database_Config_User database_config_user (webserver_request); database_config_user.trim (); diff --git a/email/receive.cpp b/email/receive.cpp index fb90865b5..7092956c8 100644 --- a/email/receive.cpp +++ b/email/receive.cpp @@ -51,7 +51,7 @@ void email_receive () for (int i = 1; i <= emailcount; i++) { Webserver_Request webserver_request; - Confirm_Worker confirm_worker = Confirm_Worker (&webserver_request); + Confirm_Worker confirm_worker = (webserver_request); Notes_Logic notes_logic (webserver_request); error.clear (); diff --git a/library/bibledit.cpp b/library/bibledit.cpp index 824b9f607..ac771c908 100644 --- a/library/bibledit.cpp +++ b/library/bibledit.cpp @@ -418,7 +418,7 @@ const char * bibledit_get_reference_for_accordance () // Get the active Bible and its versification system. Webserver_Request webserver_request; webserver_request.session_logic()->set_username(user); - Database_Config_User database_config_user (&webserver_request); + Database_Config_User database_config_user (webserver_request); string bible = webserver_request.database_config_user ()->getBible (); string versification = Database_Config_Bible::getVersificationSystem (bible); @@ -474,7 +474,7 @@ void bibledit_put_reference_from_accordance (const char * reference) int verse = filter::strings::convert_to_int(chapter_verse[1]); // Get the active Bible and its versification system. - Database_Config_User database_config_user (&webserver_request); + Database_Config_User database_config_user (webserver_request); string bible = webserver_request.database_config_user ()->getBible (); string versification = Database_Config_Bible::getVersificationSystem (bible); diff --git a/notes/logic.cpp b/notes/logic.cpp index 81c78868e..f48c2ce8a 100644 --- a/notes/logic.cpp +++ b/notes/logic.cpp @@ -327,7 +327,7 @@ void Notes_Logic::handlerAssignNote (int identifier, const string& user) // Take no action in client mode. if (client_logic_client_enabled ()) return; - Database_Config_User database_config_user (std::addressof(m_webserver_request)); + Database_Config_User database_config_user (m_webserver_request); if (database_config_user.getUserAssignedConsultationNoteNotification (user)) { // Only email the user if the user was not yet assigned this note. Database_Notes database_notes (m_webserver_request); diff --git a/sendreceive/bibles.cpp b/sendreceive/bibles.cpp index 87b799acd..f58b325c2 100644 --- a/sendreceive/bibles.cpp +++ b/sendreceive/bibles.cpp @@ -88,8 +88,8 @@ void sendreceive_bibles () Database_Logs::log (sendreceive_bibles_sendreceive_text (), Filter_Roles::translator ()); - Webserver_Request request; - Sync_Logic sync_logic = Sync_Logic (&request); + Webserver_Request webserver_request; + Sync_Logic sync_logic = Sync_Logic (&webserver_request); string response = client_logic_connection_setup ("", ""); @@ -102,15 +102,15 @@ void sendreceive_bibles () // Set the correct user in the session: The sole user on the Client. - vector users = request.database_users ()->get_users (); + vector users = webserver_request.database_users ()->get_users (); if (users.empty ()) { Database_Logs::log (translate("No user found"), Filter_Roles::translator ()); send_receive_bibles_done (); return; } string user = users [0]; - request.session_logic ()->set_username (user); - string password = request.database_users ()->get_md5 (user); + webserver_request.session_logic ()->set_username (user); + string password = webserver_request.database_users ()->get_md5 (user); // The basic request to be POSTed to the server. @@ -118,7 +118,7 @@ void sendreceive_bibles () map post; post ["u"] = filter::strings::bin2hex (user); post ["p"] = password; - post ["l"] = filter::strings::convert_to_string (request.database_users ()->get_level (user)); + post ["l"] = filter::strings::convert_to_string (webserver_request.database_users ()->get_level (user)); // Error variable. @@ -151,7 +151,7 @@ void sendreceive_bibles () // Get old and new USFM for this chapter. string oldusfm = database_bibleactions.getUsfm (bible, book, chapter); - string newusfm = request.database_bibles()->get_chapter (bible, book, chapter); + string newusfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter); // Straightaway clear the Bible action for this chapter. // This atomic operation enables new edits from the user in this chapter to be recorded straightaway, @@ -165,7 +165,7 @@ void sendreceive_bibles () string checksum = checksum_logic::get (oldusfm + newusfm); - // Generate a POST request. + // Generate a POST webserver_request. map sendpost = post; sendpost ["a"] = filter::strings::convert_to_string (Sync_Logic::bibles_send_chapter); sendpost ["b"] = bible; @@ -247,8 +247,8 @@ void sendreceive_bibles () // that the client username has access to via its credentials. // The client compares the two checksums. // If they match, it means everything is in sync. - bibles = request.database_bibles()->get_bibles (); - string client_checksum = checksum_logic::get_bibles (&request, bibles); + bibles = webserver_request.database_bibles()->get_bibles (); + string client_checksum = checksum_logic::get_bibles (webserver_request, bibles); post ["a"] = filter::strings::convert_to_string (Sync_Logic::bibles_get_total_checksum); string server_checksum = sync_logic.post (post, url, error); if (!error.empty ()) { @@ -292,7 +292,7 @@ void sendreceive_bibles () // The client now has a list of Bibles the user has access to on the server. - bibles = request.database_bibles()->get_bibles (); + bibles = webserver_request.database_bibles()->get_bibles (); bibles = filter::strings::array_diff (bibles, v_server_bibles); if (first_sync_after_connect) { // At the first synchronize action after the user connected to the Cloud, @@ -302,9 +302,9 @@ void sendreceive_bibles () // This would be undesired behaviour. Skip it. for (auto bible : bibles) { if (bible == demo_sample_bible_name ()) continue; - vector books = request.database_bibles()->get_books (bible); + vector books = webserver_request.database_bibles()->get_books (bible); for (auto book : books) { - vector chapters = request.database_bibles()->get_chapters (bible, book); + vector chapters = webserver_request.database_bibles()->get_chapters (bible, book); for (auto chapter : chapters) { database_bibleactions.record (bible, book, chapter, ""); } @@ -314,7 +314,7 @@ void sendreceive_bibles () // The client deletes any local Bible not available from the server. // It does not record change Bible actions for this operation. for (string bible : bibles) { - request.database_bibles()->delete_bible (bible); + webserver_request.database_bibles()->delete_bible (bible); DatabasePrivileges::remove_bible (bible); Database_Config_Bible::remove (bible); Database_Logs::log (sendreceive_bibles_text () + translate("Deleting Bible because the server did not grant access to it") + ": " + bible, Filter_Roles::translator ()); @@ -328,7 +328,7 @@ void sendreceive_bibles () // Compare the checksum of the whole Bible on client and server // to see if this Bible is in sync. - string client_checksum_bible = checksum_logic::get_bible (&request, bible); + string client_checksum_bible = checksum_logic::get_bible (webserver_request, bible); post ["a"] = filter::strings::convert_to_string (Sync_Logic::bibles_get_bible_checksum); post ["b"] = bible; string server_checksum_bible = sync_logic.post (post, url, error); @@ -344,7 +344,7 @@ void sendreceive_bibles () // Request all books in the $bible on the server. - vector client_books = request.database_bibles()->get_books (bible); + vector client_books = webserver_request.database_bibles()->get_books (bible); post ["a"] = filter::strings::convert_to_string (Sync_Logic::bibles_get_books); string server_books = sync_logic.post (post, url, error); if (!error.empty () || server_books.empty ()) { @@ -374,7 +374,7 @@ void sendreceive_bibles () // any books on the client and not on the server, // schedule them for upload to the Cloud. for (auto book : client_books) { - vector chapters = request.database_bibles()->get_chapters (bible, book); + vector chapters = webserver_request.database_bibles()->get_chapters (bible, book); for (auto & chapter : chapters) { database_bibleactions.record (bible, book, chapter, ""); } @@ -384,7 +384,7 @@ void sendreceive_bibles () // But for more robustness while connected to a very bad network, the client will remove only one book at a time. if (!client_books.empty ()) { int book = client_books [0]; - request.database_bibles()->delete_book (bible, book); + webserver_request.database_bibles()->delete_book (bible, book); string book_name = database::books::get_english_from_id (static_cast(book)); Database_Logs::log (sendreceive_bibles_text () + translate("Deleting book because the server does not have it") + ": " + bible + " " + book_name , Filter_Roles::translator ()); } @@ -399,7 +399,7 @@ void sendreceive_bibles () // Compare the checksum for the whole book on the client with the same on the server to see if this book is in sync. - string client_checksum_book = checksum_logic::get_book (&request, bible, book); + string client_checksum_book = checksum_logic::get_book (webserver_request, bible, book); post ["a"] = filter::strings::convert_to_string (Sync_Logic::bibles_get_book_checksum); post ["bk"] = filter::strings::convert_to_string (book); string server_checksum_book = sync_logic.post (post, url, error); @@ -414,7 +414,7 @@ void sendreceive_bibles () // The client requests all chapters per book from the server. - vector client_chapters = request.database_bibles()->get_chapters (bible, book); + vector client_chapters = webserver_request.database_bibles()->get_chapters (bible, book); post ["a"] = filter::strings::convert_to_string (Sync_Logic::bibles_get_chapters); string server_chapters = sync_logic.post (post, url, error); if (!error.empty () || server_chapters.empty ()) { @@ -450,7 +450,7 @@ void sendreceive_bibles () // If necessary it will delete another one during next sync operation. if (!client_chapters.empty ()) { int chapter = client_chapters [0]; - request.database_bibles()->delete_chapter (bible, book, chapter); + webserver_request.database_bibles()->delete_chapter (bible, book, chapter); Database_Logs::log (sendreceive_bibles_text () + translate("Deleting chapter because the server does not have it") + ": " + bible + " " + book_name + " " + filter::strings::convert_to_string (chapter), Filter_Roles::translator ()); } } @@ -471,7 +471,7 @@ void sendreceive_bibles () // Get checksum for the chapter on client and on server. // If both are the same, it means the USFM in both is the same, and we're done. - string client_checksum_chapter = checksum_logic::get_chapter (&request, bible, book, chapter); + string client_checksum_chapter = checksum_logic::get_chapter (webserver_request, bible, book, chapter); post ["a"] = filter::strings::convert_to_string (Sync_Logic::bibles_get_chapter_checksum); post ["c"] = filter::strings::convert_to_string (chapter); string server_checksum_chapter = sync_logic.post (post, url, error); @@ -515,7 +515,7 @@ void sendreceive_bibles () // If there are none, then the client stores the chapter as it gets it from the server, and is done. string old_usfm = database_bibleactions.getUsfm (bible, book, chapter); if (old_usfm.empty ()) { - request.database_bibles()->store_chapter (bible, book, chapter, server_usfm); + webserver_request.database_bibles()->store_chapter (bible, book, chapter, server_usfm); continue; } @@ -529,7 +529,7 @@ void sendreceive_bibles () // The changes will be sent to the server during the next synchronize action. vector conflicts; Database_Logs::log (sendreceive_bibles_text () + translate("Merging changes on server and client") + " " + bible + " " + book_name + " " + filter::strings::convert_to_string (chapter), Filter_Roles::translator ()); - string client_usfm = request.database_bibles()->get_chapter (bible, book, chapter); + string client_usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter); string merged_usfm = filter_merge_run (old_usfm, client_usfm, server_usfm, true, conflicts); filter_merge_add_book_chapter (conflicts, book, chapter); bible_logic::merge_irregularity_mail ( { user }, conflicts); diff --git a/session/confirm.cpp b/session/confirm.cpp index 379c72f60..cb0790d7a 100644 --- a/session/confirm.cpp +++ b/session/confirm.cpp @@ -67,7 +67,7 @@ string session_confirm ([[maybe_unused]] Webserver_Request& webserver_request) #ifdef HAVE_CLOUD - Confirm_Worker confirm_worker = Confirm_Worker (std::addressof(webserver_request)); + Confirm_Worker confirm_worker = (webserver_request); string email; bool is_valid_confirmation = confirm_worker.handleLink (email); diff --git a/session/signup.cpp b/session/signup.cpp index ade1539ff..b57292c5d 100644 --- a/session/signup.cpp +++ b/session/signup.cpp @@ -235,7 +235,7 @@ std::string session_signup ([[maybe_unused]] Webserver_Request& webserver_reques } } if (form_is_valid) { - Confirm_Worker confirm_worker = Confirm_Worker (std::addressof(webserver_request)); + Confirm_Worker confirm_worker (webserver_request); const std::string initial_subject = translate("Signup verification"); // Create the initial body of the email to send to the new user. pugi::xml_node node; diff --git a/sync/bibles.cpp b/sync/bibles.cpp index ef882d97e..9efd3480a 100644 --- a/sync/bibles.cpp +++ b/sync/bibles.cpp @@ -177,7 +177,7 @@ string sync_bibles (Webserver_Request& webserver_request) // and returns this checksum to the client. string username = webserver_request.session_logic ()->currentUser (); vector bibles = access_bible::bibles (webserver_request, username); - string server_checksum = checksum_logic::get_bibles (std::addressof(webserver_request), bibles); + string server_checksum = checksum_logic::get_bibles (webserver_request, bibles); return server_checksum; } case Sync_Logic::bibles_get_bibles: @@ -193,7 +193,7 @@ string sync_bibles (Webserver_Request& webserver_request) case Sync_Logic::bibles_get_bible_checksum: { // The server responds with the checksum for the whole Bible. - return checksum_logic::get_bible (std::addressof(webserver_request), bible); + return checksum_logic::get_bible (webserver_request, bible); } case Sync_Logic::bibles_get_books: { @@ -208,7 +208,7 @@ string sync_bibles (Webserver_Request& webserver_request) case Sync_Logic::bibles_get_book_checksum: { // The server responds with the checksum of the whole book. - return checksum_logic::get_book (std::addressof(webserver_request), bible, book); + return checksum_logic::get_book (webserver_request, bible, book); } case Sync_Logic::bibles_get_chapters: { @@ -223,7 +223,7 @@ string sync_bibles (Webserver_Request& webserver_request) case Sync_Logic::bibles_get_chapter_checksum: { // The server responds with the checksum of the whole chapter. - return checksum_logic::get_chapter (std::addressof(webserver_request), bible, book, chapter); + return checksum_logic::get_chapter (webserver_request, bible, book, chapter); } case Sync_Logic::bibles_send_chapter: { diff --git a/unittests/checksum.cpp b/unittests/checksum.cpp index 4aea7cb18..bc6b2b2a3 100644 --- a/unittests/checksum.cpp +++ b/unittests/checksum.cpp @@ -59,50 +59,50 @@ TEST (checksum, basic) // Setup some data. refresh_sandbox (true); Database_State::create (); - Webserver_Request request; - request.database_bibles()->store_chapter ("phpunit1", 1, 2, "data1"); - request.database_bibles()->store_chapter ("phpunit1", 1, 3, "data2"); - request.database_bibles()->store_chapter ("phpunit1", 1, 4, "data3"); - request.database_bibles()->store_chapter ("phpunit2", 2, 5, "data4"); + Webserver_Request webserver_request; + webserver_request.database_bibles()->store_chapter ("phpunit1", 1, 2, "data1"); + webserver_request.database_bibles()->store_chapter ("phpunit1", 1, 3, "data2"); + webserver_request.database_bibles()->store_chapter ("phpunit1", 1, 4, "data3"); + webserver_request.database_bibles()->store_chapter ("phpunit2", 2, 5, "data4"); // GetChapter1 { - const std::string checksum = checksum_logic::get_chapter (&request, "phpunit1", 1, 2); + const std::string checksum = checksum_logic::get_chapter (webserver_request, "phpunit1", 1, 2); EXPECT_EQ (md5 ("data1"), checksum); } // GetChapter2 { - const std::string checksum = checksum_logic::get_chapter (&request, "phpunit2", 2, 6); + const std::string checksum = checksum_logic::get_chapter (webserver_request, "phpunit2", 2, 6); EXPECT_EQ (md5 (""), checksum); } // GetBook1 { - const std::string checksum = checksum_logic::get_book (&request, "phpunit1", 1); + const std::string checksum = checksum_logic::get_book (webserver_request, "phpunit1", 1); EXPECT_EQ ("2ab6425924e6cd38b2474c543c5ea602", checksum); } // GetBook2 { - const std::string checksum = checksum_logic::get_book (&request, "phpunit3", 1); + const std::string checksum = checksum_logic::get_book (webserver_request, "phpunit3", 1); EXPECT_EQ ("d41d8cd98f00b204e9800998ecf8427e", checksum); } // GetBible1 { - const std::string checksum = checksum_logic::get_bible (&request, "phpunit1"); + const std::string checksum = checksum_logic::get_bible (webserver_request, "phpunit1"); EXPECT_EQ ("f9dc679a8712eb6f65b584e9688e9680", checksum); } // GetBible2 { - const std::string checksum = checksum_logic::get_bible (&request, "phpunit2"); + const std::string checksum = checksum_logic::get_bible (webserver_request, "phpunit2"); EXPECT_EQ ("ee84a85bac14adb35e887c3d89bc80ab", checksum); } // GetBibles1 { - const std::string checksum = checksum_logic::get_bibles (&request, {"phpunit1", "phpunit2"}); + const std::string checksum = checksum_logic::get_bibles (webserver_request, {"phpunit1", "phpunit2"}); EXPECT_EQ ("440b2008993816f0bc8c557b64fbdaf2", checksum); } // GetBibles2 { - const std::string checksum = checksum_logic::get_bibles (&request, {"phpunit3", "phpunit4"}); + const std::string checksum = checksum_logic::get_bibles (webserver_request, {"phpunit3", "phpunit4"}); EXPECT_EQ ("020eb29b524d7ba672d9d48bc72db455", checksum); } } diff --git a/user/account.cpp b/user/account.cpp index 5d9e39906..d5bd5f483 100644 --- a/user/account.cpp +++ b/user/account.cpp @@ -103,7 +103,7 @@ string user_account ([[maybe_unused]] Webserver_Request& webserver_request) view.set_variable ("current_password_invalid_message", translate("Current password is not valid")); } if (form_is_valid) { - Confirm_Worker confirm_worker = Confirm_Worker (std::addressof(webserver_request)); + Confirm_Worker confirm_worker (webserver_request); string initial_subject = translate("Email address verification"); string initial_body = translate("Somebody requested to change the email address that belongs to your account."); string query = webserver_request.database_users()->updateEmailQuery (username, newemail); diff --git a/user/logic.cpp b/user/logic.cpp index 51fbfeadc..7b2ed191a 100644 --- a/user/logic.cpp +++ b/user/logic.cpp @@ -125,7 +125,8 @@ void user_logic_delete_account (string user, string role, string email, string & // Remove any settings for the user. // The advantage of this is that when a user is removed, all settings are gone, // so when the same user would be created again, all settings will go back to their defaults. - Database_Config_User database_config_user (nullptr); + Webserver_Request webserver_request; + Database_Config_User database_config_user (webserver_request); database_config_user.remove (user); // Remove note assignments for clients for this user. Database_NoteAssignment database_noteassignment; diff --git a/user/notifications.cpp b/user/notifications.cpp index 6c68e9ff6..bb1070b96 100644 --- a/user/notifications.cpp +++ b/user/notifications.cpp @@ -62,7 +62,7 @@ bool user_notifications_acl (Webserver_Request& webserver_request) string user_notifications (Webserver_Request& webserver_request) { - Database_Config_User database_config_user = Database_Config_User (std::addressof(webserver_request)); + Database_Config_User database_config_user (webserver_request); Database_NoteAssignment database_noteassignment; string page; diff --git a/webserver/request.cpp b/webserver/request.cpp index 535064dee..aa3bb0c3a 100644 --- a/webserver/request.cpp +++ b/webserver/request.cpp @@ -58,7 +58,7 @@ Session_Logic * Webserver_Request::session_logic () Database_Config_User * Webserver_Request::database_config_user () { // Single live object during the entire web request. - if (!database_config_user_instance) database_config_user_instance = new Database_Config_User (this); + if (!database_config_user_instance) database_config_user_instance = new Database_Config_User (*this); return database_config_user_instance; }