aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/gnunet-service-namestore.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-11-15 14:50:56 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-11-15 14:50:56 +0000
commit6f3db5a9f86d272c27ba8c5b3da3849c536b66e6 (patch)
tree5c31256b34d84af1ee4ca57155c00e9d437202a5 /src/namestore/gnunet-service-namestore.c
parentc592e22bd5c98416b81c66ccd0abb79ccb82540a (diff)
downloadgnunet-6f3db5a9f86d272c27ba8c5b3da3849c536b66e6.tar.gz
gnunet-6f3db5a9f86d272c27ba8c5b3da3849c536b66e6.zip
implementing mantis 0002193
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r--src/namestore/gnunet-service-namestore.c107
1 files changed, 73 insertions, 34 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index d13221600..a14ad923d 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -211,7 +211,6 @@ struct KeyLoadContext
211}; 211};
212 212
213 213
214
215/** 214/**
216 * Writes the encrypted private key of a zone in a file 215 * Writes the encrypted private key of a zone in a file
217 * 216 *
@@ -794,6 +793,7 @@ handle_lookup_name (void *cls,
794 const char *name; 793 const char *name;
795 uint32_t rid; 794 uint32_t rid;
796 uint32_t type; 795 uint32_t type;
796 char *conv_name;
797 797
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
799 "Received `%s' message\n", 799 "Received `%s' message\n",
@@ -838,15 +838,23 @@ handle_lookup_name (void *cls,
838 type, name, 838 type, name,
839 GNUNET_short_h2s(&ln_msg->zone)); 839 GNUNET_short_h2s(&ln_msg->zone));
840 840
841 conv_name = GNUNET_NAMESTORE_normalize_string (name);
842 if (NULL == conv_name)
843 {
844 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
845 "Error converting name `%s'\n", name);
846 return;
847 }
848
841 /* do the actual lookup */ 849 /* do the actual lookup */
842 lnc.request_id = rid; 850 lnc.request_id = rid;
843 lnc.nc = nc; 851 lnc.nc = nc;
844 lnc.record_type = type; 852 lnc.record_type = type;
845 lnc.name = name; 853 lnc.name = conv_name;
846 lnc.zone = &ln_msg->zone; 854 lnc.zone = &ln_msg->zone;
847 if (GNUNET_SYSERR == 855 if (GNUNET_SYSERR ==
848 GSN_database->iterate_records (GSN_database->cls, 856 GSN_database->iterate_records (GSN_database->cls,
849 &ln_msg->zone, name, 0 /* offset */, 857 &ln_msg->zone, conv_name, 0 /* offset */,
850 &handle_lookup_name_it, &lnc)) 858 &handle_lookup_name_it, &lnc))
851 { 859 {
852 /* internal error (in database plugin); might be best to just hang up on 860 /* internal error (in database plugin); might be best to just hang up on
@@ -854,8 +862,10 @@ handle_lookup_name (void *cls,
854 might also be false... */ 862 might also be false... */
855 GNUNET_break (0); 863 GNUNET_break (0);
856 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 864 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
865 GNUNET_free (conv_name);
857 return; 866 return;
858 } 867 }
868 GNUNET_free (conv_name);
859 GNUNET_SERVER_receive_done (client, GNUNET_OK); 869 GNUNET_SERVER_receive_done (client, GNUNET_OK);
860} 870}
861 871
@@ -883,6 +893,7 @@ handle_record_put (void *cls,
883 size_t msg_size_exp; 893 size_t msg_size_exp;
884 const char *name; 894 const char *name;
885 const char *rd_ser; 895 const char *rd_ser;
896 char * conv_name;
886 uint32_t rid; 897 uint32_t rid;
887 uint32_t rd_ser_len; 898 uint32_t rd_ser_len;
888 uint32_t rd_count; 899 uint32_t rd_count;
@@ -932,37 +943,45 @@ handle_record_put (void *cls,
932 expire = GNUNET_TIME_absolute_ntoh (rp_msg->expire); 943 expire = GNUNET_TIME_absolute_ntoh (rp_msg->expire);
933 signature = &rp_msg->signature; 944 signature = &rp_msg->signature;
934 rd_ser = &name[name_len]; 945 rd_ser = &name[name_len];
946 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
947
948 if (GNUNET_OK !=
949 GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, rd))
935 { 950 {
936 struct GNUNET_NAMESTORE_RecordData rd[rd_count]; 951 GNUNET_break (0);
952 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
953 return;
954 }
955 GNUNET_CRYPTO_short_hash (&rp_msg->public_key,
956 sizeof (rp_msg->public_key),
957 &zone_hash);
937 958
938 if (GNUNET_OK != 959 conv_name = GNUNET_NAMESTORE_normalize_string (name);
939 GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, rd)) 960 if (NULL == conv_name)
940 { 961 {
941 GNUNET_break (0); 962 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
942 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 963 "Error converting name `%s'\n", name);
943 return; 964 return;
944 }
945 GNUNET_CRYPTO_short_hash (&rp_msg->public_key,
946 sizeof (rp_msg->public_key),
947 &zone_hash);
948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
949 "Putting %u records under name `%s' in zone `%s'\n",
950 rd_count, name,
951 GNUNET_short_h2s (&zone_hash));
952 res = GSN_database->put_records(GSN_database->cls,
953 &rp_msg->public_key,
954 expire,
955 name,
956 rd_count, rd,
957 signature);
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
959 "Putting record for name `%s': %s\n",
960 name,
961 (GNUNET_OK == res) ? "OK" : "FAILED");
962 } 965 }
966
967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
968 "Putting %u records under name `%s' in zone `%s'\n",
969 rd_count, conv_name,
970 GNUNET_short_h2s (&zone_hash));
971 res = GSN_database->put_records(GSN_database->cls,
972 &rp_msg->public_key,
973 expire,
974 conv_name,
975 rd_count, rd,
976 signature);
977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
978 "Putting record for name `%s': %s\n",
979 conv_name,
980 (GNUNET_OK == res) ? "OK" : "FAILED");
963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
964 "Sending `%s' message\n", 982 "Sending `%s' message\n",
965 "RECORD_PUT_RESPONSE"); 983 "RECORD_PUT_RESPONSE");
984 GNUNET_free (conv_name);
966 rpr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE); 985 rpr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE);
967 rpr_msg.gns_header.header.size = htons (sizeof (struct RecordPutResponseMessage)); 986 rpr_msg.gns_header.header.size = htons (sizeof (struct RecordPutResponseMessage));
968 rpr_msg.gns_header.r_id = htonl (rid); 987 rpr_msg.gns_header.r_id = htonl (rid);
@@ -1150,6 +1169,7 @@ handle_record_create (void *cls,
1150 uint32_t rid; 1169 uint32_t rid;
1151 const char *pkey_tmp; 1170 const char *pkey_tmp;
1152 const char *name_tmp; 1171 const char *name_tmp;
1172 char *conv_name;
1153 const char *rd_ser; 1173 const char *rd_ser;
1154 unsigned int rd_count; 1174 unsigned int rd_count;
1155 int res; 1175 int res;
@@ -1220,17 +1240,26 @@ handle_record_create (void *cls,
1220 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1240 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1221 &pubkey_hash); 1241 &pubkey_hash);
1222 learn_private_key (pkey); 1242 learn_private_key (pkey);
1243
1244 conv_name = GNUNET_NAMESTORE_normalize_string(name_tmp);
1245 if (NULL == conv_name)
1246 {
1247 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1248 "Error converting name `%s'\n", name_tmp);
1249 return;
1250 }
1223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1224 "Creating record for name `%s' in zone `%s'\n", 1252 "Creating record for name `%s' in zone `%s'\n",
1225 name_tmp, GNUNET_short_h2s(&pubkey_hash)); 1253 conv_name, GNUNET_short_h2s(&pubkey_hash));
1226 crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); 1254 crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
1227 crc.res = GNUNET_SYSERR; 1255 crc.res = GNUNET_SYSERR;
1228 crc.rd = &rd; 1256 crc.rd = &rd;
1229 crc.name = name_tmp; 1257 crc.name = conv_name;
1230 1258
1231 /* Get existing records for name */ 1259 /* Get existing records for name */
1232 res = GSN_database->iterate_records (GSN_database->cls, &pubkey_hash, name_tmp, 0, 1260 res = GSN_database->iterate_records (GSN_database->cls, &pubkey_hash, conv_name, 0,
1233 &handle_create_record_it, &crc); 1261 &handle_create_record_it, &crc);
1262 GNUNET_free (conv_name);
1234 if (res != GNUNET_SYSERR) 1263 if (res != GNUNET_SYSERR)
1235 res = GNUNET_OK; 1264 res = GNUNET_OK;
1236 1265
@@ -1399,6 +1428,7 @@ handle_record_remove (void *cls,
1399 const char *pkey_tmp; 1428 const char *pkey_tmp;
1400 const char *name_tmp; 1429 const char *name_tmp;
1401 const char *rd_ser; 1430 const char *rd_ser;
1431 char * conv_name;
1402 size_t key_len; 1432 size_t key_len;
1403 size_t name_len; 1433 size_t name_len;
1404 size_t rd_ser_len; 1434 size_t rd_ser_len;
@@ -1473,15 +1503,23 @@ handle_record_remove (void *cls,
1473 return; 1503 return;
1474 } 1504 }
1475 1505
1506 conv_name = GNUNET_NAMESTORE_normalize_string(name_tmp);
1507 if (NULL == conv_name)
1508 {
1509 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1510 "Error converting name `%s'\n", name_tmp);
1511 return;
1512 }
1513
1476 if (0 == rd_count) 1514 if (0 == rd_count)
1477 { 1515 {
1478 /* remove the whole name and all records */ 1516 /* remove the whole name and all records */
1479 res = GSN_database->remove_records (GSN_database->cls, 1517 res = GSN_database->remove_records (GSN_database->cls,
1480 &pubkey_hash, 1518 &pubkey_hash,
1481 name_tmp); 1519 conv_name);
1482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1483 "Removing name `%s': %s\n", 1521 "Removing name `%s': %s\n",
1484 name_tmp, (GNUNET_OK == res) ? "OK" : "FAILED"); 1522 conv_name, (GNUNET_OK == res) ? "OK" : "FAILED");
1485 if (GNUNET_OK != res) 1523 if (GNUNET_OK != res)
1486 /* Could not remove entry from database */ 1524 /* Could not remove entry from database */
1487 res = RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE; 1525 res = RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE;
@@ -1492,7 +1530,7 @@ handle_record_remove (void *cls,
1492 { 1530 {
1493 /* remove a single record */ 1531 /* remove a single record */
1494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1495 "Removing record for name `%s' in zone `%s'\n", name_tmp, 1533 "Removing record for name `%s' in zone `%s'\n", conv_name,
1496 GNUNET_short_h2s (&pubkey_hash)); 1534 GNUNET_short_h2s (&pubkey_hash));
1497 rrc.rd = &rd; 1535 rrc.rd = &rd;
1498 rrc.op_res = RECORD_REMOVE_RESULT_RECORD_NOT_FOUND; 1536 rrc.op_res = RECORD_REMOVE_RESULT_RECORD_NOT_FOUND;
@@ -1503,7 +1541,7 @@ handle_record_remove (void *cls,
1503 { 1541 {
1504 res = GSN_database->iterate_records (GSN_database->cls, 1542 res = GSN_database->iterate_records (GSN_database->cls,
1505 &pubkey_hash, 1543 &pubkey_hash,
1506 name_tmp, 1544 conv_name,
1507 off++, 1545 off++,
1508 &handle_record_remove_it, &rrc); 1546 &handle_record_remove_it, &rrc);
1509 } 1547 }
@@ -1527,6 +1565,7 @@ handle_record_remove (void *cls,
1527 break; 1565 break;
1528 } 1566 }
1529 } 1567 }
1568 GNUNET_free (conv_name);
1530 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1531 "Sending `%s' message\n", 1570 "Sending `%s' message\n",
1532 "RECORD_REMOVE_RESPONSE"); 1571 "RECORD_REMOVE_RESPONSE");