policymanagement/policyengine/policyengineserver/src/PolicyProcessor.cpp
branchRCL_3
changeset 62 19bba8228ff0
parent 61 b183ec05bd8c
equal deleted inserted replaced
61:b183ec05bd8c 62:19bba8228ff0
    28 #include "TrustedSession.h"
    28 #include "TrustedSession.h"
    29 #include "XACMLconstants.h"
    29 #include "XACMLconstants.h"
    30 #include "PolicyEngineServer.h"
    30 #include "PolicyEngineServer.h"
    31 #include "PolicyEngineClientServer.h"
    31 #include "PolicyEngineClientServer.h"
    32 #include "debug.h"
    32 #include "debug.h"
    33 #include <hbdevicedialogsymbian.h>
    33 
    34 #include <hbdevicenotificationdialogsymbian.h>
    34 #include "PolicyEngineUi.h"
    35 #include <hbtextresolversymbian.h>
    35 
    36 // CONSTANTS
    36 // CONSTANTS
    37 const TUid KUidPolicyEngineUi = { 0x10207817 };
    37 const TUid KUidPolicyEngineUi = { 0x10207817 };
    38 const TUint KDelimeterChar = '|';
    38 
    39 _LIT8( KUserAcceptMark, "A");
       
    40 
       
    41 enum TUserResponse
       
    42     {
       
    43     EUserAccept,
       
    44     EUserDeny,
       
    45     };
       
    46 
    39 
    47 // -----------------------------------------------------------------------------
    40 // -----------------------------------------------------------------------------
    48 // RAttributeContainer::AppendL()
    41 // RAttributeContainer::AppendL()
    49 // -----------------------------------------------------------------------------
    42 // -----------------------------------------------------------------------------
    50 //
    43 //
    60 	//set container properties
    53 	//set container properties
    61 	container->iAttribute = aAttribute;
    54 	container->iAttribute = aAttribute;
    62 	container->iAttributeType = aAttributeTypes; 
    55 	container->iAttributeType = aAttributeTypes; 
    63 
    56 
    64 	//append to list
    57 	//append to list
    65 	RArray<AttributeContainerHelper::TContainer*>::AppendL( container);
    58 	RArray::AppendL( container);
    66 		
    59 		
    67 	//remove from cleanup
    60 	//remove from cleanup
    68 	CleanupStack::Pop( 2, aAttribute);
    61 	CleanupStack::Pop( 2, aAttribute);
    69 }
    62 }
    70 
    63 
    80 		AttributeContainerHelper::TContainer * container = operator[]( i);
    73 		AttributeContainerHelper::TContainer * container = operator[]( i);
    81 		delete container->iAttribute;
    74 		delete container->iAttribute;
    82 		delete container;
    75 		delete container;
    83 	}
    76 	}
    84 	
    77 	
    85 	RArray<AttributeContainerHelper::TContainer*>::Close();
    78 	RArray::Close();
    86 }
    79 }
    87 
    80 
    88 
    81 
    89 
    82 
    90 // -----------------------------------------------------------------------------
    83 // -----------------------------------------------------------------------------
   751 	TDesC8& trustedSubject = attributeValue->Data()->Value();
   744 	TDesC8& trustedSubject = attributeValue->Data()->Value();
   752 
   745 
   753 	//resolve name and fingerprint
   746 	//resolve name and fingerprint
   754 	const TDesC8& name = iTrustedSession->CommonNameForSubjectL( trustedSubject, iUseEditedElements);
   747 	const TDesC8& name = iTrustedSession->CommonNameForSubjectL( trustedSubject, iUseEditedElements);
   755 	const TDesC8& fingerPrint = iTrustedSession->FingerPrintForSubjectL( trustedSubject, iUseEditedElements);
   748 	const TDesC8& fingerPrint = iTrustedSession->FingerPrintForSubjectL( trustedSubject, iUseEditedElements);
   756 	TPtrC8 ptr = fingerPrint.Left(4); // send only first 4 digits.
   749 
   757 	
       
   758 	RDEBUG_2("CPolicyProcessor::fingerPrint: %S", &fingerPrint);
       
   759 	RDEBUG_2("CPolicyProcessor::fingerPrint: %S", &ptr);
       
   760 	
       
   761 	RDEBUG8_2("CPolicyProcessor::fingerPrint: %S", &fingerPrint);
       
   762 	RDEBUG8_2("CPolicyProcessor::fingerPrint: %S", &ptr);
       
   763 	    
       
   764 	TUserResponse response = EUserDeny;
   750 	TUserResponse response = EUserDeny;
   765 
   751 
   766     CProcessorClient *client = new CProcessorClient();
   752 	if ( name.Length() && fingerPrint.Length())
   767     TInt res = client->LaunchDialog(ptr, name);
   753 	{
   768     
   754 		//create notifier
   769     if(res == 0)
   755 		RNotifier notifier;
   770         response = EUserAccept;
   756 		CleanupClosePushL( notifier);
   771     else
   757 		User::LeaveIfError( notifier.Connect() );
   772         response = EUserDeny;  
   758 		
   773 
   759 		//create parameter descriptor
       
   760 		TBuf8<100> responseBuf;
       
   761 		HBufC8 * data = HBufC8::NewLC( name.Length() + fingerPrint.Length() + 1);
       
   762 		TPtr8 ptr = data->Des();
       
   763 		ptr.Append(name);
       
   764 		ptr.Append(KDelimeterChar);
       
   765 		ptr.Append(fingerPrint.Left(4));
       
   766 
       
   767 		//create CAsyncHandler to Auto start/stop CActiveScheduler
       
   768 		CASyncHandler * async = CASyncHandler::NewLC();
       
   769 		notifier.StartNotifierAndGetResponse( async->GetRequestStatus(), KUidPolicyEngineUi, ptr, responseBuf);
       
   770 		
       
   771 		//Start CActiveScheduler and execute stop when request is completed
       
   772 		async->WaitForRequest();
       
   773 		CPolicyEngineServer::SetActiveSubSession( this);	
       
   774 
       
   775 		
       
   776 		if ( async->GetRequestStatus() > 0) //request pending...
       
   777 		{
       
   778 			notifier.CancelNotifier( KUidPolicyEngineUi);	
       
   779 		}
       
   780 		else
       
   781 		{
       
   782 			//Check response
       
   783 			if ( responseBuf == KUserAcceptMark)
       
   784 			{
       
   785 				RDEBUG("PolicyEngineServer: CPolicyProcessor user accept corporate policy!");
       
   786 				response = EUserAccept;
       
   787 			}
       
   788 		}
       
   789 		
       
   790 		CleanupStack::PopAndDestroy( 3, &notifier);	//notifier, data, CASyncHandler
       
   791 		
       
   792 		
       
   793 	}
   774 
   794 
   775 	MakeBooleanResponseL( response == EUserAccept, aResponseElement);
   795 	MakeBooleanResponseL( response == EUserAccept, aResponseElement);
   776 }
   796 }
   777 
   797 
   778 // -----------------------------------------------------------------------------
   798 // -----------------------------------------------------------------------------
   957 	
   977 	
   958 	MakeBooleanResponseL( iTrustedSession->CertificatedSession(), aResponseElement);
   978 	MakeBooleanResponseL( iTrustedSession->CertificatedSession(), aResponseElement);
   959 }
   979 }
   960 
   980 
   961 
   981 
   962 // -----------------------------------------------------------------------------
       
   963 // CProcessorClient::CProcessorClient()
       
   964 // -----------------------------------------------------------------------------
       
   965 //
       
   966 
       
   967 CProcessorClient::CProcessorClient()
       
   968     : CActive(EPriorityNormal)
       
   969     {
       
   970     CActiveScheduler::Add( this );
       
   971     iWait = new( ELeave ) CActiveSchedulerWait;
       
   972     iCompletionCode = KErrNone;
       
   973     }
       
   974 
       
   975 
       
   976 // -----------------------------------------------------------------------------
       
   977 // CProcessorClient::~CProcessorClient()
       
   978 // -----------------------------------------------------------------------------
       
   979 CProcessorClient::~CProcessorClient()
       
   980     {
       
   981     delete iWait;
       
   982     }
       
   983 
       
   984 
       
   985 // -----------------------------------------------------------------------------
       
   986 // CProcessorClient::DataReceived()
       
   987 // -----------------------------------------------------------------------------
       
   988 void CProcessorClient::DataReceived(CHbSymbianVariantMap& aData)
       
   989 {
       
   990     _LIT(KResponse, "keyResponse");
       
   991     const CHbSymbianVariant* key = aData.Get(KResponse);
       
   992         
       
   993     if(key)
       
   994     {
       
   995     TInt *res = key->Value<TInt>();
       
   996     iCompletionCode = *res;        
       
   997     iUserResponse = *res;
       
   998     }
       
   999 }
       
  1000 
       
  1001 
       
  1002 // -----------------------------------------------------------------------------
       
  1003 // CProcessorClient::DeviceDialogClosed()
       
  1004 // -----------------------------------------------------------------------------
       
  1005 void CProcessorClient::DeviceDialogClosed(TInt aCompletionCode)
       
  1006     {
       
  1007     iCompletionCode = aCompletionCode;
       
  1008     //iDevDialog->Cancel();
       
  1009     TRequestStatus* status(&iStatus);
       
  1010     User::RequestComplete(status, KErrNone);
       
  1011     }
       
  1012 
       
  1013 
       
  1014 // -----------------------------------------------------------------------------
       
  1015 // CProcessorClient::DoCancel()
       
  1016 // -----------------------------------------------------------------------------
       
  1017 void CProcessorClient::DoCancel()
       
  1018 {
       
  1019     if (iWait && iWait->IsStarted() && iWait->CanStopNow()) 
       
  1020     {
       
  1021         iCompletionCode = KErrCancel;
       
  1022         iWait->AsyncStop();
       
  1023     }  
       
  1024 }
       
  1025 
       
  1026 
       
  1027 // -----------------------------------------------------------------------------
       
  1028 // CProcessorClient::RunL()
       
  1029 // -----------------------------------------------------------------------------
       
  1030 void CProcessorClient::RunL()
       
  1031 {
       
  1032     if (iWait) 
       
  1033     {
       
  1034         iWait->AsyncStop();
       
  1035     }    
       
  1036 }
       
  1037 
       
  1038 
       
  1039 // -----------------------------------------------------------------------------
       
  1040 // CProcessorClient::LaunchDialog()
       
  1041 // -----------------------------------------------------------------------------
       
  1042 TInt CProcessorClient::LaunchDialog(const TDesC8& aFringerPrint,
       
  1043         const TDesC8& aServerName)
       
  1044     {
       
  1045     _LIT(KHbNotifier,"com.nokia.hb.policymanagementdialog/1.0");
       
  1046     _LIT(KFingerPrint, "fingerprint");
       
  1047     _LIT(KServerdisplayname, "serverdisplayname");
       
  1048 
       
  1049     RDEBUG_2("CPolicyProcessor::fingerPrint: %S", &aFringerPrint);
       
  1050     RDEBUG_2("CPolicyProcessor::fingerPrint: %S", &aServerName);
       
  1051 
       
  1052     CHbSymbianVariantMap* varMap = CHbSymbianVariantMap::NewL();
       
  1053     CleanupStack::PushL(varMap);
       
  1054 
       
  1055     TBuf<10> fingerBuf;
       
  1056     fingerBuf.Copy(aFringerPrint);
       
  1057 
       
  1058     TInt serverNameLen = aServerName.Length();
       
  1059     TBuf<50> serverName;
       
  1060     serverName.Copy(aServerName);
       
  1061 
       
  1062     RDEBUG_2("CPolicyProcessor::16 fingerPrint: %S", &fingerBuf);
       
  1063     RDEBUG_2("CPolicyProcessor::16 serverName : %S", &serverName);
       
  1064 
       
  1065     CHbSymbianVariant* fingerprintid = CHbSymbianVariant::NewL(&fingerBuf,
       
  1066             CHbSymbianVariant::EDes);
       
  1067 
       
  1068     CHbSymbianVariant* serverdisplayname = CHbSymbianVariant::NewL(
       
  1069             &serverName, CHbSymbianVariant::EDes);
       
  1070 
       
  1071     RDEBUG_2("CPolicyProcessor::fingerPrint: %S", &fingerprintid);
       
  1072     RDEBUG_2("CPolicyProcessor::fingerPrint: %S", &serverdisplayname);
       
  1073 
       
  1074     varMap->Add(KFingerPrint, fingerprintid);
       
  1075     varMap->Add(KServerdisplayname, serverdisplayname);
       
  1076 
       
  1077     iDevDialog = CHbDeviceDialogSymbian::NewL();
       
  1078     TInt err1 = iDevDialog->Show(KHbNotifier, *varMap, this);
       
  1079     TInt err = WaitUntilDeviceDialogClosed();
       
  1080 
       
  1081     CleanupStack::PopAndDestroy();
       
  1082 
       
  1083     if (iDevDialog)
       
  1084         {
       
  1085         iDevDialog->Cancel();
       
  1086         delete iDevDialog;
       
  1087         iDevDialog = NULL;
       
  1088         }
       
  1089     
       
  1090     if (err == 0)
       
  1091         {
       
  1092             LaunchTrustNotificationDialog(aServerName);
       
  1093          }
       
  1094     
       
  1095     return iUserResponse;
       
  1096     }
       
  1097 
       
  1098 
       
  1099 // -----------------------------------------------------------------------------
       
  1100 // CProcessorClient::WaitUntilDeviceDialogClosed()
       
  1101 // -----------------------------------------------------------------------------
       
  1102 TInt CProcessorClient::WaitUntilDeviceDialogClosed()
       
  1103     {
       
  1104     iCompletionCode = KErrInUse;
       
  1105     if (!IsActive() && iWait && !iWait->IsStarted())
       
  1106     {
       
  1107             iStatus = KRequestPending;
       
  1108             SetActive();
       
  1109             iWait->Start();
       
  1110             }
       
  1111     return iCompletionCode;
       
  1112     }
       
  1113 
       
  1114 void CProcessorClient::LaunchTrustNotificationDialog(const TDesC8& aServerName)
       
  1115 {
       
  1116     _LIT(KFileName, "deviceupdates_");
       
  1117     _LIT(KPath, "z:/resource/qt/translations/");
       
  1118     _LIT(KDialogIcon, "note_info.svg");
       
  1119     
       
  1120     TBool result = HbTextResolverSymbian::Init(KFileName, KPath);
       
  1121     
       
  1122     if (result) {
       
  1123         _LIT(KTrustEstablished,"txt_device_update_dpophead_trust_established");
       
  1124         _LIT(KServerID,"txt_deviceupdate_dpopinfo_trust_establised_with_1");
       
  1125         
       
  1126         HBufC* trustEstablishedText = HbTextResolverSymbian::LoadL(KTrustEstablished);
       
  1127         CleanupStack::PushL(trustEstablishedText);
       
  1128  
       
  1129         HBufC* serveridbuf = HBufC::NewLC(aServerName.Length());
       
  1130         TPtr serveridbufptr = serveridbuf->Des();
       
  1131         serveridbufptr.Copy(aServerName);
       
  1132    
       
  1133         HBufC* serverid = HbTextResolverSymbian::LoadL(KServerID,*serveridbuf);
       
  1134         CleanupStack::PushL(serverid);
       
  1135 
       
  1136         CHbDeviceNotificationDialogSymbian::NotificationL(KDialogIcon, *trustEstablishedText, *serverid);
       
  1137         
       
  1138         CleanupStack::PopAndDestroy(3); //trustEstablishedText,serveridbuf,serverid
       
  1139     }
       
  1140 }
       
  1141 
   982 
  1142 // -----------------------------------------------------------------------------
   983 // -----------------------------------------------------------------------------
  1143 // TCombiningAlgorith::TCombiningAlgorith()
   984 // TCombiningAlgorith::TCombiningAlgorith()
  1144 // -----------------------------------------------------------------------------
   985 // -----------------------------------------------------------------------------
  1145 //
   986 //