Asterisk incoming message gives: 415 unsupported m

2019-04-11 17:00发布

Me and my project group are trying to set up a PBX with asterisk. We've managed to let it work with just SIP calls and that works perfect. But once we want to try add an XML message to it Asterisk doesn't recognize it and gives "415 Unsupported Media Type". It seems like the call isn't even making it through it is getting rejected immediately.

We have tried to find the piece of code where this gets handled but didn't found anything.

The SIP message that is send to Asterisk looks like this:

Request-Line: MESSAGE sip:701@xxx.xxx.xxx.109 SIP/2.0
  Method: MESSAGE
  Request-URI: sip:701@xxx.xxx.xxx.109
  Via: SIP/2.0/UDP xxx.xxx.xxx.111:5060;branch=z9hG4bK-3f138a53
  To: <sip:701@xxx.xxx.xxx.109>
  From: <sip:702@xxx.xxx.xxx.111>;tag=7a82b127
  Call-ID: 54634d4f2e@xxx.xxx.xxx.111
  CSeq: 104 MESSAGE
  Max-Forwards: 70
  User-Agent: CareIP 7813409 v1.2.4.0
  Content-Type: application/scaip+xml
  Content-Length: 91
Message Body
  <mrq><ref>765745670002</ref<mty>ME</mty><cid>266786</cid><dty>0005</dty><stc>0010</stc></mrq

Our question(s) is/are: Where in the code or config files can we find where asterisk decides whether this is "media type" supported or not?

Or

Does someone know how to add a media type that is not supported (yet) by Asterisk?

2条回答
对你真心纯属浪费
2楼-- · 2019-04-11 17:40

It looks like the accepted Content-Type for a Message is hard-coded, so you won't be able to do this in a config file. If you look at the function receive_message() in channels\chan_sip.c, you will see the following lines:

    if (strncmp(content_type, "text/plain", strlen("text/plain"))) { /* No text/plain attachment */
    transmit_response(p, "415 Unsupported Media Type", req); /* Good enough, or? */

If you modify the strncmp() to also allow "application/scaip+xml" and recompile, it will no longer respond with the 415 Unsupported Media Type error, and you can modify the rest of the receive_message() function to suit your needs.

查看更多
孤傲高冷的网名
3楼-- · 2019-04-11 18:00

You might just use "text/plain" for the Content-Type and handle scaip+xml in your app by automatically detecting it (for example if the message begins with then you can know that it is scaip xml).

查看更多
登录 后发表回答