Increase the maximum number of characters in simple SIP messages

I send simple SIP messages with:

exten => 644,1,MessageSend(pjsip:${EXTEN},${MESSAGE(from)})
same => n,Hangup()

My WebRTC application works fine and all the messages go through, except those larger than about 1024 characters. This means there is a hard-coded limit for the maximum number of characters a SIP message can have.

I tried changing ‘MAX_BODY_SIZE 1024’ in ‘res/res_pjsip_messaging.c’, but the result was ‘web socket error’ and got disconnected from Asterisk. To connect again I had to restart Asterisk.

Please tell me how can I send simple SIP messages larger than 1024 characters. (Asterisk 18.0.0 LTS)

I think many other Astersk users will want to send SIP messages larger than 1024 bytes. This limit is so low.

I think you are the only person ever to ask about this limit. Your original thread is Maximum number of characters in simple SIP messages (maybe a moderator can re-open and merge it?) I think most of the minority that use SIP messages use them to create mobile phone SMS messages, which have an even shorter maximum length.

RFC 3428 says that messages are generally short text messages, although it does permit other uses. It also says that out of dialogue requests with a request length (I assume that includes headers) of more than 1,300 bytes should not be issued unless the recipient and network are known to support them.

Yes, in my case the recipient and network are known to support them. I don’t use Asterisk simple SIP messages for SMS. I use them in a WebRTC chat application along with audio/video calls. It functions very well except that this limit is making my application almost unusable. For encrypted messages, 1024 bytes only allow very short messages.

I’m confident that in the near future many users will be interested to send longer messages, since Asterisk will be used more frequently for WebRTC audio/video applications which also need text chat.

An hour ago I compiled Asterisk again with ‘MAX_BODY_SIZE 1048576’ instead of ‘MAX_BODY_SIZE 1024’ in ‘res/res_pjsip_messaging.c’. This time I didn’t get disconnected while trying to send text messages, but as before, messages longer than 1024 bytes didn’t get through.

I’m still hoping somebody will tell me how to increase this limit.

Unless someone has already done so then it’s unlikely anyone knows without labbing up such a thing, and examining everything.

Thank you very much jcolp for your reply. I understand the situation, but can you confirm that ‘MAX_BODY_SIZE 1024’ in ‘res/res_pjsip_messaging.c’ controls the maximum size of the body of a SIP message ?

I don’t know that code, thus my comment about someone having to investigate.

Why do you need to send text that equates to at least 8 different SMS messages?

I think he is trying to emulate something like WhatsApp, where some people will type long messages.

OK but that’s not the same. That’s like saying I’m emulating IRC for this where people type long messages.

The SMS is either going to be GSM-7 (160 characters) or UCS-2 (70 characters). Some carriers (like my ULC) will let you send them up to 2K character messages, however, they will break that up into segments to send to the destination carriers. It will then be up to the destination carriers to do what they want with those messages. My ULC will also concatenate incoming messages based on the User Data Headers in the messages telling them how to rebuild it.

These are carrier level things. So even right now with a 1024 character limit that doesn’t mean the carrier will accept it or even concatenate the messages. So right now at you would have about 7 messages with a GSM-7 message (160) because the UDH’s take up part of the message, that 160 is reduced per message. It would also be around 15 UCS-2 messages.

I mean 1024 is a good chunk of characters for a simple text based message. Now will the other devices, etc. be able to accept that? That’s going to be a per destination/device thing that needs to be figured out.

BlazeStudios, you are right about the character limit of GSM-7 or UCS-2 encoded SMS messages. I’m not trying to send any messages to regular phones via phone carriers.

I have a web application that uses SIP over WebSocket and WebRTC. It loads in a browser, it connects to my remote Asterisk server as a SIP client and I can use it to make SIP audio/video phone calls to other extensions configured on the same Asterisk server. Apart from audio/video calls I also need text chat. What communication app is that without text chat ? So, I’m using Asterisk simple SIP messages for text messages but this 1024 bytes limit is ruining everything, since I also encrypt messages before sending them, so I can only send about 110 characters in one message. Again, these are text messages, not SMS.

I’m trying now to split long messages into pieces, then send them individually and concatenate them at the destination, but since I have to also encrypt them, this proves to be difficult.

If someone knows what needs to be changed in the Asterisk code to increase this message limit, I would greately appreciate it.

And what would the acceptable message length be?

About 1048576 bytes.

I don’t think that will happen. That seems unrealistic.

What do you mean ? I don’t expect Asterisk developers to change future Asterisk versions to accomodate my use case. I see that the 1024 bytes message limit may be appropriate for the way Asterisk is used in general. What I want is to increase that limit in my Asterisk installation in order to use it with the specific application that I mentioned. This can be done, if one knows the precise parameter that needs to be changed in the code. Of course, testing will be needed.

Naive question…

Does encryption create 10x ‘noise?’

Changing the message size might not be just changing one setting. You are increasing the SIP packet size and that is going to cause havoc on things. So there might be more than one place in Asterisk for this change to work properly, not to mention the fact the clients might not be able to handle a SIP packet or a MESSAGE after a certain size.

Yes, in my case it does. It’s RSA encryption. Of course, if they are unicode characters, they will be even fewer.

I know that. I asked here, in the hope that somebody knows precisely what has to be changed or there are users who already did that. The clients will be extensions configured on the same Asterisk server.

That’s not the normal way of using public key encryption!

1024 bytes allows some optimisations in terms of allocating fixed size buffers, possibly on the stack. Whilst I don’t know what the code currently does, your requirement forces the use of fully dynamic memory allocation. It is possible that changing a parameter will break things like the thread stack size, and produce excessive RAM demand at the system level.

I can only really think of two reasons for setting a size limit. One is the use of fixed buffer allocations, and the other is limiting the ability to cause denial of service by running the system out of memory.