Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

investigate 'needscomma' in json printer #6

Closed
job opened this issue Dec 22, 2019 · 1 comment
Closed

investigate 'needscomma' in json printer #6

job opened this issue Dec 22, 2019 · 1 comment

Comments

@job
Copy link
Member

job commented Dec 22, 2019

from notes from @pschoenm:

fixed issue when running bgpq3_print_json_prefixlist multiple times, creates a comma at the beginning of json. the variable needscomma should really be a pointer that is passed to the functions during printing. for now hacked it to initialize the variable at the start of a print that uses it.

@job
Copy link
Member Author

job commented Dec 22, 2019

possible patch

diff --git a/bgpq3_printer.c b/bgpq3_printer.c
index 2842b06..64f1844 100644
--- a/bgpq3_printer.c
+++ b/bgpq3_printer.c
@@ -701,6 +701,8 @@ int
 bgpq3_print_json_aspath(FILE* f, struct bgpq_expander* b)
 {
 	int nc=0, i, j, k;
+
+	needscomma = 0;
 	fprintf(f,"{\"%s\": [", b->name?b->name:"NN");

 	for(k=0;k<65536;k++) {
@@ -1231,6 +1233,7 @@ bgpq3_print_cisco_prefixlist(FILE* f, struct bgpq_expander* b)
 int
 bgpq3_print_ciscoxr_prefixlist(FILE* f, struct bgpq_expander* b)
 {
+	needscomma = 0;
 	bname=b->name ? b->name : "NN";
 	fprintf(f,"no prefix-set %s\nprefix-set %s\n", bname, bname);
 	sx_radix_tree_foreach(b->tree,bgpq3_print_cprefixxr,f);
@@ -1241,6 +1244,7 @@ bgpq3_print_ciscoxr_prefixlist(FILE* f, struct bgpq_expander* b)
 int
 bgpq3_print_json_prefixlist(FILE* f, struct bgpq_expander* b)
 {
+	needscomma = 0;
 	fprintf(f,"{ \"%s\": [",
 		b->name?b->name:"NN");
 	sx_radix_tree_foreach(b->tree,bgpq3_print_json_prefix,f);
@@ -1251,6 +1255,7 @@ bgpq3_print_json_prefixlist(FILE* f, struct bgpq_expander* b)
 int
 bgpq3_print_bird_prefixlist(FILE* f, struct bgpq_expander* b)
 {
+	needscomma = 0;
 	if (!sx_radix_tree_empty(b->tree)) {
 		fprintf(f,"%s = [",
 			b->name?b->name:"NN");

@job job transferred this issue from another repository Jan 18, 2020
@job job closed this as completed Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant