wapstack/wapmessageapi/client/wapmessage.cpp
branchRCL_3
changeset 18 50bae5c5c85f
child 53 12b52b1a573e
equal deleted inserted replaced
17:3f227a47ad75 18:50bae5c5c85f
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 #include <wapmessage.h>
       
    18 #include <ecom/ecom.h>
       
    19 
       
    20 /** The WAP Messaging API.  Four interfaces are defined that provide bound and fully-specified versions of WDP and Connectionless Push.
       
    21 	An instantiation of each may be obtained using the CreateImplementationL() function, and must be released using Release() when no
       
    22 	longer required.  Release() causes the instantiation to be deleted.
       
    23 */
       
    24 
       
    25 // Use SWS as default WAP stack
       
    26 //  If undefined th3em NWSS stack will be used as default
       
    27 #define WAPUSE_SWS // since 8.0
       
    28 
       
    29 #ifndef WAPUSE_SWS
       
    30 // Symbian OS 7.0
       
    31 _LIT8(KDefBoundWdpCue, "wdp/bound");
       
    32 _LIT8(KDefFullSpecWdpCue, "wdp/fullyspec");
       
    33 _LIT8(KDefBoundCLPushCue, "clpush/bound");
       
    34 _LIT8(KDefFullSpecCLPushCue, "clpush/fullyspec");
       
    35 
       
    36 _LIT8(KAltBoundWdpCue, "swswdp/bound");
       
    37 _LIT8(KAltFullSpecWdpCue, "swswdp/fullyspec");
       
    38 _LIT8(KAltBoundCLPushCue, "swsclpush/bound");
       
    39 _LIT8(KAltFullSpecCLPushCue, "swsclpush/fullyspec");
       
    40 
       
    41 #else
       
    42 // Symbian OS 8.0
       
    43 _LIT8(KAltBoundWdpCue, "wdp/bound");
       
    44 _LIT8(KAltFullSpecWdpCue, "wdp/fullyspec");
       
    45 _LIT8(KAltBoundCLPushCue, "clpush/bound");
       
    46 _LIT8(KAltFullSpecCLPushCue, "clpush/fullyspec");
       
    47 
       
    48 _LIT8(KDefBoundWdpCue, "swswdp/bound");
       
    49 _LIT8(KDefFullSpecWdpCue, "swswdp/fullyspec");
       
    50 _LIT8(KDefBoundCLPushCue, "swsclpush/bound");
       
    51 _LIT8(KDefFullSpecCLPushCue, "swsclpush/fullyspec");
       
    52 #endif
       
    53 
       
    54 _LIT8(KBoundCLWSPCue, "swsclwsp/bound");
       
    55 _LIT8(KFullSpecCLWSPCue, "swsclwsp/fullyspec");
       
    56 
       
    57 /** Bound WDP
       
    58 */
       
    59 
       
    60 EXPORT_C 
       
    61 CWapBoundDatagramService* CWapBoundDatagramService::NewL()
       
    62 	/** Allocates and creates a new CWapBoundDatagramService object. 
       
    63 	* 
       
    64 	* @return	A new CWapBoundDatagramService object.
       
    65 	* @leave	System wide error codes
       
    66 	*/
       
    67 	{
       
    68 	// CWapBoundDatagramService ECOM Interface UID = 101F4471
       
    69 	const TUid KUidBoundWDPInterface = {0x101F4471};
       
    70 
       
    71 	// Set resolving parameters
       
    72 	TEComResolverParams resolverParams;
       
    73 	resolverParams.SetDataType(KDefBoundWdpCue);
       
    74 	resolverParams.SetWildcardMatch(ETrue);
       
    75 
       
    76 	// Get the instantiation
       
    77 	TInt trapValue(0); 
       
    78 	TAny* ptr = NULL;
       
    79 	TRAP(trapValue, ptr = REComSession::CreateImplementationL(KUidBoundWDPInterface,
       
    80 								 _FOFF(CWapBoundDatagramService, iDtor_ID_Key),
       
    81 								 resolverParams));
       
    82 	if(trapValue)
       
    83 	{
       
    84 		resolverParams.SetDataType(KAltBoundWdpCue);
       
    85 		// Trying to load old wapmessage plug-in
       
    86 		ptr = REComSession::CreateImplementationL(KUidBoundWDPInterface,
       
    87 								 _FOFF(CWapBoundDatagramService, iDtor_ID_Key),
       
    88 								 resolverParams);
       
    89 	}
       
    90 
       
    91 	return REINTERPRET_CAST(CWapBoundDatagramService*, ptr);
       
    92 	}
       
    93 
       
    94 EXPORT_C 
       
    95 CWapBoundDatagramService* CWapBoundDatagramService::NewL(const TUid& aImplementation)
       
    96 	/** Allocates and creates a new CWapBoundDatagramService object. 
       
    97 	* 
       
    98 	* @param aImplementation
       
    99 	* @return					A new CWapBoundDatagramService object.
       
   100 	* @leave					System wide error codes
       
   101 	*/
       
   102 	{
       
   103 		TAny* ptr = REComSession::CreateImplementationL(aImplementation,
       
   104 								 _FOFF(CWapBoundDatagramService, iDtor_ID_Key));
       
   105 
       
   106 	return	REINTERPRET_CAST(CWapBoundDatagramService*, ptr);
       
   107 	}
       
   108 
       
   109 EXPORT_C 
       
   110 CWapBoundDatagramService::~CWapBoundDatagramService()
       
   111 	/** Destructor */
       
   112 	{
       
   113 	REComSession::DestroyedImplementation(iDtor_ID_Key);
       
   114 	}
       
   115 
       
   116 EXPORT_C 
       
   117 CWapBoundDatagramService::CWapBoundDatagramService()
       
   118 	{
       
   119 	}
       
   120 
       
   121 EXPORT_C 
       
   122 void CWapBoundDatagramService::ConstructL()
       
   123 	{
       
   124 	}
       
   125 	
       
   126 /** Fully-specified WDP
       
   127 */
       
   128 
       
   129 EXPORT_C 
       
   130 CWapFullySpecDatagramService* CWapFullySpecDatagramService::NewL()
       
   131 	/** Allocates and creates a new CWapFullySpecDatagramService object. 
       
   132 	* 
       
   133 	* @return	A new CWapFullySpecDatagramService object.
       
   134 	* @leave	System wide error codes.
       
   135 	*/
       
   136 	{
       
   137 	// MWapFullySpecDatagramService ECOM Interface UID = 101F4473
       
   138 	const TUid KUidFullySpecDatagramInterface = {0x101F4473};
       
   139 
       
   140 	// Set resolving parameters
       
   141 	TEComResolverParams resolverParams;
       
   142 	resolverParams.SetDataType(KDefFullSpecWdpCue);
       
   143 	resolverParams.SetWildcardMatch(ETrue);
       
   144 
       
   145 	// Get the instantiation
       
   146 	TInt trapValue(0); 
       
   147 	TAny* ptr = NULL;
       
   148 	TRAP(trapValue, ptr = REComSession::CreateImplementationL(KUidFullySpecDatagramInterface,
       
   149 								 _FOFF(CWapFullySpecDatagramService, iDtor_ID_Key),
       
   150 								 resolverParams));
       
   151 	if(trapValue)
       
   152 	{
       
   153 		// Trying to load old wapmessage plug-in
       
   154 		resolverParams.SetDataType(KAltFullSpecWdpCue);
       
   155 		ptr = REComSession::CreateImplementationL(KUidFullySpecDatagramInterface,
       
   156 								 _FOFF(CWapFullySpecDatagramService, iDtor_ID_Key),
       
   157 								 resolverParams);
       
   158 	}
       
   159 
       
   160 	return REINTERPRET_CAST(CWapFullySpecDatagramService*, ptr);
       
   161 	}
       
   162 
       
   163 EXPORT_C 
       
   164 CWapFullySpecDatagramService* CWapFullySpecDatagramService::NewL(const TUid& aImplementation)
       
   165 	/** Allocates and creates a new CWapFullySpecDatagramService object. 
       
   166 	* 
       
   167 	* @param aImplementation	
       
   168 	* @return					A new CWapFullySpecDatagramService object.
       
   169 	* @leave					System wide error codes.
       
   170 	*/
       
   171 	{
       
   172 		TAny* ptr = REComSession::CreateImplementationL(aImplementation,
       
   173 								 _FOFF(CWapFullySpecDatagramService, iDtor_ID_Key));
       
   174 
       
   175 	return	REINTERPRET_CAST(CWapFullySpecDatagramService*, ptr);
       
   176 	}
       
   177 
       
   178 EXPORT_C 
       
   179 CWapFullySpecDatagramService::~CWapFullySpecDatagramService()
       
   180 	/** Destructor */
       
   181 	{
       
   182 	REComSession::DestroyedImplementation(iDtor_ID_Key);
       
   183 	}
       
   184 
       
   185 EXPORT_C 
       
   186 CWapFullySpecDatagramService::CWapFullySpecDatagramService()
       
   187 	{
       
   188 	}
       
   189 
       
   190 EXPORT_C 
       
   191 void CWapFullySpecDatagramService::ConstructL()
       
   192 	{
       
   193 	}
       
   194 
       
   195 /** Bound Connection-less Push
       
   196 */
       
   197 
       
   198 EXPORT_C 
       
   199 CWapBoundCLPushService* CWapBoundCLPushService::NewL()
       
   200 	/** Allocates and creates a new CWapBoundCLPushService object. 
       
   201 	*
       
   202 	* @return	A new <code>CWapBoundCLPushService</code> object.
       
   203 	* @leave	System wide error codes.
       
   204 	*/
       
   205 	{
       
   206 	// MWapBoundCLPushService ECOM Interface UID = 101F4475
       
   207 	const TUid KUidBoundCLPushInterface = {0x101F4475};
       
   208 
       
   209 	// Set resolving parameters
       
   210 	TEComResolverParams resolverParams;
       
   211 	resolverParams.SetDataType(KDefBoundCLPushCue);
       
   212 	resolverParams.SetWildcardMatch(ETrue);
       
   213 
       
   214 	// Get the instantiation
       
   215 	TInt trapValue(0); 
       
   216 	TAny* ptr = NULL;
       
   217 	TRAP(trapValue, ptr = REComSession::CreateImplementationL(KUidBoundCLPushInterface,
       
   218 								 _FOFF(CWapBoundCLPushService, iDtor_ID_Key),
       
   219 								 resolverParams));
       
   220 	if(trapValue)
       
   221 	{
       
   222 		// Trying to load old wapmessage plug-in
       
   223 		resolverParams.SetDataType(KAltBoundCLPushCue);
       
   224 		ptr = REComSession::CreateImplementationL(KUidBoundCLPushInterface,
       
   225 								 _FOFF(CWapBoundCLPushService, iDtor_ID_Key),
       
   226 								 resolverParams);
       
   227 	}
       
   228 	return REINTERPRET_CAST(CWapBoundCLPushService*, ptr);
       
   229 	}
       
   230 
       
   231 EXPORT_C 
       
   232 CWapBoundCLPushService* CWapBoundCLPushService::NewL(const TUid& aImplementation)
       
   233 	/** Allocates and creates a new CWapBoundCLPushService object. 
       
   234 	*
       
   235 	* @param aImplementation	
       
   236 	* @return					A new CWapBoundCLPushService object.
       
   237 	* @leave					System wide error codes.
       
   238 	*/
       
   239 	{
       
   240 		TAny* ptr = REComSession::CreateImplementationL(aImplementation,
       
   241 								 _FOFF(CWapBoundCLPushService, iDtor_ID_Key));
       
   242 
       
   243 	return	REINTERPRET_CAST(CWapBoundCLPushService*, ptr);
       
   244 	}
       
   245 
       
   246 EXPORT_C 
       
   247 CWapBoundCLPushService::~CWapBoundCLPushService()
       
   248 	/** Destructor */
       
   249 	{
       
   250 	REComSession::DestroyedImplementation(iDtor_ID_Key);
       
   251 	}
       
   252 
       
   253 EXPORT_C 
       
   254 CWapBoundCLPushService::CWapBoundCLPushService()
       
   255 	{
       
   256 	}
       
   257 
       
   258 EXPORT_C 
       
   259 void CWapBoundCLPushService::ConstructL()
       
   260 	{
       
   261 	}
       
   262 
       
   263 /** Fully-specified Connection-less Push
       
   264 */
       
   265 
       
   266 EXPORT_C 
       
   267 CWapFullySpecCLPushService* CWapFullySpecCLPushService::NewL()
       
   268 	/** Allocates and creates a new CWapFullySpecCLPushService object. 
       
   269 	*
       
   270 	* @return	A new CWapFullySpecCLPushService object.
       
   271 	* @leave	System wide error codes.
       
   272 	*/
       
   273 	{
       
   274 	// MWapFullySpecCLPushService ECOM Interface UID = 101F4477
       
   275 	const TUid KUidFullySpecCLPushInterface = {0x101F4477};
       
   276 
       
   277 	// Set resolving parameters
       
   278 	TEComResolverParams resolverParams;
       
   279 	resolverParams.SetDataType(KDefFullSpecCLPushCue);
       
   280 	resolverParams.SetWildcardMatch(ETrue);
       
   281 
       
   282 	// Get the instantiation
       
   283 	TInt trapValue(0); 
       
   284 	TAny* ptr = NULL;
       
   285 	TRAP(trapValue, ptr = REComSession::CreateImplementationL(KUidFullySpecCLPushInterface,
       
   286 								 _FOFF(CWapFullySpecCLPushService, iDtor_ID_Key),
       
   287 								 resolverParams));
       
   288 	if(trapValue)
       
   289 	{
       
   290 		// Trying to load old wapmessage plug-in
       
   291 		resolverParams.SetDataType(KAltFullSpecCLPushCue);
       
   292 		ptr = REComSession::CreateImplementationL(KUidFullySpecCLPushInterface,
       
   293 								 _FOFF(CWapFullySpecCLPushService, iDtor_ID_Key),
       
   294 								 resolverParams);
       
   295 	}
       
   296 
       
   297 	return REINTERPRET_CAST(CWapFullySpecCLPushService*, ptr);
       
   298 	}
       
   299 
       
   300 EXPORT_C 
       
   301 CWapFullySpecCLPushService* CWapFullySpecCLPushService::NewL(const TUid& aImplementation)
       
   302 	/** Allocates and creates a new CWapFullySpecCLPushService object. 
       
   303 	*
       
   304 	* @param aImplementation
       
   305 	* @return					A new CWapFullySpecCLPushService object.
       
   306 	* @leave					System wide error codes.
       
   307 	*/
       
   308 	{
       
   309 		TAny* ptr = REComSession::CreateImplementationL(aImplementation,
       
   310 								 _FOFF(CWapFullySpecCLPushService, iDtor_ID_Key));
       
   311 
       
   312 	return	REINTERPRET_CAST(CWapFullySpecCLPushService*, ptr);
       
   313 	}
       
   314 
       
   315 EXPORT_C 
       
   316 CWapFullySpecCLPushService::~CWapFullySpecCLPushService()
       
   317 	/** Destructor */
       
   318 	{
       
   319 	REComSession::DestroyedImplementation(iDtor_ID_Key);
       
   320 	}
       
   321 
       
   322 EXPORT_C 
       
   323 CWapFullySpecCLPushService::CWapFullySpecCLPushService()
       
   324 	{
       
   325 	}
       
   326 
       
   327 EXPORT_C 
       
   328 void CWapFullySpecCLPushService::ConstructL()
       
   329 	{
       
   330 	}
       
   331 
       
   332 /** Bound WSP
       
   333 	New interface and implementation
       
   334 */
       
   335 
       
   336 EXPORT_C 
       
   337 CWapBoundCLWSPService* CWapBoundCLWSPService::NewL()
       
   338 	/** Allocates and creates a new CWapBoundCLWSPService object. 
       
   339 	*
       
   340 	* @return					A new CWapBoundCLWSPService object.
       
   341 	* @leave					System wide error codes.
       
   342 	*/
       
   343 	{
       
   344 	// CWapBoundWSPService ECOM Interface UID = 101FBB3B
       
   345 	const TUid KUidBoundCLWSPInterface = {0x101FBB3B};
       
   346 
       
   347 	// Set resolving parameters
       
   348 	TEComResolverParams resolverParams;
       
   349 	resolverParams.SetDataType(KBoundCLWSPCue);
       
   350 	resolverParams.SetWildcardMatch(ETrue);
       
   351 
       
   352 	// Get the instantiation
       
   353 	TAny* ptr = REComSession::CreateImplementationL(KUidBoundCLWSPInterface,
       
   354 								 _FOFF(CWapBoundCLWSPService, iDtor_ID_Key),
       
   355 								 resolverParams);
       
   356 
       
   357 	return REINTERPRET_CAST(CWapBoundCLWSPService*, ptr);
       
   358 	}
       
   359 
       
   360 EXPORT_C 
       
   361 CWapBoundCLWSPService* CWapBoundCLWSPService::NewL(const TUid& aImplementation)
       
   362 	/** Allocates and creates a new CWapBoundCLWSPService object. 
       
   363 	*
       
   364 	* @param aImplementation
       
   365 	* @return					A new CWapBoundCLWSPService object.
       
   366 	* @leave					System wide error codes.
       
   367 	*/
       
   368 	{
       
   369 		TAny* ptr = REComSession::CreateImplementationL(aImplementation,
       
   370 								 _FOFF(CWapBoundCLWSPService, iDtor_ID_Key));
       
   371 
       
   372 	return	REINTERPRET_CAST(CWapBoundCLWSPService*, ptr);
       
   373 	}
       
   374 
       
   375 EXPORT_C 
       
   376 CWapBoundCLWSPService::~CWapBoundCLWSPService()
       
   377 	/** Destructor */
       
   378 	{
       
   379 	REComSession::DestroyedImplementation(iDtor_ID_Key);
       
   380 	}
       
   381 
       
   382 EXPORT_C 
       
   383 CWapBoundCLWSPService::CWapBoundCLWSPService()
       
   384 	{
       
   385 	}
       
   386 
       
   387 EXPORT_C 
       
   388 void CWapBoundCLWSPService::ConstructL()
       
   389 	{
       
   390 	}
       
   391 
       
   392 /** Fully-specified Connection-less WSP
       
   393 	New interface and implementation
       
   394 */
       
   395 
       
   396 EXPORT_C 
       
   397 CWapFullySpecCLWSPService* CWapFullySpecCLWSPService::NewL()
       
   398 	/** Allocates and creates a new CWapFullySpecCLWSPService object. 
       
   399 	*
       
   400 	* @return					A new CWapFullySpecCLWSPService object.
       
   401 	* @leave					System wide error codes.
       
   402 	*/
       
   403 	{
       
   404 	// CWapFullySpecCLWSPService ECOM Interface UID = 101FBB3D
       
   405 	const TUid KUidFullySpecCLWSPInterface = {0x101FBB3D};
       
   406 
       
   407 	// Set resolving parameters
       
   408 	TEComResolverParams resolverParams;
       
   409 	resolverParams.SetDataType(KFullSpecCLWSPCue);
       
   410 	resolverParams.SetWildcardMatch(ETrue);
       
   411 
       
   412 	// Get the instantiation
       
   413 	TAny* ptr = REComSession::CreateImplementationL(KUidFullySpecCLWSPInterface,
       
   414 								 _FOFF(CWapFullySpecCLWSPService, iDtor_ID_Key),
       
   415 								 resolverParams);
       
   416 
       
   417 	return REINTERPRET_CAST(CWapFullySpecCLWSPService*, ptr);
       
   418 	}
       
   419 
       
   420 EXPORT_C 
       
   421 CWapFullySpecCLWSPService* CWapFullySpecCLWSPService::NewL(const TUid& aImplementation)
       
   422 	/** Allocates and creates a new CWapFullySpecCLWSPService object. 
       
   423 	*
       
   424 	* @param aImplementation
       
   425 	* @return					A new CWapFullySpecCLWSPService object.
       
   426 	* @leave					System wide error codes.
       
   427 	*/
       
   428 	{
       
   429 		TAny* ptr = REComSession::CreateImplementationL(aImplementation,
       
   430 								 _FOFF(CWapFullySpecCLWSPService, iDtor_ID_Key));
       
   431 
       
   432 	return	REINTERPRET_CAST(CWapFullySpecCLWSPService*, ptr);
       
   433 	}
       
   434 
       
   435 EXPORT_C 
       
   436 CWapFullySpecCLWSPService::~CWapFullySpecCLWSPService()
       
   437 	/** Destructor */
       
   438 	{
       
   439 	REComSession::DestroyedImplementation(iDtor_ID_Key);
       
   440 	}
       
   441 
       
   442 EXPORT_C 
       
   443 CWapFullySpecCLWSPService::CWapFullySpecCLWSPService()
       
   444 	{
       
   445 	}
       
   446 
       
   447 EXPORT_C 
       
   448 void CWapFullySpecCLWSPService::ConstructL()
       
   449 	{
       
   450 	}
       
   451 
       
   452    
       
   453 EXPORT_C TInt CWapMessageUtils::GetLocalAddressesL(RArray<Wap::TAddressInfo>& aAddressInfo)
       
   454 	/** Gets a list of all the available network interface addresses.
       
   455 	*
       
   456 	* @param aAddressInfo	On return, an array of the available network interface addresses.
       
   457 	* @return				KErrNone if successful, KErrNotFound if there are no addresses available. */
       
   458 	{
       
   459 	Wap::TAddressInfo addrInfo;
       
   460 
       
   461 	// Check if the esock ini file has been parsed
       
   462 //	User::LeaveIfError(Nifman::CheckIniConfig());
       
   463 
       
   464 	// The list of interfaces is available from a RSocket.GetOpt
       
   465 	TAutoClose<RSocketServ> sockServer;
       
   466 	User::LeaveIfError(sockServer.iObj.Connect());
       
   467 	sockServer.PushL();
       
   468 
       
   469 	TAutoClose<RSocket> sock;
       
   470 	User::LeaveIfError(sock.iObj.Open(sockServer.iObj, _L("udp")));
       
   471 	sock.PushL();
       
   472 
       
   473 	User::LeaveIfError(sock.iObj.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl));
       
   474 
       
   475 	TPckgBuf<TSoInetInterfaceInfo> info, next;
       
   476 
       
   477 	TInt res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info);
       
   478 	if(res!=KErrNone)
       
   479 		User::Leave(res);
       
   480 
       
   481 	TInt validAddr = KErrNotFound;
       
   482 
       
   483 	while(res==KErrNone)
       
   484 		{
       
   485 		res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, next);
       
   486 
       
   487 		// Only consider the address is its up, and is point to point.
       
   488 		// (TODO-would it be right to include pending state addresses too????)
       
   489 		if ( (info().iState == EIfUp) &&
       
   490 			 (info().iFeatures & KIfIsPointToPoint) )
       
   491 			{
       
   492 			// Just want the interface name
       
   493 			// = info().iName;
       
   494 			// and the address
       
   495 			// = info().iAddress;
       
   496 			validAddr = KErrNone;	   
       
   497 			
       
   498 			addrInfo.iAddress = info().iAddress;
       
   499 			addrInfo.iName = info().iName;
       
   500 			aAddressInfo.Append(addrInfo);
       
   501 			}
       
   502 		}
       
   503 
       
   504 	sock.Pop();
       
   505 	sockServer.Pop();
       
   506 
       
   507 	return validAddr;
       
   508 	}