Module: kamailio Branch: master Commit: 11980eff7b72e05d400a0c9b865e12bd8c4d3762 URL: https://github.com/kamailio/kamailio/commit/11980eff7b72e05d400a0c9b865e12bd...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2016-12-22T21:44:10+01:00
websocket: implemented ws.enable and ws.disable rpc commands
---
Modified: src/modules/websocket/websocket.c Modified: src/modules/websocket/ws_handshake.c Modified: src/modules/websocket/ws_handshake.h
---
Diff: https://github.com/kamailio/kamailio/commit/11980eff7b72e05d400a0c9b865e12bd... Patch: https://github.com/kamailio/kamailio/commit/11980eff7b72e05d400a0c9b865e12bd...
---
diff --git a/src/modules/websocket/websocket.c b/src/modules/websocket/websocket.c index abfd127..7f885e3 100644 --- a/src/modules/websocket/websocket.c +++ b/src/modules/websocket/websocket.c @@ -382,11 +382,23 @@ static const char* ws_rpc_pong_doc[2] = { 0 };
+static const char* ws_rpc_enable_doc[2] = { + "Enable websocket connection handling", + 0 +}; + +static const char* ws_rpc_disable_doc[2] = { + "Disable websocket connection handling", + 0 +}; + rpc_export_t ws_rpc_cmds[] = { {"ws.dump", ws_rpc_dump, ws_rpc_dump_doc, 0}, {"ws.close", ws_rpc_close, ws_rpc_close_doc, 0}, {"ws.ping", ws_rpc_ping, ws_rpc_ping_doc, 0}, {"ws.pong", ws_rpc_pong, ws_rpc_pong_doc, 0}, + {"ws.enable", ws_rpc_enable, ws_rpc_enable_doc, 0}, + {"ws.disable", ws_rpc_disable, ws_rpc_disable_doc, 0}, {0, 0, 0, 0} };
diff --git a/src/modules/websocket/ws_handshake.c b/src/modules/websocket/ws_handshake.c index 7d547e5..c931fa2 100644 --- a/src/modules/websocket/ws_handshake.c +++ b/src/modules/websocket/ws_handshake.c @@ -460,3 +460,17 @@ struct mi_root *ws_mi_enable(struct mi_root *cmd, void *param) LM_WARN("enabling websockets\n"); return init_mi_tree(200, MI_OK_S, MI_OK_LEN); } + +void ws_rpc_disable(rpc_t* rpc, void* ctx) +{ + cfg_get(websocket, ws_cfg, enabled) = 0; + LM_WARN("disabling websockets - new connections will be dropped\n"); + return; +} + +void ws_rpc_enable(rpc_t* rpc, void* ctx) +{ + cfg_get(websocket, ws_cfg, enabled) = 1; + LM_WARN("enabling websockets\n"); + return; +} diff --git a/src/modules/websocket/ws_handshake.h b/src/modules/websocket/ws_handshake.h index 9c244a1..521a91e 100644 --- a/src/modules/websocket/ws_handshake.h +++ b/src/modules/websocket/ws_handshake.h @@ -28,6 +28,7 @@ #define _WS_HANDSHAKE_H
#include "../../core/sr_module.h" +#include "../../core/rpc.h" #include "../../core/parser/msg_parser.h" #include "websocket.h"
@@ -49,4 +50,7 @@ int ws_handle_handshake(struct sip_msg *msg); struct mi_root *ws_mi_disable(struct mi_root *cmd, void *param); struct mi_root *ws_mi_enable(struct mi_root *cmd, void *param);
+void ws_rpc_disable(rpc_t* rpc, void* ctx); +void ws_rpc_enable(rpc_t* rpc, void* ctx); + #endif /* _WS_HANDSHAKE_H */