commonappservices/alarmserver/Server/Source/ASSrvServer.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1999-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 "ASSrvServer.h"
       
    17 
       
    18 // System includes
       
    19 #include <e32base.h>
       
    20 
       
    21 // User includes
       
    22 #include "ASSrvSession.h"
       
    23 #include "ASSrvStaticUtils.h"
       
    24 
       
    25 //Only include these in the secured platform 
       
    26 #include "ASSrvAlarmQueue.h"
       
    27 #include "ASShdOpCodes.h"
       
    28 
       
    29 
       
    30 #define KPolicyElementWriteUserData 0
       
    31 #define KPolicyElementWriteDeviceData 1
       
    32 
       
    33 
       
    34 const TUint KRangeCount = 5; 
       
    35 
       
    36 const TInt KOpCodeRanges[KRangeCount] = 
       
    37 	{	
       
    38 	KCapabilityNone,
       
    39 	KCapabilityCustomCheckData, 
       
    40 	KCapabilityWriteUserData, 
       
    41 	KCapabilityWriteDeviceData, 
       
    42 	EASShdOpCodeLast,
       
    43 	};
       
    44 
       
    45 
       
    46 const TUint8 KElementsIndex[KRangeCount] =
       
    47 	{
       
    48 	CPolicyServer::EAlwaysPass, 	//Allways passing no capability required 0-99
       
    49 	CPolicyServer::ECustomCheck, 	//Custom check for the Alarm SID 		 100-199
       
    50 	KPolicyElementWriteUserData,	//Requires WriteUserData				 200-299
       
    51 	KPolicyElementWriteDeviceData,	//Requires WriteDeviceData				 300-(EASShdOpCodeLast-1)
       
    52 	CPolicyServer::ENotSupported, 	//Not Supported					 		 EASShdOpCodeLast-End
       
    53 	};
       
    54 
       
    55 const CPolicyServer::TPolicyElement KPolicyElements[] = 
       
    56 	{ 
       
    57 	{_INIT_SECURITY_POLICY_C1(ECapabilityWriteUserData), CPolicyServer::EFailClient},
       
    58 	{_INIT_SECURITY_POLICY_C1(ECapabilityWriteDeviceData), CPolicyServer::EFailClient} 
       
    59 	};
       
    60 
       
    61 const CPolicyServer::TPolicy KAlarmServerPolicy =
       
    62 	{
       
    63 	CPolicyServer::EAlwaysPass, //specifies all connect attempts should pass
       
    64 	KRangeCount,
       
    65 	KOpCodeRanges,
       
    66 	KElementsIndex, 	// what each range is compared to 
       
    67 	KPolicyElements 	// what policies range is compared to
       
    68 	};
       
    69  	
       
    70 
       
    71 
       
    72 //
       
    73 // ----> CASSrvServer (source)
       
    74 //
       
    75 
       
    76 //*************************************************************************************
       
    77 CASSrvServer::CASSrvServer()
       
    78  	:CPolicyServer(CActive::EPriorityHigh, KAlarmServerPolicy)
       
    79 	{
       
    80 	}
       
    81 
       
    82 
       
    83 //*************************************************************************************
       
    84 CASSrvServer::~CASSrvServer()
       
    85 	{
       
    86 	// In order to prevent access violations as the server
       
    87 	// shuts down, we inform all sessions that the server is
       
    88 	// about to be destroyed
       
    89 	iSessionIter.SetToFirst();
       
    90 	//
       
    91 	CASSrvSession* session = static_cast<CASSrvSession*>(iSessionIter++);
       
    92 	while(session)
       
    93 		{
       
    94 		session->HandleServerDestruction();
       
    95 		session = static_cast<CASSrvSession*>(iSessionIter++);
       
    96 		}
       
    97 	//
       
    98 	delete iServerWideData;
       
    99 	}
       
   100 
       
   101 
       
   102 //*************************************************************************************
       
   103 void CASSrvServer::ConstructL()
       
   104 	{
       
   105 	// We "start" the server here (i.e before completing construction) since
       
   106 	// if two sessions attempt to connect at the same time, we will end up
       
   107 	// setting up an alarm alert notification with a server instance which is
       
   108 	// about to be destroyed. Calling StartL here won't actually allow any connections
       
   109 	// to be created until the active scheduler has a chance to run. However, the 
       
   110 	// call below will leave should there already be a started alarm server instance.
       
   111 	//
       
   112 	StartL(ASSrvStaticUtils::ASName());
       
   113 	iServerWideData = CASSrvServerWideData::NewL();
       
   114 	}
       
   115 
       
   116 
       
   117 //*************************************************************************************
       
   118 CASSrvServer* CASSrvServer::NewLC()
       
   119 	{
       
   120 	CASSrvServer* self = new(ELeave) CASSrvServer();
       
   121 	CleanupStack::PushL(self);
       
   122 	self->ConstructL();
       
   123 	return self;
       
   124 	}
       
   125 
       
   126 
       
   127 //
       
   128 //
       
   129 //
       
   130 
       
   131 
       
   132 //*************************************************************************************
       
   133 CSession2* CASSrvServer::NewSessionL(const TVersion& aVersion,const RMessage2& /*aMessage*/) const
       
   134 	{
       
   135 	// Check client version is correct
       
   136 	const TVersion alarmServerVersion(ASSrvStaticUtils::ASVersion());
       
   137 	if	(!User::QueryVersionSupported(alarmServerVersion, aVersion))
       
   138 		User::Leave(KErrNotSupported);
       
   139 
       
   140 	// Get non-const reference
       
   141 	CASSrvServerWideData& nonConstServerWideData = *const_cast<CASSrvServerWideData*>(iServerWideData);
       
   142 
       
   143 	// Create new session
       
   144 	CASSrvSession* session = CASSrvSession::NewL(nonConstServerWideData);
       
   145 	return session;
       
   146 	}
       
   147 
       
   148 
       
   149 //
       
   150 //
       
   151 //
       
   152 
       
   153 
       
   154 //*************************************************************************************
       
   155 TInt CASSrvServer::RunError(TInt aError)
       
   156 	{
       
   157 	// A bad descriptor error implies a badly programmed client, so panic it;
       
   158 	// otherwise report the error to the client
       
   159 	if	(aError == KErrBadDescriptor)
       
   160 		{
       
   161 		ASSrvStaticUtils::PanicClient(Message(), EAlarmServerInitiatedClientPanicBadDescriptor);
       
   162 		}
       
   163 	else
       
   164 		{
       
   165 		Message().Complete(aError);
       
   166 		}
       
   167 
       
   168 	// The leave will result in an early return from CServer2::RunL(), skipping
       
   169 	// the call to request another message. So do that now in order to keep the
       
   170 	// server running.
       
   171 	ReStart();
       
   172 
       
   173 	// Indicate that we've handled the error fully
       
   174 	return KErrNone;
       
   175 	}
       
   176 	
       
   177 CPolicyServer::TCustomResult CASSrvServer::CustomSecurityCheckL(const RMessage2& aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/)
       
   178 	{
       
   179 	CPolicyServer::TCustomResult returnValue = CPolicyServer::EFail;	
       
   180 	
       
   181 	// Initially, make sure there is alarms in the queue
       
   182 	const CASSrvAlarmQueue& queue = iServerWideData->Queue();
       
   183 	if(queue.QueueAlarmCount() > 0)
       
   184 		{	
       
   185 		// Get the alarm id from the client
       
   186 		const TAlarmId alarmId = static_cast<TAlarmId>(aMsg.Int0());
       
   187 		const TASSrvAlarm* theAlarm = queue.QueueAlarmById(alarmId);
       
   188 		if (theAlarm)
       
   189 			{
       
   190 			//Now get the SID of the alarm, it should be const since we do not want to change the alarm here
       
   191 			//Check that the SID of the alarm is equal to the SID of the client
       
   192 			TSecureId AlarmOwnerSID = theAlarm->GetSid();
       
   193 			TSecureId ClientSID = aMsg.SecureId();
       
   194 			if (AlarmOwnerSID == ClientSID)
       
   195 				{
       
   196 				returnValue = CPolicyServer::EPass;
       
   197 				}		
       
   198 			}
       
   199 		}
       
   200 		
       
   201 	// If the return value is not CPolicyServer::EPass that means that the client
       
   202 	// does not own the alarm (he was not the one creating it)
       
   203 	if (returnValue != CPolicyServer::EPass)
       
   204 		{
       
   205 		// Since different OP Codes require different capabilities
       
   206 		// we then need to check the OP code
       
   207 		// It is OK to 
       
   208 		//		- EASShdOpCodeGetAlarmDetails
       
   209 		//		- EASShdOpCodeGetAlarmData
       
   210 		//		- EASShdOpCodeAlarmAtIndex
       
   211 		// even if the client is not owning the alarm, as long as it has ReadUserData
       
   212 		const TInt opCode = aMsg.Function();
       
   213 		switch(opCode)
       
   214 			{
       
   215 			case EASShdOpCodeGetAlarmDetails:
       
   216 			case EASShdOpCodeGetAlarmData:
       
   217 			case EASShdOpCodeAlarmAtIndex:
       
   218 				// Check that the client has ReadUserData
       
   219 				if (aMsg.HasCapability(ECapabilityReadUserData))
       
   220 					{
       
   221 					returnValue = CPolicyServer::EPass;
       
   222 					}
       
   223 				break;
       
   224 			case EASShdOpCodeAlarmNotificationCancelAndDeQueue:	
       
   225 			case EASShdOpCodeAlarmDelete:						
       
   226 			case EASShdOpCodeSetAlarmStatus:						
       
   227 			case EASShdOpCodeSetAlarmDayOrTimed:					
       
   228 			case EASShdOpCodeSetAlarmCharacteristics:			
       
   229 			case EASShdOpCodeSetClientData:						
       
   230 			case EASShdOpCodeAlarmDataAttach:					
       
   231 			case EASShdOpCodeAlarmDataDetach:
       
   232 #ifdef SYMBIAN_ALARM_REPEAT_EXTENSIONS
       
   233 			case EASShdOpCodeSetAlarmDays:
       
   234 #endif
       
   235 				// Check that the client has WriteDeviceData
       
   236 				if (aMsg.HasCapability(ECapabilityWriteDeviceData))
       
   237 					{
       
   238 					returnValue = CPolicyServer::EPass;
       
   239 					}
       
   240 				break;
       
   241 			default:
       
   242 				if (aMsg.HasCapability(ECapabilityReadUserData, ECapabilityWriteDeviceData))
       
   243 					{
       
   244 					// If the Client has booth ReadUserData and WriteDeviceData then just return CPolicyServer::EPass
       
   245 					returnValue = CPolicyServer::EPass;
       
   246 					}
       
   247 				break;		
       
   248 			}
       
   249 		}
       
   250 	return(returnValue);
       
   251 	}