BelledonneCommunications / linphone-sdk

Mirror for linphone-sdk (https://gitlab.linphone.org/BC/public/linphone-sdk.git)
GNU Affero General Public License v3.0
106 stars 81 forks source link

Sip Message Event #111

Closed nick2601 closed 3 years ago

nick2601 commented 3 years ago

We have an usecase in our App for which I need to send a Sip Message Event with some additional Custom Headers and Content Type.I am using message.setContentType and message.addCustomHeader.But I am getting 2 content headers in my outgoing Sip Message Event.

Trace of Request

MESSAGE sip:mcx.test-111.iitb@192.168.0.104 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:39456;branch=z9hG4bK.WhufJ5m0I;rport
From: <sip:mcx.test-111.iitb@192.168.0.103>;tag=gPTMteVWy
To: sip:mcx.test-111.iitb@192.168.0.104
CSeq: 20 MESSAGE
Call-ID: gj53EySfKC
Max-Forwards: 70
Supported: replaces, outbound, gruu
Date: Mon, 01 Feb 2021 08:09:23 GMT
Content-Type: text/plain
Content-Length: 708
User-Agent: NonMCLinphoneAndroid/4.4.0 (Nokia 6.1 Plus) LinphoneSDK/4.5.0-beta.58+5dafa37 (remotes/origin/release/4.5)

Content-Type: application/vnd.3gpp.mcptt-location-info+xml
Content-Length:540
P-Preferred-Identity:<sip:mcx.test-111.iitb@ims.mnc001.mcc001.3gppnetwork.org>

<?xml version="1.0" encoding="UTF-8"?>
<location-info xmlns="urn:3gpp:ns:mcpttLocationInfo:1.0">
<Report ReportType="NonEmergency" ReportID="7dda64d1-5830-1235-3f95-525400f2984b">
<CurrentLocation>
<MbmsSaId type="Normal">
<SaId>2</SaId>
</MbmsSaId>
<MbsfnArea type="Normal">
<MbsfnAreaId>1</MbsfnAreaId>
</MbsfnArea>
<CurrentCoordinate>
<longitude type="Normal">
<threebytes>null</threebytes>
</longitude>
<latitude type="Normal">
<threebytes>null</threebytes>
</latitude>
</CurrentCoordinate>
</CurrentLocation>
</Report>
</location-info>

Thanks in advance for the help.

Viish commented 3 years ago

Please attach the code you use to create & send the message.

nick2601 commented 3 years ago

Please attach the code you use to create & send the message.

Core core = LinphoneManager.getCore();
ProxyConfig proxyConfig = core.getDefaultProxyConfig();
Address address = proxyConfig.getIdentityAddress();
ChatRoom room = core.getChatRoom(address);
ChatMessage message = room.createEmptyMessage();
message.setContentType("app/info.xml");
message.addCutomHeader("abc","xyz");
if (room != null) {
String msg ="Some Content Body";
message.setUtf8Text(msg);
}
message.send;
Viish commented 3 years ago

Try adding the content type and custom header after the setUtf8Text() line. Also note that setUtf8Text() isn't the right method to call, instead use addUtf8TextContent()

Viish commented 3 years ago

Can I close the issue?

nick2601 commented 3 years ago

Can I close the issue?

1.There is still some issue with the addCustomHeader method, it does allows us to add special characters like "<",">","@",etc For eg: I have to send an outgoing Sip Message event with some extra header such as message.addCustomHeader("Identity","abc@org"),when I see the sip trace, I cant see "<",">" characters.

@Viish Is there another callback for consuming incoming sip MESSAGE content body into the app, I have used the onMessageReceived Call from the Core ,but still I am not able to see Incoming Message Body(some xml content).

Thanks in advance for the help.

Viish commented 3 years ago

Is there another callback for consuming incoming sip MESSAGE content body into the app, I have used the onMessageReceived Call from the Core ,but still I am not able to see Incoming Message Body(some xml content).

No, this is the way. If you aren't called in this, means your message is probably discarded for some reason.

For eg: I have to send an outgoing Sip Message event with some extra header such as message.addCustomHeader("Identity","abc@org"),when I see the sip trace, I cant see "<",">" characters.

As always please provide logs showing the issue.

Viish commented 3 years ago

2021-02-09 11:29:00.575 23101-23101/org.linphone.debug E/Linphone: No content-type in the contents list is supported...

This means you are using a ContentType that our SDK doesn't know how to handle. To handle it yourself in your app like you intend to, use core.addContentTypeSupport() method.

Viish commented 3 years ago

For your second issue, problem seems to be the device fails to resolve the domain name "ims.mnc001.mcc001.3gppnetwork.org". It works for the REGISTER because it's sent to a local machine: "192.168.0.104:8642" Check your proxy config, specifically server & route parameters (also known as Outbound Proxy).

nick2601 commented 3 years ago

2021-02-09 11:29:00.575 23101-23101/org.linphone.debug E/Linphone: No content-type in the contents list is supported...

This means you are using a ContentType that our SDK doesn't know how to handle. To handle it yourself in your app like you intend to, use core.addContentTypeSupport() method.

@Viish I could not find method core.addContentTypeSupport() under the Core class. I am using library version 4.5.0 [https://linphone.org/snapshots/docs/liblinphone/4.5.0/java/]

Viish commented 3 years ago

Indeed the method wasn't properly wrapped, it is now fixed: http://linphone.org/snapshots/docs/liblinphone/4.5/java/org/linphone/core/Core.html#addContentTypeSupport-java.lang.String- You need a SDK at least 4.5.0-beta.73+4a5c915.

Viish commented 3 years ago

Inspite of adding core.addContentType() method support for the incoming Sip Message I am not able to consume the incoming Sip message ,I am still getting Unsupported Content Type Header Error

You probably misconfigured the content-type. Please attach logs showing the issue.

Apart from that when my Message is rejected , a new Sip Message is generated automatically(I am not generating this event) ,and sent to server with some weird string in the content body causing to crash the server.

I think you are talking of the IMDN xml message sent to acknowledge reception/display of chat message. If you don't want such messages, use the following configuration:

[sip]
im_notif_policy=none

Whenever I deregister an account and try to register with the same account a Subscribe Event is generated for sip:rls@linphone.org

Simply remove this entry from your config file or set it empty like:

[sip]
rls_uri=

Finally please don't open a ticket on each project we have with the same problem, one ticket per issue is enough.

nick2601 commented 3 years ago

You probably misconfigured the content-type. Please attach logs showing the issue.

1)I have added the supported for the content type using core.addContentTypeSupport,still getting unsupported content-type error.

2)From Logs ,if you can see I get a 200 Ok for an outgoing subscribe withCall Id- jc7mdh9zF1,for which I am expected to get a Notify response which I am listening on onNotifyReceived callback but it looks like I am not able to receive the Notify Response on Linphone.I have verified from the Server Side that a notify is being sent out ,but I am not able to see it. Logs for the same:logs

Viish commented 3 years ago

1)I have added the supported for the content type using core.addContentTypeSupport,still getting unsupported content-type error.

Are you using the following after the core has been initialized?

core.addContentTypeSupport("application/vnd.3gpp.mcptt-info+xml")
core.addContentTypeSupport("application/vnd.3gpp.mcptt-location-info+xml")

I have verified from the Server Side that a notify is being sent out ,but I am not able to see it.

You are connected to your proxy through UDP, which means packets can get lost. Try again with TCP or TLS.

nick2601 commented 3 years ago

1)I have added the supported for the content type using core.addContentTypeSupport,still getting unsupported content-type error.

Are you using the following after the core has been initialized?

core.addContentTypeSupport("application/vnd.3gpp.mcptt-info+xml") core.addContentTypeSupport("application/vnd.3gpp.mcptt-location-info+xml")

Yes I am using after the core has been initialised,which should be under LinphoneManager class if I am not wrong.

Viish commented 3 years ago

Try to wait until core is started then. We have regression tests for that and they are OK.

Viish commented 3 years ago

Use the following:

for (content in chatMessage.contents) {
    android.util.Log.d(TAG, content.utf8Text);
}
Viish commented 3 years ago

1) There is no message received in the logs you attached

2) No NOTIFY in the logs either.

Viish commented 3 years ago

As you can see in the following logs:

2021-02-26 03:52:20:857 [org.linphone.debug/liblinphone] MESSAGE Insert new content type in database: `application/vnd.3gpp.mcptt-info+xml`.
2021-02-26 03:52:20:857 [org.linphone.debug/liblinphone] MESSAGE Insert new content type in database: `application/vnd.3gpp.mcptt-location-info+xml`.
2021-02-26 03:52:20:884 [org.linphone.debug/linphone-android] WARNING [Notifications Manager] Message has no text or file transfer information to display, ignoring it...

Multipart is correctly parsed, each content is stored in the database so chatMessage.getContents() will return both, and the app is notified of the received message.

Regarding your NOTIFY, we don't support out of dialog presence NOTIFY.

I have question ,Lets say I am receiving a certain message from a SipUri which is not my contact will I receive the message? Do I need to create chatroom with the intended sip address from which I am expecting a Sip Message, or the stack handles automatically?

No, you don't have to do anything. If you receive a MESSAGE from a different SIP URI that the one you used to send a message to, a new chat room will be created automatically, and you will be notified of the new chatroom/message in the onMessageReceived callback.

nick2601 commented 3 years ago

Regarding your NOTIFY, we don't support out of dialog presence NOTIFY.

@Viish 1)Can you explain me what is exactly out of dialog presence NOTIFY, and why it is ignored. As per my understanding if the Call ID and Event from the second SUBSCRIBE request is matched correctly with the NOTIFY response going out from server , the Linphone Stack should process it . Can you provide me with some insights how should I handle this issue with respect to server side.

2)Now for the Sip Message ,why I am getting this 2021-02-26 18:57:39.983 16685-16685/org.linphone.debug E/Linphone: body handler [0x723b5f1d00] transfered only [1399] bytes while [2743] were expected Inspite of using chatMessage.getContents() ,I am able to read the contents of application/vnd.3gpp.mcptt-info+xml and the contents of application/vnd.3gpp.mcptt-location-info+xml are still being ignored. I would very likely to have your suggestion on this also.

Thanks in advance for your suggestion.

Viish commented 3 years ago

As per my understanding if the Call ID and Event from the second SUBSCRIBE request is matched correctly with the NOTIFY response going out from server , the Linphone Stack should process it .

Yes, but the To header of the NOTIFY doesn't match the FROM of the subscribe, hence the out of dialog.

why I am getting this

That happens if the Content-Length header doesn't match the content length, but that shouldn't be a problem anyway.

I am able to read the contents of application/vnd.3gpp.mcptt-info+xml and the contents of application/vnd.3gpp.mcptt-location-info+xml are still being ignored.

You are able to read one but not the other?

nick2601 commented 3 years ago

You are able to read one but not the other?

Yeah I was able to read one and not the other:(

Viish commented 3 years ago

Weird. I just added a test to our test suite for your case, it works. Check out liblinphone branch feature/add_generic_content_method

nick2601 commented 3 years ago

Weird. I just added a test to our test suite for your case, it works. Check out liblinphone branch feature/add_generic_content_method

Thanks for the help solved.:)

nick2601 commented 3 years ago

As per my understanding if the Call ID and Event from the second SUBSCRIBE request is matched correctly with the NOTIFY response going out from server , the Linphone Stack should process it .

Yes, but the To header of the NOTIFY doesn't match the FROM of the subscribe, hence the out of dialog.

@Viish But the To header of the NOTIFY matches with Contact Address of the SIP SUBSCRIBE

SUBSCRIBE sip:mcptt-as-mcla-1.ims.mnc001.mcc001.3gppnetwork.org SIP/2.0
Via: SIP/2.0/UDP 172.27.232.105:44263;branch=z9hG4bK.MQV1wJ3DG;rport
From: <sip:mcx.test-111.iitb@ims.mnc001.mcc001.3gppnetwork.org>;tag=Ux9dIH7eh
To: sip:mcptt-as-mcla-1.ims.mnc001.mcc001.3gppnetwork.org
CSeq: 20 SUBSCRIBE
Call-ID: sVhwxkU8Xr
Max-Forwards: 70
Route: <sip:172.31.37.34:7684;lr>
Supported: replaces, outbound, gruu
Event: presence
Expires: 423197357
Content-Type: application/vnd.3gpp.mcptt-info+xml
Content-Length: 320
Contact: <sip:mcx.test-111.iitb@172.27.232.105:44263;transport=udp>;transport=udp;expires=600;+sip.instance="<urn:uuid:168e1fee-0a0f-0038-9ef0-cba44d3df8f7>"
P-Preferred-Identity: sip:mcx.test-111.iitbims.mnc001.mcc001.3gppnetwork.org
P-Preferred-Service: urn:urn-7:3gpp-service.ims.icsi.mcptt
P-Access-Network-Info: ADSL;utran-cell-id-3gpp=00000000
Privacy: none
Accept: application/pidf+xml
User-Agent: NonMCLinphoneAndroid/4.4.0 (Nokia 6.1 Plus) LinphoneSDK/4.5.0-beta.89+4aecab5-debug (pipelines/25895)

<?xml version="1.0" encoding="UTF-8"?>
<mcpttinfo xmlns="urn:3gpp:ns:mcpttInfo:1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mcptt-Params>
<mcptt-request-uri type="Normal">
<mcpttURI>sip:mcptt.test-111.iitb@ims.mnc001.mcc001.3gppnetwork.org</mcpttURI>
</mcptt-request-uri>
</mcptt-Params>
</mcpttinfo>

2021-03-01 11:22:57:642 [org.linphone.debug/liblinphone] MESSAGE LinphoneEvent [0x72a5921c00] moving to subscription state LinphoneSubscriptionOutgoingProgress
2021-03-01 11:22:57:666 [org.linphone.debug/belle-sip] MESSAGE bellesip_wake_lock_acquire(): Android wake lock [belle-sip recv channel] acquired [ref=0x30f2]
2021-03-01 11:22:57:667 [org.linphone.debug/belle-sip] MESSAGE bellesip_wake_lock_acquire(): cast long of wakelock 12530
2021-03-01 11:22:57:667 [org.linphone.debug/belle-sip] MESSAGE channel [0x72a58b5f00]: starting recv background task with id=[30f2].
2021-03-01 11:22:57:667 [org.linphone.debug/belle-sip] MESSAGE channel [0x72a58b5f00]: received [386] new bytes from [UDP://172.31.37.34:7684]:
SIP/2.0 200 OK
Via: SIP/2.0/UDP 172.27.232.105:44263;branch=z9hG4bK.MQV1wJ3DG;rport=44263
From: <sip:mcx.test-111.iitb@ims.mnc001.mcc001.3gppnetwork.org>;tag=Ux9dIH7eh
To: <sip:mcptt-as-mcla-1.ims.mnc001.mcc001.3gppnetwork.org>;tag=NQNeScF4N15Xe
Call-ID: sVhwxkU8Xr
CSeq: 20 SUBSCRIBE
Contact: <sip:172.31.37.34:7684>
User-Agent: MCLabs Registration Server
Content-Length: 0

NOTIFY sip:mcx.test-111.iitb@172.27.232.105:44263;transport=udp SIP/2.0
Via: SIP/2.0/UDP 172.31.37.34:7684;rport;branch=z9hG4bKS8Xjgv9FDjSSQ
Max-Forwards: 70
From: <sip:mcptt-as-mcla-1.ims.mnc001.mcc001.3gppnetwork.org>;tag=p0e7t7Z7javga
To: <sip:mcx.test-111.iitb@172.27.232.105:44263>;transport=udp
Call-ID: sVhwxkU8Xr
CSeq: 32735195 NOTIFY
Accept-Contact: *;+g.3gpp.icsi-ref="urn%3Aurn-7%3A3gpp-service.ims.icsi.mcptt";require;explicit
User-Agent: MCLabs MCX Server
Event: presence
Subscription-State: active;expires=4294967295
Content-Type: application/pidf+xml
Content-Length: 264
P-Asserted-Service: urn:urn-7:3gpp-service.ims.icsi.mcptt
P-Asserted-Identity: <sip:mcptt-as-mcla-1.ims.mnc001.mcc001.3gppnetwork.or>

<?xml version="1.0" encoding="UTF-8"?><presence xmlns="urn:ietf:params:xml:ns:pidf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mcpttPI10="urn:3gpp:ns:mcpttPresInfo:1.0" entity="sip:mcptt.test-111.iitb@ims.mnc001.mcc001.3gppnetwork.org"></presence>

So as per RFC 3261 we can map NOTIFY request to the Contact address of Sip Subscribe Event ,so out of dialog notify should not occur. So what exactly is the reason for the rejection of NOTIFY.

nick2601 commented 3 years ago

@Vish I am suppose to get multiple incoming messages from same contact and I want to store those messages in an Arraylist variable upon their arrival ,and for this I am using this code

@Override
                    public void onMessageReceived(
                            @NonNull Core core,
                            @NonNull ChatRoom chatRoom,
                            @NonNull ChatMessage message) {
                        super.onMessageReceived(core, chatRoom, message);
                        ArrayList<String> textMessage = new ArrayList<>();
                        String xml=null;
                        UserList userList = null;
                        {
                            for (Content c : message.getContents()) {
                                message.getChatRoom();
                                message.hasTextContent();
                                if (c.isText()) {
                                    textMessage.add(c.getUtf8text);
                                }
                                xml = textMessage.get(0);
                                android.util.Log.d(TAG, xml);
                            }
}

Unfortunately,I am not able to read those messages using this approach,Can you suggest some other way in storing the messages in list and retreiving values of one message at a time depending on their arrival. Thanks in advance