OpenDNSSEC-enforcer 2.1.13
db_connection.c
Go to the documentation of this file.
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#include "db_connection.h"
31#include "db_error.h"
32
33
34#include <stdlib.h>
35
36
37
39 db_connection_t* connection =
40 (db_connection_t*)calloc(1, sizeof(db_connection_t));
41
42 return connection;
43}
44
46 if (connection) {
47 if (connection->backend) {
48 db_backend_free(connection->backend);
49 }
50 free(connection);
51 }
52}
53
55 if (!connection) {
56 return DB_ERROR_UNKNOWN;
57 }
58 if (connection->configuration_list) {
59 return DB_ERROR_UNKNOWN;
60 }
61
62 connection->configuration_list = configuration_list;
63 return DB_OK;
64}
65
67 if (!connection) {
68 return DB_ERROR_UNKNOWN;
69 }
70 if (!connection->configuration_list) {
71 return DB_ERROR_UNKNOWN;
72 }
73
74 if (!connection->backend) {
75 const db_configuration_t* backend = db_configuration_list_find(connection->configuration_list, "backend");
76 if (!backend) {
77 return DB_ERROR_UNKNOWN;
78 }
79
81 if (!connection->backend) {
82 return DB_ERROR_UNKNOWN;
83 }
84 }
85 return DB_OK;
86}
87
88int db_connection_connect(const db_connection_t* connection) {
89 if (!connection) {
90 return DB_ERROR_UNKNOWN;
91 }
92 if (!connection->configuration_list) {
93 return DB_ERROR_UNKNOWN;
94 }
95 if (!connection->backend) {
96 return DB_ERROR_UNKNOWN;
97 }
98
99 return db_backend_connect(connection->backend, connection->configuration_list);
100}
101
102int db_connection_create(const db_connection_t* connection, const db_object_t* object, const db_object_field_list_t* object_field_list, const db_value_set_t* value_set) {
103 if (!connection) {
104 return DB_ERROR_UNKNOWN;
105 }
106 if (!object) {
107 return DB_ERROR_UNKNOWN;
108 }
109 if (!object_field_list) {
110 return DB_ERROR_UNKNOWN;
111 }
112 if (!value_set) {
113 return DB_ERROR_UNKNOWN;
114 }
115 if (!connection->backend) {
116 return DB_ERROR_UNKNOWN;
117 }
118
119 return db_backend_create(connection->backend, object, object_field_list, value_set);
120}
121
122db_result_list_t* db_connection_read(const db_connection_t* connection, const db_object_t* object, const db_join_list_t* join_list, const db_clause_list_t* clause_list) {
123 if (!connection) {
124 return NULL;
125 }
126 if (!object) {
127 return NULL;
128 }
129 if (!connection->backend) {
130 return NULL;
131 }
132
133 return db_backend_read(connection->backend, object, join_list, clause_list);
134}
135
136int db_connection_update(const db_connection_t* connection, const db_object_t* object, const db_object_field_list_t* object_field_list, const db_value_set_t* value_set, const db_clause_list_t* clause_list) {
137 if (!connection) {
138 return DB_ERROR_UNKNOWN;
139 }
140 if (!object) {
141 return DB_ERROR_UNKNOWN;
142 }
143 if (!object_field_list) {
144 return DB_ERROR_UNKNOWN;
145 }
146 if (!value_set) {
147 return DB_ERROR_UNKNOWN;
148 }
149 if (!connection->backend) {
150 return DB_ERROR_UNKNOWN;
151 }
152
153 return db_backend_update(connection->backend, object, object_field_list, value_set, clause_list);
154}
155
156int db_connection_delete(const db_connection_t* connection, const db_object_t* object, const db_clause_list_t* clause_list) {
157 if (!connection) {
158 return DB_ERROR_UNKNOWN;
159 }
160 if (!object) {
161 return DB_ERROR_UNKNOWN;
162 }
163 if (!connection->backend) {
164 return DB_ERROR_UNKNOWN;
165 }
166
167 return db_backend_delete(connection->backend, object, clause_list);
168}
169
170int db_connection_count(const db_connection_t* connection, const db_object_t* object, const db_join_list_t* join_list, const db_clause_list_t* clause_list, size_t* count) {
171 if (!connection) {
172 return DB_ERROR_UNKNOWN;
173 }
174 if (!object) {
175 return DB_ERROR_UNKNOWN;
176 }
177 if (!count) {
178 return DB_ERROR_UNKNOWN;
179 }
180 if (!connection->backend) {
181 return DB_ERROR_UNKNOWN;
182 }
183
184 return db_backend_count(connection->backend, object, join_list, clause_list, count);
185}
int db_backend_update(const db_backend_t *backend, const db_object_t *object, const db_object_field_list_t *object_field_list, const db_value_set_t *value_set, const db_clause_list_t *clause_list)
Definition db_backend.c:419
void db_backend_free(db_backend_t *backend)
Definition db_backend.c:318
db_result_list_t * db_backend_read(const db_backend_t *backend, const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list)
Definition db_backend.c:405
db_backend_t * db_backend_factory_get_backend(const char *name)
Definition db_backend.c:472
int db_backend_create(const db_backend_t *backend, const db_object_t *object, const db_object_field_list_t *object_field_list, const db_value_set_t *value_set)
Definition db_backend.c:385
int db_backend_delete(const db_backend_t *backend, const db_object_t *object, const db_clause_list_t *clause_list)
Definition db_backend.c:439
int db_backend_count(const db_backend_t *backend, const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list, size_t *count)
Definition db_backend.c:453
int db_backend_connect(const db_backend_t *backend, const db_configuration_list_t *configuration_list)
Definition db_backend.c:371
const char * db_configuration_value(const db_configuration_t *configuration)
const db_configuration_t * db_configuration_list_find(const db_configuration_list_t *configuration_list, const char *name)
int db_connection_create(const db_connection_t *connection, const db_object_t *object, const db_object_field_list_t *object_field_list, const db_value_set_t *value_set)
int db_connection_connect(const db_connection_t *connection)
db_connection_t * db_connection_new(void)
int db_connection_setup(db_connection_t *connection)
int db_connection_delete(const db_connection_t *connection, const db_object_t *object, const db_clause_list_t *clause_list)
void db_connection_free(db_connection_t *connection)
int db_connection_set_configuration_list(db_connection_t *connection, const db_configuration_list_t *configuration_list)
db_result_list_t * db_connection_read(const db_connection_t *connection, const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list)
int db_connection_update(const db_connection_t *connection, const db_object_t *object, const db_object_field_list_t *object_field_list, const db_value_set_t *value_set, const db_clause_list_t *clause_list)
int db_connection_count(const db_connection_t *connection, const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list, size_t *count)
#define DB_ERROR_UNKNOWN
Definition db_error.h:40
#define DB_OK
Definition db_error.h:36
const db_configuration_list_t * configuration_list
db_backend_t * backend