summaryrefslogtreecommitdiff
path: root/res
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2014-07-22 16:20:58 +0000
committerMatthew Jordan <mjordan@digium.com>2014-07-22 16:20:58 +0000
commitbb87796f67f8cef493a89e8b685e895142bfdce4 (patch)
tree533e63d1aa65281d3b13363790f88b1fc32a2574 /res
parent84beaf27bc2605fa93d78ab2285aa945dbd08db0 (diff)
ARI: Fix endpoint/channel subscription issues; allow for subscriptions to tech
This patch serves two purposes: (1) It fixes some bugs with endpoint subscriptions not reporting all of the channel events (2) It serves as the preliminary work needed for ASTERISK-23692, which allows for sending/receiving arbitrary out of call text messages through ARI in a technology agnostic fashion. The messaging functionality described on ASTERISK-23692 requires two things: (1) The ability to send/receive messages associated with an endpoint. This is relatively straight forwards with the endpoint core in Asterisk now. (2) The ability to send/receive messages associated with a technology and an arbitrary technology defined URI. This is less straight forward, as endpoints are formed from a tech + resource pair. We don't have a mechanism to note that a technology that *may* have endpoints exists. This patch provides such a mechanism, and fixes a few bugs along the way. The first major bug this patch fixes is the forwarding of channel messages to their respective endpoints. Prior to this patch, there were two problems: (1) Channel caching messages weren't forwarded. Thus, the endpoints missed most of the interesting bits (such as channel creation, destruction, state changes, etc.) (2) Channels weren't associated with their endpoint until after creation. This resulted in endpoints missing the channel creation message, which limited the usefulness of the subscription in the first place (a major use case being 'tell me when this endpoint has a channel'). Unfortunately, this meant another parameter to ast_channel_alloc. Since not all channel technologies support an ast_endpoint, this patch makes such a call optional and opts for a new function, ast_channel_alloc_with_endpoint. When endpoints are created, they will implicitly create a technology endpoint for their technology (if one does not already exist). A technology endpoint is special in that it has no state, cannot have channels created for it, cannot be created explicitly, and cannot be destroyed except on shutdown. It does, however, have all messages from other endpoints in its technology forwarded to it. Combined with the bug fixes, we now have Stasis messages being properly forwarded. Consider the following scenario: two PJSIP endpoints (foo and bar), where bar has a single channel associated with it and foo has two channels associated with it. The messages would be forwarded as follows: channel PJSIP/foo-1 -- \ --> endpoint PJSIP/foo -- / \ channel PJSIP/foo-2 -- \ ---- > endpoint PJSIP / channel PJSIP/bar-1 -----> endpoint PJSIP/bar -- ARI, through the applications resource, can: - subscribe to endpoint:PJSIP/foo and get notifications for channels PJSIP/foo-1,PJSIP/foo-2 and endpoint PJSIP/foo - subscribe to endpoint:PJSIP/bar and get notifications for channels PJSIP/bar-1 and endpoint PJSIP/bar - subscribe to endpoint:PJSIP and get notifications for channels PJSIP/foo-1,PJSIP/foo-2,PJSIP/bar-1 and endpoints PJSIP/foo,PJSIP/bar Note that since endpoint PJSIP never changes, it never has events itself. It merely provides an aggregation point for all other endpoints in its technology (which in turn aggregate all channel messages associated with that endpoint). This patch also adds endpoints to res_xmpp and chan_motif, because the actual messaging work will need it (messaging without XMPP is just sad). Review: https://reviewboard.asterisk.org/r/3760/ ASTERISK-23692 ........ Merged revisions 419196 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419203 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res')
-rw-r--r--res/ari/resource_applications.h4
-rw-r--r--res/ari/resource_endpoints.c8
-rw-r--r--res/res_xmpp.c38
3 files changed, 37 insertions, 13 deletions
diff --git a/res/ari/resource_applications.h b/res/ari/resource_applications.h
index 888f513de..be62e9d5f 100644
--- a/res/ari/resource_applications.h
+++ b/res/ari/resource_applications.h
@@ -67,7 +67,7 @@ void ast_ari_applications_get(struct ast_variable *headers, struct ast_ari_appli
struct ast_ari_applications_subscribe_args {
/*! Application's name */
const char *application_name;
- /*! Array of URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}/{resource}, deviceState:{deviceName} */
+ /*! Array of URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName} */
const char **event_source;
/*! Length of event_source array. */
size_t event_source_count;
@@ -99,7 +99,7 @@ void ast_ari_applications_subscribe(struct ast_variable *headers, struct ast_ari
struct ast_ari_applications_unsubscribe_args {
/*! Application's name */
const char *application_name;
- /*! Array of URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}/{resource}, deviceState:{deviceName} */
+ /*! Array of URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName} */
const char **event_source;
/*! Length of event_source array. */
size_t event_source_count;
diff --git a/res/ari/resource_endpoints.c b/res/ari/resource_endpoints.c
index 16b7ebd8d..ff2b150dd 100644
--- a/res/ari/resource_endpoints.c
+++ b/res/ari/resource_endpoints.c
@@ -34,6 +34,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/stasis_app.h"
#include "asterisk/stasis_endpoints.h"
#include "asterisk/channel.h"
+#include "asterisk/message.h"
void ast_ari_endpoints_list(struct ast_variable *headers,
struct ast_ari_endpoints_list_args *args,
@@ -82,6 +83,7 @@ void ast_ari_endpoints_list(struct ast_variable *headers,
ast_ari_response_ok(response, ast_json_ref(json));
}
+
void ast_ari_endpoints_list_by_tech(struct ast_variable *headers,
struct ast_ari_endpoints_list_by_tech_args *args,
struct ast_ari_response *response)
@@ -89,14 +91,17 @@ void ast_ari_endpoints_list_by_tech(struct ast_variable *headers,
RAII_VAR(struct stasis_cache *, cache, NULL, ao2_cleanup);
RAII_VAR(struct ao2_container *, snapshots, NULL, ao2_cleanup);
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+ struct ast_endpoint *tech_endpoint;
struct ao2_iterator i;
void *obj;
- if (!ast_get_channel_tech(args->tech)) {
+ tech_endpoint = ast_endpoint_find_by_id(args->tech);
+ if (!tech_endpoint) {
ast_ari_response_error(response, 404, "Not Found",
"No Endpoints found - invalid tech %s", args->tech);
return;
}
+ ao2_ref(tech_endpoint, -1);
cache = ast_endpoint_cache();
if (!cache) {
@@ -146,6 +151,7 @@ void ast_ari_endpoints_list_by_tech(struct ast_variable *headers,
ao2_iterator_destroy(&i);
ast_ari_response_ok(response, ast_json_ref(json));
}
+
void ast_ari_endpoints_get(struct ast_variable *headers,
struct ast_ari_endpoints_get_args *args,
struct ast_ari_response *response)
diff --git a/res/res_xmpp.c b/res/res_xmpp.c
index 0cfc37b4c..758a5f09a 100644
--- a/res/res_xmpp.c
+++ b/res/res_xmpp.c
@@ -559,6 +559,10 @@ static void xmpp_client_destructor(void *obj)
ast_xmpp_client_disconnect(client);
+ ast_endpoint_shutdown(client->endpoint);
+ ao2_cleanup(client->endpoint);
+ client->endpoint = NULL;
+
if (client->filter) {
iks_filter_delete(client->filter);
}
@@ -593,6 +597,20 @@ static int xmpp_buddy_cmp(void *obj, void *arg, int flags)
return !strcmp(buddy1->id, flags & OBJ_KEY ? id : buddy2->id) ? CMP_MATCH | CMP_STOP : 0;
}
+/*! \brief Internal function which changes the XMPP client state */
+static void xmpp_client_change_state(struct ast_xmpp_client *client, int state)
+{
+ if (state == client->state) {
+ return;
+ }
+ client->state = state;
+ if (client->state == XMPP_STATE_DISCONNECTED) {
+ ast_endpoint_set_state(client->endpoint, AST_ENDPOINT_OFFLINE);
+ } else if (client->state == XMPP_STATE_CONNECTED) {
+ ast_endpoint_set_state(client->endpoint, AST_ENDPOINT_ONLINE);
+ }
+}
+
/*! \brief Allocator function for ast_xmpp_client */
static struct ast_xmpp_client *xmpp_client_alloc(const char *name)
{
@@ -605,6 +623,12 @@ static struct ast_xmpp_client *xmpp_client_alloc(const char *name)
AST_LIST_HEAD_INIT(&client->messages);
client->thread = AST_PTHREADT_NULL;
+ client->endpoint = ast_endpoint_create("XMPP", name);
+ if (!client->endpoint) {
+ ao2_ref(client, -1);
+ return NULL;
+ }
+
if (!(client->buddies = ao2_container_alloc(BUDDY_BUCKETS, xmpp_buddy_hash, xmpp_buddy_cmp))) {
ast_log(LOG_ERROR, "Could not initialize buddy container for '%s'\n", name);
ao2_ref(client, -1);
@@ -626,7 +650,7 @@ static struct ast_xmpp_client *xmpp_client_alloc(const char *name)
ast_string_field_set(client, name, name);
client->timeout = 50;
- client->state = XMPP_STATE_DISCONNECTED;
+ xmpp_client_change_state(client, XMPP_STATE_DISCONNECTED);
ast_copy_string(client->mid, "aaaaa", sizeof(client->mid));
return client;
@@ -2213,12 +2237,6 @@ static const struct ast_msg_tech msg_tech = {
.msg_send = xmpp_send_cb,
};
-/*! \brief Internal function which changes the XMPP client state */
-static void xmpp_client_change_state(struct ast_xmpp_client *client, int state)
-{
- client->state = state;
-}
-
/*! \brief Internal function which creates a buddy on a client */
static struct ast_xmpp_buddy *xmpp_client_create_buddy(struct ao2_container *container, const char *id)
{
@@ -3530,7 +3548,7 @@ static int xmpp_action_hook(void *data, int type, iks *node)
int ast_xmpp_client_disconnect(struct ast_xmpp_client *client)
{
if ((client->thread != AST_PTHREADT_NULL) && !pthread_equal(pthread_self(), client->thread)) {
- client->state = XMPP_STATE_DISCONNECTING;
+ xmpp_client_change_state(client, XMPP_STATE_DISCONNECTING);
pthread_join(client->thread, NULL);
client->thread = AST_PTHREADT_NULL;
}
@@ -3559,7 +3577,7 @@ int ast_xmpp_client_disconnect(struct ast_xmpp_client *client)
iks_disconnect(client->parser);
}
- client->state = XMPP_STATE_DISCONNECTED;
+ xmpp_client_change_state(client, XMPP_STATE_DISCONNECTED);
return 0;
}
@@ -3774,7 +3792,7 @@ static void *xmpp_client_thread(void *data)
ast_log(LOG_WARNING, "JABBER: Not Supported\n");
} else if (res == IKS_NET_DROPPED) {
ast_log(LOG_WARNING, "JABBER: Dropped?\n");
- } else {
+ } else if (res == IKS_NET_UNKNOWN) {
ast_debug(5, "JABBER: Unknown\n");
}