How to check for a "false" setting in a .conf file

If I understand correctly, in pjsip.conf a false setting can be specified in 3 ways:
setting=0 [zero]

What would be the simplest construct to use to check and see if all three return true?

Setting values are arbitrary, any meaning given to them is through either a custom implementation meaning it’s up to them or through common mechanism. The implementations of ast_true[1] and ast_false[2] are what is commonly used for boolean but that doesn’t mean they have to be.

[1] asterisk/utils.c at master · asterisk/asterisk · GitHub
[2] asterisk/utils.c at master · asterisk/asterisk · GitHub

Perfect. That is what I was looking for. Thanks

One last question. Can I use this without declaring it as long as I don’t forward reference it?

int a_false(const char *s)
	/* Determine if this is a true value */
	if (!strcasecmp(s, "no") ||
	    !strcasecmp(s, "false") ||
	    !strcasecmp(s, "0")
		return -1;
	return 0;

There’s not a lot of context to your question. If you’re referring to outside of Asterisk and within a single file then you’d define it static before use.

hmmm… I was thinking of putting it into pjsip_configuration.c and would only use it there.

I don’t understand why you wouldn’t just use the existing functions, then. Why does there have to be a custom implementation?

The docs say non-declaration [no timers= line] should default to timers=yes and I’m not positive but I think typos may(??) as well.

The default is set when the option is registered with sorcery[1]. If no value is specified, then that default is used. As for typos they don’t cause it to default to yes. The implementation[2] is as follows:

  1. Clear all the timer flags so nothing is set
  2. If the option is set to “yes” or the other true values then turn on the supported timer flag.
  3. If the option is set to “required” turn on the required timer flag.
  4. If the option is NOT set to “no” or other false values then return an error.
  5. Leave the timer flags cleared, since it’s not enabled.

Invalid option values would get caught by 4 and result in the following:

[Aug 17 09:32:11] ERROR[1408968]: config_options.c:798 aco_process_var: Error parsing timers=potato at line 9 of

[1] asterisk/pjsip_configuration.c at master · asterisk/asterisk · GitHub
[2] asterisk/pjsip_configuration.c at master · asterisk/asterisk · GitHub

To be more specific, 5 is more “leave the flags as they are - if they weren’t enabled leave them cleared, if something was enabled as a result of the option value then leave it enabled”.

Cool. I was wondering what “sorcery” was all about & I couldn’t tell from the source that typos might throw an error. Only a couple small changes needed then. PJSIP_INV_SUPPORT_TIMER is required for both “required” and “always” settings.

`static int timers_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
struct ast_sip_endpoint *endpoint = obj;

/* clear all */

/* set only the required flags */
if (ast_true(var->value)) {
	endpoint->extensions.flags |= PJSIP_INV_SUPPORT_TIMER;
} else if (!strcasecmp(var->value, "required")) {
	endpoint->extensions.flags |= (PJSIP_INV_REQUIRE_TIMER | PJSIP_INV_SUPPORT_TIMER);
} else if (!strcasecmp(var->value, "always") || !strcasecmp(var->value, "forced")) {
	endpoint->extensions.flags |= (PJSIP_INV_ALWAYS_USE_TIMER | PJSIP_INV_SUPPORT_TIMER);
} else if (!ast_false(var->value)) {
	return -1;

return 0;


You should file an issue[1] and submit a patch for this.

[1] System Dashboard - Digium/Asterisk JIRA

I’ll investigate but I’m not sure I’m familiar enough with “C” to create a patch.

Does this error only appear in a log file ? I get

[Aug 20 08:53:10] ERROR[5924]: chan_pjsip.c:2668 request: Unable to create PJSIP channel - endpoint 'telnyx' was not found
[Aug 20 08:53:10] WARNING[5929][C-00000002]: app_dial.c:2576 dial_exec_full: Unable to create channel of type 'PJSIP' (cause 3 - No route to destination)

on the console. Is this because I’m only looking at $DIALSTATUS and not any deeper ? Not a problem. Just so I know what to expect.

Errors in parsing the configuration appear in the log file, at load time.

The error you quote is a run time error saying that there is no type=endpoint section, at all, with the name telnyx. That might well be because there was an invalid parameter.

Is there a way to get just a log file of those type errors from Asterisk, and not 99 log files that I don’t need? I’m running on a tiny single board computer from either an sdcard or emmc so syslog is shut down.

It is not advisable to limit the logging when debugging, but you can limit a specific file to only errors and warnings in logger.conf. The normal advice would be to enable the full log, when debugging, rather than to disable any logs.

If a module has failed to load, you can use module load, from the CLI, to see the errors on the console. If it has partly loaded, you may need to modify the timestamp on the configuration file, then do module reload.

Perfect. I didn’t exactly understand how logger.conf works. /var/log/asterisk/messages is just what I was looking for. Thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.