std::string AssociatedRelayConsumer::checkid_setup(const std::string &return_to, const std::string &trust_root) { // Try to find our assoc handle. const std::string *assoc_handle_ptr = lookup_assoc_handle(openid_provider()); if(!assoc_handle_ptr) assoc_handle_ptr = associate(); // If the handle is "DUMB", we have to fall back to the dumb consumer. if(assoc_handle_ptr->compare("DUMB") == 0) { delete assoc_handle_ptr; return DumbRelayConsumer::checkid_setup(return_to, trust_root); } // Move the string to the stack, so that return can free it. std::string assoc_handle(*assoc_handle_ptr); delete assoc_handle_ptr; // construct check_id url. std::string redirect_url(DumbRelayConsumer::checkid_setup(return_to, trust_root)); // cURL handle used for escaping. CURL *curl = new_curl_handle(); redirect_url.append("&openid.assoc_handle="); char *tmp = curl_easy_escape(curl, assoc_handle.c_str(), assoc_handle.size()); redirect_url.append(tmp); curl_free(tmp); // Clean up after curl. curl_easy_cleanup(curl); return redirect_url; }
wxString MainFrame::CheckForUpdates(wxString host, wxString url) { wxString update_url = wxT(""); wxHTTP get; get.SetHeader(_T("Content-type"), _T("text/html; charset=utf-8")); #ifdef __WXMSW__ get.SetHeader(wxT("User-Agent"), wxT("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0")); #endif get.SetTimeout(10); while (!get.Connect(host)) wxSleep(5); wxInputStream* httpStream = get.GetInputStream(url); if (get.GetError() == wxPROTO_NOERR) { if (httpStream != NULL) { size_t size = httpStream->GetSize(); if (httpStream) { wxTextInputStream text(*httpStream, wxT("\x09"), wxConvUTF8); while (httpStream->IsOk() && !httpStream->Eof() && update_url.IsEmpty()) { wxString line = text.ReadLine(); if (line.Contains(wxT("direct-download"))) { wxURL redirect_url(line.SubString(line.Find(wxT("http://")), line.Find(wxT("\" "))).BeforeLast('\"')); update_url = CheckForUpdates(redirect_url.GetServer(), redirect_url.GetPath() + wxT("?") + redirect_url.GetQuery()); } if (line.Contains(wxT(" redirected "))) { update_url = line.SubString(line.Find(wxT("http://")), line.Find(wxT(";"))).BeforeLast(';'); } } } delete httpStream; } } get.Close(); return update_url; }
std::string DumbRelayConsumer::checkid_setup(const std::string &return_to, const std::string &trust_root) { // construct check_id url. char *tmp; std::string redirect_url(openid_provider()); if(redirect_url.find_first_of('?') != redirect_url.npos) redirect_url.push_back('&'); else redirect_url.push_back('?'); redirect_url.append("openid.mode=checkid_setup"); // cURL handle used for escaping. CURL *curl = new_curl_handle(); redirect_url.append("&openid.identity="); tmp = curl_easy_escape(curl, identifier().c_str(), identifier().size()); redirect_url.append(tmp); curl_free(tmp); redirect_url.append("&openid.return_to="); tmp = curl_easy_escape(curl, return_to.c_str(), return_to.size()); redirect_url.append(tmp); curl_free(tmp); if(trust_root.size() > 0) { redirect_url.append("&openid.trust_root="); tmp = curl_easy_escape(curl, trust_root.c_str(), trust_root.size()); redirect_url.append(tmp); curl_free(tmp); } // Clean up after curl. curl_easy_cleanup(curl); return redirect_url; }