TBool CCmdRemark::Recognize( const TDesC& aCommand ) { // Obey the command family's step over mode. SetStepOver(Family()->StepOver()); // Check if is empty or begins with # character. TPtrC cmd = TfrLex::Trim(aCommand); // look for empty, # or // return ((cmd.Length() == 0) || (cmd.Match( _L("#*")) == 0) || (cmd.Match(_L("//*")) == 0 )); }
TBool CCmdListAll::Recognize( const TDesC& aCommand ) { // Check if is empty or begins with # character. TPtrC cmd = TfrLex::Trim(aCommand); return (cmd.Match( _L("?")) == 0); }
TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult) { TBool ret=EFalse; if ( aSectName.Length()!=0 ) { ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult); for ( TInt index=iInclude.Count(); (index>0) && (!ret); ) { ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult); } } if ( ret ) { if ( aResult.Match(KMatch)!=KErrNotFound ) { // We have an entry of the format // entry =*{section,entry}* // where * is one or more characters // We need to construct this from other data in the ini file replacing {*,*} // with the data from // [section] // entry =some_value HBufC* buffer=HBufC::NewLC(aResult.Length()); buffer->Des().Copy(aResult); TInt startLength=KStart().Length(); TInt sparatorLength=KSeparator().Length(); TInt endLength=KEnd().Length(); TInt bufferLength; TInt start; TInt sparator; TInt end; TPtrC remaining; TLex lex; do { bufferLength=buffer->Length(); start=buffer->Find(KStart); remaining.Set(buffer->Des().Right(bufferLength-start-startLength)); sparator=remaining.Find(KSeparator); remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength)); sparator += (start + startLength); end=remaining.Find(KEnd) + sparator + sparatorLength; TPtrC sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength); TPtrC keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength); sectionName.Set(TLex(sectionName).NextToken()); keyName.Set(TLex(keyName).NextToken()); TInt entrySize=0; TPtrC entryData; TBool found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData); for ( TInt index=iInclude.Count(); (index>0) && (!found); ) { found=iInclude[--index]->FindVar(sectionName, keyName, entryData); } if ( found ) { entrySize=entryData.Length(); } TInt newLength=start + bufferLength - end - endLength + entrySize; HBufC* bufferNew=HBufC::NewLC(newLength); bufferNew->Des().Copy(buffer->Ptr(), start); if ( entrySize>0 ) { bufferNew->Des().Append(entryData); } bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength); CleanupStack::Pop(bufferNew); CleanupStack::PopAndDestroy(buffer); buffer=bufferNew; CleanupStack::PushL(buffer); } while ( buffer->Match(KMatch)!=KErrNotFound ); iBuffer.Append(buffer); CleanupStack::Pop(buffer); aResult.Set(*buffer); INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult); } } return ret; }
/** Search fixed start URLs, i.e. URLs without schema (www., wap.). Also finds IPv4 addresses (*.*.*.*). As a special case, supports deprecated hardcoded schematic addresses finding (http://, https://, rtsp://) to make sure deprecated search cases work as they did previously. @param aText Text that will be parsed @param aFindFixedSchemas If true, will find old fixed schematic URLs also @return ETrue if any URL are found else returns EFalse @leave KErrNone, if successful; otherwise one of the other system-wide error codes. @panic ETulPanicDescriptorLength in debug build if item's position and/or length is out of the document's range. */ TBool CTulAddressStringTokenizer::SearchUrlL( const TDesC& aText, const TBool aFindFixedSchemas ) { TLex text = aText; while ( !text.Eos() ) { while( !(text.Eos()) && !IsValidUrlChar( text.Peek() ) ) text.Inc(); text.Mark(); while( !(text.Eos()) && IsValidUrlChar( text.Peek() ) ) text.Inc(); TPtrC tokenPtr = text.MarkedToken(); TBool wasValidUrl = EFalse; if ( aFindFixedSchemas ) // Search for http:// wasValidUrl = ParseUrlL( KHttpUrlAddress, tokenPtr, text.Offset() ); if (aFindFixedSchemas && !wasValidUrl) // Search for https:// wasValidUrl = ParseUrlL( KHttpsUrlAddress, tokenPtr, text.Offset() ); if (aFindFixedSchemas && !wasValidUrl) // Search for rtsp:// wasValidUrl = ParseUrlL( KRtspUrlAddress, tokenPtr, text.Offset() ); if ( !wasValidUrl ) // Search for www. wasValidUrl = ParseUrlL( KWwwUrlAddress, tokenPtr, text.Offset() ); if ( !wasValidUrl ) // Search for wap. wasValidUrl = ParseUrlL( KWapUrlAddress, tokenPtr, text.Offset() ); if ( !wasValidUrl ) // Search for IP-address (xxx.xxx.xxx.xxx) { if ( tokenPtr.Match( KIPAddress ) != KErrNotFound ) { TInt periods = 0; wasValidUrl = ETrue; TBool endWithPunctuation = EFalse; TBool betweenBrackets = EFalse; // First see if token ends with ",",".","!","?",";" or ":" TChar charac = tokenPtr[tokenPtr.Length() - 1]; TChar charac0 = tokenPtr[0]; if ( charac == ',' || charac == '.' || charac == '!' || charac == '?' || charac == ';' || charac == ':' ) { endWithPunctuation = ETrue; } // Or if it starts and ends with brackets or quotation marks else if ( ( charac0 == '(' && charac == ')' ) || ( charac0 == '"' && charac == '"' ) || ( charac0 == '[' && charac == ']' ) || ( charac0 == '<' && charac == '>' ) ) { betweenBrackets = ETrue; } TInt i = 0; TInt tokensEnd = tokenPtr.Length(); if ( endWithPunctuation ) tokensEnd--; else if ( betweenBrackets ) { i = 1; tokensEnd--; } // Take a closer look to see if a valid IP-address TBuf<3> ipPart; TInt numbers = 0; for ( ; i < tokensEnd; i++ ) { if ( !( ((TChar)tokenPtr[i]).IsDigit() || tokenPtr[i] == '.' ) ) { wasValidUrl = EFalse; break; } if ( tokenPtr[i] == '.' ) periods++; else numbers++; if ( numbers > KNumbersInIpAddress || periods > KDotsInIpAddress ) { wasValidUrl = EFalse; break; } if ( ((TChar)tokenPtr[i]).IsDigit() ) { ipPart.Append( tokenPtr[i] ); TBool checkInt = EFalse; if ( i + 1 < tokensEnd ) { if ( tokenPtr[i+1] == '.' ) checkInt = ETrue; } if ( i == tokensEnd - 1 || checkInt ) { TLex val = ipPart; TInt numberInt; TInt error = val.Val( numberInt ); if ( error != KErrNone || numberInt > 255 ) { wasValidUrl = EFalse; break; } numbers = 0; ipPart.Delete( 0, ipPart.Length() ); } } } if ( wasValidUrl && periods == KDotsInIpAddress ) { TInt startPos = text.Offset() - tokenPtr.Length(); TInt length = tokenPtr.Length(); // If there was a punctuation at the end or brackets, let's take it/them away if ( endWithPunctuation || betweenBrackets) { length--; if ( betweenBrackets ) { startPos++; length--; } } __ASSERT_DEBUG( startPos + length <= aText.Length(), Panic(ETulPanicDescriptorLength) ); AddItemL( startPos, length, EFindItemSearchURLBin ); } } } } return (iFoundItems->Count() > 0); }
TInt CCmdIf::ProcessL(const TDesC &aCommand) { // Complete the test machine - will then get the next cmd Machine()->CompleteRequest(); // this converts the first parameter (if found) into something useful! TPtrC param; TRAPD(error, param.Set(ParamsL(aCommand))); if (error != KErrNone) return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); TLex parse(param); if (!parse.Eos() && !parse.Peek().IsSpace()) return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); parse.SkipSpace(); if (parse.Eos()) // no parameters so invalid command return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); // convert into our LValue TPtrC lvalue; TRAP(error, lvalue.Set(TfrLex::GetL(parse))); if (error != KErrNone) return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); lvalue.Set(TfrLex::Peel(lvalue)); if (lvalue.Length() > 32) return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); // now check that the second 'param' is one of our comparison tokens... TPtrC opr; TRAP(error, opr.Set(TfrLex::GetL(parse))); if (error != KErrNone) return Error(KErrArgument, TFR_KFmtErrBadCmd, &opr); // check is valid length opr.Set(TfrLex::Peel(opr)); if (opr.Length() > 16) return Error(KErrArgument, THA_KErrParameterLong, &opr); // check operator is one of our known list // Param shall be HTTP or WSP opr.Set(TfrLex::TrimAndPeel(opr)); TBool eValue; if (opr.CompareF(KTxtEquals) == 0) eValue = TCO_Equals; else if (opr.CompareF(KTxtNotEqual) == 0) eValue = TCO_NotEqual; else if (opr.CompareF(KTxtGreaterThan) == 0) eValue = TCO_GreaterThan; else if (opr.CompareF(KTxtLessThan) == 0) eValue = TCO_LessThan; else if (opr.CompareF(KTxtGreaterThanEq) == 0) eValue = TCO_GreaterThanEq; else if (opr.CompareF(KTxtLessThanEq) == 0) eValue = TCO_LessThanEq; else // not recognized the comp.operator so error return Error(KErrArgument, THA_KErrInvalidOptr, &opr); // now look at the final parameter and convert into our LValue // assuming that there is anything more. TPtrC rvalue = TfrLex::Trim(parse.Remainder()); if (rvalue.Length() == 0) return Error(KErrArgument, TFR_KFmtErrBadCmd, &aCommand); rvalue.Set(TfrLex::TrimAndPeel(rvalue)); if (rvalue.Length() > 16) return Error(error, TFR_KFmtErrBadCmd, &Keyphrase()); // ParseOnly => not executed. if (Family()->Switch(CCmdFamily::EParseOnly)) return error; // determine if we're comparing numeric or data (or both!) TBool iNumeric = ETrue; TInt ilval; TInt irval; if (InetProtTextUtils::ConvertDescriptorToInt(lvalue,ilval) < 0) iNumeric = EFalse; // check we're not comparing apples with oranges... iNumeric = ((InetProtTextUtils::ConvertDescriptorToInt(rvalue,irval) < 0) && iNumeric) ? EFalse : ETrue; // now determine the comparison result (also // -1 => error or failure (i.e. < 0) 0 = false, 1 = true TInt iResult = -2; switch (eValue) { case TCO_Equals : iResult = (iNumeric) ? ((TInt) (ilval == irval)) : ((lvalue.Match(rvalue) == 0) ? 1 : 0); break; case TCO_NotEqual : iResult = (iNumeric) ? ((TInt) (ilval != irval)) : ((lvalue.Match(rvalue) != 0) ? 1 : 0); break; case TCO_GreaterThan : iResult = (iNumeric) ? ((TInt) (ilval > irval)) : ((lvalue.Match(rvalue) == 1) ? 1 : 0); break; case TCO_LessThan : iResult = (iNumeric) ? ((TInt) (ilval < irval)) : ((lvalue.Match(rvalue) == -1) ? 1 : 0); break; case TCO_GreaterThanEq : iResult = (iNumeric) ? ((TInt) (ilval >= irval)) : ((lvalue.Match(rvalue) >= 0) ? 1 : 0); break; case TCO_LessThanEq : iResult = (iNumeric) ? ((TInt) (ilval <= irval)) : ((lvalue.Match(rvalue) < 1) ? 1 : 0); break; } // the result now determines if we continue processing (and ignore any following ELSE) // before we meet the ENDIF or we skip and perform the ELSE clause... // NOTE: now we can nest IF's etc, we MUST count those that are met when we // 'ignore' lines as these MAY be incorrectly nested... TBool iSuccess = (TBool) iResult; if (iSuccess) Machine()->IfL(CIFControl::EIFTrue, iSuccess, CIFControl::EInIF); else // failed test so skip the true block Machine()->IfL(CIFControl::EELSETrue, iSuccess, CIFControl::EInIF); // whilst we would be better off returning the actual result, it bears little consequence // - in fact if we get here we're ok anyway... return KErrNone; }