1160814Ssimon/* crypto/store/str_meth.c -*- mode:C; c-file-style: "eay" -*- */ 2296341Sdelphij/* 3296341Sdelphij * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project 4296341Sdelphij * 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 14296341Sdelphij * 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) 65296341Sdelphij{ 66296341Sdelphij STORE_METHOD *store_method = 67296341Sdelphij (STORE_METHOD *)OPENSSL_malloc(sizeof(STORE_METHOD)); 68160814Ssimon 69296341Sdelphij if (store_method) { 70296341Sdelphij memset(store_method, 0, sizeof(*store_method)); 71296341Sdelphij store_method->name = BUF_strdup(name); 72296341Sdelphij } 73296341Sdelphij return store_method; 74296341Sdelphij} 75160814Ssimon 76296341Sdelphij/* 77296341Sdelphij * BIG FSCKING WARNING!!!! If you use this on a statically allocated method 78296341Sdelphij * (that is, it hasn't been allocated using STORE_create_method(), you 79296341Sdelphij * deserve anything Murphy can throw at you and more! You have been warned. 80296341Sdelphij */ 81160814Ssimonvoid STORE_destroy_method(STORE_METHOD *store_method) 82296341Sdelphij{ 83296341Sdelphij if (!store_method) 84296341Sdelphij return; 85296341Sdelphij OPENSSL_free(store_method->name); 86296341Sdelphij store_method->name = NULL; 87296341Sdelphij OPENSSL_free(store_method); 88296341Sdelphij} 89160814Ssimon 90296341Sdelphijint STORE_method_set_initialise_function(STORE_METHOD *sm, 91296341Sdelphij STORE_INITIALISE_FUNC_PTR init_f) 92296341Sdelphij{ 93296341Sdelphij sm->init = init_f; 94296341Sdelphij return 1; 95296341Sdelphij} 96160814Ssimon 97296341Sdelphijint STORE_method_set_cleanup_function(STORE_METHOD *sm, 98296341Sdelphij STORE_CLEANUP_FUNC_PTR clean_f) 99296341Sdelphij{ 100296341Sdelphij sm->clean = clean_f; 101296341Sdelphij return 1; 102296341Sdelphij} 103160814Ssimon 104296341Sdelphijint STORE_method_set_generate_function(STORE_METHOD *sm, 105296341Sdelphij STORE_GENERATE_OBJECT_FUNC_PTR 106296341Sdelphij generate_f) 107296341Sdelphij{ 108296341Sdelphij sm->generate_object = generate_f; 109296341Sdelphij return 1; 110296341Sdelphij} 111160814Ssimon 112296341Sdelphijint STORE_method_set_get_function(STORE_METHOD *sm, 113296341Sdelphij STORE_GET_OBJECT_FUNC_PTR get_f) 114296341Sdelphij{ 115296341Sdelphij sm->get_object = get_f; 116296341Sdelphij return 1; 117296341Sdelphij} 118160814Ssimon 119296341Sdelphijint STORE_method_set_store_function(STORE_METHOD *sm, 120296341Sdelphij STORE_STORE_OBJECT_FUNC_PTR store_f) 121296341Sdelphij{ 122296341Sdelphij sm->store_object = store_f; 123296341Sdelphij return 1; 124296341Sdelphij} 125160814Ssimon 126296341Sdelphijint STORE_method_set_modify_function(STORE_METHOD *sm, 127296341Sdelphij STORE_MODIFY_OBJECT_FUNC_PTR modify_f) 128296341Sdelphij{ 129296341Sdelphij sm->modify_object = modify_f; 130296341Sdelphij return 1; 131296341Sdelphij} 132160814Ssimon 133296341Sdelphijint STORE_method_set_revoke_function(STORE_METHOD *sm, 134296341Sdelphij STORE_HANDLE_OBJECT_FUNC_PTR revoke_f) 135296341Sdelphij{ 136296341Sdelphij sm->revoke_object = revoke_f; 137296341Sdelphij return 1; 138296341Sdelphij} 139160814Ssimon 140296341Sdelphijint STORE_method_set_delete_function(STORE_METHOD *sm, 141296341Sdelphij STORE_HANDLE_OBJECT_FUNC_PTR delete_f) 142296341Sdelphij{ 143296341Sdelphij sm->delete_object = delete_f; 144296341Sdelphij return 1; 145296341Sdelphij} 146160814Ssimon 147296341Sdelphijint STORE_method_set_list_start_function(STORE_METHOD *sm, 148296341Sdelphij STORE_START_OBJECT_FUNC_PTR 149296341Sdelphij list_start_f) 150296341Sdelphij{ 151296341Sdelphij sm->list_object_start = list_start_f; 152296341Sdelphij return 1; 153296341Sdelphij} 154160814Ssimon 155296341Sdelphijint STORE_method_set_list_next_function(STORE_METHOD *sm, 156296341Sdelphij STORE_NEXT_OBJECT_FUNC_PTR 157296341Sdelphij list_next_f) 158296341Sdelphij{ 159296341Sdelphij sm->list_object_next = list_next_f; 160296341Sdelphij return 1; 161296341Sdelphij} 162160814Ssimon 163296341Sdelphijint STORE_method_set_list_end_function(STORE_METHOD *sm, 164296341Sdelphij STORE_END_OBJECT_FUNC_PTR list_end_f) 165296341Sdelphij{ 166296341Sdelphij sm->list_object_end = list_end_f; 167296341Sdelphij return 1; 168296341Sdelphij} 169160814Ssimon 170296341Sdelphijint STORE_method_set_update_store_function(STORE_METHOD *sm, 171296341Sdelphij STORE_GENERIC_FUNC_PTR update_f) 172296341Sdelphij{ 173296341Sdelphij sm->update_store = update_f; 174296341Sdelphij return 1; 175296341Sdelphij} 176160814Ssimon 177296341Sdelphijint STORE_method_set_lock_store_function(STORE_METHOD *sm, 178296341Sdelphij STORE_GENERIC_FUNC_PTR lock_f) 179296341Sdelphij{ 180296341Sdelphij sm->lock_store = lock_f; 181296341Sdelphij return 1; 182296341Sdelphij} 183160814Ssimon 184296341Sdelphijint STORE_method_set_unlock_store_function(STORE_METHOD *sm, 185296341Sdelphij STORE_GENERIC_FUNC_PTR unlock_f) 186296341Sdelphij{ 187296341Sdelphij sm->unlock_store = unlock_f; 188296341Sdelphij return 1; 189296341Sdelphij} 190160814Ssimon 191296341Sdelphijint STORE_method_set_ctrl_function(STORE_METHOD *sm, 192296341Sdelphij STORE_CTRL_FUNC_PTR ctrl_f) 193296341Sdelphij{ 194296341Sdelphij sm->ctrl = ctrl_f; 195296341Sdelphij return 1; 196296341Sdelphij} 197160814Ssimon 198296341SdelphijSTORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD 199296341Sdelphij *sm) 200296341Sdelphij{ 201296341Sdelphij return sm->init; 202296341Sdelphij} 203160814Ssimon 204160814SsimonSTORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm) 205296341Sdelphij{ 206296341Sdelphij return sm->clean; 207296341Sdelphij} 208160814Ssimon 209296341SdelphijSTORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD 210296341Sdelphij *sm) 211296341Sdelphij{ 212296341Sdelphij return sm->generate_object; 213296341Sdelphij} 214160814Ssimon 215160814SsimonSTORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm) 216296341Sdelphij{ 217296341Sdelphij return sm->get_object; 218296341Sdelphij} 219160814Ssimon 220160814SsimonSTORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm) 221296341Sdelphij{ 222296341Sdelphij return sm->store_object; 223296341Sdelphij} 224160814Ssimon 225296341SdelphijSTORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD 226296341Sdelphij *sm) 227296341Sdelphij{ 228296341Sdelphij return sm->modify_object; 229296341Sdelphij} 230160814Ssimon 231296341SdelphijSTORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD 232296341Sdelphij *sm) 233296341Sdelphij{ 234296341Sdelphij return sm->revoke_object; 235296341Sdelphij} 236160814Ssimon 237296341SdelphijSTORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD 238296341Sdelphij *sm) 239296341Sdelphij{ 240296341Sdelphij return sm->delete_object; 241296341Sdelphij} 242160814Ssimon 243296341SdelphijSTORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD 244296341Sdelphij *sm) 245296341Sdelphij{ 246296341Sdelphij return sm->list_object_start; 247296341Sdelphij} 248160814Ssimon 249296341SdelphijSTORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD 250296341Sdelphij *sm) 251296341Sdelphij{ 252296341Sdelphij return sm->list_object_next; 253296341Sdelphij} 254160814Ssimon 255160814SsimonSTORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm) 256296341Sdelphij{ 257296341Sdelphij return sm->list_object_end; 258296341Sdelphij} 259160814Ssimon 260296341SdelphijSTORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD 261296341Sdelphij *sm) 262296341Sdelphij{ 263296341Sdelphij return sm->update_store; 264296341Sdelphij} 265160814Ssimon 266160814SsimonSTORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm) 267296341Sdelphij{ 268296341Sdelphij return sm->lock_store; 269296341Sdelphij} 270160814Ssimon 271296341SdelphijSTORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD 272296341Sdelphij *sm) 273296341Sdelphij{ 274296341Sdelphij return sm->unlock_store; 275296341Sdelphij} 276160814Ssimon 277160814SsimonSTORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm) 278296341Sdelphij{ 279296341Sdelphij return sm->ctrl; 280296341Sdelphij} 281