diff options
author | David M. Lee <dlee@digium.com> | 2013-07-03 19:46:50 +0000 |
---|---|---|
committer | David M. Lee <dlee@digium.com> | 2013-07-03 19:46:50 +0000 |
commit | dbc588b02f0da1caffc53faffd0a91b8f3047907 (patch) | |
tree | 61153022395c99939b5c8b9d1c397cc1c1dd30ca /rest-api-templates | |
parent | ef032842f161c7e1a5fe4e2886733926e1c3a61c (diff) |
Fix load errors related to the new ari_model_validators.
The Asterisk strategy of loading modules with RTLD_LAZY to extract metadata
from the module works well enough, until you try to take the address of a
function.
If a module takes the address of a function, that function needs to be
resolved at load time. That kinda defeats RTLD_LAZY.
This patch adds some ari_validator_{id}_fn() wrapper functions for safely
getting the function pointer from a different module.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393576 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'rest-api-templates')
-rw-r--r-- | rest-api-templates/ari_model_validators.c.mustache | 5 | ||||
-rw-r--r-- | rest-api-templates/ari_model_validators.h.mustache | 23 | ||||
-rw-r--r-- | rest-api-templates/res_stasis_http_resource.c.mustache | 4 |
3 files changed, 30 insertions, 2 deletions
diff --git a/rest-api-templates/ari_model_validators.c.mustache b/rest-api-templates/ari_model_validators.c.mustache index 0e87f8e24..04a6d1111 100644 --- a/rest-api-templates/ari_model_validators.c.mustache +++ b/rest-api-templates/ari_model_validators.c.mustache @@ -112,6 +112,11 @@ int ari_validate_{{c_id}}(struct ast_json *json) {{/properties}} return res; } + +ari_validator ari_validate_{{c_id}}_fn(void) +{ + return ari_validate_{{c_id}}; +} {{/models}} {{/api_declaration}} {{/apis}} diff --git a/rest-api-templates/ari_model_validators.h.mustache b/rest-api-templates/ari_model_validators.h.mustache index 65efbbd85..b5b90acdd 100644 --- a/rest-api-templates/ari_model_validators.h.mustache +++ b/rest-api-templates/ari_model_validators.h.mustache @@ -17,6 +17,17 @@ /*! \file * * \brief Generated file - Build validators for ARI model objects. + * + * In addition to the normal validation functions one would normally expect, + * each validator has a ari_validate_{id}_fn() companion function that returns + * the validator's function pointer. + * + * The reason for this seamingly useless indirection is the way function + * pointers interfere with module loading. Asterisk attempts to dlopen() each + * module using \c RTLD_LAZY in order to read some metadata from the module. + * Unfortunately, if you take the address of a function, the function has to be + * resolvable at load time, even if \c RTLD_LAZY is specified. By moving the + * function-address-taking into this module, we can once again be lazy. */ /* @@ -124,6 +135,11 @@ int ari_validate_date(struct ast_json *json); int ari_validate_list(struct ast_json *json, int (*fn)(struct ast_json *)); /*! @} */ + +/*! + * \brief Function type for validator functions. Allows for + */ +typedef int (*ari_validator)(struct ast_json *json); {{#apis}} {{#api_declaration}} {{#models}} @@ -138,6 +154,13 @@ int ari_validate_list(struct ast_json *json, int (*fn)(struct ast_json *)); * \returns False (zero) if invalid. */ int ari_validate_{{c_id}}(struct ast_json *json); + +/*! + * \brief Function pointer to ari_validate_{{c_id}}(). + * + * See \ref ari_model_validators.h for more details. + */ +ari_validator ari_validate_{{c_id}}_fn(void); {{/models}} {{/api_declaration}} {{/apis}} diff --git a/rest-api-templates/res_stasis_http_resource.c.mustache b/rest-api-templates/res_stasis_http_resource.c.mustache index 0f0535bcf..d35873258 100644 --- a/rest-api-templates/res_stasis_http_resource.c.mustache +++ b/rest-api-templates/res_stasis_http_resource.c.mustache @@ -89,7 +89,7 @@ static void stasis_http_{{c_nickname}}_cb( {{#response_class}} {{#is_list}} is_valid = ari_validate_list(response->message, - ari_validate_{{c_singular_name}}); + ari_validate_{{c_singular_name}}_fn()); {{/is_list}} {{^is_list}} is_valid = ari_validate_{{c_name}}( @@ -125,7 +125,7 @@ static void stasis_http_{{c_nickname}}_ws_cb(struct ast_websocket *ws_session, {{> param_parsing}} #if defined(AST_DEVMODE) session = ari_websocket_session_create(ws_session, - ari_validate_{{response_class.c_name}}); + ari_validate_{{response_class.c_name}}_fn()); #else session = ari_websocket_session_create(ws_session, NULL); #endif |