aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-15 21:34:40 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-15 21:34:40 +0000
commit61f77eb9e4701afedbf09b697ae6299ac00e0724 (patch)
tree80d251fc33a280e6f357f394cae762ea5fc71e84
parent2939ad56c07b0077a511fa8e6b8ce4937d891a03 (diff)
downloadgnunet-61f77eb9e4701afedbf09b697ae6299ac00e0724.tar.gz
gnunet-61f77eb9e4701afedbf09b697ae6299ac00e0724.zip
-towards handling rename/delete requests
-rw-r--r--src/identity/gnunet-service-identity.c111
1 files changed, 104 insertions, 7 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 9be5e0698..6a2686dd4 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -275,6 +275,22 @@ handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
275 275
276 276
277/** 277/**
278 * Send an updated message for the given ego to all listeners.
279 *
280 * @param ego ego to send the update for
281 */
282static void
283notify_listeners (struct Ego *ego)
284{
285 struct GNUNET_IDENTITY_UpdateMessage *um;
286
287 um = create_update_message (ego);
288 GNUNET_SERVER_notification_context_broadcast (nc, &um->header, GNUNET_YES);
289 GNUNET_free (um);
290}
291
292
293/**
278 * Handler for CREATE message from client, creates 294 * Handler for CREATE message from client, creates
279 * new identity. 295 * new identity.
280 * 296 *
@@ -308,12 +324,53 @@ static void
308handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client, 324handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
309 const struct GNUNET_MessageHeader *message) 325 const struct GNUNET_MessageHeader *message)
310{ 326{
327 const struct GNUNET_IDENTITY_RenameMessage *rm;
328 uint16_t size;
329 uint16_t old_name_len;
330 uint16_t new_name_len;
331 struct Ego *ego;
332 const char *old_name;
333 const char *new_name;
334
311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
312 "Received RENAME message from client\n"); 336 "Received RENAME message from client\n");
313 // setup_estimate_message (&em); 337 size = ntohs (message->size);
314 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES); 338 if (size <= sizeof (struct GNUNET_IDENTITY_RenameMessage))
315 GNUNET_break (0); // not implemented! 339 {
316 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 340 GNUNET_break (0);
341 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
342 return;
343 }
344 rm = (const struct GNUNET_IDENTITY_RenameMessage *) message;
345 old_name_len = ntohs (rm->old_name_len);
346 new_name_len = ntohs (rm->new_name_len);
347 old_name = (const char *) &rm[1];
348 new_name = &old_name[old_name_len];
349 if ( (old_name_len + new_name_len + sizeof (struct GNUNET_IDENTITY_RenameMessage) != size) ||
350 ('\0' != old_name[old_name_len - 1]) ||
351 ('\0' != new_name[new_name_len - 1]) )
352 {
353 GNUNET_break (0);
354 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
355 return;
356 }
357 for (ego = ego_head; NULL != ego; ego = ego->next)
358 {
359 if (0 == strcmp (ego->identifier,
360 old_name))
361 {
362 GNUNET_free (ego->identifier);
363 ego->identifier = GNUNET_strdup (new_name);
364 /* FIXME: also rename file! */
365 notify_listeners (ego);
366 send_result_code (client, 0, NULL);
367 GNUNET_SERVER_receive_done (client, GNUNET_OK);
368 return;
369 }
370 }
371
372 send_result_code (client, 1, gettext_noop ("no matching ego found"));
373 GNUNET_SERVER_receive_done (client, GNUNET_OK);
317} 374}
318 375
319 376
@@ -329,11 +386,51 @@ static void
329handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client, 386handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
330 const struct GNUNET_MessageHeader *message) 387 const struct GNUNET_MessageHeader *message)
331{ 388{
389 const struct GNUNET_IDENTITY_DeleteMessage *dm;
390 uint16_t size;
391 uint16_t name_len;
392 struct Ego *ego;
393 const char *name;
394
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Received DELETE message from client\n"); 396 "Received DELETE message from client\n");
334 // setup_estimate_message (&em); 397 size = ntohs (message->size);
335 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES); 398 if (size <= sizeof (struct GNUNET_IDENTITY_DeleteMessage))
336 GNUNET_break (0); // not implemented! 399 {
400 GNUNET_break (0);
401 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
402 return;
403 }
404 dm = (const struct GNUNET_IDENTITY_DeleteMessage *) message;
405 name = (const char *) &dm[1];
406 name_len = ntohs (dm->name_len);
407 if ( (name_len + sizeof (struct GNUNET_IDENTITY_DeleteMessage) != size) ||
408 (0 != ntohs (dm->reserved)) ||
409 ('\0' != name[name_len - 1]) )
410 {
411 GNUNET_break (0);
412 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
413 return;
414 }
415 for (ego = ego_head; NULL != ego; ego = ego->next)
416 {
417 if (0 == strcmp (ego->identifier,
418 name))
419 {
420 GNUNET_CONTAINER_DLL_remove (ego_head,
421 ego_tail,
422 ego);
423 /* FIXME: also delete file! */
424 GNUNET_free (ego->identifier);
425 ego->identifier = NULL;
426 notify_listeners (ego);
427 GNUNET_CRYPTO_ecc_key_free (ego->pk);
428 GNUNET_free (ego);
429 send_result_code (client, 0, NULL);
430 GNUNET_SERVER_receive_done (client, GNUNET_OK);
431 return;
432 }
433 }
337 434
338 send_result_code (client, 1, gettext_noop ("no matching ego found")); 435 send_result_code (client, 1, gettext_noop ("no matching ego found"));
339 GNUNET_SERVER_receive_done (client, GNUNET_OK); 436 GNUNET_SERVER_receive_done (client, GNUNET_OK);