bool HttpRequest::SetUserInfos(const XBOX::VString& inUser, const XBOX::VString& inPasswd, bool inAllowBasic) { if(!fHandle) return false; XBOX::VString userInfos; userInfos.AppendString(inUser).AppendCString(":").AppendString(inPasswd); int maxlen=2*userInfos.GetLength()+1; //We convert utf16 to utf8, it should be large enough. char* buf=new char[maxlen]; if(!buf) return false; int len=userInfos.ToBlock(buf, maxlen, XBOX::VTC_UTF_8, true, false); curl_easy_setopt(fHandle, CURLOPT_USERPWD, buf); delete buf; if(inAllowBasic) curl_easy_setopt(fHandle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC|CURLAUTH_DIGEST); else curl_easy_setopt(fHandle, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); return true; }
bool HttpRequest::SetClientCertificate(const XBOX::VString& inKeyPath, const XBOX::VString& inCertPath) { if(!fHandle) return false; //tmp buffer for path conversion char buf[2048]; int len=inKeyPath.ToBlock(buf, sizeof(buf), XBOX::VTC_UTF_8, true, false); curl_easy_setopt(fHandle, CURLOPT_SSLKEY, buf); len=inCertPath.ToBlock(buf, sizeof(buf), XBOX::VTC_UTF_8, true, false); curl_easy_setopt(fHandle, CURLOPT_SSLCERT, buf); return true; }
std::string StdStringFromAsciiVString(const XBOX::VString inStr) { int len=inStr.GetLength(); char* buf=new char[len]; if(!buf) return std::string(); inStr.ToBlock(buf, len, XBOX::VTC_US_ASCII, false, false); std::string outStr(buf, len); delete[] buf; return outStr; }
bool HttpRequest::SetData(const XBOX::VString& inData, XBOX::CharSet inCS) { int maxlen=2*inData.GetLength(); //We convert utf16 to utf8, it should be large enough. char* buf=new char[maxlen]; if(!buf) return false; //int len=inData.ToBlock(buf, maxlen, XBOX::VTC_UTF_8, false, false); inCS=(inCS!=XBOX::VTC_UNKNOWN ? inCS : XBOX::VTC_US_ASCII); int len=inData.ToBlock(buf, maxlen, inCS, false, false); int count=fData.AddRawPtr(buf, len); delete(buf); fReqHdrs.FixContentThings(); curl_easy_setopt(fHandle, CURLOPT_POSTFIELDSIZE, count); return len==count; }