aboutsummaryrefslogtreecommitdiff
path: root/src/gns/plugin_gnsrecord_gns.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/gns/plugin_gnsrecord_gns.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/gns/plugin_gnsrecord_gns.c')
-rw-r--r--src/gns/plugin_gnsrecord_gns.c305
1 files changed, 153 insertions, 152 deletions
diff --git a/src/gns/plugin_gnsrecord_gns.c b/src/gns/plugin_gnsrecord_gns.c
index 094307ea3..e0bc4fb0c 100644
--- a/src/gns/plugin_gnsrecord_gns.c
+++ b/src/gns/plugin_gnsrecord_gns.c
@@ -44,49 +44,49 @@
44 * @return NULL on error, otherwise human-readable representation of the value 44 * @return NULL on error, otherwise human-readable representation of the value
45 */ 45 */
46static char * 46static char *
47gns_value_to_string(void *cls, 47gns_value_to_string (void *cls,
48 uint32_t type, 48 uint32_t type,
49 const void *data, 49 const void *data,
50 size_t data_size) 50 size_t data_size)
51{ 51{
52 const char *cdata; 52 const char *cdata;
53 53
54 switch (type) 54 switch (type)
55 { 55 {
56 case GNUNET_GNSRECORD_TYPE_PKEY: 56 case GNUNET_GNSRECORD_TYPE_PKEY:
57 if (data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) 57 if (data_size != sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey))
58 return NULL; 58 return NULL;
59 return GNUNET_CRYPTO_ecdsa_public_key_to_string(data); 59 return GNUNET_CRYPTO_ecdsa_public_key_to_string (data);
60 60
61 case GNUNET_GNSRECORD_TYPE_NICK: 61 case GNUNET_GNSRECORD_TYPE_NICK:
62 return GNUNET_strndup(data, data_size); 62 return GNUNET_strndup (data, data_size);
63 63
64 case GNUNET_GNSRECORD_TYPE_LEHO: 64 case GNUNET_GNSRECORD_TYPE_LEHO:
65 return GNUNET_strndup(data, data_size); 65 return GNUNET_strndup (data, data_size);
66 66
67 case GNUNET_GNSRECORD_TYPE_GNS2DNS: { 67 case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
68 char *ns; 68 char *ns;
69 char *ip; 69 char *ip;
70 size_t off; 70 size_t off;
71 char *nstr; 71 char *nstr;
72 72
73 off = 0; 73 off = 0;
74 ns = GNUNET_DNSPARSER_parse_name(data, data_size, &off); 74 ns = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
75 ip = GNUNET_DNSPARSER_parse_name(data, data_size, &off); 75 ip = GNUNET_DNSPARSER_parse_name (data, data_size, &off);
76 if ((NULL == ns) || (NULL == ip) || (off != data_size)) 76 if ((NULL == ns) || (NULL == ip) || (off != data_size))
77 { 77 {
78 GNUNET_break_op(0); 78 GNUNET_break_op (0);
79 GNUNET_free_non_null(ns); 79 GNUNET_free_non_null (ns);
80 GNUNET_free_non_null(ip); 80 GNUNET_free_non_null (ip);
81 return NULL; 81 return NULL;
82 } 82 }
83 GNUNET_asprintf(&nstr, "%s@%s", ns, ip); 83 GNUNET_asprintf (&nstr, "%s@%s", ns, ip);
84 GNUNET_free_non_null(ns); 84 GNUNET_free_non_null (ns);
85 GNUNET_free_non_null(ip); 85 GNUNET_free_non_null (ip);
86 return nstr; 86 return nstr;
87 } 87 }
88 88
89 case GNUNET_GNSRECORD_TYPE_VPN: { 89 case GNUNET_GNSRECORD_TYPE_VPN: {
90 struct GNUNET_TUN_GnsVpnRecord vpn; 90 struct GNUNET_TUN_GnsVpnRecord vpn;
91 char *vpn_str; 91 char *vpn_str;
92 92
@@ -94,16 +94,16 @@ gns_value_to_string(void *cls,
94 if ((data_size <= sizeof(vpn)) || ('\0' != cdata[data_size - 1])) 94 if ((data_size <= sizeof(vpn)) || ('\0' != cdata[data_size - 1]))
95 return NULL; /* malformed */ 95 return NULL; /* malformed */
96 /* need to memcpy for alignment */ 96 /* need to memcpy for alignment */
97 GNUNET_memcpy(&vpn, data, sizeof(vpn)); 97 GNUNET_memcpy (&vpn, data, sizeof(vpn));
98 GNUNET_asprintf(&vpn_str, 98 GNUNET_asprintf (&vpn_str,
99 "%u %s %s", 99 "%u %s %s",
100 (unsigned int)ntohs(vpn.proto), 100 (unsigned int) ntohs (vpn.proto),
101 (const char *)GNUNET_i2s_full(&vpn.peer), 101 (const char *) GNUNET_i2s_full (&vpn.peer),
102 (const char *)&cdata[sizeof(vpn)]); 102 (const char *) &cdata[sizeof(vpn)]);
103 return vpn_str; 103 return vpn_str;
104 } 104 }
105 105
106 case GNUNET_GNSRECORD_TYPE_BOX: { 106 case GNUNET_GNSRECORD_TYPE_BOX: {
107 struct GNUNET_GNSRECORD_BoxRecord box; 107 struct GNUNET_GNSRECORD_BoxRecord box;
108 uint32_t rt; 108 uint32_t rt;
109 char *box_str; 109 char *box_str;
@@ -112,26 +112,26 @@ gns_value_to_string(void *cls,
112 cdata = data; 112 cdata = data;
113 if (data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord)) 113 if (data_size < sizeof(struct GNUNET_GNSRECORD_BoxRecord))
114 return NULL; /* malformed */ 114 return NULL; /* malformed */
115 GNUNET_memcpy(&box, data, sizeof(box)); 115 GNUNET_memcpy (&box, data, sizeof(box));
116 rt = ntohl(box.record_type); 116 rt = ntohl (box.record_type);
117 ival = GNUNET_GNSRECORD_value_to_string(rt, 117 ival = GNUNET_GNSRECORD_value_to_string (rt,
118 &cdata[sizeof(box)], 118 &cdata[sizeof(box)],
119 data_size - sizeof(box)); 119 data_size - sizeof(box));
120 if (NULL == ival) 120 if (NULL == ival)
121 return NULL; /* malformed */ 121 return NULL; /* malformed */
122 GNUNET_asprintf(&box_str, 122 GNUNET_asprintf (&box_str,
123 "%u %u %u %s", 123 "%u %u %u %s",
124 (unsigned int)ntohs(box.protocol), 124 (unsigned int) ntohs (box.protocol),
125 (unsigned int)ntohs(box.service), 125 (unsigned int) ntohs (box.service),
126 (unsigned int)rt, 126 (unsigned int) rt,
127 ival); 127 ival);
128 GNUNET_free(ival); 128 GNUNET_free (ival);
129 return box_str; 129 return box_str;
130 } 130 }
131 131
132 default: 132 default:
133 return NULL; 133 return NULL;
134 } 134 }
135} 135}
136 136
137 137
@@ -147,112 +147,112 @@ gns_value_to_string(void *cls,
147 * @return #GNUNET_OK on success 147 * @return #GNUNET_OK on success
148 */ 148 */
149static int 149static int
150gns_string_to_value(void *cls, 150gns_string_to_value (void *cls,
151 uint32_t type, 151 uint32_t type,
152 const char *s, 152 const char *s,
153 void **data, 153 void **data,
154 size_t *data_size) 154 size_t *data_size)
155{ 155{
156 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 156 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
157 157
158 if (NULL == s) 158 if (NULL == s)
159 return GNUNET_SYSERR; 159 return GNUNET_SYSERR;
160 switch (type) 160 switch (type)
161 {
162 case GNUNET_GNSRECORD_TYPE_PKEY:
163 if (GNUNET_OK !=
164 GNUNET_CRYPTO_ecdsa_public_key_from_string (s, strlen (s), &pkey))
161 { 165 {
162 case GNUNET_GNSRECORD_TYPE_PKEY: 166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
163 if (GNUNET_OK != 167 _ ("Unable to parse PKEY record `%s'\n"),
164 GNUNET_CRYPTO_ecdsa_public_key_from_string(s, strlen(s), &pkey)) 168 s);
165 { 169 return GNUNET_SYSERR;
166 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 170 }
167 _("Unable to parse PKEY record `%s'\n"), 171 *data = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
168 s); 172 GNUNET_memcpy (*data, &pkey, sizeof(pkey));
169 return GNUNET_SYSERR; 173 *data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey);
170 } 174 return GNUNET_OK;
171 *data = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPublicKey); 175
172 GNUNET_memcpy(*data, &pkey, sizeof(pkey)); 176 case GNUNET_GNSRECORD_TYPE_NICK:
173 *data_size = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey); 177 *data = GNUNET_strdup (s);
174 return GNUNET_OK; 178 *data_size = strlen (s);
175 179 return GNUNET_OK;
176 case GNUNET_GNSRECORD_TYPE_NICK: 180
177 *data = GNUNET_strdup(s); 181 case GNUNET_GNSRECORD_TYPE_LEHO:
178 *data_size = strlen(s); 182 *data = GNUNET_strdup (s);
179 return GNUNET_OK; 183 *data_size = strlen (s);
180 184 return GNUNET_OK;
181 case GNUNET_GNSRECORD_TYPE_LEHO: 185
182 *data = GNUNET_strdup(s); 186 case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
183 *data_size = strlen(s);
184 return GNUNET_OK;
185
186 case GNUNET_GNSRECORD_TYPE_GNS2DNS: {
187 char nsbuf[514]; 187 char nsbuf[514];
188 char *cpy; 188 char *cpy;
189 char *at; 189 char *at;
190 size_t off; 190 size_t off;
191 191
192 cpy = GNUNET_strdup(s); 192 cpy = GNUNET_strdup (s);
193 at = strchr(cpy, '@'); 193 at = strchr (cpy, '@');
194 if (NULL == at) 194 if (NULL == at)
195 { 195 {
196 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 _("Unable to parse GNS2DNS record `%s'\n"), 197 _ ("Unable to parse GNS2DNS record `%s'\n"),
198 s); 198 s);
199 GNUNET_free(cpy); 199 GNUNET_free (cpy);
200 return GNUNET_SYSERR; 200 return GNUNET_SYSERR;
201 } 201 }
202 *at = '\0'; 202 *at = '\0';
203 at++; 203 at++;
204 204
205 off = 0; 205 off = 0;
206 if ((GNUNET_OK != GNUNET_DNSPARSER_builder_add_name(nsbuf, 206 if ((GNUNET_OK != GNUNET_DNSPARSER_builder_add_name (nsbuf,
207 sizeof(nsbuf), 207 sizeof(nsbuf),
208 &off, 208 &off,
209 cpy)) || 209 cpy)) ||
210 (GNUNET_OK != 210 (GNUNET_OK !=
211 GNUNET_DNSPARSER_builder_add_name(nsbuf, sizeof(nsbuf), &off, at))) 211 GNUNET_DNSPARSER_builder_add_name (nsbuf, sizeof(nsbuf), &off, at)))
212 { 212 {
213 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 213 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
214 _("Failed to serialize GNS2DNS record with value `%s'\n"), 214 _ ("Failed to serialize GNS2DNS record with value `%s'\n"),
215 s); 215 s);
216 GNUNET_free(cpy); 216 GNUNET_free (cpy);
217 return GNUNET_SYSERR; 217 return GNUNET_SYSERR;
218 } 218 }
219 GNUNET_free(cpy); 219 GNUNET_free (cpy);
220 *data_size = off; 220 *data_size = off;
221 *data = GNUNET_malloc(off); 221 *data = GNUNET_malloc (off);
222 GNUNET_memcpy(*data, nsbuf, off); 222 GNUNET_memcpy (*data, nsbuf, off);
223 return GNUNET_OK; 223 return GNUNET_OK;
224 } 224 }
225 225
226 case GNUNET_GNSRECORD_TYPE_VPN: { 226 case GNUNET_GNSRECORD_TYPE_VPN: {
227 struct GNUNET_TUN_GnsVpnRecord *vpn; 227 struct GNUNET_TUN_GnsVpnRecord *vpn;
228 char s_peer[103 + 1]; 228 char s_peer[103 + 1];
229 char s_serv[253 + 1]; 229 char s_serv[253 + 1];
230 unsigned int proto; 230 unsigned int proto;
231 231
232 if (3 != sscanf(s, "%u %103s %253s", &proto, s_peer, s_serv)) 232 if (3 != sscanf (s, "%u %103s %253s", &proto, s_peer, s_serv))
233 { 233 {
234 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 234 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
235 _("Unable to parse VPN record string `%s'\n"), 235 _ ("Unable to parse VPN record string `%s'\n"),
236 s); 236 s);
237 return GNUNET_SYSERR; 237 return GNUNET_SYSERR;
238 } 238 }
239 *data_size = sizeof(struct GNUNET_TUN_GnsVpnRecord) + strlen(s_serv) + 1; 239 *data_size = sizeof(struct GNUNET_TUN_GnsVpnRecord) + strlen (s_serv) + 1;
240 *data = vpn = GNUNET_malloc(*data_size); 240 *data = vpn = GNUNET_malloc (*data_size);
241 if (GNUNET_OK != 241 if (GNUNET_OK !=
242 GNUNET_CRYPTO_eddsa_public_key_from_string((char *)s_peer, 242 GNUNET_CRYPTO_eddsa_public_key_from_string ((char *) s_peer,
243 strlen(s_peer), 243 strlen (s_peer),
244 &vpn->peer.public_key)) 244 &vpn->peer.public_key))
245 { 245 {
246 GNUNET_free(vpn); 246 GNUNET_free (vpn);
247 *data_size = 0; 247 *data_size = 0;
248 return GNUNET_SYSERR; 248 return GNUNET_SYSERR;
249 } 249 }
250 vpn->proto = htons((uint16_t)proto); 250 vpn->proto = htons ((uint16_t) proto);
251 strcpy((char *)&vpn[1], s_serv); 251 strcpy ((char *) &vpn[1], s_serv);
252 return GNUNET_OK; 252 return GNUNET_OK;
253 } 253 }
254 254
255 case GNUNET_GNSRECORD_TYPE_BOX: { 255 case GNUNET_GNSRECORD_TYPE_BOX: {
256 struct GNUNET_GNSRECORD_BoxRecord *box; 256 struct GNUNET_GNSRECORD_BoxRecord *box;
257 size_t rest; 257 size_t rest;
258 unsigned int protocol; 258 unsigned int protocol;
@@ -261,32 +261,32 @@ gns_string_to_value(void *cls,
261 void *bval; 261 void *bval;
262 size_t bval_size; 262 size_t bval_size;
263 263
264 if (3 != sscanf(s, "%u %u %u ", &protocol, &service, &record_type)) 264 if (3 != sscanf (s, "%u %u %u ", &protocol, &service, &record_type))
265 { 265 {
266 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 266 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
267 _("Unable to parse BOX record string `%s'\n"), 267 _ ("Unable to parse BOX record string `%s'\n"),
268 s); 268 s);
269 return GNUNET_SYSERR; 269 return GNUNET_SYSERR;
270 } 270 }
271 rest = snprintf(NULL, 0, "%u %u %u ", protocol, service, record_type); 271 rest = snprintf (NULL, 0, "%u %u %u ", protocol, service, record_type);
272 if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value(record_type, 272 if (GNUNET_OK != GNUNET_GNSRECORD_string_to_value (record_type,
273 &s[rest], 273 &s[rest],
274 &bval, 274 &bval,
275 &bval_size)) 275 &bval_size))
276 return GNUNET_SYSERR; 276 return GNUNET_SYSERR;
277 *data_size = sizeof(struct GNUNET_GNSRECORD_BoxRecord) + bval_size; 277 *data_size = sizeof(struct GNUNET_GNSRECORD_BoxRecord) + bval_size;
278 *data = box = GNUNET_malloc(*data_size); 278 *data = box = GNUNET_malloc (*data_size);
279 box->protocol = htons(protocol); 279 box->protocol = htons (protocol);
280 box->service = htons(service); 280 box->service = htons (service);
281 box->record_type = htonl(record_type); 281 box->record_type = htonl (record_type);
282 GNUNET_memcpy(&box[1], bval, bval_size); 282 GNUNET_memcpy (&box[1], bval, bval_size);
283 GNUNET_free(bval); 283 GNUNET_free (bval);
284 return GNUNET_OK; 284 return GNUNET_OK;
285 } 285 }
286 286
287 default: 287 default:
288 return GNUNET_SYSERR; 288 return GNUNET_SYSERR;
289 } 289 }
290} 290}
291 291
292 292
@@ -294,7 +294,8 @@ gns_string_to_value(void *cls,
294 * Mapping of record type numbers to human-readable 294 * Mapping of record type numbers to human-readable
295 * record type names. 295 * record type names.
296 */ 296 */
297static struct { 297static struct
298{
298 const char *name; 299 const char *name;
299 uint32_t number; 300 uint32_t number;
300} gns_name_map[] = { { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY }, 301} gns_name_map[] = { { "PKEY", GNUNET_GNSRECORD_TYPE_PKEY },
@@ -314,13 +315,13 @@ static struct {
314 * @return corresponding number, UINT32_MAX on error 315 * @return corresponding number, UINT32_MAX on error
315 */ 316 */
316static uint32_t 317static uint32_t
317gns_typename_to_number(void *cls, const char *gns_typename) 318gns_typename_to_number (void *cls, const char *gns_typename)
318{ 319{
319 unsigned int i; 320 unsigned int i;
320 321
321 i = 0; 322 i = 0;
322 while ((NULL != gns_name_map[i].name) && 323 while ((NULL != gns_name_map[i].name) &&
323 (0 != strcasecmp(gns_typename, gns_name_map[i].name))) 324 (0 != strcasecmp (gns_typename, gns_name_map[i].name)))
324 i++; 325 i++;
325 return gns_name_map[i].number; 326 return gns_name_map[i].number;
326} 327}
@@ -334,7 +335,7 @@ gns_typename_to_number(void *cls, const char *gns_typename)
334 * @return corresponding typestring, NULL on error 335 * @return corresponding typestring, NULL on error
335 */ 336 */
336static const char * 337static const char *
337gns_number_to_typename(void *cls, uint32_t type) 338gns_number_to_typename (void *cls, uint32_t type)
338{ 339{
339 unsigned int i; 340 unsigned int i;
340 341
@@ -352,11 +353,11 @@ gns_number_to_typename(void *cls, uint32_t type)
352 * @return the exported block API 353 * @return the exported block API
353 */ 354 */
354void * 355void *
355libgnunet_plugin_gnsrecord_gns_init(void *cls) 356libgnunet_plugin_gnsrecord_gns_init (void *cls)
356{ 357{
357 struct GNUNET_GNSRECORD_PluginFunctions *api; 358 struct GNUNET_GNSRECORD_PluginFunctions *api;
358 359
359 api = GNUNET_new(struct GNUNET_GNSRECORD_PluginFunctions); 360 api = GNUNET_new (struct GNUNET_GNSRECORD_PluginFunctions);
360 api->value_to_string = &gns_value_to_string; 361 api->value_to_string = &gns_value_to_string;
361 api->string_to_value = &gns_string_to_value; 362 api->string_to_value = &gns_string_to_value;
362 api->typename_to_number = &gns_typename_to_number; 363 api->typename_to_number = &gns_typename_to_number;
@@ -372,11 +373,11 @@ libgnunet_plugin_gnsrecord_gns_init(void *cls)
372 * @return NULL 373 * @return NULL
373 */ 374 */
374void * 375void *
375libgnunet_plugin_gnsrecord_gns_done(void *cls) 376libgnunet_plugin_gnsrecord_gns_done (void *cls)
376{ 377{
377 struct GNUNET_GNSRECORD_PluginFunctions *api = cls; 378 struct GNUNET_GNSRECORD_PluginFunctions *api = cls;
378 379
379 GNUNET_free(api); 380 GNUNET_free (api);
380 return NULL; 381 return NULL;
381} 382}
382 383