Browse code

core: added rpc commands to list listen sockets and name aliases

- core.sockets_list
- core.aliases_list

Daniel-Constantin Mierla authored on 15/12/2011 12:03:00
Showing 1 changed files
... ...
@@ -37,6 +37,9 @@
37 37
 #include "dprint.h"
38 38
 #include "core_cmd.h"
39 39
 #include "globals.h"
40
+#include "forward.h"
41
+#include "socket_info.h"
42
+#include "name_alias.h"
40 43
 #include "pt.h"
41 44
 #include "ut.h"
42 45
 #include "tcp_info.h"
... ...
@@ -974,6 +977,96 @@ static void core_udp4rawinfo(rpc_t* rpc, void* c)
974 974
 #endif /* USE_RAW_SOCKS */
975 975
 }
976 976
 
977
+/**
978
+ *
979
+ */
980
+static const char* core_aliases_list_doc[] = {
981
+	"List local SIP server host aliases",    /* Documentation string */
982
+	0                                     /* Method signature(s) */
983
+};
984
+
985
+/**
986
+ * list the name aliases for SIP server
987
+ */
988
+static void core_aliases_list(rpc_t* rpc, void* c)
989
+{
990
+	void *hr;
991
+	void *ha;
992
+	struct host_alias* a;
993
+
994
+	rpc->add(c, "{", &hr);
995
+	rpc->struct_add(hr, "s",
996
+			"myself_callbacks", is_check_self_func_list_set()?"yes":"no");
997
+	for(a=aliases; a; a=a->next) {
998
+		rpc->struct_add(hr, "{", "alias", &ha);
999
+		rpc->struct_add(ha, "sS",
1000
+				"proto",  proto2a(a->proto),
1001
+				"address", &a->alias
1002
+			);
1003
+		if (a->port)
1004
+			rpc->struct_add(ha, "d",
1005
+					"port", a->port);
1006
+		else
1007
+			rpc->struct_add(ha, "s",
1008
+					"port", "*");
1009
+	}
1010
+}
1011
+
1012
+/**
1013
+ *
1014
+ */
1015
+static const char* core_sockets_list_doc[] = {
1016
+	"List local SIP server listen sockets",    /* Documentation string */
1017
+	0                                     /* Method signature(s) */
1018
+};
1019
+
1020
+/**
1021
+ * list listen sockets for SIP server
1022
+ */
1023
+static void core_sockets_list(rpc_t* rpc, void* c)
1024
+{
1025
+	void *hr;
1026
+	void *ha;
1027
+	struct socket_info *si;
1028
+	struct socket_info** list;
1029
+	struct addr_info* ai;
1030
+	unsigned short proto;
1031
+
1032
+	proto=PROTO_UDP;
1033
+	rpc->add(c, "{", &hr);
1034
+	do{
1035
+		list=get_sock_info_list(proto);
1036
+		for(si=list?*list:0; si; si=si->next){
1037
+			rpc->struct_add(hr, "{", "socket", &ha);
1038
+			if (si->addr_info_lst){
1039
+				rpc->struct_add(ha, "ss",
1040
+						"proto", get_proto_name(proto),
1041
+						"address", si->address_str.s);
1042
+				for (ai=si->addr_info_lst; ai; ai=ai->next)
1043
+					rpc->struct_add(ha, "ss",
1044
+						"address", ai->address_str.s);
1045
+				rpc->struct_add(ha, "sss",
1046
+						"proto", si->port_no_str.s,
1047
+						"mcast", si->flags & SI_IS_MCAST ? "yes" : "no",
1048
+						"mhomed", si->flags & SI_IS_MHOMED ? "yes" : "no");
1049
+			} else {
1050
+				printf("             %s: %s",
1051
+						get_proto_name(proto),
1052
+						si->name.s);
1053
+				rpc->struct_add(ha, "ss",
1054
+						"proto", get_proto_name(proto),
1055
+						"address", si->name.s);
1056
+				if (!si->flags & SI_IS_IP)
1057
+					rpc->struct_add(ha, "ss",
1058
+						"ipaddress", si->address_str.s);
1059
+				rpc->struct_add(ha, "sss",
1060
+						"proto", si->port_no_str.s,
1061
+						"mcast", si->flags & SI_IS_MCAST ? "yes" : "no",
1062
+						"mhomed", si->flags & SI_IS_MHOMED ? "yes" : "no");
1063
+			}
1064
+		}
1065
+	} while((proto=next_proto(proto)));
1066
+}
977 1067
 
978 1068
 
979 1069
 /*
... ...
@@ -1013,6 +1106,8 @@ static rpc_export_t core_rpc_methods[] = {
1013 1013
 	{"core.sctp_info",         core_sctpinfo,          core_sctpinfo_doc,   0},
1014 1014
 	{"core.udp4_raw_info",     core_udp4rawinfo,       core_udp4rawinfo_doc,
1015 1015
 		0},
1016
+	{"core.aliases_list",      core_aliases_list,      core_aliases_list_doc,   0},
1017
+	{"core.sockets_list",      core_sockets_list,      core_sockets_list_doc,   0},
1016 1018
 #ifdef USE_DNS_CACHE
1017 1019
 	{"dns.mem_info",          dns_cache_mem_info,     dns_cache_mem_info_doc,
1018 1020
 		0	},