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 0f87a7f commit b6af6cf
Show file tree
Hide file tree
Showing 46 changed files with 73 additions and 74 deletions.
2 changes: 1 addition & 1 deletion bootstrap/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,5 +1241,5 @@ void bootstrap_index (Webserver_Request& webserver_request)
}

// Forward the browser to the default home page.
redirect_browser (std::addressof(webserver_request), index_index_url ());
redirect_browser (webserver_request, index_index_url ());
}
2 changes: 1 addition & 1 deletion changes/manage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ string changes_manage (Webserver_Request& webserver_request)
database_jobs.set_level (jobId, Filter_Roles::manager ());
database_jobs.set_start (jobId, translate ("Clearing change notifications."));
tasks_logic_queue (DELETECHANGES, {filter::strings::convert_to_string (jobId), username});
redirect_browser (std::addressof(webserver_request), jobs_index_url () + "?id=" + filter::strings::convert_to_string (jobId));
redirect_browser (webserver_request, jobs_index_url () + "?id=" + filter::strings::convert_to_string (jobId));
return string();
}

Expand Down
2 changes: 1 addition & 1 deletion collaboration/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ string collaboration_settings (Webserver_Request& webserver_request)
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 (std::addressof(webserver_request), jobs_index_url () + "?id=" + filter::strings::convert_to_string (jobId));
redirect_browser (webserver_request, jobs_index_url () + "?id=" + filter::strings::convert_to_string (jobId));
return "";
}
}
Expand Down
2 changes: 1 addition & 1 deletion compare/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::string compare_index (Webserver_Request& webserver_request)
const int job_id = database_jobs.get_new_id ();
database_jobs.set_level (job_id, Filter_Roles::consultant ());
tasks_logic_queue (COMPAREUSFM, {bible, compare, filter::strings::convert_to_string (job_id)});
redirect_browser (std::addressof(webserver_request), jobs_index_url () + "?id=" + filter::strings::convert_to_string (job_id));
redirect_browser (webserver_request, jobs_index_url () + "?id=" + filter::strings::convert_to_string (job_id));
return std::string();
}

Expand Down
2 changes: 1 addition & 1 deletion config/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ string site_url (void * webserver_request)
if (webserver_request) {
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
if (!request->host.empty ()) {
url = get_base_url (request);
url = get_base_url (*request);
return url;
}
}
Expand Down
2 changes: 1 addition & 1 deletion editor/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ string editor_select (Webserver_Request& webserver_request)
bool match = false;
for (auto url : urls) {
if (match) {
redirect_browser (std::addressof(webserver_request), url);
redirect_browser (webserver_request, url);
return "";
}
if (url.find (from) == 0) match = true;
Expand Down
21 changes: 9 additions & 12 deletions filter/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,41 +126,38 @@ vector <string> filter_url_scandir_internal (string folder)


// Gets the base URL of current Bibledit installation.
string get_base_url (void * webserver_request)
string get_base_url (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
string scheme;
string port;
if (request->secure || config_globals_enforce_https_browser) {
if (webserver_request.secure || config_globals_enforce_https_browser) {
scheme = "https";
port = config::logic::https_network_port ();
} else {
scheme = "http";
port = config::logic::http_network_port ();
}
string url = scheme + "://" + request->host + ":" + port + "/";
string url = scheme + "://" + webserver_request.host + ":" + port + "/";
return url;
}


// This function redirects the browser to "path".
// "path" is an absolute value.
void redirect_browser (void * webserver_request, string path)
void redirect_browser (Webserver_Request& webserver_request, string path)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

// A location header should contain an absolute url, like http://localhost/some/path.
// See 14.30 in the specification https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html.

// 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 (webserver_request);
string location = config::logic::site_url (std::addressof(webserver_request));

// If the request was secure, or supposed to be secure,
// ensure the location contains https rather than plain http,
// plus the correct secure port.
if (request->secure || config_globals_enforce_https_browser) {
if (webserver_request.secure || config_globals_enforce_https_browser) {
location = filter::strings::replace ("http:", "https:", location);
string plainport = config::logic::http_network_port ();
string secureport = config::logic::https_network_port ();
Expand All @@ -171,14 +168,14 @@ void redirect_browser (void * webserver_request, string path)

// If the page contains the topbar suppressing query,
// the same query will be appended on the URL of the redirected page.
if (request->query.count ("topbar") || request->post.count ("topbar")) {
if (webserver_request.query.count ("topbar") || webserver_request.post.count ("topbar")) {
string new_location = filter_url_build_http_query (location, "topbar", "0");
location.clear ();
location.append (new_location);
}

request->header = "Location: " + location;
request->response_code = 302;
webserver_request.header = "Location: " + location;
webserver_request.response_code = 302;
}


Expand Down
6 changes: 4 additions & 2 deletions filter/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#include <config/libraries.h>

std::string get_base_url (void * webserver_request);
void redirect_browser (void * webserver_request, std::string url);
class Webserver_Request;

std::string get_base_url (Webserver_Request& webserver_request);
void redirect_browser (Webserver_Request& webserver_request, std::string url);
std::string filter_url_dirname (std::string url);
std::string filter_url_dirname_web (std::string url);
std::string filter_url_basename (std::string url);
Expand Down
2 changes: 1 addition & 1 deletion journal/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ string journal_index (Webserver_Request& webserver_request)
// and then the user activates the screen on the mobile device,
// the logbook will then again be cleared, because that was the last opened URL.
// Redirecting the browser to a clean URL fixes this behaviour.
redirect_browser (std::addressof(webserver_request), journal_index_url ());
redirect_browser (webserver_request, journal_index_url ());
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion manage/hyphenation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ string manage_hyphenation (Webserver_Request& webserver_request)
error = translate("No second set of characters given");
} else {
tasks_logic_queue (HYPHENATE, {bible, webserver_request.session_logic()->currentUser ()});
redirect_browser (std::addressof(webserver_request), journal_index_url ());
redirect_browser (webserver_request, journal_index_url ());
return "";
}
}
Expand Down
2 changes: 1 addition & 1 deletion manage/users.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ string manage_users (Webserver_Request& webserver_request)
// Login on behalf of another user.
if (webserver_request.query.count ("login")) {
webserver_request.session_logic ()->switch_user (objectUsername);
redirect_browser (std::addressof(webserver_request), session_switch_url ());
redirect_browser (webserver_request, session_switch_url ());
return string();
}

Expand Down
2 changes: 1 addition & 1 deletion menu/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ std::string menu_index (Webserver_Request& webserver_request)
{
std::string item = webserver_request.query ["item"];
item = menu_logic_click (item);
redirect_browser (std::addressof(webserver_request), item);
redirect_browser (webserver_request, item);
return std::string();
}
2 changes: 1 addition & 1 deletion nmt/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ string nmt_index (Webserver_Request& webserver_request)

if (webserver_request.query.count ("export")) {
tasks_logic_queue (EXPORT2NMT, {referencebible, translatingbible});
redirect_browser (std::addressof(webserver_request), journal_index_url ());
redirect_browser (webserver_request, journal_index_url ());
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion notes/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ string notes_actions (Webserver_Request& webserver_request)

if (webserver_request.query.count ("delete")) {
notes_logic.erase (id);
redirect_browser (std::addressof(webserver_request), notes_index_url ());
redirect_browser (webserver_request, notes_index_url ());
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion notes/assign-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ string notes_assign_1 (Webserver_Request& webserver_request)
if (database_noteassignment.exists (user, assign)) {
notes_logic.assignUser (id, assign);
}
redirect_browser (std::addressof(webserver_request), notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
redirect_browser (webserver_request, notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion notes/bb-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ string notes_bible_1 (Webserver_Request& webserver_request)
string bible = webserver_request.query["bible"];
if (bible == notes_logic.generalBibleName ()) bible.clear();
notes_logic.setBible (id, bible);
redirect_browser (std::addressof(webserver_request), notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
redirect_browser (webserver_request, notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
}

Expand Down
4 changes: 2 additions & 2 deletions notes/comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ string notes_comment (Webserver_Request& webserver_request)
string comment = filter::strings::trim (webserver_request.post ["body"]);
comment = filter_url_tag_to_plus (comment);
notes_logic.addComment (id, comment);
redirect_browser (std::addressof(webserver_request), notes_note_url () + "?id=" + filter::strings::convert_to_string (id) + "&temporal=");
redirect_browser (webserver_request, notes_note_url () + "?id=" + filter::strings::convert_to_string (id) + "&temporal=");
return "";
}


if (webserver_request.post.count ("cancel")) {
redirect_browser (std::addressof(webserver_request), notes_note_url () + "?id=" + filter::strings::convert_to_string (id));
redirect_browser (webserver_request, notes_note_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion notes/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ string notes_create (Webserver_Request& webserver_request)


if (webserver_request.post.count ("cancel")) {
redirect_browser (std::addressof(webserver_request), notes_index_url ());
redirect_browser (webserver_request, notes_index_url ());
return string();
}

Expand Down
2 changes: 1 addition & 1 deletion notes/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ string notes_edit (Webserver_Request& webserver_request)
notes_logic.setContent (identifier, noteData);
string url = filter_url_build_http_query (notes_note_url (), "id", filter::strings::convert_to_string (identifier));
// View the updated note.
redirect_browser (std::addressof(webserver_request), url);
redirect_browser (webserver_request, url);
return "";
}
}
Expand Down
2 changes: 1 addition & 1 deletion notes/severity-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ string notes_severity_1 (Webserver_Request& webserver_request)
if (webserver_request.query.count ("severity")) {
int severity = filter::strings::convert_to_int (webserver_request.query["severity"]);
notes_logic.setRawSeverity (id, severity);
redirect_browser (std::addressof(webserver_request), notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
redirect_browser (webserver_request, notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
return std::string();
}

Expand Down
2 changes: 1 addition & 1 deletion notes/status-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ string notes_status_1 (Webserver_Request& webserver_request)
if (webserver_request.query.count ("status")) {
string status = webserver_request.query["status"];
notes_logic.setStatus (id, status);
redirect_browser (std::addressof(webserver_request), notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
redirect_browser (webserver_request, notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion notes/summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ string notes_summary (Webserver_Request& webserver_request)
if (webserver_request.post.count ("submit")) {
string summary = webserver_request.post["entry"];
notes_logic.set_summary (id, summary);
redirect_browser (std::addressof(webserver_request), notes_note_url () + "?id=" + filter::strings::convert_to_string (id));
redirect_browser (webserver_request, notes_note_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion notes/verses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ string notes_verses (Webserver_Request& webserver_request)
error = translate ("The note should have one or more passages assigned.");
} else {
notes_logic.setPassages (id, passages);
redirect_browser (std::addressof(webserver_request), notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
redirect_browser (webserver_request, notes_actions_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
}
}
Expand Down
2 changes: 1 addition & 1 deletion paratext/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ string paratext_index (Webserver_Request& webserver_request)
}
view.set_variable ("master", master);
view.enable_zone ("setuprunning");
redirect_browser (std::addressof(webserver_request), journal_index_url ());
redirect_browser (webserver_request, journal_index_url ());
return "";
}
}
Expand Down
4 changes: 2 additions & 2 deletions public/comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ string public_comment (Webserver_Request& webserver_request)
if (webserver_request.post.count ("submit")) {
string comment = filter::strings::trim (webserver_request.post ["comment"]);
notes_logic.addComment (id, comment);
redirect_browser (std::addressof(webserver_request), public_note_url () + "?id=" + filter::strings::convert_to_string (id));
redirect_browser (webserver_request, public_note_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
}


if (webserver_request.post.count ("cancel")) {
redirect_browser (std::addressof(webserver_request), public_note_url () + "?id=" + filter::strings::convert_to_string (id));
redirect_browser (webserver_request, public_note_url () + "?id=" + filter::strings::convert_to_string (id));
return "";
}

Expand Down
4 changes: 2 additions & 2 deletions public/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ string public_create (Webserver_Request& webserver_request)
database_notes.subscribe (identifier);
// Go to the main public notes page.
if (config::logic::default_bibledit_configuration ()) {
redirect_browser (std::addressof(webserver_request), public_index_url ());
redirect_browser (webserver_request, public_index_url ());
}
return std::string();
}


if (webserver_request.post.count ("cancel")) {
if (config::logic::default_bibledit_configuration ()) {
redirect_browser (std::addressof(webserver_request), public_index_url ());
redirect_browser (webserver_request, public_index_url ());
}
return std::string();
}
Expand Down
2 changes: 1 addition & 1 deletion public/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ string public_index (Webserver_Request& webserver_request)
{
// If the person providing public feedback is not logged in, foward to the page for entering details.
if (!webserver_request.session_logic ()->loggedIn ()) {
redirect_browser (std::addressof(webserver_request), public_login_url ());
redirect_browser (webserver_request, public_login_url ());
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion public/login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ std::string public_login (Webserver_Request& webserver_request)


if (webserver_request.session_logic ()->loggedIn ()) {
redirect_browser (std::addressof(webserver_request), public_index_url ());
redirect_browser (webserver_request, public_index_url ());
return std::string();
}

Expand Down
2 changes: 1 addition & 1 deletion redirect/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ std::string editone_index (Webserver_Request& webserver_request)
for (auto query : webserver_request.query) {
url = filter_url_build_http_query (url, query.first, query.second);
}
redirect_browser (std::addressof(webserver_request), url);
redirect_browser (webserver_request, url);
return std::string();
}
2 changes: 1 addition & 1 deletion resource/bb2resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ std::string resource_bible2resource (Webserver_Request& webserver_request)
if (webserver_request.query.count ("convert")) {
if (access_bible::write (webserver_request, bible)) {
tasks_logic_queue (CONVERTBIBLE2RESOURCE, {bible});
redirect_browser (std::addressof(webserver_request), journal_index_url ());
redirect_browser (webserver_request, journal_index_url ());
return std::string();
} else {
assets_page::error (translate("Insufficient privileges to complete operation."));
Expand Down
2 changes: 1 addition & 1 deletion resource/comparative9edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ string resource_comparative9edit (Webserver_Request& webserver_request)
client_logic_no_cache_resource_add (new_resource);
// Redirect the user to the place where to edit that new resource.
string url = resource_comparative1edit_url () + "?name=" + new_resource;
redirect_browser (std::addressof(webserver_request), url);
redirect_browser (webserver_request, url);
return "";
}
}
Expand Down
2 changes: 1 addition & 1 deletion resource/divider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ string resource_divider (Webserver_Request& webserver_request)
if (is_def) Database_Config_General::setDefaultActiveResources (resources);
else webserver_request.database_config_user()->setActiveResources (resources);
if (!is_def) webserver_request.database_config_user()->addUpdatedSetting (Sync_Logic::settings_send_resources_organization);
redirect_browser (std::addressof(webserver_request), resource_organize_url ());
redirect_browser (webserver_request, resource_organize_url ());
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion resource/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ string resource_download (Webserver_Request& webserver_request)
Database_Config_General::setResourcesToCache (resources);
}
tasks_logic_queue (SYNCRESOURCES);
redirect_browser (std::addressof(webserver_request), journal_index_url ());
redirect_browser (webserver_request, journal_index_url ());
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion resource/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ string resource_image (Webserver_Request& webserver_request)
// Immediately open the uploaded image.
string url = filter_url_build_http_query (resource_img_url (), "name", name);
url = filter_url_build_http_query (url, "image", image);
redirect_browser (std::addressof(webserver_request), url);
redirect_browser (webserver_request, url);
return "";
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion resource/img.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ string resource_img (Webserver_Request& webserver_request)

error = filter::strings::implode (errors, " ");
if (errors.empty ()) {
redirect_browser (std::addressof(webserver_request), filter_url_build_http_query (resource_image_url (), "name", name));
redirect_browser (webserver_request, filter_url_build_http_query (resource_image_url (), "name", name));
return "";
}
}
Expand Down
Loading

0 comments on commit b6af6cf

Please sign in to comment.