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
00037 std::string clientName;
00038
00039 std::string remoteAddress;
00040
00041 std::vector<std::string> groups;
00042
00043 DomeCredentials(std::string cn, std::string ra, std::vector<std::string> gr) :
00044 clientName(cn), remoteAddress(ra), groups(gr) {}
00045
00046 DomeCredentials() {}
00047 DomeCredentials(const SecurityContext *ctx) {
00048 if(ctx) {
00049
00050 clientName = ctx->credentials.clientName;
00051 if (!clientName.size())
00052 clientName = ctx->user.name;
00053
00054 remoteAddress = ctx->credentials.remoteAddress;
00055
00056 for(size_t i = 0; i < ctx->groups.size(); i++) {
00057 groups.push_back(ctx->groups[i].name);
00058 }
00059 }
00060 }
00061
00062
00063
00064
00065 };
00066
00067 enum DomeHttpCode {
00068 DOME_HTTP_OK = 200,
00069
00070 DOME_HTTP_BAD_REQUEST = 400,
00071 DOME_HTTP_DENIED = 403,
00072 DOME_HTTP_NOT_FOUND = 404,
00073 DOME_HTTP_CONFLICT = 409,
00074 DOME_HTTP_UNPROCESSABLE = 422,
00075
00076 DOME_HTTP_INTERNAL_SERVER_ERROR = 500,
00077 DOME_HTTP_INSUFFICIENT_STORAGE = 507
00078 };
00079
00080 int http_status(const DmException &e);
00081
00082 class DmStatus;
00083 int http_status(const DmStatus &e);
00084
00085 class DomeTalker {
00086 public:
00087 DomeTalker(DavixCtxPool &pool, const DomeCredentials &creds, std::string uri, std::string verb, std::string cmd);
00088 DomeTalker(DavixCtxPool &pool, std::string uri, std::string verb, std::string cmd);
00089 ~DomeTalker();
00090
00091 bool execute();
00092 bool execute(const boost::property_tree::ptree ¶ms);
00093 bool execute(const std::string &str);
00094 bool execute(const std::ostringstream &ss);
00095
00096
00097 bool execute(const std::string &key, const std::string &value);
00098
00099
00100 bool execute(const std::string &key1, const std::string &value1,
00101 const std::string &key2, const std::string &value2);
00102
00103
00104 bool execute(const std::string &key1, const std::string &value1,
00105 const std::string &key2, const std::string &value2,
00106 const std::string &key3, const std::string &value3);
00107
00108
00109 std::string err();
00110
00111
00112 int status();
00113
00114
00115 int dmlite_code();
00116
00117 const boost::property_tree::ptree& jresp();
00118 const std::string& response();
00119
00120 void setcommand(const DomeCredentials &creds, const char *verb, const char *cmd);
00121 protected:
00122
00123 static const char *reqTypes[12];
00124 int getXrdHttpReqIndex(const char *verb) {
00125 for (int i = 0; i < 12; i++) {
00126 if (!strcmp(verb, reqTypes[i])) return i;
00127 }
00128 return 0;
00129 }
00130
00131
00132
00133 void calcXrdHttpHashes(
00134 char *hash,
00135 const char *fn,
00136 int16_t request,
00137 const char *sslclientshortname,
00138 const char *sslclientvorg,
00139 const char *sslclienthost,
00140 const char *sslclientdn,
00141 time_t tim,
00142 const char *key);
00143
00144 int compareXrdHttpHashes(
00145 const char *h1,
00146 const char *h2);
00147 private:
00148 DavixCtxPool &pool_;
00149 DomeCredentials creds_;
00150 std::string uri_;
00151 std::string verb_;
00152 std::string cmd_;
00153
00154 std::string target_;
00155
00156 DavixGrabber grabber_;
00157 DavixStuff *ds_;
00158
00159 Davix::DavixError *err_;
00160 std::string response_;
00161 boost::property_tree::ptree json_;
00162 bool parsedJson_;
00163 int status_;
00164 };
00165
00166 }
00167 #endif