Browse code

utils: fixed sinitiser error

[root@localhost]# kamcmd cfg.seti param_group param_name value

=================================================================
==2409977==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 38 byte(s) in 1 object(s) allocated from:
#0 0xffff98c250af in malloc (/lib64/libasan.so.5+0xd50af)
#1 0x41549f in parse_listen_id /root/kamailio/utils/kamcmd/parse_listen_id.c:133
#2 0x4144fb in main /root/kamailio/utils/kamcmd/kamcmd.c:2075
#3 0xffff97dc0de3 in __libc_start_main (/lib64/libc.so.6+0x20de3)
#4 0x40260b (/usr/local/sbin/kamcmd+0x40260b)

Sergey Safarov authored on 20/03/2022 13:12:13 • Daniel-Constantin Mierla committed on 22/03/2022 07:09:12
Showing 1 changed files
... ...
@@ -2106,6 +2106,7 @@ int main(int argc, char** argv)
2106 2106
 			fprintf(stderr, "ERROR: Bad socket type for %s\n", sock_name);
2107 2107
 			goto error;
2108 2108
 	}
2109
+	free(sock_id->buf); /* not needed anymore */
2109 2110
 	free(sock_id); /* not needed anymore */
2110 2111
 	sock_id=0;
2111 2112
 
Browse code

kamcmd: double/float values printed without decimals when they are 0

- cope better with long (long) values stored in double fields

Daniel-Constantin Mierla authored on 12/01/2022 16:05:21
Showing 1 changed files
... ...
@@ -427,7 +427,11 @@ void print_binrpc_val(struct binrpc_val* v, int ident)
427 427
 			printf("%c", (v->u.end)?'}':'{');
428 428
 			break;
429 429
 		case BINRPC_T_DOUBLE:
430
-			printf("%f", v->u.fval);
430
+			if(v->u.fval == (double)((long long int)v->u.fval)) {
431
+				printf("%lld", (long long int)v->u.fval);
432
+			} else {
433
+				printf("%f", v->u.fval);
434
+			}
431 435
 			break;
432 436
 		default:
433 437
 			printf("ERROR: unknown type %d\n", v->type);
Browse code

utils/kamcmd: default port is 2049, adapt help and README

Henning Westerholt authored on 30/07/2019 14:37:20
Showing 1 changed files
... ...
@@ -103,7 +103,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/kamailio_ctl\n\
106
+                          e.g.:  tcp:localhost:2049 , unixs:/tmp/kamailio_ctl\n\
107 107
 cmd:\n\
108 108
     method  [arg1 [arg2...]]\n\
109 109
 arg:\n\
Browse code

kamcmd: increased the max reply size from 64kB to 128kB

Daniel-Constantin Mierla authored on 12/05/2017 14:19:04
Showing 1 changed files
... ...
@@ -67,9 +67,9 @@
67 67
 #endif
68 68
 
69 69
 #define IOVEC_CNT 20
70
-#define MAX_LINE_SIZE 16384 /* for non readline mode */
71
-#define MAX_REPLY_SIZE 65536
72
-#define MAX_BODY_SIZE  65536
70
+#define MAX_LINE_SIZE 16*1024 /* for non readline mode */
71
+#define MAX_REPLY_SIZE 128*1024
72
+#define MAX_BODY_SIZE  128*1024
73 73
 #define MAX_BINRPC_ARGS 256
74 74
 
75 75
 
Browse code

Add and fix #includes for more strict POSIX compliance

- sys/poll.h is non-standard, posix defines poll.h
- sys/time.h is needed in addition to time.h for e.g. struct timeval

Notable this fixes some build errors against musl libc

Timo Teräs authored on 28/04/2017 06:58:50
Showing 1 changed files
... ...
@@ -41,6 +41,7 @@
41 41
 #include <netdb.h> /* gethostbyname */
42 42
 #include <fcntl.h>
43 43
 #include <time.h> /* time */
44
+#include <sys/time.h>
44 45
 
45 46
 #ifdef USE_READLINE
46 47
 #include <readline/readline.h>
Browse code

kamcmd: removed svn ids, history

Daniel-Constantin Mierla authored on 13/01/2017 07:58:54
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * Copyright (C) 2006 iptelorg GmbH
3 3
  *
4
- * This file is part of kamailio, a free SIP server.
4
+ * This file is part of kamcmd, a free cli tool for Kamailio SIP server.
5 5
  *
6 6
  * kamailio is free software; you can redistribute it and/or modify
7 7
  * it under the terms of the GNU General Public License as published by
... ...
@@ -176,7 +176,7 @@ static inline char* int2str(unsigned int l, int* len)
176 176
 {
177 177
 	static char r[INT2STR_MAX_LEN];
178 178
 	int i;
179
-	
179
+
180 180
 	i=INT2STR_MAX_LEN-2;
181 181
 	r[INT2STR_MAX_LEN-1]=0; /* null terminate */
182 182
 	do{
... ...
@@ -196,11 +196,11 @@ static inline char* int2str(unsigned int l, int* len)
196 196
 static char* trim_ws(char* l)
197 197
 {
198 198
 	char* ret;
199
-	
199
+
200 200
 	for(;*l && ((*l==' ')||(*l=='\t')||(*l=='\n')||(*l=='\r')); l++);
201 201
 	ret=l;
202 202
 	if (*ret==0) return ret;
203
-	for(l=l+strlen(l)-1; (l>ret) && 
203
+	for(l=l+strlen(l)-1; (l>ret) &&
204 204
 			((*l==' ')||(*l=='\t')||(*l=='\n')||(*l=='\r')); l--);
205 205
 	*(l+1)=0;
206 206
 	return ret;
... ...
@@ -353,7 +353,7 @@ static int parse_arg(struct binrpc_val* v, char* arg)
353 353
 	double f;
354 354
 	char* tmp;
355 355
 	int len;
356
-	
356
+
357 357
 	i=strtol(arg, &tmp, 10);
358 358
 	if ((tmp==0) || (*tmp)){
359 359
 		f=strtod(arg, &tmp);
... ...
@@ -385,7 +385,7 @@ static int parse_arg(struct binrpc_val* v, char* arg)
385 385
 static int parse_cmd(struct binrpc_cmd* cmd, char** argv, int count)
386 386
 {
387 387
 	int r;
388
-	
388
+
389 389
 	cmd->method=argv[0];
390 390
 	if ((count-1)>MAX_BINRPC_ARGS){
391 391
 		fprintf(stderr,  "ERROR: too many args %d, only %d allowed\n",
... ...
@@ -444,7 +444,7 @@ int connect_unix_sock(char* name, int type)
444 444
 	int len;
445 445
 	int ret;
446 446
 	int retries;
447
-	
447
+
448 448
 	retries=0;
449 449
 	s=-1;
450 450
 	memset(&ifsun, 0, sizeof (struct sockaddr_un));
... ...
@@ -472,7 +472,7 @@ int connect_unix_sock(char* name, int type)
472 472
 				sock_dir="/tmp";
473 473
 retry:
474 474
 			ret=snprintf(mysun.sun_path, UNIX_PATH_MAX, "%s/" NAME "_%d",
475
-							sock_dir, rand()); 
475
+							sock_dir, rand());
476 476
 			if ((ret<0) ||(ret>=UNIX_PATH_MAX)){
477 477
 				fprintf(stderr, "ERROR: buffer overflow while trying to"
478 478
 							"generate unix datagram socket name");
... ...
@@ -519,7 +519,7 @@ int connect_tcpudp_socket(char* address, int port, int type)
519 519
 	struct sockaddr_in addr;
520 520
 	struct hostent* he;
521 521
 	int sock;
522
-	
522
+
523 523
 	sock=-1;
524 524
 	/* resolve destination */
525 525
 	he=gethostbyname(address);
... ...
@@ -531,7 +531,7 @@ int connect_tcpudp_socket(char* address, int port, int type)
531 531
 	addr.sin_family=he->h_addrtype;
532 532
 	addr.sin_port=htons(port);
533 533
 	memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length);
534
-	
534
+
535 535
 	sock = socket(he->h_addrtype, type, 0);
536 536
 	if (sock==-1){
537 537
 		fprintf(stderr, "ERROR: socket: %s\n", strerror(errno));
... ...
@@ -552,7 +552,7 @@ error:
552 552
 static void hexdump(unsigned char* buf, int len, int ascii)
553 553
 {
554 554
 	int r, i;
555
-	
555
+
556 556
 	/* dump it in hex */
557 557
 	for (r=0; r<len; r++){
558 558
 		if ((r) && ((r%16)==0)){
... ...
@@ -595,7 +595,7 @@ static int send_binrpc_cmd(int s, struct binrpc_cmd* cmd, int cookie)
595 595
 	struct binrpc_pkt body;
596 596
 	int ret;
597 597
 	int n;
598
-	
598
+
599 599
 	ret=binrpc_init_pkt(&body, msg_body, MAX_BODY_SIZE);
600 600
 	if (ret<0) goto binrpc_err;
601 601
 	ret=binrpc_addstr(&body, cmd->method, strlen(cmd->method));
... ...
@@ -631,7 +631,7 @@ write_again:
631 631
 			goto write_again;
632 632
 		goto error_send;
633 633
 	}
634
-	
634
+
635 635
 	return n;
636 636
 error_send:
637 637
 	return -1;
... ...
@@ -646,7 +646,7 @@ static int binrpc_errno=0;
646 646
  * returns < 0 on error, reply size on success + initializes in_pkt
647 647
  * if ret==-2 (parse error), sets binrpc_errno to the binrpc error
648 648
  * error returns: -1 - read error (check errno)
649
- *                -2 - binrpc parse error (chekc binrpc_errno) 
649
+ *                -2 - binrpc parse error (chekc binrpc_errno)
650 650
  *                -3 - cookie error (the cookied doesn't match)
651 651
  *                -4 - message too big */
652 652
 static int get_reply(int s, unsigned char* reply_buf, int max_reply_size,
... ...
@@ -658,8 +658,7 @@ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size,
658 658
 	unsigned char* msg_end;
659 659
 	int n;
660 660
 	int ret;
661
-	
662
-	
661
+
663 662
 	hdr_end=crt=reply_buf;
664 663
 	msg_end=reply_buf+max_reply_size;
665 664
 	binrpc_errno=0;
... ...
@@ -716,7 +715,7 @@ static int get_reply(int s, unsigned char* reply_buf, int max_reply_size,
716 715
 			}
717 716
 		}
718 717
 	}while(crt<msg_end);
719
-	
718
+
720 719
 	*body=hdr_end;
721 720
 	return (int)(msg_end-reply_buf);
722 721
 error_read:
... ...
@@ -737,11 +736,11 @@ static char* str_escape(char* str)
737 736
 {
738 737
 	char* n;
739 738
 	char* ret;
740
-	
739
+
741 740
 	ret=n=malloc(strlen(str)+1);
742 741
 	if (n==0)
743 742
 		goto end;
744
-	
743
+
745 744
 	for(;*str;str++){
746 745
 		*n=*str;
747 746
 		if (*str=='\\'){
... ...
@@ -786,7 +785,7 @@ end:
786 785
  *          printf("%.*s", size, s);
787 786
  *          if (type==-1)
788 787
  *            continue;
789
- *          else 
788
+ *          else
790 789
  *             printf("now we should get & print an object of type %d\n", type)
791 790
  *        }
792 791
  */
... ...
@@ -820,10 +819,10 @@ static char* parse_fmt(char* fmt, int* type, int* size)
820 819
 
821 820
 
822 821
 
823
-static int print_body(struct binrpc_parse_ctx* in_pkt, 
822
+static int print_body(struct binrpc_parse_ctx* in_pkt,
824 823
 						unsigned char* body, int size, char* fmt)
825 824
 {
826
-	
825
+
827 826
 	unsigned char* p;
828 827
 	unsigned char* end;
829 828
 	struct binrpc_val val;
... ...
@@ -833,7 +832,7 @@ static int print_body(struct binrpc_parse_ctx* in_pkt,
833 832
 	char* s;
834 833
 	int f_size;
835 834
 	int fmt_has_values;
836
-	
835
+
837 836
 	p=body;
838 837
 	end=p+size;
839 838
 	rec=0;
... ...
@@ -842,7 +841,7 @@ static int print_body(struct binrpc_parse_ctx* in_pkt,
842 841
 	/* read body */
843 842
 	while(p<end){
844 843
 		if (f){
845
-			
844
+
846 845
 			do{
847 846
 				if (*f==0)
848 847
 					f=fmt; /* reset */
... ...
@@ -903,7 +902,7 @@ error:
903 902
 
904 903
 
905 904
 
906
-static int print_fault(struct binrpc_parse_ctx* in_pkt, 
905
+static int print_fault(struct binrpc_parse_ctx* in_pkt,
907 906
 						unsigned char* body, int size)
908 907
 {
909 908
 	printf("error: ");
... ...
@@ -919,7 +918,7 @@ static int run_binrpc_cmd(int s, struct binrpc_cmd * cmd, char* fmt)
919 918
 	unsigned char* msg_body;
920 919
 	struct binrpc_parse_ctx in_pkt;
921 920
 	int ret;
922
-	
921
+
923 922
 	cookie=gen_cookie();
924 923
 	if ((ret=send_binrpc_cmd(s, cmd, cookie))<0){
925 924
 		if (ret==-1) goto error_send;
... ...
@@ -960,11 +959,11 @@ static int run_binrpc_cmd(int s, struct binrpc_cmd * cmd, char* fmt)
960 959
 	/* normal exit */
961 960
 	return 0;
962 961
 binrpc_err:
963
-	fprintf(stderr, "ERROR while building the packet: %s\n", 
962
+	fprintf(stderr, "ERROR while building the packet: %s\n",
964 963
 				binrpc_error(ret));
965 964
 	goto error;
966 965
 error_parse:
967
-	fprintf(stderr, "ERROR while parsing the reply: %s\n", 
966
+	fprintf(stderr, "ERROR while parsing the reply: %s\n",
968 967
 				binrpc_error(binrpc_errno));
969 968
 	goto error;
970 969
 error_cookie:
... ...
@@ -991,7 +990,7 @@ static int parse_line(struct binrpc_cmd* cmd, char* line)
991 990
 {
992 991
 	char* p;
993 992
 	int count;
994
-	
993
+
995 994
 	cmd->method=strtok(line, " \t");
996 995
 	if (cmd->method==0)
997 996
 		goto error_no_method;
... ...
@@ -1024,7 +1023,7 @@ error_arg:
1024 1023
 static void fix_cmd(struct binrpc_cmd* cmd, char** format)
1025 1024
 {
1026 1025
 	int r;
1027
-	
1026
+
1028 1027
 	for (r=0; cmd_aliases[r].name; r++){
1029 1028
 		if (strcmp(cmd_aliases[r].name, cmd->method)==0){
1030 1029
 			cmd->method=cmd_aliases[r].method;
... ...
@@ -1043,7 +1042,7 @@ static int run_builtins(int s, struct binrpc_cmd* cmd)
1043 1042
 {
1044 1043
 	int r;
1045 1044
 	int ret;
1046
-	
1045
+
1047 1046
 	for (r=0; builtins[r].name; r++){
1048 1047
 		if (strcmp(builtins[r].name, cmd->method)==0){
1049 1048
 			ret=builtins[r].f(s, cmd);
... ...
@@ -1062,7 +1061,7 @@ inline static int run_cmd(int s, struct binrpc_cmd* cmd, char* format)
1062 1061
 	char* fmt;
1063 1062
 
1064 1063
 	fmt=format;
1065
-	
1064
+
1066 1065
 	fix_cmd(cmd, &fmt);
1067 1066
 	if (!(ret=run_builtins(s, cmd))){
1068 1067
 		ret=run_binrpc_cmd(s, cmd, fmt);
... ...
@@ -1077,7 +1076,7 @@ inline static int run_line(int s, char* l, char* format)
1077 1076
 {
1078 1077
 	struct binrpc_cmd cmd;
1079 1078
 	int ret;
1080
-	
1079
+
1081 1080
 	if ((ret=parse_line(&cmd, l))==0){
1082 1081
 		return run_cmd(s, &cmd, format);
1083 1082
 	}
... ...
@@ -1103,7 +1102,7 @@ static void free_rpc_array(struct binrpc_val* a, int size)
1103 1102
 
1104 1103
 
1105 1104
 /* parse the body into a malloc allocated,  binrpc_val array */
1106
-static struct binrpc_val* parse_reply_body(int* records, 
1105
+static struct binrpc_val* parse_reply_body(int* records,
1107 1106
 											struct binrpc_parse_ctx* in_pkt,
1108 1107
 											unsigned char* body, int size)
1109 1108
 {
... ...
@@ -1124,7 +1123,7 @@ static struct binrpc_val* parse_reply_body(int* records,
1124 1123
 		goto error_mem;
1125 1124
 	p=body;
1126 1125
 	end=p+size;
1127
-	
1126
+
1128 1127
 	/* read body */
1129 1128
 	while(p<end){
1130 1129
 		val.type=BINRPC_T_ALL;
... ...
@@ -1194,10 +1193,10 @@ static int get_kamcmd_list(int s)
1194 1193
 	unsigned char* msg_body;
1195 1194
 	struct binrpc_parse_ctx in_pkt;
1196 1195
 	int ret;
1197
-	
1196
+
1198 1197
 	cmd.method="system.listMethods";
1199 1198
 	cmd.argc=0;
1200
-	
1199
+
1201 1200
 	cookie=gen_cookie();
1202 1201
 	if ((ret=send_binrpc_cmd(s, &cmd, cookie))<0){
1203 1202
 		if (ret==-1) goto error_send;
... ...
@@ -1275,11 +1274,11 @@ static int get_cfgvars_list(int s)
1275 1274
 	str var_name;
1276 1275
 	int r;
1277 1276
 	int ret;
1278
-	
1277
+
1279 1278
 	cmd.method="cfg.list";
1280 1279
 	cmd.argc=0;
1281 1280
 	if (!is_rpc_cmd(cmd.method)) goto error;
1282
-	
1281
+
1283 1282
 	cookie=gen_cookie();
1284 1283
 	if ((ret=send_binrpc_cmd(s, &cmd, cookie))<0){
1285 1284
 		if (ret==-1) goto error_send;
... ...
@@ -1394,7 +1393,7 @@ void free_cfg_grp_lst()
1394 1393
 {
1395 1394
 	struct cfg_var_grp* grp;
1396 1395
 	struct cfg_var_grp* last;
1397
-	
1396
+
1398 1397
 	grp=cfg_grp_lst;
1399 1398
 	while(grp){
1400 1399
 		last=grp;
... ...
@@ -1422,11 +1421,11 @@ static int get_counters_list(int s)
1422 1421
 	str var_name;
1423 1422
 	int r;
1424 1423
 	int ret;
1425
-	
1424
+
1426 1425
 	cmd.method="cnt.grps_list";
1427 1426
 	cmd.argc=0;
1428 1427
 	if (!is_rpc_cmd(cmd.method)) goto error;
1429
-	
1428
+
1430 1429
 	cookie=gen_cookie();
1431 1430
 	if ((ret=send_binrpc_cmd(s, &cmd, cookie))<0){
1432 1431
 		if (ret==-1) goto error_send;
... ...
@@ -1544,7 +1543,7 @@ void free_cnt_grp_lst()
1544 1543
 {
1545 1544
 	struct cnt_var_grp* grp;
1546 1545
 	struct cnt_var_grp* last;
1547
-	
1546
+
1548 1547
 	grp=cnt_grp_lst;
1549 1548
 	while(grp){
1550 1549
 		last=grp;
... ...
@@ -1588,7 +1587,7 @@ static void print_formatting(char* prefix, char* format, char* suffix)
1588 1587
 static int kamcmd_help(int s, struct binrpc_cmd* cmd)
1589 1588
 {
1590 1589
 	int r;
1591
-	
1590
+
1592 1591
 	if (cmd->argc && (cmd->argv[0].type==BINRPC_T_STR)){
1593 1592
 		/* if it has args, try command help */
1594 1593
 		for (r=0; cmd_aliases[r].name; r++){
... ...
@@ -1603,7 +1602,7 @@ static int kamcmd_help(int s, struct binrpc_cmd* cmd)
1603 1602
 		}
1604 1603
 		for(r=0; builtins[r].name; r++){
1605 1604
 			 if (strcmp(cmd->argv[0].u.strval.s, builtins[r].name)==0){
1606
-				 printf("builtin command: %s\n", 
1605
+				 printf("builtin command: %s\n",
1607 1606
 						 builtins[r].doc?builtins[r].doc:"undocumented");
1608 1607
 				 return 0;
1609 1608
 			 }
... ...
@@ -1614,7 +1613,7 @@ static int kamcmd_help(int s, struct binrpc_cmd* cmd)
1614 1613
 		}
1615 1614
 		return 0;
1616 1615
 	}
1617
-		
1616
+
1618 1617
 	if (rpc_no==0){
1619 1618
 		if (get_kamcmd_list(s)<0)
1620 1619
 			goto error;
... ...
@@ -1837,7 +1836,7 @@ char** kamcmd_completion(const char* text, int start, int end)
1837 1836
 	static int cnt_grp_start;
1838 1837
 	int cnt_grp_len;
1839 1838
 #endif /* USE_COUNTERS */
1840
-	
1839
+
1841 1840
 	crt_param_no=0;
1842 1841
 	/* skip over whitespace at the beginning */
1843 1842
 	for (j=0; (j<start) && (rl_line_buffer[j]==' ' ||
... ...
@@ -2044,12 +2043,12 @@ int main(int argc, char** argv)
2044 2043
 				if (isprint(optopt))
2045 2044
 					fprintf(stderr, "Unknown option `-%c'.\n", optopt);
2046 2045
 				else
2047
-					fprintf(stderr, 
2046
+					fprintf(stderr,
2048 2047
 							"Unknown option character `\\x%x'.\n",
2049 2048
 							optopt);
2050 2049
 				goto error;
2051 2050
 			case ':':
2052
-				fprintf(stderr, 
2051
+				fprintf(stderr,
2053 2052
 						"Option `-%c' requires an argument.\n",
2054 2053
 						optopt);
2055 2054
 				goto error;
... ...
@@ -2060,10 +2059,10 @@ int main(int argc, char** argv)
2060 2059
 	if (sock_name==0){
2061 2060
 		sock_name=DEFAULT_CTL_SOCKET;
2062 2061
 	}
2063
-	
2062
+
2064 2063
 	/* init the random number generator */
2065 2064
 	srand(getpid()+time(0)); /* we don't need very strong random numbers */
2066
-	
2065
+
2067 2066
 	if (sock_name==0){
2068 2067
 		fprintf(stderr, "ERROR: no server socket address specified\n");
2069 2068
 		goto error;
... ...
@@ -2073,7 +2072,7 @@ int main(int argc, char** argv)
2073 2072
 		fprintf(stderr, "ERROR: error parsing server socket address %s\n", sock_name);
2074 2073
 		goto error;
2075 2074
 	}
2076
-	
2075
+
2077 2076
 	switch(sock_id->proto){
2078 2077
 		case UDP_SOCK:
2079 2078
 		case TCP_SOCK:
... ...
@@ -2104,14 +2103,14 @@ int main(int argc, char** argv)
2104 2103
 	}
2105 2104
 	free(sock_id); /* not needed anymore */
2106 2105
 	sock_id=0;
2107
-	
2106
+
2108 2107
 	if (optind>=argc){
2109 2108
 			/*fprintf(stderr, "ERROR: no command specified\n");
2110 2109
 			goto error; */
2111 2110
 	}else{
2112 2111
 		if (parse_cmd(&cmd, &argv[optind], argc-optind)<0)
2113 2112
 			goto error;
2114
-		if (run_cmd(s, &cmd, format)<0) 
2113
+		if (run_cmd(s, &cmd, format)<0)
2115 2114
 			goto error;
2116 2115
 		goto end;
2117 2116
 	}
... ...
@@ -2129,17 +2128,17 @@ int main(int argc, char** argv)
2129 2128
 	printf("%s\n", COPYRIGHT);
2130 2129
 	printf("%s\n", DISCLAIMER);
2131 2130
 #ifdef USE_READLINE
2132
-	
2131
+
2133 2132
 	/* initialize readline */
2134 2133
 	/* allow conditional parsing of the ~/.inputrc file*/
2135
-	rl_readline_name=NAME; 
2134
+	rl_readline_name=NAME;
2136 2135
 	rl_completion_entry_function=kamcmd_generator;
2137 2136
 	rl_attempted_completion_function=kamcmd_completion;
2138
-	
2137
+
2139 2138
 	while(!quit){
2140 2139
 		line=readline(NAME "> ");
2141 2140
 		if (line==0) /* EOF */
2142
-			break; 
2141
+			break;
2143 2142
 		l=trim_ws(line); /* trim whitespace */
2144 2143
 		if (*l){
2145 2144
 			add_history(l);
Browse code

kamctl: fixed small typo

Daniel-Constantin Mierla authored on 06/01/2017 14:31:18
Showing 1 changed files
... ...
@@ -406,7 +406,7 @@ void print_binrpc_val(struct binrpc_val* v, int ident)
406 406
 	int r;
407 407
 
408 408
 	if ((v->type==BINRPC_T_STRUCT) && !v->u.end)
409
-		ident--; /* fix to have strut beg. idented differently */
409
+		ident--; /* fix to have struct beg. idented differently */
410 410
 	for (r=0; r<ident; r++) putchar('	');
411 411
 	if (v->name.s){
412 412
 		printf("%.*s: ", v->name.len, v->name.s);
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 102
     -h          This help message\n\
104 103
 address:\n\
105 104
     [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\
105
+                          e.g.:  tcp:localhost:2048 , unixs:/tmp/kamailio_ctl\n\
107 106
 cmd:\n\
108 107
     method  [arg1 [arg2...]]\n\
109 108
 arg:\n\
... ...
@@ -144,14 +143,6 @@ struct cfg_var_grp* cfg_grp_lst; /** cfg groups list, allong with var names*/
144 143
 struct cfg_var_grp* crt_cfg_grp;
145 144
 #endif /* USE_CFG_VARS */
146 145
 
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 146
 #ifdef USE_COUNTERS
156 147
 struct binrpc_val* cnt_grps_array; /* response array */
157 148
 int cnt_grps_no; /* number of response records */
... ...
@@ -238,48 +229,49 @@ struct cmd_alias{
238 229
 };
239 230
 
240 231
 
241
-struct sercmd_builtin{
232
+struct kamcmd_builtin{
242 233
 	char* name;
243 234
 	int (*f)(int, struct binrpc_cmd*);
244 235
 	char* doc;
245 236
 };
246 237
 
247 238
 
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);
239
+static int kamcmd_help(int s, struct binrpc_cmd* cmd);
240
+static int kamcmd_ver(int s, struct binrpc_cmd* cmd);
241
+static int kamcmd_quit(int s, struct binrpc_cmd* cmd);
242
+static int kamcmd_warranty(int s, struct binrpc_cmd* cmd);
252 243
 
253 244
 
254 245
 static struct cmd_alias cmd_aliases[]={
255 246
 	{	"ps",			"core.ps",				"%v\t%v\n"	},
247
+	{	"psx",			"core.psx",				0			},
256 248
 	{	"list",			"system.listMethods",	0			},
257 249
 	{	"ls",			"system.listMethods",	0			},
258
-	{	"server",		"core.version",			0			},
259
-	{	"serversion",	"core.version",			0			},
250
+	{	"ver",			"core.version",			0			},
251
+	{	"version",		"core.version",			0			},
260 252
 	{	"who",			"ctl.who",				"[%v] %v: %v %v -> %v %v\n"},
261 253
 	{	"listen",		"ctl.listen",			"[%v] %v: %v %v\n"},
262 254
 	{	"dns_mem_info",		"dns.mem_info",			"%v / %v\n"},
263
-	{	"dns_debug",	"dns.debug",			
255
+	{	"dns_debug",	"dns.debug",
264 256
 					"%v (%v): size=%v ref=%v expire=%vs last=%vs ago f=%v\n"},
265
-	{	"dns_debug_all",	"dns.debug_all",			
257
+	{	"dns_debug_all",	"dns.debug_all",
266 258
 			"%v (%v) [%v]: size=%v ref=%v expire=%vs last=%vs ago f=%v\n"
267 259
 			"\t\t%v:%v expire=%vs f=%v\n"},
268 260
 	{	"dst_blacklist_mem_info",	"dst_blacklist.mem_info",	"%v / %v\n"},
269
-	{	"dst_blacklist_debug",		"dst_blacklist.debug",	
261
+	{	"dst_blacklist_debug",		"dst_blacklist.debug",
270 262
 		"%v:%v:%v expire:%v flags: %v\n"},
271 263
 	{0,0,0}
272 264
 };
273 265
 
274 266
 
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"},
267
+static struct kamcmd_builtin builtins[]={
268
+	{	"?",		kamcmd_help, "help"},
269
+	{	"help",		kamcmd_help, "displays help for a command"},
270
+	{	"version",	kamcmd_ver,  "displays " NAME "version"},
271
+	{	"quit",		kamcmd_quit, "exits " NAME },
272
+	{	"exit",		kamcmd_quit, "exits " NAME },
273
+	{	"warranty",		kamcmd_warranty, "displays " NAME "'s warranty info"},
274
+	{	"license",		kamcmd_warranty, "displays " NAME "'s license"},
283 275
 	{0,0}
284 276
 };
285 277
 
... ...
@@ -294,9 +286,6 @@ enum complete_states {
294 286
 	COMPLETE_CFG_GRP,
295 287
 	COMPLETE_CFG_VAR,
296 288
 #endif /* USE_CFG_VARS */
297
-#ifdef USE_MI
298
-	COMPLETE_MI,
299
-#endif /* USE_Mi */
300 289
 #ifdef USE_COUNTERS
301 290
 	COMPLETE_CNT_GRP,
302 291
 	COMPLETE_CNT_VAR,
... ...
@@ -332,17 +321,6 @@ char* complete_params_cfg_var[]={
332 321
 };
333 322
 #endif /* USE_CFG_VARS */
334 323
 
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 324
 #ifdef USE_COUNTERS
347 325
 /* commands for which we complete the first param with a counter group */
348 326
 char* complete_param1_counter_grp[] = {
... ...
@@ -1208,7 +1186,7 @@ error:
1208 1186
 
1209 1187
 
1210 1188
 
1211
-static int get_sercmd_list(int s)
1189
+static int get_kamcmd_list(int s)
1212 1190
 {
1213 1191
 	struct binrpc_cmd cmd;
1214 1192
 	int cookie;
... ...
@@ -1256,7 +1234,7 @@ error:
1256 1234
 
1257 1235
 
1258 1236
 
1259
-#if defined(USE_CFG_VARS) || defined (USE_MI) || defined (USE_COUNTERS)
1237
+#if defined(USE_CFG_VARS) || defined (USE_COUNTERS)
1260 1238
 /** check if cmd is a rpc command.
1261 1239
  * Quick check (using the internal rpc_array) if cmd is a valid rpc command.
1262 1240
  * @param cmd - null terminated ascii string
... ...
@@ -1266,7 +1244,7 @@ static int is_rpc_cmd(char* cmd)
1266 1244
 {
1267 1245
 	int r;
1268 1246
 	int cmd_len;
1269
-	
1247
+
1270 1248
 	cmd_len=strlen(cmd);
1271 1249
 	for (r=0; r<rpc_no; r++){
1272 1250
 		if ((rpc_array[r].type==BINRPC_T_STR) &&
... ...
@@ -1276,7 +1254,7 @@ static int is_rpc_cmd(char* cmd)
1276 1254
 	}
1277 1255
 	return 0;
1278 1256
 }
1279
-#endif /* USE_CFG_VARS || USE_MI */
1257
+#endif /* USE_CFG_VARS */
1280 1258
 
1281 1259
 
1282 1260
 
... ...
@@ -1429,128 +1407,6 @@ void free_cfg_grp_lst()
1429 1407
 
1430 1408
 
1431 1409
 
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 1410
 #ifdef USE_COUNTERS
1555 1411
 /* retrieve the counters names and group list */
1556 1412
 static int get_counters_list(int s)
... ...
@@ -1729,7 +1585,7 @@ static void print_formatting(char* prefix, char* format, char* suffix)
1729 1585
 
1730 1586
 
1731 1587
 
1732
-static int sercmd_help(int s, struct binrpc_cmd* cmd)
1588
+static int kamcmd_help(int s, struct binrpc_cmd* cmd)
1733 1589
 {
1734 1590
 	int r;
1735 1591
 	
... ...
@@ -1760,7 +1616,7 @@ static int sercmd_help(int s, struct binrpc_cmd* cmd)
1760 1616
 	}
1761 1617
 		
1762 1618
 	if (rpc_no==0){
1763
-		if (get_sercmd_list(s)<0)
1619
+		if (get_kamcmd_list(s)<0)
1764 1620
 			goto error;
1765 1621
 	}
1766 1622
 	for (r=0; r<rpc_no; r++){
... ...
@@ -1781,7 +1637,7 @@ error:
1781 1637
 
1782 1638
 
1783 1639
 
1784
-static int sercmd_ver(int s, struct binrpc_cmd* cmd)
1640
+static int kamcmd_ver(int s, struct binrpc_cmd* cmd)
1785 1641
 {
1786 1642
 	printf("%s\n", version);
1787 1643
 	printf("%s compiled on %s \n", __FILE__, compiled);
... ...
@@ -1793,7 +1649,7 @@ static int sercmd_ver(int s, struct binrpc_cmd* cmd)
1793 1649
 
1794 1650
 
1795 1651
 
1796
-static int sercmd_quit(int s, struct binrpc_cmd* cmd)
1652
+static int kamcmd_quit(int s, struct binrpc_cmd* cmd)
1797 1653
 {
1798 1654
 	quit=1;
1799 1655
 	return 0;
... ...
@@ -1801,7 +1657,7 @@ static int sercmd_quit(int s, struct binrpc_cmd* cmd)
1801 1657
 
1802 1658
 
1803 1659
 
1804
-static int sercmd_warranty(int s, struct binrpc_cmd *cmd)
1660
+static int kamcmd_warranty(int s, struct binrpc_cmd *cmd)
1805 1661
 {
1806 1662
 	printf("%s %s\n", NAME, VERSION);
1807 1663
 	printf("%s\n", COPYRIGHT);
... ...
@@ -1813,7 +1669,7 @@ static int sercmd_warranty(int s, struct binrpc_cmd *cmd)
1813 1669
 #ifdef USE_READLINE
1814 1670
 
1815 1671
 /* readline command generator */
1816
-static char* sercmd_generator(const char* text, int state)
1672
+static char* kamcmd_generator(const char* text, int state)
1817 1673
 {
1818 1674
 	static int idx;
1819 1675
 	static int list; /* aliases, builtins, rpc_array */
... ...
@@ -1913,29 +1769,6 @@ static char* sercmd_generator(const char* text, int state)
1913 1769
 			}
1914 1770
 			break;
1915 1771
 #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 1772
 #ifdef USE_COUNTERS
1940 1773
 		case COMPLETE_CNT_GRP:
1941 1774
 			if (state==0){
... ...
@@ -1989,7 +1822,7 @@ static char* sercmd_generator(const char* text, int state)
1989 1822
 
1990 1823
 
1991 1824
 
1992
-char** sercmd_completion(const char* text, int start, int end)
1825
+char** kamcmd_completion(const char* text, int start, int end)
1993 1826
 {
1994 1827
 	int i, j;
1995 1828
 	int cmd_start, cmd_end, cmd_len;
... ...
@@ -2058,18 +1891,6 @@ char** sercmd_completion(const char* text, int start, int end)
2058 1891
 				}
2059 1892
 			}
2060 1893
 #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