diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/identity | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/identity')
-rw-r--r-- | src/identity/gnunet-identity.c | 360 | ||||
-rw-r--r-- | src/identity/gnunet-service-identity.c | 1059 | ||||
-rw-r--r-- | src/identity/identity.h | 29 | ||||
-rw-r--r-- | src/identity/identity_api.c | 605 | ||||
-rw-r--r-- | src/identity/identity_api_lookup.c | 122 | ||||
-rw-r--r-- | src/identity/identity_api_suffix_lookup.c | 122 | ||||
-rw-r--r-- | src/identity/plugin_rest_identity.c | 1090 | ||||
-rw-r--r-- | src/identity/test_identity.c | 225 | ||||
-rw-r--r-- | src/identity/test_identity_defaults.c | 178 |
9 files changed, 1887 insertions, 1903 deletions
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c index 41878fc1e..d86fd2166 100644 --- a/src/identity/gnunet-identity.c +++ b/src/identity/gnunet-identity.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 | * @file identity/gnunet-identity.c | 21 | * @file identity/gnunet-identity.c |
22 | * @brief IDENTITY management command line tool | 22 | * @brief IDENTITY management command line tool |
@@ -112,29 +112,29 @@ static int global_ret; | |||
112 | * @param cls NULL | 112 | * @param cls NULL |
113 | */ | 113 | */ |
114 | static void | 114 | static void |
115 | shutdown_task (void *cls) | 115 | shutdown_task(void *cls) |
116 | { | 116 | { |
117 | if (NULL != set_op) | 117 | if (NULL != set_op) |
118 | { | 118 | { |
119 | GNUNET_IDENTITY_cancel (set_op); | 119 | GNUNET_IDENTITY_cancel(set_op); |
120 | set_op = NULL; | 120 | set_op = NULL; |
121 | } | 121 | } |
122 | if (NULL != create_op) | 122 | if (NULL != create_op) |
123 | { | 123 | { |
124 | GNUNET_IDENTITY_cancel (create_op); | 124 | GNUNET_IDENTITY_cancel(create_op); |
125 | create_op = NULL; | 125 | create_op = NULL; |
126 | } | 126 | } |
127 | if (NULL != delete_op) | 127 | if (NULL != delete_op) |
128 | { | 128 | { |
129 | GNUNET_IDENTITY_cancel (delete_op); | 129 | GNUNET_IDENTITY_cancel(delete_op); |
130 | delete_op = NULL; | 130 | delete_op = NULL; |
131 | } | 131 | } |
132 | if (NULL != set_ego) | 132 | if (NULL != set_ego) |
133 | { | 133 | { |
134 | GNUNET_free (set_ego); | 134 | GNUNET_free(set_ego); |
135 | set_ego = NULL; | 135 | set_ego = NULL; |
136 | } | 136 | } |
137 | GNUNET_IDENTITY_disconnect (sh); | 137 | GNUNET_IDENTITY_disconnect(sh); |
138 | sh = NULL; | 138 | sh = NULL; |
139 | } | 139 | } |
140 | 140 | ||
@@ -143,15 +143,15 @@ shutdown_task (void *cls) | |||
143 | * Test if we are finished yet. | 143 | * Test if we are finished yet. |
144 | */ | 144 | */ |
145 | static void | 145 | static void |
146 | test_finished () | 146 | test_finished() |
147 | { | 147 | { |
148 | if ((NULL == create_op) && (NULL == delete_op) && (NULL == set_op) && | 148 | if ((NULL == create_op) && (NULL == delete_op) && (NULL == set_op) && |
149 | (NULL == set_subsystem) && (! list) && (! monitor)) | 149 | (NULL == set_subsystem) && (!list) && (!monitor)) |
150 | { | 150 | { |
151 | if (TIMEOUT_STATUS_CODE == global_ret) | 151 | if (TIMEOUT_STATUS_CODE == global_ret) |
152 | global_ret = 0; | 152 | global_ret = 0; |
153 | GNUNET_SCHEDULER_shutdown (); | 153 | GNUNET_SCHEDULER_shutdown(); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 | ||
157 | 157 | ||
@@ -162,14 +162,14 @@ test_finished () | |||
162 | * @param emsg NULL on success, otherwise an error message | 162 | * @param emsg NULL on success, otherwise an error message |
163 | */ | 163 | */ |
164 | static void | 164 | static void |
165 | delete_finished (void *cls, const char *emsg) | 165 | delete_finished(void *cls, const char *emsg) |
166 | { | 166 | { |
167 | struct GNUNET_IDENTITY_Operation **op = cls; | 167 | struct GNUNET_IDENTITY_Operation **op = cls; |
168 | 168 | ||
169 | *op = NULL; | 169 | *op = NULL; |
170 | if (NULL != emsg) | 170 | if (NULL != emsg) |
171 | fprintf (stderr, "%s\n", gettext (emsg)); | 171 | fprintf(stderr, "%s\n", gettext(emsg)); |
172 | test_finished (); | 172 | test_finished(); |
173 | } | 173 | } |
174 | 174 | ||
175 | 175 | ||
@@ -181,40 +181,40 @@ delete_finished (void *cls, const char *emsg) | |||
181 | * @param emsg error message, NULL on success | 181 | * @param emsg error message, NULL on success |
182 | */ | 182 | */ |
183 | static void | 183 | static void |
184 | create_finished (void *cls, | 184 | create_finished(void *cls, |
185 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 185 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
186 | const char *emsg) | 186 | const char *emsg) |
187 | { | 187 | { |
188 | struct GNUNET_IDENTITY_Operation **op = cls; | 188 | struct GNUNET_IDENTITY_Operation **op = cls; |
189 | 189 | ||
190 | *op = NULL; | 190 | *op = NULL; |
191 | if (NULL == pk) | 191 | if (NULL == pk) |
192 | { | ||
193 | fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg); | ||
194 | global_ret = 1; | ||
195 | } | ||
196 | else if (verbose) | ||
197 | { | ||
198 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
199 | char *pubs; | ||
200 | |||
201 | GNUNET_CRYPTO_ecdsa_key_get_public (pk, &pub); | ||
202 | pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub); | ||
203 | if (private_keys) | ||
204 | { | 192 | { |
205 | char *privs; | 193 | fprintf(stderr, _("Failed to create ego: %s\n"), emsg); |
206 | 194 | global_ret = 1; | |
207 | privs = GNUNET_CRYPTO_ecdsa_private_key_to_string (pk); | ||
208 | fprintf (stdout, "%s - %s\n", pubs, privs); | ||
209 | GNUNET_free (privs); | ||
210 | } | 195 | } |
211 | else | 196 | else if (verbose) |
212 | { | 197 | { |
213 | fprintf (stdout, "%s\n", pubs); | 198 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
199 | char *pubs; | ||
200 | |||
201 | GNUNET_CRYPTO_ecdsa_key_get_public(pk, &pub); | ||
202 | pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pub); | ||
203 | if (private_keys) | ||
204 | { | ||
205 | char *privs; | ||
206 | |||
207 | privs = GNUNET_CRYPTO_ecdsa_private_key_to_string(pk); | ||
208 | fprintf(stdout, "%s - %s\n", pubs, privs); | ||
209 | GNUNET_free(privs); | ||
210 | } | ||
211 | else | ||
212 | { | ||
213 | fprintf(stdout, "%s\n", pubs); | ||
214 | } | ||
215 | GNUNET_free(pubs); | ||
214 | } | 216 | } |
215 | GNUNET_free (pubs); | 217 | test_finished(); |
216 | } | ||
217 | test_finished (); | ||
218 | } | 218 | } |
219 | 219 | ||
220 | 220 | ||
@@ -225,15 +225,15 @@ create_finished (void *cls, | |||
225 | * @param emsg error message (NULL on success) | 225 | * @param emsg error message (NULL on success) |
226 | */ | 226 | */ |
227 | static void | 227 | static void |
228 | set_done (void *cls, const char *emsg) | 228 | set_done(void *cls, const char *emsg) |
229 | { | 229 | { |
230 | set_op = NULL; | 230 | set_op = NULL; |
231 | if (NULL != emsg) | 231 | if (NULL != emsg) |
232 | { | 232 | { |
233 | fprintf (stderr, _ ("Failed to set default ego: %s\n"), emsg); | 233 | fprintf(stderr, _("Failed to set default ego: %s\n"), emsg); |
234 | global_ret = 1; | 234 | global_ret = 1; |
235 | } | 235 | } |
236 | test_finished (); | 236 | test_finished(); |
237 | } | 237 | } |
238 | 238 | ||
239 | 239 | ||
@@ -269,72 +269,72 @@ set_done (void *cls, const char *emsg) | |||
269 | * @param identifier identifier assigned by the user for this ego, | 269 | * @param identifier identifier assigned by the user for this ego, |
270 | * NULL if the user just deleted the ego and it | 270 | * NULL if the user just deleted the ego and it |
271 | * must thus no longer be used | 271 | * must thus no longer be used |
272 | */ | 272 | */ |
273 | static void | 273 | static void |
274 | print_ego (void *cls, | 274 | print_ego(void *cls, |
275 | struct GNUNET_IDENTITY_Ego *ego, | 275 | struct GNUNET_IDENTITY_Ego *ego, |
276 | void **ctx, | 276 | void **ctx, |
277 | const char *identifier) | 277 | const char *identifier) |
278 | { | 278 | { |
279 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 279 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
280 | char *s; | 280 | char *s; |
281 | char *privs; | 281 | char *privs; |
282 | 282 | ||
283 | if ((NULL != set_ego) && (NULL != set_subsystem) && (NULL != ego) && | 283 | if ((NULL != set_ego) && (NULL != set_subsystem) && (NULL != ego) && |
284 | (NULL != identifier) && (0 == strcmp (identifier, set_ego))) | 284 | (NULL != identifier) && (0 == strcmp(identifier, set_ego))) |
285 | { | 285 | { |
286 | set_op = GNUNET_IDENTITY_set (sh, set_subsystem, ego, &set_done, NULL); | 286 | set_op = GNUNET_IDENTITY_set(sh, set_subsystem, ego, &set_done, NULL); |
287 | GNUNET_free (set_subsystem); | 287 | GNUNET_free(set_subsystem); |
288 | set_subsystem = NULL; | 288 | set_subsystem = NULL; |
289 | GNUNET_free (set_ego); | 289 | GNUNET_free(set_ego); |
290 | set_ego = NULL; | 290 | set_ego = NULL; |
291 | } | 291 | } |
292 | if ((NULL == ego) && (NULL != set_ego) && (NULL != set_subsystem)) | 292 | if ((NULL == ego) && (NULL != set_ego) && (NULL != set_subsystem)) |
293 | { | 293 | { |
294 | fprintf (stderr, | 294 | fprintf(stderr, |
295 | "Could not set ego to `%s' for subsystem `%s', ego not known\n", | 295 | "Could not set ego to `%s' for subsystem `%s', ego not known\n", |
296 | set_ego, | 296 | set_ego, |
297 | set_subsystem); | 297 | set_subsystem); |
298 | GNUNET_free (set_subsystem); | 298 | GNUNET_free(set_subsystem); |
299 | set_subsystem = NULL; | 299 | set_subsystem = NULL; |
300 | GNUNET_free (set_ego); | 300 | GNUNET_free(set_ego); |
301 | set_ego = NULL; | 301 | set_ego = NULL; |
302 | } | 302 | } |
303 | if ((NULL == ego) && (! monitor)) | 303 | if ((NULL == ego) && (!monitor)) |
304 | { | 304 | { |
305 | list = 0; | 305 | list = 0; |
306 | test_finished (); | 306 | test_finished(); |
307 | return; | 307 | return; |
308 | } | 308 | } |
309 | if (! (list | monitor)) | 309 | if (!(list | monitor)) |
310 | return; | 310 | return; |
311 | if ((NULL == ego) || (NULL == identifier)) | 311 | if ((NULL == ego) || (NULL == identifier)) |
312 | return; | 312 | return; |
313 | if ((NULL != set_ego) && (0 != strcmp (identifier, set_ego))) | 313 | if ((NULL != set_ego) && (0 != strcmp(identifier, set_ego))) |
314 | return; | 314 | return; |
315 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 315 | GNUNET_IDENTITY_ego_get_public_key(ego, &pk); |
316 | s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 316 | s = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); |
317 | privs = GNUNET_CRYPTO_ecdsa_private_key_to_string ( | 317 | privs = GNUNET_CRYPTO_ecdsa_private_key_to_string( |
318 | GNUNET_IDENTITY_ego_get_private_key (ego)); | 318 | GNUNET_IDENTITY_ego_get_private_key(ego)); |
319 | if ((monitor) || (NULL != identifier)) | 319 | if ((monitor) || (NULL != identifier)) |
320 | { | ||
321 | if (quiet) | ||
322 | { | 320 | { |
323 | if (private_keys) | 321 | if (quiet) |
324 | fprintf (stdout, "%s - %s\n", s, privs); | 322 | { |
323 | if (private_keys) | ||
324 | fprintf(stdout, "%s - %s\n", s, privs); | ||
325 | else | ||
326 | fprintf(stdout, "%s\n", s); | ||
327 | } | ||
325 | else | 328 | else |
326 | fprintf (stdout, "%s\n", s); | 329 | { |
330 | if (private_keys) | ||
331 | fprintf(stdout, "%s - %s - %s\n", identifier, s, privs); | ||
332 | else | ||
333 | fprintf(stdout, "%s - %s\n", identifier, s); | ||
334 | } | ||
327 | } | 335 | } |
328 | else | 336 | GNUNET_free(privs); |
329 | { | 337 | GNUNET_free(s); |
330 | if (private_keys) | ||
331 | fprintf (stdout, "%s - %s - %s\n", identifier, s, privs); | ||
332 | else | ||
333 | fprintf (stdout, "%s - %s\n", identifier, s); | ||
334 | } | ||
335 | } | ||
336 | GNUNET_free (privs); | ||
337 | GNUNET_free (s); | ||
338 | } | 338 | } |
339 | 339 | ||
340 | 340 | ||
@@ -347,30 +347,30 @@ print_ego (void *cls, | |||
347 | * @param cfg configuration | 347 | * @param cfg configuration |
348 | */ | 348 | */ |
349 | static void | 349 | static void |
350 | run (void *cls, | 350 | run(void *cls, |
351 | char *const *args, | 351 | char *const *args, |
352 | const char *cfgfile, | 352 | const char *cfgfile, |
353 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 353 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
354 | { | 354 | { |
355 | if ((NULL != set_subsystem) && (NULL == set_ego)) | 355 | if ((NULL != set_subsystem) && (NULL == set_ego)) |
356 | { | 356 | { |
357 | fprintf (stderr, "Option -s requires option -e to be specified as well.\n"); | 357 | fprintf(stderr, "Option -s requires option -e to be specified as well.\n"); |
358 | return; | 358 | return; |
359 | } | 359 | } |
360 | sh = GNUNET_IDENTITY_connect (cfg, | 360 | sh = GNUNET_IDENTITY_connect(cfg, |
361 | (monitor | list) || (NULL != set_ego) || | 361 | (monitor | list) || (NULL != set_ego) || |
362 | (NULL != set_subsystem) | 362 | (NULL != set_subsystem) |
363 | ? &print_ego | 363 | ? &print_ego |
364 | : NULL, | 364 | : NULL, |
365 | NULL); | 365 | NULL); |
366 | if (NULL != delete_ego) | 366 | if (NULL != delete_ego) |
367 | delete_op = | 367 | delete_op = |
368 | GNUNET_IDENTITY_delete (sh, delete_ego, &delete_finished, &delete_op); | 368 | GNUNET_IDENTITY_delete(sh, delete_ego, &delete_finished, &delete_op); |
369 | if (NULL != create_ego) | 369 | if (NULL != create_ego) |
370 | create_op = | 370 | create_op = |
371 | GNUNET_IDENTITY_create (sh, create_ego, &create_finished, &create_op); | 371 | GNUNET_IDENTITY_create(sh, create_ego, &create_finished, &create_op); |
372 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 372 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
373 | test_finished (); | 373 | test_finished(); |
374 | } | 374 | } |
375 | 375 | ||
376 | 376 | ||
@@ -382,64 +382,64 @@ run (void *cls, | |||
382 | * @return 0 ok, 1 on error | 382 | * @return 0 ok, 1 on error |
383 | */ | 383 | */ |
384 | int | 384 | int |
385 | main (int argc, char *const *argv) | 385 | main(int argc, char *const *argv) |
386 | { | 386 | { |
387 | struct GNUNET_GETOPT_CommandLineOption options[] = | 387 | struct GNUNET_GETOPT_CommandLineOption options[] = |
388 | {GNUNET_GETOPT_option_string ('C', | 388 | { GNUNET_GETOPT_option_string('C', |
389 | "create", | 389 | "create", |
390 | "NAME", | 390 | "NAME", |
391 | gettext_noop ("create ego NAME"), | 391 | gettext_noop("create ego NAME"), |
392 | &create_ego), | 392 | &create_ego), |
393 | GNUNET_GETOPT_option_string ('D', | 393 | GNUNET_GETOPT_option_string('D', |
394 | "delete", | 394 | "delete", |
395 | "NAME", | 395 | "NAME", |
396 | gettext_noop ("delete ego NAME "), | 396 | gettext_noop("delete ego NAME "), |
397 | &delete_ego), | 397 | &delete_ego), |
398 | GNUNET_GETOPT_option_flag ('d', | 398 | GNUNET_GETOPT_option_flag('d', |
399 | "display", | 399 | "display", |
400 | gettext_noop ("display all egos"), | 400 | gettext_noop("display all egos"), |
401 | &list), | 401 | &list), |
402 | GNUNET_GETOPT_option_flag ('q', | 402 | GNUNET_GETOPT_option_flag('q', |
403 | "quiet", | 403 | "quiet", |
404 | gettext_noop ("reduce output"), | 404 | gettext_noop("reduce output"), |
405 | &quiet), | 405 | &quiet), |
406 | GNUNET_GETOPT_option_string ( | 406 | GNUNET_GETOPT_option_string( |
407 | 'e', | 407 | 'e', |
408 | "ego", | 408 | "ego", |
409 | "NAME", | 409 | "NAME", |
410 | gettext_noop ( | 410 | gettext_noop( |
411 | "set default identity to NAME for a subsystem SUBSYSTEM (use together with -s) or restrict results to NAME (use together with -d)"), | 411 | "set default identity to NAME for a subsystem SUBSYSTEM (use together with -s) or restrict results to NAME (use together with -d)"), |
412 | &set_ego), | 412 | &set_ego), |
413 | GNUNET_GETOPT_option_flag ('m', | 413 | GNUNET_GETOPT_option_flag('m', |
414 | "monitor", | 414 | "monitor", |
415 | gettext_noop ("run in monitor mode egos"), | 415 | gettext_noop("run in monitor mode egos"), |
416 | &monitor), | 416 | &monitor), |
417 | GNUNET_GETOPT_option_flag ('p', | 417 | GNUNET_GETOPT_option_flag('p', |
418 | "private-keys", | 418 | "private-keys", |
419 | gettext_noop ("display private keys as well"), | 419 | gettext_noop("display private keys as well"), |
420 | &private_keys), | 420 | &private_keys), |
421 | GNUNET_GETOPT_option_string ( | 421 | GNUNET_GETOPT_option_string( |
422 | 's', | 422 | 's', |
423 | "set", | 423 | "set", |
424 | "SUBSYSTEM", | 424 | "SUBSYSTEM", |
425 | gettext_noop ( | 425 | gettext_noop( |
426 | "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), | 426 | "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), |
427 | &set_subsystem), | 427 | &set_subsystem), |
428 | GNUNET_GETOPT_option_verbose (&verbose), | 428 | GNUNET_GETOPT_option_verbose(&verbose), |
429 | GNUNET_GETOPT_OPTION_END}; | 429 | GNUNET_GETOPT_OPTION_END }; |
430 | int res; | 430 | int res; |
431 | 431 | ||
432 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 432 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
433 | return 4; | 433 | return 4; |
434 | global_ret = TIMEOUT_STATUS_CODE; /* timeout */ | 434 | global_ret = TIMEOUT_STATUS_CODE; /* timeout */ |
435 | res = GNUNET_PROGRAM_run (argc, | 435 | res = GNUNET_PROGRAM_run(argc, |
436 | argv, | 436 | argv, |
437 | "gnunet-identity", | 437 | "gnunet-identity", |
438 | gettext_noop ("Maintain egos"), | 438 | gettext_noop("Maintain egos"), |
439 | options, | 439 | options, |
440 | &run, | 440 | &run, |
441 | NULL); | 441 | NULL); |
442 | GNUNET_free ((void *) argv); | 442 | GNUNET_free((void *)argv); |
443 | 443 | ||
444 | if (GNUNET_OK != res) | 444 | if (GNUNET_OK != res) |
445 | return 3; | 445 | return 3; |
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 34fad3272..f399b2566 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013 GNUnet e.V. | 3 | Copyright (C) 2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 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, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 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 | */ |
@@ -42,9 +42,7 @@ | |||
42 | /** | 42 | /** |
43 | * Information we keep about each ego. | 43 | * Information we keep about each ego. |
44 | */ | 44 | */ |
45 | struct Ego | 45 | struct Ego { |
46 | { | ||
47 | |||
48 | /** | 46 | /** |
49 | * We keep egos in a DLL. | 47 | * We keep egos in a DLL. |
50 | */ | 48 | */ |
@@ -116,15 +114,15 @@ static struct Ego *ego_tail; | |||
116 | * @return full filename for the given ego | 114 | * @return full filename for the given ego |
117 | */ | 115 | */ |
118 | static char * | 116 | static char * |
119 | get_ego_filename (struct Ego *ego) | 117 | get_ego_filename(struct Ego *ego) |
120 | { | 118 | { |
121 | char *filename; | 119 | char *filename; |
122 | 120 | ||
123 | GNUNET_asprintf (&filename, | 121 | GNUNET_asprintf(&filename, |
124 | "%s%s%s", | 122 | "%s%s%s", |
125 | ego_directory, | 123 | ego_directory, |
126 | DIR_SEPARATOR_STR, | 124 | DIR_SEPARATOR_STR, |
127 | ego->identifier); | 125 | ego->identifier); |
128 | return filename; | 126 | return filename; |
129 | } | 127 | } |
130 | 128 | ||
@@ -136,11 +134,11 @@ get_ego_filename (struct Ego *ego) | |||
136 | * @param app_ctx @a client | 134 | * @param app_ctx @a client |
137 | */ | 135 | */ |
138 | static void | 136 | static void |
139 | client_disconnect_cb (void *cls, | 137 | client_disconnect_cb(void *cls, |
140 | struct GNUNET_SERVICE_Client *client, | 138 | struct GNUNET_SERVICE_Client *client, |
141 | void *app_ctx) | 139 | void *app_ctx) |
142 | { | 140 | { |
143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); | 141 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); |
144 | } | 142 | } |
145 | 143 | ||
146 | 144 | ||
@@ -153,9 +151,9 @@ client_disconnect_cb (void *cls, | |||
153 | * @return internal namestore client structure for this client | 151 | * @return internal namestore client structure for this client |
154 | */ | 152 | */ |
155 | static void * | 153 | static void * |
156 | client_connect_cb (void *cls, | 154 | client_connect_cb(void *cls, |
157 | struct GNUNET_SERVICE_Client *client, | 155 | struct GNUNET_SERVICE_Client *client, |
158 | struct GNUNET_MQ_Handle *mq) | 156 | struct GNUNET_MQ_Handle *mq) |
159 | { | 157 | { |
160 | return client; | 158 | return client; |
161 | } | 159 | } |
@@ -166,33 +164,33 @@ client_connect_cb (void *cls, | |||
166 | * @param cls unused | 164 | * @param cls unused |
167 | */ | 165 | */ |
168 | static void | 166 | static void |
169 | shutdown_task (void *cls) | 167 | shutdown_task(void *cls) |
170 | { | 168 | { |
171 | struct Ego *e; | 169 | struct Ego *e; |
172 | 170 | ||
173 | if (NULL != nc) | 171 | if (NULL != nc) |
174 | { | 172 | { |
175 | GNUNET_notification_context_destroy (nc); | 173 | GNUNET_notification_context_destroy(nc); |
176 | nc = NULL; | 174 | nc = NULL; |
177 | } | 175 | } |
178 | if (NULL != stats) | 176 | if (NULL != stats) |
179 | { | 177 | { |
180 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 178 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); |
181 | stats = NULL; | 179 | stats = NULL; |
182 | } | 180 | } |
183 | GNUNET_CONFIGURATION_destroy (subsystem_cfg); | 181 | GNUNET_CONFIGURATION_destroy(subsystem_cfg); |
184 | subsystem_cfg = NULL; | 182 | subsystem_cfg = NULL; |
185 | GNUNET_free (subsystem_cfg_file); | 183 | GNUNET_free(subsystem_cfg_file); |
186 | subsystem_cfg_file = NULL; | 184 | subsystem_cfg_file = NULL; |
187 | GNUNET_free (ego_directory); | 185 | GNUNET_free(ego_directory); |
188 | ego_directory = NULL; | 186 | ego_directory = NULL; |
189 | while (NULL != (e = ego_head)) | 187 | while (NULL != (e = ego_head)) |
190 | { | 188 | { |
191 | GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e); | 189 | GNUNET_CONTAINER_DLL_remove(ego_head, ego_tail, e); |
192 | GNUNET_free (e->pk); | 190 | GNUNET_free(e->pk); |
193 | GNUNET_free (e->identifier); | 191 | GNUNET_free(e->identifier); |
194 | GNUNET_free (e); | 192 | GNUNET_free(e); |
195 | } | 193 | } |
196 | } | 194 | } |
197 | 195 | ||
198 | 196 | ||
@@ -204,9 +202,9 @@ shutdown_task (void *cls) | |||
204 | * @param emsg error message to include (or NULL for none) | 202 | * @param emsg error message to include (or NULL for none) |
205 | */ | 203 | */ |
206 | static void | 204 | static void |
207 | send_result_code (struct GNUNET_SERVICE_Client *client, | 205 | send_result_code(struct GNUNET_SERVICE_Client *client, |
208 | uint32_t result_code, | 206 | uint32_t result_code, |
209 | const char *emsg) | 207 | const char *emsg) |
210 | { | 208 | { |
211 | struct ResultCodeMessage *rcm; | 209 | struct ResultCodeMessage *rcm; |
212 | struct GNUNET_MQ_Envelope *env; | 210 | struct GNUNET_MQ_Envelope *env; |
@@ -215,17 +213,17 @@ send_result_code (struct GNUNET_SERVICE_Client *client, | |||
215 | if (NULL == emsg) | 213 | if (NULL == emsg) |
216 | elen = 0; | 214 | elen = 0; |
217 | else | 215 | else |
218 | elen = strlen (emsg) + 1; | 216 | elen = strlen(emsg) + 1; |
219 | env = | 217 | env = |
220 | GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE); | 218 | GNUNET_MQ_msg_extra(rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE); |
221 | rcm->result_code = htonl (result_code); | 219 | rcm->result_code = htonl(result_code); |
222 | if (0 < elen) | 220 | if (0 < elen) |
223 | GNUNET_memcpy (&rcm[1], emsg, elen); | 221 | GNUNET_memcpy(&rcm[1], emsg, elen); |
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 222 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
225 | "Sending result %d (%s) to client\n", | 223 | "Sending result %d (%s) to client\n", |
226 | (int) result_code, | 224 | (int)result_code, |
227 | emsg); | 225 | emsg); |
228 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 226 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
229 | } | 227 | } |
230 | 228 | ||
231 | 229 | ||
@@ -236,18 +234,18 @@ send_result_code (struct GNUNET_SERVICE_Client *client, | |||
236 | * @return corresponding update message | 234 | * @return corresponding update message |
237 | */ | 235 | */ |
238 | static struct GNUNET_MQ_Envelope * | 236 | static struct GNUNET_MQ_Envelope * |
239 | create_update_message (struct Ego *ego) | 237 | create_update_message(struct Ego *ego) |
240 | { | 238 | { |
241 | struct UpdateMessage *um; | 239 | struct UpdateMessage *um; |
242 | struct GNUNET_MQ_Envelope *env; | 240 | struct GNUNET_MQ_Envelope *env; |
243 | size_t name_len; | 241 | size_t name_len; |
244 | 242 | ||
245 | name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); | 243 | name_len = (NULL == ego->identifier) ? 0 : (strlen(ego->identifier) + 1); |
246 | env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); | 244 | env = GNUNET_MQ_msg_extra(um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); |
247 | um->name_len = htons (name_len); | 245 | um->name_len = htons(name_len); |
248 | um->end_of_list = htons (GNUNET_NO); | 246 | um->end_of_list = htons(GNUNET_NO); |
249 | um->private_key = *ego->pk; | 247 | um->private_key = *ego->pk; |
250 | GNUNET_memcpy (&um[1], ego->identifier, name_len); | 248 | GNUNET_memcpy(&um[1], ego->identifier, name_len); |
251 | return env; | 249 | return env; |
252 | } | 250 | } |
253 | 251 | ||
@@ -260,20 +258,20 @@ create_update_message (struct Ego *ego) | |||
260 | * @return corresponding set default message | 258 | * @return corresponding set default message |
261 | */ | 259 | */ |
262 | static struct GNUNET_MQ_Envelope * | 260 | static struct GNUNET_MQ_Envelope * |
263 | create_set_default_message (struct Ego *ego, const char *servicename) | 261 | create_set_default_message(struct Ego *ego, const char *servicename) |
264 | { | 262 | { |
265 | struct SetDefaultMessage *sdm; | 263 | struct SetDefaultMessage *sdm; |
266 | struct GNUNET_MQ_Envelope *env; | 264 | struct GNUNET_MQ_Envelope *env; |
267 | size_t name_len; | 265 | size_t name_len; |
268 | 266 | ||
269 | name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1); | 267 | name_len = (NULL == servicename) ? 0 : (strlen(servicename) + 1); |
270 | env = GNUNET_MQ_msg_extra (sdm, | 268 | env = GNUNET_MQ_msg_extra(sdm, |
271 | name_len, | 269 | name_len, |
272 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); | 270 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); |
273 | sdm->name_len = htons (name_len); | 271 | sdm->name_len = htons(name_len); |
274 | sdm->reserved = htons (0); | 272 | sdm->reserved = htons(0); |
275 | sdm->private_key = *ego->pk; | 273 | sdm->private_key = *ego->pk; |
276 | GNUNET_memcpy (&sdm[1], servicename, name_len); | 274 | GNUNET_memcpy(&sdm[1], servicename, name_len); |
277 | return env; | 275 | return env; |
278 | } | 276 | } |
279 | 277 | ||
@@ -288,27 +286,27 @@ create_set_default_message (struct Ego *ego, const char *servicename) | |||
288 | * @param message the message received | 286 | * @param message the message received |
289 | */ | 287 | */ |
290 | static void | 288 | static void |
291 | handle_start_message (void *cls, const struct GNUNET_MessageHeader *message) | 289 | handle_start_message(void *cls, const struct GNUNET_MessageHeader *message) |
292 | { | 290 | { |
293 | struct GNUNET_SERVICE_Client *client = cls; | 291 | struct GNUNET_SERVICE_Client *client = cls; |
294 | struct UpdateMessage *ume; | 292 | struct UpdateMessage *ume; |
295 | struct GNUNET_MQ_Envelope *env; | 293 | struct GNUNET_MQ_Envelope *env; |
296 | struct Ego *ego; | 294 | struct Ego *ego; |
297 | 295 | ||
298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); | 296 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); |
299 | GNUNET_SERVICE_client_mark_monitor (client); | 297 | GNUNET_SERVICE_client_mark_monitor(client); |
300 | GNUNET_SERVICE_client_disable_continue_warning (client); | 298 | GNUNET_SERVICE_client_disable_continue_warning(client); |
301 | GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client)); | 299 | GNUNET_notification_context_add(nc, GNUNET_SERVICE_client_get_mq(client)); |
302 | for (ego = ego_head; NULL != ego; ego = ego->next) | 300 | for (ego = ego_head; NULL != ego; ego = ego->next) |
303 | { | 301 | { |
304 | env = create_update_message (ego); | 302 | env = create_update_message(ego); |
305 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 303 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
306 | } | 304 | } |
307 | env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); | 305 | env = GNUNET_MQ_msg_extra(ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); |
308 | ume->end_of_list = htons (GNUNET_YES); | 306 | ume->end_of_list = htons(GNUNET_YES); |
309 | ume->name_len = htons (0); | 307 | ume->name_len = htons(0); |
310 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 308 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
311 | GNUNET_SERVICE_client_continue (client); | 309 | GNUNET_SERVICE_client_continue(client); |
312 | } | 310 | } |
313 | 311 | ||
314 | 312 | ||
@@ -321,9 +319,9 @@ handle_start_message (void *cls, const struct GNUNET_MessageHeader *message) | |||
321 | * @return #GNUNET_SYSERR if message was ill-formed | 319 | * @return #GNUNET_SYSERR if message was ill-formed |
322 | */ | 320 | */ |
323 | static int | 321 | static int |
324 | check_lookup_message (void *cls, const struct LookupMessage *message) | 322 | check_lookup_message(void *cls, const struct LookupMessage *message) |
325 | { | 323 | { |
326 | GNUNET_MQ_check_zero_termination (message); | 324 | GNUNET_MQ_check_zero_termination(message); |
327 | return GNUNET_OK; | 325 | return GNUNET_OK; |
328 | } | 326 | } |
329 | 327 | ||
@@ -336,26 +334,26 @@ check_lookup_message (void *cls, const struct LookupMessage *message) | |||
336 | * @param message the message received | 334 | * @param message the message received |
337 | */ | 335 | */ |
338 | static void | 336 | static void |
339 | handle_lookup_message (void *cls, const struct LookupMessage *message) | 337 | handle_lookup_message(void *cls, const struct LookupMessage *message) |
340 | { | 338 | { |
341 | struct GNUNET_SERVICE_Client *client = cls; | 339 | struct GNUNET_SERVICE_Client *client = cls; |
342 | const char *name; | 340 | const char *name; |
343 | struct GNUNET_MQ_Envelope *env; | 341 | struct GNUNET_MQ_Envelope *env; |
344 | struct Ego *ego; | 342 | struct Ego *ego; |
345 | 343 | ||
346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n"); | 344 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n"); |
347 | name = (const char *) &message[1]; | 345 | name = (const char *)&message[1]; |
348 | for (ego = ego_head; NULL != ego; ego = ego->next) | 346 | for (ego = ego_head; NULL != ego; ego = ego->next) |
349 | { | 347 | { |
350 | if (0 != strcasecmp (name, ego->identifier)) | 348 | if (0 != strcasecmp(name, ego->identifier)) |
351 | continue; | 349 | continue; |
352 | env = create_update_message (ego); | 350 | env = create_update_message(ego); |
353 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 351 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
354 | GNUNET_SERVICE_client_continue (client); | 352 | GNUNET_SERVICE_client_continue(client); |
355 | return; | 353 | return; |
356 | } | 354 | } |
357 | send_result_code (client, 0, "ego not found"); | 355 | send_result_code(client, 0, "ego not found"); |
358 | GNUNET_SERVICE_client_continue (client); | 356 | GNUNET_SERVICE_client_continue(client); |
359 | } | 357 | } |
360 | 358 | ||
361 | 359 | ||
@@ -368,9 +366,9 @@ handle_lookup_message (void *cls, const struct LookupMessage *message) | |||
368 | * @return #GNUNET_SYSERR if message was ill-formed | 366 | * @return #GNUNET_SYSERR if message was ill-formed |
369 | */ | 367 | */ |
370 | static int | 368 | static int |
371 | check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) | 369 | check_lookup_by_suffix_message(void *cls, const struct LookupMessage *message) |
372 | { | 370 | { |
373 | GNUNET_MQ_check_zero_termination (message); | 371 | GNUNET_MQ_check_zero_termination(message); |
374 | return GNUNET_OK; | 372 | return GNUNET_OK; |
375 | } | 373 | } |
376 | 374 | ||
@@ -383,41 +381,40 @@ check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) | |||
383 | * @param message the message received | 381 | * @param message the message received |
384 | */ | 382 | */ |
385 | static void | 383 | static void |
386 | handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) | 384 | handle_lookup_by_suffix_message(void *cls, const struct LookupMessage *message) |
387 | { | 385 | { |
388 | struct GNUNET_SERVICE_Client *client = cls; | 386 | struct GNUNET_SERVICE_Client *client = cls; |
389 | const char *name; | 387 | const char *name; |
390 | struct GNUNET_MQ_Envelope *env; | 388 | struct GNUNET_MQ_Envelope *env; |
391 | struct Ego *lprefix; | 389 | struct Ego *lprefix; |
392 | 390 | ||
393 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 391 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
394 | "Received LOOKUP_BY_SUFFIX message from client\n"); | 392 | "Received LOOKUP_BY_SUFFIX message from client\n"); |
395 | name = (const char *) &message[1]; | 393 | name = (const char *)&message[1]; |
396 | lprefix = NULL; | 394 | lprefix = NULL; |
397 | for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next) | 395 | for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next) |
398 | { | ||
399 | |||
400 | if ((strlen (ego->identifier) <= strlen (name)) && | ||
401 | (0 == strcmp (ego->identifier, | ||
402 | &name[strlen (name) - strlen (ego->identifier)])) && | ||
403 | ((strlen (name) == strlen (ego->identifier)) || | ||
404 | ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) && | ||
405 | ((NULL == lprefix) || | ||
406 | (strlen (ego->identifier) > strlen (lprefix->identifier)))) | ||
407 | { | 396 | { |
408 | /* found better match, update! */ | 397 | if ((strlen(ego->identifier) <= strlen(name)) && |
409 | lprefix = ego; | 398 | (0 == strcmp(ego->identifier, |
399 | &name[strlen(name) - strlen(ego->identifier)])) && | ||
400 | ((strlen(name) == strlen(ego->identifier)) || | ||
401 | ('.' == name[strlen(name) - strlen(ego->identifier) - 1])) && | ||
402 | ((NULL == lprefix) || | ||
403 | (strlen(ego->identifier) > strlen(lprefix->identifier)))) | ||
404 | { | ||
405 | /* found better match, update! */ | ||
406 | lprefix = ego; | ||
407 | } | ||
410 | } | 408 | } |
411 | } | ||
412 | if (NULL != lprefix) | 409 | if (NULL != lprefix) |
413 | { | 410 | { |
414 | env = create_update_message (lprefix); | 411 | env = create_update_message(lprefix); |
415 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 412 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
416 | GNUNET_SERVICE_client_continue (client); | 413 | GNUNET_SERVICE_client_continue(client); |
417 | return; | 414 | return; |
418 | } | 415 | } |
419 | send_result_code (client, 0, "ego not found"); | 416 | send_result_code(client, 0, "ego not found"); |
420 | GNUNET_SERVICE_client_continue (client); | 417 | GNUNET_SERVICE_client_continue(client); |
421 | } | 418 | } |
422 | 419 | ||
423 | 420 | ||
@@ -429,26 +426,26 @@ handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) | |||
429 | * @return #GNUNET_OK if @a msg is well-formed | 426 | * @return #GNUNET_OK if @a msg is well-formed |
430 | */ | 427 | */ |
431 | static int | 428 | static int |
432 | check_get_default_message (void *cls, const struct GetDefaultMessage *msg) | 429 | check_get_default_message(void *cls, const struct GetDefaultMessage *msg) |
433 | { | 430 | { |
434 | uint16_t size; | 431 | uint16_t size; |
435 | uint16_t name_len; | 432 | uint16_t name_len; |
436 | const char *name; | 433 | const char *name; |
437 | 434 | ||
438 | size = ntohs (msg->header.size); | 435 | size = ntohs(msg->header.size); |
439 | if (size <= sizeof (struct GetDefaultMessage)) | 436 | if (size <= sizeof(struct GetDefaultMessage)) |
440 | { | 437 | { |
441 | GNUNET_break (0); | 438 | GNUNET_break(0); |
442 | return GNUNET_SYSERR; | 439 | return GNUNET_SYSERR; |
443 | } | 440 | } |
444 | name = (const char *) &msg[1]; | 441 | name = (const char *)&msg[1]; |
445 | name_len = ntohs (msg->name_len); | 442 | name_len = ntohs(msg->name_len); |
446 | if ((name_len + sizeof (struct GetDefaultMessage) != size) || | 443 | if ((name_len + sizeof(struct GetDefaultMessage) != size) || |
447 | (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1])) | 444 | (0 != ntohs(msg->reserved)) || ('\0' != name[name_len - 1])) |
448 | { | 445 | { |
449 | GNUNET_break (0); | 446 | GNUNET_break(0); |
450 | return GNUNET_SYSERR; | 447 | return GNUNET_SYSERR; |
451 | } | 448 | } |
452 | return GNUNET_OK; | 449 | return GNUNET_OK; |
453 | } | 450 | } |
454 | 451 | ||
@@ -462,7 +459,7 @@ check_get_default_message (void *cls, const struct GetDefaultMessage *msg) | |||
462 | * @param message the message received | 459 | * @param message the message received |
463 | */ | 460 | */ |
464 | static void | 461 | static void |
465 | handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) | 462 | handle_get_default_message(void *cls, const struct GetDefaultMessage *gdm) |
466 | { | 463 | { |
467 | struct GNUNET_MQ_Envelope *env; | 464 | struct GNUNET_MQ_Envelope *env; |
468 | struct GNUNET_SERVICE_Client *client = cls; | 465 | struct GNUNET_SERVICE_Client *client = cls; |
@@ -471,41 +468,41 @@ handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) | |||
471 | char *identifier; | 468 | char *identifier; |
472 | 469 | ||
473 | 470 | ||
474 | name = GNUNET_strdup ((const char *) &gdm[1]); | 471 | name = GNUNET_strdup((const char *)&gdm[1]); |
475 | GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name); | 472 | GNUNET_STRINGS_utf8_tolower((const char *)&gdm[1], name); |
476 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 473 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
477 | "Received GET_DEFAULT for service `%s' from client\n", | 474 | "Received GET_DEFAULT for service `%s' from client\n", |
478 | name); | 475 | name); |
479 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, | 476 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(subsystem_cfg, |
480 | name, | 477 | name, |
481 | "DEFAULT_IDENTIFIER", | 478 | "DEFAULT_IDENTIFIER", |
482 | &identifier)) | 479 | &identifier)) |
483 | { | ||
484 | send_result_code (client, 1, gettext_noop ("no default known")); | ||
485 | GNUNET_SERVICE_client_continue (client); | ||
486 | GNUNET_free (name); | ||
487 | return; | ||
488 | } | ||
489 | for (ego = ego_head; NULL != ego; ego = ego->next) | ||
490 | { | ||
491 | if (0 == strcmp (ego->identifier, identifier)) | ||
492 | { | 480 | { |
493 | env = create_set_default_message (ego, name); | 481 | send_result_code(client, 1, gettext_noop("no default known")); |
494 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); | 482 | GNUNET_SERVICE_client_continue(client); |
495 | GNUNET_SERVICE_client_continue (client); | 483 | GNUNET_free(name); |
496 | GNUNET_free (identifier); | ||
497 | GNUNET_free (name); | ||
498 | return; | 484 | return; |
499 | } | 485 | } |
500 | } | 486 | for (ego = ego_head; NULL != ego; ego = ego->next) |
501 | GNUNET_free (identifier); | 487 | { |
502 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name); | 488 | if (0 == strcmp(ego->identifier, identifier)) |
503 | GNUNET_free (name); | 489 | { |
504 | send_result_code (client, | 490 | env = create_set_default_message(ego, name); |
505 | 1, | 491 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); |
506 | gettext_noop ( | 492 | GNUNET_SERVICE_client_continue(client); |
507 | "default configured, but ego unknown (internal error)")); | 493 | GNUNET_free(identifier); |
508 | GNUNET_SERVICE_client_continue (client); | 494 | GNUNET_free(name); |
495 | return; | ||
496 | } | ||
497 | } | ||
498 | GNUNET_free(identifier); | ||
499 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name); | ||
500 | GNUNET_free(name); | ||
501 | send_result_code(client, | ||
502 | 1, | ||
503 | gettext_noop( | ||
504 | "default configured, but ego unknown (internal error)")); | ||
505 | GNUNET_SERVICE_client_continue(client); | ||
509 | } | 506 | } |
510 | 507 | ||
511 | 508 | ||
@@ -517,10 +514,10 @@ handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) | |||
517 | * @return 0 if the keys are equal | 514 | * @return 0 if the keys are equal |
518 | */ | 515 | */ |
519 | static int | 516 | static int |
520 | key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, | 517 | key_cmp(const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, |
521 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2) | 518 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2) |
522 | { | 519 | { |
523 | return GNUNET_memcmp (pk1, pk2); | 520 | return GNUNET_memcmp(pk1, pk2); |
524 | } | 521 | } |
525 | 522 | ||
526 | /** | 523 | /** |
@@ -531,31 +528,31 @@ key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, | |||
531 | * @return #GNUNET_OK if @a msg is well-formed | 528 | * @return #GNUNET_OK if @a msg is well-formed |
532 | */ | 529 | */ |
533 | static int | 530 | static int |
534 | check_set_default_message (void *cls, const struct SetDefaultMessage *msg) | 531 | check_set_default_message(void *cls, const struct SetDefaultMessage *msg) |
535 | { | 532 | { |
536 | uint16_t size; | 533 | uint16_t size; |
537 | uint16_t name_len; | 534 | uint16_t name_len; |
538 | const char *str; | 535 | const char *str; |
539 | 536 | ||
540 | size = ntohs (msg->header.size); | 537 | size = ntohs(msg->header.size); |
541 | if (size <= sizeof (struct SetDefaultMessage)) | 538 | if (size <= sizeof(struct SetDefaultMessage)) |
542 | { | 539 | { |
543 | GNUNET_break (0); | 540 | GNUNET_break(0); |
544 | return GNUNET_SYSERR; | 541 | return GNUNET_SYSERR; |
545 | } | 542 | } |
546 | name_len = ntohs (msg->name_len); | 543 | name_len = ntohs(msg->name_len); |
547 | GNUNET_break (0 == ntohs (msg->reserved)); | 544 | GNUNET_break(0 == ntohs(msg->reserved)); |
548 | if (name_len + sizeof (struct SetDefaultMessage) != size) | 545 | if (name_len + sizeof(struct SetDefaultMessage) != size) |
549 | { | 546 | { |
550 | GNUNET_break (0); | 547 | GNUNET_break(0); |
551 | return GNUNET_SYSERR; | 548 | return GNUNET_SYSERR; |
552 | } | 549 | } |
553 | str = (const char *) &msg[1]; | 550 | str = (const char *)&msg[1]; |
554 | if ('\0' != str[name_len - 1]) | 551 | if ('\0' != str[name_len - 1]) |
555 | { | 552 | { |
556 | GNUNET_break (0); | 553 | GNUNET_break(0); |
557 | return GNUNET_SYSERR; | 554 | return GNUNET_SYSERR; |
558 | } | 555 | } |
559 | return GNUNET_OK; | 556 | return GNUNET_OK; |
560 | } | 557 | } |
561 | 558 | ||
@@ -568,43 +565,43 @@ check_set_default_message (void *cls, const struct SetDefaultMessage *msg) | |||
568 | * @param message the message received | 565 | * @param message the message received |
569 | */ | 566 | */ |
570 | static void | 567 | static void |
571 | handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm) | 568 | handle_set_default_message(void *cls, const struct SetDefaultMessage *sdm) |
572 | { | 569 | { |
573 | struct Ego *ego; | 570 | struct Ego *ego; |
574 | struct GNUNET_SERVICE_Client *client = cls; | 571 | struct GNUNET_SERVICE_Client *client = cls; |
575 | char *str; | 572 | char *str; |
576 | 573 | ||
577 | str = GNUNET_strdup ((const char *) &sdm[1]); | 574 | str = GNUNET_strdup((const char *)&sdm[1]); |
578 | GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str); | 575 | GNUNET_STRINGS_utf8_tolower((const char *)&sdm[1], str); |
579 | 576 | ||
580 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 577 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
581 | "Received SET_DEFAULT for service `%s' from client\n", | 578 | "Received SET_DEFAULT for service `%s' from client\n", |
582 | str); | 579 | str); |
583 | for (ego = ego_head; NULL != ego; ego = ego->next) | 580 | for (ego = ego_head; NULL != ego; ego = ego->next) |
584 | { | ||
585 | if (0 == key_cmp (ego->pk, &sdm->private_key)) | ||
586 | { | 581 | { |
587 | GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, | 582 | if (0 == key_cmp(ego->pk, &sdm->private_key)) |
588 | str, | 583 | { |
589 | "DEFAULT_IDENTIFIER", | 584 | GNUNET_CONFIGURATION_set_value_string(subsystem_cfg, |
590 | ego->identifier); | 585 | str, |
591 | if (GNUNET_OK != | 586 | "DEFAULT_IDENTIFIER", |
592 | GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) | 587 | ego->identifier); |
593 | GNUNET_log ( | 588 | if (GNUNET_OK != |
594 | GNUNET_ERROR_TYPE_ERROR, | 589 | GNUNET_CONFIGURATION_write(subsystem_cfg, subsystem_cfg_file)) |
595 | _ ("Failed to write subsystem default identifier map to `%s'.\n"), | 590 | GNUNET_log( |
596 | subsystem_cfg_file); | 591 | GNUNET_ERROR_TYPE_ERROR, |
597 | send_result_code (client, 0, NULL); | 592 | _("Failed to write subsystem default identifier map to `%s'.\n"), |
598 | GNUNET_SERVICE_client_continue (client); | 593 | subsystem_cfg_file); |
599 | GNUNET_free (str); | 594 | send_result_code(client, 0, NULL); |
600 | return; | 595 | GNUNET_SERVICE_client_continue(client); |
596 | GNUNET_free(str); | ||
597 | return; | ||
598 | } | ||
601 | } | 599 | } |
602 | } | 600 | send_result_code(client, |
603 | send_result_code (client, | 601 | 1, |
604 | 1, | 602 | _("Unknown ego specified for service (internal error)")); |
605 | _ ("Unknown ego specified for service (internal error)")); | 603 | GNUNET_free(str); |
606 | GNUNET_free (str); | 604 | GNUNET_SERVICE_client_continue(client); |
607 | GNUNET_SERVICE_client_continue (client); | ||
608 | } | 605 | } |
609 | 606 | ||
610 | 607 | ||
@@ -614,21 +611,21 @@ handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm) | |||
614 | * @param ego ego to send the update for | 611 | * @param ego ego to send the update for |
615 | */ | 612 | */ |
616 | static void | 613 | static void |
617 | notify_listeners (struct Ego *ego) | 614 | notify_listeners(struct Ego *ego) |
618 | { | 615 | { |
619 | struct UpdateMessage *um; | 616 | struct UpdateMessage *um; |
620 | size_t name_len; | 617 | size_t name_len; |
621 | 618 | ||
622 | name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); | 619 | name_len = (NULL == ego->identifier) ? 0 : (strlen(ego->identifier) + 1); |
623 | um = GNUNET_malloc (sizeof (struct UpdateMessage) + name_len); | 620 | um = GNUNET_malloc(sizeof(struct UpdateMessage) + name_len); |
624 | um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); | 621 | um->header.type = htons(GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); |
625 | um->header.size = htons (sizeof (struct UpdateMessage) + name_len); | 622 | um->header.size = htons(sizeof(struct UpdateMessage) + name_len); |
626 | um->name_len = htons (name_len); | 623 | um->name_len = htons(name_len); |
627 | um->end_of_list = htons (GNUNET_NO); | 624 | um->end_of_list = htons(GNUNET_NO); |
628 | um->private_key = *ego->pk; | 625 | um->private_key = *ego->pk; |
629 | GNUNET_memcpy (&um[1], ego->identifier, name_len); | 626 | GNUNET_memcpy(&um[1], ego->identifier, name_len); |
630 | GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO); | 627 | GNUNET_notification_context_broadcast(nc, &um->header, GNUNET_NO); |
631 | GNUNET_free (um); | 628 | GNUNET_free(um); |
632 | } | 629 | } |
633 | 630 | ||
634 | /** | 631 | /** |
@@ -639,32 +636,31 @@ notify_listeners (struct Ego *ego) | |||
639 | * @return #GNUNET_OK if @a msg is well-formed | 636 | * @return #GNUNET_OK if @a msg is well-formed |
640 | */ | 637 | */ |
641 | static int | 638 | static int |
642 | check_create_message (void *cls, const struct CreateRequestMessage *msg) | 639 | check_create_message(void *cls, const struct CreateRequestMessage *msg) |
643 | { | 640 | { |
644 | |||
645 | uint16_t size; | 641 | uint16_t size; |
646 | uint16_t name_len; | 642 | uint16_t name_len; |
647 | const char *str; | 643 | const char *str; |
648 | 644 | ||
649 | size = ntohs (msg->header.size); | 645 | size = ntohs(msg->header.size); |
650 | if (size <= sizeof (struct CreateRequestMessage)) | 646 | if (size <= sizeof(struct CreateRequestMessage)) |
651 | { | 647 | { |
652 | GNUNET_break (0); | 648 | GNUNET_break(0); |
653 | return GNUNET_SYSERR; | 649 | return GNUNET_SYSERR; |
654 | } | 650 | } |
655 | name_len = ntohs (msg->name_len); | 651 | name_len = ntohs(msg->name_len); |
656 | GNUNET_break (0 == ntohs (msg->reserved)); | 652 | GNUNET_break(0 == ntohs(msg->reserved)); |
657 | if (name_len + sizeof (struct CreateRequestMessage) != size) | 653 | if (name_len + sizeof(struct CreateRequestMessage) != size) |
658 | { | 654 | { |
659 | GNUNET_break (0); | 655 | GNUNET_break(0); |
660 | return GNUNET_SYSERR; | 656 | return GNUNET_SYSERR; |
661 | } | 657 | } |
662 | str = (const char *) &msg[1]; | 658 | str = (const char *)&msg[1]; |
663 | if ('\0' != str[name_len - 1]) | 659 | if ('\0' != str[name_len - 1]) |
664 | { | 660 | { |
665 | GNUNET_break (0); | 661 | GNUNET_break(0); |
666 | return GNUNET_SYSERR; | 662 | return GNUNET_SYSERR; |
667 | } | 663 | } |
668 | return GNUNET_OK; | 664 | return GNUNET_OK; |
669 | } | 665 | } |
670 | 666 | ||
@@ -677,56 +673,55 @@ check_create_message (void *cls, const struct CreateRequestMessage *msg) | |||
677 | * @param message the message received | 673 | * @param message the message received |
678 | */ | 674 | */ |
679 | static void | 675 | static void |
680 | handle_create_message (void *cls, const struct CreateRequestMessage *crm) | 676 | handle_create_message(void *cls, const struct CreateRequestMessage *crm) |
681 | { | 677 | { |
682 | struct GNUNET_SERVICE_Client *client = cls; | 678 | struct GNUNET_SERVICE_Client *client = cls; |
683 | struct Ego *ego; | 679 | struct Ego *ego; |
684 | char *str; | 680 | char *str; |
685 | char *fn; | 681 | char *fn; |
686 | 682 | ||
687 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n"); | 683 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n"); |
688 | str = GNUNET_strdup ((const char *) &crm[1]); | 684 | str = GNUNET_strdup((const char *)&crm[1]); |
689 | GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str); | 685 | GNUNET_STRINGS_utf8_tolower((const char *)&crm[1], str); |
690 | for (ego = ego_head; NULL != ego; ego = ego->next) | 686 | for (ego = ego_head; NULL != ego; ego = ego->next) |
691 | { | ||
692 | if (0 == strcmp (ego->identifier, str)) | ||
693 | { | 687 | { |
694 | send_result_code (client, | 688 | if (0 == strcmp(ego->identifier, str)) |
695 | 1, | 689 | { |
696 | gettext_noop ( | 690 | send_result_code(client, |
697 | "identifier already in use for another ego")); | 691 | 1, |
698 | GNUNET_SERVICE_client_continue (client); | 692 | gettext_noop( |
699 | GNUNET_free (str); | 693 | "identifier already in use for another ego")); |
700 | return; | 694 | GNUNET_SERVICE_client_continue(client); |
695 | GNUNET_free(str); | ||
696 | return; | ||
697 | } | ||
701 | } | 698 | } |
702 | } | 699 | ego = GNUNET_new(struct Ego); |
703 | ego = GNUNET_new (struct Ego); | 700 | ego->pk = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); |
704 | ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | ||
705 | *ego->pk = crm->private_key; | 701 | *ego->pk = crm->private_key; |
706 | ego->identifier = GNUNET_strdup (str); | 702 | ego->identifier = GNUNET_strdup(str); |
707 | GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); | 703 | GNUNET_CONTAINER_DLL_insert(ego_head, ego_tail, ego); |
708 | send_result_code (client, 0, NULL); | 704 | send_result_code(client, 0, NULL); |
709 | fn = get_ego_filename (ego); | 705 | fn = get_ego_filename(ego); |
710 | (void) GNUNET_DISK_directory_create_for_file (fn); | 706 | (void)GNUNET_DISK_directory_create_for_file(fn); |
711 | if (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) != | 707 | if (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey) != |
712 | GNUNET_DISK_fn_write (fn, | 708 | GNUNET_DISK_fn_write(fn, |
713 | &crm->private_key, | 709 | &crm->private_key, |
714 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), | 710 | sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey), |
715 | GNUNET_DISK_PERM_USER_READ | | 711 | GNUNET_DISK_PERM_USER_READ | |
716 | GNUNET_DISK_PERM_USER_WRITE)) | 712 | GNUNET_DISK_PERM_USER_WRITE)) |
717 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); | 713 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", fn); |
718 | GNUNET_free (fn); | 714 | GNUNET_free(fn); |
719 | GNUNET_free (str); | 715 | GNUNET_free(str); |
720 | notify_listeners (ego); | 716 | notify_listeners(ego); |
721 | GNUNET_SERVICE_client_continue (client); | 717 | GNUNET_SERVICE_client_continue(client); |
722 | } | 718 | } |
723 | 719 | ||
724 | 720 | ||
725 | /** | 721 | /** |
726 | * Closure for 'handle_ego_rename'. | 722 | * Closure for 'handle_ego_rename'. |
727 | */ | 723 | */ |
728 | struct RenameContext | 724 | struct RenameContext { |
729 | { | ||
730 | /** | 725 | /** |
731 | * Old name. | 726 | * Old name. |
732 | */ | 727 | */ |
@@ -746,26 +741,26 @@ struct RenameContext | |||
746 | * @param section a section in the configuration to process | 741 | * @param section a section in the configuration to process |
747 | */ | 742 | */ |
748 | static void | 743 | static void |
749 | handle_ego_rename (void *cls, const char *section) | 744 | handle_ego_rename(void *cls, const char *section) |
750 | { | 745 | { |
751 | struct RenameContext *rc = cls; | 746 | struct RenameContext *rc = cls; |
752 | char *id; | 747 | char *id; |
753 | 748 | ||
754 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, | 749 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(subsystem_cfg, |
755 | section, | 750 | section, |
756 | "DEFAULT_IDENTIFIER", | 751 | "DEFAULT_IDENTIFIER", |
757 | &id)) | 752 | &id)) |
758 | return; | 753 | return; |
759 | if (0 != strcmp (id, rc->old_name)) | 754 | if (0 != strcmp(id, rc->old_name)) |
760 | { | 755 | { |
761 | GNUNET_free (id); | 756 | GNUNET_free(id); |
762 | return; | 757 | return; |
763 | } | 758 | } |
764 | GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, | 759 | GNUNET_CONFIGURATION_set_value_string(subsystem_cfg, |
765 | section, | 760 | section, |
766 | "DEFAULT_IDENTIFIER", | 761 | "DEFAULT_IDENTIFIER", |
767 | rc->new_name); | 762 | rc->new_name); |
768 | GNUNET_free (id); | 763 | GNUNET_free(id); |
769 | } | 764 | } |
770 | 765 | ||
771 | /** | 766 | /** |
@@ -776,7 +771,7 @@ handle_ego_rename (void *cls, const char *section) | |||
776 | * @return #GNUNET_OK if @a msg is well-formed | 771 | * @return #GNUNET_OK if @a msg is well-formed |
777 | */ | 772 | */ |
778 | static int | 773 | static int |
779 | check_rename_message (void *cls, const struct RenameMessage *msg) | 774 | check_rename_message(void *cls, const struct RenameMessage *msg) |
780 | { | 775 | { |
781 | uint16_t size; | 776 | uint16_t size; |
782 | uint16_t old_name_len; | 777 | uint16_t old_name_len; |
@@ -784,23 +779,23 @@ check_rename_message (void *cls, const struct RenameMessage *msg) | |||
784 | const char *old_name; | 779 | const char *old_name; |
785 | const char *new_name; | 780 | const char *new_name; |
786 | 781 | ||
787 | size = ntohs (msg->header.size); | 782 | size = ntohs(msg->header.size); |
788 | if (size <= sizeof (struct RenameMessage)) | 783 | if (size <= sizeof(struct RenameMessage)) |
789 | { | 784 | { |
790 | GNUNET_break (0); | 785 | GNUNET_break(0); |
791 | return GNUNET_SYSERR; | 786 | return GNUNET_SYSERR; |
792 | } | 787 | } |
793 | old_name_len = ntohs (msg->old_name_len); | 788 | old_name_len = ntohs(msg->old_name_len); |
794 | new_name_len = ntohs (msg->new_name_len); | 789 | new_name_len = ntohs(msg->new_name_len); |
795 | old_name = (const char *) &msg[1]; | 790 | old_name = (const char *)&msg[1]; |
796 | new_name = &old_name[old_name_len]; | 791 | new_name = &old_name[old_name_len]; |
797 | if ((old_name_len + new_name_len + sizeof (struct RenameMessage) != size) || | 792 | if ((old_name_len + new_name_len + sizeof(struct RenameMessage) != size) || |
798 | ('\0' != old_name[old_name_len - 1]) || | 793 | ('\0' != old_name[old_name_len - 1]) || |
799 | ('\0' != new_name[new_name_len - 1])) | 794 | ('\0' != new_name[new_name_len - 1])) |
800 | { | 795 | { |
801 | GNUNET_break (0); | 796 | GNUNET_break(0); |
802 | return GNUNET_SYSERR; | 797 | return GNUNET_SYSERR; |
803 | } | 798 | } |
804 | 799 | ||
805 | return GNUNET_OK; | 800 | return GNUNET_OK; |
806 | } | 801 | } |
@@ -815,7 +810,7 @@ check_rename_message (void *cls, const struct RenameMessage *msg) | |||
815 | * @param message the message received | 810 | * @param message the message received |
816 | */ | 811 | */ |
817 | static void | 812 | static void |
818 | handle_rename_message (void *cls, const struct RenameMessage *rm) | 813 | handle_rename_message(void *cls, const struct RenameMessage *rm) |
819 | { | 814 | { |
820 | uint16_t old_name_len; | 815 | uint16_t old_name_len; |
821 | struct Ego *ego; | 816 | struct Ego *ego; |
@@ -827,65 +822,65 @@ handle_rename_message (void *cls, const struct RenameMessage *rm) | |||
827 | char *fn_new; | 822 | char *fn_new; |
828 | const char *old_name_tmp; | 823 | const char *old_name_tmp; |
829 | 824 | ||
830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n"); | 825 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n"); |
831 | old_name_len = ntohs (rm->old_name_len); | 826 | old_name_len = ntohs(rm->old_name_len); |
832 | old_name_tmp = (const char *) &rm[1]; | 827 | old_name_tmp = (const char *)&rm[1]; |
833 | old_name = GNUNET_strdup (old_name_tmp); | 828 | old_name = GNUNET_strdup(old_name_tmp); |
834 | GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name); | 829 | GNUNET_STRINGS_utf8_tolower(old_name_tmp, old_name); |
835 | new_name = GNUNET_strdup (&old_name_tmp[old_name_len]); | 830 | new_name = GNUNET_strdup(&old_name_tmp[old_name_len]); |
836 | GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name); | 831 | GNUNET_STRINGS_utf8_tolower(&old_name_tmp[old_name_len], new_name); |
837 | 832 | ||
838 | /* check if new name is already in use */ | 833 | /* check if new name is already in use */ |
839 | for (ego = ego_head; NULL != ego; ego = ego->next) | 834 | for (ego = ego_head; NULL != ego; ego = ego->next) |
840 | { | ||
841 | if (0 == strcmp (ego->identifier, new_name)) | ||
842 | { | 835 | { |
843 | send_result_code (client, 1, gettext_noop ("target name already exists")); | 836 | if (0 == strcmp(ego->identifier, new_name)) |
844 | GNUNET_SERVICE_client_continue (client); | 837 | { |
845 | GNUNET_free (old_name); | 838 | send_result_code(client, 1, gettext_noop("target name already exists")); |
846 | GNUNET_free (new_name); | 839 | GNUNET_SERVICE_client_continue(client); |
847 | return; | 840 | GNUNET_free(old_name); |
841 | GNUNET_free(new_name); | ||
842 | return; | ||
843 | } | ||
848 | } | 844 | } |
849 | } | ||
850 | 845 | ||
851 | /* locate old name and, if found, perform rename */ | 846 | /* locate old name and, if found, perform rename */ |
852 | for (ego = ego_head; NULL != ego; ego = ego->next) | 847 | for (ego = ego_head; NULL != ego; ego = ego->next) |
853 | { | ||
854 | if (0 == strcmp (ego->identifier, old_name)) | ||
855 | { | 848 | { |
856 | fn_old = get_ego_filename (ego); | 849 | if (0 == strcmp(ego->identifier, old_name)) |
857 | GNUNET_free (ego->identifier); | 850 | { |
858 | rename_ctx.old_name = old_name; | 851 | fn_old = get_ego_filename(ego); |
859 | rename_ctx.new_name = new_name; | 852 | GNUNET_free(ego->identifier); |
860 | GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, | 853 | rename_ctx.old_name = old_name; |
861 | &handle_ego_rename, | 854 | rename_ctx.new_name = new_name; |
862 | &rename_ctx); | 855 | GNUNET_CONFIGURATION_iterate_sections(subsystem_cfg, |
863 | if (GNUNET_OK != | 856 | &handle_ego_rename, |
864 | GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) | 857 | &rename_ctx); |
865 | GNUNET_log ( | 858 | if (GNUNET_OK != |
866 | GNUNET_ERROR_TYPE_ERROR, | 859 | GNUNET_CONFIGURATION_write(subsystem_cfg, subsystem_cfg_file)) |
867 | _ ("Failed to write subsystem default identifier map to `%s'.\n"), | 860 | GNUNET_log( |
868 | subsystem_cfg_file); | 861 | GNUNET_ERROR_TYPE_ERROR, |
869 | ego->identifier = GNUNET_strdup (new_name); | 862 | _("Failed to write subsystem default identifier map to `%s'.\n"), |
870 | fn_new = get_ego_filename (ego); | 863 | subsystem_cfg_file); |
871 | if (0 != rename (fn_old, fn_new)) | 864 | ego->identifier = GNUNET_strdup(new_name); |
872 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); | 865 | fn_new = get_ego_filename(ego); |
873 | GNUNET_free (fn_old); | 866 | if (0 != rename(fn_old, fn_new)) |
874 | GNUNET_free (fn_new); | 867 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); |
875 | GNUNET_free (old_name); | 868 | GNUNET_free(fn_old); |
876 | GNUNET_free (new_name); | 869 | GNUNET_free(fn_new); |
877 | notify_listeners (ego); | 870 | GNUNET_free(old_name); |
878 | send_result_code (client, 0, NULL); | 871 | GNUNET_free(new_name); |
879 | GNUNET_SERVICE_client_continue (client); | 872 | notify_listeners(ego); |
880 | return; | 873 | send_result_code(client, 0, NULL); |
874 | GNUNET_SERVICE_client_continue(client); | ||
875 | return; | ||
876 | } | ||
881 | } | 877 | } |
882 | } | ||
883 | 878 | ||
884 | /* failed to locate old name */ | 879 | /* failed to locate old name */ |
885 | send_result_code (client, 1, gettext_noop ("no matching ego found")); | 880 | send_result_code(client, 1, gettext_noop("no matching ego found")); |
886 | GNUNET_free (old_name); | 881 | GNUNET_free(old_name); |
887 | GNUNET_free (new_name); | 882 | GNUNET_free(new_name); |
888 | GNUNET_SERVICE_client_continue (client); | 883 | GNUNET_SERVICE_client_continue(client); |
889 | } | 884 | } |
890 | 885 | ||
891 | 886 | ||
@@ -897,26 +892,26 @@ handle_rename_message (void *cls, const struct RenameMessage *rm) | |||
897 | * @param section a section in the configuration to process | 892 | * @param section a section in the configuration to process |
898 | */ | 893 | */ |
899 | static void | 894 | static void |
900 | handle_ego_delete (void *cls, const char *section) | 895 | handle_ego_delete(void *cls, const char *section) |
901 | { | 896 | { |
902 | const char *identifier = cls; | 897 | const char *identifier = cls; |
903 | char *id; | 898 | char *id; |
904 | 899 | ||
905 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, | 900 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(subsystem_cfg, |
906 | section, | 901 | section, |
907 | "DEFAULT_IDENTIFIER", | 902 | "DEFAULT_IDENTIFIER", |
908 | &id)) | 903 | &id)) |
909 | return; | 904 | return; |
910 | if (0 != strcmp (id, identifier)) | 905 | if (0 != strcmp(id, identifier)) |
911 | { | 906 | { |
912 | GNUNET_free (id); | 907 | GNUNET_free(id); |
913 | return; | 908 | return; |
914 | } | 909 | } |
915 | GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, | 910 | GNUNET_CONFIGURATION_set_value_string(subsystem_cfg, |
916 | section, | 911 | section, |
917 | "DEFAULT_IDENTIFIER", | 912 | "DEFAULT_IDENTIFIER", |
918 | NULL); | 913 | NULL); |
919 | GNUNET_free (id); | 914 | GNUNET_free(id); |
920 | } | 915 | } |
921 | 916 | ||
922 | /** | 917 | /** |
@@ -927,26 +922,26 @@ handle_ego_delete (void *cls, const char *section) | |||
927 | * @return #GNUNET_OK if @a msg is well-formed | 922 | * @return #GNUNET_OK if @a msg is well-formed |
928 | */ | 923 | */ |
929 | static int | 924 | static int |
930 | check_delete_message (void *cls, const struct DeleteMessage *msg) | 925 | check_delete_message(void *cls, const struct DeleteMessage *msg) |
931 | { | 926 | { |
932 | uint16_t size; | 927 | uint16_t size; |
933 | uint16_t name_len; | 928 | uint16_t name_len; |
934 | const char *name; | 929 | const char *name; |
935 | 930 | ||
936 | size = ntohs (msg->header.size); | 931 | size = ntohs(msg->header.size); |
937 | if (size <= sizeof (struct DeleteMessage)) | 932 | if (size <= sizeof(struct DeleteMessage)) |
938 | { | 933 | { |
939 | GNUNET_break (0); | 934 | GNUNET_break(0); |
940 | return GNUNET_SYSERR; | 935 | return GNUNET_SYSERR; |
941 | } | 936 | } |
942 | name = (const char *) &msg[1]; | 937 | name = (const char *)&msg[1]; |
943 | name_len = ntohs (msg->name_len); | 938 | name_len = ntohs(msg->name_len); |
944 | if ((name_len + sizeof (struct DeleteMessage) != size) || | 939 | if ((name_len + sizeof(struct DeleteMessage) != size) || |
945 | (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1])) | 940 | (0 != ntohs(msg->reserved)) || ('\0' != name[name_len - 1])) |
946 | { | 941 | { |
947 | GNUNET_break (0); | 942 | GNUNET_break(0); |
948 | return GNUNET_SYSERR; | 943 | return GNUNET_SYSERR; |
949 | } | 944 | } |
950 | return GNUNET_OK; | 945 | return GNUNET_OK; |
951 | } | 946 | } |
952 | 947 | ||
@@ -960,50 +955,50 @@ check_delete_message (void *cls, const struct DeleteMessage *msg) | |||
960 | * @param message the message received | 955 | * @param message the message received |
961 | */ | 956 | */ |
962 | static void | 957 | static void |
963 | handle_delete_message (void *cls, const struct DeleteMessage *dm) | 958 | handle_delete_message(void *cls, const struct DeleteMessage *dm) |
964 | { | 959 | { |
965 | struct Ego *ego; | 960 | struct Ego *ego; |
966 | char *name; | 961 | char *name; |
967 | char *fn; | 962 | char *fn; |
968 | struct GNUNET_SERVICE_Client *client = cls; | 963 | struct GNUNET_SERVICE_Client *client = cls; |
969 | 964 | ||
970 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n"); | 965 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n"); |
971 | name = GNUNET_strdup ((const char *) &dm[1]); | 966 | name = GNUNET_strdup((const char *)&dm[1]); |
972 | GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name); | 967 | GNUNET_STRINGS_utf8_tolower((const char *)&dm[1], name); |
973 | 968 | ||
974 | for (ego = ego_head; NULL != ego; ego = ego->next) | 969 | for (ego = ego_head; NULL != ego; ego = ego->next) |
975 | { | ||
976 | if (0 == strcmp (ego->identifier, name)) | ||
977 | { | 970 | { |
978 | GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego); | 971 | if (0 == strcmp(ego->identifier, name)) |
979 | GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, | 972 | { |
980 | &handle_ego_delete, | 973 | GNUNET_CONTAINER_DLL_remove(ego_head, ego_tail, ego); |
981 | ego->identifier); | 974 | GNUNET_CONFIGURATION_iterate_sections(subsystem_cfg, |
982 | if (GNUNET_OK != | 975 | &handle_ego_delete, |
983 | GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) | 976 | ego->identifier); |
984 | GNUNET_log ( | 977 | if (GNUNET_OK != |
985 | GNUNET_ERROR_TYPE_ERROR, | 978 | GNUNET_CONFIGURATION_write(subsystem_cfg, subsystem_cfg_file)) |
986 | _ ("Failed to write subsystem default identifier map to `%s'.\n"), | 979 | GNUNET_log( |
987 | subsystem_cfg_file); | 980 | GNUNET_ERROR_TYPE_ERROR, |
988 | fn = get_ego_filename (ego); | 981 | _("Failed to write subsystem default identifier map to `%s'.\n"), |
989 | if (0 != unlink (fn)) | 982 | subsystem_cfg_file); |
990 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 983 | fn = get_ego_filename(ego); |
991 | GNUNET_free (fn); | 984 | if (0 != unlink(fn)) |
992 | GNUNET_free (ego->identifier); | 985 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
993 | ego->identifier = NULL; | 986 | GNUNET_free(fn); |
994 | notify_listeners (ego); | 987 | GNUNET_free(ego->identifier); |
995 | GNUNET_free (ego->pk); | 988 | ego->identifier = NULL; |
996 | GNUNET_free (ego); | 989 | notify_listeners(ego); |
997 | GNUNET_free (name); | 990 | GNUNET_free(ego->pk); |
998 | send_result_code (client, 0, NULL); | 991 | GNUNET_free(ego); |
999 | GNUNET_SERVICE_client_continue (client); | 992 | GNUNET_free(name); |
1000 | return; | 993 | send_result_code(client, 0, NULL); |
994 | GNUNET_SERVICE_client_continue(client); | ||
995 | return; | ||
996 | } | ||
1001 | } | 997 | } |
1002 | } | ||
1003 | 998 | ||
1004 | send_result_code (client, 1, gettext_noop ("no matching ego found")); | 999 | send_result_code(client, 1, gettext_noop("no matching ego found")); |
1005 | GNUNET_free (name); | 1000 | GNUNET_free(name); |
1006 | GNUNET_SERVICE_client_continue (client); | 1001 | GNUNET_SERVICE_client_continue(client); |
1007 | } | 1002 | } |
1008 | 1003 | ||
1009 | 1004 | ||
@@ -1018,30 +1013,30 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm) | |||
1018 | * #GNUNET_SYSERR to abort iteration with error! | 1013 | * #GNUNET_SYSERR to abort iteration with error! |
1019 | */ | 1014 | */ |
1020 | static int | 1015 | static int |
1021 | process_ego_file (void *cls, const char *filename) | 1016 | process_ego_file(void *cls, const char *filename) |
1022 | { | 1017 | { |
1023 | struct Ego *ego; | 1018 | struct Ego *ego; |
1024 | const char *fn; | 1019 | const char *fn; |
1025 | 1020 | ||
1026 | fn = strrchr (filename, (int) DIR_SEPARATOR); | 1021 | fn = strrchr(filename, (int)DIR_SEPARATOR); |
1027 | if (NULL == fn) | 1022 | if (NULL == fn) |
1028 | { | 1023 | { |
1029 | GNUNET_break (0); | 1024 | GNUNET_break(0); |
1030 | return GNUNET_OK; | 1025 | return GNUNET_OK; |
1031 | } | 1026 | } |
1032 | ego = GNUNET_new (struct Ego); | 1027 | ego = GNUNET_new(struct Ego); |
1033 | ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file (filename); | 1028 | ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file(filename); |
1034 | if (NULL == ego->pk) | 1029 | if (NULL == ego->pk) |
1035 | { | 1030 | { |
1036 | GNUNET_free (ego); | 1031 | GNUNET_free(ego); |
1037 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1032 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1038 | _ ("Failed to parse ego information in `%s'\n"), | 1033 | _("Failed to parse ego information in `%s'\n"), |
1039 | filename); | 1034 | filename); |
1040 | return GNUNET_OK; | 1035 | return GNUNET_OK; |
1041 | } | 1036 | } |
1042 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1); | 1037 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1); |
1043 | ego->identifier = GNUNET_strdup (fn + 1); | 1038 | ego->identifier = GNUNET_strdup(fn + 1); |
1044 | GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); | 1039 | GNUNET_CONTAINER_DLL_insert(ego_head, ego_tail, ego); |
1045 | return GNUNET_OK; | 1040 | return GNUNET_OK; |
1046 | } | 1041 | } |
1047 | 1042 | ||
@@ -1054,103 +1049,103 @@ process_ego_file (void *cls, const char *filename) | |||
1054 | * @param c configuration to use | 1049 | * @param c configuration to use |
1055 | */ | 1050 | */ |
1056 | static void | 1051 | static void |
1057 | run (void *cls, | 1052 | run(void *cls, |
1058 | const struct GNUNET_CONFIGURATION_Handle *c, | 1053 | const struct GNUNET_CONFIGURATION_Handle *c, |
1059 | struct GNUNET_SERVICE_Handle *service) | 1054 | struct GNUNET_SERVICE_Handle *service) |
1060 | { | 1055 | { |
1061 | cfg = c; | 1056 | cfg = c; |
1062 | nc = GNUNET_notification_context_create (1); | 1057 | nc = GNUNET_notification_context_create(1); |
1063 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, | 1058 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg, |
1064 | "identity", | 1059 | "identity", |
1065 | "EGODIR", | 1060 | "EGODIR", |
1066 | &ego_directory)) | 1061 | &ego_directory)) |
1067 | { | 1062 | { |
1068 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); | 1063 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); |
1069 | GNUNET_SCHEDULER_shutdown (); | 1064 | GNUNET_SCHEDULER_shutdown(); |
1070 | return; | 1065 | return; |
1071 | } | 1066 | } |
1072 | if (GNUNET_OK != | 1067 | if (GNUNET_OK != |
1073 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1068 | GNUNET_CONFIGURATION_get_value_filename(cfg, |
1074 | "identity", | 1069 | "identity", |
1075 | "SUBSYSTEM_CFG", | 1070 | "SUBSYSTEM_CFG", |
1076 | &subsystem_cfg_file)) | 1071 | &subsystem_cfg_file)) |
1077 | { | 1072 | { |
1078 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 1073 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, |
1079 | "identity", | 1074 | "identity", |
1080 | "SUBSYSTEM_CFG"); | 1075 | "SUBSYSTEM_CFG"); |
1081 | GNUNET_SCHEDULER_shutdown (); | 1076 | GNUNET_SCHEDULER_shutdown(); |
1082 | return; | 1077 | return; |
1083 | } | 1078 | } |
1084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1079 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1085 | "Loading subsystem configuration `%s'\n", | 1080 | "Loading subsystem configuration `%s'\n", |
1086 | subsystem_cfg_file); | 1081 | subsystem_cfg_file); |
1087 | subsystem_cfg = GNUNET_CONFIGURATION_create (); | 1082 | subsystem_cfg = GNUNET_CONFIGURATION_create(); |
1088 | if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) && | 1083 | if ((GNUNET_YES == GNUNET_DISK_file_test(subsystem_cfg_file)) && |
1089 | (GNUNET_OK != | 1084 | (GNUNET_OK != |
1090 | GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file))) | 1085 | GNUNET_CONFIGURATION_parse(subsystem_cfg, subsystem_cfg_file))) |
1091 | { | 1086 | { |
1092 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1087 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1093 | _ ( | 1088 | _( |
1094 | "Failed to parse subsystem identity configuration file `%s'\n"), | 1089 | "Failed to parse subsystem identity configuration file `%s'\n"), |
1095 | subsystem_cfg_file); | 1090 | subsystem_cfg_file); |
1096 | GNUNET_SCHEDULER_shutdown (); | 1091 | GNUNET_SCHEDULER_shutdown(); |
1097 | return; | 1092 | return; |
1098 | } | 1093 | } |
1099 | stats = GNUNET_STATISTICS_create ("identity", cfg); | 1094 | stats = GNUNET_STATISTICS_create("identity", cfg); |
1100 | if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory)) | 1095 | if (GNUNET_OK != GNUNET_DISK_directory_create(ego_directory)) |
1101 | { | 1096 | { |
1102 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1097 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1103 | _ ("Failed to create directory `%s' for storing egos\n"), | 1098 | _("Failed to create directory `%s' for storing egos\n"), |
1104 | ego_directory); | 1099 | ego_directory); |
1105 | } | 1100 | } |
1106 | GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL); | 1101 | GNUNET_DISK_directory_scan(ego_directory, &process_ego_file, NULL); |
1107 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1102 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
1108 | } | 1103 | } |
1109 | 1104 | ||
1110 | 1105 | ||
1111 | /** | 1106 | /** |
1112 | * Define "main" method using service macro. | 1107 | * Define "main" method using service macro. |
1113 | */ | 1108 | */ |
1114 | GNUNET_SERVICE_MAIN ( | 1109 | GNUNET_SERVICE_MAIN( |
1115 | "identity", | 1110 | "identity", |
1116 | GNUNET_SERVICE_OPTION_NONE, | 1111 | GNUNET_SERVICE_OPTION_NONE, |
1117 | &run, | 1112 | &run, |
1118 | &client_connect_cb, | 1113 | &client_connect_cb, |
1119 | &client_disconnect_cb, | 1114 | &client_disconnect_cb, |
1120 | NULL, | 1115 | NULL, |
1121 | GNUNET_MQ_hd_fixed_size (start_message, | 1116 | GNUNET_MQ_hd_fixed_size(start_message, |
1122 | GNUNET_MESSAGE_TYPE_IDENTITY_START, | 1117 | GNUNET_MESSAGE_TYPE_IDENTITY_START, |
1123 | struct GNUNET_MessageHeader, | 1118 | struct GNUNET_MessageHeader, |
1124 | NULL), | 1119 | NULL), |
1125 | GNUNET_MQ_hd_var_size (lookup_message, | 1120 | GNUNET_MQ_hd_var_size(lookup_message, |
1126 | GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, | 1121 | GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, |
1127 | struct LookupMessage, | 1122 | struct LookupMessage, |
1128 | NULL), | 1123 | NULL), |
1129 | GNUNET_MQ_hd_var_size (lookup_by_suffix_message, | 1124 | GNUNET_MQ_hd_var_size(lookup_by_suffix_message, |
1130 | GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, | 1125 | GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, |
1131 | struct LookupMessage, | 1126 | struct LookupMessage, |
1132 | NULL), | 1127 | NULL), |
1133 | GNUNET_MQ_hd_var_size (get_default_message, | 1128 | GNUNET_MQ_hd_var_size(get_default_message, |
1134 | GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, | 1129 | GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, |
1135 | struct GetDefaultMessage, | 1130 | struct GetDefaultMessage, |
1136 | NULL), | 1131 | NULL), |
1137 | GNUNET_MQ_hd_var_size (set_default_message, | 1132 | GNUNET_MQ_hd_var_size(set_default_message, |
1138 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, | 1133 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, |
1139 | struct SetDefaultMessage, | 1134 | struct SetDefaultMessage, |
1140 | NULL), | 1135 | NULL), |
1141 | GNUNET_MQ_hd_var_size (create_message, | 1136 | GNUNET_MQ_hd_var_size(create_message, |
1142 | GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, | 1137 | GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, |
1143 | struct CreateRequestMessage, | 1138 | struct CreateRequestMessage, |
1144 | NULL), | 1139 | NULL), |
1145 | GNUNET_MQ_hd_var_size (rename_message, | 1140 | GNUNET_MQ_hd_var_size(rename_message, |
1146 | GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, | 1141 | GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, |
1147 | struct RenameMessage, | 1142 | struct RenameMessage, |
1148 | NULL), | 1143 | NULL), |
1149 | GNUNET_MQ_hd_var_size (delete_message, | 1144 | GNUNET_MQ_hd_var_size(delete_message, |
1150 | GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, | 1145 | GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, |
1151 | struct DeleteMessage, | 1146 | struct DeleteMessage, |
1152 | NULL), | 1147 | NULL), |
1153 | GNUNET_MQ_handler_end ()); | 1148 | GNUNET_MQ_handler_end()); |
1154 | 1149 | ||
1155 | 1150 | ||
1156 | /* end of gnunet-service-identity.c */ | 1151 | /* end of gnunet-service-identity.c */ |
diff --git a/src/identity/identity.h b/src/identity/identity.h index 6ef16e39d..6a4090ad8 100644 --- a/src/identity/identity.h +++ b/src/identity/identity.h | |||
@@ -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 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
@@ -39,8 +39,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
39 | * GET_DEFAULT maybe answered with this message on failure; | 39 | * GET_DEFAULT maybe answered with this message on failure; |
40 | * CREATE and RENAME will always be answered with this message. | 40 | * CREATE and RENAME will always be answered with this message. |
41 | */ | 41 | */ |
42 | struct ResultCodeMessage | 42 | struct ResultCodeMessage { |
43 | { | ||
44 | /** | 43 | /** |
45 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE | 44 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE |
46 | */ | 45 | */ |
@@ -59,8 +58,7 @@ struct ResultCodeMessage | |||
59 | /** | 58 | /** |
60 | * Client informs service about desire to lookup a (single) pseudonym. | 59 | * Client informs service about desire to lookup a (single) pseudonym. |
61 | */ | 60 | */ |
62 | struct LookupMessage | 61 | struct LookupMessage { |
63 | { | ||
64 | /** | 62 | /** |
65 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP or | 63 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP or |
66 | * #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX | 64 | * #GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX |
@@ -74,8 +72,7 @@ struct LookupMessage | |||
74 | /** | 72 | /** |
75 | * Service informs client about status of a pseudonym. | 73 | * Service informs client about status of a pseudonym. |
76 | */ | 74 | */ |
77 | struct UpdateMessage | 75 | struct UpdateMessage { |
78 | { | ||
79 | /** | 76 | /** |
80 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE | 77 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE |
81 | */ | 78 | */ |
@@ -105,8 +102,7 @@ struct UpdateMessage | |||
105 | * Client requests knowledge about default identity for | 102 | * Client requests knowledge about default identity for |
106 | * a subsystem from identity service. | 103 | * a subsystem from identity service. |
107 | */ | 104 | */ |
108 | struct GetDefaultMessage | 105 | struct GetDefaultMessage { |
109 | { | ||
110 | /** | 106 | /** |
111 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT | 107 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT |
112 | */ | 108 | */ |
@@ -131,8 +127,7 @@ struct GetDefaultMessage | |||
131 | * Used from service to client as a result to the GET_DEFAULT | 127 | * Used from service to client as a result to the GET_DEFAULT |
132 | * message, used from client to service to SET_DEFAULT. | 128 | * message, used from client to service to SET_DEFAULT. |
133 | */ | 129 | */ |
134 | struct SetDefaultMessage | 130 | struct SetDefaultMessage { |
135 | { | ||
136 | /** | 131 | /** |
137 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT | 132 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT |
138 | */ | 133 | */ |
@@ -161,8 +156,7 @@ struct SetDefaultMessage | |||
161 | * Client requests creation of an identity. Service | 156 | * Client requests creation of an identity. Service |
162 | * will respond with a result code. | 157 | * will respond with a result code. |
163 | */ | 158 | */ |
164 | struct CreateRequestMessage | 159 | struct CreateRequestMessage { |
165 | { | ||
166 | /** | 160 | /** |
167 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_CREATE | 161 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_CREATE |
168 | */ | 162 | */ |
@@ -191,8 +185,7 @@ struct CreateRequestMessage | |||
191 | * Client requests renaming of an identity. Service | 185 | * Client requests renaming of an identity. Service |
192 | * will respond with a result code. | 186 | * will respond with a result code. |
193 | */ | 187 | */ |
194 | struct RenameMessage | 188 | struct RenameMessage { |
195 | { | ||
196 | /** | 189 | /** |
197 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME | 190 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME |
198 | */ | 191 | */ |
@@ -217,8 +210,7 @@ struct RenameMessage | |||
217 | * Client requests deletion of an identity. Service | 210 | * Client requests deletion of an identity. Service |
218 | * will respond with a result code. | 211 | * will respond with a result code. |
219 | */ | 212 | */ |
220 | struct DeleteMessage | 213 | struct DeleteMessage { |
221 | { | ||
222 | /** | 214 | /** |
223 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE | 215 | * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE |
224 | */ | 216 | */ |
@@ -242,8 +234,7 @@ GNUNET_NETWORK_STRUCT_END | |||
242 | /** | 234 | /** |
243 | * Handle for an ego. | 235 | * Handle for an ego. |
244 | */ | 236 | */ |
245 | struct GNUNET_IDENTITY_Ego | 237 | struct GNUNET_IDENTITY_Ego { |
246 | { | ||
247 | /** | 238 | /** |
248 | * Private key associated with this ego. | 239 | * Private key associated with this ego. |
249 | */ | 240 | */ |
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c index c463da641..530ee2d13 100644 --- a/src/identity/identity_api.c +++ b/src/identity/identity_api.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 identity/identity_api.c | 22 | * @file identity/identity_api.c |
@@ -30,15 +30,13 @@ | |||
30 | #include "gnunet_identity_service.h" | 30 | #include "gnunet_identity_service.h" |
31 | #include "identity.h" | 31 | #include "identity.h" |
32 | 32 | ||
33 | #define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from(kind, "identity-api", __VA_ARGS__) |
34 | 34 | ||
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Handle for an operation with the identity service. | 37 | * Handle for an operation with the identity service. |
38 | */ | 38 | */ |
39 | struct GNUNET_IDENTITY_Operation | 39 | struct GNUNET_IDENTITY_Operation { |
40 | { | ||
41 | |||
42 | /** | 40 | /** |
43 | * Main identity handle. | 41 | * Main identity handle. |
44 | */ | 42 | */ |
@@ -93,8 +91,7 @@ struct GNUNET_IDENTITY_Operation | |||
93 | /** | 91 | /** |
94 | * Handle for the service. | 92 | * Handle for the service. |
95 | */ | 93 | */ |
96 | struct GNUNET_IDENTITY_Handle | 94 | struct GNUNET_IDENTITY_Handle { |
97 | { | ||
98 | /** | 95 | /** |
99 | * Configuration to use. | 96 | * Configuration to use. |
100 | */ | 97 | */ |
@@ -154,7 +151,7 @@ struct GNUNET_IDENTITY_Handle | |||
154 | * @return handle for the anonymous user, must not be freed | 151 | * @return handle for the anonymous user, must not be freed |
155 | */ | 152 | */ |
156 | const struct GNUNET_IDENTITY_Ego * | 153 | const struct GNUNET_IDENTITY_Ego * |
157 | GNUNET_IDENTITY_ego_get_anonymous () | 154 | GNUNET_IDENTITY_ego_get_anonymous() |
158 | { | 155 | { |
159 | static struct GNUNET_IDENTITY_Ego anon; | 156 | static struct GNUNET_IDENTITY_Ego anon; |
160 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 157 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
@@ -162,9 +159,9 @@ GNUNET_IDENTITY_ego_get_anonymous () | |||
162 | if (NULL != anon.pk) | 159 | if (NULL != anon.pk) |
163 | return &anon; | 160 | return &anon; |
164 | anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) | 161 | anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) |
165 | GNUNET_CRYPTO_ecdsa_key_get_anonymous (); | 162 | GNUNET_CRYPTO_ecdsa_key_get_anonymous(); |
166 | GNUNET_CRYPTO_ecdsa_key_get_public (anon.pk, &pub); | 163 | GNUNET_CRYPTO_ecdsa_key_get_public(anon.pk, &pub); |
167 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &anon.id); | 164 | GNUNET_CRYPTO_hash(&pub, sizeof(pub), &anon.id); |
168 | return &anon; | 165 | return &anon; |
169 | } | 166 | } |
170 | 167 | ||
@@ -175,7 +172,7 @@ GNUNET_IDENTITY_ego_get_anonymous () | |||
175 | * @param cls handle to the identity service. | 172 | * @param cls handle to the identity service. |
176 | */ | 173 | */ |
177 | static void | 174 | static void |
178 | reconnect (void *cls); | 175 | reconnect(void *cls); |
179 | 176 | ||
180 | 177 | ||
181 | /** | 178 | /** |
@@ -187,18 +184,18 @@ reconnect (void *cls); | |||
187 | * @return #GNUNET_OK (continue to iterate) | 184 | * @return #GNUNET_OK (continue to iterate) |
188 | */ | 185 | */ |
189 | static int | 186 | static int |
190 | free_ego (void *cls, const struct GNUNET_HashCode *key, void *value) | 187 | free_ego(void *cls, const struct GNUNET_HashCode *key, void *value) |
191 | { | 188 | { |
192 | struct GNUNET_IDENTITY_Handle *h = cls; | 189 | struct GNUNET_IDENTITY_Handle *h = cls; |
193 | struct GNUNET_IDENTITY_Ego *ego = value; | 190 | struct GNUNET_IDENTITY_Ego *ego = value; |
194 | 191 | ||
195 | if (NULL != h->cb) | 192 | if (NULL != h->cb) |
196 | h->cb (h->cb_cls, ego, &ego->ctx, NULL); | 193 | h->cb(h->cb_cls, ego, &ego->ctx, NULL); |
197 | GNUNET_free (ego->pk); | 194 | GNUNET_free(ego->pk); |
198 | GNUNET_free (ego->name); | 195 | GNUNET_free(ego->name); |
199 | GNUNET_assert (GNUNET_YES == | 196 | GNUNET_assert(GNUNET_YES == |
200 | GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value)); | 197 | GNUNET_CONTAINER_multihashmap_remove(h->egos, key, value)); |
201 | GNUNET_free (ego); | 198 | GNUNET_free(ego); |
202 | return GNUNET_OK; | 199 | return GNUNET_OK; |
203 | } | 200 | } |
204 | 201 | ||
@@ -209,38 +206,38 @@ free_ego (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
209 | * @param h transport service to reconnect | 206 | * @param h transport service to reconnect |
210 | */ | 207 | */ |
211 | static void | 208 | static void |
212 | reschedule_connect (struct GNUNET_IDENTITY_Handle *h) | 209 | reschedule_connect(struct GNUNET_IDENTITY_Handle *h) |
213 | { | 210 | { |
214 | struct GNUNET_IDENTITY_Operation *op; | 211 | struct GNUNET_IDENTITY_Operation *op; |
215 | 212 | ||
216 | GNUNET_assert (NULL == h->reconnect_task); | 213 | GNUNET_assert(NULL == h->reconnect_task); |
217 | 214 | ||
218 | if (NULL != h->mq) | 215 | if (NULL != h->mq) |
219 | { | 216 | { |
220 | GNUNET_MQ_destroy (h->mq); | 217 | GNUNET_MQ_destroy(h->mq); |
221 | h->mq = NULL; | 218 | h->mq = NULL; |
222 | } | 219 | } |
223 | while (NULL != (op = h->op_head)) | 220 | while (NULL != (op = h->op_head)) |
224 | { | 221 | { |
225 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 222 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); |
226 | if (NULL != op->cont) | 223 | if (NULL != op->cont) |
227 | op->cont (op->cls, "Error in communication with the identity service"); | 224 | op->cont(op->cls, "Error in communication with the identity service"); |
228 | else if (NULL != op->cb) | 225 | else if (NULL != op->cb) |
229 | op->cb (op->cls, NULL, NULL, NULL); | 226 | op->cb(op->cls, NULL, NULL, NULL); |
230 | else if (NULL != op->create_cont) | 227 | else if (NULL != op->create_cont) |
231 | op->create_cont (op->cls, | 228 | op->create_cont(op->cls, |
232 | NULL, | 229 | NULL, |
233 | "Failed to communicate with the identity service"); | 230 | "Failed to communicate with the identity service"); |
234 | GNUNET_free_non_null (op->pk); | 231 | GNUNET_free_non_null(op->pk); |
235 | GNUNET_free (op); | 232 | GNUNET_free(op); |
236 | } | 233 | } |
237 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); | 234 | GNUNET_CONTAINER_multihashmap_iterate(h->egos, &free_ego, h); |
238 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 235 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
239 | "Scheduling task to reconnect to identity service in %s.\n", | 236 | "Scheduling task to reconnect to identity service in %s.\n", |
240 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); | 237 | GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); |
241 | h->reconnect_task = | 238 | h->reconnect_task = |
242 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); | 239 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); |
243 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 240 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); |
244 | } | 241 | } |
245 | 242 | ||
246 | 243 | ||
@@ -253,11 +250,11 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h) | |||
253 | * @param error error code | 250 | * @param error error code |
254 | */ | 251 | */ |
255 | static void | 252 | static void |
256 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 253 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
257 | { | 254 | { |
258 | struct GNUNET_IDENTITY_Handle *h = cls; | 255 | struct GNUNET_IDENTITY_Handle *h = cls; |
259 | 256 | ||
260 | reschedule_connect (h); | 257 | reschedule_connect(h); |
261 | } | 258 | } |
262 | 259 | ||
263 | 260 | ||
@@ -270,10 +267,10 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
270 | * @return #GNUNET_OK if the message is well-formed | 267 | * @return #GNUNET_OK if the message is well-formed |
271 | */ | 268 | */ |
272 | static int | 269 | static int |
273 | check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 270 | check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) |
274 | { | 271 | { |
275 | if (sizeof (*rcm) != htons (rcm->header.size)) | 272 | if (sizeof(*rcm) != htons(rcm->header.size)) |
276 | GNUNET_MQ_check_zero_termination (rcm); | 273 | GNUNET_MQ_check_zero_termination(rcm); |
277 | return GNUNET_OK; | 274 | return GNUNET_OK; |
278 | } | 275 | } |
279 | 276 | ||
@@ -285,29 +282,29 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
285 | * @param rcm result message received | 282 | * @param rcm result message received |
286 | */ | 283 | */ |
287 | static void | 284 | static void |
288 | handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 285 | handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) |
289 | { | 286 | { |
290 | struct GNUNET_IDENTITY_Handle *h = cls; | 287 | struct GNUNET_IDENTITY_Handle *h = cls; |
291 | struct GNUNET_IDENTITY_Operation *op; | 288 | struct GNUNET_IDENTITY_Operation *op; |
292 | uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm); | 289 | uint16_t size = ntohs(rcm->header.size) - sizeof(*rcm); |
293 | const char *str = (0 == size) ? NULL : (const char *) &rcm[1]; | 290 | const char *str = (0 == size) ? NULL : (const char *)&rcm[1]; |
294 | 291 | ||
295 | op = h->op_head; | 292 | op = h->op_head; |
296 | if (NULL == op) | 293 | if (NULL == op) |
297 | { | 294 | { |
298 | GNUNET_break (0); | 295 | GNUNET_break(0); |
299 | reschedule_connect (h); | 296 | reschedule_connect(h); |
300 | return; | 297 | return; |
301 | } | 298 | } |
302 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 299 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); |
303 | if (NULL != op->cont) | 300 | if (NULL != op->cont) |
304 | op->cont (op->cls, str); | 301 | op->cont(op->cls, str); |
305 | else if (NULL != op->cb) | 302 | else if (NULL != op->cb) |
306 | op->cb (op->cls, NULL, NULL, NULL); | 303 | op->cb(op->cls, NULL, NULL, NULL); |
307 | else if (NULL != op->create_cont) | 304 | else if (NULL != op->create_cont) |
308 | op->create_cont (op->cls, (NULL == str) ? op->pk : NULL, str); | 305 | op->create_cont(op->cls, (NULL == str) ? op->pk : NULL, str); |
309 | GNUNET_free_non_null (op->pk); | 306 | GNUNET_free_non_null(op->pk); |
310 | GNUNET_free (op); | 307 | GNUNET_free(op); |
311 | } | 308 | } |
312 | 309 | ||
313 | 310 | ||
@@ -319,18 +316,18 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
319 | * @return #GNUNET_OK if the message is well-formed | 316 | * @return #GNUNET_OK if the message is well-formed |
320 | */ | 317 | */ |
321 | static int | 318 | static int |
322 | check_identity_update (void *cls, const struct UpdateMessage *um) | 319 | check_identity_update(void *cls, const struct UpdateMessage *um) |
323 | { | 320 | { |
324 | uint16_t size = ntohs (um->header.size); | 321 | uint16_t size = ntohs(um->header.size); |
325 | uint16_t name_len = ntohs (um->name_len); | 322 | uint16_t name_len = ntohs(um->name_len); |
326 | const char *str = (const char *) &um[1]; | 323 | const char *str = (const char *)&um[1]; |
327 | 324 | ||
328 | if ((size != name_len + sizeof (struct UpdateMessage)) || | 325 | if ((size != name_len + sizeof(struct UpdateMessage)) || |
329 | ((0 != name_len) && ('\0' != str[name_len - 1]))) | 326 | ((0 != name_len) && ('\0' != str[name_len - 1]))) |
330 | { | 327 | { |
331 | GNUNET_break (0); | 328 | GNUNET_break(0); |
332 | return GNUNET_SYSERR; | 329 | return GNUNET_SYSERR; |
333 | } | 330 | } |
334 | return GNUNET_OK; | 331 | return GNUNET_OK; |
335 | } | 332 | } |
336 | 333 | ||
@@ -342,70 +339,70 @@ check_identity_update (void *cls, const struct UpdateMessage *um) | |||
342 | * @param um message received | 339 | * @param um message received |
343 | */ | 340 | */ |
344 | static void | 341 | static void |
345 | handle_identity_update (void *cls, const struct UpdateMessage *um) | 342 | handle_identity_update(void *cls, const struct UpdateMessage *um) |
346 | { | 343 | { |
347 | struct GNUNET_IDENTITY_Handle *h = cls; | 344 | struct GNUNET_IDENTITY_Handle *h = cls; |
348 | uint16_t name_len = ntohs (um->name_len); | 345 | uint16_t name_len = ntohs(um->name_len); |
349 | const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; | 346 | const char *str = (0 == name_len) ? NULL : (const char *)&um[1]; |
350 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 347 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
351 | struct GNUNET_HashCode id; | 348 | struct GNUNET_HashCode id; |
352 | struct GNUNET_IDENTITY_Ego *ego; | 349 | struct GNUNET_IDENTITY_Ego *ego; |
353 | 350 | ||
354 | if (GNUNET_YES == ntohs (um->end_of_list)) | 351 | if (GNUNET_YES == ntohs(um->end_of_list)) |
355 | { | ||
356 | /* end of initial list of data */ | ||
357 | if (NULL != h->cb) | ||
358 | h->cb (h->cb_cls, NULL, NULL, NULL); | ||
359 | return; | ||
360 | } | ||
361 | GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); | ||
362 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id); | ||
363 | ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id); | ||
364 | if (NULL == ego) | ||
365 | { | ||
366 | /* ego was created */ | ||
367 | if (NULL == str) | ||
368 | { | 352 | { |
369 | /* deletion of unknown ego? not allowed */ | 353 | /* end of initial list of data */ |
370 | GNUNET_break (0); | 354 | if (NULL != h->cb) |
371 | reschedule_connect (h); | 355 | h->cb(h->cb_cls, NULL, NULL, NULL); |
372 | return; | 356 | return; |
373 | } | 357 | } |
374 | ego = GNUNET_new (struct GNUNET_IDENTITY_Ego); | 358 | GNUNET_CRYPTO_ecdsa_key_get_public(&um->private_key, &pub); |
375 | ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey); | 359 | GNUNET_CRYPTO_hash(&pub, sizeof(pub), &id); |
376 | *ego->pk = um->private_key; | 360 | ego = GNUNET_CONTAINER_multihashmap_get(h->egos, &id); |
377 | ego->name = GNUNET_strdup (str); | 361 | if (NULL == ego) |
378 | ego->id = id; | 362 | { |
379 | GNUNET_assert (GNUNET_YES == | 363 | /* ego was created */ |
380 | GNUNET_CONTAINER_multihashmap_put ( | 364 | if (NULL == str) |
381 | h->egos, | 365 | { |
382 | &ego->id, | 366 | /* deletion of unknown ego? not allowed */ |
383 | ego, | 367 | GNUNET_break(0); |
384 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 368 | reschedule_connect(h); |
385 | } | 369 | return; |
370 | } | ||
371 | ego = GNUNET_new(struct GNUNET_IDENTITY_Ego); | ||
372 | ego->pk = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); | ||
373 | *ego->pk = um->private_key; | ||
374 | ego->name = GNUNET_strdup(str); | ||
375 | ego->id = id; | ||
376 | GNUNET_assert(GNUNET_YES == | ||
377 | GNUNET_CONTAINER_multihashmap_put( | ||
378 | h->egos, | ||
379 | &ego->id, | ||
380 | ego, | ||
381 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
382 | } | ||
386 | if (NULL == str) | 383 | if (NULL == str) |
387 | { | 384 | { |
388 | /* ego was deleted */ | 385 | /* ego was deleted */ |
389 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (h->egos, | 386 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(h->egos, |
390 | &ego->id, | 387 | &ego->id, |
391 | ego)); | 388 | ego)); |
392 | } | 389 | } |
393 | else | 390 | else |
394 | { | 391 | { |
395 | /* ego changed name */ | 392 | /* ego changed name */ |
396 | GNUNET_free (ego->name); | 393 | GNUNET_free(ego->name); |
397 | ego->name = GNUNET_strdup (str); | 394 | ego->name = GNUNET_strdup(str); |
398 | } | 395 | } |
399 | /* inform application about change */ | 396 | /* inform application about change */ |
400 | if (NULL != h->cb) | 397 | if (NULL != h->cb) |
401 | h->cb (h->cb_cls, ego, &ego->ctx, str); | 398 | h->cb(h->cb_cls, ego, &ego->ctx, str); |
402 | /* complete deletion */ | 399 | /* complete deletion */ |
403 | if (NULL == str) | 400 | if (NULL == str) |
404 | { | 401 | { |
405 | GNUNET_free (ego->pk); | 402 | GNUNET_free(ego->pk); |
406 | GNUNET_free (ego->name); | 403 | GNUNET_free(ego->name); |
407 | GNUNET_free (ego); | 404 | GNUNET_free(ego); |
408 | } | 405 | } |
409 | } | 406 | } |
410 | 407 | ||
411 | 408 | ||
@@ -418,18 +415,18 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
418 | * @return #GNUNET_OK if the message is well-formed | 415 | * @return #GNUNET_OK if the message is well-formed |
419 | */ | 416 | */ |
420 | static int | 417 | static int |
421 | check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) | 418 | check_identity_set_default(void *cls, const struct SetDefaultMessage *sdm) |
422 | { | 419 | { |
423 | uint16_t size = ntohs (sdm->header.size) - sizeof (*sdm); | 420 | uint16_t size = ntohs(sdm->header.size) - sizeof(*sdm); |
424 | uint16_t name_len = ntohs (sdm->name_len); | 421 | uint16_t name_len = ntohs(sdm->name_len); |
425 | const char *str = (const char *) &sdm[1]; | 422 | const char *str = (const char *)&sdm[1]; |
426 | 423 | ||
427 | if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1]))) | 424 | if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1]))) |
428 | { | 425 | { |
429 | GNUNET_break (0); | 426 | GNUNET_break(0); |
430 | return GNUNET_SYSERR; | 427 | return GNUNET_SYSERR; |
431 | } | 428 | } |
432 | GNUNET_break (0 == ntohs (sdm->reserved)); | 429 | GNUNET_break(0 == ntohs(sdm->reserved)); |
433 | return GNUNET_OK; | 430 | return GNUNET_OK; |
434 | } | 431 | } |
435 | 432 | ||
@@ -442,7 +439,7 @@ check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) | |||
442 | * @param sdm message received | 439 | * @param sdm message received |
443 | */ | 440 | */ |
444 | static void | 441 | static void |
445 | handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) | 442 | handle_identity_set_default(void *cls, const struct SetDefaultMessage *sdm) |
446 | { | 443 | { |
447 | struct GNUNET_IDENTITY_Handle *h = cls; | 444 | struct GNUNET_IDENTITY_Handle *h = cls; |
448 | struct GNUNET_IDENTITY_Operation *op; | 445 | struct GNUNET_IDENTITY_Operation *op; |
@@ -450,28 +447,28 @@ handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) | |||
450 | struct GNUNET_HashCode id; | 447 | struct GNUNET_HashCode id; |
451 | struct GNUNET_IDENTITY_Ego *ego; | 448 | struct GNUNET_IDENTITY_Ego *ego; |
452 | 449 | ||
453 | GNUNET_CRYPTO_ecdsa_key_get_public (&sdm->private_key, &pub); | 450 | GNUNET_CRYPTO_ecdsa_key_get_public(&sdm->private_key, &pub); |
454 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id); | 451 | GNUNET_CRYPTO_hash(&pub, sizeof(pub), &id); |
455 | ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id); | 452 | ego = GNUNET_CONTAINER_multihashmap_get(h->egos, &id); |
456 | if (NULL == ego) | 453 | if (NULL == ego) |
457 | { | 454 | { |
458 | GNUNET_break (0); | 455 | GNUNET_break(0); |
459 | reschedule_connect (h); | 456 | reschedule_connect(h); |
460 | return; | 457 | return; |
461 | } | 458 | } |
462 | op = h->op_head; | 459 | op = h->op_head; |
463 | if (NULL == op) | 460 | if (NULL == op) |
464 | { | 461 | { |
465 | GNUNET_break (0); | 462 | GNUNET_break(0); |
466 | reschedule_connect (h); | 463 | reschedule_connect(h); |
467 | return; | 464 | return; |
468 | } | 465 | } |
469 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 466 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
470 | "Received SET_DEFAULT message from identity service\n"); | 467 | "Received SET_DEFAULT message from identity service\n"); |
471 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 468 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); |
472 | if (NULL != op->cb) | 469 | if (NULL != op->cb) |
473 | op->cb (op->cls, ego, &ego->ctx, ego->name); | 470 | op->cb(op->cls, ego, &ego->ctx, ego->name); |
474 | GNUNET_free (op); | 471 | GNUNET_free(op); |
475 | } | 472 | } |
476 | 473 | ||
477 | 474 | ||
@@ -481,38 +478,38 @@ handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm) | |||
481 | * @param cls handle to the identity service. | 478 | * @param cls handle to the identity service. |
482 | */ | 479 | */ |
483 | static void | 480 | static void |
484 | reconnect (void *cls) | 481 | reconnect(void *cls) |
485 | { | 482 | { |
486 | struct GNUNET_IDENTITY_Handle *h = cls; | 483 | struct GNUNET_IDENTITY_Handle *h = cls; |
487 | struct GNUNET_MQ_MessageHandler handlers[] = | 484 | struct GNUNET_MQ_MessageHandler handlers[] = |
488 | {GNUNET_MQ_hd_var_size (identity_result_code, | 485 | { GNUNET_MQ_hd_var_size(identity_result_code, |
489 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, | 486 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, |
490 | struct ResultCodeMessage, | 487 | struct ResultCodeMessage, |
491 | h), | 488 | h), |
492 | GNUNET_MQ_hd_var_size (identity_update, | 489 | GNUNET_MQ_hd_var_size(identity_update, |
493 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, | 490 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, |
494 | struct UpdateMessage, | 491 | struct UpdateMessage, |
495 | h), | 492 | h), |
496 | GNUNET_MQ_hd_var_size (identity_set_default, | 493 | GNUNET_MQ_hd_var_size(identity_set_default, |
497 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, | 494 | GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, |
498 | struct SetDefaultMessage, | 495 | struct SetDefaultMessage, |
499 | h), | 496 | h), |
500 | GNUNET_MQ_handler_end ()}; | 497 | GNUNET_MQ_handler_end() }; |
501 | struct GNUNET_MQ_Envelope *env; | 498 | struct GNUNET_MQ_Envelope *env; |
502 | struct GNUNET_MessageHeader *msg; | 499 | struct GNUNET_MessageHeader *msg; |
503 | 500 | ||
504 | h->reconnect_task = NULL; | 501 | h->reconnect_task = NULL; |
505 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n"); | 502 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n"); |
506 | GNUNET_assert (NULL == h->mq); | 503 | GNUNET_assert(NULL == h->mq); |
507 | h->mq = | 504 | h->mq = |
508 | GNUNET_CLIENT_connect (h->cfg, "identity", handlers, &mq_error_handler, h); | 505 | GNUNET_CLIENT_connect(h->cfg, "identity", handlers, &mq_error_handler, h); |
509 | if (NULL == h->mq) | 506 | if (NULL == h->mq) |
510 | return; | 507 | return; |
511 | if (NULL != h->cb) | 508 | if (NULL != h->cb) |
512 | { | 509 | { |
513 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_IDENTITY_START); | 510 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_IDENTITY_START); |
514 | GNUNET_MQ_send (h->mq, env); | 511 | GNUNET_MQ_send(h->mq, env); |
515 | } | 512 | } |
516 | } | 513 | } |
517 | 514 | ||
518 | 515 | ||
@@ -525,23 +522,23 @@ reconnect (void *cls) | |||
525 | * @return handle to use | 522 | * @return handle to use |
526 | */ | 523 | */ |
527 | struct GNUNET_IDENTITY_Handle * | 524 | struct GNUNET_IDENTITY_Handle * |
528 | GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 525 | GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, |
529 | GNUNET_IDENTITY_Callback cb, | 526 | GNUNET_IDENTITY_Callback cb, |
530 | void *cb_cls) | 527 | void *cb_cls) |
531 | { | 528 | { |
532 | struct GNUNET_IDENTITY_Handle *h; | 529 | struct GNUNET_IDENTITY_Handle *h; |
533 | 530 | ||
534 | h = GNUNET_new (struct GNUNET_IDENTITY_Handle); | 531 | h = GNUNET_new(struct GNUNET_IDENTITY_Handle); |
535 | h->cfg = cfg; | 532 | h->cfg = cfg; |
536 | h->cb = cb; | 533 | h->cb = cb; |
537 | h->cb_cls = cb_cls; | 534 | h->cb_cls = cb_cls; |
538 | h->egos = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES); | 535 | h->egos = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_YES); |
539 | reconnect (h); | 536 | reconnect(h); |
540 | if (NULL == h->mq) | 537 | if (NULL == h->mq) |
541 | { | 538 | { |
542 | GNUNET_free (h); | 539 | GNUNET_free(h); |
543 | return NULL; | 540 | return NULL; |
544 | } | 541 | } |
545 | return h; | 542 | return h; |
546 | } | 543 | } |
547 | 544 | ||
@@ -553,7 +550,7 @@ GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
553 | * @return associated ECC key, valid as long as the ego is valid | 550 | * @return associated ECC key, valid as long as the ego is valid |
554 | */ | 551 | */ |
555 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * | 552 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * |
556 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) | 553 | GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego) |
557 | { | 554 | { |
558 | return ego->pk; | 555 | return ego->pk; |
559 | } | 556 | } |
@@ -566,10 +563,10 @@ GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego) | |||
566 | * @param pk set to ego's public key | 563 | * @param pk set to ego's public key |
567 | */ | 564 | */ |
568 | void | 565 | void |
569 | GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, | 566 | GNUNET_IDENTITY_ego_get_public_key(const struct GNUNET_IDENTITY_Ego *ego, |
570 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk) | 567 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk) |
571 | { | 568 | { |
572 | GNUNET_CRYPTO_ecdsa_key_get_public (ego->pk, pk); | 569 | GNUNET_CRYPTO_ecdsa_key_get_public(ego->pk, pk); |
573 | } | 570 | } |
574 | 571 | ||
575 | 572 | ||
@@ -584,10 +581,10 @@ GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, | |||
584 | * @return handle to abort the operation | 581 | * @return handle to abort the operation |
585 | */ | 582 | */ |
586 | struct GNUNET_IDENTITY_Operation * | 583 | struct GNUNET_IDENTITY_Operation * |
587 | GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, | 584 | GNUNET_IDENTITY_get(struct GNUNET_IDENTITY_Handle *h, |
588 | const char *service_name, | 585 | const char *service_name, |
589 | GNUNET_IDENTITY_Callback cb, | 586 | GNUNET_IDENTITY_Callback cb, |
590 | void *cb_cls) | 587 | void *cb_cls) |
591 | { | 588 | { |
592 | struct GNUNET_IDENTITY_Operation *op; | 589 | struct GNUNET_IDENTITY_Operation *op; |
593 | struct GNUNET_MQ_Envelope *env; | 590 | struct GNUNET_MQ_Envelope *env; |
@@ -596,24 +593,24 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, | |||
596 | 593 | ||
597 | if (NULL == h->mq) | 594 | if (NULL == h->mq) |
598 | return NULL; | 595 | return NULL; |
599 | GNUNET_assert (NULL != h->cb); | 596 | GNUNET_assert(NULL != h->cb); |
600 | slen = strlen (service_name) + 1; | 597 | slen = strlen(service_name) + 1; |
601 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct GetDefaultMessage)) | 598 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GetDefaultMessage)) |
602 | { | 599 | { |
603 | GNUNET_break (0); | 600 | GNUNET_break(0); |
604 | return NULL; | 601 | return NULL; |
605 | } | 602 | } |
606 | op = GNUNET_new (struct GNUNET_IDENTITY_Operation); | 603 | op = GNUNET_new(struct GNUNET_IDENTITY_Operation); |
607 | op->h = h; | 604 | op->h = h; |
608 | op->cb = cb; | 605 | op->cb = cb; |
609 | op->cls = cb_cls; | 606 | op->cls = cb_cls; |
610 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 607 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
611 | env = | 608 | env = |
612 | GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT); | 609 | GNUNET_MQ_msg_extra(gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT); |
613 | gdm->name_len = htons (slen); | 610 | gdm->name_len = htons(slen); |
614 | gdm->reserved = htons (0); | 611 | gdm->reserved = htons(0); |
615 | GNUNET_memcpy (&gdm[1], service_name, slen); | 612 | GNUNET_memcpy(&gdm[1], service_name, slen); |
616 | GNUNET_MQ_send (h->mq, env); | 613 | GNUNET_MQ_send(h->mq, env); |
617 | return op; | 614 | return op; |
618 | } | 615 | } |
619 | 616 | ||
@@ -629,11 +626,11 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, | |||
629 | * @return handle to abort the operation | 626 | * @return handle to abort the operation |
630 | */ | 627 | */ |
631 | struct GNUNET_IDENTITY_Operation * | 628 | struct GNUNET_IDENTITY_Operation * |
632 | GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | 629 | GNUNET_IDENTITY_set(struct GNUNET_IDENTITY_Handle *h, |
633 | const char *service_name, | 630 | const char *service_name, |
634 | struct GNUNET_IDENTITY_Ego *ego, | 631 | struct GNUNET_IDENTITY_Ego *ego, |
635 | GNUNET_IDENTITY_Continuation cont, | 632 | GNUNET_IDENTITY_Continuation cont, |
636 | void *cont_cls) | 633 | void *cont_cls) |
637 | { | 634 | { |
638 | struct GNUNET_IDENTITY_Operation *op; | 635 | struct GNUNET_IDENTITY_Operation *op; |
639 | struct GNUNET_MQ_Envelope *env; | 636 | struct GNUNET_MQ_Envelope *env; |
@@ -642,25 +639,25 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | |||
642 | 639 | ||
643 | if (NULL == h->mq) | 640 | if (NULL == h->mq) |
644 | return NULL; | 641 | return NULL; |
645 | GNUNET_assert (NULL != h->cb); | 642 | GNUNET_assert(NULL != h->cb); |
646 | slen = strlen (service_name) + 1; | 643 | slen = strlen(service_name) + 1; |
647 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct SetDefaultMessage)) | 644 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct SetDefaultMessage)) |
648 | { | 645 | { |
649 | GNUNET_break (0); | 646 | GNUNET_break(0); |
650 | return NULL; | 647 | return NULL; |
651 | } | 648 | } |
652 | op = GNUNET_new (struct GNUNET_IDENTITY_Operation); | 649 | op = GNUNET_new(struct GNUNET_IDENTITY_Operation); |
653 | op->h = h; | 650 | op->h = h; |
654 | op->cont = cont; | 651 | op->cont = cont; |
655 | op->cls = cont_cls; | 652 | op->cls = cont_cls; |
656 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 653 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
657 | env = | 654 | env = |
658 | GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); | 655 | GNUNET_MQ_msg_extra(sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); |
659 | sdm->name_len = htons (slen); | 656 | sdm->name_len = htons(slen); |
660 | sdm->reserved = htons (0); | 657 | sdm->reserved = htons(0); |
661 | sdm->private_key = *ego->pk; | 658 | sdm->private_key = *ego->pk; |
662 | GNUNET_memcpy (&sdm[1], service_name, slen); | 659 | GNUNET_memcpy(&sdm[1], service_name, slen); |
663 | GNUNET_MQ_send (h->mq, env); | 660 | GNUNET_MQ_send(h->mq, env); |
664 | return op; | 661 | return op; |
665 | } | 662 | } |
666 | 663 | ||
@@ -675,10 +672,10 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, | |||
675 | * @return handle to abort the operation | 672 | * @return handle to abort the operation |
676 | */ | 673 | */ |
677 | struct GNUNET_IDENTITY_Operation * | 674 | struct GNUNET_IDENTITY_Operation * |
678 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | 675 | GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h, |
679 | const char *name, | 676 | const char *name, |
680 | GNUNET_IDENTITY_CreateContinuation cont, | 677 | GNUNET_IDENTITY_CreateContinuation cont, |
681 | void *cont_cls) | 678 | void *cont_cls) |
682 | { | 679 | { |
683 | struct GNUNET_IDENTITY_Operation *op; | 680 | struct GNUNET_IDENTITY_Operation *op; |
684 | struct GNUNET_MQ_Envelope *env; | 681 | struct GNUNET_MQ_Envelope *env; |
@@ -688,25 +685,25 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
688 | 685 | ||
689 | if (NULL == h->mq) | 686 | if (NULL == h->mq) |
690 | return NULL; | 687 | return NULL; |
691 | slen = strlen (name) + 1; | 688 | slen = strlen(name) + 1; |
692 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct CreateRequestMessage)) | 689 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct CreateRequestMessage)) |
693 | { | 690 | { |
694 | GNUNET_break (0); | 691 | GNUNET_break(0); |
695 | return NULL; | 692 | return NULL; |
696 | } | 693 | } |
697 | op = GNUNET_new (struct GNUNET_IDENTITY_Operation); | 694 | op = GNUNET_new(struct GNUNET_IDENTITY_Operation); |
698 | op->h = h; | 695 | op->h = h; |
699 | op->create_cont = cont; | 696 | op->create_cont = cont; |
700 | op->cls = cont_cls; | 697 | op->cls = cont_cls; |
701 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 698 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
702 | env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); | 699 | env = GNUNET_MQ_msg_extra(crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); |
703 | crm->name_len = htons (slen); | 700 | crm->name_len = htons(slen); |
704 | crm->reserved = htons (0); | 701 | crm->reserved = htons(0); |
705 | pk = GNUNET_CRYPTO_ecdsa_key_create (); | 702 | pk = GNUNET_CRYPTO_ecdsa_key_create(); |
706 | crm->private_key = *pk; | 703 | crm->private_key = *pk; |
707 | op->pk = pk; | 704 | op->pk = pk; |
708 | GNUNET_memcpy (&crm[1], name, slen); | 705 | GNUNET_memcpy(&crm[1], name, slen); |
709 | GNUNET_MQ_send (h->mq, env); | 706 | GNUNET_MQ_send(h->mq, env); |
710 | return op; | 707 | return op; |
711 | } | 708 | } |
712 | 709 | ||
@@ -722,11 +719,11 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, | |||
722 | * @return handle to abort the operation | 719 | * @return handle to abort the operation |
723 | */ | 720 | */ |
724 | struct GNUNET_IDENTITY_Operation * | 721 | struct GNUNET_IDENTITY_Operation * |
725 | GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h, | 722 | GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h, |
726 | const char *old_name, | 723 | const char *old_name, |
727 | const char *new_name, | 724 | const char *new_name, |
728 | GNUNET_IDENTITY_Continuation cb, | 725 | GNUNET_IDENTITY_Continuation cb, |
729 | void *cb_cls) | 726 | void *cb_cls) |
730 | { | 727 | { |
731 | struct GNUNET_IDENTITY_Operation *op; | 728 | struct GNUNET_IDENTITY_Operation *op; |
732 | struct GNUNET_MQ_Envelope *env; | 729 | struct GNUNET_MQ_Envelope *env; |
@@ -737,30 +734,30 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h, | |||
737 | 734 | ||
738 | if (NULL == h->mq) | 735 | if (NULL == h->mq) |
739 | return NULL; | 736 | return NULL; |
740 | slen_old = strlen (old_name) + 1; | 737 | slen_old = strlen(old_name) + 1; |
741 | slen_new = strlen (new_name) + 1; | 738 | slen_new = strlen(new_name) + 1; |
742 | if ((slen_old >= GNUNET_MAX_MESSAGE_SIZE) || | 739 | if ((slen_old >= GNUNET_MAX_MESSAGE_SIZE) || |
743 | (slen_new >= GNUNET_MAX_MESSAGE_SIZE) || | 740 | (slen_new >= GNUNET_MAX_MESSAGE_SIZE) || |
744 | (slen_old + slen_new >= | 741 | (slen_old + slen_new >= |
745 | GNUNET_MAX_MESSAGE_SIZE - sizeof (struct RenameMessage))) | 742 | GNUNET_MAX_MESSAGE_SIZE - sizeof(struct RenameMessage))) |
746 | { | 743 | { |
747 | GNUNET_break (0); | 744 | GNUNET_break(0); |
748 | return NULL; | 745 | return NULL; |
749 | } | 746 | } |
750 | op = GNUNET_new (struct GNUNET_IDENTITY_Operation); | 747 | op = GNUNET_new(struct GNUNET_IDENTITY_Operation); |
751 | op->h = h; | 748 | op->h = h; |
752 | op->cont = cb; | 749 | op->cont = cb; |
753 | op->cls = cb_cls; | 750 | op->cls = cb_cls; |
754 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 751 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
755 | env = GNUNET_MQ_msg_extra (grm, | 752 | env = GNUNET_MQ_msg_extra(grm, |
756 | slen_old + slen_new, | 753 | slen_old + slen_new, |
757 | GNUNET_MESSAGE_TYPE_IDENTITY_RENAME); | 754 | GNUNET_MESSAGE_TYPE_IDENTITY_RENAME); |
758 | grm->old_name_len = htons (slen_old); | 755 | grm->old_name_len = htons(slen_old); |
759 | grm->new_name_len = htons (slen_new); | 756 | grm->new_name_len = htons(slen_new); |
760 | dst = (char *) &grm[1]; | 757 | dst = (char *)&grm[1]; |
761 | GNUNET_memcpy (dst, old_name, slen_old); | 758 | GNUNET_memcpy(dst, old_name, slen_old); |
762 | GNUNET_memcpy (&dst[slen_old], new_name, slen_new); | 759 | GNUNET_memcpy(&dst[slen_old], new_name, slen_new); |
763 | GNUNET_MQ_send (h->mq, env); | 760 | GNUNET_MQ_send(h->mq, env); |
764 | return op; | 761 | return op; |
765 | } | 762 | } |
766 | 763 | ||
@@ -775,10 +772,10 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h, | |||
775 | * @return handle to abort the operation | 772 | * @return handle to abort the operation |
776 | */ | 773 | */ |
777 | struct GNUNET_IDENTITY_Operation * | 774 | struct GNUNET_IDENTITY_Operation * |
778 | GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h, | 775 | GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *h, |
779 | const char *name, | 776 | const char *name, |
780 | GNUNET_IDENTITY_Continuation cb, | 777 | GNUNET_IDENTITY_Continuation cb, |
781 | void *cb_cls) | 778 | void *cb_cls) |
782 | { | 779 | { |
783 | struct GNUNET_IDENTITY_Operation *op; | 780 | struct GNUNET_IDENTITY_Operation *op; |
784 | struct GNUNET_MQ_Envelope *env; | 781 | struct GNUNET_MQ_Envelope *env; |
@@ -787,22 +784,22 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h, | |||
787 | 784 | ||
788 | if (NULL == h->mq) | 785 | if (NULL == h->mq) |
789 | return NULL; | 786 | return NULL; |
790 | slen = strlen (name) + 1; | 787 | slen = strlen(name) + 1; |
791 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct DeleteMessage)) | 788 | if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct DeleteMessage)) |
792 | { | 789 | { |
793 | GNUNET_break (0); | 790 | GNUNET_break(0); |
794 | return NULL; | 791 | return NULL; |
795 | } | 792 | } |
796 | op = GNUNET_new (struct GNUNET_IDENTITY_Operation); | 793 | op = GNUNET_new(struct GNUNET_IDENTITY_Operation); |
797 | op->h = h; | 794 | op->h = h; |
798 | op->cont = cb; | 795 | op->cont = cb; |
799 | op->cls = cb_cls; | 796 | op->cls = cb_cls; |
800 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op); | 797 | GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); |
801 | env = GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE); | 798 | env = GNUNET_MQ_msg_extra(gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE); |
802 | gdm->name_len = htons (slen); | 799 | gdm->name_len = htons(slen); |
803 | gdm->reserved = htons (0); | 800 | gdm->reserved = htons(0); |
804 | GNUNET_memcpy (&gdm[1], name, slen); | 801 | GNUNET_memcpy(&gdm[1], name, slen); |
805 | GNUNET_MQ_send (h->mq, env); | 802 | GNUNET_MQ_send(h->mq, env); |
806 | return op; | 803 | return op; |
807 | } | 804 | } |
808 | 805 | ||
@@ -816,16 +813,16 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h, | |||
816 | * @param op operation to cancel | 813 | * @param op operation to cancel |
817 | */ | 814 | */ |
818 | void | 815 | void |
819 | GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op) | 816 | GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op) |
820 | { | 817 | { |
821 | op->cont = NULL; | 818 | op->cont = NULL; |
822 | op->cb = NULL; | 819 | op->cb = NULL; |
823 | op->create_cont = NULL; | 820 | op->create_cont = NULL; |
824 | if (NULL != op->pk) | 821 | if (NULL != op->pk) |
825 | { | 822 | { |
826 | GNUNET_free (op->pk); | 823 | GNUNET_free(op->pk); |
827 | op->pk = NULL; | 824 | op->pk = NULL; |
828 | } | 825 | } |
829 | } | 826 | } |
830 | 827 | ||
831 | 828 | ||
@@ -835,35 +832,35 @@ GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op) | |||
835 | * @param h handle to destroy | 832 | * @param h handle to destroy |
836 | */ | 833 | */ |
837 | void | 834 | void |
838 | GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h) | 835 | GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h) |
839 | { | 836 | { |
840 | struct GNUNET_IDENTITY_Operation *op; | 837 | struct GNUNET_IDENTITY_Operation *op; |
841 | 838 | ||
842 | GNUNET_assert (NULL != h); | 839 | GNUNET_assert(NULL != h); |
843 | if (h->reconnect_task != NULL) | 840 | if (h->reconnect_task != NULL) |
844 | { | 841 | { |
845 | GNUNET_SCHEDULER_cancel (h->reconnect_task); | 842 | GNUNET_SCHEDULER_cancel(h->reconnect_task); |
846 | h->reconnect_task = NULL; | 843 | h->reconnect_task = NULL; |
847 | } | 844 | } |
848 | if (NULL != h->egos) | 845 | if (NULL != h->egos) |
849 | { | 846 | { |
850 | GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h); | 847 | GNUNET_CONTAINER_multihashmap_iterate(h->egos, &free_ego, h); |
851 | GNUNET_CONTAINER_multihashmap_destroy (h->egos); | 848 | GNUNET_CONTAINER_multihashmap_destroy(h->egos); |
852 | h->egos = NULL; | 849 | h->egos = NULL; |
853 | } | 850 | } |
854 | while (NULL != (op = h->op_head)) | 851 | while (NULL != (op = h->op_head)) |
855 | { | 852 | { |
856 | GNUNET_break (NULL == op->cont); | 853 | GNUNET_break(NULL == op->cont); |
857 | GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op); | 854 | GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); |
858 | GNUNET_free_non_null (op->pk); | 855 | GNUNET_free_non_null(op->pk); |
859 | GNUNET_free (op); | 856 | GNUNET_free(op); |
860 | } | 857 | } |
861 | if (NULL != h->mq) | 858 | if (NULL != h->mq) |
862 | { | 859 | { |
863 | GNUNET_MQ_destroy (h->mq); | 860 | GNUNET_MQ_destroy(h->mq); |
864 | h->mq = NULL; | 861 | h->mq = NULL; |
865 | } | 862 | } |
866 | GNUNET_free (h); | 863 | GNUNET_free(h); |
867 | } | 864 | } |
868 | 865 | ||
869 | /* end of identity_api.c */ | 866 | /* end of identity_api.c */ |
diff --git a/src/identity/identity_api_lookup.c b/src/identity/identity_api_lookup.c index 56ebf6f47..faf647c07 100644 --- a/src/identity/identity_api_lookup.c +++ b/src/identity/identity_api_lookup.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 identity/identity_api_lookup.c | 22 | * @file identity/identity_api_lookup.c |
@@ -28,15 +28,13 @@ | |||
28 | #include "gnunet_identity_service.h" | 28 | #include "gnunet_identity_service.h" |
29 | #include "identity.h" | 29 | #include "identity.h" |
30 | 30 | ||
31 | #define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "identity-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Handle for ego lookup. | 35 | * Handle for ego lookup. |
36 | */ | 36 | */ |
37 | struct GNUNET_IDENTITY_EgoLookup | 37 | struct GNUNET_IDENTITY_EgoLookup { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Connection to service. | 39 | * Connection to service. |
42 | */ | 40 | */ |
@@ -68,10 +66,10 @@ struct GNUNET_IDENTITY_EgoLookup | |||
68 | * @return #GNUNET_OK if the message is well-formed | 66 | * @return #GNUNET_OK if the message is well-formed |
69 | */ | 67 | */ |
70 | static int | 68 | static int |
71 | check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 69 | check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) |
72 | { | 70 | { |
73 | if (sizeof (*rcm) != htons (rcm->header.size)) | 71 | if (sizeof(*rcm) != htons(rcm->header.size)) |
74 | GNUNET_MQ_check_zero_termination (rcm); | 72 | GNUNET_MQ_check_zero_termination(rcm); |
75 | return GNUNET_OK; | 73 | return GNUNET_OK; |
76 | } | 74 | } |
77 | 75 | ||
@@ -83,12 +81,12 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
83 | * @param rcm result message received | 81 | * @param rcm result message received |
84 | */ | 82 | */ |
85 | static void | 83 | static void |
86 | handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 84 | handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) |
87 | { | 85 | { |
88 | struct GNUNET_IDENTITY_EgoLookup *el = cls; | 86 | struct GNUNET_IDENTITY_EgoLookup *el = cls; |
89 | 87 | ||
90 | el->cb (el->cb_cls, NULL); | 88 | el->cb(el->cb_cls, NULL); |
91 | GNUNET_IDENTITY_ego_lookup_cancel (el); | 89 | GNUNET_IDENTITY_ego_lookup_cancel(el); |
92 | } | 90 | } |
93 | 91 | ||
94 | 92 | ||
@@ -100,18 +98,18 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
100 | * @return #GNUNET_OK if the message is well-formed | 98 | * @return #GNUNET_OK if the message is well-formed |
101 | */ | 99 | */ |
102 | static int | 100 | static int |
103 | check_identity_update (void *cls, const struct UpdateMessage *um) | 101 | check_identity_update(void *cls, const struct UpdateMessage *um) |
104 | { | 102 | { |
105 | uint16_t size = ntohs (um->header.size); | 103 | uint16_t size = ntohs(um->header.size); |
106 | uint16_t name_len = ntohs (um->name_len); | 104 | uint16_t name_len = ntohs(um->name_len); |
107 | const char *str = (const char *) &um[1]; | 105 | const char *str = (const char *)&um[1]; |
108 | 106 | ||
109 | if ((size != name_len + sizeof (struct UpdateMessage)) || | 107 | if ((size != name_len + sizeof(struct UpdateMessage)) || |
110 | ((0 != name_len) && ('\0' != str[name_len - 1]))) | 108 | ((0 != name_len) && ('\0' != str[name_len - 1]))) |
111 | { | 109 | { |
112 | GNUNET_break (0); | 110 | GNUNET_break(0); |
113 | return GNUNET_SYSERR; | 111 | return GNUNET_SYSERR; |
114 | } | 112 | } |
115 | return GNUNET_OK; | 113 | return GNUNET_OK; |
116 | } | 114 | } |
117 | 115 | ||
@@ -123,23 +121,23 @@ check_identity_update (void *cls, const struct UpdateMessage *um) | |||
123 | * @param um message received | 121 | * @param um message received |
124 | */ | 122 | */ |
125 | static void | 123 | static void |
126 | handle_identity_update (void *cls, const struct UpdateMessage *um) | 124 | handle_identity_update(void *cls, const struct UpdateMessage *um) |
127 | { | 125 | { |
128 | struct GNUNET_IDENTITY_EgoLookup *el = cls; | 126 | struct GNUNET_IDENTITY_EgoLookup *el = cls; |
129 | uint16_t name_len = ntohs (um->name_len); | 127 | uint16_t name_len = ntohs(um->name_len); |
130 | const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; | 128 | const char *str = (0 == name_len) ? NULL : (const char *)&um[1]; |
131 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | 129 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; |
132 | struct GNUNET_HashCode id; | 130 | struct GNUNET_HashCode id; |
133 | struct GNUNET_IDENTITY_Ego ego; | 131 | struct GNUNET_IDENTITY_Ego ego; |
134 | 132 | ||
135 | GNUNET_break (GNUNET_YES != ntohs (um->end_of_list)); | 133 | GNUNET_break(GNUNET_YES != ntohs(um->end_of_list)); |
136 | GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub); | 134 | GNUNET_CRYPTO_ecdsa_key_get_public(&um->private_key, &pub); |
137 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id); | 135 | GNUNET_CRYPTO_hash(&pub, sizeof(pub), &id); |
138 | ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) &um->private_key; | 136 | ego.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *)&um->private_key; |
139 | ego.name = (char *) str; | 137 | ego.name = (char *)str; |
140 | ego.id = id; | 138 | ego.id = id; |
141 | el->cb (el->cb_cls, &ego); | 139 | el->cb(el->cb_cls, &ego); |
142 | GNUNET_IDENTITY_ego_lookup_cancel (el); | 140 | GNUNET_IDENTITY_ego_lookup_cancel(el); |
143 | } | 141 | } |
144 | 142 | ||
145 | 143 | ||
@@ -152,11 +150,11 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
152 | * @param error error code | 150 | * @param error error code |
153 | */ | 151 | */ |
154 | static void | 152 | static void |
155 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 153 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
156 | { | 154 | { |
157 | struct GNUNET_IDENTITY_EgoLookup *el = cls; | 155 | struct GNUNET_IDENTITY_EgoLookup *el = cls; |
158 | 156 | ||
159 | el->cb (el->cb_cls, NULL); | 157 | el->cb(el->cb_cls, NULL); |
160 | } | 158 | } |
161 | 159 | ||
162 | 160 | ||
@@ -170,46 +168,46 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
170 | * @return NULL on error | 168 | * @return NULL on error |
171 | */ | 169 | */ |
172 | struct GNUNET_IDENTITY_EgoLookup * | 170 | struct GNUNET_IDENTITY_EgoLookup * |
173 | GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | 171 | GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, |
174 | const char *name, | 172 | const char *name, |
175 | GNUNET_IDENTITY_EgoCallback cb, | 173 | GNUNET_IDENTITY_EgoCallback cb, |
176 | void *cb_cls) | 174 | void *cb_cls) |
177 | { | 175 | { |
178 | struct GNUNET_IDENTITY_EgoLookup *el; | 176 | struct GNUNET_IDENTITY_EgoLookup *el; |
179 | struct GNUNET_MQ_Envelope *env; | 177 | struct GNUNET_MQ_Envelope *env; |
180 | struct GNUNET_MessageHeader *req; | 178 | struct GNUNET_MessageHeader *req; |
181 | size_t nlen; | 179 | size_t nlen; |
182 | 180 | ||
183 | GNUNET_assert (NULL != cb); | 181 | GNUNET_assert(NULL != cb); |
184 | el = GNUNET_new (struct GNUNET_IDENTITY_EgoLookup); | 182 | el = GNUNET_new(struct GNUNET_IDENTITY_EgoLookup); |
185 | el->cb = cb; | 183 | el->cb = cb; |
186 | el->cb_cls = cb_cls; | 184 | el->cb_cls = cb_cls; |
187 | { | 185 | { |
188 | struct GNUNET_MQ_MessageHandler handlers[] = | 186 | struct GNUNET_MQ_MessageHandler handlers[] = |
189 | {GNUNET_MQ_hd_var_size (identity_result_code, | 187 | { GNUNET_MQ_hd_var_size(identity_result_code, |
190 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, | 188 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, |
191 | struct ResultCodeMessage, | 189 | struct ResultCodeMessage, |
192 | el), | 190 | el), |
193 | GNUNET_MQ_hd_var_size (identity_update, | 191 | GNUNET_MQ_hd_var_size(identity_update, |
194 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, | 192 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, |
195 | struct UpdateMessage, | 193 | struct UpdateMessage, |
196 | el), | 194 | el), |
197 | GNUNET_MQ_handler_end ()}; | 195 | GNUNET_MQ_handler_end() }; |
198 | 196 | ||
199 | el->mq = | 197 | el->mq = |
200 | GNUNET_CLIENT_connect (cfg, "identity", handlers, &mq_error_handler, el); | 198 | GNUNET_CLIENT_connect(cfg, "identity", handlers, &mq_error_handler, el); |
201 | } | 199 | } |
202 | if (NULL == el->mq) | 200 | if (NULL == el->mq) |
203 | { | 201 | { |
204 | GNUNET_break (0); | 202 | GNUNET_break(0); |
205 | GNUNET_free (el); | 203 | GNUNET_free(el); |
206 | return NULL; | 204 | return NULL; |
207 | } | 205 | } |
208 | el->name = GNUNET_strdup (name); | 206 | el->name = GNUNET_strdup(name); |
209 | nlen = strlen (name) + 1; | 207 | nlen = strlen(name) + 1; |
210 | env = GNUNET_MQ_msg_extra (req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP); | 208 | env = GNUNET_MQ_msg_extra(req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP); |
211 | memcpy (&req[1], name, nlen); | 209 | memcpy(&req[1], name, nlen); |
212 | GNUNET_MQ_send (el->mq, env); | 210 | GNUNET_MQ_send(el->mq, env); |
213 | return el; | 211 | return el; |
214 | } | 212 | } |
215 | 213 | ||
@@ -220,11 +218,11 @@ GNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
220 | * @param el handle for lookup to abort | 218 | * @param el handle for lookup to abort |
221 | */ | 219 | */ |
222 | void | 220 | void |
223 | GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el) | 221 | GNUNET_IDENTITY_ego_lookup_cancel(struct GNUNET_IDENTITY_EgoLookup *el) |
224 | { | 222 | { |
225 | GNUNET_MQ_destroy (el->mq); | 223 | GNUNET_MQ_destroy(el->mq); |
226 | GNUNET_free (el->name); | 224 | GNUNET_free(el->name); |
227 | GNUNET_free (el); | 225 | GNUNET_free(el); |
228 | } | 226 | } |
229 | 227 | ||
230 | 228 | ||
diff --git a/src/identity/identity_api_suffix_lookup.c b/src/identity/identity_api_suffix_lookup.c index 685030e40..51d8f39a6 100644 --- a/src/identity/identity_api_suffix_lookup.c +++ b/src/identity/identity_api_suffix_lookup.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 identity/identity_api_suffix_lookup.c | 22 | * @file identity/identity_api_suffix_lookup.c |
@@ -28,15 +28,13 @@ | |||
28 | #include "gnunet_identity_service.h" | 28 | #include "gnunet_identity_service.h" |
29 | #include "identity.h" | 29 | #include "identity.h" |
30 | 30 | ||
31 | #define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "identity-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Handle for ego lookup. | 35 | * Handle for ego lookup. |
36 | */ | 36 | */ |
37 | struct GNUNET_IDENTITY_EgoSuffixLookup | 37 | struct GNUNET_IDENTITY_EgoSuffixLookup { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Connection to service. | 39 | * Connection to service. |
42 | */ | 40 | */ |
@@ -68,11 +66,11 @@ struct GNUNET_IDENTITY_EgoSuffixLookup | |||
68 | * @return #GNUNET_OK if the message is well-formed | 66 | * @return #GNUNET_OK if the message is well-formed |
69 | */ | 67 | */ |
70 | static int | 68 | static int |
71 | check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 69 | check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) |
72 | { | 70 | { |
73 | (void) cls; | 71 | (void)cls; |
74 | if (sizeof (*rcm) != htons (rcm->header.size)) | 72 | if (sizeof(*rcm) != htons(rcm->header.size)) |
75 | GNUNET_MQ_check_zero_termination (rcm); | 73 | GNUNET_MQ_check_zero_termination(rcm); |
76 | return GNUNET_OK; | 74 | return GNUNET_OK; |
77 | } | 75 | } |
78 | 76 | ||
@@ -84,13 +82,13 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
84 | * @param rcm result message received | 82 | * @param rcm result message received |
85 | */ | 83 | */ |
86 | static void | 84 | static void |
87 | handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 85 | handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) |
88 | { | 86 | { |
89 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; | 87 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; |
90 | 88 | ||
91 | (void) rcm; | 89 | (void)rcm; |
92 | el->cb (el->cb_cls, NULL, NULL); | 90 | el->cb(el->cb_cls, NULL, NULL); |
93 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); | 91 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); |
94 | } | 92 | } |
95 | 93 | ||
96 | 94 | ||
@@ -102,19 +100,19 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
102 | * @return #GNUNET_OK if the message is well-formed | 100 | * @return #GNUNET_OK if the message is well-formed |
103 | */ | 101 | */ |
104 | static int | 102 | static int |
105 | check_identity_update (void *cls, const struct UpdateMessage *um) | 103 | check_identity_update(void *cls, const struct UpdateMessage *um) |
106 | { | 104 | { |
107 | uint16_t size = ntohs (um->header.size); | 105 | uint16_t size = ntohs(um->header.size); |
108 | uint16_t name_len = ntohs (um->name_len); | 106 | uint16_t name_len = ntohs(um->name_len); |
109 | const char *str = (const char *) &um[1]; | 107 | const char *str = (const char *)&um[1]; |
110 | 108 | ||
111 | (void) cls; | 109 | (void)cls; |
112 | if ((size != name_len + sizeof (struct UpdateMessage)) || | 110 | if ((size != name_len + sizeof(struct UpdateMessage)) || |
113 | ((0 != name_len) && ('\0' != str[name_len - 1]))) | 111 | ((0 != name_len) && ('\0' != str[name_len - 1]))) |
114 | { | 112 | { |
115 | GNUNET_break (0); | 113 | GNUNET_break(0); |
116 | return GNUNET_SYSERR; | 114 | return GNUNET_SYSERR; |
117 | } | 115 | } |
118 | return GNUNET_OK; | 116 | return GNUNET_OK; |
119 | } | 117 | } |
120 | 118 | ||
@@ -126,14 +124,14 @@ check_identity_update (void *cls, const struct UpdateMessage *um) | |||
126 | * @param um message received | 124 | * @param um message received |
127 | */ | 125 | */ |
128 | static void | 126 | static void |
129 | handle_identity_update (void *cls, const struct UpdateMessage *um) | 127 | handle_identity_update(void *cls, const struct UpdateMessage *um) |
130 | { | 128 | { |
131 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; | 129 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; |
132 | uint16_t name_len = ntohs (um->name_len); | 130 | uint16_t name_len = ntohs(um->name_len); |
133 | const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; | 131 | const char *str = (0 == name_len) ? NULL : (const char *)&um[1]; |
134 | 132 | ||
135 | el->cb (el->cb_cls, &um->private_key, str); | 133 | el->cb(el->cb_cls, &um->private_key, str); |
136 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); | 134 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); |
137 | } | 135 | } |
138 | 136 | ||
139 | 137 | ||
@@ -146,13 +144,13 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
146 | * @param error error code | 144 | * @param error error code |
147 | */ | 145 | */ |
148 | static void | 146 | static void |
149 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 147 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
150 | { | 148 | { |
151 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; | 149 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; |
152 | 150 | ||
153 | (void) error; | 151 | (void)error; |
154 | el->cb (el->cb_cls, NULL, NULL); | 152 | el->cb(el->cb_cls, NULL, NULL); |
155 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); | 153 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); |
156 | } | 154 | } |
157 | 155 | ||
158 | 156 | ||
@@ -166,46 +164,46 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
166 | * @return NULL on error | 164 | * @return NULL on error |
167 | */ | 165 | */ |
168 | struct GNUNET_IDENTITY_EgoSuffixLookup * | 166 | struct GNUNET_IDENTITY_EgoSuffixLookup * |
169 | GNUNET_IDENTITY_ego_lookup_by_suffix (const struct GNUNET_CONFIGURATION_Handle *cfg, | 167 | GNUNET_IDENTITY_ego_lookup_by_suffix(const struct GNUNET_CONFIGURATION_Handle *cfg, |
170 | const char *suffix, | 168 | const char *suffix, |
171 | GNUNET_IDENTITY_EgoSuffixCallback cb, | 169 | GNUNET_IDENTITY_EgoSuffixCallback cb, |
172 | void *cb_cls) | 170 | void *cb_cls) |
173 | { | 171 | { |
174 | struct GNUNET_IDENTITY_EgoSuffixLookup *el; | 172 | struct GNUNET_IDENTITY_EgoSuffixLookup *el; |
175 | struct GNUNET_MQ_Envelope *env; | 173 | struct GNUNET_MQ_Envelope *env; |
176 | struct GNUNET_MessageHeader *req; | 174 | struct GNUNET_MessageHeader *req; |
177 | size_t nlen; | 175 | size_t nlen; |
178 | 176 | ||
179 | GNUNET_assert (NULL != cb); | 177 | GNUNET_assert(NULL != cb); |
180 | el = GNUNET_new (struct GNUNET_IDENTITY_EgoSuffixLookup); | 178 | el = GNUNET_new(struct GNUNET_IDENTITY_EgoSuffixLookup); |
181 | el->cb = cb; | 179 | el->cb = cb; |
182 | el->cb_cls = cb_cls; | 180 | el->cb_cls = cb_cls; |
183 | { | 181 | { |
184 | struct GNUNET_MQ_MessageHandler handlers[] = | 182 | struct GNUNET_MQ_MessageHandler handlers[] = |
185 | {GNUNET_MQ_hd_var_size (identity_result_code, | 183 | { GNUNET_MQ_hd_var_size(identity_result_code, |
186 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, | 184 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, |
187 | struct ResultCodeMessage, | 185 | struct ResultCodeMessage, |
188 | el), | 186 | el), |
189 | GNUNET_MQ_hd_var_size (identity_update, | 187 | GNUNET_MQ_hd_var_size(identity_update, |
190 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, | 188 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, |
191 | struct UpdateMessage, | 189 | struct UpdateMessage, |
192 | el), | 190 | el), |
193 | GNUNET_MQ_handler_end ()}; | 191 | GNUNET_MQ_handler_end() }; |
194 | 192 | ||
195 | el->mq = | 193 | el->mq = |
196 | GNUNET_CLIENT_connect (cfg, "identity", handlers, &mq_error_handler, el); | 194 | GNUNET_CLIENT_connect(cfg, "identity", handlers, &mq_error_handler, el); |
197 | } | 195 | } |
198 | if (NULL == el->mq) | 196 | if (NULL == el->mq) |
199 | { | 197 | { |
200 | GNUNET_break (0); | 198 | GNUNET_break(0); |
201 | GNUNET_free (el); | 199 | GNUNET_free(el); |
202 | return NULL; | 200 | return NULL; |
203 | } | 201 | } |
204 | el->suffix = GNUNET_strdup (suffix); | 202 | el->suffix = GNUNET_strdup(suffix); |
205 | nlen = strlen (suffix) + 1; | 203 | nlen = strlen(suffix) + 1; |
206 | env = GNUNET_MQ_msg_extra (req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX); | 204 | env = GNUNET_MQ_msg_extra(req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX); |
207 | memcpy (&req[1], suffix, nlen); | 205 | memcpy(&req[1], suffix, nlen); |
208 | GNUNET_MQ_send (el->mq, env); | 206 | GNUNET_MQ_send(el->mq, env); |
209 | return el; | 207 | return el; |
210 | } | 208 | } |
211 | 209 | ||
@@ -216,11 +214,11 @@ GNUNET_IDENTITY_ego_lookup_by_suffix (const struct GNUNET_CONFIGURATION_Handle * | |||
216 | * @param el handle for lookup to abort | 214 | * @param el handle for lookup to abort |
217 | */ | 215 | */ |
218 | void | 216 | void |
219 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (struct GNUNET_IDENTITY_EgoSuffixLookup *el) | 217 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(struct GNUNET_IDENTITY_EgoSuffixLookup *el) |
220 | { | 218 | { |
221 | GNUNET_MQ_destroy (el->mq); | 219 | GNUNET_MQ_destroy(el->mq); |
222 | GNUNET_free (el->suffix); | 220 | GNUNET_free(el->suffix); |
223 | GNUNET_free (el); | 221 | GNUNET_free(el); |
224 | } | 222 | } |
225 | 223 | ||
226 | 224 | ||
diff --git a/src/identity/plugin_rest_identity.c b/src/identity/plugin_rest_identity.c index ac1965a75..1f6ec94ee 100644 --- a/src/identity/plugin_rest_identity.c +++ b/src/identity/plugin_rest_identity.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012-2015 GNUnet e.V. | 3 | Copyright (C) 2012-2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -129,16 +129,14 @@ static char *allow_methods; | |||
129 | /** | 129 | /** |
130 | * @brief struct returned by the initialization function of the plugin | 130 | * @brief struct returned by the initialization function of the plugin |
131 | */ | 131 | */ |
132 | struct Plugin | 132 | struct Plugin { |
133 | { | ||
134 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 133 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
135 | }; | 134 | }; |
136 | 135 | ||
137 | /** | 136 | /** |
138 | * The ego list | 137 | * The ego list |
139 | */ | 138 | */ |
140 | struct EgoEntry | 139 | struct EgoEntry { |
141 | { | ||
142 | /** | 140 | /** |
143 | * DLL | 141 | * DLL |
144 | */ | 142 | */ |
@@ -168,8 +166,7 @@ struct EgoEntry | |||
168 | /** | 166 | /** |
169 | * The request handle | 167 | * The request handle |
170 | */ | 168 | */ |
171 | struct RequestHandle | 169 | struct RequestHandle { |
172 | { | ||
173 | /** | 170 | /** |
174 | * The data from the REST request | 171 | * The data from the REST request |
175 | */ | 172 | */ |
@@ -257,38 +254,38 @@ struct RequestHandle | |||
257 | * @param handle Handle to clean up | 254 | * @param handle Handle to clean up |
258 | */ | 255 | */ |
259 | static void | 256 | static void |
260 | cleanup_handle (void *cls) | 257 | cleanup_handle(void *cls) |
261 | { | 258 | { |
262 | struct RequestHandle *handle = cls; | 259 | struct RequestHandle *handle = cls; |
263 | struct EgoEntry *ego_entry; | 260 | struct EgoEntry *ego_entry; |
264 | struct EgoEntry *ego_tmp; | 261 | struct EgoEntry *ego_tmp; |
265 | 262 | ||
266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); | 263 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); |
267 | if (NULL != handle->timeout_task) | 264 | if (NULL != handle->timeout_task) |
268 | { | 265 | { |
269 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | 266 | GNUNET_SCHEDULER_cancel(handle->timeout_task); |
270 | handle->timeout_task = NULL; | 267 | handle->timeout_task = NULL; |
271 | } | 268 | } |
272 | 269 | ||
273 | if (NULL != handle->url) | 270 | if (NULL != handle->url) |
274 | GNUNET_free (handle->url); | 271 | GNUNET_free(handle->url); |
275 | if (NULL != handle->emsg) | 272 | if (NULL != handle->emsg) |
276 | GNUNET_free (handle->emsg); | 273 | GNUNET_free(handle->emsg); |
277 | if (NULL != handle->name) | 274 | if (NULL != handle->name) |
278 | GNUNET_free (handle->name); | 275 | GNUNET_free(handle->name); |
279 | if (NULL != handle->identity_handle) | 276 | if (NULL != handle->identity_handle) |
280 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | 277 | GNUNET_IDENTITY_disconnect(handle->identity_handle); |
281 | 278 | ||
282 | for (ego_entry = handle->ego_head; NULL != ego_entry;) | 279 | for (ego_entry = handle->ego_head; NULL != ego_entry;) |
283 | { | 280 | { |
284 | ego_tmp = ego_entry; | 281 | ego_tmp = ego_entry; |
285 | ego_entry = ego_entry->next; | 282 | ego_entry = ego_entry->next; |
286 | GNUNET_free (ego_tmp->identifier); | 283 | GNUNET_free(ego_tmp->identifier); |
287 | GNUNET_free (ego_tmp->keystring); | 284 | GNUNET_free(ego_tmp->keystring); |
288 | GNUNET_free (ego_tmp); | 285 | GNUNET_free(ego_tmp); |
289 | } | 286 | } |
290 | 287 | ||
291 | GNUNET_free (handle); | 288 | GNUNET_free(handle); |
292 | } | 289 | } |
293 | 290 | ||
294 | /** | 291 | /** |
@@ -297,26 +294,26 @@ cleanup_handle (void *cls) | |||
297 | * @param cls the `struct RequestHandle` | 294 | * @param cls the `struct RequestHandle` |
298 | */ | 295 | */ |
299 | static void | 296 | static void |
300 | do_error (void *cls) | 297 | do_error(void *cls) |
301 | { | 298 | { |
302 | struct RequestHandle *handle = cls; | 299 | struct RequestHandle *handle = cls; |
303 | struct MHD_Response *resp; | 300 | struct MHD_Response *resp; |
304 | json_t *json_error = json_object (); | 301 | json_t *json_error = json_object(); |
305 | char *response; | 302 | char *response; |
306 | 303 | ||
307 | if (NULL == handle->emsg) | 304 | if (NULL == handle->emsg) |
308 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_ERROR_UNKNOWN); | 305 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_ERROR_UNKNOWN); |
309 | 306 | ||
310 | json_object_set_new (json_error, "error", json_string (handle->emsg)); | 307 | json_object_set_new(json_error, "error", json_string(handle->emsg)); |
311 | 308 | ||
312 | if (0 == handle->response_code) | 309 | if (0 == handle->response_code) |
313 | handle->response_code = MHD_HTTP_OK; | 310 | handle->response_code = MHD_HTTP_OK; |
314 | response = json_dumps (json_error, 0); | 311 | response = json_dumps(json_error, 0); |
315 | resp = GNUNET_REST_create_response (response); | 312 | resp = GNUNET_REST_create_response(response); |
316 | handle->proc (handle->proc_cls, resp, handle->response_code); | 313 | handle->proc(handle->proc_cls, resp, handle->response_code); |
317 | json_decref (json_error); | 314 | json_decref(json_error); |
318 | GNUNET_free (response); | 315 | GNUNET_free(response); |
319 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 316 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
320 | } | 317 | } |
321 | 318 | ||
322 | 319 | ||
@@ -330,29 +327,30 @@ do_error (void *cls) | |||
330 | * @return EgoEntry or NULL if not found | 327 | * @return EgoEntry or NULL if not found |
331 | */ | 328 | */ |
332 | struct EgoEntry * | 329 | struct EgoEntry * |
333 | get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) | 330 | get_egoentry(struct RequestHandle *handle, char *pubkey, char *name) |
334 | { | 331 | { |
335 | struct EgoEntry *ego_entry; | 332 | struct EgoEntry *ego_entry; |
333 | |||
336 | if (NULL != pubkey) | 334 | if (NULL != pubkey) |
337 | { | ||
338 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
339 | ego_entry = ego_entry->next) | ||
340 | { | 335 | { |
341 | if (0 != strcasecmp (pubkey, ego_entry->keystring)) | 336 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
342 | continue; | 337 | ego_entry = ego_entry->next) |
343 | return ego_entry; | 338 | { |
339 | if (0 != strcasecmp(pubkey, ego_entry->keystring)) | ||
340 | continue; | ||
341 | return ego_entry; | ||
342 | } | ||
344 | } | 343 | } |
345 | } | ||
346 | if (NULL != name) | 344 | if (NULL != name) |
347 | { | ||
348 | for (ego_entry = handle->ego_head; NULL != ego_entry; | ||
349 | ego_entry = ego_entry->next) | ||
350 | { | 345 | { |
351 | if (0 != strcasecmp (name, ego_entry->identifier)) | 346 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
352 | continue; | 347 | ego_entry = ego_entry->next) |
353 | return ego_entry; | 348 | { |
349 | if (0 != strcasecmp(name, ego_entry->identifier)) | ||
350 | continue; | ||
351 | return ego_entry; | ||
352 | } | ||
354 | } | 353 | } |
355 | } | ||
356 | return NULL; | 354 | return NULL; |
357 | } | 355 | } |
358 | 356 | ||
@@ -366,10 +364,10 @@ get_egoentry (struct RequestHandle *handle, char *pubkey, char *name) | |||
366 | * @param name the id of the ego | 364 | * @param name the id of the ego |
367 | */ | 365 | */ |
368 | static void | 366 | static void |
369 | ego_get_for_subsystem (void *cls, | 367 | ego_get_for_subsystem(void *cls, |
370 | struct GNUNET_IDENTITY_Ego *ego, | 368 | struct GNUNET_IDENTITY_Ego *ego, |
371 | void **ctx, | 369 | void **ctx, |
372 | const char *name) | 370 | const char *name) |
373 | { | 371 | { |
374 | struct RequestHandle *handle = cls; | 372 | struct RequestHandle *handle = cls; |
375 | struct MHD_Response *resp; | 373 | struct MHD_Response *resp; |
@@ -379,34 +377,34 @@ ego_get_for_subsystem (void *cls, | |||
379 | char *public_key_string; | 377 | char *public_key_string; |
380 | 378 | ||
381 | if (NULL == ego) | 379 | if (NULL == ego) |
382 | { | 380 | { |
383 | handle->response_code = MHD_HTTP_NOT_FOUND; | 381 | handle->response_code = MHD_HTTP_NOT_FOUND; |
384 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | 382 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
385 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 383 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
386 | return; | 384 | return; |
387 | } | 385 | } |
388 | 386 | ||
389 | GNUNET_IDENTITY_ego_get_public_key (ego, &public_key); | 387 | GNUNET_IDENTITY_ego_get_public_key(ego, &public_key); |
390 | public_key_string = GNUNET_CRYPTO_ecdsa_public_key_to_string (&public_key); | 388 | public_key_string = GNUNET_CRYPTO_ecdsa_public_key_to_string(&public_key); |
391 | 389 | ||
392 | // create json with subsystem identity | 390 | // create json with subsystem identity |
393 | json_root = json_object (); | 391 | json_root = json_object(); |
394 | json_object_set_new (json_root, | 392 | json_object_set_new(json_root, |
395 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, | 393 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, |
396 | json_string (public_key_string)); | 394 | json_string(public_key_string)); |
397 | json_object_set_new (json_root, | 395 | json_object_set_new(json_root, |
398 | GNUNET_REST_IDENTITY_PARAM_NAME, | 396 | GNUNET_REST_IDENTITY_PARAM_NAME, |
399 | json_string (name)); | 397 | json_string(name)); |
400 | 398 | ||
401 | result_str = json_dumps (json_root, 0); | 399 | result_str = json_dumps(json_root, 0); |
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 400 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
403 | resp = GNUNET_REST_create_response (result_str); | 401 | resp = GNUNET_REST_create_response(result_str); |
404 | 402 | ||
405 | json_decref (json_root); | 403 | json_decref(json_root); |
406 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 404 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
407 | GNUNET_free (result_str); | 405 | GNUNET_free(result_str); |
408 | GNUNET_free (public_key_string); | 406 | GNUNET_free(public_key_string); |
409 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 407 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
410 | } | 408 | } |
411 | 409 | ||
412 | /** | 410 | /** |
@@ -417,35 +415,35 @@ ego_get_for_subsystem (void *cls, | |||
417 | * @param cls the RequestHandle | 415 | * @param cls the RequestHandle |
418 | */ | 416 | */ |
419 | void | 417 | void |
420 | ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | 418 | ego_get_subsystem(struct GNUNET_REST_RequestHandle *con_handle, |
421 | const char *url, | 419 | const char *url, |
422 | void *cls) | 420 | void *cls) |
423 | { | 421 | { |
424 | struct RequestHandle *handle = cls; | 422 | struct RequestHandle *handle = cls; |
425 | char *subsystem; | 423 | char *subsystem; |
426 | 424 | ||
427 | if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) | 425 | if (strlen(GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen(handle->url)) |
428 | { | 426 | { |
429 | handle->emsg = GNUNET_strdup ("Missing subsystem name"); | 427 | handle->emsg = GNUNET_strdup("Missing subsystem name"); |
430 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 428 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
431 | return; | 429 | return; |
432 | } | 430 | } |
433 | subsystem = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; | 431 | subsystem = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; |
434 | //requested default identity of subsystem | 432 | //requested default identity of subsystem |
435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); | 433 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Looking for %s's ego\n", subsystem); |
436 | 434 | ||
437 | handle->op = GNUNET_IDENTITY_get (handle->identity_handle, | 435 | handle->op = GNUNET_IDENTITY_get(handle->identity_handle, |
438 | subsystem, | 436 | subsystem, |
439 | &ego_get_for_subsystem, | 437 | &ego_get_for_subsystem, |
440 | handle); | 438 | handle); |
441 | 439 | ||
442 | if (NULL == handle->op) | 440 | if (NULL == handle->op) |
443 | { | 441 | { |
444 | handle->response_code = MHD_HTTP_NOT_FOUND; | 442 | handle->response_code = MHD_HTTP_NOT_FOUND; |
445 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | 443 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
446 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 444 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
447 | return; | 445 | return; |
448 | } | 446 | } |
449 | } | 447 | } |
450 | 448 | ||
451 | 449 | ||
@@ -457,9 +455,9 @@ ego_get_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | |||
457 | * @param cls the RequestHandle | 455 | * @param cls the RequestHandle |
458 | */ | 456 | */ |
459 | void | 457 | void |
460 | ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | 458 | ego_get_all(struct GNUNET_REST_RequestHandle *con_handle, |
461 | const char *url, | 459 | const char *url, |
462 | void *cls) | 460 | void *cls) |
463 | { | 461 | { |
464 | struct RequestHandle *handle = cls; | 462 | struct RequestHandle *handle = cls; |
465 | struct EgoEntry *ego_entry; | 463 | struct EgoEntry *ego_entry; |
@@ -468,30 +466,30 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
468 | json_t *json_ego; | 466 | json_t *json_ego; |
469 | char *result_str; | 467 | char *result_str; |
470 | 468 | ||
471 | json_root = json_array (); | 469 | json_root = json_array(); |
472 | //Return ego/egos | 470 | //Return ego/egos |
473 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 471 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
474 | ego_entry = ego_entry->next) | 472 | ego_entry = ego_entry->next) |
475 | { | 473 | { |
476 | json_ego = json_object (); | 474 | json_ego = json_object(); |
477 | json_object_set_new (json_ego, | 475 | json_object_set_new(json_ego, |
478 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, | 476 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, |
479 | json_string (ego_entry->keystring)); | 477 | json_string(ego_entry->keystring)); |
480 | json_object_set_new (json_ego, | 478 | json_object_set_new(json_ego, |
481 | GNUNET_REST_IDENTITY_PARAM_NAME, | 479 | GNUNET_REST_IDENTITY_PARAM_NAME, |
482 | json_string (ego_entry->identifier)); | 480 | json_string(ego_entry->identifier)); |
483 | json_array_append (json_root, json_ego); | 481 | json_array_append(json_root, json_ego); |
484 | json_decref (json_ego); | 482 | json_decref(json_ego); |
485 | } | 483 | } |
486 | 484 | ||
487 | result_str = json_dumps (json_root, 0); | 485 | result_str = json_dumps(json_root, 0); |
488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 486 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
489 | resp = GNUNET_REST_create_response (result_str); | 487 | resp = GNUNET_REST_create_response(result_str); |
490 | 488 | ||
491 | json_decref (json_root); | 489 | json_decref(json_root); |
492 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 490 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
493 | GNUNET_free (result_str); | 491 | GNUNET_free(result_str); |
494 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 492 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
495 | } | 493 | } |
496 | 494 | ||
497 | 495 | ||
@@ -502,28 +500,28 @@ ego_get_all (struct GNUNET_REST_RequestHandle *con_handle, | |||
502 | * @param ego_entry the struct EgoEntry for the response | 500 | * @param ego_entry the struct EgoEntry for the response |
503 | */ | 501 | */ |
504 | void | 502 | void |
505 | ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) | 503 | ego_get_response(struct RequestHandle *handle, struct EgoEntry *ego_entry) |
506 | { | 504 | { |
507 | struct MHD_Response *resp; | 505 | struct MHD_Response *resp; |
508 | json_t *json_ego; | 506 | json_t *json_ego; |
509 | char *result_str; | 507 | char *result_str; |
510 | 508 | ||
511 | json_ego = json_object (); | 509 | json_ego = json_object(); |
512 | json_object_set_new (json_ego, | 510 | json_object_set_new(json_ego, |
513 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, | 511 | GNUNET_REST_IDENTITY_PARAM_PUBKEY, |
514 | json_string (ego_entry->keystring)); | 512 | json_string(ego_entry->keystring)); |
515 | json_object_set_new (json_ego, | 513 | json_object_set_new(json_ego, |
516 | GNUNET_REST_IDENTITY_PARAM_NAME, | 514 | GNUNET_REST_IDENTITY_PARAM_NAME, |
517 | json_string (ego_entry->identifier)); | 515 | json_string(ego_entry->identifier)); |
518 | 516 | ||
519 | result_str = json_dumps (json_ego, 0); | 517 | result_str = json_dumps(json_ego, 0); |
520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | 518 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); |
521 | resp = GNUNET_REST_create_response (result_str); | 519 | resp = GNUNET_REST_create_response(result_str); |
522 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 520 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
523 | 521 | ||
524 | json_decref (json_ego); | 522 | json_decref(json_ego); |
525 | GNUNET_free (result_str); | 523 | GNUNET_free(result_str); |
526 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 524 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
527 | } | 525 | } |
528 | 526 | ||
529 | 527 | ||
@@ -535,9 +533,9 @@ ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
535 | * @param cls the RequestHandle | 533 | * @param cls the RequestHandle |
536 | */ | 534 | */ |
537 | void | 535 | void |
538 | ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | 536 | ego_get_pubkey(struct GNUNET_REST_RequestHandle *con_handle, |
539 | const char *url, | 537 | const char *url, |
540 | void *cls) | 538 | void *cls) |
541 | { | 539 | { |
542 | struct RequestHandle *handle = cls; | 540 | struct RequestHandle *handle = cls; |
543 | struct EgoEntry *ego_entry; | 541 | struct EgoEntry *ego_entry; |
@@ -545,25 +543,25 @@ ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
545 | 543 | ||
546 | keystring = NULL; | 544 | keystring = NULL; |
547 | 545 | ||
548 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | 546 | if (strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen(handle->url)) |
549 | { | 547 | { |
550 | handle->response_code = MHD_HTTP_NOT_FOUND; | 548 | handle->response_code = MHD_HTTP_NOT_FOUND; |
551 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_PUBKEY); | 549 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); |
552 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 550 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
553 | return; | 551 | return; |
554 | } | 552 | } |
555 | keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; | 553 | keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; |
556 | ego_entry = get_egoentry (handle, keystring, NULL); | 554 | ego_entry = get_egoentry(handle, keystring, NULL); |
557 | 555 | ||
558 | if (NULL == ego_entry) | 556 | if (NULL == ego_entry) |
559 | { | 557 | { |
560 | handle->response_code = MHD_HTTP_NOT_FOUND; | 558 | handle->response_code = MHD_HTTP_NOT_FOUND; |
561 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | 559 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
562 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 560 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
563 | return; | 561 | return; |
564 | } | 562 | } |
565 | 563 | ||
566 | ego_get_response (handle, ego_entry); | 564 | ego_get_response(handle, ego_entry); |
567 | } | 565 | } |
568 | 566 | ||
569 | /** | 567 | /** |
@@ -574,9 +572,9 @@ ego_get_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
574 | * @param cls the RequestHandle | 572 | * @param cls the RequestHandle |
575 | */ | 573 | */ |
576 | void | 574 | void |
577 | ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, | 575 | ego_get_name(struct GNUNET_REST_RequestHandle *con_handle, |
578 | const char *url, | 576 | const char *url, |
579 | void *cls) | 577 | void *cls) |
580 | { | 578 | { |
581 | struct RequestHandle *handle = cls; | 579 | struct RequestHandle *handle = cls; |
582 | struct EgoEntry *ego_entry; | 580 | struct EgoEntry *ego_entry; |
@@ -584,25 +582,25 @@ ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
584 | 582 | ||
585 | egoname = NULL; | 583 | egoname = NULL; |
586 | 584 | ||
587 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | 585 | if (strlen(GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen(handle->url)) |
588 | { | 586 | { |
589 | handle->response_code = MHD_HTTP_NOT_FOUND; | 587 | handle->response_code = MHD_HTTP_NOT_FOUND; |
590 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); | 588 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); |
591 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 589 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
592 | return; | 590 | return; |
593 | } | 591 | } |
594 | egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; | 592 | egoname = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; |
595 | ego_entry = get_egoentry (handle, NULL, egoname); | 593 | ego_entry = get_egoentry(handle, NULL, egoname); |
596 | 594 | ||
597 | if (NULL == ego_entry) | 595 | if (NULL == ego_entry) |
598 | { | 596 | { |
599 | handle->response_code = MHD_HTTP_NOT_FOUND; | 597 | handle->response_code = MHD_HTTP_NOT_FOUND; |
600 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | 598 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
601 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 599 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
602 | return; | 600 | return; |
603 | } | 601 | } |
604 | 602 | ||
605 | ego_get_response (handle, ego_entry); | 603 | ego_get_response(handle, ego_entry); |
606 | } | 604 | } |
607 | 605 | ||
608 | 606 | ||
@@ -613,25 +611,25 @@ ego_get_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
613 | * @param emsg error message | 611 | * @param emsg error message |
614 | */ | 612 | */ |
615 | static void | 613 | static void |
616 | do_finished (void *cls, const char *emsg) | 614 | do_finished(void *cls, const char *emsg) |
617 | { | 615 | { |
618 | struct RequestHandle *handle = cls; | 616 | struct RequestHandle *handle = cls; |
619 | struct MHD_Response *resp; | 617 | struct MHD_Response *resp; |
620 | 618 | ||
621 | handle->op = NULL; | 619 | handle->op = NULL; |
622 | if (NULL != emsg) | 620 | if (NULL != emsg) |
623 | { | 621 | { |
624 | handle->emsg = GNUNET_strdup (emsg); | 622 | handle->emsg = GNUNET_strdup(emsg); |
625 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 623 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
626 | return; | 624 | return; |
627 | } | 625 | } |
628 | if (0 == handle->response_code) | 626 | if (0 == handle->response_code) |
629 | { | 627 | { |
630 | handle->response_code = MHD_HTTP_NO_CONTENT; | 628 | handle->response_code = MHD_HTTP_NO_CONTENT; |
631 | } | 629 | } |
632 | resp = GNUNET_REST_create_response (NULL); | 630 | resp = GNUNET_REST_create_response(NULL); |
633 | handle->proc (handle->proc_cls, resp, handle->response_code); | 631 | handle->proc(handle->proc_cls, resp, handle->response_code); |
634 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 632 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
635 | } | 633 | } |
636 | 634 | ||
637 | 635 | ||
@@ -643,14 +641,14 @@ do_finished (void *cls, const char *emsg) | |||
643 | * @param emsg error message | 641 | * @param emsg error message |
644 | */ | 642 | */ |
645 | static void | 643 | static void |
646 | do_finished_create (void *cls, | 644 | do_finished_create(void *cls, |
647 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 645 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
648 | const char *emsg) | 646 | const char *emsg) |
649 | { | 647 | { |
650 | struct RequestHandle *handle = cls; | 648 | struct RequestHandle *handle = cls; |
651 | 649 | ||
652 | (void) pk; | 650 | (void)pk; |
653 | do_finished (handle, emsg); | 651 | do_finished(handle, emsg); |
654 | } | 652 | } |
655 | 653 | ||
656 | 654 | ||
@@ -661,7 +659,7 @@ do_finished_create (void *cls, | |||
661 | * @param ego_entry the struct EgoEntry we want to edit | 659 | * @param ego_entry the struct EgoEntry we want to edit |
662 | */ | 660 | */ |
663 | void | 661 | void |
664 | ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | 662 | ego_edit(struct RequestHandle *handle, struct EgoEntry *ego_entry) |
665 | { | 663 | { |
666 | struct EgoEntry *ego_entry_tmp; | 664 | struct EgoEntry *ego_entry_tmp; |
667 | struct MHD_Response *resp; | 665 | struct MHD_Response *resp; |
@@ -673,79 +671,78 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
673 | 671 | ||
674 | //if no data | 672 | //if no data |
675 | if (0 >= handle->data_size) | 673 | if (0 >= handle->data_size) |
676 | { | 674 | { |
677 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 675 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); |
678 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 676 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
679 | return; | 677 | return; |
680 | } | 678 | } |
681 | //if not json | 679 | //if not json |
682 | term_data[handle->data_size] = '\0'; | 680 | term_data[handle->data_size] = '\0'; |
683 | GNUNET_memcpy (term_data, handle->data, handle->data_size); | 681 | GNUNET_memcpy(term_data, handle->data, handle->data_size); |
684 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); | 682 | data_js = json_loads(term_data, JSON_DECODE_ANY, &err); |
685 | 683 | ||
686 | if (NULL == data_js) | 684 | if (NULL == data_js) |
687 | { | 685 | { |
688 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 686 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); |
689 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 687 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
690 | return; | 688 | return; |
691 | } | 689 | } |
692 | 690 | ||
693 | newname = NULL; | 691 | newname = NULL; |
694 | //NEW NAME | 692 | //NEW NAME |
695 | json_state = 0; | 693 | json_state = 0; |
696 | json_state = json_unpack (data_js, | 694 | json_state = json_unpack(data_js, |
697 | "{s:s!}", | 695 | "{s:s!}", |
698 | GNUNET_REST_IDENTITY_PARAM_NEWNAME, | 696 | GNUNET_REST_IDENTITY_PARAM_NEWNAME, |
699 | &newname); | 697 | &newname); |
700 | //Change name with pubkey or name identifier | 698 | //Change name with pubkey or name identifier |
701 | if (0 != json_state) | 699 | if (0 != json_state) |
702 | { | 700 | { |
703 | 701 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); | |
704 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 702 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
705 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 703 | json_decref(data_js); |
706 | json_decref (data_js); | 704 | return; |
707 | return; | 705 | } |
708 | } | ||
709 | 706 | ||
710 | if (NULL == newname) | 707 | if (NULL == newname) |
711 | { | 708 | { |
712 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 709 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
713 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 710 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
714 | json_decref (data_js); | 711 | json_decref(data_js); |
715 | return; | 712 | return; |
716 | } | 713 | } |
717 | 714 | ||
718 | if (0 >= strlen (newname)) | 715 | if (0 >= strlen(newname)) |
719 | { | 716 | { |
720 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 717 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
721 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 718 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
722 | json_decref (data_js); | 719 | json_decref(data_js); |
723 | return; | 720 | return; |
724 | } | 721 | } |
725 | 722 | ||
726 | ego_entry_tmp = get_egoentry (handle, NULL, newname); | 723 | ego_entry_tmp = get_egoentry(handle, NULL, newname); |
727 | if (NULL != ego_entry_tmp) | 724 | if (NULL != ego_entry_tmp) |
728 | { | 725 | { |
729 | //Ego with same name not allowed (even if its the ego we change) | 726 | //Ego with same name not allowed (even if its the ego we change) |
730 | resp = GNUNET_REST_create_response (NULL); | 727 | resp = GNUNET_REST_create_response(NULL); |
731 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | 728 | handle->proc(handle->proc_cls, resp, MHD_HTTP_CONFLICT); |
732 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 729 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
733 | json_decref (data_js); | 730 | json_decref(data_js); |
734 | return; | 731 | return; |
735 | } | 732 | } |
736 | handle->op = GNUNET_IDENTITY_rename (handle->identity_handle, | 733 | handle->op = GNUNET_IDENTITY_rename(handle->identity_handle, |
737 | ego_entry->identifier, | 734 | ego_entry->identifier, |
738 | newname, | 735 | newname, |
739 | &do_finished, | 736 | &do_finished, |
740 | handle); | 737 | handle); |
741 | if (NULL == handle->op) | 738 | if (NULL == handle->op) |
742 | { | 739 | { |
743 | handle->emsg = GNUNET_strdup ("Rename failed"); | 740 | handle->emsg = GNUNET_strdup("Rename failed"); |
744 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 741 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
745 | json_decref (data_js); | 742 | json_decref(data_js); |
746 | return; | 743 | return; |
747 | } | 744 | } |
748 | json_decref (data_js); | 745 | json_decref(data_js); |
749 | return; | 746 | return; |
750 | } | 747 | } |
751 | 748 | ||
@@ -758,9 +755,9 @@ ego_edit (struct RequestHandle *handle, struct EgoEntry *ego_entry) | |||
758 | * @param cls the RequestHandle | 755 | * @param cls the RequestHandle |
759 | */ | 756 | */ |
760 | void | 757 | void |
761 | ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | 758 | ego_edit_pubkey(struct GNUNET_REST_RequestHandle *con_handle, |
762 | const char *url, | 759 | const char *url, |
763 | void *cls) | 760 | void *cls) |
764 | { | 761 | { |
765 | struct RequestHandle *handle = cls; | 762 | struct RequestHandle *handle = cls; |
766 | struct EgoEntry *ego_entry; | 763 | struct EgoEntry *ego_entry; |
@@ -768,25 +765,25 @@ ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
768 | 765 | ||
769 | keystring = NULL; | 766 | keystring = NULL; |
770 | 767 | ||
771 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | 768 | if (strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen(handle->url)) |
772 | { | 769 | { |
773 | handle->response_code = MHD_HTTP_NOT_FOUND; | 770 | handle->response_code = MHD_HTTP_NOT_FOUND; |
774 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_PUBKEY); | 771 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); |
775 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 772 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
776 | return; | 773 | return; |
777 | } | 774 | } |
778 | keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; | 775 | keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; |
779 | ego_entry = get_egoentry (handle, keystring, NULL); | 776 | ego_entry = get_egoentry(handle, keystring, NULL); |
780 | 777 | ||
781 | if (NULL == ego_entry) | 778 | if (NULL == ego_entry) |
782 | { | 779 | { |
783 | handle->response_code = MHD_HTTP_NOT_FOUND; | 780 | handle->response_code = MHD_HTTP_NOT_FOUND; |
784 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | 781 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
785 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 782 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
786 | return; | 783 | return; |
787 | } | 784 | } |
788 | 785 | ||
789 | ego_edit (handle, ego_entry); | 786 | ego_edit(handle, ego_entry); |
790 | } | 787 | } |
791 | 788 | ||
792 | /** | 789 | /** |
@@ -797,9 +794,9 @@ ego_edit_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
797 | * @param cls the RequestHandle | 794 | * @param cls the RequestHandle |
798 | */ | 795 | */ |
799 | void | 796 | void |
800 | ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | 797 | ego_edit_name(struct GNUNET_REST_RequestHandle *con_handle, |
801 | const char *url, | 798 | const char *url, |
802 | void *cls) | 799 | void *cls) |
803 | { | 800 | { |
804 | struct RequestHandle *handle = cls; | 801 | struct RequestHandle *handle = cls; |
805 | struct EgoEntry *ego_entry; | 802 | struct EgoEntry *ego_entry; |
@@ -807,25 +804,25 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
807 | 804 | ||
808 | name = NULL; | 805 | name = NULL; |
809 | 806 | ||
810 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | 807 | if (strlen(GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen(handle->url)) |
811 | { | 808 | { |
812 | handle->response_code = MHD_HTTP_NOT_FOUND; | 809 | handle->response_code = MHD_HTTP_NOT_FOUND; |
813 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); | 810 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); |
814 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 811 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
815 | return; | 812 | return; |
816 | } | 813 | } |
817 | name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; | 814 | name = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; |
818 | ego_entry = get_egoentry (handle, NULL, name); | 815 | ego_entry = get_egoentry(handle, NULL, name); |
819 | 816 | ||
820 | if (NULL == ego_entry) | 817 | if (NULL == ego_entry) |
821 | { | 818 | { |
822 | handle->response_code = MHD_HTTP_NOT_FOUND; | 819 | handle->response_code = MHD_HTTP_NOT_FOUND; |
823 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | 820 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
824 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 821 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
825 | return; | 822 | return; |
826 | } | 823 | } |
827 | 824 | ||
828 | ego_edit (handle, ego_entry); | 825 | ego_edit(handle, ego_entry); |
829 | } | 826 | } |
830 | 827 | ||
831 | /** | 828 | /** |
@@ -836,9 +833,9 @@ ego_edit_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
836 | * @param cls the RequestHandle | 833 | * @param cls the RequestHandle |
837 | */ | 834 | */ |
838 | void | 835 | void |
839 | ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | 836 | ego_edit_subsystem(struct GNUNET_REST_RequestHandle *con_handle, |
840 | const char *url, | 837 | const char *url, |
841 | void *cls) | 838 | void *cls) |
842 | { | 839 | { |
843 | struct RequestHandle *handle = cls; | 840 | struct RequestHandle *handle = cls; |
844 | struct EgoEntry *ego_entry; | 841 | struct EgoEntry *ego_entry; |
@@ -851,88 +848,88 @@ ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | |||
851 | 848 | ||
852 | name = NULL; | 849 | name = NULL; |
853 | 850 | ||
854 | if (strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen (handle->url)) | 851 | if (strlen(GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) >= strlen(handle->url)) |
855 | { | 852 | { |
856 | handle->response_code = MHD_HTTP_NOT_FOUND; | 853 | handle->response_code = MHD_HTTP_NOT_FOUND; |
857 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); | 854 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); |
858 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 855 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
859 | return; | 856 | return; |
860 | } | 857 | } |
861 | name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; | 858 | name = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM) + 1]; |
862 | ego_entry = get_egoentry (handle, NULL, name); | 859 | ego_entry = get_egoentry(handle, NULL, name); |
863 | 860 | ||
864 | if (NULL == ego_entry) | 861 | if (NULL == ego_entry) |
865 | { | 862 | { |
866 | handle->response_code = MHD_HTTP_NOT_FOUND; | 863 | handle->response_code = MHD_HTTP_NOT_FOUND; |
867 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | 864 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
868 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 865 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
869 | return; | 866 | return; |
870 | } | 867 | } |
871 | 868 | ||
872 | //if no data | 869 | //if no data |
873 | if (0 >= handle->data_size) | 870 | if (0 >= handle->data_size) |
874 | { | 871 | { |
875 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 872 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); |
876 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 873 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
877 | return; | 874 | return; |
878 | } | 875 | } |
879 | //if not json | 876 | //if not json |
880 | term_data[handle->data_size] = '\0'; | 877 | term_data[handle->data_size] = '\0'; |
881 | GNUNET_memcpy (term_data, handle->data, handle->data_size); | 878 | GNUNET_memcpy(term_data, handle->data, handle->data_size); |
882 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); | 879 | data_js = json_loads(term_data, JSON_DECODE_ANY, &err); |
883 | 880 | ||
884 | if (NULL == data_js) | 881 | if (NULL == data_js) |
885 | { | 882 | { |
886 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 883 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); |
887 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 884 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
888 | return; | 885 | return; |
889 | } | 886 | } |
890 | 887 | ||
891 | newsubsys = NULL; | 888 | newsubsys = NULL; |
892 | //SUBSYSTEM | 889 | //SUBSYSTEM |
893 | json_state = 0; | 890 | json_state = 0; |
894 | json_state = json_unpack (data_js, | 891 | json_state = json_unpack(data_js, |
895 | "{s:s!}", | 892 | "{s:s!}", |
896 | GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM, | 893 | GNUNET_REST_IDENTITY_PARAM_SUBSYSTEM, |
897 | &newsubsys); | 894 | &newsubsys); |
898 | //Change subsystem with pubkey or name identifier | 895 | //Change subsystem with pubkey or name identifier |
899 | if (0 != json_state) | 896 | if (0 != json_state) |
900 | { | 897 | { |
901 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 898 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
902 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 899 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
903 | json_decref (data_js); | 900 | json_decref(data_js); |
904 | return; | 901 | return; |
905 | } | 902 | } |
906 | 903 | ||
907 | if (NULL == newsubsys) | 904 | if (NULL == newsubsys) |
908 | { | 905 | { |
909 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 906 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
910 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 907 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
911 | json_decref (data_js); | 908 | json_decref(data_js); |
912 | return; | 909 | return; |
913 | } | 910 | } |
914 | 911 | ||
915 | if (0 >= strlen (newsubsys)) | 912 | if (0 >= strlen(newsubsys)) |
916 | { | 913 | { |
917 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 914 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
918 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 915 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
919 | json_decref (data_js); | 916 | json_decref(data_js); |
920 | return; | 917 | return; |
921 | } | 918 | } |
922 | 919 | ||
923 | handle->response_code = MHD_HTTP_NO_CONTENT; | 920 | handle->response_code = MHD_HTTP_NO_CONTENT; |
924 | handle->op = GNUNET_IDENTITY_set (handle->identity_handle, | 921 | handle->op = GNUNET_IDENTITY_set(handle->identity_handle, |
925 | newsubsys, | 922 | newsubsys, |
926 | ego_entry->ego, | 923 | ego_entry->ego, |
927 | &do_finished, | 924 | &do_finished, |
928 | handle); | 925 | handle); |
929 | if (NULL == handle->op) | 926 | if (NULL == handle->op) |
930 | { | 927 | { |
931 | handle->emsg = GNUNET_strdup ("Setting subsystem failed"); | 928 | handle->emsg = GNUNET_strdup("Setting subsystem failed"); |
932 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 929 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
933 | return; | 930 | return; |
934 | } | 931 | } |
935 | json_decref (data_js); | 932 | json_decref(data_js); |
936 | return; | 933 | return; |
937 | } | 934 | } |
938 | 935 | ||
@@ -944,9 +941,9 @@ ego_edit_subsystem (struct GNUNET_REST_RequestHandle *con_handle, | |||
944 | * @param cls the RequestHandle | 941 | * @param cls the RequestHandle |
945 | */ | 942 | */ |
946 | void | 943 | void |
947 | ego_create (struct GNUNET_REST_RequestHandle *con_handle, | 944 | ego_create(struct GNUNET_REST_RequestHandle *con_handle, |
948 | const char *url, | 945 | const char *url, |
949 | void *cls) | 946 | void *cls) |
950 | { | 947 | { |
951 | struct RequestHandle *handle = cls; | 948 | struct RequestHandle *handle = cls; |
952 | struct EgoEntry *ego_entry; | 949 | struct EgoEntry *ego_entry; |
@@ -957,73 +954,73 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
957 | int json_unpack_state; | 954 | int json_unpack_state; |
958 | char term_data[handle->data_size + 1]; | 955 | char term_data[handle->data_size + 1]; |
959 | 956 | ||
960 | if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url)) | 957 | if (strlen(GNUNET_REST_API_NS_IDENTITY) != strlen(handle->url)) |
961 | { | 958 | { |
962 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 959 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
963 | return; | 960 | return; |
964 | } | 961 | } |
965 | 962 | ||
966 | if (0 >= handle->data_size) | 963 | if (0 >= handle->data_size) |
967 | { | 964 | { |
968 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 965 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); |
969 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 966 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
970 | return; | 967 | return; |
971 | } | 968 | } |
972 | term_data[handle->data_size] = '\0'; | 969 | term_data[handle->data_size] = '\0'; |
973 | GNUNET_memcpy (term_data, handle->data, handle->data_size); | 970 | GNUNET_memcpy(term_data, handle->data, handle->data_size); |
974 | data_js = json_loads (term_data, JSON_DECODE_ANY, &err); | 971 | data_js = json_loads(term_data, JSON_DECODE_ANY, &err); |
975 | if (NULL == data_js) | 972 | if (NULL == data_js) |
976 | { | 973 | { |
977 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_NO_DATA); | 974 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_NO_DATA); |
978 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 975 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
979 | json_decref (data_js); | 976 | json_decref(data_js); |
980 | return; | 977 | return; |
981 | } | 978 | } |
982 | json_unpack_state = 0; | 979 | json_unpack_state = 0; |
983 | json_unpack_state = | 980 | json_unpack_state = |
984 | json_unpack (data_js, "{s:s!}", GNUNET_REST_IDENTITY_PARAM_NAME, &egoname); | 981 | json_unpack(data_js, "{s:s!}", GNUNET_REST_IDENTITY_PARAM_NAME, &egoname); |
985 | if (0 != json_unpack_state) | 982 | if (0 != json_unpack_state) |
986 | { | 983 | { |
987 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 984 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
988 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 985 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
989 | json_decref (data_js); | 986 | json_decref(data_js); |
990 | return; | 987 | return; |
991 | } | 988 | } |
992 | 989 | ||
993 | if (NULL == egoname) | 990 | if (NULL == egoname) |
994 | { | 991 | { |
995 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 992 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
996 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 993 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
997 | json_decref (data_js); | 994 | json_decref(data_js); |
998 | return; | 995 | return; |
999 | } | 996 | } |
1000 | if (0 >= strlen (egoname)) | 997 | if (0 >= strlen(egoname)) |
1001 | { | 998 | { |
1002 | json_decref (data_js); | 999 | json_decref(data_js); |
1003 | handle->emsg = GNUNET_strdup (GNUNET_REST_ERROR_DATA_INVALID); | 1000 | handle->emsg = GNUNET_strdup(GNUNET_REST_ERROR_DATA_INVALID); |
1004 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1001 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1005 | return; | 1002 | return; |
1006 | } | 1003 | } |
1007 | GNUNET_STRINGS_utf8_tolower (egoname, egoname); | 1004 | GNUNET_STRINGS_utf8_tolower(egoname, egoname); |
1008 | for (ego_entry = handle->ego_head; NULL != ego_entry; | 1005 | for (ego_entry = handle->ego_head; NULL != ego_entry; |
1009 | ego_entry = ego_entry->next) | 1006 | ego_entry = ego_entry->next) |
1010 | { | ||
1011 | if (0 == strcasecmp (egoname, ego_entry->identifier)) | ||
1012 | { | 1007 | { |
1013 | resp = GNUNET_REST_create_response (NULL); | 1008 | if (0 == strcasecmp(egoname, ego_entry->identifier)) |
1014 | handle->proc (handle->proc_cls, resp, MHD_HTTP_CONFLICT); | 1009 | { |
1015 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 1010 | resp = GNUNET_REST_create_response(NULL); |
1016 | json_decref (data_js); | 1011 | handle->proc(handle->proc_cls, resp, MHD_HTTP_CONFLICT); |
1017 | return; | 1012 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
1013 | json_decref(data_js); | ||
1014 | return; | ||
1015 | } | ||
1018 | } | 1016 | } |
1019 | } | 1017 | handle->name = GNUNET_strdup(egoname); |
1020 | handle->name = GNUNET_strdup (egoname); | 1018 | json_decref(data_js); |
1021 | json_decref (data_js); | ||
1022 | handle->response_code = MHD_HTTP_CREATED; | 1019 | handle->response_code = MHD_HTTP_CREATED; |
1023 | handle->op = GNUNET_IDENTITY_create (handle->identity_handle, | 1020 | handle->op = GNUNET_IDENTITY_create(handle->identity_handle, |
1024 | handle->name, | 1021 | handle->name, |
1025 | &do_finished_create, | 1022 | &do_finished_create, |
1026 | handle); | 1023 | handle); |
1027 | } | 1024 | } |
1028 | 1025 | ||
1029 | /** | 1026 | /** |
@@ -1034,9 +1031,9 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle, | |||
1034 | * @param cls the RequestHandle | 1031 | * @param cls the RequestHandle |
1035 | */ | 1032 | */ |
1036 | void | 1033 | void |
1037 | ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | 1034 | ego_delete_pubkey(struct GNUNET_REST_RequestHandle *con_handle, |
1038 | const char *url, | 1035 | const char *url, |
1039 | void *cls) | 1036 | void *cls) |
1040 | { | 1037 | { |
1041 | struct RequestHandle *handle = cls; | 1038 | struct RequestHandle *handle = cls; |
1042 | struct EgoEntry *ego_entry; | 1039 | struct EgoEntry *ego_entry; |
@@ -1044,29 +1041,29 @@ ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
1044 | 1041 | ||
1045 | keystring = NULL; | 1042 | keystring = NULL; |
1046 | 1043 | ||
1047 | if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url)) | 1044 | if (strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen(handle->url)) |
1048 | { | 1045 | { |
1049 | handle->response_code = MHD_HTTP_NOT_FOUND; | 1046 | handle->response_code = MHD_HTTP_NOT_FOUND; |
1050 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_PUBKEY); | 1047 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_PUBKEY); |
1051 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1048 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1052 | return; | 1049 | return; |
1053 | } | 1050 | } |
1054 | keystring = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; | 1051 | keystring = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_PUBKEY) + 1]; |
1055 | ego_entry = get_egoentry (handle, keystring, NULL); | 1052 | ego_entry = get_egoentry(handle, keystring, NULL); |
1056 | 1053 | ||
1057 | if (NULL == ego_entry) | 1054 | if (NULL == ego_entry) |
1058 | { | 1055 | { |
1059 | handle->response_code = MHD_HTTP_NOT_FOUND; | 1056 | handle->response_code = MHD_HTTP_NOT_FOUND; |
1060 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | 1057 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
1061 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1058 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1062 | return; | 1059 | return; |
1063 | } | 1060 | } |
1064 | 1061 | ||
1065 | handle->response_code = MHD_HTTP_NO_CONTENT; | 1062 | handle->response_code = MHD_HTTP_NO_CONTENT; |
1066 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, | 1063 | handle->op = GNUNET_IDENTITY_delete(handle->identity_handle, |
1067 | ego_entry->identifier, | 1064 | ego_entry->identifier, |
1068 | &do_finished, | 1065 | &do_finished, |
1069 | handle); | 1066 | handle); |
1070 | } | 1067 | } |
1071 | 1068 | ||
1072 | 1069 | ||
@@ -1078,9 +1075,9 @@ ego_delete_pubkey (struct GNUNET_REST_RequestHandle *con_handle, | |||
1078 | * @param cls the RequestHandle | 1075 | * @param cls the RequestHandle |
1079 | */ | 1076 | */ |
1080 | void | 1077 | void |
1081 | ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, | 1078 | ego_delete_name(struct GNUNET_REST_RequestHandle *con_handle, |
1082 | const char *url, | 1079 | const char *url, |
1083 | void *cls) | 1080 | void *cls) |
1084 | { | 1081 | { |
1085 | struct RequestHandle *handle = cls; | 1082 | struct RequestHandle *handle = cls; |
1086 | struct EgoEntry *ego_entry; | 1083 | struct EgoEntry *ego_entry; |
@@ -1088,29 +1085,29 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
1088 | 1085 | ||
1089 | name = NULL; | 1086 | name = NULL; |
1090 | 1087 | ||
1091 | if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url)) | 1088 | if (strlen(GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen(handle->url)) |
1092 | { | 1089 | { |
1093 | handle->response_code = MHD_HTTP_NOT_FOUND; | 1090 | handle->response_code = MHD_HTTP_NOT_FOUND; |
1094 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_MISSING_NAME); | 1091 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_MISSING_NAME); |
1095 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1092 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1096 | return; | 1093 | return; |
1097 | } | 1094 | } |
1098 | name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; | 1095 | name = &handle->url[strlen(GNUNET_REST_API_NS_IDENTITY_NAME) + 1]; |
1099 | ego_entry = get_egoentry (handle, NULL, name); | 1096 | ego_entry = get_egoentry(handle, NULL, name); |
1100 | 1097 | ||
1101 | if (NULL == ego_entry) | 1098 | if (NULL == ego_entry) |
1102 | { | 1099 | { |
1103 | handle->response_code = MHD_HTTP_NOT_FOUND; | 1100 | handle->response_code = MHD_HTTP_NOT_FOUND; |
1104 | handle->emsg = GNUNET_strdup (GNUNET_REST_IDENTITY_NOT_FOUND); | 1101 | handle->emsg = GNUNET_strdup(GNUNET_REST_IDENTITY_NOT_FOUND); |
1105 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1102 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1106 | return; | 1103 | return; |
1107 | } | 1104 | } |
1108 | 1105 | ||
1109 | handle->response_code = MHD_HTTP_NO_CONTENT; | 1106 | handle->response_code = MHD_HTTP_NO_CONTENT; |
1110 | handle->op = GNUNET_IDENTITY_delete (handle->identity_handle, | 1107 | handle->op = GNUNET_IDENTITY_delete(handle->identity_handle, |
1111 | ego_entry->identifier, | 1108 | ego_entry->identifier, |
1112 | &do_finished, | 1109 | &do_finished, |
1113 | handle); | 1110 | handle); |
1114 | } | 1111 | } |
1115 | 1112 | ||
1116 | 1113 | ||
@@ -1122,18 +1119,18 @@ ego_delete_name (struct GNUNET_REST_RequestHandle *con_handle, | |||
1122 | * @param cls the RequestHandle | 1119 | * @param cls the RequestHandle |
1123 | */ | 1120 | */ |
1124 | static void | 1121 | static void |
1125 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, | 1122 | options_cont(struct GNUNET_REST_RequestHandle *con_handle, |
1126 | const char *url, | 1123 | const char *url, |
1127 | void *cls) | 1124 | void *cls) |
1128 | { | 1125 | { |
1129 | struct MHD_Response *resp; | 1126 | struct MHD_Response *resp; |
1130 | struct RequestHandle *handle = cls; | 1127 | struct RequestHandle *handle = cls; |
1131 | 1128 | ||
1132 | //For now, independent of path return all options | 1129 | //For now, independent of path return all options |
1133 | resp = GNUNET_REST_create_response (NULL); | 1130 | resp = GNUNET_REST_create_response(NULL); |
1134 | MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods); | 1131 | MHD_add_response_header(resp, "Access-Control-Allow-Methods", allow_methods); |
1135 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | 1132 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); |
1136 | GNUNET_SCHEDULER_add_now (&cleanup_handle, handle); | 1133 | GNUNET_SCHEDULER_add_now(&cleanup_handle, handle); |
1137 | return; | 1134 | return; |
1138 | } | 1135 | } |
1139 | 1136 | ||
@@ -1143,39 +1140,39 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1143 | * @param handle the request handle | 1140 | * @param handle the request handle |
1144 | */ | 1141 | */ |
1145 | static void | 1142 | static void |
1146 | init_cont (struct RequestHandle *handle) | 1143 | init_cont(struct RequestHandle *handle) |
1147 | { | 1144 | { |
1148 | struct GNUNET_REST_RequestHandlerError err; | 1145 | struct GNUNET_REST_RequestHandlerError err; |
1149 | static const struct GNUNET_REST_RequestHandler handlers[] = | 1146 | static const struct GNUNET_REST_RequestHandler handlers[] = |
1150 | {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_ALL, &ego_get_all}, | 1147 | { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_ALL, &ego_get_all }, |
1151 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_get_pubkey}, | 1148 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY, &ego_get_pubkey }, |
1152 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name}, | 1149 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name }, |
1153 | {MHD_HTTP_METHOD_GET, | 1150 | { MHD_HTTP_METHOD_GET, |
1154 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | 1151 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, |
1155 | &ego_get_subsystem}, | 1152 | &ego_get_subsystem }, |
1156 | {MHD_HTTP_METHOD_PUT, | 1153 | { MHD_HTTP_METHOD_PUT, |
1157 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | 1154 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, |
1158 | &ego_edit_pubkey}, | 1155 | &ego_edit_pubkey }, |
1159 | {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name}, | 1156 | { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name }, |
1160 | {MHD_HTTP_METHOD_PUT, | 1157 | { MHD_HTTP_METHOD_PUT, |
1161 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, | 1158 | GNUNET_REST_API_NS_IDENTITY_SUBSYSTEM, |
1162 | &ego_edit_subsystem}, | 1159 | &ego_edit_subsystem }, |
1163 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create}, | 1160 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create }, |
1164 | {MHD_HTTP_METHOD_DELETE, | 1161 | { MHD_HTTP_METHOD_DELETE, |
1165 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, | 1162 | GNUNET_REST_API_NS_IDENTITY_PUBKEY, |
1166 | &ego_delete_pubkey}, | 1163 | &ego_delete_pubkey }, |
1167 | {MHD_HTTP_METHOD_DELETE, | 1164 | { MHD_HTTP_METHOD_DELETE, |
1168 | GNUNET_REST_API_NS_IDENTITY_NAME, | 1165 | GNUNET_REST_API_NS_IDENTITY_NAME, |
1169 | &ego_delete_name}, | 1166 | &ego_delete_name }, |
1170 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont}, | 1167 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont }, |
1171 | GNUNET_REST_HANDLER_END}; | 1168 | GNUNET_REST_HANDLER_END }; |
1172 | 1169 | ||
1173 | if (GNUNET_NO == | 1170 | if (GNUNET_NO == |
1174 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | 1171 | GNUNET_REST_handle_request(handle->rest_handle, handlers, &err, handle)) |
1175 | { | 1172 | { |
1176 | handle->response_code = err.error_code; | 1173 | handle->response_code = err.error_code; |
1177 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1174 | GNUNET_SCHEDULER_add_now(&do_error, handle); |
1178 | } | 1175 | } |
1179 | } | 1176 | } |
1180 | 1177 | ||
1181 | /** | 1178 | /** |
@@ -1212,32 +1209,32 @@ init_cont (struct RequestHandle *handle) | |||
1212 | * must thus no longer be used | 1209 | * must thus no longer be used |
1213 | */ | 1210 | */ |
1214 | static void | 1211 | static void |
1215 | init_egos (void *cls, | 1212 | init_egos(void *cls, |
1216 | struct GNUNET_IDENTITY_Ego *ego, | 1213 | struct GNUNET_IDENTITY_Ego *ego, |
1217 | void **ctx, | 1214 | void **ctx, |
1218 | const char *identifier) | 1215 | const char *identifier) |
1219 | { | 1216 | { |
1220 | struct RequestHandle *handle = cls; | 1217 | struct RequestHandle *handle = cls; |
1221 | struct EgoEntry *ego_entry; | 1218 | struct EgoEntry *ego_entry; |
1222 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | 1219 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; |
1223 | 1220 | ||
1224 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | 1221 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) |
1225 | { | 1222 | { |
1226 | handle->state = ID_REST_STATE_POST_INIT; | 1223 | handle->state = ID_REST_STATE_POST_INIT; |
1227 | init_cont (handle); | 1224 | init_cont(handle); |
1228 | return; | 1225 | return; |
1229 | } | 1226 | } |
1230 | if (ID_REST_STATE_INIT == handle->state) | 1227 | if (ID_REST_STATE_INIT == handle->state) |
1231 | { | 1228 | { |
1232 | ego_entry = GNUNET_new (struct EgoEntry); | 1229 | ego_entry = GNUNET_new(struct EgoEntry); |
1233 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | 1230 | GNUNET_IDENTITY_ego_get_public_key(ego, &pk); |
1234 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | 1231 | ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string(&pk); |
1235 | ego_entry->ego = ego; | 1232 | ego_entry->ego = ego; |
1236 | GNUNET_asprintf (&ego_entry->identifier, "%s", identifier); | 1233 | GNUNET_asprintf(&ego_entry->identifier, "%s", identifier); |
1237 | GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head, | 1234 | GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head, |
1238 | handle->ego_tail, | 1235 | handle->ego_tail, |
1239 | ego_entry); | 1236 | ego_entry); |
1240 | } | 1237 | } |
1241 | } | 1238 | } |
1242 | 1239 | ||
1243 | /** | 1240 | /** |
@@ -1252,11 +1249,11 @@ init_egos (void *cls, | |||
1252 | * @return GNUNET_OK if request accepted | 1249 | * @return GNUNET_OK if request accepted |
1253 | */ | 1250 | */ |
1254 | static void | 1251 | static void |
1255 | rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | 1252 | rest_process_request(struct GNUNET_REST_RequestHandle *rest_handle, |
1256 | GNUNET_REST_ResultProcessor proc, | 1253 | GNUNET_REST_ResultProcessor proc, |
1257 | void *proc_cls) | 1254 | void *proc_cls) |
1258 | { | 1255 | { |
1259 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | 1256 | struct RequestHandle *handle = GNUNET_new(struct RequestHandle); |
1260 | 1257 | ||
1261 | handle->response_code = 0; | 1258 | handle->response_code = 0; |
1262 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1259 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
@@ -1266,17 +1263,17 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1266 | handle->data = rest_handle->data; | 1263 | handle->data = rest_handle->data; |
1267 | handle->data_size = rest_handle->data_size; | 1264 | handle->data_size = rest_handle->data_size; |
1268 | 1265 | ||
1269 | handle->url = GNUNET_strdup (rest_handle->url); | 1266 | handle->url = GNUNET_strdup(rest_handle->url); |
1270 | if (handle->url[strlen (handle->url) - 1] == '/') | 1267 | if (handle->url[strlen(handle->url) - 1] == '/') |
1271 | handle->url[strlen (handle->url) - 1] = '\0'; | 1268 | handle->url[strlen(handle->url) - 1] = '\0'; |
1272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); | 1269 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n"); |
1273 | 1270 | ||
1274 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &init_egos, handle); | 1271 | handle->identity_handle = GNUNET_IDENTITY_connect(cfg, &init_egos, handle); |
1275 | 1272 | ||
1276 | handle->timeout_task = | 1273 | handle->timeout_task = |
1277 | GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_error, handle); | 1274 | GNUNET_SCHEDULER_add_delayed(handle->timeout, &do_error, handle); |
1278 | 1275 | ||
1279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); | 1276 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected\n"); |
1280 | } | 1277 | } |
1281 | 1278 | ||
1282 | /** | 1279 | /** |
@@ -1286,7 +1283,7 @@ rest_process_request (struct GNUNET_REST_RequestHandle *rest_handle, | |||
1286 | * @return NULL on error, otherwise the plugin context | 1283 | * @return NULL on error, otherwise the plugin context |
1287 | */ | 1284 | */ |
1288 | void * | 1285 | void * |
1289 | libgnunet_plugin_rest_identity_init (void *cls) | 1286 | libgnunet_plugin_rest_identity_init(void *cls) |
1290 | { | 1287 | { |
1291 | static struct Plugin plugin; | 1288 | static struct Plugin plugin; |
1292 | struct GNUNET_REST_Plugin *api; | 1289 | struct GNUNET_REST_Plugin *api; |
@@ -1294,21 +1291,21 @@ libgnunet_plugin_rest_identity_init (void *cls) | |||
1294 | cfg = cls; | 1291 | cfg = cls; |
1295 | if (NULL != plugin.cfg) | 1292 | if (NULL != plugin.cfg) |
1296 | return NULL; /* can only initialize once! */ | 1293 | return NULL; /* can only initialize once! */ |
1297 | memset (&plugin, 0, sizeof (struct Plugin)); | 1294 | memset(&plugin, 0, sizeof(struct Plugin)); |
1298 | plugin.cfg = cfg; | 1295 | plugin.cfg = cfg; |
1299 | api = GNUNET_new (struct GNUNET_REST_Plugin); | 1296 | api = GNUNET_new(struct GNUNET_REST_Plugin); |
1300 | api->cls = &plugin; | 1297 | api->cls = &plugin; |
1301 | api->name = GNUNET_REST_API_NS_IDENTITY; | 1298 | api->name = GNUNET_REST_API_NS_IDENTITY; |
1302 | api->process_request = &rest_process_request; | 1299 | api->process_request = &rest_process_request; |
1303 | GNUNET_asprintf (&allow_methods, | 1300 | GNUNET_asprintf(&allow_methods, |
1304 | "%s, %s, %s, %s, %s", | 1301 | "%s, %s, %s, %s, %s", |
1305 | MHD_HTTP_METHOD_GET, | 1302 | MHD_HTTP_METHOD_GET, |
1306 | MHD_HTTP_METHOD_POST, | 1303 | MHD_HTTP_METHOD_POST, |
1307 | MHD_HTTP_METHOD_PUT, | 1304 | MHD_HTTP_METHOD_PUT, |
1308 | MHD_HTTP_METHOD_DELETE, | 1305 | MHD_HTTP_METHOD_DELETE, |
1309 | MHD_HTTP_METHOD_OPTIONS); | 1306 | MHD_HTTP_METHOD_OPTIONS); |
1310 | 1307 | ||
1311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n")); | 1308 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Identity REST API initialized\n")); |
1312 | return api; | 1309 | return api; |
1313 | } | 1310 | } |
1314 | 1311 | ||
@@ -1319,15 +1316,16 @@ libgnunet_plugin_rest_identity_init (void *cls) | |||
1319 | * @return always NULL | 1316 | * @return always NULL |
1320 | */ | 1317 | */ |
1321 | void * | 1318 | void * |
1322 | libgnunet_plugin_rest_identity_done (void *cls) | 1319 | libgnunet_plugin_rest_identity_done(void *cls) |
1323 | { | 1320 | { |
1324 | struct GNUNET_REST_Plugin *api = cls; | 1321 | struct GNUNET_REST_Plugin *api = cls; |
1325 | struct Plugin *plugin = api->cls; | 1322 | struct Plugin *plugin = api->cls; |
1323 | |||
1326 | plugin->cfg = NULL; | 1324 | plugin->cfg = NULL; |
1327 | 1325 | ||
1328 | GNUNET_free_non_null (allow_methods); | 1326 | GNUNET_free_non_null(allow_methods); |
1329 | GNUNET_free (api); | 1327 | GNUNET_free(api); |
1330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n"); | 1328 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n"); |
1331 | return NULL; | 1329 | return NULL; |
1332 | } | 1330 | } |
1333 | 1331 | ||
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c index 74c052917..7f7371422 100644 --- a/src/identity/test_identity.c +++ b/src/identity/test_identity.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 identity/test_identity.c | 22 | * @file identity/test_identity.c |
@@ -29,7 +29,7 @@ | |||
29 | #include "gnunet_testing_lib.h" | 29 | #include "gnunet_testing_lib.h" |
30 | 30 | ||
31 | 31 | ||
32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 32 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) |
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
@@ -54,33 +54,33 @@ static struct GNUNET_SCHEDULER_Task *endbadly_task; | |||
54 | 54 | ||
55 | #define CHECK(cond) \ | 55 | #define CHECK(cond) \ |
56 | do \ | 56 | do \ |
57 | { \ | 57 | { \ |
58 | if (! (cond)) \ | 58 | if (!(cond)) \ |
59 | { \ | 59 | { \ |
60 | GNUNET_break (0); \ | 60 | GNUNET_break(0); \ |
61 | end (); \ | 61 | end(); \ |
62 | return; \ | 62 | return; \ |
63 | } \ | 63 | } \ |
64 | } while (0) | 64 | } while (0) |
65 | 65 | ||
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Clean up all resources used. | 68 | * Clean up all resources used. |
69 | */ | 69 | */ |
70 | static void | 70 | static void |
71 | cleanup (void *cls) | 71 | cleanup(void *cls) |
72 | { | 72 | { |
73 | (void) cls; | 73 | (void)cls; |
74 | if (NULL != op) | 74 | if (NULL != op) |
75 | { | 75 | { |
76 | GNUNET_IDENTITY_cancel (op); | 76 | GNUNET_IDENTITY_cancel(op); |
77 | op = NULL; | 77 | op = NULL; |
78 | } | 78 | } |
79 | if (NULL != h) | 79 | if (NULL != h) |
80 | { | 80 | { |
81 | GNUNET_IDENTITY_disconnect (h); | 81 | GNUNET_IDENTITY_disconnect(h); |
82 | h = NULL; | 82 | h = NULL; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
@@ -90,9 +90,9 @@ cleanup (void *cls) | |||
90 | * @param cls NULL | 90 | * @param cls NULL |
91 | */ | 91 | */ |
92 | static void | 92 | static void |
93 | endbadly (void *cls) | 93 | endbadly(void *cls) |
94 | { | 94 | { |
95 | GNUNET_SCHEDULER_shutdown (); | 95 | GNUNET_SCHEDULER_shutdown(); |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
@@ -100,14 +100,14 @@ endbadly (void *cls) | |||
100 | * Finish the testcase (successfully). | 100 | * Finish the testcase (successfully). |
101 | */ | 101 | */ |
102 | static void | 102 | static void |
103 | end () | 103 | end() |
104 | { | 104 | { |
105 | if (NULL != endbadly_task) | 105 | if (NULL != endbadly_task) |
106 | { | 106 | { |
107 | GNUNET_SCHEDULER_cancel (endbadly_task); | 107 | GNUNET_SCHEDULER_cancel(endbadly_task); |
108 | endbadly_task = NULL; | 108 | endbadly_task = NULL; |
109 | } | 109 | } |
110 | GNUNET_SCHEDULER_shutdown (); | 110 | GNUNET_SCHEDULER_shutdown(); |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
@@ -123,57 +123,64 @@ end () | |||
123 | * must thus no longer be used | 123 | * must thus no longer be used |
124 | */ | 124 | */ |
125 | static void | 125 | static void |
126 | notification_cb (void *cls, | 126 | notification_cb(void *cls, |
127 | struct GNUNET_IDENTITY_Ego *ego, | 127 | struct GNUNET_IDENTITY_Ego *ego, |
128 | void **ctx, | 128 | void **ctx, |
129 | const char *identifier) | 129 | const char *identifier) |
130 | { | 130 | { |
131 | static struct GNUNET_IDENTITY_Ego *my_ego; | 131 | static struct GNUNET_IDENTITY_Ego *my_ego; |
132 | static int round; | 132 | static int round; |
133 | 133 | ||
134 | switch (round) | 134 | switch (round) |
135 | { | 135 | { |
136 | case 0: /* end of initial iteration */ | 136 | case 0: /* end of initial iteration */ |
137 | CHECK (NULL == ego); | 137 | CHECK(NULL == ego); |
138 | CHECK (NULL == identifier); | 138 | CHECK(NULL == identifier); |
139 | break; | 139 | break; |
140 | case 1: /* create */ | 140 | |
141 | CHECK (NULL != ego); | 141 | case 1: /* create */ |
142 | CHECK (NULL != identifier); | 142 | CHECK(NULL != ego); |
143 | CHECK (0 == strcmp (identifier, "test-id")); | 143 | CHECK(NULL != identifier); |
144 | my_ego = ego; | 144 | CHECK(0 == strcmp(identifier, "test-id")); |
145 | *ctx = &round; | 145 | my_ego = ego; |
146 | break; | 146 | *ctx = &round; |
147 | case 2: /* rename */ | 147 | break; |
148 | CHECK (my_ego == ego); | 148 | |
149 | CHECK (NULL != identifier); | 149 | case 2: /* rename */ |
150 | CHECK (0 == strcmp (identifier, "test")); | 150 | CHECK(my_ego == ego); |
151 | CHECK (*ctx == &round); | 151 | CHECK(NULL != identifier); |
152 | break; | 152 | CHECK(0 == strcmp(identifier, "test")); |
153 | case 3: /* reconnect-down */ | 153 | CHECK(*ctx == &round); |
154 | CHECK (my_ego == ego); | 154 | break; |
155 | CHECK (NULL == identifier); | 155 | |
156 | CHECK (*ctx == &round); | 156 | case 3: /* reconnect-down */ |
157 | *ctx = NULL; | 157 | CHECK(my_ego == ego); |
158 | break; | 158 | CHECK(NULL == identifier); |
159 | case 4: /* reconnect-up */ | 159 | CHECK(*ctx == &round); |
160 | CHECK (NULL != identifier); | 160 | *ctx = NULL; |
161 | CHECK (0 == strcmp (identifier, "test")); | 161 | break; |
162 | my_ego = ego; | 162 | |
163 | *ctx = &round; | 163 | case 4: /* reconnect-up */ |
164 | break; | 164 | CHECK(NULL != identifier); |
165 | case 5: /* end of iteration after reconnect */ | 165 | CHECK(0 == strcmp(identifier, "test")); |
166 | CHECK (NULL == ego); | 166 | my_ego = ego; |
167 | CHECK (NULL == identifier); | 167 | *ctx = &round; |
168 | break; | 168 | break; |
169 | case 6: /* delete */ | 169 | |
170 | CHECK (my_ego == ego); | 170 | case 5: /* end of iteration after reconnect */ |
171 | CHECK (*ctx == &round); | 171 | CHECK(NULL == ego); |
172 | *ctx = NULL; | 172 | CHECK(NULL == identifier); |
173 | break; | 173 | break; |
174 | default: | 174 | |
175 | CHECK (0); | 175 | case 6: /* delete */ |
176 | } | 176 | CHECK(my_ego == ego); |
177 | CHECK(*ctx == &round); | ||
178 | *ctx = NULL; | ||
179 | break; | ||
180 | |||
181 | default: | ||
182 | CHECK(0); | ||
183 | } | ||
177 | round++; | 184 | round++; |
178 | } | 185 | } |
179 | 186 | ||
@@ -185,12 +192,12 @@ notification_cb (void *cls, | |||
185 | * @param emsg (should also be NULL) | 192 | * @param emsg (should also be NULL) |
186 | */ | 193 | */ |
187 | static void | 194 | static void |
188 | delete_cont (void *cls, const char *emsg) | 195 | delete_cont(void *cls, const char *emsg) |
189 | { | 196 | { |
190 | op = NULL; | 197 | op = NULL; |
191 | CHECK (NULL == emsg); | 198 | CHECK(NULL == emsg); |
192 | res = 0; | 199 | res = 0; |
193 | end (); | 200 | end(); |
194 | } | 201 | } |
195 | 202 | ||
196 | 203 | ||
@@ -200,9 +207,9 @@ delete_cont (void *cls, const char *emsg) | |||
200 | * @param cls NULL | 207 | * @param cls NULL |
201 | */ | 208 | */ |
202 | static void | 209 | static void |
203 | finally_delete (void *cls) | 210 | finally_delete(void *cls) |
204 | { | 211 | { |
205 | op = GNUNET_IDENTITY_delete (h, "test", &delete_cont, NULL); | 212 | op = GNUNET_IDENTITY_delete(h, "test", &delete_cont, NULL); |
206 | } | 213 | } |
207 | 214 | ||
208 | 215 | ||
@@ -213,13 +220,13 @@ finally_delete (void *cls) | |||
213 | * @param emsg (should also be NULL) | 220 | * @param emsg (should also be NULL) |
214 | */ | 221 | */ |
215 | static void | 222 | static void |
216 | fail_rename_cont (void *cls, const char *emsg) | 223 | fail_rename_cont(void *cls, const char *emsg) |
217 | { | 224 | { |
218 | CHECK (NULL != emsg); | 225 | CHECK(NULL != emsg); |
219 | op = NULL; | 226 | op = NULL; |
220 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 227 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
221 | &finally_delete, | 228 | &finally_delete, |
222 | NULL); | 229 | NULL); |
223 | } | 230 | } |
224 | 231 | ||
225 | 232 | ||
@@ -230,10 +237,10 @@ fail_rename_cont (void *cls, const char *emsg) | |||
230 | * @param emsg (should also be NULL) | 237 | * @param emsg (should also be NULL) |
231 | */ | 238 | */ |
232 | static void | 239 | static void |
233 | success_rename_cont (void *cls, const char *emsg) | 240 | success_rename_cont(void *cls, const char *emsg) |
234 | { | 241 | { |
235 | CHECK (NULL == emsg); | 242 | CHECK(NULL == emsg); |
236 | op = GNUNET_IDENTITY_rename (h, "test-id", "test", &fail_rename_cont, NULL); | 243 | op = GNUNET_IDENTITY_rename(h, "test-id", "test", &fail_rename_cont, NULL); |
237 | } | 244 | } |
238 | 245 | ||
239 | 246 | ||
@@ -245,14 +252,14 @@ success_rename_cont (void *cls, const char *emsg) | |||
245 | * @param emsg error message | 252 | * @param emsg error message |
246 | */ | 253 | */ |
247 | static void | 254 | static void |
248 | create_cb (void *cls, | 255 | create_cb(void *cls, |
249 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 256 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
250 | const char *emsg) | 257 | const char *emsg) |
251 | { | 258 | { |
252 | CHECK (NULL != pk); | 259 | CHECK(NULL != pk); |
253 | CHECK (NULL == emsg); | 260 | CHECK(NULL == emsg); |
254 | op = | 261 | op = |
255 | GNUNET_IDENTITY_rename (h, "test-id", "test", &success_rename_cont, NULL); | 262 | GNUNET_IDENTITY_rename(h, "test-id", "test", &success_rename_cont, NULL); |
256 | } | 263 | } |
257 | 264 | ||
258 | 265 | ||
@@ -264,30 +271,30 @@ create_cb (void *cls, | |||
264 | * @param peer handle to access more of the peer (not used) | 271 | * @param peer handle to access more of the peer (not used) |
265 | */ | 272 | */ |
266 | static void | 273 | static void |
267 | run (void *cls, | 274 | run(void *cls, |
268 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 275 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
269 | struct GNUNET_TESTING_Peer *peer) | 276 | struct GNUNET_TESTING_Peer *peer) |
270 | { | 277 | { |
271 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); | 278 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); |
272 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | 279 | GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); |
273 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | 280 | h = GNUNET_IDENTITY_connect(cfg, ¬ification_cb, NULL); |
274 | CHECK (NULL != h); | 281 | CHECK(NULL != h); |
275 | op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); | 282 | op = GNUNET_IDENTITY_create(h, "test-id", &create_cb, NULL); |
276 | } | 283 | } |
277 | 284 | ||
278 | 285 | ||
279 | int | 286 | int |
280 | main (int argc, char *argv[]) | 287 | main(int argc, char *argv[]) |
281 | { | 288 | { |
282 | GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); | 289 | GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); |
283 | res = 1; | 290 | res = 1; |
284 | if (0 != GNUNET_TESTING_service_run ("test-identity", | 291 | if (0 != GNUNET_TESTING_service_run("test-identity", |
285 | "identity", | 292 | "identity", |
286 | "test_identity.conf", | 293 | "test_identity.conf", |
287 | &run, | 294 | &run, |
288 | NULL)) | 295 | NULL)) |
289 | return 1; | 296 | return 1; |
290 | GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); | 297 | GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); |
291 | return res; | 298 | return res; |
292 | } | 299 | } |
293 | 300 | ||
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c index 71e70e7ba..6e14022c6 100644 --- a/src/identity/test_identity_defaults.c +++ b/src/identity/test_identity_defaults.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 identity/test_identity.c | 22 | * @file identity/test_identity.c |
@@ -29,7 +29,7 @@ | |||
29 | #include "gnunet_testing_lib.h" | 29 | #include "gnunet_testing_lib.h" |
30 | 30 | ||
31 | 31 | ||
32 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 32 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) |
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
@@ -54,33 +54,33 @@ static struct GNUNET_SCHEDULER_Task *endbadly_task; | |||
54 | 54 | ||
55 | #define CHECK(cond) \ | 55 | #define CHECK(cond) \ |
56 | do \ | 56 | do \ |
57 | { \ | 57 | { \ |
58 | if (! (cond)) \ | 58 | if (!(cond)) \ |
59 | { \ | 59 | { \ |
60 | GNUNET_break (0); \ | 60 | GNUNET_break(0); \ |
61 | end (); \ | 61 | end(); \ |
62 | return; \ | 62 | return; \ |
63 | } \ | 63 | } \ |
64 | } while (0) | 64 | } while (0) |
65 | 65 | ||
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Clean up all resources used. | 68 | * Clean up all resources used. |
69 | */ | 69 | */ |
70 | static void | 70 | static void |
71 | cleanup (void *cls) | 71 | cleanup(void *cls) |
72 | { | 72 | { |
73 | (void) cls; | 73 | (void)cls; |
74 | if (NULL != op) | 74 | if (NULL != op) |
75 | { | 75 | { |
76 | GNUNET_IDENTITY_cancel (op); | 76 | GNUNET_IDENTITY_cancel(op); |
77 | op = NULL; | 77 | op = NULL; |
78 | } | 78 | } |
79 | if (NULL != h) | 79 | if (NULL != h) |
80 | { | 80 | { |
81 | GNUNET_IDENTITY_disconnect (h); | 81 | GNUNET_IDENTITY_disconnect(h); |
82 | h = NULL; | 82 | h = NULL; |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
@@ -90,9 +90,9 @@ cleanup (void *cls) | |||
90 | * @param cls NULL | 90 | * @param cls NULL |
91 | */ | 91 | */ |
92 | static void | 92 | static void |
93 | endbadly (void *cls) | 93 | endbadly(void *cls) |
94 | { | 94 | { |
95 | GNUNET_SCHEDULER_shutdown (); | 95 | GNUNET_SCHEDULER_shutdown(); |
96 | res = 1; | 96 | res = 1; |
97 | } | 97 | } |
98 | 98 | ||
@@ -101,14 +101,14 @@ endbadly (void *cls) | |||
101 | * Termiante the testcase. | 101 | * Termiante the testcase. |
102 | */ | 102 | */ |
103 | static void | 103 | static void |
104 | end () | 104 | end() |
105 | { | 105 | { |
106 | if (NULL != endbadly_task) | 106 | if (NULL != endbadly_task) |
107 | { | 107 | { |
108 | GNUNET_SCHEDULER_cancel (endbadly_task); | 108 | GNUNET_SCHEDULER_cancel(endbadly_task); |
109 | endbadly_task = NULL; | 109 | endbadly_task = NULL; |
110 | } | 110 | } |
111 | GNUNET_SCHEDULER_shutdown (); | 111 | GNUNET_SCHEDULER_shutdown(); |
112 | } | 112 | } |
113 | 113 | ||
114 | 114 | ||
@@ -119,12 +119,12 @@ end () | |||
119 | * @param emsg (should also be NULL) | 119 | * @param emsg (should also be NULL) |
120 | */ | 120 | */ |
121 | static void | 121 | static void |
122 | delete_cont (void *cls, const char *emsg) | 122 | delete_cont(void *cls, const char *emsg) |
123 | { | 123 | { |
124 | op = NULL; | 124 | op = NULL; |
125 | CHECK (NULL == emsg); | 125 | CHECK(NULL == emsg); |
126 | res = 0; | 126 | res = 0; |
127 | end (); | 127 | end(); |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
@@ -135,16 +135,16 @@ delete_cont (void *cls, const char *emsg) | |||
135 | * @param emsg (should also be NULL) | 135 | * @param emsg (should also be NULL) |
136 | */ | 136 | */ |
137 | static void | 137 | static void |
138 | get_cb (void *cls, | 138 | get_cb(void *cls, |
139 | struct GNUNET_IDENTITY_Ego *ego, | 139 | struct GNUNET_IDENTITY_Ego *ego, |
140 | void **ctx, | 140 | void **ctx, |
141 | const char *identifier) | 141 | const char *identifier) |
142 | { | 142 | { |
143 | op = NULL; | 143 | op = NULL; |
144 | CHECK (NULL != ego); | 144 | CHECK(NULL != ego); |
145 | CHECK (NULL != identifier); | 145 | CHECK(NULL != identifier); |
146 | CHECK (0 == strcmp (identifier, "test-id")); | 146 | CHECK(0 == strcmp(identifier, "test-id")); |
147 | op = GNUNET_IDENTITY_delete (h, "test-id", &delete_cont, NULL); | 147 | op = GNUNET_IDENTITY_delete(h, "test-id", &delete_cont, NULL); |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
@@ -160,15 +160,15 @@ get_cb (void *cls, | |||
160 | * must thus no longer be used | 160 | * must thus no longer be used |
161 | */ | 161 | */ |
162 | static void | 162 | static void |
163 | dummy_cb (void *cls, | 163 | dummy_cb(void *cls, |
164 | struct GNUNET_IDENTITY_Ego *ego, | 164 | struct GNUNET_IDENTITY_Ego *ego, |
165 | void **ctx, | 165 | void **ctx, |
166 | const char *identifier) | 166 | const char *identifier) |
167 | { | 167 | { |
168 | (void) cls; | 168 | (void)cls; |
169 | (void) ego; | 169 | (void)ego; |
170 | (void) ctx; | 170 | (void)ctx; |
171 | (void) identifier; | 171 | (void)identifier; |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
@@ -180,15 +180,15 @@ dummy_cb (void *cls, | |||
180 | * @param peer handle to access more of the peer (not used) | 180 | * @param peer handle to access more of the peer (not used) |
181 | */ | 181 | */ |
182 | static void | 182 | static void |
183 | run_get (void *cls, | 183 | run_get(void *cls, |
184 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 184 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
185 | struct GNUNET_TESTING_Peer *peer) | 185 | struct GNUNET_TESTING_Peer *peer) |
186 | { | 186 | { |
187 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); | 187 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); |
188 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | 188 | GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); |
189 | h = GNUNET_IDENTITY_connect (cfg, &dummy_cb, NULL); | 189 | h = GNUNET_IDENTITY_connect(cfg, &dummy_cb, NULL); |
190 | CHECK (NULL != h); | 190 | CHECK(NULL != h); |
191 | op = GNUNET_IDENTITY_get (h, "test-service", &get_cb, NULL); | 191 | op = GNUNET_IDENTITY_get(h, "test-service", &get_cb, NULL); |
192 | } | 192 | } |
193 | 193 | ||
194 | 194 | ||
@@ -199,11 +199,11 @@ run_get (void *cls, | |||
199 | * @param emsg (should also be NULL) | 199 | * @param emsg (should also be NULL) |
200 | */ | 200 | */ |
201 | static void | 201 | static void |
202 | success_set_cont (void *cls, const char *emsg) | 202 | success_set_cont(void *cls, const char *emsg) |
203 | { | 203 | { |
204 | op = NULL; | 204 | op = NULL; |
205 | CHECK (NULL == emsg); | 205 | CHECK(NULL == emsg); |
206 | end (); | 206 | end(); |
207 | } | 207 | } |
208 | 208 | ||
209 | 209 | ||
@@ -219,16 +219,16 @@ success_set_cont (void *cls, const char *emsg) | |||
219 | * must thus no longer be used | 219 | * must thus no longer be used |
220 | */ | 220 | */ |
221 | static void | 221 | static void |
222 | notification_cb (void *cls, | 222 | notification_cb(void *cls, |
223 | struct GNUNET_IDENTITY_Ego *ego, | 223 | struct GNUNET_IDENTITY_Ego *ego, |
224 | void **ctx, | 224 | void **ctx, |
225 | const char *identifier) | 225 | const char *identifier) |
226 | { | 226 | { |
227 | if (NULL == ego) | 227 | if (NULL == ego) |
228 | return; /* skip first call */ | 228 | return; /* skip first call */ |
229 | if (NULL == identifier) | 229 | if (NULL == identifier) |
230 | return; /* deletion / shutdown */ | 230 | return; /* deletion / shutdown */ |
231 | op = GNUNET_IDENTITY_set (h, "test-service", ego, &success_set_cont, NULL); | 231 | op = GNUNET_IDENTITY_set(h, "test-service", ego, &success_set_cont, NULL); |
232 | } | 232 | } |
233 | 233 | ||
234 | 234 | ||
@@ -240,12 +240,12 @@ notification_cb (void *cls, | |||
240 | * @param emsg error message | 240 | * @param emsg error message |
241 | */ | 241 | */ |
242 | static void | 242 | static void |
243 | create_cb (void *cls, | 243 | create_cb(void *cls, |
244 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 244 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, |
245 | const char *emsg) | 245 | const char *emsg) |
246 | { | 246 | { |
247 | CHECK (NULL == emsg); | 247 | CHECK(NULL == emsg); |
248 | CHECK (NULL != pk); | 248 | CHECK(NULL != pk); |
249 | op = NULL; | 249 | op = NULL; |
250 | } | 250 | } |
251 | 251 | ||
@@ -258,36 +258,36 @@ create_cb (void *cls, | |||
258 | * @param peer handle to access more of the peer (not used) | 258 | * @param peer handle to access more of the peer (not used) |
259 | */ | 259 | */ |
260 | static void | 260 | static void |
261 | run_set (void *cls, | 261 | run_set(void *cls, |
262 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 262 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
263 | struct GNUNET_TESTING_Peer *peer) | 263 | struct GNUNET_TESTING_Peer *peer) |
264 | { | 264 | { |
265 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); | 265 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &endbadly, NULL); |
266 | GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); | 266 | GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL); |
267 | h = GNUNET_IDENTITY_connect (cfg, ¬ification_cb, NULL); | 267 | h = GNUNET_IDENTITY_connect(cfg, ¬ification_cb, NULL); |
268 | CHECK (NULL != h); | 268 | CHECK(NULL != h); |
269 | op = GNUNET_IDENTITY_create (h, "test-id", &create_cb, NULL); | 269 | op = GNUNET_IDENTITY_create(h, "test-id", &create_cb, NULL); |
270 | } | 270 | } |
271 | 271 | ||
272 | 272 | ||
273 | int | 273 | int |
274 | main (int argc, char *argv[]) | 274 | main(int argc, char *argv[]) |
275 | { | 275 | { |
276 | GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); | 276 | GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); |
277 | res = 1; | 277 | res = 1; |
278 | if (0 != GNUNET_TESTING_service_run ("test-identity-defaults", | 278 | if (0 != GNUNET_TESTING_service_run("test-identity-defaults", |
279 | "identity", | 279 | "identity", |
280 | "test_identity.conf", | 280 | "test_identity.conf", |
281 | &run_set, | 281 | &run_set, |
282 | NULL)) | 282 | NULL)) |
283 | return 1; | 283 | return 1; |
284 | if (0 != GNUNET_TESTING_service_run ("test-identity-defaults", | 284 | if (0 != GNUNET_TESTING_service_run("test-identity-defaults", |
285 | "identity", | 285 | "identity", |
286 | "test_identity.conf", | 286 | "test_identity.conf", |
287 | &run_get, | 287 | &run_get, |
288 | NULL)) | 288 | NULL)) |
289 | return 1; | 289 | return 1; |
290 | GNUNET_DISK_directory_remove ("/tmp/gnunet/test-identity-service"); | 290 | GNUNET_DISK_directory_remove("/tmp/gnunet/test-identity-service"); |
291 | return res; | 291 | return res; |
292 | } | 292 | } |
293 | 293 | ||