1 /* 2 * Copyright (c) 2014 Jerry Lundström <lundstrom.jerry@gmail.com> 3 * Copyright (c) 2014 .SE (The Internet Infrastructure Foundation). 4 * Copyright (c) 2014 OpenDNSSEC AB (svb) 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #ifndef __db_configuration_h 31 #define __db_configuration_h 32 33 struct db_configuration; 34 struct db_configuration_list; 35 typedef struct db_configuration db_configuration_t; 36 typedef struct db_configuration_list db_configuration_list_t; 37 38 /** 39 * A database configuration represented by a key and value. 40 */ 41 struct db_configuration { 42 db_configuration_t* next; 43 char* name; 44 char* value; 45 }; 46 47 /** 48 * Create a new database configuration. 49 * \return a db_configuration_t pointer or NULL on error. 50 */ 51 extern db_configuration_t* db_configuration_new(void); 52 53 /** 54 * Delete a database configuration. 55 * \param[in] configuration a db_configuration_t pointer. 56 */ 57 extern void db_configuration_free(db_configuration_t* configuration); 58 59 /** 60 * Get the value of a database configuration. 61 * \param[in] configuration a db_configuration_t pointer. 62 * \return a character pointer or NULL on error or if no database configuration 63 * value has been set. 64 */ 65 extern const char* db_configuration_value(const db_configuration_t* configuration); 66 67 /** 68 * Set the name of a database configuration. 69 * \param[in] configuration a db_configuration_t pointer. 70 * \param[in] name a character pointer. 71 * \return DB_ERROR_* on failure, otherwise DB_OK. 72 */ 73 extern int db_configuration_set_name(db_configuration_t* configuration, const char* name); 74 75 /** 76 * Set the value of a database configuration. 77 * \param[in] configuration a db_configuration_t pointer. 78 * \param[in] value a character pointer. 79 * \return DB_ERROR_* on failure, otherwise DB_OK. 80 */ 81 extern int db_configuration_set_value(db_configuration_t* configuration, const char* value); 82 83 /** 84 * Check if the database configuration is not empty. 85 * \param[in] configuration a db_configuration_t pointer. 86 * \return DB_ERROR_* if empty, otherwise DB_OK. 87 */ 88 extern int db_configuration_not_empty(const db_configuration_t* configuration); 89 90 /** 91 * A list of database configurations. 92 */ 93 struct db_configuration_list { 94 db_configuration_t* begin; 95 db_configuration_t* end; 96 }; 97 98 /** 99 * Create a new database configuration list. 100 * \return a db_configuration_list_t pointer or NULL on error. 101 */ 102 extern db_configuration_list_t* db_configuration_list_new(void); 103 104 /** 105 * Delete a database configuration list and all database configurations in the 106 * list. 107 * \param[in] configuration_list a db_configuration_list_t pointer. 108 */ 109 extern void db_configuration_list_free(db_configuration_list_t* configuration_list); 110 111 /** 112 * free global allocator. 113 * db_configuration_list_free MUST be called for all its contents. 114 */ 115 /** 116 * Add a database configuration to a database configuration list, this takes 117 * over the ownership of the database configuration. 118 * \param[in] configuration_list a db_configuration_list_t pointer. 119 * \param[in] configuration a db_configuration_t pointer. 120 * \return DB_ERROR_* on failure, otherwise DB_OK. 121 */ 122 extern int db_configuration_list_add(db_configuration_list_t* configuration_list, db_configuration_t* configuration); 123 124 /** 125 * Find a database configuration by name within a database configuration list. 126 * \param[in] configuration_list a db_configuration_list_t pointer. 127 * \param[in] name a character pointer. 128 * \return a db_configuration_t pointer or NULL on error or if the database 129 * configuration does not exist. 130 */ 131 extern const db_configuration_t* db_configuration_list_find(const db_configuration_list_t* configuration_list, const char* name); 132 133 #endif 134