syncmlfw/common/alertqueue/src/NSmlDSAlertParser12.cpp
changeset 0 b497e44ab2fc
child 25 b183ec05bd8c
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Parser for SyncML 1.2 formatted alert message
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ecom.h>
       
    20 #include <barsread.h>
       
    21 #include <barsc.h>
       
    22 #include <s32mem.h>
       
    23 #include <NSmlDSTypesRes.rsg>
       
    24 #include <data_caging_path_literals.hrh> 
       
    25 
       
    26 #include <nsmlconstants.h>
       
    27 #include <nsmldsconstants.h>
       
    28 #include "NSmlAlertQueue.h"
       
    29 #include "nsmldssettings.h"
       
    30 #include "nsmldshostclient.h"
       
    31 #include <nsmldebug.h>
       
    32 
       
    33 //Fix to Remove the Bad Compiler Warnings
       
    34 #ifndef __WINS__
       
    35 // This lowers the unnecessary compiler warning (armv5) to remark.
       
    36 // "Warning:  #174-D: expression has no effect..." is caused by 
       
    37 // DBG_ARGS8 macro in no-debug builds.
       
    38 #pragma diag_remark 174
       
    39 #endif
       
    40 
       
    41 // ---------------------------------------------------------
       
    42 // CNSmlDSAlertParser12(CSmlAlertInfo& aAlertInfo, CSyncMLHistoryPushMsg& aHistoryInfo )
       
    43 // Returns pointer to the buffer
       
    44 // ---------------------------------------------------------
       
    45 //
       
    46 CNSmlDSAlertParser12::CNSmlDSAlertParser12( CSmlAlertInfo& aAlertInfo, CSyncMLHistoryPushMsg& aHistoryInfo )
       
    47 : CNSmlMessageParserBase( aAlertInfo, aHistoryInfo )
       
    48 	{
       
    49 	_DBG_FILE("CNSmlDSAlertParser12::CNSmlDSAlertParser12");
       
    50 	}
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // CNSmlDSAlertParser12::~CNSmlDSAlertParser12()
       
    54 // Destructor
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 CNSmlDSAlertParser12::~CNSmlDSAlertParser12()
       
    58 	{
       
    59 	_DBG_FILE("CNSmlDSAlertParser12::~CNSmlDSAlertParser12");
       
    60 	}
       
    61 	
       
    62 // ---------------------------------------------------------
       
    63 // CNSmlDSAlertParser12::ParseMessageL()
       
    64 // Parses the aler message
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 void CNSmlDSAlertParser12::ParseMessageL()
       
    68 	{
       
    69 	_DBG_FILE("CNSmlDSAlertParser12::ParseMessageL : Begin");
       
    70 	CheckLengthL( KNSmlAlertVersionPos + 1 );
       
    71 		
       
    72 	iHistoryInfo.SetMsgDigest( Message().Left( KNSmlAlertVersionPos ) );
       
    73 	
       
    74 	// version
       
    75 	TInt version;
       
    76 	version = ((TUint8) Message()[ KNSmlAlertVersionPos ]) << 8;
       
    77 	version |= (TUint8) Message()[ KNSmlAlertVersionPos + 1 ];
       
    78 	version = version >> 6;
       
    79 	
       
    80 	// ui interaction mode
       
    81 	TInt uiMode = (TUint8) Message()[ KNSmlAlertVersionPos + 1 ] & KUiModeMask; 
       
    82 	uiMode = uiMode >> 4;
       
    83 	
       
    84 	if (uiMode == 0)
       
    85 		{
       
    86 		uiMode = CSmlAlertInfo::ECreateJob;
       
    87 		}
       
    88 	iAlertInfo.SetJobControl( (CSmlAlertInfo::TJobControl) uiMode );
       
    89 	
       
    90 	// initiator
       
    91 	TInt initiator = (TUint8) Message()[ KNSmlAlertVersionPos + 1 ] & KInitiatorMask; 
       
    92 	initiator = initiator >> 3;
       
    93 	
       
    94 	// reserved
       
    95 	TInt futNum = (TUint8) Message()[KNSmlAlertVersionPos + 1] & KMaskUpperFuture;
       
    96 	
       
    97 	// session id
       
    98 	CheckLengthL( KNSmlAlertSession + 1 );
       
    99 	TInt sessionId;
       
   100 	sessionId = ((TUint8) Message()[ KNSmlAlertSession ]) << 8;
       
   101 	sessionId |= (TUint8) Message()[ KNSmlAlertSession + 1 ];
       
   102 	iAlertInfo.SetSessionId( sessionId );
       
   103 	
       
   104 	CheckLengthL( KNSmlAlertServerIdLength );
       
   105 	// server id length
       
   106 	TInt serverIdLength;
       
   107 	serverIdLength = (TUint8) Message()[ KNSmlAlertServerIdLength ];
       
   108 	
       
   109 	CheckLengthL( KNSmlAlertServerIdLenPos + serverIdLength );
       
   110 
       
   111 	// server id
       
   112 	HBufC8* hostAddress = HBufC8::NewLC( serverIdLength );
       
   113 	hostAddress->Des().Copy( Message().Mid(KNSmlAlertServerIdLenPos, serverIdLength));
       
   114 
       
   115 	// Try to find profile before accessing content types
       
   116 	SearchProfileL( *hostAddress );
       
   117 #ifdef __NSML_DEBUG__
       
   118 	TPtrC8 pn( hostAddress->Des() );
       
   119 	DBG_ARGS8(_S8("CNSmlDSAlertParser12::ParseMessageL: hostAddress %S"), &pn);
       
   120 #endif // __NSML_DEBUG__
       
   121 
       
   122 	if ( iFoundProfiles.Count() == 0 )
       
   123 		{
       
   124 		iAlertInfo.SetProfileId( KNSmlNullId );
       
   125 		User::Leave( KErrNotFound );
       
   126 		}
       
   127 		
       
   128 	CleanupStack::PopAndDestroy(); // hostAddress
       
   129 
       
   130 	// number of syncs
       
   131 	TInt numSyncs = (TUint8) Message()[ KNSmlAlertServerIdLenPos + serverIdLength] >> 4;
       
   132 	
       
   133 	// reserved for future
       
   134 	(TUint8) Message()[ KNSmlAlertServerIdLenPos + serverIdLength] & KFutureMask;
       
   135 	
       
   136 	TInt firstBytePlace = KNSmlAlertServerIdLenPos + serverIdLength + 1;
       
   137 	
       
   138 	if ( numSyncs )
       
   139 		{
       
   140 		TInt syncType;
       
   141 		TInt contentType;
       
   142 	//	TBuf8<KNSmlBufLength> syncTypeString;
       
   143 	//	TBuf8<KNSmlBufLength> contentTypeString;
       
   144 		
       
   145 		for (TInt i=0; i<numSyncs; i++)
       
   146 			{
       
   147 			// synctype
       
   148 			syncType = (TUint8) Message()[firstBytePlace] >> 4;
       
   149 			ValidateSyncType( syncType );
       
   150 			
       
   151 			// future use
       
   152 			(TUint8) Message()[firstBytePlace] & KFutureMask;
       
   153 			
       
   154 			// content type
       
   155 			contentType = (TUint8) Message()[firstBytePlace + 2] << 8;
       
   156 #ifdef __NSML_DEBUG__
       
   157 	DBG_ARGS(_S("CNSmlDSAlertParser12::ParseMessageL: Before bitwise or:  '%d'"), contentType );
       
   158 #endif // __NSML_DEBUG__
       
   159 			contentType |= (TUint8) Message()[firstBytePlace + 3];
       
   160 
       
   161 			// server uri length
       
   162 			TInt dbPathLength = (TUint8) Message()[firstBytePlace + 4];
       
   163 			
       
   164 			// server uri
       
   165 			HBufC8* databaseURI = HBufC8::NewLC( dbPathLength );
       
   166 			
       
   167 			databaseURI->Des().Copy( Message().Mid(firstBytePlace + KNSmlDatabasePathStartPos, dbPathLength ));
       
   168 #ifdef __NSML_DEBUG__ 
       
   169 	// writting little late
       
   170 	DBG_ARGS(_S("CNSmlDSAlertParser12::ParseMessageL: After bitwise or : '%d'"), contentType );
       
   171 #endif // __NSML_DEBUG__			
       
   172 			if ( syncType != -1 )
       
   173 				{
       
   174 				for (TInt profileCount = 0; profileCount < iFoundProfiles.Count(); profileCount++)
       
   175 					{
       
   176 					MatchContentTypeL( *databaseURI, contentType, (TSmlSyncType) syncType, profileCount);
       
   177 					}
       
   178 				}
       
   179 			
       
   180 			// find the start of the next content type in message
       
   181 			// start + position of database path + length of database path
       
   182 			firstBytePlace = firstBytePlace + KNSmlDatabasePathStartPos + dbPathLength;
       
   183 			
       
   184 			CleanupStack::PopAndDestroy(); // databaseURI
       
   185 			}
       
   186 		}
       
   187 	
       
   188 	// vendor-info
       
   189 	HBufC8* vendorInfo = HBufC8::NewLC( Message().Length() - firstBytePlace );
       
   190 	vendorInfo->Des().Copy( Message().Mid( firstBytePlace, Message().Length() - firstBytePlace ));
       
   191 	iAlertInfo.SetVendorSpecificInfoL( vendorInfo->Des() );
       
   192 	CleanupStack::PopAndDestroy(); // vendorInfo
       
   193 	
       
   194 	// Resolve the profile to use
       
   195 	ResolveProfileL( numSyncs );
       
   196 	_DBG_FILE("CNSmlDSAlertParser12::ParseMessageL : Ends");
       
   197 	}
       
   198 
       
   199 // ---------------------------------------------------------
       
   200 // CNSmlDSAlertParser12::ValidateSyncType( TInt aSyncType )
       
   201 // Changes the server sync type to synchronization initiation sync type
       
   202 // ---------------------------------------------------------
       
   203 //
       
   204 void CNSmlDSAlertParser12::ValidateSyncType( TInt& aSyncType )
       
   205 	{
       
   206 	switch ( KNSmlServerAlertCode + aSyncType )
       
   207 		{
       
   208 		
       
   209 		case KNSmlServerAlertCodeTwoWay: 
       
   210 			aSyncType = ESmlTwoWay;
       
   211 			break;
       
   212 		
       
   213 		case KNSmlServerAlertCodeOneWayFromClient: 
       
   214 			aSyncType = ESmlOneWayFromClient;
       
   215 			break;
       
   216 		
       
   217 		case KNSmlServerAlertCodeRefreshFromClient: 
       
   218 			aSyncType = ESmlRefreshFromClient;
       
   219 			break;
       
   220 		
       
   221 		case KNSmlServerAlertCodeOneWayFromServer: 
       
   222 			aSyncType = ESmlOneWayFromServer;
       
   223 			break;
       
   224 		
       
   225 		case KNSmlServerAlertCodeRefreshFromServer: 
       
   226 			aSyncType = ESmlRefreshFromServer;
       
   227 			break;
       
   228 		
       
   229 		default:
       
   230 			aSyncType = -1; 
       
   231 			break;
       
   232 		
       
   233 		}
       
   234 	}
       
   235 
       
   236 // ---------------------------------------------------------
       
   237 // CNSmlDSAlertParser12::ResolveProfileL( TInt aContentCount )
       
   238 // Resolves best matching profile
       
   239 // ---------------------------------------------------------
       
   240 //
       
   241 void CNSmlDSAlertParser12::ResolveProfileL( TInt aContentCount )
       
   242 	{
       
   243 	CNSmlAlertInfo* info = NULL;
       
   244 	TInt matchCheck(0);
       
   245 	TInt matchIndex(0);
       
   246 	
       
   247 	TBool match(EFalse);
       
   248 	
       
   249 	#ifdef __NSML_DEBUG__
       
   250 		DBG_ARGS(_S("CNSmlDSAlertParser12::ResolveProfileL: aContentCount:  '%d'"), aContentCount );
       
   251 	#endif // __NSML_DEBUG__
       
   252 	for ( TInt index = 0; index < iFoundProfiles.Count(); index++ )
       
   253 		{
       
   254 		info = iFoundProfiles[index];
       
   255 		
       
   256 		if ( info->iMatchCount == aContentCount )
       
   257 			{
       
   258 			match = ETrue;
       
   259 			break; //all contents found and full match
       
   260 			}
       
   261 		
       
   262 		if ( info->iMatchCount > matchCheck )
       
   263 			{
       
   264 			matchIndex = index;
       
   265 			}
       
   266 		
       
   267 		}
       
   268 			
       
   269 	if ( !match )	
       
   270 		{
       
   271 		info = iFoundProfiles[matchIndex];
       
   272 		}
       
   273 	
       
   274 	iAlertInfo.SetProfileId( info->iProfileId );
       
   275 	
       
   276 	for (TInt i=0; i< info->iTaskInfo.Count(); i++ )
       
   277 		{
       
   278 		iAlertInfo.TaskIds().AppendL( info->iTaskInfo[i]->iTaskId );
       
   279 		iAlertInfo.TaskSyncTypes().AppendL( info->iTaskInfo[i]->iSyncType );
       
   280 		}
       
   281 	
       
   282 	
       
   283 	}
       
   284 	
       
   285 // ---------------------------------------------------------
       
   286 // CNSmlDSAlertParser12::SearchProfileL( TDesC8& aServerUri )
       
   287 // Finds profile comparing the server id
       
   288 // ---------------------------------------------------------
       
   289 //
       
   290 void CNSmlDSAlertParser12::SearchProfileL( TDesC8& aServerUri )
       
   291 	{
       
   292 	CNSmlDSSettings* settings = CNSmlDSSettings::NewLC();
       
   293 	
       
   294 	CNSmlDSProfileList* profileList = new ( ELeave ) CArrayPtrFlat<CNSmlDSProfileListItem>(1);
       
   295 	CleanupStack::PushL( PtrArrCleanupItem( CNSmlDSProfileListItem, profileList ) );
       
   296 
       
   297 	settings->GetAllProfileListL( profileList );
       
   298 	
       
   299 	HBufC *uri = HBufC::NewLC(aServerUri.Size());
       
   300 	TPtr typePtr = uri->Des();
       
   301 	CnvUtfConverter::ConvertToUnicodeFromUtf8( typePtr, aServerUri);
       
   302 
       
   303 	//read profile values
       
   304 	for (TInt index = 0; index < profileList->Count(); index++ )
       
   305 		{
       
   306 		TInt profileId = profileList->At(index)->IntValue(EDSProfileId);
       
   307 		
       
   308 		CNSmlDSProfile* profile = settings->ProfileL(profileId);
       
   309 		CleanupStack::PushL( profile );
       
   310 		
       
   311 		if (uri->Des().Compare( profile->StrValue( EDSProfileServerId) ) == 0)
       
   312 			{
       
   313 			if ( iAlertInfo.Transport() == KUidNSmlMediumTypeInternet.iUid )
       
   314 			    {
       
   315 			    // accept only internet bearers
       
   316 			    if ( ( profile->IntValue(EDSProfileTransportId) == KUidNSmlMediumTypeInternet.iUid ) 
       
   317 			       && ( profile->IntValue(EDSProfileServerAlertedAction) != ESmlDisableSync ) )
       
   318     				{
       
   319     				CNSmlAlertInfo* info = new (ELeave) CNSmlAlertInfo;
       
   320     				info->iProfileId = profile->IntValue( EDSProfileId );
       
   321     				info->iIAPId = profile->IntValue( EDSProfileIAPId );
       
   322     				iFoundProfiles.AppendL( info );
       
   323     				}        
       
   324 			    }
       
   325 			else
       
   326 			    {
       
   327 			    // accept only local bearers
       
   328 			    if ( ( profile->IntValue(EDSProfileTransportId) != KUidNSmlMediumTypeInternet.iUid ) 
       
   329 			        && ( profile->IntValue(EDSProfileServerAlertedAction) != ESmlDisableSync ) )
       
   330     				{
       
   331     				CNSmlAlertInfo* info = new (ELeave) CNSmlAlertInfo;
       
   332     				info->iProfileId = profile->IntValue( EDSProfileId );
       
   333     				info->iIAPId = profile->IntValue( EDSProfileIAPId );
       
   334     				iFoundProfiles.AppendL( info );
       
   335     				}        
       
   336 			    }			
       
   337 			}
       
   338 		CleanupStack::PopAndDestroy(); //profile
       
   339 		}
       
   340 		
       
   341 	CleanupStack::PopAndDestroy(3); //uri, profileList, settings	
       
   342 	
       
   343 	if ( iAlertInfo.Transport() == KUidNSmlMediumTypeInternet.iUid )
       
   344 	    {
       
   345 	    if ( iFoundProfiles.Count() > 1 )
       
   346     	    {
       
   347     	    RArray<TInt> indexes;
       
   348             CleanupClosePushL( indexes );
       
   349             
       
   350             for (TInt j = 0; j < iFoundProfiles.Count(); j++ )
       
   351                 {
       
   352                 CNSmlAlertInfo* info = iFoundProfiles[j];
       
   353                 if ( info->iIAPId == -1 )    
       
   354                     {
       
   355                     indexes.Append( j );    
       
   356                     }
       
   357                 }
       
   358             
       
   359             if ( indexes.Count() < iFoundProfiles.Count() )
       
   360                 {
       
   361                 for ( TInt count(0); count < indexes.Count(); count++ )
       
   362                     {
       
   363                     CNSmlAlertInfo* temp = iFoundProfiles[indexes[count]];
       
   364                     iFoundProfiles.Remove( indexes[count] );
       
   365                     delete temp;
       
   366                     temp = NULL;            
       
   367                     }	        
       
   368                 }
       
   369                 
       
   370         	CleanupStack::PopAndDestroy( &indexes );    
       
   371     	    }				    
       
   372 	        
       
   373 	    }
       
   374 	}
       
   375 
       
   376 // ---------------------------------------------------------
       
   377 // CNSmlDSAlertParser12::MatchContentTypeL( TDesC8& aPath, TInt aContentType, TSmlSyncType aSyncType, TInt aProfileIndex )
       
   378 // Matches alerted content type by local database
       
   379 // ---------------------------------------------------------
       
   380 //
       
   381 void CNSmlDSAlertParser12::MatchContentTypeL( TDesC8& aPath, TInt aContentType, TSmlSyncType aSyncType, TInt aProfileIndex )
       
   382 	{
       
   383 #ifdef __NSML_DEBUG__
       
   384 	TPtrC8 pn( aPath ); 
       
   385 	DBG_ARGS8(_S8("CNSmlDSAlertParser12::MatchContentTypeL: aPath %S"), &pn);
       
   386 #endif // __NSML_DEBUG__
       
   387 
       
   388 	RImplInfoPtrArray implArray;
       
   389 	CleanupStack::PushL(PtrArrCleanupItemRArr(CImplementationInformation, &implArray));
       
   390 	
       
   391 	TUid dsUid = { KNSmlDSInterfaceUid };
       
   392 	REComSession::ListImplementationsL(dsUid, implArray);
       
   393 	
       
   394 	// Look through adapters to get right uid and ParameterList
       
   395 	TInt countImpls = implArray.Count();
       
   396 	CImplementationInformation* implInfo = NULL;
       
   397 #ifdef __NSML_DEBUG__
       
   398 	DBG_ARGS(_S("CNSmlDSAlertParser12::MatchContentTypeL: countImpls : '%d'"), countImpls );
       
   399 #endif // __NSML_DEBUG__
       
   400 	
       
   401 	for (TInt i = 0 ; i < countImpls; i++)
       
   402 		{
       
   403 		implInfo = implArray[ i ];
       
   404 		
       
   405 		CNSmlDSSettings* settings = CNSmlDSSettings::NewLC();
       
   406 		
       
   407 		CNSmlDSProfile* profile = settings->ProfileL( iFoundProfiles[aProfileIndex]->iProfileId );
       
   408 		CleanupStack::PushL( profile );
       
   409 		
       
   410 		CNSmlDSContentType* type = profile->ContentType( implInfo->ImplementationUid().iUid );
       
   411 		
       
   412 		if ( type )
       
   413 			{
       
   414 						
       
   415 			HBufC *uri = HBufC::NewLC(aPath.Size());
       
   416 			TPtr typePtr = uri->Des();
       
   417 			CnvUtfConverter::ConvertToUnicodeFromUtf8( typePtr, aPath);
       
   418 			
       
   419 #ifdef __NSML_DEBUG__
       
   420 	DBG_ARGS(_S16("CNSmlDSAlertParser12::MatchContentTypeL: typePtr : %S"), &typePtr);
       
   421 	DBG_ARGS(_S16("CNSmlDSAlertParser12::MatchContentTypeL: type Sting Val : %S"), &type->StrValue( EDSAdapterServerDataSource ));
       
   422 #endif // __NSML_DEBUG__
       
   423 
       
   424 			if (typePtr.Compare( type->StrValue( EDSAdapterServerDataSource ))  == 0)
       
   425 				{
       
   426 				/* CR: 403-1188 */
       
   427 				if (iAlertInfo.Transport() != KUidNSmlMediumTypeInternet.iUid)
       
   428 					{
       
   429 					_DBG_FILE("CNSmlDSAlertParser12::MatchContentTypeL : Inside Not Internet");
       
   430 					if ( ConvertContentTypeL( aContentType, implInfo->ImplementationUid().iUid ))
       
   431 						{
       
   432 						iFoundProfiles[aProfileIndex]->iMatchCount++;
       
   433 					
       
   434 						TNSmlContentTypeInfo* info = new (ELeave) TNSmlContentTypeInfo;
       
   435 						info->iTaskId = type->IntValue( EDSAdapterTableId );
       
   436 						info->iSyncType = aSyncType;
       
   437 					
       
   438 						iFoundProfiles[aProfileIndex]->iTaskInfo.AppendL( info );
       
   439 						
       
   440 						type->SetIntValue (EDSAdapterEnabled, ETrue) ; 
       
   441 										
       
   442 						profile->SaveL() ;
       
   443 						}
       
   444 				} // CR: 403-1188
       
   445 				else
       
   446 					{
       
   447 					_DBG_FILE("CNSmlDSAlertParser12::MatchContentTypeL : Inside Internet");
       
   448 					if ( ConvertContentTypeL( aContentType, implInfo->ImplementationUid().iUid ) && ( type->IntValue(EDSAdapterEnabled ) != EFalse) )
       
   449 						{
       
   450 						iFoundProfiles[aProfileIndex]->iMatchCount++;
       
   451 						
       
   452 						TNSmlContentTypeInfo* info = new (ELeave) TNSmlContentTypeInfo;
       
   453 						info->iTaskId = type->IntValue( EDSAdapterTableId );
       
   454 						info->iSyncType = aSyncType;
       
   455 						
       
   456 						iFoundProfiles[aProfileIndex]->iTaskInfo.AppendL( info );
       
   457 						}	
       
   458 					}				
       
   459 				}
       
   460 
       
   461 			CleanupStack::PopAndDestroy(); //uri
       
   462 			
       
   463 			}
       
   464 		CleanupStack::PopAndDestroy(2); // settings, profile
       
   465 		}
       
   466 					
       
   467 	REComSession::FinalClose();
       
   468 	
       
   469 	CleanupStack::PopAndDestroy(); //implArray
       
   470 	
       
   471 	}
       
   472 
       
   473 // ---------------------------------------------------------
       
   474 // CNSmlDSAlertParser12::ConvertContentTypeL( const TInt aContentNum, const TInt aDataProviderId )
       
   475 // Matches the mime types of the content type
       
   476 // ---------------------------------------------------------
       
   477 //
       
   478 TBool CNSmlDSAlertParser12::ConvertContentTypeL( const TInt aContentNum, const TInt aDataProviderId )
       
   479 	{
       
   480 	
       
   481 	HBufC8* contentType;
       
   482 	
       
   483 	TInt pc(0);
       
   484 	RFs	fs;
       
   485 	User::LeaveIfError( fs.Connect() );
       
   486 	CleanupClosePushL(fs);
       
   487 	pc++;
       
   488 	
       
   489 	TFileName fileName;
       
   490 	Dll::FileName( fileName );
       
   491 	
       
   492 	TParse parse;
       
   493 	parse.Set( KNSmlAlertDirAndResource, &KDC_RESOURCE_FILES_DIR, NULL );
       
   494 	fileName = parse.FullName();
       
   495 	
       
   496 #ifdef __NSML_DEBUG__
       
   497 		TPtrC16 pn( fileName.Ptr(), fileName.Size());
       
   498 		DBG_ARGS(_S16("CNSmlDSAlertParser12::ConvertContentTypeL: typePtr %S"), &pn);
       
   499 #endif // __NSML_DEBUG__
       
   500 
       
   501 	RResourceFile resourceFile; 
       
   502 	resourceFile.OpenL( fs,fileName );
       
   503 	CleanupClosePushL( resourceFile );
       
   504 	pc++;
       
   505 	
       
   506 	HBufC8* typesRes = resourceFile.AllocReadLC( NSML_DS_CONTENT_TYPES );
       
   507 	pc++;
       
   508 	TResourceReader reader;
       
   509 	reader.SetBuffer( typesRes );
       
   510 
       
   511 	TUint32 nOfTypes = reader.ReadInt16();
       
   512 	HBufC* textPtr = NULL;
       
   513 	TUint32 numCode;
       
   514 	TBool contentFound(EFalse);
       
   515 	
       
   516 #ifdef __NSML_DEBUG__
       
   517 	DBG_ARGS(_S("CNSmlDSAlertParser12::ConvertContentTypeL: nOfTypes : '%d'"), nOfTypes );
       
   518 #endif // __NSML_DEBUG__
       
   519 		
       
   520 	for ( TUint32 i=0; i < nOfTypes; i++)
       
   521 		{
       
   522 		numCode = reader.ReadInt16();
       
   523 		textPtr = reader.ReadHBufCL();
       
   524 		if ( numCode == aContentNum )
       
   525 			{
       
   526 			contentFound = ETrue;
       
   527 			break;
       
   528 			}
       
   529 		delete textPtr;
       
   530 		textPtr = NULL;
       
   531 		}
       
   532 	
       
   533 	if ( contentFound )
       
   534 		{
       
   535 		CleanupStack::PushL( textPtr );
       
   536 		pc++;
       
   537 		
       
   538 		TPtr tmpPtr = textPtr->Des();
       
   539 #ifdef __NSML_DEBUG__
       
   540 	TPtrC16 pn( tmpPtr);
       
   541 	DBG_ARGS(_S16("CNSmlDSAlertParser12::ConvertContentTypeL: tmpPtr %S"), &pn);
       
   542 #endif // __NSML_DEBUG__
       
   543 		tmpPtr.LowerCase();
       
   544 		contentType = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *textPtr );
       
   545 		CleanupStack::PushL( contentType );  // Leave aContentText to the cleanupstack
       
   546 		pc++;
       
   547 		
       
   548 		CNSmlDSHostClient* hostClient = CNSmlDSHostClient::NewLC();
       
   549 		pc++;
       
   550 		
       
   551 		RArray<TSmlDataProviderId> dataProviders;
       
   552 		dataProviders.AppendL( aDataProviderId );
       
   553 #ifdef __NSML_DEBUG__
       
   554 	DBG_ARGS(_S("CNSmlDSAlertParser12::ConvertContentTypeL: aDataProviderId: '%d'"), aDataProviderId );
       
   555 #endif // __NSML_DEBUG__
       
   556 		CleanupClosePushL( dataProviders );
       
   557 		pc++;
       
   558 		
       
   559 		RArray<TInt> resultArray;
       
   560 		CleanupClosePushL( resultArray );
       
   561 		pc++;
       
   562 		TInt status(KErrNone);
       
   563 		
       
   564 		hostClient->CreateDataProvidersL( dataProviders, resultArray );
       
   565 		
       
   566 		for (TInt index = 0; index < dataProviders.Count(); index++)
       
   567 			{
       
   568 			if (resultArray[index] != KErrNone)
       
   569 				{
       
   570 				contentFound = EFalse;
       
   571 				}
       
   572 			}
       
   573 		
       
   574 		if ( contentFound )
       
   575 			{
       
   576 			TNSmlDPInformation* adapterInfo = hostClient->DataProviderInformationL( aDataProviderId, status );
       
   577 			
       
   578 			if ( status == KErrNone)
       
   579 				{
       
   580 				
       
   581 				TInt mimeSupported(EFalse);
       
   582 				
       
   583 				TInt mimeCount = adapterInfo->iMimeTypes->Count();
       
   584 #ifdef __NSML_DEBUG__
       
   585 	DBG_ARGS(_S("CNSmlDSAlertParser12::ConvertContentTypeL: mimeCount: '%d'"), mimeCount );
       
   586 #endif // __NSML_DEBUG__
       
   587 				TPtrC8 pType = contentType->Des();
       
   588 				
       
   589 				if ( aContentNum != 0 )
       
   590 					{
       
   591 					for (TInt i = 0; i < mimeCount; i++)
       
   592 						{
       
   593 						TPtrC8 pInfo = (* adapterInfo->iMimeTypes )[i];						
       
   594 #ifdef __NSML_DEBUG__
       
   595 	DBG_ARGS8(_S8("CNSmlDSAlertParser12::ConvertContentTypeL: pType %S"), &pType);
       
   596 	DBG_ARGS8(_S8("CNSmlDSAlertParser12::ConvertContentTypeL: pInfo %S"), &pInfo);
       
   597 #endif // __NSML_DEBUG__
       
   598 						if ( pType.Compare( pInfo ) == 0 )
       
   599 							{
       
   600 							mimeSupported = ETrue;
       
   601 							break;
       
   602 							}	
       
   603 						}
       
   604 						
       
   605 					}
       
   606 				else
       
   607 					{
       
   608 					mimeSupported = ETrue;	
       
   609 					}
       
   610 				
       
   611 				
       
   612 				contentFound = mimeSupported;
       
   613 				
       
   614 				}
       
   615 			else
       
   616 				{
       
   617 				contentFound = EFalse;
       
   618 				}
       
   619 			
       
   620 			if ( adapterInfo )
       
   621 			    {
       
   622 			    delete adapterInfo->iDisplayName;
       
   623 		    	delete adapterInfo->iMimeTypes;
       
   624 			    delete adapterInfo->iMimeVersions;
       
   625 			    delete adapterInfo;		        
       
   626 			    }
       
   627 		
       
   628 			}
       
   629 		}
       
   630 	
       
   631 	CleanupStack::PopAndDestroy(pc);
       
   632 		
       
   633 	return contentFound;
       
   634 	}
       
   635