// ----------------------------------------------------------------------------- // CUpnpHttpSession::ParseRangeHeader // Parse range values // ----------------------------------------------------------------------------- // TBool CUpnpRangeHeaderParser::ParseRangeHeader( TDesC8& aRangeHeader, TInt& aStartPos, TInt& aEndPos ) { // Check header's syntax: "bytes=x-y" where y i optional TInt pos( KErrNotFound ); // 1 string has to contain "=" pos = aRangeHeader.FindC( UpnpString::KEqual() ); if( pos == KErrNotFound ) return EFalse; // 2 "bytes" has to be at the beginnig pos = aRangeHeader.FindC( UpnpHTTP::KBytes() ); if( pos == KErrNotFound || pos != 0 ) return EFalse; // 3 Sets position to after bytes pos = UpnpHTTP::KBytes().Length(); // 4 If there any space or tab after "bytes" - move pos after it CUpnpRangeHeaderParser::MovePosition( aRangeHeader, pos ); // 5 "=" - has to be at this position (after "bytes" + spaces or tabs) if( aRangeHeader[ pos ] != UpnpString::KEqual()[0] ) return EFalse; // 6 Sets position to after "=" pos++; // 7 If there any space or tab after "=" - move pos after it CUpnpRangeHeaderParser::MovePosition( aRangeHeader, pos ); // 8 extract x-y. -1 stands for '=' length TPtrC8 byteRange = aRangeHeader.Right( aRangeHeader.Length() - pos ); // 9 There can't be any comas because multi-range is not allowed if( byteRange.Find( UpnpString::KComa() ) != KErrNotFound ) return EFalse; // 10 "-" delimiter must occure and it cant't be first char, because notation as follows: "-y" is not allowed pos = byteRange.Find( UpnpString::KMinus() ); if( pos == KErrNotFound ) return EFalse; // 11 Checks if it is a final bytes request // e.g. Range: bytes= -20 if( pos == 0 ) { // If there any space or tab after "-" - move pos after it CUpnpRangeHeaderParser::MovePosition( byteRange.Right( byteRange.Length()-1 ), pos ); // if pos equal 0 should be 1 to avoid "-" in getting number from string operation pos = pos == 0 ? 1 : pos; TLex8 endMinus( byteRange.Right( byteRange.Length() - pos ) ); endMinus.SkipSpace(); TInt error = endMinus.Val( aEndPos ); if ( !CUpnpRangeHeaderParser::HandleConversionException( endMinus, aEndPos, error ) ) { return EFalse; } // We have to check if something else than space or tab leaves after conversion - unless for example 11a will be correct but it is not if ( CUpnpRangeHeaderParser::HasImproperChars( endMinus ) ) return EFalse; aStartPos = KErrNotFound; return ETrue; } // 12 All looks fine, so now parse it and get x and y TLex8 start( byteRange.Left( pos ) ); start.SkipSpace(); // 13 If conversion fails - return error TInt error = start.Val( aStartPos ); if ( !CUpnpRangeHeaderParser::HandleConversionException( start, aStartPos, error ) ) { return EFalse; } // 14 We have to check if something else than space or tab leaves after conversion - unless for example 11a will be correct but it is not if ( CUpnpRangeHeaderParser::HasImproperChars( start ) ) return EFalse; // y is optional if( ( byteRange.Length() - pos - 1 ) > 0 ) { TLex8 end( byteRange.Right( byteRange.Length() - pos - 1 ) ); end.SkipSpace(); error = end.Val( aEndPos ); if ( !CUpnpRangeHeaderParser::HandleConversionException( end, aEndPos, error ) ) { return EFalse; } // We have to check if something else than space or tab leaves after conversion - unless for example 11a will be correct but it is not if ( CUpnpRangeHeaderParser::HasImproperChars( end ) ) return EFalse; } else { aEndPos = KErrNotFound; } return ETrue; }