aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-15 21:56:32 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-15 21:56:32 +0000
commit40de04e450a22baca40ce7c02b935d0bd9863f8d (patch)
tree4d30e10aa5db91140c09010985e9854c8075559f /src
parentd0550c56cee3e21663b5a09e97024aef69fb83a7 (diff)
downloadgnunet-40de04e450a22baca40ce7c02b935d0bd9863f8d.tar.gz
gnunet-40de04e450a22baca40ce7c02b935d0bd9863f8d.zip
-handle get default
Diffstat (limited to 'src')
-rw-r--r--src/identity/gnunet-service-identity.c94
1 files changed, 89 insertions, 5 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 8284b6537..050628e59 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -207,6 +207,37 @@ create_update_message (struct Ego *ego)
207 207
208 208
209/** 209/**
210 * Create a set default message with information about the current state of an ego.
211 *
212 * @param ego ego to create message for
213 * @return corresponding set default message
214 */
215static struct GNUNET_IDENTITY_SetDefaultMessage *
216create_set_default_message (struct Ego *ego)
217{
218 struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
219 char *str;
220 uint16_t pk_len;
221 size_t name_len;
222 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
223
224 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
225 enc = GNUNET_CRYPTO_ecc_encode_key (ego->pk);
226 pk_len = ntohs (enc->size);
227 sdm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len);
228 sdm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
229 sdm->header.size = htons (sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) + pk_len + name_len);
230 sdm->name_len = htons (name_len);
231 sdm->pk_len = htons (pk_len);
232 str = (char *) &sdm[1];
233 memcpy (str, enc, pk_len);
234 memcpy (&str[pk_len], ego->identifier, name_len);
235 GNUNET_free (enc);
236 return sdm;
237}
238
239
240/**
210 * Handler for START message from client, sends information 241 * Handler for START message from client, sends information
211 * about all identities to the client immediately and 242 * about all identities to the client immediately and
212 * adds the client to the notification context for future 243 * adds the client to the notification context for future
@@ -248,12 +279,61 @@ static void
248handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client, 279handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
249 const struct GNUNET_MessageHeader *message) 280 const struct GNUNET_MessageHeader *message)
250{ 281{
282 const struct GNUNET_IDENTITY_GetDefaultMessage *gdm;
283 struct GNUNET_IDENTITY_SetDefaultMessage *sdm;
284 uint16_t size;
285 uint16_t name_len;
286 struct Ego *ego;
287 const char *name;
288 char *identifier;
289
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "Received GET_DEFAULT message from client\n"); 291 "Received GET_DEFAULT message from client\n");
253 // setup_estimate_message (&em); 292 size = ntohs (message->size);
254 // GNUNET_SERVER_notification_context_unicast (nc, client, &em.header, GNUNET_YES); 293 if (size <= sizeof (struct GNUNET_IDENTITY_GetDefaultMessage))
255 GNUNET_break (0); // not implemented! 294 {
256 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 295 GNUNET_break (0);
296 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
297 return;
298 }
299 gdm = (const struct GNUNET_IDENTITY_GetDefaultMessage *) message;
300 name = (const char *) &gdm[1];
301 name_len = ntohs (gdm->name_len);
302 if ( (name_len + sizeof (struct GNUNET_IDENTITY_GetDefaultMessage) != size) ||
303 (0 != ntohs (gdm->reserved)) ||
304 ('\0' != name[name_len - 1]) )
305 {
306 GNUNET_break (0);
307 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
308 return;
309 }
310 if (GNUNET_OK !=
311 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
312 name,
313 "DEFAULT_IDENTIFIER",
314 &identifier))
315 {
316 /* FIXME: not sure client API handles this case correctly right now... */
317 send_result_code (client, 1, gettext_noop ("no default known"));
318 GNUNET_SERVER_receive_done (client, GNUNET_OK);
319 return;
320 }
321 for (ego = ego_head; NULL != ego; ego = ego->next)
322 {
323 if (0 == strcmp (ego->identifier,
324 identifier))
325 {
326 sdm = create_set_default_message (ego);
327 GNUNET_SERVER_notification_context_broadcast (nc, &sdm->header, GNUNET_YES);
328 GNUNET_free (sdm);
329 GNUNET_SERVER_receive_done (client, GNUNET_OK);
330 return;
331 }
332 }
333 /* FIXME: not sure client API handles this case correctly right now... */
334 send_result_code (client, 1,
335 gettext_noop ("default configured, but ego unknown (internal error)"));
336 GNUNET_SERVER_receive_done (client, GNUNET_OK);
257} 337}
258 338
259 339
@@ -497,12 +577,16 @@ handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client,
497 * 577 *
498 * @param cls NULL 578 * @param cls NULL
499 * @param filename name of the file to parse 579 * @param filename name of the file to parse
580 * @return GNUNET_OK to continue to iterate,
581 * GNUNET_NO to stop iteration with no error,
582 * GNUNET_SYSERR to abort iteration with error!
500 */ 583 */
501static void 584static int
502process_ego_file (void *cls, 585process_ego_file (void *cls,
503 const char *filename) 586 const char *filename)
504{ 587{
505 GNUNET_break (0); // not implemented 588 GNUNET_break (0); // not implemented
589 return GNUNET_OK;
506} 590}
507 591
508 592