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 325843c commit d5e76e6
Show file tree
Hide file tree
Showing 46 changed files with 5,442 additions and 436 deletions.
81 changes: 40 additions & 41 deletions bootstrap/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,106 +762,105 @@ void bootstrap_index (Webserver_Request& webserver_request)
}

// Help menu.
if ((help_index_url (url)) && browser_request_security_okay (webserver_request) && help_index_acl (std::addressof(webserver_request))) {
webserver_request.reply = help_index (std::addressof(webserver_request), url);
if ((help_index_url (url)) && browser_request_security_okay (webserver_request) && help_index_acl (webserver_request)) {
webserver_request.reply = help_index (webserver_request, url);
return;
}

// User menu.
if ((url == user_notifications_url ()) && browser_request_security_okay (webserver_request) && user_notifications_acl (std::addressof(webserver_request))) {
webserver_request.reply = user_notifications (std::addressof(webserver_request));
if ((url == user_notifications_url ()) && browser_request_security_okay (webserver_request) && user_notifications_acl (webserver_request)) {
webserver_request.reply = user_notifications (webserver_request);
return;
}

if ((url == user_account_url ()) && browser_request_security_okay (webserver_request) && user_account_acl (std::addressof(webserver_request))) {
webserver_request.reply = user_account (std::addressof(webserver_request));
if ((url == user_account_url ()) && browser_request_security_okay (webserver_request) && user_account_acl (webserver_request)) {
webserver_request.reply = user_account (webserver_request);
return;
}

// Public feedback menu.
if ((url == public_index_url ()) && browser_request_security_okay (webserver_request) && public_index_acl (std::addressof(webserver_request))) {
webserver_request.reply = public_index (std::addressof(webserver_request));
if ((url == public_index_url ()) && browser_request_security_okay (webserver_request) && public_index_acl (webserver_request)) {
webserver_request.reply = public_index (webserver_request);
return;
}

if ((url == public_login_url ()) && browser_request_security_okay (webserver_request) && public_login_acl (std::addressof(webserver_request))) {
webserver_request.reply = public_login (std::addressof(webserver_request));
if ((url == public_login_url ()) && browser_request_security_okay (webserver_request) && public_login_acl (webserver_request)) {
webserver_request.reply = public_login (webserver_request);
return;
}

if ((url == public_chapter_url ()) && browser_request_security_okay (webserver_request) && public_chapter_acl (std::addressof(webserver_request))) {
webserver_request.reply = public_chapter (std::addressof(webserver_request));
if ((url == public_chapter_url ()) && browser_request_security_okay (webserver_request) && public_chapter_acl (webserver_request)) {
webserver_request.reply = public_chapter (webserver_request);
return;
}

if ((url == public_notes_url ()) && browser_request_security_okay (webserver_request) && public_notes_acl (std::addressof(webserver_request))) {
webserver_request.reply = public_notes (std::addressof(webserver_request));
if ((url == public_notes_url ()) && browser_request_security_okay (webserver_request) && public_notes_acl (webserver_request)) {
webserver_request.reply = public_notes (webserver_request);
return;
}

if ((url == public_new_url ()) && browser_request_security_okay (webserver_request) && public_new_acl (std::addressof(webserver_request))) {
webserver_request.reply = public_new (std::addressof(webserver_request));
if ((url == public_new_url ()) && browser_request_security_okay (webserver_request) && public_new_acl (webserver_request)) {
webserver_request.reply = public_new (webserver_request);
return;
}

if ((url == public_create_url ()) && browser_request_security_okay (webserver_request) && public_create_acl (std::addressof(webserver_request))) {
webserver_request.reply = public_create (std::addressof(webserver_request));
if ((url == public_create_url ()) && browser_request_security_okay (webserver_request) && public_create_acl (webserver_request)) {
webserver_request.reply = public_create (webserver_request);
return;
}

if ((url == public_note_url ()) && browser_request_security_okay (webserver_request) && public_note_acl (std::addressof(webserver_request))) {
webserver_request.reply = public_note (std::addressof(webserver_request));
if ((url == public_note_url ()) && browser_request_security_okay (webserver_request) && public_note_acl (webserver_request)) {
webserver_request.reply = public_note (webserver_request);
return;
}

if ((url == public_comment_url ()) && browser_request_security_okay (webserver_request) && public_comment_acl (std::addressof(webserver_request))) {
webserver_request.reply = public_comment (std::addressof(webserver_request));
if ((url == public_comment_url ()) && browser_request_security_okay (webserver_request) && public_comment_acl (webserver_request)) {
webserver_request.reply = public_comment (webserver_request);
return;
}

// Pages not in any menu.
if ((url == jobs_index_url ()) && browser_request_security_okay (webserver_request) && jobs_index_acl (std::addressof(webserver_request))) {
webserver_request.reply = jobs_index (std::addressof(webserver_request));
if ((url == jobs_index_url ()) && browser_request_security_okay (webserver_request) && jobs_index_acl (webserver_request)) {
webserver_request.reply = jobs_index (webserver_request);
return;
}

if ((url == search_all_url ()) && browser_request_security_okay (webserver_request) && search_all_acl (std::addressof(webserver_request))) {
webserver_request.reply = search_all (std::addressof(webserver_request));
if ((url == search_all_url ()) && browser_request_security_okay (webserver_request) && search_all_acl (webserver_request)) {
webserver_request.reply = search_all (webserver_request);
return;
}

if ((url == search_replace_url ()) && browser_request_security_okay (webserver_request) && search_replace_acl (std::addressof(webserver_request))) {
webserver_request.reply = search_replace (std::addressof(webserver_request));
if ((url == search_replace_url ()) && browser_request_security_okay (webserver_request) && search_replace_acl (webserver_request)) {
webserver_request.reply = search_replace (webserver_request);
return;
}

if ((url == search_search2_url ()) && browser_request_security_okay (webserver_request) && search_search2_acl (std::addressof(webserver_request))) {
webserver_request.reply = search_search2 (std::addressof(webserver_request));
if ((url == search_search2_url ()) && browser_request_security_okay (webserver_request) && search_search2_acl (webserver_request)) {
webserver_request.reply = search_search2 (webserver_request);
return;
}

if ((url == search_replace2_url ()) && browser_request_security_okay (webserver_request) && search_replace2_acl (std::addressof(webserver_request))) {
webserver_request.reply = search_replace2 (std::addressof(webserver_request));
if ((url == search_replace2_url ()) && browser_request_security_okay (webserver_request) && search_replace2_acl (webserver_request)) {
webserver_request.reply = search_replace2 (webserver_request);
return;
}

if ((url == search_similar_url ()) && browser_request_security_okay (webserver_request) && search_similar_acl (std::addressof(webserver_request))) {
webserver_request.reply = search_similar (std::addressof(webserver_request));
if ((url == search_similar_url ()) && browser_request_security_okay (webserver_request) && search_similar_acl (webserver_request)) {
webserver_request.reply = search_similar (webserver_request);
return;
}

if ((url == search_strongs_url ()) && browser_request_security_okay (webserver_request) && search_strongs_acl (std::addressof(webserver_request))) {
webserver_request.reply = search_strongs (std::addressof(webserver_request));
if ((url == search_strongs_url ()) && browser_request_security_okay (webserver_request) && search_strongs_acl (webserver_request)) {
webserver_request.reply = search_strongs (webserver_request);
return;
}

if ((url == search_strong_url ()) && browser_request_security_okay (webserver_request) && search_strong_acl (std::addressof(webserver_request))) {
webserver_request.reply = search_strong (std::addressof(webserver_request));
if ((url == search_strong_url ()) && browser_request_security_okay (webserver_request) && search_strong_acl (webserver_request)) {
webserver_request.reply = search_strong (webserver_request);
return;
}

if ((url == search_originals_url ()) && browser_request_security_okay (webserver_request) && search_originals_acl (std::addressof(webserver_request))) {
webserver_request.reply = search_originals (std::addressof(webserver_request));
if ((url == search_originals_url ()) && browser_request_security_okay (webserver_request) && search_originals_acl (webserver_request)) {
webserver_request.reply = search_originals (webserver_request);
return;
}

Expand Down
25 changes: 13 additions & 12 deletions help/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,39 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <locale/translate.h>
#include <assets/header.h>
#include <assets/external.h>
using namespace std;


string help_index_html (const string& url)
std::string help_index_html (const std::string& url)
{
string path (url);
std::string path (url);
size_t pos = url.find ("/");
if (pos != std::string::npos) path.erase (0, ++pos);
if (pos != std::string::npos)
path.erase (0, ++pos);
path.append (".html");
path = filter_url_create_root_path ({"help", path});
return path;
}


bool help_index_url (const string& url)
bool help_index_url (const std::string& url)
{
size_t pos = url.find ("help/");
if (pos != 0) return false;
return file_or_dir_exists (help_index_html (url));
}


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


string help_index (void * webserver_request, const string& url)
std::string help_index (Webserver_Request& webserver_request, const std::string& url)
{
string page {};
std::string page {};

Assets_Header header = Assets_Header (translate("Help"), webserver_request);
Assets_Header header = Assets_Header (translate("Help"), std::addressof(webserver_request));
page = header.run ();

Assets_View view {};
Expand All @@ -69,9 +69,10 @@ string help_index (void * webserver_request, const string& url)

view.set_variable ("config", filter_url_create_root_path ({config::logic::config_folder ()}));

string filename (url);
std::string filename (url);
size_t pos = url.find ("/");
if (pos != std::string::npos) filename.erase (0, ++pos);
if (pos != std::string::npos)
filename.erase (0, ++pos);

page += view.render ("help", filename);

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

std::string help_index_html (const std::string& url);
bool help_index_url (const std::string& url);
bool help_index_acl (void * webserver_request);
std::string help_index (void * webserver_request, const std::string& url);
bool help_index_acl (Webserver_Request& webserver_request);
std::string help_index (Webserver_Request& webserver_request, const std::string& url);
26 changes: 12 additions & 14 deletions jobs/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,33 @@ string jobs_index_url ()
}


bool jobs_index_acl (void * webserver_request)
bool jobs_index_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 jobs_index (void * webserver_request)
string jobs_index (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

string page;

Assets_Header header = Assets_Header (translate ("Job"), request);
Assets_Header header = Assets_Header (translate ("Job"), std::addressof(webserver_request));

Assets_View view;

int id = filter::strings::convert_to_int (request->query ["id"]);
const int id = filter::strings::convert_to_int (webserver_request.query ["id"]);

// Get information about this job.
Database_Jobs database_jobs = Database_Jobs ();
bool exists = database_jobs.id_exists (id);
int level = database_jobs.get_level (id);
string start = database_jobs.get_start (id);
string percentage = database_jobs.get_percentage (id);
string progress = database_jobs.get_progress (id);
string result = database_jobs.get_result (id);
const bool exists = database_jobs.id_exists (id);
const int level = database_jobs.get_level (id);
const string start = database_jobs.get_start (id);
const string percentage = database_jobs.get_percentage (id);
const string progress = database_jobs.get_progress (id);
const string result = database_jobs.get_result (id);

// Access control for the user.
int userlevel = request->session_logic()->currentLevel ();
const int userlevel = webserver_request.session_logic()->currentLevel ();

string contents;
if (!exists) {
Expand Down
4 changes: 2 additions & 2 deletions jobs/index.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string jobs_index_url ();
bool jobs_index_acl (void * webserver_request);
std::string jobs_index (void * webserver_request);
bool jobs_index_acl (Webserver_Request& webserver_request);
std::string jobs_index (Webserver_Request& webserver_request);
Binary file added libbibledit.a.MpBesj
Binary file not shown.
Binary file added libbibledit.a.onYIWR
Binary file not shown.
20 changes: 10 additions & 10 deletions menu/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,49 +482,49 @@ string menu_logic_search_category (void * webserver_request, string * tooltip)
labels.push_back (label);
}

if (search_replace_acl (webserver_request)) {
if (search_replace_acl (*request)) {
string label = translate ("Replace");
html.push_back (menu_logic_create_item (search_replace_url (), label, true, "", ""));
labels.push_back (label);
}

if (search_search2_acl (webserver_request)) {
if (search_search2_acl (*request)) {
string label = translate ("Advanced search");
html.push_back (menu_logic_create_item (search_search2_url (), translate ("Advanced search"), true, "", ""));
labels.push_back (label);
}

if (search_replace2_acl (webserver_request)) {
if (search_replace2_acl (*request)) {
string label = translate ("Advanced replace");
html.push_back (menu_logic_create_item (search_replace2_url (), label, true, "", ""));
labels.push_back (label);
}

if (search_all_acl (webserver_request)) {
if (search_all_acl (*request)) {
string label = translate ("Search all Bibles and notes");
html.push_back (menu_logic_create_item (search_all_url (), label, true, "", ""));
labels.push_back (label);
}

if (search_similar_acl (webserver_request)) {
if (search_similar_acl (*request)) {
string label = translate ("Search Bible for similar verses");
html.push_back (menu_logic_create_item (search_similar_url (), label, true, "", ""));
labels.push_back (label);
}

if (search_strongs_acl (webserver_request)) {
if (search_strongs_acl (*request)) {
string label = translate ("Search Bible for similar Strong's numbers");
html.push_back (menu_logic_create_item (search_strongs_url (), label, true, "", ""));
labels.push_back (label);
}

if (search_strong_acl (webserver_request)) {
if (search_strong_acl (*request)) {
string label = translate ("Search Bible for Strong's number");
html.push_back (menu_logic_create_item (search_strong_url (), label, true, "", ""));
labels.push_back (label);
}

if (search_originals_acl (webserver_request)) {
if (search_originals_acl (*request)) {
string label = translate ("Search Bible for similar Hebrew or Greek words");
html.push_back (menu_logic_create_item (search_originals_url (), label, true, "", ""));
labels.push_back (label);
Expand Down Expand Up @@ -869,7 +869,7 @@ string menu_logic_settings_category (void * webserver_request, string * tooltip)
#endif

if (label == notifications) {
if (user_notifications_acl (webserver_request)) {
if (user_notifications_acl (*request)) {
html.push_back (menu_logic_create_item (user_notifications_url (), label, true, "", ""));
tiplabels.push_back (label);
}
Expand All @@ -879,7 +879,7 @@ string menu_logic_settings_category (void * webserver_request, string * tooltip)
if (label == account) {
if (!demo) {
if (!ldap_logic_is_on ()) {
if (user_account_acl (webserver_request)) {
if (user_account_acl (*request)) {
html.push_back (menu_logic_create_item (user_account_url (), label, true, "", ""));
tiplabels.push_back (label);
}
Expand Down
Loading

0 comments on commit d5e76e6

Please sign in to comment.