diff options
Diffstat (limited to 'src/reclaim/plugin_gnsrecord_reclaim.c')
-rw-r--r-- | src/reclaim/plugin_gnsrecord_reclaim.c | 118 |
1 files changed, 48 insertions, 70 deletions
diff --git a/src/reclaim/plugin_gnsrecord_reclaim.c b/src/reclaim/plugin_gnsrecord_reclaim.c index 2f075d8b9..612fec3bd 100644 --- a/src/reclaim/plugin_gnsrecord_reclaim.c +++ b/src/reclaim/plugin_gnsrecord_reclaim.c | |||
@@ -24,11 +24,12 @@ | |||
24 | * @author Martin Schanzenbach | 24 | * @author Martin Schanzenbach |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | |||
27 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | |||
28 | #include "gnunet_gnsrecord_lib.h" | 30 | #include "gnunet_gnsrecord_lib.h" |
29 | #include "gnunet_gnsrecord_plugin.h" | 31 | #include "gnunet_gnsrecord_plugin.h" |
30 | 32 | ||
31 | |||
32 | /** | 33 | /** |
33 | * Convert the 'value' of a record to a string. | 34 | * Convert the 'value' of a record to a string. |
34 | * | 35 | * |
@@ -38,25 +39,21 @@ | |||
38 | * @param data_size number of bytes in @a data | 39 | * @param data_size number of bytes in @a data |
39 | * @return NULL on error, otherwise human-readable representation of the value | 40 | * @return NULL on error, otherwise human-readable representation of the value |
40 | */ | 41 | */ |
41 | static char * | 42 | static char *value_to_string (void *cls, uint32_t type, const void *data, |
42 | value_to_string (void *cls, | 43 | size_t data_size) |
43 | uint32_t type, | ||
44 | const void *data, | ||
45 | size_t data_size) | ||
46 | { | 44 | { |
47 | switch (type) | 45 | switch (type) { |
48 | { | 46 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: |
49 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: | 47 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); |
50 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); | 48 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: |
51 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: | 49 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: |
52 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: | 50 | return GNUNET_strndup (data, data_size); |
53 | return GNUNET_strndup (data, data_size); | 51 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: |
54 | case GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ: | 52 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: |
55 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: | 53 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
56 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 54 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); |
57 | return GNUNET_STRINGS_data_to_string_alloc (data, data_size); | 55 | default: |
58 | default: | 56 | return NULL; |
59 | return NULL; | ||
60 | } | 57 | } |
61 | } | 58 | } |
62 | 59 | ||
@@ -72,36 +69,25 @@ value_to_string (void *cls, | |||
72 | * @param data_size set to number of bytes in @a data | 69 | * @param data_size set to number of bytes in @a data |
73 | * @return #GNUNET_OK on success | 70 | * @return #GNUNET_OK on success |
74 | */ | 71 | */ |
75 | static int | 72 | static int string_to_value (void *cls, uint32_t type, const char *s, |
76 | string_to_value (void *cls, | 73 | void **data, size_t *data_size) |
77 | uint32_t type, | ||
78 | const char *s, | ||
79 | void **data, | ||
80 | size_t *data_size) | ||
81 | { | 74 | { |
82 | if (NULL == s) | 75 | if (NULL == s) |
83 | return GNUNET_SYSERR; | 76 | return GNUNET_SYSERR; |
84 | switch (type) | 77 | switch (type) { |
85 | { | 78 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: |
86 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR: | 79 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); |
87 | return GNUNET_STRINGS_string_to_data (s, | 80 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: |
88 | strlen (s), | 81 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: |
89 | *data, | 82 | *data = GNUNET_strdup (s); |
90 | *data_size); | 83 | *data_size = strlen (s); |
91 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT: | 84 | return GNUNET_OK; |
92 | case GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT: | 85 | case GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF: |
93 | *data = GNUNET_strdup (s); | 86 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: |
94 | *data_size = strlen (s); | 87 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: |
95 | return GNUNET_OK; | 88 | return GNUNET_STRINGS_string_to_data (s, strlen (s), *data, *data_size); |
96 | case GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ: | 89 | default: |
97 | case GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER: | 90 | return GNUNET_SYSERR; |
98 | case GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF: | ||
99 | return GNUNET_STRINGS_string_to_data (s, | ||
100 | strlen (s), | ||
101 | *data, | ||
102 | *data_size); | ||
103 | default: | ||
104 | return GNUNET_SYSERR; | ||
105 | } | 91 | } |
106 | } | 92 | } |
107 | 93 | ||
@@ -114,14 +100,13 @@ static struct { | |||
114 | const char *name; | 100 | const char *name; |
115 | uint32_t number; | 101 | uint32_t number; |
116 | } name_map[] = { | 102 | } name_map[] = { |
117 | { "RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR }, | 103 | {"RECLAIM_ATTR", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR}, |
118 | { "RECLAIM_AUTHZ", GNUNET_GNSRECORD_TYPE_RECLAIM_AUTHZ }, | 104 | {"RECLAIM_ATTR_REF", GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF}, |
119 | { "RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER }, | 105 | {"RECLAIM_MASTER", GNUNET_GNSRECORD_TYPE_RECLAIM_MASTER}, |
120 | { "RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT }, | 106 | {"RECLAIM_OIDC_CLIENT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_CLIENT}, |
121 | { "RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT }, | 107 | {"RECLAIM_OIDC_REDIRECT", GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT}, |
122 | { "RECLAIM_TICKETREF", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF }, | 108 | {"RECLAIM_TICKETREF", GNUNET_GNSRECORD_TYPE_RECLAIM_TICKETREF}, |
123 | { NULL, UINT32_MAX } | 109 | {NULL, UINT32_MAX}}; |
124 | }; | ||
125 | 110 | ||
126 | 111 | ||
127 | /** | 112 | /** |
@@ -131,15 +116,13 @@ static struct { | |||
131 | * @param dns_typename name to convert | 116 | * @param dns_typename name to convert |
132 | * @return corresponding number, UINT32_MAX on error | 117 | * @return corresponding number, UINT32_MAX on error |
133 | */ | 118 | */ |
134 | static uint32_t | 119 | static uint32_t typename_to_number (void *cls, const char *dns_typename) |
135 | typename_to_number (void *cls, | ||
136 | const char *dns_typename) | ||
137 | { | 120 | { |
138 | unsigned int i; | 121 | unsigned int i; |
139 | 122 | ||
140 | i=0; | 123 | i = 0; |
141 | while ( (NULL != name_map[i].name) && | 124 | while ((NULL != name_map[i].name) && |
142 | (0 != strcasecmp (dns_typename, name_map[i].name)) ) | 125 | (0 != strcasecmp (dns_typename, name_map[i].name))) |
143 | i++; | 126 | i++; |
144 | return name_map[i].number; | 127 | return name_map[i].number; |
145 | } | 128 | } |
@@ -152,15 +135,12 @@ typename_to_number (void *cls, | |||
152 | * @param type number of a type to convert | 135 | * @param type number of a type to convert |
153 | * @return corresponding typestring, NULL on error | 136 | * @return corresponding typestring, NULL on error |
154 | */ | 137 | */ |
155 | static const char * | 138 | static const char *number_to_typename (void *cls, uint32_t type) |
156 | number_to_typename (void *cls, | ||
157 | uint32_t type) | ||
158 | { | 139 | { |
159 | unsigned int i; | 140 | unsigned int i; |
160 | 141 | ||
161 | i=0; | 142 | i = 0; |
162 | while ( (NULL != name_map[i].name) && | 143 | while ((NULL != name_map[i].name) && (type != name_map[i].number)) |
163 | (type != name_map[i].number) ) | ||
164 | i++; | 144 | i++; |
165 | return name_map[i].name; | 145 | return name_map[i].name; |
166 | } | 146 | } |
@@ -172,8 +152,7 @@ number_to_typename (void *cls, | |||
172 | * @param cls NULL | 152 | * @param cls NULL |
173 | * @return the exported block API | 153 | * @return the exported block API |
174 | */ | 154 | */ |
175 | void * | 155 | void *libgnunet_plugin_gnsrecord_reclaim_init (void *cls) |
176 | libgnunet_plugin_gnsrecord_reclaim_init (void *cls) | ||
177 | { | 156 | { |
178 | struct GNUNET_GNSRECORD_PluginFunctions *api; | 157 | struct GNUNET_GNSRECORD_PluginFunctions *api; |
179 | 158 | ||
@@ -192,8 +171,7 @@ libgnunet_plugin_gnsrecord_reclaim_init (void *cls) | |||
192 | * @param cls the return value from #libgnunet_plugin_block_test_init | 171 | * @param cls the return value from #libgnunet_plugin_block_test_init |
193 | * @return NULL | 172 | * @return NULL |
194 | */ | 173 | */ |
195 | void * | 174 | void *libgnunet_plugin_gnsrecord_reclaim_done (void *cls) |
196 | libgnunet_plugin_gnsrecord_reclaim_done (void *cls) | ||
197 | { | 175 | { |
198 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; | 176 | struct GNUNET_GNSRECORD_PluginFunctions *api = cls; |
199 | 177 | ||