// --------------------------------------------------------------------------- // SdpUtil::ChopElementsFromLineL // Chops all the elements that are divided by delimiter from the string // --------------------------------------------------------------------------- // void SdpUtil::ChopElementsFromLineL( RArray<TPtrC8>& aArray, TLex8& aLexer, TChar aDelimiter, TInt aErrCode ) { // Chop the elements to the array from lexer TBool eofcFound = EFalse; while (!eofcFound) { aLexer.Mark(); // Parse single token, leave other special characters // to token except aDelimiter | '\r' | '\n' | '\0' while ( aLexer.Peek() != aDelimiter && aLexer.Peek() != KCRChar && aLexer.Peek() != KLFChar && aLexer.Peek() != KEofChar ) { aLexer.Inc(); } if ( aLexer.MarkedToken().Length() > 0 ) { aArray.AppendL( aLexer.MarkedToken() ); } if ( aDelimiter == KSPChar && aLexer.Peek() == aDelimiter ) { SkipSpacesUntilNextLineBreak( aLexer ); } // Check if its end-of-line if ( aLexer.Peek() == KCRChar ) { aLexer.Inc(); } if ( aLexer.Peek() == KLFChar ) { aLexer.Inc(); if ( aLexer.Peek() != KEofChar ) { User::Leave( aErrCode ); } eofcFound = ETrue; } else if ( aLexer.Peek() == KEofChar ) { // EoF character not tolerated at the middle of the string User::Leave( aErrCode ); } else { aLexer.Inc(); } } }
// ----------------------------------------------------------------------------- // CWPPushMessage::GetTokenText // ----------------------------------------------------------------------------- // TPtrC8 CWPPushMessage::GetTokenText( TLex8& aPointer ) const { // Token text is just characters with an end-of-string marker. aPointer.Mark(); while( !aPointer.Eos() && aPointer.Get() != EKeyNull ) { // Do nothing } return aPointer.MarkedToken(); }
// ----------------------------------------------------------------------------- // CWPPushMessage::GetTextString // ----------------------------------------------------------------------------- // TPtrC8 CWPPushMessage::GetTextString( TLex8& aPointer ) const { // Text-string can be quoted. if( aPointer.Peek() == KQuotedTextStringStart ) { aPointer.Inc(); } aPointer.Mark(); while( aPointer.Get() != EKeyNull ) { // Nothing } // We don't want to have NULL in the resulting descriptor, so // back that out. aPointer.UnGet(); TPtrC8 result( aPointer.MarkedToken() ); aPointer.Inc(); return result; }
// ----------------------------------------------------------------------------- // CWPPushMessage::GetTextValue // ----------------------------------------------------------------------------- // TPtrC8 CWPPushMessage::GetTextValue( TLex8& aPointer ) const { // Text-value can be quoted, so skip that first. if( aPointer.Peek() == KQuotedStringStart ) { aPointer.Inc(); } aPointer.Mark(); // It is null-terminated while( aPointer.Get() != EKeyNull ) { // Do nothing } // We don't want to have NULL in the resulting descriptor, so // back that out. TPtrC8 result( aPointer.MarkedToken() ); result.Set( result.Left( Max( 0, result.Length()-1 ) ) ); return result; }
// ----------------------------------------------------------------------------- // SdpUtil::GetElementsFromLineL // Gets all the elements from a single line // ----------------------------------------------------------------------------- // RArray<TPtrC8> SdpUtil::GetElementsFromLineL( TLex8& aLexer, TChar aDelimiter, TInt aErrCode ) { RArray<TPtrC8> lineArray; CleanupClosePushL( lineArray ); // Header is special case, because it is joined _without_ // space character with the first attribute, so it must be // parsed separately aLexer.Mark(); // curChar must be != KEqualChar at first comparison for ( TChar curChar( KSPChar ); curChar != KEqualChar; ) { curChar = aLexer.Peek(); // Syntax check if ( curChar == KEofChar || curChar == KLFChar || curChar == KCRChar ) { User::Leave( aErrCode ); } aLexer.Inc(); } // Append header to array User::LeaveIfError( lineArray.Append( aLexer.MarkedToken() ) ); // Whitespace MUST NOT be used after the "=" sign if (aLexer.Peek() == KSPChar) { User::Leave( aErrCode ); } // Get the other elements from the string to the array ChopElementsFromLineL( lineArray, aLexer, aDelimiter, aErrCode ); CleanupStack::Pop(); // lineArray return lineArray; }
void CDomainNameCodec::EncodeL(TDomainNameArray& aNames, RBuf8& aBuf8) { TUint requiredLength = 0; TUint8 nameIdx = 0; for (nameIdx=0;nameIdx<aNames.Count();nameIdx++) { // The total length required for the labels that comprise an // individual domain name needs to take into the length octet // for the initial label and the null-termination character. // Hence the '+ 2' below. requiredLength += (aNames[nameIdx].Length() + 2); // A further length check is performed on each domain name to // ensure it does not exceed the maximum length permitted according // to RFC 1035. if(aNames[nameIdx].Length() > KMaxDomainNameLength) { User::Leave(KErrArgument); } } aBuf8.Zero(); aBuf8.ReAllocL(requiredLength); TLex8 domainName; TPtrC8 currentLabel; for (nameIdx=0;nameIdx<aNames.Count();nameIdx++) { domainName.Assign(aNames[nameIdx]); domainName.Mark(); while (!domainName.Eos()) { TChar ch; do { ch = domainName.Get(); } while ( ch != TChar('.') && !domainName.Eos() ); // if not the end of the string, unget the previous char to skip the trailing // dot in our marked token // if( !domainName.Eos() ) { domainName.UnGet(); } currentLabel.Set(domainName.MarkedToken()); // move past the dot again, or do nothing in particular at EOS // domainName.Get(); User::LeaveIfError(currentLabel.Length() > KMaxDnsLabelLength ? KErrArgument : KErrNone); aBuf8.Append(TChar(currentLabel.Length())); aBuf8.Append(currentLabel); domainName.Mark(); } aBuf8.Append(TChar(0)); } }