diff --git a/client/app_control.cpp b/client/app_control.cpp index 750e53de66..4a83dbc317 100644 --- a/client/app_control.cpp +++ b/client/app_control.cpp @@ -69,6 +69,7 @@ using std::vector; #include "shmem.h" #include "str_replace.h" #include "str_util.h" +#include "url.h" #include "util.h" #include "client_msgs.h" @@ -1633,7 +1634,7 @@ void ACTIVE_TASK::read_task_state_file() { ); return; } - if (strcmp(s, result->project->master_url)) { + if (!urls_match(s, result->project->master_url)) { msg_printf(wup->project, MSG_INTERNAL_ERROR, "wrong project URL in task state file" ); diff --git a/client/client_state.cpp b/client/client_state.cpp index b8aed81b8d..ffd6f29bdd 100644 --- a/client/client_state.cpp +++ b/client/client_state.cpp @@ -51,6 +51,7 @@ #include "parse.h" #include "str_replace.h" #include "str_util.h" +#include "url.h" #include "util.h" #ifdef _WIN32 #include "run_app_windows.h" @@ -1189,21 +1190,21 @@ bool CLIENT_STATE::poll_slow_events() { #endif // ifndef SIM -// See if the project specified by master_url already exists -// in the client state record. Ignore any trailing "/" characters +// Find the project with the given master_url. +// Ignore differences in protocol, case, and trailing / // PROJECT* CLIENT_STATE::lookup_project(const char* master_url) { - int len1, len2; - char *mu; + char buf[256]; - len1 = (int)strlen(master_url); - if (master_url[strlen(master_url)-1] == '/') len1--; + safe_strcpy(buf, master_url); + canonicalize_master_url(buf, sizeof(buf)); + char* p = strstr(buf, "//"); + if (!p) return NULL; for (unsigned int i=0; imaster_url; - len2 = (int)strlen(mu); - if (mu[strlen(mu)-1] == '/') len2--; - if (!strncmp(master_url, projects[i]->master_url, max(len1,len2))) { + char* q = strstr(projects[i]->master_url, "//"); + if (!q) continue; + if (!strcmp(p, q)) { return projects[i]; } } diff --git a/client/gui_rpc_server_ops.cpp b/client/gui_rpc_server_ops.cpp index b684c356e7..c409aa5ae1 100644 --- a/client/gui_rpc_server_ops.cpp +++ b/client/gui_rpc_server_ops.cpp @@ -748,7 +748,7 @@ static void handle_get_project_init_status(GUI_RPC_CONN& grc) { // for (unsigned i=0; imaster_url, gstate.project_init.url)) { + if (urls_match(p->master_url, gstate.project_init.url)) { gstate.project_init.remove(); break; } diff --git a/client/log_flags.cpp b/client/log_flags.cpp index 40d4bad109..81a1a86443 100644 --- a/client/log_flags.cpp +++ b/client/log_flags.cpp @@ -37,6 +37,7 @@ #include "parse.h" #include "str_replace.h" #include "str_util.h" +#include "url.h" #include "client_state.h" #include "client_msgs.h" @@ -681,7 +682,7 @@ void process_gpu_exclusions() { for (j=0; jmaster_url)) continue; + if (!urls_match(eg.url.c_str(), p->master_url)) continue; COPROC_INSTANCE_BITMAP mask; if (eg.device_num >= 0) { int index = cp.device_num_index(eg.device_num); @@ -775,7 +776,7 @@ bool gpu_excluded(APP* app, COPROC& cp, int ind) { PROJECT* p = app->project; for (unsigned int i=0; imaster_url)) continue; + if (!urls_match(eg.url.c_str(), p->master_url)) continue; if (!eg.type.empty() && (eg.type != cp.type)) continue; if (!eg.appname.empty() && (eg.appname != app->name)) continue; if (eg.device_num >= 0 && eg.device_num != cp.device_nums[ind]) continue; diff --git a/lib/url.cpp b/lib/url.cpp index 1a7e77aff2..5d9ed3a268 100644 --- a/lib/url.cpp +++ b/lib/url.cpp @@ -248,6 +248,15 @@ bool is_https_transition(const char* url1, const char* url2) { return true; } +// return true if url1 and url2 are the same except protocol +// +bool urls_match(const char* url1, const char* url2) { + const char* p = strstr(url1, "//"); + const char* q = strstr(url2, "//"); + if (!p || !q) return false; + return strcmp(p, q) == 0; +} + // is the string a valid master URL, in canonical form? // bool valid_master_url(char* buf) { diff --git a/lib/url.h b/lib/url.h index fd27e41e75..943c9a21dc 100644 --- a/lib/url.h +++ b/lib/url.h @@ -47,5 +47,5 @@ extern void canonicalize_master_url(char *url, int len); extern void canonicalize_master_url(std::string&); extern bool is_https(const char*); extern bool is_https_transition(const char* ur1l, const char* url2); - +extern bool urls_match(const char* url1, const char* url2); #endif