Skip to content

Commit

Permalink
websocket: exported functions to kemi framework
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 17, 2017
1 parent b36d012 commit 64adb29
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 24 deletions.
48 changes: 44 additions & 4 deletions src/modules/websocket/websocket.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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 },

Expand Down Expand Up @@ -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;
}
52 changes: 34 additions & 18 deletions src/modules/websocket/ws_frame.c
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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);
}

/*
Expand Down
8 changes: 6 additions & 2 deletions src/modules/websocket/ws_frame.h
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/modules/websocket/ws_handshake.c
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/modules/websocket/ws_handshake.h
Expand Up @@ -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);
Expand Down

0 comments on commit 64adb29

Please sign in to comment.