From b8aa3248ec9deecf45f535893a34c693b38e508c Mon Sep 17 00:00:00 2001 From: Olle Johansson <oej@edvina.net> Date: Tue, 22 Jan 2008 20:35:10 +0000 Subject: [PATCH] Add a generic function to set the bridged call PVT unique id string as a channel variable BRIDGEPVTCALLID This is important for call tracing in log files and CDRs, so that the SIP callID can be traced along servers. The CHANNEL dialplan function won't work here, since the outbound channel is gone when we need the Call-ID. Other channel drivers may now implement the same function :-), but this patch only supports chan_sip.so. Inspired by (issue #11816) Reported by: ctooley Patch by oej git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@99644 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 15 +++++++++++++++ include/asterisk/channel.h | 3 +++ main/channel.c | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 507ac276e7..6c7c15884e 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -1676,6 +1676,7 @@ static int sip_transfer(struct ast_channel *ast, const char *dest); static int sip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan); static int sip_senddigit_begin(struct ast_channel *ast, char digit); static int sip_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration); +static char *sip_get_callid(struct ast_channel *chan); static int handle_request_do(struct sip_request *req, struct sockaddr_in *sin); static int sip_standard_port(struct sip_socket s); @@ -2036,6 +2037,7 @@ static const struct ast_channel_tech sip_tech = { .early_bridge = ast_rtp_early_bridge, .send_text = sip_sendtext, /* called with chan locked */ .func_channel_read = acf_channel_read, + .get_pvt_uniqueid = sip_get_callid, }; /*! \brief This version of the sip channel tech has no send_digit_begin @@ -3238,6 +3240,15 @@ static int sip_sendhtml(struct ast_channel *chan, int subclass, const char *data return 0; } +/*! \brief Deliver SIP call ID for the call */ +static char *sip_get_callid(struct ast_channel *chan) +{ + struct sip_pvt *p = chan->tech_pvt; + if (!p) + return ""; + return ((char *)p->callid); +} + /*! \brief Send SIP MESSAGE text within a call Called from PBX core sendtext() application */ static int sip_sendtext(struct ast_channel *ast, const char *text) @@ -14381,6 +14392,10 @@ static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, stru manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", "Channel: %s\r\nChanneltype: %s\r\nUniqueid: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\nPeername: %s\r\n", p->owner->name, p->owner->uniqueid, "SIP", p->callid, p->fullcontact, p->peername); + /* Set bridged channel variable */ + bridgepeer = ast_bridged_channel(p->owner); + if (bridgepeer) + pbx_builtin_setvar_helper(bridgepeer, "SIP_BRIDGED_CALLID", p->callid); } else { /* RE-invite */ ast_queue_frame(p->owner, &ast_null_frame); } diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index efb87fde6e..58fec7a468 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -335,6 +335,9 @@ struct ast_channel_tech { /*! \brief Set base channel (agent and local) */ int (* set_base_channel)(struct ast_channel *chan, struct ast_channel *base); + + /*! \brief Get the unique identifier for the PVT, i.e. SIP call-ID for SIP */ + char * (* get_pvt_uniqueid)(struct ast_channel *chan); }; struct ast_epoll_data; diff --git a/main/channel.c b/main/channel.c index d9e0183106..d4d878008b 100644 --- a/main/channel.c +++ b/main/channel.c @@ -4222,6 +4222,10 @@ enum ast_bridge_result ast_channel_bridge(struct ast_channel *c0, struct ast_cha pbx_builtin_setvar_helper(c0, "BRIDGEPEER", c1->name); if (!ast_strlen_zero(pbx_builtin_getvar_helper(c1, "BRIDGEPEER"))) pbx_builtin_setvar_helper(c1, "BRIDGEPEER", c0->name); + if (c0->tech->get_pvt_uniqueid) + pbx_builtin_setvar_helper(c1, "BRIDGEPVTCALLID", c0->tech->get_pvt_uniqueid(c0)); + if (c1->tech->get_pvt_uniqueid) + pbx_builtin_setvar_helper(c0, "BRIDGEPVTCALLID", c1->tech->get_pvt_uniqueid(c1)); if (c0->tech->bridge && (config->timelimit == 0) && -- GitLab