1295016Sjkim/* crypto/store/str_meth.c */ 2280304Sjkim/* 3280304Sjkim * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project 4280304Sjkim * 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 14280304Sjkim * 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) 65280304Sjkim{ 66280304Sjkim STORE_METHOD *store_method = 67280304Sjkim (STORE_METHOD *)OPENSSL_malloc(sizeof(STORE_METHOD)); 68160814Ssimon 69280304Sjkim if (store_method) { 70280304Sjkim memset(store_method, 0, sizeof(*store_method)); 71280304Sjkim store_method->name = BUF_strdup(name); 72280304Sjkim } 73280304Sjkim return store_method; 74280304Sjkim} 75160814Ssimon 76280304Sjkim/* 77280304Sjkim * BIG FSCKING WARNING!!!! If you use this on a statically allocated method 78280304Sjkim * (that is, it hasn't been allocated using STORE_create_method(), you 79280304Sjkim * deserve anything Murphy can throw at you and more! You have been warned. 80280304Sjkim */ 81160814Ssimonvoid STORE_destroy_method(STORE_METHOD *store_method) 82280304Sjkim{ 83280304Sjkim if (!store_method) 84280304Sjkim return; 85280304Sjkim OPENSSL_free(store_method->name); 86280304Sjkim store_method->name = NULL; 87280304Sjkim OPENSSL_free(store_method); 88280304Sjkim} 89160814Ssimon 90280304Sjkimint STORE_method_set_initialise_function(STORE_METHOD *sm, 91280304Sjkim STORE_INITIALISE_FUNC_PTR init_f) 92280304Sjkim{ 93280304Sjkim sm->init = init_f; 94280304Sjkim return 1; 95280304Sjkim} 96160814Ssimon 97280304Sjkimint STORE_method_set_cleanup_function(STORE_METHOD *sm, 98280304Sjkim STORE_CLEANUP_FUNC_PTR clean_f) 99280304Sjkim{ 100280304Sjkim sm->clean = clean_f; 101280304Sjkim return 1; 102280304Sjkim} 103160814Ssimon 104280304Sjkimint STORE_method_set_generate_function(STORE_METHOD *sm, 105280304Sjkim STORE_GENERATE_OBJECT_FUNC_PTR 106280304Sjkim generate_f) 107280304Sjkim{ 108280304Sjkim sm->generate_object = generate_f; 109280304Sjkim return 1; 110280304Sjkim} 111160814Ssimon 112280304Sjkimint STORE_method_set_get_function(STORE_METHOD *sm, 113280304Sjkim STORE_GET_OBJECT_FUNC_PTR get_f) 114280304Sjkim{ 115280304Sjkim sm->get_object = get_f; 116280304Sjkim return 1; 117280304Sjkim} 118160814Ssimon 119280304Sjkimint STORE_method_set_store_function(STORE_METHOD *sm, 120280304Sjkim STORE_STORE_OBJECT_FUNC_PTR store_f) 121280304Sjkim{ 122280304Sjkim sm->store_object = store_f; 123280304Sjkim return 1; 124280304Sjkim} 125160814Ssimon 126280304Sjkimint STORE_method_set_modify_function(STORE_METHOD *sm, 127280304Sjkim STORE_MODIFY_OBJECT_FUNC_PTR modify_f) 128280304Sjkim{ 129280304Sjkim sm->modify_object = modify_f; 130280304Sjkim return 1; 131280304Sjkim} 132160814Ssimon 133280304Sjkimint STORE_method_set_revoke_function(STORE_METHOD *sm, 134280304Sjkim STORE_HANDLE_OBJECT_FUNC_PTR revoke_f) 135280304Sjkim{ 136280304Sjkim sm->revoke_object = revoke_f; 137280304Sjkim return 1; 138280304Sjkim} 139160814Ssimon 140280304Sjkimint STORE_method_set_delete_function(STORE_METHOD *sm, 141280304Sjkim STORE_HANDLE_OBJECT_FUNC_PTR delete_f) 142280304Sjkim{ 143280304Sjkim sm->delete_object = delete_f; 144280304Sjkim return 1; 145280304Sjkim} 146160814Ssimon 147280304Sjkimint STORE_method_set_list_start_function(STORE_METHOD *sm, 148280304Sjkim STORE_START_OBJECT_FUNC_PTR 149280304Sjkim list_start_f) 150280304Sjkim{ 151280304Sjkim sm->list_object_start = list_start_f; 152280304Sjkim return 1; 153280304Sjkim} 154160814Ssimon 155280304Sjkimint STORE_method_set_list_next_function(STORE_METHOD *sm, 156280304Sjkim STORE_NEXT_OBJECT_FUNC_PTR 157280304Sjkim list_next_f) 158280304Sjkim{ 159280304Sjkim sm->list_object_next = list_next_f; 160280304Sjkim return 1; 161280304Sjkim} 162160814Ssimon 163280304Sjkimint STORE_method_set_list_end_function(STORE_METHOD *sm, 164280304Sjkim STORE_END_OBJECT_FUNC_PTR list_end_f) 165280304Sjkim{ 166280304Sjkim sm->list_object_end = list_end_f; 167280304Sjkim return 1; 168280304Sjkim} 169160814Ssimon 170280304Sjkimint STORE_method_set_update_store_function(STORE_METHOD *sm, 171280304Sjkim STORE_GENERIC_FUNC_PTR update_f) 172280304Sjkim{ 173280304Sjkim sm->update_store = update_f; 174280304Sjkim return 1; 175280304Sjkim} 176160814Ssimon 177280304Sjkimint STORE_method_set_lock_store_function(STORE_METHOD *sm, 178280304Sjkim STORE_GENERIC_FUNC_PTR lock_f) 179280304Sjkim{ 180280304Sjkim sm->lock_store = lock_f; 181280304Sjkim return 1; 182280304Sjkim} 183160814Ssimon 184280304Sjkimint STORE_method_set_unlock_store_function(STORE_METHOD *sm, 185280304Sjkim STORE_GENERIC_FUNC_PTR unlock_f) 186280304Sjkim{ 187280304Sjkim sm->unlock_store = unlock_f; 188280304Sjkim return 1; 189280304Sjkim} 190160814Ssimon 191280304Sjkimint STORE_method_set_ctrl_function(STORE_METHOD *sm, 192280304Sjkim STORE_CTRL_FUNC_PTR ctrl_f) 193280304Sjkim{ 194280304Sjkim sm->ctrl = ctrl_f; 195280304Sjkim return 1; 196280304Sjkim} 197160814Ssimon 198280304SjkimSTORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD 199280304Sjkim *sm) 200280304Sjkim{ 201280304Sjkim return sm->init; 202280304Sjkim} 203160814Ssimon 204160814SsimonSTORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm) 205280304Sjkim{ 206280304Sjkim return sm->clean; 207280304Sjkim} 208160814Ssimon 209280304SjkimSTORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD 210280304Sjkim *sm) 211280304Sjkim{ 212280304Sjkim return sm->generate_object; 213280304Sjkim} 214160814Ssimon 215160814SsimonSTORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm) 216280304Sjkim{ 217280304Sjkim return sm->get_object; 218280304Sjkim} 219160814Ssimon 220160814SsimonSTORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm) 221280304Sjkim{ 222280304Sjkim return sm->store_object; 223280304Sjkim} 224160814Ssimon 225280304SjkimSTORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD 226280304Sjkim *sm) 227280304Sjkim{ 228280304Sjkim return sm->modify_object; 229280304Sjkim} 230160814Ssimon 231280304SjkimSTORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD 232280304Sjkim *sm) 233280304Sjkim{ 234280304Sjkim return sm->revoke_object; 235280304Sjkim} 236160814Ssimon 237280304SjkimSTORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD 238280304Sjkim *sm) 239280304Sjkim{ 240280304Sjkim return sm->delete_object; 241280304Sjkim} 242160814Ssimon 243280304SjkimSTORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD 244280304Sjkim *sm) 245280304Sjkim{ 246280304Sjkim return sm->list_object_start; 247280304Sjkim} 248160814Ssimon 249280304SjkimSTORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD 250280304Sjkim *sm) 251280304Sjkim{ 252280304Sjkim return sm->list_object_next; 253280304Sjkim} 254160814Ssimon 255160814SsimonSTORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm) 256280304Sjkim{ 257280304Sjkim return sm->list_object_end; 258280304Sjkim} 259160814Ssimon 260280304SjkimSTORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD 261280304Sjkim *sm) 262280304Sjkim{ 263280304Sjkim return sm->update_store; 264280304Sjkim} 265160814Ssimon 266160814SsimonSTORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm) 267280304Sjkim{ 268280304Sjkim return sm->lock_store; 269280304Sjkim} 270160814Ssimon 271280304SjkimSTORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD 272280304Sjkim *sm) 273280304Sjkim{ 274280304Sjkim return sm->unlock_store; 275280304Sjkim} 276160814Ssimon 277160814SsimonSTORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm) 278280304Sjkim{ 279280304Sjkim return sm->ctrl; 280280304Sjkim} 281