CernVM-FS  2.13.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/logging.h"
10 #include "util/pointer.h"
11 
13  std::string *session_token) {
14  if (buffer.data.size() == 0 || session_token == NULL) {
15  return kLeaseReplyFailure;
16  }
17 
19  if (!reply.IsValid() || !reply->IsValid()) {
20  return kLeaseReplyFailure;
21  }
22 
23  const JSON *result = JsonDocument::SearchInObject(reply->root(), "status",
24  JSON_STRING);
25  if (result != NULL) {
26  const std::string status = result->string_value;
27  if (status == "ok") {
28  LogCvmfs(kLogCvmfs, kLogStdout, "Gateway reply: ok");
29  const JSON *token = JsonDocument::SearchInObject(
30  reply->root(), "session_token", JSON_STRING);
31  if (token != NULL) {
32  LogCvmfs(kLogCvmfs, kLogDebug, "Session token: %s",
33  token->string_value);
34  *session_token = token->string_value;
35  return kLeaseReplySuccess;
36  }
37  } else if (status == "path_busy") {
38  const JSON *time_remaining = JsonDocument::SearchInObject(
39  reply->root(), "time_remaining", JSON_INT);
40  if (time_remaining != NULL) {
41  LogCvmfs(kLogCvmfs, kLogStdout, "Path busy. Time remaining = %d s",
42  time_remaining->int_value);
43  return kLeaseReplyBusy;
44  }
45  } else if (status == "error") {
46  const JSON *reason = JsonDocument::SearchInObject(reply->root(), "reason",
47  JSON_STRING);
48  if (reason != NULL) {
49  LogCvmfs(kLogCvmfs, kLogStdout, "Error: %s", reason->string_value);
50  }
51  } else {
52  LogCvmfs(kLogCvmfs, kLogStdout, "Unknown reply. Status: %s",
53  status.c_str());
54  }
55  }
56 
57  return kLeaseReplyFailure;
58 }
59 
61  if (buffer.data.size() == 0) {
62  return kLeaseReplyFailure;
63  }
64 
66  if (!reply.IsValid() || !reply->IsValid()) {
67  return kLeaseReplyFailure;
68  }
69 
70  const JSON *result = JsonDocument::SearchInObject(reply->root(), "status",
71  JSON_STRING);
72  if (result != NULL) {
73  const std::string status = result->string_value;
74  if (status == "ok") {
75  LogCvmfs(kLogCvmfs, kLogStdout, "Gateway reply: ok");
76  return kLeaseReplySuccess;
77  } else if (status == "invalid_token") {
78  LogCvmfs(kLogCvmfs, kLogStdout, "Error: invalid session token");
79  } else if (status == "error") {
80  const JSON *reason = JsonDocument::SearchInObject(reply->root(), "reason",
81  JSON_STRING);
82  if (reason != NULL) {
83  LogCvmfs(kLogCvmfs, kLogStdout, "Error: %s", reason->string_value);
84  }
85  } else {
86  LogCvmfs(kLogCvmfs, kLogStdout, "Unknown reply. Status: %s",
87  status.c_str());
88  }
89  }
90 
91  return kLeaseReplyFailure;
92 }
static JSON * SearchInObject(const JSON *json_object, const std::string &name, const json_type type)
bool IsValid() const
Definition: json_document.h:26
static JsonDocument * Create(const std::string &text)
std::string data
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:545