bool Utils::findStringInStringForTag(string str1, string str2) { toLowerInPlace(str1); toLowerInPlace(str2); size_t found = str1.find(str2); if (found == string::npos) { return false; } else { return true; } }
void URI::parseHostAndPort(std::string::const_iterator& it, const std::string::const_iterator& end) { if (it == end) return; std::string host; if (*it == '[') { // IPv6 address while (it != end && *it != ']') host += *it++; if (it == end) throw SyntaxException("unterminated IPv6 address"); host += *it++; } else { while (it != end && *it != ':') host += *it++; } if (it != end && *it == ':') { ++it; std::string port; while (it != end) port += *it++; if (!port.empty()) { int nport = 0; if (NumberParser::tryParse(port, nport) && nport > 0 && nport < 65536) _port = (unsigned short) nport; else throw SyntaxException("bad or invalid port number", port); } else _port = getWellKnownPort(); } else _port = getWellKnownPort(); _host = host; toLowerInPlace(_host); }
void URI::setScheme(const std::string& scheme) { _scheme = scheme; toLowerInPlace(_scheme); if (_port == 0) _port = getWellKnownPort(); }
URI::URI(const std::string& scheme, const std::string& authority, const std::string& path, const std::string& query): _scheme(scheme), _path(path), _query(query) { toLowerInPlace(_scheme); std::string::const_iterator beg = authority.begin(); std::string::const_iterator end = authority.end(); parseAuthority(beg, end); }
URI::URI(const std::string& scheme, const std::string& pathEtc): _scheme(scheme), _port(0) { toLowerInPlace(_scheme); _port = getWellKnownPort(); std::string::const_iterator beg = pathEtc.begin(); std::string::const_iterator end = pathEtc.end(); parsePathEtc(beg, end); }
URI::URI(const std::string& scheme, const std::string& authority, const std::string& pathEtc): _scheme(scheme) { toLowerInPlace(_scheme); std::string::const_iterator beg = authority.begin(); std::string::const_iterator end = authority.end(); parseAuthority(beg, end); beg = pathEtc.begin(); end = pathEtc.end(); parsePathEtc(beg, end); }
bool ofxAMFHTTPRequest::parseHTTPHeaders() { StringTokenizer header_tokens( raw_headers ,"\r\n" ,StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY ); size_t num_tokens = header_tokens.count(); for(int i = 0; i < num_tokens; ++i) { StringTokenizer spec_token( header_tokens[i] ,":" ,StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY ); // 0 = GET or POST if(i > 0 && spec_token.count() < 2) { ofLogError("ofxamfhttprequest: parse http header error: spec count not 2 for: " +header_tokens[i]); return false; } if(i == 0) { // @todo add request type (post or get) } else if(i > 0) { string spec_val = ""; for(int j = 1; j < spec_token.count(); ++j) { spec_val += spec_token[j] +((j < spec_token.count()-1) ? ":" : ""); } string spec_name = spec_token[0]; toLowerInPlace(spec_name); headers[spec_name] = spec_val; } } return true; }
//------------------------------------------------------------------------------ HTTPRequestHandler* ofxIpVideoServerRoute::createRequestHandler(const HTTPServerRequest& request) { URI uri(request.getURI()); if(ofxIpVideoServerRouteHandler::matchRoute(uri,settings.route)) { ofxIpVideoServerFrame::Settings targetSettings; string query = uri.getQuery(); NameValueCollection queryMap = ofGetQueryMap(uri); if(queryMap.has("vflip")) { string vflip = queryMap.get("vflip"); targetSettings.bFlipVertical = icompare(vflip,"1") == 0 || icompare(vflip,"true") == 0 || icompare(vflip,"t") == 0 || icompare(vflip,"y") == 0 || icompare(vflip,"yes") == 0; } if(queryMap.has("hflip")) { string hflip = queryMap.get("hflip"); targetSettings.bFlipHorizontal = icompare(hflip,"1") == 0 || icompare(hflip,"true") == 0 || icompare(hflip,"t") == 0 || icompare(hflip,"y") == 0 || icompare(hflip,"yes") == 0; } if(queryMap.has("size")) { string size = queryMap.get("size"); toLowerInPlace(size); vector<string> tokens = ofSplitString(size,"x"); if(tokens.size() == 2) { int width = ofToInt(tokens[0]); int height = ofToInt(tokens[1]); if(width > 0 && height > 0) { width = MIN(width,MAX_VIDEO_DIM); height = MIN(height,MAX_VIDEO_DIM); targetSettings.width = width; targetSettings.height = height; } } } if(queryMap.has("quality")) { string quality = queryMap.get("quality"); if(icompare(quality,"best")) { targetSettings.quality = OF_IMAGE_QUALITY_BEST; } else if(icompare(quality,"high")) { targetSettings.quality = OF_IMAGE_QUALITY_HIGH; } else if(icompare(quality,"medium")) { targetSettings.quality = OF_IMAGE_QUALITY_MEDIUM; } else if(icompare(quality,"low")) { targetSettings.quality = OF_IMAGE_QUALITY_LOW; } else if(icompare(quality,"worst")) { targetSettings.quality = OF_IMAGE_QUALITY_WORST; } else { // no change } } ofxIpVideoServerFrameQueue* queue = new ofxIpVideoServerFrameQueue(targetSettings); queues.push_back(queue); return new ofxIpVideoServerRouteHandler(settings,*queue); } else { return NULL; } }
std::string toLower( std::string const& s ) { std::string lc = s; toLowerInPlace( lc ); return lc; }