Debian Codegraph @

src/lib/object_store/SessionObjectStore.h

raw
1 /*
2 * Copyright (c) 2010 SURFnet bv
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*****************************************************************************
28 SessionObjectStore.h
29
30 The token class; a token is stored in a directory containing several files.
31 Each object is stored in a separate file and a token object is present that
32 has the token specific attributes
33 *****************************************************************************/
34
35 #ifndef _SOFTHSM_V2_SESSIONOBJECTSTORE_H
36 #define _SOFTHSM_V2_SESSIONOBJECTSTORE_H
37
38 #include "config.h"
39 #include "OSAttribute.h"
40 #include "SessionObject.h"
41 #include "MutexFactory.h"
42 #include "cryptoki.h"
43 #include <string>
44 #include <set>
45 #include <map>
46 #include <list>
47 #include <memory>
48
49 class SessionObjectStore
50 {
51 public:
52 // Constructor
53 SessionObjectStore();
54
55 // Return the total number of objects in the store
56 int getObjectCount();
57
58 // Insert the session objects into the given OSObject set
59 void getObjects(std::set<OSObject*> &inObjects);
60
61 // Insert the session objects for the given slotID into the given OSObject set
62 void getObjects(CK_SLOT_ID slotID, std::set<OSObject*> &inObjects);
63
64 // Create a new object
65 SessionObject* createObject(CK_SLOT_ID slotID, CK_SESSION_HANDLE hSession, bool isPrivate = false);
66
67 // Delete an object
68 bool deleteObject(SessionObject* object);
69
70 // Indicate that a session has been closed; invalidates all objects
71 // associated with this session.
72 void sessionClosed(CK_SESSION_HANDLE hSession);
73
74 // Indicate that for a token all sessions have been closed.
75 // Invalidates all objects associated with the token.
76 void allSessionsClosed(CK_SLOT_ID slotID);
77
78 // Indicate that a token has been logged out; invalidates all private
79 // objects associated with this token.
80 void tokenLoggedOut(CK_SLOT_ID slotID);
81
82 // Destructor
83 virtual ~SessionObjectStore();
84
85 // Clears the store; should be called when all sessions are closed
86 void clearStore();
87
88 private:
89 // The current objects in the store
90 std::set<SessionObject*> objects;
91
92 // All the objects ever kept in the store
93 std::set<SessionObject*> allObjects;
94
95 // The current list of files
96 std::set<std::string> currentFiles;
97
98 // For thread safeness
99 Mutex* storeMutex;
100 };
101
102 #endif // !_SOFTHSM_V2_SESSIONOBJECTSTORE_H
103