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

Using break outside of case #27

Open
dilyanpalauzov opened this issue Jan 9, 2023 · 3 comments
Open

Using break outside of case #27

dilyanpalauzov opened this issue Jan 9, 2023 · 3 comments

Comments

@dilyanpalauzov
Copy link
Contributor

https://www.kamailio.org/wikidocs/cookbooks/devel/core/ says about break:

'break' statement can be used to end a 'case' block in a 'switch' statement or exit from a 'while' statement.

IMPORTANT NOTE: break can be used only to mark the end of a case branch (as it is in shell scripts). If you are trying to use break outside a case block the script will return error -- you must use return there.

https://www.kamailio.org/docs/modules/devel/modules/tm.html contains examples with break, like:

request_route {
  seturi("sip:[email protected]");
  append_branch("sip:[email protected]");
  append_branch("sip:[email protected]");
  append_branch("sip:[email protected]");

  t_relay();
  break;
}

Either the definition for break is wrong, or the four tm-examples are incorrect.

The cited documentation is contradicting itself on whether break can be used in while.

@dilyanpalauzov
Copy link
Contributor Author

https://github.com/kamailio/kamailio/blob/master/src/modules/rtpproxy/examples/alg.cfg contains more examples with break outside of case and switch.

@miconda
Copy link
Member

miconda commented Jan 19, 2023

The break was the first execution control statement, before exit/drop as well as before while/switch. The examples using break where it should be exit are very old, they must be updated.

Now whether break can still be used there or not: probably it should be tested, in 2008 we merged source code of Kamailio and SER projects, and it could have some functionality inherited from SER code base, which Kamailio devs might not have used or be familiar with. So it could be like a backward-compatibility functionality.

But, over all, the recommandation is to use break on in while/switch, in other places there are more suggesting options like exit or drop.

@henningw
Copy link
Contributor

Just to add, did a quick test, it parses and starts. But we certainly should remove it from the module examples.

henning@app01:~/repositories/kamailio$ cat etc/test.cfg
loadmodule "tm.so"

request_route {
  seturi("sip:[email protected]");

  t_relay();
  break;
}

henning@app01:~/repositories/kamailio$ ./src/kamailio -f etc/test.cfg -E -L src/modules/ -Y /tmp/
Listening on
             udp: 127.0.0.1:5060
[..]

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

3 participants