Boolean HTTPMessage::parseRequestLine( const String& startLine, String& methodName, String& requestUri, String& httpVersion) { // Request-Line = Method SP Request-URI SP HTTP-Version CRLF // Extract the method-name: Uint32 space1 = startLine.find(' '); if (space1 == PEG_NOT_FOUND) return false; methodName = startLine.subString(0, space1); // Extrat the request-URI: Uint32 space2 = startLine.find(space1 + 1, ' '); if (space2 == PEG_NOT_FOUND) return false; Uint32 uriPos = space1 + 1; requestUri = startLine.subString(uriPos, space2 - uriPos); // Extract the HTTP version: httpVersion = startLine.subString(space2 + 1); return true; }
// // parse the HTTP authentication header // Boolean HTTPMessage::parseHttpAuthHeader( const String& authHeader, String& authTypeString, String& cookie) { PEG_METHOD_ENTER(TRC_HTTP, "HTTPMessage::parseHttpAuthHeader()"); // // Extract the authentication type: // Uint32 space = authHeader.find(' '); if ( space == PEG_NOT_FOUND ) { PEG_METHOD_EXIT(); return false; } authTypeString = authHeader.subString(0, space); // // Extract the cookie: // cookie = authHeader.subString(space + 1); PEG_METHOD_EXIT(); return true; }
// // parse the local authentication header // Boolean HTTPMessage::parseLocalAuthHeader( const String& authHeader, String& authType, String& userName, String& cookie) { PEG_METHOD_ENTER(TRC_HTTP, "HTTPMessage::parseLocalAuthHeader()"); // // Extract the authentication type: // Uint32 space = authHeader.find(' '); if ( space == PEG_NOT_FOUND ) { PEG_METHOD_EXIT(); return false; } authType = authHeader.subString(0, space); Uint32 startQuote = authHeader.find(space, '"'); if ( startQuote == PEG_NOT_FOUND ) { PEG_METHOD_EXIT(); return false; } Uint32 endQuote = authHeader.find(startQuote + 1, '"'); if ( endQuote == PEG_NOT_FOUND ) { PEG_METHOD_EXIT(); return false; } String temp = authHeader.subString( startQuote + 1, (endQuote - startQuote - 1)); // // Extract the user name and cookie: // Uint32 colon = temp.find(0, ':'); if ( colon == PEG_NOT_FOUND ) { userName = temp; } else { userName = temp.subString(0, colon); cookie = temp; } PEG_METHOD_EXIT(); return true; }
bool ImageDesignManager::validatePalette(PaletteColorCustomizationVariable* palette, int value, int skillLevel) { String paletteFileName = palette->getPaletteFileName(); int idx = paletteFileName.lastIndexOf("/"); if (idx != -1) { String paletteName = paletteFileName.subString(idx + 1); paletteName = paletteName.subString(0, paletteName.indexOf(".")); //info("palette name = " + paletteName, true); PaletteData* data = CustomizationIdManager::instance()->getPaletteData(paletteName); if (data == NULL) { //error("could not find palette data for " + paletteName); } else { int maxIndex; switch (skillLevel) { case -1: maxIndex = data->getCreationIndexes(); break; case 0: maxIndex = data->getIdNoviceIndexes(); break; case 1: maxIndex = data->getIdLevel1Indexes(); break; case 2: maxIndex = data->getIdLevel2Indexes(); break; case 3: maxIndex = data->getIdLevel3Indexes(); break; case 4: maxIndex = data->getIdLevel4Indexes(); break; case 5: maxIndex = data->getIdMasterIndexes(); break; default: maxIndex = -1; break; } if (value >= maxIndex || value < 0) { instance()->error("value for " + paletteFileName + " value " + value + " outside bound " + String::valueOf(maxIndex)); return false; } else { //info(name + " value " + String::valueOf(val) + " inside bound " + String::valueOf(maxIndex) + " for " + name , true); } } } return true; }
bool String::filenameIsAbsolutePath(const char* szText) { String sText = szText; return #if defined(WIN32) sText.subString(1, 1) == ":" || sText.startsWith("/") || sText.subString(0, 2) == String_FILEPATHSEPARATOR String_FILEPATHSEPARATOR #else sText.startsWith(String_FILEPATHSEPARATOR); #endif ; }
String NameManager::appendSyllable(const String& left, const String& right, NameData* data) { if (left == "") return right; int leftLen = left.length(); int leftFragType = NameManagerType::FRAG_MIXED; int i = leftLen; String leftFragment = ""; while (i > 0) { --i; String leftFrag = left.subString(i, leftLen); int fragType = getFragmentType(leftFrag, data); if (fragType == NameManagerType::FRAG_MIXED || fragType == NameManagerType::FRAG_SPECIAL) break; leftFragment = leftFrag; leftFragType = fragType; } int rightFragType = NameManagerType::FRAG_MIXED; String rightFragment = ""; int r = 0; while (r < right.length()) { ++r; String rightFrag = right.subString(0, r); int fragType = getFragmentType(rightFrag, data); if (fragType == NameManagerType::FRAG_MIXED || fragType == NameManagerType::FRAG_SPECIAL) break; rightFragment = rightFrag; rightFragType = fragType; } if (rightFragType != leftFragType) return left + right; if (leftFragment == rightFragment) return left; if (leftFragType == NameManagerType::FRAG_CONSONANT) return left + data->getRandomVowel() + right; else return left + data->getRandomMiddleConsonant() + right; }
/* Fix up a string with embedded comma with extra escape character and return the result. This is a hack to get around the problem that arrays having strings with an embedded comma are treat the embedded comma as an array item separator. NOTE: The correct solution is to add a new value factory funciton for arrays specifically that uses a different separator on an array of values. BUG 497 fix, KS Sept 2003 */ String valueFactory::stringWComma(String tmp) { //String tmp = *$3; String rtn = String::EMPTY; Uint32 len; while((len = tmp.find(',')) != PEG_NOT_FOUND) { rtn.append(tmp.subString(0,len)); rtn.append("\\,"); tmp = tmp.subString(len+1); } if (tmp.size() > 0) rtn.append(tmp); return(rtn); }
/** Get the homed path for a given property. */ String ConfigManager::getHomedPath(const String& value) { String homedPath; if (value != String::EMPTY) { if (System::is_absolute_path((const char *)value.getCString())) { return value; } // // Get the pegasusHome and prepend it // String temp = value; Uint32 pos = 0; Uint32 token = 0; do { if ((pos = temp.find(FileSystem::getPathDelimiter())) == PEG_NOT_FOUND) { pos = temp.size(); token = 0; } else { token = 1; } if (System::is_absolute_path( (const char *)temp.subString(0, pos).getCString())) { homedPath.append(temp.subString(0,pos)); } else { homedPath.append(_pegasusHome + "/" + temp.subString(0, pos)); } if (token == 1) homedPath.append(FileSystem::getPathDelimiter()); temp.remove(0, pos + token); } while (temp.size() > 0); } return homedPath; }
bool PetManagerImplementation::isTrainedCommand( PetControlDevice* petControlDevice, unsigned int commandId, const String& msg ){ // Check if pet is trained in the command if( !petControlDevice->hasTrainedCommand( commandId ) ) return false; // Check if string exactly matches registered command if( petControlDevice->getTrainedCommand(commandId) == msg ) return true; // Check if string matches registered command with or without the pet's name String name = petControlDevice->getCustomObjectName().toString(); if( name.length() > 2 ){ String petName = name.subString( 1, name.length()-1 ); // Remove parenthesis String cmdWithName = petName + " " + petControlDevice->getTrainedCommand(commandId); if( cmdWithName == msg ) return true; String msgWithName = petName + " " + msg; if( petControlDevice->getTrainedCommand(commandId) == msgWithName ) return true; } return false; }
String NameManager::generateUniqueName(NameData* nameData, NameRules* rules) { String pattern = nameData->getRandomUniquePattern(); String result = ""; Vector<String> usedRoots; for (int i = 0; i < pattern.length(); i++) { String patType = pattern.subString(i, i + 1); if (patType == "*") { result = appendSyllable(result, generateRandomizedName(nameData, rules), nameData); } else { for (;;) { String root = ""; String unique = nameData->getRandomUnique(patType, root); if (root != "" && usedRoots.contains(root)) continue; result += unique; if (root != "") usedRoots.add(root); break; } } } return result; }
Boolean _isChild( CIMNamespaceName& parentNamespaceName, CIMNamespaceName& namespaceName) { String parent = parentNamespaceName.getString(); String child = namespaceName.getString(); // // If length of namespace name is shorter than or equal to the // length of parent namespace name, cannot be a child // if (child.size () <= parent.size ()) { return false; } // // Compare prefix substring of namespace name with parent namespace name // else if (String::equalNoCase (child.subString (0, parent.size ()), parent)) { return true; } return false; }
void testAuthHeader() { LocalAuthenticationHandler localAuthHandler; String respHeader = localAuthHandler.getAuthResponseHeader(authType, testUser, authInfo); #ifdef DEBUG if (verbose) cout << "respHeader= " << respHeader << endl; #endif challenge = authInfo->getAuthChallenge(); PEGASUS_ASSERT(respHeader.size() != 0); Uint32 startQuote = respHeader.find(0, '"'); assert(startQuote != PEG_NOT_FOUND); Uint32 endQuote = respHeader.find(startQuote + 1, '"'); assert(startQuote != PEG_NOT_FOUND); filePath = respHeader.subString(startQuote + 1, (endQuote - startQuote - 1)); PEGASUS_ASSERT(filePath.size() != 0); }
void findModuleName( const String &filename, String &name ) { uint32 pos = filename.rfind( "/" ); if ( pos == csh::npos ) { name = filename; } else { name = filename.subString( pos + 1 ); } // find the dot pos = name.rfind( "." ); if ( pos != csh::npos ) { name = name.subString( 0, pos ); } }
void findModulepath( const String &filename, String &path ) { uint32 pos = filename.rfind( "/" ); if ( pos != csh::npos ) { path = filename.subString( 0, pos ); } }
//len must be known in advance; you can not pass a subString of the returned buffer to ws_endWriteFrame() String ws_beginWriteFrame(FrameWriter& fw, int len) { int hdrlen = sizeof(WebSocketParser::ws_header1); if (len > 125 && len <= 0xFFFF) hdrlen += sizeof(WebSocketParser::ws_header_extended16); if (len > 0xFFFF) hdrlen += sizeof(WebSocketParser::ws_header_extended64); String buf = fw.beginInsert(hdrlen + len); return buf.subString(hdrlen, len); }
bool HeaderValue::parseValuePart( const String& v ) { TRACE( "parseValuePart: %s", v.getRawStorage() ); uint32 pos=0, pos1=0; // now parse all the parameters while( (pos1 = v.find(",", pos) ) != String::npos ) { m_lValues.push_back( URI::URLDecode( v.subString(pos, pos1) ) ); m_lValues.back().trim(); pos = pos1+1; } m_lValues.push_back( URI::URLDecode( v.subString(pos) ) ); m_lValues.back().trim(); return true; }
// Parse out the flagname and the value from a long flag option that // may be in the form // --longflag=value static void partsFromLongOpt( const String& s, String& name, String& value) { for (unsigned int i = 0; i < s.size(); i++) { if (s[i] == '=') { name = s.subString(0, i); value = s.subString(i+1); return; } } name = s; value = ""; }
void DBIConnect( VMachine *vm ) { Item *paramsI = vm->param(0); Item *i_tropts = vm->param(1); if ( paramsI == 0 || ! paramsI->isString() || ( i_tropts != 0 && ! i_tropts->isString() ) ) { throw new ParamError( ErrorParam( e_inv_params, __LINE__ ) .extra( "S,[S]" ) ); } String *params = paramsI->asString(); String provName = *params; String connString = ""; uint32 colonPos = params->find( ":" ); if ( colonPos != csh::npos ) { provName = params->subString( 0, colonPos ); connString = params->subString( colonPos + 1 ); } DBIHandle *hand = 0; try { DBIService *provider = theDBIService.loadDbProvider( vm, provName ); // if it's 0, the service has already raised an error in the vm and we have nothing to do. fassert( provider != 0 ); hand = provider->connect( connString ); if( i_tropts != 0 ) { hand->options( *i_tropts->asString() ); } // great, we have the database handler open. Now we must create a falcon object to store it. CoreObject *instance = provider->makeInstance( vm, hand ); vm->retval( instance ); } catch( DBIError* error ) { delete hand; throw error; } }
bool HeaderValue::parseParamPart( const String& v ) { TRACE( "parseParamPart: %s", v.getRawStorage() ); uint32 pos = v.find( "=" ); if( pos == String::npos ) return false; String sKey = v.subString(0,pos); sKey.trim(); String sValue = v.subString(pos+1); sValue.trim(); if( sValue.startsWith("\"") && sValue.endsWith("\"") ) { sValue = sValue.subString(1,sValue.length()-1); } // prevent misunderstading effectively empty values if( sValue.size() == 0 ) { m_mParameters[sKey] = ""; return true; } // Is URI encoded? String sValFinal = URI::URLDecode( sValue ); if( sValFinal.size() == 0 ) { // if it's not URI encoded, then it must be UTF-8 encoded // also, no valid utf-8 encoding can be uri encoded, so... String sValDec; sValue.c_ize(); sValDec.fromUTF8( (char*) sValue.getRawStorage() ); m_mParameters[sKey] = sValDec; } else { m_mParameters[sKey] = sValFinal; } return true; }
void Path::split(const String &path,String& dirpath, String& filename) { if (path.isEmpty ()) THROW("IDS_ILLEGAL_PATH"); if (path.findFirstOf (Path::invalidPathChars, 0) != String::NO_POSITION) THROW("IDS_ILLEGAL_PATH"); dirpath.clear(); filename.clear(); String p = Path::adaptSep(path); #ifdef __WINDOWS__ // TODO // deal route like \\.\device\somthing // and \\?\volume\something // and driver: like C: // C:dir should throw an error? #endif // deal when start with separator size_t headSlashNum = 0; if (isSeparator(p[0])) { while (isSeparator( p[headSlashNum])) { dirpath += Path::separator; headSlashNum++; if (headSlashNum == p.getLength()) { break; } } } p = p.subString(headSlashNum); // find most right sep pos size_t posLastSlash = p.findLastOf(Path::separator); if (posLastSlash == p.getLength() - 1) { dirpath += p.subString(0, p.getLength() - 1); filename = String::EMPTY; } else if (posLastSlash == String::NO_POSITION) { filename = p; } else { dirpath += String(p, 0, posLastSlash); filename.assign(p, posLastSlash + 1, String::NO_POSITION); } }
void BuffImplementation::parseSkillModifierString(const String& modifierstring) { StringTokenizer tokenizer(modifierstring); tokenizer.setDelimeter(";"); while (tokenizer.hasMoreTokens()) { String token; tokenizer.getStringToken(token); int tokpos = token.indexOf("="); if (tokpos == -1) continue; String modname = token.subString(0, tokpos); float value = Float::valueOf(token.subString(tokpos + 1, token.length())); skillModifiers.put(modname, (int) value); } }
void BuffImplementation::parseAttributeModifierString(const String& modifierstring) { StringTokenizer tokenizer(modifierstring); tokenizer.setDelimeter(";"); while (tokenizer.hasMoreTokens()) { String token; tokenizer.getStringToken(token); int tokpos = token.indexOf("="); if (tokpos == -1) continue; uint8 attribute = CreatureAttribute::getAttribute(token.subString(0, tokpos)); int value = Integer::valueOf(token.subString(tokpos + 1, token.length())); attributeModifiers.put(attribute, value); } }
size_t String::findFirst(size_t start,const String &s)const { for(size_t i=start;i!=size();++i) { auto subStr = s.subString(i, s.size()); if(subStr == s) return i; } return SIZE_MAX; }
bool StringStream::writeString( const String &source, uint32 begin, uint32 end ) { if( begin != 0 || ( end != -1 && end < source.length() ) ) { return StringStream::subWriteString( source.subString(begin, end) ); } else { return StringStream::subWriteString( source ); } }
void PlayerManagementSessionImplementation::parseBanDuration(const String& duration) { StringTokenizer tokenizer(duration); int durationInSeconds = 0; try { while(tokenizer.hasMoreTokens()) { String token; tokenizer.getStringToken(token); if(token.length() < 2) throw Exception(); char timeframe = token.charAt(token.length() - 1); token = token.subString(0, token.length() - 1); int units = Integer::valueOf(token); int seconds = 0; switch(timeframe) { case 'y': seconds = 60 * 60 * 24 * 365; break; case 'm': seconds = 60 * 60 * 24 * 30; break; case 'd': seconds = 60 * 60 * 24; break; case 'h': seconds = 60 * 60; break; case 'M': seconds = 60; break; default: throw Exception(); break; } durationInSeconds += (units * seconds); } banExpiration = durationInSeconds + time(0); if(banReason.isEmpty()) sendBanReason(); else showBanSummary(); } catch(Exception& e) { sendBanDuration(); } }
String NameManager::capitalizeName(String& name) { String result = ""; bool capNext = true; for (int i = 0; i < name.length(); ++i) { if (capNext) result += name.subString(i, i + 1).toUpperCase(); else result += name.subString(i, i + 1); if (name.subString(i, i + 1) == " ") capNext = true; else if (name.subString(i, i + 1) == "'" || name.subString(i, i + 1) == "-") // Letter after a ' or - is not always capitalized capNext = System::random(100) > 50; else capNext = false; } return result; }
/** Initialize config property with the value specified in the command line. */ Boolean ConfigManager::_initPropertyWithCommandLineOption( const String& option) { Uint32 pos = option.find('='); if (pos == PEG_NOT_FOUND) { // // The property value was not specified // throw UnrecognizedConfigProperty(option); } // // Get the property name and value // String propertyName = option.subString(0, pos); String propertyValue = option.subString(pos + 1); return initCurrentValue(propertyName, propertyValue); }
String ApLib::getRandomString(int nLength) { String sRandom; while (sRandom.chars() < nLength) { String sId = getRandomString(); sRandom += sId.subString(0, nLength - sRandom.chars()); } return sRandom; }
bool HeaderValue::parseValue( const String& v ) { TRACE( "parseValue: %s", v.getRawStorage() ); m_sRawValue = v; uint32 pos=0, pos1=0; // get the value pos = v.find(";"); if( pos == String::npos ) { // eventually, parse it also as parameters // --- but don't complain if it's not in the format V=N parseParamPart( v ); return parseValuePart( v ); } // else if( ! parseValuePart( v.subString(0,pos) ) ) return false; // eventually, parse it also as parameters // --- but don't complain if it's not in the format V=N parseParamPart( v.subString(0,pos) ); // now parse all the parameters ++pos; while( (pos1 = v.find(";", pos) ) != String::npos ) { if( ! parseParamPart( v.subString(pos, pos1) ) ) return false; pos = pos1+1; } // the last parameter return parseParamPart( v.subString(pos) ); }
void clientRepositoryInterface::init(_repositoryType type, const String &location) { String message; // _ot = ot; if (type == REPOSITORY_INTERFACE_LOCAL) { _repository = new CIMRepository(location); // test to find if repository exists. } else if (type == REPOSITORY_INTERFACE_CLIENT) { // create a CIMClient object and put it in _client try { Uint32 index = location.find (':'); String host = location.subString (0, index); Uint32 portNumber = 0; if (index != PEG_NOT_FOUND) { String portStr = location.subString (index + 1, location.size ()); sscanf (portStr.getCString (), "%u", &portNumber); } cout << "open " << host << " port " << portNumber << endl; _client = new CIMClient(); _client->connect (host, portNumber, String::EMPTY, String::EMPTY); } catch(Exception &e) { cerr << "Internal Error:" << e.getMessage() << endl; delete _client; _client = 0; } } else { throw IndexOutOfBoundsException(); } }