[Asterisk-code-review] res pjsip exten state: Use the extension for publishing to. (asterisk[master])
Joshua Colp
asteriskteam at digium.com
Wed May 11 13:32:57 CDT 2016
Joshua Colp has uploaded a new change for review.
https://gerrit.asterisk.org/2808
Change subject: res_pjsip_exten_state: Use the extension for publishing to.
......................................................................
res_pjsip_exten_state: Use the extension for publishing to.
This change uses the newly added multi-user support for
outbound publish to publish to the specific user that an
extension state change is for.
This also extends extends the res_pjsip_outbound_publish support
to include the user specific From and To URI information in
the outbound publishing of extension state. Since the URI
is used when constructing the body it is important to ensure
that the correct local and remote URIs are used.
ASTERISK-25965
Change-Id: I668fdf697b1e171d4c7e6f282b2e1590f8356ca1
---
M include/asterisk/res_pjsip_outbound_publish.h
M res/res_pjsip_exten_state.c
M res/res_pjsip_outbound_publish.c
3 files changed, 98 insertions(+), 5 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/08/2808/1
diff --git a/include/asterisk/res_pjsip_outbound_publish.h b/include/asterisk/res_pjsip_outbound_publish.h
index 2831afb..a578b5a 100644
--- a/include/asterisk/res_pjsip_outbound_publish.h
+++ b/include/asterisk/res_pjsip_outbound_publish.h
@@ -104,6 +104,21 @@
const char *ast_sip_publish_client_get_from_uri(struct ast_sip_outbound_publish_client *client);
/*!
+ * \brief Get the From URI the client will use for a specific user.
+ * \since 14.0.0
+ *
+ * \param client The publication client to get the From URI of a user
+ * \param user The user to retrieve the From URI for
+ * \param uri A buffer to place the URI into
+ * \param size The size of the buffer
+ *
+ * \retval From-uri on success
+ * \retval Empty-string on failure
+ */
+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);
+
+/*!
* \brief Get the To URI the client will use.
* \since 14.0.0
*
@@ -115,6 +130,21 @@
const char *ast_sip_publish_client_get_to_uri(struct ast_sip_outbound_publish_client *client);
/*!
+ * \brief Get the To URI the client will use for a specific user.
+ * \since 14.0.0
+ *
+ * \param client The publication client to get the To URI of a user
+ * \param user The user to retrieve the To URI for
+ * \param uri A buffer to place the URI into
+ * \param size The size of the buffer
+ *
+ * \retval To-uri on success
+ * \retval Empty-string on failure
+ */
+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);
+
+/*!
* \brief Alternative for ast_datastore_alloc()
*
* There are two major differences between this and ast_datastore_alloc()
diff --git a/res/res_pjsip_exten_state.c b/res/res_pjsip_exten_state.c
index 22fb69c..25b9bf1 100644
--- a/res/res_pjsip_exten_state.c
+++ b/res/res_pjsip_exten_state.c
@@ -647,21 +647,21 @@
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 @@
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 f37ce23..4dfc0ea 100644
--- a/res/res_pjsip_outbound_publish.c
+++ b/res/res_pjsip_outbound_publish.c
@@ -190,6 +190,10 @@
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,11 +529,52 @@
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);
+
+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 = ao2_find(client->publishers, user, OBJ_SEARCH_KEY);
+ if (!publisher) {
+ SCOPED_WRLOCK(lock, &load_lock);
+ if (!(publisher = sip_outbound_publish_client_add_publisher(client, user))) {
+ 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;
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 = ao2_find(client->publishers, user, OBJ_SEARCH_KEY);
+ if (!publisher) {
+ SCOPED_WRLOCK(lock, &load_lock);
+ if (!(publisher = sip_outbound_publish_client_add_publisher(client, user))) {
+ 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)
@@ -897,6 +942,21 @@
return -1;
}
+ /* The sip_outbound_publisher_set_uris ensures the From and To are NULL terminated */
+ publisher->from_uri = ast_strdup(from_uri.ptr);
+ if (!publisher->from_uri) {
+ pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+ pjsip_publishc_destroy(publisher->client);
+ return -1;
+ }
+
+ publisher->to_uri = ast_strdup(to_uri.ptr);
+ if (!publisher->to_uri) {
+ pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+ pjsip_publishc_destroy(publisher->client);
+ return -1;
+ }
+
pj_cstr(&event, publish->event);
if (pjsip_publishc_init(publisher->client, &event, &server_uri, &from_uri, &to_uri,
publish->expiration != PJ_SUCCESS)) {
@@ -936,6 +996,9 @@
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) {
--
To view, visit https://gerrit.asterisk.org/2808
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I668fdf697b1e171d4c7e6f282b2e1590f8356ca1
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>
More information about the asterisk-code-review
mailing list