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 undefined environmental variables with #!defenv #2967

Closed
whosgonna opened this issue Dec 8, 2021 · 5 comments
Closed

Using undefined environmental variables with #!defenv #2967

whosgonna opened this issue Dec 8, 2021 · 5 comments

Comments

@whosgonna
Copy link
Contributor

Description

Currently, an undefined environmental variable with #!defenv results in Kamailio failing to start. The proposal here that if the environmental variable is not defined, then the macro value would be undefined as well. For example:

!#KAMAILIO
loadmodule "xlog"
loadmodule "pv"

#!defenv FOO

request_route {
    #!ifdef FOO
        xlog("L_INFO","Environmental variable $$FOO is set\n");
    #!else
        xlog("L_WARN","Environmental variable $$FOO is NOT set\n");
    #!endif
    forward();
}

Currently this configuration will fail to load if environmental variable is not set. My proposal is to either allow #!envdef to accept an undefined environmental variable and have the preprocessor macro undefined, or to add a new keyword (#!envdefn perhaps?) to allow this behavior.

@whosgonna
Copy link
Contributor Author

I've forked and written a patch to add #!defenvn , as well #!defenvns to auto quote the value based on the new #!defenvs, however in testing it appears that #!defenvs is not working. I'm not sure in what order you'd like to have the PR submitted: I can submit now with both #!defenvs and #!defenvns not working, or I can wait for (or possibly fix) #!defenvs and then rebase my changes off of that.

Thoughts?

@whosgonna
Copy link
Contributor Author

Proposed changes are in https://github.com/whosgonna/kamailio/tree/iss2967

@whosgonna
Copy link
Contributor Author

As indicated by @miconda, I've refactored the keywords from defenvn to trydefenv and from defenvs to trydefenvns.

@whosgonna
Copy link
Contributor Author

@miconda indicated in the Kamailio mailing list that they code for #!defenvs would be pushed. Once that's done, I'll merge to my fork, then submit a PR.

miconda pushed a commit that referenced this issue Dec 10, 2021
Feature Request GH #2967 for undefined defenv

Add new keywords for preprocessing:

- #!trydefenv - The same as #!defenv, except if the variable is
  undefined, the def value will be undefined as well.

- #!trydefenvs - The same as #!defenvs, except if the variable is
  undefined, the def value will be undefined as well.
@miconda
Copy link
Member

miconda commented Dec 13, 2021

PR was merged.

@miconda miconda closed this as completed Dec 13, 2021
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

2 participants