[Asterisk-code-review] jansson: json_pack with new format to verify required runtime version. (...asterisk[16])

George Joseph asteriskteam at digium.com
Mon Mar 11 09:49:30 CDT 2019


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/11112 )

Change subject: jansson: json_pack with new format to verify required runtime version.
......................................................................

jansson: json_pack with new format to verify required runtime version.

Add a json_pack at startup that will fail if runtime links against a
library older than jansson-2.11.

Change-Id: I101aebafe0f9407650206f7c552dad3d69377b5a
---
M include/asterisk/json.h
M main/asterisk.c
M main/json.c
3 files changed, 21 insertions(+), 3 deletions(-)

Approvals:
  Sean Bright: Looks good to me, but someone else must approve
  Joshua C. Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/include/asterisk/json.h b/include/asterisk/json.h
index 0a75e78..665380c 100644
--- a/include/asterisk/json.h
+++ b/include/asterisk/json.h
@@ -89,7 +89,7 @@
 /*!
  * \brief Initialize the JSON library.
  */
-void ast_json_init(void);
+int ast_json_init(void);
 
 /*!
  * \brief Set custom allocators instead of the standard ast_malloc() and ast_free().
diff --git a/main/asterisk.c b/main/asterisk.c
index 763983c..554b149 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -4056,7 +4056,7 @@
 	}
 	ast_verb(0, "PBX UUID: %s\n", pbx_uuid);
 
-	ast_json_init();
+	check_init(ast_json_init(), "libjansson");
 	ast_ulaw_init();
 	ast_alaw_init();
 	tdd_init();
diff --git a/main/json.c b/main/json.c
index 9a94767..f72de41 100644
--- a/main/json.c
+++ b/main/json.c
@@ -693,10 +693,28 @@
 	return ast_json_string_create(ast_str_buffer(string));
 }
 
-void ast_json_init(void)
+int ast_json_init(void)
 {
+	json_t *version_check;
+
 	/* Setup to use Asterisk custom allocators */
 	ast_json_reset_alloc_funcs();
+
+	/* We depend on functionality of jansson-2.11 but don't actually use
+	 * any symbols.  If we link at runtime to less than 2.11 this json_pack
+	 * will return NULL. */
+	version_check = json_pack("{s: o?, s: o*}",
+		"JSON", NULL,
+		"Bourne", NULL);
+	if (!version_check) {
+		ast_log(LOG_ERROR, "There was a problem finding jansson 2.11 runtime libraries.\n"
+			"Please rebuild Asterisk using ./configure --with-jansson-bundled.\n");
+		return -1;
+	}
+
+	json_decref(version_check);
+
+	return 0;
 }
 
 static void json_payload_destructor(void *obj)

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11112
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I101aebafe0f9407650206f7c552dad3d69377b5a
Gerrit-Change-Number: 11112
Gerrit-PatchSet: 3
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua C. Colp <jcolp at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190311/11f9bea1/attachment-0001.html>


More information about the asterisk-code-review mailing list