diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-20 13:22:56 +0900 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-10-20 13:22:56 +0900 |
commit | 3d7d23db1764973179fe9fc0013b942692c47df5 (patch) | |
tree | 6a4c4ca241ccb11432dc0f5276eb6a317bf2c7dc /src/namestore | |
parent | aa827c7e06a8f52334d5492627832582964747c4 (diff) | |
download | gnunet-3d7d23db1764973179fe9fc0013b942692c47df5.tar.gz gnunet-3d7d23db1764973179fe9fc0013b942692c47df5.zip |
- fix sqlite free issue; allow to autotedect or provide corectly in zonefile
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-namestore-zonefile.c | 60 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 22 | ||||
-rw-r--r-- | 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 | |||
@@ -122,6 +122,11 @@ static struct GNUNET_IDENTITY_Handle *id; | |||
122 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 122 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
123 | 123 | ||
124 | /** | 124 | /** |
125 | * Scheduled parse task | ||
126 | */ | ||
127 | static struct GNUNET_SCHEDULER_Task *parse_task; | ||
128 | |||
129 | /** | ||
125 | * The current state of the parser | 130 | * The current state of the parser |
126 | */ | 131 | */ |
127 | static int state; | 132 | static int state; |
@@ -129,9 +134,12 @@ static int state; | |||
129 | enum ZonefileImportState | 134 | enum ZonefileImportState |
130 | { | 135 | { |
131 | 136 | ||
132 | /* The initial state */ | 137 | /* Uninitialized */ |
133 | ZS_READY, | 138 | ZS_READY, |
134 | 139 | ||
140 | /* The initial state */ | ||
141 | ZS_ORIGIN_SET, | ||
142 | |||
135 | /* The $ORIGIN has changed */ | 143 | /* The $ORIGIN has changed */ |
136 | ZS_ORIGIN_CHANGED, | 144 | ZS_ORIGIN_CHANGED, |
137 | 145 | ||
@@ -171,7 +179,8 @@ do_shutdown (void *cls) | |||
171 | void *rd_ptr = (void*) rd[i].data; | 179 | void *rd_ptr = (void*) rd[i].data; |
172 | GNUNET_free (rd_ptr); | 180 | GNUNET_free (rd_ptr); |
173 | } | 181 | } |
174 | 182 | if (NULL != parse_task) | |
183 | GNUNET_SCHEDULER_cancel (parse_task); | ||
175 | } | 184 | } |
176 | 185 | ||
177 | static void | 186 | static void |
@@ -283,9 +292,9 @@ origin_create_cb (void *cls, const struct GNUNET_IDENTITY_PrivateKey *pk, | |||
283 | GNUNET_SCHEDULER_shutdown (); | 292 | GNUNET_SCHEDULER_shutdown (); |
284 | return; | 293 | return; |
285 | } | 294 | } |
286 | state = ZS_READY; | 295 | state = ZS_ORIGIN_SET; |
287 | zone_pkey = *pk; | 296 | zone_pkey = *pk; |
288 | GNUNET_SCHEDULER_add_now (&parse, NULL); | 297 | parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL); |
289 | } | 298 | } |
290 | 299 | ||
291 | static void | 300 | static void |
@@ -305,9 +314,9 @@ origin_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
305 | NULL); | 314 | NULL); |
306 | return; | 315 | return; |
307 | } | 316 | } |
308 | state = ZS_READY; | 317 | state = ZS_ORIGIN_SET; |
309 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | 318 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); |
310 | GNUNET_SCHEDULER_add_now (&parse, NULL); | 319 | parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL); |
311 | } | 320 | } |
312 | 321 | ||
313 | static void | 322 | static void |
@@ -334,7 +343,7 @@ add_continuation (void *cls, int32_t success, const char *emsg) | |||
334 | &origin_lookup_cb, NULL); | 343 | &origin_lookup_cb, NULL); |
335 | return; | 344 | return; |
336 | } | 345 | } |
337 | GNUNET_SCHEDULER_add_now (&parse, NULL); | 346 | parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL); |
338 | } | 347 | } |
339 | 348 | ||
340 | 349 | ||
@@ -372,18 +381,20 @@ parse (void *cls) | |||
372 | int bracket_unclosed = 0; | 381 | int bracket_unclosed = 0; |
373 | int quoted = 0; | 382 | int quoted = 0; |
374 | 383 | ||
384 | parse_task = NULL; | ||
375 | /* use filename provided as 1st argument (stdin by default) */ | 385 | /* use filename provided as 1st argument (stdin by default) */ |
376 | int i = 0; | 386 | int ln = 0; |
377 | while (res = fgets (buf, sizeof(buf), stdin)) /* read each line of input */ | 387 | while (res = fgets (buf, sizeof(buf), stdin)) /* read each line of input */ |
378 | { | 388 | { |
379 | i++; | 389 | ln++; |
380 | ttl_line = 0; | 390 | ttl_line = 0; |
381 | token = trim (buf); | 391 | token = trim (buf); |
382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
383 | "Trimmed line (bracket %s): `%s'\n", | 393 | "Trimmed line (bracket %s): `%s'\n", |
384 | (bracket_unclosed > 0) ? "unclosed" : "closed", | 394 | (bracket_unclosed > 0) ? "unclosed" : "closed", |
385 | token); | 395 | token); |
386 | if ((1 == strlen (token)) && (' ' == *token)) | 396 | if ((0 == strlen (token)) || |
397 | ((1 == strlen (token)) && (' ' == *token))) | ||
387 | continue; // I guess we can safely ignore blank lines | 398 | continue; // I guess we can safely ignore blank lines |
388 | if (bracket_unclosed == 0) | 399 | if (bracket_unclosed == 0) |
389 | { | 400 | { |
@@ -393,7 +404,7 @@ parse (void *cls) | |||
393 | next = strchr (token, ' '); | 404 | next = strchr (token, ' '); |
394 | if (NULL == next) | 405 | if (NULL == next) |
395 | { | 406 | { |
396 | fprintf (stderr, "Error at line %u: %s\n", i, token); | 407 | fprintf (stderr, "Error at line %u: %s\n", ln, token); |
397 | break; | 408 | break; |
398 | } | 409 | } |
399 | next[0] = '\0'; | 410 | next[0] = '\0'; |
@@ -498,6 +509,14 @@ parse (void *cls) | |||
498 | } | 509 | } |
499 | break; | 510 | break; |
500 | } | 511 | } |
512 | if (ZS_READY == state) | ||
513 | { | ||
514 | fprintf (stderr, | ||
515 | _ ("You must provide $ORIGIN in your zonefile or via arguments (--zone)!\n")); | ||
516 | ret = 1; | ||
517 | GNUNET_SCHEDULER_shutdown (); | ||
518 | return; | ||
519 | } | ||
501 | // This is a record, let's go | 520 | // This is a record, let's go |
502 | if (MAX_RECORDS_PER_NAME == rd_count) | 521 | if (MAX_RECORDS_PER_NAME == rd_count) |
503 | { | 522 | { |
@@ -507,7 +526,6 @@ parse (void *cls) | |||
507 | ret = 1; | 526 | ret = 1; |
508 | GNUNET_SCHEDULER_shutdown (); | 527 | GNUNET_SCHEDULER_shutdown (); |
509 | return; | 528 | return; |
510 | |||
511 | } | 529 | } |
512 | rd[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 530 | rd[rd_count].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
513 | rd[rd_count].expiration_time = ttl.rel_value_us; | 531 | rd[rd_count].expiration_time = ttl.rel_value_us; |
@@ -598,7 +616,7 @@ parse (void *cls) | |||
598 | rd[0] = rd[rd_count]; // recover last rd parsed. | 616 | rd[0] = rd[rd_count]; // recover last rd parsed. |
599 | rd_count = 1; | 617 | rd_count = 1; |
600 | strcpy (lastname, newname); | 618 | strcpy (lastname, newname); |
601 | state = ZS_READY; | 619 | state = ZS_ORIGIN_SET; |
602 | } | 620 | } |
603 | else | 621 | else |
604 | rd_count = 0; | 622 | rd_count = 0; |
@@ -637,7 +655,7 @@ tx_start (void *cls, int32_t success, const char *emsg) | |||
637 | ret = -1; | 655 | ret = -1; |
638 | return; | 656 | return; |
639 | } | 657 | } |
640 | GNUNET_SCHEDULER_add_now (&parse, NULL); | 658 | parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL); |
641 | } | 659 | } |
642 | 660 | ||
643 | static void | 661 | static void |
@@ -654,12 +672,15 @@ identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
654 | fprintf (stderr, | 672 | fprintf (stderr, |
655 | _ ("Ego `%s' not known to identity service\n"), | 673 | _ ("Ego `%s' not known to identity service\n"), |
656 | ego_name); | 674 | ego_name); |
675 | |||
657 | } | 676 | } |
658 | GNUNET_SCHEDULER_shutdown (); | 677 | GNUNET_SCHEDULER_shutdown (); |
659 | ret = -1; | 678 | ret = -1; |
660 | return; | 679 | return; |
661 | } | 680 | } |
662 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | 681 | zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); |
682 | sprintf (origin, "%s.", ego_name); | ||
683 | state = ZS_ORIGIN_SET; | ||
663 | ns_qe = GNUNET_NAMESTORE_transaction_begin (ns, | 684 | ns_qe = GNUNET_NAMESTORE_transaction_begin (ns, |
664 | &tx_start, | 685 | &tx_start, |
665 | NULL); | 686 | NULL); |
@@ -688,13 +709,10 @@ run (void *cls, | |||
688 | _ ("Failed to connect to IDENTITY\n")); | 709 | _ ("Failed to connect to IDENTITY\n")); |
689 | return; | 710 | return; |
690 | } | 711 | } |
691 | if (NULL == ego_name) | 712 | if (NULL != ego_name) |
692 | { | 713 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); |
693 | fprintf (stderr, _ ("You must provide a zone ego to use\n")); | 714 | else |
694 | GNUNET_SCHEDULER_shutdown (); | 715 | parse_task = GNUNET_SCHEDULER_add_now (&parse, NULL); |
695 | return; | ||
696 | } | ||
697 | el = GNUNET_IDENTITY_ego_lookup (cfg, ego_name, &identity_cb, (void *) cfg); | ||
698 | state = ZS_READY; | 716 | state = ZS_READY; |
699 | } | 717 | } |
700 | 718 | ||
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, | |||
1198 | GNUNET_free (zm); | 1198 | GNUNET_free (zm); |
1199 | break; | 1199 | break; |
1200 | } | 1200 | } |
1201 | for (struct StoreActivity *sa = sa_head; NULL != sa; sa = sa->next) | 1201 | sa = sa_head; |
1202 | while (NULL != sa) | ||
1202 | { | 1203 | { |
1203 | if (sa->nc == nc) | 1204 | if (nc != sa->nc) |
1204 | { | 1205 | { |
1205 | /* this may free sa */ | 1206 | sa = sa->next; |
1206 | free_store_activity (sa); | 1207 | continue; |
1207 | break; /* there can only be one per nc */ | ||
1208 | } | 1208 | } |
1209 | sn = sa->next; | ||
1210 | free_store_activity (sa); | ||
1211 | sa = sn; | ||
1209 | } | 1212 | } |
1210 | while (NULL != (no = nc->op_head)) | 1213 | while (NULL != (no = nc->op_head)) |
1211 | { | 1214 | { |
@@ -1761,7 +1764,8 @@ store_record_set (struct NamestoreClient *nc, | |||
1761 | return GNUNET_SYSERR; | 1764 | return GNUNET_SYSERR; |
1762 | } | 1765 | } |
1763 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1764 | "%u/%u records before tombstone\n", rd_nf_count, rd_clean_off); | 1767 | "%u/%u records before tombstone\n", rd_nf_count, |
1768 | rd_clean_off); | ||
1765 | /* | 1769 | /* |
1766 | * If existing_block_exp is 0, then there was no record set | 1770 | * If existing_block_exp is 0, then there was no record set |
1767 | * and no tombstone. | 1771 | * and no tombstone. |
@@ -1804,7 +1808,7 @@ store_record_set (struct NamestoreClient *nc, | |||
1804 | { | 1808 | { |
1805 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1806 | "Client tried to remove non-existant record\n"); | 1810 | "Client tried to remove non-existant record\n"); |
1807 | *emsg = GNUNET_strdup (_("Not records to delete.")); | 1811 | *emsg = GNUNET_strdup (_ ("Not records to delete.")); |
1808 | res = GNUNET_NO; | 1812 | res = GNUNET_NO; |
1809 | } | 1813 | } |
1810 | } | 1814 | } |
@@ -1897,9 +1901,9 @@ send_tx_response (int rid, int status, char *emsg, struct NamestoreClient *nc) | |||
1897 | txr_msg->success = htons (status); | 1901 | txr_msg->success = htons (status); |
1898 | err_tmp = (char *) &txr_msg[1]; | 1902 | err_tmp = (char *) &txr_msg[1]; |
1899 | GNUNET_memcpy (err_tmp, emsg, err_len); | 1903 | GNUNET_memcpy (err_tmp, emsg, err_len); |
1900 | GNUNET_free (emsg); | 1904 | if (NULL != emsg) |
1905 | GNUNET_free (emsg); | ||
1901 | GNUNET_MQ_send (nc->mq, env); | 1906 | GNUNET_MQ_send (nc->mq, env); |
1902 | |||
1903 | } | 1907 | } |
1904 | 1908 | ||
1905 | /** | 1909 | /** |
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) | |||
177 | es)) | 177 | es)) |
178 | { | 178 | { |
179 | LOG (GNUNET_ERROR_TYPE_ERROR, | 179 | LOG (GNUNET_ERROR_TYPE_ERROR, |
180 | _("Failed to setup database with: `%s'\n"), | 180 | _ ("Failed to setup database with: `%s'\n"), |
181 | sqlite3_errmsg (plugin->dbh)); | 181 | sqlite3_errmsg (plugin->dbh)); |
182 | return GNUNET_SYSERR; | 182 | return GNUNET_SYSERR; |
183 | } | 183 | } |
184 | if (GNUNET_OK != | 184 | if (GNUNET_OK != |
@@ -712,11 +712,18 @@ namestore_sqlite_transaction_begin (void *cls, | |||
712 | char **emsg) | 712 | char **emsg) |
713 | { | 713 | { |
714 | struct Plugin *plugin = cls; | 714 | struct Plugin *plugin = cls; |
715 | int rc; | ||
716 | char *sqlEmsg; | ||
717 | |||
715 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); | 718 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); |
716 | return (SQLITE_BUSY == sqlite3_exec (plugin->dbh, | 719 | rc = sqlite3_exec (plugin->dbh, "BEGIN IMMEDIATE TRANSACTION;", |
717 | "BEGIN IMMEDIATE TRANSACTION;", NULL, | 720 | NULL, NULL, &sqlEmsg); |
718 | NULL, emsg)) ? GNUNET_SYSERR : | 721 | if (SQLITE_OK != rc) |
719 | GNUNET_YES; | 722 | { |
723 | *emsg = GNUNET_strdup (sqlEmsg); | ||
724 | sqlite3_free (sqlEmsg); | ||
725 | } | ||
726 | return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES; | ||
720 | } | 727 | } |
721 | 728 | ||
722 | /** | 729 | /** |
@@ -732,10 +739,18 @@ namestore_sqlite_transaction_rollback (void *cls, | |||
732 | char **emsg) | 739 | char **emsg) |
733 | { | 740 | { |
734 | struct Plugin *plugin = cls; | 741 | struct Plugin *plugin = cls; |
742 | int rc; | ||
743 | char *sqlEmsg; | ||
744 | |||
735 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); | 745 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); |
736 | return (SQLITE_BUSY == sqlite3_exec (plugin->dbh, "ROLLBACK;", NULL, | 746 | rc = sqlite3_exec (plugin->dbh, "ROLLBACK;", |
737 | NULL, emsg)) ? GNUNET_SYSERR : | 747 | NULL, NULL, &sqlEmsg); |
738 | GNUNET_YES; | 748 | if (SQLITE_OK != rc) |
749 | { | ||
750 | *emsg = GNUNET_strdup (sqlEmsg); | ||
751 | sqlite3_free (sqlEmsg); | ||
752 | } | ||
753 | return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES; | ||
739 | } | 754 | } |
740 | 755 | ||
741 | /** | 756 | /** |
@@ -751,10 +766,18 @@ namestore_sqlite_transaction_commit (void *cls, | |||
751 | char **emsg) | 766 | char **emsg) |
752 | { | 767 | { |
753 | struct Plugin *plugin = cls; | 768 | struct Plugin *plugin = cls; |
769 | int rc; | ||
770 | char *sqlEmsg; | ||
771 | |||
754 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); | 772 | GNUNET_assert (GNUNET_OK == database_prepare (plugin)); |
755 | return (SQLITE_BUSY == sqlite3_exec (plugin->dbh, "END TRANSACTION;", NULL, | 773 | rc = sqlite3_exec (plugin->dbh, "END TRANSACTION;", |
756 | NULL, emsg)) ? GNUNET_SYSERR : | 774 | NULL, NULL, &sqlEmsg); |
757 | GNUNET_YES; | 775 | if (SQLITE_OK != rc) |
776 | { | ||
777 | *emsg = GNUNET_strdup (sqlEmsg); | ||
778 | sqlite3_free (sqlEmsg); | ||
779 | } | ||
780 | return (SQLITE_OK != rc) ? GNUNET_SYSERR : GNUNET_YES; | ||
758 | } | 781 | } |
759 | 782 | ||
760 | static enum GNUNET_GenericReturnValue | 783 | static enum GNUNET_GenericReturnValue |