From 593181e196837ca62f11d4ea4930a47326bbca91 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 26 Feb 2014 16:16:51 -0800 Subject: [PATCH] scheduler: if gui_urls.xml or project_files.xml don't end with \n, add one Otherwise the scheduler reply has two tags on one line, which messes up old clients that don't use the new XML parse --- lib/str_util.cpp | 11 +++++++++++ lib/str_util.h | 5 +++++ sched/sched_types.cpp | 2 ++ 3 files changed, 18 insertions(+) diff --git a/lib/str_util.cpp b/lib/str_util.cpp index 85c2eb6b28..9339efe2ac 100644 --- a/lib/str_util.cpp +++ b/lib/str_util.cpp @@ -703,3 +703,14 @@ void strip_translation(char* p) { remove_str(p, "_(\""); remove_str(p, "\")"); } + +char* lf_terminate(char* p) { + int n = strlen(p); + if (p[n-1] == '\n') { + return p; + } + p = (char*)realloc(p, n+2); + p[n] = '\n'; + p[n+1] = 0; + return p; +} diff --git a/lib/str_util.h b/lib/str_util.h index 8dcfd5ce8f..a1adaf9a6f 100644 --- a/lib/str_util.h +++ b/lib/str_util.h @@ -75,6 +75,11 @@ extern int string_substitute( // extern void mysql_timestamp(double, char*); +// take a malloced string. +// if \n is not last char, add it. +// +extern char* lf_terminate(char*); + extern const char* network_status_string(int); extern const char* rpc_reason_string(int); extern const char* suspend_reason_string(int reason); diff --git a/sched/sched_types.cpp b/sched/sched_types.cpp index 7e2b2d039a..2454d3e077 100644 --- a/sched/sched_types.cpp +++ b/sched/sched_types.cpp @@ -1344,6 +1344,7 @@ void GLOBAL_PREFS::defaults() { void GUI_URLS::init() { text = 0; read_file_malloc(config.project_path("gui_urls.xml"), text); + text = lf_terminate(text); } void GUI_URLS::get_gui_urls(USER& user, HOST& host, TEAM& team, char* buf, int len) { @@ -1385,6 +1386,7 @@ void GUI_URLS::get_gui_urls(USER& user, HOST& host, TEAM& team, char* buf, int l void PROJECT_FILES::init() { text = 0; read_file_malloc(config.project_path("project_files.xml"), text); + text = lf_terminate(text); } void get_weak_auth(USER& user, char* buf) {