mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 20:04:50 +00:00
channel: Add multi-tenant identifier.
This patch introduces a new identifier for channels: tenantid. It's a stringfield on the channel that can be used for general purposes. It will be inherited by other channels the same way that linkedid is. You can set tenantid in a few ways. The first is to set it in the dialplan with the Set and CHANNEL functions: exten => example,1,Set(CHANNEL(tenantid)=My tenant ID) It can also be accessed via CHANNEL: exten => example,2,NoOp(CHANNEL(tenantid)) Another method is to use the new tenantid option for pjsip endpoints in pjsip.conf: [my_endpoint] type=endpoint tenantid=My tenant ID This is considered the best approach since you will be able to see the tenant ID as early as the Newchannel event. It can also be set using set_var in pjsip.conf on the endpoint like setting other channel variable: set_var=CHANNEL(tenantid)=My tenant ID Note that set_var will not show tenant ID on the Newchannel event, however. Tenant ID has also been added to CDR. It's read-only and can be accessed via CDR(tenantid). You can also get the tenant ID of the last channel communicated with via CDR(peertenantid). Tenant ID will also show up in CEL records if it has been set, and the version number has been bumped accordingly. Fixes: #740 UserNote: tenantid has been added to channels. It can be read in dialplan via CHANNEL(tenantid), and it can be set using Set(CHANNEL(tenantid)=My tenant ID). In pjsip.conf, it is recommended to use the new tenantid option for pjsip endpoints (e.g., tenantid=My tenant ID) so that it will show up in Newchannel events. You can set it like any other channel variable using set_var in pjsip.conf as well, but note that this will NOT show up in Newchannel events. Tenant ID is also available in CDR and can be accessed with CDR(tenantid). The peer tenant ID can also be accessed with CDR(peertenantid). CEL includes tenant ID as well if it has been set. UpgradeNote: A new versioned struct (ast_channel_initializers) has been added that gets passed to __ast_channel_alloc_ap. The new function ast_channel_alloc_with_initializers should be used when creating channels that require the use of this struct. Currently the only value in the struct is for tenantid, but now more fields can be added to the struct as necessary rather than the __ast_channel_alloc_ap function. A new option (tenantid) has been added to endpoints in pjsip.conf as well. CEL has had its version bumped to include tenant ID.
This commit is contained in:
19
main/cdr.c
19
main/cdr.c
@@ -765,7 +765,8 @@ struct cdr_object {
|
||||
struct ast_flags flags; /*!< Flags on the CDR */
|
||||
AST_DECLARE_STRING_FIELDS(
|
||||
AST_STRING_FIELD(linkedid); /*!< Linked ID. Cached here as it may change out from party A, which must be immutable */
|
||||
AST_STRING_FIELD(uniqueid); /*!< Unique id of party A. Cached here as it is the master CDR container key */
|
||||
AST_STRING_FIELD(uniqueid); /*!< Unique id of party A. Cached here as it is the master CDR container key */
|
||||
AST_STRING_FIELD(tenantid); /*!< Tenant ID. Cached here because the value can be manipulated through dialplan */
|
||||
AST_STRING_FIELD(name); /*!< Channel name of party A. Cached here as the party A address may change */
|
||||
AST_STRING_FIELD(bridge); /*!< The bridge the party A happens to be in. */
|
||||
AST_STRING_FIELD(appl); /*!< The last accepted application party A was in */
|
||||
@@ -1094,6 +1095,7 @@ static struct cdr_object *cdr_object_alloc(struct ast_channel_snapshot *chan, co
|
||||
ast_string_field_set(cdr, uniqueid, chan->base->uniqueid);
|
||||
ast_string_field_set(cdr, name, chan->base->name);
|
||||
ast_string_field_set(cdr, linkedid, chan->peer->linkedid);
|
||||
ast_string_field_set(cdr, tenantid, chan->base->tenantid);
|
||||
cdr->disposition = AST_CDR_NULL;
|
||||
cdr->sequence = ast_atomic_fetchadd_int(&global_cdr_sequence, +1);
|
||||
cdr->lastevent = *event_time;
|
||||
@@ -1362,6 +1364,7 @@ static struct ast_cdr *cdr_object_create_public_records(struct cdr_object *cdr)
|
||||
ast_copy_string(cdr_copy->lastdata, it_cdr->data, sizeof(cdr_copy->lastdata));
|
||||
ast_copy_string(cdr_copy->dst, it_cdr->exten, sizeof(cdr_copy->dst));
|
||||
ast_copy_string(cdr_copy->dcontext, it_cdr->context, sizeof(cdr_copy->dcontext));
|
||||
ast_copy_string(cdr_copy->tenantid, it_cdr->tenantid, sizeof(cdr_copy->tenantid));
|
||||
|
||||
/* Party B */
|
||||
if (party_b) {
|
||||
@@ -1370,6 +1373,7 @@ static struct ast_cdr *cdr_object_create_public_records(struct cdr_object *cdr)
|
||||
if (!ast_strlen_zero(it_cdr->party_b.userfield)) {
|
||||
snprintf(cdr_copy->userfield, sizeof(cdr_copy->userfield), "%s;%s", it_cdr->party_a.userfield, it_cdr->party_b.userfield);
|
||||
}
|
||||
ast_copy_string(cdr_copy->peertenantid, party_b->base->tenantid, sizeof(cdr_copy->peertenantid));
|
||||
}
|
||||
if (ast_strlen_zero(cdr_copy->userfield) && !ast_strlen_zero(it_cdr->party_a.userfield)) {
|
||||
ast_copy_string(cdr_copy->userfield, it_cdr->party_a.userfield, sizeof(cdr_copy->userfield));
|
||||
@@ -3166,6 +3170,10 @@ void ast_cdr_format_var(struct ast_cdr *cdr, const char *name, char **ret, char
|
||||
ast_copy_string(workspace, cdr->uniqueid, workspacelen);
|
||||
} else if (!strcasecmp(name, "linkedid")) {
|
||||
ast_copy_string(workspace, cdr->linkedid, workspacelen);
|
||||
} else if (!strcasecmp(name, "tenantid")) {
|
||||
ast_copy_string(workspace, cdr->tenantid, workspacelen);
|
||||
} else if (!strcasecmp(name, "peertenantid")) {
|
||||
ast_copy_string(workspace, cdr->peertenantid, workspacelen);
|
||||
} else if (!strcasecmp(name, "userfield")) {
|
||||
ast_copy_string(workspace, cdr->userfield, workspacelen);
|
||||
} else if (!strcasecmp(name, "sequence")) {
|
||||
@@ -3232,6 +3240,7 @@ static const char * const cdr_readonly_vars[] = {
|
||||
"accountcode",
|
||||
"uniqueid",
|
||||
"linkedid",
|
||||
"tenantid",
|
||||
"userfield",
|
||||
"sequence",
|
||||
NULL
|
||||
@@ -3353,6 +3362,14 @@ static int cdr_object_format_property(struct cdr_object *cdr_obj, const char *na
|
||||
ast_copy_string(value, party_a->base->uniqueid, length);
|
||||
} else if (!strcasecmp(name, "linkedid")) {
|
||||
ast_copy_string(value, cdr_obj->linkedid, length);
|
||||
} else if (!strcasecmp(name, "tenantid")) {
|
||||
ast_copy_string(value, party_a->base->tenantid, length);
|
||||
} else if (!strcasecmp(name, "peertenantid")) {
|
||||
if (party_b) {
|
||||
ast_copy_string(value, party_b->base->tenantid, length);
|
||||
} else {
|
||||
ast_copy_string(value, "", length);
|
||||
}
|
||||
} else if (!strcasecmp(name, "userfield")) {
|
||||
ast_copy_string(value, cdr_obj->party_a.userfield, length);
|
||||
} else if (!strcasecmp(name, "sequence")) {
|
||||
|
Reference in New Issue
Block a user