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 6, 2024
1 parent e64807d commit 63f0efa
Show file tree
Hide file tree
Showing 26 changed files with 45 additions and 50 deletions.
4 changes: 2 additions & 2 deletions assets/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ string Assets_Header::run ()
m_view->set_variable ("included_editor_stylesheet", m_included_editor_stylesheet);
}

bool basic_mode = config::logic::basic_mode (std::addressof(m_webserver_request));
bool basic_mode = config::logic::basic_mode (m_webserver_request);
string basicadvanced;
if (basic_mode) basicadvanced = "basic";
else basicadvanced = "advanced";
Expand Down Expand Up @@ -301,7 +301,7 @@ string Assets_Header::run ()
if (!m_bread_crumbs.empty ()) {
// No bread crumbs in basic mode.
// The crumbs would be incorrect anyway, because they show the trail of advanced mode.
if (!config::logic::basic_mode (std::addressof(m_webserver_request))) {
if (!config::logic::basic_mode (m_webserver_request)) {
stringstream track;
track << "<a href=" << quoted(index_index_url ()) << ">";
track << menu_logic_menu_text ("") << "</a>";
Expand Down
2 changes: 1 addition & 1 deletion changes/changes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ string changes_changes (Webserver_Request& webserver_request)
stringstream loading {};
loading << "var loading = " << quoted(translate("Loading ...")) << ";";
string script = loading.str();
config::logic::swipe_enabled (std::addressof(webserver_request), script);
config::logic::swipe_enabled (webserver_request, script);
view.set_variable ("script", script);


Expand Down
3 changes: 2 additions & 1 deletion checks/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ void checks_run (string bible)

// Add a link to the online checking results.
if (!emailBody.empty ()) {
string siteUrl = config::logic::site_url (nullptr);
Webserver_Request webserver_request;
string siteUrl = config::logic::site_url (webserver_request);
stringstream body1 {};
body1 << "<p><a href=" << quoted (siteUrl + checks_index_url ()) << ">" << translate("Checking results online") << "</a></p>";
emailBody.push_back (body1.str());
Expand Down
2 changes: 1 addition & 1 deletion client/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ std::string client_index (Webserver_Request& webserver_request)
view.enable_zone ("info");
}

const bool basic_mode {config::logic::basic_mode (std::addressof(webserver_request))};
const bool basic_mode {config::logic::basic_mode (webserver_request)};
if (basic_mode) view.enable_zone("basicmode");

std::string page {};
Expand Down
31 changes: 11 additions & 20 deletions config/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,36 +137,32 @@ int my_stoi (const string& str, void * idx, int base)


// Returns whether the interface is supposed to be in basic mode.
bool basic_mode (void * webserver_request)
bool basic_mode (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
bool basic_mode {request->database_config_user ()->getBasicInterfaceMode ()};
bool basic_mode {webserver_request.database_config_user ()->getBasicInterfaceMode ()};
return basic_mode;
}


// This returns the URL of Bibledit Cloud that faces the user.
string site_url (void * webserver_request)
string site_url (Webserver_Request& webserver_request)
{
// When the administrator has entered a fixed value for the user-facing URL, take that.
// It overrides everything.
string url = config::logic::manual_user_facing_url ();
if (!url.empty ()) return url;

// If a webserver request is passed, take the host from there.
// The results is that in a situation where 192.168.2.6 is the same as localhost,
// The result is that in a situation where 192.168.2.6 is the same as localhost,
// user can connect from localhost and also from 192.168.2.6.
// In the past there was a situation that the admin set up a central server for the whole team on his localhost.
// Then team members that connected to 192.168.2.6 were forwarded to localhost (which of course failed).
// This solution deals with that.
if (webserver_request) {
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
if (!request->host.empty ()) {
url = get_base_url (*request);
return url;
}
if (!webserver_request.host.empty ()) {
url = get_base_url (webserver_request);
return url;
}

// No URL found yet.
// This occurs during scheduled tasks that require the URL to add it to emails sent out.
// Take the URL stored on login.
Expand Down Expand Up @@ -247,13 +243,11 @@ bool enforce_https_client ()
}


void swipe_enabled (void * webserver_request, string & script)
void swipe_enabled (Webserver_Request& webserver_request, string & script)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

string true_false {"false"};
if (request->session_logic ()->touchEnabled ()) {
if (request->database_config_user ()->getSwipeActionsAvailable ()) {
if (webserver_request.session_logic ()->touchEnabled ()) {
if (webserver_request.database_config_user ()->getSwipeActionsAvailable ()) {
true_false = "true";
}
}
Expand Down Expand Up @@ -300,6 +294,3 @@ string google_translate_json_key_path ()


} // End of namespace.



8 changes: 5 additions & 3 deletions config/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include <config/libraries.h>

class Webserver_Request;

namespace config::logic {

const char * config_folder ();
Expand All @@ -33,15 +35,15 @@ std::string admin_username ();
std::string admin_password ();
std::string admin_email ();
int my_stoi (const std::string& str, void * idx = nullptr, int base = 10);
bool basic_mode (void * webserver_request);
std::string site_url (void * webserver_request);
bool basic_mode (Webserver_Request& webserver_request);
std::string site_url (Webserver_Request& webserver_request);
std::string manual_user_facing_url ();
std::string server_key_path (const bool force);
std::string server_certificate_path (const bool force);
std::string authorities_certificates_path (const bool force);
bool enforce_https_browser ();
bool enforce_https_client ();
void swipe_enabled (void * webserver_request, std::string & script);
void swipe_enabled (Webserver_Request& webserver_request, std::string & script);
bool indonesian_member_cloud ();
bool default_bibledit_configuration ();
std::string google_translate_json_key_path ();
Expand Down
3 changes: 2 additions & 1 deletion confirm/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void Confirm_Worker::setup (string mailto, string username,
}
node.text ().set (information.c_str());
node = document.append_child ("p");
string siteUrl = config::logic::site_url (webserver_request);
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
string siteUrl = config::logic::site_url (*request);
string confirmation_url = filter_url_build_http_query (siteUrl + session_confirm_url (), "id", to_string(confirmation_id));
node.text ().set (confirmation_url.c_str());
stringstream output;
Expand Down
4 changes: 2 additions & 2 deletions edit/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ std::string edit_index (Webserver_Request& webserver_request)
script_stream << "var verticalCaretPosition = " << webserver_request.database_config_user ()->getVerticalCaretPosition () << ";\n";
script_stream << "var verseSeparator = " << quoted(Database_Config_General::getNotesVerseSeparator ()) << ";\n";
std::string script = script_stream.str();
config::logic::swipe_enabled (std::addressof(webserver_request), script);
config::logic::swipe_enabled (webserver_request, script);
view.set_variable ("script", script);


Expand All @@ -161,7 +161,7 @@ std::string edit_index (Webserver_Request& webserver_request)

// In basic mode the editor has no controls and fewer indicators.
// In basic mode, the user can just edit text, and cannot style it.
const bool basic_mode = config::logic::basic_mode (std::addressof(webserver_request));
const bool basic_mode = config::logic::basic_mode (webserver_request);
if (!basic_mode) view.enable_zone ("advancedmode");


Expand Down
2 changes: 1 addition & 1 deletion editone2/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ string editone2_index (Webserver_Request& webserver_request)
script_stream << "var verticalCaretPosition = " << verticalCaretPosition << ";\n";
script_stream << "var verseSeparator = " << quoted(Database_Config_General::getNotesVerseSeparator ()) << ";\n";
string script {script_stream.str()};
config::logic::swipe_enabled (std::addressof(webserver_request), script);
config::logic::swipe_enabled (webserver_request, script);
view.set_variable ("script", script);

string custom_class = Filter_Css::getClass (bible);
Expand Down
2 changes: 1 addition & 1 deletion editusfm/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ std::string editusfm_index (Webserver_Request& webserver_request)
ss << "var usfmEditorWriteAccess = true;" << std::endl;
ss << "var verticalCaretPosition = " << verticalCaretPosition << ";" << std::endl;
std::string script = ss.str();
config::logic::swipe_enabled (std::addressof(webserver_request), script);
config::logic::swipe_enabled (webserver_request, script);
view.set_variable ("script", script);


Expand Down
2 changes: 1 addition & 1 deletion filter/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void redirect_browser (Webserver_Request& webserver_request, string path)
// The absolute location contains the user-facing URL, when the administrator entered it.
// This is needed in case of a proxy server,
// where Bibledit may not be able to obtain the user-facing URL of the website.
string location = config::logic::site_url (std::addressof(webserver_request));
string location = config::logic::site_url (webserver_request);

// If the request was secure, or supposed to be secure,
// ensure the location contains https rather than plain http,
Expand Down
2 changes: 1 addition & 1 deletion navigation/passage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ string Navigation_Passage::get_mouse_navigator (Webserver_Request& webserver_req

bool passage_clipped = false;

bool basic_mode = config::logic::basic_mode (std::addressof(webserver_request));
bool basic_mode = config::logic::basic_mode (webserver_request);

xml_document document;

Expand Down
2 changes: 1 addition & 1 deletion notes/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ string notes_index (Webserver_Request& webserver_request)
// Manager roles and higher can do mass updates on the notes.
if (level >= Filter_Roles::manager ()) {
// No mass updates in basic mode.
if (!config::logic::basic_mode (std::addressof(webserver_request))) {
if (!config::logic::basic_mode (webserver_request)) {
view.enable_zone ("update");
}
}
Expand Down
4 changes: 2 additions & 2 deletions notes/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,15 @@ void Notes_Logic::emailUsers (int identifier, const string& label, string bible,
contents << "<br>" << std::endl;
contents << "<p>";
contents << "<a href=";
string notelink = config::logic::site_url (std::addressof(m_webserver_request)) + notes_note_url () + "?id=" + filter::strings::convert_to_string (identifier);
string notelink = config::logic::site_url (m_webserver_request) + notes_note_url () + "?id=" + filter::strings::convert_to_string (identifier);
contents << quoted (notelink);
contents << ">";
contents << translate ("View or respond online");
contents << "</a>";
contents << " " << translate ("or") << " ";

contents << "<a href=";
string workspacelink = config::logic::site_url (std::addressof(m_webserver_request)) + workspace_index_url () + "?note=" + filter::strings::convert_to_string (identifier);
string workspacelink = config::logic::site_url (m_webserver_request) + workspace_index_url () + "?note=" + filter::strings::convert_to_string (identifier);
contents << quoted (workspacelink);
contents << ">";
contents << translate ("open the workspace online");
Expand Down
2 changes: 1 addition & 1 deletion read/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ string read_index (Webserver_Request& webserver_request)
script_stream << "var verticalCaretPosition = " << verticalCaretPosition << ";\n";
script_stream << "var verseSeparator = " << quoted(Database_Config_General::getNotesVerseSeparator ()) << ";\n";
string script {script_stream.str()};
config::logic::swipe_enabled (std::addressof(webserver_request), script);
config::logic::swipe_enabled (webserver_request, script);
view.set_variable ("script", script);

string cls = Filter_Css::getClass (bible);
Expand Down
2 changes: 1 addition & 1 deletion resource/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ string resource_index (Webserver_Request& webserver_request)
int window_position = config_globals_resource_window_positions [username];
string script = "var resourceCount = " + filter::strings::convert_to_string (resource_count) + ";\n"
"var resourceWindowPosition = " + filter::strings::convert_to_string (window_position) + ";";
config::logic::swipe_enabled (std::addressof(webserver_request), script);
config::logic::swipe_enabled (webserver_request, script);
view.set_variable ("script", script);


Expand Down
2 changes: 1 addition & 1 deletion resource/user1view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ string resource_user1view (Webserver_Request& webserver_request)
}
}
string script = filter::strings::implode (code, "\n");
config::logic::swipe_enabled (std::addressof(webserver_request), script);
config::logic::swipe_enabled (webserver_request, script);
view.set_variable ("script", script);


Expand Down
2 changes: 1 addition & 1 deletion search/all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ string search_all (Webserver_Request& webserver_request)
Database_Notes database_notes = Database_Notes (webserver_request);


const string site_url = config::logic::site_url (std::addressof(webserver_request));
const string site_url = config::logic::site_url (webserver_request);


vector <string> bibles = access_bible::bibles (webserver_request);
Expand Down
2 changes: 1 addition & 1 deletion search/replace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool search_replace_acl (Webserver_Request& webserver_request)

string search_replace (Webserver_Request& webserver_request)
{
const string siteUrl = config::logic::site_url (std::addressof(webserver_request));
const string siteUrl = config::logic::site_url (webserver_request);

string bible = webserver_request.database_config_user()->getBible ();
if (webserver_request.query.count ("b")) {
Expand Down
2 changes: 1 addition & 1 deletion search/replacego.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool search_replacego_acl (Webserver_Request& webserver_request)

string search_replacego (Webserver_Request& webserver_request)
{
string siteUrl = config::logic::site_url (std::addressof(webserver_request));
string siteUrl = config::logic::site_url (webserver_request);


// Get the action variables from the query.
Expand Down
2 changes: 1 addition & 1 deletion search/replacego2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool search_replacego2_acl (Webserver_Request& webserver_request)

string search_replacego2 (Webserver_Request& webserver_request)
{
string siteUrl = config::logic::site_url (std::addressof(webserver_request));
string siteUrl = config::logic::site_url (webserver_request);


// Get the action variables from the query.
Expand Down
2 changes: 1 addition & 1 deletion search/replacepre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool search_replacepre_acl (Webserver_Request& webserver_request)

string search_replacepre (Webserver_Request& webserver_request)
{
string siteUrl = config::logic::site_url (std::addressof(webserver_request));
string siteUrl = config::logic::site_url (webserver_request);


// Get search variables from the query.
Expand Down
2 changes: 1 addition & 1 deletion search/replacepre2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool search_replacepre2_acl (Webserver_Request& webserver_request)

string search_replacepre2 (Webserver_Request& webserver_request)
{
string siteUrl = config::logic::site_url (std::addressof(webserver_request));
string siteUrl = config::logic::site_url (webserver_request);


// Get search variables from the query.
Expand Down
2 changes: 1 addition & 1 deletion search/search2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool search_search2_acl (Webserver_Request& webserver_request)

string search_search2 (Webserver_Request& webserver_request)
{
string siteUrl = config::logic::site_url (std::addressof(webserver_request));
string siteUrl = config::logic::site_url (webserver_request);


string bible = webserver_request.database_config_user()->getBible ();
Expand Down
2 changes: 1 addition & 1 deletion sendreceive/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ string sendreceive_index (Webserver_Request& webserver_request)
}


bool basic_mode = config::logic::basic_mode (std::addressof(webserver_request));
bool basic_mode = config::logic::basic_mode (webserver_request);
if (basic_mode) view.enable_zone("basicmode");

page += view.render ("sendreceive", "index");
Expand Down
2 changes: 1 addition & 1 deletion statistics/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void statistics_statistics ()
Database_Logs::log (translate("Sending statistics"), Filter_Roles::manager ());


string siteUrl = config::logic::site_url (nullptr);
string siteUrl = config::logic::site_url (webserver_request);


vector <string> bibles = webserver_request.database_bibles()->get_bibles ();
Expand Down

0 comments on commit 63f0efa

Please sign in to comment.