Browse code

kamctl: option for rpc command to replace tokens in parameters

- supported now: replace '=CRLF=' with '\r\n'
- fix 'kamctl ping' command by replacing '=CRLF=' with '\r\n'
in multi-headers parameter

Daniel-Constantin Mierla authored on 18/01/2021 09:19:05
Showing 2 changed files
... ...
@@ -2036,7 +2036,7 @@ kamailio_stop() {
2036 2036
 options_ping() {
2037 2037
 	myhost=`get_my_host`
2038 2038
 	require_ctlengine
2039
-	CMDPARAMS="tm.t_uac_start OPTIONS \"$1\" \".\" \".\" \"From:sip:daemon@$myhost"$'\r\n'"To:<$1>"$'\r\n'"Contact:sip:daemon@$myhost"$'\r\n'"\""
2039
+	CMDPARAMS="= tm.t_uac_start OPTIONS \"$1\" \".\" \".\" \"From:sip:daemon@$myhost=CRLF=To:<$1>=CRLF=Contact:sip:daemon@$myhost=CRLF=\""
2040 2040
 	if [ $CTLENGINETYPE -eq 1 ] ; then
2041 2041
 		ctl_cmd_run $CMDPARAMS
2042 2042
 	else
... ...
@@ -101,6 +101,12 @@ rpc_cmd()
101 101
 		chmod a+w $path
102 102
 	fi
103 103
 
104
+	PARAMEVAL="no"
105
+	if [ "$1" = "=" ]; then
106
+		PARAMEVAL="yes"
107
+		shift
108
+	fi
109
+
104 110
 	# construct the command now
105 111
 	CMD="{\"jsonrpc\": \"2.0\", \"method\": \"$1\"";
106 112
 	shift
... ...
@@ -114,7 +120,12 @@ rpc_cmd()
114 120
 		shift
115 121
 		while [ -n "$1" ] ; do
116 122
 			rpcparamval "${1}"
117
-			CMD="${CMD}, ${RPCVAL}"
123
+			if [ "$PARAMEVAL" = "yes" ]; then
124
+				CMDPARAM=`echo "$RPCVAL" | awk -F'=CRLF=' '{$1=$1}1' OFS='\r\n'`
125
+				CMD="${CMD}, ${CMDPARAM}"
126
+			else
127
+				CMD="${CMD}, ${RPCVAL}"
128
+			fi
118 129
 			shift
119 130
 		done
120 131
 		CMD="${CMD}]"