Index: main/pbx.c =================================================================== --- main/pbx.c (revision 349445) +++ main/pbx.c (working copy) @@ -719,6 +719,35 @@ RaiseException + + + Retrieve the SIP peer that auto-registered an extension. + + + + Default is the current extension. + Priority 1 of extension should have been + auto-registered by SIP, possibly via regexten=. + + + The context to use when searching for extension. + Default is the current context. + context should be one specified by regcontext= in + sip.conf. + + + + If extension was auto-registered in context as the + result of regcontext= in sip.conf, REGISTRANT returns the name of its associated peer, even if + extension was created due to regexten=. + If priority 1 of extension can't be found, or wasn't created by SIP, the + null string is returned. + Example: Here, regexten= has been used to assign extensions in the range 250-299 to + peers with names like 002699ABD834. + include => sip-autoreg ; regcontext = sip-autoreg + exten => _2[5-9]X, 2, Dial(SIP/${REGISTRANT()}) + + Sets a time to be used with the channel to test logical conditions. @@ -3474,6 +3503,38 @@ .read = acf_exception_read, }; +static int acf_registrant(struct ast_channel *chan, const char *name, char *data, char *buf, size_t len) +{ + char *context, *exten; + struct ast_exten *e; + struct pbx_find_info q = { .stacklen = 0 }; + char *parse; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(exten); + AST_APP_ARG(context); + ); + + parse = ast_strdupa(data); + AST_NONSTANDARD_APP_ARGS(args, parse, '@'); + exten = ast_strlen_zero(args.exten) ? chan->exten : args.exten; + context = ast_strlen_zero(args.context) ? chan->context : args.context; + buf[0] = '\0'; + e = pbx_find_extension(chan, NULL, &q, context, exten, 1, NULL, NULL, E_MATCH); + if (e /* Did we find exten, 1 ? */ + && e->registrar && !strcmp(e->registrar, "SIP") /* Registered by SIP ? */ + && e->app && !strcmp(e->app, "Noop") /* Does it execute Noop() ? */ + && !ast_strlen_zero(e->data)) { /* And Noop() has an argument ? */ + ast_copy_string(buf, e->data, len); /* That's our peer */ + return 0; + } + return -1; +} + +static struct ast_custom_function registrant = { + .name = "REGISTRANT", + .read = acf_registrant, +}; + static char *handle_show_functions(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_custom_function *acf; @@ -10449,6 +10510,7 @@ ast_data_register_multiple_core(pbx_data_providers, ARRAY_LEN(pbx_data_providers)); __ast_custom_function_register(&exception_function, NULL); __ast_custom_function_register(&testtime_function, NULL); + __ast_custom_function_register(®istrant, NULL); /* Register builtin applications */ for (x = 0; x < ARRAY_LEN(builtins); x++) {