+struct Response
+{
+ bool done;
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+ RESULT result;
+ bool status;
+
+ static bool callback(void* data, const RESULT& result, bool status)
+ {
+ Response& resp = *static_cast<Response*>(data);
+ pthread_mutex_lock(&resp.mutex);
+ resp.result = result;
+ resp.status = status;
+ resp.done = true;
+ pthread_cond_signal(&resp.cond);
+ pthread_mutex_unlock(&resp.mutex);
+ return true;
+ }
+} response;
+
+STG_PAIR* toSTGPairs(const PAIRS& source)
+{
+ STG_PAIR * pairs = new STG_PAIR[source.size() + 1];
+ for (size_t pos = 0; pos < source.size(); ++pos) {
+ bzero(pairs[pos].key, sizeof(STG_PAIR::key));
+ bzero(pairs[pos].value, sizeof(STG_PAIR::value));
+ strncpy(pairs[pos].key, source[pos].first.c_str(), sizeof(STG_PAIR::key));
+ strncpy(pairs[pos].value, source[pos].second.c_str(), sizeof(STG_PAIR::value));
+ }
+ bzero(pairs[source.size()].key, sizeof(STG_PAIR::key));
+ bzero(pairs[source.size()].value, sizeof(STG_PAIR::value));
+
+ return pairs;
+}
+
+PAIRS fromSTGPairs(const STG_PAIR* pairs)
+{
+ const STG_PAIR* pair = pairs;
+ PAIRS res;
+
+ while (!emptyPair(pair)) {
+ res.push_back(std::pair<std::string, std::string>(pair->key, pair->value));
+ ++pair;
+ }
+
+ return res;
+}
+
+STG_RESULT toResult(const RESULT& source)
+{
+ STG_RESULT result;
+ result.modify = toSTGPairs(source.modify);
+ result.reply = toSTGPairs(source.reply);
+ return result;