Miscellaneous
+
diff --git a/doc/prefs_impl.html b/doc/prefs_impl.html
new file mode 100644
index 0000000000..ae4ce02882
--- /dev/null
+++ b/doc/prefs_impl.html
@@ -0,0 +1,52 @@
+
+In database:
+ user.global_prefs: XML, within tags
+ may be empty; nonempty only if user has actually seen
+ always includes element
+ includes , elements if
+ prefs came from another project
+ user.project_prefs: XML, within tags
+ always present.
+ contains at least element
+
+In client:
+ global_prefs.xml (present ONLY if have obtained from a server)
+ same as user.global_prefs,
+ but the following is inserted at start:
+
+
+ stored in memory:
+ in parsed form (as struct)
+ account_XXX.xml
+ same as user.project_prefs, but with the following added:
+
+
+ stored in memory:
+ in PROJECT struct
+ master_url, authenticator, resource share parsed;
+ project_specific_prefs raw XML (with enclosing tags)
+
+
+RPC request:
+ includes global_prefs.xml if it's there
+
+RPC handling and reply:
+ always send project prefs
+ if request message includes global prefs
+ if missing in DB, or request copy is newer:
+ install in DB
+ else if DB copy is newer
+ include DB copy in reply
+ else
+ if present in DB, include in reply
+
+handling of RPC reply
+ if includes global prefs
+ insert , elements if missing
+ write to global_prefs.xml
+ parse into memory
+ project prefs
+ insert , elements,
+ write to account_XXX.xml file
+ parse; update resource share, project_specific_prefs in PROJECT struct
+
diff --git a/doc/prefs_mod.html b/doc/prefs_mod.html
deleted file mode 100644
index 927942558a..0000000000
--- a/doc/prefs_mod.html
+++ /dev/null
@@ -1,4 +0,0 @@
-Modifying Preferences
-
-Modifying Preferences
-
diff --git a/html/user/prefs.inc b/html/user/prefs.inc
index 5433a45f6e..4d21258479 100644
--- a/html/user/prefs.inc
+++ b/html/user/prefs.inc
@@ -287,6 +287,8 @@ function prefs_project_parse_form(&$prefs) {
//
function global_prefs_make_xml($prefs) {
$xml = "\n";
+ $now = time();
+ $xml = $xml."$now\n";
if ($prefs->dont_run_on_batteries) {
$xml = $xml."\n";
}
@@ -322,14 +324,12 @@ function project_prefs_make_xml($prefs) {
//
function global_prefs_update($user, $prefs) {
$prefs_xml = global_prefs_make_xml($prefs);
- $now = time();
- mysql_query("update user set global_prefs='$prefs_xml', global_prefs_mod_time=$now where id=$user->id");
+ mysql_query("update user set global_prefs='$prefs_xml' where id=$user->id");
$user->global_prefs = $prefs_xml;
}
function project_prefs_update($user, $prefs) {
$prefs_xml = project_prefs_make_xml($prefs);
- $now = time();
mysql_query("update user set project_prefs='$prefs_xml' where id=$user->id");
$user->project_prefs = $prefs_xml;
}
diff --git a/sched/handle_request.C b/sched/handle_request.C
index a3a22225e8..8c5e628039 100644
--- a/sched/handle_request.C
+++ b/sched/handle_request.C
@@ -224,23 +224,39 @@ int update_host_record(SCHEDULER_REQUEST& sreq, HOST& host) {
return 0;
}
+// Deal with global preferences.
// If the client sent global prefs, and they're more recent than ours,
// update user record in DB.
-// If we our DB has more recent global prefs than client's, send them.
+// If DB has more recent global prefs than client's, send them.
//
int handle_global_prefs(SCHEDULER_REQUEST& sreq, SCHEDULER_REPLY& reply) {
- if (sreq.global_prefs_mod_time > reply.user.global_prefs_mod_time
- && strlen(sreq.global_prefs_xml)
- ) {
- strncpy(reply.user.global_prefs, sreq.global_prefs_xml, sizeof(reply.user.global_prefs));
- reply.user.global_prefs_mod_time = sreq.global_prefs_mod_time;
- if (reply.user.global_prefs_mod_time > (unsigned)time(0)) {
- reply.user.global_prefs_mod_time = (unsigned)time(0);
+ unsigned int req_mod_time, db_mod_time;
+ bool need_update;
+ reply.send_global_prefs = false;
+ if (sreq.global_prefs_xml) {
+ need_update = false;
+ parse_int(sreq.global_prefs_xml, "", (int)req_mod_time);
+ if (strlen(reply.user.global_prefs)) {
+ parse_int(reply.user.global_prefs, "", (int)db_mod_time);
+ if (req_mod_time > db_mod_time) {
+ need_update = true;
+ } else if (req_mod_time < db_mod_time) {
+ reply.send_global_prefs = true;
+ }
+ } else {
+ need_update = true;
+ }
+ if (need_update) {
+ strncpy(
+ reply.user.global_prefs, sreq.global_prefs_xml,
+ sizeof(reply.user.global_prefs)
+ );
+ db_user_update(reply.user);
+ }
+ } else {
+ if (strlen(reply.user.global_prefs)) {
+ reply.send_global_prefs = true;
}
- db_user_update(reply.user);
- }
- if (reply.user.global_prefs_mod_time > sreq.global_prefs_mod_time) {
- reply.send_global_prefs = true;
}
return 0;
}
diff --git a/sched/server_types.C b/sched/server_types.C
index dbac35f0c4..588d159047 100644
--- a/sched/server_types.C
+++ b/sched/server_types.C
@@ -46,7 +46,6 @@ int SCHEDULER_REQUEST::parse(FILE* fin) {
strcpy(authenticator, "");
hostid = 0;
work_req_seconds = 0;
- global_prefs_mod_time = 0;
global_prefs_xml = strdup("");
fgets(buf, 256, fin);
@@ -59,14 +58,13 @@ int SCHEDULER_REQUEST::parse(FILE* fin) {
else if (parse_str(buf, "", platform_name, sizeof(platform_name))) continue;
else if (parse_int(buf, "", core_client_version)) continue;
else if (parse_int(buf, "", work_req_seconds)) continue;
- else if (parse_int(buf, "", (int)global_prefs_mod_time)) {
- continue;
- }
- else if (match_tag(buf, "")) {
+ else if (match_tag(buf, "")) {
+ global_prefs_xml = strdup("\n");
while (fgets(buf, 256, fin)) {
- if (strstr(buf, "")) break;
+ if (strstr(buf, "")) break;
strcatdup(global_prefs_xml, buf);
}
+ strcatdup(global_prefs_xml, "