|
1 /* |
|
2 * Copyright (c) 2004-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "clientsession.h" |
|
20 #include <e32std.h> |
|
21 #include <e32uid.h> |
|
22 #include "clientutils.h" |
|
23 #include "fstokenservername.h" |
|
24 |
|
25 |
|
26 // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ |
|
27 // Tokentype session class for file based certificate store |
|
28 // Connects and passes messages to the file store tokentype server |
|
29 // Coded specifically for file store token type |
|
30 // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ |
|
31 |
|
32 _LIT(KFSTokenServerImg,"fstokenserver"); |
|
33 |
|
34 RFileStoreClientSession::RFileStoreClientSession() |
|
35 {} |
|
36 |
|
37 TInt RFileStoreClientSession::SendRequest(TFSTokenMessages aRequest, const TIpcArgs& aArgs) const |
|
38 { |
|
39 return SendReceive(aRequest, aArgs); |
|
40 } |
|
41 |
|
42 void RFileStoreClientSession::SendAsyncRequest(TFSTokenMessages aRequest, const TIpcArgs& aArgs, TRequestStatus* aStatus) const |
|
43 { |
|
44 __ASSERT_ALWAYS(aStatus, FSTokenPanic(EBadArgument)); |
|
45 |
|
46 if (aStatus) |
|
47 { |
|
48 *aStatus = KRequestPending; |
|
49 SendReceive(aRequest, aArgs, *aStatus); |
|
50 } |
|
51 } |
|
52 |
|
53 |
|
54 // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ |
|
55 // Client-server startup code |
|
56 // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ // \\ |
|
57 |
|
58 static TInt StartServer(); // Forward declaration |
|
59 // |
|
60 // Connect to the server, attempting to start it if necessary |
|
61 // |
|
62 TInt RFileStoreClientSession::Connect(ETokenEnum aToken) |
|
63 { |
|
64 // The version is made up of three pieces of information: |
|
65 // 1. iMajor - The token we want to talk to |
|
66 // 2. iMinor - The protocol version number |
|
67 // 3. iBuild - unused |
|
68 TVersion version(aToken, KFSProtolVersion, 0); |
|
69 |
|
70 TInt retry=2; |
|
71 for (;;) |
|
72 { |
|
73 TInt r=CreateSession(KFSTokenServerName, version, 1); |
|
74 if (r!=KErrNotFound && r!=KErrServerTerminated) |
|
75 return r; |
|
76 if (--retry==0) |
|
77 return r; |
|
78 r=StartServer(); |
|
79 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
80 return r; |
|
81 } |
|
82 } |
|
83 |
|
84 TInt StartServer() |
|
85 { |
|
86 // Server startup is different for WINS in EKA1 mode ONLY (lack of process |
|
87 // emulation - we load the library in this instance |
|
88 const TUidType serverUid(KNullUid, KNullUid, KUidFSTokenServer); |
|
89 |
|
90 RProcess server; |
|
91 TInt r = server.Create(KFSTokenServerImg, KNullDesC, serverUid); |
|
92 |
|
93 if (r != KErrNone) |
|
94 { |
|
95 return r; |
|
96 } |
|
97 |
|
98 // Synchronise with the process to make sure it hasn't died straight away |
|
99 TRequestStatus stat; |
|
100 server.Rendezvous(stat); |
|
101 if (stat != KRequestPending) |
|
102 { |
|
103 // logon failed - server is not yet running, so cannot have terminated |
|
104 server.Kill(0); // Abort startup |
|
105 } |
|
106 else |
|
107 { |
|
108 // logon OK - start the server |
|
109 server.Resume(); |
|
110 } |
|
111 |
|
112 // Wait to synchronise with server - if it dies in the meantime, it |
|
113 // also gets completed |
|
114 User::WaitForRequest(stat); |
|
115 |
|
116 // We can't use the 'exit reason' if the server panicked as this |
|
117 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
118 // from KErrNone |
|
119 r = (server.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); |
|
120 server.Close(); |
|
121 return (r); |
|
122 } |