[asterisk-commits] qwell: branch qwell/fun_with_transports r384645 - /team/qwell/fun_with_transp...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 3 12:17:59 CDT 2013
Author: qwell
Date: Wed Apr 3 12:17:56 2013
New Revision: 384645
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384645
Log:
Add a session supplement, to force ourselves onto "our" dialogs.
Modified:
team/qwell/fun_with_transports/res/res_sip_transport_websocket.c
Modified: team/qwell/fun_with_transports/res/res_sip_transport_websocket.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/fun_with_transports/res/res_sip_transport_websocket.c?view=diff&rev=384645&r1=384644&r2=384645
==============================================================================
--- team/qwell/fun_with_transports/res/res_sip_transport_websocket.c (original)
+++ team/qwell/fun_with_transports/res/res_sip_transport_websocket.c Wed Apr 3 12:17:56 2013
@@ -25,10 +25,12 @@
#include "asterisk.h"
#include <pjsip.h>
-
+#include <pjsip_ua.h>
+
+#include "asterisk/module.h"
#include "asterisk/http_websocket.h"
#include "asterisk/res_sip.h"
-#include "asterisk/module.h"
+#include "asterisk/res_sip_session.h"
#include "asterisk/taskprocessor.h"
static int transport_type_ws;
@@ -120,6 +122,12 @@
pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&buf, ast_sockaddr_stringify(ast_websocket_remote_address(newtransport->ws_session))), &newtransport->transport.key.rem_addr);
newtransport->transport.key.rem_addr.addr.sa_family = pj_AF_INET();
newtransport->transport.key.type = ast_websocket_is_secure(newtransport->ws_session) ? transport_type_wss : transport_type_ws;
+
+ newtransport->transport.local_name.host.ptr = (char *)pj_pool_alloc(pool, newtransport->transport.addr_len+4);
+ pj_sockaddr_print(&newtransport->transport.key.rem_addr, newtransport->transport.local_name.host.ptr, PJ_INET6_ADDRSTRLEN+4, 0);
+ newtransport->transport.local_name.host.slen = pj_ansi_strlen(newtransport->transport.local_name.host.ptr);
+ newtransport->transport.local_name.port = pj_sockaddr_get_port(&newtransport->transport.key.rem_addr);
+
newtransport->transport.type_name = (char*)pjsip_transport_get_type_name(newtransport->transport.key.type);
newtransport->transport.flag = pjsip_transport_get_flag_from_type((pjsip_transport_type_e)newtransport->transport.key.type);
newtransport->transport.info = (char*) pj_pool_alloc(newtransport->transport.pool, 64);
@@ -217,12 +225,47 @@
ast_websocket_unref(session);
}
+static int websocket_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
+{
+ int type = rdata->tp_info.transport->key.type;
+ if (type == transport_type_ws || type == transport_type_wss) {
+ /* This is one of our transports. We need to force it to use us on the dialog. */
+ pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_TRANSPORT, };
+
+ selector.u.transport = rdata->tp_info.transport;
+
+ pjsip_dlg_set_transport(session->inv_session->dlg, &selector);
+ }
+ return 0;
+}
+
+static void websocket_outgoing_request(struct ast_sip_session *session, struct pjsip_tx_data *tdata)
+{
+ struct pjsip_transport *transport = (struct pjsip_transport*)session->inv_session->dlg->tp_sel.u.transport;
+
+ if (transport->key.type == transport_type_ws || transport->key.type == transport_type_wss) {
+ /* Avoid DNS resolution, so it doesn't try to resolve a bogus address. */
+ tdata->dest_info.addr.count = 1;
+ tdata->dest_info.addr.entry[0].type = transport->key.type;
+ tdata->dest_info.addr.entry[0].addr = transport->key.rem_addr;
+ tdata->dest_info.addr.entry[0].addr_len = transport->addr_len;
+ }
+}
+
+static struct ast_sip_session_supplement websocket_supplement = {
+ .incoming_request = websocket_incoming_request,
+ .outgoing_request = websocket_outgoing_request,
+};
+
static int load_module(void)
{
+ ast_websocket_add_protocol("sip", websocket_cb);
+
pjsip_transport_register_type(PJSIP_TRANSPORT_RELIABLE, "WS", 5060, &transport_type_ws);
pjsip_transport_register_type(PJSIP_TRANSPORT_RELIABLE, "WSS", 5060, &transport_type_wss);
- ast_websocket_add_protocol("sip", websocket_cb);
+ ast_sip_session_register_supplement(&websocket_supplement);
+
return AST_MODULE_LOAD_SUCCESS;
}
More information about the asterisk-commits
mailing list