aboutsummaryrefslogtreecommitdiff
path: root/src/identity/gnunet-service-identity.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/identity/gnunet-service-identity.c')
-rw-r--r--src/identity/gnunet-service-identity.c1059
1 files changed, 527 insertions, 532 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 34fad3272..f399b2566 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V. 3 Copyright (C) 2013 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -42,9 +42,7 @@
42/** 42/**
43 * Information we keep about each ego. 43 * Information we keep about each ego.
44 */ 44 */
45struct Ego 45struct Ego {
46{
47
48 /** 46 /**
49 * We keep egos in a DLL. 47 * We keep egos in a DLL.
50 */ 48 */
@@ -116,15 +114,15 @@ static struct Ego *ego_tail;
116 * @return full filename for the given ego 114 * @return full filename for the given ego
117 */ 115 */
118static char * 116static char *
119get_ego_filename (struct Ego *ego) 117get_ego_filename(struct Ego *ego)
120{ 118{
121 char *filename; 119 char *filename;
122 120
123 GNUNET_asprintf (&filename, 121 GNUNET_asprintf(&filename,
124 "%s%s%s", 122 "%s%s%s",
125 ego_directory, 123 ego_directory,
126 DIR_SEPARATOR_STR, 124 DIR_SEPARATOR_STR,
127 ego->identifier); 125 ego->identifier);
128 return filename; 126 return filename;
129} 127}
130 128
@@ -136,11 +134,11 @@ get_ego_filename (struct Ego *ego)
136 * @param app_ctx @a client 134 * @param app_ctx @a client
137 */ 135 */
138static void 136static void
139client_disconnect_cb (void *cls, 137client_disconnect_cb(void *cls,
140 struct GNUNET_SERVICE_Client *client, 138 struct GNUNET_SERVICE_Client *client,
141 void *app_ctx) 139 void *app_ctx)
142{ 140{
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); 141 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
144} 142}
145 143
146 144
@@ -153,9 +151,9 @@ client_disconnect_cb (void *cls,
153 * @return internal namestore client structure for this client 151 * @return internal namestore client structure for this client
154 */ 152 */
155static void * 153static void *
156client_connect_cb (void *cls, 154client_connect_cb(void *cls,
157 struct GNUNET_SERVICE_Client *client, 155 struct GNUNET_SERVICE_Client *client,
158 struct GNUNET_MQ_Handle *mq) 156 struct GNUNET_MQ_Handle *mq)
159{ 157{
160 return client; 158 return client;
161} 159}
@@ -166,33 +164,33 @@ client_connect_cb (void *cls,
166 * @param cls unused 164 * @param cls unused
167 */ 165 */
168static void 166static void
169shutdown_task (void *cls) 167shutdown_task(void *cls)
170{ 168{
171 struct Ego *e; 169 struct Ego *e;
172 170
173 if (NULL != nc) 171 if (NULL != nc)
174 { 172 {
175 GNUNET_notification_context_destroy (nc); 173 GNUNET_notification_context_destroy(nc);
176 nc = NULL; 174 nc = NULL;
177 } 175 }
178 if (NULL != stats) 176 if (NULL != stats)
179 { 177 {
180 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 178 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
181 stats = NULL; 179 stats = NULL;
182 } 180 }
183 GNUNET_CONFIGURATION_destroy (subsystem_cfg); 181 GNUNET_CONFIGURATION_destroy(subsystem_cfg);
184 subsystem_cfg = NULL; 182 subsystem_cfg = NULL;
185 GNUNET_free (subsystem_cfg_file); 183 GNUNET_free(subsystem_cfg_file);
186 subsystem_cfg_file = NULL; 184 subsystem_cfg_file = NULL;
187 GNUNET_free (ego_directory); 185 GNUNET_free(ego_directory);
188 ego_directory = NULL; 186 ego_directory = NULL;
189 while (NULL != (e = ego_head)) 187 while (NULL != (e = ego_head))
190 { 188 {
191 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e); 189 GNUNET_CONTAINER_DLL_remove(ego_head, ego_tail, e);
192 GNUNET_free (e->pk); 190 GNUNET_free(e->pk);
193 GNUNET_free (e->identifier); 191 GNUNET_free(e->identifier);
194 GNUNET_free (e); 192 GNUNET_free(e);
195 } 193 }
196} 194}
197 195
198 196
@@ -204,9 +202,9 @@ shutdown_task (void *cls)
204 * @param emsg error message to include (or NULL for none) 202 * @param emsg error message to include (or NULL for none)
205 */ 203 */
206static void 204static void
207send_result_code (struct GNUNET_SERVICE_Client *client, 205send_result_code(struct GNUNET_SERVICE_Client *client,
208 uint32_t result_code, 206 uint32_t result_code,
209 const char *emsg) 207 const char *emsg)
210{ 208{
211 struct ResultCodeMessage *rcm; 209 struct ResultCodeMessage *rcm;
212 struct GNUNET_MQ_Envelope *env; 210 struct GNUNET_MQ_Envelope *env;
@@ -215,17 +213,17 @@ send_result_code (struct GNUNET_SERVICE_Client *client,
215 if (NULL == emsg) 213 if (NULL == emsg)
216 elen = 0; 214 elen = 0;
217 else 215 else
218 elen = strlen (emsg) + 1; 216 elen = strlen(emsg) + 1;
219 env = 217 env =
220 GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE); 218 GNUNET_MQ_msg_extra(rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
221 rcm->result_code = htonl (result_code); 219 rcm->result_code = htonl(result_code);
222 if (0 < elen) 220 if (0 < elen)
223 GNUNET_memcpy (&rcm[1], emsg, elen); 221 GNUNET_memcpy(&rcm[1], emsg, elen);
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 222 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
225 "Sending result %d (%s) to client\n", 223 "Sending result %d (%s) to client\n",
226 (int) result_code, 224 (int)result_code,
227 emsg); 225 emsg);
228 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 226 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env);
229} 227}
230 228
231 229
@@ -236,18 +234,18 @@ send_result_code (struct GNUNET_SERVICE_Client *client,
236 * @return corresponding update message 234 * @return corresponding update message
237 */ 235 */
238static struct GNUNET_MQ_Envelope * 236static struct GNUNET_MQ_Envelope *
239create_update_message (struct Ego *ego) 237create_update_message(struct Ego *ego)
240{ 238{
241 struct UpdateMessage *um; 239 struct UpdateMessage *um;
242 struct GNUNET_MQ_Envelope *env; 240 struct GNUNET_MQ_Envelope *env;
243 size_t name_len; 241 size_t name_len;
244 242
245 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); 243 name_len = (NULL == ego->identifier) ? 0 : (strlen(ego->identifier) + 1);
246 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); 244 env = GNUNET_MQ_msg_extra(um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
247 um->name_len = htons (name_len); 245 um->name_len = htons(name_len);
248 um->end_of_list = htons (GNUNET_NO); 246 um->end_of_list = htons(GNUNET_NO);
249 um->private_key = *ego->pk; 247 um->private_key = *ego->pk;
250 GNUNET_memcpy (&um[1], ego->identifier, name_len); 248 GNUNET_memcpy(&um[1], ego->identifier, name_len);
251 return env; 249 return env;
252} 250}
253 251
@@ -260,20 +258,20 @@ create_update_message (struct Ego *ego)
260 * @return corresponding set default message 258 * @return corresponding set default message
261 */ 259 */
262static struct GNUNET_MQ_Envelope * 260static struct GNUNET_MQ_Envelope *
263create_set_default_message (struct Ego *ego, const char *servicename) 261create_set_default_message(struct Ego *ego, const char *servicename)
264{ 262{
265 struct SetDefaultMessage *sdm; 263 struct SetDefaultMessage *sdm;
266 struct GNUNET_MQ_Envelope *env; 264 struct GNUNET_MQ_Envelope *env;
267 size_t name_len; 265 size_t name_len;
268 266
269 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1); 267 name_len = (NULL == servicename) ? 0 : (strlen(servicename) + 1);
270 env = GNUNET_MQ_msg_extra (sdm, 268 env = GNUNET_MQ_msg_extra(sdm,
271 name_len, 269 name_len,
272 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT); 270 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
273 sdm->name_len = htons (name_len); 271 sdm->name_len = htons(name_len);
274 sdm->reserved = htons (0); 272 sdm->reserved = htons(0);
275 sdm->private_key = *ego->pk; 273 sdm->private_key = *ego->pk;
276 GNUNET_memcpy (&sdm[1], servicename, name_len); 274 GNUNET_memcpy(&sdm[1], servicename, name_len);
277 return env; 275 return env;
278} 276}
279 277
@@ -288,27 +286,27 @@ create_set_default_message (struct Ego *ego, const char *servicename)
288 * @param message the message received 286 * @param message the message received
289 */ 287 */
290static void 288static void
291handle_start_message (void *cls, const struct GNUNET_MessageHeader *message) 289handle_start_message(void *cls, const struct GNUNET_MessageHeader *message)
292{ 290{
293 struct GNUNET_SERVICE_Client *client = cls; 291 struct GNUNET_SERVICE_Client *client = cls;
294 struct UpdateMessage *ume; 292 struct UpdateMessage *ume;
295 struct GNUNET_MQ_Envelope *env; 293 struct GNUNET_MQ_Envelope *env;
296 struct Ego *ego; 294 struct Ego *ego;
297 295
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n"); 296 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
299 GNUNET_SERVICE_client_mark_monitor (client); 297 GNUNET_SERVICE_client_mark_monitor(client);
300 GNUNET_SERVICE_client_disable_continue_warning (client); 298 GNUNET_SERVICE_client_disable_continue_warning(client);
301 GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client)); 299 GNUNET_notification_context_add(nc, GNUNET_SERVICE_client_get_mq(client));
302 for (ego = ego_head; NULL != ego; ego = ego->next) 300 for (ego = ego_head; NULL != ego; ego = ego->next)
303 { 301 {
304 env = create_update_message (ego); 302 env = create_update_message(ego);
305 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 303 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env);
306 } 304 }
307 env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); 305 env = GNUNET_MQ_msg_extra(ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
308 ume->end_of_list = htons (GNUNET_YES); 306 ume->end_of_list = htons(GNUNET_YES);
309 ume->name_len = htons (0); 307 ume->name_len = htons(0);
310 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 308 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env);
311 GNUNET_SERVICE_client_continue (client); 309 GNUNET_SERVICE_client_continue(client);
312} 310}
313 311
314 312
@@ -321,9 +319,9 @@ handle_start_message (void *cls, const struct GNUNET_MessageHeader *message)
321 * @return #GNUNET_SYSERR if message was ill-formed 319 * @return #GNUNET_SYSERR if message was ill-formed
322 */ 320 */
323static int 321static int
324check_lookup_message (void *cls, const struct LookupMessage *message) 322check_lookup_message(void *cls, const struct LookupMessage *message)
325{ 323{
326 GNUNET_MQ_check_zero_termination (message); 324 GNUNET_MQ_check_zero_termination(message);
327 return GNUNET_OK; 325 return GNUNET_OK;
328} 326}
329 327
@@ -336,26 +334,26 @@ check_lookup_message (void *cls, const struct LookupMessage *message)
336 * @param message the message received 334 * @param message the message received
337 */ 335 */
338static void 336static void
339handle_lookup_message (void *cls, const struct LookupMessage *message) 337handle_lookup_message(void *cls, const struct LookupMessage *message)
340{ 338{
341 struct GNUNET_SERVICE_Client *client = cls; 339 struct GNUNET_SERVICE_Client *client = cls;
342 const char *name; 340 const char *name;
343 struct GNUNET_MQ_Envelope *env; 341 struct GNUNET_MQ_Envelope *env;
344 struct Ego *ego; 342 struct Ego *ego;
345 343
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n"); 344 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n");
347 name = (const char *) &message[1]; 345 name = (const char *)&message[1];
348 for (ego = ego_head; NULL != ego; ego = ego->next) 346 for (ego = ego_head; NULL != ego; ego = ego->next)
349 { 347 {
350 if (0 != strcasecmp (name, ego->identifier)) 348 if (0 != strcasecmp(name, ego->identifier))
351 continue; 349 continue;
352 env = create_update_message (ego); 350 env = create_update_message(ego);
353 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 351 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env);
354 GNUNET_SERVICE_client_continue (client); 352 GNUNET_SERVICE_client_continue(client);
355 return; 353 return;
356 } 354 }
357 send_result_code (client, 0, "ego not found"); 355 send_result_code(client, 0, "ego not found");
358 GNUNET_SERVICE_client_continue (client); 356 GNUNET_SERVICE_client_continue(client);
359} 357}
360 358
361 359
@@ -368,9 +366,9 @@ handle_lookup_message (void *cls, const struct LookupMessage *message)
368 * @return #GNUNET_SYSERR if message was ill-formed 366 * @return #GNUNET_SYSERR if message was ill-formed
369 */ 367 */
370static int 368static int
371check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) 369check_lookup_by_suffix_message(void *cls, const struct LookupMessage *message)
372{ 370{
373 GNUNET_MQ_check_zero_termination (message); 371 GNUNET_MQ_check_zero_termination(message);
374 return GNUNET_OK; 372 return GNUNET_OK;
375} 373}
376 374
@@ -383,41 +381,40 @@ check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
383 * @param message the message received 381 * @param message the message received
384 */ 382 */
385static void 383static void
386handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message) 384handle_lookup_by_suffix_message(void *cls, const struct LookupMessage *message)
387{ 385{
388 struct GNUNET_SERVICE_Client *client = cls; 386 struct GNUNET_SERVICE_Client *client = cls;
389 const char *name; 387 const char *name;
390 struct GNUNET_MQ_Envelope *env; 388 struct GNUNET_MQ_Envelope *env;
391 struct Ego *lprefix; 389 struct Ego *lprefix;
392 390
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 391 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
394 "Received LOOKUP_BY_SUFFIX message from client\n"); 392 "Received LOOKUP_BY_SUFFIX message from client\n");
395 name = (const char *) &message[1]; 393 name = (const char *)&message[1];
396 lprefix = NULL; 394 lprefix = NULL;
397 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next) 395 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
398 {
399
400 if ((strlen (ego->identifier) <= strlen (name)) &&
401 (0 == strcmp (ego->identifier,
402 &name[strlen (name) - strlen (ego->identifier)])) &&
403 ((strlen (name) == strlen (ego->identifier)) ||
404 ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
405 ((NULL == lprefix) ||
406 (strlen (ego->identifier) > strlen (lprefix->identifier))))
407 { 396 {
408 /* found better match, update! */ 397 if ((strlen(ego->identifier) <= strlen(name)) &&
409 lprefix = ego; 398 (0 == strcmp(ego->identifier,
399 &name[strlen(name) - strlen(ego->identifier)])) &&
400 ((strlen(name) == strlen(ego->identifier)) ||
401 ('.' == name[strlen(name) - strlen(ego->identifier) - 1])) &&
402 ((NULL == lprefix) ||
403 (strlen(ego->identifier) > strlen(lprefix->identifier))))
404 {
405 /* found better match, update! */
406 lprefix = ego;
407 }
410 } 408 }
411 }
412 if (NULL != lprefix) 409 if (NULL != lprefix)
413 { 410 {
414 env = create_update_message (lprefix); 411 env = create_update_message(lprefix);
415 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 412 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env);
416 GNUNET_SERVICE_client_continue (client); 413 GNUNET_SERVICE_client_continue(client);
417 return; 414 return;
418 } 415 }
419 send_result_code (client, 0, "ego not found"); 416 send_result_code(client, 0, "ego not found");
420 GNUNET_SERVICE_client_continue (client); 417 GNUNET_SERVICE_client_continue(client);
421} 418}
422 419
423 420
@@ -429,26 +426,26 @@ handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
429 * @return #GNUNET_OK if @a msg is well-formed 426 * @return #GNUNET_OK if @a msg is well-formed
430 */ 427 */
431static int 428static int
432check_get_default_message (void *cls, const struct GetDefaultMessage *msg) 429check_get_default_message(void *cls, const struct GetDefaultMessage *msg)
433{ 430{
434 uint16_t size; 431 uint16_t size;
435 uint16_t name_len; 432 uint16_t name_len;
436 const char *name; 433 const char *name;
437 434
438 size = ntohs (msg->header.size); 435 size = ntohs(msg->header.size);
439 if (size <= sizeof (struct GetDefaultMessage)) 436 if (size <= sizeof(struct GetDefaultMessage))
440 { 437 {
441 GNUNET_break (0); 438 GNUNET_break(0);
442 return GNUNET_SYSERR; 439 return GNUNET_SYSERR;
443 } 440 }
444 name = (const char *) &msg[1]; 441 name = (const char *)&msg[1];
445 name_len = ntohs (msg->name_len); 442 name_len = ntohs(msg->name_len);
446 if ((name_len + sizeof (struct GetDefaultMessage) != size) || 443 if ((name_len + sizeof(struct GetDefaultMessage) != size) ||
447 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1])) 444 (0 != ntohs(msg->reserved)) || ('\0' != name[name_len - 1]))
448 { 445 {
449 GNUNET_break (0); 446 GNUNET_break(0);
450 return GNUNET_SYSERR; 447 return GNUNET_SYSERR;
451 } 448 }
452 return GNUNET_OK; 449 return GNUNET_OK;
453} 450}
454 451
@@ -462,7 +459,7 @@ check_get_default_message (void *cls, const struct GetDefaultMessage *msg)
462 * @param message the message received 459 * @param message the message received
463 */ 460 */
464static void 461static void
465handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm) 462handle_get_default_message(void *cls, const struct GetDefaultMessage *gdm)
466{ 463{
467 struct GNUNET_MQ_Envelope *env; 464 struct GNUNET_MQ_Envelope *env;
468 struct GNUNET_SERVICE_Client *client = cls; 465 struct GNUNET_SERVICE_Client *client = cls;
@@ -471,41 +468,41 @@ handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
471 char *identifier; 468 char *identifier;
472 469
473 470
474 name = GNUNET_strdup ((const char *) &gdm[1]); 471 name = GNUNET_strdup((const char *)&gdm[1]);
475 GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name); 472 GNUNET_STRINGS_utf8_tolower((const char *)&gdm[1], name);
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 473 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
477 "Received GET_DEFAULT for service `%s' from client\n", 474 "Received GET_DEFAULT for service `%s' from client\n",
478 name); 475 name);
479 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 476 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(subsystem_cfg,
480 name, 477 name,
481 "DEFAULT_IDENTIFIER", 478 "DEFAULT_IDENTIFIER",
482 &identifier)) 479 &identifier))
483 {
484 send_result_code (client, 1, gettext_noop ("no default known"));
485 GNUNET_SERVICE_client_continue (client);
486 GNUNET_free (name);
487 return;
488 }
489 for (ego = ego_head; NULL != ego; ego = ego->next)
490 {
491 if (0 == strcmp (ego->identifier, identifier))
492 { 480 {
493 env = create_set_default_message (ego, name); 481 send_result_code(client, 1, gettext_noop("no default known"));
494 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); 482 GNUNET_SERVICE_client_continue(client);
495 GNUNET_SERVICE_client_continue (client); 483 GNUNET_free(name);
496 GNUNET_free (identifier);
497 GNUNET_free (name);
498 return; 484 return;
499 } 485 }
500 } 486 for (ego = ego_head; NULL != ego; ego = ego->next)
501 GNUNET_free (identifier); 487 {
502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name); 488 if (0 == strcmp(ego->identifier, identifier))
503 GNUNET_free (name); 489 {
504 send_result_code (client, 490 env = create_set_default_message(ego, name);
505 1, 491 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env);
506 gettext_noop ( 492 GNUNET_SERVICE_client_continue(client);
507 "default configured, but ego unknown (internal error)")); 493 GNUNET_free(identifier);
508 GNUNET_SERVICE_client_continue (client); 494 GNUNET_free(name);
495 return;
496 }
497 }
498 GNUNET_free(identifier);
499 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name);
500 GNUNET_free(name);
501 send_result_code(client,
502 1,
503 gettext_noop(
504 "default configured, but ego unknown (internal error)"));
505 GNUNET_SERVICE_client_continue(client);
509} 506}
510 507
511 508
@@ -517,10 +514,10 @@ handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
517 * @return 0 if the keys are equal 514 * @return 0 if the keys are equal
518 */ 515 */
519static int 516static int
520key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1, 517key_cmp(const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
521 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2) 518 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2)
522{ 519{
523 return GNUNET_memcmp (pk1, pk2); 520 return GNUNET_memcmp(pk1, pk2);
524} 521}
525 522
526/** 523/**
@@ -531,31 +528,31 @@ key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
531 * @return #GNUNET_OK if @a msg is well-formed 528 * @return #GNUNET_OK if @a msg is well-formed
532 */ 529 */
533static int 530static int
534check_set_default_message (void *cls, const struct SetDefaultMessage *msg) 531check_set_default_message(void *cls, const struct SetDefaultMessage *msg)
535{ 532{
536 uint16_t size; 533 uint16_t size;
537 uint16_t name_len; 534 uint16_t name_len;
538 const char *str; 535 const char *str;
539 536
540 size = ntohs (msg->header.size); 537 size = ntohs(msg->header.size);
541 if (size <= sizeof (struct SetDefaultMessage)) 538 if (size <= sizeof(struct SetDefaultMessage))
542 { 539 {
543 GNUNET_break (0); 540 GNUNET_break(0);
544 return GNUNET_SYSERR; 541 return GNUNET_SYSERR;
545 } 542 }
546 name_len = ntohs (msg->name_len); 543 name_len = ntohs(msg->name_len);
547 GNUNET_break (0 == ntohs (msg->reserved)); 544 GNUNET_break(0 == ntohs(msg->reserved));
548 if (name_len + sizeof (struct SetDefaultMessage) != size) 545 if (name_len + sizeof(struct SetDefaultMessage) != size)
549 { 546 {
550 GNUNET_break (0); 547 GNUNET_break(0);
551 return GNUNET_SYSERR; 548 return GNUNET_SYSERR;
552 } 549 }
553 str = (const char *) &msg[1]; 550 str = (const char *)&msg[1];
554 if ('\0' != str[name_len - 1]) 551 if ('\0' != str[name_len - 1])
555 { 552 {
556 GNUNET_break (0); 553 GNUNET_break(0);
557 return GNUNET_SYSERR; 554 return GNUNET_SYSERR;
558 } 555 }
559 return GNUNET_OK; 556 return GNUNET_OK;
560} 557}
561 558
@@ -568,43 +565,43 @@ check_set_default_message (void *cls, const struct SetDefaultMessage *msg)
568 * @param message the message received 565 * @param message the message received
569 */ 566 */
570static void 567static void
571handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm) 568handle_set_default_message(void *cls, const struct SetDefaultMessage *sdm)
572{ 569{
573 struct Ego *ego; 570 struct Ego *ego;
574 struct GNUNET_SERVICE_Client *client = cls; 571 struct GNUNET_SERVICE_Client *client = cls;
575 char *str; 572 char *str;
576 573
577 str = GNUNET_strdup ((const char *) &sdm[1]); 574 str = GNUNET_strdup((const char *)&sdm[1]);
578 GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str); 575 GNUNET_STRINGS_utf8_tolower((const char *)&sdm[1], str);
579 576
580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 577 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
581 "Received SET_DEFAULT for service `%s' from client\n", 578 "Received SET_DEFAULT for service `%s' from client\n",
582 str); 579 str);
583 for (ego = ego_head; NULL != ego; ego = ego->next) 580 for (ego = ego_head; NULL != ego; ego = ego->next)
584 {
585 if (0 == key_cmp (ego->pk, &sdm->private_key))
586 { 581 {
587 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 582 if (0 == key_cmp(ego->pk, &sdm->private_key))
588 str, 583 {
589 "DEFAULT_IDENTIFIER", 584 GNUNET_CONFIGURATION_set_value_string(subsystem_cfg,
590 ego->identifier); 585 str,
591 if (GNUNET_OK != 586 "DEFAULT_IDENTIFIER",
592 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) 587 ego->identifier);
593 GNUNET_log ( 588 if (GNUNET_OK !=
594 GNUNET_ERROR_TYPE_ERROR, 589 GNUNET_CONFIGURATION_write(subsystem_cfg, subsystem_cfg_file))
595 _ ("Failed to write subsystem default identifier map to `%s'.\n"), 590 GNUNET_log(
596 subsystem_cfg_file); 591 GNUNET_ERROR_TYPE_ERROR,
597 send_result_code (client, 0, NULL); 592 _("Failed to write subsystem default identifier map to `%s'.\n"),
598 GNUNET_SERVICE_client_continue (client); 593 subsystem_cfg_file);
599 GNUNET_free (str); 594 send_result_code(client, 0, NULL);
600 return; 595 GNUNET_SERVICE_client_continue(client);
596 GNUNET_free(str);
597 return;
598 }
601 } 599 }
602 } 600 send_result_code(client,
603 send_result_code (client, 601 1,
604 1, 602 _("Unknown ego specified for service (internal error)"));
605 _ ("Unknown ego specified for service (internal error)")); 603 GNUNET_free(str);
606 GNUNET_free (str); 604 GNUNET_SERVICE_client_continue(client);
607 GNUNET_SERVICE_client_continue (client);
608} 605}
609 606
610 607
@@ -614,21 +611,21 @@ handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm)
614 * @param ego ego to send the update for 611 * @param ego ego to send the update for
615 */ 612 */
616static void 613static void
617notify_listeners (struct Ego *ego) 614notify_listeners(struct Ego *ego)
618{ 615{
619 struct UpdateMessage *um; 616 struct UpdateMessage *um;
620 size_t name_len; 617 size_t name_len;
621 618
622 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1); 619 name_len = (NULL == ego->identifier) ? 0 : (strlen(ego->identifier) + 1);
623 um = GNUNET_malloc (sizeof (struct UpdateMessage) + name_len); 620 um = GNUNET_malloc(sizeof(struct UpdateMessage) + name_len);
624 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE); 621 um->header.type = htons(GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
625 um->header.size = htons (sizeof (struct UpdateMessage) + name_len); 622 um->header.size = htons(sizeof(struct UpdateMessage) + name_len);
626 um->name_len = htons (name_len); 623 um->name_len = htons(name_len);
627 um->end_of_list = htons (GNUNET_NO); 624 um->end_of_list = htons(GNUNET_NO);
628 um->private_key = *ego->pk; 625 um->private_key = *ego->pk;
629 GNUNET_memcpy (&um[1], ego->identifier, name_len); 626 GNUNET_memcpy(&um[1], ego->identifier, name_len);
630 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO); 627 GNUNET_notification_context_broadcast(nc, &um->header, GNUNET_NO);
631 GNUNET_free (um); 628 GNUNET_free(um);
632} 629}
633 630
634/** 631/**
@@ -639,32 +636,31 @@ notify_listeners (struct Ego *ego)
639 * @return #GNUNET_OK if @a msg is well-formed 636 * @return #GNUNET_OK if @a msg is well-formed
640 */ 637 */
641static int 638static int
642check_create_message (void *cls, const struct CreateRequestMessage *msg) 639check_create_message(void *cls, const struct CreateRequestMessage *msg)
643{ 640{
644
645 uint16_t size; 641 uint16_t size;
646 uint16_t name_len; 642 uint16_t name_len;
647 const char *str; 643 const char *str;
648 644
649 size = ntohs (msg->header.size); 645 size = ntohs(msg->header.size);
650 if (size <= sizeof (struct CreateRequestMessage)) 646 if (size <= sizeof(struct CreateRequestMessage))
651 { 647 {
652 GNUNET_break (0); 648 GNUNET_break(0);
653 return GNUNET_SYSERR; 649 return GNUNET_SYSERR;
654 } 650 }
655 name_len = ntohs (msg->name_len); 651 name_len = ntohs(msg->name_len);
656 GNUNET_break (0 == ntohs (msg->reserved)); 652 GNUNET_break(0 == ntohs(msg->reserved));
657 if (name_len + sizeof (struct CreateRequestMessage) != size) 653 if (name_len + sizeof(struct CreateRequestMessage) != size)
658 { 654 {
659 GNUNET_break (0); 655 GNUNET_break(0);
660 return GNUNET_SYSERR; 656 return GNUNET_SYSERR;
661 } 657 }
662 str = (const char *) &msg[1]; 658 str = (const char *)&msg[1];
663 if ('\0' != str[name_len - 1]) 659 if ('\0' != str[name_len - 1])
664 { 660 {
665 GNUNET_break (0); 661 GNUNET_break(0);
666 return GNUNET_SYSERR; 662 return GNUNET_SYSERR;
667 } 663 }
668 return GNUNET_OK; 664 return GNUNET_OK;
669} 665}
670 666
@@ -677,56 +673,55 @@ check_create_message (void *cls, const struct CreateRequestMessage *msg)
677 * @param message the message received 673 * @param message the message received
678 */ 674 */
679static void 675static void
680handle_create_message (void *cls, const struct CreateRequestMessage *crm) 676handle_create_message(void *cls, const struct CreateRequestMessage *crm)
681{ 677{
682 struct GNUNET_SERVICE_Client *client = cls; 678 struct GNUNET_SERVICE_Client *client = cls;
683 struct Ego *ego; 679 struct Ego *ego;
684 char *str; 680 char *str;
685 char *fn; 681 char *fn;
686 682
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n"); 683 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
688 str = GNUNET_strdup ((const char *) &crm[1]); 684 str = GNUNET_strdup((const char *)&crm[1]);
689 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str); 685 GNUNET_STRINGS_utf8_tolower((const char *)&crm[1], str);
690 for (ego = ego_head; NULL != ego; ego = ego->next) 686 for (ego = ego_head; NULL != ego; ego = ego->next)
691 {
692 if (0 == strcmp (ego->identifier, str))
693 { 687 {
694 send_result_code (client, 688 if (0 == strcmp(ego->identifier, str))
695 1, 689 {
696 gettext_noop ( 690 send_result_code(client,
697 "identifier already in use for another ego")); 691 1,
698 GNUNET_SERVICE_client_continue (client); 692 gettext_noop(
699 GNUNET_free (str); 693 "identifier already in use for another ego"));
700 return; 694 GNUNET_SERVICE_client_continue(client);
695 GNUNET_free(str);
696 return;
697 }
701 } 698 }
702 } 699 ego = GNUNET_new(struct Ego);
703 ego = GNUNET_new (struct Ego); 700 ego->pk = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey);
704 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
705 *ego->pk = crm->private_key; 701 *ego->pk = crm->private_key;
706 ego->identifier = GNUNET_strdup (str); 702 ego->identifier = GNUNET_strdup(str);
707 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); 703 GNUNET_CONTAINER_DLL_insert(ego_head, ego_tail, ego);
708 send_result_code (client, 0, NULL); 704 send_result_code(client, 0, NULL);
709 fn = get_ego_filename (ego); 705 fn = get_ego_filename(ego);
710 (void) GNUNET_DISK_directory_create_for_file (fn); 706 (void)GNUNET_DISK_directory_create_for_file(fn);
711 if (sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey) != 707 if (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey) !=
712 GNUNET_DISK_fn_write (fn, 708 GNUNET_DISK_fn_write(fn,
713 &crm->private_key, 709 &crm->private_key,
714 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey), 710 sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey),
715 GNUNET_DISK_PERM_USER_READ | 711 GNUNET_DISK_PERM_USER_READ |
716 GNUNET_DISK_PERM_USER_WRITE)) 712 GNUNET_DISK_PERM_USER_WRITE))
717 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn); 713 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "write", fn);
718 GNUNET_free (fn); 714 GNUNET_free(fn);
719 GNUNET_free (str); 715 GNUNET_free(str);
720 notify_listeners (ego); 716 notify_listeners(ego);
721 GNUNET_SERVICE_client_continue (client); 717 GNUNET_SERVICE_client_continue(client);
722} 718}
723 719
724 720
725/** 721/**
726 * Closure for 'handle_ego_rename'. 722 * Closure for 'handle_ego_rename'.
727 */ 723 */
728struct RenameContext 724struct RenameContext {
729{
730 /** 725 /**
731 * Old name. 726 * Old name.
732 */ 727 */
@@ -746,26 +741,26 @@ struct RenameContext
746 * @param section a section in the configuration to process 741 * @param section a section in the configuration to process
747 */ 742 */
748static void 743static void
749handle_ego_rename (void *cls, const char *section) 744handle_ego_rename(void *cls, const char *section)
750{ 745{
751 struct RenameContext *rc = cls; 746 struct RenameContext *rc = cls;
752 char *id; 747 char *id;
753 748
754 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 749 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(subsystem_cfg,
755 section, 750 section,
756 "DEFAULT_IDENTIFIER", 751 "DEFAULT_IDENTIFIER",
757 &id)) 752 &id))
758 return; 753 return;
759 if (0 != strcmp (id, rc->old_name)) 754 if (0 != strcmp(id, rc->old_name))
760 { 755 {
761 GNUNET_free (id); 756 GNUNET_free(id);
762 return; 757 return;
763 } 758 }
764 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 759 GNUNET_CONFIGURATION_set_value_string(subsystem_cfg,
765 section, 760 section,
766 "DEFAULT_IDENTIFIER", 761 "DEFAULT_IDENTIFIER",
767 rc->new_name); 762 rc->new_name);
768 GNUNET_free (id); 763 GNUNET_free(id);
769} 764}
770 765
771/** 766/**
@@ -776,7 +771,7 @@ handle_ego_rename (void *cls, const char *section)
776 * @return #GNUNET_OK if @a msg is well-formed 771 * @return #GNUNET_OK if @a msg is well-formed
777 */ 772 */
778static int 773static int
779check_rename_message (void *cls, const struct RenameMessage *msg) 774check_rename_message(void *cls, const struct RenameMessage *msg)
780{ 775{
781 uint16_t size; 776 uint16_t size;
782 uint16_t old_name_len; 777 uint16_t old_name_len;
@@ -784,23 +779,23 @@ check_rename_message (void *cls, const struct RenameMessage *msg)
784 const char *old_name; 779 const char *old_name;
785 const char *new_name; 780 const char *new_name;
786 781
787 size = ntohs (msg->header.size); 782 size = ntohs(msg->header.size);
788 if (size <= sizeof (struct RenameMessage)) 783 if (size <= sizeof(struct RenameMessage))
789 { 784 {
790 GNUNET_break (0); 785 GNUNET_break(0);
791 return GNUNET_SYSERR; 786 return GNUNET_SYSERR;
792 } 787 }
793 old_name_len = ntohs (msg->old_name_len); 788 old_name_len = ntohs(msg->old_name_len);
794 new_name_len = ntohs (msg->new_name_len); 789 new_name_len = ntohs(msg->new_name_len);
795 old_name = (const char *) &msg[1]; 790 old_name = (const char *)&msg[1];
796 new_name = &old_name[old_name_len]; 791 new_name = &old_name[old_name_len];
797 if ((old_name_len + new_name_len + sizeof (struct RenameMessage) != size) || 792 if ((old_name_len + new_name_len + sizeof(struct RenameMessage) != size) ||
798 ('\0' != old_name[old_name_len - 1]) || 793 ('\0' != old_name[old_name_len - 1]) ||
799 ('\0' != new_name[new_name_len - 1])) 794 ('\0' != new_name[new_name_len - 1]))
800 { 795 {
801 GNUNET_break (0); 796 GNUNET_break(0);
802 return GNUNET_SYSERR; 797 return GNUNET_SYSERR;
803 } 798 }
804 799
805 return GNUNET_OK; 800 return GNUNET_OK;
806} 801}
@@ -815,7 +810,7 @@ check_rename_message (void *cls, const struct RenameMessage *msg)
815 * @param message the message received 810 * @param message the message received
816 */ 811 */
817static void 812static void
818handle_rename_message (void *cls, const struct RenameMessage *rm) 813handle_rename_message(void *cls, const struct RenameMessage *rm)
819{ 814{
820 uint16_t old_name_len; 815 uint16_t old_name_len;
821 struct Ego *ego; 816 struct Ego *ego;
@@ -827,65 +822,65 @@ handle_rename_message (void *cls, const struct RenameMessage *rm)
827 char *fn_new; 822 char *fn_new;
828 const char *old_name_tmp; 823 const char *old_name_tmp;
829 824
830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n"); 825 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
831 old_name_len = ntohs (rm->old_name_len); 826 old_name_len = ntohs(rm->old_name_len);
832 old_name_tmp = (const char *) &rm[1]; 827 old_name_tmp = (const char *)&rm[1];
833 old_name = GNUNET_strdup (old_name_tmp); 828 old_name = GNUNET_strdup(old_name_tmp);
834 GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name); 829 GNUNET_STRINGS_utf8_tolower(old_name_tmp, old_name);
835 new_name = GNUNET_strdup (&old_name_tmp[old_name_len]); 830 new_name = GNUNET_strdup(&old_name_tmp[old_name_len]);
836 GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name); 831 GNUNET_STRINGS_utf8_tolower(&old_name_tmp[old_name_len], new_name);
837 832
838 /* check if new name is already in use */ 833 /* check if new name is already in use */
839 for (ego = ego_head; NULL != ego; ego = ego->next) 834 for (ego = ego_head; NULL != ego; ego = ego->next)
840 {
841 if (0 == strcmp (ego->identifier, new_name))
842 { 835 {
843 send_result_code (client, 1, gettext_noop ("target name already exists")); 836 if (0 == strcmp(ego->identifier, new_name))
844 GNUNET_SERVICE_client_continue (client); 837 {
845 GNUNET_free (old_name); 838 send_result_code(client, 1, gettext_noop("target name already exists"));
846 GNUNET_free (new_name); 839 GNUNET_SERVICE_client_continue(client);
847 return; 840 GNUNET_free(old_name);
841 GNUNET_free(new_name);
842 return;
843 }
848 } 844 }
849 }
850 845
851 /* locate old name and, if found, perform rename */ 846 /* locate old name and, if found, perform rename */
852 for (ego = ego_head; NULL != ego; ego = ego->next) 847 for (ego = ego_head; NULL != ego; ego = ego->next)
853 {
854 if (0 == strcmp (ego->identifier, old_name))
855 { 848 {
856 fn_old = get_ego_filename (ego); 849 if (0 == strcmp(ego->identifier, old_name))
857 GNUNET_free (ego->identifier); 850 {
858 rename_ctx.old_name = old_name; 851 fn_old = get_ego_filename(ego);
859 rename_ctx.new_name = new_name; 852 GNUNET_free(ego->identifier);
860 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, 853 rename_ctx.old_name = old_name;
861 &handle_ego_rename, 854 rename_ctx.new_name = new_name;
862 &rename_ctx); 855 GNUNET_CONFIGURATION_iterate_sections(subsystem_cfg,
863 if (GNUNET_OK != 856 &handle_ego_rename,
864 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) 857 &rename_ctx);
865 GNUNET_log ( 858 if (GNUNET_OK !=
866 GNUNET_ERROR_TYPE_ERROR, 859 GNUNET_CONFIGURATION_write(subsystem_cfg, subsystem_cfg_file))
867 _ ("Failed to write subsystem default identifier map to `%s'.\n"), 860 GNUNET_log(
868 subsystem_cfg_file); 861 GNUNET_ERROR_TYPE_ERROR,
869 ego->identifier = GNUNET_strdup (new_name); 862 _("Failed to write subsystem default identifier map to `%s'.\n"),
870 fn_new = get_ego_filename (ego); 863 subsystem_cfg_file);
871 if (0 != rename (fn_old, fn_new)) 864 ego->identifier = GNUNET_strdup(new_name);
872 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); 865 fn_new = get_ego_filename(ego);
873 GNUNET_free (fn_old); 866 if (0 != rename(fn_old, fn_new))
874 GNUNET_free (fn_new); 867 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
875 GNUNET_free (old_name); 868 GNUNET_free(fn_old);
876 GNUNET_free (new_name); 869 GNUNET_free(fn_new);
877 notify_listeners (ego); 870 GNUNET_free(old_name);
878 send_result_code (client, 0, NULL); 871 GNUNET_free(new_name);
879 GNUNET_SERVICE_client_continue (client); 872 notify_listeners(ego);
880 return; 873 send_result_code(client, 0, NULL);
874 GNUNET_SERVICE_client_continue(client);
875 return;
876 }
881 } 877 }
882 }
883 878
884 /* failed to locate old name */ 879 /* failed to locate old name */
885 send_result_code (client, 1, gettext_noop ("no matching ego found")); 880 send_result_code(client, 1, gettext_noop("no matching ego found"));
886 GNUNET_free (old_name); 881 GNUNET_free(old_name);
887 GNUNET_free (new_name); 882 GNUNET_free(new_name);
888 GNUNET_SERVICE_client_continue (client); 883 GNUNET_SERVICE_client_continue(client);
889} 884}
890 885
891 886
@@ -897,26 +892,26 @@ handle_rename_message (void *cls, const struct RenameMessage *rm)
897 * @param section a section in the configuration to process 892 * @param section a section in the configuration to process
898 */ 893 */
899static void 894static void
900handle_ego_delete (void *cls, const char *section) 895handle_ego_delete(void *cls, const char *section)
901{ 896{
902 const char *identifier = cls; 897 const char *identifier = cls;
903 char *id; 898 char *id;
904 899
905 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 900 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(subsystem_cfg,
906 section, 901 section,
907 "DEFAULT_IDENTIFIER", 902 "DEFAULT_IDENTIFIER",
908 &id)) 903 &id))
909 return; 904 return;
910 if (0 != strcmp (id, identifier)) 905 if (0 != strcmp(id, identifier))
911 { 906 {
912 GNUNET_free (id); 907 GNUNET_free(id);
913 return; 908 return;
914 } 909 }
915 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, 910 GNUNET_CONFIGURATION_set_value_string(subsystem_cfg,
916 section, 911 section,
917 "DEFAULT_IDENTIFIER", 912 "DEFAULT_IDENTIFIER",
918 NULL); 913 NULL);
919 GNUNET_free (id); 914 GNUNET_free(id);
920} 915}
921 916
922/** 917/**
@@ -927,26 +922,26 @@ handle_ego_delete (void *cls, const char *section)
927 * @return #GNUNET_OK if @a msg is well-formed 922 * @return #GNUNET_OK if @a msg is well-formed
928 */ 923 */
929static int 924static int
930check_delete_message (void *cls, const struct DeleteMessage *msg) 925check_delete_message(void *cls, const struct DeleteMessage *msg)
931{ 926{
932 uint16_t size; 927 uint16_t size;
933 uint16_t name_len; 928 uint16_t name_len;
934 const char *name; 929 const char *name;
935 930
936 size = ntohs (msg->header.size); 931 size = ntohs(msg->header.size);
937 if (size <= sizeof (struct DeleteMessage)) 932 if (size <= sizeof(struct DeleteMessage))
938 { 933 {
939 GNUNET_break (0); 934 GNUNET_break(0);
940 return GNUNET_SYSERR; 935 return GNUNET_SYSERR;
941 } 936 }
942 name = (const char *) &msg[1]; 937 name = (const char *)&msg[1];
943 name_len = ntohs (msg->name_len); 938 name_len = ntohs(msg->name_len);
944 if ((name_len + sizeof (struct DeleteMessage) != size) || 939 if ((name_len + sizeof(struct DeleteMessage) != size) ||
945 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1])) 940 (0 != ntohs(msg->reserved)) || ('\0' != name[name_len - 1]))
946 { 941 {
947 GNUNET_break (0); 942 GNUNET_break(0);
948 return GNUNET_SYSERR; 943 return GNUNET_SYSERR;
949 } 944 }
950 return GNUNET_OK; 945 return GNUNET_OK;
951} 946}
952 947
@@ -960,50 +955,50 @@ check_delete_message (void *cls, const struct DeleteMessage *msg)
960 * @param message the message received 955 * @param message the message received
961 */ 956 */
962static void 957static void
963handle_delete_message (void *cls, const struct DeleteMessage *dm) 958handle_delete_message(void *cls, const struct DeleteMessage *dm)
964{ 959{
965 struct Ego *ego; 960 struct Ego *ego;
966 char *name; 961 char *name;
967 char *fn; 962 char *fn;
968 struct GNUNET_SERVICE_Client *client = cls; 963 struct GNUNET_SERVICE_Client *client = cls;
969 964
970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n"); 965 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
971 name = GNUNET_strdup ((const char *) &dm[1]); 966 name = GNUNET_strdup((const char *)&dm[1]);
972 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name); 967 GNUNET_STRINGS_utf8_tolower((const char *)&dm[1], name);
973 968
974 for (ego = ego_head; NULL != ego; ego = ego->next) 969 for (ego = ego_head; NULL != ego; ego = ego->next)
975 {
976 if (0 == strcmp (ego->identifier, name))
977 { 970 {
978 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego); 971 if (0 == strcmp(ego->identifier, name))
979 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, 972 {
980 &handle_ego_delete, 973 GNUNET_CONTAINER_DLL_remove(ego_head, ego_tail, ego);
981 ego->identifier); 974 GNUNET_CONFIGURATION_iterate_sections(subsystem_cfg,
982 if (GNUNET_OK != 975 &handle_ego_delete,
983 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) 976 ego->identifier);
984 GNUNET_log ( 977 if (GNUNET_OK !=
985 GNUNET_ERROR_TYPE_ERROR, 978 GNUNET_CONFIGURATION_write(subsystem_cfg, subsystem_cfg_file))
986 _ ("Failed to write subsystem default identifier map to `%s'.\n"), 979 GNUNET_log(
987 subsystem_cfg_file); 980 GNUNET_ERROR_TYPE_ERROR,
988 fn = get_ego_filename (ego); 981 _("Failed to write subsystem default identifier map to `%s'.\n"),
989 if (0 != unlink (fn)) 982 subsystem_cfg_file);
990 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); 983 fn = get_ego_filename(ego);
991 GNUNET_free (fn); 984 if (0 != unlink(fn))
992 GNUNET_free (ego->identifier); 985 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
993 ego->identifier = NULL; 986 GNUNET_free(fn);
994 notify_listeners (ego); 987 GNUNET_free(ego->identifier);
995 GNUNET_free (ego->pk); 988 ego->identifier = NULL;
996 GNUNET_free (ego); 989 notify_listeners(ego);
997 GNUNET_free (name); 990 GNUNET_free(ego->pk);
998 send_result_code (client, 0, NULL); 991 GNUNET_free(ego);
999 GNUNET_SERVICE_client_continue (client); 992 GNUNET_free(name);
1000 return; 993 send_result_code(client, 0, NULL);
994 GNUNET_SERVICE_client_continue(client);
995 return;
996 }
1001 } 997 }
1002 }
1003 998
1004 send_result_code (client, 1, gettext_noop ("no matching ego found")); 999 send_result_code(client, 1, gettext_noop("no matching ego found"));
1005 GNUNET_free (name); 1000 GNUNET_free(name);
1006 GNUNET_SERVICE_client_continue (client); 1001 GNUNET_SERVICE_client_continue(client);
1007} 1002}
1008 1003
1009 1004
@@ -1018,30 +1013,30 @@ handle_delete_message (void *cls, const struct DeleteMessage *dm)
1018 * #GNUNET_SYSERR to abort iteration with error! 1013 * #GNUNET_SYSERR to abort iteration with error!
1019 */ 1014 */
1020static int 1015static int
1021process_ego_file (void *cls, const char *filename) 1016process_ego_file(void *cls, const char *filename)
1022{ 1017{
1023 struct Ego *ego; 1018 struct Ego *ego;
1024 const char *fn; 1019 const char *fn;
1025 1020
1026 fn = strrchr (filename, (int) DIR_SEPARATOR); 1021 fn = strrchr(filename, (int)DIR_SEPARATOR);
1027 if (NULL == fn) 1022 if (NULL == fn)
1028 { 1023 {
1029 GNUNET_break (0); 1024 GNUNET_break(0);
1030 return GNUNET_OK; 1025 return GNUNET_OK;
1031 } 1026 }
1032 ego = GNUNET_new (struct Ego); 1027 ego = GNUNET_new(struct Ego);
1033 ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file (filename); 1028 ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file(filename);
1034 if (NULL == ego->pk) 1029 if (NULL == ego->pk)
1035 { 1030 {
1036 GNUNET_free (ego); 1031 GNUNET_free(ego);
1037 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1032 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1038 _ ("Failed to parse ego information in `%s'\n"), 1033 _("Failed to parse ego information in `%s'\n"),
1039 filename); 1034 filename);
1040 return GNUNET_OK; 1035 return GNUNET_OK;
1041 } 1036 }
1042 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1); 1037 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1);
1043 ego->identifier = GNUNET_strdup (fn + 1); 1038 ego->identifier = GNUNET_strdup(fn + 1);
1044 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego); 1039 GNUNET_CONTAINER_DLL_insert(ego_head, ego_tail, ego);
1045 return GNUNET_OK; 1040 return GNUNET_OK;
1046} 1041}
1047 1042
@@ -1054,103 +1049,103 @@ process_ego_file (void *cls, const char *filename)
1054 * @param c configuration to use 1049 * @param c configuration to use
1055 */ 1050 */
1056static void 1051static void
1057run (void *cls, 1052run(void *cls,
1058 const struct GNUNET_CONFIGURATION_Handle *c, 1053 const struct GNUNET_CONFIGURATION_Handle *c,
1059 struct GNUNET_SERVICE_Handle *service) 1054 struct GNUNET_SERVICE_Handle *service)
1060{ 1055{
1061 cfg = c; 1056 cfg = c;
1062 nc = GNUNET_notification_context_create (1); 1057 nc = GNUNET_notification_context_create(1);
1063 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, 1058 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(cfg,
1064 "identity", 1059 "identity",
1065 "EGODIR", 1060 "EGODIR",
1066 &ego_directory)) 1061 &ego_directory))
1067 { 1062 {
1068 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); 1063 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
1069 GNUNET_SCHEDULER_shutdown (); 1064 GNUNET_SCHEDULER_shutdown();
1070 return; 1065 return;
1071 } 1066 }
1072 if (GNUNET_OK != 1067 if (GNUNET_OK !=
1073 GNUNET_CONFIGURATION_get_value_filename (cfg, 1068 GNUNET_CONFIGURATION_get_value_filename(cfg,
1074 "identity", 1069 "identity",
1075 "SUBSYSTEM_CFG", 1070 "SUBSYSTEM_CFG",
1076 &subsystem_cfg_file)) 1071 &subsystem_cfg_file))
1077 { 1072 {
1078 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1073 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
1079 "identity", 1074 "identity",
1080 "SUBSYSTEM_CFG"); 1075 "SUBSYSTEM_CFG");
1081 GNUNET_SCHEDULER_shutdown (); 1076 GNUNET_SCHEDULER_shutdown();
1082 return; 1077 return;
1083 } 1078 }
1084 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1079 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1085 "Loading subsystem configuration `%s'\n", 1080 "Loading subsystem configuration `%s'\n",
1086 subsystem_cfg_file); 1081 subsystem_cfg_file);
1087 subsystem_cfg = GNUNET_CONFIGURATION_create (); 1082 subsystem_cfg = GNUNET_CONFIGURATION_create();
1088 if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) && 1083 if ((GNUNET_YES == GNUNET_DISK_file_test(subsystem_cfg_file)) &&
1089 (GNUNET_OK != 1084 (GNUNET_OK !=
1090 GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file))) 1085 GNUNET_CONFIGURATION_parse(subsystem_cfg, subsystem_cfg_file)))
1091 { 1086 {
1092 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1087 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1093 _ ( 1088 _(
1094 "Failed to parse subsystem identity configuration file `%s'\n"), 1089 "Failed to parse subsystem identity configuration file `%s'\n"),
1095 subsystem_cfg_file); 1090 subsystem_cfg_file);
1096 GNUNET_SCHEDULER_shutdown (); 1091 GNUNET_SCHEDULER_shutdown();
1097 return; 1092 return;
1098 } 1093 }
1099 stats = GNUNET_STATISTICS_create ("identity", cfg); 1094 stats = GNUNET_STATISTICS_create("identity", cfg);
1100 if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory)) 1095 if (GNUNET_OK != GNUNET_DISK_directory_create(ego_directory))
1101 { 1096 {
1102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1097 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1103 _ ("Failed to create directory `%s' for storing egos\n"), 1098 _("Failed to create directory `%s' for storing egos\n"),
1104 ego_directory); 1099 ego_directory);
1105 } 1100 }
1106 GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL); 1101 GNUNET_DISK_directory_scan(ego_directory, &process_ego_file, NULL);
1107 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 1102 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
1108} 1103}
1109 1104
1110 1105
1111/** 1106/**
1112 * Define "main" method using service macro. 1107 * Define "main" method using service macro.
1113 */ 1108 */
1114GNUNET_SERVICE_MAIN ( 1109GNUNET_SERVICE_MAIN(
1115 "identity", 1110 "identity",
1116 GNUNET_SERVICE_OPTION_NONE, 1111 GNUNET_SERVICE_OPTION_NONE,
1117 &run, 1112 &run,
1118 &client_connect_cb, 1113 &client_connect_cb,
1119 &client_disconnect_cb, 1114 &client_disconnect_cb,
1120 NULL, 1115 NULL,
1121 GNUNET_MQ_hd_fixed_size (start_message, 1116 GNUNET_MQ_hd_fixed_size(start_message,
1122 GNUNET_MESSAGE_TYPE_IDENTITY_START, 1117 GNUNET_MESSAGE_TYPE_IDENTITY_START,
1123 struct GNUNET_MessageHeader, 1118 struct GNUNET_MessageHeader,
1124 NULL), 1119 NULL),
1125 GNUNET_MQ_hd_var_size (lookup_message, 1120 GNUNET_MQ_hd_var_size(lookup_message,
1126 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, 1121 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
1127 struct LookupMessage, 1122 struct LookupMessage,
1128 NULL), 1123 NULL),
1129 GNUNET_MQ_hd_var_size (lookup_by_suffix_message, 1124 GNUNET_MQ_hd_var_size(lookup_by_suffix_message,
1130 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, 1125 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX,
1131 struct LookupMessage, 1126 struct LookupMessage,
1132 NULL), 1127 NULL),
1133 GNUNET_MQ_hd_var_size (get_default_message, 1128 GNUNET_MQ_hd_var_size(get_default_message,
1134 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, 1129 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
1135 struct GetDefaultMessage, 1130 struct GetDefaultMessage,
1136 NULL), 1131 NULL),
1137 GNUNET_MQ_hd_var_size (set_default_message, 1132 GNUNET_MQ_hd_var_size(set_default_message,
1138 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 1133 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
1139 struct SetDefaultMessage, 1134 struct SetDefaultMessage,
1140 NULL), 1135 NULL),
1141 GNUNET_MQ_hd_var_size (create_message, 1136 GNUNET_MQ_hd_var_size(create_message,
1142 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, 1137 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
1143 struct CreateRequestMessage, 1138 struct CreateRequestMessage,
1144 NULL), 1139 NULL),
1145 GNUNET_MQ_hd_var_size (rename_message, 1140 GNUNET_MQ_hd_var_size(rename_message,
1146 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, 1141 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
1147 struct RenameMessage, 1142 struct RenameMessage,
1148 NULL), 1143 NULL),
1149 GNUNET_MQ_hd_var_size (delete_message, 1144 GNUNET_MQ_hd_var_size(delete_message,
1150 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, 1145 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
1151 struct DeleteMessage, 1146 struct DeleteMessage,
1152 NULL), 1147 NULL),
1153 GNUNET_MQ_handler_end ()); 1148 GNUNET_MQ_handler_end());
1154 1149
1155 1150
1156/* end of gnunet-service-identity.c */ 1151/* end of gnunet-service-identity.c */