diff --git a/src/modules/websocket/websocket.c b/src/modules/websocket/websocket.c index 146666787a5..ec2833d8398 100644 --- a/src/modules/websocket/websocket.c +++ b/src/modules/websocket/websocket.c @@ -36,6 +36,7 @@ #include "../../core/mem/mem.h" #include "../../core/mod_fix.h" #include "../../core/parser/msg_parser.h" +#include "../../core/kemi.h" #include "../../core/rpc.h" #include "../../core/rpc_lookup.h" #include "ws_conn.h" @@ -71,18 +72,18 @@ int ws_verbose_list = 0; static cmd_export_t cmds[] = { /* ws_frame.c */ - { "ws_close", (cmd_function) ws_close, + { "ws_close", (cmd_function)w_ws_close0, 0, 0, 0, ANY_ROUTE }, - { "ws_close", (cmd_function) ws_close2, + { "ws_close", (cmd_function)w_ws_close2, 2, ws_close_fixup, 0, ANY_ROUTE }, - { "ws_close", (cmd_function) ws_close3, + { "ws_close", (cmd_function)w_ws_close3, 3, ws_close_fixup, 0, ANY_ROUTE }, /* ws_handshake.c */ - { "ws_handle_handshake", (cmd_function) ws_handle_handshake, + { "ws_handle_handshake", (cmd_function)w_ws_handle_handshake, 0, 0, 0, ANY_ROUTE }, @@ -394,3 +395,42 @@ static int ws_init_rpc(void) } return 0; } + +/** + * + */ +/* clang-format off */ +static sr_kemi_t sr_kemi_websocket_exports[] = { + { str_init("websocket"), str_init("handle_handshake"), + SR_KEMIP_INT, ws_handle_handshake, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("websocket"), str_init("close"), + SR_KEMIP_INT, ws_close, + { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("websocket"), str_init("close_reason"), + SR_KEMIP_INT, ws_close2, + { SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + { str_init("websocket"), str_init("close_conid"), + SR_KEMIP_INT, ws_close3, + { SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_INT, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, + + { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } } +}; +/* clang-format on */ + +/** + * + */ +int mod_register(char *path, int *dlflags, void *p1, void *p2) +{ + sr_kemi_modules_add(sr_kemi_websocket_exports); + return 0; +} \ No newline at end of file diff --git a/src/modules/websocket/ws_frame.c b/src/modules/websocket/ws_frame.c index cdd13428a61..8f3ab7332c9 100644 --- a/src/modules/websocket/ws_frame.c +++ b/src/modules/websocket/ws_frame.c @@ -904,13 +904,33 @@ int ws_close(sip_msg_t *msg) return ret; } -int ws_close2(sip_msg_t *msg, char *_status, char *_reason) +int w_ws_close0(sip_msg_t *msg, char *p1, char *p2) +{ + return ws_close(msg); +} + +int ws_close2(sip_msg_t *msg, int status, str *reason) { - int status; - str reason; ws_connection_t *wsc; int ret; + if ((wsc = wsconn_get(msg->rcv.proto_reserved1)) == NULL) { + LM_ERR("failed to retrieve WebSocket connection\n"); + return -1; + } + + ret = (close_connection(&wsc, LOCAL_CLOSE, status, *reason) == 0) ? 1: 0; + + wsconn_put(wsc); + + return ret; +} + +int w_ws_close2(sip_msg_t *msg, char *_status, char *_reason) +{ + int status; + str reason; + if (get_int_fparam(&status, msg, (fparam_t *) _status) < 0) { LM_ERR("failed to get status code\n"); return -1; @@ -920,26 +940,31 @@ int ws_close2(sip_msg_t *msg, char *_status, char *_reason) LM_ERR("failed to get reason string\n"); return -1; } + return ws_close2(msg, status, &reason); +} - if ((wsc = wsconn_get(msg->rcv.proto_reserved1)) == NULL) { +int ws_close3(sip_msg_t *msg, int status, str *reason, int con) +{ + ws_connection_t *wsc; + int ret; + + if ((wsc = wsconn_get(con)) == NULL) { LM_ERR("failed to retrieve WebSocket connection\n"); return -1; } - ret = (close_connection(&wsc, LOCAL_CLOSE, status, reason) == 0) ? 1: 0; + ret = (close_connection(&wsc, LOCAL_CLOSE, status, *reason) == 0) ? 1: 0; wsconn_put(wsc); return ret; } -int ws_close3(sip_msg_t *msg, char *_status, char *_reason, char *_con) +int w_ws_close3(sip_msg_t *msg, char *_status, char *_reason, char *_con) { int status; str reason; int con; - ws_connection_t *wsc; - int ret; if (get_int_fparam(&status, msg, (fparam_t *) _status) < 0) { LM_ERR("failed to get status code\n"); @@ -956,16 +981,7 @@ int ws_close3(sip_msg_t *msg, char *_status, char *_reason, char *_con) return -1; } - if ((wsc = wsconn_get(con)) == NULL) { - LM_ERR("failed to retrieve WebSocket connection\n"); - return -1; - } - - ret = (close_connection(&wsc, LOCAL_CLOSE, status, reason) == 0) ? 1: 0; - - wsconn_put(wsc); - - return ret; + return ws_close3(msg, status, &reason, con); } /* diff --git a/src/modules/websocket/ws_frame.h b/src/modules/websocket/ws_frame.h index e4d3481d2cb..48bee1e5d57 100644 --- a/src/modules/websocket/ws_frame.h +++ b/src/modules/websocket/ws_frame.h @@ -73,9 +73,13 @@ extern stat_var *ws_msrp_transmitted_frames; int ws_frame_receive(void *data); int ws_frame_transmit(void *data); void ws_keepalive(unsigned int ticks, void *param); + int ws_close(sip_msg_t *msg); -int ws_close2(sip_msg_t *msg, char *_status, char *_reason); -int ws_close3(sip_msg_t *msg, char *_status, char *_reason, char *_con); +int w_ws_close0(sip_msg_t *msg, char *p1, char *p2); +int ws_close2(sip_msg_t *msg, int status, str *reason); +int w_ws_close2(sip_msg_t *msg, char *_status, char *_reason); +int ws_close3(sip_msg_t *msg, int status, str *reason, int con); +int w_ws_close3(sip_msg_t *msg, char *_status, char *_reason, char *_con); void ws_rpc_close(rpc_t* rpc, void* ctx); void ws_rpc_ping(rpc_t* rpc, void* ctx); diff --git a/src/modules/websocket/ws_handshake.c b/src/modules/websocket/ws_handshake.c index bf479d67fd3..1010991e26f 100644 --- a/src/modules/websocket/ws_handshake.c +++ b/src/modules/websocket/ws_handshake.c @@ -446,6 +446,11 @@ int ws_handle_handshake(struct sip_msg *msg) return 0; } +int w_ws_handle_handshake(sip_msg_t *msg, char *p1, char *p2) +{ + return ws_handle_handshake(msg); +} + void ws_rpc_disable(rpc_t* rpc, void* ctx) { cfg_get(websocket, ws_cfg, enabled) = 0; diff --git a/src/modules/websocket/ws_handshake.h b/src/modules/websocket/ws_handshake.h index ec4a17a8bb1..eba13938da5 100644 --- a/src/modules/websocket/ws_handshake.h +++ b/src/modules/websocket/ws_handshake.h @@ -47,6 +47,7 @@ extern stat_var *ws_sip_successful_handshakes; extern stat_var *ws_msrp_successful_handshakes; int ws_handle_handshake(struct sip_msg *msg); +int w_ws_handle_handshake(sip_msg_t *msg, char *p1, char *p2); void ws_rpc_disable(rpc_t* rpc, void* ctx); void ws_rpc_enable(rpc_t* rpc, void* ctx);