datacommsserver/esockserver/ssock/ss_api_ext.cpp
changeset 0 dfb7c4ff071f
child 4 928ed51ddc43
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2005-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  @file
       
    18  @released
       
    19 */
       
    20 
       
    21 #define SYMBIAN_NETWORKING_UPS
       
    22 
       
    23 #include "ss_api_ext.h"
       
    24 
       
    25 #include <comms-infras/ss_log.h>
       
    26 #include <comms-infras/ss_roles.h>
       
    27 #include <ss_glob.h>
       
    28 #include <es_panic.h>
       
    29 #include <ss_std.h>
       
    30 #include <comms-infras/ss_nodemessages.h>
       
    31 #include <comms-infras/ss_nodemessages_internal.h>
       
    32 #include <comms-infras/ss_nodemessages_legacy.h>
       
    33 
       
    34 
       
    35 #ifdef _DEBUG
       
    36 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    37 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    38 _LIT(KSpecAssert_ESockSSocks_p_xt, "ESockSSocks_p_xt");
       
    39 #endif
       
    40 
       
    41 using namespace Elements;
       
    42 using namespace ESock;
       
    43 using namespace Messages;
       
    44 
       
    45 //
       
    46 // CExtItfMsgPluginInfo
       
    47 //
       
    48 
       
    49 EXPORT_C CExtItfMsgPluginInfo* CExtItfMsgPluginInfo::NewInstanceL(const STypeId& aTypeId)
       
    50 	{
       
    51 	TUid destroyUid;
       
    52 	CExtItfMsgPluginInfo* obj = reinterpret_cast<CExtItfMsgPluginInfo*>(REComSession::CreateImplementationL(aTypeId.iUid, destroyUid, (TAny*)aTypeId.iType));
       
    53 	obj->iDestroyUid = destroyUid;
       
    54 	return obj;
       
    55 	}
       
    56 
       
    57 EXPORT_C CExtItfMsgPluginInfo::~CExtItfMsgPluginInfo()
       
    58 	{
       
    59 	__ASSERT_DEBUG(iDestroyUid.iUid!=0, User::Panic(KSpecAssert_ESockSSocks_p_xt, 1));
       
    60 	REComSession::DestroyedImplementation(iDestroyUid);
       
    61 	}
       
    62 
       
    63 //
       
    64 // CCommsApiExtResponder
       
    65 //
       
    66 
       
    67 EXPORT_C CCommsApiExtResponder::CCommsApiExtResponder()
       
    68 	{
       
    69 	}
       
    70 
       
    71 EXPORT_C CCommsApiExtResponder::~CCommsApiExtResponder()
       
    72 	{
       
    73 	}
       
    74 
       
    75 EXPORT_C void CCommsApiExtResponder::Complete(CCommsApiExtResponder*& aThis, TInt aError)
       
    76 	{
       
    77 	if (aThis==NULL)
       
    78 		{
       
    79 		return;
       
    80 		}
       
    81 
       
    82 	aThis->DoComplete(aError);
       
    83 	delete aThis;
       
    84 	aThis = NULL;
       
    85 	}
       
    86 
       
    87 //
       
    88 // CCommsApiExtIpcResponder
       
    89 //
       
    90 
       
    91 EXPORT_C void CCommsApiExtIpcResponder::DoComplete(TInt aError)
       
    92 	{
       
    93 	iResponseMsg.Complete(aError);
       
    94 	}
       
    95 
       
    96 EXPORT_C CCommsApiExtIpcResponder* CCommsApiExtIpcResponder::NewL(const RMessage2& aMessage)
       
    97 	{
       
    98 	return new (ELeave) CCommsApiExtIpcResponder(aMessage);
       
    99 	}
       
   100 
       
   101 EXPORT_C CCommsApiExtIpcResponder* CCommsApiExtIpcResponder::NewL(Elements::RResponseMsg& aResponseMsg)
       
   102 	{
       
   103 	return new (ELeave) CCommsApiExtIpcResponder(aResponseMsg);
       
   104 	}
       
   105 
       
   106 //
       
   107 // RLegacyRepsonseMsg
       
   108 //
       
   109 EXPORT_C RLegacyResponseMsg::RLegacyResponseMsg()
       
   110 	: iNodeAddr(Messages::TNodeCtxId::NullId())
       
   111 	{}
       
   112 
       
   113 EXPORT_C RLegacyResponseMsg::RLegacyResponseMsg(MeshMachine::TNodeContextBase& aContext)
       
   114 	: Elements::RResponseMsg(), iNodeAddr(aContext.ActivityId(), aContext.NodeId())
       
   115 	{}
       
   116 
       
   117 EXPORT_C RLegacyResponseMsg::RLegacyResponseMsg(MeshMachine::TNodeContextBase& aContext, const RMessage2& aMessage, TInt aInterfaceId, TInt aRequestMsgParam, TInt aResponseMsgParam)
       
   118 	: Elements::RResponseMsg(aMessage, aInterfaceId, aRequestMsgParam, aResponseMsgParam), iNodeAddr(aContext.ActivityId(), aContext.NodeId())
       
   119 	{}
       
   120 	
       
   121 EXPORT_C RLegacyResponseMsg::RLegacyResponseMsg(MeshMachine::TNodeContextBase& aContext, const RMessage2& aMessage, const Den::TApiExtIdentification& aInterfaceId, TInt aRequestMsgParam, TInt aResponseMsgParam)
       
   122 	: Elements::RResponseMsg(aMessage, aInterfaceId, aRequestMsgParam, aResponseMsgParam), iNodeAddr(aContext.ActivityId(), aContext.NodeId())
       
   123 	{}
       
   124 	
       
   125 EXPORT_C void RLegacyResponseMsg::Complete(TInt aError) const
       
   126 	{
       
   127 	TCFLegacyMessage::TLegacyRMessage2Processed msg(TLegacyRMessage2Response(TLegacyRMessage2Response::ENormal, aError));
       
   128     RNodeInterface::OpenPostMessageClose(iNodeAddr, iNodeAddr, msg);
       
   129 	iNodeAddr.SetNull();
       
   130 	}
       
   131 
       
   132 EXPORT_C void RLegacyResponseMsg::Panic(const TDesC& aCategory, TInt aReason) const
       
   133 	{
       
   134 	TCFLegacyMessage::TLegacyRMessage2Processed msg(TLegacyRMessage2Response(TLegacyRMessage2Response::EPanic, aReason, aCategory));
       
   135     RNodeInterface::OpenPostMessageClose(iNodeAddr, iNodeAddr, msg);
       
   136 	iNodeAddr.SetNull();
       
   137 	}
       
   138 
       
   139 EXPORT_C TBool RLegacyResponseMsg::IsNull() const
       
   140 	{
       
   141 	return iNodeAddr.IsNull();
       
   142 	}
       
   143 
       
   144 //
       
   145 // CCommsApiExtLegacyIpcResponder
       
   146 //
       
   147 EXPORT_C void CCommsApiExtLegacyIpcResponder::DoComplete(TInt aError)
       
   148 	{
       
   149 	iResponseMsg.Complete(aError);
       
   150 	}
       
   151 
       
   152 EXPORT_C CCommsApiExtLegacyIpcResponder* CCommsApiExtLegacyIpcResponder::NewL(MeshMachine::TNodeContextBase& aContext, const RMessage2& aMessage)
       
   153 	{
       
   154 	return new (ELeave) CCommsApiExtLegacyIpcResponder(aContext, aMessage);
       
   155 	}
       
   156 
       
   157 EXPORT_C CCommsApiExtLegacyIpcResponder* CCommsApiExtLegacyIpcResponder::NewL(RLegacyResponseMsg& aResponseMsg)
       
   158 	{
       
   159 	return new (ELeave) CCommsApiExtLegacyIpcResponder(aResponseMsg);
       
   160 	}
       
   161 
       
   162 // CCommsApiExtIpcOpenResponder
       
   163 
       
   164 EXPORT_C CCommsApiExtIpcOpenResponder* CCommsApiExtIpcOpenResponder::NewL(TSupportedCommsApiExt aInterfaceId, TSubSessionUniqueId aClientId, const RMessage2& aMessage)
       
   165 	{
       
   166 	return new (ELeave) CCommsApiExtIpcOpenResponder(aInterfaceId, aClientId, aMessage);
       
   167 	}
       
   168 
       
   169 EXPORT_C void CCommsApiExtIpcOpenResponder::DoComplete(TInt aError)
       
   170 	{
       
   171 	if (aError!=KErrNone)
       
   172 		{
       
   173 		SockManGlobals::Get()->iCommsApiExtRegister.DeRegisterInterface(iInterfaceId, iClientId);
       
   174 		}
       
   175 	CCommsApiExtIpcResponder::DoComplete(aError);
       
   176 	}
       
   177 
       
   178 
       
   179 //
       
   180 // AIPCClientInfo
       
   181 //
       
   182 
       
   183 /**
       
   184    @param aSubSessionUniqueId The id of the subsession to query
       
   185    @param aUidType The uid type
       
   186    @return KErrNone on success and KErrCorrupt when the current aSubSessionUniqueId
       
   187    could not be mapped to an existing client.
       
   188 */
       
   189 EXPORT_C TInt AIPCClientInfo::ClientUidType(TSubSessionUniqueId aSubSessionUniqueId, TUidType& aUidType) const
       
   190 	{
       
   191 	TProcessId processId;
       
   192 	TThreadId threadId;
       
   193 	TInt err = GetSubsessionOwnerInfo(aSubSessionUniqueId, processId, aUidType, threadId);
       
   194 	return err;
       
   195 	}
       
   196 
       
   197 /**
       
   198    Retrieves the secure id of the owner of the subsession
       
   199    @param aSubSessionUniqueId The id of the subsession to query
       
   200    @param aUid The secure id of the owner of the subsession
       
   201    @return KErrNone if the call is successful, otherwise one of the system-wide error codes.
       
   202 */
       
   203 EXPORT_C TInt AIPCClientInfo::ClientSid(TSubSessionUniqueId aSubSessionUniqueId, TSecureId& aSid) const
       
   204 	{
       
   205 	RProcess process;
       
   206 	TInt res = OpenClientProcess(aSubSessionUniqueId, process);
       
   207 	if (res == KErrNone)
       
   208 		{
       
   209         aSid = process.SecureId();
       
   210         process.Close();
       
   211 		}
       
   212 
       
   213     return res;
       
   214 	}
       
   215 
       
   216 /**
       
   217    Opens the RProcess of the owning client process of the subsession. The caller is responsible
       
   218    for calling the RProcess.Close() method.
       
   219    @param aSubSessionUniqueId The subsession id of to obtain the client process information from
       
   220    @param aProcess Upon returning from a successful call aProcess is an opened RProcess.
       
   221    @return KErrNone if the call is successful, otherwise one of the system-wide error codes.
       
   222 */
       
   223 EXPORT_C TInt AIPCClientInfo::OpenClientProcess(TSubSessionUniqueId aSubSessionUniqueId, RProcess& aProcess) const
       
   224     {
       
   225     TProcessId processId;
       
   226 	TUidType uidType;
       
   227 	TThreadId threadId;
       
   228 
       
   229 	TInt err = GetSubsessionOwnerInfo(aSubSessionUniqueId, processId, uidType, threadId);
       
   230 	if (err == KErrNone)
       
   231 	    {
       
   232         err = aProcess.Open(processId);
       
   233 	    }
       
   234 
       
   235     return err;
       
   236     }
       
   237 
       
   238 /**
       
   239    Retrieves information about the owner of the subsession
       
   240    @param aSubSessionUniqueId The subsession id of to obtain the client process information from
       
   241    @return KErrNone if the call is successful, otherwise one of the system-wide error codes.
       
   242    @note The thread id. returned is that which opened the RSocketServ, not the RSocket.
       
   243 */
       
   244 TInt AIPCClientInfo::GetSubsessionOwnerInfo(TSubSessionUniqueId aSubSessionUniqueId, TProcessId& aProcessId, TUidType& aUidType, TThreadId& aThreadId) const
       
   245     {
       
   246 	CWorkerThread* worker = SockManGlobals::Get()->SelfWorker();
       
   247 	__ASSERT_DEBUG(worker, Panic(ENonESockWorkerThread));
       
   248 	
       
   249 	CPlayer* player = worker->Player();
       
   250 	__ASSERT_DEBUG(player, Panic(ENonESockWorkerThread));
       
   251 	
       
   252 	CSockSubSession* ss = player->SubSession(aSubSessionUniqueId);
       
   253 	
       
   254 	if (ss == NULL)
       
   255 		{
       
   256 		return KErrCorrupt;
       
   257 		}
       
   258 
       
   259 	ss->GetOwnerInfo(aProcessId, aUidType, aThreadId);
       
   260 	return KErrNone;
       
   261    }
       
   262 
       
   263 EXPORT_C TInt AIPCClientPlatsecInfo::SecureId(TSubSessionUniqueId aSubSessionUniqueId, TSecureId& aResult) const
       
   264     {
       
   265 	return ClientSid(aSubSessionUniqueId, aResult);
       
   266     }
       
   267 
       
   268 
       
   269 EXPORT_C TInt AIPCClientPlatsecInfo::VendorId(TSubSessionUniqueId aSubSessionUniqueId, TVendorId& aResult) const
       
   270     {
       
   271 	RProcess process;
       
   272 	TInt res = OpenClientProcess(aSubSessionUniqueId, process);
       
   273 	if (res == KErrNone)
       
   274 		{
       
   275         aResult = process.VendorId();
       
   276         process.Close();
       
   277 		}
       
   278 
       
   279     return res;
       
   280     }
       
   281 
       
   282 
       
   283 EXPORT_C TBool AIPCClientPlatsecInfo::HasCapability(TSubSessionUniqueId aSubSessionUniqueId, const TCapability aCapability) const
       
   284    {
       
   285    RProcess process;
       
   286    TInt res = OpenClientProcess(aSubSessionUniqueId, process);
       
   287    if (res != KErrNone) { return EFalse; }
       
   288 
       
   289    TBool platsecResult;
       
   290    platsecResult = process.HasCapability(aCapability);
       
   291    process.Close();
       
   292 
       
   293    return platsecResult;
       
   294    }
       
   295 
       
   296 
       
   297 EXPORT_C TInt AIPCClientPlatsecInfo::CheckPolicy(TSubSessionUniqueId aSubSessionUniqueId, const TSecurityPolicy& aPolicy) const
       
   298     {
       
   299 	RProcess process;
       
   300 	TInt res = OpenClientProcess(aSubSessionUniqueId, process);
       
   301 	if (res != KErrNone)
       
   302         {
       
   303         return res;
       
   304         }
       
   305 
       
   306     TBool platsecResult;
       
   307     platsecResult = aPolicy.CheckPolicy(process);
       
   308     if (!platsecResult)
       
   309         {
       
   310         return KErrPermissionDenied;
       
   311         }
       
   312     return KErrNone;
       
   313     }
       
   314 
       
   315 #ifdef SYMBIAN_NETWORKING_UPS
       
   316 EXPORT_C TInt AIPCClientPlatsecInfo::GetProcessAndThreadId(TSubSessionUniqueId aSubSessionUniqueId, TProcessId& aProcessId, TThreadId& aThreadId) const
       
   317     {
       
   318     TUidType   uidType;
       
   319     
       
   320 	TInt rc = GetSubsessionOwnerInfo(aSubSessionUniqueId, aProcessId, uidType, aThreadId);
       
   321 	return rc;
       
   322     }
       
   323 #endif //SYMBIAN_NETWORKING_UPS
       
   324 
       
   325 /**
       
   326 
       
   327 */
       
   328 EXPORT_C AExtensionInterfaceThickBase::AExtensionInterfaceThickBase(const Meta::STypeId& aMsgImplTid) 
       
   329 :	iMsgImplTid(aMsgImplTid)
       
   330 	{
       
   331 	}
       
   332 
       
   333 /**
       
   334 
       
   335 */
       
   336 EXPORT_C AExtensionInterfaceThickBase::~AExtensionInterfaceThickBase()
       
   337 	{
       
   338 	}
       
   339 
       
   340 /**
       
   341 	Null default implementation
       
   342 */
       
   343 EXPORT_C void AExtensionInterfaceThickBase::OpenExtensionInterface(TSubSessionUniqueId /* aClientId */, const TRuntimeCtxId& /*aControlClient*/, CCommsApiExtResponder* aResponder)
       
   344 	{
       
   345 	CCommsApiExtResponder::Complete(aResponder,KErrNone);
       
   346 	}
       
   347 
       
   348 /**
       
   349 	Null default implementation
       
   350 */
       
   351 EXPORT_C void AExtensionInterfaceThickBase::CancelExtensionInterface(TSubSessionUniqueId /* aClientId */)
       
   352 	{
       
   353 	}
       
   354 
       
   355 /**
       
   356 	Null default implementation
       
   357 */
       
   358 EXPORT_C void AExtensionInterfaceThickBase::CloseExtensionInterface(TSubSessionUniqueId /* aClientId */)
       
   359 	{
       
   360 	}
       
   361 
       
   362 /*
       
   363 EXPORT_C void AExtensionInterfaceThickBase::RegisterMessagesL()
       
   364 	{
       
   365 	__ASSERT_DEBUG(iMsgPluginInfo==NULL, User::Panic(KSpecAssert_ESockSSocks_p_xt, 2)); //Well, we should not be opening the same interface 
       
   366 		{
       
   367 		iMsgPluginInfo = static_cast<MExtItfMsgPluginInfo*>(REComSession::CreateImplementationL(iMsgImplUid, iDtorIdKey));
       
   368 		}
       
   369 	const TImplementationProxy* implProxyTable = iMsgPluginInfo->ImplementationProxy();
       
   370 	CWorkerThread* worker = SockManGlobals::Get()->SelfWorker();
       
   371 	worker->RegisterInterfaceL(iMsgImplUid, iMsgPluginInfo->ImplementationProxyTableSize(), implProxyTable);
       
   372 	}
       
   373 	
       
   374 EXPORT_C void AExtensionInterfaceThickBase::DeregisterMessages()
       
   375 	{
       
   376 	CWorkerThread* worker = SockManGlobals::Get()->SelfWorker();
       
   377 	worker->DeregisterInterface(iMsgImplUid);
       
   378 	REComSession::DestroyedImplementation(iDtorIdKey);
       
   379 	REComSession::FinalClose();
       
   380 	}
       
   381 */
       
   382