diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-07-15 21:40:26 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-07-15 21:40:26 +0000 |
commit | e1f35f347f36df880838d5a208d2998e218aaecf (patch) | |
tree | f604bab7d14396d948623e4101840aa52a4ef7b5 /src/identity/gnunet-service-identity.c | |
parent | 61f77eb9e4701afedbf09b697ae6299ac00e0724 (diff) | |
download | gnunet-e1f35f347f36df880838d5a208d2998e218aaecf.tar.gz gnunet-e1f35f347f36df880838d5a208d2998e218aaecf.zip |
-towards handling identifier creation
Diffstat (limited to 'src/identity/gnunet-service-identity.c')
-rw-r--r-- | src/identity/gnunet-service-identity.c | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 6a2686dd4..62485f353 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -302,12 +302,62 @@ static void | |||
302 | handle_create_message (void *cls, struct GNUNET_SERVER_Client *client, | 302 | handle_create_message (void *cls, struct GNUNET_SERVER_Client *client, |
303 | const struct GNUNET_MessageHeader *message) | 303 | const struct GNUNET_MessageHeader *message) |
304 | { | 304 | { |
305 | const struct GNUNET_IDENTITY_CreateRequestMessage *crm; | ||
306 | uint16_t size; | ||
307 | uint16_t name_len; | ||
308 | uint16_t pk_len; | ||
309 | struct Ego *ego; | ||
310 | const char *str; | ||
311 | struct GNUNET_CRYPTO_EccPrivateKey *pk; | ||
312 | |||
305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
306 | "Received CREATE message from client\n"); | 314 | "Received CREATE message from client\n"); |
307 | // setup_estimate_message (&em); | 315 | size = ntohs (message->size); |
308 | // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES); | 316 | if (size <= sizeof (struct GNUNET_IDENTITY_CreateRequestMessage)) |
309 | GNUNET_break (0); // not implemented! | 317 | { |
310 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 318 | GNUNET_break (0); |
319 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
320 | return; | ||
321 | } | ||
322 | crm = (const struct GNUNET_IDENTITY_CreateRequestMessage *) message; | ||
323 | name_len = ntohs (crm->name_len); | ||
324 | pk_len = ntohs (crm->pk_len); | ||
325 | str = (const char *) &crm[1]; | ||
326 | if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size) || | ||
327 | (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES))) ) | ||
328 | { | ||
329 | GNUNET_break (0); | ||
330 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
331 | return; | ||
332 | } | ||
333 | str = &str[pk_len]; | ||
334 | if ('\0' != str[name_len - 1]) | ||
335 | { | ||
336 | GNUNET_break (0); | ||
337 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
338 | return; | ||
339 | } | ||
340 | for (ego = ego_head; NULL != ego; ego = ego->next) | ||
341 | { | ||
342 | if (0 == strcmp (ego->identifier, | ||
343 | str)) | ||
344 | { | ||
345 | send_result_code (client, 1, gettext_noop ("identifier already in use for another ego")); | ||
346 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
347 | GNUNET_CRYPTO_ecc_key_free (pk); | ||
348 | return; | ||
349 | } | ||
350 | } | ||
351 | ego = GNUNET_new (struct Ego); | ||
352 | ego->pk = pk; | ||
353 | ego->identifier = GNUNET_strdup (str); | ||
354 | GNUNET_CONTAINER_DLL_insert (ego_head, | ||
355 | ego_tail, | ||
356 | ego); | ||
357 | send_result_code (client, 0, NULL); | ||
358 | /* FIXME: also write to file! */ | ||
359 | notify_listeners (ego); | ||
360 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
311 | } | 361 | } |
312 | 362 | ||
313 | 363 | ||