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 7, 2024
1 parent 0abd702 commit f241a00
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 186 deletions.
12 changes: 6 additions & 6 deletions demo/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,17 @@ void demo_create_sample_workspaces (Webserver_Request& webserver_request)
};

webserver_request.database_config_user()->setActiveWorkspace ("USFM");
workspace_set_urls (std::addressof(webserver_request), urls);
workspace_set_widths (std::addressof(webserver_request), widths);
workspace_set_heights (std::addressof(webserver_request), row_heights);
workspace_set_urls (webserver_request, urls);
workspace_set_widths (webserver_request, widths);
workspace_set_heights (webserver_request, row_heights);

urls[0] = editone2_index_url ();
urls[1] = resource_index_url ();

webserver_request.database_config_user()->setActiveWorkspace (demo_workspace ());
workspace_set_urls (std::addressof(webserver_request), urls);
workspace_set_widths (std::addressof(webserver_request), widths);
workspace_set_heights (std::addressof(webserver_request), row_heights);
workspace_set_urls (webserver_request, urls);
workspace_set_widths (webserver_request, widths);
workspace_set_heights (webserver_request, row_heights);
}


Expand Down
2 changes: 1 addition & 1 deletion menu/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ string menu_logic_workspace_category (Webserver_Request& webserver_request, stri
if (workspace_organize_acl (webserver_request)) {
string activeWorkspace = webserver_request.database_config_user()->getActiveWorkspace ();

vector <string> workspaces = workspace_get_names (std::addressof(webserver_request));
vector <string> workspaces = workspace_get_names (webserver_request);
for (size_t i = 0; i < workspaces.size(); i++) {
string item = menu_logic_create_item (workspace_index_url () + "?bench=" + filter::strings::convert_to_string (i), workspaces[i], true, "", "");
// Adds an active class if it is the current workspace.
Expand Down
2 changes: 1 addition & 1 deletion session/login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ std::string session_login (Webserver_Request& webserver_request)
}
if (form_is_valid) {
// Optionally query the LDAP server and log the response.
user_logic_optional_ldap_authentication (std::addressof(webserver_request), user, pass);
user_logic_optional_ldap_authentication (webserver_request, user, pass);
// Authenticate against local database.
if (webserver_request.session_logic()->attempt_login (user, pass, touch_enabled)) {
// Log the login.
Expand Down
60 changes: 30 additions & 30 deletions unittests/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ TEST (workspaces, basic)
// Initial setup for the tests.
refresh_sandbox (false);
{
Webserver_Request request;
test_workspaces_setup (request);
Webserver_Request webserver_request;
test_workspaces_setup (webserver_request);

EXPECT_EQ ("100", workspace_process_units ("100"));
EXPECT_EQ ("1", workspace_process_units ("100 %"));
EXPECT_EQ ("1", workspace_process_units ("100 px"));

EXPECT_EQ ("Default", workspace_get_active_name (&request));
request.database_config_user()->setActiveWorkspace ("unittest");
EXPECT_EQ ("unittest", workspace_get_active_name (&request));
EXPECT_EQ ("Default", workspace_get_active_name (webserver_request));
webserver_request.database_config_user()->setActiveWorkspace ("unittest");
EXPECT_EQ ("unittest", workspace_get_active_name (webserver_request));

std::map <int, std::string> standard = {
std::pair (0, "editone2/index"),
Expand All @@ -59,8 +59,8 @@ TEST (workspaces, basic)
std::pair (10, "url1"),
std::pair (2, "url2")
};
workspace_set_urls (&request, urls);
std::map <int, std::string> result = workspace_get_urls (&request, false);
workspace_set_urls (webserver_request, urls);
std::map <int, std::string> result = workspace_get_urls (webserver_request, false);
EXPECT_EQ (urls, result);
}

Expand All @@ -71,47 +71,47 @@ TEST (workspaces, basic)
std::pair (2, "1"),
std::pair (3, "1")
};
std::map <int, std::string> result = workspace_get_widths (&request);
std::map <int, std::string> result = workspace_get_widths (webserver_request);
EXPECT_EQ (widths, result);
}

{
std::vector <std::string> workspaces = workspace_get_names (&request);
std::vector <std::string> workspaces = workspace_get_names (webserver_request);
EXPECT_EQ (std::vector<std::string>{"unittest"}, workspaces);
}
}

refresh_sandbox (true);
{
Webserver_Request request;
test_workspaces_setup (request);
request.database_config_user()->setActiveWorkspace ("unittest");
workspace_set_urls (&request, {std::pair (10, "url10")});
request.database_config_user()->setActiveWorkspace ("unittest2");
Webserver_Request webserver_request;
test_workspaces_setup (webserver_request);
webserver_request.database_config_user()->setActiveWorkspace ("unittest");
workspace_set_urls (webserver_request, {std::pair (10, "url10")});
webserver_request.database_config_user()->setActiveWorkspace ("unittest2");
std::map <int, std::string> standard = { std::pair (0, "url0"), std::pair (5, "url5")};
workspace_set_urls (&request, standard);
std::vector <std::string> workspaces = workspace_get_names (&request);
workspace_set_urls (webserver_request, standard);
std::vector <std::string> workspaces = workspace_get_names (webserver_request);
EXPECT_EQ ((std::vector <std::string>{"unittest", "unittest2"}), workspaces);
workspace_delete (&request, "unittest3");
workspaces = workspace_get_names (&request);
workspace_delete (webserver_request, "unittest3");
workspaces = workspace_get_names (webserver_request);
EXPECT_EQ ((std::vector <std::string>{"unittest", "unittest2"}), workspaces);
workspace_delete (&request, "unittest2");
workspaces = workspace_get_names (&request);
workspace_delete (webserver_request, "unittest2");
workspaces = workspace_get_names (webserver_request);
EXPECT_EQ (std::vector <std::string>{"unittest"}, workspaces);
}

refresh_sandbox (true);
{
Webserver_Request request;
test_workspaces_setup (request);
request.database_config_user()->setActiveWorkspace ("unittest2");
workspace_set_urls (&request, {std::pair (10, "url10")});
request.database_config_user()->setActiveWorkspace ("abc32");
workspace_set_urls (&request, {std::pair (10, "url10"), std::pair (11, "url11")});
request.database_config_user()->setActiveWorkspace ("zzz");
workspace_set_urls (&request, {std::pair (120, "url120"), std::pair (121, "url121")});
workspace_reorder (&request, {"zzz", "yyy", "unittest2", "abc32"});
std::vector <std::string> workspaces = workspace_get_names (&request);
Webserver_Request webserver_request;
test_workspaces_setup (webserver_request);
webserver_request.database_config_user()->setActiveWorkspace ("unittest2");
workspace_set_urls (webserver_request, {std::pair (10, "url10")});
webserver_request.database_config_user()->setActiveWorkspace ("abc32");
workspace_set_urls (webserver_request, {std::pair (10, "url10"), std::pair (11, "url11")});
webserver_request.database_config_user()->setActiveWorkspace ("zzz");
workspace_set_urls (webserver_request, {std::pair (120, "url120"), std::pair (121, "url121")});
workspace_reorder (webserver_request, {"zzz", "yyy", "unittest2", "abc32"});
std::vector <std::string> workspaces = workspace_get_names (webserver_request);
EXPECT_EQ ((std::vector <std::string>{"zzz", "unittest2", "abc32"}), workspaces);
}
}
Expand Down
23 changes: 11 additions & 12 deletions user/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
using namespace std;


void user_logic_optional_ldap_authentication (void * webserver_request, string user, string pass)
void user_logic_optional_ldap_authentication (Webserver_Request& webserver_request, string user, string pass)
{
if (ldap_logic_is_on ()) {
// Query the LDAP server and log the response.
Expand All @@ -45,24 +45,23 @@ void user_logic_optional_ldap_authentication (void * webserver_request, string u
int role;
ldap_logic_fetch (user, pass, ldap_okay, email, role, true);
if (ldap_okay) {
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
if (request->database_users ()->usernameExists (user)) {
if (webserver_request.database_users ()->usernameExists (user)) {
// Verify and/or update the fields for the user in the local database.
if (request->database_users ()->get_md5 (user) != md5 (pass)) {
request->database_users ()->set_password (user, pass);
if (webserver_request.database_users ()->get_md5 (user) != md5 (pass)) {
webserver_request.database_users ()->set_password (user, pass);
}
if (request->database_users ()->get_level (user) != role) {
request->database_users ()->set_level (user, role);
if (webserver_request.database_users ()->get_level (user) != role) {
webserver_request.database_users ()->set_level (user, role);
}
if (request->database_users ()->get_email (user) != email) {
request->database_users ()->updateUserEmail (user, email);
if (webserver_request.database_users ()->get_email (user) != email) {
webserver_request.database_users ()->updateUserEmail (user, email);
}
if (!request->database_users ()->get_enabled (user)) {
request->database_users ()->set_enabled (user, true);
if (!webserver_request.database_users ()->get_enabled (user)) {
webserver_request.database_users ()->set_enabled (user, true);
}
} else {
// Enter the user into the database.
request->database_users ()->add_user (user, pass, role, email);
webserver_request.database_users ()->add_user (user, pass, role, email);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion user/logic.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>

void user_logic_optional_ldap_authentication (void * webserver_request, std::string user, std::string pass);
class Webserver_Request;

void user_logic_optional_ldap_authentication (Webserver_Request& webserver_request, std::string user, std::string pass);

bool user_logic_login_failure_check_okay ();
void user_logic_login_failure_register ();
Expand Down
12 changes: 6 additions & 6 deletions workspace/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool workspace_index_acl (Webserver_Request& webserver_request)

std::string workspace_index (Webserver_Request& webserver_request)
{
const std::vector <std::string> workspaces = workspace_get_names (std::addressof(webserver_request));
const std::vector <std::string> workspaces = workspace_get_names (webserver_request);

// Set the requested workspace as the active one.
if (webserver_request.query.count ("bench")) {
Expand Down Expand Up @@ -77,7 +77,7 @@ std::string workspace_index (Webserver_Request& webserver_request)
create = (workspaces [0] == workspace_get_default_name ());
}
if (create) {
workspace_create_defaults (std::addressof(webserver_request));
workspace_create_defaults (webserver_request);
}


Expand All @@ -102,8 +102,8 @@ std::string workspace_index (Webserver_Request& webserver_request)
Assets_View view;


std::map <int, std::string> urls = workspace_get_urls (std::addressof(webserver_request), true);
std::map <int, std::string> widths = workspace_get_widths (std::addressof(webserver_request));
std::map <int, std::string> urls = workspace_get_urls (webserver_request, true);
std::map <int, std::string> widths = workspace_get_widths (webserver_request);
// The Bible editor number, starting from 1, going up.
std::map <int, int> editor_numbers = workspace_add_bible_editor_number (urls);
for (int key = 0; key < 15; key++) {
Expand All @@ -123,7 +123,7 @@ std::string workspace_index (Webserver_Request& webserver_request)
}


std::map <int, std::string> heights = workspace_get_heights (std::addressof(webserver_request));
std::map <int, std::string> heights = workspace_get_heights (webserver_request);
for (int key = 0; key < 3; key++) {
const std::string height = heights [key];
const int row = key + 1;
Expand All @@ -134,7 +134,7 @@ std::string workspace_index (Webserver_Request& webserver_request)
}


std::string workspacewidth = workspace_get_entire_width (std::addressof(webserver_request));
std::string workspacewidth = workspace_get_entire_width (webserver_request);
if (!workspacewidth.empty ()) {
workspacewidth.insert (0, "width: ");
workspacewidth.append (";");
Expand Down
Loading

0 comments on commit f241a00

Please sign in to comment.