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 1, 2024
1 parent 802bb24 commit f3f4e14
Show file tree
Hide file tree
Showing 22 changed files with 250 additions and 269 deletions.
40 changes: 20 additions & 20 deletions bootstrap/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,53 +686,53 @@ void bootstrap_index (Webserver_Request& webserver_request)
return;
}

if ((url == manage_accounts_url ()) && browser_request_security_okay (webserver_request) && manage_accounts_acl (std::addressof(webserver_request))) {
webserver_request.reply = manage_accounts (std::addressof(webserver_request));
if ((url == manage_accounts_url ()) && browser_request_security_okay (webserver_request) && manage_accounts_acl (webserver_request)) {
webserver_request.reply = manage_accounts (webserver_request);
return;
}

if ((url == manage_index_url ()) && browser_request_security_okay (webserver_request) && manage_index_acl (std::addressof(webserver_request))) {
webserver_request.reply = manage_index (std::addressof(webserver_request));
if ((url == manage_index_url ()) && browser_request_security_okay (webserver_request) && manage_index_acl (webserver_request)) {
webserver_request.reply = manage_index (webserver_request);
return;
}

if ((url == system_index_url ()) && browser_request_security_okay (webserver_request) && system_index_acl (std::addressof(webserver_request))) {
webserver_request.reply = system_index (std::addressof(webserver_request));
if ((url == system_index_url ()) && browser_request_security_okay (webserver_request) && system_index_acl (webserver_request)) {
webserver_request.reply = system_index (webserver_request);
return;
}

if ((url == system_googletranslate_url ()) && browser_request_security_okay (webserver_request) && system_googletranslate_acl (std::addressof(webserver_request))) {
webserver_request.reply = system_googletranslate (std::addressof(webserver_request));
if ((url == system_googletranslate_url ()) && browser_request_security_okay (webserver_request) && system_googletranslate_acl (webserver_request)) {
webserver_request.reply = system_googletranslate (webserver_request);
return;
}

if ((url == email_index_url ()) && browser_request_security_okay (webserver_request) && email_index_acl (std::addressof(webserver_request))) {
webserver_request.reply = email_index (std::addressof(webserver_request));
if ((url == email_index_url ()) && browser_request_security_okay (webserver_request) && email_index_acl (webserver_request)) {
webserver_request.reply = email_index (webserver_request);
return;
}

if ((url == styles_indexm_url ()) && browser_request_security_okay (webserver_request) && styles_indexm_acl (std::addressof(webserver_request))) {
webserver_request.reply = styles_indexm (std::addressof(webserver_request));
if ((url == styles_indexm_url ()) && browser_request_security_okay (webserver_request) && styles_indexm_acl (webserver_request)) {
webserver_request.reply = styles_indexm (webserver_request);
return;
}

if ((url == styles_sheetm_url ()) && browser_request_security_okay (webserver_request) && styles_sheetm_acl (std::addressof(webserver_request))) {
webserver_request.reply = styles_sheetm (std::addressof(webserver_request));
if ((url == styles_sheetm_url ()) && browser_request_security_okay (webserver_request) && styles_sheetm_acl (webserver_request)) {
webserver_request.reply = styles_sheetm (webserver_request);
return;
}

if ((url == styles_view_url ()) && browser_request_security_okay (webserver_request) && styles_view_acl (std::addressof(webserver_request))) {
webserver_request.reply = styles_view (std::addressof(webserver_request));
if ((url == styles_view_url ()) && browser_request_security_okay (webserver_request) && styles_view_acl (webserver_request)) {
webserver_request.reply = styles_view (webserver_request);
return;
}

if ((url == versification_index_url ()) && browser_request_security_okay (webserver_request) && versification_index_acl (std::addressof(webserver_request))) {
webserver_request.reply = versification_index (std::addressof(webserver_request));
if ((url == versification_index_url ()) && browser_request_security_okay (webserver_request) && versification_index_acl (webserver_request)) {
webserver_request.reply = versification_index (webserver_request);
return;
}

if ((url == versification_system_url ()) && browser_request_security_okay (webserver_request) && versification_system_acl (std::addressof(webserver_request))) {
webserver_request.reply = versification_system (std::addressof(webserver_request));
if ((url == versification_system_url ()) && browser_request_security_okay (webserver_request) && versification_system_acl (webserver_request)) {
webserver_request.reply = versification_system (webserver_request);
return;
}

Expand Down
42 changes: 20 additions & 22 deletions email/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,27 @@ string email_index_url ()
}


bool email_index_acl (void * webserver_request)
bool email_index_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 email_index (void * webserver_request)
string email_index (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

string page;

Assets_Header header = Assets_Header (translate("Mail"), webserver_request);
Assets_Header header = Assets_Header (translate("Mail"), std::addressof(webserver_request));
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
page = header.run ();

Assets_View view;

// Site name and email.
if (request->post ["email"] != "") {
if (webserver_request.post ["email"] != "") {
bool form_is_valid = true;
string sitename = request->post ["sitename"];
string sitemail = request->post ["sitemail"];
string sitename = webserver_request.post ["sitename"];
string sitemail = webserver_request.post ["sitemail"];
if (sitemail.length () > 0) {
if (!filter_url_email_is_valid (sitemail)) {
form_is_valid = false;
Expand All @@ -78,12 +76,12 @@ string email_index (void * webserver_request)
view.set_variable ("sitemail", Database_Config_General::getSiteMailAddress ());

// Email retrieval.
if (request->post ["retrieve"] != "") {
string storagehost = request->post ["storagehost"];
string storageusername = request->post ["storageusername"];
string storagepassword = request->post ["storagepassword"];
string storagesecurity = request->post ["storagesecurity"];
string storageport = request->post ["storageport"];
if (webserver_request.post ["retrieve"] != "") {
string storagehost = webserver_request.post ["storagehost"];
string storageusername = webserver_request.post ["storageusername"];
string storagepassword = webserver_request.post ["storagepassword"];
string storagesecurity = webserver_request.post ["storagesecurity"];
string storageport = webserver_request.post ["storageport"];
Database_Config_General::setMailStorageHost (storagehost);
Database_Config_General::setMailStorageUsername (storageusername);
Database_Config_General::setMailStoragePassword (storagepassword);
Expand Down Expand Up @@ -111,13 +109,13 @@ string email_index (void * webserver_request)
view.set_variable ("storageport", Database_Config_General::getMailStoragePort ());

// Sending email.
if (request->post ["send"] != "") {
string sendhost = request->post ["sendhost"];
string sendauthentication = request->post ["sendauthentication"];
string sendusername = request->post ["sendusername"];
string sendpassword = request->post ["sendpassword"];
string sendsecurity = request->post ["sendsecurity"];
string sendport = request->post ["sendport"];
if (webserver_request.post ["send"] != "") {
string sendhost = webserver_request.post ["sendhost"];
string sendauthentication = webserver_request.post ["sendauthentication"];
string sendusername = webserver_request.post ["sendusername"];
string sendpassword = webserver_request.post ["sendpassword"];
string sendsecurity = webserver_request.post ["sendsecurity"];
string sendport = webserver_request.post ["sendport"];
Database_Config_General::setMailSendHost (sendhost);
Database_Config_General::setMailSendUsername (sendusername);
Database_Config_General::setMailSendPassword (sendpassword);
Expand Down
4 changes: 2 additions & 2 deletions email/index.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;

std::string email_index_url ();
bool email_index_acl (void * webserver_request);
std::string email_index (void * webserver_request);
bool email_index_acl (Webserver_Request& webserver_request);
std::string email_index (Webserver_Request& webserver_request);
36 changes: 17 additions & 19 deletions manage/accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,34 @@ string manage_accounts_url ()
}


bool manage_accounts_acl (void * webserver_request)
bool manage_accounts_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 manage_accounts (void * webserver_request)
string manage_accounts (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

bool user_updated = false;
bool privileges_updated = false;

string page;
Assets_Header header = Assets_Header (translate("Accounts"), webserver_request);
Assets_Header header = Assets_Header (translate("Accounts"), std::addressof(webserver_request));
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
page = header.run ();

Assets_View view;

// The user to act on.
string objectUsername = request->query["user"];
int user_level = request->database_users ()->get_level (objectUsername);
string objectUsername = webserver_request.query["user"];
int user_level = webserver_request.database_users ()->get_level (objectUsername);

// Delete a user.
if (request->query.count ("delete")) {
if (webserver_request.query.count ("delete")) {
string role = Filter_Roles::text (user_level);
string email = request->database_users ()->get_email (objectUsername);
vector <string> users = request->database_users ()->get_users ();
vector <string> administrators = request->database_users ()->getAdministrators ();
string email = webserver_request.database_users ()->get_email (objectUsername);
vector <string> users = webserver_request.database_users ()->get_users ();
vector <string> administrators = webserver_request.database_users ()->getAdministrators ();
if (users.size () == 1) {
page += assets_page::error (translate("Cannot remove the last user"));
} else if ((user_level >= Filter_Roles::admin ()) && (administrators.size () == 1)) {
Expand Down Expand Up @@ -108,15 +106,15 @@ string manage_accounts (void * webserver_request)
}

// Retrieve assigned users.
vector <string> users = access_user::assignees (webserver_request);
for (auto & username : users) {
const vector <string> users = access_user::assignees (std::addressof(webserver_request));
for (const auto& username : users) {

// Gather details for this user account.
user_level = request->database_users ()->get_level (username);
string role = Filter_Roles::text (user_level);
string email = request->database_users ()->get_email (username);
int seconds = filter::date::seconds_since_epoch() - account_creation_times[username];
string days = filter::strings::convert_to_string (seconds / (3600 * 24));
user_level = webserver_request.database_users ()->get_level (username);
const string role = Filter_Roles::text (user_level);
const string email = webserver_request.database_users ()->get_email (username);
const int seconds = filter::date::seconds_since_epoch() - account_creation_times[username];
const string days = filter::strings::convert_to_string (seconds / (3600 * 24));

// Pass information about this user to the flate engine for display.
view.add_iteration ("tbody", {
Expand Down
4 changes: 2 additions & 2 deletions manage/accounts.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;

std::string manage_accounts_url ();
bool manage_accounts_acl (void * webserver_request);
std::string manage_accounts (void * webserver_request);
bool manage_accounts_acl (Webserver_Request& webserver_request);
std::string manage_accounts (Webserver_Request& webserver_request);
8 changes: 4 additions & 4 deletions manage/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ string manage_index_url ()
}


bool manage_index_acl (void * webserver_request)
bool manage_index_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 manage_index (void * webserver_request)
string manage_index (Webserver_Request& webserver_request)
{
string page;
Assets_Header header = Assets_Header (translate("Manage"), webserver_request);
Assets_Header header = Assets_Header (translate("Manage"), std::addressof(webserver_request));
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
page = header.run ();
Assets_View view;
Expand Down
4 changes: 2 additions & 2 deletions manage/index.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;

std::string manage_index_url ();
bool manage_index_acl (void * webserver_request);
std::string manage_index (void * webserver_request);
bool manage_index_acl (Webserver_Request& webserver_request);
std::string manage_index (Webserver_Request& webserver_request);
8 changes: 4 additions & 4 deletions menu/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,22 +788,22 @@ string menu_logic_settings_category (void * webserver_request, string * tooltip)

if (label == mail) {
#ifndef HAVE_CLIENT
if (email_index_acl (webserver_request)) {
if (email_index_acl (*request)) {
html.push_back (menu_logic_create_item (email_index_url (), label, true, "", ""));
tiplabels.push_back (label);
}
#endif
}

if (label == styles) {
if (styles_indexm_acl (webserver_request)) {
if (styles_indexm_acl (*request)) {
html.push_back (menu_logic_create_item (styles_indexm_url (), menu_logic_styles_text (), true, "", ""));
tiplabels.push_back (menu_logic_styles_text ());
}
}

if (label == versifications) {
if (versification_index_acl (webserver_request)) {
if (versification_index_acl (*request)) {
html.push_back (menu_logic_create_item (versification_index_url (), menu_logic_versification_index_text (), true, "", ""));
tiplabels.push_back (menu_logic_versification_index_text ());
}
Expand Down Expand Up @@ -896,7 +896,7 @@ string menu_logic_settings_category (void * webserver_request, string * tooltip)
}

if (label == system) {
if (system_index_acl (webserver_request)) {
if (system_index_acl (*request)) {
html.push_back (menu_logic_create_item (system_index_url (), label, true, "", ""));
tiplabels.push_back (label);
}
Expand Down
26 changes: 12 additions & 14 deletions styles/indexm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,29 @@ string styles_indexm_url ()
}


bool styles_indexm_acl (void * webserver_request)
bool styles_indexm_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 styles_indexm (void * webserver_request)
string styles_indexm (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

string page {};

Assets_Header header = Assets_Header (translate("Styles"), webserver_request);
Assets_Header header = Assets_Header (translate("Styles"), std::addressof(webserver_request));
header.add_bread_crumb (menu_logic_settings_menu (), menu_logic_settings_text ());
page = header.run ();

Assets_View view {};

Database_Styles database_styles {};

string username {request->session_logic ()->currentUser ()};
int userlevel {request->session_logic ()->currentLevel ()};
string username {webserver_request.session_logic ()->currentUser ()};
int userlevel {webserver_request.session_logic ()->currentLevel ()};

if (request->post.count ("new")) {
string name {request->post["entry"]};
if (webserver_request.post.count ("new")) {
string name {webserver_request.post["entry"]};
// Remove spaces at the ends of the name for the new stylesheet.
// Because predictive keyboards can add a space to the name,
// and the stylesheet system is not built for whitespace at the start / end of the name of the stylesheet.
Expand All @@ -85,16 +83,16 @@ string styles_indexm (void * webserver_request)
page += assets_page::success (translate("The stylesheet has been created"));
}
}
if (request->query.count ("new")) {
if (webserver_request.query.count ("new")) {
Dialog_Entry dialog_entry = Dialog_Entry ("indexm", translate("Please enter the name for the new stylesheet"), string(), "new", string());
page += dialog_entry.run();
return page;
}

if (request->query.count ("delete")) {
string del {request->query ["delete"]};
if (webserver_request.query.count ("delete")) {
string del {webserver_request.query ["delete"]};
if (!del.empty()) {
string confirm {request->query ["confirm"]};
string confirm {webserver_request.query ["confirm"]};
if (confirm == "yes") {
bool write = database_styles.hasWriteAccess (username, del);
if (userlevel >= Filter_Roles::admin ()) write = true;
Expand Down
4 changes: 2 additions & 2 deletions styles/indexm.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
class Webserver_Request;

std::string styles_indexm_url ();
bool styles_indexm_acl (void * webserver_request);
std::string styles_indexm (void * webserver_request);
bool styles_indexm_acl (Webserver_Request& webserver_request);
std::string styles_indexm (Webserver_Request& webserver_request);
Loading

0 comments on commit f3f4e14

Please sign in to comment.