aboutsummaryrefslogtreecommitdiff
path: root/src/bindings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings.c')
-rw-r--r--src/bindings.c129
1 files changed, 0 insertions, 129 deletions
diff --git a/src/bindings.c b/src/bindings.c
deleted file mode 100644
index b7325d4..0000000
--- a/src/bindings.c
+++ /dev/null
@@ -1,129 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file bindings.h
23 */
24
25#include "bindings.h"
26#include "util.h"
27
28MESSENGER_Bindings*
29bindings_create()
30{
31 MESSENGER_Bindings *bindings = GNUNET_new(MESSENGER_Bindings);
32
33 bindings->map = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO);
34
35 return bindings;
36}
37
38void
39bindings_put(MESSENGER_Bindings *bindings,
40 gconstpointer key,
41 gpointer value)
42{
43 struct GNUNET_ShortHashCode hash;
44 memset(&hash, 0, sizeof(hash));
45 memcpy(&hash, &key, sizeof(key));
46
47 GNUNET_CONTAINER_multishortmap_put(
48 bindings->map,
49 &hash,
50 (void*) value,
51 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
52 );
53}
54
55int
56_bindings_append_list(void *cls,
57 UNUSED const struct GNUNET_ShortHashCode *key,
58 void *value)
59{
60 GList **list = (GList**) cls;
61 *list = g_list_append(*list, (gpointer) value);
62 return GNUNET_YES;
63}
64
65void
66bindings_remove(MESSENGER_Bindings *bindings,
67 const void *key,
68 void *value,
69 void (destroy)(void*))
70{
71 struct GNUNET_ShortHashCode hash;
72 memset(&hash, 0, sizeof(hash));
73 memcpy(&hash, &key, sizeof(key));
74
75 if (value)
76 {
77 GNUNET_CONTAINER_multishortmap_remove(
78 bindings->map,
79 &hash,
80 (void*) value
81 );
82
83 if (destroy)
84 destroy(value);
85 }
86 else
87 {
88 GList *values = NULL;
89
90 GNUNET_CONTAINER_multishortmap_get_multiple(
91 bindings->map,
92 &hash,
93 _bindings_append_list,
94 &values
95 );
96
97 GNUNET_CONTAINER_multishortmap_remove_all(
98 bindings->map,
99 &hash
100 );
101
102 if (destroy)
103 g_list_free_full(values, destroy);
104 else
105 g_list_free(values);
106 }
107}
108
109void*
110bindings_get(const MESSENGER_Bindings *bindings,
111 const void *key)
112{
113 struct GNUNET_ShortHashCode hash;
114 memset(&hash, 0, sizeof(hash));
115 memcpy(&hash, &key, sizeof(key));
116
117 return GNUNET_CONTAINER_multishortmap_get(
118 bindings->map,
119 &hash
120 );
121}
122
123void
124bindings_destroy(MESSENGER_Bindings *bindings)
125{
126 GNUNET_CONTAINER_multishortmap_destroy(bindings->map);
127
128 GNUNET_free(bindings);
129}