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 4, 2024
1 parent d5e76e6 commit 95ec384
Show file tree
Hide file tree
Showing 122 changed files with 1,020 additions and 1,107 deletions.
9 changes: 3 additions & 6 deletions assets/external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ string assets_external_url ()
}


string assets_external (void * webserver_request)
string assets_external (Webserver_Request& webserver_request)
{
// The request from the client.
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

// Whether a URL was POSTed, that is, whether it was clicked by the user.
string href = request->post ["href"];
string href = webserver_request.post ["href"];
if (!href.empty ()) {
config_globals_external_url = request->post ["href"];
config_globals_external_url = webserver_request.post ["href"];
return string();
}

Expand Down
4 changes: 3 additions & 1 deletion assets/external.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include <config/libraries.h>

class Webserver_Request;

std::string assets_external_url ();
std::string assets_external (void * webserver_request);
std::string assets_external (Webserver_Request& webserver_request);

std::string assets_external_logic_link_addon ();
233 changes: 105 additions & 128 deletions bootstrap/bootstrap.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion changes/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ string changes_interlinks (void * webserver_request, string my_url)

string revisions = "revisions";
if (index_listing_url (revisions) != my_url) {
if (index_listing_acl (webserver_request, revisions)) {
if (index_listing_acl (*request, revisions)) {
urls.push_back (index_listing_url (revisions));
labels.push_back (translate ("Download"));
}
Expand Down
17 changes: 7 additions & 10 deletions checks/settingspairs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,32 @@ string checks_settingspairs_url ()
}


bool checks_settingspairs_acl ([[maybe_unused]] void * webserver_request)
bool checks_settingspairs_acl ([[maybe_unused]] Webserver_Request& webserver_request)
{
#ifdef HAVE_CLIENT
return true;
#else
return Filter_Roles::access_control (webserver_request, Filter_Roles::manager ());
return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::manager ());
#endif
}


string checks_settingspairs (void * webserver_request)
string checks_settingspairs (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);


string page {};
Assets_Header header = Assets_Header (translate ("Matching pairs"), webserver_request);
Assets_Header header = Assets_Header (translate ("Matching pairs"), std::addressof(webserver_request));
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (checks_settings_url (), menu_logic_checks_settings_text ());
page = header.run ();
Assets_View view {};


string bible = access_bible::clamp (webserver_request, request->database_config_user()->getBible ());
string bible = access_bible::clamp (std::addressof(webserver_request), webserver_request.database_config_user()->getBible ());
view.set_variable ("bible", bible);


if (request->post.count ("pairs")) {
string fragment = request->post["pairs"];
if (webserver_request.post.count ("pairs")) {
string fragment = webserver_request.post["pairs"];
vector <string> errors {};
vector <string> pairs = filter::strings::explode (fragment, ' ');
bool okay {true};
Expand Down
4 changes: 2 additions & 2 deletions checks/settingspairs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string checks_settingspairs_url ();
bool checks_settingspairs_acl (void * webserver_request);
std::string checks_settingspairs (void * webserver_request);
bool checks_settingspairs_acl (Webserver_Request& webserver_request);
std::string checks_settingspairs (Webserver_Request& webserver_request);
17 changes: 7 additions & 10 deletions checks/settingspatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,31 @@ string checks_settingspatterns_url ()
}


bool checks_settingspatterns_acl ([[maybe_unused]] void * webserver_request)
bool checks_settingspatterns_acl ([[maybe_unused]] Webserver_Request& webserver_request)
{
#ifdef HAVE_CLIENT
return true;
#else
return Filter_Roles::access_control (webserver_request, Filter_Roles::manager ());
return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::manager ());
#endif
}


string checks_settingspatterns (void * webserver_request)
string checks_settingspatterns (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);


string page {};
Assets_Header header = Assets_Header (translate ("Patterns"), webserver_request);
Assets_Header header = Assets_Header (translate ("Patterns"), std::addressof(webserver_request));
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (checks_settings_url (), menu_logic_checks_settings_text ());
page = header.run ();
Assets_View view {};


string bible = access_bible::clamp (webserver_request, request->database_config_user()->getBible ());
string bible = access_bible::clamp (std::addressof(webserver_request), webserver_request.database_config_user()->getBible ());


if (request->post.count ("patterns")) {
string patterns = request->post ["patterns"];
if (webserver_request.post.count ("patterns")) {
string patterns = webserver_request.post ["patterns"];
if (!bible.empty ()) Database_Config_Bible::setCheckingPatterns (bible, patterns);
view.set_variable ("success", translate("The patterns were saved"));
}
Expand Down
4 changes: 2 additions & 2 deletions checks/settingspatterns.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string checks_settingspatterns_url ();
bool checks_settingspatterns_acl (void * webserver_request);
std::string checks_settingspatterns (void * webserver_request);
bool checks_settingspatterns_acl (Webserver_Request& webserver_request);
std::string checks_settingspatterns (Webserver_Request& webserver_request);
41 changes: 19 additions & 22 deletions checks/settingssentences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,70 +44,67 @@ string checks_settingssentences_url ()
}


bool checks_settingssentences_acl ([[maybe_unused]] void * webserver_request)
bool checks_settingssentences_acl ([[maybe_unused]] Webserver_Request& webserver_request)
{
#ifdef HAVE_CLIENT
return true;
#else
return Filter_Roles::access_control (webserver_request, Filter_Roles::manager ());
return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::manager ());
#endif
}


string checks_settingssentences (void * webserver_request)
string checks_settingssentences (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);


string page {};
Assets_Header header = Assets_Header (translate ("Sentence Structure"), webserver_request);
Assets_Header header = Assets_Header (translate ("Sentence Structure"), std::addressof(webserver_request));
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
header.add_bread_crumb (checks_settings_url (), menu_logic_checks_settings_text ());
page = header.run ();
Assets_View view {};


string bible = access_bible::clamp (webserver_request, request->database_config_user()->getBible ());
string bible = access_bible::clamp (std::addressof(webserver_request), webserver_request.database_config_user()->getBible ());


if (request->post.count ("capitals")) {
Database_Config_Bible::setSentenceStructureCapitals (bible, request->post["capitals"]);
if (webserver_request.post.count ("capitals")) {
Database_Config_Bible::setSentenceStructureCapitals (bible, webserver_request.post["capitals"]);
view.set_variable ("success", translate("The capitals were stored"));
}


if (request->post.count ("smallletters")) {
Database_Config_Bible::setSentenceStructureSmallLetters (bible, request->post["smallletters"]);
if (webserver_request.post.count ("smallletters")) {
Database_Config_Bible::setSentenceStructureSmallLetters (bible, webserver_request.post["smallletters"]);
view.set_variable ("success", translate("The small letters were stored"));
}


if (request->post.count ("endpunctuationmarks")) {
Database_Config_Bible::setSentenceStructureEndPunctuation (bible, request->post["endpunctuationmarks"]);
if (webserver_request.post.count ("endpunctuationmarks")) {
Database_Config_Bible::setSentenceStructureEndPunctuation (bible, webserver_request.post["endpunctuationmarks"]);
view.set_variable ("success", translate("The punctuation marks at the ends of sentences were stored"));
}


if (request->post.count ("middlepunctuationmarks")) {
Database_Config_Bible::setSentenceStructureMiddlePunctuation (bible, request->post["middlepunctuationmarks"]);
if (webserver_request.post.count ("middlepunctuationmarks")) {
Database_Config_Bible::setSentenceStructureMiddlePunctuation (bible, webserver_request.post["middlepunctuationmarks"]);
view.set_variable ("success", translate("The punctuation marks within the sentences were stored"));
}


if (request->post.count ("disregards")) {
Database_Config_Bible::setSentenceStructureDisregards (bible, request->post["disregards"]);
if (webserver_request.post.count ("disregards")) {
Database_Config_Bible::setSentenceStructureDisregards (bible, webserver_request.post["disregards"]);
view.set_variable ("success", translate("The characters that should be disregarded within the sentences were stored"));
}


if (request->post.count ("names")) {
Database_Config_Bible::setSentenceStructureNames (bible, request->post["names"]);
if (webserver_request.post.count ("names")) {
Database_Config_Bible::setSentenceStructureNames (bible, webserver_request.post["names"]);
view.set_variable ("success", translate("The names that may occur after mid-sentence punctuation were stored"));
}


if (request->post.count ("within_sentence_paragraph_markers")) {
Database_Config_Bible::setSentenceStructureWithinSentenceMarkers (bible, request->post["within_sentence_paragraph_markers"]);
if (webserver_request.post.count ("within_sentence_paragraph_markers")) {
Database_Config_Bible::setSentenceStructureWithinSentenceMarkers (bible, webserver_request.post["within_sentence_paragraph_markers"]);
view.set_variable ("success", translate("The markers that start a new line but not necessarily a new sentence were saved"));
}

Expand Down
4 changes: 2 additions & 2 deletions checks/settingssentences.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string checks_settingssentences_url ();
bool checks_settingssentences_acl (void * webserver_request);
std::string checks_settingssentences (void * webserver_request);
bool checks_settingssentences_acl (Webserver_Request& webserver_request);
std::string checks_settingssentences (Webserver_Request& webserver_request);
17 changes: 8 additions & 9 deletions checks/suppress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,24 @@ string checks_suppress_url ()
}


bool checks_suppress_acl (void * webserver_request)
bool checks_suppress_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 checks_suppress (void * webserver_request)
string checks_suppress (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
Database_Check database_check {};


string page {};
page = assets_page::header (translate ("Suppressed checking results"), webserver_request);
page = assets_page::header (translate ("Suppressed checking results"), std::addressof(webserver_request));
Assets_View view {};


if (request->query.count ("release")) {
int release = filter::strings::convert_to_int (request->query["release"]);
if (webserver_request.query.count ("release")) {
int release = filter::strings::convert_to_int (webserver_request.query["release"]);
database_check.release (release);
view.set_variable ("success", translate ("The check result is no longer suppressed."));
}
Expand All @@ -67,9 +66,9 @@ string checks_suppress (void * webserver_request)
// Get the Bibles the user has write-access to.
vector <string> bibles {};
{
vector <string> all_bibles = request->database_bibles()->get_bibles ();
vector <string> all_bibles = webserver_request.database_bibles()->get_bibles ();
for (const auto & bible : all_bibles) {
if (access_bible::write (webserver_request, bible)) {
if (access_bible::write (std::addressof(webserver_request), bible)) {
bibles.push_back (bible);
}
}
Expand Down
4 changes: 2 additions & 2 deletions checks/suppress.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string checks_suppress_url ();
bool checks_suppress_acl (void * webserver_request);
std::string checks_suppress (void * webserver_request);
bool checks_suppress_acl (Webserver_Request& webserver_request);
std::string checks_suppress (Webserver_Request& webserver_request);
22 changes: 10 additions & 12 deletions collaboration/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,37 @@ string collaboration_settings_url ()
}


bool collaboration_settings_acl (void * webserver_request)
bool collaboration_settings_acl (Webserver_Request& webserver_request)
{
return Filter_Roles::access_control (webserver_request, Filter_Roles::admin ());
return Filter_Roles::access_control (std::addressof(webserver_request), Filter_Roles::admin ());
}


string collaboration_settings (void * webserver_request)
string collaboration_settings (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

string page;
Assets_Header header = Assets_Header (translate("Collaboration"), request);
Assets_Header header = Assets_Header (translate("Collaboration"), std::addressof(webserver_request));
page = header.run ();
Assets_View view;


string object = request->query ["object"];
string object = webserver_request.query ["object"];
view.set_variable ("object", object);


if (request->post.count ("url")) {
if (webserver_request.post.count ("url")) {
if (!object.empty ()) {
string url = request->post["url"];
string url = webserver_request.post["url"];
Database_Config_Bible::setRemoteRepositoryUrl (object, url);
string source = request->post["source"];
string readwrite = request->post["readwrite"];
string source = webserver_request.post["source"];
string readwrite = webserver_request.post["readwrite"];
Database_Config_Bible::setReadFromGit (object, readwrite == "sendreceive");
Database_Jobs database_jobs = Database_Jobs ();
int jobId = database_jobs.get_new_id ();
database_jobs.set_level (jobId, Filter_Roles::admin ());
database_jobs.set_start (jobId, collaboration_link_header ());
tasks_logic_queue (LINKGITREPOSITORY, {object, filter::strings::convert_to_string (jobId), source});
redirect_browser (request, jobs_index_url () + "?id=" + filter::strings::convert_to_string (jobId));
redirect_browser (std::addressof(webserver_request), jobs_index_url () + "?id=" + filter::strings::convert_to_string (jobId));
return "";
}
}
Expand Down
4 changes: 2 additions & 2 deletions collaboration/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string collaboration_settings_url ();
bool collaboration_settings_acl (void * webserver_request);
std::string collaboration_settings (void * webserver_request);
bool collaboration_settings_acl (Webserver_Request& webserver_request);
std::string collaboration_settings (Webserver_Request& webserver_request);
17 changes: 8 additions & 9 deletions consistency/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ string consistency_input_url ()
}


bool consistency_input_acl (void * webserver_request)
bool consistency_input_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 consistency_input (void * webserver_request)
string consistency_input (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
int id = filter::strings::convert_to_int (request->post ["id"]);
string passages = request->post ["passages"];
string translations = request->post ["translations"];
const int id = filter::strings::convert_to_int (webserver_request.post ["id"]);
const string passages = webserver_request.post ["passages"];
const string translations = webserver_request.post ["translations"];
Database_Volatile::setValue (id, "passages", passages);
Database_Volatile::setValue (id, "translations", translations);
Consistency_Logic consistency_logic (webserver_request, id);
string response = consistency_logic.response ();
Consistency_Logic consistency_logic (std::addressof(webserver_request), id);
const string response = consistency_logic.response ();
Database_Volatile::setValue (id, "response", response);
return response;
}
4 changes: 2 additions & 2 deletions consistency/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string consistency_input_url ();
bool consistency_input_acl (void * webserver_request);
std::string consistency_input (void * webserver_request);
bool consistency_input_acl (Webserver_Request& webserver_request);
std::string consistency_input (Webserver_Request& webserver_request);
Loading

0 comments on commit 95ec384

Please sign in to comment.