[asterisk-dev] Methodologies for validating dialplan

Mark Murawski markm-lists at intellasoft.net
Wed Jan 5 17:06:07 CST 2022


Throwing my .02 in here.  Adjust to .10 for inflation!

On 1/4/22 14:53, asterisk at phreaknet.org wrote:
> .... 
> However, there are a lot of dialplan problems that represent potentially 
> valid syntax that will cause an error at runtime, such as branching to 
> somewhere that doesn't exist. The dialplan will reload with no errors, 
> since there isn't a syntax issue, but at runtime, the call will fail 
> (and most likely crash). I found over the years that a lot of these were 
> often simple typos or issues that were easily fixed but wasted a lot of 
> time in finding solely in the "test, test, test" approach. Another 
> common grievance I hear time to time about the dialplan is most issues 
> are caught at runtime, not "compile time" (i.e. dialplan reload).

I love it!

And... take an example from a basic cli call that has a validator built-in:

static char *meetme_kick_cmd(struct ast_cli_entry *e, int cmd, struct 
ast_cli_args *a)
         switch (cmd) {
         case CLI_INIT:
                 e->command = "meetme kick";
                 e->usage =
                         "Usage: meetme kick <confno> all|<userno>\n"
                         "       Kick a conference or a user in a 
                 return NULL;
         case CLI_GENERATE:
                 return complete_meetmecmd_mute_kick(a->line, a->word, 
a->pos, a->n);

         if (a->argc != 4) {
                 return CLI_SHOWUSAGE;

         return meetme_cmd_helper(a);

This design pattern has self-contained validation.  And it's up to the 
function to validate as much or as little as it wants to.

We would need a new ast_register_application_xml2 and 
ast_custom_function_register2 to have a new design pattern for 
self-validating functions and applications.

Each application would know what kind of parameters it takes, and what's 
valid and not valid

new-stle for say... Goto Application

static int gosub_exec(int cmd, struct ast_channel *chan, const char *data)
		... do some validation!

ideally gosub knows it's being passed an exten/context/priority and can 
call ast_exists_extension at dialplan parse time via the validator flow

This would be a major undertaking to add validation for every function 
and every application but since dialplan is so ubiquitous and is 
probably never going away... would make huge inroads to making sure 
everything is as correct as possible at parse/load time.

More information about the asterisk-dev mailing list