38 #include "asterisk/stasis_message_router.h"
40 #include "asterisk/stasis_channels.h"
43 static const char *test_category =
"/stasis/channels/";
45 static void safe_channel_release(
struct ast_channel *chan)
64 info->name = __func__;
65 info->category = test_category;
66 info->summary =
"Test creation of ast_channel_blob objects";
67 info->description =
"Test creation of ast_channel_blob objects";
68 return AST_TEST_NOT_RUN;
74 chan =
ast_channel_alloc(0,
AST_STATE_DOWN,
"100",
"Alice",
"100",
"100",
"default", NULL, NULL, 0,
"TEST/Alice");
75 ast_channel_unlock(chan);
80 ast_channel_lock(chan);
85 ast_channel_unlock(chan);
86 ast_test_validate(
test, NULL != msg);
88 ast_test_validate(
test, NULL != blob);
90 ast_test_validate(
test, NULL != blob->
blob);
98 ast_test_validate(
test, NULL != msg);
100 ast_test_validate(
test, NULL != blob);
102 ast_test_validate(
test, NULL != blob->
blob);
105 return AST_TEST_PASS;
119 info->name = __func__;
120 info->category = test_category;
121 info->summary =
"Test creation of ast_channel_blob objects";
122 info->description =
"Test creation of ast_channel_blob objects";
123 return AST_TEST_NOT_RUN;
129 chan =
ast_channel_alloc(0,
AST_STATE_DOWN,
"100",
"Alice",
"100",
"100",
"default", NULL, NULL, 0,
"TEST/Alice");
130 ast_channel_unlock(chan);
135 ast_channel_lock(chan);
137 ast_channel_unlock(chan);
138 ast_test_validate(
test, NULL != msg);
140 ast_test_validate(
test, NULL != blob);
145 return AST_TEST_PASS;
156 info->name = __func__;
157 info->category = test_category;
158 info->summary =
"Test creation of ast_multi_channel_blob objects";
159 info->description =
"Test creation of ast_multi_channel_blob objects";
160 return AST_TEST_NOT_RUN;
170 ast_test_validate(
test, NULL != blob);
173 return AST_TEST_PASS;
188 info->name = __func__;
189 info->category = test_category;
190 info->summary =
"Test creation of ast_multi_channel_blob objects";
191 info->description =
"Test creation of ast_multi_channel_blob objects";
192 return AST_TEST_NOT_RUN;
199 chan_alice =
ast_channel_alloc(0,
AST_STATE_DOWN,
"100",
"Alice",
"100",
"100",
"default", NULL, NULL, 0,
"TEST/Alice");
200 ast_channel_unlock(chan_alice);
201 chan_bob =
ast_channel_alloc(0,
AST_STATE_DOWN,
"200",
"Bob",
"200",
"200",
"default", NULL, NULL, 0,
"TEST/Bob");
202 ast_channel_unlock(chan_bob);
203 chan_charlie =
ast_channel_alloc(0,
AST_STATE_DOWN,
"300",
"Bob",
"300",
"300",
"default", NULL, NULL, 0,
"TEST/Charlie");
204 ast_channel_unlock(chan_charlie);
207 ast_channel_lock(chan_alice);
209 ast_channel_unlock(chan_alice);
210 ast_channel_lock(chan_bob);
212 ast_channel_unlock(chan_bob);
213 ast_channel_lock(chan_charlie);
215 ast_channel_unlock(chan_charlie);
222 ast_test_validate(
test, NULL != snapshot);
223 ast_test_validate(
test, 0 == strcmp(
"TEST/Alice", snapshot->
base->
name));
227 ast_test_validate(
test, NULL != snapshot);
228 ast_test_validate(
test, 0 != strcmp(
"TEST/Alice", snapshot->
base->
name));
232 ast_test_validate(
test, NULL != matches);
234 snapshot = ao2_find(matches,
"TEST/Bob",
OBJ_KEY);
235 ast_test_validate(
test, NULL != snapshot);
236 ao2_cleanup(snapshot);
237 snapshot = ao2_find(matches,
"TEST/Charlie",
OBJ_KEY);
238 ast_test_validate(
test, NULL != snapshot);
239 ao2_cleanup(snapshot);
241 ao2_cleanup(matches);
243 return AST_TEST_PASS;
256 info->name = __func__;
257 info->category = test_category;
258 info->summary =
"Test creation of ast_channel_blob objects";
259 info->description =
"Test creation of ast_channel_blob objects";
260 return AST_TEST_NOT_RUN;
267 chan =
ast_channel_alloc(0,
AST_STATE_DOWN,
"cid_num",
"cid_name",
"acctcode",
"exten",
"context", NULL, NULL, 0,
"TEST/name");
268 ast_channel_unlock(chan);
269 ast_test_validate(
test, NULL != chan);
270 ast_channel_lock(chan);
272 ast_channel_unlock(chan);
273 ast_test_validate(
test, NULL != snapshot);
277 " s: { s: s, s: s, s: i, s: s, s: s },"
278 " s: { s: s, s: s },"
279 " s: { s: s, s: s },"
285 "accountcode",
"acctcode",
286 "id", ast_channel_uniqueid(chan),
289 "context",
"context",
303 ast_channel_creationtime(chan), NULL));
307 return AST_TEST_PASS;
322 info->name = __func__;
323 info->category = test_category;
324 info->summary =
"Test creation of ast_channel_blob objects with rdnis";
325 info->description =
"Test creation of ast_channel_blob objects with rdnis";
326 return AST_TEST_NOT_RUN;
332 chan =
ast_channel_alloc(0,
AST_STATE_DOWN,
"cid_num",
"cid_name",
"acctcode",
"exten",
"context", NULL, NULL, 0,
"TEST/name");
333 ast_channel_unlock(chan);
334 ast_test_validate(
test, NULL != chan);
336 ast_channel_lock(chan);
338 data.from.number.valid = 1;
342 ast_channel_unlock(chan);
344 ast_channel_lock(chan);
346 ast_channel_unlock(chan);
347 ast_test_validate(
test, NULL != snapshot);
351 " s: { s: s, s: s, s: i, s: s, s: s },"
352 " s: { s: s, s: s },"
353 " s: { s: s, s: s },"
360 "accountcode",
"acctcode",
361 "id", ast_channel_uniqueid(chan),
364 "context",
"context",
376 "caller_rdnis",
"123456",
379 ast_channel_creationtime(chan), NULL));
383 return AST_TEST_PASS;
386 static int unload_module(
void)
388 AST_TEST_UNREGISTER(channel_blob_create);
389 AST_TEST_UNREGISTER(null_blob);
390 AST_TEST_UNREGISTER(multi_channel_blob_create);
391 AST_TEST_UNREGISTER(multi_channel_blob_snapshots);
392 AST_TEST_UNREGISTER(channel_snapshot_json);
393 AST_TEST_UNREGISTER(channel_redirect_snapshot_json);
398 static int load_module(
void)
400 AST_TEST_REGISTER(channel_blob_create);
401 AST_TEST_REGISTER(null_blob);
402 AST_TEST_REGISTER(multi_channel_blob_create);
403 AST_TEST_REGISTER(multi_channel_blob_snapshots);
404 AST_TEST_REGISTER(channel_snapshot_json);
405 AST_TEST_REGISTER(channel_redirect_snapshot_json);
411 .support_level = AST_MODULE_SUPPORT_CORE,
413 .unload = unload_module
Main Channel structure associated with a channel.
struct ast_channel_snapshot_base * base
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
struct ast_channel_snapshot * snapshot
struct ast_channel * ast_channel_release(struct ast_channel *chan)
Unlink and release reference to a channel.
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
Structure representing a snapshot of channel state.
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
enum stasis_message_type_result stasis_message_type_create(const char *name, struct stasis_message_vtable *vtable, struct stasis_message_type **result)
Create a new message type.
#define ast_strdup(str)
A wrapper for strdup()
struct ast_channel_snapshot * ast_channel_snapshot_create(struct ast_channel *chan)
Generate a snapshot of the channel state. This is an ao2 object, so ao2_cleanup() to deallocate...
struct ast_json * ast_multi_channel_blob_get_json(struct ast_multi_channel_blob *obj)
Retrieve the JSON blob from a ast_multi_channel_blob. Returned ast_json is still owned by obj...
Blob of data associated with a channel.
struct ast_json * ast_json_null(void)
Get the JSON null value.
General Asterisk PBX channel definitions.
void ast_multi_channel_blob_add_channel(struct ast_multi_channel_blob *obj, const char *role, struct ast_channel_snapshot *snapshot)
Add a ast_channel_snapshot to a ast_multi_channel_blob object.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update)
Set the redirecting id information in the Asterisk channel.
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
struct ao2_container * ast_multi_channel_blob_get_channels(struct ast_multi_channel_blob *obj, const char *role)
Retrieve all channel snapshots associated with a specific role from a ast_multi_channel_blob.
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
Redirecting Line information. RDNIS (Redirecting Directory Number Information Service) Where a call d...
struct stasis_message * ast_channel_blob_create(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
Creates a ast_channel_blob message.
void ast_party_redirecting_free(struct ast_party_redirecting *doomed)
Destroy the redirecting information contents.
int ast_json_equal(const struct ast_json *lhs, const struct ast_json *rhs)
Compare two JSON objects.
void ast_party_redirecting_init(struct ast_party_redirecting *init)
Initialize the given redirecting structure.
struct ast_channel_snapshot * ast_multi_channel_blob_get_channel(struct ast_multi_channel_blob *obj, const char *role)
Retrieve a channel snapshot associated with a specific role from a ast_multi_channel_blob.
A multi channel blob data structure for multi_channel_blob stasis messages.
#define AST_TEST_DEFINE(hdr)
Abstract JSON element (object, array, string, int, ...).
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
#define ASTERISK_GPL_KEY
The text the key() function should return.
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_multi_channel_blob * ast_multi_channel_blob_create(struct ast_json *blob)
Create a ast_multi_channel_blob suitable for a stasis_message.
const ast_string_field name