3 #include "stg_client.h"
12 STG_PAIR* toSTGPairs(const PAIRS& source)
14 STG_PAIR * pairs = new STG_PAIR[source.size() + 1];
15 for (size_t pos = 0; pos < source.size(); ++pos) {
16 bzero(pairs[pos].key, sizeof(STG_PAIR::key));
17 bzero(pairs[pos].value, sizeof(STG_PAIR::value));
18 strncpy(pairs[pos].key, source[pos].first.c_str(), sizeof(STG_PAIR::key));
19 strncpy(pairs[pos].value, source[pos].second.c_str(), sizeof(STG_PAIR::value));
22 bzero(pairs[source.size()].key, sizeof(STG_PAIR::key));
23 bzero(pairs[source.size()].value, sizeof(STG_PAIR::value));
28 PAIRS fromSTGPairs(const STG_PAIR* pairs)
30 const STG_PAIR* pair = pairs;
33 while (!emptyPair(pair)) {
34 res.push_back(std::pair<std::string, std::string>(pair->key, pair->value));
41 STG_RESULT toResult(const RESULT& source)
44 result.modify = toSTGPairs(source.modify);
45 result.reply = toSTGPairs(source.reply);
49 STG_RESULT emptyResult()
51 STG_RESULT result = {NULL, NULL};
55 std::string toString(const char* value)
63 STG_RESULT stgRequest(STG_CLIENT::TYPE type, const char* userName, const char* password, const STG_PAIR* pairs)
65 STG_CLIENT* client = STG_CLIENT::get();
67 // TODO: log "Not configured"
71 return toResult(client->request(type, toString(userName), toString(password), fromSTGPairs(pairs)));
72 } catch (const STG_CLIENT::Error& ex) {
80 int stgInstantiateImpl(const char* address)
82 if (STG_CLIENT::configure(toString(address)))
88 STG_RESULT stgAuthorizeImpl(const char* userName, const char* password, const STG_PAIR* pairs)
90 return stgRequest(STG_CLIENT::AUTHORIZE, userName, password, pairs);
93 STG_RESULT stgAuthenticateImpl(const char* userName, const char* password, const STG_PAIR* pairs)
95 return stgRequest(STG_CLIENT::AUTHENTICATE, userName, password, pairs);
98 STG_RESULT stgPostAuthImpl(const char* userName, const char* password, const STG_PAIR* pairs)
100 return stgRequest(STG_CLIENT::POST_AUTH, userName, password, pairs);
103 STG_RESULT stgPreAcctImpl(const char* userName, const char* password, const STG_PAIR* pairs)
105 return stgRequest(STG_CLIENT::PRE_ACCT, userName, password, pairs);
108 STG_RESULT stgAccountingImpl(const char* userName, const char* password, const STG_PAIR* pairs)
110 return stgRequest(STG_CLIENT::ACCOUNT, userName, password, pairs);