// Get the user id from Leonardo servername // returns 0=no id, -1=transaction failed static int GetUserIDFromServer() { int retval = -1; int rxlen; char txbuf[512]; char username[128]; char password[128]; char rxcontent[32]; TCHAR2ascii(LiveTrackerusr_Config, txbuf, sizeof(username)); UrlEncode(txbuf, username, sizeof(username)); TCHAR2ascii(LiveTrackerpwd_Config, txbuf, sizeof(password)); UrlEncode(txbuf, password, sizeof(username)); sprintf(txbuf,"GET /client.php?op=login&user=%s&pass=%s HTTP/1.0\r\nHost: %s\r\n\r\n", username, password, _server_name); rxlen = DoTransactionToServer(txbuf, strlen(txbuf), rxcontent, sizeof(rxcontent)); if ( rxlen > 0) { rxcontent[rxlen]=0; retval = -1; sscanf(rxcontent,"%d",&retval); } return retval; }
/*---------------------------------------------------------------------- | NPT_UrlQuery::SetField +---------------------------------------------------------------------*/ NPT_Result NPT_UrlQuery::SetField(const char* name, const char* value, bool encoded) { NPT_String ename; if (encoded) { ename = name; } else { ename = UrlEncode(name); } for (NPT_List<Field>::Iterator it = m_Fields.GetFirstItem(); it; ++it) { Field& field = *it; if (field.m_Name == ename) { if (encoded) { field.m_Value = value; } else { field.m_Value = UrlEncode(value); } return NPT_SUCCESS; } } // field not found, add it return AddField(name, value, encoded); }
/*---------------------------------------------------------------------- | NPT_UrlQuery::Field::Field +---------------------------------------------------------------------*/ NPT_UrlQuery::Field::Field(const char* name, const char* value, bool encoded) { if (encoded) { m_Name = name; m_Value = value; } else { m_Name = UrlEncode(name); m_Value = UrlEncode(value); } }
string UrlBuildGet( const string & urlBase, const map< string, string > & params ) { string url = urlBase; int count = 0; for( map<string,string>::const_iterator it = params.begin(); it != params.end(); ++it ) { url += count == 0 ? "?" : "&"; url += UrlEncode( it->first ); url += "="; url += UrlEncode( it->second ); count++; } return url; }
bool Downloader::TwitterLogin(const std::string& user, const std::string& pwd) { if (twitter_logged) return true; std::string html, fields; twitter_logged = false; if (!GetUrl("http://mobile.twitter.com/session/new", &html)) { goto end; } MSG_DEBUG("downloader", "Login connect success!"); // Find authenticity_token value if (!FindNameValue(auth, "authenticity_token", html)) { error = _("Can't find authenticity_token"); goto end; } MSG_DEBUG("downloader", "authenticity_token=%s", auth.c_str()); html.clear(); fields = "authenticity_token=" + auth + "&username="******"&password="******"downloader", "Fields: %s\n", fields.c_str()); if (!Post("http://mobile.twitter.com/session", &html, fields)) { goto end; } #if 0 if (html.find("class=\"warning\"") != std::string::npos) { printf("Login failed, probably incorrect credentials\n"); goto end; } #endif MSG_DEBUG("downloader", "Login success!\n"); html.clear(); twitter_logged = true; end: if (!twitter_logged && IsLOGGING("download")) { FILE *f = fopen("out.htm", "wt"); fwrite(html.c_str(), html.size(), 1, f); fclose(f); MSG_DEBUG("downloader", "Login failed: %s\n", error.c_str()); } return twitter_logged; }
// 构建下载BankCtrl和服务器通讯的xml文件 bool CBkInfoDownloadManager::ConstructBkCtrlCommunicateXml(LPSTR lpBankID, std::string& info) { ATLASSERT (NULL != lpBankID); if (NULL == lpBankID) return false; LPSTR szXmlInfoPattern = "<?xml version=\"1.0\" encoding=\"utf-8\"?><moneyhub><modules><module><name>"; std::string allXmlStr = szXmlInfoPattern; std::string strBankName = CFavBankOperator::GetBankIDOrBankName (lpBankID); allXmlStr += strBankName; allXmlStr += "</name></module></modules></moneyhub>"; ///////////////////////////////////////////////////////////////////////// DWORD dwBufLen = strlen(allXmlStr.c_str()) + 32; LPSTR lpszXmlInfo = new char[dwBufLen]; strcpy_s(lpszXmlInfo,dwBufLen,allXmlStr.c_str()); int dwSize = strlen(lpszXmlInfo) * 2 + 1; unsigned char* pszOut = new unsigned char[dwSize]; base64_encode((LPBYTE)lpszXmlInfo, strlen(lpszXmlInfo), pszOut, &dwSize); pszOut[dwSize] = 0; info = "xml="; info += UrlEncode((char *)pszOut); delete []pszOut; delete []lpszXmlInfo; return true; }
CString MakeHtmlOptimizerUrl(const CString &url, const CString &optUrl) { LOG1(5, "MakeHtmlOptimizerUrl('%S')", url); CString u = optUrl; u.Replace(_T("[%URL%]"), UrlEncode(url)); return u; }
void CustomRequest::obtainHttpUrl(const char *type, Dictionary *param, char *url){ param->setObject(Integer::create(1),"s"); Json::Value jsonValue = JsonUtil::jsonValueWithDictionary(param); Json::FastWriter writer; std::string jsonString = writer.write(jsonValue); std::string jsonStringEncode = UrlEncode(jsonString); sprintf(url, "%s","http://m.weather.com.cn/data/101010100.html"); }
bool Downloader::Tweet(const std::string& text) { if (!twitter_logged) return false; std::string txt = "authenticity_token=" + auth + "&tweet%5Btext%5D=" + UrlEncode(text); MSG_DEBUG("downloader", "fields=%s", txt.c_str()); return Post("https://mobile.twitter.com/", NULL, txt); }
bool Downloader::FacebookStatus(const std::string& text) { if (!fb_logged) return false; std::string txt = "fb_dtsg=" + fb_dtsg + "&post_form_id=" + post_form_id + "&status=" + UrlEncode(text) + "&update=Update&target="; MSG_DEBUG("downloader", "fields=%s", txt.c_str()); return Post(form.c_str(), NULL, txt.c_str()); }
String URL::GetQueryString() const { String query_string; int count = 0; for ( Parameters::const_iterator itr = parameters.begin(); itr != parameters.end(); ++itr ) { query_string += ( count == 0 ) ? "" : "&"; query_string += UrlEncode((*itr).first); query_string += "="; query_string += UrlEncode((*itr).second); count++; } return query_string; }
void CPostData::sendData(IN LPCTSTR lpszUrl, IN LPSTR pData, IN DWORD dwLen, IN DWORD dwTimeOut) { ATLASSERT(NULL != pData && dwLen > 0); if (NULL == pData || dwLen <= 0) return; if(dwTimeOut > 0 && dwTimeOut <= 60000) m_dwTimeOut = dwTimeOut; else m_dwTimeOut = 60000; // 先转换成宽字节 int nLength = MultiByteToWideChar( CP_ACP, 0, (char*)pData, -1, 0, 0); if (nLength <= 0) return; WCHAR *pWchar = new WCHAR[nLength + 1]; memset(pWchar, 0, sizeof(WCHAR)*(nLength + 1)); MultiByteToWideChar(CP_ACP, 0, (char*)pData, -1, pWchar, nLength); // 转换成UTF-8下的编码 nLength = WideCharToMultiByte(CP_UTF8, 0, pWchar, -1, NULL, 0, NULL, NULL); if (nLength <= 0) return; char* pStrData = new char[nLength + 1]; memset(pStrData, 0, sizeof(char)*(nLength + 1)); ::WideCharToMultiByte(CP_UTF8, 0, pWchar, nLength, pStrData, nLength, NULL,FALSE); delete []pWchar; std::string allXmlStr = pStrData; delete []pStrData; DWORD dwBufLen = strlen(allXmlStr.c_str()) + 32; LPSTR lpszXmlInfo = new char[dwBufLen]; strcpy_s(lpszXmlInfo,dwBufLen,allXmlStr.c_str()); int dwSize = strlen(lpszXmlInfo) * 2 + 1; unsigned char* pszOut = new unsigned char[dwSize]; base64_encode((LPBYTE)lpszXmlInfo, strlen(lpszXmlInfo), pszOut, &dwSize); pszOut[dwSize] = 0; std::string info = "xml="; info += UrlEncode((char *)pszOut); delete []pszOut; delete []lpszXmlInfo; PostData(lpszUrl,(LPVOID)info.c_str(),info.size() ); }
void CWaveSession::PostRequests() { // This method is responsible for deleting the requests because requests // may later be stored. Responses can be linked to a request and when this // becomes necessary, this function will take the requests for later retrieval. // Now, we just delete them. wstringstream szPostData; ASSERT(m_vRequestQueue.size() > 0); szPostData << L"count=" << m_vRequestQueue.size(); INT nOffset = 0; for (TWaveRequestVectorConstIter iter = m_vRequestQueue.begin(); iter != m_vRequestQueue.end(); iter++) { szPostData << L"&req" << nOffset << L"_key=" << UrlEncode(SerializeRequest(*iter)); nOffset++; } // Post the JSON to the channel. wstring szUrl = Format(WAVE_URL_CHANNEL_POST, m_szStickySessionID.c_str(), m_szSID.c_str(), m_nRID++, BuildHash().c_str()); if (m_lpPostRequest != NULL) { m_vOwnedRequests.push_back(m_lpPostRequest); } m_lpPostRequest = new CCurl(szUrl, m_lpTargetWindow); m_lpPostRequest->SetUserAgent(GetUserAgent()); m_lpPostRequest->SetTimeout(WEB_TIMEOUT_SHORT); m_lpPostRequest->SetIgnoreSSLErrors(TRUE); m_lpPostRequest->SetCookies(GetCookies()); m_lpPostRequest->SetUrlEncodedPostData(szPostData.str()); CNotifierApp::Instance()->QueueRequest(m_lpPostRequest); for (TWaveRequestVectorIter iter1 = m_vRequestQueue.begin(); iter1 != m_vRequestQueue.end(); iter1++) { ASSERT(*iter1 != NULL); (*iter1)->RequestCompleted(); delete *iter1; } m_vRequestQueue.clear(); }
std::string UrlEncodeString(const std::string & decoded){ const char * sz_decoded = decoded.c_str(); size_t needed_length = decoded.length() * 3 + 3; char stackalloc[64]; char * buf = needed_length > sizeof(stackalloc)/sizeof(*stackalloc) ? (char *)malloc(needed_length) : stackalloc; UrlEncode(decoded.c_str(), buf, needed_length); std::string result(buf); if (buf != stackalloc) { free(buf); } return result; }
void CSubtitleDlDlg::OnOK() { SetStatus(ResStr(IDS_SUBDL_DLG_DOWNLOADING)); for (int i = 0; i < m_list.GetItemCount(); ++i) { if (m_list.GetCheck(i)) { m_selsubs.AddTail(*reinterpret_cast<isdb_subtitle*>(m_list.GetItemData(i))); } } m_fReplaceSubs = IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED; CMainFrame* pMF = static_cast<CMainFrame*>(GetParentFrame()); if (m_fReplaceSubs) { pMF->m_pSubStreams.RemoveAll(); } CComPtr<ISubStream> pSubStreamToSet; POSITION pos = m_selsubs.GetHeadPosition(); while (pos) { const isdb_subtitle& sub = m_selsubs.GetNext(pos); AppSettings& s = AfxGetAppSettings(); CInternetSession is; CStringA url = "http://" + s.strISDb + "/dl.php?"; CStringA args, ticket, str; args.Format("id=%d&ticket=%s", sub.id, UrlEncode(ticket), true); url.Append(args); if (OpenUrl(is, CString(url), str)) { CAutoPtr<CRenderedTextSubtitle> pRTS(DNew CRenderedTextSubtitle(&pMF->m_csSubLock, &s.subdefstyle, s.fUseDefaultSubtitlesStyle)); if (pRTS && pRTS->Open((BYTE*)(LPCSTR)str, str.GetLength(), DEFAULT_CHARSET, CString(sub.name)) && pRTS->GetStreamCount() > 0) { CComPtr<ISubStream> pSubStream = pRTS.Detach(); pMF->m_pSubStreams.AddTail(pSubStream); if (!pSubStreamToSet) { pSubStreamToSet = pSubStream; } } } } if (pSubStreamToSet) { pMF->SetSubtitle(pSubStreamToSet); } __super::OnOK(); }
/*---------------------------------------------------------------------- | NPT_UrlQuery::GetField +---------------------------------------------------------------------*/ const char* NPT_UrlQuery::GetField(const char* name) { NPT_String ename = UrlEncode(name); for (NPT_List<Field>::Iterator it = m_Fields.GetFirstItem(); it; ++it) { Field& field = *it; if (field.m_Name == ename) return field.m_Value; } // field not found return NULL; }
void CAppWindow::DisplayHelp() { wstringstream szUrl; szUrl << MANUAL_LINK << L"?version=" << UrlEncode(CVersion::GetAppVersion()); LPCWSTR szLanguageCode = GetLanguageCode(); if (szLanguageCode != NULL) { szUrl << L"&lang=" << szLanguageCode; } CNotifierApp::Instance()->OpenUrl(szUrl.str()); }
BOOL CWaveSession::Reconnect() { if (m_szUsername.empty() || m_szPassword.empty()) { return FALSE; } if (m_lpRequest != NULL) { m_vOwnedRequests.push_back(m_lpRequest); } m_lpRequest = new CCurl(WAVE_URL_CLIENTLOGIN, m_lpTargetWindow); m_lpRequest->SetUserAgent(GetUserAgent()); m_lpRequest->SetTimeout(WEB_TIMEOUT_SHORT); m_lpRequest->SetIgnoreSSLErrors(TRUE); m_lpRequest->SetReader(new CCurlUTF8StringReader()); wstringstream szPostData; szPostData << L"accountType=GOOGLE&Email=" << UrlEncode(m_szUsername) << L"&Passwd=" << UrlEncode(m_szPassword) << L"&service=wave&source=net.sf.wave-notify"; m_lpRequest->SetUrlEncodedPostData(szPostData.str()); m_nRequesting = WSR_AUTH_KEY; CNotifierApp::Instance()->QueueRequest(m_lpRequest); return TRUE; }
BUrl::BUrl(const BPath& path) : fUrlString(), fProtocol(), fUser(), fPassword(), fHost(), fPort(0), fPath(), fRequest(), fHasHost(false), fHasFragment(false) { SetUrlString(UrlEncode(path.Path(), true, true)); SetProtocol("file"); }
bool UserStatsLoader::Update(string const & userName) { { lock_guard<mutex> g(m_mutex); m_userName = userName; } auto const url = kUserStatsUrl + "&name=" + UrlEncode(userName); TRequest request(url); if (!request.RunHTTPRequest()) { LOG(LWARNING, ("Network error while connecting to", url)); return false; } if (request.error_code() != 200) { LOG(LWARNING, ("Server returned", request.error_code(), "for url", url)); return false; } auto const response = request.server_response(); pugi::xml_document document; if (!document.load_buffer(response.data(), response.size())) { LOG(LWARNING, ("Cannot parse server response:", response)); return false; } auto changesCount = document.select_node("mmwatch/edits/@value").attribute().as_int(-1); auto rank = document.select_node("mmwatch/rank/@value").attribute().as_int(-1); auto levelUpFeat = document.select_node("mmwatch/levelUpFeat/@value").attribute().as_string(); lock_guard<mutex> g(m_mutex); if (m_userName != userName) return false; m_lastUpdate = time(nullptr); m_userStats = UserStats(m_lastUpdate, rank, changesCount, levelUpFeat); SaveToSettings(); return true; }
INT_PTR CMsnProto::MsnSendHotmail(WPARAM wParam, LPARAM) { const HANDLE hContact = (HANDLE)wParam; char szEmail[MSN_MAX_EMAIL_LEN]; if (MSN_IsMeByContact(hContact, szEmail)) MsnGotoInbox(0, 0); else if (msnLoggedIn) { char szEmailEnc[MSN_MAX_EMAIL_LEN*3], szUrl[256]; UrlEncode(szEmail, szEmailEnc, sizeof(szEmailEnc)); mir_snprintf(szUrl, sizeof(szUrl), "http://mail.live.com?rru=compose?to=%s", szEmailEnc); MsnInvokeMyURL(true, szUrl); } return 0; }
void CWaveSession::PostAuthCookieRequest() { if (m_lpRequest != NULL) { m_vOwnedRequests.push_back(m_lpRequest); } m_lpRequest = new CCurl( Format(WAVE_URL_AUTH, UrlEncode(m_szAuthKey).c_str()), m_lpTargetWindow ); m_lpRequest->SetUserAgent(GetUserAgent()); m_lpRequest->SetTimeout(WEB_TIMEOUT_SHORT); m_lpRequest->SetIgnoreSSLErrors(TRUE); m_nRequesting = WSR_COOKIE; CNotifierApp::Instance()->QueueRequest(m_lpRequest); }
void UserLoginStatistics::sendLaunchStat(unsigned int channelId,const char* version,const char* platform, const char* equdid,const char* eqtype,const char* mac) { const char* netUrl = LuaTinkerManager::Get()->callLuaFunc<const char*>("Script/GameConfigParse.lua","GetLaunchStatUrl"); if(netUrl == NULL) { return; } char channel[20]; sprintf(channel,"%u",channelId); std::string channelStr = UrlEncode(channel); std::string versionStr = UrlEncode(version); std::string platformStr = UrlEncode(platform); std::string equdidStr = UrlEncode(equdid); std::string eqtypeStr = UrlEncode(eqtype); std::string macStr = UrlEncode(mac); std::string url = netUrl; url.append("?"); url.append("&channel="); url.append(channelStr); url.append("&version="); url.append(version); url.append("&platform="); url.append(platformStr); url.append("&equdid="); url.append(equdidStr); url.append("&eqtype="); url.append(eqtypeStr); url.append("&mac="); url.append(mac); CURLcode curlRes; CURL* easyCurl = curl_easy_init(); if (easyCurl == NULL) { return; } curl_easy_setopt(easyCurl, CURLOPT_URL,url.c_str()); curl_easy_setopt(easyCurl, CURLOPT_CONNECTTIMEOUT,3); curlRes = curl_easy_perform(easyCurl); curl_easy_cleanup(easyCurl); if(curlRes != CURLE_OK) { //AppDelegate::GetShareAppDelegate()->ShowToast("Sorry , NetWork is disconnect ! UserLoginStatistics::sendLaunchStat"); } }
CStringA makeargs(CPlaylist& pl) { CList<filehash> fhs; mpc_filehash(pl, fhs); CAtlList<CStringA> args; POSITION pos = fhs.GetHeadPosition(); for (int i = 0; pos; i++) { filehash& fh = fhs.GetNext(pos); CStringA str; str.Format("name[%d]=%s&size[%d]=%016I64x&hash[%d]=%016I64x", i, UrlEncode(CStringA(fh.name)), i, fh.size, i, fh.mpc_filehash); args.AddTail(str); } return Implode(args, '&'); }
/** * Called when the application crashes. */ void CrashCallback(void* address) { extern const unsigned int g_buildNumber; Report report; report.AttachMiniDump(); if (report.Preview()) { std::stringstream stream; stream << "Decoda (Build " << MainApp::s_buildNumber << ")"; std::string buffer = UrlEncode(stream.str()); char serverAddress[1024]; sprintf(serverAddress, "http://www.unknownworlds.com/game_scripts/report/crash.php?application=%s&address=0x%08X", buffer.c_str(), reinterpret_cast<unsigned int>(address)); report.Submit(serverAddress, NULL); } }
void CSubtitleDlDlg::OnOK() { SetStatus(ResStr(IDS_SUBDL_DLG_DOWNLOADING)); for (int i = 0; i < m_list.GetItemCount(); ++i) { if (m_list.GetCheck(i)) { m_selsubs.AddTail(*reinterpret_cast<isdb_subtitle*>(m_list.GetItemData(i))); } } m_fReplaceSubs = IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED; CMainFrame* pMF = static_cast<CMainFrame*>(GetParentFrame()); if (m_fReplaceSubs) { pMF->m_pSubStreams.RemoveAll(); } CComPtr<ISubStream> pSubStreamToSet; POSITION pos = m_selsubs.GetHeadPosition(); while (pos) { const isdb_subtitle& sub = m_selsubs.GetNext(pos); AppSettings& s = AfxGetAppSettings(); CInternetSession is; CStringA url = "http://" + s.strISDb + "/dl.php?"; CStringA args, ticket, str; args.Format("id=%d&ticket=%s", sub.id, UrlEncode(ticket)); url.Append(args); if (OpenUrl(is, CString(url), str)) { if (pMF->b_UseVSFilter) { if (CComQIPtr<IDirectVobSub> pDVS = pMF->GetVSFilter()) { TCHAR lpszTempPath[_MAX_PATH] = { 0 }; if (::GetTempPath(_MAX_PATH, lpszTempPath)) { CString subFileName(lpszTempPath); subFileName.Append(CString(sub.name)); if (::PathFileExists(subFileName)) { ::DeleteFile(subFileName); } CFile cf; if (cf.Open(subFileName, CFile::modeCreate|CFile::modeWrite|CFile::shareDenyNone)) { cf.Write(str.GetString(), str.GetLength()); cf.Close(); if (SUCCEEDED(pDVS->put_FileName((LPWSTR)(LPCWSTR)subFileName))) { pDVS->put_SelectedLanguage(0); pDVS->put_HideSubtitles(true); pDVS->put_HideSubtitles(false); } ::DeleteFile(subFileName); } } __super::OnOK(); return; } } CAutoPtr<CRenderedTextSubtitle> pRTS(DNew CRenderedTextSubtitle(&pMF->m_csSubLock, &s.subdefstyle, s.fUseDefaultSubtitlesStyle)); if (pRTS && pRTS->Open((BYTE*)(LPCSTR)str, str.GetLength(), DEFAULT_CHARSET, CString(sub.name)) && pRTS->GetStreamCount() > 0) { CComPtr<ISubStream> pSubStream = pRTS.Detach(); pMF->m_pSubStreams.AddTail(pSubStream); if (!pSubStreamToSet) { pSubStreamToSet = pSubStream; } } } } if (pSubStreamToSet) { pMF->SetSubtitle(pSubStreamToSet); AfxGetAppSettings().fEnableSubtitles = true; } __super::OnOK(); }
wstring CWaveSession::GetWaveUrl(wstring szWaveId) const { ASSERT(!szWaveId.empty()); return Format(WAVE_URL_WAVE, UrlEncode(m_szAuthKey).c_str(), UrlEncode(UrlEncode(szWaveId)).c_str()); }
void CBkInfoDownloadManager::MyBankUsbKeyDownload(LPUSBRECORD pUsbNode) // 下载USBKEY// LPSTR lpBankID, LPVOID lpVoid, int nSize { std::string strBankID = pUsbNode->fav; std::string strXml = pUsbNode->xml; std::string strVer = pUsbNode->ver; //检测银行控件是否已经安装 CBankData* pBankData = CBankData::GetInstance(); // 2者条件满足一个就进行安装 bool bAddBkCtrl = false; CBkInfoDownloadManager* pManager = CBkInfoDownloadManager::GetInstance (); bool bSetup = pManager->IsSetupAlready (pUsbNode->fav); bool bExist = pBankData->IsFavExist(strBankID); if ((!bSetup) || (!bExist)) { m_bAddBkCtrl = true; // 标记下载的银行控件是USBKEY触发的 CNotifyFavProgress::GetInstance()->AddFav(pUsbNode->fav);//调用js开始安装 bAddBkCtrl = true; } // 得到USBKEY保存的名字,VID+PID+MID std::wstring strSaveName; wchar_t wchTemp[20] = {0}; _itow_s (pUsbNode->vid, wchTemp, 19, 10); strSaveName += wchTemp; memset (wchTemp, 0, sizeof (wchTemp)); _itow_s (pUsbNode->pid, wchTemp, 19, 10); strSaveName += wchTemp; memset (wchTemp, 0, sizeof (wchTemp)); _itow_s (pUsbNode->mid, wchTemp, 19, 10); strSaveName += wchTemp; // 得到ID的下载控件对象指针 CDownloadManagerThread* pTempThread = FindBankCtrlDLManager((LPSTR)strBankID.c_str ()); if (NULL == pTempThread) { pTempThread = new CDownloadManagerThread (); // 创建一个管理对象 ::EnterCriticalSection(&m_cs); m_BankManager.insert (std::make_pair (strBankID.c_str (), pTempThread)); // 将新生成的加入到map ::LeaveCriticalSection (&m_cs); } std::wstring strXmlPath, strCtrlPath; if (m_wstrDLTempPath.empty ()) m_wstrDLTempPath = GetTempCachePath (); // 得到下载的临时路径 strXmlPath = m_wstrDLTempPath; strCtrlPath = m_wstrDLTempPath; strXmlPath += strSaveName; strXmlPath += L".xml"; strCtrlPath += strSaveName; strCtrlPath += L".exe"; //做base64编码 DWORD dwBufLen = strlen(strXml.c_str()) + 32; LPSTR lpszXmlInfo = new char[dwBufLen]; strcpy_s(lpszXmlInfo,dwBufLen,strXml.c_str()); int dwSize = strlen(lpszXmlInfo) * 2 + 1; unsigned char* pszOut = new unsigned char[dwSize]; base64_encode((LPBYTE)lpszXmlInfo, strlen(lpszXmlInfo), pszOut, &dwSize); pszOut[dwSize] = 0; strXml = "xml="; strXml += UrlEncode((char *)pszOut); // 从服务器端下载检验码和下载连接(采用阻塞方式下载,没有创建新的线程下载,因为要校验码) std::wstring downPath = CHostContainer::GetInstance()->GetHostName(kWeb); downPath += CA2W(MONEYHUB_USBKEY_URL); DOWN_LOAD_PARAM_NODE myNode; myNode.bCreateThread = false; myNode.strHWID = m_strHWID; myNode.strSendData = strXml; //myNode.dwPostDataLength = strXml.size (); myNode.strSaveFile = strXmlPath; myNode.strUrl = downPath; if (!pTempThread->CreateDownLoadTask (&myNode)) { CRecordProgram::GetInstance()->FeedbackError(MY_ERROR_PRO_CORE, ERR_DOWNLOAD_XML_USBKEY, L"MyBankUsbKeyDownload从服务器端下载XML文件失败!"); } // 检验验证码,并得到下载连接 std::string strNewCk; std::string strVersion; std::list<std::wstring> UrlList; if (!CheckUsbKeyXml(strXmlPath.c_str (), UrlList, strNewCk, strVersion)) { CRecordProgram::GetInstance()->FeedbackError(MY_ERROR_PRO_CORE, ERR_READ_XML_USBKEY, CRecordProgram::GetInstance()->GetRecordInfo(L"MyBankUsbKeyDownload解析%s数据失败!",strXmlPath.c_str ())); } bool bUpData = false; // 进行版本比较 int nVerComp = MyTwoVersionCompare (strVersion, strVer); // 表示要弹出版本要更新的提示 if (nVerComp > 0) bUpData = true; if(strVer == DEFAULT_INSTALL_VERSION) { bUpData = false; } // 检验该usb控件是否已经安装,没有安装就下载安装 bool bCheck = m_staticpICheckFile->CheckServerXmlFile (bUpData, *pUsbNode); if(bCheck == false) return; int nStatus = pUsbNode->status; // 用这个来判定是否安装 if (200 == nStatus) { // 如果银行控件已经收藏 if (bAddBkCtrl == false || bSetup == true || bUpData == false) { USBKeyInfo* pusb = CUSBHardWareDetector::GetInstance()->CheckUSBHardWare(pUsbNode->vid, pUsbNode->pid, pUsbNode->mid);//从内存文件中获得相关信息 if(!pusb) return; wstring msg; msg = pusb->hardware.goodsname + L"软件安装正常,可以使用"; mhShowMessage( GetActiveWindow(), msg.c_str()); return; } } // 更新USBKEY的版本 CBankData::GetInstance ()->UpdateUSB (pUsbNode->vid, pUsbNode->pid, pUsbNode->mid, strVersion); if (UrlList.size() <= 0) { CRecordProgram::GetInstance()->FeedbackError(MY_ERROR_PRO_CORE, ERR_DOWNLOAD_URL_NOFOUND_USBKEY, L"MyBankUsbKeyDownload没有检测到下载链接!"); } std::list<std::wstring>::iterator it; for (it = UrlList.begin (); it != UrlList.end (); it ++) // 创建下载任务 { DOWN_LOAD_PARAM_NODE myNode; myNode.bCreateThread = true; myNode.strHWID = m_strHWID; myNode.emKind = emUsbKey; // 下载USBKEY myNode.strSetupPath = m_wstrSetupPath; myNode.bSetupDlFile = true; myNode.strSaveFile = strCtrlPath; myNode.strUrl = (*it); // 初始化USBKEY特有的参数 myNode.dwUsbKeyParam.nMid = pUsbNode->mid; myNode.dwUsbKeyParam.nPid = pUsbNode->pid; myNode.dwUsbKeyParam.nVid = pUsbNode->vid; myNode.dwUsbKeyParam.strVersion = pUsbNode->ver; pTempThread->CreateDownLoadTask (&myNode); } }
#include "testing/testing.hpp" #include "coding/url_encode.hpp" char const * orig1 = "http://google.com/main_index.php"; char const * enc1 = "http%3A%2F%2Fgoogle.com%2Fmain_index.php"; char const * orig2 = "Some File Name.ext"; char const * enc2 = "Some%20File%20Name.ext"; char const * orig3 = "Wow, two spaces?!"; char const * enc3 = "Wow%2C%20%20two%20spaces%3F%21"; char const * orig4 = "#$%^&@~[]{}()|*+`\"\'"; char const * enc4 = "%23%24%25%5E%26%40~%5B%5D%7B%7D%28%29%7C%2A%2B%60%22%27"; UNIT_TEST(UrlEncode) { TEST_EQUAL(UrlEncode(""), "", ()); TEST_EQUAL(UrlEncode(" "), "%20", ()); TEST_EQUAL(UrlEncode("%% "), "%25%25%20", ()); TEST_EQUAL(UrlEncode("20"), "20", ()); TEST_EQUAL(UrlEncode("Guinea-Bissau"), "Guinea-Bissau", ()); TEST_EQUAL(UrlEncode(orig1), enc1, ()); TEST_EQUAL(UrlEncode(orig2), enc2, ()); TEST_EQUAL(UrlEncode(orig3), enc3, ()); TEST_EQUAL(UrlEncode(orig4), enc4, ()); } UNIT_TEST(UrlDecode) { TEST_EQUAL(UrlDecode(""), "", ()); TEST_EQUAL(UrlDecode("%20"), " ", ()); TEST_EQUAL(UrlDecode("%25%25%20"), "%% ", ());
wstring CWaveSession::GetInboxUrl() const { return Format(WAVE_URL_INBOX, UrlEncode(m_szAuthKey).c_str()); }