Add debug output to state load/save

This commit is contained in:
Gergely Polonkai 2016-03-20 18:46:59 +00:00
parent 21ee03d030
commit 33bb63e4f1
1 changed files with 28 additions and 0 deletions

View File

@ -594,6 +594,10 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
var node = new Json.Node(Json.NodeType.OBJECT);
node.set_object(root);
if (Config.DEBUG) {
debug("Saving state to %s\n", filename);
}
var generator = new Json.Generator();
generator.set_root(node);
generator.to_file(filename);
@ -605,6 +609,10 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
{
var parser = new Json.Parser();
if (Config.DEBUG) {
debug("Loading state from %s\n", filename);
}
parser.load_from_file(filename);
Json.Node? node = parser.get_root();
@ -622,6 +630,10 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
base_url = node.get_string();
if (Config.DEBUG) {
debug("Loaded base URL %s", base_url);
}
if ((node = root.get_member("validate_certificate")) == null) {
throw new Matrix.Error.INVALID_FORMAT(
"Save data has no validate_certificate key");
@ -631,18 +643,34 @@ public class Matrix.HTTPClient : Matrix.HTTPAPI, Matrix.Client {
if ((node = root.get_member("user_id")) != null) {
_user_id = node.get_string();
if (Config.DEBUG) {
debug("Loaded user ID %s", user_id);
}
}
if ((node = root.get_member("homeserver_name")) != null) {
_homeserver = node.get_string();
if (Config.DEBUG) {
debug("Loaded homeserver name %s", homeserver);
}
}
if ((node = root.get_member("access_token")) != null) {
token = node.get_string();
if (Config.DEBUG) {
debug("Loaded access token %s", token);
}
}
if ((node = root.get_member("refresh_token")) != null) {
refresh_token = node.get_string();
if (Config.DEBUG) {
debug("Loaded refresh token %s", refresh_token);
}
}
}
}