aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/namestore_api.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-10-25 15:36:32 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-10-25 15:36:32 +0000
commit0b80f1a54fd5efba4bca8dc4269cc0cb8e25d77d (patch)
tree52a514ecf5d7cb4dda055a0a9c5c9ea0d78a8a77 /src/namestore/namestore_api.c
parent1ef878cfd071e9273ca2f8e11e743cfe6886ac1a (diff)
downloadgnunet-0b80f1a54fd5efba4bca8dc4269cc0cb8e25d77d.tar.gz
gnunet-0b80f1a54fd5efba4bca8dc4269cc0cb8e25d77d.zip
api communication done
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r--src/namestore/namestore_api.c75
1 files changed, 74 insertions, 1 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 9d290fca2..303b05c98 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -281,6 +281,72 @@ handle_record_store_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
281 281
282/** 282/**
283 * Handle an incoming message of type 283 * Handle an incoming message of type
284 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
285 *
286 * @param qe the respective entry in the message queue
287 * @param msg the message we received
288 * @param size the message size
289 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and we did NOT notify the client
290 */
291static int
292handle_lookup_result (struct GNUNET_NAMESTORE_QueueEntry *qe,
293 const struct LabelLookupResponseMessage *msg,
294 size_t size)
295{
296 const char *name;
297 const char *rd_tmp;
298 size_t exp_msg_len;
299 size_t msg_len;
300 size_t name_len;
301 size_t rd_len;
302 unsigned int rd_count;
303
304 LOG (GNUNET_ERROR_TYPE_DEBUG,
305 "Received `%s'\n",
306 "RECORD_LOOKUP_RESULT");
307
308 rd_len = ntohs (msg->rd_len);
309 rd_count = ntohs (msg->rd_count);
310 msg_len = ntohs (msg->gns_header.header.size);
311 name_len = ntohs (msg->name_len);
312 GNUNET_break (0 == ntohs (msg->reserved));
313 exp_msg_len = sizeof (struct LabelLookupResponseMessage) + name_len + rd_len;
314 if (msg_len != exp_msg_len)
315 {
316 GNUNET_break (0);
317 return GNUNET_SYSERR;
318 }
319 name = (const char *) &msg[1];
320 if ( (name_len > 0) &&
321 ('\0' != name[name_len -1]) )
322 {
323 GNUNET_break (0);
324 return GNUNET_SYSERR;
325 }
326 rd_tmp = &name[name_len];
327 {
328 struct GNUNET_GNSRECORD_Data rd[rd_count];
329
330 if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize(rd_len, rd_tmp, rd_count, rd))
331 {
332 GNUNET_break (0);
333 return GNUNET_SYSERR;
334 }
335 if (0 == name_len)
336 name = NULL;
337 if (NULL != qe->proc)
338 qe->proc (qe->proc_cls,
339 &msg->private_key,
340 name,
341 rd_count,
342 (rd_count > 0) ? rd : NULL);
343 }
344 return GNUNET_OK;
345}
346
347
348/**
349 * Handle an incoming message of type
284 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT 350 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
285 * 351 *
286 * @param qe the respective entry in the message queue 352 * @param qe the respective entry in the message queue
@@ -462,6 +528,13 @@ manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe,
462 return GNUNET_SYSERR; 528 return GNUNET_SYSERR;
463 } 529 }
464 return handle_record_result (qe, (const struct RecordResultMessage *) msg, size); 530 return handle_record_result (qe, (const struct RecordResultMessage *) msg, size);
531 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE:
532 if (size < sizeof (struct LabelLookupResponseMessage))
533 {
534 GNUNET_break (0);
535 return GNUNET_SYSERR;
536 }
537 return handle_lookup_result (qe, (const struct LabelLookupResponseMessage *) msg, size);
465 default: 538 default:
466 GNUNET_break (0); 539 GNUNET_break (0);
467 return GNUNET_SYSERR; 540 return GNUNET_SYSERR;
@@ -1026,7 +1099,7 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
1026 msg->gns_header.header.size = htons (msg_size); 1099 msg->gns_header.header.size = htons (msg_size);
1027 msg->gns_header.r_id = htonl (qe->op_id); 1100 msg->gns_header.r_id = htonl (qe->op_id);
1028 msg->zone = *pkey; 1101 msg->zone = *pkey;
1029 msg->label_len = htons(label_len); 1102 msg->label_len = htonl(label_len);
1030 memcpy (&msg[1], label, label_len); 1103 memcpy (&msg[1], label, label_len);
1031 1104
1032 /* transmit message */ 1105 /* transmit message */