realtimenetprots/sipfw/ProfileAgent/Profile/Src/sipprofileparameter.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2002-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 // Name        : sipprofileparameter
       
    15 // Part of     : SIP Profile
       
    16 // implementation
       
    17 // Version     : 1.0
       
    18 // INCLUDE FILES
       
    19 //
       
    20 
       
    21 
       
    22 
       
    23 #include "sipprofileparameter.h"
       
    24 
       
    25 // ============================ MEMBER FUNCTIONS ===============================
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CSIPProfileParameter::NewL
       
    29 // Two-phased constructor.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CSIPProfileParameter* CSIPProfileParameter::NewL(
       
    33     const TDesC8& aKey,
       
    34     const TDesC8& aValue)
       
    35 	{
       
    36 	CSIPProfileParameter* self = CSIPProfileParameter::NewLC(aKey, aValue);
       
    37 	CleanupStack::Pop(self);
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CSIPProfileParameter::NewLC
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CSIPProfileParameter* CSIPProfileParameter::NewLC(
       
    47     const TDesC8& aKey,
       
    48     const TDesC8& aValue)
       
    49 	{
       
    50 	CSIPProfileParameter* self = new (ELeave) CSIPProfileParameter();
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL(aKey, aValue);
       
    53 	return self;
       
    54 	}
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CSIPProfileParameter::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CSIPProfileParameter* CSIPProfileParameter::NewL(const TDesC8& aKey)
       
    62 	{
       
    63 	CSIPProfileParameter* self = CSIPProfileParameter::NewLC(aKey);
       
    64 	CleanupStack::Pop(self);
       
    65 	return self;
       
    66 	}
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CSIPProfileParameter::NewLC
       
    70 // Two-phased constructor.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CSIPProfileParameter* CSIPProfileParameter::NewLC(const TDesC8& aKey)
       
    74 	{
       
    75 	CSIPProfileParameter* self = new (ELeave) CSIPProfileParameter();
       
    76 	CleanupStack::PushL(self);
       
    77 	self->ConstructL(aKey);
       
    78 	return self;
       
    79 	}
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CSIPProfileParameter::~CSIPProfileParameter
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CSIPProfileParameter::~CSIPProfileParameter()
       
    86 	{
       
    87 	delete iParameterKey;
       
    88 	iParameterKey = 0;
       
    89 	delete iParameterValue;
       
    90 	iParameterValue = 0;
       
    91 	delete iEmpty;
       
    92 	iEmpty = 0;
       
    93 	}
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CSIPProfileParameter::Key
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 const TDesC8& CSIPProfileParameter::Key() const
       
   100 	{
       
   101 	return *iParameterKey;
       
   102 	}
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CSIPProfileParameter::ValueL
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 const TDesC8& CSIPProfileParameter::ValueL() const
       
   109 	{
       
   110 	__ASSERT_ALWAYS (iParameterValue != 0, User::Leave (KErrNotFound));
       
   111 	return *iParameterValue;
       
   112 	}
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CSIPProfileParameter::Value
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 const TDesC8& CSIPProfileParameter::Value() const
       
   119 	{
       
   120 	if (iParameterValue)
       
   121 		{
       
   122 		return *iParameterValue;
       
   123 		}
       
   124 	else
       
   125 		{
       
   126 		return *iEmpty;
       
   127 		}
       
   128 	}
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // CSIPProfileParameter::InternalizeL
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 CSIPProfileParameter* CSIPProfileParameter::InternalizeL(
       
   135     RReadStream& aReadStream)
       
   136 	{
       
   137 	CSIPProfileParameter* self = new (ELeave) CSIPProfileParameter();
       
   138 	CleanupStack::PushL(self);
       
   139 	self->DoInternalizeL (aReadStream);
       
   140 	CleanupStack::Pop(self);
       
   141 	return self;
       
   142 	}
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CSIPProfileParameter::ExternalizeL
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CSIPProfileParameter::ExternalizeL(RWriteStream& aWriteStream) const
       
   149 	{
       
   150 	__ASSERT_ALWAYS (iParameterKey != 0, User::Leave (KErrArgument));
       
   151 	__ASSERT_ALWAYS (iParameterValue != 0, User::Leave (KErrArgument));
       
   152 
       
   153 	aWriteStream.WriteInt32L(iParameterKey->Length());
       
   154 	aWriteStream.WriteL(*iParameterKey);
       
   155 	aWriteStream.WriteInt32L(iParameterValue->Length());
       
   156 	aWriteStream.WriteL(*iParameterValue);
       
   157 	}
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CSIPProfileParameter::ExternalizedSizeL
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 TUint CSIPProfileParameter::ExternalizedSizeL() const
       
   164 	{
       
   165 	__ASSERT_ALWAYS (iParameterKey != 0, User::Leave (KErrArgument));
       
   166 	__ASSERT_ALWAYS (iParameterValue != 0, User::Leave (KErrArgument));
       
   167 
       
   168 	TUint size = 8;
       
   169 	size = size + iParameterKey->Length();
       
   170 	size = size + iParameterValue->Length();
       
   171 
       
   172 	return size;
       
   173 	}
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CSIPProfileParameter::operator==
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 TBool CSIPProfileParameter::operator==(
       
   180     const CSIPProfileParameter& aParameter) const 
       
   181 	{
       
   182 	if (iParameterKey->Compare(aParameter.Key()) != 0)
       
   183 		{
       
   184 		return EFalse;
       
   185 		}
       
   186 
       
   187 	if (iParameterValue != 0)
       
   188 		{
       
   189 		if (iParameterValue->Compare(aParameter.Value()) != 0)
       
   190 			{
       
   191 			return EFalse;
       
   192 			}
       
   193 		}
       
   194 	else
       
   195 		{
       
   196 		if (aParameter.Value().Length() > 0)
       
   197 			{
       
   198 			return EFalse;
       
   199 			}
       
   200 		}
       
   201 	return ETrue;
       
   202     }
       
   203 
       
   204 // -----------------------------------------------------------------------------
       
   205 // CSIPProfileParameter::ConstructL
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void CSIPProfileParameter::ConstructL(const TDesC8& aKey, const TDesC8& aValue)
       
   209 	{
       
   210 	iEmpty = HBufC8::NewL(0);
       
   211 	iParameterKey = aKey.AllocL();
       
   212 	iParameterKey->Des().Trim();
       
   213 	if (iParameterKey->Length() == 0) User::Leave(KErrArgument);
       
   214 
       
   215 	iParameterValue = aValue.AllocL();
       
   216 	iParameterValue->Des().Trim();
       
   217 	}
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CSIPProfileParameter::ConstructL
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 void CSIPProfileParameter::ConstructL(const TDesC8& aKey)
       
   224 	{
       
   225 	iEmpty = HBufC8::NewL(0);
       
   226 	iParameterKey = aKey.AllocL();
       
   227 	iParameterKey->Des().Trim();
       
   228 	if (iParameterKey->Length() == 0) User::Leave(KErrArgument);
       
   229 	}
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CSIPProfileParameter::CSIPProfileParameter
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 CSIPProfileParameter::CSIPProfileParameter()
       
   236 	{
       
   237 	}
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CSIPProfileParameter::DoInternalizeL
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 void CSIPProfileParameter::DoInternalizeL(RReadStream& aReadStream)
       
   244 	{
       
   245 	TInt32 keyLength = aReadStream.ReadInt32L();
       
   246 	__ASSERT_ALWAYS (keyLength >= 0, User::Leave (KErrCorrupt));
       
   247 	__ASSERT_ALWAYS (keyLength < KMaxTInt/2, User::Leave (KErrCorrupt));
       
   248 	iParameterKey = HBufC8::NewL (keyLength);
       
   249 	TPtr8 key(iParameterKey->Des());
       
   250 	aReadStream.ReadL (key, keyLength);
       
   251 
       
   252 	TInt32 valueLength = aReadStream.ReadInt32L();
       
   253 	__ASSERT_ALWAYS (valueLength >= 0, User::Leave (KErrCorrupt));
       
   254 	__ASSERT_ALWAYS (valueLength < KMaxTInt/2, User::Leave (KErrCorrupt));
       
   255 	iParameterValue = HBufC8::NewL (valueLength);
       
   256 	TPtr8 value(iParameterValue->Des());
       
   257 	aReadStream.ReadL (value, valueLength);
       
   258 	}