baresip/re

websocket messages should be sent as text instead of binary

pitti98 opened this issue · 3 comments

This is not a bug per se, it just makes working with wireshark easier because then it properly decodes the SIP content. The browser sends them as text, too.

diff --git a/src/sip/transp.c b/src/sip/transp.c
index 6429157..68d9454 100644
--- a/src/sip/transp.c
+++ b/src/sip/transp.c
@@ -1475,7 +1475,7 @@ int sip_transp_send(struct sip_connqent **qentp, struct sip *sip, void *sock,
 
                        trace_send(sip, tp, conn, &dsttmp, mb);
 
-                       err = websock_send(conn->websock_conn, WEBSOCK_BIN,
+                       err = websock_send(conn->websock_conn, WEBSOCK_TEXT,
                                           "%b",
                                           mbuf_buf(mb), mbuf_get_left(mb));
                        if (err) {

The call to websock_send() in transp.c/ws_conn_send() should be changed as well.

not sure about this. We should follow the RFC:

https://datatracker.ietf.org/doc/html/rfc7118#section-4.2

[4.2](https://datatracker.ietf.org/doc/html/rfc7118#section-4.2).  SIP Encoding

   WebSocket messages can be transported in either UTF-8 text frames or
   binary frames.  SIP [[RFC3261](https://datatracker.ietf.org/doc/html/rfc3261)] allows both text and binary bodies in
   SIP requests and responses.  Therefore, SIP WebSocket Clients and SIP
   WebSocket Servers MUST accept both text and binary frames.

      If there is at least one non-UTF-8 symbol in the whole SIP message
      (including headers and the body), then the whole message MUST be
      sent within a WebSocket binary message.  Given the nature of
      JavaScript and the WebSocket API, it is RECOMMENDED to use UTF-8
      encoding (or ASCII, which is a subset of UTF-8) for SIP messages
      carried over a WebSocket connection.

I would prefer to use Binary mode all the time.