46 std::string QueryString, Path, Protocol, Host, Port;
48 static Uri Parse(
const std::string &uri)
52 typedef std::string::const_iterator iterator_t;
54 if (uri.length() == 0)
57 iterator_t uriEnd = uri.end();
60 iterator_t queryStart = std::find(uri.begin(), uriEnd,
'?');
63 iterator_t protocolStart = uri.begin();
64 iterator_t protocolEnd = std::find(protocolStart, uriEnd,
':');
66 if (protocolEnd != uriEnd)
68 std::string prot = &*(protocolEnd);
69 if ((prot.length() >= 3) && (prot.substr(0, 3) ==
"://"))
71 result.Protocol = std::string(protocolStart, protocolEnd);
75 protocolEnd = uri.begin();
78 protocolEnd = uri.begin();
81 iterator_t hostStart = protocolEnd;
82 iterator_t pathStart = std::find(hostStart, uriEnd,
'/');
84 iterator_t hostEnd = std::find(protocolEnd,
85 (pathStart != uriEnd) ? pathStart : queryStart,
88 result.Host = std::string(hostStart, hostEnd);
91 if ((hostEnd != uriEnd) && ((&*(hostEnd))[0] ==
':'))
94 iterator_t portEnd = (pathStart != uriEnd) ? pathStart : queryStart;
95 result.Port = std::string(hostEnd, portEnd);
99 if (pathStart != uriEnd)
100 result.Path = std::string(pathStart, queryStart);
103 if (queryStart != uriEnd)
104 result.QueryString = std::string(queryStart, uri.end());
190 std::vector<std::string> values;
204 SCurlOption(
const CURLoption& moption,
const long& mvalue)
212 SCurlOption(
const CURLoption& moption,
const std::string& mvalue)
220 SCurlOption(
const CURLoption& moption,
const std::vector<std::string>& mvalue)
228 SCurlOption(
const CURLoption& moption,
const char* mvalue,
const unsigned int size)
232 uploadData.buf = (
char*)malloc(size + 1);
233 memcpy(uploadData.buf, mvalue, size);
234 uploadData.len = size;
243 static size_t payloadSource(
void *ptr,
size_t size,
size_t nmemb,
void *userp)
247 unsigned int len = curOpt->uploadData.len - curOpt->uploadData.pos;
248 if (len > size * nmemb)
250 memcpy(ptr, curOpt->uploadData.buf + curOpt->uploadData.pos, len);
251 curOpt->uploadData.pos += len;
253 if (curOpt->uploadData.pos >= curOpt->uploadData.len)
255 free(curOpt->uploadData.buf);
256 curOpt->uploadData.buf = 0;
276 boost::mutex m_terminateMutex;
277 boost::mutex m_mutex;
278 boost::mutex m_thread_lock;
281 std::vector<SCurlOption> m_options;
284 std::vector<SFormField> m_formFields;
286 static bool CheckUrl(
const std::string& url_s);
291 SCurl(
const std::string& url);
301 void SetHeader(
const std::vector<std::string>& header);
302 void SetOption(
const CURLoption& opt,
const std::string& value);
303 void SetOption(
const CURLoption& opt,
const int& value);
304 void SetOption(
const CURLoption& opt,
const std::vector<std::string>& value);
305 void SetOption(
const CURLoption& opt,
const char* mvalue,
const unsigned int size);
307 void AddFormField(
const std::string& name,
const std::string& value,
const bool& file);
310 static size_t Write_data(
char* ptr,
size_t size,
size_t nmemb,
void* userdata);
311 int Progress(
void *userdata,
double dltotal,
double dlnow,
double ultotal,
double ulnow);