aboutsummaryrefslogtreecommitdiff
path: root/src/identity
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2016-09-28 12:43:27 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2016-09-28 12:43:27 +0000
commitbca283abc269e0794226b82d16b762ed68718a91 (patch)
tree636c93ef4e793948ab95c6a8ebbe3e3472eca95a /src/identity
parent64732cdb0d95320d9274b26fcac6e617d6473248 (diff)
downloadgnunet-bca283abc269e0794226b82d16b762ed68718a91.tar.gz
gnunet-bca283abc269e0794226b82d16b762ed68718a91.zip
-new service API
Diffstat (limited to 'src/identity')
-rw-r--r--src/identity/gnunet-service-identity.c720
-rw-r--r--src/identity/identity.h14
-rw-r--r--src/identity/identity_api.c40
3 files changed, 448 insertions, 326 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index b868719c3..fdd7cfdc1 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -87,7 +87,7 @@ static struct GNUNET_STATISTICS_Handle *stats;
87/** 87/**
88 * Notification context, simplifies client broadcasts. 88 * Notification context, simplifies client broadcasts.
89 */ 89 */
90static struct GNUNET_SERVER_NotificationContext *nc; 90static struct GNUNET_NotificationContext *nc;
91 91
92/** 92/**
93 * Directory where we store the identities. 93 * Directory where we store the identities.
@@ -129,6 +129,39 @@ get_ego_filename (struct Ego *ego)
129 return filename; 129 return filename;
130} 130}
131 131
132/**
133 * Called whenever a client is disconnected.
134 *
135 * @param cls closure
136 * @param client identification of the client
137 * @param app_ctx @a client
138 */
139static void
140client_disconnect_cb (void *cls,
141 struct GNUNET_SERVICE_Client *client,
142 void *app_ctx)
143{
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Client %p disconnected\n",
146 client);
147}
148
149
150/**
151 * Add a client to our list of active clients.
152 *
153 * @param cls NULL
154 * @param client client to add
155 * @param mq message queue for @a client
156 * @return internal namestore client structure for this client
157 */
158static void *
159client_connect_cb (void *cls,
160 struct GNUNET_SERVICE_Client *client,
161 struct GNUNET_MQ_Handle *mq)
162{
163 return client;
164}
132 165
133/** 166/**
134 * Task run during shutdown. 167 * Task run during shutdown.
@@ -142,7 +175,7 @@ shutdown_task (void *cls)
142 175
143 if (NULL != nc) 176 if (NULL != nc)
144 { 177 {
145 GNUNET_SERVER_notification_context_destroy (nc); 178 GNUNET_notification_context_destroy (nc);
146 nc = NULL; 179 nc = NULL;
147 } 180 }
148 if (NULL != stats) 181 if (NULL != stats)
@@ -174,29 +207,29 @@ shutdown_task (void *cls)
174 * @param emsg error message to include (or NULL for none) 207 * @param emsg error message to include (or NULL for none)
175 */ 208 */
176static void 209static void
177send_result_code (struct GNUNET_SERVER_Client *client, 210send_result_code (struct GNUNET_SERVICE_Client *client,
178 uint32_t result_code, 211 uint32_t result_code,
179 const char *emsg) 212 const char *emsg)
180{ 213{
181 struct GNUNET_IDENTITY_ResultCodeMessage *rcm; 214 struct ResultCodeMessage *rcm;
215 struct GNUNET_MQ_Envelope *env;
182 size_t elen; 216 size_t elen;
183 217
184 if (NULL == emsg) 218 if (NULL == emsg)
185 elen = 0; 219 elen = 0;
186 else 220 else
187 elen = strlen (emsg) + 1; 221 elen = strlen (emsg) + 1;
188 rcm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_ResultCodeMessage) + elen); 222 env = GNUNET_MQ_msg_extra (rcm,
189 rcm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE); 223 elen,
190 rcm->header.size = htons (sizeof (struct GNUNET_IDENTITY_ResultCodeMessage) + elen); 224 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
191 rcm->result_code = htonl (result_code); 225 rcm->result_code = htonl (result_code);
192 if (0 < elen) 226 if (0 < elen)
193 GNUNET_memcpy (&rcm[1], emsg, elen); 227 GNUNET_memcpy (&rcm[1], emsg, elen);
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "Sending result %d (%s) to client\n", 229 "Sending result %d (%s) to client\n",
196 (int) result_code, 230 (int) result_code,
197 emsg); 231 emsg);
198 GNUNET_SERVER_notification_context_unicast (nc, client, &rcm->header, GNUNET_NO); 232 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
199 GNUNET_free (rcm);
200} 233}
201 234
202 235
@@ -206,21 +239,22 @@ send_result_code (struct GNUNET_SERVER_Client *client,
206 * @param ego ego to create message for 239 * @param ego ego to create message for
207 * @return corresponding update message 240 * @return corresponding update message
208 */ 241 */
209static struct GNUNET_IDENTITY_UpdateMessage * 242static struct GNUNET_MQ_Envelope *
210create_update_message (struct Ego *ego) 243create_update_message (struct Ego *ego)
211{ 244{
212 struct GNUNET_IDENTITY_UpdateMessage *um; 245 struct UpdateMessage *um;
246 struct GNUNET_MQ_Envelope *env;
213 size_t name_len; 247 size_t name_len;
214 248
215 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); 249 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
216 um = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + name_len); 250 env = GNUNET_MQ_msg_extra (um,
217 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); 251 name_len,
218 um->header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage) + name_len); 252 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
219 um->name_len = htons (name_len); 253 um->name_len = htons (name_len);
220 um->end_of_list = htons (GNUNET_NO); 254 um->end_of_list = htons (GNUNET_NO);
221 um->private_key = *ego->pk; 255 um->private_key = *ego->pk;
222 GNUNET_memcpy (&um[1], ego->identifier, name_len); 256 GNUNET_memcpy (&um[1], ego->identifier, name_len);
223 return um; 257 return env;
224} 258}
225 259
226 260
@@ -231,22 +265,23 @@ create_update_message (struct Ego *ego)
231 * @param servicename name of the service to provide in the message 265 * @param servicename name of the service to provide in the message
232 * @return corresponding set default message 266 * @return corresponding set default message
233 */ 267 */
234static struct GNUNET_IDENTITY_SetDefaultMessage * 268static struct GNUNET_MQ_Envelope *
235create_set_default_message (struct Ego *ego, 269create_set_default_message (struct Ego *ego,
236 const char *servicename) 270 const char *servicename)
237{ 271{
238 struct GNUNET_IDENTITY_SetDefaultMessage *sdm; 272 struct SetDefaultMessage *sdm;
273 struct GNUNET_MQ_Envelope *env;
239 size_t name_len; 274 size_t name_len;
240 275
241 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1); 276 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
242 sdm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + name_len); 277 env = GNUNET_MQ_msg_extra (sdm,
243 sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); 278 name_len,
244 sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + name_len); 279 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
245 sdm->name_len = htons (name_len); 280 sdm->name_len = htons (name_len);
246 sdm->reserved = htons (0); 281 sdm->reserved = htons (0);
247 sdm->private_key = *ego->pk; 282 sdm->private_key = *ego->pk;
248 GNUNET_memcpy (&sdm[1], servicename, name_len); 283 GNUNET_memcpy (&sdm[1], servicename, name_len);
249 return sdm; 284 return env;
250} 285}
251 286
252 287
@@ -261,29 +296,65 @@ create_set_default_message (struct Ego *ego,
261 * @param message the message received 296 * @param message the message received
262 */ 297 */
263static void 298static void
264handle_start_message (void *cls, struct GNUNET_SERVER_Client *client, 299handle_start_message (void *cls,
265 const struct GNUNET_MessageHeader *message) 300 const struct GNUNET_MessageHeader *message)
266{ 301{
267 struct GNUNET_IDENTITY_UpdateMessage *um; 302 struct UpdateMessage *ume;
268 struct GNUNET_IDENTITY_UpdateMessage ume; 303 struct GNUNET_SERVICE_Client *client = cls;
304 struct GNUNET_MQ_Envelope *env;
269 struct Ego *ego; 305 struct Ego *ego;
270 306
271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
272 "Received START message from client\n"); 308 "Received START message from client\n");
273 GNUNET_SERVER_notification_context_add (nc, client); 309 GNUNET_SERVICE_client_mark_monitor (client);
310 GNUNET_SERVICE_client_disable_continue_warning (client);
311 GNUNET_notification_context_add (nc,
312 GNUNET_SERVICE_client_get_mq(client));
274 for (ego = ego_head; NULL != ego; ego = ego->next) 313 for (ego = ego_head; NULL != ego; ego = ego->next)
275 { 314 {
276 um = create_update_message (ego); 315 env = create_update_message (ego);
277 GNUNET_SERVER_notification_context_unicast (nc, client, &um->header, GNUNET_NO); 316 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(client), env);
278 GNUNET_free (um); 317 }
318 env = GNUNET_MQ_msg_extra (ume,
319 0,
320 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
321 ume->end_of_list = htons (GNUNET_YES);
322 ume->name_len = htons (0);
323 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(client), env);
324 GNUNET_SERVICE_client_continue (client);
325}
326
327/**
328 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message
329 *
330 * @param cls client sending the message
331 * @param msg message of type `struct GetDefaultMessage`
332 * @return #GNUNET_OK if @a msg is well-formed
333 */
334static int
335check_get_default_message (void *cls,
336 const struct GetDefaultMessage *msg)
337{
338 uint16_t size;
339 uint16_t name_len;
340 const char *name;
341
342 size = ntohs (msg->header.size);
343 if (size <= sizeof (struct GetDefaultMessage))
344 {
345 GNUNET_break (0);
346 return GNUNET_SYSERR;
347 }
348 name = (const char *) &msg[1];
349 name_len = ntohs (msg->name_len);
350 if ( (name_len + sizeof (struct GetDefaultMessage) != size) ||
351 (0 != ntohs (msg->reserved)) ||
352 ('\0' != name[name_len - 1]) )
353 {
354 GNUNET_break (0);
355 return GNUNET_SYSERR;
279 } 356 }
280 memset (&ume, 0, sizeof (ume)); 357 return GNUNET_OK;
281 ume.header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
282 ume.header.size = htons (sizeof (struct GNUNET_IDENTITY_UpdateMessage));
283 ume.end_of_list = htons (GNUNET_YES);
284 ume.name_len = htons (0);
285 GNUNET_SERVER_notification_context_unicast (nc, client, &ume.header, GNUNET_NO);
286 GNUNET_SERVER_receive_done (client, GNUNET_OK);
287} 358}
288 359
289 360
@@ -296,70 +367,50 @@ handle_start_message (void *cls, struct GNUNET_SERVER_Client *client,
296 * @param message the message received 367 * @param message the message received
297 */ 368 */
298static void 369static void
299handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client, 370handle_get_default_message (void *cls,
300 const struct GNUNET_MessageHeader *message) 371 const struct GetDefaultMessage *gdm)
301{ 372{
302 const struct GNUNET_IDENTITY_GetDefaultMessage *gdm; 373 struct GNUNET_MQ_Envelope *env;
303 struct GNUNET_IDENTITY_SetDefaultMessage *sdm; 374 struct GNUNET_SERVICE_Client *client = cls;
304 uint16_t size;
305 uint16_t name_len;
306 struct Ego *ego; 375 struct Ego *ego;
307 const char *name; 376 const char *name;
308 char *identifier; 377 char *identifier;
309 378
310 size = ntohs (message->size); 379
311 if (size <= sizeof (struct GNUNET_IDENTITY_GetDefaultMessage))
312 {
313 GNUNET_break (0);
314 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
315 return;
316 }
317 gdm = (const struct GNUNET_IDENTITY_GetDefaultMessage *) message;
318 name = (const char *) &gdm[1]; 380 name = (const char *) &gdm[1];
319 name_len = ntohs (gdm->name_len);
320 if ( (name_len + sizeof (struct GNUNET_IDENTITY_GetDefaultMessage) != size) ||
321 (0 != ntohs (gdm->reserved)) ||
322 ('\0' != name[name_len - 1]) )
323 {
324 GNUNET_break (0);
325 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
326 return;
327 }
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
329 "Received GET_DEFAULT for service `%s' from client\n", 382 "Received GET_DEFAULT for service `%s' from client\n",
330 name); 383 name);
331 if (GNUNET_OK != 384 if (GNUNET_OK !=
332 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 385 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
333 name, 386 name,
334 "DEFAULT_IDENTIFIER", 387 "DEFAULT_IDENTIFIER",
335 &identifier)) 388 &identifier))
336 { 389 {
337 send_result_code (client, 1, gettext_noop ("no default known")); 390 send_result_code (client, 1, gettext_noop ("no default known"));
338 GNUNET_SERVER_receive_done (client, GNUNET_OK); 391 GNUNET_SERVICE_client_continue (client);
339 return; 392 return;
340 } 393 }
341 for (ego = ego_head; NULL != ego; ego = ego->next) 394 for (ego = ego_head; NULL != ego; ego = ego->next)
342 { 395 {
343 if (0 == strcmp (ego->identifier, 396 if (0 == strcmp (ego->identifier,
344 identifier)) 397 identifier))
345 { 398 {
346 sdm = create_set_default_message (ego, 399 env = create_set_default_message (ego,
347 name); 400 name);
348 GNUNET_SERVER_notification_context_unicast (nc, client, 401 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
349 &sdm->header, GNUNET_NO); 402 GNUNET_SERVICE_client_continue (client);
350 GNUNET_free (sdm);
351 GNUNET_SERVER_receive_done (client, GNUNET_OK);
352 GNUNET_free (identifier); 403 GNUNET_free (identifier);
353 return; 404 return;
354 } 405 }
355 } 406 }
356 GNUNET_free (identifier); 407 GNUNET_free (identifier);
357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
358 "Failed to find ego `%s'\n", 409 "Failed to find ego `%s'\n",
359 name); 410 name);
360 send_result_code (client, 1, 411 send_result_code (client, 1,
361 gettext_noop ("default configured, but ego unknown (internal error)")); 412 gettext_noop ("default configured, but ego unknown (internal error)"));
362 GNUNET_SERVER_receive_done (client, GNUNET_OK); 413 GNUNET_SERVICE_client_continue (client);
363} 414}
364 415
365 416
@@ -372,78 +423,90 @@ handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
372 */ 423 */
373static int 424static int
374key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, 425key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
375 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2) 426 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2)
376{ 427{
377 return memcmp (pk1, pk2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); 428 return memcmp (pk1, pk2, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey));
378} 429}
379 430
380
381/** 431/**
382 * Handler for SET_DEFAULT message from client, updates 432 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT message
383 * default identity for some service.
384 * 433 *
385 * @param cls unused 434 * @param cls client sending the message
386 * @param client who sent the message 435 * @param msg message of type `struct SetDefaultMessage`
387 * @param message the message received 436 * @return #GNUNET_OK if @a msg is well-formed
388 */ 437 */
389static void 438static int
390handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client, 439check_set_default_message (void *cls,
391 const struct GNUNET_MessageHeader *message) 440 const struct SetDefaultMessage *msg)
392{ 441{
393 const struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
394 uint16_t size; 442 uint16_t size;
395 uint16_t name_len; 443 uint16_t name_len;
396 struct Ego *ego;
397 const char *str; 444 const char *str;
398 445
399 size = ntohs (message->size); 446 size = ntohs (msg->header.size);
400 if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) 447 if (size <= sizeof (struct SetDefaultMessage))
401 { 448 {
402 GNUNET_break (0); 449 GNUNET_break (0);
403 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 450 return GNUNET_SYSERR;
404 return;
405 } 451 }
406 sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) message; 452 name_len = ntohs (msg->name_len);
407 name_len = ntohs (sdm->name_len); 453 GNUNET_break (0 == ntohs (msg->reserved));
408 GNUNET_break (0 == ntohs (sdm->reserved)); 454 if (name_len + sizeof (struct SetDefaultMessage) != size)
409 if (name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size)
410 { 455 {
411 GNUNET_break (0); 456 GNUNET_break (0);
412 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 457 return GNUNET_SYSERR;
413 return;
414 } 458 }
415 str = (const char *) &sdm[1]; 459 str = (const char *) &msg[1];
416 if ('\0' != str[name_len - 1]) 460 if ('\0' != str[name_len - 1])
417 { 461 {
418 GNUNET_break (0); 462 GNUNET_break (0);
419 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 463 return GNUNET_SYSERR;
420 return;
421 } 464 }
465 return GNUNET_OK;
466}
467
468/**
469 * Handler for SET_DEFAULT message from client, updates
470 * default identity for some service.
471 *
472 * @param cls unused
473 * @param client who sent the message
474 * @param message the message received
475 */
476static void
477handle_set_default_message (void *cls,
478 const struct SetDefaultMessage *sdm)
479{
480 struct Ego *ego;
481 struct GNUNET_SERVICE_Client *client = cls;
482 const char *str;
483
484 str = (const char *) &sdm[1];
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
423 "Received SET_DEFAULT for service `%s' from client\n", 486 "Received SET_DEFAULT for service `%s' from client\n",
424 str); 487 str);
425 for (ego = ego_head; NULL != ego; ego = ego->next) 488 for (ego = ego_head; NULL != ego; ego = ego->next)
426 { 489 {
427 if (0 == key_cmp (ego->pk, 490 if (0 == key_cmp (ego->pk,
428 &sdm->private_key)) 491 &sdm->private_key))
429 { 492 {
430 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 493 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
431 str, 494 str,
432 "DEFAULT_IDENTIFIER", 495 "DEFAULT_IDENTIFIER",
433 ego->identifier); 496 ego->identifier);
434 if (GNUNET_OK != 497 if (GNUNET_OK !=
435 GNUNET_CONFIGURATION_write (subsystem_cfg, 498 GNUNET_CONFIGURATION_write (subsystem_cfg,
436 subsystem_cfg_file)) 499 subsystem_cfg_file))
437 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 500 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
438 _("Failed to write subsystem default identifier map to `%s'.\n"), 501 _("Failed to write subsystem default identifier map to `%s'.\n"),
439 subsystem_cfg_file); 502 subsystem_cfg_file);
440 send_result_code (client, 0, NULL); 503 send_result_code (client, 0, NULL);
441 GNUNET_SERVER_receive_done (client, GNUNET_OK); 504 GNUNET_SERVICE_client_continue (client);
442 return; 505 return;
443 } 506 }
444 } 507 }
445 send_result_code (client, 1, _("Unknown ego specified for service (internal error)")); 508 send_result_code (client, 1, _("Unknown ego specified for service (internal error)"));
446 GNUNET_SERVER_receive_done (client, GNUNET_OK); 509 GNUNET_SERVICE_client_continue (client);
447} 510}
448 511
449 512
@@ -455,65 +518,88 @@ handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
455static void 518static void
456notify_listeners (struct Ego *ego) 519notify_listeners (struct Ego *ego)
457{ 520{
458 struct GNUNET_IDENTITY_UpdateMessage *um; 521 struct UpdateMessage *um;
522 size_t name_len;
459 523
460 um = create_update_message (ego); 524 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
461 GNUNET_SERVER_notification_context_broadcast (nc, &um->header, GNUNET_NO); 525 um = GNUNET_malloc (sizeof (struct UpdateMessage) + name_len);
526 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
527 um->header.size = htons (sizeof (struct UpdateMessage) + name_len);
528 um->name_len = htons (name_len);
529 um->end_of_list = htons (GNUNET_NO);
530 um->private_key = *ego->pk;
531 GNUNET_memcpy (&um[1], ego->identifier, name_len);
532 GNUNET_notification_context_broadcast (nc,
533 &um->header,
534 GNUNET_NO);
462 GNUNET_free (um); 535 GNUNET_free (um);
463} 536}
464 537
465
466/** 538/**
467 * Handler for CREATE message from client, creates 539 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_CREATE message
468 * new identity.
469 * 540 *
470 * @param cls unused 541 * @param cls client sending the message
471 * @param client who sent the message 542 * @param msg message of type `struct CreateRequestMessage`
472 * @param message the message received 543 * @return #GNUNET_OK if @a msg is well-formed
473 */ 544 */
474static void 545static int
475handle_create_message (void *cls, struct GNUNET_SERVER_Client *client, 546check_create_message (void *cls,
476 const struct GNUNET_MessageHeader *message) 547 const struct CreateRequestMessage *msg)
477{ 548{
478 const struct GNUNET_IDENTITY_CreateRequestMessage *crm; 549
479 uint16_t size; 550 uint16_t size;
480 uint16_t name_len; 551 uint16_t name_len;
481 struct Ego *ego;
482 const char *str; 552 const char *str;
483 char *fn;
484 553
485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 554 size = ntohs (msg->header.size);
486 "Received CREATE message from client\n"); 555 if (size <= sizeof (struct CreateRequestMessage))
487 size = ntohs (message->size);
488 if (size <= sizeof (struct GNUNET_IDENTITY_CreateRequestMessage))
489 { 556 {
490 GNUNET_break (0); 557 GNUNET_break (0);
491 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 558 return GNUNET_SYSERR;
492 return;
493 } 559 }
494 crm = (const struct GNUNET_IDENTITY_CreateRequestMessage *) message; 560 name_len = ntohs (msg->name_len);
495 name_len = ntohs (crm->name_len); 561 GNUNET_break (0 == ntohs (msg->reserved));
496 GNUNET_break (0 == ntohs (crm->reserved)); 562 if (name_len + sizeof (struct CreateRequestMessage) != size)
497 if (name_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size)
498 { 563 {
499 GNUNET_break (0); 564 GNUNET_break (0);
500 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 565 return GNUNET_SYSERR;
501 return;
502 } 566 }
503 str = (const char *) &crm[1]; 567 str = (const char *) &msg[1];
504 if ('\0' != str[name_len - 1]) 568 if ('\0' != str[name_len - 1])
505 { 569 {
506 GNUNET_break (0); 570 GNUNET_break (0);
507 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 571 return GNUNET_SYSERR;
508 return;
509 } 572 }
573 return GNUNET_OK;
574}
575
576/**
577 * Handler for CREATE message from client, creates
578 * new identity.
579 *
580 * @param cls unused
581 * @param client who sent the message
582 * @param message the message received
583 */
584static void
585handle_create_message (void *cls,
586 const struct CreateRequestMessage *crm)
587{
588 struct GNUNET_SERVICE_Client *client = cls;
589 struct Ego *ego;
590 const char *str;
591 char *fn;
592
593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
594 "Received CREATE message from client\n");
595 str = (const char *) &crm[1];
510 for (ego = ego_head; NULL != ego; ego = ego->next) 596 for (ego = ego_head; NULL != ego; ego = ego->next)
511 { 597 {
512 if (0 == strcmp (ego->identifier, 598 if (0 == strcmp (ego->identifier,
513 str)) 599 str))
514 { 600 {
515 send_result_code (client, 1, gettext_noop ("identifier already in use for another ego")); 601 send_result_code (client, 1, gettext_noop ("identifier already in use for another ego"));
516 GNUNET_SERVER_receive_done (client, GNUNET_OK); 602 GNUNET_SERVICE_client_continue (client);
517 return; 603 return;
518 } 604 }
519 } 605 }
@@ -522,22 +608,22 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client,
522 *ego->pk = crm->private_key; 608 *ego->pk = crm->private_key;
523 ego->identifier = GNUNET_strdup (str); 609 ego->identifier = GNUNET_strdup (str);
524 GNUNET_CONTAINER_DLL_insert (ego_head, 610 GNUNET_CONTAINER_DLL_insert (ego_head,
525 ego_tail, 611 ego_tail,
526 ego); 612 ego);
527 send_result_code (client, 0, NULL); 613 send_result_code (client, 0, NULL);
528 fn = get_ego_filename (ego); 614 fn = get_ego_filename (ego);
529 (void) GNUNET_DISK_directory_create_for_file (fn); 615 (void) GNUNET_DISK_directory_create_for_file (fn);
530 if (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) != 616 if (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) !=
531 GNUNET_DISK_fn_write (fn, 617 GNUNET_DISK_fn_write (fn,
532 &crm->private_key, 618 &crm->private_key,
533 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 619 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey),
534 GNUNET_DISK_PERM_USER_READ | 620 GNUNET_DISK_PERM_USER_READ |
535 GNUNET_DISK_PERM_USER_WRITE)) 621 GNUNET_DISK_PERM_USER_WRITE))
536 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 622 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
537 "write", fn); 623 "write", fn);
538 GNUNET_free (fn); 624 GNUNET_free (fn);
539 notify_listeners (ego); 625 notify_listeners (ego);
540 GNUNET_SERVER_receive_done (client, GNUNET_OK); 626 GNUNET_SERVICE_client_continue (client);
541} 627}
542 628
543 629
@@ -557,7 +643,6 @@ struct RenameContext
557 const char *new_name; 643 const char *new_name;
558}; 644};
559 645
560
561/** 646/**
562 * An ego was renamed; rename it in all subsystems where it is 647 * An ego was renamed; rename it in all subsystems where it is
563 * currently set as the default. 648 * currently set as the default.
@@ -567,16 +652,16 @@ struct RenameContext
567 */ 652 */
568static void 653static void
569handle_ego_rename (void *cls, 654handle_ego_rename (void *cls,
570 const char *section) 655 const char *section)
571{ 656{
572 struct RenameContext *rc = cls; 657 struct RenameContext *rc = cls;
573 char *id; 658 char *id;
574 659
575 if (GNUNET_OK != 660 if (GNUNET_OK !=
576 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 661 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
577 section, 662 section,
578 "DEFAULT_IDENTIFIER", 663 "DEFAULT_IDENTIFIER",
579 &id)) 664 &id))
580 return; 665 return;
581 if (0 != strcmp (id, rc->old_name)) 666 if (0 != strcmp (id, rc->old_name))
582 { 667 {
@@ -584,12 +669,50 @@ handle_ego_rename (void *cls,
584 return; 669 return;
585 } 670 }
586 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 671 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
587 section, 672 section,
588 "DEFAULT_IDENTIFIER", 673 "DEFAULT_IDENTIFIER",
589 rc->new_name); 674 rc->new_name);
590 GNUNET_free (id); 675 GNUNET_free (id);
591} 676}
592 677
678/**
679 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME message
680 *
681 * @param cls client sending the message
682 * @param msg message of type `struct RenameMessage`
683 * @return #GNUNET_OK if @a msg is well-formed
684 */
685static int
686check_rename_message (void *cls,
687 const struct RenameMessage *msg)
688{
689 uint16_t size;
690 uint16_t old_name_len;
691 uint16_t new_name_len;
692 const char *old_name;
693 const char *new_name;
694
695 size = ntohs (msg->header.size);
696 if (size <= sizeof (struct RenameMessage))
697 {
698 GNUNET_break (0);
699 return GNUNET_SYSERR;
700 }
701 old_name_len = ntohs (msg->old_name_len);
702 new_name_len = ntohs (msg->new_name_len);
703 old_name = (const char *) &msg[1];
704 new_name = &old_name[old_name_len];
705 if ( (old_name_len + new_name_len + sizeof (struct RenameMessage) != size) ||
706 ('\0' != old_name[old_name_len - 1]) ||
707 ('\0' != new_name[new_name_len - 1]) )
708 {
709 GNUNET_break (0);
710 return GNUNET_SYSERR;
711 }
712
713 return GNUNET_OK;
714}
715
593 716
594/** 717/**
595 * Handler for RENAME message from client, creates 718 * Handler for RENAME message from client, creates
@@ -600,51 +723,32 @@ handle_ego_rename (void *cls,
600 * @param message the message received 723 * @param message the message received
601 */ 724 */
602static void 725static void
603handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client, 726handle_rename_message (void *cls,
604 const struct GNUNET_MessageHeader *message) 727 const struct RenameMessage *rm)
605{ 728{
606 const struct GNUNET_IDENTITY_RenameMessage *rm;
607 uint16_t size;
608 uint16_t old_name_len; 729 uint16_t old_name_len;
609 uint16_t new_name_len;
610 struct Ego *ego; 730 struct Ego *ego;
611 const char *old_name; 731 const char *old_name;
612 const char *new_name; 732 const char *new_name;
613 struct RenameContext rename_ctx; 733 struct RenameContext rename_ctx;
734 struct GNUNET_SERVICE_Client *client = cls;
614 char *fn_old; 735 char *fn_old;
615 char *fn_new; 736 char *fn_new;
616 737
617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
618 "Received RENAME message from client\n"); 739 "Received RENAME message from client\n");
619 size = ntohs (message->size);
620 if (size <= sizeof (struct GNUNET_IDENTITY_RenameMessage))
621 {
622 GNUNET_break (0);
623 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
624 return;
625 }
626 rm = (const struct GNUNET_IDENTITY_RenameMessage *) message;
627 old_name_len = ntohs (rm->old_name_len); 740 old_name_len = ntohs (rm->old_name_len);
628 new_name_len = ntohs (rm->new_name_len);
629 old_name = (const char *) &rm[1]; 741 old_name = (const char *) &rm[1];
630 new_name = &old_name[old_name_len]; 742 new_name = &old_name[old_name_len];
631 if ( (old_name_len + new_name_len + sizeof (struct GNUNET_IDENTITY_RenameMessage) != size) ||
632 ('\0' != old_name[old_name_len - 1]) ||
633 ('\0' != new_name[new_name_len - 1]) )
634 {
635 GNUNET_break (0);
636 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
637 return;
638 }
639 743
640 /* check if new name is already in use */ 744 /* check if new name is already in use */
641 for (ego = ego_head; NULL != ego; ego = ego->next) 745 for (ego = ego_head; NULL != ego; ego = ego->next)
642 { 746 {
643 if (0 == strcmp (ego->identifier, 747 if (0 == strcmp (ego->identifier,
644 new_name)) 748 new_name))
645 { 749 {
646 send_result_code (client, 1, gettext_noop ("target name already exists")); 750 send_result_code (client, 1, gettext_noop ("target name already exists"));
647 GNUNET_SERVER_receive_done (client, GNUNET_OK); 751 GNUNET_SERVICE_client_continue (client);
648 return; 752 return;
649 } 753 }
650 } 754 }
@@ -653,37 +757,37 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
653 for (ego = ego_head; NULL != ego; ego = ego->next) 757 for (ego = ego_head; NULL != ego; ego = ego->next)
654 { 758 {
655 if (0 == strcmp (ego->identifier, 759 if (0 == strcmp (ego->identifier,
656 old_name)) 760 old_name))
657 { 761 {
658 fn_old = get_ego_filename (ego); 762 fn_old = get_ego_filename (ego);
659 GNUNET_free (ego->identifier); 763 GNUNET_free (ego->identifier);
660 rename_ctx.old_name = old_name; 764 rename_ctx.old_name = old_name;
661 rename_ctx.new_name = new_name; 765 rename_ctx.new_name = new_name;
662 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, 766 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
663 &handle_ego_rename, 767 &handle_ego_rename,
664 &rename_ctx); 768 &rename_ctx);
665 if (GNUNET_OK != 769 if (GNUNET_OK !=
666 GNUNET_CONFIGURATION_write (subsystem_cfg, 770 GNUNET_CONFIGURATION_write (subsystem_cfg,
667 subsystem_cfg_file)) 771 subsystem_cfg_file))
668 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 772 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
669 _("Failed to write subsystem default identifier map to `%s'.\n"), 773 _("Failed to write subsystem default identifier map to `%s'.\n"),
670 subsystem_cfg_file); 774 subsystem_cfg_file);
671 ego->identifier = GNUNET_strdup (new_name); 775 ego->identifier = GNUNET_strdup (new_name);
672 fn_new = get_ego_filename (ego); 776 fn_new = get_ego_filename (ego);
673 if (0 != RENAME (fn_old, fn_new)) 777 if (0 != RENAME (fn_old, fn_new))
674 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); 778 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
675 GNUNET_free (fn_old); 779 GNUNET_free (fn_old);
676 GNUNET_free (fn_new); 780 GNUNET_free (fn_new);
677 notify_listeners (ego); 781 notify_listeners (ego);
678 send_result_code (client, 0, NULL); 782 send_result_code (client, 0, NULL);
679 GNUNET_SERVER_receive_done (client, GNUNET_OK); 783 GNUNET_SERVICE_client_continue (client);
680 return; 784 return;
681 } 785 }
682 } 786 }
683 787
684 /* failed to locate old name */ 788 /* failed to locate old name */
685 send_result_code (client, 1, gettext_noop ("no matching ego found")); 789 send_result_code (client, 1, gettext_noop ("no matching ego found"));
686 GNUNET_SERVER_receive_done (client, GNUNET_OK); 790 GNUNET_SERVICE_client_continue (client);
687} 791}
688 792
689 793
@@ -696,16 +800,16 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client,
696 */ 800 */
697static void 801static void
698handle_ego_delete (void *cls, 802handle_ego_delete (void *cls,
699 const char *section) 803 const char *section)
700{ 804{
701 const char *identifier = cls; 805 const char *identifier = cls;
702 char *id; 806 char *id;
703 807
704 if (GNUNET_OK != 808 if (GNUNET_OK !=
705 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 809 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
706 section, 810 section,
707 "DEFAULT_IDENTIFIER", 811 "DEFAULT_IDENTIFIER",
708 &id)) 812 &id))
709 return; 813 return;
710 if (0 != strcmp (id, identifier)) 814 if (0 != strcmp (id, identifier))
711 { 815 {
@@ -713,12 +817,45 @@ handle_ego_delete (void *cls,
713 return; 817 return;
714 } 818 }
715 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 819 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
716 section, 820 section,
717 "DEFAULT_IDENTIFIER", 821 "DEFAULT_IDENTIFIER",
718 NULL); 822 NULL);
719 GNUNET_free (id); 823 GNUNET_free (id);
720} 824}
721 825
826/**
827 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE message
828 *
829 * @param cls client sending the message
830 * @param msg message of type `struct DeleteMessage`
831 * @return #GNUNET_OK if @a msg is well-formed
832 */
833static int
834check_delete_message (void *cls,
835 const struct DeleteMessage *msg)
836{
837 uint16_t size;
838 uint16_t name_len;
839 const char *name;
840
841 size = ntohs (msg->header.size);
842 if (size <= sizeof (struct DeleteMessage))
843 {
844 GNUNET_break (0);
845 return GNUNET_SYSERR;
846 }
847 name = (const char *) &msg[1];
848 name_len = ntohs (msg->name_len);
849 if ( (name_len + sizeof (struct DeleteMessage) != size) ||
850 (0 != ntohs (msg->reserved)) ||
851 ('\0' != name[name_len - 1]) )
852 {
853 GNUNET_break (0);
854 return GNUNET_SYSERR;
855 }
856 return GNUNET_OK;
857}
858
722 859
723/** 860/**
724 * Handler for DELETE message from client, creates 861 * Handler for DELETE message from client, creates
@@ -729,56 +866,37 @@ handle_ego_delete (void *cls,
729 * @param message the message received 866 * @param message the message received
730 */ 867 */
731static void 868static void
732handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client, 869handle_delete_message (void *cls,
733 const struct GNUNET_MessageHeader *message) 870 const struct DeleteMessage *dm)
734{ 871{
735 const struct GNUNET_IDENTITY_DeleteMessage *dm;
736 uint16_t size;
737 uint16_t name_len;
738 struct Ego *ego; 872 struct Ego *ego;
739 const char *name; 873 const char *name;
740 char *fn; 874 char *fn;
875 struct GNUNET_SERVICE_Client *client = cls;
741 876
742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
743 "Received DELETE message from client\n"); 878 "Received DELETE message from client\n");
744 size = ntohs (message->size);
745 if (size <= sizeof (struct GNUNET_IDENTITY_DeleteMessage))
746 {
747 GNUNET_break (0);
748 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
749 return;
750 }
751 dm = (const struct GNUNET_IDENTITY_DeleteMessage *) message;
752 name = (const char *) &dm[1]; 879 name = (const char *) &dm[1];
753 name_len = ntohs (dm->name_len);
754 if ( (name_len + sizeof (struct GNUNET_IDENTITY_DeleteMessage) != size) ||
755 (0 != ntohs (dm->reserved)) ||
756 ('\0' != name[name_len - 1]) )
757 {
758 GNUNET_break (0);
759 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
760 return;
761 }
762 for (ego = ego_head; NULL != ego; ego = ego->next) 880 for (ego = ego_head; NULL != ego; ego = ego->next)
763 { 881 {
764 if (0 == strcmp (ego->identifier, 882 if (0 == strcmp (ego->identifier,
765 name)) 883 name))
766 { 884 {
767 GNUNET_CONTAINER_DLL_remove (ego_head, 885 GNUNET_CONTAINER_DLL_remove (ego_head,
768 ego_tail, 886 ego_tail,
769 ego); 887 ego);
770 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, 888 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
771 &handle_ego_delete, 889 &handle_ego_delete,
772 ego->identifier); 890 ego->identifier);
773 if (GNUNET_OK != 891 if (GNUNET_OK !=
774 GNUNET_CONFIGURATION_write (subsystem_cfg, 892 GNUNET_CONFIGURATION_write (subsystem_cfg,
775 subsystem_cfg_file)) 893 subsystem_cfg_file))
776 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 894 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
777 _("Failed to write subsystem default identifier map to `%s'.\n"), 895 _("Failed to write subsystem default identifier map to `%s'.\n"),
778 subsystem_cfg_file); 896 subsystem_cfg_file);
779 fn = get_ego_filename (ego); 897 fn = get_ego_filename (ego);
780 if (0 != UNLINK (fn)) 898 if (0 != UNLINK (fn))
781 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 899 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
782 GNUNET_free (fn); 900 GNUNET_free (fn);
783 GNUNET_free (ego->identifier); 901 GNUNET_free (ego->identifier);
784 ego->identifier = NULL; 902 ego->identifier = NULL;
@@ -786,13 +904,13 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
786 GNUNET_free (ego->pk); 904 GNUNET_free (ego->pk);
787 GNUNET_free (ego); 905 GNUNET_free (ego);
788 send_result_code (client, 0, NULL); 906 send_result_code (client, 0, NULL);
789 GNUNET_SERVER_receive_done (client, GNUNET_OK); 907 GNUNET_SERVICE_client_continue (client);
790 return; 908 return;
791 } 909 }
792 } 910 }
793 911
794 send_result_code (client, 1, gettext_noop ("no matching ego found")); 912 send_result_code (client, 1, gettext_noop ("no matching ego found"));
795 GNUNET_SERVER_receive_done (client, GNUNET_OK); 913 GNUNET_SERVICE_client_continue (client);
796} 914}
797 915
798 916
@@ -808,7 +926,7 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
808 */ 926 */
809static int 927static int
810process_ego_file (void *cls, 928process_ego_file (void *cls,
811 const char *filename) 929 const char *filename)
812{ 930{
813 struct Ego *ego; 931 struct Ego *ego;
814 const char *fn; 932 const char *fn;
@@ -830,12 +948,12 @@ process_ego_file (void *cls,
830 return GNUNET_OK; 948 return GNUNET_OK;
831 } 949 }
832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
833 "Loaded ego `%s'\n", 951 "Loaded ego `%s'\n",
834 fn + 1); 952 fn + 1);
835 ego->identifier = GNUNET_strdup (fn + 1); 953 ego->identifier = GNUNET_strdup (fn + 1);
836 GNUNET_CONTAINER_DLL_insert (ego_head, 954 GNUNET_CONTAINER_DLL_insert (ego_head,
837 ego_tail, 955 ego_tail,
838 ego); 956 ego);
839 return GNUNET_OK; 957 return GNUNET_OK;
840} 958}
841 959
@@ -849,30 +967,15 @@ process_ego_file (void *cls,
849 */ 967 */
850static void 968static void
851run (void *cls, 969run (void *cls,
852 struct GNUNET_SERVER_Handle *server, 970 const struct GNUNET_CONFIGURATION_Handle *c,
853 const struct GNUNET_CONFIGURATION_Handle *c) 971 struct GNUNET_SERVICE_Handle *service)
854{ 972{
855 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
856 {&handle_start_message, NULL,
857 GNUNET_MESSAGE_TYPE_IDENTITY_START, sizeof (struct GNUNET_MessageHeader)},
858 {&handle_get_default_message, NULL,
859 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, 0},
860 {&handle_set_default_message, NULL,
861 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 0},
862 {&handle_create_message, NULL,
863 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, 0},
864 {&handle_rename_message, NULL,
865 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, 0},
866 {&handle_delete_message, NULL,
867 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, 0},
868 {NULL, NULL, 0, 0}
869 };
870
871 cfg = c; 973 cfg = c;
974 nc = GNUNET_notification_context_create (1);
872 if (GNUNET_OK != 975 if (GNUNET_OK !=
873 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", 976 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity",
874 "EGODIR", 977 "EGODIR",
875 &ego_directory)) 978 &ego_directory))
876 { 979 {
877 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); 980 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
878 GNUNET_SCHEDULER_shutdown (); 981 GNUNET_SCHEDULER_shutdown ();
@@ -880,62 +983,81 @@ run (void *cls,
880 } 983 }
881 if (GNUNET_OK != 984 if (GNUNET_OK !=
882 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", 985 GNUNET_CONFIGURATION_get_value_filename (cfg, "identity",
883 "SUBSYSTEM_CFG", 986 "SUBSYSTEM_CFG",
884 &subsystem_cfg_file)) 987 &subsystem_cfg_file))
885 { 988 {
886 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "SUBSYSTEM_CFG"); 989 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "SUBSYSTEM_CFG");
887 GNUNET_SCHEDULER_shutdown (); 990 GNUNET_SCHEDULER_shutdown ();
888 return; 991 return;
889 } 992 }
890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 993 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
891 "Loading subsystem configuration `%s'\n", 994 "Loading subsystem configuration `%s'\n",
892 subsystem_cfg_file); 995 subsystem_cfg_file);
893 subsystem_cfg = GNUNET_CONFIGURATION_create (); 996 subsystem_cfg = GNUNET_CONFIGURATION_create ();
894 if ( (GNUNET_YES == 997 if ( (GNUNET_YES ==
895 GNUNET_DISK_file_test (subsystem_cfg_file)) && 998 GNUNET_DISK_file_test (subsystem_cfg_file)) &&
896 (GNUNET_OK != 999 (GNUNET_OK !=
897 GNUNET_CONFIGURATION_parse (subsystem_cfg, 1000 GNUNET_CONFIGURATION_parse (subsystem_cfg,
898 subsystem_cfg_file)) ) 1001 subsystem_cfg_file)) )
899 { 1002 {
900 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1003 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
901 _("Failed to parse subsystem identity configuration file `%s'\n"), 1004 _("Failed to parse subsystem identity configuration file `%s'\n"),
902 subsystem_cfg_file); 1005 subsystem_cfg_file);
903 GNUNET_SCHEDULER_shutdown (); 1006 GNUNET_SCHEDULER_shutdown ();
904 return; 1007 return;
905 } 1008 }
906 stats = GNUNET_STATISTICS_create ("identity", cfg); 1009 stats = GNUNET_STATISTICS_create ("identity", cfg);
907 GNUNET_SERVER_add_handlers (server, handlers);
908 nc = GNUNET_SERVER_notification_context_create (server, 1);
909 if (GNUNET_OK != 1010 if (GNUNET_OK !=
910 GNUNET_DISK_directory_create (ego_directory)) 1011 GNUNET_DISK_directory_create (ego_directory))
911 { 1012 {
912 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1013 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
913 _("Failed to create directory `%s' for storing egos\n"), 1014 _("Failed to create directory `%s' for storing egos\n"),
914 ego_directory); 1015 ego_directory);
915 } 1016 }
916 GNUNET_DISK_directory_scan (ego_directory, 1017 GNUNET_DISK_directory_scan (ego_directory,
917 &process_ego_file, 1018 &process_ego_file,
918 NULL); 1019 NULL);
919 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1020 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
920 NULL); 1021 NULL);
921} 1022}
922 1023
923 1024
924/** 1025/**
925 * The main function for the network size estimation service. 1026 * Define "main" method using service macro.
926 *
927 * @param argc number of arguments from the command line
928 * @param argv command line arguments
929 * @return 0 ok, 1 on error
930 */ 1027 */
931int 1028GNUNET_SERVICE_MAIN
932main (int argc, char *const *argv) 1029("identity",
933{ 1030 GNUNET_SERVICE_OPTION_NONE,
934 return (GNUNET_OK == 1031 &run,
935 GNUNET_SERVICE_run (argc, argv, "identity", 1032 &client_connect_cb,
936 GNUNET_SERVICE_OPTION_NONE, 1033 &client_disconnect_cb,
937 &run, NULL)) ? 0 : 1; 1034 NULL,
938} 1035 GNUNET_MQ_hd_fixed_size (start_message,
1036 GNUNET_MESSAGE_TYPE_IDENTITY_START,
1037 struct GNUNET_MessageHeader,
1038 NULL),
1039 GNUNET_MQ_hd_var_size (get_default_message,
1040 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
1041 struct GetDefaultMessage,
1042 NULL),
1043 GNUNET_MQ_hd_var_size (set_default_message,
1044 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
1045 struct SetDefaultMessage,
1046 NULL),
1047 GNUNET_MQ_hd_var_size (create_message,
1048 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
1049 struct CreateRequestMessage,
1050 NULL),
1051 GNUNET_MQ_hd_var_size (rename_message,
1052 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
1053 struct RenameMessage,
1054 NULL),
1055 GNUNET_MQ_hd_var_size (delete_message,
1056 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
1057 struct DeleteMessage,
1058 NULL),
1059 GNUNET_MQ_handler_end());
1060
939 1061
940 1062
941/* end of gnunet-service-identity.c */ 1063/* end of gnunet-service-identity.c */
diff --git a/src/identity/identity.h b/src/identity/identity.h
index 75dc3f08c..aae650a79 100644
--- a/src/identity/identity.h
+++ b/src/identity/identity.h
@@ -39,7 +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 */
42struct GNUNET_IDENTITY_ResultCodeMessage 42struct ResultCodeMessage
43{ 43{
44 /** 44 /**
45 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE 45 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE
@@ -60,7 +60,7 @@ struct GNUNET_IDENTITY_ResultCodeMessage
60/** 60/**
61 * Service informs client about status of a pseudonym. 61 * Service informs client about status of a pseudonym.
62 */ 62 */
63struct GNUNET_IDENTITY_UpdateMessage 63struct UpdateMessage
64{ 64{
65 /** 65 /**
66 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE 66 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE
@@ -93,7 +93,7 @@ struct GNUNET_IDENTITY_UpdateMessage
93 * Client requests knowledge about default identity for 93 * Client requests knowledge about default identity for
94 * a subsystem from identity service. 94 * a subsystem from identity service.
95 */ 95 */
96struct GNUNET_IDENTITY_GetDefaultMessage 96struct GetDefaultMessage
97{ 97{
98 /** 98 /**
99 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT 99 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT
@@ -120,7 +120,7 @@ struct GNUNET_IDENTITY_GetDefaultMessage
120 * Used from service to client as a result to the GET_DEFAULT 120 * Used from service to client as a result to the GET_DEFAULT
121 * message, used from client to service to SET_DEFAULT. 121 * message, used from client to service to SET_DEFAULT.
122 */ 122 */
123struct GNUNET_IDENTITY_SetDefaultMessage 123struct SetDefaultMessage
124{ 124{
125 /** 125 /**
126 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT 126 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT
@@ -151,7 +151,7 @@ struct GNUNET_IDENTITY_SetDefaultMessage
151 * Client requests creation of an identity. Service 151 * Client requests creation of an identity. Service
152 * will respond with a result code. 152 * will respond with a result code.
153 */ 153 */
154struct GNUNET_IDENTITY_CreateRequestMessage 154struct CreateRequestMessage
155{ 155{
156 /** 156 /**
157 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_CREATE 157 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_CREATE
@@ -182,7 +182,7 @@ struct GNUNET_IDENTITY_CreateRequestMessage
182 * Client requests renaming of an identity. Service 182 * Client requests renaming of an identity. Service
183 * will respond with a result code. 183 * will respond with a result code.
184 */ 184 */
185struct GNUNET_IDENTITY_RenameMessage 185struct RenameMessage
186{ 186{
187 /** 187 /**
188 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME 188 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME
@@ -208,7 +208,7 @@ struct GNUNET_IDENTITY_RenameMessage
208 * Client requests deletion of an identity. Service 208 * Client requests deletion of an identity. Service
209 * will respond with a result code. 209 * will respond with a result code.
210 */ 210 */
211struct GNUNET_IDENTITY_DeleteMessage 211struct DeleteMessage
212{ 212{
213 /** 213 /**
214 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE 214 * Type: #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index dd61fdfb4..10a64d1ba 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -304,7 +304,7 @@ mq_error_handler (void *cls,
304 */ 304 */
305static int 305static int
306check_identity_result_code (void *cls, 306check_identity_result_code (void *cls,
307 const struct GNUNET_IDENTITY_ResultCodeMessage *rcm) 307 const struct ResultCodeMessage *rcm)
308{ 308{
309 uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm); 309 uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm);
310 const char *str = (const char *) &rcm[1]; 310 const char *str = (const char *) &rcm[1];
@@ -328,7 +328,7 @@ check_identity_result_code (void *cls,
328 */ 328 */
329static void 329static void
330handle_identity_result_code (void *cls, 330handle_identity_result_code (void *cls,
331 const struct GNUNET_IDENTITY_ResultCodeMessage *rcm) 331 const struct ResultCodeMessage *rcm)
332{ 332{
333 struct GNUNET_IDENTITY_Handle *h = cls; 333 struct GNUNET_IDENTITY_Handle *h = cls;
334 struct GNUNET_IDENTITY_Operation *op; 334 struct GNUNET_IDENTITY_Operation *op;
@@ -363,13 +363,13 @@ handle_identity_result_code (void *cls,
363 */ 363 */
364static int 364static int
365check_identity_update (void *cls, 365check_identity_update (void *cls,
366 const struct GNUNET_IDENTITY_UpdateMessage *um) 366 const struct UpdateMessage *um)
367{ 367{
368 uint16_t size = ntohs (um->header.size); 368 uint16_t size = ntohs (um->header.size);
369 uint16_t name_len = ntohs (um->name_len); 369 uint16_t name_len = ntohs (um->name_len);
370 const char *str = (const char *) &um[1]; 370 const char *str = (const char *) &um[1];
371 371
372 if ( (size != name_len + sizeof (struct GNUNET_IDENTITY_UpdateMessage)) || 372 if ( (size != name_len + sizeof (struct UpdateMessage)) ||
373 ( (0 != name_len) && 373 ( (0 != name_len) &&
374 ('\0' != str[name_len - 1])) ) 374 ('\0' != str[name_len - 1])) )
375 { 375 {
@@ -388,7 +388,7 @@ check_identity_update (void *cls,
388 */ 388 */
389static void 389static void
390handle_identity_update (void *cls, 390handle_identity_update (void *cls,
391 const struct GNUNET_IDENTITY_UpdateMessage *um) 391 const struct UpdateMessage *um)
392{ 392{
393 struct GNUNET_IDENTITY_Handle *h = cls; 393 struct GNUNET_IDENTITY_Handle *h = cls;
394 uint16_t name_len = ntohs (um->name_len); 394 uint16_t name_len = ntohs (um->name_len);
@@ -475,7 +475,7 @@ handle_identity_update (void *cls,
475 */ 475 */
476static int 476static int
477check_identity_set_default (void *cls, 477check_identity_set_default (void *cls,
478 const struct GNUNET_IDENTITY_SetDefaultMessage *sdm) 478 const struct SetDefaultMessage *sdm)
479{ 479{
480 uint16_t size = ntohs (sdm->header.size) - sizeof (*sdm); 480 uint16_t size = ntohs (sdm->header.size) - sizeof (*sdm);
481 uint16_t name_len = ntohs (sdm->name_len); 481 uint16_t name_len = ntohs (sdm->name_len);
@@ -502,7 +502,7 @@ check_identity_set_default (void *cls,
502 */ 502 */
503static void 503static void
504handle_identity_set_default (void *cls, 504handle_identity_set_default (void *cls,
505 const struct GNUNET_IDENTITY_SetDefaultMessage *sdm) 505 const struct SetDefaultMessage *sdm)
506{ 506{
507 struct GNUNET_IDENTITY_Handle *h = cls; 507 struct GNUNET_IDENTITY_Handle *h = cls;
508 struct GNUNET_IDENTITY_Operation *op; 508 struct GNUNET_IDENTITY_Operation *op;
@@ -556,15 +556,15 @@ reconnect (void *cls)
556 struct GNUNET_MQ_MessageHandler handlers[] = { 556 struct GNUNET_MQ_MessageHandler handlers[] = {
557 GNUNET_MQ_hd_var_size (identity_result_code, 557 GNUNET_MQ_hd_var_size (identity_result_code,
558 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, 558 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
559 struct GNUNET_IDENTITY_ResultCodeMessage, 559 struct ResultCodeMessage,
560 h), 560 h),
561 GNUNET_MQ_hd_var_size (identity_update, 561 GNUNET_MQ_hd_var_size (identity_update,
562 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, 562 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE,
563 struct GNUNET_IDENTITY_UpdateMessage, 563 struct UpdateMessage,
564 h), 564 h),
565 GNUNET_MQ_hd_var_size (identity_set_default, 565 GNUNET_MQ_hd_var_size (identity_set_default,
566 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 566 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
567 struct GNUNET_IDENTITY_SetDefaultMessage, 567 struct SetDefaultMessage,
568 h), 568 h),
569 GNUNET_MQ_handler_end () 569 GNUNET_MQ_handler_end ()
570 }; 570 };
@@ -665,13 +665,13 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h,
665{ 665{
666 struct GNUNET_IDENTITY_Operation *op; 666 struct GNUNET_IDENTITY_Operation *op;
667 struct GNUNET_MQ_Envelope *env; 667 struct GNUNET_MQ_Envelope *env;
668 struct GNUNET_IDENTITY_GetDefaultMessage *gdm; 668 struct GetDefaultMessage *gdm;
669 size_t slen; 669 size_t slen;
670 670
671 if (NULL == h->mq) 671 if (NULL == h->mq)
672 return NULL; 672 return NULL;
673 slen = strlen (service_name) + 1; 673 slen = strlen (service_name) + 1;
674 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_GetDefaultMessage)) 674 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GetDefaultMessage))
675 { 675 {
676 GNUNET_break (0); 676 GNUNET_break (0);
677 return NULL; 677 return NULL;
@@ -716,13 +716,13 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
716{ 716{
717 struct GNUNET_IDENTITY_Operation *op; 717 struct GNUNET_IDENTITY_Operation *op;
718 struct GNUNET_MQ_Envelope *env; 718 struct GNUNET_MQ_Envelope *env;
719 struct GNUNET_IDENTITY_SetDefaultMessage *sdm; 719 struct SetDefaultMessage *sdm;
720 size_t slen; 720 size_t slen;
721 721
722 if (NULL == h->mq) 722 if (NULL == h->mq)
723 return NULL; 723 return NULL;
724 slen = strlen (service_name) + 1; 724 slen = strlen (service_name) + 1;
725 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) 725 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct SetDefaultMessage))
726 { 726 {
727 GNUNET_break (0); 727 GNUNET_break (0);
728 return NULL; 728 return NULL;
@@ -766,14 +766,14 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
766{ 766{
767 struct GNUNET_IDENTITY_Operation *op; 767 struct GNUNET_IDENTITY_Operation *op;
768 struct GNUNET_MQ_Envelope *env; 768 struct GNUNET_MQ_Envelope *env;
769 struct GNUNET_IDENTITY_CreateRequestMessage *crm; 769 struct CreateRequestMessage *crm;
770 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 770 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
771 size_t slen; 771 size_t slen;
772 772
773 if (NULL == h->mq) 773 if (NULL == h->mq)
774 return NULL; 774 return NULL;
775 slen = strlen (name) + 1; 775 slen = strlen (name) + 1;
776 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_CreateRequestMessage)) 776 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct CreateRequestMessage))
777 { 777 {
778 GNUNET_break (0); 778 GNUNET_break (0);
779 return NULL; 779 return NULL;
@@ -821,7 +821,7 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
821{ 821{
822 struct GNUNET_IDENTITY_Operation *op; 822 struct GNUNET_IDENTITY_Operation *op;
823 struct GNUNET_MQ_Envelope *env; 823 struct GNUNET_MQ_Envelope *env;
824 struct GNUNET_IDENTITY_RenameMessage *grm; 824 struct RenameMessage *grm;
825 size_t slen_old; 825 size_t slen_old;
826 size_t slen_new; 826 size_t slen_new;
827 char *dst; 827 char *dst;
@@ -832,7 +832,7 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
832 slen_new = strlen (new_name) + 1; 832 slen_new = strlen (new_name) + 1;
833 if ( (slen_old >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 833 if ( (slen_old >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
834 (slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 834 (slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
835 (slen_old + slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_RenameMessage)) ) 835 (slen_old + slen_new >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct RenameMessage)) )
836 { 836 {
837 GNUNET_break (0); 837 GNUNET_break (0);
838 return NULL; 838 return NULL;
@@ -879,13 +879,13 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h,
879{ 879{
880 struct GNUNET_IDENTITY_Operation *op; 880 struct GNUNET_IDENTITY_Operation *op;
881 struct GNUNET_MQ_Envelope *env; 881 struct GNUNET_MQ_Envelope *env;
882 struct GNUNET_IDENTITY_DeleteMessage *gdm; 882 struct DeleteMessage *gdm;
883 size_t slen; 883 size_t slen;
884 884
885 if (NULL == h->mq) 885 if (NULL == h->mq)
886 return NULL; 886 return NULL;
887 slen = strlen (name) + 1; 887 slen = strlen (name) + 1;
888 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_IDENTITY_DeleteMessage)) 888 if (slen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct DeleteMessage))
889 { 889 {
890 GNUNET_break (0); 890 GNUNET_break (0);
891 return NULL; 891 return NULL;