aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-03-21 15:43:56 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-03-21 15:43:56 +0000
commit13c5308bd3b81ff92bba7708124f47846fe26c3d (patch)
tree42bc02530be7d3e3d7ea13411a1e3833b65e7b01 /src
parent4851f02b771d731feed878352fcd03bd4d037185 (diff)
downloadgnunet-13c5308bd3b81ff92bba7708124f47846fe26c3d.tar.gz
gnunet-13c5308bd3b81ff92bba7708124f47846fe26c3d.zip
- changes to record remove
Diffstat (limited to 'src')
-rw-r--r--src/namestore/gnunet-service-namestore.c91
-rw-r--r--src/namestore/namestore_api.c13
2 files changed, 68 insertions, 36 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 6efe1d475..3852a1406 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1016,16 +1016,30 @@ handle_record_remove_it (void *cls,
1016 found = GNUNET_SYSERR; 1016 found = GNUNET_SYSERR;
1017 for (c = 0; c < rd_count; c++) 1017 for (c = 0; c < rd_count; c++)
1018 { 1018 {
1019 if ((rd[c].expiration.abs_value == rrc->rd->expiration.abs_value) && 1019 if (rd[c].expiration.abs_value != rrc->rd->expiration.abs_value)
1020 (rd[c].flags == rrc->rd->flags) && 1020 continue;
1021 (rd[c].record_type == rrc->rd->record_type) && 1021 GNUNET_break(0);
1022 (rd[c].data_size == rrc->rd->data_size) && 1022 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SENT FLAGES: %u \n",rd[c].flags);
1023 (0 == memcmp (rd[c].data, rrc->rd->data, rrc->rd->data_size))) 1023 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STORED FLAGES: %u \n",rrc->rd->flags);
1024 { 1024 /*
1025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found record to remove!\n", rd_count); 1025 if (rd[c].flags != rrc->rd->flags)
1026 found = c; 1026 continue;*/
1027 break; 1027 GNUNET_break(0);
1028 } 1028 if (rd[c].record_type != rrc->rd->record_type)
1029 continue;
1030 GNUNET_break(0);
1031 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "SENT FLAGES: %u \n",rd[c].data_size);
1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STORED FLAGES: %u \n",rrc->rd->data_size);
1033 /*
1034 if (rd[c].data_size != rrc->rd->data_size)
1035 continue;
1036 GNUNET_break(0);
1037 if (0 != memcmp (rd[c].data, rrc->rd->data, rrc->rd->data_size))
1038 continue;
1039 GNUNET_break(0); */
1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found record to remove!\n", rd_count);
1041 found = c;
1042 break;
1029 } 1043 }
1030 if (GNUNET_SYSERR == found) 1044 if (GNUNET_SYSERR == found)
1031 { 1045 {
@@ -1127,7 +1141,7 @@ static void handle_record_remove (void *cls,
1127 return; 1141 return;
1128 } 1142 }
1129 1143
1130 if ((rd_count != 1) || (rd_ser_len < 1) || (name_len >=256) || (name_len == 0)) 1144 if ((name_len >=256) || (name_len == 0))
1131 { 1145 {
1132 GNUNET_break_op (0); 1146 GNUNET_break_op (0);
1133 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1147 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1143,13 +1157,6 @@ static void handle_record_remove (void *cls,
1143 return; 1157 return;
1144 } 1158 }
1145 1159
1146 if ((rd_count != 1) || (rd_ser_len < 1) || (name_len >=256) || (name_len == 0))
1147 {
1148 GNUNET_break_op (0);
1149 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1150 return;
1151 }
1152
1153 pkey_tmp = (char *) &rr_msg[1]; 1160 pkey_tmp = (char *) &rr_msg[1];
1154 name_tmp = &pkey_tmp[key_len]; 1161 name_tmp = &pkey_tmp[key_len];
1155 rd_ser = &name_tmp[name_len]; 1162 rd_ser = &name_tmp[name_len];
@@ -1188,31 +1195,51 @@ static void handle_record_remove (void *cls,
1188 GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1195 GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1189 } 1196 }
1190 1197
1198
1191 struct GNUNET_NAMESTORE_RecordData rd[rd_count]; 1199 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
1192 res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd); 1200 res = GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_ser, rd_count, rd);
1193 if ((res != GNUNET_OK) || (rd_count != 1)) 1201 if ((res != GNUNET_OK) || (rd_count > 1))
1194 { 1202 {
1195 GNUNET_break_op (0); 1203 GNUNET_break_op (0);
1196 goto send; 1204 goto send;
1197 } 1205 }
1198 1206
1199 struct RemoveRecordContext rrc; 1207 if (0 == rd_count)
1200 rrc.rd = rd; 1208 {
1201 rrc.pkey = pkey; 1209 /* remove the whole name and all records */
1210 /* Database operation */
1211 res = GSN_database->remove_records (GSN_database->cls,
1212 &pubkey_hash,
1213 name_tmp);
1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing name `%s': %s\n",
1215 name_tmp, (GNUNET_OK == res) ? "OK" : "FAIL");
1202 1216
1203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s(&pubkey_hash)); 1217 if (GNUNET_OK != res)
1218 /* Could not remove entry from database */
1219 res = 4;
1220 else
1221 res = 0;
1222 }
1223 else
1224 {
1225 /* remove a single record */
1226 struct RemoveRecordContext rrc;
1227 rrc.rd = rd;
1228 rrc.pkey = pkey;
1204 1229
1205 /* Database operation */ 1230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s' in zone `%s'\n", name_tmp, GNUNET_short_h2s(&pubkey_hash));
1206 res = GSN_database->iterate_records (GSN_database->cls,
1207 &pubkey_hash,
1208 name_tmp,
1209 0,
1210 handle_record_remove_it, &rrc);
1211 1231
1212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s': %s\n", 1232 /* Database operation */
1213 name_tmp, (rrc.op_res == 0) ? "OK" : "FAIL"); 1233 res = GSN_database->iterate_records (GSN_database->cls,
1214 res = rrc.op_res; 1234 &pubkey_hash,
1235 name_tmp,
1236 0,
1237 handle_record_remove_it, &rrc);
1215 1238
1239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing record for name `%s': %s\n",
1240 name_tmp, (rrc.op_res == 0) ? "OK" : "FAIL");
1241 res = rrc.op_res;
1242 }
1216 /* Send response */ 1243 /* Send response */
1217send: 1244send:
1218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_REMOVE_RESPONSE"); 1245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_REMOVE_RESPONSE");
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index be80e2091..a0f37f9f1 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1221,7 +1221,7 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
1221 * @param h handle to the namestore 1221 * @param h handle to the namestore
1222 * @param pkey private key of the zone 1222 * @param pkey private key of the zone
1223 * @param name name that is being mapped (at most 255 characters long) 1223 * @param name name that is being mapped (at most 255 characters long)
1224 * @param rd record data 1224 * @param rd record data, remove specific record, NULL to remove the name and all records
1225 * @param cont continuation to call when done 1225 * @param cont continuation to call when done
1226 * @param cont_cls closure for cont 1226 * @param cont_cls closure for cont
1227 * @return handle to abort the request 1227 * @return handle to abort the request
@@ -1244,6 +1244,7 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
1244 size_t name_len = 0; 1244 size_t name_len = 0;
1245 size_t key_len = 0; 1245 size_t key_len = 0;
1246 uint32_t rid = 0; 1246 uint32_t rid = 0;
1247 uint16_t rd_count = 1;
1247 1248
1248 GNUNET_assert (NULL != h); 1249 GNUNET_assert (NULL != h);
1249 1250
@@ -1260,9 +1261,13 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
1260 GNUNET_assert (pkey_enc != NULL); 1261 GNUNET_assert (pkey_enc != NULL);
1261 key_len = ntohs (pkey_enc->len); 1262 key_len = ntohs (pkey_enc->len);
1262 1263
1263 rd_ser_len = GNUNET_NAMESTORE_records_get_size(1, rd); 1264 if (NULL == rd)
1265 rd_count = 0;
1266 else
1267 rd_count = 1;
1268 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1264 char rd_ser[rd_ser_len]; 1269 char rd_ser[rd_ser_len];
1265 GNUNET_NAMESTORE_records_serialize(1, rd, rd_ser_len, rd_ser); 1270 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
1266 1271
1267 name_len = strlen (name) + 1; 1272 name_len = strlen (name) + 1;
1268 1273
@@ -1284,7 +1289,7 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
1284 msg->gns_header.r_id = htonl (rid); 1289 msg->gns_header.r_id = htonl (rid);
1285 msg->name_len = htons (name_len); 1290 msg->name_len = htons (name_len);
1286 msg->rd_len = htons (rd_ser_len); 1291 msg->rd_len = htons (rd_ser_len);
1287 msg->rd_count = htons (1); 1292 msg->rd_count = htons (rd_count);
1288 msg->pkey_len = htons (key_len); 1293 msg->pkey_len = htons (key_len);
1289 memcpy (pkey_tmp, pkey_enc, key_len); 1294 memcpy (pkey_tmp, pkey_enc, key_len);
1290 memcpy (name_tmp, name, name_len); 1295 memcpy (name_tmp, name, name_len);