[asterisk-bugs] [JIRA] (ASTERISK-28513) Should To: be rewritten when forwarding to a phone

Brian J. Murrell (JIRA) noreply at issues.asterisk.org
Wed Oct 16 08:33:48 CDT 2019


    [ https://issues.asterisk.org/jira/browse/ASTERISK-28513?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=248434#comment-248434 ] 

Brian J. Murrell commented on ASTERISK-28513:
---------------------------------------------

> System name is not guaranteed to be non-empty

Ahhh.  I did account for that in my latest patch but didn't seem to attach it here.  Here it is:

{noformat}
diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -43,6 +43,7 @@
 #include "asterisk/res_pjsip.h"
 #include "asterisk/res_pjsip_session.h"
 #include "asterisk/taskprocessor.h"
+#include "asterisk/paths.h"
 
 const pjsip_method pjsip_message_method = {PJSIP_OTHER_METHOD, {"MESSAGE", 7} };
 
@@ -230,10 +230,17 @@
 	parsed_name_addr = (pjsip_name_addr *) pjsip_parse_uri(tdata->pool, to, strlen(to),
 		PJSIP_PARSE_URI_AS_NAMEADDR);
 	if (parsed_name_addr) {
-		if (pj_strlen(&parsed_name_addr->display)) {
-			pjsip_name_addr *name_addr =
-				(pjsip_name_addr *) PJSIP_MSG_TO_HDR(tdata->msg)->uri;
+		pjsip_sip_uri *uri;
+		pjsip_name_addr *name_addr =
+			(pjsip_name_addr *) PJSIP_MSG_TO_HDR(tdata->msg)->uri;
+		uri = pjsip_uri_get_uri(name_addr);
+		if (!ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
+			pj_str_t my_host = pj_str(ast_config_AST_SYSTEM_NAME);
+			pj_strdup(tdata->pool, &uri->host, &my_host);
+		} else 
+			ast_log(LOG_WARNING, "Unable to rewrite MESSAGE to systemname because systemname (%s) is empty\n", ast_config_AST_SYSTEM_NAME);
 
+		if (pj_strlen(&parsed_name_addr->display)) {
 			pj_strdup(tdata->pool, &name_addr->display, &parsed_name_addr->display);
 		}
 	}
{noformat}

I do get the following warnings when building with this patch applied:

{noformat}
   [CC] res_pjsip_messaging.c -> res_pjsip_messaging.o
res_pjsip_messaging.c: In function 'update_to':
res_pjsip_messaging.c:239:4: warning: passing argument 1 of 'pj_str' discards 'const' qualifier from pointer target type [enabled by default]
    pj_str_t my_host = pj_str(ast_config_AST_SYSTEM_NAME);
    ^
In file included from /home/brian/rpm/BUILD/asterisk-13.29.0/third-party/pjproject/source/pjsip/include/pjsip/sip_transport_tls.h:31:0,
                 from /home/brian/rpm/BUILD/asterisk-13.29.0/third-party/pjproject/source/pjsip/include/pjsip.h:45,
                 from /home/brian/rpm/BUILD/asterisk-13.29.0/third-party/pjproject/source/pjsip/include/pjsua-lib/pjsua.h:30,
                 from res_pjsip_messaging.c:38:
/home/brian/rpm/BUILD/asterisk-13.29.0/third-party/pjproject/source/pjlib/include/pj/string.h:79:20: note: expected 'char *' but argument is of type 'const char *'
 PJ_IDECL(pj_str_t) pj_str(char *str);
                    ^
{noformat}

Casting away the {{const}} doesn't seem like the correct solution though.  Is the correct solution to take a non-const copy of {{ast_config_AST_SYSTEM_NAME}} to pass into {{pj_str()}} or is there a different way to handle this situation with {{pj_str_t}}?

> Should To: be rewritten when forwarding to a phone
> --------------------------------------------------
>
>                 Key: ASTERISK-28513
>                 URL: https://issues.asterisk.org/jira/browse/ASTERISK-28513
>             Project: Asterisk
>          Issue Type: Bug
>      Security Level: None
>          Components: Resources/res_pjsip_messaging
>    Affects Versions: 13.28.0
>            Reporter: Brian J. Murrell
>            Assignee: Unassigned
>            Severity: Minor
>              Labels: pjsip
>
> I have run into a problem with {{MESSAGE}} s and the [Linphone Android client|https://github.com/BelledonneCommunications/linphone-android].
> The [issue|https://github.com/BelledonneCommunications/linphone-android/issues/605] as described in their tracker is that when {{MESSAGE}} s come to the linphone client from the same sender, they can be "filed" into many different threads, rather than all in one chat/thread.  This is because linphone separates chats based on both the From: and To: headers.
> As I am sure you know, the {{To:}} header of a client can vary wildly based on the IP address it's connecting from.  This means that every time the IP address of the SIP client changes, a new chat for the same sender is created.
> But the problem is that Asterisk is setting the {{To:}} header of the {{MESSAGE}} to the {{user at ip_address}} of the remote SIP client and so this means that every time the IP address of the remote SIP client changes, a new To: header is created, and so is a new chat in the SIP client.
> Linphone defends this behaviour by insisting that the {{To:}} header value is a logical value of the recipient for a given domain and should always remain it's logical value no matter whether it's being forwarded on to a SIP client or not.
> So for example, if my Asterisk server is at pbx.example.com and somebody (my VOIP provider for example) send a {{MESSAGE}} to 555-555-1212 at ip-address-of-my-asterisk, when my Asterisk server receives that message and then wants to forward it on to a SIP client, the To: should be {{To:  _recipient_]@pbx.example.com}}, not {{To: _recipient_ at ip-address-of-SIP-client}}.
> They quote [RFC 3261 section 8.1.1.2|https://tools.ietf.org/html/rfc3261#section-8.1.1.2] further in defending this behaviour.  My reading of it doesn't leave me with much to argue against their defence.
> I don't see any way to make Asterisk (with PJSIP) to follow this behaviour.



--
This message was sent by Atlassian JIRA
(v6.2#6252)



More information about the asterisk-bugs mailing list