summaryrefslogtreecommitdiff
path: root/channels/chan_sip.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2010-05-17 15:36:31 +0000
committerMark Michelson <mmichelson@digium.com>2010-05-17 15:36:31 +0000
commitb5d5cc565fadf7427c567267f935f0402423dd70 (patch)
treee0f98e5d12f079b7d8f94c031808eaea340b8065 /channels/chan_sip.c
parentfa5350f7d7b538dcd1402390f44d2f4722652d3c (diff)
Enhancements to connected line and redirecting work.
From reviewboard: Digium has a commercial customer who has made extensive use of the connected party and redirecting information present in later versions of Asterisk Business Edition and which is to be in the upcoming 1.8 release. Through their use of the feature, new problems and solutions have come about. This patch adds several enhancements to maximize usage of the connected party and redirecting information functionality. First, Asterisk trunk already had connected line interception macros. These macros allow you to manipulate connected line information before it was sent out to its target. This patch adds the same feature except for redirecting information instead. Second, the ast_callerid and ast_party_id structures have been enhanced to provide a "tag." This tag can be set with func_callerid, func_connectedline, func_redirecting, and in the case of DAHDI, mISDN, and SIP channels, can be set in a configuration file. The idea behind the callerid tag is that it can be set to whatever value the administrator likes. Later, when running connected line and redirecting macros, the admin can read the tag off the appropriate structure to determine what action to take. You can think of this sort of like a channel variable, except that instead of having the variable associated with a channel, the variable is associated with a specific identity within Asterisk. Third, app_dial has two new options, s and u. The s option lets a dialplan writer force a specific caller ID tag to be placed on the outgoing channel. The u option allows the dialplan writer to force a specific calling presentation value on the outgoing channel. Fourth, there is a new control frame subclass called AST_CONTROL_READ_ACTION added. This was added to correct a very specific situation. In the case of SIP semi-attended (blond) transfers, the party being transferred would not have the opportunity to run a connected line interception macro to possibly alter the transfer target's connected line information. The issue here was that during a blond transfer, the SIP transfer code has no bridged channel on which to queue the connected line update. The way this was corrected was to add this new control frame subclass. Now, we queue an AST_CONTROL_READ_ACTION frame on the channel on which the connected line interception macro should be run. When ast_read is called to read the frame, ast_read responds by calling a callback function associated with the specific read action the control frame describes. In this case, the action taken is to run the connected line interception macro on the transferee's channel. Review: https://reviewboard.asterisk.org/r/652/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@263541 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r--channels/chan_sip.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 6fe3e1c6f..d0a876659 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -4741,6 +4741,7 @@ static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
ast_string_field_set(dialog, context, peer->context);
ast_string_field_set(dialog, cid_num, peer->cid_num);
ast_string_field_set(dialog, cid_name, peer->cid_name);
+ ast_string_field_set(dialog, cid_tag, peer->cid_tag);
ast_string_field_set(dialog, mwi_from, peer->mwi_from);
ast_string_field_set(dialog, parkinglot, peer->parkinglot);
ast_string_field_set(dialog, engine, peer->engine);
@@ -6281,6 +6282,7 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit
ast_channel_lock(tmp);
sip_pvt_lock(i);
ast_channel_cc_params_init(tmp, i->cc_params);
+ tmp->cid.cid_tag = ast_strdup(i->cid_tag);
ast_channel_unlock(tmp);
tmp->tech = ( ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INFO || ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_SHORTINFO) ? &sip_tech_info : &sip_tech;
@@ -13395,7 +13397,11 @@ static int get_rdnis(struct sip_pvt *p, struct sip_request *oreq, char **name, c
params++;
/* Check if we have a reason parameter */
if ((reason_param = strcasestr(params, "reason="))) {
+ char *end;
reason_param+=7;
+ if ((end = strchr(reason_param, ';'))) {
+ *end = '\0';
+ }
/* Remove enclosing double-quotes */
if (*reason_param == '"')
ast_strip_quoted(reason_param, "\"", "\"");
@@ -14118,6 +14124,8 @@ static enum check_auth_result check_peer_ok(struct sip_pvt *p, char *of,
}
if (!ast_strlen_zero(peer->cid_name))
ast_string_field_set(p, cid_name, peer->cid_name);
+ if (!ast_strlen_zero(peer->cid_tag))
+ ast_string_field_set(p, cid_tag, peer->cid_tag);
if (peer->callingpres)
p->callingpres = peer->callingpres;
}
@@ -17527,6 +17535,7 @@ static void change_redirecting_information(struct sip_pvt *p, struct sip_request
ast_debug(3, "Got redirecting from name %s\n", redirecting_from_name);
redirecting->from.name = redirecting_from_name;
}
+ redirecting->from.tag = (char *) p->cid_tag;
if (!ast_strlen_zero(redirecting_to_number)) {
if (redirecting->to.number) {
ast_free(redirecting->to.number);
@@ -17541,6 +17550,7 @@ static void change_redirecting_information(struct sip_pvt *p, struct sip_request
ast_debug(3, "Got redirecting to name %s\n", redirecting_from_number);
redirecting->to.name = redirecting_to_name;
}
+ redirecting->to.tag = (char *) p->cid_tag;
redirecting->reason = reason;
}
@@ -17888,6 +17898,7 @@ static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest
ast_party_connected_line_init(&connected);
connected.id.number = (char *) p->cid_num;
connected.id.name = (char *) p->cid_name;
+ connected.id.tag = (char *) p->cid_tag;
connected.id.number_presentation = p->callingpres;
connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
ast_channel_queue_connected_line_update(p->owner, &connected);
@@ -17932,6 +17943,7 @@ static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest
ast_party_connected_line_init(&connected);
connected.id.number = (char *) p->cid_num;
connected.id.name = (char *) p->cid_name;
+ connected.id.tag = (char *) p->cid_tag;
connected.id.number_presentation = p->callingpres;
connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
ast_channel_queue_connected_line_update(p->owner, &connected);
@@ -17977,6 +17989,7 @@ static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest
ast_party_connected_line_init(&connected);
connected.id.number = (char *) p->cid_num;
connected.id.name = (char *) p->cid_name;
+ connected.id.tag = (char *) p->cid_tag;
connected.id.number_presentation = p->callingpres;
connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
ast_channel_queue_connected_line_update(p->owner, &connected);
@@ -20121,6 +20134,7 @@ static int handle_request_update(struct sip_pvt *p, struct sip_request *req)
ast_party_connected_line_init(&connected);
connected.id.number = (char *) p->cid_num;
connected.id.name = (char *) p->cid_name;
+ connected.id.tag = (char *) p->cid_tag;
connected.id.number_presentation = p->callingpres;
connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;
ast_channel_queue_connected_line_update(p->owner, &connected);
@@ -20448,6 +20462,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int
ast_party_connected_line_init(&connected);
connected.id.number = (char *) p->cid_num;
connected.id.name = (char *) p->cid_name;
+ connected.id.tag = (char *) p->cid_tag;
connected.id.number_presentation = p->callingpres;
connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;
ast_channel_queue_connected_line_update(p->owner, &connected);
@@ -21073,11 +21088,30 @@ static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *
ast_channel_queue_connected_line_update(target.chan2, &connected_to_target);
} else {
/* Since target.chan1 isn't actually connected to another channel, there is no way for us
- * to queue a frame so that its connected line status will be updated. Instead, we have to
- * change it directly. Since we are not the channel thread, we cannot run a connected line
- * interception macro on target.chan1
+ * to queue a frame so that its connected line status will be updated.
+ *
+ * Instead, we use the somewhat hackish approach of using a special control frame type that
+ * instructs ast_read to perform a specific action. In this case, the frame we queue tells
+ * ast_read to call the connected line interception macro configured for target.chan1.
+ */
+ struct ast_control_read_action_payload *frame_payload;
+ int payload_size;
+ int frame_size;
+ unsigned char connected_line_data[1024];
+ payload_size = ast_connected_line_build_data(connected_line_data, sizeof(connected_line_data), &connected_to_target);
+ frame_size = payload_size + sizeof(*frame_payload);
+ if (payload_size != -1 && (frame_payload = alloca(frame_size))) {
+ frame_payload->payload_size = payload_size;
+ memcpy(frame_payload->payload, connected_line_data, payload_size);
+ frame_payload->action = AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO;
+ ast_queue_control_data(target.chan1, AST_CONTROL_READ_ACTION, frame_payload, frame_size);
+ }
+ /* In addition to queueing the read action frame so that target.chan1's connected line info
+ * will be updated, we also are going to queue a plain old connected line update on target.chan1. This
+ * way, either Dial or Queue can apply this connected line update to the outgoing ringing channel.
*/
- ast_channel_update_connected_line(target.chan1, &connected_to_target);
+ ast_channel_queue_connected_line_update(target.chan1, &connected_to_transferee);
+
}
ast_channel_unref(current->chan1);
}
@@ -24718,6 +24752,7 @@ static void set_peer_defaults(struct sip_peer *peer)
ast_string_field_set(peer, md5secret, "");
ast_string_field_set(peer, cid_num, "");
ast_string_field_set(peer, cid_name, "");
+ ast_string_field_set(peer, cid_tag, "");
ast_string_field_set(peer, fromdomain, "");
ast_string_field_set(peer, fromuser, "");
ast_string_field_set(peer, regexten, "");
@@ -24933,6 +24968,8 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
ast_string_field_set(peer, cid_name, "");
} else if (!strcasecmp(v->name, "cid_number")) {
ast_string_field_set(peer, cid_num, v->value);
+ } else if (!strcasecmp(v->name, "cid_tag")) {
+ ast_string_field_set(peer, cid_tag, v->value);
} else if (!strcasecmp(v->name, "context")) {
ast_string_field_set(peer, context, v->value);
ast_set_flag(&peer->flags[1], SIP_PAGE2_HAVEPEERCONTEXT);