diff options
Diffstat (limited to 'res')
-rw-r--r-- | res/res_pjsip_dialog_info_body_generator.c | 2 | ||||
-rw-r--r-- | res/res_pjsip_exten_state.c | 10 | ||||
-rw-r--r-- | res/res_pjsip_outbound_publish.c | 91 |
3 files changed, 84 insertions, 19 deletions
diff --git a/res/res_pjsip_dialog_info_body_generator.c b/res/res_pjsip_dialog_info_body_generator.c index d21af2ae6..5006b9efb 100644 --- a/res/res_pjsip_dialog_info_body_generator.c +++ b/res/res_pjsip_dialog_info_body_generator.c @@ -157,7 +157,7 @@ static int dialog_info_generate_body_content(void *body, void *data) /* The maximum number of times the ast_str() for the body text can grow before we declare an XML body * too large to send. */ -#define MAX_STRING_GROWTHS 3 +#define MAX_STRING_GROWTHS 6 static void dialog_info_to_string(void *body, struct ast_str **str) { diff --git a/res/res_pjsip_exten_state.c b/res/res_pjsip_exten_state.c index 22fb69c29..25b9bf1fe 100644 --- a/res/res_pjsip_exten_state.c +++ b/res/res_pjsip_exten_state.c @@ -647,21 +647,21 @@ static int exten_state_publisher_cb(void *data) publisher = AST_VECTOR_GET(&pub_data->pubs, idx); - uri = ast_sip_publish_client_get_from_uri(publisher->client); + uri = ast_sip_publish_client_get_user_from_uri(publisher->client, pub_data->exten_state_data.exten, + pub_data->exten_state_data.local, sizeof(pub_data->exten_state_data.local)); if (ast_strlen_zero(uri)) { ast_log(LOG_WARNING, "PUBLISH client '%s' has no from_uri or server_uri defined.\n", publisher->name); continue; } - ast_copy_string(pub_data->exten_state_data.local, uri, sizeof(pub_data->exten_state_data.local)); - uri = ast_sip_publish_client_get_to_uri(publisher->client); + uri = ast_sip_publish_client_get_user_to_uri(publisher->client, pub_data->exten_state_data.exten, + pub_data->exten_state_data.remote, sizeof(pub_data->exten_state_data.remote)); if (ast_strlen_zero(uri)) { ast_log(LOG_WARNING, "PUBLISH client '%s' has no to_uri or server_uri defined.\n", publisher->name); continue; } - ast_copy_string(pub_data->exten_state_data.remote, uri, sizeof(pub_data->exten_state_data.remote)); pub_data->exten_state_data.datastores = publisher->datastores; @@ -678,7 +678,7 @@ static int exten_state_publisher_cb(void *data) body.type = publisher->body_type; body.subtype = publisher->body_subtype; body.body_text = ast_str_buffer(body_text); - ast_sip_publish_client_send(publisher->client, &body); + ast_sip_publish_client_user_send(publisher->client, pub_data->exten_state_data.exten, &body); } pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool); diff --git a/res/res_pjsip_outbound_publish.c b/res/res_pjsip_outbound_publish.c index f37ce2305..1c3b0c644 100644 --- a/res/res_pjsip_outbound_publish.c +++ b/res/res_pjsip_outbound_publish.c @@ -190,6 +190,10 @@ struct sip_outbound_publisher { struct ast_sip_outbound_publish_client *owner; /*! \brief Underlying publish client */ pjsip_publishc *client; + /*! \brief The From URI for this specific publisher */ + char *from_uri; + /*! \brief The To URI for this specific publisher */ + char *to_uri; /*! \brief Timer entry for refreshing publish */ pj_timer_entry timer; /*! \brief The number of auth attempts done */ @@ -525,6 +529,49 @@ const char *ast_sip_publish_client_get_from_uri(struct ast_sip_outbound_publish_ return S_OR(publish->from_uri, S_OR(publish->server_uri, "")); } +static struct sip_outbound_publisher *sip_outbound_publish_client_add_publisher( + struct ast_sip_outbound_publish_client *client, const char *user); + +static struct sip_outbound_publisher *sip_outbound_publish_client_get_publisher( + struct ast_sip_outbound_publish_client *client, const char *user) +{ + struct sip_outbound_publisher *publisher; + + /* + * Lock before searching since there could be a race between searching and adding. + * Just use the load_lock since we might need to lock it anyway (if adding) and + * also it simplifies the code (otherwise we'd have to lock the publishers, no- + * lock the search and pass a flag to 'add publisher to no-lock the potential link). + */ + ast_rwlock_wrlock(&load_lock); + publisher = ao2_find(client->publishers, user, OBJ_SEARCH_KEY); + if (!publisher) { + if (!(publisher = sip_outbound_publish_client_add_publisher(client, user))) { + ast_rwlock_unlock(&load_lock); + return NULL; + } + } + ast_rwlock_unlock(&load_lock); + + return publisher; +} + +const char *ast_sip_publish_client_get_user_from_uri(struct ast_sip_outbound_publish_client *client, const char *user, + char *uri, size_t size) +{ + struct sip_outbound_publisher *publisher; + + publisher = sip_outbound_publish_client_get_publisher(client, user); + if (!publisher) { + return NULL; + } + + ast_copy_string(uri, publisher->from_uri, size); + ao2_ref(publisher, -1); + + return uri; +} + const char *ast_sip_publish_client_get_to_uri(struct ast_sip_outbound_publish_client *client) { struct ast_sip_outbound_publish *publish = client->publish; @@ -532,6 +579,22 @@ const char *ast_sip_publish_client_get_to_uri(struct ast_sip_outbound_publish_cl return S_OR(publish->to_uri, S_OR(publish->server_uri, "")); } +const char *ast_sip_publish_client_get_user_to_uri(struct ast_sip_outbound_publish_client *client, const char *user, + char *uri, size_t size) +{ + struct sip_outbound_publisher *publisher; + + publisher = sip_outbound_publish_client_get_publisher(client, user); + if (!publisher) { + return NULL; + } + + ast_copy_string(uri, publisher->to_uri, size); + ao2_ref(publisher, -1); + + return uri; +} + int ast_sip_register_event_publisher_handler(struct ast_sip_event_publisher_handler *handler) { struct ast_sip_event_publisher_handler *existing; @@ -828,6 +891,11 @@ static int sip_outbound_publisher_set_uris( return -1; } + publisher->to_uri = ast_strdup(to_uri->ptr); + if (!publisher->to_uri) { + return -1; + } + if (ast_strlen_zero(publish->from_uri)) { from_uri->ptr = server_uri->ptr; from_uri->slen = server_uri->slen; @@ -837,6 +905,11 @@ static int sip_outbound_publisher_set_uris( return -1; } + publisher->from_uri = ast_strdup(from_uri->ptr); + if (!publisher->from_uri) { + return -1; + } + return 0; } @@ -936,6 +1009,9 @@ static void sip_outbound_publisher_destroy(void *obj) ao2_cleanup(publisher->owner); + ast_free(publisher->from_uri); + ast_free(publisher->to_uri); + /* if unloading the module and all objects have been unpublished send the signal to finish unloading */ if (unloading.is_unloading) { @@ -1018,21 +1094,10 @@ int ast_sip_publish_client_user_send(struct ast_sip_outbound_publish_client *cli struct sip_outbound_publisher *publisher; int res; - /* - * Lock before searching since there could be a race between searching and adding. - * Just use the load_lock since we might need to lock it anyway (if adding) and - * also it simplifies the code (otherwise we'd have to lock the publishers, no- - * lock the search and pass a flag to 'add publisher to no-lock the potential link). - */ - ast_rwlock_wrlock(&load_lock); - publisher = ao2_find(client->publishers, user, OBJ_SEARCH_KEY); + publisher = sip_outbound_publish_client_get_publisher(client, user); if (!publisher) { - if (!(publisher = sip_outbound_publish_client_add_publisher(client, user))) { - ast_rwlock_unlock(&load_lock); - return -1; - } + return -1; } - ast_rwlock_unlock(&load_lock); publisher_client_send(publisher, (void *)body, &res, 0); ao2_ref(publisher, -1); |