vector<Category*>* Session::GetCategories(string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = GET; string url = host + "/categories." + format; cout << endl << "url: " << url << endl; int status = authRequest->authWebRequest(url, method); vector<Category*>* result = new vector<Category*>(); if (status <= 202 && "" != authRequest->GetReceivedData()) { Stub_Categories* stub = new Stub_Categories(); if (format == "xml") { (static_cast<XmlSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), stub); } else { (static_cast<JsonSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), stub); } result = stub->GetCategories(); delete stub; } HandleRequest(method, url, ""); HandleConfigurationResponse(status, authRequest); delete authRequest; return result; }
vector<string>* Session::GetBlacklist(string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = GET; string url = host + "/blacklist." + format; cout << endl << "url: " << url << endl; int status = authRequest->authWebRequest(url, method); vector<string>* result = new vector<string>(); if (status <= 202 && "" != authRequest->GetReceivedData()) { Stub_Blacklist* stub = new Stub_Blacklist(); if (format == "xml") { (static_cast<XmlSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), stub); } else { (static_cast<JsonSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), stub); } result = stub->GetBlacklistItems(); // @TODO don't forget that items are stored in stub, so if // we delete items in stub's destructor - all items from result // will be removed too. // maybe we should use smart pointer? delete stub; } HandleRequest(method, url, ""); HandleConfigurationResponse(status, authRequest); delete authRequest; return result; }
void JabberClient::auth_register() { AuthRequest *req = new AuthRequest(this); req->start_element("query"); req->add_attribute("xmlns", "jabber:iq:register"); req->text_tag("username", data.owner.ID); req->text_tag("password", getPassword()); req->send(); m_requests.push_back(req); }
void JabberClient::auth_digest() { AuthRequest *req = new AuthRequest(this); req->start_element("query"); req->add_attribute("xmlns", "jabber:iq:auth"); req->text_tag("username", data.owner.ID); string digest = m_id; digest += getPassword().utf8(); SHA_CTX c; unsigned char md[SHA_DIGEST_LENGTH]; SHA1_Init(&c); SHA1_Update(&c, digest.c_str(),(unsigned long)digest.length()); SHA1_Final(md, &c); digest = ""; for (unsigned i = 0; i < SHA_DIGEST_LENGTH; i++){ char b[3]; sprintf(b, "%02x",md[i]); digest += b; } req->text_tag("digest", digest.c_str()); req->text_tag("resource", data.owner.Resource); req->send(); m_requests.push_back(req); }
int Session::QueueCollection(Collection* collection, string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = POST; string url = host + "/collection." + format; cout << endl << "url: " << url << endl; string body = ""; if (format == "xml") { body = (static_cast<XmlSerializer*>(serializer))->Serialize(collection); } else { body = (static_cast<JsonSerializer*>(serializer))->Serialize(collection); } int result = authRequest->authWebRequest(url, method, body); HandleCollAutoResponse(result, authRequest); HandleRequest(method, url, body); delete authRequest; return result; }
int Session::UpdateItems(string path, UpdateProxy<T>* proxy, string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = POST; string url = host + "/" + path + "." + format; cout << endl << "url: " << url << endl; string body = ""; if (format == "xml") { body = (static_cast<XmlSerializer*>(serializer))->Serialize(proxy); } else { body = (static_cast<JsonSerializer*>(serializer))->Serialize(proxy); } int result = authRequest->authWebRequest(url, method, body); HandleRequest(POST, url, body); HandleConfigurationResponse(result, authRequest); delete authRequest; return result; }
CollAnalyticData* Session::GetCollection(string collectionId, string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = GET; string url = host + "/collection/" + collectionId + "." + format; cout << endl << "url: " << url << endl; int status = authRequest->authWebRequest(url, method); CollAnalyticData* result = new CollAnalyticData(); if (status <= 202 && "" != authRequest->GetReceivedData()) { if (format == "xml") { (static_cast<XmlSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), result); } else { (static_cast<JsonSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), result); } } HandleRequest(method, url, ""); HandleConfigurationResponse(status, authRequest); delete authRequest; return result; }
Subscription* Session::VerifySubscription() { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, "", applicationName); QueryMethod method = GET; string url = host + "/subscription." + format; cout << endl << "url: " << url << endl; int status = authRequest->authWebRequest(url, method); Subscription* result = new Subscription(); if (status <= 202 && "" != authRequest->GetReceivedData()) { if (format == "xml") { (static_cast<XmlSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), result); } else { (static_cast<JsonSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), result); } } HandleRequest(method, url, ""); HandleConfigurationResponse(status, authRequest); delete authRequest; return result; }
int Session::QueueBatch(vector<Document*>* documents, string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = POST; string url = host + "/document/batch." + format; cout << endl << "url: " << url << endl; Stub_Tasks* documentsStub = new Stub_Tasks(documents); string body = ""; if (format == "xml") { body = (static_cast<XmlSerializer*>(serializer))->Serialize(documentsStub); } else { body = (static_cast<JsonSerializer*>(serializer))->Serialize(documentsStub); } delete documentsStub; int result = authRequest->authWebRequest(url, method, body); HandleDocAutoResponse(result, authRequest); HandleRequest(method, url, body); delete authRequest; return result; }
void JabberClient::auth_plain() { AuthRequest *req = new AuthRequest(this); req->start_element("query"); req->add_attribute("xmlns", "jabber:iq:auth"); QString username = data.owner.getId(); username = getToken(username, '@'); req->text_tag("username", username); req->text_tag("password", getPassword()); req->text_tag("resource", data.owner.getResource()); req->send(); m_requests.push_back(req); }
void JabberClient::auth_digest() { AuthRequest *req = new AuthRequest(this); req->start_element("query"); req->add_attribute("xmlns", "jabber:iq:auth"); QString username = data.owner.getId(); username = getToken(username, '@'); req->text_tag("username", username); QString digest = m_id; digest += getPassword(); QByteArray md = QCryptographicHash::hash(digest.toUtf8(), QCryptographicHash::Sha1); digest = QString::null; for (int i = 0; i < md.size(); i++){ char b[3]; sprintf(b, "%02x", md[i] & 0xFF); digest += b; } req->text_tag("digest", digest); req->text_tag("resource", data.owner.getResource()); req->send(); m_requests.push_back(req); }