Skip to content

Commit

Permalink
stasis: Update the snapshot after setting the redirect
Browse files Browse the repository at this point in the history
The previous commit added the caller_rdnis attribute. Make it
avialble during a possible ChanngelHangupRequest.
  • Loading branch information
zecke authored and asterisk-org-access-app[bot] committed Nov 7, 2023
1 parent 69590ba commit 69cf329
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions main/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -9119,6 +9119,7 @@ void ast_channel_set_redirecting(struct ast_channel *chan, const struct ast_part
ast_channel_lock(chan);
ast_party_redirecting_set(ast_channel_redirecting(chan), redirecting, update);
ast_channel_snapshot_invalidate_segment(chan, AST_CHANNEL_SNAPSHOT_INVALIDATE_CALLER);
ast_channel_publish_snapshot(chan);
ast_channel_unlock(chan);
}

Expand Down
78 changes: 78 additions & 0 deletions tests/test_stasis_channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,90 @@ AST_TEST_DEFINE(channel_snapshot_json)
return AST_TEST_PASS;
}

AST_TEST_DEFINE(channel_redirect_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);
struct ast_party_redirecting data;


switch (cmd) {
case TEST_INIT:
info->name = __func__;
info->category = test_category;
info->summary = "Test creation of ast_channel_blob objects with rdnis";
info->description = "Test creation of ast_channel_blob objects with rdnis";
return AST_TEST_NOT_RUN;
case TEST_EXECUTE:
break;
}

ast_test_validate(test, NULL == ast_channel_snapshot_to_json(NULL, NULL));
chan = ast_channel_alloc(0, AST_STATE_DOWN, "cid_num", "cid_name", "acctcode", "exten", "context", NULL, NULL, 0, "TEST/name");
ast_channel_unlock(chan);
ast_test_validate(test, NULL != chan);

ast_channel_lock(chan);
ast_party_redirecting_init(&data);
data.from.number.valid = 1;
data.from.number.str = ast_strdup("123456");
ast_channel_set_redirecting(chan, &data, NULL);
ast_party_redirecting_free(&data);
ast_channel_unlock(chan);

ast_channel_lock(chan);
snapshot = ast_channel_snapshot_create(chan);
ast_channel_unlock(chan);
ast_test_validate(test, NULL != snapshot);

actual = ast_channel_snapshot_to_json(snapshot, NULL);
expected = ast_json_pack("{ s: s, s: s, s: s, s: s, s: s,"
" s: { s: s, s: s, s: i, s: s, s: s },"
" s: { s: s, s: s },"
" s: { s: s, s: s },"
" s: s"
" s: s"
" s: o"
"}",
"name", "TEST/name",
"state", "Down",
"accountcode", "acctcode",
"id", ast_channel_uniqueid(chan),
"protocol_id", "",
"dialplan",
"context", "context",
"exten", "exten",
"priority", 1,
"app_name", "",
"app_data", "",
"caller",
"name", "cid_name",
"number", "cid_num",
"connected",
"name", "",
"number", "",
"language", "en",
"caller_rdnis", "123456",
"creationtime",
ast_json_timeval(
ast_channel_creationtime(chan), NULL));

ast_test_validate(test, ast_json_equal(expected, actual));

return AST_TEST_PASS;
}

static int unload_module(void)
{
AST_TEST_UNREGISTER(channel_blob_create);
AST_TEST_UNREGISTER(null_blob);
AST_TEST_UNREGISTER(multi_channel_blob_create);
AST_TEST_UNREGISTER(multi_channel_blob_snapshots);
AST_TEST_UNREGISTER(channel_snapshot_json);
AST_TEST_UNREGISTER(channel_redirect_snapshot_json);

return 0;
}
Expand All @@ -325,6 +402,7 @@ static int load_module(void)
AST_TEST_REGISTER(multi_channel_blob_create);
AST_TEST_REGISTER(multi_channel_blob_snapshots);
AST_TEST_REGISTER(channel_snapshot_json);
AST_TEST_REGISTER(channel_redirect_snapshot_json);

return AST_MODULE_LOAD_SUCCESS;
}
Expand Down

0 comments on commit 69cf329

Please sign in to comment.