Browse code

kamcmd: removed mi related code

Daniel-Constantin Mierla authored on 06/01/2017 13:54:32
Showing 1 changed files
... ...
@@ -47,7 +47,6 @@
47 47
 #include <readline/history.h>
48 48
 
49 49
 #define USE_CFG_VARS /* cfg group and vars completion */
50
-#define USE_MI  /* mi completion */
51 50
 #define USE_COUNTERS /* counters/statistics completion */
52 51
 #endif
53 52
 
... ...
@@ -103,7 +102,7 @@ Options:\n\
103 103
     -h          This help message\n\
104 104
 address:\n\
105 105
     [proto:]name[:port]   where proto is one of tcp, udp, unixs or unixd\n\
106
-                          e.g.:  tcp:localhost:2048 , unixs:/tmp/ser_ctl\n\
106
+                          e.g.:  tcp:localhost:2048 , unixs:/tmp/kamailio_ctl\n\
107 107
 cmd:\n\
108 108
     method  [arg1 [arg2...]]\n\
109 109
 arg:\n\
... ...
@@ -144,14 +143,6 @@ struct cfg_var_grp* cfg_grp_lst; /** cfg groups list, allong with var names*/
144 144
 struct cfg_var_grp* crt_cfg_grp;
145 145
 #endif /* USE_CFG_VARS */
146 146
 
147
-#ifdef USE_MI
148
-struct binrpc_val* mi_which_array;
149
-int mi_which_no;
150
-
151
-str* mi_cmds;
152
-int mi_cmds_no;
153
-#endif /* USE_MI */
154
-
155 147
 #ifdef USE_COUNTERS
156 148
 struct binrpc_val* cnt_grps_array; /* response array */
157 149
 int cnt_grps_no; /* number of response records */
... ...
@@ -238,48 +229,49 @@ struct cmd_alias{
238 238
 };
239 239
 
240 240
 
241
-struct sercmd_builtin{
241
+struct kamcmd_builtin{
242 242
 	char* name;
243 243
 	int (*f)(int, struct binrpc_cmd*);
244 244
 	char* doc;
245 245
 };
246 246
 
247 247
 
248
-static int sercmd_help(int s, struct binrpc_cmd* cmd);
249
-static int sercmd_ver(int s, struct binrpc_cmd* cmd);
250
-static int sercmd_quit(int s, struct binrpc_cmd* cmd);
251
-static int sercmd_warranty(int s, struct binrpc_cmd* cmd);
248
+static int kamcmd_help(int s, struct binrpc_cmd* cmd);
249
+static int kamcmd_ver(int s, struct binrpc_cmd* cmd);
250
+static int kamcmd_quit(int s, struct binrpc_cmd* cmd);
251
+static int kamcmd_warranty(int s, struct binrpc_cmd* cmd);
252 252
 
253 253
 
254 254
 static struct cmd_alias cmd_aliases[]={
255 255
 	{	"ps",			"core.ps",				"%v\t%v\n"	},
256
+	{	"psx",			"core.psx",				0			},
256 257
 	{	"list",			"system.listMethods",	0			},
257 258
 	{	"ls",			"system.listMethods",	0			},
258
-	{	"server",		"core.version",			0			},
259
-	{	"serversion",	"core.version",			0			},
259
+	{	"ver",			"core.version",			0			},
260
+	{	"version",		"core.version",			0			},
260 261
 	{	"who",			"ctl.who",				"[%v] %v: %v %v -> %v %v\n"},
261 262
 	{	"listen",		"ctl.listen",			"[%v] %v: %v %v\n"},
262 263
 	{	"dns_mem_info",		"dns.mem_info",			"%v / %v\n"},
263
-	{	"dns_debug",	"dns.debug",			
264
+	{	"dns_debug",	"dns.debug",
264 265
 					"%v (%v): size=%v ref=%v expire=%vs last=%vs ago f=%v\n"},
265
-	{	"dns_debug_all",	"dns.debug_all",			
266
+	{	"dns_debug_all",	"dns.debug_all",
266 267
 			"%v (%v) [%v]: size=%v ref=%v expire=%vs last=%vs ago f=%v\n"
267 268
 			"\t\t%v:%v expire=%vs f=%v\n"},
268 269
 	{	"dst_blacklist_mem_info",	"dst_blacklist.mem_info",	"%v / %v\n"},
269
-	{	"dst_blacklist_debug",		"dst_blacklist.debug",	
270
+	{	"dst_blacklist_debug",		"dst_blacklist.debug",
270 271
 		"%v:%v:%v expire:%v flags: %v\n"},
271 272
 	{0,0,0}
272 273
 };
273 274
 
274 275
 
275
-static struct sercmd_builtin builtins[]={
276
-	{	"?",		sercmd_help, "help"},
277
-	{	"help",		sercmd_help, "displays help for a command"},
278
-	{	"version",	sercmd_ver,  "displays " NAME "version"},
279
-	{	"quit",		sercmd_quit, "exits " NAME },
280
-	{	"exit",		sercmd_quit, "exits " NAME },
281
-	{	"warranty",		sercmd_warranty, "displays " NAME "'s warranty info"},
282
-	{	"license",		sercmd_warranty, "displays " NAME "'s license"},
276
+static struct kamcmd_builtin builtins[]={
277
+	{	"?",		kamcmd_help, "help"},
278
+	{	"help",		kamcmd_help, "displays help for a command"},
279
+	{	"version",	kamcmd_ver,  "displays " NAME "version"},
280
+	{	"quit",		kamcmd_quit, "exits " NAME },
281
+	{	"exit",		kamcmd_quit, "exits " NAME },
282
+	{	"warranty",		kamcmd_warranty, "displays " NAME "'s warranty info"},
283
+	{	"license",		kamcmd_warranty, "displays " NAME "'s license"},
283 284
 	{0,0}
284 285
 };
285 286
 
... ...
@@ -294,9 +286,6 @@ enum complete_states {
294 294
 	COMPLETE_CFG_GRP,
295 295
 	COMPLETE_CFG_VAR,
296 296
 #endif /* USE_CFG_VARS */
297
-#ifdef USE_MI
298
-	COMPLETE_MI,
299
-#endif /* USE_Mi */
300 297
 #ifdef USE_COUNTERS
301 298
 	COMPLETE_CNT_GRP,
302 299
 	COMPLETE_CNT_VAR,
... ...
@@ -332,17 +321,6 @@ char* complete_params_cfg_var[]={
332 332
 };
333 333
 #endif /* USE_CFG_VARS */
334 334
 
335
-#ifdef USE_MI
336
-/* commands for which we complete the first param with an mi command*/
337
-char* complete_params_mi[]={
338
-	"mi",
339
-	"mi_fifo",
340
-	"mi_dg",
341
-	"mi_xmlrpc",
342
-	0
343
-};
344
-#endif /* USE_MI */
345
-
346 335
 #ifdef USE_COUNTERS
347 336
 /* commands for which we complete the first param with a counter group */
348 337
 char* complete_param1_counter_grp[] = {
... ...
@@ -1208,7 +1186,7 @@ error:
1208 1208
 
1209 1209
 
1210 1210
 
1211
-static int get_sercmd_list(int s)
1211
+static int get_kamcmd_list(int s)
1212 1212
 {
1213 1213
 	struct binrpc_cmd cmd;
1214 1214
 	int cookie;
... ...
@@ -1256,7 +1234,7 @@ error:
1256 1256
 
1257 1257
 
1258 1258
 
1259
-#if defined(USE_CFG_VARS) || defined (USE_MI) || defined (USE_COUNTERS)
1259
+#if defined(USE_CFG_VARS) || defined (USE_COUNTERS)
1260 1260
 /** check if cmd is a rpc command.
1261 1261
  * Quick check (using the internal rpc_array) if cmd is a valid rpc command.
1262 1262
  * @param cmd - null terminated ascii string
... ...
@@ -1266,7 +1244,7 @@ static int is_rpc_cmd(char* cmd)
1266 1266
 {
1267 1267
 	int r;
1268 1268
 	int cmd_len;
1269
-	
1269
+
1270 1270
 	cmd_len=strlen(cmd);
1271 1271
 	for (r=0; r<rpc_no; r++){
1272 1272
 		if ((rpc_array[r].type==BINRPC_T_STR) &&
... ...
@@ -1276,7 +1254,7 @@ static int is_rpc_cmd(char* cmd)
1276 1276
 	}
1277 1277
 	return 0;
1278 1278
 }
1279
-#endif /* USE_CFG_VARS || USE_MI */
1279
+#endif /* USE_CFG_VARS */
1280 1280
 
1281 1281
 
1282 1282
 
... ...
@@ -1429,128 +1407,6 @@ void free_cfg_grp_lst()
1429 1429
 
1430 1430
 
1431 1431
 
1432
-#ifdef USE_MI
1433
-/* retrieve the mi list */
1434
-static int get_mi_list(int s)
1435
-{
1436
-	struct binrpc_cmd cmd;
1437
-	int cookie;
1438
-	unsigned char reply_buf[MAX_REPLY_SIZE];
1439
-	unsigned char* msg_body;
1440
-	struct binrpc_parse_ctx in_pkt;
1441
-	char* p;
1442
-	char* end;
1443
-	str mi_name;
1444
-	int mi_which_results;
1445
-	int r;
1446
-	int ret;
1447
-	
1448
-	cmd.method="mi";
1449
-	cmd.argv[0].type=BINRPC_T_STR;
1450
-	cmd.argv[0].u.strval.s="which";
1451
-	cmd.argv[0].u.strval.len=strlen(cmd.argv[0].u.strval.s);
1452
-	cmd.argc=1;
1453
-	if (!is_rpc_cmd(cmd.method)) goto error;
1454
-	
1455
-	cookie=gen_cookie();
1456
-	if ((ret=send_binrpc_cmd(s, &cmd, cookie))<0){
1457
-		if (ret==-1) goto error_send;
1458
-		else goto binrpc_err;
1459
-	}
1460
-	/* read reply */
1461
-	memset(&in_pkt, 0, sizeof(in_pkt));
1462
-	if ((ret=get_reply(s, reply_buf, MAX_REPLY_SIZE, cookie, &in_pkt,
1463
-					&msg_body))<0){
1464
-		goto error;
1465
-	}
1466
-	switch(in_pkt.type){
1467
-		case BINRPC_FAULT:
1468
-			if (print_fault(&in_pkt, msg_body, in_pkt.tlen)<0){
1469
-				goto error;
1470
-			}
1471
-			break;
1472
-		case BINRPC_REPL:
1473
-			mi_which_no=25; /* default rpc list */
1474
-			if ((mi_which_array=parse_reply_body(&mi_which_no, &in_pkt,
1475
-												msg_body, in_pkt.tlen))==0)
1476
-				goto error;
1477
-			break;
1478
-		default:
1479
-			fprintf(stderr, "ERROR: not a reply\n");
1480
-			goto error;
1481
-	}
1482
-	
1483
-	
1484
-	/* get the mi commands number */
1485
-	mi_which_results=0;
1486
-	for (r=0; r<mi_which_no; r++){
1487
-		if (mi_which_array[r].type!=BINRPC_T_STR)
1488
-			continue;
1489
-		/* we are interestend only in lines starting with ':', e.g.:
1490
-		   :: version */
1491
-		if ((mi_which_array[r].u.strval.len) &&
1492
-			(mi_which_array[r].u.strval.s[0]==':'))
1493
-			mi_which_results++;
1494
-	}
1495
-	/* no mi commands */
1496
-	if (mi_which_results==0)
1497
-		goto error;
1498
-	/* alloc the mi_cmds array */
1499
-	mi_cmds=malloc(mi_which_results*sizeof(*mi_cmds));
1500
-	if (mi_cmds==0) goto error_mem;
1501
-	memset(mi_cmds, 0, mi_which_results* sizeof(*mi_cmds));
1502
-	/* get the mi names list */
1503
-	for (r=0; r<mi_which_no; r++){
1504
-		if (mi_which_array[r].type!=BINRPC_T_STR)
1505
-			continue;
1506
-		p=mi_which_array[r].u.strval.s;
1507
-		end=p+mi_which_array[r].u.strval.len;
1508
-		/* we are interestend only in lines starting with ':', e.g.:
1509
-			:: version */
1510
-		if ((p>=end) || (*p!=':'))
1511
-			continue;
1512
-		p++;
1513
-		/* skip over to the next ':' */
1514
-		for(;p<end && *p!=':'; p++);
1515
-		if (p>=end) continue;
1516
-		p++;
1517
-		/* skip over spaces */
1518
-		for(;p<end && (*p==' ' || *p=='\t'); p++);
1519
-		if (p>=end || *p=='\n') continue;
1520
-		if (mi_cmds_no >= mi_which_results){
1521
-			fprintf(stderr, "BUG: wrong mi cmds no (%d >= %d)\n",
1522
-							mi_cmds_no, mi_which_results);
1523
-			goto error;
1524
-		}
1525
-		mi_name.s=p;
1526
-		for(; p<end && *p!=' ' && *p!='\t' && *p!='\n'; p++);
1527
-		mi_name.len=(int)(long)(p-mi_name.s);
1528
-		mi_cmds[mi_cmds_no]=mi_name;
1529
-		mi_cmds_no++;
1530
-	}
1531
-	
1532
-	return 0;
1533
-binrpc_err:
1534
-error_send:
1535
-error:
1536
-error_mem:
1537
-	return -1;
1538
-}
1539
-
1540
-
1541
-
1542
-void free_mi_cmds()
1543
-{
1544
-	if (mi_cmds){
1545
-		free(mi_cmds);
1546
-		mi_cmds=0;
1547
-		mi_cmds_no=0;
1548
-	}
1549
-}
1550
-#endif /* USE_MI */
1551
-
1552
-
1553
-
1554 1432
 #ifdef USE_COUNTERS
1555 1433
 /* retrieve the counters names and group list */
1556 1434
 static int get_counters_list(int s)
... ...
@@ -1729,7 +1585,7 @@ static void print_formatting(char* prefix, char* format, char* suffix)
1729 1729
 
1730 1730
 
1731 1731
 
1732
-static int sercmd_help(int s, struct binrpc_cmd* cmd)
1732
+static int kamcmd_help(int s, struct binrpc_cmd* cmd)
1733 1733
 {
1734 1734
 	int r;
1735 1735
 	
... ...
@@ -1760,7 +1616,7 @@ static int sercmd_help(int s, struct binrpc_cmd* cmd)
1760 1760
 	}
1761 1761
 		
1762 1762
 	if (rpc_no==0){
1763
-		if (get_sercmd_list(s)<0)
1763
+		if (get_kamcmd_list(s)<0)
1764 1764
 			goto error;
1765 1765
 	}
1766 1766
 	for (r=0; r<rpc_no; r++){
... ...
@@ -1781,7 +1637,7 @@ error:
1781 1781
 
1782 1782
 
1783 1783
 
1784
-static int sercmd_ver(int s, struct binrpc_cmd* cmd)
1784
+static int kamcmd_ver(int s, struct binrpc_cmd* cmd)
1785 1785
 {
1786 1786
 	printf("%s\n", version);
1787 1787
 	printf("%s compiled on %s \n", __FILE__, compiled);
... ...
@@ -1793,7 +1649,7 @@ static int sercmd_ver(int s, struct binrpc_cmd* cmd)
1793 1793
 
1794 1794
 
1795 1795
 
1796
-static int sercmd_quit(int s, struct binrpc_cmd* cmd)
1796
+static int kamcmd_quit(int s, struct binrpc_cmd* cmd)
1797 1797
 {
1798 1798
 	quit=1;
1799 1799
 	return 0;
... ...
@@ -1801,7 +1657,7 @@ static int sercmd_quit(int s, struct binrpc_cmd* cmd)
1801 1801
 
1802 1802
 
1803 1803
 
1804
-static int sercmd_warranty(int s, struct binrpc_cmd *cmd)
1804
+static int kamcmd_warranty(int s, struct binrpc_cmd *cmd)
1805 1805
 {
1806 1806
 	printf("%s %s\n", NAME, VERSION);
1807 1807
 	printf("%s\n", COPYRIGHT);
... ...
@@ -1813,7 +1669,7 @@ static int sercmd_warranty(int s, struct binrpc_cmd *cmd)
1813 1813
 #ifdef USE_READLINE
1814 1814
 
1815 1815
 /* readline command generator */
1816
-static char* sercmd_generator(const char* text, int state)
1816
+static char* kamcmd_generator(const char* text, int state)
1817 1817
 {
1818 1818
 	static int idx;
1819 1819
 	static int list; /* aliases, builtins, rpc_array */
... ...
@@ -1913,29 +1769,6 @@ static char* sercmd_generator(const char* text, int state)
1913 1913
 			}
1914 1914
 			break;
1915 1915
 #endif /* USE_CFG_VARS */
1916
-#ifdef USE_MI
1917
-		case COMPLETE_MI:
1918
-			if (state==0){
1919
-				/* init */
1920
-				len=strlen(text);
1921
-				idx=0;
1922
-			}
1923
-			while(idx < mi_cmds_no){
1924
-				if (len<=mi_cmds[idx].len &&
1925
-						memcmp(text, mi_cmds[idx].s, len)==0) {
1926
-					/* zero-term copy of the var name */
1927
-					name=malloc(mi_cmds[idx].len+1);
1928
-					if (name){
1929
-						memcpy(name, mi_cmds[idx].s, mi_cmds[idx].len);
1930
-						name[mi_cmds[idx].len]=0;
1931
-					}
1932
-					idx++;
1933
-					return name;
1934
-				}
1935
-				idx++;
1936
-			}
1937
-			break;
1938
-#endif /* USE_MI */
1939 1916
 #ifdef USE_COUNTERS
1940 1917
 		case COMPLETE_CNT_GRP:
1941 1918
 			if (state==0){
... ...
@@ -1989,7 +1822,7 @@ static char* sercmd_generator(const char* text, int state)
1989 1989
 
1990 1990
 
1991 1991
 
1992
-char** sercmd_completion(const char* text, int start, int end)
1992
+char** kamcmd_completion(const char* text, int start, int end)
1993 1993
 {
1994 1994
 	int i, j;
1995 1995
 	int cmd_start, cmd_end, cmd_len;
... ...
@@ -2058,18 +1891,6 @@ char** sercmd_completion(const char* text, int start, int end)
2058 2058
 				}
2059 2059
 			}
2060 2060
 #endif /* USE_CFG_VARS */
2061
-#ifdef USE_MI
2062
-			/* try complete_parms_mi */
2063
-			for(i=0; complete_params_mi[i]; i++){
2064
-				if ((cmd_len==strlen(complete_params_mi[i])) &&
2065
-						(strncmp(&rl_line_buffer[cmd_start],
2066
-								 complete_params_mi[i],
2067
-								 cmd_len)==0)){
2068
-						attempted_completion_state=COMPLETE_MI;
2069
-						goto end;
2070
-				}
2071
-			}
2072
-#endif /* USE_MI */
2073 2061
 #ifdef USE_COUNTERS
2074 2062
 			/* try  complete_param*_cfg_grp */
2075 2063
 			for(i=0; complete_param1_counter_grp[i]; i++){
... ...
@@ -2145,7 +1966,7 @@ char** sercmd_completion(const char* text, int start, int end)
2145 2145
 		attempted_completion_state=COMPLETE_NOTHING;
2146 2146
 	}
2147 2147
 end:
2148
-	return 0; /* let readline call sercmd_generator */
2148
+	return 0; /* let readline call kamcmd_generator */
2149 2149
 }
2150 2150
 
2151 2151
 #endif /* USE_READLINE */
... ...
@@ -2295,13 +2116,10 @@ int main(int argc, char** argv)
2295 2295
 		goto end;
2296 2296
 	}
2297 2297
 	/* interactive mode */
2298
-	if (get_sercmd_list(s)==0){
2298
+	if (get_kamcmd_list(s)==0){
2299 2299
 	#ifdef USE_CFG_VARS
2300 2300
 		get_cfgvars_list(s);
2301 2301
 	#endif /* USE_CFG_VARS */
2302
-	#ifdef USE_MI
2303
-		get_mi_list(s);
2304
-	#endif /* USE_MI */
2305 2302
 	#ifdef USE_COUNTERS
2306 2303
 		get_counters_list(s);
2307 2304
 	#endif /* USE_COUNTERS */
... ...
@@ -2315,8 +2133,8 @@ int main(int argc, char** argv)
2315 2315
 	/* initialize readline */
2316 2316
 	/* allow conditional parsing of the ~/.inputrc file*/
2317 2317
 	rl_readline_name=NAME; 
2318
-	rl_completion_entry_function=sercmd_generator;
2319
-	rl_attempted_completion_function=sercmd_completion;
2318
+	rl_completion_entry_function=kamcmd_generator;
2319
+	rl_attempted_completion_function=kamcmd_completion;
2320 2320
 	
2321 2321
 	while(!quit){
2322 2322
 		line=readline(NAME "> ");
... ...
@@ -2364,15 +2182,6 @@ end:
2364 2364
 		cfg_vars_no=0;
2365 2365
 	}
2366 2366
 #endif /* USE_CFG_VARS */
2367
-#ifdef USE_MI
2368
-	if (mi_cmds)
2369
-		free_mi_cmds();
2370
-	if (mi_which_array){
2371
-		free_rpc_array(mi_which_array, mi_which_no);
2372
-		mi_which_array=0;
2373
-		mi_which_no=0;
2374
-	}
2375
-#endif /* USE_MI */
2376 2367
 #ifdef USE_COUNTERS
2377 2368
 	if (cnt_grp_lst)
2378 2369
 		free_cnt_grp_lst();
... ...
@@ -2400,15 +2209,6 @@ error:
2400 2400
 		cfg_vars_no=0;
2401 2401
 	}
2402 2402
 #endif /* USE_CFG_VARS */
2403
-#ifdef USE_MI
2404
-	if (mi_cmds)
2405
-		free_mi_cmds();
2406
-	if (mi_which_array){
2407
-		free_rpc_array(mi_which_array, mi_which_no);
2408
-		mi_which_array=0;
2409
-		mi_which_no=0;
2410
-	}
2411
-#endif /* USE_MI */
2412 2403
 #ifdef USE_COUNTERS
2413 2404
 	if (cnt_grp_lst)
2414 2405
 		free_cnt_grp_lst();