policymanagement/dmutilserver/src/DMUtilClient.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 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 "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: Implementation of policymanagement components
       
    15 *
       
    16 */
       
    17 /* DMUtilClient.cpp
       
    18 */
       
    19 
       
    20 #include <e32svr.h>
       
    21 #include <centralrepository.h>
       
    22 #include "PMUtilInternalCRKeys.h"
       
    23 #include "DMUtilClientServer.h"
       
    24 #include "DMUtilClient.h"
       
    25 #include "DMCert.h"
       
    26 #include "debug.h"
       
    27 
       
    28 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
    29 #include <e32property.h>
       
    30 const TUid KUidSmlSyncAgentCategory = { 0x10009F46 }; // temporary
       
    31 const TUint KHttpsServerCertificateKey = 1234; // temporary
       
    32 #else
       
    33 // nothing
       
    34 #endif
       
    35 
       
    36 // MACROS
       
    37 
       
    38 
       
    39 // Standard server startup code
       
    40 // 
       
    41 static TInt StartServer()
       
    42 	{
       
    43 	RDEBUG("DMUtilServer: Starting server...");
       
    44 	
       
    45 	const TUidType serverUid(KNullUid,KNullUid,KDMUtilServerUid);
       
    46 
       
    47 	// EPOC and EKA 2 is easy, we just create a new server process. Simultaneous
       
    48 	// launching of two such processes should be detected when the second one
       
    49 	// attempts to create the server object, failing with KErrAlreadyExists.
       
    50 	RProcess server;
       
    51 	//TInt r=server.Create(KHelloWorldServerImg,KNullDesC,serverUid);
       
    52 	TInt r=server.Create(KDMUtilServerImg,KNullDesC);
       
    53 
       
    54 	if (r!=KErrNone)
       
    55 		{
       
    56 		RDEBUG_2("DMUtilClient: server start failed %d",r);
       
    57 		return r;
       
    58 		}
       
    59 	TRequestStatus stat;
       
    60 	server.Rendezvous(stat);
       
    61 	if (stat!=KRequestPending)
       
    62 		server.Kill(0);		// abort startup
       
    63 	else
       
    64 		server.Resume();	// logon OK - start the server
       
    65 	RDEBUG("DMUtilClient: Started");
       
    66 	User::WaitForRequest(stat);		// wait for start or death
       
    67 	// we can't use the 'exit reason' if the server panicked as this
       
    68 	// is the panic 'reason' and may be '0' which cannot be distinguished
       
    69 	// from KErrNone
       
    70 	r=(server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
       
    71 	server.Close();
       
    72 	return r;
       
    73 	}
       
    74 
       
    75 // This is the standard retry pattern for server connection
       
    76 EXPORT_C TInt RDMUtil::Connect()
       
    77 	{
       
    78 	RDEBUG("RDMUtil::Connect - start");
       
    79 	TInt retry=2;
       
    80 	for (;;)
       
    81 		{
       
    82 		TInt r=CreateSession(KDMUtilServerName,TVersion(0,0,0),50);
       
    83 		if (r!=KErrNotFound && r!=KErrServerTerminated)
       
    84 			return r;
       
    85 		if (--retry==0)
       
    86 			return r;
       
    87 		r=StartServer();
       
    88 		if (r!=KErrNone && r!=KErrAlreadyExists)
       
    89 			return r;
       
    90 		}
       
    91 	}
       
    92 
       
    93 EXPORT_C void RDMUtil::Close()
       
    94 	{
       
    95 	RSessionBase::Close();  //basecall
       
    96 	}
       
    97 	
       
    98 	
       
    99 EXPORT_C TInt RDMUtil::RemoveACL( const TDesC8& aURI, TBool aRestoreDefaults)
       
   100 {
       
   101 	TPckg<TBool> par2Pack( aRestoreDefaults);	
       
   102 	
       
   103 	return SendReceive( ERemoveACL, TIpcArgs( &aURI, &par2Pack));			
       
   104 }
       
   105 
       
   106 EXPORT_C TInt RDMUtil::AddACLForNode( const TDesC8& aURI, const TACLDestination& aDestination, const TAclCommands& aCommandType)
       
   107 {
       
   108 	TPckg<TACLDestination> par2Pack( aDestination);	
       
   109 	TPckg<TAclCommands> par3Pack( aCommandType);	
       
   110 	
       
   111 	return SendReceive( EAddACL, TIpcArgs( &aURI, &par2Pack, &par3Pack));			
       
   112 	
       
   113 }
       
   114 
       
   115 EXPORT_C TInt RDMUtil::SetACLForNode( const TDesC8& aURI, const TACLDestination& aDestination, const TAclCommands& aCommandType)
       
   116 {
       
   117 	TPckg<TACLDestination> par2Pack( aDestination);	
       
   118 	TPckg<TAclCommands> par3Pack( aCommandType);	
       
   119 	
       
   120 	return SendReceive( ESetACL, TIpcArgs( &aURI, &par2Pack, &par3Pack));			
       
   121 }
       
   122 	
       
   123 EXPORT_C TInt RDMUtil::SetMngSessionCertificate( const TCertInfo& aCertInfo)
       
   124 {
       
   125 	TPckg<TCertInfo> certInfoPckg( aCertInfo);		
       
   126 	
       
   127 	return SendReceive( EMngSessionCertificate, TIpcArgs( &certInfoPckg));				
       
   128 }
       
   129 	
       
   130 
       
   131 
       
   132 EXPORT_C TInt RDMUtil::NewDMSession( const TCertInfo& aCertInfo, const TDesC8& aServerID)
       
   133 {
       
   134 	TPckg<TCertInfo> certInfoPckg( aCertInfo);		
       
   135 	
       
   136 	return SendReceive( ENewDMSession, TIpcArgs( &certInfoPckg, &aServerID));			
       
   137 }
       
   138 
       
   139 
       
   140 EXPORT_C TInt RDMUtil::Flush()
       
   141 {
       
   142 	return SendReceive( EFlush, TIpcArgs());
       
   143 }
       
   144 
       
   145 EXPORT_C TInt RDMUtil::UpdatePolicyMngStatusFlags( KPolicyMngStatusFlags aPolicyMngStatusFlags)
       
   146 {
       
   147 	TPckg<KPolicyMngStatusFlags> policyMngPckg( aPolicyMngStatusFlags);		
       
   148 	
       
   149 	return SendReceive( EUpdatePolicyMngStatusFlags, TIpcArgs( &policyMngPckg));	
       
   150 }
       
   151 
       
   152 EXPORT_C TInt RDMUtil::PerformRFS()
       
   153 {
       
   154 	return SendReceive( EPerformDMUtilRFS);	
       
   155 }
       
   156 
       
   157 
       
   158 
       
   159 EXPORT_C TInt RDMUtil::GetDMSessionCertInfo( TCertInfo &aCertInfo )
       
   160 {
       
   161     TPckg<TCertInfo> certp( aCertInfo );
       
   162     return SendReceive( EGetDMSessionCertInfo, TIpcArgs( &certp ) );
       
   163 }
       
   164 
       
   165 EXPORT_C TInt RDMUtil::GetDMSessionServerId( TDes8& aServerId )
       
   166 {
       
   167     return SendReceive( EGetDMSessionServerId, TIpcArgs( &aServerId ) );
       
   168 }
       
   169 
       
   170 EXPORT_C TInt RDMUtil::MarkMMCWipe()
       
   171 	{
       
   172 	return SendReceive( EMarkMMCWipe );
       
   173 	}
       
   174 
       
   175 EXPORT_C TInt RDMCert::Get( TCertInfo &aCertInfo )
       
   176 	{
       
   177 	TInt result = KErrNone;
       
   178 	TPckg<TCertInfo> certp( aCertInfo );
       
   179 	
       
   180 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   181 	result = RProperty::Get( KUidSmlSyncAgentCategory, KHttpsServerCertificateKey, certp );
       
   182 #else
       
   183 	TRAPD( err, 
       
   184 		{
       
   185 		CRepository* rep = CRepository::NewL( KCRUidPolicyManagementUtilInternalKeys );
       
   186 		CleanupStack::PushL( rep );
       
   187 		result = rep->Get( KSyncMLSessionCertificate, certp );
       
   188 		CleanupStack::PopAndDestroy( rep );
       
   189 		} );
       
   190 	if( err != KErrNone )
       
   191 		{
       
   192 		result = err;
       
   193 		}	
       
   194 #endif
       
   195 	
       
   196 	return result;
       
   197 	};
       
   198