size_t curlHeaderCallback(void* data, size_t size, size_t nmemb, void* user_data) { LLCurl::Easy* easy = (LLCurl::Easy*)user_data; size_t n = size * nmemb; easy->getHeaderOutput().write((const char*)data, n); return n; }
size_t curlWriteCallback(char* data, size_t size, size_t nmemb, void* user_data) { LLCurl::Easy* easy = (LLCurl::Easy*)user_data; S32 n = size * nmemb; easy->getOutput()->append(easy->getChannels().in(), (const U8*)data, n); return n; }
bool LLCurlRequest::post(const std::string& url, const headers_t& headers, const LLSD& data, LLCurl::ResponderPtr responder) { LLCurl::Easy* easy = allocEasy(); if (!easy) { return false; } easy->prepRequest(url, headers, responder); LLSDSerialize::toXML(data, easy->getInput()); S32 bytes = easy->getInput().str().length(); easy->setopt(CURLOPT_POST, 1); easy->setopt(CURLOPT_POSTFIELDS, (void*)NULL); easy->setopt(CURLOPT_POSTFIELDSIZE, bytes); easy->slist_append("Content-Type: application/llsd+xml"); easy->setHeaders(); lldebugs << "POSTING: " << bytes << " bytes." << llendl; bool res = addEasy(easy); return res; }
bool LLCurlRequest::post(const std::string& url, const headers_t& headers, const std::string& data, LLCurl::ResponderPtr responder, S32 time_out) { LLCurl::Easy* easy = allocEasy(); if (!easy) { return false; } easy->prepRequest(url, headers, responder, time_out); easy->getInput().write(data.data(), data.size()); S32 bytes = easy->getInput().str().length(); easy->setopt(CURLOPT_POST, 1); easy->setopt(CURLOPT_POSTFIELDS, (void*)NULL); easy->setopt(CURLOPT_POSTFIELDSIZE, bytes); easy->slist_append("Content-Type: application/octet-stream"); easy->setHeaders(); lldebugs << "POSTING: " << bytes << " bytes." << llendl; bool res = addEasy(easy); return res; }
bool LLCurlRequest::getByteRange(const std::string& url, S32 offset, S32 length, LLCurl::ResponderPtr responder) { LLCurl::Easy* easy = allocEasy(); if (!easy) { return false; } easy->prepRequest(url, responder); easy->setopt(CURLOPT_HTTPGET, 1); if (length > 0) { std::string range = llformat("Range: bytes=%d-%d", offset,offset+length-1); easy->slist_append(range.c_str()); } easy->setHeaders(); bool res = addEasy(easy); return res; }
size_t curlReadCallback(char* data, size_t size, size_t nmemb, void* user_data) { LLCurl::Easy* easy = (LLCurl::Easy*)user_data; S32 n = size * nmemb; S32 startpos = easy->getInput().tellg(); easy->getInput().seekg(0, std::ios::end); S32 endpos = easy->getInput().tellg(); easy->getInput().seekg(startpos, std::ios::beg); S32 maxn = endpos - startpos; n = llmin(n, maxn); easy->getInput().read((char*)data, n); return n; }