diff options
author | Joshua Colp <jcolp@digium.com> | 2016-01-14 06:32:04 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2016-01-14 06:32:04 -0600 |
commit | 236896f39172e3f97d69f0a8ab2593ac259d745f (patch) | |
tree | 8c94c9b1d0e69689426feff01f8783b33fa8f51d /res/res_pjsip | |
parent | caba57631d87935d984a211df8ef14ecb5e04722 (diff) | |
parent | 22801a06ee26993db9ad26b39b83315de29410cb (diff) |
Merge "pjsip: Add option global/regcontext" into 13
Diffstat (limited to 'res/res_pjsip')
-rw-r--r-- | res/res_pjsip/config_global.c | 22 | ||||
-rw-r--r-- | res/res_pjsip/pjsip_configuration.c | 23 |
2 files changed, 45 insertions, 0 deletions
diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c index ef706f0b3..3d88ffc2a 100644 --- a/res/res_pjsip/config_global.c +++ b/res/res_pjsip/config_global.c @@ -35,6 +35,7 @@ #define DEFAULT_ENDPOINT_IDENTIFIER_ORDER "ip,username,anonymous" #define DEFAULT_MAX_INITIAL_QUALIFY_TIME 0 #define DEFAULT_FROM_USER "asterisk" +#define DEFAULT_REGCONTEXT "" static char default_useragent[256]; @@ -42,6 +43,7 @@ struct global_config { SORCERY_OBJECT(details); AST_DECLARE_STRING_FIELDS( AST_STRING_FIELD(useragent); + AST_STRING_FIELD(regcontext); AST_STRING_FIELD(default_outbound_endpoint); /*! Debug logging yes|no|host */ AST_STRING_FIELD(debug); @@ -137,6 +139,23 @@ char *ast_sip_get_debug(void) return res; } +char *ast_sip_get_regcontext(void) +{ + char *res; + struct global_config *cfg; + + cfg = get_global_cfg(); + if (!cfg) { + return ast_strdup(DEFAULT_REGCONTEXT); + } + + res = ast_strdup(cfg->regcontext); + ao2_ref(cfg, -1); + + return res; +} + + char *ast_sip_get_endpoint_identifier_order(void) { char *res; @@ -310,6 +329,9 @@ int ast_sip_initialize_sorcery_global(void) OPT_UINT_T, 0, FLDSET(struct global_config, max_initial_qualify_time)); ast_sorcery_object_field_register(sorcery, "global", "default_from_user", DEFAULT_FROM_USER, OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, default_from_user)); + ast_sorcery_object_field_register(sorcery, "global", "regcontext", DEFAULT_REGCONTEXT, + OPT_STRINGFIELD_T, 0, STRFLDSET(struct global_config, regcontext)); + if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) { return -1; diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index c7fc195d3..d4473ff63 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -21,6 +21,7 @@ #include "asterisk/callerid.h" #include "asterisk/test.h" #include "asterisk/statsd.h" +#include "asterisk/pbx.h" /*! \brief Number of buckets for persistent endpoint information */ #define PERSISTENT_BUCKETS 53 @@ -68,6 +69,7 @@ static int persistent_endpoint_update_state(void *obj, void *arg, int flags) struct ao2_iterator i; struct ast_sip_contact *contact; enum ast_endpoint_state state = AST_ENDPOINT_OFFLINE; + char *regcontext; if (status) { char rtt[32]; @@ -116,16 +118,37 @@ static int persistent_endpoint_update_state(void *obj, void *arg, int flags) return 0; } + regcontext = ast_sip_get_regcontext(); + if (state == AST_ENDPOINT_ONLINE) { ast_endpoint_set_state(endpoint, AST_ENDPOINT_ONLINE); blob = ast_json_pack("{s: s}", "peer_status", "Reachable"); + + if (!ast_strlen_zero(regcontext)) { + if (!ast_exists_extension(NULL, regcontext, ast_endpoint_get_resource(endpoint), 1, NULL)) { + ast_add_extension(regcontext, 1, ast_endpoint_get_resource(endpoint), 1, NULL, NULL, + "Noop", ast_strdup(ast_endpoint_get_resource(endpoint)), ast_free_ptr, "SIP"); + } + } + ast_verb(1, "Endpoint %s is now Reachable\n", ast_endpoint_get_resource(endpoint)); } else { ast_endpoint_set_state(endpoint, AST_ENDPOINT_OFFLINE); blob = ast_json_pack("{s: s}", "peer_status", "Unreachable"); + + if (!ast_strlen_zero(regcontext)) { + struct pbx_find_info q = { .stacklen = 0 }; + + if (pbx_find_extension(NULL, NULL, &q, regcontext, ast_endpoint_get_resource(endpoint), 1, NULL, "", E_MATCH)) { + ast_context_remove_extension(regcontext, ast_endpoint_get_resource(endpoint), 1, NULL); + } + } + ast_verb(1, "Endpoint %s is now Unreachable\n", ast_endpoint_get_resource(endpoint)); } + ast_free(regcontext); + ast_endpoint_blob_publish(endpoint, ast_endpoint_state_type(), blob); ast_json_unref(blob); ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "PJSIP/%s", ast_endpoint_get_resource(endpoint)); |