sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: // System includes sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: //User includes sl@0: #include "UriUtilsInternal.h" sl@0: #include "TValidator.h" sl@0: sl@0: //Constants sl@0: _LIT8(KTransport, "transport"); sl@0: _LIT8(KUser, "user"); sl@0: _LIT8(KMethod, "method"); sl@0: _LIT8(KTtl, "ttl"); sl@0: _LIT8(KMaddr, "maddr"); sl@0: _LIT8(KLr, "lr"); sl@0: _LIT8(KExtension, "ext" ); sl@0: _LIT8(KIsdnSubAddress, "isub" ); sl@0: _LIT8(KContext, "phone-context" ); sl@0: const TInt KMaxHostAddr = 255; sl@0: sl@0: sl@0: /** sl@0: Constructor. sl@0: */ sl@0: TValidatorBase::TValidatorBase(const TUriC8& aUri) sl@0: : iUri(aUri) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Checks the Uri to be valid. sl@0: If there is no valid Host, Port, userinfo, Path, Query or Fragment then the sl@0: return value indicates an appropriate invalid Component. else returns zero, sl@0: which indicates given uri is valid. sl@0: sl@0: @return whether the Uri is Valid by returning zero or appropriate error value sl@0: for Invalid Uri. sl@0: */ sl@0: TInt TValidatorBase::Validate() sl@0: { sl@0: if (!IsValidHost()) sl@0: { sl@0: return KUriUtilsErrInvalidHost; sl@0: } sl@0: sl@0: if (!IsValidPort()) sl@0: { sl@0: return KUriUtilsErrInvalidPort; sl@0: } sl@0: sl@0: if (!IsValidUserInfo()) sl@0: { sl@0: return KUriUtilsErrInvalidUserInfo; sl@0: } sl@0: sl@0: if (!IsValidPath()) sl@0: { sl@0: return KUriUtilsErrInvalidParam; sl@0: } sl@0: sl@0: if (!IsValidQuery()) sl@0: { sl@0: return KUriUtilsErrInvalidHeaders; sl@0: } sl@0: sl@0: if (!IsValidFragment()) sl@0: { sl@0: return KUriUtilsErrInvalidFragment; sl@0: } sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Checks whether the given character is in Valid Set of characters. sl@0: @param aChar A Character needs to be checked against Set of characters. sl@0: @param aCharSet A set of Characters Descriptor. sl@0: @return returns ETrue if aChar is a Valid Character else returns EFalse. sl@0: */ sl@0: TBool TValidatorBase::IsInCharSet(TText8 aChar, const TDesC8& aCharSet) const sl@0: { sl@0: for (TInt i = 0; i < aCharSet.Length(); i++) sl@0: { sl@0: if (aChar == aCharSet[i]) sl@0: { sl@0: return ETrue; sl@0: } sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: /** sl@0: Checks whether the given descriptor is Valid or not. sl@0: @param aDes A Descriptor needs to be checked against Set of characters sl@0: defined in aCharTypes. sl@0: @param aCharTypes A set of Characters Descriptor. sl@0: @param aEscapeValid For the given aCharTypes whether the Escape encoded is valid sl@0: or not while Validating aDes, is specified by setting ETrue or EFalse sl@0: @return returns ETrue if aDes is a Valid descriptor else returns EFalse. sl@0: */ sl@0: TBool TValidatorBase::IsValidCharacters(const TDesC8& aDes, TUint32 aCharTypes, TBool aEscapeValid) const sl@0: { sl@0: TInt len = aDes.Length(); sl@0: for (TInt i=0; i < len; i++) sl@0: { sl@0: TUint8 ch = aDes[i]; sl@0: // check for and decode '%' encoded characters sl@0: if (aEscapeValid && ch == '%') sl@0: { sl@0: TInt hex; sl@0: if (!EscapeUtils::IsEscapeTriple(aDes.Mid(i,3), hex)) sl@0: { sl@0: // not a valid encoding sl@0: return EFalse; sl@0: } sl@0: i += 2; sl@0: continue; sl@0: } sl@0: sl@0: if ((aCharTypes & KCharSetNumber) && (ch >= '0' && ch <= '9')) sl@0: { sl@0: continue; sl@0: } sl@0: if ((aCharTypes & KCharSetLowerAlpha) && (ch >= 'a' && ch <= 'z')) sl@0: { sl@0: continue; sl@0: } sl@0: if ((aCharTypes & KCharSetUpperAlpha) && (ch >= 'A' && ch <= 'Z')) sl@0: { sl@0: continue; sl@0: } sl@0: if ((aCharTypes & KCharSetAlways) && IsInCharSet(ch, KAlwaysValidChars())) sl@0: { sl@0: continue; sl@0: } sl@0: if ((aCharTypes & KCharSetCommon) && IsInCharSet(ch, KCommonValidChars)) sl@0: { sl@0: continue; sl@0: } sl@0: if ((aCharTypes & KCharSetUser) && IsInCharSet(ch, KValidUserChars)) sl@0: { sl@0: continue; sl@0: } sl@0: if ((aCharTypes & KCharSetParam) && IsInCharSet(ch, KValidParamChars)) sl@0: { sl@0: continue; sl@0: } sl@0: if ((aCharTypes & KCharSetHeader) && IsInCharSet(ch, KValidHeaderChars)) sl@0: { sl@0: continue; sl@0: } sl@0: if ((aCharTypes & KCharSetSipMark) && IsInCharSet(ch, KUriAlwaysValidSipMarkChars)) sl@0: { sl@0: continue; sl@0: } sl@0: sl@0: if ((aCharTypes & KCharSetSipPwd) && IsInCharSet(ch, KUriValidSipPwdChars)) sl@0: { sl@0: continue; sl@0: } sl@0: sl@0: if ((aCharTypes & KCharSetSipTkn) && IsInCharSet(ch, KUriValidSipToken)) sl@0: { sl@0: continue; sl@0: } sl@0: sl@0: // character is not valid so exit sl@0: return EFalse; sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: The meaning empty here is that the component is present but it's value is not present sl@0: This occures when the delimeter for a component is in the URI but there is sl@0: nothing in the URI after the delimeter. For example: sl@0: 1. sip:loc.com - a URI with no port sl@0: 2. sip:loc.com: - a URI with a port delimeter but no port value. The port is 'empty'. sl@0: 3. sip:loc.com:1666 - a URI with a port sl@0: sl@0: @param aDes A Descriptor. sl@0: @return ETrue or EFalse. sl@0: */ sl@0: TBool TValidatorBase::IsEmpty(const TDesC8& aDes) const sl@0: { sl@0: TInt len = aDes.Length(); sl@0: const TUint8* ptr = aDes.Ptr(); sl@0: if (!len && ptr) sl@0: { sl@0: // An entry for this item has been created so the delimeter was encountered sl@0: // However, no value has been found. The item is empty sl@0: return ETrue; sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: sl@0: // sl@0: // Implementatin of support for Sip-Uris as specified in RFC 3261. // sl@0: // sl@0: sl@0: /** sl@0: Constructor. sl@0: */ sl@0: TValidatorSip::TValidatorSip(const TUriC8& aUri) sl@0: : TValidatorBase(aUri) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Checks that a Host is in a valid form as specified in RFC 3261. sl@0: sl@0: @return A boolean value of ETrue if uri contains valid Host, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidHost() const sl@0: { sl@0: const TDesC8& host = iUri.Extract(EUriHost); sl@0: if (host.Length() == 0) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: // IPv4 and IPv6 hosts are validated so just check text hosts sl@0: if (UriUtils::HostType(host) == UriUtils::ETextHost && !IsTextHostValid(host)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks that a Port is in a valid form as specified in RFC 3261. sl@0: sl@0: @return A boolean value of ETrue if uri contains valid Port, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidPort() const sl@0: { sl@0: const TDesC8& port = iUri.Extract(EUriPort); sl@0: if (IsEmpty(port)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return IsValidCharacters(port, KCharSetNumber); sl@0: } sl@0: sl@0: /** sl@0: Checks whether Userinfo contains valid characters in the sip-uri as specified in RFC 3261. sl@0: sl@0: @param aUser The descriptor to be checked. sl@0: @return A boolean value of ETrue if uri contains valid Userinfo, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidUser(const TDesC8& aUser) const sl@0: { sl@0: return IsValidCharacters(aUser, KCharSetUserAll, ETrue); sl@0: } sl@0: sl@0: /** sl@0: Checks whether Password contains valid characters in the sip-uri as specified in RFC 3261. sl@0: sl@0: @param aPassword The descriptor to be checked. sl@0: @return A boolean value of ETrue if uri contains valid Password, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidPassword(const TDesC8& aPassword) const sl@0: { sl@0: if (!aPassword.Length()) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return IsValidCharacters(aPassword, KCharSetSipPassWord, ETrue); sl@0: } sl@0: sl@0: /** sl@0: Checks that a UserInfo is in a valid form as specified in RFC 3261. sl@0: sl@0: @return A boolean value of ETrue if uri contains valid UserInfo, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidUserInfo() const sl@0: { sl@0: const TDesC8& userInfo = iUri.Extract(EUriUserinfo); sl@0: sl@0: if (IsEmpty(userInfo)) sl@0: { sl@0: // The '@' UserInfo sparator was found in the URI but no username/password sl@0: // is present sl@0: return EFalse; sl@0: } sl@0: sl@0: TInt separatorPos = userInfo.Locate(KUserPwdSeparator); sl@0: if (separatorPos != KErrNotFound) sl@0: { sl@0: // seperator found so there is a username and password sl@0: // the username is left of the separator sl@0: if (!IsValidUser(userInfo.Left(separatorPos))) sl@0: { sl@0: return EFalse; sl@0: } sl@0: // the password is right of the separator sl@0: return IsValidPassword(userInfo.Right(userInfo.Length() - separatorPos-1)); sl@0: } sl@0: sl@0: // there is no password element sl@0: return IsValidUser(userInfo); sl@0: } sl@0: sl@0: /** sl@0: Checks whether any duplicate parameter names exist in the sl@0: whole path of the sip-uri. sl@0: sl@0: @param aParamName The descriptor to be checked. sl@0: @param aParamList the path/parameter part of uri, which conatians all parameters and values. sl@0: @return A boolean value of ETrue if uri contains duplicate parameters, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsDuplicated(const TDesC8& aParamName, const TDelimitedParserBase8 aParamList) const sl@0: { sl@0: // roll back to the start of the lhs segment parser sl@0: while(aParamList.Dec() != KErrNotFound) sl@0: { sl@0: //Nothing to do sl@0: } sl@0: sl@0: TPtrC8 name; sl@0: TPtrC8 value; sl@0: TPtrC8 segment; sl@0: TInt count = 0; sl@0: while( aParamList.GetNext(segment) == KErrNone ) sl@0: { sl@0: GetNameValuePair(segment, name, value); sl@0: if (aParamName.CompareF(name) == 0) sl@0: { sl@0: count++; sl@0: } sl@0: if (count > 1) sl@0: { sl@0: // The parameter name appears more than once in the paramter list sl@0: return ETrue; sl@0: } sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: /** sl@0: Checks whether parameter contains valid characters in the sip-uri as specified in RFC 3261. sl@0: sl@0: @param aParam The descriptor to be checked. sl@0: @return A boolean value of ETrue if uri contains valid parameter, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidParam(const TDesC8& aParam) const sl@0: { sl@0: return IsValidCharacters(aParam, KCharSetParamAll, ETrue); sl@0: } sl@0: sl@0: /** sl@0: Checks whether ParamSegment contains valid characters in sl@0: Parameter name and Parameter value as specified in RFC 3261. sl@0: sl@0: @param aName The descriptor for parameter name to be checked as per RFC 3261. sl@0: @param aValue The descriptor for value to be checked as per RFC 3261. sl@0: @return A boolean value of ETrue if uri contains valid parameters and values, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidParamSegment(const TDesC8& aName, const TDesC8& aValue) const sl@0: { sl@0: if (!aName.Length() || !IsValidParam(aName) ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: /************************************************************************************************************** sl@0: * As per RFC 3261 if the uri-parameter contains name as Tranport or User or Method then its Value must be * sl@0: * the characters as specified in Token. else if the name is Ttl then its value must lie in between 0 - 255. * sl@0: * else if the name is Maddr then its value must be a host, else if the name is lr then it must not conatin * sl@0: * any value, else it must be a other-parameter whose value must conatin the characters specified in paramchar.* sl@0: * As per INC 115503 and due to IOP issue Validation of lr paramater is not performed. * sl@0: ***************************************************************************************************************/ sl@0: if ( ( (aName.CompareF(KTransport()) == 0 || aName.CompareF(KUser()) == 0 || aName.CompareF(KMethod()) == 0 ) sl@0: && !IsValidParamToken(aValue) ) sl@0: || ( aName.CompareF(KTtl()) == 0 && !IsValidParamTtl(aValue) ) sl@0: || ( aName.CompareF(KMaddr()) == 0 && !IsValidParamMaddr(aValue) ) sl@0: || ( aName.CompareF(KTransport()) != 0 && aName.CompareF(KUser()) != 0 && aName.CompareF(KMethod()) != 0 && aName.CompareF(KTtl()) != 0 sl@0: && aName.CompareF(KMaddr()) != 0 && aName.CompareF(KLr()) != 0 && !IsValidParam(aValue)) sl@0: ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks whether parameters "transport", "User" and "Method" contains valid characters in the sl@0: sip-uri as specified in RFC 3261. sl@0: sl@0: @param aParam The descriptor to be checked. sl@0: @return A boolean value of ETrue if uri contains valid parameter, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidParamToken(const TDesC8& aParam) const sl@0: { sl@0: if (!aParam.Length()) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return IsValidCharacters(aParam, KCharSetSipToken, EFalse); sl@0: } sl@0: sl@0: /** sl@0: Checks whether parameter "ttl" contains valid characters in the sip-uri as specified in RFC 3261. sl@0: sl@0: sl@0: @param aParam The descriptor to be checked. sl@0: @return A boolean value of ETrue if uri contains valid parameter, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidParamTtl(const TDesC8& aParam) const sl@0: { sl@0: if (!aParam.Length() || aParam.Length() > 3 || !IsValidCharacters(aParam, KCharSetNumber, EFalse) ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: TLex8 lex(aParam); sl@0: TInt address = 0; sl@0: lex.Val(address); sl@0: if( address > KMaxHostAddr ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks whether parameter "maddr" contains valid characters in the sip-uri as specified in RFC 3261. sl@0: sl@0: @param aParam The descriptor to be checked. sl@0: @return A boolean value of ETrue if uri contains valid parameter, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidParamMaddr(const TDesC8& aParam) const sl@0: { sl@0: if (!aParam.Length() && UriUtils::HostType(aParam) == UriUtils::ETextHost && !IsTextHostValid(aParam)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks that a Path/uri-parameter is in a valid form as specified in RFC 3261. sl@0: sl@0: @return A boolean value of ETrue if uri contains valid Path/uri-parameter, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidPath() const sl@0: { sl@0: const TDesC8& parameters = iUri.Extract(EUriPath); sl@0: TDelimitedPathSegmentParser8 parser; sl@0: parser.Parse(parameters); sl@0: sl@0: // sip parameters should start with a ';' sl@0: if (parameters.Length() && parameters[0] != ';') sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: TPtrC8 name; sl@0: TPtrC8 value; sl@0: TPtrC8 segment; sl@0: while( parser.GetNext(segment) == KErrNone ) sl@0: { sl@0: GetNameValuePair(segment, name, value); sl@0: if (IsEmpty(value) || IsDuplicated(name, parser) || !IsValidParamSegment(name, value)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: } sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks whether Header contains valid characters as specified in RFC 3261. sl@0: sl@0: @param aHeader The descriptor to be checked as per RFC 3261. sl@0: @return A boolean value of ETrue if uri contains valid Header, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidHeader(const TDesC8& aHeader) const sl@0: { sl@0: return IsValidCharacters(aHeader, KCharSetHeaderAll, ETrue); sl@0: } sl@0: sl@0: /** sl@0: Checks whether HeaderSegment contains valid name and values as specified in RFC 3261. sl@0: sl@0: @param aName The descriptor for Header name to be checked as per RFC 3261. sl@0: @param aValue The descriptor for Header value to be checked as per RFC 3261. sl@0: @return A boolean value of ETrue if uri contains valid Header name and Header values, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidHeaderSegment(const TDesC8& aName, const TDesC8& aValue) const sl@0: { sl@0: if (!aName.Length() || !IsValidHeader(aName) || !IsValidHeader(aValue)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks that a Query/Header is in a valid form as specified in RFC 3261. sl@0: sl@0: @return A boolean value of ETrue if uri contains valid Query/Header, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidQuery() const sl@0: { sl@0: const TDesC8& headers = iUri.Extract(EUriQuery); sl@0: if (IsEmpty(headers)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: TDelimitedQueryParser8 parser; sl@0: parser.Parse(headers); sl@0: sl@0: TPtrC8 name; sl@0: TPtrC8 value; sl@0: TPtrC8 segment; sl@0: while( parser.GetNext(segment) == KErrNone ) sl@0: { sl@0: // must be in the form name=value even if the value part is empty sl@0: if (segment.Locate(KEqualsSeparator) == KErrNotFound) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: GetNameValuePair(segment, name, value); sl@0: if (IsDuplicated(name, parser) || !IsValidHeaderSegment(name, value)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks that a Fragment is in a valid form as specified in RFC 3261. sl@0: Infact, SIP URIs should not contain a fragment. It it contains a sl@0: fragment then it is not a valid fragment. sl@0: sl@0: @return A boolean value of ETrue if uri contains valid Fragment, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorSip::IsValidFragment() const sl@0: { sl@0: const TDesC8& frag = iUri.Extract(EUriFragment); sl@0: if (IsEmpty(frag)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: // SIP URIs should not contain a fragment sl@0: if (frag.Length()) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: sl@0: // sl@0: // Implementatin of partial support for tel-Uris specified in RFC 3966. // sl@0: // Parsing of phone number separators as specified in RFC 3966 // sl@0: // section 5 will not be supported. // sl@0: // The Implementation supports only of the form tel:36789017;isub=1411 // sl@0: // It does not support lexicographical order of parameters for Validation.// sl@0: // sl@0: sl@0: /** sl@0: Constructor. sl@0: @param aUri A reference to a parsed uri object. sl@0: */ sl@0: TValidatorTel::TValidatorTel(const TUriC8& aUri) sl@0: : TValidatorBase(aUri) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Checks whether valid parameter names and values exist in the sl@0: whole path of the tel-uri. sl@0: sl@0: @param aName The descriptor for parameter name to be checked as per RFC3966. sl@0: @param aValue The descriptor for value to be checked as per RFC3966. sl@0: @return A boolean value of ETrue if uri contains valid parameters and values, sl@0: EFalse if it does not. sl@0: */ sl@0: TBool TValidatorTel::IsValidParamSegment(const TDesC8& aName, const TDesC8& aValue) const sl@0: { sl@0: //Validation of the Name sl@0: if (!aName.Length() || !IsValidCharacters(aName, KCharSetParamAll) ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: //Validation of the Value based on ISDN, EXTN, Phone-context or any. sl@0: if( ( KIsdnSubAddress().CompareF(aName) == 0 && !IsValidCharacters(aValue, KCharSetParamAll, ETrue) ) || sl@0: ( KExtension().CompareF(aName) == 0 && !IsValidCharacters(aValue, KCharSetNumber) ) || sl@0: ( KContext().CompareF(aName) == 0 && !IsValidCharacters(aValue, KCharSetParamAll) ) || sl@0: ( KIsdnSubAddress().CompareF(aName) != 0 && sl@0: KExtension().CompareF(aName) != 0 && sl@0: KContext().CompareF(aName) != 0 && sl@0: !IsValidCharacters(aValue, KCharSetParamAll, ETrue) ) ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks whether any duplicate parameter names exist in the sl@0: whole path of the tel-uri, and also checks whether the both ISDN and EXTN sl@0: parameters exist in tel-uri. sl@0: sl@0: @param aParamName The descriptor to be checked. sl@0: @param aParamList the path part of uri, which conatians all parameters and values. sl@0: @return A boolean value of ETrue if uri contains duplicate parameters or sl@0: both isdn and extn parameters exist, EFalse if it does not. sl@0: */ sl@0: TBool TValidatorTel::IsDuplicated(const TDesC8& aParamName, const TDelimitedParserBase8 aParamList) const sl@0: { sl@0: // roll back to the start of the lhs segment parser sl@0: while(aParamList.Dec() != KErrNotFound) sl@0: { sl@0: //do nothing sl@0: } sl@0: aParamList.Inc(); //To exclude phone number from the list. sl@0: sl@0: TPtrC8 name; sl@0: TPtrC8 value; sl@0: TPtrC8 segment; sl@0: TInt count = 0; sl@0: while( aParamList.GetNext(segment) == KErrNone ) sl@0: { sl@0: GetNameValuePair(segment, name, value); sl@0: if (aParamName.CompareF(name) == 0) sl@0: { sl@0: count++; sl@0: } sl@0: if (count > 1) sl@0: { sl@0: // The parameter name appears more than once in the paramter list sl@0: return ETrue; sl@0: } sl@0: if( ( KIsdnSubAddress().CompareF(aParamName) == 0 && KExtension().CompareF(name) == 0 ) || sl@0: ( KExtension().CompareF(aParamName) == 0 && KIsdnSubAddress().CompareF(name) == 0 ) ) sl@0: { sl@0: //Both ISDN and EXTN should not exist in Uri sl@0: return ETrue; sl@0: } sl@0: } sl@0: sl@0: return EFalse; sl@0: } sl@0: sl@0: /** sl@0: Checks that a path is in a valid form sl@0: sl@0: @return ETrue if the path is valid otherwise EFalse sl@0: */ sl@0: TBool TValidatorTel::IsValidPath() const sl@0: { sl@0: const TDesC8& path = iUri.Extract(EUriPath); sl@0: //empty path is invalid sl@0: if(!path.Length()) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: //Implementation of all the steps specified in section 2.5.2.2 sl@0: //Validation of the path components of tel uri sl@0: sl@0: TDelimitedPathSegmentParser8 parser; sl@0: parser.Parse(path); sl@0: sl@0: // tel parameters should start with a '+' or 'digit' sl@0: TChar ch( path[0] ); sl@0: if(! (ch == '+' || ch.IsDigit()) ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: TPtrC8 name; sl@0: TPtrC8 value; sl@0: TPtrC8 segment; sl@0: //First segemnt must be telephone number sl@0: if (parser.GetNext(segment) == KErrNone) sl@0: { sl@0: GetNameValuePair(segment, name, value); sl@0: //contains only digits sl@0: if(!IsValidCharacters(name.Mid(1), KCharSetNumber)) sl@0: { sl@0: return EFalse; sl@0: } sl@0: } sl@0: //Remainig all the segments sl@0: while( parser.GetNext(segment) == KErrNone ) sl@0: { sl@0: GetNameValuePair(segment, name, value); sl@0: if(IsEmpty(segment)) sl@0: { sl@0: return ETrue; sl@0: } sl@0: if ( IsEmpty(value) || IsDuplicated(name, parser) || !IsValidParamSegment(name, value) ) sl@0: { sl@0: return EFalse; sl@0: } sl@0: } sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks that a host is in a valid form sl@0: sl@0: @return ETrue. "tel" uri does not conatin host sl@0: */ sl@0: TBool TValidatorTel::IsValidHost() const sl@0: { sl@0: //do nothing sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks that a UserInfo is in a valid form sl@0: sl@0: @return ETrue. "tel" uri does not conatin UserInfo sl@0: */ sl@0: TBool TValidatorTel::IsValidUserInfo() const sl@0: { sl@0: //do nothing sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks that a Port is in a valid form sl@0: sl@0: @return ETrue. "tel" uri does not conatin Port sl@0: */ sl@0: TBool TValidatorTel::IsValidPort() const sl@0: { sl@0: //do nothing sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks that a Query is in a valid form sl@0: sl@0: @return ETrue. "tel" uri does not conatin Query sl@0: */ sl@0: TBool TValidatorTel::IsValidQuery() const sl@0: { sl@0: //do nothing sl@0: return ETrue; sl@0: } sl@0: sl@0: /** sl@0: Checks that a Fragment is in a valid form sl@0: sl@0: @return ETrue. "tel" uri does not conatin Fragment sl@0: */ sl@0: TBool TValidatorTel::IsValidFragment() const sl@0: { sl@0: //do nothing sl@0: return ETrue; sl@0: } sl@0: