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 Test Stasis Channel messages and objects
|
|
|
|
*
|
|
|
|
* \author\verbatim Matt Jordan <mjordan@digium.com> \endverbatim
|
|
|
|
*
|
|
|
|
* \ingroup tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*** MODULEINFO
|
|
|
|
<depend>TEST_FRAMEWORK</depend>
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
|
|
|
#include "asterisk/astobj2.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/stasis.h"
|
|
|
|
#include "asterisk/stasis_message_router.h"
|
|
|
|
#include "asterisk/test.h"
|
|
|
|
#include "asterisk/stasis_channels.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
|
|
|
|
static const char *test_category = "/stasis/channels/";
|
|
|
|
|
|
|
|
static void safe_channel_release(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
if (!chan) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ast_channel_release(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_TEST_DEFINE(channel_blob_create)
|
|
|
|
{
|
|
|
|
struct ast_channel_blob *blob;
|
2013-05-08 18:34:50 +00:00
|
|
|
RAII_VAR(struct stasis_message_type *, type, NULL, ao2_cleanup);
|
2013-04-08 14:26:37 +00:00
|
|
|
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
|
|
|
|
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
|
|
|
|
RAII_VAR(struct ast_json *, bad_json, NULL, ast_json_unref);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TEST_INIT:
|
|
|
|
info->name = __func__;
|
|
|
|
info->category = test_category;
|
|
|
|
info->summary = "Test creation of ast_channel_blob objects";
|
|
|
|
info->description = "Test creation of ast_channel_blob objects";
|
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
case TEST_EXECUTE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-06 12:55:28 +00:00
|
|
|
ast_test_validate(test, stasis_message_type_create("test-type", NULL, &type) == STASIS_MESSAGE_TYPE_SUCCESS);
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, NULL, 0, "TEST/Alice");
|
2013-12-18 19:28:05 +00:00
|
|
|
ast_channel_unlock(chan);
|
2013-04-08 14:26:37 +00:00
|
|
|
json = ast_json_pack("{s: s}",
|
2013-05-08 18:34:50 +00:00
|
|
|
"foo", "bar");
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
/* Off nominal creation */
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_lock(chan);
|
2013-05-08 18:34:50 +00:00
|
|
|
ast_test_validate(test, NULL == ast_channel_blob_create(chan, NULL, json));
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
/* Test for single channel */
|
2013-05-08 18:34:50 +00:00
|
|
|
msg = ast_channel_blob_create(chan, type, json);
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(chan);
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_test_validate(test, NULL != msg);
|
|
|
|
blob = stasis_message_data(msg);
|
|
|
|
ast_test_validate(test, NULL != blob);
|
|
|
|
ast_test_validate(test, NULL != blob->snapshot);
|
|
|
|
ast_test_validate(test, NULL != blob->blob);
|
2013-05-08 18:34:50 +00:00
|
|
|
ast_test_validate(test, type == stasis_message_type(msg));
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
ast_test_validate(test, 1 == ao2_ref(msg, 0));
|
|
|
|
ao2_cleanup(msg);
|
|
|
|
|
|
|
|
/* Test for global channels */
|
2013-05-08 18:34:50 +00:00
|
|
|
msg = ast_channel_blob_create(NULL, type, json);
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_test_validate(test, NULL != msg);
|
|
|
|
blob = stasis_message_data(msg);
|
|
|
|
ast_test_validate(test, NULL != blob);
|
|
|
|
ast_test_validate(test, NULL == blob->snapshot);
|
|
|
|
ast_test_validate(test, NULL != blob->blob);
|
2013-05-08 18:34:50 +00:00
|
|
|
ast_test_validate(test, type == stasis_message_type(msg));
|
|
|
|
|
|
|
|
return AST_TEST_PASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_TEST_DEFINE(null_blob)
|
|
|
|
{
|
|
|
|
struct ast_channel_blob *blob;
|
|
|
|
RAII_VAR(struct stasis_message_type *, type, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
|
|
|
|
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
|
|
|
|
RAII_VAR(struct ast_json *, bad_json, NULL, ast_json_unref);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TEST_INIT:
|
|
|
|
info->name = __func__;
|
|
|
|
info->category = test_category;
|
|
|
|
info->summary = "Test creation of ast_channel_blob objects";
|
|
|
|
info->description = "Test creation of ast_channel_blob objects";
|
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
case TEST_EXECUTE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-06 12:55:28 +00:00
|
|
|
ast_test_validate(test, stasis_message_type_create("test-type", NULL, &type) == STASIS_MESSAGE_TYPE_SUCCESS);
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, NULL, 0, "TEST/Alice");
|
2013-12-18 19:28:05 +00:00
|
|
|
ast_channel_unlock(chan);
|
2013-05-08 18:34:50 +00:00
|
|
|
json = ast_json_pack("{s: s}",
|
|
|
|
"foo", "bar");
|
|
|
|
|
|
|
|
/* Test for single channel */
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_lock(chan);
|
2013-05-08 18:34:50 +00:00
|
|
|
msg = ast_channel_blob_create(chan, type, NULL);
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(chan);
|
2013-05-08 18:34:50 +00:00
|
|
|
ast_test_validate(test, NULL != msg);
|
|
|
|
blob = stasis_message_data(msg);
|
|
|
|
ast_test_validate(test, NULL != blob);
|
|
|
|
ast_test_validate(test, NULL != blob->snapshot);
|
|
|
|
ast_test_validate(test, ast_json_null() == blob->blob);
|
|
|
|
ast_test_validate(test, type == stasis_message_type(msg));
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
return AST_TEST_PASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_TEST_DEFINE(multi_channel_blob_create)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_multi_channel_blob *, blob, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
|
|
|
|
RAII_VAR(struct ast_json *, bad_json, NULL, ast_json_unref);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TEST_INIT:
|
|
|
|
info->name = __func__;
|
|
|
|
info->category = test_category;
|
|
|
|
info->summary = "Test creation of ast_multi_channel_blob objects";
|
|
|
|
info->description = "Test creation of ast_multi_channel_blob objects";
|
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
case TEST_EXECUTE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
json = ast_json_pack("{s: s}",
|
2013-05-08 18:34:50 +00:00
|
|
|
"foo", "bar");
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
/* Test for single channel */
|
|
|
|
blob = ast_multi_channel_blob_create(json);
|
|
|
|
ast_test_validate(test, NULL != blob);
|
|
|
|
ast_test_validate(test, NULL != ast_multi_channel_blob_get_json(blob));
|
|
|
|
|
|
|
|
return AST_TEST_PASS;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_TEST_DEFINE(multi_channel_blob_snapshots)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_multi_channel_blob *, blob, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
|
|
|
|
RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
|
|
|
|
RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
|
|
|
|
RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
|
|
|
|
struct ast_channel_snapshot *snapshot;
|
|
|
|
struct ao2_container *matches;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TEST_INIT:
|
|
|
|
info->name = __func__;
|
|
|
|
info->category = test_category;
|
|
|
|
info->summary = "Test creation of ast_multi_channel_blob objects";
|
|
|
|
info->description = "Test creation of ast_multi_channel_blob objects";
|
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
case TEST_EXECUTE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
json = ast_json_pack("{s: s}",
|
|
|
|
"type", "test");
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
chan_alice = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, NULL, 0, "TEST/Alice");
|
2013-12-18 19:28:05 +00:00
|
|
|
ast_channel_unlock(chan_alice);
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, "200", "Bob", "200", "200", "default", NULL, NULL, 0, "TEST/Bob");
|
2013-12-18 19:28:05 +00:00
|
|
|
ast_channel_unlock(chan_bob);
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
chan_charlie = ast_channel_alloc(0, AST_STATE_DOWN, "300", "Bob", "300", "300", "default", NULL, NULL, 0, "TEST/Charlie");
|
2013-12-18 19:28:05 +00:00
|
|
|
ast_channel_unlock(chan_charlie);
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
blob = ast_multi_channel_blob_create(json);
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_lock(chan_alice);
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_multi_channel_blob_add_channel(blob, "Caller", ast_channel_snapshot_create(chan_alice));
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(chan_alice);
|
|
|
|
ast_channel_lock(chan_bob);
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_multi_channel_blob_add_channel(blob, "Peer", ast_channel_snapshot_create(chan_bob));
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(chan_bob);
|
|
|
|
ast_channel_lock(chan_charlie);
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_multi_channel_blob_add_channel(blob, "Peer", ast_channel_snapshot_create(chan_charlie));
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(chan_charlie);
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
/* Test for unknown role */
|
|
|
|
ast_test_validate(test, NULL == ast_multi_channel_blob_get_channel(blob, "Foobar"));
|
|
|
|
|
|
|
|
/* Test for single match */
|
|
|
|
snapshot = ast_multi_channel_blob_get_channel(blob, "Caller");
|
|
|
|
ast_test_validate(test, NULL != snapshot);
|
|
|
|
ast_test_validate(test, 0 == strcmp("TEST/Alice", snapshot->name));
|
|
|
|
|
|
|
|
/* Test for single match, multiple possibilities */
|
|
|
|
snapshot = ast_multi_channel_blob_get_channel(blob, "Peer");
|
|
|
|
ast_test_validate(test, NULL != snapshot);
|
|
|
|
ast_test_validate(test, 0 != strcmp("TEST/Alice", snapshot->name));
|
|
|
|
|
|
|
|
/* Multi-match */
|
|
|
|
matches = ast_multi_channel_blob_get_channels(blob, "Peer");
|
|
|
|
ast_test_validate(test, NULL != matches);
|
|
|
|
ast_test_validate(test, 2 == ao2_container_count(matches));
|
|
|
|
snapshot = ao2_find(matches, "TEST/Bob", OBJ_KEY);
|
|
|
|
ast_test_validate(test, NULL != snapshot);
|
|
|
|
ao2_cleanup(snapshot);
|
|
|
|
snapshot = ao2_find(matches, "TEST/Charlie", OBJ_KEY);
|
|
|
|
ast_test_validate(test, NULL != snapshot);
|
|
|
|
ao2_cleanup(snapshot);
|
|
|
|
ast_test_validate(test, 1 == ao2_ref(matches, 0));
|
|
|
|
ao2_cleanup(matches);
|
|
|
|
|
|
|
|
return AST_TEST_PASS;
|
|
|
|
}
|
|
|
|
|
2013-04-15 16:43:47 +00:00
|
|
|
AST_TEST_DEFINE(channel_snapshot_json)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
|
|
|
|
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
|
|
|
RAII_VAR(struct ast_json *, expected, NULL, ast_json_unref);
|
|
|
|
RAII_VAR(struct ast_json *, actual, NULL, ast_json_unref);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TEST_INIT:
|
|
|
|
info->name = __func__;
|
|
|
|
info->category = test_category;
|
|
|
|
info->summary = "Test creation of ast_channel_blob objects";
|
|
|
|
info->description = "Test creation of ast_channel_blob objects";
|
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
case TEST_EXECUTE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-11-22 23:57:45 +00:00
|
|
|
ast_test_validate(test, NULL == ast_channel_snapshot_to_json(NULL, NULL));
|
2013-04-15 16:43:47 +00:00
|
|
|
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
chan = ast_channel_alloc(0, AST_STATE_DOWN, "cid_num", "cid_name", "acctcode", "exten", "context", NULL, NULL, 0, "TEST/name");
|
2013-12-18 19:28:05 +00:00
|
|
|
ast_channel_unlock(chan);
|
2013-04-15 16:43:47 +00:00
|
|
|
ast_test_validate(test, NULL != chan);
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_lock(chan);
|
2013-04-15 16:43:47 +00:00
|
|
|
snapshot = ast_channel_snapshot_create(chan);
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(chan);
|
2013-04-15 16:43:47 +00:00
|
|
|
ast_test_validate(test, NULL != snapshot);
|
|
|
|
|
2013-11-22 23:57:45 +00:00
|
|
|
actual = ast_channel_snapshot_to_json(snapshot, 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
|
|
|
expected = ast_json_pack("{ s: s, s: s, s: s, s: s,"
|
2013-04-15 16:43:47 +00:00
|
|
|
" s: { s: s, s: s, s: i },"
|
|
|
|
" s: { s: s, s: s },"
|
|
|
|
" s: { s: s, s: s },"
|
|
|
|
" s: o"
|
|
|
|
"}",
|
|
|
|
"name", "TEST/name",
|
|
|
|
"state", "Down",
|
|
|
|
"accountcode", "acctcode",
|
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
|
|
|
"id", ast_channel_uniqueid(chan),
|
2013-04-15 16:43:47 +00:00
|
|
|
"dialplan",
|
|
|
|
"context", "context",
|
|
|
|
"exten", "exten",
|
|
|
|
"priority", 1,
|
|
|
|
"caller",
|
|
|
|
"name", "cid_name",
|
|
|
|
"number", "cid_num",
|
|
|
|
"connected",
|
|
|
|
"name", "",
|
|
|
|
"number", "",
|
|
|
|
"creationtime",
|
|
|
|
ast_json_timeval(
|
|
|
|
ast_channel_creationtime(chan), NULL));
|
|
|
|
|
|
|
|
ast_test_validate(test, ast_json_equal(expected, actual));
|
|
|
|
|
|
|
|
return AST_TEST_PASS;
|
|
|
|
}
|
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
static int unload_module(void)
|
|
|
|
{
|
|
|
|
AST_TEST_UNREGISTER(channel_blob_create);
|
2013-05-08 18:34:50 +00:00
|
|
|
AST_TEST_UNREGISTER(null_blob);
|
2013-04-08 14:26:37 +00:00
|
|
|
AST_TEST_UNREGISTER(multi_channel_blob_create);
|
|
|
|
AST_TEST_UNREGISTER(multi_channel_blob_snapshots);
|
2013-04-15 16:43:47 +00:00
|
|
|
AST_TEST_UNREGISTER(channel_snapshot_json);
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_module(void)
|
|
|
|
{
|
|
|
|
AST_TEST_REGISTER(channel_blob_create);
|
2013-05-08 18:34:50 +00:00
|
|
|
AST_TEST_REGISTER(null_blob);
|
2013-04-08 14:26:37 +00:00
|
|
|
AST_TEST_REGISTER(multi_channel_blob_create);
|
|
|
|
AST_TEST_REGISTER(multi_channel_blob_snapshots);
|
2013-04-15 16:43:47 +00:00
|
|
|
AST_TEST_REGISTER(channel_snapshot_json);
|
2013-04-08 14:26:37 +00:00
|
|
|
|
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, 0, "Stasis Channel Testing",
|
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module
|
|
|
|
);
|