aboutsummaryrefslogtreecommitdiff
path: root/src/identity/identity_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/identity_api.c')
-rw-r--r--src/identity/identity_api.c590
1 files changed, 296 insertions, 294 deletions
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index 530ee2d13..42e25c11d 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -30,13 +30,14 @@
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 */
39struct GNUNET_IDENTITY_Operation { 39struct GNUNET_IDENTITY_Operation
40{
40 /** 41 /**
41 * Main identity handle. 42 * Main identity handle.
42 */ 43 */
@@ -91,7 +92,8 @@ struct GNUNET_IDENTITY_Operation {
91/** 92/**
92 * Handle for the service. 93 * Handle for the service.
93 */ 94 */
94struct GNUNET_IDENTITY_Handle { 95struct GNUNET_IDENTITY_Handle
96{
95 /** 97 /**
96 * Configuration to use. 98 * Configuration to use.
97 */ 99 */
@@ -151,7 +153,7 @@ struct GNUNET_IDENTITY_Handle {
151 * @return handle for the anonymous user, must not be freed 153 * @return handle for the anonymous user, must not be freed
152 */ 154 */
153const struct GNUNET_IDENTITY_Ego * 155const struct GNUNET_IDENTITY_Ego *
154GNUNET_IDENTITY_ego_get_anonymous() 156GNUNET_IDENTITY_ego_get_anonymous ()
155{ 157{
156 static struct GNUNET_IDENTITY_Ego anon; 158 static struct GNUNET_IDENTITY_Ego anon;
157 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 159 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
@@ -159,9 +161,9 @@ GNUNET_IDENTITY_ego_get_anonymous()
159 if (NULL != anon.pk) 161 if (NULL != anon.pk)
160 return &anon; 162 return &anon;
161 anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) 163 anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *)
162 GNUNET_CRYPTO_ecdsa_key_get_anonymous(); 164 GNUNET_CRYPTO_ecdsa_key_get_anonymous ();
163 GNUNET_CRYPTO_ecdsa_key_get_public(anon.pk, &pub); 165 GNUNET_CRYPTO_ecdsa_key_get_public (anon.pk, &pub);
164 GNUNET_CRYPTO_hash(&pub, sizeof(pub), &anon.id); 166 GNUNET_CRYPTO_hash (&pub, sizeof(pub), &anon.id);
165 return &anon; 167 return &anon;
166} 168}
167 169
@@ -172,7 +174,7 @@ GNUNET_IDENTITY_ego_get_anonymous()
172 * @param cls handle to the identity service. 174 * @param cls handle to the identity service.
173 */ 175 */
174static void 176static void
175reconnect(void *cls); 177reconnect (void *cls);
176 178
177 179
178/** 180/**
@@ -184,18 +186,18 @@ reconnect(void *cls);
184 * @return #GNUNET_OK (continue to iterate) 186 * @return #GNUNET_OK (continue to iterate)
185 */ 187 */
186static int 188static int
187free_ego(void *cls, const struct GNUNET_HashCode *key, void *value) 189free_ego (void *cls, const struct GNUNET_HashCode *key, void *value)
188{ 190{
189 struct GNUNET_IDENTITY_Handle *h = cls; 191 struct GNUNET_IDENTITY_Handle *h = cls;
190 struct GNUNET_IDENTITY_Ego *ego = value; 192 struct GNUNET_IDENTITY_Ego *ego = value;
191 193
192 if (NULL != h->cb) 194 if (NULL != h->cb)
193 h->cb(h->cb_cls, ego, &ego->ctx, NULL); 195 h->cb (h->cb_cls, ego, &ego->ctx, NULL);
194 GNUNET_free(ego->pk); 196 GNUNET_free (ego->pk);
195 GNUNET_free(ego->name); 197 GNUNET_free (ego->name);
196 GNUNET_assert(GNUNET_YES == 198 GNUNET_assert (GNUNET_YES ==
197 GNUNET_CONTAINER_multihashmap_remove(h->egos, key, value)); 199 GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value));
198 GNUNET_free(ego); 200 GNUNET_free (ego);
199 return GNUNET_OK; 201 return GNUNET_OK;
200} 202}
201 203
@@ -206,38 +208,38 @@ free_ego(void *cls, const struct GNUNET_HashCode *key, void *value)
206 * @param h transport service to reconnect 208 * @param h transport service to reconnect
207 */ 209 */
208static void 210static void
209reschedule_connect(struct GNUNET_IDENTITY_Handle *h) 211reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
210{ 212{
211 struct GNUNET_IDENTITY_Operation *op; 213 struct GNUNET_IDENTITY_Operation *op;
212 214
213 GNUNET_assert(NULL == h->reconnect_task); 215 GNUNET_assert (NULL == h->reconnect_task);
214 216
215 if (NULL != h->mq) 217 if (NULL != h->mq)
216 { 218 {
217 GNUNET_MQ_destroy(h->mq); 219 GNUNET_MQ_destroy (h->mq);
218 h->mq = NULL; 220 h->mq = NULL;
219 } 221 }
220 while (NULL != (op = h->op_head)) 222 while (NULL != (op = h->op_head))
221 { 223 {
222 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); 224 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
223 if (NULL != op->cont) 225 if (NULL != op->cont)
224 op->cont(op->cls, "Error in communication with the identity service"); 226 op->cont (op->cls, "Error in communication with the identity service");
225 else if (NULL != op->cb) 227 else if (NULL != op->cb)
226 op->cb(op->cls, NULL, NULL, NULL); 228 op->cb (op->cls, NULL, NULL, NULL);
227 else if (NULL != op->create_cont) 229 else if (NULL != op->create_cont)
228 op->create_cont(op->cls, 230 op->create_cont (op->cls,
229 NULL, 231 NULL,
230 "Failed to communicate with the identity service"); 232 "Failed to communicate with the identity service");
231 GNUNET_free_non_null(op->pk); 233 GNUNET_free_non_null (op->pk);
232 GNUNET_free(op); 234 GNUNET_free (op);
233 } 235 }
234 GNUNET_CONTAINER_multihashmap_iterate(h->egos, &free_ego, h); 236 GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h);
235 LOG(GNUNET_ERROR_TYPE_DEBUG, 237 LOG (GNUNET_ERROR_TYPE_DEBUG,
236 "Scheduling task to reconnect to identity service in %s.\n", 238 "Scheduling task to reconnect to identity service in %s.\n",
237 GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); 239 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES));
238 h->reconnect_task = 240 h->reconnect_task =
239 GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); 241 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
240 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); 242 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
241} 243}
242 244
243 245
@@ -250,11 +252,11 @@ reschedule_connect(struct GNUNET_IDENTITY_Handle *h)
250 * @param error error code 252 * @param error error code
251 */ 253 */
252static void 254static void
253mq_error_handler(void *cls, enum GNUNET_MQ_Error error) 255mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
254{ 256{
255 struct GNUNET_IDENTITY_Handle *h = cls; 257 struct GNUNET_IDENTITY_Handle *h = cls;
256 258
257 reschedule_connect(h); 259 reschedule_connect (h);
258} 260}
259 261
260 262
@@ -267,10 +269,10 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
267 * @return #GNUNET_OK if the message is well-formed 269 * @return #GNUNET_OK if the message is well-formed
268 */ 270 */
269static int 271static int
270check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) 272check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
271{ 273{
272 if (sizeof(*rcm) != htons(rcm->header.size)) 274 if (sizeof(*rcm) != htons (rcm->header.size))
273 GNUNET_MQ_check_zero_termination(rcm); 275 GNUNET_MQ_check_zero_termination (rcm);
274 return GNUNET_OK; 276 return GNUNET_OK;
275} 277}
276 278
@@ -282,29 +284,29 @@ check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm)
282 * @param rcm result message received 284 * @param rcm result message received
283 */ 285 */
284static void 286static void
285handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) 287handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
286{ 288{
287 struct GNUNET_IDENTITY_Handle *h = cls; 289 struct GNUNET_IDENTITY_Handle *h = cls;
288 struct GNUNET_IDENTITY_Operation *op; 290 struct GNUNET_IDENTITY_Operation *op;
289 uint16_t size = ntohs(rcm->header.size) - sizeof(*rcm); 291 uint16_t size = ntohs (rcm->header.size) - sizeof(*rcm);
290 const char *str = (0 == size) ? NULL : (const char *)&rcm[1]; 292 const char *str = (0 == size) ? NULL : (const char *) &rcm[1];
291 293
292 op = h->op_head; 294 op = h->op_head;
293 if (NULL == op) 295 if (NULL == op)
294 { 296 {
295 GNUNET_break(0); 297 GNUNET_break (0);
296 reschedule_connect(h); 298 reschedule_connect (h);
297 return; 299 return;
298 } 300 }
299 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); 301 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
300 if (NULL != op->cont) 302 if (NULL != op->cont)
301 op->cont(op->cls, str); 303 op->cont (op->cls, str);
302 else if (NULL != op->cb) 304 else if (NULL != op->cb)
303 op->cb(op->cls, NULL, NULL, NULL); 305 op->cb (op->cls, NULL, NULL, NULL);
304 else if (NULL != op->create_cont) 306 else if (NULL != op->create_cont)
305 op->create_cont(op->cls, (NULL == str) ? op->pk : NULL, str); 307 op->create_cont (op->cls, (NULL == str) ? op->pk : NULL, str);
306 GNUNET_free_non_null(op->pk); 308 GNUNET_free_non_null (op->pk);
307 GNUNET_free(op); 309 GNUNET_free (op);
308} 310}
309 311
310 312
@@ -316,18 +318,18 @@ handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm)
316 * @return #GNUNET_OK if the message is well-formed 318 * @return #GNUNET_OK if the message is well-formed
317 */ 319 */
318static int 320static int
319check_identity_update(void *cls, const struct UpdateMessage *um) 321check_identity_update (void *cls, const struct UpdateMessage *um)
320{ 322{
321 uint16_t size = ntohs(um->header.size); 323 uint16_t size = ntohs (um->header.size);
322 uint16_t name_len = ntohs(um->name_len); 324 uint16_t name_len = ntohs (um->name_len);
323 const char *str = (const char *)&um[1]; 325 const char *str = (const char *) &um[1];
324 326
325 if ((size != name_len + sizeof(struct UpdateMessage)) || 327 if ((size != name_len + sizeof(struct UpdateMessage)) ||
326 ((0 != name_len) && ('\0' != str[name_len - 1]))) 328 ((0 != name_len) && ('\0' != str[name_len - 1])))
327 { 329 {
328 GNUNET_break(0); 330 GNUNET_break (0);
329 return GNUNET_SYSERR; 331 return GNUNET_SYSERR;
330 } 332 }
331 return GNUNET_OK; 333 return GNUNET_OK;
332} 334}
333 335
@@ -339,70 +341,70 @@ check_identity_update(void *cls, const struct UpdateMessage *um)
339 * @param um message received 341 * @param um message received
340 */ 342 */
341static void 343static void
342handle_identity_update(void *cls, const struct UpdateMessage *um) 344handle_identity_update (void *cls, const struct UpdateMessage *um)
343{ 345{
344 struct GNUNET_IDENTITY_Handle *h = cls; 346 struct GNUNET_IDENTITY_Handle *h = cls;
345 uint16_t name_len = ntohs(um->name_len); 347 uint16_t name_len = ntohs (um->name_len);
346 const char *str = (0 == name_len) ? NULL : (const char *)&um[1]; 348 const char *str = (0 == name_len) ? NULL : (const char *) &um[1];
347 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 349 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
348 struct GNUNET_HashCode id; 350 struct GNUNET_HashCode id;
349 struct GNUNET_IDENTITY_Ego *ego; 351 struct GNUNET_IDENTITY_Ego *ego;
350 352
351 if (GNUNET_YES == ntohs(um->end_of_list)) 353 if (GNUNET_YES == ntohs (um->end_of_list))
352 { 354 {
353 /* end of initial list of data */ 355 /* end of initial list of data */
354 if (NULL != h->cb) 356 if (NULL != h->cb)
355 h->cb(h->cb_cls, NULL, NULL, NULL); 357 h->cb (h->cb_cls, NULL, NULL, NULL);
356 return; 358 return;
357 } 359 }
358 GNUNET_CRYPTO_ecdsa_key_get_public(&um->private_key, &pub); 360 GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub);
359 GNUNET_CRYPTO_hash(&pub, sizeof(pub), &id); 361 GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id);
360 ego = GNUNET_CONTAINER_multihashmap_get(h->egos, &id); 362 ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id);
361 if (NULL == ego) 363 if (NULL == ego)
364 {
365 /* ego was created */
366 if (NULL == str)
362 { 367 {
363 /* ego was created */ 368 /* deletion of unknown ego? not allowed */
364 if (NULL == str) 369 GNUNET_break (0);
365 { 370 reschedule_connect (h);
366 /* deletion of unknown ego? not allowed */ 371 return;
367 GNUNET_break(0);
368 reschedule_connect(h);
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 } 372 }
373 ego = GNUNET_new (struct GNUNET_IDENTITY_Ego);
374 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
375 *ego->pk = um->private_key;
376 ego->name = GNUNET_strdup (str);
377 ego->id = id;
378 GNUNET_assert (GNUNET_YES ==
379 GNUNET_CONTAINER_multihashmap_put (
380 h->egos,
381 &ego->id,
382 ego,
383 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
384 }
383 if (NULL == str) 385 if (NULL == str)
384 { 386 {
385 /* ego was deleted */ 387 /* ego was deleted */
386 GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(h->egos, 388 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (h->egos,
387 &ego->id, 389 &ego->id,
388 ego)); 390 ego));
389 } 391 }
390 else 392 else
391 { 393 {
392 /* ego changed name */ 394 /* ego changed name */
393 GNUNET_free(ego->name); 395 GNUNET_free (ego->name);
394 ego->name = GNUNET_strdup(str); 396 ego->name = GNUNET_strdup (str);
395 } 397 }
396 /* inform application about change */ 398 /* inform application about change */
397 if (NULL != h->cb) 399 if (NULL != h->cb)
398 h->cb(h->cb_cls, ego, &ego->ctx, str); 400 h->cb (h->cb_cls, ego, &ego->ctx, str);
399 /* complete deletion */ 401 /* complete deletion */
400 if (NULL == str) 402 if (NULL == str)
401 { 403 {
402 GNUNET_free(ego->pk); 404 GNUNET_free (ego->pk);
403 GNUNET_free(ego->name); 405 GNUNET_free (ego->name);
404 GNUNET_free(ego); 406 GNUNET_free (ego);
405 } 407 }
406} 408}
407 409
408 410
@@ -415,18 +417,18 @@ handle_identity_update(void *cls, const struct UpdateMessage *um)
415 * @return #GNUNET_OK if the message is well-formed 417 * @return #GNUNET_OK if the message is well-formed
416 */ 418 */
417static int 419static int
418check_identity_set_default(void *cls, const struct SetDefaultMessage *sdm) 420check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
419{ 421{
420 uint16_t size = ntohs(sdm->header.size) - sizeof(*sdm); 422 uint16_t size = ntohs (sdm->header.size) - sizeof(*sdm);
421 uint16_t name_len = ntohs(sdm->name_len); 423 uint16_t name_len = ntohs (sdm->name_len);
422 const char *str = (const char *)&sdm[1]; 424 const char *str = (const char *) &sdm[1];
423 425
424 if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1]))) 426 if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1])))
425 { 427 {
426 GNUNET_break(0); 428 GNUNET_break (0);
427 return GNUNET_SYSERR; 429 return GNUNET_SYSERR;
428 } 430 }
429 GNUNET_break(0 == ntohs(sdm->reserved)); 431 GNUNET_break (0 == ntohs (sdm->reserved));
430 return GNUNET_OK; 432 return GNUNET_OK;
431} 433}
432 434
@@ -439,7 +441,7 @@ check_identity_set_default(void *cls, const struct SetDefaultMessage *sdm)
439 * @param sdm message received 441 * @param sdm message received
440 */ 442 */
441static void 443static void
442handle_identity_set_default(void *cls, const struct SetDefaultMessage *sdm) 444handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
443{ 445{
444 struct GNUNET_IDENTITY_Handle *h = cls; 446 struct GNUNET_IDENTITY_Handle *h = cls;
445 struct GNUNET_IDENTITY_Operation *op; 447 struct GNUNET_IDENTITY_Operation *op;
@@ -447,28 +449,28 @@ handle_identity_set_default(void *cls, const struct SetDefaultMessage *sdm)
447 struct GNUNET_HashCode id; 449 struct GNUNET_HashCode id;
448 struct GNUNET_IDENTITY_Ego *ego; 450 struct GNUNET_IDENTITY_Ego *ego;
449 451
450 GNUNET_CRYPTO_ecdsa_key_get_public(&sdm->private_key, &pub); 452 GNUNET_CRYPTO_ecdsa_key_get_public (&sdm->private_key, &pub);
451 GNUNET_CRYPTO_hash(&pub, sizeof(pub), &id); 453 GNUNET_CRYPTO_hash (&pub, sizeof(pub), &id);
452 ego = GNUNET_CONTAINER_multihashmap_get(h->egos, &id); 454 ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id);
453 if (NULL == ego) 455 if (NULL == ego)
454 { 456 {
455 GNUNET_break(0); 457 GNUNET_break (0);
456 reschedule_connect(h); 458 reschedule_connect (h);
457 return; 459 return;
458 } 460 }
459 op = h->op_head; 461 op = h->op_head;
460 if (NULL == op) 462 if (NULL == op)
461 { 463 {
462 GNUNET_break(0); 464 GNUNET_break (0);
463 reschedule_connect(h); 465 reschedule_connect (h);
464 return; 466 return;
465 } 467 }
466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
467 "Received SET_DEFAULT message from identity service\n"); 469 "Received SET_DEFAULT message from identity service\n");
468 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); 470 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
469 if (NULL != op->cb) 471 if (NULL != op->cb)
470 op->cb(op->cls, ego, &ego->ctx, ego->name); 472 op->cb (op->cls, ego, &ego->ctx, ego->name);
471 GNUNET_free(op); 473 GNUNET_free (op);
472} 474}
473 475
474 476
@@ -478,38 +480,38 @@ handle_identity_set_default(void *cls, const struct SetDefaultMessage *sdm)
478 * @param cls handle to the identity service. 480 * @param cls handle to the identity service.
479 */ 481 */
480static void 482static void
481reconnect(void *cls) 483reconnect (void *cls)
482{ 484{
483 struct GNUNET_IDENTITY_Handle *h = cls; 485 struct GNUNET_IDENTITY_Handle *h = cls;
484 struct GNUNET_MQ_MessageHandler handlers[] = 486 struct GNUNET_MQ_MessageHandler handlers[] =
485 { GNUNET_MQ_hd_var_size(identity_result_code, 487 { GNUNET_MQ_hd_var_size (identity_result_code,
486 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, 488 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
487 struct ResultCodeMessage, 489 struct ResultCodeMessage,
488 h), 490 h),
489 GNUNET_MQ_hd_var_size(identity_update, 491 GNUNET_MQ_hd_var_size (identity_update,
490 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, 492 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE,
491 struct UpdateMessage, 493 struct UpdateMessage,
492 h), 494 h),
493 GNUNET_MQ_hd_var_size(identity_set_default, 495 GNUNET_MQ_hd_var_size (identity_set_default,
494 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 496 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
495 struct SetDefaultMessage, 497 struct SetDefaultMessage,
496 h), 498 h),
497 GNUNET_MQ_handler_end() }; 499 GNUNET_MQ_handler_end () };
498 struct GNUNET_MQ_Envelope *env; 500 struct GNUNET_MQ_Envelope *env;
499 struct GNUNET_MessageHeader *msg; 501 struct GNUNET_MessageHeader *msg;
500 502
501 h->reconnect_task = NULL; 503 h->reconnect_task = NULL;
502 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n"); 504 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n");
503 GNUNET_assert(NULL == h->mq); 505 GNUNET_assert (NULL == h->mq);
504 h->mq = 506 h->mq =
505 GNUNET_CLIENT_connect(h->cfg, "identity", handlers, &mq_error_handler, h); 507 GNUNET_CLIENT_connect (h->cfg, "identity", handlers, &mq_error_handler, h);
506 if (NULL == h->mq) 508 if (NULL == h->mq)
507 return; 509 return;
508 if (NULL != h->cb) 510 if (NULL != h->cb)
509 { 511 {
510 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_IDENTITY_START); 512 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_IDENTITY_START);
511 GNUNET_MQ_send(h->mq, env); 513 GNUNET_MQ_send (h->mq, env);
512 } 514 }
513} 515}
514 516
515 517
@@ -522,23 +524,23 @@ reconnect(void *cls)
522 * @return handle to use 524 * @return handle to use
523 */ 525 */
524struct GNUNET_IDENTITY_Handle * 526struct GNUNET_IDENTITY_Handle *
525GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, 527GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
526 GNUNET_IDENTITY_Callback cb, 528 GNUNET_IDENTITY_Callback cb,
527 void *cb_cls) 529 void *cb_cls)
528{ 530{
529 struct GNUNET_IDENTITY_Handle *h; 531 struct GNUNET_IDENTITY_Handle *h;
530 532
531 h = GNUNET_new(struct GNUNET_IDENTITY_Handle); 533 h = GNUNET_new (struct GNUNET_IDENTITY_Handle);
532 h->cfg = cfg; 534 h->cfg = cfg;
533 h->cb = cb; 535 h->cb = cb;
534 h->cb_cls = cb_cls; 536 h->cb_cls = cb_cls;
535 h->egos = GNUNET_CONTAINER_multihashmap_create(16, GNUNET_YES); 537 h->egos = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
536 reconnect(h); 538 reconnect (h);
537 if (NULL == h->mq) 539 if (NULL == h->mq)
538 { 540 {
539 GNUNET_free(h); 541 GNUNET_free (h);
540 return NULL; 542 return NULL;
541 } 543 }
542 return h; 544 return h;
543} 545}
544 546
@@ -550,7 +552,7 @@ GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg,
550 * @return associated ECC key, valid as long as the ego is valid 552 * @return associated ECC key, valid as long as the ego is valid
551 */ 553 */
552const struct GNUNET_CRYPTO_EcdsaPrivateKey * 554const struct GNUNET_CRYPTO_EcdsaPrivateKey *
553GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego) 555GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego)
554{ 556{
555 return ego->pk; 557 return ego->pk;
556} 558}
@@ -563,10 +565,10 @@ GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
563 * @param pk set to ego's public key 565 * @param pk set to ego's public key
564 */ 566 */
565void 567void
566GNUNET_IDENTITY_ego_get_public_key(const struct GNUNET_IDENTITY_Ego *ego, 568GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego,
567 struct GNUNET_CRYPTO_EcdsaPublicKey *pk) 569 struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
568{ 570{
569 GNUNET_CRYPTO_ecdsa_key_get_public(ego->pk, pk); 571 GNUNET_CRYPTO_ecdsa_key_get_public (ego->pk, pk);
570} 572}
571 573
572 574
@@ -581,10 +583,10 @@ GNUNET_IDENTITY_ego_get_public_key(const struct GNUNET_IDENTITY_Ego *ego,
581 * @return handle to abort the operation 583 * @return handle to abort the operation
582 */ 584 */
583struct GNUNET_IDENTITY_Operation * 585struct GNUNET_IDENTITY_Operation *
584GNUNET_IDENTITY_get(struct GNUNET_IDENTITY_Handle *h, 586GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h,
585 const char *service_name, 587 const char *service_name,
586 GNUNET_IDENTITY_Callback cb, 588 GNUNET_IDENTITY_Callback cb,
587 void *cb_cls) 589 void *cb_cls)
588{ 590{
589 struct GNUNET_IDENTITY_Operation *op; 591 struct GNUNET_IDENTITY_Operation *op;
590 struct GNUNET_MQ_Envelope *env; 592 struct GNUNET_MQ_Envelope *env;
@@ -593,24 +595,24 @@ GNUNET_IDENTITY_get(struct GNUNET_IDENTITY_Handle *h,
593 595
594 if (NULL == h->mq) 596 if (NULL == h->mq)
595 return NULL; 597 return NULL;
596 GNUNET_assert(NULL != h->cb); 598 GNUNET_assert (NULL != h->cb);
597 slen = strlen(service_name) + 1; 599 slen = strlen (service_name) + 1;
598 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GetDefaultMessage)) 600 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GetDefaultMessage))
599 { 601 {
600 GNUNET_break(0); 602 GNUNET_break (0);
601 return NULL; 603 return NULL;
602 } 604 }
603 op = GNUNET_new(struct GNUNET_IDENTITY_Operation); 605 op = GNUNET_new (struct GNUNET_IDENTITY_Operation);
604 op->h = h; 606 op->h = h;
605 op->cb = cb; 607 op->cb = cb;
606 op->cls = cb_cls; 608 op->cls = cb_cls;
607 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); 609 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
608 env = 610 env =
609 GNUNET_MQ_msg_extra(gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT); 611 GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT);
610 gdm->name_len = htons(slen); 612 gdm->name_len = htons (slen);
611 gdm->reserved = htons(0); 613 gdm->reserved = htons (0);
612 GNUNET_memcpy(&gdm[1], service_name, slen); 614 GNUNET_memcpy (&gdm[1], service_name, slen);
613 GNUNET_MQ_send(h->mq, env); 615 GNUNET_MQ_send (h->mq, env);
614 return op; 616 return op;
615} 617}
616 618
@@ -626,11 +628,11 @@ GNUNET_IDENTITY_get(struct GNUNET_IDENTITY_Handle *h,
626 * @return handle to abort the operation 628 * @return handle to abort the operation
627 */ 629 */
628struct GNUNET_IDENTITY_Operation * 630struct GNUNET_IDENTITY_Operation *
629GNUNET_IDENTITY_set(struct GNUNET_IDENTITY_Handle *h, 631GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
630 const char *service_name, 632 const char *service_name,
631 struct GNUNET_IDENTITY_Ego *ego, 633 struct GNUNET_IDENTITY_Ego *ego,
632 GNUNET_IDENTITY_Continuation cont, 634 GNUNET_IDENTITY_Continuation cont,
633 void *cont_cls) 635 void *cont_cls)
634{ 636{
635 struct GNUNET_IDENTITY_Operation *op; 637 struct GNUNET_IDENTITY_Operation *op;
636 struct GNUNET_MQ_Envelope *env; 638 struct GNUNET_MQ_Envelope *env;
@@ -639,25 +641,25 @@ GNUNET_IDENTITY_set(struct GNUNET_IDENTITY_Handle *h,
639 641
640 if (NULL == h->mq) 642 if (NULL == h->mq)
641 return NULL; 643 return NULL;
642 GNUNET_assert(NULL != h->cb); 644 GNUNET_assert (NULL != h->cb);
643 slen = strlen(service_name) + 1; 645 slen = strlen (service_name) + 1;
644 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct SetDefaultMessage)) 646 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct SetDefaultMessage))
645 { 647 {
646 GNUNET_break(0); 648 GNUNET_break (0);
647 return NULL; 649 return NULL;
648 } 650 }
649 op = GNUNET_new(struct GNUNET_IDENTITY_Operation); 651 op = GNUNET_new (struct GNUNET_IDENTITY_Operation);
650 op->h = h; 652 op->h = h;
651 op->cont = cont; 653 op->cont = cont;
652 op->cls = cont_cls; 654 op->cls = cont_cls;
653 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); 655 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
654 env = 656 env =
655 GNUNET_MQ_msg_extra(sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); 657 GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
656 sdm->name_len = htons(slen); 658 sdm->name_len = htons (slen);
657 sdm->reserved = htons(0); 659 sdm->reserved = htons (0);
658 sdm->private_key = *ego->pk; 660 sdm->private_key = *ego->pk;
659 GNUNET_memcpy(&sdm[1], service_name, slen); 661 GNUNET_memcpy (&sdm[1], service_name, slen);
660 GNUNET_MQ_send(h->mq, env); 662 GNUNET_MQ_send (h->mq, env);
661 return op; 663 return op;
662} 664}
663 665
@@ -672,10 +674,10 @@ GNUNET_IDENTITY_set(struct GNUNET_IDENTITY_Handle *h,
672 * @return handle to abort the operation 674 * @return handle to abort the operation
673 */ 675 */
674struct GNUNET_IDENTITY_Operation * 676struct GNUNET_IDENTITY_Operation *
675GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h, 677GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
676 const char *name, 678 const char *name,
677 GNUNET_IDENTITY_CreateContinuation cont, 679 GNUNET_IDENTITY_CreateContinuation cont,
678 void *cont_cls) 680 void *cont_cls)
679{ 681{
680 struct GNUNET_IDENTITY_Operation *op; 682 struct GNUNET_IDENTITY_Operation *op;
681 struct GNUNET_MQ_Envelope *env; 683 struct GNUNET_MQ_Envelope *env;
@@ -685,25 +687,25 @@ GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h,
685 687
686 if (NULL == h->mq) 688 if (NULL == h->mq)
687 return NULL; 689 return NULL;
688 slen = strlen(name) + 1; 690 slen = strlen (name) + 1;
689 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct CreateRequestMessage)) 691 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct CreateRequestMessage))
690 { 692 {
691 GNUNET_break(0); 693 GNUNET_break (0);
692 return NULL; 694 return NULL;
693 } 695 }
694 op = GNUNET_new(struct GNUNET_IDENTITY_Operation); 696 op = GNUNET_new (struct GNUNET_IDENTITY_Operation);
695 op->h = h; 697 op->h = h;
696 op->create_cont = cont; 698 op->create_cont = cont;
697 op->cls = cont_cls; 699 op->cls = cont_cls;
698 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); 700 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
699 env = GNUNET_MQ_msg_extra(crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); 701 env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
700 crm->name_len = htons(slen); 702 crm->name_len = htons (slen);
701 crm->reserved = htons(0); 703 crm->reserved = htons (0);
702 pk = GNUNET_CRYPTO_ecdsa_key_create(); 704 pk = GNUNET_CRYPTO_ecdsa_key_create ();
703 crm->private_key = *pk; 705 crm->private_key = *pk;
704 op->pk = pk; 706 op->pk = pk;
705 GNUNET_memcpy(&crm[1], name, slen); 707 GNUNET_memcpy (&crm[1], name, slen);
706 GNUNET_MQ_send(h->mq, env); 708 GNUNET_MQ_send (h->mq, env);
707 return op; 709 return op;
708} 710}
709 711
@@ -719,11 +721,11 @@ GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *h,
719 * @return handle to abort the operation 721 * @return handle to abort the operation
720 */ 722 */
721struct GNUNET_IDENTITY_Operation * 723struct GNUNET_IDENTITY_Operation *
722GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h, 724GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
723 const char *old_name, 725 const char *old_name,
724 const char *new_name, 726 const char *new_name,
725 GNUNET_IDENTITY_Continuation cb, 727 GNUNET_IDENTITY_Continuation cb,
726 void *cb_cls) 728 void *cb_cls)
727{ 729{
728 struct GNUNET_IDENTITY_Operation *op; 730 struct GNUNET_IDENTITY_Operation *op;
729 struct GNUNET_MQ_Envelope *env; 731 struct GNUNET_MQ_Envelope *env;
@@ -734,30 +736,30 @@ GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h,
734 736
735 if (NULL == h->mq) 737 if (NULL == h->mq)
736 return NULL; 738 return NULL;
737 slen_old = strlen(old_name) + 1; 739 slen_old = strlen (old_name) + 1;
738 slen_new = strlen(new_name) + 1; 740 slen_new = strlen (new_name) + 1;
739 if ((slen_old >= GNUNET_MAX_MESSAGE_SIZE) || 741 if ((slen_old >= GNUNET_MAX_MESSAGE_SIZE) ||
740 (slen_new >= GNUNET_MAX_MESSAGE_SIZE) || 742 (slen_new >= GNUNET_MAX_MESSAGE_SIZE) ||
741 (slen_old + slen_new >= 743 (slen_old + slen_new >=
742 GNUNET_MAX_MESSAGE_SIZE - sizeof(struct RenameMessage))) 744 GNUNET_MAX_MESSAGE_SIZE - sizeof(struct RenameMessage)))
743 { 745 {
744 GNUNET_break(0); 746 GNUNET_break (0);
745 return NULL; 747 return NULL;
746 } 748 }
747 op = GNUNET_new(struct GNUNET_IDENTITY_Operation); 749 op = GNUNET_new (struct GNUNET_IDENTITY_Operation);
748 op->h = h; 750 op->h = h;
749 op->cont = cb; 751 op->cont = cb;
750 op->cls = cb_cls; 752 op->cls = cb_cls;
751 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); 753 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
752 env = GNUNET_MQ_msg_extra(grm, 754 env = GNUNET_MQ_msg_extra (grm,
753 slen_old + slen_new, 755 slen_old + slen_new,
754 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME); 756 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME);
755 grm->old_name_len = htons(slen_old); 757 grm->old_name_len = htons (slen_old);
756 grm->new_name_len = htons(slen_new); 758 grm->new_name_len = htons (slen_new);
757 dst = (char *)&grm[1]; 759 dst = (char *) &grm[1];
758 GNUNET_memcpy(dst, old_name, slen_old); 760 GNUNET_memcpy (dst, old_name, slen_old);
759 GNUNET_memcpy(&dst[slen_old], new_name, slen_new); 761 GNUNET_memcpy (&dst[slen_old], new_name, slen_new);
760 GNUNET_MQ_send(h->mq, env); 762 GNUNET_MQ_send (h->mq, env);
761 return op; 763 return op;
762} 764}
763 765
@@ -772,10 +774,10 @@ GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *h,
772 * @return handle to abort the operation 774 * @return handle to abort the operation
773 */ 775 */
774struct GNUNET_IDENTITY_Operation * 776struct GNUNET_IDENTITY_Operation *
775GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *h, 777GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h,
776 const char *name, 778 const char *name,
777 GNUNET_IDENTITY_Continuation cb, 779 GNUNET_IDENTITY_Continuation cb,
778 void *cb_cls) 780 void *cb_cls)
779{ 781{
780 struct GNUNET_IDENTITY_Operation *op; 782 struct GNUNET_IDENTITY_Operation *op;
781 struct GNUNET_MQ_Envelope *env; 783 struct GNUNET_MQ_Envelope *env;
@@ -784,22 +786,22 @@ GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *h,
784 786
785 if (NULL == h->mq) 787 if (NULL == h->mq)
786 return NULL; 788 return NULL;
787 slen = strlen(name) + 1; 789 slen = strlen (name) + 1;
788 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct DeleteMessage)) 790 if (slen >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct DeleteMessage))
789 { 791 {
790 GNUNET_break(0); 792 GNUNET_break (0);
791 return NULL; 793 return NULL;
792 } 794 }
793 op = GNUNET_new(struct GNUNET_IDENTITY_Operation); 795 op = GNUNET_new (struct GNUNET_IDENTITY_Operation);
794 op->h = h; 796 op->h = h;
795 op->cont = cb; 797 op->cont = cb;
796 op->cls = cb_cls; 798 op->cls = cb_cls;
797 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, op); 799 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
798 env = GNUNET_MQ_msg_extra(gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE); 800 env = GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE);
799 gdm->name_len = htons(slen); 801 gdm->name_len = htons (slen);
800 gdm->reserved = htons(0); 802 gdm->reserved = htons (0);
801 GNUNET_memcpy(&gdm[1], name, slen); 803 GNUNET_memcpy (&gdm[1], name, slen);
802 GNUNET_MQ_send(h->mq, env); 804 GNUNET_MQ_send (h->mq, env);
803 return op; 805 return op;
804} 806}
805 807
@@ -813,16 +815,16 @@ GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *h,
813 * @param op operation to cancel 815 * @param op operation to cancel
814 */ 816 */
815void 817void
816GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op) 818GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op)
817{ 819{
818 op->cont = NULL; 820 op->cont = NULL;
819 op->cb = NULL; 821 op->cb = NULL;
820 op->create_cont = NULL; 822 op->create_cont = NULL;
821 if (NULL != op->pk) 823 if (NULL != op->pk)
822 { 824 {
823 GNUNET_free(op->pk); 825 GNUNET_free (op->pk);
824 op->pk = NULL; 826 op->pk = NULL;
825 } 827 }
826} 828}
827 829
828 830
@@ -832,35 +834,35 @@ GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
832 * @param h handle to destroy 834 * @param h handle to destroy
833 */ 835 */
834void 836void
835GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h) 837GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h)
836{ 838{
837 struct GNUNET_IDENTITY_Operation *op; 839 struct GNUNET_IDENTITY_Operation *op;
838 840
839 GNUNET_assert(NULL != h); 841 GNUNET_assert (NULL != h);
840 if (h->reconnect_task != NULL) 842 if (h->reconnect_task != NULL)
841 { 843 {
842 GNUNET_SCHEDULER_cancel(h->reconnect_task); 844 GNUNET_SCHEDULER_cancel (h->reconnect_task);
843 h->reconnect_task = NULL; 845 h->reconnect_task = NULL;
844 } 846 }
845 if (NULL != h->egos) 847 if (NULL != h->egos)
846 { 848 {
847 GNUNET_CONTAINER_multihashmap_iterate(h->egos, &free_ego, h); 849 GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h);
848 GNUNET_CONTAINER_multihashmap_destroy(h->egos); 850 GNUNET_CONTAINER_multihashmap_destroy (h->egos);
849 h->egos = NULL; 851 h->egos = NULL;
850 } 852 }
851 while (NULL != (op = h->op_head)) 853 while (NULL != (op = h->op_head))
852 { 854 {
853 GNUNET_break(NULL == op->cont); 855 GNUNET_break (NULL == op->cont);
854 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, op); 856 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
855 GNUNET_free_non_null(op->pk); 857 GNUNET_free_non_null (op->pk);
856 GNUNET_free(op); 858 GNUNET_free (op);
857 } 859 }
858 if (NULL != h->mq) 860 if (NULL != h->mq)
859 { 861 {
860 GNUNET_MQ_destroy(h->mq); 862 GNUNET_MQ_destroy (h->mq);
861 h->mq = NULL; 863 h->mq = NULL;
862 } 864 }
863 GNUNET_free(h); 865 GNUNET_free (h);
864} 866}
865 867
866/* end of identity_api.c */ 868/* end of identity_api.c */