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);
55 result.returnCode = source.returnCode;
59 STG_RESULT emptyResult()
61 STG_RESULT result = {NULL, NULL, STG_REJECT};
65 std::string toString(const char* value)
73 STG_RESULT stgRequest(REQUEST_TYPE type, const char* userName, const char* password, const STG_PAIR* pairs)
75 Client* client = Client::get();
77 RadLog("Client is not configured.");
81 return toResult(client->request(type, toString(userName), toString(password), fromSTGPairs(pairs)));
82 } catch (const std::runtime_error& ex) {
83 RadLog("Error: '%s'.", ex.what());
90 int stgInstantiateImpl(const char* address)
92 if (Client::configure(toString(address)))
98 STG_RESULT stgAuthorizeImpl(const char* userName, const char* password, const STG_PAIR* pairs)
100 return stgRequest(RLM::AUTHORIZE, userName, password, pairs);
103 STG_RESULT stgAuthenticateImpl(const char* userName, const char* password, const STG_PAIR* pairs)
105 return stgRequest(RLM::AUTHENTICATE, userName, password, pairs);
108 STG_RESULT stgPostAuthImpl(const char* userName, const char* password, const STG_PAIR* pairs)
110 return stgRequest(RLM::POST_AUTH, userName, password, pairs);
113 STG_RESULT stgPreAcctImpl(const char* userName, const char* password, const STG_PAIR* pairs)
115 return stgRequest(RLM::PRE_ACCT, userName, password, pairs);
118 STG_RESULT stgAccountingImpl(const char* userName, const char* password, const STG_PAIR* pairs)
120 return stgRequest(RLM::ACCOUNT, userName, password, pairs);