os/security/authorisation/userpromptservice/examples/integration/tmsgserver/tmsgserver.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-2009 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 the License "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: 
    15 * Example code
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22  @internalComponent
    23  @test
    24 */
    25 
    26 #ifndef TMSGSERVER_H_
    27 #define TMSGSERVER_H_
    28 
    29 #include <e32base.h>
    30 #include <e32cmn.h>
    31 #include <e32std.h>
    32 #include <ups/upsclient.h>
    33 
    34 
    35 // Standard shutdown timer for transient servers
    36 class CShutdown : public CTimer
    37 	{
    38 	enum {KMyShutdownDelay=0x200000};	// approx 2s
    39 public:
    40 	inline CShutdown();
    41 	inline void ConstructL();
    42 	inline void Start();
    43 private:
    44 	void RunL();
    45 	}; 
    46 
    47 enum TMsgServerPanic
    48 	{
    49 	EPanicIllegalFunction,
    50 	};	
    51 		
    52 /**
    53  Example system server that uses the User Prompt Service.
    54  */
    55 class CMsgServer : public CPolicyServer
    56 	{
    57 public:
    58 	static CMsgServer* NewLC();
    59 	CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
    60 	inline UserPromptService::RUpsSession& Ups();	
    61 	void AddSession();
    62 	void DropSession();	   
    63 	TCustomResult CustomFailureActionL(const RMessage2& aMessage, TInt aAction, const TSecurityInfo& aMissing);
    64 	~CMsgServer();
    65 private:
    66 	CMsgServer();
    67 	void ConstructL();
    68 private:
    69 	// Server Policies
    70 	static const TInt KPolicyRanges = 3;
    71 	static const TInt KPolicyElements = 1;
    72 	static const TInt iRanges[KPolicyRanges];
    73 	static const TUint8 iElementsIndex[KPolicyRanges];
    74 	static const CPolicyServer::TPolicyElement iPolicyElements[KPolicyElements];
    75 	static const CPolicyServer::TPolicy iPolicy;
    76 	CShutdown iShutdown;
    77 	TInt iSessionCount;
    78 	
    79 	UserPromptService::RUpsSession iUps;	/// UPS session class held by Server
    80 	};	
    81 	
    82 /**
    83  Active object that asynchronously processes the sending of a message. 
    84  An extra state is added to support UPS authorisation.
    85  In a more complicated server there may be several different message processor
    86  classes.
    87  */	   
    88 class CMsgProcessor : public CActive
    89 	{
    90 	enum TState {EIdle, EAuthorising, ESending};
    91 public:
    92 	static CMsgProcessor* NewL(UserPromptService::RUpsSubsession& aAuth);		
    93 	void ProcessL(const RMessage2& aMessage, TBool aPlatsecResult);
    94 	~CMsgProcessor();
    95 private:
    96 	CMsgProcessor(UserPromptService::RUpsSubsession& aAuth);
    97 	void ConstructL();
    98 	void RunL();
    99 	void DoCancel();
   100 	TInt RunError(TInt aError);
   101 	void Reset();
   102 	void GetParamsL(const RMessage2& aMessage);	
   103 	void AuthoriseL(const RMessage2& aMessage, TBool aPlatsecResult);
   104 	void SendL();
   105 	
   106 private:
   107 	RMessage2 iMessage;
   108 	TState iState;
   109 	RBuf iMsgTo;
   110 	RBuf iMsgBody;
   111 	RTimer iTimer;		
   112 	
   113 	UserPromptService::RUpsSubsession& iAuth;	/// Handle to UPS sub-session for client
   114 	TUpsDecision iDecision;						/// Whether the request was authorised
   115 	TBool iPlatsecResult;						/// Whether the platsec check passed	
   116 	// In techview this corresponds to 
   117 	// ups\policies\test\tupspolicies\resource\ups_01041000_01041001.rss
   118 	// and is recognised by the example UPS dialog creator and notifier.
   119 	static const TUint KServiceId = 0x01041001;
   120 	};
   121 	
   122 /**
   123  Session class for example message server that uses the User Prompt Service
   124  */
   125 class CMsgServerSession : public CSession2
   126 	{
   127 public:
   128 	CMsgServerSession();
   129 	void CreateL();	
   130 	void SetPlatsecResult(TBool aResult);
   131 	~CMsgServerSession();
   132 private:
   133 	inline CMsgServer& Server(); 
   134 	void ServiceL(const RMessage2& aMessage);		 
   135 	CMsgProcessor* iProcessor;
   136 		  
   137 	/// Normally, a sub-session is created for each client or client connection
   138 	UserPromptService::RUpsSubsession iAuth;	
   139 	/// Only initialise iAuth once
   140 	TBool iAuthInitialised;
   141 	/// RUpsSubsession::Authorise needs to know whether the platsec check passed
   142 	TBool iPlatsecResult;
   143 	};
   144 #endif /* TMSGSERVER_H_*/