1 /*
2  * Copyright (C) 2020-2021 Bareos GmbH & Co. KG
3  * Copyright (C) 2010 SCALITY SA. All rights reserved.
4  * http://www.scality.com
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY SCALITY SA ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL SCALITY SA OR CONTRIBUTORS BE LIABLE FOR
21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * The views and conclusions contained in the software and documentation
30  * are those of the authors and should not be interpreted as representing
31  * official policies, either expressed or implied, of SCALITY SA.
32  *
33  * https://github.com/scality/Droplet
34  */
35 #ifndef BAREOS_DROPLET_LIBDROPLET_INCLUDE_DROPLET_DICT_H_
36 #define BAREOS_DROPLET_LIBDROPLET_INCLUDE_DROPLET_DICT_H_
37 
38 struct dpl_dict;
39 
40 typedef struct dpl_dict_var {
41   struct dpl_dict_var* prev;
42   struct dpl_dict_var* next;
43   char* key;
44   dpl_value_t* val;
45 } dpl_dict_var_t;
46 
47 typedef dpl_status_t (*dpl_dict_func_t)(dpl_dict_var_t* var, void* cb_arg);
48 
49 typedef struct dpl_dict {
50   dpl_dict_var_t** buckets;
51   unsigned int n_buckets;
52 } dpl_dict_t;
53 
54 /* PROTO dict.c */
55 /* src/dict.c */
56 dpl_dict_t* dpl_dict_new(int n_buckets);
57 dpl_dict_var_t* dpl_dict_get(const dpl_dict_t* dict, const char* key);
58 dpl_status_t dpl_dict_get_lowered(const dpl_dict_t* dict,
59                                   const char* key,
60                                   dpl_dict_var_t** varp);
61 char* dpl_dict_get_value(const dpl_dict_t* dict, const char* key);
62 dpl_status_t dpl_dict_iterate(const dpl_dict_t* dict,
63                               dpl_dict_func_t cb_func,
64                               void* cb_arg);
65 int dpl_dict_count(const dpl_dict_t* dict);
66 void dpl_dict_var_free(dpl_dict_var_t* var);
67 void dpl_dict_free(dpl_dict_t* dict);
68 void dpl_dict_print(const dpl_dict_t* dict, FILE* f, int level);
69 dpl_status_t dpl_dict_add_value(dpl_dict_t* dict,
70                                 const char* key,
71                                 dpl_value_t* value,
72                                 int lowered);
73 dpl_status_t dpl_dict_add(dpl_dict_t* dict,
74                           const char* key,
75                           const char* string,
76                           int lowered);
77 void dpl_dict_remove(dpl_dict_t* dict, dpl_dict_var_t* var);
78 dpl_status_t dpl_dict_copy(dpl_dict_t* dst, const dpl_dict_t* src);
79 dpl_dict_t* dpl_dict_dup(const dpl_dict_t* src);
80 dpl_status_t dpl_dict_filter_prefix(dpl_dict_t* dst,
81                                     const dpl_dict_t* src,
82                                     const char* prefix);
83 dpl_status_t dpl_dict_filter_no_prefix(dpl_dict_t* dst,
84                                        const dpl_dict_t* src,
85                                        const char* prefix);
86 #endif  // BAREOS_DROPLET_LIBDROPLET_INCLUDE_DROPLET_DICT_H_
87