OpenDNSSEC-enforcer  2.1.7
db_value.h
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 #ifndef __db_value_h
31 #define __db_value_h
32 
33 struct db_value;
34 struct db_value_set;
35 typedef struct db_value db_value_t;
36 typedef struct db_value_set db_value_set_t;
37 
38 #include "config.h"
39 
40 #include "db_type.h"
41 #include "db_enum.h"
42 
43 #include <stdlib.h>
44 
48 struct db_value {
51  char* text;
57  const char* enum_text;
58 };
59 
60 #define DB_VALUE_EMPTY { DB_TYPE_EMPTY, 0, NULL, 0, 0, 0, 0, 0, NULL }
61 
66 extern db_value_t* db_value_new(void);
67 
72 extern void db_value_free(db_value_t* value);
73 
78 extern void db_value_reset(db_value_t* value);
79 
86 extern int db_value_copy(db_value_t* value, const db_value_t* from_value);
87 
97 extern int db_value_cmp(const db_value_t* value_a, const db_value_t* value_b, int* result);
98 
104 extern db_type_t db_value_type(const db_value_t* value);
105 
113 extern const db_type_int32_t* db_value_int32(const db_value_t* value);
114 
122 extern const db_type_uint32_t* db_value_uint32(const db_value_t* value);
123 
131 extern const db_type_int64_t* db_value_int64(const db_value_t* value);
132 
140 extern const db_type_uint64_t* db_value_uint64(const db_value_t* value);
141 
147 extern const char* db_value_text(const db_value_t* value);
148 
155 extern int db_value_enum_value(const db_value_t* value, int* enum_value);
156 
162 extern int db_value_not_empty(const db_value_t* value);
163 
170 extern int db_value_to_int32(const db_value_t* value, db_type_int32_t* to_int32);
171 
178 extern int db_value_to_uint32(const db_value_t* value, db_type_uint32_t* to_uint32);
179 
186 extern int db_value_to_int64(const db_value_t* value, db_type_int64_t* to_int64);
187 
194 extern int db_value_to_uint64(const db_value_t* value, db_type_uint64_t* to_uint64);
195 
202 extern int db_value_to_text(const db_value_t* value, char** to_text);
203 
211 extern int db_value_to_enum_value(const db_value_t* value, int* to_int, const db_enum_t* enum_set);
212 
219 extern int db_value_from_int32(db_value_t* value, db_type_int32_t from_int32);
220 
227 extern int db_value_from_uint32(db_value_t* value, db_type_uint32_t from_uint32);
228 
235 extern int db_value_from_int64(db_value_t* value, db_type_int64_t from_int64);
236 
243 extern int db_value_from_uint64(db_value_t* value, db_type_uint64_t from_uint64);
244 
251 extern int db_value_from_text(db_value_t* value, const char* from_text);
252 
260 extern int db_value_from_text2(db_value_t* value, const char* from_text, size_t size);
261 
269 extern int db_value_from_enum_value(db_value_t* value, int enum_value, const db_enum_t* enum_set);
270 
276 extern int db_value_set_primary_key(db_value_t* value);
277 
281 struct db_value_set {
283  size_t size;
284 };
285 
291 extern db_value_set_t* db_value_set_new(size_t size);
292 
298 extern db_value_set_t* db_value_set_new_copy(const db_value_set_t* from_value_set);
299 
304 extern void db_value_set_free(db_value_set_t* value_set);
305 
311 extern size_t db_value_set_size(const db_value_set_t* value_set);
312 
319 extern const db_value_t* db_value_set_at(const db_value_set_t* value_set, size_t at);
320 
327 extern db_value_t* db_value_set_get(db_value_set_t* value_set, size_t at);
328 
329 #endif
db_type_t
Definition: db_type.h:54
uint64_t db_type_uint64_t
Definition: db_type.h:50
uint32_t db_type_uint32_t
Definition: db_type.h:42
int64_t db_type_int64_t
Definition: db_type.h:46
int32_t db_type_int32_t
Definition: db_type.h:38
int db_value_to_int32(const db_value_t *value, db_type_int32_t *to_int32)
Definition: db_value.c:357
db_type_t db_value_type(const db_value_t *value)
Definition: db_value.c:269
const db_type_uint32_t * db_value_uint32(const db_value_t *value)
Definition: db_value.c:288
int db_value_set_primary_key(db_value_t *value)
Definition: db_value.c:595
int db_value_from_enum_value(db_value_t *value, int enum_value, const db_enum_t *enum_set)
Definition: db_value.c:572
void db_value_set_free(db_value_set_t *value_set)
Definition: db_value.c:697
const char * db_value_text(const db_value_t *value)
Definition: db_value.c:321
int db_value_from_uint32(db_value_t *value, db_type_uint32_t from_uint32)
Definition: db_value.c:492
int db_value_to_int64(const db_value_t *value, db_type_int64_t *to_int64)
Definition: db_value.c:387
int db_value_from_text(db_value_t *value, const char *from_text)
Definition: db_value.c:531
int db_value_from_int32(db_value_t *value, db_type_int32_t from_int32)
Definition: db_value.c:479
db_value_set_t * db_value_set_new_copy(const db_value_set_t *from_value_set)
Definition: db_value.c:670
int db_value_copy(db_value_t *value, const db_value_t *from_value)
Definition: db_value.c:77
int db_value_from_int64(db_value_t *value, db_type_int64_t from_int64)
Definition: db_value.c:505
const db_type_uint64_t * db_value_uint64(const db_value_t *value)
Definition: db_value.c:310
int db_value_cmp(const db_value_t *value_a, const db_value_t *value_b, int *result)
Definition: db_value.c:102
size_t db_value_set_size(const db_value_set_t *value_set)
Definition: db_value.c:734
int db_value_to_uint32(const db_value_t *value, db_type_uint32_t *to_uint32)
Definition: db_value.c:372
int db_value_from_text2(db_value_t *value, const char *from_text, size_t size)
Definition: db_value.c:550
const db_type_int32_t * db_value_int32(const db_value_t *value)
Definition: db_value.c:277
int db_value_to_text(const db_value_t *value, char **to_text)
Definition: db_value.c:417
const db_value_t * db_value_set_at(const db_value_set_t *value_set, size_t at)
Definition: db_value.c:742
void db_value_free(db_value_t *value)
Definition: db_value.c:51
int db_value_not_empty(const db_value_t *value)
Definition: db_value.c:347
int db_value_enum_value(const db_value_t *value, int *enum_value)
Definition: db_value.c:332
db_value_set_t * db_value_set_new(size_t size)
Definition: db_value.c:622
int db_value_to_uint64(const db_value_t *value, db_type_uint64_t *to_uint64)
Definition: db_value.c:402
int db_value_to_enum_value(const db_value_t *value, int *to_int, const db_enum_t *enum_set)
Definition: db_value.c:438
void db_value_reset(db_value_t *value)
Definition: db_value.c:60
db_value_t * db_value_new(void)
Definition: db_value.c:40
db_value_t * db_value_set_get(db_value_set_t *value_set, size_t at)
Definition: db_value.c:756
const db_type_int64_t * db_value_int64(const db_value_t *value)
Definition: db_value.c:299
int db_value_from_uint64(db_value_t *value, db_type_uint64_t from_uint64)
Definition: db_value.c:518
db_value_t * values
Definition: db_value.h:282
size_t size
Definition: db_value.h:283
db_type_uint32_t uint32
Definition: db_value.h:53
db_type_uint64_t uint64
Definition: db_value.h:55
db_type_int32_t int32
Definition: db_value.h:52
int enum_value
Definition: db_value.h:56
int primary_key
Definition: db_value.h:50
char * text
Definition: db_value.h:51
db_type_t type
Definition: db_value.h:49
db_type_int64_t int64
Definition: db_value.h:54
const char * enum_text
Definition: db_value.h:57