summaryrefslogtreecommitdiffstats
path: root/security/nss/lib/ckfw/dbm/ckdbm.h
blob: 8c2607cb35593d72e92c1b6c3b03d78f598e15e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef CKDBM_H
#define CKDBM_H

#include "nssckmdt.h"
#include "nssckfw.h"

/*
 * I'm including this for access to the arena functions.
 * Looks like we should publish that API.
 */
#ifndef BASE_H
#include "base.h"
#endif /* BASE_H */

/*
 * This is where the Netscape extensions live, at least for now.
 */
#ifndef CKT_H
#include "ckt.h"
#endif /* CKT_H */

#include "mcom_db.h"

NSS_EXTERN_DATA NSSCKMDInstance nss_dbm_mdInstance;

typedef struct nss_dbm_db_struct nss_dbm_db_t;
struct nss_dbm_db_struct {
    DB *db;
    NSSCKFWMutex *crustylock;
};

typedef struct nss_dbm_dbt_struct nss_dbm_dbt_t;
struct nss_dbm_dbt_struct {
    DBT dbt;
    nss_dbm_db_t *my_db;
};

typedef struct nss_dbm_instance_struct nss_dbm_instance_t;
struct nss_dbm_instance_struct {
    NSSArena *arena;
    CK_ULONG nSlots;
    char **filenames;
    int *flags; /* e.g. O_RDONLY, O_RDWR */
};

typedef struct nss_dbm_slot_struct nss_dbm_slot_t;
struct nss_dbm_slot_struct {
    nss_dbm_instance_t *instance;
    char *filename;
    int flags;
    nss_dbm_db_t *token_db;
};

typedef struct nss_dbm_token_struct nss_dbm_token_t;
struct nss_dbm_token_struct {
    NSSArena *arena;
    nss_dbm_slot_t *slot;
    nss_dbm_db_t *session_db;
    NSSUTF8 *label;
};

struct nss_dbm_dbt_node {
    struct nss_dbm_dbt_node *next;
    nss_dbm_dbt_t *dbt;
};

typedef struct nss_dbm_session_struct nss_dbm_session_t;
struct nss_dbm_session_struct {
    NSSArena *arena;
    nss_dbm_token_t *token;
    CK_ULONG deviceError;
    struct nss_dbm_dbt_node *session_objects;
    NSSCKFWMutex *list_lock;
};

typedef struct nss_dbm_object_struct nss_dbm_object_t;
struct nss_dbm_object_struct {
    NSSArena *arena; /* token or session */
    nss_dbm_dbt_t *handle;
};

typedef struct nss_dbm_find_struct nss_dbm_find_t;
struct nss_dbm_find_struct {
    NSSArena *arena;
    struct nss_dbm_dbt_node *found;
    NSSCKFWMutex *list_lock;
};

NSS_EXTERN NSSCKMDSlot *
nss_dbm_mdSlot_factory(
    nss_dbm_instance_t *instance,
    char *filename,
    int flags,
    CK_RV *pError);

NSS_EXTERN NSSCKMDToken *
nss_dbm_mdToken_factory(
    nss_dbm_slot_t *slot,
    CK_RV *pError);

NSS_EXTERN NSSCKMDSession *
nss_dbm_mdSession_factory(
    nss_dbm_token_t *token,
    NSSCKFWSession *fwSession,
    NSSCKFWInstance *fwInstance,
    CK_BBOOL rw,
    CK_RV *pError);

NSS_EXTERN NSSCKMDObject *
nss_dbm_mdObject_factory(
    nss_dbm_object_t *object,
    CK_RV *pError);

NSS_EXTERN NSSCKMDFindObjects *
nss_dbm_mdFindObjects_factory(
    nss_dbm_find_t *find,
    CK_RV *pError);

NSS_EXTERN nss_dbm_db_t *
nss_dbm_db_open(
    NSSArena *arena,
    NSSCKFWInstance *fwInstance,
    char *filename,
    int flags,
    CK_RV *pError);

NSS_EXTERN void
nss_dbm_db_close(
    nss_dbm_db_t *db);

NSS_EXTERN CK_VERSION
nss_dbm_db_get_format_version(
    nss_dbm_db_t *db);

NSS_EXTERN CK_RV
nss_dbm_db_set_label(
    nss_dbm_db_t *db,
    NSSUTF8 *label);

NSS_EXTERN NSSUTF8 *
nss_dbm_db_get_label(
    nss_dbm_db_t *db,
    NSSArena *arena,
    CK_RV *pError);

NSS_EXTERN CK_RV
nss_dbm_db_delete_object(
    nss_dbm_dbt_t *dbt);

NSS_EXTERN nss_dbm_dbt_t *
nss_dbm_db_create_object(
    NSSArena *arena,
    nss_dbm_db_t *db,
    CK_ATTRIBUTE_PTR pTemplate,
    CK_ULONG ulAttributeCount,
    CK_RV *pError,
    CK_ULONG *pdbrv);

NSS_EXTERN CK_RV
nss_dbm_db_find_objects(
    nss_dbm_find_t *find,
    nss_dbm_db_t *db,
    CK_ATTRIBUTE_PTR pTemplate,
    CK_ULONG ulAttributeCount,
    CK_ULONG *pdbrv);

NSS_EXTERN CK_BBOOL
nss_dbm_db_object_still_exists(
    nss_dbm_dbt_t *dbt);

NSS_EXTERN CK_ULONG
nss_dbm_db_get_object_attribute_count(
    nss_dbm_dbt_t *dbt,
    CK_RV *pError,
    CK_ULONG *pdbrv);

NSS_EXTERN CK_RV
nss_dbm_db_get_object_attribute_types(
    nss_dbm_dbt_t *dbt,
    CK_ATTRIBUTE_TYPE_PTR typeArray,
    CK_ULONG ulCount,
    CK_ULONG *pdbrv);

NSS_EXTERN CK_ULONG
nss_dbm_db_get_object_attribute_size(
    nss_dbm_dbt_t *dbt,
    CK_ATTRIBUTE_TYPE type,
    CK_RV *pError,
    CK_ULONG *pdbrv);

NSS_EXTERN NSSItem *
nss_dbm_db_get_object_attribute(
    nss_dbm_dbt_t *dbt,
    NSSArena *arena,
    CK_ATTRIBUTE_TYPE type,
    CK_RV *pError,
    CK_ULONG *pdbrv);

NSS_EXTERN CK_RV
nss_dbm_db_set_object_attribute(
    nss_dbm_dbt_t *dbt,
    CK_ATTRIBUTE_TYPE type,
    NSSItem *value,
    CK_ULONG *pdbrv);

#endif /* CKDBM_H */