[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: - fix sqlite free issue; allow to autote
From: |
gnunet |
Subject: |
[gnunet] branch master updated: - fix sqlite free issue; allow to autotedect or provide corectly in zonefile |
Date: |
Thu, 20 Oct 2022 06:23:02 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 3d7d23db1 - fix sqlite free issue; allow to autotedect or provide
corectly in zonefile
3d7d23db1 is described below
commit 3d7d23db1764973179fe9fc0013b942692c47df5
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Thu Oct 20 13:22:56 2022 +0900
- fix sqlite free issue; allow to autotedect or provide corectly in
zonefile
---
src/namestore/gnunet-namestore-zonefile.c | 60 ++++++++++++++++++++-----------
src/namestore/gnunet-service-namestore.c | 22 +++++++-----
src/namestore/plugin_namestore_sqlite.c | 47 +++++++++++++++++-------
3 files changed, 87 insertions(+), 42 deletions(-)
diff --git a/src/namestore/gnunet-namestore-zonefile.c
b/src/namestore/gnunet-namestore-zonefile.c
index 14dc60acc..26906d140 100644
--- a/src/namestore/gnunet-namestore-zonefile.c
+++ b/src/namestore/gnunet-namestore-zonefile.c
@@ -121,6 +121,11 @@ static struct GNUNET_IDENTITY_Handle *id;
*/
static const struct GNUNET_CONFIGURATION_Handle *cfg;
+/**
+ * Scheduled parse task
+ */
+static struct GNUNET_SCHEDULER_Task *parse_task;
+
/**
* The current state of the parser
*/
@@ -129,9 +134,12 @@ static int state;
enum ZonefileImportState
{
- /* The initial state */
+ /* Uninitialized */
ZS_READY,
+ /* The initial state */
+ ZS_ORIGIN_SET,
+
/* The $ORIGIN has changed */
ZS_ORIGIN_CHANGED,
@@ -171,7 +179,8 @@ do_shutdown (void *cls)
void *rd_ptr = (void*) rd[i].data;
GNUNET_free (rd_ptr);
}
-
+ if (NULL != parse_task)
+ GNUNET_SCHEDULER_cancel (parse_task);
}
static void
@@ -283,9 +292,9 @@ origin_create_cb (void *cls, const struct
GNUNET_IDENTITY_PrivateKey *pk,
GNUNET_SCHEDULER_shutdown ();
return;
}
- state = ZS_READY;
+ state = ZS_ORIGIN_SET;
zone_pkey = *pk;
- GNUNET_SCHEDULER_add_now (&parse, NULL);
+ parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL);
}
static void
@@ -305,9 +314,9 @@ origin_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego
*ego)
NULL);
return;
}
- state = ZS_READY;
+ state = ZS_ORIGIN_SET;
zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
- GNUNET_SCHEDULER_add_now (&parse, NULL);
+ parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL);
}
static void
@@ -334,7 +343,7 @@ add_continuation (void *cls, int32_t success, const char
*emsg)
&origin_lookup_cb, NULL);
return;
}
- GNUNET_SCHEDULER_add_now (&parse, NULL);
+ parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL);
}
@@ -372,18 +381,20 @@ parse (void *cls)
int bracket_unclosed = 0;
int quoted = 0;
+ parse_task = NULL;
/* use filename provided as 1st argument (stdin by default) */
- int i = 0;
+ int ln = 0;
while (res = fgets (buf, sizeof(buf), stdin)) /* read
each line of input */
{
- i++;
+ ln++;
ttl_line = 0;
token = trim (buf);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Trimmed line (bracket %s): `%s'\n",
(bracket_unclosed > 0) ? "unclosed" : "closed",
token);
- if ((1 == strlen (token)) && (' ' == *token))
+ if ((0 == strlen (token)) ||
+ ((1 == strlen (token)) && (' ' == *token)))
continue; // I guess we can safely ignore blank lines
if (bracket_unclosed == 0)
{
@@ -393,7 +404,7 @@ parse (void *cls)
next = strchr (token, ' ');
if (NULL == next)
{
- fprintf (stderr, "Error at line %u: %s\n", i, token);
+ fprintf (stderr, "Error at line %u: %s\n", ln, token);
break;
}
next[0] = '\0';
@@ -498,6 +509,14 @@ parse (void *cls)
}
break;
}
+ if (ZS_READY == state)
+ {
+ fprintf (stderr,
+ _ ("You must provide $ORIGIN in your zonefile or via
arguments (--zone)!\n"));
+ ret = 1;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
// This is a record, let's go
if (MAX_RECORDS_PER_NAME == rd_count)
{
@@ -507,7 +526,6 @@ parse (void *cls)
ret = 1;
GNUNET_SCHEDULER_shutdown ();
return;
-
}
rd[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
rd[rd_count].expiration_time = ttl.rel_value_us;
@@ -598,7 +616,7 @@ parse (void *cls)
rd[0] = rd[rd_count]; // recover last rd parsed.
rd_count = 1;
strcpy (lastname, newname);
- state = ZS_READY;
+ state = ZS_ORIGIN_SET;
}
else
rd_count = 0;
@@ -637,7 +655,7 @@ tx_start (void *cls, int32_t success, const char *emsg)
ret = -1;
return;
}
- GNUNET_SCHEDULER_add_now (&parse, NULL);
+ parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL);
}
static void
@@ -654,12 +672,15 @@ identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
fprintf (stderr,
_ ("Ego `%s' not known to identity service\n"),
ego_name);
+
}
GNUNET_SCHEDULER_shutdown ();
ret = -1;
return;
}
zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
+ sprintf (origin, "%s.", ego_name);
+ state = ZS_ORIGIN_SET;
ns_qe = GNUNET_NAMESTORE_transaction_begin (ns,
&tx_start,
NULL);
@@ -688,13 +709,10 @@ run (void *cls,
_ ("Failed to connect to IDENTITY\n"));
return;
}
- if (NULL == ego_name)
- {
- fprintf (stderr, _ ("You must provide a zone ego to use\n"));
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg);
+ if (NULL != ego_name)
+ el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *)
cfg);
+ else
+ parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL);
state = ZS_READY;
}
diff --git a/src/namestore/gnunet-service-namestore.c
b/src/namestore/gnunet-service-namestore.c
index 6b93c1973..7cd36f317 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1198,14 +1198,17 @@ client_disconnect_cb (void *cls,
GNUNET_free (zm);
break;
}
- for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next)
+ sa = sa_head;
+ while (NULL != sa)
{
- if (sa->nc == nc)
+ if (nc != sa->nc)
{
- /* this may free sa */
- free_store_activity (sa);
- break; /* there can only be one per nc */
+ sa = sa->next;
+ continue;
}
+ sn = sa->next;
+ free_store_activity (sa);
+ sa = sn;
}
while (NULL != (no = nc->op_head))
{
@@ -1761,7 +1764,8 @@ store_record_set (struct NamestoreClient *nc,
return GNUNET_SYSERR;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%u/%u records before tombstone\n", rd_nf_count,
rd_clean_off);
+ "%u/%u records before tombstone\n", rd_nf_count,
+ rd_clean_off);
/*
* If existing_block_exp is 0, then there was no record set
* and no tombstone.
@@ -1804,7 +1808,7 @@ store_record_set (struct NamestoreClient *nc,
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Client tried to remove non-existant record\n");
- *emsg = GNUNET_strdup (_("Not records to delete."));
+ *emsg = GNUNET_strdup (_ ("Not records to delete."));
res = GNUNET_NO;
}
}
@@ -1897,9 +1901,9 @@ send_tx_response (int rid, int status, char *emsg, struct
NamestoreClient *nc)
txr_msg->success = htons (status);
err_tmp = (char *) &txr_msg[1];
GNUNET_memcpy (err_tmp, emsg, err_len);
- GNUNET_free (emsg);
+ if (NULL != emsg)
+ GNUNET_free (emsg);
GNUNET_MQ_send (nc->mq, env);
-
}
/**
diff --git a/src/namestore/plugin_namestore_sqlite.c
b/src/namestore/plugin_namestore_sqlite.c
index 67440063b..ca0d9c81c 100644
--- a/src/namestore/plugin_namestore_sqlite.c
+++ b/src/namestore/plugin_namestore_sqlite.c
@@ -177,8 +177,8 @@ database_prepare (struct Plugin *plugin)
es))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
- _("Failed to setup database with: `%s'\n"),
- sqlite3_errmsg (plugin->dbh));
+ _ ("Failed to setup database with: `%s'\n"),
+ sqlite3_errmsg (plugin->dbh));
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -712,11 +712,18 @@ namestore_sqlite_transaction_begin (void *cls,
char **emsg)
{
struct Plugin *plugin = cls;
+ int rc;
+ char *sqlEmsg;
+
GNUNET_assert (GNUNET_OK == database_prepare (plugin));
- return (SQLITE_BUSY == sqlite3_exec (plugin->dbh,
- "BEGIN IMMEDIATE TRANSACTION;", NULL,
- NULL, emsg)) ? GNUNET_SYSERR :
- GNUNET_YES;
+ rc = sqlite3_exec (plugin->dbh, "BEGIN IMMEDIATE TRANSACTION;",
+ NULL, NULL, &sqlEmsg);
+ if (SQLITE_OK != rc)
+ {
+ *emsg = GNUNET_strdup (sqlEmsg);
+ sqlite3_free (sqlEmsg);
+ }
+ return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES;
}
/**
@@ -732,10 +739,18 @@ namestore_sqlite_transaction_rollback (void *cls,
char **emsg)
{
struct Plugin *plugin = cls;
+ int rc;
+ char *sqlEmsg;
+
GNUNET_assert (GNUNET_OK == database_prepare (plugin));
- return (SQLITE_BUSY == sqlite3_exec (plugin->dbh, "ROLLBACK;", NULL,
- NULL, emsg)) ? GNUNET_SYSERR :
- GNUNET_YES;
+ rc = sqlite3_exec (plugin->dbh, "ROLLBACK;",
+ NULL, NULL, &sqlEmsg);
+ if (SQLITE_OK != rc)
+ {
+ *emsg = GNUNET_strdup (sqlEmsg);
+ sqlite3_free (sqlEmsg);
+ }
+ return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES;
}
/**
@@ -751,10 +766,18 @@ namestore_sqlite_transaction_commit (void *cls,
char **emsg)
{
struct Plugin *plugin = cls;
+ int rc;
+ char *sqlEmsg;
+
GNUNET_assert (GNUNET_OK == database_prepare (plugin));
- return (SQLITE_BUSY == sqlite3_exec (plugin->dbh, "END TRANSACTION;", NULL,
- NULL, emsg)) ? GNUNET_SYSERR :
- GNUNET_YES;
+ rc = sqlite3_exec (plugin->dbh, "END TRANSACTION;",
+ NULL, NULL, &sqlEmsg);
+ if (SQLITE_OK != rc)
+ {
+ *emsg = GNUNET_strdup (sqlEmsg);
+ sqlite3_free (sqlEmsg);
+ }
+ return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES;
}
static enum GNUNET_GenericReturnValue
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: - fix sqlite free issue; allow to autotedect or provide corectly in zonefile,
gnunet <=