TEST(Utils, UriCoding) { string src1 = "This is a simple & short test."; string src2 = "$ & < > ? ; # : = , \" ' ~ + %-_"; string src3 = "! * ' ( ) ; : @ & = + $ , / ? % # [ ]"; string src4 = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i " "j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 - _ . ~"; string dst1 = "This%20is%20a%20simple%20%26%20short%20test."; string dst2 = "%24%20%26%20%3C%20%3E%20%3F%20%3B%20%23%20%3A%20%3D%20%2C%20%22%20%27%" "20~%20%2B%20%25-_"; string dst3 = "%21%20%2A%20%27%20%28%20%29%20%3B%20%3A%20%40%20%26%20%3D%20%2B%20%24%" "20%2C%20%2F%20%3F%20%25%20%23%20%5B%20%5D"; string dst4 = "A%20B%20C%20D%20E%20F%20G%20H%20I%20J%20K%20L%20M%20N%20O%20P%20Q%20R%" "20S%20T%20U%20V%20W%20X%20Y%20Z%20a%20b%20c%20d%20e%20f%20g%20h%20i%" "20j%20k%20l%20m%20n%20o%20p%20q%20r%20s%20t%20u%20v%20w%20x%20y%20z%" "200%201%202%203%204%205%206%207%208%209%20-%20_%20.%20~"; EXPECT_EQ(dst1, UriEncode(src1)); EXPECT_EQ(dst2, UriEncode(src2)); EXPECT_EQ(dst3, UriEncode(src3)); EXPECT_EQ(dst4, UriEncode(src4)); EXPECT_EQ(src1, UriDecode(dst1)); EXPECT_EQ(src2, UriDecode(dst2)); EXPECT_EQ(src3, UriDecode(dst3)); EXPECT_EQ(src4, UriDecode(dst4)); }
UriCodecTest::UriCodecTest() { assert(UriEncode("ABC") == "ABC"); const std::string ORG("\0\1\2", 3); const std::string ENC("%00%01%02"); assert(UriEncode(ORG) == ENC); assert(UriDecode(ENC) == ORG); assert(UriEncode("\xFF") == "%FF"); assert(UriDecode("%FF") == "\xFF"); assert(UriDecode("%ff") == "\xFF"); // unsafe chars test, RFC1738 const std::string UNSAFE(" <>#{}|\\^~[]`"); std::string sUnsafeEnc = UriEncode(UNSAFE); assert(std::string::npos == sUnsafeEnc.find_first_of(UNSAFE)); assert(UriDecode(sUnsafeEnc) == UNSAFE); // random test const int MAX_LEN = 128; char a[MAX_LEN]; srand((unsigned)time(NULL)); for (int i = 0; i < 100; i++) { for (int j = 0; j < MAX_LEN; j++) a[j] = rand() % (1 << 8); int nLen = rand() % MAX_LEN; std::string sOrg(a, nLen); std::string sEnc = UriEncode(sOrg); assert(sOrg == UriDecode(sEnc)); } }
void CGameListCtrl::OnWiki(wxCommandEvent& WXUNUSED (event)) { const GameListItem *iso = GetSelectedISO(); if (!iso) return; std::string wikiUrl = "http://wiki.dolphin-emu.org/dolphin-redirect.php?gameid=[GAME_ID]"; wikiUrl = ReplaceAll(wikiUrl, "[GAME_ID]", UriEncode(iso->GetUniqueID())); if (UriEncode(iso->GetName(0)).length() < 100) wikiUrl = ReplaceAll(wikiUrl, "[GAME_NAME]", UriEncode(iso->GetName(0))); else wikiUrl = ReplaceAll(wikiUrl, "[GAME_NAME]", ""); WxUtils::Launch(wikiUrl.c_str()); }
string ofxRemoteUI::getValuesAsString(){ stringstream out; map<int,string>::iterator it = orderedKeys.begin(); while( it != orderedKeys.end() ){ RemoteUIParam param = params[it->second]; out << UriEncode(it->second) << "="; switch (param.type) { case REMOTEUI_PARAM_FLOAT: out << param.floatVal << endl; break; case REMOTEUI_PARAM_INT: out << param.intVal << endl; break; case REMOTEUI_PARAM_COLOR: out << (int)param.redVal << " " << (int)param.greenVal << " " << (int)param.blueVal << " " << (int)param.alphaVal << " " << endl; break; case REMOTEUI_PARAM_ENUM: out << param.intVal << endl; break; case REMOTEUI_PARAM_BOOL: out << (param.boolVal?"1":"0") << endl; break; case REMOTEUI_PARAM_STRING: out << UriEncode(param.stringVal) << endl; break; } ++it; } return out.str(); }
S3Params S3BucketReader::constructReaderParams(BucketContent& key) { // encode the key name but leave the "/" // "/encoded_path/encoded_name" string keyEncoded = UriEncode(key.getName()); FindAndReplace(keyEncoded, "%2F", "/"); S3Params readerParams = this->params.setPrefix(keyEncoded); readerParams.setKeySize(key.getSize()); S3DEBUG("key: %s, size: %" PRIu64, readerParams.getS3Url().getFullUrlForCurl().c_str(), readerParams.getKeySize()); return readerParams; }
// Uploads a deck to secret library bool DeckUpload::Upload(wxString &sCrypt, wxString &sLibrary, wxString &sTitle, wxString &sAuthor, wxString &sDesc, wxString &sUserName, wxString &sPassword) { bool result = FALSE; wxHTTP httpPost; wxString postBuffer = wxT(""); int timeoutCount = 0; httpPost.SetHeader(wxT("Content-type"), wxT("application/x-www-form-urlencoded")); httpPost.SetTimeout(10); // 10 seconds of timeout instead of 10 minutes ... postBuffer += wxT("sl_deck_submit=1&"); postBuffer += wxT("sl_user_agent=ardb&"); postBuffer += wxT("sl_agent_version=2.9.0&"); postBuffer += wxT("username="******"&"); postBuffer += wxT("password="******"&"); postBuffer += wxT("title=") + UriEncode(sTitle) + wxT("&"); postBuffer += wxT("author=") + UriEncode(sAuthor) + wxT("&"); postBuffer += wxT("description=") + UriEncode(sDesc) + wxT("&"); postBuffer += wxT("public=1&"); postBuffer += wxT("crypt="); postBuffer += UriEncode(sCrypt); postBuffer += wxT("&"); postBuffer += wxT("library="); postBuffer += UriEncode(sLibrary); httpPost.SetPostBuffer(postBuffer); while (!httpPost.Connect(wxT("www.secretlibrary.info"))) { // only the server, no pages here yet ... wxSleep(5); timeoutCount++; if (timeoutCount > 4) { break; } } wxInputStream *httpStream = httpPost.GetInputStream(wxT("/api.php")); if (httpPost.GetError() == wxPROTO_NOERR) { wxString res; int idx; wxStringOutputStream out_stream(&res); httpStream->Read(out_stream); idx = res.Find(wxT(':')); if (idx != wxNOT_FOUND) { if (res.BeforeFirst(wxT(':')) == wxT('0')) { wxMessageBox(res.Mid(idx+1),wxT("Deck Uploaded")); } else { wxMessageBox(res.Mid(idx+1),wxT("Secret Library Error")); } } result = TRUE; } return result; }
// A C++ near equivalent for PHP's urlencode function. string filter_url_urlencode (string url) { url = UriEncode (url); return url; }