Skip to content

Commit

Permalink
Clearer types in code rather than void pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Jan 5, 2024
1 parent 95ec384 commit 88df824
Show file tree
Hide file tree
Showing 35 changed files with 299 additions and 336 deletions.
64 changes: 32 additions & 32 deletions bootstrap/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions developer/delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions developer/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
50 changes: 24 additions & 26 deletions editone2/save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 *>(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");
}

Expand All @@ -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");
}

Expand All @@ -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
Expand All @@ -128,32 +126,32 @@ 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);
}


// 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 <Merge_Conflict> 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)) {
Expand All @@ -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 ();
}
Expand Down
4 changes: 2 additions & 2 deletions editone2/save.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Loading

0 comments on commit 88df824

Please sign in to comment.