Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] if $params(1) is a number, it maybe auto changed #3378

Open
gao114882 opened this issue Apr 28, 2024 · 4 comments
Open

[BUG] if $params(1) is a number, it maybe auto changed #3378

gao114882 opened this issue Apr 28, 2024 · 4 comments

Comments

@gao114882
Copy link

OpenSIPS version you are running

./opensips -V 
version: opensips 3.3.10 (x86_64/linux)
flags: STATS: On, DISABLE_NAGLE, USE_MCAST, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, HP_MALLOC, DBG_MALLOC, FAST_LOCK-ADAPTIVE_WAIT
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535
poll method support: poll, epoll, sigio_rt, select.
main.c compiled on 08:51:17 Apr 25 2024 with gcc 4.8.5

Describe the bug

I define a variable of type int that, when passed as an argument to a function, is automatically transformed,which is weird.
here is my opensips.cfg:


include_file "opensips_m02.cfg"

route[message_param] {
	xlog("-------- message_param ----------\n");
	$json(param) := "{}";
	$json(param/out_ip) = "172.16.4.111";
	$json(param/out_port) = 5160;
	$json(param/out_ptl) = "udp";
}

route{

	if (is_method("OPTIONS")) {
		options_reply();
		exit;
	}
	if (!mf_process_maxfwd_header(10)) {
		send_reply(483,"Too Many Hops");
		exit;
	}
	xlog("L_INFO","---------- route main ------$rm, $fu, $rU,$fU,$si\n");
	if (nat_uac_test(32)) {
		xlog("L_INFO","---------- fix nat------\n");
    	fix_nated_register();
    	fix_nated_contact();
		if (has_body("application/sdp")) {
			fix_nated_sdp(2);  # rewrite c= with source address
		}
    }
	match_dialog();
	# route(license);
	route(message_param);
	# route(rate_limit);
	xlog("L_INFO","---------- route main ------$rm, $fu, $rU,$fU,$si\n");
	route(m02);
}

onreply_route {
	xlog("----------- main reply ---------:$rm, $rs\n");
	if (is_method("OPTIONS")) {
		exit; 
	}
	load_dialog_ctx($ci);
	route(message_param);
	route(m02_reply);
	unload_dialog_ctx();
	exit;
}

route[modify_rr] {
	xlog("---------- modify_rr ------------:$rm, $hdrcnt(Record-Route),$param(1),$param(2),$param(3)\n");
	if($hdrcnt(Record-Route) > 0) {
		$json(rr) := "[]";
		$var(i) = 0;
		while($var(i) < $hdrcnt(Record-Route)) {
			$var(rr) = $(hdr(Record-Route)[$var(i)]);
			$var(j) = 0;
			$var(rr_one) = $(var(rr){s.select,$var(j),,});
			while($var(rr_one) != NULL) {
				$json(rr[]) = $var(rr_one);	
				$var(j) = $var(j) + 1;
				$var(rr_one) = $(var(rr){s.select,$var(j),,});
			}
			$var(i) = $var(i) + 1;
		}
		xlog("---------- modify_rr ----2--------:$rm,$param(1),$param(2),$param(3)\n");
		$var(i) = 0;
		while($json(rr[$var(i)]) != NULL) {
			$var(rr) = $json(rr[$var(i)]);
			$var(str) = ";source=" + $socket_in(proto) + ":" + $socket_in(ip) + ":" + $socket_in(port);
			$var(pos) = $(var(rr){s.index, $var(str)});
			xlog("---------- modify_rr ----3--------:$rm,$param(1),$param(2),$param(3)\n");
			if ($var(pos) != NULL) {
				$var(str) = "sip:";
				$var(pos) = $(var(rr){s.rindex, $var(str)});
				$var(len) = $var(pos) + 4;
				$var(pre_app) = $(var(rr){s.substr, 0, $var(len)});
				xlog("---------- modify_rr ----4--------:$rm,$param(1),$param(2),$param(3)\n");
				$var(str) = ";";
				$var(pos) = $(var(rr){s.index, $var(str), $var(pos)});
				$var(len) = $(var(rr){s.len}) - $var(pos);
				$var(temp) = $(var(rr){s.substr, $var(pos), $var(len)});

				$var(str) = ";transport=";
				$var(pos) = $(var(temp){s.index, $var(str)});

				if($var(pos) == NULL) {
					$var(mid_app) = "";
					$var(suf_app) = $var(temp);
				} else {
					if($var(pos) == 0) {
						$var(mid_app) = "";
					} else {
						$var(len) = $var(pos);
						$var(mid_app) = $(var(temp){s.substr, 0, $var(len)});
					}
					$var(str) = ";";
					$var(pos) = $var(pos) + 1;
					$var(pos) = $(var(temp){s.index, $var(str), $var(pos)});
					if($var(pos) == NULL) {
						$var(suf_app) = ">";
					} else {
						$var(len) = $(var(temp){s.len}) - $var(pos);
						$var(suf_app) = $(var(temp){s.substr, $var(pos), $var(len)});
					}
				}

				$json(rr[$var(i)]) = "Record-Route: " + $var(pre_app) + $param(1) + ":" + $param(2)
					+ $var(mid_app) + ";transport=" + $param(3) + $var(suf_app) + "\r\n";
				xlog("---------- modify_rr ----1--------:$rm,$param(1),$param(2),$param(3),$json(rr[$var(i)])\n");

			} else {
				$json(rr[$var(i)]) = "Record-Route: " + $var(rr) + "\r\n";
			}
			$var(i) = $var(i) + 1;
		}

		remove_hf("Record-Route");
		$var(i) = 0;
		while($json(rr[$var(i)]) != NULL) {
			append_hf("$json(rr[$var(i)])", "Record-Route");
			$var(i) = $var(i) + 1;
		}
	}
}

opensips_m02.cfg:

route[m02_reply] {
    if($rm == "INVITE") {
                xlog("---------------------m02_reply---1----------------:$rm, $rs, $json(param/out_port)\n");
		route(modify_rr, $json(param/out_ip), $json(param/out_port), $json(param/out_ptl));
    }
    route(m02_rtpengine_manager);
}

here is my opensips.log, you can see that I can't change this $param(1). but it's auto changed. besides, I also find that, If
$json(param/out_port) = "5160", change int to string, the result is correct.

企业微信截图_17142673453276

To Reproduce

Expected behavior

Relevant System Logs

OS/environment information

  • Operating System:
  • OpenSIPS installation:
  • other relevant information:

Additional context

Copy link

Any updates here? No progress has been made in the last 15 days, marking as stale. Will close this issue if no further updates are made in the next 30 days.

@github-actions github-actions bot added the stale label May 13, 2024
@gao114882
Copy link
Author

still exists

@stale stale bot removed the stale label May 16, 2024
Copy link

Any updates here? No progress has been made in the last 15 days, marking as stale. Will close this issue if no further updates are made in the next 30 days.

@github-actions github-actions bot added the stale label May 31, 2024
@gao114882
Copy link
Author

exists

@stale stale bot removed the stale label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant