jansson: json_pack with new format to verify required runtime version.
authorCorey Farrell <git@cfware.com>
Thu, 7 Mar 2019 23:17:49 +0000 (18:17 -0500)
committerCorey Farrell <git@cfware.com>
Fri, 8 Mar 2019 18:47:50 +0000 (12:47 -0600)
Add a json_pack at startup that will fail if runtime links against a
library older than jansson-2.11.

Change-Id: I101aebafe0f9407650206f7c552dad3d69377b5a

include/asterisk/json.h
main/asterisk.c
main/json.c

index 0a75e78..665380c 100644 (file)
@@ -89,7 +89,7 @@ typedef AST_JSON_INT_T ast_json_int_t;
 /*!
  * \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().
index 36e956f..6d9a5f5 100644 (file)
@@ -4059,7 +4059,7 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou
        }
        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();
index 9a94767..f72de41 100644 (file)
@@ -693,10 +693,28 @@ struct ast_json *ast_json_ipaddr(const struct ast_sockaddr *addr, enum ast_trans
        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)