void AppSettings::ReadSettings(string iniFile) { NameValueCollection settings = ReadIniSection(Name.c_str(), iniFile.c_str()); // expand indirect values first for (NameValueCollection::iterator itr = settings.begin(), end = settings.end(); itr != end; ++itr) itr->second = GetIndirectValue(itr->second.c_str()); // next expand qualifiers for (NameValueCollection::iterator itr = settings.begin(), end = settings.end(); itr != end; ++itr) itr->second = ExpandQualifiers(itr->second.c_str(), settings); // finally expand environment variables, last because it clobbers my custom qualifier expansion for (NameValueCollection::iterator itr = settings.begin(), end = settings.end(); itr != end; ++itr) itr->second = ExpandEnvironment(itr->second); std::swap(Environment, settings); rootPath = GetSetting<string>("RootPath"); rootPaths = TokenizeString(GetSetting<string>("RootPaths").c_str(), ";"); searchPaths = TokenizeString(GetSetting<string>("TextureSearchPaths").c_str(), ";"); extensions = TokenizeString(GetSetting<string>("TextureExtensions").c_str(), ";"); textureRootPaths = TokenizeString(GetSetting<string>("TextureRootPaths").c_str(), ";"); Skeleton = GetSetting<string>("Skeleton"); useSkeleton = GetSetting<bool>("UseSkeleton", useSkeleton); goToSkeletonBindPosition = GetSetting<bool>("GoToSkeletonBindPosition", goToSkeletonBindPosition); disableCreateNubsForBones = GetSetting<bool>("DisableCreateNubsForBones", disableCreateNubsForBones); applyOverallTransformToSkinAndBones = GetSetting<int>("ApplyOverallTransformToSkinAndBones", -1); dummyNodeMatches = TokenizeString(GetSetting<string>("DummyNodeMatches").c_str(), ";"); }
//------------------------------------------------------------------------------ void ofxHTTPBaseRequest::addHeaders(const NameValueCollection& _headers) { NameValueCollection::ConstIterator iter = _headers.begin(); while(iter != _headers.end()) { addHeader((*iter).first,(*iter).second); ++iter; } }
//------------------------------------------------------------------------------ void ofxHTTPBaseRequest::addFormFields(const NameValueCollection& formFields) { NameValueCollection::ConstIterator iter = formFields.begin(); while(iter != formFields.end()) { addFormField((*iter).first,(*iter).second); ++iter; } }
void AppSettings::ReadSettings(tstring iniFile) { NameValueCollection settings = ReadIniSection(Name.c_str(), iniFile.c_str()); // expand indirect values first for (NameValueCollection::iterator itr = settings.begin(), end = settings.end(); itr != end; ++itr) itr->second = GetIndirectValue(itr->second.c_str()); // next expand qualifiers for (NameValueCollection::iterator itr = settings.begin(), end = settings.end(); itr != end; ++itr) itr->second = ExpandQualifiers(itr->second.c_str(), settings); // finally expand environment variables, last because it clobbers my custom qualifier expansion for (NameValueCollection::iterator itr = settings.begin(), end = settings.end(); itr != end; ++itr) itr->second = ExpandEnvironment(itr->second); std::swap(Environment, settings); NiVersion = GetSetting<tstring>(TEXT("NiVersion"), TEXT("20.0.0.5")); NiUserVersion = GetSetting<int>(TEXT("NiUserVersion"), 0); NiUserVersion2 = GetSetting<int>(TEXT("NiUserVersion2"), 0); rootPath = GetSetting<tstring>(TEXT("RootPath")); rootPaths = TokenizeString(GetSetting<tstring>(TEXT("RootPaths")).c_str(), TEXT(";")); searchPaths = TokenizeString(GetSetting<tstring>(TEXT("TextureSearchPaths")).c_str(), TEXT(";")); extensions = TokenizeString(GetSetting<tstring>(TEXT("TextureExtensions")).c_str(), TEXT(";")); textureRootPaths = TokenizeString(GetSetting<tstring>(TEXT("TextureRootPaths")).c_str(), TEXT(";")); materialRootPaths = TokenizeString(GetSetting<tstring>(TEXT("MaterialPaths")).c_str(), TEXT(";")); Skeleton = GetSetting<tstring>(TEXT("Skeleton")); useSkeleton = GetSetting<bool>(TEXT("UseSkeleton"), useSkeleton); skeletonSearchPaths = TokenizeString(GetSetting<tstring>(TEXT("SkeletonSearchPaths"), TEXT(".")).c_str(), TEXT(";")); goToSkeletonBindPosition = GetSetting<bool>(TEXT("GoToSkeletonBindPosition"), goToSkeletonBindPosition); disableCreateNubsForBones = GetSetting<bool>(TEXT("DisableCreateNubsForBones"), disableCreateNubsForBones); applyOverallTransformToSkinAndBones = GetSetting<int>(TEXT("ApplyOverallTransformToSkinAndBones"), -1); textureUseFullPath = GetSetting<int>(TEXT("TextureUseFullPath"), textureUseFullPath); dummyNodeMatches = TokenizeString(GetSetting<tstring>(TEXT("DummyNodeMatches")).c_str(), TEXT(";")); rotate90Degrees = TokenizeString(GetSetting<tstring>(TEXT("Rotate90Degrees")).c_str(), TEXT(";")); supportPrnStrings = GetSetting<bool>(TEXT("SupportPrnStrings"), supportPrnStrings); doNotReuseExistingBones = GetSetting<bool>(TEXT("DoNotReuseExistingBones"), doNotReuseExistingBones); skeletonCheck = GetSetting<tstring>(TEXT("SkeletonCheck")); }
void HTTPRequest::setCookies(const NameValueCollection& cookies) { std::string cookie; cookie.reserve(64); for (NameValueCollection::ConstIterator it = cookies.begin(); it != cookies.end(); ++it) { if (it != cookies.begin()) cookie.append("; "); cookie.append(it->first); cookie.append("="); cookie.append(it->second); } add(COOKIE, cookie); }
std::string WebSessionManager::getId(const std::string& appName, const Poco::Net::HTTPServerRequest& request) { std::string id; std::string name(cookieName(appName)); NameValueCollection cookies; request.getCookies(cookies); NameValueCollection::ConstIterator it = cookies.find(name); if (it != cookies.end()) id = it->second; return id; }
HTTPCookie::HTTPCookie(const NameValueCollection& nvc): _version(0), _secure(false), _maxAge(-1), _httpOnly(false) { for (NameValueCollection::ConstIterator it = nvc.begin(); it != nvc.end(); ++it) { const std::string& name = it->first; const std::string& value = it->second; if (icompare(name, "comment") == 0) { setComment(value); } else if (icompare(name, "domain") == 0) { setDomain(value); } else if (icompare(name, "path") == 0) { setPath(value); } else if (icompare(name, "max-age") == 0) { setMaxAge(NumberParser::parse(value)); } else if (icompare(name, "secure") == 0) { setSecure(true); } else if (icompare(name, "expires") == 0) { int tzd; DateTime exp = DateTimeParser::parse(value, tzd); Timestamp now; setMaxAge((int) ((exp.timestamp() - now) / Timestamp::resolution())); } else if (icompare(name, "version") == 0) { setVersion(NumberParser::parse(value)); } else if (icompare(name, "HttpOnly") == 0) { setHttpOnly(true); } else { setName(name); setValue(value); } } }
//------------------------------------------------------------------------------ bool ofxWebServerBaseRouteHandler::isValidRequest(const Settings& settings, HTTPServerRequest& request, HTTPServerResponse& response) { string sessionId = ""; // extract cookie from request NameValueCollection cookies; request.getCookies(cookies); NameValueCollection::ConstIterator it = cookies.find(settings.sessionCookieName); if (it != cookies.end()) { sessionId = it->second; } else { sessionId = ofxWebServerSessionManager::generateSessionKey(request); HTTPCookie cookie(settings.sessionCookieName,sessionId); cookie.setPath("/"); // set no age, so it expires @ end of session response.addCookie(cookie); } // TODO: update session manager URI uri(request.getURI()); const string path = uri.getPath(); // just get the path if(settings.requireAuthentication) { if(request.hasCredentials()) { HTTPBasicCredentials credentials(request); const string& user = credentials.getUsername(); const string& pwd = credentials.getPassword(); if(settings.username == credentials.getUsername() && settings.password == credentials.getPassword()) { // add an authentication cookie? return true; } else { response.setStatusAndReason(HTTPResponse::HTTP_UNAUTHORIZED); sendErrorResponse(response); return false; } } else { response.requireAuthentication(settings.realm); response.setContentLength(0); response.send(); return false; } } else { return true; } }
HTTPCookie::HTTPCookie(const NameValueCollection& nvc): _version(0), _secure(false), _maxAge(-1), _httpOnly(false) { for (NameValueCollection::ConstIterator it = nvc.begin(); it != nvc.end(); ++it) { const std::string& name = it->first; const std::string& value = it->second; if (icompare(name, "comment") == 0) { setComment(value); } else if (icompare(name, "domain") == 0) { setDomain(value); } else if (icompare(name, "path") == 0) { setPath(value); } else if (icompare(name, "priority") == 0) { setPriority(value); } else if (icompare(name, "max-age") == 0) { throw NotImplementedException("HTTPCookie::HTTPCookie max-age"); } else if (icompare(name, "secure") == 0) { setSecure(true); } else if (icompare(name, "expires") == 0) { throw NotImplementedException("HTTPCookie::HTTPCookie expires"); } else if (icompare(name, "version") == 0) { throw NotImplementedException("HTTPCookie::HTTPCookie version"); } else if (icompare(name, "HttpOnly") == 0) { setHttpOnly(true); } else { setName(name); setValue(value); } } }
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response) { HTMLForm form(request, request.stream()); response.setContentType("text/html"); response.setChunkedTransferEncoding(true); std::ostream& ostr = response.send(); URI requestURI(request.getURI()); ostr << "<html><head><title>Echo HTTP Headers and HTML Form Information</title>" "<link rel=\"stylesheet\" href=\"css/styles.css\" type=\"text/css\"/></head><body>" "<div class=\"header\">" "<h1 class=\"category\">Open Service Platform</h1>" "<h1 class=\"title\">Echo HTTP Headers and HTML Form Information</H1>" "</div>" "<div class=\"body\">"; // echo the items available by method ostr << "<h2>Request</h2>" << "<ul>" << "<li><b>Method:</b> " << request.getMethod() << "</li>" << "<li><b>URI Path:</b> " << requestURI.getPath() << "</li>" << "<li><b>URI Query:</b> " << requestURI.getQuery() << "</li>" << "<li><b>HTTP Version:</b> " << request.getVersion() << "</li>" << "<li><b>Host:</b> " << request.getHost() << "</li>" << "<li><b>Content Type:</b> " << request.getContentType() << "</li>" << "<li><b>Chunked:</b> " << (request.getChunkedTransferEncoding() ? "true" : "false") << "</li>" << "<li><b>Keep Alive:</b> " << (request.getKeepAlive() ? "true" : "false") << "</li>" << "<li><b>Transfer Encoding:</b> " << request.getTransferEncoding() << "</li>" << "<li><b>Client Address:</b> " << request.clientAddress().toString() << "</li>"; if (request.hasContentLength()) { ostr << "<li><b>Content Length:</b> " << request.getContentLength64() << "</li>"; } ostr << "</ul>"; // echo the request headers { ostr << "<hr>" "<h2>Request Headers</h2><ul>\n"; NameValueCollection headers; NameValueCollection::ConstIterator itr(request.begin()); NameValueCollection::ConstIterator itrEnd(request.end()); for (; itr != itrEnd; ++itr) { ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>"; } ostr << "</ul>"; } // echo any cookies { NameValueCollection cookies; request.getCookies(cookies); if (!cookies.empty()) { ostr << "<hr>"; ostr << "<h2>Cookies</h2><ul>\n"; NameValueCollection::ConstIterator itr(cookies.begin()); NameValueCollection::ConstIterator itrEnd(cookies.end()); for (; itr != itrEnd; ++itr) { ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>"; } ostr << "</ul>"; } } // echo any form data (GETs or POSTs) if (!form.empty()) { ostr << "<hr>" "<h2>Form Data</h2><ul>\n"; NameValueCollection::ConstIterator itr(form.begin()); NameValueCollection::ConstIterator itrEnd(form.end()); for (; itr != itrEnd; ++itr) { ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>\n"; } ostr << "</ul>"; } ostr << "<hr>" << "<h2>Response</h2>" << "<ul>" << "<li><b>Status:</b> " << response.getStatus() << "</li>" << "<li><b>Reason:</b> " << response.getReason() << "</li>" << "</ul>"; // echo the response headers { ostr << "<hr>" "<h2>Response Headers</h2><ul>\n"; NameValueCollection headers; NameValueCollection::ConstIterator itr(response.begin()); NameValueCollection::ConstIterator itrEnd(response.end()); for (; itr != itrEnd; ++itr) { ostr << "<li><b>" << htmlize(itr->first) << "</b>: " << htmlize(itr->second) << "</li>"; } ostr << "</ul>"; } ostr << "</div></body></html>"; }
void NameValueCollectionTest::testNameValueCollection() { NameValueCollection nvc; assert (nvc.empty()); assert (nvc.size() == 0); nvc.set("name", "value"); assert (!nvc.empty()); assert (nvc["name"] == "value"); assert (nvc["Name"] == "value"); nvc.set("name2", "value2"); assert (nvc.get("name2") == "value2"); assert (nvc.get("NAME2") == "value2"); assert (nvc.size() == 2); try { std::string value = nvc.get("name3"); fail("not found - must throw"); } catch (NotFoundException&) { } try { std::string value = nvc["name3"]; fail("not found - must throw"); } catch (NotFoundException&) { } assert (nvc.get("name", "default") == "value"); assert (nvc.get("name3", "default") == "default"); assert (nvc.has("name")); assert (nvc.has("name2")); assert (!nvc.has("name3")); nvc.add("name3", "value3"); assert (nvc.get("name3") == "value3"); nvc.add("name3", "value31"); NameValueCollection::ConstIterator it = nvc.find("Name3"); assert (it != nvc.end()); std::string v1 = it->second; assert (it->first == "name3"); ++it; assert (it != nvc.end()); std::string v2 = it->second; assert (it->first == "name3"); assert ((v1 == "value3" && v2 == "value31") || (v1 == "value31" && v2 == "value3")); nvc.erase("name3"); assert (!nvc.has("name3")); assert (nvc.find("name3") == nvc.end()); it = nvc.begin(); assert (it != nvc.end()); ++it; assert (it != nvc.end()); ++it; assert (it == nvc.end()); nvc.clear(); assert (nvc.empty()); assert (nvc.size() == 0); }