diff options
Diffstat (limited to 'src/reclaim/plugin_gnsrecord_reclaim.c')
-rw-r--r-- | src/reclaim/plugin_gnsrecord_reclaim.c | 101 |
1 files changed, 55 insertions, 46 deletions
diff --git a/src/reclaim/plugin_gnsrecord_reclaim.c b/src/reclaim/plugin_gnsrecord_reclaim.c index 48cdd9811..708142774 100644 --- a/src/reclaim/plugin_gnsrecord_reclaim.c +++ b/src/reclaim/plugin_gnsrecord_reclaim.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file reclaim/plugin_gnsrecord_reclaim.c | 22 | * @file reclaim/plugin_gnsrecord_reclaim.c |
@@ -40,21 +40,25 @@ | |||
40 | * @return NULL on error, otherwise human-readable representation of the value | 40 | * @return NULL on error, otherwise human-readable representation of the value |
41 | */ | 41 | */ |
42 | static char * | 42 | static char * |
43 | value_to_string (void *cls, uint32_t type, const void *data, size_t data_size) | 43 | value_to_string(void *cls, uint32_t type, const void *data, size_t data_size) |
44 | { | 44 | { |
45 | switch (type) { | 45 | switch (type) |
46 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: | 46 | { |
47 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); | 47 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: |
48 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: | 48 | return GNUNET_STRINGS_data_to_string_alloc(data, data_size); |
49 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: | 49 | |
50 | return GNUNET_strndup (data, data_size); | 50 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: |
51 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: | 51 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: |
52 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: | 52 | return GNUNET_strndup(data, data_size); |
53 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 53 | |
54 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); | 54 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: |
55 | default: | 55 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: |
56 | return NULL; | 56 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
57 | } | 57 | return GNUNET_STRINGS_data_to_string_alloc(data, data_size); |
58 | |||
59 | default: | ||
60 | return NULL; | ||
61 | } | ||
58 | } | 62 | } |
59 | 63 | ||
60 | 64 | ||
@@ -70,26 +74,30 @@ value_to_string (void *cls, uint32_t type, const void *data, size_t data_size) | |||
70 | * @return #GNUNET_OK on success | 74 | * @return #GNUNET_OK on success |
71 | */ | 75 | */ |
72 | static int | 76 | static int |
73 | string_to_value (void *cls, uint32_t type, const char *s, void **data, | 77 | string_to_value(void *cls, uint32_t type, const char *s, void **data, |
74 | size_t *data_size) | 78 | size_t *data_size) |
75 | { | 79 | { |
76 | if (NULL == s) | 80 | if (NULL == s) |
77 | return GNUNET_SYSERR; | 81 | return GNUNET_SYSERR; |
78 | switch (type) { | 82 | switch (type) |
79 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: | 83 | { |
80 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); | 84 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: |
81 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: | 85 | return GNUNET_STRINGS_string_to_data(s, strlen(s), *data, *data_size); |
82 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: | 86 | |
83 | *data = GNUNET_strdup (s); | 87 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: |
84 | *data_size = strlen (s); | 88 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: |
85 | return GNUNET_OK; | 89 | *data = GNUNET_strdup(s); |
86 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: | 90 | *data_size = strlen(s); |
87 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 91 | return GNUNET_OK; |
88 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: | 92 | |
89 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); | 93 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: |
90 | default: | 94 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
91 | return GNUNET_SYSERR; | 95 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET: |
92 | } | 96 | return GNUNET_STRINGS_string_to_data(s, strlen(s), *data, *data_size); |
97 | |||
98 | default: | ||
99 | return GNUNET_SYSERR; | ||
100 | } | ||
93 | } | 101 | } |
94 | 102 | ||
95 | 103 | ||
@@ -101,13 +109,14 @@ static struct { | |||
101 | const char *name; | 109 | const char *name; |
102 | uint32_t number; | 110 | uint32_t number; |
103 | } name_map[] = { | 111 | } name_map[] = { |
104 | {"RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR}, | 112 | { "RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR }, |
105 | {"RECLAIM_ATTR_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF}, | 113 | { "RECLAIM_ATTR_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF }, |
106 | {"RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER}, | 114 | { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER }, |
107 | {"RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT}, | 115 | { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT }, |
108 | {"RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT}, | 116 | { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT }, |
109 | {"RECLAIM_TICKET", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET}, | 117 | { "RECLAIM_TICKET", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET }, |
110 | {NULL, UINT32_MAX}}; | 118 | { NULL, UINT32_MAX } |
119 | }; | ||
111 | 120 | ||
112 | 121 | ||
113 | /** | 122 | /** |
@@ -118,13 +127,13 @@ static struct { | |||
118 | * @return corresponding number, UINT32_MAX on error | 127 | * @return corresponding number, UINT32_MAX on error |
119 | */ | 128 | */ |
120 | static uint32_t | 129 | static uint32_t |
121 | typename_to_number (void *cls, const char *dns_typename) | 130 | typename_to_number(void *cls, const char *dns_typename) |
122 | { | 131 | { |
123 | unsigned int i; | 132 | unsigned int i; |
124 | 133 | ||
125 | i = 0; | 134 | i = 0; |
126 | while ((NULL != name_map[i].name) && | 135 | while ((NULL != name_map[i].name) && |
127 | (0 != strcasecmp (dns_typename, name_map[i].name))) | 136 | (0 != strcasecmp(dns_typename, name_map[i].name))) |
128 | i++; | 137 | i++; |
129 | return name_map[i].number; | 138 | return name_map[i].number; |
130 | } | 139 | } |
@@ -138,7 +147,7 @@ typename_to_number (void *cls, const char *dns_typename) | |||
138 | * @return corresponding typestring, NULL on error | 147 | * @return corresponding typestring, NULL on error |
139 | */ | 148 | */ |
140 | static const char * | 149 | static const char * |
141 | number_to_typename (void *cls, uint32_t type) | 150 | number_to_typename(void *cls, uint32_t type) |
142 | { | 151 | { |
143 | unsigned int i; | 152 | unsigned int i; |
144 | 153 | ||
@@ -156,11 +165,11 @@ number_to_typename (void *cls, uint32_t type) | |||
156 | * @return the exported block API | 165 | * @return the exported block API |
157 | */ | 166 | */ |
158 | void * | 167 | void * |
159 | libgnunet_plugin_gnsrecord_reclaim_init (void *cls) | 168 | libgnunet_plugin_gnsrecord_reclaim_init(void *cls) |
160 | { | 169 | { |
161 | struct GNUNET_GNSRECORD_PluginFunctions *api; | 170 | struct GNUNET_GNSRECORD_PluginFunctions *api; |
162 | 171 | ||
163 | api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions); | 172 | api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); |
164 | api->value_to_string = &value_to_string; | 173 | api->value_to_string = &value_to_string; |
165 | api->string_to_value = &string_to_value; | 174 | api->string_to_value = &string_to_value; |
166 | api->typename_to_number = &typename_to_number; | 175 | api->typename_to_number = &typename_to_number; |
@@ -176,11 +185,11 @@ libgnunet_plugin_gnsrecord_reclaim_init (void *cls) | |||
176 | * @return NULL | 185 | * @return NULL |
177 | */ | 186 | */ |
178 | void * | 187 | void * |
179 | libgnunet_plugin_gnsrecord_reclaim_done (void *cls) | 188 | libgnunet_plugin_gnsrecord_reclaim_done(void *cls) |
180 | { | 189 | { |
181 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; | 190 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; |
182 | 191 | ||
183 | GNUNET_free (api); | 192 | GNUNET_free(api); |
184 | return NULL; | 193 | return NULL; |
185 | } | 194 | } |
186 | 195 | ||