Msrp/MsrpHeader/src/TMSRPHeaderUtil.cpp
author shivsood
Sat, 12 Jun 2010 14:30:11 +0530
branchMSRP_FrameWork
changeset 25 505ad3f0ce5c
permissions -rw-r--r--
MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia. MSRP Implementation as per RFC 4975 and RCS specifications that supports 1. Multiple one to one chat data sessions as per RCS/RFC 4975 specifications. 2. Multiple file Sharing sessions as per RCS. 3. Data Chunking requirements as per 4975. 3. MSRP Connection sharing requirements as per RFC 4975
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
     1
/*
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
     2
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
     3
* All rights reserved.
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
     4
* This component and the accompanying materials are made available
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
     6
* which accompanies this distribution, and is available
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html."
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
     8
* Initial Contributors:
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
     9
* Nokia Corporation - initial contribution.
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    10
* Contributors:
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    11
*
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    12
* Description:
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    13
* MSRP Implementation
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    14
*
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    15
*/
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    16
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    17
// CLASS HEADER
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    18
#include "TMSRPHeaderUtil.h"
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    19
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    20
// INTERNAL INCLUDES
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    21
#include "MsrpCommon.h"
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    22
#include "CMSRPByteRangeHeader.h"
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    23
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    24
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    25
// -----------------------------------------------------------------------------
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    26
// TMSRPHeaderUtil::ConvertToNumberL
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    27
// -----------------------------------------------------------------------------
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    28
//
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    29
TInt TMSRPHeaderUtil::ConvertToNumber( const TDesC8& aString )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    30
    {
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    31
	// checking for special characters:
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    32
	// Unknown byte range end
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    33
	if ( aString == KAsterisk )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    34
		{
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    35
		// Range unknown
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    36
		return KUnknownRange;
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    37
		}
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    38
	TLex8 numberToConvert( aString );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    39
	TInt convertedNumber( 0 );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    40
	numberToConvert.Val( convertedNumber );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    41
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    42
	return convertedNumber;
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    43
	}
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    44
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    45
// -----------------------------------------------------------------------------
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    46
// TMSRPHeaderUtil::AppendStringL
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    47
// -----------------------------------------------------------------------------
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    48
//
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    49
void TMSRPHeaderUtil::AppendStringL( const TDesC8& aString, TDes8& aDest )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    50
	{
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    51
	TInt newLength = aString.Length() + aDest.Length();
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    52
	if ( newLength > aDest.MaxLength() )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    53
		{
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    54
		// not enough room
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    55
		User::Leave( KErrArgument );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    56
		}
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    57
	aDest.Append( aString );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    58
	}
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    59
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    60
// -----------------------------------------------------------------------------
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    61
// TMSRPHeaderUtil::CheckStringValidity
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    62
// -----------------------------------------------------------------------------
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    63
//
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    64
TBool TMSRPHeaderUtil::CheckStringValidity( const TDesC8& aString )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    65
	{
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    66
	if ( !aString.Length() )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    67
		{
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    68
		return EFalse;
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    69
		}
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    70
	
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    71
	// Checks the syntax for the Content-Type string only. May need to extend to other headers as well
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    72
	
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    73
	TChar charToFind( KDividedCharacter );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    74
	TInt matchLoc = aString.Locate( charToFind );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    75
	if( matchLoc == KErrNotFound || matchLoc == (aString.Length() -1) )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    76
	    {
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    77
        return EFalse;
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    78
	    }
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    79
	
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    80
	TPtrC8 typePtr = aString.Left(matchLoc);
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    81
	TLex8 lex( typePtr );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    82
	TChar chr = lex.Get();
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    83
	while ( chr )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    84
		{
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    85
		if ( !chr.IsAlphaDigit() && chr != '!' && chr != '#' && chr != '$' && chr != '%' && chr != '&' &&
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    86
		      chr != '\'' && chr != '*' && chr != '+' && chr != '-' && chr != '.' && chr != '^' && 
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    87
		      chr != '_' && chr != '`' && chr != '{' && chr != '|' && chr != '}' && chr != '~' )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    88
			{
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    89
			return EFalse;
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    90
			}
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    91
		chr = lex.Get();
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    92
		}
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    93
	
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    94
	TPtrC8 subtypePtr = aString.Mid( matchLoc+1 );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    95
	lex.Assign( subtypePtr );
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    96
	chr = lex.Get();
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    97
	while ( chr )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    98
        {
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
    99
        if ( !chr.IsAlphaDigit() && chr != '!' && chr != '#' && chr != '$' && chr != '%' && chr != '&' &&
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   100
              chr != '\'' && chr != '*' && chr != '+' && chr != '-' && chr != '.' && chr != '^' && 
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   101
              chr != '_' && chr != '`' && chr != '{' && chr != '|' && chr != '}' && chr != '~' )
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   102
            {
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   103
            return EFalse;
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   104
            }
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   105
        chr = lex.Get();
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   106
        }
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   107
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   108
	return ETrue;
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   109
	}
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   110
505ad3f0ce5c MSRP Chat and File Sharing FrameWork - Initial Contribution from Nokia.
shivsood
parents:
diff changeset
   111
// End of File