applayerprotocols/httptransportfw/Test/Acceptance/Iter2/trans.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2004-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 //
       
    15 
       
    16 #include <f32file.h>
       
    17 #include <x509cert.h>
       
    18 
       
    19 #include "trans.h"
       
    20 #include <http.h>
       
    21 
       
    22 //For Proxy Info.
       
    23 #include <cdblen.h>
       
    24 #include <cdbcols.h>
       
    25 #include <commsdat.h>
       
    26 #include <comms-infras/dbaccess.h>
       
    27 #include <metadatabase.h>
       
    28 #include <commsdattypesv1_1.h>
       
    29 #include <commsdattypeinfov1_1.h>
       
    30 
       
    31 _LIT(KProxyServerName, 			"10.29.23.12");
       
    32 _LIT(KProtocolName, 			"http");
       
    33 const TInt KPortNumber = 9003;
       
    34 
       
    35 
       
    36 _LIT(KItemName,						"name");
       
    37 
       
    38 // Proxy server set as either a session property or transaction property
       
    39 _LIT(KItemProxy,					"proxy");
       
    40 _LIT(KItemTransactionProxy,			"transactionproxy");  
       
    41 _LIT(KItemProxyPort,					"proxy_port");
       
    42 _LIT(KItemTransactionProxyPort,			"proxy_trans_port");  
       
    43 
       
    44 // Proxy usage at either session or transaction level. Turning off proxy at 
       
    45 // the session level has no effect or the transaction proxy settings and vice 
       
    46 // versa
       
    47 _LIT(KItemProxyUsage,				"proxyUsage");
       
    48 _LIT(KItemTransactionProxyUsage,	"transactionProxyUsage");
       
    49 _LIT8(KItemProxyOff,				"ProxyOff");
       
    50 
       
    51 _LIT(KItemMethod,					"method");
       
    52 _LIT(KItemUri,						"uri");
       
    53 _LIT(KItemUrisch,						"uri_scheme"); //new
       
    54 _LIT(KItemUriport,						"port"); // new
       
    55 _LIT(KItemUripath,						"path");  //new
       
    56 _LIT(KItemBody,						"body");
       
    57 _LIT(KItemBodyFile,					"bodyfile");
       
    58 _LIT(KItemAccept,					"Accept");
       
    59 _LIT(KItemAcceptCharset,			"Accept-Charset");
       
    60 _LIT(KItemAcceptEncoding,			"Accept-Encoding");
       
    61 _LIT(KItemContentType,				"Content-Type");
       
    62 _LIT(KItemContentLength,			"Content-Length");
       
    63 _LIT(KItemExpect,					"Expect");
       
    64 _LIT(KItemExpectedStatusCode,		"test_validation_param_statuscode");
       
    65 _LIT(KItemExpectedError,			"test_validation_param_expectederror");
       
    66 _LIT(KItemTransactionNumber,		"Transaction");
       
    67 _LIT(KItemHeader,					"header");
       
    68 _LIT(KUserName,						"username");
       
    69 _LIT(KPassword,						"password");
       
    70 _LIT(KFrom,							"from");
       
    71 _LIT(KItemRedirectCheck,			"test_validation_param_numredirects");
       
    72 
       
    73 _LIT8(KMethodGet,					"GET");
       
    74 _LIT8(KUriSymbian,					"www.symbian.com");
       
    75 _LIT8(KUrisch,						"http://"); //new
       
    76 
       
    77 _LIT(KItemDefaultProxyUsage,		"defaultProxyUsage");
       
    78 _LIT8(KItemDefaultProxyOn, 			"On");
       
    79 
       
    80 
       
    81 
       
    82 const TDesC& CHttpTestTransactions::TestName()
       
    83 	{
       
    84 	return iTestName;
       
    85 	}
       
    86 
       
    87 CHttpTestTransactions::~CHttpTestTransactions()
       
    88 	{
       
    89 	delete iBody;
       
    90 	}	
       
    91 
       
    92 void CHttpTestTransactions::CloseTestSession()
       
    93 	{
       
    94 	iUsername.Close();
       
    95 	iPassword.Close();
       
    96 	delete iBody;
       
    97 	iBody = NULL;
       
    98 	}
       
    99 
       
   100 // Returns back index of the item in the section that is the end of 
       
   101 // transaction, used to find where transactions are for multiple transactions
       
   102 TInt CHttpTestTransactions::FindEndOfTransaction(TInt aStartItem)
       
   103 	{
       
   104 	TInt count= iIniFile->Section(iSectionNumber).Items().Count();
       
   105 	TInt ii = aStartItem;
       
   106 	for (; ii < count; ++ii)
       
   107 		{
       
   108 		//Start of a new transaction
       
   109 		if (iIniFile->Section(iSectionNumber).Item(ii).Item().CompareF(
       
   110 			KItemTransactionNumber) == 0)
       
   111 			{
       
   112 			return ii -1;
       
   113 			}
       
   114 		}
       
   115 	// Got to end of section;
       
   116 	return ii;
       
   117 	}
       
   118 
       
   119 HBufC8* CHttpTestTransactions::FindItemLC(const TDesC& aItem, TInt aStart, TInt aEnd, const TDesC8 aDefault)
       
   120 	{
       
   121 	for (TInt ii = aStart; ii< aEnd; ++ii)
       
   122 		{
       
   123 		if (iIniFile->Section(iSectionNumber).Item(ii).Item().CompareF(aItem) == 0)
       
   124 			{
       
   125 			TPtrC valuePtr(iIniFile->Section(iSectionNumber).Item(ii).Value());
       
   126 			HBufC8* value8 = HBufC8::NewLC(valuePtr.Length());
       
   127 			TPtr8  valuePtr8= value8->Des();
       
   128 			valuePtr8.Copy(valuePtr);
       
   129 			return value8;
       
   130 			}
       
   131 		}
       
   132 	return aDefault.AllocLC();
       
   133 	}
       
   134 
       
   135 RHTTPTransaction CHttpTestTransactions::CreateTransactionL(TInt aStartItem)
       
   136 	{
       
   137 	TInt endItem= FindEndOfTransaction(aStartItem);
       
   138 	
       
   139 	// Get the method
       
   140 	HBufC8* method = FindItemLC(KItemMethod,aStartItem,endItem, KMethodGet);
       
   141 	TPtr8  methodPtr8= method->Des();
       
   142 
       
   143 	// Get the uri value
       
   144 	HBufC8* urisch = FindItemLC(KItemUrisch, aStartItem,endItem, KUrisch);
       
   145 	HBufC8* uriport = FindItemLC(KItemUriport, aStartItem,endItem, KNullDesC8);
       
   146 	HBufC8* uripath = FindItemLC(KItemUripath, aStartItem,endItem, KNullDesC8);
       
   147 
       
   148 	HBufC8* uri = FindItemLC(KItemUri, aStartItem,endItem, KUriSymbian);
       
   149 	TPtr8  uritempPtr8= uri->Des();
       
   150 
       
   151 	HBufC8* newtempUri8 = TSrvAddrVal::ReplaceHostNameL(uritempPtr8, iIniSettingsFile);
       
   152 	CleanupStack::PushL(newtempUri8);
       
   153 	TPtr8 Bufsch(urisch->Des());
       
   154 	TPtr8 Bufuri=newtempUri8->Des();
       
   155 	TPtr8 Bufport(uriport->Des());
       
   156 	TPtr8 Bufpath=uripath->Des();
       
   157 	TInt len;
       
   158 
       
   159 	len=Bufsch.Size()+Bufuri.Size()+Bufport.Size()+Bufpath.Size()+1;
       
   160 	//HBufC8* newUri8;
       
   161 	HBufC8* newUri8=HBufC8::NewL(len);
       
   162 	CleanupStack::PushL(newUri8);
       
   163 	TPtr8 newUriPtr8(newUri8->Des());
       
   164 
       
   165 	if (uritempPtr8.Find(_L8("http://"))==KErrNotFound) 
       
   166 	{
       
   167 		newUriPtr8.Copy(Bufsch);
       
   168 		newUriPtr8.Append(Bufuri);
       
   169 		if(Bufport.Size()>0) 
       
   170 		{
       
   171 			newUriPtr8.Append(_L8(":"));  //add ":" before the port number
       
   172 		}
       
   173 		newUriPtr8.Append(Bufport);
       
   174 		newUriPtr8.Append(Bufpath);
       
   175 	}
       
   176 	else
       
   177 	{
       
   178 		newUriPtr8.Copy(uritempPtr8); // Compatible with old uri format
       
   179 
       
   180 	}
       
   181 // 
       
   182 	TUriParser8 testUri;
       
   183 		testUri.Parse(newUriPtr8);
       
   184 
       
   185 	//open a  transaction and log it
       
   186 	RHTTPTransaction transaction = iSession.OpenTransactionL(testUri, *this, iMyStrP.OpenFStringL(*method));
       
   187 	iOpenTransactionCount++;
       
   188 	TSrvAddrVal::LogUsing8BitDesL(iEngine, _L8("Transaction Created:\t method "));
       
   189 	TSrvAddrVal::LogUsing8BitDesL(iEngine, methodPtr8);
       
   190 	TSrvAddrVal::LogUsing8BitDesL(iEngine, _L8("Transaction Created:\t URI "));
       
   191 	TSrvAddrVal::LogUsing8BitDesL(iEngine, newUriPtr8);
       
   192 	iEngine->Utils().LogIt(_L("Transaction Created in Session"));
       
   193 
       
   194 	//Get a handle of the request and its headers in iTransaction
       
   195 	RHTTPRequest myRequest = transaction.Request();
       
   196 	RHTTPHeaders myHeaders = myRequest.GetHeaderCollection();
       
   197 	
       
   198 	TBool allowTransactionProxySetting = ETrue;
       
   199 	// check for transaction proxy support first
       
   200 	HBufC8* proxyUsage = FindItemLC(KItemTransactionProxyUsage,aStartItem, endItem,KNullDesC8);
       
   201 	if (proxyUsage->Length() > 0 && proxyUsage->CompareF(KItemProxyOff) == 0)
       
   202 		{	
       
   203 		RHTTPTransactionPropertySet transactionProperties = transaction.PropertySet();
       
   204 		RStringPool strP = iSession.StringPool();
       
   205 		
       
   206 		THTTPHdrVal proxyUsage(strP.StringF(HTTP::EDoNotUseProxy, RHTTPSession::GetTable()));
       
   207 		transactionProperties.SetPropertyL(strP.StringF(HTTP::EProxyUsage, RHTTPSession::GetTable()), proxyUsage);
       
   208 				
       
   209 		allowTransactionProxySetting = EFalse;
       
   210 		}
       
   211 		
       
   212 	CleanupStack::PopAndDestroy(proxyUsage);
       
   213 
       
   214 
       
   215 	for (TInt ii = aStartItem; ii<endItem; ++ii)
       
   216 		{
       
   217 		TPtrC itemPtr(iIniFile->Section(iSectionNumber).Item(ii).Item());
       
   218 		HBufC8* itemBuff8 = HBufC8::NewLC(itemPtr.Length());
       
   219 		TPtr8  itemPtr8= itemBuff8->Des();
       
   220 		itemPtr8.Copy(itemPtr);
       
   221 		RStringF item=iMyStrP.OpenFStringL(itemPtr8);
       
   222 		CleanupClosePushL ( item );
       
   223 
       
   224 		TPtrC valuePtr(iIniFile->Section(iSectionNumber).Item(ii).Value());
       
   225 		HBufC8* valueBuff8 = HBufC8::NewLC(valuePtr.Length());
       
   226 		TPtr8 valuePtr8= valueBuff8->Des();
       
   227 		valuePtr8.Copy(valuePtr);
       
   228 		RStringF value =iMyStrP.OpenFStringL(valuePtr8);
       
   229 		CleanupClosePushL ( value );
       
   230 	
       
   231 		if (itemPtr.CompareF(KItemHeader)==0)
       
   232 			DoHeaderL(myHeaders,*valueBuff8);
       
   233 		else if (itemPtr.CompareF(KUserName)==0)
       
   234 			iUsername= iMyStrP.OpenStringL(valuePtr8);
       
   235 		else if (itemPtr.CompareF(KPassword)==0)
       
   236 			iPassword= iMyStrP.OpenStringL(valuePtr8);
       
   237 		else if (itemPtr.CompareF(KItemExpect) == 0 &&
       
   238 					valuePtr.CompareF(_L("100-continue"))==0)
       
   239 						myHeaders.SetFieldL(item, value);
       
   240 		else if (itemPtr.CompareF(KFrom) == 0)
       
   241 			myHeaders.SetFieldL(item, value);
       
   242 
       
   243 
       
   244 		else if (itemPtr.CompareF(KItemContentType)==0)
       
   245 			myHeaders.SetFieldL(item, value);
       
   246 		else if (itemPtr.CompareF(KItemContentLength)==0)	
       
   247 			{
       
   248 			//convert content-length to TInt
       
   249 			TLex lex(valuePtr);
       
   250 			TInt length = 0;
       
   251 			lex.Val(length);
       
   252 			myHeaders.SetFieldL(item, length);
       
   253 			}
       
   254 		else if (itemPtr.CompareF(KItemAccept)==0)
       
   255 			CreateAcceptStringL(myHeaders);
       
   256 		else if (itemPtr.CompareF(KItemAcceptCharset)==0)
       
   257 			CreateAcceptCharsetStringL(myHeaders);
       
   258 		else if (itemPtr.CompareF(KItemAcceptEncoding)==0)
       
   259 			CreateAcceptEncodingStringL(myHeaders);
       
   260 		else if (itemPtr.CompareF(KItemBody)==0)
       
   261 			{
       
   262 			iBody= (*valueBuff8).AllocL();
       
   263 			myRequest.SetBody(*this );
       
   264 			}
       
   265 		else if (itemPtr.CompareF(KItemBodyFile)==0)
       
   266 			{
       
   267 			LoadBodyFromFileL(valuePtr);
       
   268 			myRequest.SetBody(*this );
       
   269 			}
       
   270 		else if (itemPtr.CompareF(KItemExpectedStatusCode)==0)
       
   271 			{
       
   272 			//get the 'test_validation_param_statuscode' from the ini file...
       
   273 			TPtrC expectedStatusCodePtr = iIniFile->Section(iSectionNumber).ItemL(KItemExpectedStatusCode).Value();
       
   274 			TLex statusCodeLex(expectedStatusCodePtr);
       
   275 			TInt statuscode;
       
   276 			statusCodeLex.Val(statuscode);
       
   277 			// ...and put it  into iExpectedStatusCode
       
   278 			iExpectedStatusCode = statuscode;
       
   279 			}	
       
   280 		else if (itemPtr.CompareF(KItemExpectedError)==0)
       
   281 			{
       
   282 			//get the 'test_validation_param_expectederror' from the 
       
   283 			//ini file...
       
   284 			TPtrC expectedParamPtr = iIniFile->Section(iSectionNumber).ItemL(KItemExpectedError).Value();
       
   285 			TLex paramLex(expectedParamPtr);
       
   286 			TInt param;
       
   287 			paramLex.Val(param);
       
   288 			// ...and put it  into iExpectedError
       
   289 			iExpectedError = param;
       
   290 			}
       
   291 		else if (itemPtr.CompareF(KItemTransactionProxy)==0 && 
       
   292 			allowTransactionProxySetting)
       
   293 			// set proxy settings on transaction
       
   294 			{
       
   295 			// Get the proxy value
       
   296 			TPtrC proxyPtr16 = iIniFile->Section(iSectionNumber).ItemL(KItemTransactionProxy).Value();
       
   297 			// Get the proxy port
       
   298 			HBufC8* Transactionport = FindItemLC(KItemTransactionProxyPort,aStartItem,endItem, KNullDesC8); // new
       
   299 			TPtr8  TransactionportPtr8= Transactionport->Des();
       
   300 
       
   301 			HBufC16* proxyUrl16 = TSrvAddrVal::ReplaceHostNameL(proxyPtr16, iIniSettingsFile);
       
   302 			CleanupStack::PushL(proxyUrl16);
       
   303 			TPtr16 proxyUrlPtr16 = proxyUrl16->Des();
       
   304 			if (TransactionportPtr8.Length())
       
   305 			{			
       
   306 				len=proxyUrlPtr16.Length() + TransactionportPtr8.Length() +1;
       
   307 			}
       
   308 			else
       
   309 				len=proxyUrlPtr16.Length();
       
   310 
       
   311 			// Converting proxyUrl16 to 8 bit
       
   312 			HBufC8* proxyUrl8 = HBufC8::NewLC(len);
       
   313 			TPtr8 proxyUrlPtr8 = proxyUrl8->Des();
       
   314 			proxyUrlPtr8.Copy(proxyUrlPtr16);
       
   315 			if (TransactionportPtr8.Length())
       
   316 			{
       
   317 				proxyUrlPtr8.Append(_L(":"));
       
   318 				proxyUrlPtr8.Append(TransactionportPtr8);
       
   319 			}
       
   320 
       
   321 			if (proxyPtr16.Length() > 0)
       
   322 				{
       
   323 				RHTTPTransactionPropertySet transactionProperties = transaction.PropertySet();
       
   324 				RStringPool strP = iSession.StringPool();
       
   325 				RStringF proxyAddr = strP.OpenFStringL(proxyUrlPtr8);
       
   326 				CleanupClosePushL(proxyAddr);
       
   327 				THTTPHdrVal proxyUsage(strP.StringF(HTTP::EUseProxy, RHTTPSession::GetTable()));
       
   328 				transactionProperties.SetPropertyL(strP.StringF(HTTP::EProxyUsage,RHTTPSession::GetTable()), proxyUsage);
       
   329 				transactionProperties.SetPropertyL(strP.StringF(HTTP::EProxyAddress,RHTTPSession::GetTable()), proxyAddr);
       
   330 				CleanupStack::PopAndDestroy(1,&proxyAddr);
       
   331 				}
       
   332 			CleanupStack::PopAndDestroy(3, Transactionport);// and proxyUrl16, proxyUrl8
       
   333 			}
       
   334 	
       
   335 		CleanupStack::PopAndDestroy ( 2 ); // item, value
       
   336 		CleanupStack::PopAndDestroy(2);// valueBuff8, itemBuff8
       
   337 		}
       
   338 	
       
   339 	CleanupStack::PopAndDestroy(7, method); // Urisch,Uriport, Utipath, uri, newtempUri8, newUri
       
   340 
       
   341 
       
   342 
       
   343 
       
   344 	return transaction;
       
   345 	}
       
   346 
       
   347 void CHttpTestTransactions::ConstructL(CScriptFile& aIniFile, CScriptFile* aIniSettingsFile, const TInt aSectionNumber)
       
   348 	{
       
   349 	iUsernameUsed = EFalse;
       
   350 	iIniFile =&aIniFile;
       
   351 	iIniSettingsFile = aIniSettingsFile;
       
   352 	iSectionNumber=aSectionNumber;
       
   353 	//get the 'Name' section item 
       
   354 	iTestName.Append(iIniFile->Section(iSectionNumber).ItemL(KItemName).Value());
       
   355 
       
   356 	_LIT(KLogCert, "LogCert");
       
   357 	if(aIniFile.Section(aSectionNumber).Item(KLogCert) != NULL)
       
   358 		iLogCert = ETrue;
       
   359 	}
       
   360 
       
   361 TBool CHttpTestTransactions::GetNextDataPart(TPtrC8& aDataChunk)
       
   362 	{
       
   363 	//add a body 
       
   364 	aDataChunk.Set(*iBody);
       
   365 	return ETrue;
       
   366 	}
       
   367 
       
   368 void CHttpTestTransactions::ReleaseData() 
       
   369 	{
       
   370 	}
       
   371 	
       
   372 TInt CHttpTestTransactions::OverallDataSize()
       
   373 	{
       
   374 	return iBody->Length();
       
   375 	}
       
   376 
       
   377 // aHeader will be in the format field:value
       
   378 void CHttpTestTransactions::DoHeaderL(RHTTPHeaders aRequestHeaders, const TDesC8& aHeader)
       
   379 	{
       
   380 	// get the field
       
   381 	TInt colonPos = aHeader.Locate(':');
       
   382 	if (colonPos == KErrNotFound)
       
   383 		return;
       
   384 
       
   385 	RStringF field = iMyStrP.OpenFStringL(aHeader.Left(colonPos));
       
   386 	CleanupClosePushL(field);
       
   387 	TPtrC8 value8 = aHeader.Mid(colonPos+1, aHeader.Length() - (colonPos+1));
       
   388 
       
   389 	RStringF value = iMyStrP.OpenFStringL(value8);
       
   390 	CleanupClosePushL(value);
       
   391 
       
   392 	aRequestHeaders.SetFieldL(field,value);
       
   393 	CleanupStack::PopAndDestroy(2, &field); // and value
       
   394 	}
       
   395 
       
   396 
       
   397 void CHttpTestTransactions::CreateAcceptStringL(RHTTPHeaders aRequestHeaders)
       
   398 	{
       
   399 	// parse the accept header
       
   400 	TLex input(iIniFile->Section(iSectionNumber).ItemL(KItemAccept).Value());
       
   401 	TPtrC accept;
       
   402 
       
   403 	// go through all the accept values and add to the header
       
   404 	// 
       
   405 	while (CScriptFile::GetNextWord(input, ',', accept) == KErrNone)
       
   406 		{
       
   407 		// There may be parameters that will have to be store along with the 
       
   408 		// accept value Accept: text/plain, text/html; q=0.8, 
       
   409 		TPtrC paramPtr(accept);
       
   410 		if (paramPtr.Locate(';') != KErrNotFound)
       
   411 			{
       
   412 			// extra parameter exists and this needs to be stored
       
   413 			TLex param(paramPtr);
       
   414 			
       
   415 			// skip any leading whitespace
       
   416 			param.SkipSpaceAndMark();
       
   417 
       
   418 			// anything upto the semicolon (;) is the normal value
       
   419 			while (param.Peek() != ';')
       
   420 				param.Inc();
       
   421 			TPtrC acceptVal = param.MarkedToken();
       
   422 
       
   423 			// skip over the semicolon (;)
       
   424 			param.Inc();
       
   425 
       
   426 			// skip any leading whitespace
       
   427 			param.SkipSpaceAndMark();
       
   428 
       
   429 			// anything upto the equal sign (=) is the parameter name
       
   430 			while (param.Peek() != '=')
       
   431 				param.Inc();
       
   432 			param.MarkedToken();  // qParam should be  'q'
       
   433 			// skip over the equals sign (=)
       
   434 			param.Inc();
       
   435 
       
   436 			// skip any leading whitespace
       
   437 			param.SkipSpaceAndMark();
       
   438 			TPtrC qParamVal=param.Remainder(); // qParamVal is the value of q
       
   439 
       
   440 			// store each value in the header class
       
   441 			HBufC8*  acceptValBuff8= HBufC8::NewLC(acceptVal.Length());
       
   442 			TPtr8 acceptVal8= acceptValBuff8->Des();
       
   443 			acceptVal8.Copy(acceptVal);
       
   444 			RStringF acceptStr= iMyStrP.OpenFStringL(acceptVal8);
       
   445 			CleanupClosePushL(acceptStr);
       
   446 			THTTPHdrVal acceptHdr(acceptStr);
       
   447 			// store each Q-value in the header class
       
   448 			HBufC8*  qParamValBuff8= HBufC8::NewLC(qParamVal.Length());
       
   449 			TPtr8 qParamVal8= qParamValBuff8->Des();
       
   450 			qParamVal8.Copy(qParamVal);
       
   451 			TLex8 str(qParamVal8);
       
   452 			TReal qReal=0;
       
   453 			str.Val(qReal);
       
   454 			THTTPHdrVal::TQConv qVal(qReal);
       
   455 			THTTPHdrVal qHdr(qVal);
       
   456 			aRequestHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()), acceptHdr, iMyStrP.OpenFStringL(_L8("q")), qHdr);
       
   457 
       
   458 			CleanupStack::PopAndDestroy(3, acceptValBuff8); // and acceptStr, qParamValBuff8
       
   459 			}
       
   460 		else
       
   461 			{
       
   462 			TPtrC acceptVal = accept;
       
   463 
       
   464 			// store each value in the header class
       
   465 			TBuf8<1000> acceptVal8;
       
   466 			acceptVal8.Copy(acceptVal);
       
   467 
       
   468 			RStringF accept= iMyStrP.OpenFStringL(acceptVal8);
       
   469 			CleanupClosePushL ( accept );
       
   470 			THTTPHdrVal acceptHdr(accept);
       
   471 			aRequestHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAccept, RHTTPSession::GetTable()),acceptHdr);
       
   472 			CleanupStack::PopAndDestroy ( &accept );
       
   473 			}
       
   474 		}
       
   475 	}
       
   476 
       
   477 void CHttpTestTransactions::CreateAcceptCharsetStringL(RHTTPHeaders aRequestHeaders)
       
   478 	{
       
   479 	// parse the accept header
       
   480 	TLex input(iIniFile->Section(iSectionNumber).ItemL(KItemAcceptCharset).Value());
       
   481 	TPtrC accept;
       
   482 	
       
   483 	// go through all the accept values and add to the header
       
   484 	// 
       
   485 	while (CScriptFile::GetNextWord(input, ',', accept) == KErrNone)
       
   486 		{
       
   487 		// There may be parameters that will have to be store along with the 
       
   488 		// accept value Accept: text/plain, text/html; q=0.8, 
       
   489 		TPtrC paramPtr(accept);
       
   490 		if (paramPtr.Locate(';') != KErrNotFound)
       
   491 			{
       
   492 			// extra parameter exists and this needs to be stored
       
   493 			TLex param(paramPtr);
       
   494 			
       
   495 			// skip any leading whitespace
       
   496 			param.SkipSpaceAndMark();
       
   497 
       
   498 			// anything upto the semicolon (;) is the normal value
       
   499 			while (param.Peek() != ';')
       
   500 				param.Inc();
       
   501 			TPtrC acceptVal = param.MarkedToken();
       
   502 
       
   503 			// skip over the semicolon (;)
       
   504 			param.Inc();
       
   505 
       
   506 			// skip any leading whitespace
       
   507 			param.SkipSpaceAndMark();
       
   508 
       
   509 			// anything upto the equal sign (=) is the parameter name
       
   510 			while (param.Peek() != '=')
       
   511 				param.Inc();
       
   512 			param.MarkedToken();
       
   513 
       
   514 			// skip over the equals sign (=)
       
   515 			param.Inc();
       
   516 
       
   517 			// skip any leading whitespace
       
   518 			param.SkipSpaceAndMark();
       
   519 			param.Remainder();
       
   520 
       
   521 			// store each value in the header class
       
   522 			HBufC8*  acceptValBuff8= HBufC8::NewLC(acceptVal.Length());
       
   523 			TPtr8 acceptVal8= acceptValBuff8->Des();
       
   524 			acceptVal8.Copy(acceptVal);
       
   525 
       
   526 			RStringF acceptStr= iMyStrP.OpenFStringL(acceptVal8);
       
   527 			CleanupClosePushL(acceptStr);
       
   528 			THTTPHdrVal acceptHdr(acceptStr);
       
   529 			
       
   530 			aRequestHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAcceptCharset, RHTTPSession::GetTable()),acceptHdr);
       
   531 			CleanupStack::PopAndDestroy(2, acceptValBuff8); // and acceptStr
       
   532 			}
       
   533 		else
       
   534 			{
       
   535 			TPtrC acceptVal = accept;
       
   536 
       
   537 			// store each value in the header class
       
   538 			TBuf8<1000> acceptVal8;
       
   539 			acceptVal8.Copy(acceptVal);
       
   540 			RStringF accept= iMyStrP.OpenFStringL(acceptVal8);
       
   541 			CleanupClosePushL ( accept );
       
   542 			THTTPHdrVal acceptHdr(accept);
       
   543 			aRequestHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAcceptCharset, RHTTPSession::GetTable()),acceptHdr);
       
   544 			CleanupStack::PopAndDestroy ( &accept );
       
   545 			}
       
   546 		}
       
   547 	}
       
   548 
       
   549 
       
   550 void CHttpTestTransactions::CreateAcceptEncodingStringL(RHTTPHeaders aRequestHeaders)
       
   551 	{
       
   552 	// parse the accept header
       
   553 	TLex input(iIniFile->Section(iSectionNumber).ItemL(KItemAcceptEncoding).Value());
       
   554 	TPtrC accept;
       
   555 	
       
   556 	// go through all the accept values and add to the header
       
   557 	// 
       
   558 	while (CScriptFile::GetNextWord(input, ',', accept) == KErrNone)
       
   559 		{
       
   560 		// There may be parameters that will have to be store along with the 
       
   561 		// accept value Accept: text/plain, text/html; q=0.8, 
       
   562 		TPtrC paramPtr(accept);
       
   563 		if (paramPtr.Locate(';') != KErrNotFound)
       
   564 			{
       
   565 			// extra parameter exists and this needs to be stored
       
   566 			TLex param(paramPtr);
       
   567 			
       
   568 			// skip any leading whitespace
       
   569 			param.SkipSpaceAndMark();
       
   570 
       
   571 			// anything upto the semicolon (;) is the normal value
       
   572 			while (param.Peek() != ';')
       
   573 				param.Inc();
       
   574 			TPtrC acceptVal = param.MarkedToken();
       
   575 
       
   576 			// skip over the semicolon (;)
       
   577 			param.Inc();
       
   578 
       
   579 			// skip any leading whitespace
       
   580 			param.SkipSpaceAndMark();
       
   581 
       
   582 			// anything upto the equal sign (=) is the parameter name
       
   583 			while (param.Peek() != '=')
       
   584 				param.Inc();
       
   585 			param.MarkedToken();
       
   586 
       
   587 			// skip over the equals sign (=)
       
   588 			param.Inc();
       
   589 
       
   590 			// skip any leading whitespace
       
   591 			param.SkipSpaceAndMark();
       
   592 			param.Remainder();
       
   593 
       
   594 			// store each value in the header class
       
   595 			HBufC8*  acceptValBuff8= HBufC8::NewLC(acceptVal.Length());
       
   596 			TPtr8 acceptVal8= acceptValBuff8->Des();
       
   597 			acceptVal8.Copy(acceptVal);
       
   598 
       
   599 			RStringF acceptStr= iMyStrP.OpenFStringL(acceptVal8);
       
   600 			CleanupClosePushL(acceptStr);
       
   601 			THTTPHdrVal acceptHdr(acceptStr);
       
   602 			
       
   603 			aRequestHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAcceptEncoding, RHTTPSession::GetTable()),acceptHdr);
       
   604 			CleanupStack::PopAndDestroy(2, acceptValBuff8); // and acceptStr
       
   605 			}
       
   606 		else
       
   607 			{
       
   608 			TPtrC acceptVal = accept;
       
   609 
       
   610 			// store each value in the header class
       
   611 			TBuf8<1000> acceptVal8;
       
   612 			acceptVal8.Copy(acceptVal);
       
   613 			RStringF accept= iMyStrP.OpenFStringL(acceptVal8);
       
   614 			CleanupClosePushL ( accept );
       
   615 			THTTPHdrVal acceptHdr(accept);
       
   616 			aRequestHeaders.SetFieldL(iMyStrP.StringF(HTTP::EAcceptEncoding, RHTTPSession::GetTable()),acceptHdr);
       
   617 			CleanupStack::PopAndDestroy ( &accept );
       
   618 			}
       
   619 		}
       
   620 	}
       
   621 
       
   622 
       
   623 TBool CHttpTestTransactions::GetCredentialsL(const TUriC8& aURI, RString aRealm, RStringF aAuthenticationType, RString& aUsername, RString& aPassword)
       
   624 	{
       
   625 	if (!iUsernameUsed && !(((RStringTokenBase) iUsername).IsNull()) && !(((RStringTokenBase) iPassword).IsNull()) )
       
   626 		{
       
   627 		iEngine->Utils().LogIt(_L("Supplying credentials"));
       
   628 		iEngine->Utils().DumpData(aURI.UriDes());
       
   629 		iEngine->Utils().DumpData(aRealm.DesC());	
       
   630 		iEngine->Utils().DumpData(aAuthenticationType.DesC());
       
   631 		aUsername= iUsername.Copy();
       
   632 		aPassword= iPassword.Copy();
       
   633 		iUsernameUsed = ETrue;
       
   634 		return ETrue;
       
   635 		}
       
   636 	else
       
   637 		return EFalse;
       
   638 	}
       
   639 
       
   640 
       
   641 TReal CHttpTestTransactions::StrToReal(TPtr8 aStrToConvToReal)
       
   642 	{
       
   643 	// this function parses a real number of the type r = a.b
       
   644 	// and  creates the correspondent real number 'result'
       
   645 	TLex8 str(aStrToConvToReal);
       
   646 	TReal result=0;
       
   647 
       
   648 	// A is the part of the string before the point
       
   649 	str.Mark();
       
   650 	while (str.Peek() != '.')
       
   651 		{
       
   652 		if(str.Peek() > 48 ||  str.Peek() < 57 )
       
   653 			{
       
   654 			str.Val(result) ;
       
   655 			str.Inc();
       
   656 			}
       
   657 		}
       
   658 	return result;
       
   659 	}
       
   660 
       
   661 void CHttpTestTransactions::SetProxyL(TInt aStartItem)
       
   662 	{
       
   663 	TInt endItem= FindEndOfTransaction(aStartItem);
       
   664 	
       
   665 	// Check to see if proxies have been disabled at the session level
       
   666 	HBufC8* proxyUsage = FindItemLC(KItemProxyUsage,aStartItem,endItem, KNullDesC8);
       
   667 	if (proxyUsage->Length() > 0 && proxyUsage->CompareF(KItemProxyOff) == 0)
       
   668 		{
       
   669 		CleanupStack::PopAndDestroy(1, proxyUsage);
       
   670 		return; // don't use a proxy so kip setting it
       
   671 		}
       
   672 	
       
   673 		// Check to see if proxy type was default/defined for the session.
       
   674 	HBufC8* proxyType = FindItemLC(KItemDefaultProxyUsage, aStartItem, endItem, KNullDesC8);
       
   675  if(proxyType->Length() > 0)
       
   676 		{
       
   677 		if (proxyType->CompareF(KItemDefaultProxyOn) == 0)
       
   678 			{//Use default Proxy.
       
   679 			CleanupStack::PopAndDestroy(2, proxyUsage);//and proxyType
       
   680 				
       
   681 			iEngine->Utils().LogIt(_L("Create Default Proxy in DB and Set it"));
       
   682 			//Delete Proxy if found in Ced file. 
       
   683 			TRAPD(cedErr, ConfigureDefaultProxyL(EDelete));
       
   684 			//Create Default Proxy in CommsDat.
       
   685 			TRAP(cedErr, ConfigureDefaultProxyL(ECreate));			
       
   686 			#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
   687 			iSession.SetupDefaultProxyFromCommsDatL();
       
   688 			#endif	//SYMBIAN_ENABLE_SPLIT_HEADERS
       
   689 			//Delete the Default Proxy stored in CommsDat.
       
   690 			TRAP(cedErr, ConfigureDefaultProxyL(EDelete));
       
   691 			}
       
   692 		else
       
   693 			{
       
   694 			CleanupStack::PopAndDestroy(2, proxyUsage);//and proxyType
       
   695 			//Donot make Use of any type of Proxy.
       
   696 			}
       
   697 		}
       
   698 	else
       
   699 		{	
       
   700 
       
   701 		// Get the proxy if there is one and set it on the session
       
   702 		HBufC8* proxy = FindItemLC(KItemProxy,aStartItem,endItem, KNullDesC8);
       
   703 		TPtr8 proxyAddrPtr8 = proxy->Des();
       
   704 		HBufC8* proxyport = FindItemLC(KItemProxyPort,aStartItem,endItem, KNullDesC8); //new
       
   705 		TPtr8 proxyportPtr8 = proxyport->Des();
       
   706 
       
   707 	HBufC8* proxyAddrUrl8 = TSrvAddrVal::ReplaceHostNameL(proxyAddrPtr8, iIniSettingsFile);
       
   708 		CleanupStack::PushL(proxyAddrUrl8);
       
   709 		TPtr8 proxyUrlAddrPtr8 = proxyAddrUrl8->Des();
       
   710 		TInt len;
       
   711 		if(proxyportPtr8.Size()) 
       
   712 			{
       
   713 			len= proxyUrlAddrPtr8.Size() + proxyportPtr8.Size()+1;
       
   714 			}
       
   715 		else
       
   716 			len= proxyUrlAddrPtr8.Size();
       
   717 
       
   718       HBufC8* proxyUrl8 = HBufC8::NewL(len);  //new
       
   719 	  CleanupStack::PushL(proxyUrl8);
       
   720 		TPtr8 proxyUrlPtr8(proxyUrl8->Des());
       
   721 		proxyUrlPtr8.Copy(proxyUrlAddrPtr8);
       
   722 		if(proxyportPtr8.Size()>0)
       
   723 			{
       
   724 			proxyUrlPtr8.Append(_L8(":"));
       
   725 			proxyUrlPtr8.Append(proxyportPtr8);
       
   726 			}
       
   727 		
       
   728 		if (proxy->Length() > 0)
       
   729 			{
       
   730 			RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
       
   731 			RStringPool strP = iSession.StringPool();
       
   732 			RStringF proxyAddr = strP.OpenFStringL(proxyUrlPtr8);
       
   733 			CleanupClosePushL(proxyAddr);
       
   734 			THTTPHdrVal proxyUsage(strP.StringF(HTTP::EUseProxy, RHTTPSession::GetTable()));
       
   735 			connInfo.SetPropertyL(strP.StringF(HTTP::EProxyUsage, RHTTPSession::GetTable()), proxyUsage);
       
   736 			connInfo.SetPropertyL(strP.StringF(HTTP::EProxyAddress, RHTTPSession::GetTable()), proxyAddr);
       
   737 			CleanupStack::PopAndDestroy(1,&proxyAddr);
       
   738 			}
       
   739 		CleanupStack::PopAndDestroy(6, proxyUsage); // and proxyType, proxy, proxyport, proxyAddrUrl8, proxyUrl8
       
   740 
       
   741 		}
       
   742 	
       
   743 	}
       
   744 
       
   745 void CHttpTestTransactions::SetMaxRedirectsL(TInt aStartItem)
       
   746 	{
       
   747 	TInt endItem= FindEndOfTransaction(aStartItem);
       
   748 	HBufC8* maxRedirectsText = FindItemLC(KItemRedirectCheck,aStartItem, endItem, KNullDesC8);
       
   749 	if (maxRedirectsText && maxRedirectsText->Length() > 0)
       
   750 		{
       
   751 		TLex8 paramLex(*maxRedirectsText);
       
   752 		TInt param;
       
   753 		paramLex.Val(param);
       
   754 		iExpectedNumberRedirects = param;
       
   755 		RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
       
   756 		RStringPool p=iSession.StringPool();
       
   757 		connInfo.SetPropertyL(p.StringF(HTTP::EMaxRedirect, RHTTPSession::GetTable()),THTTPHdrVal(iExpectedNumberRedirects));
       
   758 		}
       
   759 	CleanupStack::PopAndDestroy(maxRedirectsText);
       
   760 	}
       
   761 
       
   762 void CHttpTestTransactions::LogCertificateL(TCertInfo aCertInfo)
       
   763 	{
       
   764 	TBuf<20> fingerprint;
       
   765 	fingerprint.Copy(aCertInfo.iFingerprint);
       
   766 	TBuf<64> subjectName;
       
   767 	subjectName.Copy(aCertInfo.iSubjectDNInfo.iCommonName);
       
   768 	TBuf<64> issuerName;
       
   769 	issuerName.Copy(aCertInfo.iIssuerDNInfo.iCommonName);
       
   770 	TBuf<32> serialNo;
       
   771 	const TInt serLength = aCertInfo.iSerialNo.Length();
       
   772 	for(TInt index = 0; index < serLength; ++index)
       
   773 		{
       
   774 		serialNo.AppendFormat(_L("%02x"), aCertInfo.iSerialNo[index]);
       
   775 		}
       
   776 	serialNo.UpperCase();
       
   777 
       
   778 	// Log certificate data
       
   779 	iEngine->Utils().LogIt(_L("--Server Certificate:"));
       
   780 	iEngine->Utils().LogIt(_L("-----------------------------------"));
       
   781 	iEngine->Utils().LogIt(_L("--Subject:     %S"), &subjectName);
       
   782 	iEngine->Utils().LogIt(_L("--Issuer:      %S"), &issuerName);
       
   783 	iEngine->Utils().LogIt(_L("--Version:     %d"), aCertInfo.iVersionNo);
       
   784 	iEngine->Utils().LogIt(_L("--Serial No:   %S"), &serialNo);
       
   785 	iEngine->Utils().LogIt(_L("--Fingerprint: %S"), &fingerprint);
       
   786 	iEngine->Utils().LogIt(_L("--Digest:	  %d"), aCertInfo.iDigAlg );
       
   787 	
       
   788 	_LIT(KDateFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S.%C%:3");
       
   789 	TBuf<40> dateTimeString;
       
   790 	aCertInfo.iStartValDate.FormatL(dateTimeString, KDateFormat);
       
   791 	iEngine->Utils().LogIt(_L("--Start Date:  %S"), &dateTimeString);
       
   792 	aCertInfo.iEndValDate.FormatL(dateTimeString, KDateFormat);
       
   793 	iEngine->Utils().LogIt(_L("--End Date:    %S"), &dateTimeString);
       
   794 	iEngine->Utils().LogIt(_L("-----------------------------------"));
       
   795 	}
       
   796 
       
   797 void CHttpTestTransactions::LogCertificateL(const CX509Certificate* aCertInfo)
       
   798 	{
       
   799 	HBufC* issuerName = aCertInfo->IssuerL();
       
   800 	HBufC* subjectName = aCertInfo->SubjectL();
       
   801 
       
   802 	// Log certificate data
       
   803 	iEngine->Utils().LogIt(_L("--X905 Server Certificate:"));
       
   804 	iEngine->Utils().LogIt(_L("-----------------------------------"));
       
   805 	iEngine->Utils().LogIt(_L("-----------------------------------"));
       
   806 
       
   807 
       
   808 	CleanupStack::PopAndDestroy(2, issuerName);
       
   809 	}
       
   810 
       
   811 
       
   812 void CHttpTestTransactions::LoadBodyFromFileL(const TDesC& aFilePath)
       
   813 	{
       
   814 	RFs fileSession;
       
   815 	User::LeaveIfError(fileSession.Connect());
       
   816 	CleanupClosePushL(fileSession);
       
   817 	
       
   818 	RFile bodyFile;
       
   819 	TInt err = bodyFile.Open(fileSession, aFilePath, EFileRead & EFileShareReadersOnly);
       
   820 	if( err==KErrNotFound || err==KErrPathNotFound)
       
   821 		{
       
   822 		// Try and resolve the file location as it may reside on another drive
       
   823 		TParse fileName;
       
   824 		fileName.Set(aFilePath, NULL, NULL);
       
   825 		TPtrC resolvedFile;
       
   826 		if(fileName.DrivePresent())
       
   827 			{
       
   828 			// Drive is present, so strip the drive letter off
       
   829 			resolvedFile.Set(aFilePath.Mid(2));
       
   830 			}
       
   831 		else
       
   832 			{
       
   833 			resolvedFile.Set(aFilePath);
       
   834 			}
       
   835 			
       
   836 		// file finder will look in the session drive first, then Y->A,Z
       
   837 		// so set session drive to Y (save old and restore it afterwards)
       
   838 		TFileName* savedPath = new TFileName;
       
   839 		fileSession.SessionPath(*savedPath);
       
   840 		
       
   841 		_LIT(KTopDrive,"Y:\\");
       
   842 		fileSession.SetSessionPath(KTopDrive);
       
   843 		TFindFile fileFinder(fileSession);
       
   844     	err = fileFinder.FindByDir(resolvedFile,KNullDesC);
       
   845 		if(err==KErrNone)
       
   846 			{
       
   847 			fileName.Set(fileFinder.File(),NULL,NULL);
       
   848 			err = bodyFile.Open(fileSession, fileName.FullName(), EFileRead & EFileShareReadersOnly);
       
   849 			}
       
   850 			
       
   851 		// Revert back to the original session path
       
   852 		fileSession.SetSessionPath(*savedPath);
       
   853 
       
   854 		delete savedPath;
       
   855 		}
       
   856 
       
   857 	User::LeaveIfError(err);
       
   858 	CleanupClosePushL(bodyFile);
       
   859 	
       
   860 	delete iBody;
       
   861 	iBody = NULL;
       
   862 	
       
   863 	TInt fileSize = 0;
       
   864 	User::LeaveIfError(bodyFile.Size(fileSize));
       
   865 	iBody = HBufC8::NewL(fileSize);
       
   866 	TPtr8 buffer = iBody->Des();
       
   867 	User::LeaveIfError(bodyFile.Read(buffer));
       
   868 	
       
   869 	CleanupStack::PopAndDestroy(2, &fileSession);
       
   870 	}
       
   871 
       
   872 //Creates a Default Proxy in CommsDat database for use by the build machine.
       
   873 //Once all test cases were executed, deletes the Proxy record that was successfully created.
       
   874 void CHttpTestTransactions::ConfigureDefaultProxyL(TConfigureProxyAction aAction)
       
   875 	{		
       
   876 	TInt32 defaultIapId = 0;
       
   877 	TUint32 serviceId = 0;
       
   878 	TBuf<KCommsDbSvrMaxFieldLength> serviceType;
       
   879 	TBuf<KCommsDbSvrMaxFieldLength> protName;
       
   880 	TBuf<KCommsDbSvrMaxFieldLength> serverName;
       
   881 	
       
   882 	// use commsDat API
       
   883  	// Create CommmsDat session using latest version of commsdat
       
   884 	CMDBSession* dbSession = CMDBSession::NewLC(CMDBSession::LatestVersion());
       
   885 	
       
   886 	//Read Default IAP inorder to get its service Id and type.	
       
   887 	//Default IAP is the one in "connection preferences" table and with a "rank" of 1.
       
   888 	CCDConnectionPrefsRecord *connPrefRecord = static_cast<CCDConnectionPrefsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord));
       
   889     CleanupStack::PushL(connPrefRecord);   
       
   890 
       
   891     // Set the direction of connection
       
   892     connPrefRecord->iDirection = ECommDbConnectionDirectionOutgoing;
       
   893     connPrefRecord->iRanking = 1;
       
   894     
       
   895     if(!connPrefRecord->FindL(*dbSession))
       
   896         {
       
   897         User::Leave(KErrNotFound);      
       
   898         }           
       
   899     defaultIapId = connPrefRecord->iDefaultIAP;
       
   900     iEngine->Utils().LogIt(_L("Default IAP value %d"), defaultIapId);
       
   901 	//Done with Connection Preference Table, Destroy it.
       
   902 	CleanupStack::PopAndDestroy	(connPrefRecord);
       
   903 	
       
   904 	//Got the default IAP id which was its record id in IAP table.
       
   905 	//Get the Service ID and Serivce type of this IAP.
       
   906 	CCDIAPRecord* defaultIapRecord = static_cast<CCDIAPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord));
       
   907 	CleanupStack::PushL(defaultIapRecord);
       
   908 	
       
   909 	//Set the ID.
       
   910 	defaultIapRecord->SetRecordId (defaultIapId);
       
   911 	//Load the record.
       
   912 	defaultIapRecord->LoadL(*dbSession);
       
   913 	//read its serice id and service type.	
       
   914 	serviceId = defaultIapRecord->iService;		
       
   915 	serviceType.Copy(defaultIapRecord->iServiceType);
       
   916 	//Done with IAP Record read, Destroy it.
       
   917 	CleanupStack::PopAndDestroy(defaultIapRecord);	
       
   918 	iEngine->Utils().LogIt(_L("Default ServiceID:%d;ServiceType:%S"), serviceId, &serviceType);
       
   919 	// Now we've got serviceId and serviceType,
       
   920 
       
   921  	if (aAction == ECreate)
       
   922 		{// Create proxy record for this Service ID and service Type	
       
   923 		CCDProxiesRecord* pProxyRecord = static_cast<CCDProxiesRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdProxiesRecord));
       
   924 		CleanupStack::PushL(pProxyRecord);
       
   925 
       
   926 		pProxyRecord->iServiceType.SetMaxLengthL(serviceType.Length());
       
   927 		pProxyRecord->iServiceType = serviceType;
       
   928 	
       
   929 		pProxyRecord->iService = serviceId;
       
   930 		pProxyRecord->iUseProxyServer = ETrue;
       
   931 	
       
   932 		serverName.Copy(KProxyServerName);
       
   933 		pProxyRecord->iServerName.SetMaxLengthL(serverName.Length());
       
   934 		pProxyRecord->iServerName = serverName;
       
   935 	
       
   936 		protName.Copy(KProtocolName);
       
   937 		pProxyRecord->iProtocolName.SetMaxLengthL(protName.Length());
       
   938 		pProxyRecord->iProtocolName = protName;
       
   939 	
       
   940 		pProxyRecord->iPortNumber = KPortNumber;	
       
   941 		pProxyRecord->SetRecordId(KCDNewRecordRequest);
       
   942 	
       
   943 		TRAPD(storeErr,	dbSession->OpenTransactionL());
       
   944 		TRAP(storeErr, pProxyRecord->StoreL(*dbSession));
       
   945 		iEngine->Utils().LogIt(_L("Created New Default Proxy:%S, at Port:%d"), &serverName, KPortNumber);
       
   946 		TRAP(storeErr,	dbSession->CommitTransactionL());			
       
   947 		
       
   948 		CleanupStack::PopAndDestroy(pProxyRecord);
       
   949 		}
       
   950 	else if (aAction == EDelete)
       
   951 		{// Delete proxy record for this Service ID and service Type that was created earlier by us		
       
   952 		CMDBRecordSet<CCDProxiesRecord>* pProxiesRecordSet = new (ELeave)CMDBRecordSet<CCDProxiesRecord>(KCDTIdProxiesRecord);
       
   953 		CleanupStack::PushL(pProxiesRecordSet);
       
   954 
       
   955 		CCDProxiesRecord* primingProxyRecord = static_cast <CCDProxiesRecord*> (CCDRecordBase::RecordFactoryL(KCDTIdProxiesRecord));
       
   956 		CleanupStack::PushL(primingProxyRecord);
       
   957 		// build priming record for the search
       
   958 		primingProxyRecord->iServiceType.SetMaxLengthL(serviceType.Length());
       
   959 		primingProxyRecord->iServiceType = serviceType;
       
   960 	
       
   961 		primingProxyRecord->iService = serviceId;
       
   962 		primingProxyRecord->iUseProxyServer = ETrue;
       
   963 	
       
   964 		pProxiesRecordSet->iRecords.AppendL(primingProxyRecord);
       
   965 		CleanupStack::Pop(primingProxyRecord);
       
   966 	
       
   967 		iEngine->Utils().LogIt(_L("Searching for this Default Proxy"));	
       
   968 		
       
   969 		// Search for the priming record		
       
   970 		if (pProxiesRecordSet->FindL(*dbSession))
       
   971 			{//If exists Delete it
       
   972 			serverName.Copy(primingProxyRecord->iServerName);
       
   973 			TUint32 proxyPort = primingProxyRecord->iPortNumber;
       
   974 			iEngine->Utils().LogIt(_L("Found Default Proxy Record:%S at port%d"), &serverName, proxyPort);
       
   975 			TRAPD(deleteErr, dbSession->OpenTransactionL());
       
   976 
       
   977 			TRAP(deleteErr, primingProxyRecord->DeleteL(*dbSession));
       
   978 			iEngine->Utils().LogIt(_L("Deleted Default Proxy"));	
       
   979 			
       
   980 			TRAP(deleteErr, dbSession->CommitTransactionL());
       
   981 			}
       
   982 			
       
   983 		CleanupStack::PopAndDestroy(pProxiesRecordSet);
       
   984 		}
       
   985      CleanupStack::PopAndDestroy(dbSession);
       
   986 	}