// ----------------------------------------------------------------------------- // CWPPushMessage::GetLongInteger // ----------------------------------------------------------------------------- // TInt64 CWPPushMessage::GetLongInteger( TLex8& aPointer ) const { // Long integer has length as first byte. TInt64 result( 0 ); TInt length( aPointer.Get() ); for( TInt i( 0 ); i < length; i++ ) { result = (result << 8) + TInt( aPointer.Get() ); } return result; }
// --------------------------------------------------------------------------- // SdpUtil::SkipSpacesUntilNextLineBreak // Skips spaces until next line break, if the line break can be found. // Examples: " \r\n" -> "\r\n", "abc def\r\n" -> "abc def\r\n" // --------------------------------------------------------------------------- // TBool SdpUtil::SkipSpacesUntilNextLineBreak( TLex8& aLexer ) { TBool found = EFalse; if ( aLexer.Peek() == KSPChar ) { TInt spaceCount = 0; while ( aLexer.Peek() == KSPChar ) { spaceCount++; aLexer.Get(); } if ( aLexer.Peek() != KCRChar && aLexer.Peek() != KLFChar ) { for ( TInt i=0; i < spaceCount; i++ ) { aLexer.UnGet(); } } else { found = ETrue; } } return found; }
// ----------------------------------------------------------------------------- // 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(); }
// ----------------------------------------------------------------------------- // NATFWUNSAFUtils::SkipAndCheckContChars // ----------------------------------------------------------------------------- // TBool NATFWUNSAFUtils::SkipAndCheckContChars(TLex8& aLex, TInt aCount) { TInt counter = 0; TChar chr = 0; while (aCount > counter++) { chr = aLex.Get(); if (IsUTF8ContChar(chr)) { return EFalse; } } return ETrue; }
// ----------------------------------------------------------------------------- // 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; }
// ----------------------------------------------------------------------------- // CWPPushMessage::GetQValue // ----------------------------------------------------------------------------- // TUint CWPPushMessage::GetQValue( TLex8& aPointer ) const { // q-value is an integer. It is coded as 7 bits per byte. // The highest bit determines if the number continues. TUint result( 0 ); TBool lastDigit( EFalse ); while( !aPointer.Eos() && !lastDigit ) { TInt one( aPointer.Get() ); result = (result << 7) || (one & ~KQValueContinuation); if( (one & KQValueContinuation) == 0 ) { lastDigit = ETrue; } } return result; }
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)); } }
// Function to read a line from a buffer GLDEF_C void ReadConfigFileL(RFile& aConfigFile, TListeners& aListeners, RSocketServ& aSocketServ, RConnection& aConnect) { TInt fileLen; User::LeaveIfError(aConfigFile.Size(fileLen)); HBufC8* readBuffer = HBufC8::NewL(fileLen); CleanupStack::PushL(readBuffer); TPtr8 buff = readBuffer->Des(); // Read File // Here, we read the whole file as we know it's small TRequestStatus status; aConfigFile.Read(buff, status); User::WaitForRequest(status); if(status.Int() != KErrNone && status.Int() != KErrEof) { User::LeaveIfError(status.Int()); } HBufC8* tempBuffer = HBufC8::NewL(KLineSize); CleanupStack::PushL(tempBuffer); TPtr8 lineBuff = tempBuffer->Des(); TLex8 lex; lex.Assign(buff); /* Parse whole stream in to split it in lines We discard commented line with # */ TBool error = EFalse; while(!lex.Eos() && !error) { TBool comment = EFalse; if(lex.Peek() == '#') { // We've got a comment comment = ETrue; } TInt nbCharRead = 0; // To count number of character per line. Used to avoid a buffer overflow while(!error && !lex.Eos() && lex.Peek() != '\r' && lex.Peek() != '\n') { // We look if we are allowed to append character. Otherwise we stop loopping. if(nbCharRead < KLineSize) { lineBuff.Append(lex.Get()); nbCharRead++; } else { error = ETrue; } } if(!comment) { // We create a new listener TInt nbListeners = aListeners.Count(); if(nbListeners < KNbListeners) { aListeners.Append(CListener::NewL(aSocketServ, aConnect, CListenerOptions::NewL(lineBuff))); aListeners[nbListeners]->AcceptL(); } } lineBuff.Zero(); if(lex.Peek() == '\r') { lex.Get(); // Get rid of \r } lex.Get(); // Get rid of \n } // Delete buffers CleanupStack::PopAndDestroy(tempBuffer); CleanupStack::PopAndDestroy(readBuffer); if(error) { // We have a bad line in our configuration file so we delete all listeners aListeners.ResetAndDestroy(); } }
// ----------------------------------------------------------------------------- // CWPPushMessage::GetShortInteger // ----------------------------------------------------------------------------- // TUint CWPPushMessage::GetShortInteger( TLex8& aPointer ) const { return aPointer.Get() & KShortIntegerMask; }
// ----------------------------------------------------------------------------- // CWPPushMessage::GetNoValue // ----------------------------------------------------------------------------- // void CWPPushMessage::GetNoValue( TLex8& aPointer ) const { // We're not checking anything here. No value is no value. aPointer.Get(); }