00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef UTILS_DOMETALKER_H
00025 #define UTILS_DOMETALKER_H
00026
00027 #include <davix/davix.hpp>
00028 #include "DavixPool.h"
00029 #include "cpp/authn.h"
00030
00031 #include <boost/property_tree/ptree.hpp>
00032
00033 namespace dmlite {
00034
00035 struct DomeCredentials {
00036 std::string clientName;
00037 std::string remoteAddress;
00038 std::vector<std::string> groups;
00039
00040 DomeCredentials(std::string cn, std::string ra, std::vector<std::string> gr) :
00041 clientName(cn), remoteAddress(ra), groups(gr) {}
00042
00043 DomeCredentials() {}
00044 DomeCredentials(const SecurityContext *ctx) {
00045 if(ctx) {
00046 clientName = ctx->credentials.clientName;
00047 if (!clientName.size())
00048 clientName = ctx->user.name;
00049
00050 remoteAddress = ctx->credentials.remoteAddress;
00051
00052 for(size_t i = 0; i < ctx->groups.size(); i++) {
00053 groups.push_back(ctx->groups[i].name);
00054 }
00055 }
00056 }
00057 };
00058
00059 enum DomeHttpCode {
00060 DOME_HTTP_OK = 200,
00061
00062 DOME_HTTP_BAD_REQUEST = 400,
00063 DOME_HTTP_DENIED = 403,
00064 DOME_HTTP_NOT_FOUND = 404,
00065 DOME_HTTP_CONFLICT = 409,
00066 DOME_HTTP_UNPROCESSABLE = 422,
00067
00068 DOME_HTTP_INTERNAL_SERVER_ERROR = 500,
00069 DOME_HTTP_INSUFFICIENT_STORAGE = 507
00070 };
00071
00072 int http_status(const dmlite::DmException &e);
00073
00074 class DomeTalker {
00075 public:
00076 DomeTalker(DavixCtxPool &pool, const DomeCredentials &creds, std::string uri, std::string verb, std::string cmd);
00077 ~DomeTalker();
00078
00079 bool execute();
00080 bool execute(const boost::property_tree::ptree ¶ms);
00081 bool execute(const std::string &str);
00082 bool execute(const std::ostringstream &ss);
00083
00084
00085 bool execute(const std::string &key, const std::string &value);
00086
00087
00088 bool execute(const std::string &key1, const std::string &value1,
00089 const std::string &key2, const std::string &value2);
00090
00091
00092 std::string err();
00093
00094
00095 int status();
00096
00097
00098 int dmlite_code();
00099
00100 const boost::property_tree::ptree& jresp();
00101 const std::string& response();
00102 private:
00103 DavixCtxPool &pool_;
00104 DomeCredentials creds_;
00105 std::string uri_;
00106 std::string verb_;
00107 std::string cmd_;
00108
00109 std::string target_;
00110
00111 DavixGrabber grabber_;
00112 DavixStuff *ds_;
00113
00114 Davix::DavixError *err_;
00115 std::string response_;
00116 boost::property_tree::ptree json_;
00117 bool parsedJson_;
00118 int status_;
00119 };
00120
00121 }
00122 #endif