realtimenetprots/sipfw/SIP/Server/src/CSipCSServer.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     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 // Name          : CSipCSServer.cpp
       
    15 // Part of       : SIPServerCore
       
    16 // Version       : SIP/3.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "sipclientserver.h"
       
    23 #include "CSipCSServer.h"
       
    24 #include "CSipServerCore.h"
       
    25 #include "CSipCSSession.h"
       
    26 #include "TSipCSPlatSecPolicy.h"
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CSipCSServer::NewL
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CSipCSServer* CSipCSServer::NewL(CSipServerCore& aServerCore)
       
    33 	{
       
    34     CSipCSServer* self = CSipCSServer::NewLC(aServerCore);
       
    35     CleanupStack::Pop(self);
       
    36     return self;
       
    37 	}
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CSipCSServer::NewLC
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CSipCSServer* CSipCSServer::NewLC(CSipServerCore& aServerCore)
       
    44 	{
       
    45 	CSipCSServer* self = new(ELeave)CSipCSServer(EPriorityHigh,aServerCore);
       
    46     CleanupStack::PushL(self);
       
    47     self->ConstructL();
       
    48     return self;
       
    49 	}
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CSipCSServer::ConstructL
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void CSipCSServer::ConstructL()
       
    56 	{
       
    57     StartL(KSipServerName);
       
    58 	}
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CSipCSServer::CSipCSServer
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CSipCSServer::CSipCSServer(TInt aPriority, CSipServerCore& aServerCore)
       
    65  : CPolicyServer(aPriority, TSipCSPlatSecPolicy),
       
    66    iServerCore(aServerCore)
       
    67 	{
       
    68 	iSecurityInfo.SetToCurrentInfo();
       
    69 	iSecurityInfo.iCaps.RemoveCapability(ECapabilityProtServ);
       
    70 	}
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CSipCSServer::~CSipCSServer
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CSipCSServer::~CSipCSServer()
       
    77 	{
       
    78 	}
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CSipCSServer::NewSessionL
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CSession2* CSipCSServer::NewSessionL(const TVersion &aVersion,
       
    85                                      const RMessage2& /*aMessage*/) const
       
    86 	{
       
    87 	// check we're the right version
       
    88 	if (!User::QueryVersionSupported (TVersion (KSipServerMajorVersionNumber,
       
    89                                                 KSipServerMinorVersionNumber,
       
    90                                                 KSipServerBuildVersionNumber),
       
    91                                                 aVersion))
       
    92 		{
       
    93 		User::Leave(KErrNotSupported);
       
    94 		}
       
    95     return CSipCSSession::NewL(iServerCore);
       
    96 	}
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CSipCSServer::ConnectionStateChangedL
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CSipCSServer::ConnectionStateChangedL(TUint32 aIapId,
       
   103                                            CSIPConnection::TState aState)
       
   104 	{
       
   105 	// inform all the sessions
       
   106 	iSessionIter.SetToFirst();
       
   107     CSipCSSession* session = 0;
       
   108 	for (CSession2* s=iSessionIter; s!=0; s=iSessionIter++)
       
   109 		{
       
   110 		session = static_cast<CSipCSSession*>(s);
       
   111 		session->ConnectionStateChangedL (aIapId,aState);
       
   112 		}
       
   113 	}
       
   114 	
       
   115 // -----------------------------------------------------------------------------
       
   116 // CSipCSServer::FindOwner
       
   117 // -----------------------------------------------------------------------------
       
   118 //    
       
   119 MTransactionOwner* CSipCSServer::FindOwner(TUint32 aIapId, const TUid& aUid)
       
   120 	{
       
   121 	MTransactionOwner* transactionOwner = NULL;
       
   122 	iSessionIter.SetToFirst();
       
   123     CSipCSSession* session = 0;
       
   124 	for (CSession2* s=iSessionIter; s!=0 && !transactionOwner; s=iSessionIter++)
       
   125 		{
       
   126 		session = static_cast<CSipCSSession*>(s);
       
   127 		if (session->Uid() == aUid)
       
   128 			{
       
   129 			transactionOwner = &(session->FindOwner(aIapId));
       
   130 			}
       
   131 		}
       
   132 	return transactionOwner;
       
   133 	}	
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CSipCSServer::RunError
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 TInt CSipCSServer::RunError(TInt aError)
       
   140 	{
       
   141 	if (aError == KErrBadDescriptor)
       
   142 		{
       
   143         // A bad descriptor error implies a badly programmed client, 
       
   144         // so panic it; otherwise report the error to the client
       
   145 		Message().Panic(KSipCSServerPanic, EBadDescriptor);
       
   146 		}
       
   147 	else
       
   148 		{
       
   149 		Message().Complete(aError);
       
   150 		}
       
   151 	//
       
   152 	// The leave will result in an early return from CServer::RunL(), skipping
       
   153 	// the call to request another message. So do that now in order to keep the
       
   154 	// server running.
       
   155 	ReStart();
       
   156 	return KErrNone; // handled the error fully
       
   157 	}
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CSipCSServer::CustomSecurityCheckL
       
   161 // -----------------------------------------------------------------------------
       
   162 //	
       
   163 CPolicyServer::TCustomResult CSipCSServer::CustomSecurityCheckL(
       
   164     const RMessage2& aMsg,
       
   165     TInt& /*aAction*/,
       
   166     TSecurityInfo& /*aMissing*/)
       
   167     {
       
   168     // Profile server is allowed to set opts regardless of its capabilities 
       
   169     const TUint32 KProfileServerUidVal = 0x101F413C;
       
   170     TUid clientUid = aMsg.SecureId();
       
   171         
       
   172     if ( ( aMsg.Function() == ESipItcSetSIPSockOpt || 
       
   173            aMsg.Function() == ESipItcSetSIPSockOptWithDes ) &&
       
   174           clientUid.iUid != KProfileServerUidVal )
       
   175         {
       
   176         TSecurityInfo clientSecurityInfo(aMsg);
       
   177         TCapabilitySet sipServerCaps;
       
   178         sipServerCaps.SetEmpty();
       
   179         sipServerCaps.Union(iSecurityInfo.iCaps);
       
   180         sipServerCaps.RemoveCapability(ECapabilityReadUserData); // Maintain SC
       
   181         if (!clientSecurityInfo.iCaps.HasCapabilities(sipServerCaps))
       
   182             {
       
   183             return CPolicyServer::EFail;
       
   184             }
       
   185         }
       
   186     return CPolicyServer::EPass;
       
   187     }