aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorwachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96>2012-11-15 14:50:56 +0000
committerwachs <wachs@140774ce-b5e7-0310-ab8b-a85725594a96>2012-11-15 14:50:56 +0000
commit22b70dae29a6c12cafad8f3daf8927cc7afbdb41 (patch)
tree5c31256b34d84af1ee4ca57155c00e9d437202a5 /src/namestore
parent7ddd23afdb36d9c1cc2292747875ce206dfd2b91 (diff)
implementing mantis 0002193
git-svn-id: https://gnunet.org/svn/gnunet@24985 140774ce-b5e7-0310-ab8b-a85725594a96
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/gnunet-service-namestore.c107
-rw-r--r--src/namestore/namestore.h8
-rw-r--r--src/namestore/namestore_common.c19
-rw-r--r--src/namestore/test_namestore_api.conf4
-rw-r--r--src/namestore/test_namestore_api_create.c4
-rw-r--r--src/namestore/test_namestore_api_create_update.c4
-rw-r--r--src/namestore/test_namestore_api_lookup.c2
-rw-r--r--src/namestore/test_namestore_api_lookup_specific_type.c5
-rw-r--r--src/namestore/test_namestore_api_put.c4
-rw-r--r--src/namestore/test_namestore_api_remove.c4
-rw-r--r--src/namestore/test_namestore_api_remove_not_existing_record.c4
-rw-r--r--src/namestore/test_namestore_api_sign_verify.c2
12 files changed, 122 insertions, 45 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index d13221600c..a14ad923d4 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -211,7 +211,6 @@ struct KeyLoadContext
};
-
/**
* Writes the encrypted private key of a zone in a file
*
@@ -794,6 +793,7 @@ handle_lookup_name (void *cls,
const char *name;
uint32_t rid;
uint32_t type;
+ char *conv_name;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' message\n",
@@ -838,15 +838,23 @@ handle_lookup_name (void *cls,
type, name,
GNUNET_short_h2s(&ln_msg->zone));
+ conv_name = GNUNET_NAMESTORE_normalize_string (name);
+ if (NULL == conv_name)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error converting name `%s'\n", name);
+ return;
+ }
+
/* do the actual lookup */
lnc.request_id = rid;
lnc.nc = nc;
lnc.record_type = type;
- lnc.name = name;
+ lnc.name = conv_name;
lnc.zone = &ln_msg->zone;
if (GNUNET_SYSERR ==
GSN_database->iterate_records (GSN_database->cls,
- &ln_msg->zone, name, 0 /* offset */,
+ &ln_msg->zone, conv_name, 0 /* offset */,
&handle_lookup_name_it, &lnc))
{
/* internal error (in database plugin); might be best to just hang up on
@@ -854,8 +862,10 @@ handle_lookup_name (void *cls,
might also be false... */
GNUNET_break (0);
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_free (conv_name);
return;
}
+ GNUNET_free (conv_name);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
}
@@ -883,6 +893,7 @@ handle_record_put (void *cls,
size_t msg_size_exp;
const char *name;
const char *rd_ser;
+ char * conv_name;
uint32_t rid;
uint32_t rd_ser_len;
uint32_t rd_count;
@@ -932,37 +943,45 @@ handle_record_put (void *cls,
expire = GNUNET_TIME_absolute_ntoh (rp_msg->expire);
signature = &rp_msg->signature;
rd_ser = &name[name_len];
+ struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+
+ if (GNUNET_OK !=
+ GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, rd))
{
- struct GNUNET_NAMESTORE_RecordData rd[rd_count];
+ GNUNET_break (0);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ return;
+ }
+ GNUNET_CRYPTO_short_hash (&rp_msg->public_key,
+ sizeof (rp_msg->public_key),
+ &zone_hash);
- if (GNUNET_OK !=
- GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, rd))
- {
- GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ conv_name = GNUNET_NAMESTORE_normalize_string (name);
+ if (NULL == conv_name)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error converting name `%s'\n", name);
return;
- }
- GNUNET_CRYPTO_short_hash (&rp_msg->public_key,
- sizeof (rp_msg->public_key),
- &zone_hash);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Putting %u records under name `%s' in zone `%s'\n",
- rd_count, name,
- GNUNET_short_h2s (&zone_hash));
- res = GSN_database->put_records(GSN_database->cls,
- &rp_msg->public_key,
- expire,
- name,
- rd_count, rd,
- signature);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Putting record for name `%s': %s\n",
- name,
- (GNUNET_OK == res) ? "OK" : "FAILED");
}
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Putting %u records under name `%s' in zone `%s'\n",
+ rd_count, conv_name,
+ GNUNET_short_h2s (&zone_hash));
+ res = GSN_database->put_records(GSN_database->cls,
+ &rp_msg->public_key,
+ expire,
+ conv_name,
+ rd_count, rd,
+ signature);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Putting record for name `%s': %s\n",
+ conv_name,
+ (GNUNET_OK == res) ? "OK" : "FAILED");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending `%s' message\n",
"RECORD_PUT_RESPONSE");
+ GNUNET_free (conv_name);
rpr_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE);
rpr_msg.gns_header.header.size = htons (sizeof (struct RecordPutResponseMessage));
rpr_msg.gns_header.r_id = htonl (rid);
@@ -1150,6 +1169,7 @@ handle_record_create (void *cls,
uint32_t rid;
const char *pkey_tmp;
const char *name_tmp;
+ char *conv_name;
const char *rd_ser;
unsigned int rd_count;
int res;
@@ -1220,17 +1240,26 @@ handle_record_create (void *cls,
sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&pubkey_hash);
learn_private_key (pkey);
+
+ conv_name = GNUNET_NAMESTORE_normalize_string(name_tmp);
+ if (NULL == conv_name)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error converting name `%s'\n", name_tmp);
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Creating record for name `%s' in zone `%s'\n",
- name_tmp, GNUNET_short_h2s(&pubkey_hash));
+ conv_name, GNUNET_short_h2s(&pubkey_hash));
crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire);
crc.res = GNUNET_SYSERR;
crc.rd = &rd;
- crc.name = name_tmp;
+ crc.name = conv_name;
/* Get existing records for name */
- res = GSN_database->iterate_records (GSN_database->cls, &pubkey_hash, name_tmp, 0,
+ res = GSN_database->iterate_records (GSN_database->cls, &pubkey_hash, conv_name, 0,
&handle_create_record_it, &crc);
+ GNUNET_free (conv_name);
if (res != GNUNET_SYSERR)
res = GNUNET_OK;
@@ -1399,6 +1428,7 @@ handle_record_remove (void *cls,
const char *pkey_tmp;
const char *name_tmp;
const char *rd_ser;
+ char * conv_name;
size_t key_len;
size_t name_len;
size_t rd_ser_len;
@@ -1473,15 +1503,23 @@ handle_record_remove (void *cls,
return;
}
+ conv_name = GNUNET_NAMESTORE_normalize_string(name_tmp);
+ if (NULL == conv_name)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error converting name `%s'\n", name_tmp);
+ return;
+ }
+
if (0 == rd_count)
{
/* remove the whole name and all records */
res = GSN_database->remove_records (GSN_database->cls,
&pubkey_hash,
- name_tmp);
+ conv_name);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Removing name `%s': %s\n",
- name_tmp, (GNUNET_OK == res) ? "OK" : "FAILED");
+ conv_name, (GNUNET_OK == res) ? "OK" : "FAILED");
if (GNUNET_OK != res)
/* Could not remove entry from database */
res = RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE;
@@ -1492,7 +1530,7 @@ handle_record_remove (void *cls,
{
/* remove a single record */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Removing record for name `%s' in zone `%s'\n", name_tmp,
+ "Removing record for name `%s' in zone `%s'\n", conv_name,
GNUNET_short_h2s (&pubkey_hash));
rrc.rd = &rd;
rrc.op_res = RECORD_REMOVE_RESULT_RECORD_NOT_FOUND;
@@ -1503,7 +1541,7 @@ handle_record_remove (void *cls,
{
res = GSN_database->iterate_records (GSN_database->cls,
&pubkey_hash,
- name_tmp,
+ conv_name,
off++,
&handle_record_remove_it, &rrc);
}
@@ -1527,6 +1565,7 @@ handle_record_remove (void *cls,
break;
}
}
+ GNUNET_free (conv_name);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending `%s' message\n",
"RECORD_REMOVE_RESPONSE");
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index 49015f158e..42cc2b2d18 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -32,6 +32,14 @@
#define MAX_NAME_LEN 256
/**
+ * Convert a string from to local codeset to UTF-8 lowercase
+ * @param src source string
+ * @return converted result
+ */
+char *
+GNUNET_NAMESTORE_normalize_string (const char *src);
+
+/**
* Convert a short hash to a string (for printing debug messages).
* This is one of the very few calls in the entire API that is
* NOT reentrant!
diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c
index 47029b73b0..4033748096 100644
--- a/src/namestore/namestore_common.c
+++ b/src/namestore/namestore_common.c
@@ -71,6 +71,25 @@ struct NetworkRecord
GNUNET_NETWORK_STRUCT_END
+/**
+ * Convert a string from to local codeset to UTF-8 lowercase
+ * @param src source string
+ * @return converted result
+ */
+char *
+GNUNET_NAMESTORE_normalize_string (const char *src)
+{
+ char *utf_8_str;
+
+ GNUNET_assert (NULL != src);
+ /* Convert to UTF8 */
+ utf_8_str = GNUNET_STRINGS_to_utf8 (src, strlen (src), nl_langinfo (CODESET));
+ GNUNET_assert (NULL != utf_8_str);
+ /* normalize */
+ GNUNET_STRINGS_utf8_tolower(utf_8_str, &utf_8_str);
+ return utf_8_str;
+}
+
/**
* Convert a short hash to a string (for printing debug messages).
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index 565805921f..a685ab4dcf 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -4,7 +4,7 @@ DEFAULTSERVICES = namestore
UNIXPATH = /tmp/gnunet-p1-service-arm.sock
[namestore]
-#PREFIX = valgrind --leak-check=full --track-origins=yes
+#PREFIX = valgrind
AUTOSTART = YES
UNIXPATH = /tmp/gnunet-service-namestore.sock
UNIX_MATCH_UID = YES
@@ -12,7 +12,7 @@ UNIX_MATCH_GID = YES
PORT = 2099
HOSTNAME = localhost
HOME = $SERVICEHOME
-BINARY = gnunet-service-namestore
+BINARY = gnunet-service-namestore2
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;
DATABASE = sqlite
diff --git a/src/namestore/test_namestore_api_create.c b/src/namestore/test_namestore_api_create.c
index 583f78a01d..63e403c066 100644
--- a/src/namestore/test_namestore_api_create.c
+++ b/src/namestore/test_namestore_api_create.c
@@ -84,6 +84,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (privkey != NULL)
GNUNET_CRYPTO_rsa_key_free (privkey);
privkey = NULL;
+ GNUNET_free_non_null (s_name);
res = 1;
}
@@ -99,6 +100,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_free ((void *) s_first_record->data);
GNUNET_free (s_first_record);
GNUNET_free_non_null (s_second_record);
+ GNUNET_free_non_null (s_name);
if (privkey != NULL)
GNUNET_CRYPTO_rsa_key_free (privkey);
privkey = NULL;
@@ -361,7 +363,7 @@ run (void *cls,
GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
/* create record */
- s_name = "dummy.dummy.gnunet";
+ s_name = GNUNET_NAMESTORE_normalize_string ("DUMMY.dummy.gnunet");
s_first_record = create_record (1);
rd_ser_len = GNUNET_NAMESTORE_records_get_size(1, s_first_record);
diff --git a/src/namestore/test_namestore_api_create_update.c b/src/namestore/test_namestore_api_create_update.c
index 1601b39d80..8998cabab4 100644
--- a/src/namestore/test_namestore_api_create_update.c
+++ b/src/namestore/test_namestore_api_create_update.c
@@ -82,6 +82,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (privkey != NULL)
GNUNET_CRYPTO_rsa_key_free (privkey);
privkey = NULL;
+ GNUNET_free_non_null (s_name);
res = 1;
}
@@ -103,6 +104,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (nsh != NULL)
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
+ GNUNET_free_non_null (s_name);
}
@@ -213,7 +215,7 @@ run (void *cls,
GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
/* create record */
- s_name = "dummy.dummy.gnunet";
+ s_name = GNUNET_NAMESTORE_normalize_string ("DUMMY.dummy.gnunet");
s_first_record = create_record (1);
rd_ser_len = GNUNET_NAMESTORE_records_get_size(1, s_first_record);
diff --git a/src/namestore/test_namestore_api_lookup.c b/src/namestore/test_namestore_api_lookup.c
index c60354e9e6..53e4626e50 100644
--- a/src/namestore/test_namestore_api_lookup.c
+++ b/src/namestore/test_namestore_api_lookup.c
@@ -228,7 +228,7 @@ run (void *cls,
GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
/* create record */
- s_name = "dummy.dummy.gnunet";
+ s_name = GNUNET_NAMESTORE_normalize_string ("DUMMY.dummy.gnunet");
s_rd = create_record (RECORDS);
rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd);
diff --git a/src/namestore/test_namestore_api_lookup_specific_type.c b/src/namestore/test_namestore_api_lookup_specific_type.c
index 793e55c1e0..be45d938e3 100644
--- a/src/namestore/test_namestore_api_lookup_specific_type.c
+++ b/src/namestore/test_namestore_api_lookup_specific_type.c
@@ -78,6 +78,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (privkey != NULL)
GNUNET_CRYPTO_rsa_key_free (privkey);
privkey = NULL;
+ GNUNET_free_non_null (s_name);
res = 1;
}
@@ -97,7 +98,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_free_non_null((void *) s_rd[c].data);
}
GNUNET_free (s_rd);
-
+ GNUNET_free_non_null (s_name);
if (privkey != NULL)
GNUNET_CRYPTO_rsa_key_free (privkey);
privkey = NULL;
@@ -286,7 +287,7 @@ run (void *cls,
GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
/* create record */
- s_name = "dummy.dummy.gnunet";
+ s_name = GNUNET_NAMESTORE_normalize_string ("DUMMY.dummy.gnunet");
s_rd = create_record (RECORDS);
rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd);
diff --git a/src/namestore/test_namestore_api_put.c b/src/namestore/test_namestore_api_put.c
index 3cf1b465b3..d15d22f31a 100644
--- a/src/namestore/test_namestore_api_put.c
+++ b/src/namestore/test_namestore_api_put.c
@@ -137,7 +137,7 @@ run (void *cls,
struct GNUNET_TESTING_Peer *peer)
{
struct GNUNET_CRYPTO_RsaSignature *signature;
- const char * s_name = "dummy.dummy.gnunet";
+ char * s_name;
int c;
char *hostkey_file;
struct GNUNET_TIME_Absolute et;
@@ -155,6 +155,7 @@ run (void *cls,
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
/* create record */
+ s_name = GNUNET_NAMESTORE_normalize_string ("DUMMY.dummy.gnunet");
s_rd = create_record (RECORDS);
et.abs_value = s_rd[0].expiration_time;
signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, s_rd, RECORDS);
@@ -167,6 +168,7 @@ run (void *cls,
for (c = 0; c < RECORDS; c++)
GNUNET_free_non_null((void *) s_rd[c].data);
GNUNET_free (s_rd);
+ GNUNET_free (s_name);
}
diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c
index 87303bc49d..f2bcf0e664 100644
--- a/src/namestore/test_namestore_api_remove.c
+++ b/src/namestore/test_namestore_api_remove.c
@@ -79,6 +79,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (privkey != NULL)
GNUNET_CRYPTO_rsa_key_free (privkey);
privkey = NULL;
+ GNUNET_free_non_null (s_name);
res = 1;
}
@@ -102,6 +103,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (nsh != NULL)
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
+ GNUNET_free_non_null (s_name);
}
@@ -259,7 +261,7 @@ run (void *cls,
GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
/* create record */
- s_name = "dummy.dummy.gnunet";
+ s_name = GNUNET_NAMESTORE_normalize_string ("DUMMY.dummy.gnunet");
s_rd = create_record (RECORDS);
rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd);
diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c
index 472ddbdfe1..54a273b9b7 100644
--- a/src/namestore/test_namestore_api_remove_not_existing_record.c
+++ b/src/namestore/test_namestore_api_remove_not_existing_record.c
@@ -79,6 +79,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (privkey != NULL)
GNUNET_CRYPTO_rsa_key_free (privkey);
privkey = NULL;
+ GNUNET_free_non_null (s_name);
res = 1;
}
@@ -103,6 +104,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
if (nsh != NULL)
GNUNET_NAMESTORE_disconnect (nsh);
nsh = NULL;
+ GNUNET_free_non_null (s_name);
}
@@ -195,7 +197,7 @@ run (void *cls,
GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
/* create record */
- s_name = "dummy.dummy.gnunet";
+ s_name = GNUNET_NAMESTORE_normalize_string ("DUMMY.dummy.gnunet");
s_rd = create_record (RECORDS);
rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd);
diff --git a/src/namestore/test_namestore_api_sign_verify.c b/src/namestore/test_namestore_api_sign_verify.c
index fe7425ebf2..10be25bb40 100644
--- a/src/namestore/test_namestore_api_sign_verify.c
+++ b/src/namestore/test_namestore_api_sign_verify.c
@@ -94,7 +94,7 @@ run (void *cls, char *const *args, const char *cfgfile,
int res_w;
/* create record */
- s_name = "dummy.dummy.gnunet";
+ s_name = "DUMMY.dummy.gnunet";
s_rd = create_record (RECORDS);
signature = GNUNET_NAMESTORE_create_signature (privkey, expire, s_name, s_rd, RECORDS);