1295009Sjkim/* crypto/store/str_meth.c */
2280297Sjkim/*
3280297Sjkim * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project
4280297Sjkim * 2003.
5160814Ssimon */
6160814Ssimon/* ====================================================================
7160814Ssimon * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.
8160814Ssimon *
9160814Ssimon * Redistribution and use in source and binary forms, with or without
10160814Ssimon * modification, are permitted provided that the following conditions
11160814Ssimon * are met:
12160814Ssimon *
13160814Ssimon * 1. Redistributions of source code must retain the above copyright
14280297Sjkim *    notice, this list of conditions and the following disclaimer.
15160814Ssimon *
16160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright
17160814Ssimon *    notice, this list of conditions and the following disclaimer in
18160814Ssimon *    the documentation and/or other materials provided with the
19160814Ssimon *    distribution.
20160814Ssimon *
21160814Ssimon * 3. All advertising materials mentioning features or use of this
22160814Ssimon *    software must display the following acknowledgment:
23160814Ssimon *    "This product includes software developed by the OpenSSL Project
24160814Ssimon *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25160814Ssimon *
26160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27160814Ssimon *    endorse or promote products derived from this software without
28160814Ssimon *    prior written permission. For written permission, please contact
29160814Ssimon *    openssl-core@openssl.org.
30160814Ssimon *
31160814Ssimon * 5. Products derived from this software may not be called "OpenSSL"
32160814Ssimon *    nor may "OpenSSL" appear in their names without prior written
33160814Ssimon *    permission of the OpenSSL Project.
34160814Ssimon *
35160814Ssimon * 6. Redistributions of any form whatsoever must retain the following
36160814Ssimon *    acknowledgment:
37160814Ssimon *    "This product includes software developed by the OpenSSL Project
38160814Ssimon *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39160814Ssimon *
40160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43160814Ssimon * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE.
52160814Ssimon * ====================================================================
53160814Ssimon *
54160814Ssimon * This product includes cryptographic software written by Eric Young
55160814Ssimon * (eay@cryptsoft.com).  This product includes software written by Tim
56160814Ssimon * Hudson (tjh@cryptsoft.com).
57160814Ssimon *
58160814Ssimon */
59160814Ssimon
60160814Ssimon#include <string.h>
61160814Ssimon#include <openssl/buffer.h>
62160814Ssimon#include "str_locl.h"
63160814Ssimon
64160814SsimonSTORE_METHOD *STORE_create_method(char *name)
65280297Sjkim{
66280297Sjkim    STORE_METHOD *store_method =
67280297Sjkim        (STORE_METHOD *)OPENSSL_malloc(sizeof(STORE_METHOD));
68160814Ssimon
69280297Sjkim    if (store_method) {
70280297Sjkim        memset(store_method, 0, sizeof(*store_method));
71280297Sjkim        store_method->name = BUF_strdup(name);
72280297Sjkim    }
73280297Sjkim    return store_method;
74280297Sjkim}
75160814Ssimon
76280297Sjkim/*
77280297Sjkim * BIG FSCKING WARNING!!!! If you use this on a statically allocated method
78280297Sjkim * (that is, it hasn't been allocated using STORE_create_method(), you
79280297Sjkim * deserve anything Murphy can throw at you and more! You have been warned.
80280297Sjkim */
81160814Ssimonvoid STORE_destroy_method(STORE_METHOD *store_method)
82280297Sjkim{
83280297Sjkim    if (!store_method)
84280297Sjkim        return;
85280297Sjkim    OPENSSL_free(store_method->name);
86280297Sjkim    store_method->name = NULL;
87280297Sjkim    OPENSSL_free(store_method);
88280297Sjkim}
89160814Ssimon
90280297Sjkimint STORE_method_set_initialise_function(STORE_METHOD *sm,
91280297Sjkim                                         STORE_INITIALISE_FUNC_PTR init_f)
92280297Sjkim{
93280297Sjkim    sm->init = init_f;
94280297Sjkim    return 1;
95280297Sjkim}
96160814Ssimon
97280297Sjkimint STORE_method_set_cleanup_function(STORE_METHOD *sm,
98280297Sjkim                                      STORE_CLEANUP_FUNC_PTR clean_f)
99280297Sjkim{
100280297Sjkim    sm->clean = clean_f;
101280297Sjkim    return 1;
102280297Sjkim}
103160814Ssimon
104280297Sjkimint STORE_method_set_generate_function(STORE_METHOD *sm,
105280297Sjkim                                       STORE_GENERATE_OBJECT_FUNC_PTR
106280297Sjkim                                       generate_f)
107280297Sjkim{
108280297Sjkim    sm->generate_object = generate_f;
109280297Sjkim    return 1;
110280297Sjkim}
111160814Ssimon
112280297Sjkimint STORE_method_set_get_function(STORE_METHOD *sm,
113280297Sjkim                                  STORE_GET_OBJECT_FUNC_PTR get_f)
114280297Sjkim{
115280297Sjkim    sm->get_object = get_f;
116280297Sjkim    return 1;
117280297Sjkim}
118160814Ssimon
119280297Sjkimint STORE_method_set_store_function(STORE_METHOD *sm,
120280297Sjkim                                    STORE_STORE_OBJECT_FUNC_PTR store_f)
121280297Sjkim{
122280297Sjkim    sm->store_object = store_f;
123280297Sjkim    return 1;
124280297Sjkim}
125160814Ssimon
126280297Sjkimint STORE_method_set_modify_function(STORE_METHOD *sm,
127280297Sjkim                                     STORE_MODIFY_OBJECT_FUNC_PTR modify_f)
128280297Sjkim{
129280297Sjkim    sm->modify_object = modify_f;
130280297Sjkim    return 1;
131280297Sjkim}
132160814Ssimon
133280297Sjkimint STORE_method_set_revoke_function(STORE_METHOD *sm,
134280297Sjkim                                     STORE_HANDLE_OBJECT_FUNC_PTR revoke_f)
135280297Sjkim{
136280297Sjkim    sm->revoke_object = revoke_f;
137280297Sjkim    return 1;
138280297Sjkim}
139160814Ssimon
140280297Sjkimint STORE_method_set_delete_function(STORE_METHOD *sm,
141280297Sjkim                                     STORE_HANDLE_OBJECT_FUNC_PTR delete_f)
142280297Sjkim{
143280297Sjkim    sm->delete_object = delete_f;
144280297Sjkim    return 1;
145280297Sjkim}
146160814Ssimon
147280297Sjkimint STORE_method_set_list_start_function(STORE_METHOD *sm,
148280297Sjkim                                         STORE_START_OBJECT_FUNC_PTR
149280297Sjkim                                         list_start_f)
150280297Sjkim{
151280297Sjkim    sm->list_object_start = list_start_f;
152280297Sjkim    return 1;
153280297Sjkim}
154160814Ssimon
155280297Sjkimint STORE_method_set_list_next_function(STORE_METHOD *sm,
156280297Sjkim                                        STORE_NEXT_OBJECT_FUNC_PTR
157280297Sjkim                                        list_next_f)
158280297Sjkim{
159280297Sjkim    sm->list_object_next = list_next_f;
160280297Sjkim    return 1;
161280297Sjkim}
162160814Ssimon
163280297Sjkimint STORE_method_set_list_end_function(STORE_METHOD *sm,
164280297Sjkim                                       STORE_END_OBJECT_FUNC_PTR list_end_f)
165280297Sjkim{
166280297Sjkim    sm->list_object_end = list_end_f;
167280297Sjkim    return 1;
168280297Sjkim}
169160814Ssimon
170280297Sjkimint STORE_method_set_update_store_function(STORE_METHOD *sm,
171280297Sjkim                                           STORE_GENERIC_FUNC_PTR update_f)
172280297Sjkim{
173280297Sjkim    sm->update_store = update_f;
174280297Sjkim    return 1;
175280297Sjkim}
176160814Ssimon
177280297Sjkimint STORE_method_set_lock_store_function(STORE_METHOD *sm,
178280297Sjkim                                         STORE_GENERIC_FUNC_PTR lock_f)
179280297Sjkim{
180280297Sjkim    sm->lock_store = lock_f;
181280297Sjkim    return 1;
182280297Sjkim}
183160814Ssimon
184280297Sjkimint STORE_method_set_unlock_store_function(STORE_METHOD *sm,
185280297Sjkim                                           STORE_GENERIC_FUNC_PTR unlock_f)
186280297Sjkim{
187280297Sjkim    sm->unlock_store = unlock_f;
188280297Sjkim    return 1;
189280297Sjkim}
190160814Ssimon
191280297Sjkimint STORE_method_set_ctrl_function(STORE_METHOD *sm,
192280297Sjkim                                   STORE_CTRL_FUNC_PTR ctrl_f)
193280297Sjkim{
194280297Sjkim    sm->ctrl = ctrl_f;
195280297Sjkim    return 1;
196280297Sjkim}
197160814Ssimon
198280297SjkimSTORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD
199280297Sjkim                                                               *sm)
200280297Sjkim{
201280297Sjkim    return sm->init;
202280297Sjkim}
203160814Ssimon
204160814SsimonSTORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm)
205280297Sjkim{
206280297Sjkim    return sm->clean;
207280297Sjkim}
208160814Ssimon
209280297SjkimSTORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD
210280297Sjkim                                                                  *sm)
211280297Sjkim{
212280297Sjkim    return sm->generate_object;
213280297Sjkim}
214160814Ssimon
215160814SsimonSTORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm)
216280297Sjkim{
217280297Sjkim    return sm->get_object;
218280297Sjkim}
219160814Ssimon
220160814SsimonSTORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm)
221280297Sjkim{
222280297Sjkim    return sm->store_object;
223280297Sjkim}
224160814Ssimon
225280297SjkimSTORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD
226280297Sjkim                                                              *sm)
227280297Sjkim{
228280297Sjkim    return sm->modify_object;
229280297Sjkim}
230160814Ssimon
231280297SjkimSTORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD
232280297Sjkim                                                              *sm)
233280297Sjkim{
234280297Sjkim    return sm->revoke_object;
235280297Sjkim}
236160814Ssimon
237280297SjkimSTORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD
238280297Sjkim                                                              *sm)
239280297Sjkim{
240280297Sjkim    return sm->delete_object;
241280297Sjkim}
242160814Ssimon
243280297SjkimSTORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD
244280297Sjkim                                                                 *sm)
245280297Sjkim{
246280297Sjkim    return sm->list_object_start;
247280297Sjkim}
248160814Ssimon
249280297SjkimSTORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD
250280297Sjkim                                                               *sm)
251280297Sjkim{
252280297Sjkim    return sm->list_object_next;
253280297Sjkim}
254160814Ssimon
255160814SsimonSTORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm)
256280297Sjkim{
257280297Sjkim    return sm->list_object_end;
258280297Sjkim}
259160814Ssimon
260280297SjkimSTORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD
261280297Sjkim                                                              *sm)
262280297Sjkim{
263280297Sjkim    return sm->update_store;
264280297Sjkim}
265160814Ssimon
266160814SsimonSTORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm)
267280297Sjkim{
268280297Sjkim    return sm->lock_store;
269280297Sjkim}
270160814Ssimon
271280297SjkimSTORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD
272280297Sjkim                                                              *sm)
273280297Sjkim{
274280297Sjkim    return sm->unlock_store;
275280297Sjkim}
276160814Ssimon
277160814SsimonSTORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm)
278280297Sjkim{
279280297Sjkim    return sm->ctrl;
280280297Sjkim}
281