[asterisk-dev] [svn-commits] kharwell: branch 12 r404663 - in /branches/12: ./ channels/ configs/ include/...

Matthew Jordan mjordan at digium.com
Fri Jan 3 09:50:28 CST 2014


On Fri, Jan 3, 2014 at 4:25 AM, Olle E. Johansson <oej at edvina.net> wrote:
>
> On 02 Jan 2014, at 20:06, SVN commits to the Digium repositories <svn-commits at lists.digium.com> wrote:
>
>> res_pjsip: add 'set_var' support on endpoints
>
> Coming in late...
>
> In sip.conf, skinny.conf and other places, it's "setvar" without underscore.
>
> Why change the syntax already used?
>

Hey Olle -

The syntax here is strictly snake case for two reasons:

(1) It keeps it in line with the other options in pjsip.conf. Yay consistency!

(2) More importantly, it lets us do some magic with the formatting of
the option for the AMI Action PJSIPShowEndpoint. Because the pjsip
stack uses sorcery (and underneath that, Terry's excellent
configuration framework), the handler for the AMI action has the
ability to 'walk' all configuration options for the endpoint - without
having to explicitly name them! The benefit of this is that adding a
configuration option is guaranteed to automagically show up in the
CLI/AMI inspection commands/Actions. However, the option will be
returned from sorcery exactly as it is defined in the conf file. Since
AMI traditionally uses camel case, we need to have an easy mechanism
to convert the configuration file parameter to an AMI field. If the
configuration file parameters are defined as snake case, then the
conversion to camel case is easy - that is, we can turn 'set_var' to
'SetVar' using a utility function. If, however, the parameter was
'setvar', then the best we could do automatically is 'Setvar', which,
while not terrible for that parameter, is pretty bad for lots of
others.

Just to show how nifty this is, this is the function that converts any
configuration object in pjsip.conf to an AMI event:

>From pjsip_configuration:

int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
{
    RAII_VAR(struct ast_variable *, objset, ast_sorcery_objectset_create(
             ast_sip_get_sorcery(), obj), ast_variables_destroy);
    struct ast_variable *i;

    if (!objset) {
        return -1;
    }

    sip_sorcery_object_ami_set_type_name(obj, buf);

    for (i = objset; i; i = i->next) {
        RAII_VAR(char *, camel, ast_to_camel_case(i->name), ast_free);
        ast_str_append(buf, 0, "%s: %s\r\n", camel, i->value);
    }

    return 0;
}

Hope that helps!

Matt

-- 
Matthew Jordan
Digium, Inc. | Engineering Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: http://digium.com & http://asterisk.org



More information about the asterisk-dev mailing list