]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix SIP connected line updates.
authorRichard Mudgett <rmudgett@digium.com>
Fri, 6 May 2011 16:19:18 +0000 (16:19 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Fri, 6 May 2011 16:19:18 +0000 (16:19 +0000)
This patch fixes a couple SIP connected line update problems:

1) The connected line needs to be updated when the initial INVITE is sent
if there is a peer callerid configured.  Previously, the connected line
information did not get reported until the call was connected so SIP could
not report connected line information in ringing or progress messages.

2) The connected line should not be updated on initial connect if there is
no connected line information.  Previously, all it did was wipe out any
default preset CONNECTEDLINE information set by the dialplan with empty
strings.

(closes issue #18367)
Reported by: GeorgeKonopacki
Patches:
      issue18367_v1.8.patch uploaded by rmudgett (license 664)
Tested by: rmudgett

Review: https://reviewboard.asterisk.org/r/1199/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@317670 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c

index 05705cba6231e51fdb7f83baaa23845f1847e74c..773ebb4873e854d3a534bde9135bbe96d1fcde4d 100644 (file)
@@ -5375,8 +5375,34 @@ static int sip_call(struct ast_channel *ast, char *dest, int timeout)
                res = -1;
        } else {
                int xmitres;
+               struct ast_party_connected_line connected;
+               struct ast_set_party_connected_line update_connected;
 
                sip_pvt_lock(p);
+
+               /* Supply initial connected line information if available. */
+               memset(&update_connected, 0, sizeof(update_connected));
+               ast_party_connected_line_init(&connected);
+               if (!ast_strlen_zero(p->cid_num)
+                       || (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
+                       update_connected.id.number = 1;
+                       connected.id.number.valid = 1;
+                       connected.id.number.str = (char *) p->cid_num;
+                       connected.id.number.presentation = p->callingpres;
+               }
+               if (!ast_strlen_zero(p->cid_name)
+                       || (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
+                       update_connected.id.name = 1;
+                       connected.id.name.valid = 1;
+                       connected.id.name.str = (char *) p->cid_name;
+                       connected.id.name.presentation = p->callingpres;
+               }
+               if (update_connected.id.number || update_connected.id.name) {
+                       connected.id.tag = (char *) p->cid_tag;
+                       connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
+                       ast_channel_queue_connected_line_update(ast, &connected, &update_connected);
+               }
+
                xmitres = transmit_invite(p, SIP_INVITE, 1, 2, uri);
                sip_pvt_unlock(p);
                if (xmitres == XMIT_ERROR)
@@ -12380,15 +12406,18 @@ static void update_connectedline(struct sip_pvt *p, const void *data, size_t dat
                        ast_set_flag(&p->flags[0], SIP_NEEDREINVITE);
                }
        } else {
+               ast_set_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
                if (ast_test_flag(&p->flags[1], SIP_PAGE2_RPID_IMMEDIATE)) {
                        struct sip_request resp;
 
                        if ((p->owner->_state == AST_STATE_RING) && !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT)) {
+                               ast_clear_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
                                respprep(&resp, p, "180 Ringing", &p->initreq);
                                add_rpid(&resp, p);
                                send_response(p, &resp, XMIT_UNRELIABLE, 0);
                                ast_set_flag(&p->flags[0], SIP_RINGING);
                        } else if (p->owner->_state == AST_STATE_RINGING) {
+                               ast_clear_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
                                respprep(&resp, p, "183 Session Progress", &p->initreq);
                                add_rpid(&resp, p);
                                send_response(p, &resp, XMIT_UNRELIABLE, 0);
@@ -12396,8 +12425,6 @@ static void update_connectedline(struct sip_pvt *p, const void *data, size_t dat
                        } else {
                                ast_debug(1, "Unable able to send update to '%s' in state '%s'\n", p->owner->name, ast_state2str(p->owner->_state));
                        }
-               } else {
-                       ast_set_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND);
                }
        }
 }
@@ -19150,20 +19177,20 @@ static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest
                        ast_log(LOG_WARNING, "Unable to cancel SIP destruction.  Expect bad things.\n");
                if (!req->ignore && p->owner) {
                        if (get_rpid(p, req)) {
+                               /* Queue a connected line update */
                                ast_party_connected_line_init(&connected);
                                memset(&update_connected, 0, sizeof(update_connected));
-                               if (p->cid_num) {
-                                       update_connected.id.number = 1;
-                                       connected.id.number.valid = 1;
-                                       connected.id.number.str = (char *) p->cid_num;
-                                       connected.id.number.presentation = p->callingpres;
-                               }
-                               if (p->cid_name) {
-                                       update_connected.id.name = 1;
-                                       connected.id.name.valid = 1;
-                                       connected.id.name.str = (char *) p->cid_name;
-                                       connected.id.name.presentation = p->callingpres;
-                               }
+
+                               update_connected.id.number = 1;
+                               connected.id.number.valid = 1;
+                               connected.id.number.str = (char *) p->cid_num;
+                               connected.id.number.presentation = p->callingpres;
+
+                               update_connected.id.name = 1;
+                               connected.id.name.valid = 1;
+                               connected.id.name.str = (char *) p->cid_name;
+                               connected.id.name.presentation = p->callingpres;
+
                                connected.id.tag = (char *) p->cid_tag;
                                connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
                                ast_channel_queue_connected_line_update(p->owner, &connected,
@@ -19215,18 +19242,17 @@ static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest
                                /* Queue a connected line update */
                                ast_party_connected_line_init(&connected);
                                memset(&update_connected, 0, sizeof(update_connected));
-                               if (p->cid_num) {
-                                       update_connected.id.number = 1;
-                                       connected.id.number.valid = 1;
-                                       connected.id.number.str = (char *) p->cid_num;
-                                       connected.id.number.presentation = p->callingpres;
-                               }
-                               if (p->cid_name) {
-                                       update_connected.id.name = 1;
-                                       connected.id.name.valid = 1;
-                                       connected.id.name.str = (char *) p->cid_name;
-                                       connected.id.name.presentation = p->callingpres;
-                               }
+
+                               update_connected.id.number = 1;
+                               connected.id.number.valid = 1;
+                               connected.id.number.str = (char *) p->cid_num;
+                               connected.id.number.presentation = p->callingpres;
+
+                               update_connected.id.name = 1;
+                               connected.id.name.valid = 1;
+                               connected.id.name.str = (char *) p->cid_name;
+                               connected.id.name.presentation = p->callingpres;
+
                                connected.id.tag = (char *) p->cid_tag;
                                connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
                                ast_channel_queue_connected_line_update(p->owner, &connected,
@@ -19268,26 +19294,37 @@ static void handle_response_invite(struct sip_pvt *p, int resp, const char *rest
                        ast_rtp_instance_activate(p->rtp);
                }
 
-               if (!req->ignore && p->owner && (get_rpid(p, req) || !reinvite)) {
-                       /* Queue a connected line update */
-                       ast_party_connected_line_init(&connected);
-                       memset(&update_connected, 0, sizeof(update_connected));
-                       if (p->cid_num) {
-                               update_connected.id.number = 1;
-                               connected.id.number.valid = 1;
-                               connected.id.number.str = (char *) p->cid_num;
-                               connected.id.number.presentation = p->callingpres;
-                       }
-                       if (p->cid_name) {
-                               update_connected.id.name = 1;
-                               connected.id.name.valid = 1;
-                               connected.id.name.str = (char *) p->cid_name;
-                               connected.id.name.presentation = p->callingpres;
+               if (!req->ignore && p->owner) {
+                       int rpid_changed;
+
+                       rpid_changed = get_rpid(p, req);
+                       if (rpid_changed || !reinvite) {
+                               /* Queue a connected line update */
+                               ast_party_connected_line_init(&connected);
+                               memset(&update_connected, 0, sizeof(update_connected));
+                               if (rpid_changed
+                                       || !ast_strlen_zero(p->cid_num)
+                                       || (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
+                                       update_connected.id.number = 1;
+                                       connected.id.number.valid = 1;
+                                       connected.id.number.str = (char *) p->cid_num;
+                                       connected.id.number.presentation = p->callingpres;
+                               }
+                               if (rpid_changed
+                                       || !ast_strlen_zero(p->cid_name)
+                                       || (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) {
+                                       update_connected.id.name = 1;
+                                       connected.id.name.valid = 1;
+                                       connected.id.name.str = (char *) p->cid_name;
+                                       connected.id.name.presentation = p->callingpres;
+                               }
+                               if (update_connected.id.number || update_connected.id.name) {
+                                       connected.id.tag = (char *) p->cid_tag;
+                                       connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
+                                       ast_channel_queue_connected_line_update(p->owner, &connected,
+                                               &update_connected);
+                               }
                        }
-                       connected.id.tag = (char *) p->cid_tag;
-                       connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
-                       ast_channel_queue_connected_line_update(p->owner, &connected,
-                               &update_connected);
                }
 
                /* Parse contact header for continued conversation */
@@ -21160,20 +21197,20 @@ static int handle_request_update(struct sip_pvt *p, struct sip_request *req)
        if (get_rpid(p, req)) {
                struct ast_party_connected_line connected;
                struct ast_set_party_connected_line update_connected;
+
                ast_party_connected_line_init(&connected);
                memset(&update_connected, 0, sizeof(update_connected));
-               if (p->cid_num) {
-                       update_connected.id.number = 1;
-                       connected.id.number.valid = 1;
-                       connected.id.number.str = (char *) p->cid_num;
-                       connected.id.number.presentation = p->callingpres;
-               }
-               if (p->cid_name) {
-                       update_connected.id.name = 1;
-                       connected.id.name.valid = 1;
-                       connected.id.name.str = (char *) p->cid_name;
-                       connected.id.name.presentation = p->callingpres;
-               }
+
+               update_connected.id.number = 1;
+               connected.id.number.valid = 1;
+               connected.id.number.str = (char *) p->cid_num;
+               connected.id.number.presentation = p->callingpres;
+
+               update_connected.id.name = 1;
+               connected.id.name.valid = 1;
+               connected.id.name.str = (char *) p->cid_name;
+               connected.id.name.presentation = p->callingpres;
+
                connected.id.tag = (char *) p->cid_tag;
                connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;
                ast_channel_queue_connected_line_update(p->owner, &connected, &update_connected);
@@ -21505,18 +21542,17 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int
 
                                ast_party_connected_line_init(&connected);
                                memset(&update_connected, 0, sizeof(update_connected));
-                               if (p->cid_num) {
-                                       update_connected.id.number = 1;
-                                       connected.id.number.valid = 1;
-                                       connected.id.number.str = (char *) p->cid_num;
-                                       connected.id.number.presentation = p->callingpres;
-                               }
-                               if (p->cid_name) {
-                                       update_connected.id.name = 1;
-                                       connected.id.name.valid = 1;
-                                       connected.id.name.str = (char *) p->cid_name;
-                                       connected.id.name.presentation = p->callingpres;
-                               }
+
+                               update_connected.id.number = 1;
+                               connected.id.number.valid = 1;
+                               connected.id.number.str = (char *) p->cid_num;
+                               connected.id.number.presentation = p->callingpres;
+
+                               update_connected.id.name = 1;
+                               connected.id.name.valid = 1;
+                               connected.id.name.str = (char *) p->cid_name;
+                               connected.id.name.presentation = p->callingpres;
+
                                connected.id.tag = (char *) p->cid_tag;
                                connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER;
                                ast_channel_queue_connected_line_update(p->owner, &connected,