aboutsummaryrefslogtreecommitdiff
path: root/src/service/namestore/namestore_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/namestore/namestore_api.c')
-rw-r--r--src/service/namestore/namestore_api.c333
1 files changed, 222 insertions, 111 deletions
diff --git a/src/service/namestore/namestore_api.c b/src/service/namestore/namestore_api.c
index 7a4438e30..435c1622d 100644
--- a/src/service/namestore/namestore_api.c
+++ b/src/service/namestore/namestore_api.c
@@ -26,13 +26,9 @@
26 * @author Christian Grothoff 26 * @author Christian Grothoff
27 */ 27 */
28 28
29#include "platform.h" 29#include "gnunet_protocols.h"
30#include "gnunet_error_codes.h" 30#include "gnunet_error_codes.h"
31#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
32#include "gnunet_constants.h"
33#include "gnunet_arm_service.h"
34#include "gnunet_signatures.h"
35#include "gnunet_gns_service.h"
36#include "gnunet_namestore_service.h" 32#include "gnunet_namestore_service.h"
37#include "namestore.h" 33#include "namestore.h"
38 34
@@ -87,6 +83,11 @@ struct GNUNET_NAMESTORE_QueueEntry
87 GNUNET_NAMESTORE_RecordSetMonitor proc2; 83 GNUNET_NAMESTORE_RecordSetMonitor proc2;
88 84
89 /** 85 /**
86 * Function to call with the records we get back including optional editor hint.
87 */
88 GNUNET_NAMESTORE_EditRecordSetBeginCallback edit_proc;
89
90 /**
90 * Closure for @e proc. 91 * Closure for @e proc.
91 */ 92 */
92 void *proc_cls; 93 void *proc_cls;
@@ -355,16 +356,17 @@ check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count)
355 return GNUNET_OK; 356 return GNUNET_OK;
356} 357}
357 358
359
358/** 360/**
359 * Handle an incoming message of type 361 * Handle an incoming message of type
360 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE 362 * #GNUNET_MESSAGE_TYPE_NAMESTORE_GENERIC_RESPONSE
361 * 363 *
362 * @param cls 364 * @param cls
363 * @param msg the message we received 365 * @param msg the message we received
364 */ 366 */
365static void 367static void
366handle_record_store_response (void *cls, 368handle_generic_response (void *cls,
367 const struct RecordStoreResponseMessage *msg) 369 const struct NamestoreResponseMessage *msg)
368{ 370{
369 struct GNUNET_NAMESTORE_Handle *h = cls; 371 struct GNUNET_NAMESTORE_Handle *h = cls;
370 struct GNUNET_NAMESTORE_QueueEntry *qe; 372 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -469,9 +471,9 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
469 key_len = ntohs (msg->key_len); 471 key_len = ntohs (msg->key_len);
470 GNUNET_assert (GNUNET_SYSERR != 472 GNUNET_assert (GNUNET_SYSERR !=
471 GNUNET_CRYPTO_read_private_key_from_buffer (&msg[1], 473 GNUNET_CRYPTO_read_private_key_from_buffer (&msg[1],
472 key_len, 474 key_len,
473 &private_key, 475 &private_key,
474 &kbytes_read)); 476 &kbytes_read));
475 GNUNET_assert (kbytes_read == key_len); 477 GNUNET_assert (kbytes_read == key_len);
476 name = (const char *) &msg[1] + key_len; 478 name = (const char *) &msg[1] + key_len;
477 if (GNUNET_NO == found) 479 if (GNUNET_NO == found)
@@ -512,6 +514,93 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
512 514
513/** 515/**
514 * Handle an incoming message of type 516 * Handle an incoming message of type
517 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE
518 *
519 * @param cls
520 * @param msg the message we received
521 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
522 */
523static int
524check_edit_record_set_response (void *cls, const struct
525 EditRecordSetResponseMessage *msg)
526{
527 const char *editor_hint;
528 size_t msg_len;
529 size_t editor_hint_len;
530 size_t rd_len;
531
532 (void) cls;
533 rd_len = ntohs (msg->rd_len);
534 msg_len = ntohs (msg->gns_header.header.size);
535 editor_hint_len = ntohs (msg->editor_hint_len);
536 if (msg_len != sizeof(struct EditRecordSetResponseMessage) + editor_hint_len
537 + rd_len)
538 {
539 GNUNET_break (0);
540 return GNUNET_SYSERR;
541 }
542 editor_hint = (const char *) &msg[1];
543 if ((0 == editor_hint_len) || ('\0' != editor_hint[editor_hint_len - 1]))
544 {
545 GNUNET_break (0);
546 return GNUNET_SYSERR;
547 }
548 return check_rd (rd_len, &editor_hint[editor_hint_len], ntohs (
549 msg->rd_count));
550}
551
552
553/**
554 * Handle an incoming message of type
555 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE
556 *
557 * @param cls
558 * @param msg the message we received
559 */
560static void
561handle_edit_record_set_response (void *cls, const struct
562 EditRecordSetResponseMessage *msg)
563{
564 struct GNUNET_NAMESTORE_Handle *h = cls;
565 struct GNUNET_NAMESTORE_QueueEntry *qe;
566 const char *editor_hint;
567 const char *rd_tmp;
568 size_t rd_len;
569 size_t editor_hint_len;
570 unsigned int rd_count;
571
572 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received EDIT_RECORD_SET_RESPONSE\n");
573 rd_len = ntohs (msg->rd_len);
574 rd_count = ntohs (msg->rd_count);
575 editor_hint_len = ntohs (msg->editor_hint_len);
576 qe = find_qe (h, ntohl (msg->gns_header.r_id));
577 if (NULL == qe)
578 return; /* rid not found */
579 editor_hint = (const char *) &msg[1];
580 rd_tmp = &editor_hint[editor_hint_len];
581 {
582 struct GNUNET_GNSRECORD_Data rd[rd_count];
583
584 GNUNET_assert (
585 GNUNET_OK ==
586 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd));
587 if (0 == editor_hint_len)
588 editor_hint = NULL;
589 if (NULL != qe->edit_proc)
590 qe->edit_proc (qe->proc_cls,
591 ntohs (msg->ec),
592 rd_count,
593 (rd_count > 0) ? rd : NULL,
594 editor_hint);
595 free_qe (qe);
596 return;
597 }
598 GNUNET_assert (0);
599}
600
601
602/**
603 * Handle an incoming message of type
515 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT 604 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
516 * 605 *
517 * @param cls 606 * @param cls
@@ -593,9 +682,9 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
593 name = (const char *) &msg[1] + key_len; 682 name = (const char *) &msg[1] + key_len;
594 GNUNET_assert (GNUNET_SYSERR != 683 GNUNET_assert (GNUNET_SYSERR !=
595 GNUNET_CRYPTO_read_private_key_from_buffer (&msg[1], 684 GNUNET_CRYPTO_read_private_key_from_buffer (&msg[1],
596 key_len, 685 key_len,
597 &private_key, 686 &private_key,
598 &kbytes_read)); 687 &kbytes_read));
599 GNUNET_assert (kbytes_read == key_len); 688 GNUNET_assert (kbytes_read == key_len);
600 rd_tmp = &name[name_len]; 689 rd_tmp = &name[name_len];
601 { 690 {
@@ -674,25 +763,6 @@ handle_record_result_end (void *cls, const struct GNUNET_NAMESTORE_Header *msg)
674 free_ze (ze); 763 free_ze (ze);
675} 764}
676 765
677static void
678handle_tx_control_result (void *cls,
679 const struct TxControlResultMessage *msg)
680{
681 struct GNUNET_NAMESTORE_Handle *h = cls;
682 struct GNUNET_NAMESTORE_QueueEntry *qe;
683 enum GNUNET_ErrorCode res;
684
685 qe = find_qe (h, ntohl (msg->gns_header.r_id));
686 res = ntohs (msg->ec);
687 LOG (GNUNET_ERROR_TYPE_DEBUG,
688 "Received TX_CONTROL_RESULT with result %d\n",
689 res);
690 if (NULL == qe)
691 return;
692 if (NULL != qe->cont)
693 qe->cont (qe->cont_cls, res);
694 free_qe (qe);
695}
696 766
697/** 767/**
698 * Handle an incoming message of type 768 * Handle an incoming message of type
@@ -769,9 +839,9 @@ handle_zone_to_name_response (void *cls,
769 key_len = ntohs (msg->key_len); 839 key_len = ntohs (msg->key_len);
770 GNUNET_assert (GNUNET_SYSERR != 840 GNUNET_assert (GNUNET_SYSERR !=
771 GNUNET_CRYPTO_read_private_key_from_buffer (&msg[1], 841 GNUNET_CRYPTO_read_private_key_from_buffer (&msg[1],
772 key_len, 842 key_len,
773 &zone, 843 &zone,
774 &kbytes_read)); 844 &kbytes_read));
775 GNUNET_assert (kbytes_read == key_len); 845 GNUNET_assert (kbytes_read == key_len);
776 switch (res) 846 switch (res)
777 { 847 {
@@ -849,9 +919,9 @@ static void
849reconnect (struct GNUNET_NAMESTORE_Handle *h) 919reconnect (struct GNUNET_NAMESTORE_Handle *h)
850{ 920{
851 struct GNUNET_MQ_MessageHandler handlers[] = 921 struct GNUNET_MQ_MessageHandler handlers[] =
852 { GNUNET_MQ_hd_fixed_size (record_store_response, 922 { GNUNET_MQ_hd_fixed_size (generic_response,
853 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, 923 GNUNET_MESSAGE_TYPE_NAMESTORE_GENERIC_RESPONSE,
854 struct RecordStoreResponseMessage, 924 struct NamestoreResponseMessage,
855 h), 925 h),
856 GNUNET_MQ_hd_var_size (zone_to_name_response, 926 GNUNET_MQ_hd_var_size (zone_to_name_response,
857 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE, 927 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE,
@@ -869,10 +939,10 @@ reconnect (struct GNUNET_NAMESTORE_Handle *h)
869 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE, 939 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE,
870 struct LabelLookupResponseMessage, 940 struct LabelLookupResponseMessage,
871 h), 941 h),
872 GNUNET_MQ_hd_fixed_size (tx_control_result, 942 GNUNET_MQ_hd_var_size (edit_record_set_response,
873 GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT, 943 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE,
874 struct TxControlResultMessage, 944 struct EditRecordSetResponseMessage,
875 h), 945 h),
876 GNUNET_MQ_handler_end () }; 946 GNUNET_MQ_handler_end () };
877 struct GNUNET_NAMESTORE_ZoneIterator *it; 947 struct GNUNET_NAMESTORE_ZoneIterator *it;
878 struct GNUNET_NAMESTORE_QueueEntry *qe; 948 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -1048,7 +1118,7 @@ warn_delay (void *cls)
1048 1118
1049 1119
1050struct GNUNET_NAMESTORE_QueueEntry * 1120struct GNUNET_NAMESTORE_QueueEntry *
1051GNUNET_NAMESTORE_records_store ( 1121GNUNET_NAMESTORE_record_set_store (
1052 struct GNUNET_NAMESTORE_Handle *h, 1122 struct GNUNET_NAMESTORE_Handle *h,
1053 const struct GNUNET_CRYPTO_PrivateKey *pkey, 1123 const struct GNUNET_CRYPTO_PrivateKey *pkey,
1054 const char *label, 1124 const char *label,
@@ -1062,12 +1132,13 @@ GNUNET_NAMESTORE_records_store (
1062 ri.a_label = label; 1132 ri.a_label = label;
1063 ri.a_rd_count = rd_count; 1133 ri.a_rd_count = rd_count;
1064 ri.a_rd = (struct GNUNET_GNSRECORD_Data *) rd; 1134 ri.a_rd = (struct GNUNET_GNSRECORD_Data *) rd;
1065 return GNUNET_NAMESTORE_records_store2 (h, pkey, 1, &ri, &rds_sent, 1135 return GNUNET_NAMESTORE_records_store (h, pkey, 1, &ri, &rds_sent,
1066 cont, cont_cls); 1136 cont, cont_cls);
1067} 1137}
1068 1138
1139
1069struct GNUNET_NAMESTORE_QueueEntry * 1140struct GNUNET_NAMESTORE_QueueEntry *
1070GNUNET_NAMESTORE_records_store2 ( 1141GNUNET_NAMESTORE_records_store (
1071 struct GNUNET_NAMESTORE_Handle *h, 1142 struct GNUNET_NAMESTORE_Handle *h,
1072 const struct GNUNET_CRYPTO_PrivateKey *pkey, 1143 const struct GNUNET_CRYPTO_PrivateKey *pkey,
1073 unsigned int rd_set_count, 1144 unsigned int rd_set_count,
@@ -1147,8 +1218,8 @@ GNUNET_NAMESTORE_records_store2 (
1147 msg->key_len = htons (key_len); 1218 msg->key_len = htons (key_len);
1148 msg->rd_set_count = htons ((uint16_t) (*rds_sent)); 1219 msg->rd_set_count = htons ((uint16_t) (*rds_sent));
1149 GNUNET_CRYPTO_write_private_key_to_buffer (pkey, 1220 GNUNET_CRYPTO_write_private_key_to_buffer (pkey,
1150 &msg[1], 1221 &msg[1],
1151 key_len); 1222 key_len);
1152 rd_set = (struct RecordSet*) (((char*) &msg[1]) + key_len); 1223 rd_set = (struct RecordSet*) (((char*) &msg[1]) + key_len);
1153 for (int i = 0; i < *rds_sent; i++) 1224 for (int i = 0; i < *rds_sent; i++)
1154 { 1225 {
@@ -1201,7 +1272,6 @@ records_lookup (
1201 void *error_cb_cls, 1272 void *error_cb_cls,
1202 GNUNET_NAMESTORE_RecordMonitor rm, 1273 GNUNET_NAMESTORE_RecordMonitor rm,
1203 void *rm_cls, 1274 void *rm_cls,
1204 int is_edit_request,
1205 enum GNUNET_GNSRECORD_Filter filter) 1275 enum GNUNET_GNSRECORD_Filter filter)
1206{ 1276{
1207 struct GNUNET_NAMESTORE_QueueEntry *qe; 1277 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -1231,11 +1301,10 @@ records_lookup (
1231 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP); 1301 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP);
1232 msg->gns_header.r_id = htonl (qe->op_id); 1302 msg->gns_header.r_id = htonl (qe->op_id);
1233 GNUNET_CRYPTO_write_private_key_to_buffer (pkey, 1303 GNUNET_CRYPTO_write_private_key_to_buffer (pkey,
1234 &msg[1], 1304 &msg[1],
1235 key_len); 1305 key_len);
1236 1306
1237 msg->key_len = htons (key_len); 1307 msg->key_len = htons (key_len);
1238 msg->is_edit_request = htons (is_edit_request);
1239 msg->label_len = htons (label_len); 1308 msg->label_len = htons (label_len);
1240 msg->filter = htons (filter); 1309 msg->filter = htons (filter);
1241 GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len); 1310 GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
@@ -1246,6 +1315,7 @@ records_lookup (
1246 return qe; 1315 return qe;
1247} 1316}
1248 1317
1318
1249struct GNUNET_NAMESTORE_QueueEntry * 1319struct GNUNET_NAMESTORE_QueueEntry *
1250GNUNET_NAMESTORE_records_lookup ( 1320GNUNET_NAMESTORE_records_lookup (
1251 struct GNUNET_NAMESTORE_Handle *h, 1321 struct GNUNET_NAMESTORE_Handle *h,
@@ -1258,10 +1328,11 @@ GNUNET_NAMESTORE_records_lookup (
1258{ 1328{
1259 return records_lookup (h, pkey, label, 1329 return records_lookup (h, pkey, label,
1260 error_cb, error_cb_cls, 1330 error_cb, error_cb_cls,
1261 rm, rm_cls, GNUNET_NO, GNUNET_GNSRECORD_FILTER_NONE); 1331 rm, rm_cls, GNUNET_GNSRECORD_FILTER_NONE);
1262 1332
1263} 1333}
1264 1334
1335
1265struct GNUNET_NAMESTORE_QueueEntry * 1336struct GNUNET_NAMESTORE_QueueEntry *
1266GNUNET_NAMESTORE_records_lookup2 ( 1337GNUNET_NAMESTORE_records_lookup2 (
1267 struct GNUNET_NAMESTORE_Handle *h, 1338 struct GNUNET_NAMESTORE_Handle *h,
@@ -1275,27 +1346,12 @@ GNUNET_NAMESTORE_records_lookup2 (
1275{ 1346{
1276 return records_lookup (h, pkey, label, 1347 return records_lookup (h, pkey, label,
1277 error_cb, error_cb_cls, 1348 error_cb, error_cb_cls,
1278 rm, rm_cls, GNUNET_NO, filter); 1349 rm, rm_cls, filter);
1279 1350
1280} 1351}
1281 1352
1282 1353
1283struct GNUNET_NAMESTORE_QueueEntry * 1354struct GNUNET_NAMESTORE_QueueEntry *
1284GNUNET_NAMESTORE_records_edit (
1285 struct GNUNET_NAMESTORE_Handle *h,
1286 const struct GNUNET_CRYPTO_PrivateKey *pkey,
1287 const char *label,
1288 GNUNET_SCHEDULER_TaskCallback error_cb,
1289 void *error_cb_cls,
1290 GNUNET_NAMESTORE_RecordMonitor rm,
1291 void *rm_cls)
1292{
1293 return records_lookup (h, pkey, label,
1294 error_cb, error_cb_cls,
1295 rm, rm_cls, GNUNET_YES, GNUNET_GNSRECORD_FILTER_NONE);
1296}
1297
1298struct GNUNET_NAMESTORE_QueueEntry *
1299GNUNET_NAMESTORE_zone_to_name ( 1355GNUNET_NAMESTORE_zone_to_name (
1300 struct GNUNET_NAMESTORE_Handle *h, 1356 struct GNUNET_NAMESTORE_Handle *h,
1301 const struct GNUNET_CRYPTO_PrivateKey *zone, 1357 const struct GNUNET_CRYPTO_PrivateKey *zone,
@@ -1331,8 +1387,8 @@ GNUNET_NAMESTORE_zone_to_name (
1331 msg->pkey_len = htons (pkey_len); 1387 msg->pkey_len = htons (pkey_len);
1332 GNUNET_CRYPTO_write_private_key_to_buffer (zone, &msg[1], key_len); 1388 GNUNET_CRYPTO_write_private_key_to_buffer (zone, &msg[1], key_len);
1333 GNUNET_CRYPTO_write_public_key_to_buffer (value_zone, 1389 GNUNET_CRYPTO_write_public_key_to_buffer (value_zone,
1334 (char*) &msg[1] + key_len, 1390 (char*) &msg[1] + key_len,
1335 pkey_len); 1391 pkey_len);
1336 if (NULL == h->mq) 1392 if (NULL == h->mq)
1337 qe->env = env; 1393 qe->env = env;
1338 else 1394 else
@@ -1389,6 +1445,7 @@ GNUNET_NAMESTORE_zone_iteration_start (
1389 return it; 1445 return it;
1390} 1446}
1391 1447
1448
1392struct GNUNET_NAMESTORE_ZoneIterator * 1449struct GNUNET_NAMESTORE_ZoneIterator *
1393GNUNET_NAMESTORE_zone_iteration_start2 ( 1450GNUNET_NAMESTORE_zone_iteration_start2 (
1394 struct GNUNET_NAMESTORE_Handle *h, 1451 struct GNUNET_NAMESTORE_Handle *h,
@@ -1494,69 +1551,123 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe)
1494 free_qe (qe); 1551 free_qe (qe);
1495} 1552}
1496 1553
1554
1497/** 1555/**
1498 * New API draft. Experimental 1556 * New API draft. Experimental
1499 */ 1557 */
1500 1558
1501static struct GNUNET_NAMESTORE_QueueEntry * 1559struct GNUNET_NAMESTORE_QueueEntry *
1502send_transaction_control_msg (struct GNUNET_NAMESTORE_Handle *h, 1560GNUNET_NAMESTORE_record_set_edit_begin (struct GNUNET_NAMESTORE_Handle *h,
1503 GNUNET_NAMESTORE_ContinuationWithStatus cont, 1561 const struct
1504 void *cont_cls, 1562 GNUNET_CRYPTO_PrivateKey *pkey,
1505 enum GNUNET_NAMESTORE_TxControl ctrl) 1563 const char *label,
1564 const char *editor_hint,
1565 GNUNET_NAMESTORE_EditRecordSetBeginCallback
1566 edit_cb,
1567 void *edit_cb_cls)
1506{ 1568{
1507 struct GNUNET_NAMESTORE_QueueEntry *qe; 1569 struct GNUNET_NAMESTORE_QueueEntry *qe;
1508 struct GNUNET_MQ_Envelope *env; 1570 struct GNUNET_MQ_Envelope *env;
1509 struct TxControlMessage *msg; 1571 struct EditRecordSetMessage *msg;
1510 uint32_t rid; 1572 size_t label_len;
1573 size_t key_len;
1574 size_t editor_hint_len;
1511 1575
1512 rid = get_op_id (h); 1576 if (1 == (label_len = strlen (label) + 1))
1577 {
1578 GNUNET_break (0);
1579 return NULL;
1580 }
1581 GNUNET_assert (editor_hint != NULL);
1582 editor_hint_len = strlen (editor_hint) + 1;
1513 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1583 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
1514 qe->h = h; 1584 qe->h = h;
1515 qe->cont = cont; 1585 qe->edit_proc = edit_cb;
1516 qe->cont_cls = cont_cls; 1586 qe->proc_cls = edit_cb_cls;
1517 qe->op_id = rid; 1587 qe->op_id = get_op_id (h);
1518 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1588 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1519 1589
1520 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL); 1590 key_len = GNUNET_CRYPTO_private_key_get_length (pkey);
1521 msg->gns_header.r_id = htonl (rid); 1591 env = GNUNET_MQ_msg_extra (msg,
1522 msg->control = htons (ctrl); 1592 label_len + key_len + editor_hint_len,
1593 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT);
1594 msg->gns_header.r_id = htonl (qe->op_id);
1595 GNUNET_CRYPTO_write_private_key_to_buffer (pkey,
1596 &msg[1],
1597 key_len);
1598
1599 msg->key_len = htons (key_len);
1600 msg->label_len = htons (label_len);
1601 msg->editor_hint_len = htons (editor_hint_len);
1602 GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
1603 GNUNET_memcpy (((char*) &msg[1]) + key_len + label_len, editor_hint,
1604 editor_hint_len);
1523 if (NULL == h->mq) 1605 if (NULL == h->mq)
1524 qe->env = env; 1606 qe->env = env;
1525 else 1607 else
1526 GNUNET_MQ_send (h->mq, env); 1608 GNUNET_MQ_send (h->mq, env);
1527 return qe; 1609 return qe;
1528 GNUNET_break (0);
1529 return NULL;
1530} 1610}
1531 1611
1532struct GNUNET_NAMESTORE_QueueEntry *
1533GNUNET_NAMESTORE_transaction_begin (struct GNUNET_NAMESTORE_Handle *h,
1534 GNUNET_NAMESTORE_ContinuationWithStatus cont,
1535 void *cont_cls)
1536{
1537 return send_transaction_control_msg (h, cont, cont_cls,
1538 GNUNET_NAMESTORE_TX_BEGIN);
1539}
1540 1612
1541struct GNUNET_NAMESTORE_QueueEntry * 1613struct GNUNET_NAMESTORE_QueueEntry *
1542GNUNET_NAMESTORE_transaction_commit (struct GNUNET_NAMESTORE_Handle *h, 1614GNUNET_NAMESTORE_record_set_edit_cancel (struct GNUNET_NAMESTORE_Handle *h,
1543 GNUNET_NAMESTORE_ContinuationWithStatus 1615 const struct
1544 cont, 1616 GNUNET_CRYPTO_PrivateKey *pkey,
1545 void *cont_cls) 1617 const char *label,
1618 const char *editor_hint,
1619 const char *editor_hint_replacement,
1620 GNUNET_SCHEDULER_TaskCallback
1621 finished_cb,
1622 void *finished_cls)
1546{ 1623{
1547 return send_transaction_control_msg (h, cont, cont_cls, 1624 struct GNUNET_NAMESTORE_QueueEntry *qe;
1548 GNUNET_NAMESTORE_TX_COMMIT); 1625 struct GNUNET_MQ_Envelope *env;
1549} 1626 struct EditRecordSetCancelMessage *msg;
1627 size_t label_len;
1628 size_t key_len;
1629 size_t editor_hint_len;
1630 size_t editor_hint_replacement_len;
1550 1631
1632 if (1 == (label_len = strlen (label) + 1))
1633 {
1634 GNUNET_break (0);
1635 return NULL;
1636 }
1637 GNUNET_assert (editor_hint != NULL);
1638 editor_hint_len = strlen (editor_hint) + 1;
1639 GNUNET_assert (editor_hint != NULL);
1640 editor_hint_replacement_len = strlen (editor_hint_replacement) + 1;
1641 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry);
1642 qe->h = h;
1643 qe->op_id = get_op_id (h);
1644 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1551 1645
1552struct GNUNET_NAMESTORE_QueueEntry * 1646 key_len = GNUNET_CRYPTO_private_key_get_length (pkey);
1553GNUNET_NAMESTORE_transaction_rollback (struct GNUNET_NAMESTORE_Handle *h, 1647 env = GNUNET_MQ_msg_extra (msg,
1554 GNUNET_NAMESTORE_ContinuationWithStatus 1648 label_len + key_len + editor_hint_len
1555 cont, 1649 + editor_hint_replacement_len,
1556 void *cont_cls) 1650 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_CANCEL);
1557{ 1651 msg->gns_header.r_id = htonl (qe->op_id);
1558 return send_transaction_control_msg (h, cont, cont_cls, 1652 GNUNET_CRYPTO_write_private_key_to_buffer (pkey,
1559 GNUNET_NAMESTORE_TX_ROLLBACK); 1653 &msg[1],
1654 key_len);
1655
1656 msg->key_len = htons (key_len);
1657 msg->label_len = htons (label_len);
1658 msg->editor_hint_len = htons (editor_hint_len);
1659 msg->editor_hint_replacement_len = htons (editor_hint_replacement_len);
1660 GNUNET_memcpy (((char*) &msg[1]) + key_len, label, label_len);
1661 GNUNET_memcpy (((char*) &msg[1]) + key_len + label_len, editor_hint,
1662 editor_hint_len);
1663 GNUNET_memcpy (((char*) &msg[1]) + key_len + label_len + editor_hint_len,
1664 editor_hint_replacement,
1665 editor_hint_replacement_len);
1666 if (NULL == h->mq)
1667 qe->env = env;
1668 else
1669 GNUNET_MQ_send (h->mq, env);
1670 return qe;
1560} 1671}
1561 1672
1562 1673