Browse code

websocket: removed mi commands

- corresponding rpc commands can be used

Daniel-Constantin Mierla authored on 30/12/2016 08:29:51
Showing 11 changed files
... ...
@@ -50,8 +50,5 @@ endif
50 50
 
51 51
 DEFS+=-DKAMAILIO_MOD_INTERFACE
52 52
 
53
-SERLIBPATH=../../lib
54
-SER_LIBS+=$(SERLIBPATH)/kmi/kmi
55
-
56 53
 include ../../Makefile.modules
57 54
 
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  *
20 20
  * Exception: permission to copy, modify, propagate, and distribute a work
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  *
20 20
  * Exception: permission to copy, modify, propagate, and distribute a work
... ...
@@ -11,7 +11,7 @@
11 11
  * Software is furnished to do so, subject to the following conditions:
12 12
  *   The above copyright notice and this permission notice shall be included
13 13
  *   in all copies or substantial portions of the Software.
14
- * 
14
+ *
15 15
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 16
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 17
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
... ...
@@ -19,7 +19,7 @@
19 19
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 20
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 21
  * DEALINGS IN THE SOFTWARE.
22
- * 
22
+ *
23 23
  * See http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ for details.
24 24
  */
25 25
 
... ...
@@ -33,7 +33,6 @@
33 33
 #include "../../core/timer_proc.h"
34 34
 #include "../../core/cfg/cfg.h"
35 35
 #include "../../core/counters.h"
36
-#include "../../lib/kmi/mi.h"
37 36
 #include "../../core/mem/mem.h"
38 37
 #include "../../core/mod_fix.h"
39 38
 #include "../../core/parser/msg_parser.h"
... ...
@@ -144,22 +143,6 @@ static stat_export_t stats[] = {
144 143
 	{ 0, 0, 0 }
145 144
 };
146 145
 
147
-static mi_export_t mi_cmds[] = {
148
-	/* ws_conn.c */
149
-	{ "ws.dump",	ws_mi_dump,    0, 0, 0 },
150
-
151
-	/* ws_frame.c */
152
-	{ "ws.close",   ws_mi_close,   0, 0, 0 },
153
-	{ "ws.ping",    ws_mi_ping,    0, 0, 0 },
154
-	{ "ws.pong",	ws_mi_pong,    0, 0, 0 },
155
-
156
-	/* ws_handshake.c */
157
-	{ "ws.disable", ws_mi_disable, 0, 0, 0 },
158
-	{ "ws.enable",	ws_mi_enable,  0, 0, 0 },
159
-
160
-	{ 0, 0, 0, 0, 0 }
161
-};
162
-
163 146
 static pv_export_t mod_pvs[] = {
164 147
     {{"ws_conid", (sizeof("ws_conid")-1)}, PVT_CONTEXT,
165 148
      pv_get_ws_conid_f, 0, 0, 0, 0, 0},
... ...
@@ -172,8 +155,8 @@ struct module_exports exports = {
172 155
 	cmds,			/* Exported functions */
173 156
 	params,			/* Exported parameters */
174 157
 	stats,			/* exported statistics */
175
-	mi_cmds,		/* exported MI functions */
176
-	mod_pvs,                /* exported pseudo-variables */
158
+	0,				/* exported MI functions */
159
+	mod_pvs,		/* exported pseudo-variables */
177 160
 	0,			/* extra processes */
178 161
 	mod_init,		/* module initialization function */
179 162
 	0,			/* response function */
... ...
@@ -207,12 +190,6 @@ static int mod_init(void)
207 190
 		goto error;
208 191
 	}
209 192
 
210
-	if (register_mi_mod(exports.name, mi_cmds) != 0)
211
-	{
212
-		LM_ERR("registering MI commands\n");
213
-		goto error;
214
-	}
215
-
216 193
 	if(ws_init_rpc()<0)
217 194
 	{
218 195
 		LM_ERR("failed to register RPC commands\n");
... ...
@@ -29,7 +29,6 @@
29 29
 #include "../../core/tcp_conn.h"
30 30
 #include "../../core/fmsg.h"
31 31
 #include "../../core/counters.h"
32
-#include "../../lib/kmi/tree.h"
33 32
 #include "../../core/mem/mem.h"
34 33
 #include "ws_conn.h"
35 34
 #include "websocket.h"
... ...
@@ -529,187 +528,6 @@ int wsconn_put_list(ws_connection_t **list_head)
529 528
 	return 0;
530 529
 }
531 530
 
532
-static int add_node(struct mi_root *tree, ws_connection_t *wsc)
533
-{
534
-	int interval;
535
-	char *src_proto, *dst_proto, *pong, *sub_protocol;
536
-	char src_ip[IP6_MAX_STR_SIZE + 1], dst_ip[IP6_MAX_STR_SIZE + 1];
537
-	struct tcp_connection *con = tcpconn_get(wsc->id, 0, 0, 0, 0);
538
-
539
-	if (con)
540
-	{
541
-		src_proto = (con->rcv.proto== PROTO_WS) ? "ws" : "wss";
542
-		memset(src_ip, 0, IP6_MAX_STR_SIZE + 1);
543
-		ip_addr2sbuf(&con->rcv.src_ip, src_ip, IP6_MAX_STR_SIZE);
544
-
545
-		dst_proto = (con->rcv.proto == PROTO_WS) ? "ws" : "wss";
546
-		memset(dst_ip, 0, IP6_MAX_STR_SIZE + 1);
547
-		ip_addr2sbuf(&con->rcv.dst_ip, dst_ip, IP6_MAX_STR_SIZE);
548
-
549
-		pong = wsc->awaiting_pong ? "awaiting Pong, " : "";
550
-
551
-		interval = (int)time(NULL) - wsc->last_used;
552
-		if (wsc->sub_protocol == SUB_PROTOCOL_SIP)
553
-			sub_protocol = "sip";
554
-		else if (wsc->sub_protocol == SUB_PROTOCOL_MSRP)
555
-			sub_protocol = "msrp";
556
-		else
557
-			sub_protocol = "**UNKNOWN**";
558
-
559
-		if (addf_mi_node_child(&tree->node, 0, 0, 0,
560
-					"%d: %s:%s:%hu -> %s:%s:%hu (state: %s"
561
-					", %s last used %ds ago"
562
-					", sub-protocol: %s)",
563
-					wsc->id,
564
-					src_proto,
565
-					strlen(src_ip) ? src_ip : "*",
566
-					con->rcv.src_port,
567
-					dst_proto,
568
-					strlen(dst_ip) ? dst_ip : "*",
569
-					con->rcv.dst_port,
570
-					wsconn_state_str[wsc->state],
571
-					pong,
572
-					interval,
573
-					sub_protocol) == 0)
574
-		{
575
-			tcpconn_put(con);
576
-			return -1;
577
-		}
578
-
579
-		tcpconn_put(con);
580
-		return 1;
581
-	}
582
-	else
583
-		return 0;
584
-}
585
-
586
-struct mi_root *ws_mi_dump(struct mi_root *cmd, void *param)
587
-{
588
-	int h, connections = 0, truncated = 0, order = 0, found = 0;
589
-	ws_connection_t *wsc;
590
-	struct mi_node *node = NULL;
591
-	struct mi_root *rpl_tree;
592
-
593
-	node = cmd->node.kids;
594
-	if (node != NULL)
595
-	{
596
-		if (node->value.s == NULL || node->value.len == 0)
597
-		{
598
-			LM_WARN("empty display order parameter\n");
599
-			return init_mi_tree(400, str_status_empty_param.s,
600
-						str_status_empty_param.len);
601
-		}
602
-		strlower(&node->value);
603
-		if (strncmp(node->value.s, "id_hash", 7) == 0)
604
-			order = 0;
605
-		else if (strncmp(node->value.s, "used_desc", 9) == 0)
606
-			order = 1;
607
-		else if (strncmp(node->value.s, "used_asc", 8) == 0)
608
-			order = 2;
609
-		else
610
-		{
611
-			LM_WARN("bad display order parameter\n");
612
-			return init_mi_tree(400, str_status_bad_param.s,
613
-						str_status_bad_param.len);
614
-		}
615
-
616
-		if (node->next != NULL)
617
-		{
618
-			LM_WARN("too many parameters\n");
619
-			return init_mi_tree(400, str_status_too_many_params.s,
620
-						str_status_too_many_params.len);
621
-		}
622
-	}
623
-
624
-	rpl_tree = init_mi_tree(200, MI_OK_S, MI_OK_LEN);
625
-	if (rpl_tree == NULL)
626
-		return 0;
627
-
628
-	WSCONN_LOCK;
629
-	if (order == 0)
630
-	{
631
-		for (h = 0; h < TCP_ID_HASH_SIZE; h++)
632
-		{
633
-			wsc = wsconn_id_hash[h];
634
-			while(wsc)
635
-			{
636
-				if ((found = add_node(rpl_tree, wsc)) < 0)
637
-				{
638
-					free_mi_tree(rpl_tree);
639
-					return 0;
640
-				}
641
-
642
-
643
-				connections += found;
644
-				if (connections >= MAX_WS_CONNS_DUMP)
645
-				{
646
-					truncated = 1;
647
-					break;
648
-				}
649
-
650
-				wsc = wsc->id_next;
651
-			}
652
-
653
-			if (truncated == 1)
654
-				break;
655
-		}
656
-	}
657
-	else if (order == 1)
658
-	{
659
-		wsc = wsconn_used_list->head;
660
-		while (wsc)
661
-		{
662
-			if ((found = add_node(rpl_tree, wsc)) < 0)
663
-			{
664
-				free_mi_tree(rpl_tree);
665
-				return 0;
666
-			}
667
-
668
-			connections += found;
669
-			if (connections >= MAX_WS_CONNS_DUMP)
670
-			{
671
-				truncated = 1;
672
-				break;
673
-			}
674
-
675
-			wsc = wsc->used_next;
676
-		}
677
-	}
678
-	else
679
-	{
680
-		wsc = wsconn_used_list->tail;
681
-		while (wsc)
682
-		{
683
-			if ((found = add_node(rpl_tree, wsc)) < 0)
684
-			{
685
-				free_mi_tree(rpl_tree);
686
-				return 0;
687
-			}
688
-
689
-			connections += found;
690
-			if (connections >= MAX_WS_CONNS_DUMP)
691
-			{
692
-				truncated = 1;
693
-				break;
694
-			}
695
-
696
-			wsc = wsc->used_prev;
697
-		}
698
-	}
699
-	WSCONN_UNLOCK;
700
-
701
-	if (addf_mi_node_child(&rpl_tree->node, 0, 0, 0,
702
-				"%d WebSocket connection%s found%s",
703
-				connections, connections == 1 ? "" : "s",
704
-				truncated == 1 ? "(truncated)" : "") == 0)
705
-	{
706
-		free_mi_tree(rpl_tree);
707
-		return 0;
708
-	}
709
-
710
-	return rpl_tree;
711
-}
712
-
713 531
 
714 532
 static int ws_rpc_add_node(rpc_t* rpc, void* ctx, void* ih, ws_connection_t *wsc)
715 533
 {
... ...
@@ -30,7 +30,6 @@
30 30
 #include "../../core/atomic_ops.h"
31 31
 
32 32
 #include "../../core/counters.h"
33
-#include "../../lib/kmi/tree.h"
34 33
 #include "../../core/rpc.h"
35 34
 
36 35
 typedef enum
... ...
@@ -98,6 +97,5 @@ ws_connection_t *wsconn_get(int id);
98 97
 int wsconn_put(ws_connection_t *wsc);
99 98
 ws_connection_t **wsconn_get_list(void);
100 99
 int wsconn_put_list(ws_connection_t **list);
101
-struct mi_root *ws_mi_dump(struct mi_root *cmd, void *param);
102 100
 void ws_rpc_dump(rpc_t* rpc, void* ctx);
103 101
 #endif /* _WS_CONN_H */
... ...
@@ -40,7 +40,6 @@
40 40
 #include "../../core/tcp_read.h"
41 41
 #include "../../core/tcp_server.h"
42 42
 #include "../../core/counters.h"
43
-#include "../../lib/kmi/tree.h"
44 43
 #include "../../core/mem/mem.h"
45 44
 #include "ws_conn.h"
46 45
 #include "ws_frame.h"
... ...
@@ -854,123 +853,6 @@ static int ws_send_crlf(ws_connection_t *wsc, int opcode)
854 853
 	return 0;
855 854
 }
856 855
 
857
-struct mi_root *ws_mi_close(struct mi_root *cmd, void *param)
858
-{
859
-	unsigned int id;
860
-	struct mi_node *node = NULL;
861
-	ws_connection_t *wsc;
862
-
863
-	node = cmd->node.kids;
864
-	if (node == NULL)
865
-	{
866
-		LM_WARN("no connection ID parameter\n");
867
-		return init_mi_tree(400, str_status_empty_param.s,
868
-					str_status_empty_param.len);
869
-	}
870
-	if (node->value.s == NULL || node->value.len == 0)
871
-	{
872
-		LM_WARN("empty connection ID parameter\n");
873
-		return init_mi_tree(400, str_status_empty_param.s,
874
-					str_status_empty_param.len);
875
-	}
876
-	if (str2int(&node->value, &id) < 0)
877
-	{
878
-		LM_ERR("converting string to int\n");
879
-		return init_mi_tree(400, str_status_string_error.s,
880
-					str_status_string_error.len);
881
-	}
882
-	if (node->next != NULL)
883
-	{
884
-		LM_WARN("too many parameters\n");
885
-		return init_mi_tree(400, str_status_too_many_params.s,
886
-					str_status_too_many_params.len);
887
-	}
888
-
889
-	if ((wsc = wsconn_get(id)) == NULL)
890
-	{
891
-		LM_WARN("bad connection ID parameter\n");
892
-		return init_mi_tree(400, str_status_bad_param.s,
893
-					str_status_bad_param.len);
894
-	}
895
-
896
-	int ret = close_connection(&wsc, LOCAL_CLOSE, 1000, str_status_normal_closure);
897
-
898
-	wsconn_put(wsc);
899
-
900
-	if (ret < 0)
901
-	{
902
-		LM_WARN("closing connection\n");
903
-		return init_mi_tree(500, str_status_error_closing.s,
904
-					str_status_error_closing.len);
905
-	}
906
-
907
-	return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
908
-}
909
-
910
-static struct mi_root *mi_ping_pong(struct mi_root *cmd, void *param,
911
-					int opcode)
912
-{
913
-	unsigned int id;
914
-	struct mi_node *node = NULL;
915
-	ws_connection_t *wsc;
916
-
917
-	node = cmd->node.kids;
918
-	if (node == NULL)
919
-	{
920
-		LM_WARN("no connection ID parameter\n");
921
-		return init_mi_tree(400, str_status_empty_param.s,
922
-					str_status_empty_param.len);
923
-	}
924
-	if (node->value.s == NULL || node->value.len == 0)
925
-	{
926
-		LM_WARN("empty connection ID parameter\n");
927
-		return init_mi_tree(400, str_status_empty_param.s,
928
-					str_status_empty_param.len);
929
-	}
930
-	if (str2int(&node->value, &id) < 0)
931
-	{
932
-		LM_ERR("converting string to int\n");
933
-		return init_mi_tree(400, str_status_string_error.s,
934
-					str_status_string_error.len);
935
-	}
936
-	if (node->next != NULL)
937
-	{
938
-		LM_WARN("too many parameters\n");
939
-		return init_mi_tree(400, str_status_too_many_params.s,
940
-					str_status_too_many_params.len);
941
-	}
942
-
943
-	if ((wsc = wsconn_get(id)) == NULL)
944
-	{
945
-		LM_WARN("bad connection ID parameter\n");
946
-		return init_mi_tree(400, str_status_bad_param.s,
947
-					str_status_bad_param.len);
948
-	}
949
-
950
-	int ret = ping_pong(wsc, opcode);
951
-
952
-	wsconn_put(wsc);
953
-
954
-	if (ret < 0)
955
-	{
956
-		LM_WARN("sending %s\n", OPCODE_PING ? "Ping" : "Pong");
957
-		return init_mi_tree(500, str_status_error_sending.s,
958
-					str_status_error_sending.len);
959
-	}
960
-
961
-	return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
962
-}
963
-
964
-struct mi_root *ws_mi_ping(struct mi_root *cmd, void *param)
965
-{
966
-	return mi_ping_pong(cmd, param, OPCODE_PING);
967
-}
968
-
969
-struct mi_root *ws_mi_pong(struct mi_root *cmd, void *param)
970
-{
971
-	return mi_ping_pong(cmd, param, OPCODE_PONG);
972
-}
973
-
974 856
 void ws_keepalive(unsigned int ticks, void *param)
975 857
 {
976 858
 	int check_time = (int) time(NULL)
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  *
20 20
  * Exception: permission to copy, modify, propagate, and distribute a work
... ...
@@ -31,7 +31,6 @@
31 31
 #include "../../core/sr_module.h"
32 32
 #include "../../core/str.h"
33 33
 #include "../../core/rpc.h"
34
-#include "../../lib/kmi/tree.h"
35 34
 #include "ws_conn.h"
36 35
 
37 36
 typedef enum
... ...
@@ -73,9 +72,6 @@ extern stat_var *ws_msrp_transmitted_frames;
73 72
 
74 73
 int ws_frame_receive(void *data);
75 74
 int ws_frame_transmit(void *data);
76
-struct mi_root *ws_mi_close(struct mi_root *cmd, void *param);
77
-struct mi_root *ws_mi_ping(struct mi_root *cmd, void *param);
78
-struct mi_root *ws_mi_pong(struct mi_root *cmd, void *param);
79 75
 void ws_keepalive(unsigned int ticks, void *param);
80 76
 int ws_close(sip_msg_t *msg);
81 77
 int ws_close2(sip_msg_t *msg, char *_status, char *_reason);
... ...
@@ -34,7 +34,6 @@
34 34
 #include "../../core/tcp_conn.h"
35 35
 #include "../../core/counters.h"
36 36
 #include "../../core/strutils.h"
37
-#include "../../lib/kmi/tree.h"
38 37
 #include "../../core/mem/mem.h"
39 38
 #include "../../core/parser/msg_parser.h"
40 39
 #include "../sl/sl.h"
... ...
@@ -447,20 +446,6 @@ end:
447 446
 	return 0;
448 447
 }
449 448
 
450
-struct mi_root *ws_mi_disable(struct mi_root *cmd, void *param)
451
-{
452
-	cfg_get(websocket, ws_cfg, enabled) = 0;
453
-	LM_WARN("disabling websockets - new connections will be dropped\n");
454
-	return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
455
-}
456
-
457
-struct mi_root *ws_mi_enable(struct mi_root *cmd, void *param)
458
-{
459
-	cfg_get(websocket, ws_cfg, enabled) = 1;
460
-	LM_WARN("enabling websockets\n");
461
-	return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
462
-}
463
-
464 449
 void ws_rpc_disable(rpc_t* rpc, void* ctx)
465 450
 {
466 451
 	cfg_get(websocket, ws_cfg, enabled) = 0;
... ...
@@ -13,8 +13,8 @@
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
15 15
  *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  *
20 20
  * Exception: permission to copy, modify, propagate, and distribute a work
... ...
@@ -47,8 +47,6 @@ extern stat_var *ws_sip_successful_handshakes;
47 47
 extern stat_var *ws_msrp_successful_handshakes;
48 48
 
49 49
 int ws_handle_handshake(struct sip_msg *msg);
50
-struct mi_root *ws_mi_disable(struct mi_root *cmd, void *param);
51
-struct mi_root *ws_mi_enable(struct mi_root *cmd, void *param);
52 50
 
53 51
 void ws_rpc_disable(rpc_t* rpc, void* ctx);
54 52
 void ws_rpc_enable(rpc_t* rpc, void* ctx);