summaryrefslogtreecommitdiff
path: root/res/res_pjsip_transport_websocket.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2014-08-24 19:37:00 +0000
committerJoshua Colp <jcolp@digium.com>2014-08-24 19:37:00 +0000
commit497a92d07905b1e44c5e997f7ce5b2d3baf21e5b (patch)
tree6b400141c830603cf3e679e8668e4650cbb06d0e /res/res_pjsip_transport_websocket.c
parent477e2e6edb5a66091dafdb77f61caa3638c2efd5 (diff)
res_pjsip_transport_websocket: Attach the Websocket module on outgoing INVITEs.
In order to alter the Contact header on in-dialog requests and responses the Websocket module must be attached on outgoing INVITEs. The Contact header is modified so that the PJSIP transport layer can find and use the existing Websocket connection based on the source IP address, port, and transport. ASTERISK-24143 #close Reported by: Aleksei Kulakov ........ Merged revisions 421955 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 421956 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@421957 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pjsip_transport_websocket.c')
-rw-r--r--res/res_pjsip_transport_websocket.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/res/res_pjsip_transport_websocket.c b/res/res_pjsip_transport_websocket.c
index b90b6090a..00d807f68 100644
--- a/res/res_pjsip_transport_websocket.c
+++ b/res/res_pjsip_transport_websocket.c
@@ -341,6 +341,22 @@ static pjsip_module websocket_module = {
.id = -1,
.priority = PJSIP_MOD_PRIORITY_TRANSPORT_LAYER,
.on_rx_request = websocket_on_rx_msg,
+ .on_rx_response = websocket_on_rx_msg,
+};
+
+/*! \brief Function called when an INVITE goes out */
+static void websocket_outgoing_invite_request(struct ast_sip_session *session, struct pjsip_tx_data *tdata)
+{
+ if (session->inv_session->state == PJSIP_INV_STATE_NULL) {
+ pjsip_dlg_add_usage(session->inv_session->dlg, &websocket_module, NULL);
+ }
+}
+
+/*! \brief Supplement for adding Websocket functionality to dialog */
+static struct ast_sip_session_supplement websocket_supplement = {
+ .method = "INVITE",
+ .priority = AST_SIP_SUPPLEMENT_PRIORITY_FIRST + 1,
+ .outgoing_request = websocket_outgoing_invite_request,
};
static int load_module(void)
@@ -352,7 +368,13 @@ static int load_module(void)
return AST_MODULE_LOAD_DECLINE;
}
+ if (ast_sip_session_register_supplement(&websocket_supplement)) {
+ ast_sip_unregister_service(&websocket_module);
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
if (ast_websocket_add_protocol("sip", websocket_cb)) {
+ ast_sip_session_unregister_supplement(&websocket_supplement);
ast_sip_unregister_service(&websocket_module);
return AST_MODULE_LOAD_DECLINE;
}
@@ -363,6 +385,7 @@ static int load_module(void)
static int unload_module(void)
{
ast_sip_unregister_service(&websocket_module);
+ ast_sip_session_unregister_supplement(&websocket_supplement);
ast_websocket_remove_protocol("sip", websocket_cb);
return 0;