struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(ast);
char *uniqueid = ast_threadstorage_get(&uniqueid_threadbuf, UNIQUEID_BUFSIZE);
- if (!uniqueid) {
+ if (!channel || !uniqueid) {
return "";
}
--- /dev/null
+Subject: ari
+Subject: stasis_channels
+
+Expose channel driver's unique id (which is the Call-ID for SIP/PJSIP)
+to ARI channel resources as 'protocol_id'.
+
+ASTERISK-30027
struct varshead *manager_vars; /*!< Variables to be appended to manager events */
int tech_properties; /*!< Properties of the channel's technology */
struct varshead *ari_vars; /*!< Variables to be appended to ARI events */
+
+ AST_STRING_FIELD_EXTENDED(protocol_id); /*!< Channel driver protocol id (i.e. Call-ID for chan_sip/chan_pjsip) */
};
/*!
snapshot = ao2_alloc_options(sizeof(*snapshot), channel_snapshot_dtor,
AO2_ALLOC_OPT_LOCK_NOLOCK);
- if (!snapshot || ast_string_field_init(snapshot, 1024)) {
+ if (!snapshot || ast_string_field_init(snapshot, 1024) || ast_string_field_init_extended(snapshot, protocol_id)) {
ao2_cleanup(snapshot);
return NULL;
}
snapshot->ari_vars = ast_channel_get_ari_vars(chan);
snapshot->tech_properties = ast_channel_tech(chan)->properties;
+ if (ast_channel_tech(chan)->get_pvt_uniqueid) {
+ ast_string_field_set(snapshot, protocol_id, ast_channel_tech(chan)->get_pvt_uniqueid(chan));
+ }
+
return snapshot;
}
}
json_chan = ast_json_pack(
- /* Broken up into groups of three for readability */
- "{ s: s, s: s, s: s,"
+ /* Broken up into groups for readability */
+ "{ s: s, s: s, s: s, s: s,"
" s: o, s: o, s: s,"
" s: o, s: o, s: s }",
/* First line */
"id", snapshot->uniqueid,
"name", snapshot->name,
"state", ast_state2str(snapshot->state),
+ "protocol_id", snapshot->protocol_id,
/* Second line */
"caller", ast_json_name_number(
snapshot->caller_name, snapshot->caller_number),
int has_id = 0;
int has_language = 0;
int has_name = 0;
+ int has_protocol_id = 0;
int has_state = 0;
for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
res = 0;
}
} else
+ if (strcmp("protocol_id", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_protocol_id = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Channel field protocol_id failed validation\n");
+ res = 0;
+ }
+ } else
if (strcmp("state", ast_json_object_iter_key(iter)) == 0) {
int prop_is_valid;
has_state = 1;
res = 0;
}
+ if (!has_protocol_id) {
+ ast_log(LOG_ERROR, "ARI Channel missing required field protocol_id\n");
+ res = 0;
+ }
+
if (!has_state) {
ast_log(LOG_ERROR, "ARI Channel missing required field state\n");
res = 0;
* - id: string (required)
* - language: string (required)
* - name: string (required)
+ * - protocol_id: string (required)
* - state: string (required)
* Dialed
* DialplanCEP
"type": "string",
"description": "Unique identifier of the channel.\n\nThis is the same as the Uniqueid field in AMI."
},
+ "protocol_id": {
+ "required": true,
+ "type": "string",
+ "description": "Protocol id from underlying channel driver (i.e. Call-ID for chan_sip/chan_pjsip; will be empty if not applicable or not implemented by driver)."
+ },
"name": {
"required": true,
"type": "string",
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,"
+ 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 },"
"state", "Down",
"accountcode", "acctcode",
"id", ast_channel_uniqueid(chan),
+ "protocol_id", "",
"dialplan",
"context", "context",
"exten", "exten",