genericservices/httputils/UriParser/TValidator.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Internal classes for PREQ748 - Adding support for the SIP scheme in URIs.
       
    15 // Classes for validating URIs according to their scheme
       
    16 // File contains internal classes for validatin URIs according to
       
    17 // their scheme type
       
    18 // 
       
    19 //
       
    20 
       
    21 /**
       
    22  @file TValidator.h
       
    23  @see Uri8.h
       
    24 */
       
    25 
       
    26 #ifndef __TVALIDATOR_H__
       
    27 #define __TVALIDATOR_H__
       
    28 
       
    29 #include <uri8.h>
       
    30 #include <delimitedparser8.h>
       
    31 
       
    32 // Constants
       
    33 //
       
    34 _LIT8(KAlwaysValidChars, "-_.!~*'");
       
    35 _LIT8(KCommonValidChars, "()/+$");
       
    36 _LIT8(KValidUserChars, "=,;?&");
       
    37 _LIT8(KValidParamChars, "[]:&");
       
    38 _LIT8(KValidHeaderChars, "[]:?");
       
    39 _LIT8(KUriAlwaysValidSipMarkChars, "-_.!~*'()");	
       
    40 _LIT8(KUriValidSipPwdChars, "&=+$,");
       
    41 _LIT8(KUriValidSipToken, "%+`"); 
       
    42 
       
    43 const TUint32 KCharSetNumber 		= 0x001;
       
    44 const TUint32 KCharSetLowerAlpha 	= 0x002;
       
    45 const TUint32 KCharSetUpperAlpha 	= 0x004;
       
    46 const TUint32 KCharSetAlways	 	= 0x008;
       
    47 const TUint32 KCharSetCommon	 	= 0x010;
       
    48 const TUint32 KCharSetUser	 		= 0x020;
       
    49 const TUint32 KCharSetParam		 	= 0x040;
       
    50 const TUint32 KCharSetHeader	 	= 0x080;
       
    51 const TUint32 KCharSetSipMark 		= 0x100;
       
    52 const TUint32 KCharSetSipPwd 		= 0x200;
       
    53 const TUint32 KCharSetSipTkn		= 0x400;
       
    54 const TUint32 KCharSetAlphnumberic	= KCharSetNumber | KCharSetLowerAlpha | KCharSetUpperAlpha;
       
    55 const TUint32 KCharSetUserAll	 	= KCharSetUser | KCharSetAlphnumberic | KCharSetAlways | KCharSetCommon;
       
    56 const TUint32 KCharSetParamAll	 	= KCharSetParam | KCharSetAlphnumberic | KCharSetAlways | KCharSetCommon;
       
    57 const TUint32 KCharSetHeaderAll 	= KCharSetHeader | KCharSetAlphnumberic | KCharSetAlways | KCharSetCommon;
       
    58 const TUint32 KCharSetSipPassWord = KCharSetAlphnumberic| KCharSetSipPwd | KCharSetSipMark ;
       
    59 const TUint32 KCharSetSipToken	= KCharSetAlphnumberic| KCharSetAlways | KCharSetSipTkn;
       
    60 
       
    61 /**
       
    62 	Comments : This class provides Base functionality for Validation of an URI.
       
    63 	which needs to be overridden by derived classes for validation Based on their RFC 
       
    64 	specifications.
       
    65 	
       
    66 	@internalComponent
       
    67 	@released
       
    68 */
       
    69 class TValidatorBase
       
    70 	{
       
    71 public:
       
    72 	TValidatorBase(const TUriC8& aUri);
       
    73 	TInt Validate();
       
    74 
       
    75 protected:
       
    76 	// Implemented by derived validator classes
       
    77 	virtual TBool IsValidUserInfo() const = 0;
       
    78 	virtual TBool IsValidHost() const = 0;
       
    79 	virtual TBool IsValidPort() const = 0;
       
    80 	virtual TBool IsValidPath() const = 0;
       
    81 	virtual TBool IsValidQuery() const = 0;
       
    82 	virtual TBool IsValidFragment() const = 0;
       
    83 
       
    84 	// general utility methods
       
    85 	TBool IsValidCharacters(const TDesC8& aDes, TUint32 aCharTypes, TBool aEscapeValid = EFalse) const;
       
    86 	TBool IsEmpty(const TDesC8& aDes) const;
       
    87 
       
    88 private:
       
    89 	TBool IsInCharSet(TText8 aChar, const TDesC8& aCharSet) const;
       
    90 
       
    91 protected:
       
    92 	const TUriC8& iUri;
       
    93 	};
       
    94 
       
    95 /**
       
    96 Dependencies : TValidatorBase.
       
    97 Comments : This class provides Sip Uri Validation functinality.
       
    98  		   This is implemented as specified in RFC 3261.
       
    99 	
       
   100 	@internalComponent
       
   101 	@released
       
   102 */
       
   103 class TValidatorSip: public TValidatorBase
       
   104 	{
       
   105 public:
       
   106 	TValidatorSip(const TUriC8& aUri);
       
   107 private:
       
   108 	// from TValidatorBase
       
   109 	TBool IsValidUserInfo() const;
       
   110 	TBool IsValidHost() const;
       
   111 	TBool IsValidPort() const;
       
   112 	TBool IsValidPath() const;
       
   113 	TBool IsValidQuery() const;
       
   114 	TBool IsValidFragment() const;
       
   115 
       
   116 	// supporting methods for the above
       
   117 	TBool IsValidUser(const TDesC8& aUser) const;
       
   118 	TBool IsValidPassword(const TDesC8& aPassword) const;
       
   119 	TBool IsDuplicated(const TDesC8& aParamName, const TDelimitedParserBase8 aParamList) const;
       
   120 	TBool IsValidParam(const TDesC8& aParam) const;
       
   121 	TBool IsValidParamSegment(const TDesC8& aName, const TDesC8& aValue) const;
       
   122 	TBool IsValidHeader(const TDesC8& aHeader) const;
       
   123 	TBool IsValidHeaderSegment(const TDesC8& aName, const TDesC8& aValue) const;
       
   124 	TBool IsValidParamToken(const TDesC8& aParam) const;
       
   125 	TBool IsValidParamTtl(const TDesC8& aParam) const;
       
   126 	TBool IsValidParamMaddr(const TDesC8& aParam) const;
       
   127 };
       
   128 
       
   129 /**
       
   130 Dependencies : TValidatorBase.
       
   131 Comments : This class provides Tel Uri Validation functinality.
       
   132  		   Only Partial support for tel-Uris specified in RFC 3966. 
       
   133 		   section 5 of RFC 3966 is not supported.
       
   134 	@internalComponent
       
   135 	@released
       
   136 */
       
   137 class TValidatorTel: public TValidatorBase
       
   138 	{
       
   139 public:
       
   140 	TValidatorTel(const TUriC8& aUri);
       
   141 private:
       
   142 	// from TValidatorBase
       
   143 	TBool IsValidUserInfo() const;
       
   144 	TBool IsValidHost() const;
       
   145 	TBool IsValidPort() const;
       
   146 	TBool IsValidPath() const;
       
   147 	TBool IsValidQuery() const;
       
   148 	TBool IsValidFragment() const;
       
   149 	
       
   150 	// supporting methods for the above
       
   151 	TBool IsDuplicated(const TDesC8& aParamName, const TDelimitedParserBase8 aParamList) const;
       
   152 	TBool IsValidParamSegment(const TDesC8& aName, const TDesC8& aValue) const;
       
   153 };
       
   154 
       
   155 #endif	// __TVALIDATOR_H__