1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 /*
6  *  JARNAV.C
7  *
8  *  JAR stuff needed for client only.
9  *
10  */
11 
12 #include "jar.h"
13 #include "jarint.h"
14 
15 /* from proto.h */
16 extern MWContext *FE_GetInitContext(void);
17 
18 /* To return an MWContext for Java */
19 static MWContext *(*jar_fn_FindSomeContext)(void) = NULL;
20 
21 /* To fabricate an MWContext for FE_GetPassword */
22 static MWContext *(*jar_fn_GetInitContext)(void) = NULL;
23 
24 /*
25  *  J A R _ i n i t
26  *
27  *  Initialize the JAR functions.
28  *
29  */
30 
31 void
JAR_init(void)32 JAR_init(void)
33 {
34     JAR_init_callbacks(XP_GetString, NULL, NULL);
35 }
36 
37 /*
38  *  J A R _ s e t _ c o n t e x t
39  *
40  *  Set the jar window context for use by PKCS11, since
41  *  it may be needed to prompt the user for a password.
42  *
43  */
44 int
JAR_set_context(JAR * jar,MWContext * mw)45 JAR_set_context(JAR *jar, MWContext *mw)
46 {
47     if (mw) {
48         jar->mw = mw;
49     } else {
50         /* jar->mw = XP_FindSomeContext(); */
51         jar->mw = NULL;
52         /*
53          * We can't find a context because we're in startup state and none
54          * exist yet. go get an FE_InitContext that only works at
55          * initialization time.
56          */
57         /* Turn on the mac when we get the FE_ function */
58         if (jar->mw == NULL) {
59             jar->mw = jar_fn_GetInitContext();
60         }
61     }
62     return 0;
63 }
64