1160814Ssimon/* crypto/store/str_meth.c -*- mode:C; c-file-style: "eay" -*- */ 2296465Sdelphij/* 3296465Sdelphij * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project 4296465Sdelphij * 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 14296465Sdelphij * 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) 65296465Sdelphij{ 66296465Sdelphij STORE_METHOD *store_method = 67296465Sdelphij (STORE_METHOD *)OPENSSL_malloc(sizeof(STORE_METHOD)); 68160814Ssimon 69296465Sdelphij if (store_method) { 70296465Sdelphij memset(store_method, 0, sizeof(*store_method)); 71296465Sdelphij store_method->name = BUF_strdup(name); 72296465Sdelphij } 73296465Sdelphij return store_method; 74296465Sdelphij} 75160814Ssimon 76296465Sdelphij/* 77296465Sdelphij * BIG FSCKING WARNING!!!! If you use this on a statically allocated method 78296465Sdelphij * (that is, it hasn't been allocated using STORE_create_method(), you 79296465Sdelphij * deserve anything Murphy can throw at you and more! You have been warned. 80296465Sdelphij */ 81160814Ssimonvoid STORE_destroy_method(STORE_METHOD *store_method) 82296465Sdelphij{ 83296465Sdelphij if (!store_method) 84296465Sdelphij return; 85296465Sdelphij OPENSSL_free(store_method->name); 86296465Sdelphij store_method->name = NULL; 87296465Sdelphij OPENSSL_free(store_method); 88296465Sdelphij} 89160814Ssimon 90296465Sdelphijint STORE_method_set_initialise_function(STORE_METHOD *sm, 91296465Sdelphij STORE_INITIALISE_FUNC_PTR init_f) 92296465Sdelphij{ 93296465Sdelphij sm->init = init_f; 94296465Sdelphij return 1; 95296465Sdelphij} 96160814Ssimon 97296465Sdelphijint STORE_method_set_cleanup_function(STORE_METHOD *sm, 98296465Sdelphij STORE_CLEANUP_FUNC_PTR clean_f) 99296465Sdelphij{ 100296465Sdelphij sm->clean = clean_f; 101296465Sdelphij return 1; 102296465Sdelphij} 103160814Ssimon 104296465Sdelphijint STORE_method_set_generate_function(STORE_METHOD *sm, 105296465Sdelphij STORE_GENERATE_OBJECT_FUNC_PTR 106296465Sdelphij generate_f) 107296465Sdelphij{ 108296465Sdelphij sm->generate_object = generate_f; 109296465Sdelphij return 1; 110296465Sdelphij} 111160814Ssimon 112296465Sdelphijint STORE_method_set_get_function(STORE_METHOD *sm, 113296465Sdelphij STORE_GET_OBJECT_FUNC_PTR get_f) 114296465Sdelphij{ 115296465Sdelphij sm->get_object = get_f; 116296465Sdelphij return 1; 117296465Sdelphij} 118160814Ssimon 119296465Sdelphijint STORE_method_set_store_function(STORE_METHOD *sm, 120296465Sdelphij STORE_STORE_OBJECT_FUNC_PTR store_f) 121296465Sdelphij{ 122296465Sdelphij sm->store_object = store_f; 123296465Sdelphij return 1; 124296465Sdelphij} 125160814Ssimon 126296465Sdelphijint STORE_method_set_modify_function(STORE_METHOD *sm, 127296465Sdelphij STORE_MODIFY_OBJECT_FUNC_PTR modify_f) 128296465Sdelphij{ 129296465Sdelphij sm->modify_object = modify_f; 130296465Sdelphij return 1; 131296465Sdelphij} 132160814Ssimon 133296465Sdelphijint STORE_method_set_revoke_function(STORE_METHOD *sm, 134296465Sdelphij STORE_HANDLE_OBJECT_FUNC_PTR revoke_f) 135296465Sdelphij{ 136296465Sdelphij sm->revoke_object = revoke_f; 137296465Sdelphij return 1; 138296465Sdelphij} 139160814Ssimon 140296465Sdelphijint STORE_method_set_delete_function(STORE_METHOD *sm, 141296465Sdelphij STORE_HANDLE_OBJECT_FUNC_PTR delete_f) 142296465Sdelphij{ 143296465Sdelphij sm->delete_object = delete_f; 144296465Sdelphij return 1; 145296465Sdelphij} 146160814Ssimon 147296465Sdelphijint STORE_method_set_list_start_function(STORE_METHOD *sm, 148296465Sdelphij STORE_START_OBJECT_FUNC_PTR 149296465Sdelphij list_start_f) 150296465Sdelphij{ 151296465Sdelphij sm->list_object_start = list_start_f; 152296465Sdelphij return 1; 153296465Sdelphij} 154160814Ssimon 155296465Sdelphijint STORE_method_set_list_next_function(STORE_METHOD *sm, 156296465Sdelphij STORE_NEXT_OBJECT_FUNC_PTR 157296465Sdelphij list_next_f) 158296465Sdelphij{ 159296465Sdelphij sm->list_object_next = list_next_f; 160296465Sdelphij return 1; 161296465Sdelphij} 162160814Ssimon 163296465Sdelphijint STORE_method_set_list_end_function(STORE_METHOD *sm, 164296465Sdelphij STORE_END_OBJECT_FUNC_PTR list_end_f) 165296465Sdelphij{ 166296465Sdelphij sm->list_object_end = list_end_f; 167296465Sdelphij return 1; 168296465Sdelphij} 169160814Ssimon 170296465Sdelphijint STORE_method_set_update_store_function(STORE_METHOD *sm, 171296465Sdelphij STORE_GENERIC_FUNC_PTR update_f) 172296465Sdelphij{ 173296465Sdelphij sm->update_store = update_f; 174296465Sdelphij return 1; 175296465Sdelphij} 176160814Ssimon 177296465Sdelphijint STORE_method_set_lock_store_function(STORE_METHOD *sm, 178296465Sdelphij STORE_GENERIC_FUNC_PTR lock_f) 179296465Sdelphij{ 180296465Sdelphij sm->lock_store = lock_f; 181296465Sdelphij return 1; 182296465Sdelphij} 183160814Ssimon 184296465Sdelphijint STORE_method_set_unlock_store_function(STORE_METHOD *sm, 185296465Sdelphij STORE_GENERIC_FUNC_PTR unlock_f) 186296465Sdelphij{ 187296465Sdelphij sm->unlock_store = unlock_f; 188296465Sdelphij return 1; 189296465Sdelphij} 190160814Ssimon 191296465Sdelphijint STORE_method_set_ctrl_function(STORE_METHOD *sm, 192296465Sdelphij STORE_CTRL_FUNC_PTR ctrl_f) 193296465Sdelphij{ 194296465Sdelphij sm->ctrl = ctrl_f; 195296465Sdelphij return 1; 196296465Sdelphij} 197160814Ssimon 198296465SdelphijSTORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD 199296465Sdelphij *sm) 200296465Sdelphij{ 201296465Sdelphij return sm->init; 202296465Sdelphij} 203160814Ssimon 204160814SsimonSTORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm) 205296465Sdelphij{ 206296465Sdelphij return sm->clean; 207296465Sdelphij} 208160814Ssimon 209296465SdelphijSTORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD 210296465Sdelphij *sm) 211296465Sdelphij{ 212296465Sdelphij return sm->generate_object; 213296465Sdelphij} 214160814Ssimon 215160814SsimonSTORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm) 216296465Sdelphij{ 217296465Sdelphij return sm->get_object; 218296465Sdelphij} 219160814Ssimon 220160814SsimonSTORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm) 221296465Sdelphij{ 222296465Sdelphij return sm->store_object; 223296465Sdelphij} 224160814Ssimon 225296465SdelphijSTORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD 226296465Sdelphij *sm) 227296465Sdelphij{ 228296465Sdelphij return sm->modify_object; 229296465Sdelphij} 230160814Ssimon 231296465SdelphijSTORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD 232296465Sdelphij *sm) 233296465Sdelphij{ 234296465Sdelphij return sm->revoke_object; 235296465Sdelphij} 236160814Ssimon 237296465SdelphijSTORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD 238296465Sdelphij *sm) 239296465Sdelphij{ 240296465Sdelphij return sm->delete_object; 241296465Sdelphij} 242160814Ssimon 243296465SdelphijSTORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD 244296465Sdelphij *sm) 245296465Sdelphij{ 246296465Sdelphij return sm->list_object_start; 247296465Sdelphij} 248160814Ssimon 249296465SdelphijSTORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD 250296465Sdelphij *sm) 251296465Sdelphij{ 252296465Sdelphij return sm->list_object_next; 253296465Sdelphij} 254160814Ssimon 255160814SsimonSTORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm) 256296465Sdelphij{ 257296465Sdelphij return sm->list_object_end; 258296465Sdelphij} 259160814Ssimon 260296465SdelphijSTORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD 261296465Sdelphij *sm) 262296465Sdelphij{ 263296465Sdelphij return sm->update_store; 264296465Sdelphij} 265160814Ssimon 266160814SsimonSTORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm) 267296465Sdelphij{ 268296465Sdelphij return sm->lock_store; 269296465Sdelphij} 270160814Ssimon 271296465SdelphijSTORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD 272296465Sdelphij *sm) 273296465Sdelphij{ 274296465Sdelphij return sm->unlock_store; 275296465Sdelphij} 276160814Ssimon 277160814SsimonSTORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm) 278296465Sdelphij{ 279296465Sdelphij return sm->ctrl; 280296465Sdelphij} 281