Module: sip-router
Branch: pd/websocket
Commit: 4611d052b9e73f9b301a043da632e28b7ec65bf4
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=4611d05…
Author: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Date: Sat Jun 23 21:57:37 2012 +0100
modules/websocket: now using libunistring:u8_check() to work out whether to send text or binary websocket frames
- There is no straight-forward (or practical) way to be sure that a SIP request
only contains UTF-8 characters and therefore should be sent as text instead
of binary. However, you can sometimes tell whether the request definitely
isn't UTF-8 by checking for invalid byte sequences - and when it is definitely
not UTF-8 frames _MUST_ be sent as binary.
---
modules/websocket/Makefile | 1 +
modules/websocket/ws_frame.c | 10 +++++-----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/modules/websocket/Makefile b/modules/websocket/Makefile
index dade653..8304bfb 100644
--- a/modules/websocket/Makefile
+++ b/modules/websocket/Makefile
@@ -17,6 +17,7 @@ else
DEFS+= $(shell pkg-config --cflags libssl)
LIBS= $(shell pkg-config --libs libssl)
endif
+LIBS+= -lunistring
DEFS+=-DOPENSER_MOD_INTERFACE
diff --git a/modules/websocket/ws_frame.c b/modules/websocket/ws_frame.c
index 6b565c3..ec5f8a5 100644
--- a/modules/websocket/ws_frame.c
+++ b/modules/websocket/ws_frame.c
@@ -22,6 +22,7 @@
*/
#include <limits.h>
+#include <unistr.h>
#include "../../receive.h"
#include "../../stats.h"
#include "../../str.h"
@@ -592,9 +593,10 @@ int ws_frame_transmit(void *data)
memset(&frame, 0, sizeof(frame));
frame.fin = 1;
- /* Can't be sure whether this message is UTF-8 or not so always send
- as binary */
- frame.opcode = OPCODE_BINARY_FRAME;
+ /* Can't be sure whether this message is UTF-8 or not so check to see
+ if it "might" be UTF-8 and send as binary if it definitely isn't */
+ frame.opcode = (u8_check((uint8_t *) wsev->buf, wsev->len) == NULL) ?
+ OPCODE_TEXT_FRAME: OPCODE_BINARY_FRAME;
frame.payload_len = wsev->len;
frame.payload_data = wsev->buf;
frame.wsc = wsconn_get(wsev->id);
@@ -602,11 +604,9 @@ int ws_frame_transmit(void *data)
if (encode_and_send_ws_frame(&frame, CONN_CLOSE_DONT) < 0)
{
LM_ERR("sending SIP message\n");
- if (wsev->buf) pkg_free(wsev->buf);
return -1;
}
- if (wsev->buf) pkg_free(wsev->buf);
return 0;
}
Hi,
I am just trying to work out exactly what needs to be updated in the
Kamailio core/parser for WebSockets.
I already know that the Via: parser needs to be updated to understand
the WS and WSS transports, and the URI parser needs to be updated to
understand the the WS transport, but is there anything else?
I'd appreciate it if anyone has any ideas about what else might need
changed (and where in the code), as my guessing at this could be a bit
hit-and-miss...
I don't plan to add a forward_ws() function to core because I don't
think it'll work (or at least not in all cases as servers cannot
initiate WebSocket connections). But are there updates needed in the
following areas (and any ideas where in the code I should look)?
* forward_no_connect()
* the proto core variable
* the snd_proto core variable
* Is a WS keyword (like SCTP/TCP/TLS/UDP) needed
* Are the pseudo variables (for example, I know that the mutable
variable $du needs to do the right thing as this is fundamental
to being able to route requests), transformations, and selects
that need to be updated
* Are there any modules (rr, nathelper?) that need to be updated
Thanks for your help,
Peter
--
Peter Dunkley
Technical Director
Crocodile RCS Ltd