2013-04-08 14:26:37 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Matt Jordan <mjordan@digium.com>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
*
|
|
|
|
* \brief Stasis Messages and Data Types for Channel Objects
|
|
|
|
*
|
|
|
|
* \author \verbatim Matt Jordan <mjordan@digium.com> \endverbatim
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
#include "asterisk/astobj2.h"
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
#include "asterisk/json.h"
|
2013-06-13 13:15:56 +00:00
|
|
|
#include "asterisk/pbx.h"
|
2013-07-25 04:06:32 +00:00
|
|
|
#include "asterisk/bridge.h"
|
2013-07-08 19:19:55 +00:00
|
|
|
#include "asterisk/translate.h"
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
#include "asterisk/stasis.h"
|
2013-08-01 13:49:34 +00:00
|
|
|
#include "asterisk/stasis_cache_pattern.h"
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
#include "asterisk/stasis_channels.h"
|
2014-09-19 15:54:20 +00:00
|
|
|
#include "asterisk/dial.h"
|
|
|
|
#include "asterisk/linkedlists.h"
|
2013-04-08 14:26:37 +00:00
|
|
|
|
2013-06-11 15:46:35 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<managerEvent language="en_US" name="VarSet">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_DIALPLAN">
|
|
|
|
<synopsis>Raised when a variable is set to a particular value.</synopsis>
|
|
|
|
<syntax>
|
2013-08-01 17:07:52 +00:00
|
|
|
<channel_snapshot/>
|
2013-06-11 15:46:35 +00:00
|
|
|
<parameter name="Variable">
|
|
|
|
<para>The variable being set.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="Value">
|
|
|
|
<para>The new value of the variable.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
Replace chan_agent with app_agent_pool.
The ill conceived chan_agent is no more. It is now replaced by
app_agent_pool.
Agents login using the AgentLogin() application as before. The
AgentLogin() application no longer does any authentication.
Authentication is now the responsibility of the dialplan. (Besides, the
authentication done by chan_agent did not match what the voice prompts
asked for.)
Sample extensions.conf
[login]
; Sample agent 1001 login
; Set COLP for in between calls so the agent does not see the last caller COLP.
exten => 1001,1,Set(CONNECTEDLINE(all)="Agent Waiting" <1001>)
; Give the agent DTMF transfer and disconnect features when connected to a caller.
same => n,Set(CHANNEL(dtmf-features)=TX)
same => n,AgentLogin(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
[caller]
; Sample caller direct connect to agent 1001
exten => 800,1,AgentRequest(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
; Sample caller going through a Queue to agent 1001
exten => 900,1,Queue(agent_q)
same => n,Hangup()
Sample queues.conf
[agent_q]
member => Local/800@caller,,SuperAgent,Agent:1001
Under the hood operation overview:
1) Logged in agents wait for callers in an agents holding bridge.
2) Caller requests an agent using AgentRequest()
3) A basic bridge is created, the agent is notified, and caller joins the
basic bridge to wait for the agent.
4) The agent is either automatically connected to the caller or must ack
the call to connect.
5) The agent is moved from the agents holding bridge to the basic bridge.
6) The agent and caller talk.
7) The connection is ended by either party.
8) The agent goes back to the agents holding bridge.
To avoid some locking issues with the agent holding bridge, I needed to
make some changes to the after bridge callback support. The after bridge
callback is now a list of requested callbacks with the last to be added
the only active callback. The after bridge callback for failed callbacks
will always happen in the channel thread when the channel leaves the
bridging system or is destroyed.
(closes issue ASTERISK-21554)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2657/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394417 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-15 23:20:55 +00:00
|
|
|
<managerEvent language="en_US" name="AgentLogin">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_AGENT">
|
|
|
|
<synopsis>Raised when an Agent has logged in.</synopsis>
|
|
|
|
<syntax>
|
2013-08-01 17:07:52 +00:00
|
|
|
<channel_snapshot/>
|
Replace chan_agent with app_agent_pool.
The ill conceived chan_agent is no more. It is now replaced by
app_agent_pool.
Agents login using the AgentLogin() application as before. The
AgentLogin() application no longer does any authentication.
Authentication is now the responsibility of the dialplan. (Besides, the
authentication done by chan_agent did not match what the voice prompts
asked for.)
Sample extensions.conf
[login]
; Sample agent 1001 login
; Set COLP for in between calls so the agent does not see the last caller COLP.
exten => 1001,1,Set(CONNECTEDLINE(all)="Agent Waiting" <1001>)
; Give the agent DTMF transfer and disconnect features when connected to a caller.
same => n,Set(CHANNEL(dtmf-features)=TX)
same => n,AgentLogin(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
[caller]
; Sample caller direct connect to agent 1001
exten => 800,1,AgentRequest(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
; Sample caller going through a Queue to agent 1001
exten => 900,1,Queue(agent_q)
same => n,Hangup()
Sample queues.conf
[agent_q]
member => Local/800@caller,,SuperAgent,Agent:1001
Under the hood operation overview:
1) Logged in agents wait for callers in an agents holding bridge.
2) Caller requests an agent using AgentRequest()
3) A basic bridge is created, the agent is notified, and caller joins the
basic bridge to wait for the agent.
4) The agent is either automatically connected to the caller or must ack
the call to connect.
5) The agent is moved from the agents holding bridge to the basic bridge.
6) The agent and caller talk.
7) The connection is ended by either party.
8) The agent goes back to the agents holding bridge.
To avoid some locking issues with the agent holding bridge, I needed to
make some changes to the after bridge callback support. The after bridge
callback is now a list of requested callbacks with the last to be added
the only active callback. The after bridge callback for failed callbacks
will always happen in the channel thread when the channel leaves the
bridging system or is destroyed.
(closes issue ASTERISK-21554)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2657/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394417 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-15 23:20:55 +00:00
|
|
|
<parameter name="Agent">
|
|
|
|
<para>Agent ID of the agent.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<see-also>
|
|
|
|
<ref type="application">AgentLogin</ref>
|
|
|
|
<ref type="managerEvent">AgentLogoff</ref>
|
|
|
|
</see-also>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
|
|
|
<managerEvent language="en_US" name="AgentLogoff">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_AGENT">
|
|
|
|
<synopsis>Raised when an Agent has logged off.</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<xi:include xpointer="xpointer(/docs/managerEvent[@name='AgentLogin']/managerEventInstance/syntax/parameter)" />
|
|
|
|
<parameter name="Logintime">
|
|
|
|
<para>The number of seconds the agent was logged in.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<see-also>
|
|
|
|
<ref type="managerEvent">AgentLogin</ref>
|
|
|
|
</see-also>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
2014-05-30 12:42:57 +00:00
|
|
|
<managerEvent language="en_US" name="ChannelTalkingStart">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_CLASS">
|
|
|
|
<synopsis>Raised when talking is detected on a channel.</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<channel_snapshot/>
|
|
|
|
</syntax>
|
|
|
|
<see-also>
|
|
|
|
<ref type="function">TALK_DETECT</ref>
|
|
|
|
<ref type="managerEvent">ChannelTalkingStop</ref>
|
|
|
|
</see-also>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
|
|
|
<managerEvent language="en_US" name="ChannelTalkingStop">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_CLASS">
|
|
|
|
<synopsis>Raised when talking is no longer detected on a channel.</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<channel_snapshot/>
|
|
|
|
<parameter name="Duration">
|
|
|
|
<para>The length in time, in milliseconds, that talking was
|
|
|
|
detected on the channel.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<see-also>
|
|
|
|
<ref type="function">TALK_DETECT</ref>
|
|
|
|
<ref type="managerEvent">ChannelTalkingStart</ref>
|
|
|
|
</see-also>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
2013-06-11 15:46:35 +00:00
|
|
|
***/
|
2013-04-08 14:26:37 +00:00
|
|
|
|
2013-06-11 15:46:35 +00:00
|
|
|
#define NUM_MULTI_CHANNEL_BLOB_BUCKETS 7
|
2013-04-08 14:26:37 +00:00
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
static struct stasis_cp_all *channel_cache_all;
|
|
|
|
static struct stasis_cache *channel_cache_by_name;
|
|
|
|
static struct stasis_caching_topic *channel_by_name_topic;
|
2013-04-08 14:26:37 +00:00
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
struct stasis_cp_all *ast_channel_cache_all(void)
|
|
|
|
{
|
|
|
|
return channel_cache_all;
|
|
|
|
}
|
2013-04-08 14:26:37 +00:00
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
struct stasis_cache *ast_channel_cache(void)
|
|
|
|
{
|
|
|
|
return stasis_cp_all_cache(channel_cache_all);
|
|
|
|
}
|
2013-05-31 12:27:29 +00:00
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
struct stasis_topic *ast_channel_topic_all(void)
|
|
|
|
{
|
2013-08-01 13:49:34 +00:00
|
|
|
return stasis_cp_all_topic(channel_cache_all);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stasis_topic *ast_channel_topic_all_cached(void)
|
|
|
|
{
|
|
|
|
return stasis_cp_all_topic_cached(channel_cache_all);
|
2013-04-08 14:26:37 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
struct stasis_cache *ast_channel_cache_by_name(void)
|
2013-04-08 14:26:37 +00:00
|
|
|
{
|
2013-08-01 13:49:34 +00:00
|
|
|
return channel_cache_by_name;
|
2013-04-08 14:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char *channel_snapshot_get_id(struct stasis_message *message)
|
|
|
|
{
|
|
|
|
struct ast_channel_snapshot *snapshot;
|
|
|
|
if (ast_channel_snapshot_type() != stasis_message_type(message)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
snapshot = stasis_message_data(message);
|
|
|
|
return snapshot->uniqueid;
|
|
|
|
}
|
|
|
|
|
2013-05-31 12:27:29 +00:00
|
|
|
static const char *channel_snapshot_get_name(struct stasis_message *message)
|
|
|
|
{
|
|
|
|
struct ast_channel_snapshot *snapshot;
|
|
|
|
if (ast_channel_snapshot_type() != stasis_message_type(message)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
snapshot = stasis_message_data(message);
|
|
|
|
return snapshot->name;
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:33:21 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Hash function for \ref ast_channel_snapshot objects
|
|
|
|
*/
|
2013-04-08 14:26:37 +00:00
|
|
|
static int channel_snapshot_hash_cb(const void *obj, const int flags)
|
|
|
|
{
|
|
|
|
const struct ast_channel_snapshot *snapshot = obj;
|
|
|
|
const char *name = (flags & OBJ_KEY) ? obj : snapshot->name;
|
|
|
|
return ast_str_case_hash(name);
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:33:21 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Comparison function for \ref ast_channel_snapshot objects
|
|
|
|
*/
|
2013-04-08 14:26:37 +00:00
|
|
|
static int channel_snapshot_cmp_cb(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct ast_channel_snapshot *left = obj;
|
|
|
|
struct ast_channel_snapshot *right = arg;
|
|
|
|
const char *match = (flags & OBJ_KEY) ? arg : right->name;
|
|
|
|
return strcasecmp(left->name, match) ? 0 : (CMP_MATCH | CMP_STOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void channel_snapshot_dtor(void *obj)
|
|
|
|
{
|
|
|
|
struct ast_channel_snapshot *snapshot = obj;
|
2013-07-08 19:19:55 +00:00
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_string_field_free_memory(snapshot);
|
2013-06-12 02:13:31 +00:00
|
|
|
ao2_cleanup(snapshot->manager_vars);
|
2017-02-03 21:26:23 +00:00
|
|
|
ao2_cleanup(snapshot->ari_vars);
|
2013-04-08 14:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan)
|
|
|
|
{
|
2014-04-15 18:30:24 +00:00
|
|
|
struct ast_channel_snapshot *snapshot;
|
|
|
|
struct ast_bridge *bridge;
|
2013-04-08 14:26:37 +00:00
|
|
|
|
2013-06-07 12:56:56 +00:00
|
|
|
/* no snapshots for dummy channels */
|
|
|
|
if (!ast_channel_tech(chan)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-10 23:09:49 +00:00
|
|
|
snapshot = ao2_alloc_options(sizeof(*snapshot), channel_snapshot_dtor,
|
|
|
|
AO2_ALLOC_OPT_LOCK_NOLOCK);
|
2013-04-08 14:26:37 +00:00
|
|
|
if (!snapshot || ast_string_field_init(snapshot, 1024)) {
|
2014-04-15 18:30:24 +00:00
|
|
|
ao2_cleanup(snapshot);
|
2013-04-08 14:26:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_string_field_set(snapshot, name, ast_channel_name(chan));
|
2013-07-08 19:19:55 +00:00
|
|
|
ast_string_field_set(snapshot, type, ast_channel_tech(chan)->type);
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_string_field_set(snapshot, accountcode, ast_channel_accountcode(chan));
|
|
|
|
ast_string_field_set(snapshot, peeraccount, ast_channel_peeraccount(chan));
|
|
|
|
ast_string_field_set(snapshot, userfield, ast_channel_userfield(chan));
|
|
|
|
ast_string_field_set(snapshot, uniqueid, ast_channel_uniqueid(chan));
|
|
|
|
ast_string_field_set(snapshot, linkedid, ast_channel_linkedid(chan));
|
|
|
|
ast_string_field_set(snapshot, hangupsource, ast_channel_hangupsource(chan));
|
|
|
|
if (ast_channel_appl(chan)) {
|
|
|
|
ast_string_field_set(snapshot, appl, ast_channel_appl(chan));
|
|
|
|
}
|
|
|
|
if (ast_channel_data(chan)) {
|
|
|
|
ast_string_field_set(snapshot, data, ast_channel_data(chan));
|
|
|
|
}
|
|
|
|
ast_string_field_set(snapshot, context, ast_channel_context(chan));
|
|
|
|
ast_string_field_set(snapshot, exten, ast_channel_exten(chan));
|
|
|
|
|
|
|
|
ast_string_field_set(snapshot, caller_name,
|
2013-11-05 20:59:39 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, ""));
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_string_field_set(snapshot, caller_number,
|
2013-11-05 20:59:39 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, ""));
|
2013-06-17 03:00:38 +00:00
|
|
|
ast_string_field_set(snapshot, caller_dnid, S_OR(ast_channel_dialed(chan)->number.str, ""));
|
|
|
|
ast_string_field_set(snapshot, caller_subaddr,
|
2013-11-05 20:59:39 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->id.subaddress.valid, ast_channel_caller(chan)->id.subaddress.str, ""));
|
2013-06-17 03:00:38 +00:00
|
|
|
ast_string_field_set(snapshot, dialed_subaddr,
|
|
|
|
S_COR(ast_channel_dialed(chan)->subaddress.valid, ast_channel_dialed(chan)->subaddress.str, ""));
|
2013-06-13 13:15:56 +00:00
|
|
|
ast_string_field_set(snapshot, caller_ani,
|
|
|
|
S_COR(ast_channel_caller(chan)->ani.number.valid, ast_channel_caller(chan)->ani.number.str, ""));
|
|
|
|
ast_string_field_set(snapshot, caller_rdnis,
|
|
|
|
S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, ""));
|
|
|
|
ast_string_field_set(snapshot, caller_dnid,
|
|
|
|
S_OR(ast_channel_dialed(chan)->number.str, ""));
|
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_string_field_set(snapshot, connected_name,
|
|
|
|
S_COR(ast_channel_connected(chan)->id.name.valid, ast_channel_connected(chan)->id.name.str, ""));
|
|
|
|
ast_string_field_set(snapshot, connected_number,
|
|
|
|
S_COR(ast_channel_connected(chan)->id.number.valid, ast_channel_connected(chan)->id.number.str, ""));
|
2013-05-23 20:11:35 +00:00
|
|
|
ast_string_field_set(snapshot, language, ast_channel_language(chan));
|
2013-04-08 14:26:37 +00:00
|
|
|
|
2013-07-08 19:19:55 +00:00
|
|
|
if ((bridge = ast_channel_get_bridge(chan))) {
|
2016-05-09 19:27:53 +00:00
|
|
|
if (!ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) {
|
|
|
|
ast_string_field_set(snapshot, bridgeid, bridge->uniqueid);
|
|
|
|
}
|
2014-04-15 18:30:24 +00:00
|
|
|
ao2_cleanup(bridge);
|
2013-07-08 19:19:55 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
snapshot->creationtime = ast_channel_creationtime(chan);
|
|
|
|
snapshot->state = ast_channel_state(chan);
|
|
|
|
snapshot->priority = ast_channel_priority(chan);
|
|
|
|
snapshot->amaflags = ast_channel_amaflags(chan);
|
|
|
|
snapshot->hangupcause = ast_channel_hangupcause(chan);
|
Handle hangup logic in the Stasis message bus and consumers of Stasis messages
This patch does the following:
* It adds a new soft hangup flag AST_SOFTHANGUP_HANGUP_EXEC that is set when a
channel is executing dialplan hangup logic, i.e., the 'h' extension or a
hangup handler. Stasis messages now also convey the soft hangup flag so
consumers of the messages can know when a channel is executing said
hangup logic.
* It adds a new channel flag, AST_FLAG_DEAD, which is set when a channel is
well and truly dead. Not just a zombie, but dead, Jim. Manager, CEL, CDRs,
and other consumers of Stasis have been updated to look for this flag to
know when the channel should by lying six feet under.
* The CDR engine has been updated to better handle a channel entering and
leaving a bridge. Previously, a new CDR was automatically created when a
channel left a bridge and put into the 'Pending' state; however, this
way of handling CDRs made it difficult for the 'endbeforehexten' logic to
work correctly - there was always a new CDR waiting in the hangup logic
and, even if 'ended', wouldn't be the CDR people wanted to inspect in the
hangup routine. This patch completely removes the Pending state and instead
defers creation of the new CDR until it gets a new message that requires
a new CDR.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393777 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-07 20:34:38 +00:00
|
|
|
ast_copy_flags(&snapshot->flags, ast_channel_flags(chan), 0xFFFFFFFF);
|
2013-04-10 15:34:47 +00:00
|
|
|
snapshot->caller_pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
|
Handle hangup logic in the Stasis message bus and consumers of Stasis messages
This patch does the following:
* It adds a new soft hangup flag AST_SOFTHANGUP_HANGUP_EXEC that is set when a
channel is executing dialplan hangup logic, i.e., the 'h' extension or a
hangup handler. Stasis messages now also convey the soft hangup flag so
consumers of the messages can know when a channel is executing said
hangup logic.
* It adds a new channel flag, AST_FLAG_DEAD, which is set when a channel is
well and truly dead. Not just a zombie, but dead, Jim. Manager, CEL, CDRs,
and other consumers of Stasis have been updated to look for this flag to
know when the channel should by lying six feet under.
* The CDR engine has been updated to better handle a channel entering and
leaving a bridge. Previously, a new CDR was automatically created when a
channel left a bridge and put into the 'Pending' state; however, this
way of handling CDRs made it difficult for the 'endbeforehexten' logic to
work correctly - there was always a new CDR waiting in the hangup logic
and, even if 'ended', wouldn't be the CDR people wanted to inspect in the
hangup routine. This patch completely removes the Pending state and instead
defers creation of the new CDR until it gets a new message that requires
a new CDR.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393777 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-07 20:34:38 +00:00
|
|
|
ast_set_flag(&snapshot->softhangup_flags, ast_channel_softhangup_internal_flag(chan));
|
2013-04-10 15:34:47 +00:00
|
|
|
|
|
|
|
snapshot->manager_vars = ast_channel_get_manager_vars(chan);
|
2016-11-11 16:45:37 +00:00
|
|
|
snapshot->ari_vars = ast_channel_get_ari_vars(chan);
|
2013-07-19 19:23:39 +00:00
|
|
|
snapshot->tech_properties = ast_channel_tech(chan)->properties;
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void publish_message_for_channel_topics(struct stasis_message *message, struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
if (chan) {
|
|
|
|
stasis_publish(ast_channel_topic(chan), message);
|
|
|
|
} else {
|
|
|
|
stasis_publish(ast_channel_topic_all(), message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void channel_blob_dtor(void *obj)
|
|
|
|
{
|
|
|
|
struct ast_channel_blob *event = obj;
|
|
|
|
ao2_cleanup(event->snapshot);
|
|
|
|
ast_json_unref(event->blob);
|
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
static void ast_channel_publish_dial_internal(struct ast_channel *caller,
|
|
|
|
struct ast_channel *peer, struct ast_channel *forwarded, const char *dialstring,
|
|
|
|
const char *dialstatus, const char *forward)
|
2013-04-08 14:26:37 +00:00
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_multi_channel_blob *, payload, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
|
2013-06-12 02:13:31 +00:00
|
|
|
RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct ast_channel_snapshot *, peer_snapshot, NULL, ao2_cleanup);
|
2013-12-14 17:19:41 +00:00
|
|
|
RAII_VAR(struct ast_channel_snapshot *, forwarded_snapshot, NULL, ao2_cleanup);
|
2013-04-08 14:26:37 +00:00
|
|
|
|
2014-08-06 12:55:28 +00:00
|
|
|
if (!ast_channel_dial_type()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_assert(peer != NULL);
|
2013-06-25 13:03:17 +00:00
|
|
|
blob = ast_json_pack("{s: s, s: s, s: s}",
|
2013-04-08 14:26:37 +00:00
|
|
|
"dialstatus", S_OR(dialstatus, ""),
|
2013-06-25 13:03:17 +00:00
|
|
|
"forward", S_OR(forward, ""),
|
2013-04-08 14:26:37 +00:00
|
|
|
"dialstring", S_OR(dialstring, ""));
|
|
|
|
if (!blob) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
payload = ast_multi_channel_blob_create(blob);
|
|
|
|
if (!payload) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caller) {
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_lock(caller);
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
if (ast_strlen_zero(dialstatus)) {
|
|
|
|
caller_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(caller));
|
|
|
|
} else {
|
|
|
|
caller_snapshot = ast_channel_snapshot_create(caller);
|
|
|
|
}
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(caller);
|
2013-04-08 14:26:37 +00:00
|
|
|
if (!caller_snapshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ast_multi_channel_blob_add_channel(payload, "caller", caller_snapshot);
|
|
|
|
}
|
|
|
|
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_lock(peer);
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
if (ast_strlen_zero(dialstatus)) {
|
|
|
|
peer_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(peer));
|
|
|
|
} else {
|
|
|
|
peer_snapshot = ast_channel_snapshot_create(peer);
|
|
|
|
}
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(peer);
|
2013-04-08 14:26:37 +00:00
|
|
|
if (!peer_snapshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ast_multi_channel_blob_add_channel(payload, "peer", peer_snapshot);
|
|
|
|
|
2013-12-14 17:19:41 +00:00
|
|
|
if (forwarded) {
|
2014-04-18 16:27:31 +00:00
|
|
|
ast_channel_lock(forwarded);
|
2013-12-14 17:19:41 +00:00
|
|
|
forwarded_snapshot = ast_channel_snapshot_create(forwarded);
|
2014-04-18 16:27:31 +00:00
|
|
|
ast_channel_unlock(forwarded);
|
2013-12-14 17:19:41 +00:00
|
|
|
if (!forwarded_snapshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ast_multi_channel_blob_add_channel(payload, "forwarded", forwarded_snapshot);
|
|
|
|
}
|
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
msg = stasis_message_create(ast_channel_dial_type(), payload);
|
|
|
|
if (!msg) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-09 20:00:56 +00:00
|
|
|
publish_message_for_channel_topics(msg, caller ?: peer);
|
2013-04-08 14:26:37 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
static void remove_dial_masquerade(struct ast_channel *peer);
|
2015-05-04 17:16:24 +00:00
|
|
|
static void remove_dial_masquerade_caller(struct ast_channel *caller);
|
2014-09-19 15:54:20 +00:00
|
|
|
static int set_dial_masquerade(struct ast_channel *caller,
|
|
|
|
struct ast_channel *peer, const char *dialstring);
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_channel *peer,
|
|
|
|
struct ast_channel *forwarded, const char *dialstring, const char *dialstatus,
|
|
|
|
const char *forward)
|
2013-06-25 13:03:17 +00:00
|
|
|
{
|
2014-10-14 16:43:33 +00:00
|
|
|
ast_assert(peer != NULL);
|
|
|
|
|
2015-05-04 17:16:24 +00:00
|
|
|
/* XXX With an early bridge the below dial masquerade datastore code could, theoretically,
|
|
|
|
* go away as the act of changing the channel during dialing would be done using the bridge
|
|
|
|
* API itself and not a masquerade.
|
|
|
|
*/
|
|
|
|
|
2014-09-19 15:54:20 +00:00
|
|
|
if (caller) {
|
2014-10-14 16:43:33 +00:00
|
|
|
/*
|
|
|
|
* Lock two or three channels.
|
|
|
|
*
|
|
|
|
* We need to hold the locks to hold off a potential masquerade
|
|
|
|
* messing up the stasis dial event ordering.
|
|
|
|
*/
|
|
|
|
for (;; ast_channel_unlock(caller), sched_yield()) {
|
|
|
|
ast_channel_lock(caller);
|
|
|
|
if (ast_channel_trylock(peer)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (forwarded && ast_channel_trylock(forwarded)) {
|
|
|
|
ast_channel_unlock(peer);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_strlen_zero(dialstatus)) {
|
2014-09-19 15:54:20 +00:00
|
|
|
set_dial_masquerade(caller, peer, dialstring);
|
2014-10-14 16:43:33 +00:00
|
|
|
} else {
|
|
|
|
remove_dial_masquerade(peer);
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
ast_channel_publish_dial_internal(caller, peer, forwarded, dialstring, dialstatus,
|
|
|
|
forward);
|
2014-09-19 15:54:20 +00:00
|
|
|
|
|
|
|
if (caller) {
|
2014-10-14 16:43:33 +00:00
|
|
|
if (forwarded) {
|
|
|
|
ast_channel_unlock(forwarded);
|
|
|
|
}
|
2014-09-19 15:54:20 +00:00
|
|
|
ast_channel_unlock(peer);
|
2015-05-04 17:16:24 +00:00
|
|
|
remove_dial_masquerade_caller(caller);
|
2014-09-19 15:54:20 +00:00
|
|
|
ast_channel_unlock(caller);
|
|
|
|
}
|
2013-06-25 13:03:17 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
void ast_channel_publish_dial(struct ast_channel *caller, struct ast_channel *peer,
|
|
|
|
const char *dialstring, const char *dialstatus)
|
|
|
|
{
|
|
|
|
ast_channel_publish_dial_forward(caller, peer, NULL, dialstring, dialstatus, NULL);
|
|
|
|
}
|
|
|
|
|
2013-05-24 20:44:07 +00:00
|
|
|
static struct stasis_message *create_channel_blob_message(struct ast_channel_snapshot *snapshot,
|
|
|
|
struct stasis_message_type *type,
|
|
|
|
struct ast_json *blob)
|
2013-04-08 14:26:37 +00:00
|
|
|
{
|
2014-04-01 22:34:30 +00:00
|
|
|
struct stasis_message *msg;
|
|
|
|
struct ast_channel_blob *obj;
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
obj = ao2_alloc(sizeof(*obj), channel_blob_dtor);
|
|
|
|
if (!obj) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-23 20:11:35 +00:00
|
|
|
if (snapshot) {
|
|
|
|
obj->snapshot = snapshot;
|
2013-05-24 20:44:07 +00:00
|
|
|
ao2_ref(obj->snapshot, +1);
|
2013-04-08 14:26:37 +00:00
|
|
|
}
|
2014-04-01 22:34:30 +00:00
|
|
|
if (!blob) {
|
|
|
|
blob = ast_json_null();
|
|
|
|
}
|
2013-04-08 14:26:37 +00:00
|
|
|
obj->blob = ast_json_ref(blob);
|
|
|
|
|
2013-05-08 18:34:50 +00:00
|
|
|
msg = stasis_message_create(type, obj);
|
2014-04-01 22:34:30 +00:00
|
|
|
ao2_cleanup(obj);
|
2013-04-08 14:26:37 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2013-05-29 02:26:17 +00:00
|
|
|
struct stasis_message *ast_channel_blob_create_from_cache(const char *channel_id,
|
2013-05-24 20:44:07 +00:00
|
|
|
struct stasis_message_type *type,
|
|
|
|
struct ast_json *blob)
|
2013-05-23 20:11:35 +00:00
|
|
|
{
|
2013-05-24 20:44:07 +00:00
|
|
|
RAII_VAR(struct ast_channel_snapshot *, snapshot,
|
2014-08-06 12:55:28 +00:00
|
|
|
NULL,
|
2013-05-24 20:44:07 +00:00
|
|
|
ao2_cleanup);
|
2013-05-23 20:11:35 +00:00
|
|
|
|
2014-08-06 12:55:28 +00:00
|
|
|
if (!type) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = ast_channel_snapshot_get_latest(channel_id);
|
|
|
|
|
2013-05-24 20:44:07 +00:00
|
|
|
return create_channel_blob_message(snapshot, type, blob);
|
2013-05-23 20:11:35 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 20:44:07 +00:00
|
|
|
struct stasis_message *ast_channel_blob_create(struct ast_channel *chan,
|
|
|
|
struct stasis_message_type *type, struct ast_json *blob)
|
2013-05-23 20:11:35 +00:00
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
|
|
|
|
2014-08-06 12:55:28 +00:00
|
|
|
if (!type) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-24 20:44:07 +00:00
|
|
|
if (chan) {
|
|
|
|
snapshot = ast_channel_snapshot_create(chan);
|
2013-05-23 20:11:35 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 20:44:07 +00:00
|
|
|
return create_channel_blob_message(snapshot, type, blob);
|
2013-05-23 20:11:35 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
/*! \brief A channel snapshot wrapper object used in \ref ast_multi_channel_blob objects */
|
|
|
|
struct channel_role_snapshot {
|
|
|
|
struct ast_channel_snapshot *snapshot; /*!< A channel snapshot */
|
|
|
|
char role[0]; /*!< The role assigned to the channel */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief A multi channel blob data structure for multi_channel_blob stasis messages */
|
|
|
|
struct ast_multi_channel_blob {
|
|
|
|
struct ao2_container *channel_snapshots; /*!< A container holding the snapshots */
|
|
|
|
struct ast_json *blob; /*< A blob of JSON data */
|
|
|
|
};
|
|
|
|
|
2013-08-16 17:33:21 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Standard comparison function for \ref channel_role_snapshot objects
|
|
|
|
*/
|
2013-04-08 14:26:37 +00:00
|
|
|
static int channel_role_single_cmp_cb(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct channel_role_snapshot *left = obj;
|
|
|
|
struct channel_role_snapshot *right = arg;
|
|
|
|
const char *match = (flags & OBJ_KEY) ? arg : right->role;
|
|
|
|
return strcasecmp(left->role, match) ? 0 : (CMP_MATCH | CMP_STOP);
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:33:21 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Multi comparison function for \ref channel_role_snapshot objects
|
|
|
|
*/
|
2013-04-08 14:26:37 +00:00
|
|
|
static int channel_role_multi_cmp_cb(void *obj, void *arg, int flags)
|
|
|
|
{
|
|
|
|
struct channel_role_snapshot *left = obj;
|
|
|
|
struct channel_role_snapshot *right = arg;
|
|
|
|
const char *match = (flags & OBJ_KEY) ? arg : right->role;
|
|
|
|
return strcasecmp(left->role, match) ? 0 : (CMP_MATCH);
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:33:21 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Hash function for \ref channel_role_snapshot objects
|
|
|
|
*/
|
2013-04-08 14:26:37 +00:00
|
|
|
static int channel_role_hash_cb(const void *obj, const int flags)
|
|
|
|
{
|
|
|
|
const struct channel_role_snapshot *snapshot = obj;
|
|
|
|
const char *name = (flags & OBJ_KEY) ? obj : snapshot->role;
|
|
|
|
return ast_str_case_hash(name);
|
|
|
|
}
|
|
|
|
|
2013-08-16 17:33:21 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Destructor for \ref ast_multi_channel_blob objects
|
|
|
|
*/
|
2013-04-08 14:26:37 +00:00
|
|
|
static void multi_channel_blob_dtor(void *obj)
|
|
|
|
{
|
|
|
|
struct ast_multi_channel_blob *multi_blob = obj;
|
|
|
|
|
|
|
|
ao2_cleanup(multi_blob->channel_snapshots);
|
|
|
|
ast_json_unref(multi_blob->blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ast_multi_channel_blob *ast_multi_channel_blob_create(struct ast_json *blob)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_multi_channel_blob *, obj,
|
|
|
|
ao2_alloc(sizeof(*obj), multi_channel_blob_dtor),
|
|
|
|
ao2_cleanup);
|
|
|
|
|
|
|
|
ast_assert(blob != NULL);
|
|
|
|
|
|
|
|
if (!obj) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj->channel_snapshots = ao2_container_alloc(NUM_MULTI_CHANNEL_BLOB_BUCKETS,
|
|
|
|
channel_role_hash_cb, channel_role_single_cmp_cb);
|
|
|
|
if (!obj->channel_snapshots) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj->blob = ast_json_ref(blob);
|
|
|
|
|
|
|
|
ao2_ref(obj, +1);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2013-05-24 20:44:07 +00:00
|
|
|
struct ast_channel_snapshot *ast_channel_snapshot_get_latest(const char *uniqueid)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
|
|
|
|
struct ast_channel_snapshot *snapshot;
|
|
|
|
|
|
|
|
ast_assert(!ast_strlen_zero(uniqueid));
|
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
message = stasis_cache_get(ast_channel_cache(),
|
2013-05-24 20:44:07 +00:00
|
|
|
ast_channel_snapshot_type(),
|
|
|
|
uniqueid);
|
|
|
|
if (!message) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = stasis_message_data(message);
|
|
|
|
if (!snapshot) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ao2_ref(snapshot, +1);
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
2013-05-31 12:27:29 +00:00
|
|
|
struct ast_channel_snapshot *ast_channel_snapshot_get_latest_by_name(const char *name)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
|
|
|
|
struct ast_channel_snapshot *snapshot;
|
|
|
|
|
|
|
|
ast_assert(!ast_strlen_zero(name));
|
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
message = stasis_cache_get(ast_channel_cache_by_name(),
|
2013-05-31 12:27:29 +00:00
|
|
|
ast_channel_snapshot_type(),
|
|
|
|
name);
|
|
|
|
if (!message) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = stasis_message_data(message);
|
|
|
|
if (!snapshot) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ao2_ref(snapshot, +1);
|
|
|
|
return snapshot;
|
|
|
|
}
|
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
static void channel_role_snapshot_dtor(void *obj)
|
|
|
|
{
|
|
|
|
struct channel_role_snapshot *role_snapshot = obj;
|
|
|
|
ao2_cleanup(role_snapshot->snapshot);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_multi_channel_blob_add_channel(struct ast_multi_channel_blob *obj, const char *role, struct ast_channel_snapshot *snapshot)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct channel_role_snapshot *, role_snapshot, NULL, ao2_cleanup);
|
|
|
|
int role_len = strlen(role) + 1;
|
|
|
|
|
|
|
|
if (!obj || ast_strlen_zero(role) || !snapshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-10 23:09:49 +00:00
|
|
|
role_snapshot = ao2_alloc_options(sizeof(*role_snapshot) + role_len, channel_role_snapshot_dtor,
|
|
|
|
AO2_ALLOC_OPT_LOCK_NOLOCK);
|
2013-04-08 14:26:37 +00:00
|
|
|
if (!role_snapshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ast_copy_string(role_snapshot->role, role, role_len);
|
|
|
|
role_snapshot->snapshot = snapshot;
|
|
|
|
ao2_ref(role_snapshot->snapshot, +1);
|
|
|
|
ao2_link(obj->channel_snapshots, role_snapshot);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ast_channel_snapshot *ast_multi_channel_blob_get_channel(struct ast_multi_channel_blob *obj, const char *role)
|
|
|
|
{
|
|
|
|
struct channel_role_snapshot *role_snapshot;
|
|
|
|
|
|
|
|
if (!obj || ast_strlen_zero(role)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
role_snapshot = ao2_find(obj->channel_snapshots, role, OBJ_KEY);
|
|
|
|
/* Note that this function does not increase the ref count on snapshot */
|
|
|
|
if (!role_snapshot) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ao2_ref(role_snapshot, -1);
|
|
|
|
return role_snapshot->snapshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ao2_container *ast_multi_channel_blob_get_channels(struct ast_multi_channel_blob *obj, const char *role)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ao2_container *, ret_container,
|
|
|
|
ao2_container_alloc(NUM_MULTI_CHANNEL_BLOB_BUCKETS, channel_snapshot_hash_cb, channel_snapshot_cmp_cb),
|
|
|
|
ao2_cleanup);
|
|
|
|
struct ao2_iterator *it_role_snapshots;
|
|
|
|
struct channel_role_snapshot *role_snapshot;
|
|
|
|
char *arg;
|
|
|
|
|
|
|
|
if (!obj || ast_strlen_zero(role) || !ret_container) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
arg = ast_strdupa(role);
|
|
|
|
|
|
|
|
it_role_snapshots = ao2_callback(obj->channel_snapshots, OBJ_MULTIPLE | OBJ_KEY, channel_role_multi_cmp_cb, arg);
|
|
|
|
if (!it_role_snapshots) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((role_snapshot = ao2_iterator_next(it_role_snapshots))) {
|
|
|
|
ao2_link(ret_container, role_snapshot->snapshot);
|
|
|
|
ao2_ref(role_snapshot, -1);
|
|
|
|
}
|
|
|
|
ao2_iterator_destroy(it_role_snapshots);
|
|
|
|
|
|
|
|
ao2_ref(ret_container, +1);
|
|
|
|
return ret_container;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ast_json *ast_multi_channel_blob_get_json(struct ast_multi_channel_blob *obj)
|
|
|
|
{
|
|
|
|
if (!obj) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return obj->blob;
|
|
|
|
}
|
|
|
|
|
2013-10-02 16:23:34 +00:00
|
|
|
void ast_channel_stage_snapshot(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
ast_set_flag(ast_channel_flags(chan), AST_FLAG_SNAPSHOT_STAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_SNAPSHOT_STAGE);
|
|
|
|
ast_channel_publish_snapshot(chan);
|
|
|
|
}
|
|
|
|
|
2013-05-23 20:11:35 +00:00
|
|
|
void ast_channel_publish_snapshot(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
|
|
|
|
|
2014-08-06 12:55:28 +00:00
|
|
|
if (!ast_channel_snapshot_type()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-02 16:23:34 +00:00
|
|
|
if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_SNAPSHOT_STAGE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-23 20:11:35 +00:00
|
|
|
snapshot = ast_channel_snapshot_create(chan);
|
|
|
|
if (!snapshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = stasis_message_create(ast_channel_snapshot_type(), snapshot);
|
|
|
|
if (!message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_assert(ast_channel_topic(chan) != NULL);
|
|
|
|
stasis_publish(ast_channel_topic(chan), message);
|
|
|
|
}
|
|
|
|
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
void ast_channel_publish_cached_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
|
|
|
|
{
|
|
|
|
struct stasis_message *message;
|
|
|
|
|
|
|
|
if (!blob) {
|
|
|
|
blob = ast_json_null();
|
|
|
|
}
|
|
|
|
|
|
|
|
message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan), type, blob);
|
|
|
|
if (message) {
|
|
|
|
stasis_publish(ast_channel_topic(chan), message);
|
|
|
|
}
|
|
|
|
ao2_cleanup(message);
|
|
|
|
}
|
|
|
|
|
2013-06-17 03:00:38 +00:00
|
|
|
void ast_channel_publish_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
|
|
|
|
{
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
struct stasis_message *message;
|
2013-06-17 03:00:38 +00:00
|
|
|
|
|
|
|
if (!blob) {
|
|
|
|
blob = ast_json_null();
|
|
|
|
}
|
|
|
|
|
|
|
|
message = ast_channel_blob_create(chan, type, blob);
|
|
|
|
if (message) {
|
|
|
|
stasis_publish(ast_channel_topic(chan), message);
|
|
|
|
}
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
ao2_cleanup(message);
|
2013-06-17 03:00:38 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
void ast_channel_publish_varset(struct ast_channel *chan, const char *name, const char *value)
|
|
|
|
{
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
struct ast_json *blob;
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
ast_assert(name != NULL);
|
|
|
|
ast_assert(value != NULL);
|
|
|
|
|
2013-05-21 14:17:24 +00:00
|
|
|
blob = ast_json_pack("{s: s, s: s}",
|
2013-04-08 14:26:37 +00:00
|
|
|
"variable", name,
|
|
|
|
"value", value);
|
|
|
|
if (!blob) {
|
|
|
|
ast_log(LOG_ERROR, "Error creating message\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-18 04:22:05 +00:00
|
|
|
/*! If there are manager variables, force a cache update */
|
|
|
|
if (chan && ast_channel_has_manager_vars()) {
|
|
|
|
ast_channel_publish_snapshot(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chan) {
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
ast_channel_publish_cached_blob(chan, ast_channel_varset_type(), blob);
|
|
|
|
} else {
|
2014-06-18 04:22:05 +00:00
|
|
|
/* This function is NULL safe for global variables */
|
|
|
|
ast_channel_publish_blob(NULL, ast_channel_varset_type(), blob);
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
}
|
2014-06-18 04:22:05 +00:00
|
|
|
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
ast_json_unref(blob);
|
2013-04-08 14:26:37 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 15:46:35 +00:00
|
|
|
static struct ast_manager_event_blob *varset_to_ami(struct stasis_message *msg)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
|
|
|
|
struct ast_channel_blob *obj = stasis_message_data(msg);
|
|
|
|
const char *variable =
|
|
|
|
ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
|
2015-06-08 14:44:04 +00:00
|
|
|
RAII_VAR(char *, value, ast_escape_c_alloc(
|
|
|
|
ast_json_string_get(ast_json_object_get(obj->blob, "value"))), ast_free);
|
|
|
|
|
|
|
|
if (!value) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-06-11 15:46:35 +00:00
|
|
|
|
|
|
|
if (obj->snapshot) {
|
|
|
|
channel_event_string =
|
|
|
|
ast_manager_build_channel_state_string(obj->snapshot);
|
|
|
|
} else {
|
|
|
|
channel_event_string = ast_str_create(35);
|
|
|
|
ast_str_set(&channel_event_string, 0,
|
|
|
|
"Channel: none\r\n"
|
|
|
|
"Uniqueid: none\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!channel_event_string) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_manager_event_blob_create(EVENT_FLAG_DIALPLAN, "VarSet",
|
|
|
|
"%s"
|
|
|
|
"Variable: %s\r\n"
|
|
|
|
"Value: %s\r\n",
|
|
|
|
ast_str_buffer(channel_event_string), variable, value);
|
|
|
|
}
|
|
|
|
|
Replace chan_agent with app_agent_pool.
The ill conceived chan_agent is no more. It is now replaced by
app_agent_pool.
Agents login using the AgentLogin() application as before. The
AgentLogin() application no longer does any authentication.
Authentication is now the responsibility of the dialplan. (Besides, the
authentication done by chan_agent did not match what the voice prompts
asked for.)
Sample extensions.conf
[login]
; Sample agent 1001 login
; Set COLP for in between calls so the agent does not see the last caller COLP.
exten => 1001,1,Set(CONNECTEDLINE(all)="Agent Waiting" <1001>)
; Give the agent DTMF transfer and disconnect features when connected to a caller.
same => n,Set(CHANNEL(dtmf-features)=TX)
same => n,AgentLogin(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
[caller]
; Sample caller direct connect to agent 1001
exten => 800,1,AgentRequest(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
; Sample caller going through a Queue to agent 1001
exten => 900,1,Queue(agent_q)
same => n,Hangup()
Sample queues.conf
[agent_q]
member => Local/800@caller,,SuperAgent,Agent:1001
Under the hood operation overview:
1) Logged in agents wait for callers in an agents holding bridge.
2) Caller requests an agent using AgentRequest()
3) A basic bridge is created, the agent is notified, and caller joins the
basic bridge to wait for the agent.
4) The agent is either automatically connected to the caller or must ack
the call to connect.
5) The agent is moved from the agents holding bridge to the basic bridge.
6) The agent and caller talk.
7) The connection is ended by either party.
8) The agent goes back to the agents holding bridge.
To avoid some locking issues with the agent holding bridge, I needed to
make some changes to the after bridge callback support. The after bridge
callback is now a list of requested callbacks with the last to be added
the only active callback. The after bridge callback for failed callbacks
will always happen in the channel thread when the channel leaves the
bridging system or is destroyed.
(closes issue ASTERISK-21554)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2657/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394417 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-15 23:20:55 +00:00
|
|
|
static struct ast_manager_event_blob *agent_login_to_ami(struct stasis_message *msg)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
|
|
|
|
struct ast_channel_blob *obj = stasis_message_data(msg);
|
|
|
|
const char *agent = ast_json_string_get(ast_json_object_get(obj->blob, "agent"));
|
|
|
|
|
|
|
|
channel_string = ast_manager_build_channel_state_string(obj->snapshot);
|
|
|
|
if (!channel_string) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_manager_event_blob_create(EVENT_FLAG_AGENT, "AgentLogin",
|
|
|
|
"%s"
|
|
|
|
"Agent: %s\r\n",
|
|
|
|
ast_str_buffer(channel_string), agent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_manager_event_blob *agent_logoff_to_ami(struct stasis_message *msg)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
|
|
|
|
struct ast_channel_blob *obj = stasis_message_data(msg);
|
|
|
|
const char *agent = ast_json_string_get(ast_json_object_get(obj->blob, "agent"));
|
|
|
|
long logintime = ast_json_integer_get(ast_json_object_get(obj->blob, "logintime"));
|
|
|
|
|
|
|
|
channel_string = ast_manager_build_channel_state_string(obj->snapshot);
|
|
|
|
if (!channel_string) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_manager_event_blob_create(EVENT_FLAG_AGENT, "AgentLogoff",
|
|
|
|
"%s"
|
|
|
|
"Agent: %s\r\n"
|
|
|
|
"Logintime: %ld\r\n",
|
|
|
|
ast_str_buffer(channel_string), agent, logintime);
|
|
|
|
}
|
|
|
|
|
2013-05-17 17:43:58 +00:00
|
|
|
void ast_publish_channel_state(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
|
|
|
|
|
2014-08-06 12:55:28 +00:00
|
|
|
if (!ast_channel_snapshot_type()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-17 17:43:58 +00:00
|
|
|
ast_assert(chan != NULL);
|
|
|
|
if (!chan) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot = ast_channel_snapshot_create(chan);
|
|
|
|
if (!snapshot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
message = stasis_message_create(ast_channel_snapshot_type(), snapshot);
|
|
|
|
if (!message) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_assert(ast_channel_topic(chan) != NULL);
|
|
|
|
stasis_publish(ast_channel_topic(chan), message);
|
|
|
|
}
|
|
|
|
|
2013-11-22 20:10:46 +00:00
|
|
|
struct ast_json *ast_channel_snapshot_to_json(
|
|
|
|
const struct ast_channel_snapshot *snapshot,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
2013-04-15 16:43:47 +00:00
|
|
|
{
|
2017-11-03 22:43:18 +00:00
|
|
|
struct ast_json *json_chan;
|
2013-04-15 16:43:47 +00:00
|
|
|
|
2013-11-22 20:10:46 +00:00
|
|
|
if (snapshot == NULL
|
|
|
|
|| (sanitize && sanitize->channel_snapshot
|
|
|
|
&& sanitize->channel_snapshot(snapshot))) {
|
2013-04-15 16:43:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
json_chan = ast_json_pack(
|
|
|
|
/* Broken up into groups of three for readability */
|
|
|
|
"{ s: s, s: s, s: s,"
|
|
|
|
" s: o, s: o, s: s,"
|
2014-12-09 20:20:27 +00:00
|
|
|
" s: o, s: o, s: s }",
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
/* First line */
|
|
|
|
"id", snapshot->uniqueid,
|
|
|
|
"name", snapshot->name,
|
|
|
|
"state", ast_state2str(snapshot->state),
|
|
|
|
/* Second line */
|
|
|
|
"caller", ast_json_name_number(
|
|
|
|
snapshot->caller_name, snapshot->caller_number),
|
|
|
|
"connected", ast_json_name_number(
|
|
|
|
snapshot->connected_name, snapshot->connected_number),
|
|
|
|
"accountcode", snapshot->accountcode,
|
|
|
|
/* Third line */
|
|
|
|
"dialplan", ast_json_dialplan_cep(
|
|
|
|
snapshot->context, snapshot->exten, snapshot->priority),
|
2014-12-09 20:20:27 +00:00
|
|
|
"creationtime", ast_json_timeval(snapshot->creationtime, NULL),
|
|
|
|
"language", snapshot->language);
|
2013-04-15 16:43:47 +00:00
|
|
|
|
2016-11-11 16:45:37 +00:00
|
|
|
if (snapshot->ari_vars && !AST_LIST_EMPTY(snapshot->ari_vars)) {
|
|
|
|
ast_json_object_set(json_chan, "channelvars", ast_json_channel_vars(snapshot->ari_vars));
|
|
|
|
}
|
|
|
|
|
2017-11-03 22:43:18 +00:00
|
|
|
return json_chan;
|
2013-04-15 16:43:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 13:13:06 +00:00
|
|
|
int ast_channel_snapshot_cep_equal(
|
|
|
|
const struct ast_channel_snapshot *old_snapshot,
|
|
|
|
const struct ast_channel_snapshot *new_snapshot)
|
|
|
|
{
|
|
|
|
ast_assert(old_snapshot != NULL);
|
|
|
|
ast_assert(new_snapshot != NULL);
|
|
|
|
|
|
|
|
/* We actually get some snapshots with CEP set, but before the
|
|
|
|
* application is set. Since empty application is invalid, we treat
|
|
|
|
* setting the application from nothing as a CEP change.
|
|
|
|
*/
|
|
|
|
if (ast_strlen_zero(old_snapshot->appl) &&
|
|
|
|
!ast_strlen_zero(new_snapshot->appl)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return old_snapshot->priority == new_snapshot->priority &&
|
|
|
|
strcmp(old_snapshot->context, new_snapshot->context) == 0 &&
|
|
|
|
strcmp(old_snapshot->exten, new_snapshot->exten) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_channel_snapshot_caller_id_equal(
|
|
|
|
const struct ast_channel_snapshot *old_snapshot,
|
|
|
|
const struct ast_channel_snapshot *new_snapshot)
|
|
|
|
{
|
|
|
|
ast_assert(old_snapshot != NULL);
|
|
|
|
ast_assert(new_snapshot != NULL);
|
|
|
|
return strcmp(old_snapshot->caller_number, new_snapshot->caller_number) == 0 &&
|
|
|
|
strcmp(old_snapshot->caller_name, new_snapshot->caller_name) == 0;
|
|
|
|
}
|
|
|
|
|
2014-12-08 16:24:36 +00:00
|
|
|
int ast_channel_snapshot_connected_line_equal(
|
|
|
|
const struct ast_channel_snapshot *old_snapshot,
|
|
|
|
const struct ast_channel_snapshot *new_snapshot)
|
|
|
|
{
|
|
|
|
ast_assert(old_snapshot != NULL);
|
|
|
|
ast_assert(new_snapshot != NULL);
|
|
|
|
return strcmp(old_snapshot->connected_number, new_snapshot->connected_number) == 0 &&
|
|
|
|
strcmp(old_snapshot->connected_name, new_snapshot->connected_name) == 0;
|
|
|
|
}
|
|
|
|
|
2013-11-22 20:10:46 +00:00
|
|
|
static struct ast_json *channel_blob_to_json(
|
|
|
|
struct stasis_message *message,
|
|
|
|
const char *type,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_json *, out, NULL, ast_json_unref);
|
|
|
|
struct ast_channel_blob *channel_blob = stasis_message_data(message);
|
|
|
|
struct ast_json *blob = channel_blob->blob;
|
|
|
|
struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
|
|
|
|
const struct timeval *tv = stasis_message_timestamp(message);
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
if (blob == NULL || ast_json_is_null(blob)) {
|
|
|
|
out = ast_json_object_create();
|
|
|
|
} else {
|
|
|
|
/* blobs are immutable, so shallow copies are fine */
|
|
|
|
out = ast_json_copy(blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!out) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res |= ast_json_object_set(out, "type", ast_json_string_create(type));
|
|
|
|
res |= ast_json_object_set(out, "timestamp",
|
|
|
|
ast_json_timeval(*tv, NULL));
|
|
|
|
|
|
|
|
/* For global channel messages, the snapshot is optional */
|
|
|
|
if (snapshot) {
|
2013-11-22 20:10:46 +00:00
|
|
|
struct ast_json *json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
|
|
|
|
|
|
|
|
if (!json_channel) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
res |= ast_json_object_set(out, "channel", json_channel);
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (res != 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_json_ref(out);
|
|
|
|
}
|
|
|
|
|
2013-11-22 20:10:46 +00:00
|
|
|
static struct ast_json *dtmf_end_to_json(
|
|
|
|
struct stasis_message *message,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
{
|
|
|
|
struct ast_channel_blob *channel_blob = stasis_message_data(message);
|
|
|
|
struct ast_json *blob = channel_blob->blob;
|
|
|
|
struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
|
|
|
|
const char *direction =
|
|
|
|
ast_json_string_get(ast_json_object_get(blob, "direction"));
|
2015-12-14 18:04:15 +00:00
|
|
|
const char *digit =
|
|
|
|
ast_json_string_get(ast_json_object_get(blob, "digit"));
|
|
|
|
long duration_ms =
|
|
|
|
ast_json_integer_get(ast_json_object_get(blob, "duration_ms"));
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
const struct timeval *tv = stasis_message_timestamp(message);
|
2015-01-30 16:49:59 +00:00
|
|
|
struct ast_json *json_channel;
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
|
|
|
|
/* Only present received DTMF end events as JSON */
|
|
|
|
if (strcasecmp("Received", direction) != 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-30 16:49:59 +00:00
|
|
|
json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
|
2013-11-22 20:10:46 +00:00
|
|
|
if (!json_channel) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-12-14 18:04:15 +00:00
|
|
|
return ast_json_pack("{s: s, s: o, s: s, s: i, s: o}",
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
"type", "ChannelDtmfReceived",
|
|
|
|
"timestamp", ast_json_timeval(*tv, NULL),
|
2015-12-14 18:04:15 +00:00
|
|
|
"digit", digit,
|
|
|
|
"duration_ms", duration_ms,
|
2013-11-22 20:10:46 +00:00
|
|
|
"channel", json_channel);
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 20:10:46 +00:00
|
|
|
static struct ast_json *varset_to_json(
|
|
|
|
struct stasis_message *message,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
{
|
2013-11-22 20:10:46 +00:00
|
|
|
return channel_blob_to_json(message, "ChannelVarset", sanitize);
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 20:10:46 +00:00
|
|
|
static struct ast_json *hangup_request_to_json(
|
|
|
|
struct stasis_message *message,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
{
|
2013-11-22 20:10:46 +00:00
|
|
|
return channel_blob_to_json(message, "ChannelHangupRequest", sanitize);
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
2013-12-14 17:19:41 +00:00
|
|
|
static struct ast_json *dial_to_json(
|
|
|
|
struct stasis_message *message,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
|
|
|
{
|
|
|
|
struct ast_multi_channel_blob *payload = stasis_message_data(message);
|
|
|
|
struct ast_json *blob = ast_multi_channel_blob_get_json(payload);
|
2015-12-14 18:04:15 +00:00
|
|
|
const char *dialstatus =
|
|
|
|
ast_json_string_get(ast_json_object_get(blob, "dialstatus"));
|
|
|
|
const char *forward =
|
|
|
|
ast_json_string_get(ast_json_object_get(blob, "forward"));
|
|
|
|
const char *dialstring =
|
|
|
|
ast_json_string_get(ast_json_object_get(blob, "dialstring"));
|
2013-12-14 17:19:41 +00:00
|
|
|
struct ast_json *caller_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "caller"), sanitize);
|
|
|
|
struct ast_json *peer_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "peer"), sanitize);
|
|
|
|
struct ast_json *forwarded_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "forwarded"), sanitize);
|
|
|
|
struct ast_json *json;
|
|
|
|
const struct timeval *tv = stasis_message_timestamp(message);
|
|
|
|
int res = 0;
|
|
|
|
|
2015-12-14 18:04:15 +00:00
|
|
|
json = ast_json_pack("{s: s, s: o, s: s, s: s, s: s}",
|
2013-12-14 17:19:41 +00:00
|
|
|
"type", "Dial",
|
|
|
|
"timestamp", ast_json_timeval(*tv, NULL),
|
2015-12-14 18:04:15 +00:00
|
|
|
"dialstatus", dialstatus,
|
|
|
|
"forward", forward,
|
|
|
|
"dialstring", dialstring);
|
2013-12-14 17:19:41 +00:00
|
|
|
if (!json) {
|
2014-02-21 18:04:54 +00:00
|
|
|
ast_json_unref(caller_json);
|
|
|
|
ast_json_unref(peer_json);
|
|
|
|
ast_json_unref(forwarded_json);
|
2013-12-14 17:19:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (caller_json) {
|
|
|
|
res |= ast_json_object_set(json, "caller", caller_json);
|
|
|
|
}
|
|
|
|
if (peer_json) {
|
|
|
|
res |= ast_json_object_set(json, "peer", peer_json);
|
|
|
|
}
|
|
|
|
if (forwarded_json) {
|
|
|
|
res |= ast_json_object_set(json, "forwarded", forwarded_json);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
ast_json_unref(json);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
2014-05-30 12:42:57 +00:00
|
|
|
static struct ast_manager_event_blob *talking_start_to_ami(struct stasis_message *msg)
|
|
|
|
{
|
|
|
|
struct ast_str *channel_string;
|
|
|
|
struct ast_channel_blob *obj = stasis_message_data(msg);
|
|
|
|
struct ast_manager_event_blob *blob;
|
|
|
|
|
|
|
|
channel_string = ast_manager_build_channel_state_string(obj->snapshot);
|
|
|
|
if (!channel_string) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
blob = ast_manager_event_blob_create(EVENT_FLAG_CALL, "ChannelTalkingStart",
|
|
|
|
"%s", ast_str_buffer(channel_string));
|
|
|
|
ast_free(channel_string);
|
|
|
|
|
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_json *talking_start_to_json(struct stasis_message *message,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
|
|
|
{
|
|
|
|
return channel_blob_to_json(message, "ChannelTalkingStarted", sanitize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_manager_event_blob *talking_stop_to_ami(struct stasis_message *msg)
|
|
|
|
{
|
|
|
|
struct ast_str *channel_string;
|
|
|
|
struct ast_channel_blob *obj = stasis_message_data(msg);
|
|
|
|
int duration = ast_json_integer_get(ast_json_object_get(obj->blob, "duration"));
|
|
|
|
struct ast_manager_event_blob *blob;
|
|
|
|
|
|
|
|
channel_string = ast_manager_build_channel_state_string(obj->snapshot);
|
|
|
|
if (!channel_string) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
blob = ast_manager_event_blob_create(EVENT_FLAG_CALL, "ChannelTalkingStop",
|
|
|
|
"%s"
|
|
|
|
"Duration: %d\r\n",
|
|
|
|
ast_str_buffer(channel_string),
|
|
|
|
duration);
|
|
|
|
ast_free(channel_string);
|
|
|
|
|
|
|
|
return blob;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_json *talking_stop_to_json(struct stasis_message *message,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
|
|
|
{
|
|
|
|
return channel_blob_to_json(message, "ChannelTalkingFinished", sanitize);
|
|
|
|
}
|
|
|
|
|
2015-04-07 15:22:42 +00:00
|
|
|
static struct ast_json *hold_to_json(struct stasis_message *message,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
|
|
|
{
|
|
|
|
struct ast_channel_blob *channel_blob = stasis_message_data(message);
|
|
|
|
struct ast_json *blob = channel_blob->blob;
|
|
|
|
struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
|
|
|
|
const char *musicclass = ast_json_string_get(ast_json_object_get(blob, "musicclass"));
|
|
|
|
const struct timeval *tv = stasis_message_timestamp(message);
|
|
|
|
struct ast_json *json_channel;
|
|
|
|
|
|
|
|
json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
|
|
|
|
if (!json_channel) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_json_pack("{s: s, s: o, s: s, s: o}",
|
|
|
|
"type", "ChannelHold",
|
|
|
|
"timestamp", ast_json_timeval(*tv, NULL),
|
|
|
|
"musicclass", S_OR(musicclass, "N/A"),
|
|
|
|
"channel", json_channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_json *unhold_to_json(struct stasis_message *message,
|
|
|
|
const struct stasis_message_sanitizer *sanitize)
|
|
|
|
{
|
|
|
|
struct ast_channel_blob *channel_blob = stasis_message_data(message);
|
|
|
|
struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
|
|
|
|
const struct timeval *tv = stasis_message_timestamp(message);
|
|
|
|
struct ast_json *json_channel;
|
|
|
|
|
|
|
|
json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
|
|
|
|
if (!json_channel) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast_json_pack("{s: s, s: o, s: o}",
|
|
|
|
"type", "ChannelUnhold",
|
|
|
|
"timestamp", ast_json_timeval(*tv, NULL),
|
|
|
|
"channel", json_channel);
|
|
|
|
}
|
|
|
|
|
2013-06-11 15:46:35 +00:00
|
|
|
/*!
|
|
|
|
* @{ \brief Define channel message types.
|
|
|
|
*/
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_snapshot_type);
|
2013-12-14 17:19:41 +00:00
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_dial_type,
|
|
|
|
.to_json = dial_to_json,
|
|
|
|
);
|
2013-06-11 15:46:35 +00:00
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_varset_type,
|
|
|
|
.to_ami = varset_to_ami,
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
.to_json = varset_to_json,
|
|
|
|
);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_request_type,
|
|
|
|
.to_json = hangup_request_to_json,
|
2013-06-11 15:46:35 +00:00
|
|
|
);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_begin_type);
|
Update events to use Swagger 1.3 subtyping, and related aftermath
This patch started with the simple idea of changing the /events data
model to be more sane. The original model would send out events like:
{ "stasis_start": { "args": [], "channel": { ... } } }
The event discriminator was the field name instead of being a value in
the object, due to limitations in how Swagger 1.1 could model objects.
While technically sufficient in communicating event information, it was
really difficult to deal with in terms of client side JSON handling.
This patch takes advantage of a proposed extension[1] to Swagger which
allows type variance through the use of a discriminator field. This had
a domino effect that made this a surprisingly large patch.
[1]: https://groups.google.com/d/msg/wordnik-api/EC3rGajE0os/ey_5dBI_jWcJ
In changing the models, I also had to change the swagger_model.py
processor so it can handle the type discriminator and subtyping. I took
that a big step forward, and using that information to generate an
ari_model module, which can validate a JSON object against the Swagger
model.
The REST and WebSocket generators were changed to take advantage of the
validators. If compiled with AST_DEVMODE enabled, JSON objects that
don't match their corresponding models will not be sent out. For REST
API calls, a 500 Internal Server response is sent. For WebSockets, the
invalid JSON message is replaced with an error message.
Since this took over about half of the job of the existing JSON
generators, and the .to_json virtual function on messages took over the
other half, I reluctantly removed the generators.
The validators turned up all sorts of errors and inconsistencies in our
data models, and the code. These were cleaned up, with checks in the
code generator avoid some of the consistency problems in the future.
* The model for a channel snapshot was trimmed down to match the
information sent via AMI. Many of the field being sent were not
useful in the general case.
* The model for a bridge snapshot was updated to be more consistent
with the other ARI models.
Another impact of introducing subtyping was that the swagger-codegen
documentation generator was insufficient (at least until it catches up
with Swagger 1.2). I wanted it to be easier to generate docs for the API
anyways, so I ported the wiki pages to use the Asterisk Swagger
generator. In the process, I was able to clean up many of the model
links, which would occasionally give inconsistent results on the wiki. I
also added error responses to the wiki docs, making the wiki
documentation more complete.
Finally, since Stasis-HTTP will now be named Asterisk REST Interface
(ARI), any new functions and files I created carry the ari_ prefix. I
changed a few stasis_http references to ari where it was non-intrusive
and made sense.
(closes issue ASTERISK-21885)
Review: https://reviewboard.asterisk.org/r/2639/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-03 16:32:41 +00:00
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_end_type,
|
|
|
|
.to_json = dtmf_end_to_json,
|
|
|
|
);
|
2015-04-07 15:22:42 +00:00
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_hold_type,
|
|
|
|
.to_json = hold_to_json,
|
|
|
|
);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type,
|
|
|
|
.to_json = unhold_to_json,
|
|
|
|
);
|
2013-06-11 15:46:35 +00:00
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_handler_type);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_moh_start_type);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_moh_stop_type);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_start_type);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_stop_type);
|
Replace chan_agent with app_agent_pool.
The ill conceived chan_agent is no more. It is now replaced by
app_agent_pool.
Agents login using the AgentLogin() application as before. The
AgentLogin() application no longer does any authentication.
Authentication is now the responsibility of the dialplan. (Besides, the
authentication done by chan_agent did not match what the voice prompts
asked for.)
Sample extensions.conf
[login]
; Sample agent 1001 login
; Set COLP for in between calls so the agent does not see the last caller COLP.
exten => 1001,1,Set(CONNECTEDLINE(all)="Agent Waiting" <1001>)
; Give the agent DTMF transfer and disconnect features when connected to a caller.
same => n,Set(CHANNEL(dtmf-features)=TX)
same => n,AgentLogin(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
[caller]
; Sample caller direct connect to agent 1001
exten => 800,1,AgentRequest(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
; Sample caller going through a Queue to agent 1001
exten => 900,1,Queue(agent_q)
same => n,Hangup()
Sample queues.conf
[agent_q]
member => Local/800@caller,,SuperAgent,Agent:1001
Under the hood operation overview:
1) Logged in agents wait for callers in an agents holding bridge.
2) Caller requests an agent using AgentRequest()
3) A basic bridge is created, the agent is notified, and caller joins the
basic bridge to wait for the agent.
4) The agent is either automatically connected to the caller or must ack
the call to connect.
5) The agent is moved from the agents holding bridge to the basic bridge.
6) The agent and caller talk.
7) The connection is ended by either party.
8) The agent goes back to the agents holding bridge.
To avoid some locking issues with the agent holding bridge, I needed to
make some changes to the after bridge callback support. The after bridge
callback is now a list of requested callbacks with the last to be added
the only active callback. The after bridge callback for failed callbacks
will always happen in the channel thread when the channel leaves the
bridging system or is destroyed.
(closes issue ASTERISK-21554)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2657/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394417 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-15 23:20:55 +00:00
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_agent_login_type,
|
|
|
|
.to_ami = agent_login_to_ami,
|
|
|
|
);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_agent_logoff_type,
|
|
|
|
.to_ami = agent_logoff_to_ami,
|
|
|
|
);
|
2014-05-30 12:42:57 +00:00
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_talking_start,
|
|
|
|
.to_ami = talking_start_to_ami,
|
|
|
|
.to_json = talking_start_to_json,
|
|
|
|
);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN(ast_channel_talking_stop,
|
|
|
|
.to_ami = talking_stop_to_ami,
|
|
|
|
.to_json = talking_stop_to_json,
|
|
|
|
);
|
2013-06-11 15:46:35 +00:00
|
|
|
|
|
|
|
/*! @} */
|
|
|
|
|
Avoid unnecessary cleanups during immediate shutdown
This patch addresses issues during immediate shutdowns, where modules
are not unloaded, but Asterisk atexit handlers are run.
In the typical case, this usually isn't a big deal. But the
introduction of the Stasis message bus makes it much more likely for
asynchronous activity to be happening off in some thread during
shutdown.
During an immediate shutdown, Asterisk skips unloading modules. But
while it is processing the atexit handlers, there is a window of time
where some of the core message types have been cleaned up, but the
message bus is still running. Specifically, it's still running
module subscriptions that might be using the core message types. If a
message is received by that subscription in that window, it will
attempt to use a message type that has been cleaned up.
To solve this problem, this patch introduces ast_register_cleanup().
This function operates identically to ast_register_atexit(), except
that cleanup calls are not invoked on an immediate shutdown. All of
the core message type and topic cleanup was moved from atexit handlers
to cleanup handlers.
This ensures that core type and topic cleanup only happens if the
modules that used them are first unloaded.
This patch also changes the ast_assert() when accessing a cleaned up
or uninitialized message type to an error log message. Message type
functions are actually NULL safe across the board, so the assert was a
bit heavy handed. Especially for anyone with DO_CRASH enabled.
Review: https://reviewboard.asterisk.org/r/2562/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-30 17:05:53 +00:00
|
|
|
static void stasis_channels_cleanup(void)
|
2013-04-08 14:26:37 +00:00
|
|
|
{
|
Stasis: address refcount races; implementation comments
Change r395954 reordered some stasis object destruction, which should
have been fine. Unfortunately, it caused some hard to reproduce issues
related to objects being accessed after they had been destroyed. The
patch in r396329 fixed the destruction order problem; this patch
addresses the underlying issue. A few other stasis-related fixes were
also added.
* Add ref-bumps around areas where objects may get transitively
destroyed. (For example, where we lock a topic, unref a subscription,
which unrefs the topic, which explodes the topic when we try to
unlock it.)
* Wrote an extensive doxygen page about Stasis implementation,
relationships between objects, lifecycles of objects, how the
refcounting works, etc. Many other comments were added, corrected, or
cleaned up.
* Added an assert to the topic dtor to catch extra ref decrements.
* Fixed type used after destruction errors for graceful shutdown in
stasis_channels.c.
* I added two unit tests in an attempt to catch destruction order
issues. Since the underlying cause is a race condition, though, the
tests rarely failed even when the code was wrong.
* Fixed a leak in stasis_cache_pattern.c.
(closes issue ASTERISK-22243)
Review: https://reviewboard.asterisk.org/r/2746/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396842 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-08-16 16:03:34 +00:00
|
|
|
stasis_caching_unsubscribe_and_join(channel_by_name_topic);
|
|
|
|
channel_by_name_topic = NULL;
|
|
|
|
ao2_cleanup(channel_cache_by_name);
|
|
|
|
channel_cache_by_name = NULL;
|
|
|
|
ao2_cleanup(channel_cache_all);
|
|
|
|
channel_cache_all = NULL;
|
|
|
|
|
2013-05-08 18:34:50 +00:00
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_snapshot_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dial_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_varset_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hangup_request_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type);
|
2013-05-24 21:21:25 +00:00
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hold_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_unhold_type);
|
2013-05-24 20:44:07 +00:00
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_start_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_chanspy_stop_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_fax_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hangup_handler_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_moh_start_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_moh_stop_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_monitor_start_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_monitor_stop_type);
|
Replace chan_agent with app_agent_pool.
The ill conceived chan_agent is no more. It is now replaced by
app_agent_pool.
Agents login using the AgentLogin() application as before. The
AgentLogin() application no longer does any authentication.
Authentication is now the responsibility of the dialplan. (Besides, the
authentication done by chan_agent did not match what the voice prompts
asked for.)
Sample extensions.conf
[login]
; Sample agent 1001 login
; Set COLP for in between calls so the agent does not see the last caller COLP.
exten => 1001,1,Set(CONNECTEDLINE(all)="Agent Waiting" <1001>)
; Give the agent DTMF transfer and disconnect features when connected to a caller.
same => n,Set(CHANNEL(dtmf-features)=TX)
same => n,AgentLogin(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
[caller]
; Sample caller direct connect to agent 1001
exten => 800,1,AgentRequest(1001)
same => n,NoOp(AGENT_STATUS is ${AGENT_STATUS})
same => n,Hangup()
; Sample caller going through a Queue to agent 1001
exten => 900,1,Queue(agent_q)
same => n,Hangup()
Sample queues.conf
[agent_q]
member => Local/800@caller,,SuperAgent,Agent:1001
Under the hood operation overview:
1) Logged in agents wait for callers in an agents holding bridge.
2) Caller requests an agent using AgentRequest()
3) A basic bridge is created, the agent is notified, and caller joins the
basic bridge to wait for the agent.
4) The agent is either automatically connected to the caller or must ack
the call to connect.
5) The agent is moved from the agents holding bridge to the basic bridge.
6) The agent and caller talk.
7) The connection is ended by either party.
8) The agent goes back to the agents holding bridge.
To avoid some locking issues with the agent holding bridge, I needed to
make some changes to the after bridge callback support. The after bridge
callback is now a list of requested callbacks with the last to be added
the only active callback. The after bridge callback for failed callbacks
will always happen in the channel thread when the channel leaves the
bridging system or is destroyed.
(closes issue ASTERISK-21554)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2657/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@394417 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-07-15 23:20:55 +00:00
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_agent_login_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_agent_logoff_type);
|
2014-05-30 12:42:57 +00:00
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_talking_start);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_talking_stop);
|
2013-04-08 14:26:37 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
int ast_stasis_channels_init(void)
|
2013-04-08 14:26:37 +00:00
|
|
|
{
|
2013-08-01 13:49:34 +00:00
|
|
|
int res = 0;
|
|
|
|
|
Avoid unnecessary cleanups during immediate shutdown
This patch addresses issues during immediate shutdowns, where modules
are not unloaded, but Asterisk atexit handlers are run.
In the typical case, this usually isn't a big deal. But the
introduction of the Stasis message bus makes it much more likely for
asynchronous activity to be happening off in some thread during
shutdown.
During an immediate shutdown, Asterisk skips unloading modules. But
while it is processing the atexit handlers, there is a window of time
where some of the core message types have been cleaned up, but the
message bus is still running. Specifically, it's still running
module subscriptions that might be using the core message types. If a
message is received by that subscription in that window, it will
attempt to use a message type that has been cleaned up.
To solve this problem, this patch introduces ast_register_cleanup().
This function operates identically to ast_register_atexit(), except
that cleanup calls are not invoked on an immediate shutdown. All of
the core message type and topic cleanup was moved from atexit handlers
to cleanup handlers.
This ensures that core type and topic cleanup only happens if the
modules that used them are first unloaded.
This patch also changes the ast_assert() when accessing a cleaned up
or uninitialized message type to an error log message. Message type
functions are actually NULL safe across the board, so the assert was a
bit heavy handed. Especially for anyone with DO_CRASH enabled.
Review: https://reviewboard.asterisk.org/r/2562/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-05-30 17:05:53 +00:00
|
|
|
ast_register_cleanup(stasis_channels_cleanup);
|
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
channel_cache_all = stasis_cp_all_create("ast_channel_topic_all",
|
|
|
|
channel_snapshot_get_id);
|
|
|
|
if (!channel_cache_all) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-08-23 20:14:46 +00:00
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_agent_login_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_agent_logoff_type);
|
2013-05-24 21:21:25 +00:00
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
channel_cache_by_name = stasis_cache_create(channel_snapshot_get_name);
|
|
|
|
if (!channel_cache_by_name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-08-23 20:14:46 +00:00
|
|
|
/* This should be initialized before the caching topic */
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_snapshot_type);
|
|
|
|
|
2013-08-01 13:49:34 +00:00
|
|
|
channel_by_name_topic = stasis_caching_topic_create(
|
|
|
|
stasis_cp_all_topic(channel_cache_all),
|
|
|
|
channel_cache_by_name);
|
|
|
|
if (!channel_by_name_topic) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dial_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_varset_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hangup_request_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_begin_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_dtmf_end_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hold_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_unhold_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_start_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_chanspy_stop_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_fax_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_hangup_handler_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_moh_start_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_moh_stop_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_monitor_start_type);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_monitor_stop_type);
|
2014-05-30 12:42:57 +00:00
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_talking_start);
|
|
|
|
res |= STASIS_MESSAGE_TYPE_INIT(ast_channel_talking_stop);
|
2013-08-01 13:49:34 +00:00
|
|
|
|
|
|
|
return res;
|
2013-04-08 14:26:37 +00:00
|
|
|
}
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
|
2014-09-19 15:54:20 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief A list element for the dial_masquerade_datastore -- stores data about a dialed peer
|
|
|
|
*/
|
|
|
|
struct dial_target {
|
2014-10-14 16:43:33 +00:00
|
|
|
/*! Called party channel. */
|
2014-09-19 15:54:20 +00:00
|
|
|
struct ast_channel *peer;
|
2014-10-14 16:43:33 +00:00
|
|
|
/*! Dialstring used to call the peer. */
|
2014-09-19 15:54:20 +00:00
|
|
|
char *dialstring;
|
2014-10-14 16:43:33 +00:00
|
|
|
/*! Next entry in the list. */
|
2014-09-19 15:54:20 +00:00
|
|
|
AST_LIST_ENTRY(dial_target) list;
|
|
|
|
};
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
static void dial_target_free(struct dial_target *doomed)
|
|
|
|
{
|
|
|
|
if (!doomed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ast_free(doomed->dialstring);
|
2015-04-30 20:20:43 +00:00
|
|
|
ast_channel_cleanup(doomed->peer);
|
2014-10-14 16:43:33 +00:00
|
|
|
ast_free(doomed);
|
|
|
|
}
|
|
|
|
|
2014-09-19 15:54:20 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Datastore used for advancing dial state in the case of a masquerade
|
|
|
|
* against a channel in the process of dialing.
|
|
|
|
*/
|
|
|
|
struct dial_masquerade_datastore {
|
2014-10-14 16:43:33 +00:00
|
|
|
/*! Calling party channel. */
|
|
|
|
struct ast_channel *caller;
|
|
|
|
/*! List of called peers. */
|
|
|
|
AST_LIST_HEAD_NOLOCK(, dial_target) dialed_peers;
|
2014-09-19 15:54:20 +00:00
|
|
|
};
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
static void dial_masquerade_datastore_cleanup(struct dial_masquerade_datastore *masq_data)
|
|
|
|
{
|
|
|
|
struct dial_target *cur;
|
|
|
|
|
|
|
|
while ((cur = AST_LIST_REMOVE_HEAD(&masq_data->dialed_peers, list))) {
|
|
|
|
dial_target_free(cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dial_masquerade_datastore_remove_chan(struct dial_masquerade_datastore *masq_data, struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
struct dial_target *cur;
|
|
|
|
|
|
|
|
ao2_lock(masq_data);
|
|
|
|
if (masq_data->caller == chan) {
|
|
|
|
dial_masquerade_datastore_cleanup(masq_data);
|
|
|
|
} else {
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&masq_data->dialed_peers, cur, list) {
|
|
|
|
if (cur->peer == chan) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(list);
|
|
|
|
dial_target_free(cur);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
}
|
|
|
|
ao2_unlock(masq_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dial_masquerade_datastore_dtor(void *vdoomed)
|
|
|
|
{
|
|
|
|
dial_masquerade_datastore_cleanup(vdoomed);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dial_masquerade_datastore *dial_masquerade_datastore_alloc(void)
|
|
|
|
{
|
|
|
|
struct dial_masquerade_datastore *masq_data;
|
|
|
|
|
|
|
|
masq_data = ao2_alloc(sizeof(struct dial_masquerade_datastore),
|
|
|
|
dial_masquerade_datastore_dtor);
|
|
|
|
if (!masq_data) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
AST_LIST_HEAD_INIT_NOLOCK(&masq_data->dialed_peers);
|
|
|
|
return masq_data;
|
|
|
|
}
|
|
|
|
|
2014-09-19 15:54:20 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
2014-10-14 16:43:33 +00:00
|
|
|
* \brief Datastore destructor for dial_masquerade_datastore
|
2014-09-19 15:54:20 +00:00
|
|
|
*/
|
|
|
|
static void dial_masquerade_datastore_destroy(void *data)
|
|
|
|
{
|
2014-10-14 16:43:33 +00:00
|
|
|
ao2_ref(data, -1);
|
|
|
|
}
|
|
|
|
|
2015-05-04 17:16:24 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Datastore destructor for dial_masquerade_datastore
|
|
|
|
*/
|
|
|
|
static void dial_masquerade_caller_datastore_destroy(void *data)
|
|
|
|
{
|
|
|
|
dial_masquerade_datastore_cleanup(data);
|
|
|
|
ao2_ref(data, -1);
|
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
static struct ast_datastore *dial_masquerade_datastore_find(struct ast_channel *chan);
|
|
|
|
|
|
|
|
static void dial_masquerade_fixup(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
|
|
|
|
{
|
|
|
|
struct dial_masquerade_datastore *masq_data = data;
|
2014-09-19 15:54:20 +00:00
|
|
|
struct dial_target *cur;
|
2014-10-14 16:43:33 +00:00
|
|
|
struct ast_datastore *datastore;
|
|
|
|
|
|
|
|
ao2_lock(masq_data);
|
|
|
|
if (!masq_data->caller) {
|
|
|
|
/* Nothing to do but remove the datastore */
|
|
|
|
} else if (masq_data->caller == old_chan) {
|
|
|
|
/* The caller channel is being masqueraded out. */
|
|
|
|
ast_debug(1, "Caller channel %s being masqueraded out to %s (is_empty:%d)\n",
|
|
|
|
ast_channel_name(new_chan), ast_channel_name(old_chan),
|
|
|
|
AST_LIST_EMPTY(&masq_data->dialed_peers));
|
|
|
|
AST_LIST_TRAVERSE(&masq_data->dialed_peers, cur, list) {
|
|
|
|
ast_channel_publish_dial_internal(new_chan, cur->peer, NULL,
|
|
|
|
cur->dialstring, "NOANSWER", NULL);
|
|
|
|
ast_channel_publish_dial_internal(old_chan, cur->peer, NULL,
|
|
|
|
cur->dialstring, NULL, NULL);
|
|
|
|
}
|
|
|
|
dial_masquerade_datastore_cleanup(masq_data);
|
|
|
|
} else {
|
|
|
|
/* One of the peer channels is being masqueraded out. */
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&masq_data->dialed_peers, cur, list) {
|
|
|
|
if (cur->peer == old_chan) {
|
|
|
|
ast_debug(1, "Peer channel %s being masqueraded out to %s\n",
|
|
|
|
ast_channel_name(new_chan), ast_channel_name(old_chan));
|
|
|
|
ast_channel_publish_dial_internal(masq_data->caller, new_chan, NULL,
|
|
|
|
cur->dialstring, "CANCEL", NULL);
|
|
|
|
ast_channel_publish_dial_internal(masq_data->caller, old_chan, NULL,
|
|
|
|
cur->dialstring, NULL, NULL);
|
|
|
|
|
|
|
|
AST_LIST_REMOVE_CURRENT(list);
|
|
|
|
dial_target_free(cur);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
}
|
|
|
|
ao2_unlock(masq_data);
|
2014-09-19 15:54:20 +00:00
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
/* Remove the datastore from the channel. */
|
|
|
|
datastore = dial_masquerade_datastore_find(old_chan);
|
|
|
|
if (!datastore) {
|
|
|
|
return;
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
2014-10-14 16:43:33 +00:00
|
|
|
ast_channel_datastore_remove(old_chan, datastore);
|
|
|
|
ast_datastore_free(datastore);
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Primary purpose for dial_masquerade_datastore, publishes
|
|
|
|
* the channel dial event needed to set the incoming channel into the
|
|
|
|
* dial state during a masquerade.
|
|
|
|
* \param data pointer to the dial_masquerade_datastore
|
2014-10-14 16:43:33 +00:00
|
|
|
* \param old_chan Channel being replaced
|
2014-09-19 15:54:20 +00:00
|
|
|
* \param new_chan Channel being pushed to dial mode
|
|
|
|
*/
|
2014-10-14 16:43:33 +00:00
|
|
|
static void dial_masquerade_breakdown(void *data, struct ast_channel *old_chan, struct ast_channel *new_chan)
|
2014-09-19 15:54:20 +00:00
|
|
|
{
|
|
|
|
struct dial_masquerade_datastore *masq_data = data;
|
|
|
|
struct dial_target *cur;
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
ao2_lock(masq_data);
|
|
|
|
|
|
|
|
if (!masq_data->caller) {
|
|
|
|
ao2_unlock(masq_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (masq_data->caller == new_chan) {
|
|
|
|
/*
|
|
|
|
* The caller channel is being masqueraded into.
|
|
|
|
* The masquerade is likely because of a blonde transfer.
|
|
|
|
*/
|
|
|
|
ast_debug(1, "Caller channel %s being masqueraded into by %s (is_empty:%d)\n",
|
|
|
|
ast_channel_name(old_chan), ast_channel_name(new_chan),
|
|
|
|
AST_LIST_EMPTY(&masq_data->dialed_peers));
|
|
|
|
AST_LIST_TRAVERSE(&masq_data->dialed_peers, cur, list) {
|
|
|
|
ast_channel_publish_dial_internal(old_chan, cur->peer, NULL,
|
|
|
|
cur->dialstring, "NOANSWER", NULL);
|
|
|
|
ast_channel_publish_dial_internal(new_chan, cur->peer, NULL,
|
|
|
|
cur->dialstring, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ao2_unlock(masq_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* One of the peer channels is being masqueraded into.
|
|
|
|
* The masquerade is likely because of a call pickup.
|
|
|
|
*/
|
2014-09-19 15:54:20 +00:00
|
|
|
AST_LIST_TRAVERSE(&masq_data->dialed_peers, cur, list) {
|
2014-10-14 16:43:33 +00:00
|
|
|
if (cur->peer == new_chan) {
|
|
|
|
ast_debug(1, "Peer channel %s being masqueraded into by %s\n",
|
|
|
|
ast_channel_name(old_chan), ast_channel_name(new_chan));
|
|
|
|
ast_channel_publish_dial_internal(masq_data->caller, old_chan, NULL,
|
|
|
|
cur->dialstring, "CANCEL", NULL);
|
|
|
|
ast_channel_publish_dial_internal(masq_data->caller, new_chan, NULL,
|
|
|
|
cur->dialstring, NULL, NULL);
|
|
|
|
break;
|
|
|
|
}
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
ao2_unlock(masq_data);
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ast_datastore_info dial_masquerade_info = {
|
|
|
|
.type = "stasis-chan-dial-masq",
|
|
|
|
.destroy = dial_masquerade_datastore_destroy,
|
2014-10-14 16:43:33 +00:00
|
|
|
.chan_fixup = dial_masquerade_fixup,
|
|
|
|
.chan_breakdown = dial_masquerade_breakdown,
|
2014-09-19 15:54:20 +00:00
|
|
|
};
|
|
|
|
|
2015-05-04 17:16:24 +00:00
|
|
|
static const struct ast_datastore_info dial_masquerade_caller_info = {
|
|
|
|
.type = "stasis-chan-dial-masq",
|
|
|
|
.destroy = dial_masquerade_caller_datastore_destroy,
|
|
|
|
.chan_fixup = dial_masquerade_fixup,
|
|
|
|
.chan_breakdown = dial_masquerade_breakdown,
|
|
|
|
};
|
|
|
|
|
2014-09-19 15:54:20 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
2014-10-14 16:43:33 +00:00
|
|
|
* \brief Find the dial masquerade datastore on the given channel.
|
|
|
|
*
|
2014-09-19 15:54:20 +00:00
|
|
|
* \param chan Channel a datastore data is wanted from
|
|
|
|
*
|
2014-10-14 16:43:33 +00:00
|
|
|
* \return A pointer to the datastore if it exists.
|
2014-09-19 15:54:20 +00:00
|
|
|
*/
|
2014-10-14 16:43:33 +00:00
|
|
|
static struct ast_datastore *dial_masquerade_datastore_find(struct ast_channel *chan)
|
2014-09-19 15:54:20 +00:00
|
|
|
{
|
2015-05-04 17:16:24 +00:00
|
|
|
struct ast_datastore *datastore;
|
|
|
|
|
|
|
|
datastore = ast_channel_datastore_find(chan, &dial_masquerade_info, NULL);
|
|
|
|
if (!datastore) {
|
|
|
|
datastore = ast_channel_datastore_find(chan, &dial_masquerade_caller_info, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return datastore;
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \internal
|
2014-10-14 16:43:33 +00:00
|
|
|
* \brief Add the dial masquerade datastore to a channel.
|
|
|
|
*
|
|
|
|
* \param chan Channel to setup dial masquerade datastore on.
|
|
|
|
* \param masq_data NULL to setup caller datastore otherwise steals the ref on success.
|
|
|
|
*
|
|
|
|
* \retval masq_data given or created on success.
|
|
|
|
* (A ref is not returned but can be obtained before chan is unlocked.)
|
|
|
|
* \retval NULL on error. masq_data ref is not stolen.
|
2014-09-19 15:54:20 +00:00
|
|
|
*/
|
2014-10-14 16:43:33 +00:00
|
|
|
static struct dial_masquerade_datastore *dial_masquerade_datastore_add(
|
|
|
|
struct ast_channel *chan, struct dial_masquerade_datastore *masq_data)
|
2014-09-19 15:54:20 +00:00
|
|
|
{
|
2014-10-14 16:43:33 +00:00
|
|
|
struct ast_datastore *datastore;
|
2014-09-19 15:54:20 +00:00
|
|
|
|
2015-05-04 17:16:24 +00:00
|
|
|
datastore = ast_datastore_alloc(!masq_data ? &dial_masquerade_caller_info : &dial_masquerade_info, NULL);
|
2014-09-19 15:54:20 +00:00
|
|
|
if (!datastore) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
if (!masq_data) {
|
|
|
|
masq_data = dial_masquerade_datastore_alloc();
|
|
|
|
if (!masq_data) {
|
|
|
|
ast_datastore_free(datastore);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-05-04 17:16:24 +00:00
|
|
|
masq_data->caller = chan;
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
datastore->data = masq_data;
|
2014-09-19 15:54:20 +00:00
|
|
|
ast_channel_datastore_add(chan, datastore);
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
return masq_data;
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
static int set_dial_masquerade(struct ast_channel *caller, struct ast_channel *peer, const char *dialstring)
|
2014-09-19 15:54:20 +00:00
|
|
|
{
|
2014-10-14 16:43:33 +00:00
|
|
|
struct ast_datastore *datastore;
|
|
|
|
struct dial_masquerade_datastore *masq_data;
|
|
|
|
struct dial_target *target;
|
2014-09-19 15:54:20 +00:00
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
/* Find or create caller datastore */
|
|
|
|
datastore = dial_masquerade_datastore_find(caller);
|
|
|
|
if (!datastore) {
|
|
|
|
masq_data = dial_masquerade_datastore_add(caller, NULL);
|
|
|
|
} else {
|
|
|
|
masq_data = datastore->data;
|
|
|
|
}
|
|
|
|
if (!masq_data) {
|
2014-09-19 15:54:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-10-14 16:43:33 +00:00
|
|
|
ao2_ref(masq_data, +1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Someone likely forgot to do an ast_channel_publish_dial()
|
|
|
|
* or ast_channel_publish_dial_forward() with a final dial
|
|
|
|
* status on the channel.
|
|
|
|
*/
|
|
|
|
ast_assert(masq_data->caller == caller);
|
2014-09-19 15:54:20 +00:00
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
/* Create peer target to put into datastore */
|
|
|
|
target = ast_calloc(1, sizeof(*target));
|
|
|
|
if (!target) {
|
|
|
|
ao2_ref(masq_data, -1);
|
2014-09-19 15:54:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (dialstring) {
|
|
|
|
target->dialstring = ast_strdup(dialstring);
|
|
|
|
if (!target->dialstring) {
|
|
|
|
ast_free(target);
|
2014-10-14 16:43:33 +00:00
|
|
|
ao2_ref(masq_data, -1);
|
2014-09-19 15:54:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 20:20:43 +00:00
|
|
|
target->peer = ast_channel_ref(peer);
|
2014-10-14 16:43:33 +00:00
|
|
|
|
|
|
|
/* Put peer target into datastore */
|
|
|
|
ao2_lock(masq_data);
|
|
|
|
dial_masquerade_datastore_remove_chan(masq_data, peer);
|
|
|
|
AST_LIST_INSERT_HEAD(&masq_data->dialed_peers, target, list);
|
|
|
|
ao2_unlock(masq_data);
|
|
|
|
|
|
|
|
datastore = dial_masquerade_datastore_find(peer);
|
|
|
|
if (datastore) {
|
|
|
|
if (datastore->data == masq_data) {
|
|
|
|
/*
|
|
|
|
* Peer already had the datastore for this dial masquerade.
|
|
|
|
* This was a redundant peer dial masquerade setup.
|
|
|
|
*/
|
|
|
|
ao2_ref(masq_data, -1);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-09-19 15:54:20 +00:00
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
/* Something is wrong. Try to fix if the assert doesn't abort. */
|
|
|
|
ast_assert(0);
|
2014-09-19 15:54:20 +00:00
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
/* Remove the stale dial masquerade datastore */
|
|
|
|
dial_masquerade_datastore_remove_chan(datastore->data, peer);
|
|
|
|
ast_channel_datastore_remove(peer, datastore);
|
|
|
|
ast_datastore_free(datastore);
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
/* Create the peer dial masquerade datastore */
|
|
|
|
if (dial_masquerade_datastore_add(peer, masq_data)) {
|
|
|
|
/* Success */
|
|
|
|
return 0;
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
2014-10-14 16:43:33 +00:00
|
|
|
|
|
|
|
/* Failed to create the peer datastore */
|
|
|
|
dial_masquerade_datastore_remove_chan(masq_data, peer);
|
|
|
|
ao2_ref(masq_data, -1);
|
|
|
|
return -1;
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
static void remove_dial_masquerade(struct ast_channel *peer)
|
2014-09-19 15:54:20 +00:00
|
|
|
{
|
2014-10-14 16:43:33 +00:00
|
|
|
struct ast_datastore *datastore;
|
|
|
|
struct dial_masquerade_datastore *masq_data;
|
2014-09-19 15:54:20 +00:00
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
datastore = dial_masquerade_datastore_find(peer);
|
|
|
|
if (!datastore) {
|
2014-09-19 15:54:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-14 16:43:33 +00:00
|
|
|
masq_data = datastore->data;
|
|
|
|
if (masq_data) {
|
|
|
|
dial_masquerade_datastore_remove_chan(masq_data, peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_channel_datastore_remove(peer, datastore);
|
|
|
|
ast_datastore_free(datastore);
|
2014-09-19 15:54:20 +00:00
|
|
|
}
|
2015-05-04 17:16:24 +00:00
|
|
|
|
|
|
|
static void remove_dial_masquerade_caller(struct ast_channel *caller)
|
|
|
|
{
|
|
|
|
struct ast_datastore *datastore;
|
|
|
|
struct dial_masquerade_datastore *masq_data;
|
|
|
|
|
|
|
|
datastore = dial_masquerade_datastore_find(caller);
|
|
|
|
if (!datastore) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
masq_data = datastore->data;
|
|
|
|
if (!masq_data || !AST_LIST_EMPTY(&masq_data->dialed_peers)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dial_masquerade_datastore_remove_chan(masq_data, caller);
|
|
|
|
|
|
|
|
ast_channel_datastore_remove(caller, datastore);
|
|
|
|
ast_datastore_free(datastore);
|
|
|
|
}
|