summaryrefslogtreecommitdiff
path: root/res/res_pjsip/pjsip_distributor.c
diff options
context:
space:
mode:
authorzuul <zuul@gerrit.asterisk.org>2017-02-21 22:55:13 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2017-02-21 22:55:13 -0600
commit1774f778f66a000734c1b176588a469f0d52ea9c (patch)
treec5edab5081b4ef5b10fe814e3b5898f1d02d68a1 /res/res_pjsip/pjsip_distributor.c
parentac6e0fdcdb32d4532bb9f65f0c051cddf8646895 (diff)
parent6400f5f309a47e66b94c9befecd862ccd2b73aee (diff)
Merge "res_pjsip: Update artificial auth whenever default_realm changes."
Diffstat (limited to 'res/res_pjsip/pjsip_distributor.c')
-rw-r--r--res/res_pjsip/pjsip_distributor.c84
1 files changed, 61 insertions, 23 deletions
diff --git a/res/res_pjsip/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c
index 39d31651e..cca26a83c 100644
--- a/res/res_pjsip/pjsip_distributor.c
+++ b/res/res_pjsip/pjsip_distributor.c
@@ -43,7 +43,6 @@ struct ast_sched_context *prune_context;
/* From the auth/realm realtime column size */
#define MAX_REALM_LENGTH 40
-static char default_realm[MAX_REALM_LENGTH + 1];
#define DEFAULT_SUSPECTS_BUCKETS 53
@@ -455,35 +454,54 @@ static pj_bool_t distributor(pjsip_rx_data *rdata)
return PJ_TRUE;
}
-static struct ast_sip_auth *artificial_auth;
+static struct ast_sip_auth *alloc_artificial_auth(char *default_realm)
+{
+ struct ast_sip_auth *fake_auth;
+
+ fake_auth = ast_sorcery_alloc(ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE,
+ "artificial");
+ if (!fake_auth) {
+ return NULL;
+ }
+
+ ast_string_field_set(fake_auth, realm, default_realm);
+ ast_string_field_set(fake_auth, auth_user, "");
+ ast_string_field_set(fake_auth, auth_pass, "");
+ fake_auth->type = AST_SIP_AUTH_TYPE_ARTIFICIAL;
+
+ return fake_auth;
+}
+
+static AO2_GLOBAL_OBJ_STATIC(artificial_auth);
static int create_artificial_auth(void)
{
- if (!(artificial_auth = ast_sorcery_alloc(
- ast_sip_get_sorcery(), SIP_SORCERY_AUTH_TYPE, "artificial"))) {
+ char default_realm[MAX_REALM_LENGTH + 1];
+ struct ast_sip_auth *fake_auth;
+
+ ast_sip_get_default_realm(default_realm, sizeof(default_realm));
+ fake_auth = alloc_artificial_auth(default_realm);
+ if (!fake_auth) {
ast_log(LOG_ERROR, "Unable to create artificial auth\n");
return -1;
}
- ast_string_field_set(artificial_auth, realm, default_realm);
- ast_string_field_set(artificial_auth, auth_user, "");
- ast_string_field_set(artificial_auth, auth_pass, "");
- artificial_auth->type = AST_SIP_AUTH_TYPE_ARTIFICIAL;
+ ao2_global_obj_replace_unref(artificial_auth, fake_auth);
+ ao2_ref(fake_auth, -1);
return 0;
}
struct ast_sip_auth *ast_sip_get_artificial_auth(void)
{
- ao2_ref(artificial_auth, +1);
- return artificial_auth;
+ return ao2_global_obj_ref(artificial_auth);
}
static struct ast_sip_endpoint *artificial_endpoint = NULL;
static int create_artificial_endpoint(void)
{
- if (!(artificial_endpoint = ast_sorcery_alloc(
- ast_sip_get_sorcery(), "endpoint", NULL))) {
+ artificial_endpoint = ast_sorcery_alloc(ast_sip_get_sorcery(), "endpoint", NULL);
+ if (!artificial_endpoint) {
return -1;
}
@@ -961,20 +979,40 @@ static int clean_task(const void *data)
static void global_loaded(const char *object_type)
{
- char *identifier_order = ast_sip_get_endpoint_identifier_order();
- char *io_copy = identifier_order ? ast_strdupa(identifier_order) : NULL;
- char *identify_method;
-
- ast_free(identifier_order);
- using_auth_username = 0;
- while ((identify_method = ast_strip(strsep(&io_copy, ",")))) {
- if (!strcmp(identify_method, "auth_username")) {
- using_auth_username = 1;
- break;
+ char default_realm[MAX_REALM_LENGTH + 1];
+ struct ast_sip_auth *fake_auth;
+ char *identifier_order;
+
+ /* Update using_auth_username */
+ identifier_order = ast_sip_get_endpoint_identifier_order();
+ if (identifier_order) {
+ char *identify_method;
+ char *io_copy = ast_strdupa(identifier_order);
+ int new_using = 0;
+
+ ast_free(identifier_order);
+ while ((identify_method = ast_strip(strsep(&io_copy, ",")))) {
+ if (!strcmp(identify_method, "auth_username")) {
+ new_using = 1;
+ break;
+ }
}
+ using_auth_username = new_using;
}
+ /* Update default_realm of artificial_auth */
ast_sip_get_default_realm(default_realm, sizeof(default_realm));
+ fake_auth = ast_sip_get_artificial_auth();
+ if (!fake_auth || strcmp(fake_auth->realm, default_realm)) {
+ ao2_cleanup(fake_auth);
+
+ fake_auth = alloc_artificial_auth(default_realm);
+ if (fake_auth) {
+ ao2_global_obj_replace_unref(artificial_auth, fake_auth);
+ ao2_ref(fake_auth, -1);
+ }
+ }
+
ast_sip_get_unidentified_request_thresholds(&unidentified_count, &unidentified_period, &unidentified_prune_interval);
/* Clean out the old task, if any */
@@ -1107,7 +1145,7 @@ void ast_sip_destroy_distributor(void)
internal_sip_unregister_service(&endpoint_mod);
internal_sip_unregister_service(&distributor_mod);
- ao2_cleanup(artificial_auth);
+ ao2_global_obj_release(artificial_auth);
ao2_cleanup(artificial_endpoint);
ast_sorcery_observer_remove(ast_sip_get_sorcery(), "global", &global_observer);