#include "XmlRpc.h" #include #include #include #include using namespace XmlRpc; using namespace std; map make_hash(const string& user_string) { string s = user_string.substr(1, user_string.size() - 2); map m; int size = s.size(); char* ptr = new char[size]; string key, value; char* pch; copy(s.begin(), s.end(), ptr); pch = strtok(ptr, ",:"); while (1) { key = pch; pch = strtok(NULL, ",:"); value = pch; m[key] = value; pch = strtok(NULL, ",:"); if (pch == NULL) break; } delete[] ptr; return m; } int main(int argc, char* argv[]) { if (argc != 3) { std::cerr << "Usage: HelloClient serverHost serverPort\n"; return -1; } int port = atoi(argv[2]); XmlRpcClient c(argv[1], port); string methodName, res_str; map session; stringstream oss; { methodName = "session.login_with_password"; XmlRpcValue args, result; args[0] = "versus"; args[1] = "passwd"; cout << "DEBUG: ececuting method " << methodName << " with args: " << args << endl; if (!c.execute(methodName.c_str(), args, result)) std::cout << "Error calling '" << methodName << "'\n\n"; oss << result; res_str = oss.str(); } session = make_hash(res_str); { methodName = "host.get_all"; XmlRpcValue args, result; args[0] = session["Value"]; cout << "DEBUG: ececuting method " << methodName << " with args: " << args << endl; if (c.execute(methodName.c_str(), args, result)) std::cout << methodName << "'s result:" << result << "\n\n"; } return 0; }