aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_namestore_service.h28
-rw-r--r--src/namestore/gnunet-service-namestore.c41
-rw-r--r--src/namestore/namestore.h5
-rw-r--r--src/namestore/namestore_api.c26
-rw-r--r--src/namestore/plugin_rest_namestore.c107
5 files changed, 165 insertions, 42 deletions
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index 998eb19d0..f08c4746b 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -290,6 +290,33 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
290 GNUNET_NAMESTORE_RecordMonitor rm, 290 GNUNET_NAMESTORE_RecordMonitor rm,
291 void *rm_cls); 291 void *rm_cls);
292 292
293/**
294 * Lookup an item in the namestore with GNSRECORD filter.
295 *
296 * @param h handle to the namestore
297 * @param pkey private key of the zone
298 * @param label name that is being mapped
299 * @param error_cb function to call on error (i.e. disconnect)
300 * the handle is afterwards invalid
301 * @param error_cb_cls closure for @a error_cb
302 * @param rm function to call with the result (with 0 records if we don't have that label);
303 * the handle is afterwards invalid
304 * @param rm_cls closure for @a rm
305 * @param filter the record set filter to use
306 * @return handle to abort the request
307 */
308struct GNUNET_NAMESTORE_QueueEntry *
309GNUNET_NAMESTORE_records_lookup2 (struct GNUNET_NAMESTORE_Handle *h,
310 const struct
311 GNUNET_IDENTITY_PrivateKey *pkey,
312 const char *label,
313 GNUNET_SCHEDULER_TaskCallback error_cb,
314 void *error_cb_cls,
315 GNUNET_NAMESTORE_RecordMonitor rm,
316 void *rm_cls,
317 enum GNUNET_GNSRECORD_Filter filter);
318
319
293 320
294/** 321/**
295 * Look for an existing PKEY delegation record for a given public key. 322 * Look for an existing PKEY delegation record for a given public key.
@@ -393,6 +420,7 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
393 * @param finish_cb function to call on completion 420 * @param finish_cb function to call on completion
394 * the handle is afterwards invalid 421 * the handle is afterwards invalid
395 * @param finish_cb_cls closure for @a finish_cb 422 * @param finish_cb_cls closure for @a finish_cb
423 * @param filter the record set filter to use
396 * @return an iterator handle to use for iteration 424 * @return an iterator handle to use for iteration
397 */ 425 */
398struct GNUNET_NAMESTORE_ZoneIterator * 426struct GNUNET_NAMESTORE_ZoneIterator *
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index b2cc826fd..c164fed3a 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1272,32 +1272,37 @@ client_connect_cb (void *cls,
1272struct RecordLookupContext 1272struct RecordLookupContext
1273{ 1273{
1274 /** 1274 /**
1275 * FIXME. 1275 * The label to look up.
1276 */ 1276 */
1277 const char *label; 1277 const char *label;
1278 1278
1279 /** 1279 /**
1280 * FIXME. 1280 * The record result.
1281 */ 1281 */
1282 char *res_rd; 1282 char *res_rd;
1283 1283
1284 /** 1284 /**
1285 * FIXME. 1285 * The nick for the zone.
1286 */ 1286 */
1287 struct GNUNET_GNSRECORD_Data *nick; 1287 struct GNUNET_GNSRECORD_Data *nick;
1288 1288
1289 /** 1289 /**
1290 * FIXME. 1290 * If a record set was found or not.
1291 */ 1291 */
1292 int found; 1292 int found;
1293 1293
1294 /** 1294 /**
1295 * FIXME. 1295 * The record filter
1296 */
1297 enum GNUNET_GNSRECORD_Filter filter;
1298
1299 /**
1300 * The number of found records.
1296 */ 1301 */
1297 unsigned int res_rd_count; 1302 unsigned int res_rd_count;
1298 1303
1299 /** 1304 /**
1300 * FIXME. 1305 * The length of the serialized records.
1301 */ 1306 */
1302 ssize_t rd_ser_len; 1307 ssize_t rd_ser_len;
1303}; 1308};
@@ -1320,16 +1325,35 @@ lookup_it (void *cls,
1320 uint64_t seq, 1325 uint64_t seq,
1321 const struct GNUNET_IDENTITY_PrivateKey *private_key, 1326 const struct GNUNET_IDENTITY_PrivateKey *private_key,
1322 const char *label, 1327 const char *label,
1323 unsigned int rd_count, 1328 unsigned int rd_count_nf,
1324 const struct GNUNET_GNSRECORD_Data *rd) 1329 const struct GNUNET_GNSRECORD_Data *rd_nf)
1325{ 1330{
1326 struct RecordLookupContext *rlc = cls; 1331 struct RecordLookupContext *rlc = cls;
1332 struct GNUNET_GNSRECORD_Data rd[rd_count_nf];
1333 struct GNUNET_TIME_Absolute block_exp;
1334 unsigned int rd_count = 0;
1335 char *emsg;
1327 1336
1328 (void) private_key; 1337 (void) private_key;
1329 GNUNET_assert (0 != seq); 1338 GNUNET_assert (0 != seq);
1330 if (0 != strcmp (label, rlc->label)) 1339 if (0 != strcmp (label, rlc->label))
1331 return; 1340 return;
1332 rlc->found = GNUNET_YES; 1341 rlc->found = GNUNET_YES;
1342
1343 if (GNUNET_OK != GNUNET_GNSRECORD_normalize_record_set (rlc->label,
1344 rd_nf,
1345 rd_count_nf,
1346 rd,
1347 &rd_count,
1348 &block_exp,
1349 rlc->filter,
1350 &emsg))
1351 {
1352 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg);
1353 GNUNET_free (emsg);
1354 GNUNET_assert (0);
1355 }
1356
1333 if (0 == rd_count) 1357 if (0 == rd_count)
1334 { 1358 {
1335 rlc->rd_ser_len = 0; 1359 rlc->rd_ser_len = 0;
@@ -1468,6 +1492,7 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg)
1468 } 1492 }
1469 name_len = strlen (conv_name) + 1; 1493 name_len = strlen (conv_name) + 1;
1470 rlc.label = conv_name; 1494 rlc.label = conv_name;
1495 rlc.filter = ntohs (ll_msg->filter);
1471 rlc.found = GNUNET_NO; 1496 rlc.found = GNUNET_NO;
1472 rlc.res_rd_count = 0; 1497 rlc.res_rd_count = 0;
1473 rlc.res_rd = NULL; 1498 rlc.res_rd = NULL;
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index d7b6fd13e..ea35269a4 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -158,6 +158,11 @@ struct LabelLookupMessage
158 uint32_t is_edit_request GNUNET_PACKED; 158 uint32_t is_edit_request GNUNET_PACKED;
159 159
160 /** 160 /**
161 * The record filter
162 */
163 uint16_t filter;
164
165 /**
161 * The private key of the zone to look up in 166 * The private key of the zone to look up in
162 */ 167 */
163 struct GNUNET_IDENTITY_PrivateKey zone; 168 struct GNUNET_IDENTITY_PrivateKey zone;
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index cf2247d18..f92e6ef41 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1234,7 +1234,8 @@ records_lookup (
1234 void *error_cb_cls, 1234 void *error_cb_cls,
1235 GNUNET_NAMESTORE_RecordMonitor rm, 1235 GNUNET_NAMESTORE_RecordMonitor rm,
1236 void *rm_cls, 1236 void *rm_cls,
1237 int is_edit_request) 1237 int is_edit_request,
1238 enum GNUNET_GNSRECORD_Filter filter)
1238{ 1239{
1239 struct GNUNET_NAMESTORE_QueueEntry *qe; 1240 struct GNUNET_NAMESTORE_QueueEntry *qe;
1240 struct GNUNET_MQ_Envelope *env; 1241 struct GNUNET_MQ_Envelope *env;
@@ -1263,6 +1264,7 @@ records_lookup (
1263 msg->zone = *pkey; 1264 msg->zone = *pkey;
1264 msg->is_edit_request = htonl (is_edit_request); 1265 msg->is_edit_request = htonl (is_edit_request);
1265 msg->label_len = htonl (label_len); 1266 msg->label_len = htonl (label_len);
1267 msg->filter = htons (filter);
1266 GNUNET_memcpy (&msg[1], label, label_len); 1268 GNUNET_memcpy (&msg[1], label, label_len);
1267 if (NULL == h->mq) 1269 if (NULL == h->mq)
1268 qe->env = env; 1270 qe->env = env;
@@ -1283,11 +1285,29 @@ GNUNET_NAMESTORE_records_lookup (
1283{ 1285{
1284 return records_lookup (h, pkey, label, 1286 return records_lookup (h, pkey, label,
1285 error_cb, error_cb_cls, 1287 error_cb, error_cb_cls,
1286 rm, rm_cls, GNUNET_NO); 1288 rm, rm_cls, GNUNET_NO, GNUNET_GNSRECORD_FILTER_NONE);
1287 1289
1288} 1290}
1289 1291
1290struct GNUNET_NAMESTORE_QueueEntry * 1292struct GNUNET_NAMESTORE_QueueEntry *
1293GNUNET_NAMESTORE_records_lookup2 (
1294 struct GNUNET_NAMESTORE_Handle *h,
1295 const struct GNUNET_IDENTITY_PrivateKey *pkey,
1296 const char *label,
1297 GNUNET_SCHEDULER_TaskCallback error_cb,
1298 void *error_cb_cls,
1299 GNUNET_NAMESTORE_RecordMonitor rm,
1300 void *rm_cls,
1301 enum GNUNET_GNSRECORD_Filter filter)
1302{
1303 return records_lookup (h, pkey, label,
1304 error_cb, error_cb_cls,
1305 rm, rm_cls, GNUNET_NO, filter);
1306
1307}
1308
1309
1310struct GNUNET_NAMESTORE_QueueEntry *
1291GNUNET_NAMESTORE_records_edit ( 1311GNUNET_NAMESTORE_records_edit (
1292 struct GNUNET_NAMESTORE_Handle *h, 1312 struct GNUNET_NAMESTORE_Handle *h,
1293 const struct GNUNET_IDENTITY_PrivateKey *pkey, 1313 const struct GNUNET_IDENTITY_PrivateKey *pkey,
@@ -1299,7 +1319,7 @@ GNUNET_NAMESTORE_records_edit (
1299{ 1319{
1300 return records_lookup (h, pkey, label, 1320 return records_lookup (h, pkey, label,
1301 error_cb, error_cb_cls, 1321 error_cb, error_cb_cls,
1302 rm, rm_cls, GNUNET_YES); 1322 rm, rm_cls, GNUNET_YES, GNUNET_GNSRECORD_FILTER_NONE);
1303} 1323}
1304 1324
1305struct GNUNET_NAMESTORE_QueueEntry * 1325struct GNUNET_NAMESTORE_QueueEntry *
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index 5a5fdb9a8..fcc6068e8 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -52,7 +52,12 @@
52/** 52/**
53 * Error message No identity found 53 * Error message No identity found
54 */ 54 */
55#define GNUNET_REST_IDENTITY_NOT_FOUND "No identity found" 55#define GNUNET_REST_IDENTITY_NOT_FOUND "Zone not found"
56
57/**
58 * Error message No record found
59 */
60#define GNUNET_REST_RECORD_NOT_FOUND "Record not found"
56 61
57 62
58/** 63/**
@@ -521,8 +526,12 @@ namestore_list_finished (void *cls)
521 handle->list_it = NULL; 526 handle->list_it = NULL;
522 527
523 if (NULL == handle->resp_object) 528 if (NULL == handle->resp_object)
524 handle->resp_object = json_array (); 529 {
525 530 handle->response_code = MHD_HTTP_NOT_FOUND;
531 handle->emsg = GNUNET_strdup (GNUNET_REST_RECORD_NOT_FOUND);
532 GNUNET_SCHEDULER_add_now (&do_error, handle);
533 return;
534 }
526 result_str = json_dumps (handle->resp_object, 0); 535 result_str = json_dumps (handle->resp_object, 0);
527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); 536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
528 resp = GNUNET_REST_create_response (result_str); 537 resp = GNUNET_REST_create_response (result_str);
@@ -545,7 +554,8 @@ namestore_list_iteration (void *cls,
545 const struct GNUNET_IDENTITY_PrivateKey *zone_key, 554 const struct GNUNET_IDENTITY_PrivateKey *zone_key,
546 const char *rname, 555 const char *rname,
547 unsigned int rd_len, 556 unsigned int rd_len,
548 const struct GNUNET_GNSRECORD_Data *rd) 557 const struct GNUNET_GNSRECORD_Data *rd,
558 struct GNUNET_TIME_Absolute expiry)
549{ 559{
550 struct RequestHandle *handle = cls; 560 struct RequestHandle *handle = cls;
551 struct GNUNET_GNSRECORD_Data rd_filtered[rd_len]; 561 struct GNUNET_GNSRECORD_Data rd_filtered[rd_len];
@@ -553,8 +563,13 @@ namestore_list_iteration (void *cls,
553 int i = 0; 563 int i = 0;
554 int j = 0; 564 int j = 0;
555 565
556 if (NULL == handle->resp_object) 566 if (rd_len == 0)
557 handle->resp_object = json_array (); 567 {
568 /** skip **/
569 GNUNET_NAMESTORE_zone_iterator_next (handle->list_it, 1);
570 return;
571 }
572
558 for (i = 0; i < rd_len; i++) 573 for (i = 0; i < rd_len; i++)
559 { 574 {
560 if ((GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) && 575 if ((GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) &&
@@ -567,6 +582,8 @@ namestore_list_iteration (void *cls,
567 /** Only add if not empty **/ 582 /** Only add if not empty **/
568 if (j > 0) 583 if (j > 0)
569 { 584 {
585 if (NULL == handle->resp_object)
586 handle->resp_object = json_array ();
570 record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (rname, 587 record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (rname,
571 rd_filtered, 588 rd_filtered,
572 j); 589 j);
@@ -600,13 +617,10 @@ ns_get_lookup_cb (void *cls,
600{ 617{
601 struct RequestHandle *handle = cls; 618 struct RequestHandle *handle = cls;
602 struct GNUNET_GNSRECORD_Data rd_filtered[rd_len]; 619 struct GNUNET_GNSRECORD_Data rd_filtered[rd_len];
603 json_t *record_obj;
604 int i = 0; 620 int i = 0;
605 int j = 0; 621 int j = 0;
606 622
607 handle->ns_qe = NULL; 623 handle->ns_qe = NULL;
608 if (NULL == handle->resp_object)
609 handle->resp_object = json_array ();
610 for (i = 0; i < rd_len; i++) 624 for (i = 0; i < rd_len; i++)
611 { 625 {
612 if ((GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) && 626 if ((GNUNET_GNSRECORD_TYPE_ANY != handle->record_type) &&
@@ -616,14 +630,17 @@ ns_get_lookup_cb (void *cls,
616 rd_filtered[j].data = rd[i].data; 630 rd_filtered[j].data = rd[i].data;
617 j++; 631 j++;
618 } 632 }
619 /** Only add if not empty **/ 633 /** Return 404 if no set was found **/
620 if (j > 0) 634 if (j == 0)
621 { 635 {
622 record_obj = GNUNET_GNSRECORD_JSON_from_gnsrecord (label, 636 handle->response_code = MHD_HTTP_NOT_FOUND;
623 rd_filtered, 637 handle->emsg = GNUNET_strdup (GNUNET_REST_RECORD_NOT_FOUND);
624 j); 638 GNUNET_SCHEDULER_add_now (&do_error, handle);
625 json_array_append_new (handle->resp_object, record_obj); 639 return;
626 } 640 }
641 handle->resp_object = GNUNET_GNSRECORD_JSON_from_gnsrecord (label,
642 rd_filtered,
643 j);
627 GNUNET_SCHEDULER_add_now (&namestore_list_finished, handle); 644 GNUNET_SCHEDULER_add_now (&namestore_list_finished, handle);
628} 645}
629 646
@@ -643,9 +660,11 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
643 struct RequestHandle *handle = cls; 660 struct RequestHandle *handle = cls;
644 struct EgoEntry *ego_entry; 661 struct EgoEntry *ego_entry;
645 struct GNUNET_HashCode key; 662 struct GNUNET_HashCode key;
663 enum GNUNET_GNSRECORD_Filter filter_flags;
646 char *egoname; 664 char *egoname;
647 char *labelname; 665 char *labelname;
648 char *typename; 666 char *typename;
667 char *boolstring;
649 668
650 egoname = NULL; 669 egoname = NULL;
651 ego_entry = NULL; 670 ego_entry = NULL;
@@ -679,19 +698,44 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
679 if (NULL != typename) 698 if (NULL != typename)
680 handle->record_type = GNUNET_GNSRECORD_typename_to_number (typename); 699 handle->record_type = GNUNET_GNSRECORD_typename_to_number (typename);
681 } 700 }
701 GNUNET_CRYPTO_hash ("omit_private", strlen ("omit_private"), &key);
702 filter_flags = GNUNET_GNSRECORD_FILTER_NONE;
703 if (GNUNET_YES ==
704 GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key))
705 {
706 boolstring = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
707 &key);
708 if ((0 == strcmp (boolstring, "1")) ||
709 (0 == strcmp (boolstring, "yes")) ||
710 (0 == strcmp (boolstring, "true")))
711 filter_flags = GNUNET_GNSRECORD_FILTER_OMIT_PRIVATE;
712 }
713 GNUNET_CRYPTO_hash ("include_maintenance", strlen ("include_maintenance"),
714 &key);
715 if (GNUNET_YES ==
716 GNUNET_CONTAINER_multihashmap_contains (con_handle->url_param_map, &key))
717 {
718 boolstring = GNUNET_CONTAINER_multihashmap_get (con_handle->url_param_map,
719 &key);
720 if ((0 == strcmp (boolstring, "1")) ||
721 (0 == strcmp (boolstring, "yes")) ||
722 (0 == strcmp (boolstring, "true")))
723 filter_flags |= GNUNET_GNSRECORD_FILTER_INCLUDE_MAINTENANCE;
724 }
682 labelname = &egoname[strlen (ego_entry->identifier)]; 725 labelname = &egoname[strlen (ego_entry->identifier)];
683 // set zone to name if given
684 if (1 >= strlen (labelname)) 726 if (1 >= strlen (labelname))
685 { 727 {
728 /* Iterate over all records */
686 handle->list_it = 729 handle->list_it =
687 GNUNET_NAMESTORE_zone_iteration_start (ns_handle, 730 GNUNET_NAMESTORE_zone_iteration_start2 (ns_handle,
688 handle->zone_pkey, 731 handle->zone_pkey,
689 &namestore_iteration_error, 732 &namestore_iteration_error,
690 handle, 733 handle,
691 &namestore_list_iteration, 734 &namestore_list_iteration,
692 handle, 735 handle,
693 &namestore_list_finished, 736 &namestore_list_finished,
694 handle); 737 handle,
738 filter_flags);
695 if (NULL == handle->list_it) 739 if (NULL == handle->list_it)
696 { 740 {
697 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); 741 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);
@@ -701,13 +745,14 @@ namestore_get (struct GNUNET_REST_RequestHandle *con_handle,
701 return; 745 return;
702 } 746 }
703 handle->record_name = GNUNET_strdup (labelname + 1); 747 handle->record_name = GNUNET_strdup (labelname + 1);
704 handle->ns_qe = GNUNET_NAMESTORE_records_lookup (ns_handle, 748 handle->ns_qe = GNUNET_NAMESTORE_records_lookup2 (ns_handle,
705 handle->zone_pkey, 749 handle->zone_pkey,
706 handle->record_name, 750 handle->record_name,
707 &ns_lookup_error_cb, 751 &ns_lookup_error_cb,
708 handle, 752 handle,
709 &ns_get_lookup_cb, 753 &ns_get_lookup_cb,
710 handle); 754 handle,
755 filter_flags);
711 if (NULL == handle->ns_qe) 756 if (NULL == handle->ns_qe)
712 { 757 {
713 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); 758 handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED);