3 #include "stg_client.h"
12 namespace RLM = STG::RLM;
17 using RLM::REQUEST_TYPE;
22 STG_PAIR* toSTGPairs(const PAIRS& source)
24 STG_PAIR * pairs = new STG_PAIR[source.size() + 1];
25 for (size_t pos = 0; pos < source.size(); ++pos) {
26 bzero(pairs[pos].key, sizeof(pairs[pos].key));
27 bzero(pairs[pos].value, sizeof(pairs[pos].value));
28 strncpy(pairs[pos].key, source[pos].first.c_str(), sizeof(pairs[pos].key));
29 strncpy(pairs[pos].value, source[pos].second.c_str(), sizeof(pairs[pos].value));
31 bzero(pairs[source.size()].key, sizeof(pairs[source.size()].key));
32 bzero(pairs[source.size()].value, sizeof(pairs[source.size()].value));
37 PAIRS fromSTGPairs(const STG_PAIR* pairs)
39 const STG_PAIR* pair = pairs;
42 while (!emptyPair(pair)) {
43 res.push_back(std::pair<std::string, std::string>(pair->key, pair->value));
50 STG_RESULT toResult(const RESULT& source)
53 result.modify = toSTGPairs(source.modify);
54 result.reply = toSTGPairs(source.reply);
58 STG_RESULT emptyResult()
60 STG_RESULT result = {NULL, NULL};
64 std::string toString(const char* value)
72 STG_RESULT stgRequest(REQUEST_TYPE type, const char* userName, const char* password, const STG_PAIR* pairs)
74 Client* client = Client::get();
76 RadLog("Client is not configured.");
80 return toResult(client->request(type, toString(userName), toString(password), fromSTGPairs(pairs)));
81 } catch (const std::runtime_error& ex) {
82 RadLog("Error: '%s'.", ex.what());
89 int stgInstantiateImpl(const char* address)
91 if (Client::configure(toString(address)))
97 STG_RESULT stgAuthorizeImpl(const char* userName, const char* password, const STG_PAIR* pairs)
99 return stgRequest(RLM::AUTHORIZE, userName, password, pairs);
102 STG_RESULT stgAuthenticateImpl(const char* userName, const char* password, const STG_PAIR* pairs)
104 return stgRequest(RLM::AUTHENTICATE, userName, password, pairs);
107 STG_RESULT stgPostAuthImpl(const char* userName, const char* password, const STG_PAIR* pairs)
109 return stgRequest(RLM::POST_AUTH, userName, password, pairs);
112 STG_RESULT stgPreAcctImpl(const char* userName, const char* password, const STG_PAIR* pairs)
114 return stgRequest(RLM::PRE_ACCT, userName, password, pairs);
117 STG_RESULT stgAccountingImpl(const char* userName, const char* password, const STG_PAIR* pairs)
119 return stgRequest(RLM::ACCOUNT, userName, password, pairs);