CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swissknife_lease_json.cc
Go to the documentation of this file.
1 
6 
7 #include "json.h"
8 #include "json_document.h"
9 #include "util/pointer.h"
10 
11 #include "util/logging.h"
12 
14  std::string *session_token) {
15  if (buffer.data.size() == 0 || session_token == NULL) {
16  return kLeaseReplyFailure;
17  }
18 
20  if (!reply.IsValid() || !reply->IsValid()) {
21  return kLeaseReplyFailure;
22  }
23 
24  const JSON *result =
25  JsonDocument::SearchInObject(reply->root(), "status", JSON_STRING);
26  if (result != NULL) {
27  const std::string status = result->string_value;
28  if (status == "ok") {
29  LogCvmfs(kLogCvmfs, kLogStdout, "Gateway reply: ok");
30  const JSON *token = JsonDocument::SearchInObject(
31  reply->root(), "session_token", JSON_STRING);
32  if (token != NULL) {
33  LogCvmfs(kLogCvmfs, kLogDebug, "Session token: %s",
34  token->string_value);
35  *session_token = token->string_value;
36  return kLeaseReplySuccess;
37  }
38  } else if (status == "path_busy") {
39  const JSON *time_remaining = JsonDocument::SearchInObject(
40  reply->root(), "time_remaining", JSON_INT);
41  if (time_remaining != NULL) {
42  LogCvmfs(kLogCvmfs, kLogStdout, "Path busy. Time remaining = %d s",
43  time_remaining->int_value);
44  return kLeaseReplyBusy;
45  }
46  } else if (status == "error") {
47  const JSON *reason =
48  JsonDocument::SearchInObject(reply->root(), "reason", JSON_STRING);
49  if (reason != NULL) {
50  LogCvmfs(kLogCvmfs, kLogStdout, "Error: %s", reason->string_value);
51  }
52  } else {
53  LogCvmfs(kLogCvmfs, kLogStdout, "Unknown reply. Status: %s",
54  status.c_str());
55  }
56  }
57 
58  return kLeaseReplyFailure;
59 }
60 
62  if (buffer.data.size() == 0) {
63  return kLeaseReplyFailure;
64  }
65 
67  if (!reply.IsValid() || !reply->IsValid()) {
68  return kLeaseReplyFailure;
69  }
70 
71  const JSON *result =
72  JsonDocument::SearchInObject(reply->root(), "status", JSON_STRING);
73  if (result != NULL) {
74  const std::string status = result->string_value;
75  if (status == "ok") {
76  LogCvmfs(kLogCvmfs, kLogStdout, "Gateway reply: ok");
77  return kLeaseReplySuccess;
78  } else if (status == "invalid_token") {
79  LogCvmfs(kLogCvmfs, kLogStdout, "Error: invalid session token");
80  } else if (status == "error") {
81  const JSON *reason =
82  JsonDocument::SearchInObject(reply->root(), "reason", JSON_STRING);
83  if (reason != NULL) {
84  LogCvmfs(kLogCvmfs, kLogStdout, "Error: %s", reason->string_value);
85  }
86  } else {
87  LogCvmfs(kLogCvmfs, kLogStdout, "Unknown reply. Status: %s",
88  status.c_str());
89  }
90  }
91 
92  return kLeaseReplyFailure;
93 }
static JSON * SearchInObject(const JSON *json_object, const std::string &name, const json_type type)
std::string data
bool IsValid() const
Definition: json_document.h:26
static JsonDocument * Create(const std::string &text)
static LeaseReply ParseDropReply(const CurlBuffer &buffer, int llvl)
struct json_value JSON
Definition: helper_allow.cc:11
static LeaseReply ParseAcquireReply(const CurlBuffer &buffer, std::string *session_token, int llvl)
const JSON * root() const
Definition: json_document.h:25
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528