os/ossrv/lowlevellibsandfws/apputils/bsul/test/t_clientmessage/testclientmessageschema.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-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 <e32capability.h>
    17 #include "t_clientmessagetestserver.h"
    18 
    19 using namespace BSUL;
    20 
    21 enum TCustomParamType
    22 	{
    23 	EParamCustom1 = (0x10000 | EParamPckg),
    24 	EParamCustom2 = (0x20000 | EParamPckg),
    25 	EParamCustom3 = (0x30000 | EParamInt),
    26 	EParamCustom4 = (0x40000 | EParamDes16Read),
    27 	EParamCustom5 = (0x90000 | EParamPckg)
    28 	};
    29 
    30 
    31 /* These are the parameter description sets for each message to be handled by the
    32  * server. These descriptions provide the type of the parameter and constraints
    33  * used to validate messages recieved from the client.  The particular validation
    34  * requirements are defined in the appropriate CMessageParameterBase derived class
    35  * and parameter objects are instantiated via the Parameter factory Lookup table.
    36  */
    37 //Integer parameter set
    38 const TParameterDetails KMessage0Params[2] = {{EParamInt,-10,100},{EParamInt,0,200}};
    39 
    40 //These parameter sets are incorrectly defined. Attempts to call this message should
    41 //panic the server.
    42 const TParameterDetails KMessage2Params[1] = {{EParamInt,100,10}};
    43 const TParameterDetails KMessage3Params[1] = {{EParamInt,-10,-20}};
    44 
    45 //Des*Read parameter sets
    46 const TParameterDetails KMessage4Params[2] = {{EParamDes8Read,2,16},{EParamDes16Read,0,32}};
    47 
    48 //These parameter sets are incorrectly defined. Attempts to call this message should
    49 //panic the server.
    50 const TParameterDetails KMessage8Params[1] = {{EParamDes8Read,0,-16}};
    51 
    52 //Des* parameter sets
    53 const TParameterDetails KMessage9Params[4] = {{EParamDes8,64,64},
    54 												{EParamInt,0,64},
    55 												{EParamDes16,128,128},
    56 												{EParamInt,0,128}};
    57 
    58 const TParameterDetails KMessage11Params[4] = {{EParamDes8,64,64},
    59 												{EParamInt,0,64},
    60 												{EParamDes16,128,128},
    61 												{EParamInt,0,128}};
    62 
    63 //These parameter sets are incorrectly defined. Attempts to call this message should
    64 //panic the server.
    65 const TParameterDetails KMessage12Params[1] = {{EParamDes8,-64,64}};
    66 const TParameterDetails KMessage13Params[1] = {{EParamDes8,64,-64}};
    67 
    68 //Des parameter sets
    69 const TParameterDetails KMessage14Params[3] = {{EParamDes8Read,0,16},
    70 												{EParamInt,0,16},
    71 												{EParamDes8,16,16}};
    72 
    73 const TParameterDetails KMessage15Params[3] = {{EParamDes16Read,0,64},
    74 												{EParamInt,0,64},
    75 												{EParamDes16,64,64}};
    76 
    77 //Ptr parameter sets
    78 const TParameterDetails KMessage16Params[1] = {{EParamPtr,0,0}};
    79 
    80 
    81 //Custom parameter sets
    82 const TParameterDetails KMessage18Params[1] = {{EParamCustom1,sizeof(CMTestStruct2),sizeof(CMTestStruct2)}};
    83 const TParameterDetails KMessage19Params[1] = {{EParamCustom2,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
    84 
    85 //Invalid parameter type
    86 const TParameterDetails KMessage27Params[1] = {{453,0,0}};
    87 
    88 //standard param types with custom validation functions
    89 //Custom parameter sets
    90 const TParameterDetails KMessage28Params[1] = {{EParamCustom3,0,0}};
    91 const TParameterDetails KMessage29Params[1] = {{EParamCustom4,0,32}};
    92 
    93 //Pkg parameter
    94 const TParameterDetails KMessage30Params[1] = {{EParamPckg,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
    95 
    96 const TParameterDetails KMessage31Params[2] = {{EParamInt,EGetIntL,EWrite16L},{EParamPtr,0,0}};
    97 
    98 //Custom parameter type. EParamCustom5 is incorrectly defined as the validation function
    99 //index is outside the range of the supplied validation fuction array
   100 const TParameterDetails KMessage32Params[1] = {{EParamCustom5,sizeof(CMTestStruct1),sizeof(CMTestStruct1)}};
   101 
   102 
   103 
   104 /* This Security Policy defines the requirements for a client to interact
   105  * with the server. If a client sends a request to the server and doesnt
   106  * meet the security policy, the request is denied with KErrAccessDenied.
   107  * 
   108  */
   109 _LIT_SECURITY_POLICY_PASS(KDefaultPolicy);
   110 _LIT_SECURITY_POLICY_FAIL(KFailPolicy);
   111 _LIT_SECURITY_POLICY_S0(KSidPassPolicy,0x10285B57);
   112 _LIT_SECURITY_POLICY_S0(KSidFailPolicy,0x12345678);
   113 _LIT_SECURITY_POLICY_C2(KCapFailPolicy,ECapabilityReadUserData,ECapabilityPowerMgmt);
   114 _LIT_SECURITY_POLICY_C2(KCapPassPolicy,ECapabilityReadUserData,ECapabilityWriteUserData);
   115 
   116 /* This is the array of messages that will be accepted by the server.  
   117  * The messages are defined as follows:
   118  *  	{Function Number, Number of Parameters, Parameter Descriptions}
   119  * When loading the message objects, this table is traversed and so the most 
   120  * frequently called messages should be first in the list to ensure the most
   121  * efficient operation
   122  */
   123 const TClientMessageSchema KClientMessages[] = 
   124 	{
   125 	MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params),
   126 	MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage0Params),
   127 	MESSAGE_SCHEMA(ETestMessage2,KDefaultPolicy,KMessage2Params),
   128 	MESSAGE_SCHEMA(ETestMessage3,KDefaultPolicy,KMessage3Params),
   129 	MESSAGE_SCHEMA(ETestMessage4,KDefaultPolicy,KMessage4Params),
   130 	MESSAGE_SCHEMA(ETestMessage5,KDefaultPolicy,KMessage4Params),
   131 	MESSAGE_SCHEMA(ETestMessage6,KDefaultPolicy,KMessage4Params),
   132 	MESSAGE_SCHEMA(ETestMessage7,KDefaultPolicy,KMessage4Params),
   133 	MESSAGE_SCHEMA(ETestMessage8,KDefaultPolicy,KMessage8Params),											 
   134 	MESSAGE_SCHEMA(ETestMessage9,KDefaultPolicy,KMessage9Params),
   135 	MESSAGE_SCHEMA(ETestMessage10,KDefaultPolicy,KMessage9Params),
   136 	MESSAGE_SCHEMA(ETestMessage11,KDefaultPolicy,KMessage11Params),
   137 	MESSAGE_SCHEMA(ETestMessage12,KDefaultPolicy,KMessage12Params),
   138 	MESSAGE_SCHEMA(ETestMessage13,KDefaultPolicy,KMessage13Params),
   139 	MESSAGE_SCHEMA(ETestMessage14,KDefaultPolicy,KMessage14Params),
   140 	MESSAGE_SCHEMA(ETestMessage15,KDefaultPolicy,KMessage15Params),
   141 	MESSAGE_SCHEMA(ETestMessage16,KDefaultPolicy,KMessage16Params),
   142 	MESSAGE_SCHEMA(ETestMessage17,KDefaultPolicy,KMessage16Params),
   143 	MESSAGE_SCHEMA(ETestMessage18,KDefaultPolicy,KMessage18Params),
   144 	MESSAGE_SCHEMA(ETestMessage19,KDefaultPolicy,KMessage19Params),
   145 	MESSAGE_SCHEMA(ETestMessage20,KFailPolicy,KMessage0Params),
   146 	MESSAGE_SCHEMA(ETestMessage21,KSidPassPolicy,KMessage0Params),
   147 	MESSAGE_SCHEMA(ETestMessage22,KSidFailPolicy,KMessage0Params),
   148 	MESSAGE_SCHEMA(ETestMessage23,KCapPassPolicy,KMessage0Params),
   149 	MESSAGE_SCHEMA(ETestMessage24,KCapFailPolicy,KMessage0Params),
   150 	MESSAGE_SCHEMA_NO_PARAMS(ETestMessage25,KDefaultPolicy),
   151 	MESSAGE_SCHEMA(ETestMessage26,KDefaultPolicy,KNoParams),
   152 	MESSAGE_SCHEMA(ETestMessage27,KDefaultPolicy,KMessage27Params),
   153 	MESSAGE_SCHEMA(ETestMessage28,KDefaultPolicy,KMessage28Params),
   154 	MESSAGE_SCHEMA(ETestMessage29,KDefaultPolicy,KMessage29Params),
   155 	MESSAGE_SCHEMA(ETestMessage30,KDefaultPolicy,KMessage30Params),
   156 	MESSAGE_SCHEMA(ETestMessage31,KDefaultPolicy,KMessage31Params),
   157 	MESSAGE_SCHEMA(ETestMessage32,KDefaultPolicy,KMessage32Params)
   158 	};
   159 														 
   160 static void ValidationFn1L(CMessageParameterBase* aParameter);
   161 static void ValidationFn2L(CMessageParameterBase* aParameter);
   162 static void ValidationFn3L(CMessageParameterBase* aParameter);
   163 static void ValidationFn4L(CMessageParameterBase* aParameter);
   164 
   165 const TCustomValidationFn KCustomValidationFunctions[] = {NULL,
   166 														&ValidationFn1L,
   167 														&ValidationFn2L,
   168 														&ValidationFn3L,
   169 														&ValidationFn4L};
   170 
   171 extern const TClientMessageServerData KServerData = SERVER_DATA(KClientMessages,
   172 																KCustomValidationFunctions,
   173 																"CMTestServer",
   174 																ESrvFlagLogBadMessages);
   175 
   176 void ValidationFn1L(CMessageParameterBase* aParameter)
   177 	{
   178 	CMTestStruct2 struct1;
   179 
   180 	TPckg<CMTestStruct2> pData(struct1);
   181 	
   182 	if(aParameter->GetDesLengthL() != sizeof(CMTestStruct2))
   183 		{
   184 		User::Leave(KErrBadDescriptor);
   185 		}
   186 	
   187 	aParameter->ReadL(pData,0);
   188 	
   189 	if((struct1.iEnum < ETestVal0)||(struct1.iEnum > ETestVal3))
   190 		{
   191 		User::Leave(KErrBadParameter);
   192 		}
   193 	
   194 	if(struct1.iDes.Length() <= 0)
   195 		{
   196 		User::Leave(KErrBadParameter);
   197 		}
   198 	
   199 	if(struct1.iCount < 0)
   200 		{
   201 		User::Leave(KErrBadParameter);
   202 		}	
   203 	}
   204 
   205 void ValidationFn2L(CMessageParameterBase* aParameter)
   206 	{
   207 	CMTestStruct1 struct1;
   208 	TPckg<CMTestStruct1> pData(struct1);
   209 	
   210 	aParameter->ReadL(pData,0);
   211 	
   212 	if(struct1.iInt <= 0)
   213 		{
   214 		User::Leave(KErrBadParameter);
   215 		}
   216 	}
   217 
   218 void ValidationFn3L(CMessageParameterBase* aParameter)
   219 	{
   220 	
   221 	TInt value = aParameter->GetIntL();
   222 	
   223 	if(value%4 != 0)
   224 		{
   225 		User::Leave(KErrBadParameter);
   226 		}
   227 
   228 	}
   229 
   230 void ValidationFn4L(CMessageParameterBase* aParameter)
   231 	{
   232 	TBuf<32> data;
   233 	
   234 	aParameter->ReadL(data,0);
   235 	
   236 	if(data != _L("Expected Data"))
   237 		{
   238 		User::Leave(KErrBadParameter);
   239 		}
   240 	}
   241 
   242 
   243 //parameter sets for server2
   244 const TParameterDetails KMessage0Params2[2] = {{EParamInt,0,10},{EParamInt,-100,100}};
   245 
   246 /* Descriptor parameter for server2 */
   247 const TParameterDetails KMessage1Params2[1] = {{EParamDes8Read,0,16}};
   248 
   249 /* This is the array of messages that will be accepted by the server.  
   250  * The messages are defined as follows:
   251  *  	{Function Number, Number of Parameters, Parameter Descriptions}
   252  */
   253 const TClientMessageSchema KClientMessages2[] = {MESSAGE_SCHEMA(ETestMessage0,KDefaultPolicy,KMessage0Params2),
   254 												MESSAGE_SCHEMA(ETestMessage1,KDefaultPolicy,KMessage1Params2)};
   255 
   256 const TCustomValidationFn KCustomValidationFunctions2[] = {NULL};
   257 
   258 extern const TClientMessageServerData KServer2Data = SERVER_DATA(KClientMessages2,
   259 																KCustomValidationFunctions2,
   260 																"CMTestServer2",
   261 																(ESrvFlagLogBadMessages | ESrvFlagDoNotPanicClientOnBadMessageErrors));