New feature in v3: cast!

Brian Candler B.Candler at pobox.com
Mon May 13 09:49:44 CEST 2013


On Sun, May 12, 2013 at 02:40:53PM -0400, Arran Cudbard-Bell wrote:
> The proper syntax for such a comparison is:
> 
> if (&Framed-IP-Address > 192.168.0.0/24) {
> 
> }

Ah, suddenly I see where we're going. If it had used a more Perl-PHP-like $
I think I would have gotten it straight away.

  if ($Framed-IP-Address > 192.168.0.0/24) { .. }

Aside: with explicit variable reference like this, I think the update {...}
syntax might become redundant.  e.g.  you could just have

  $Tmp-IP-0 := $Framed-IP-Address

An explicit tag could also allow the expression language to expand to
cover eval, although minuses would have to be space-delimited:

  if ($Event-Timestamp - $Acct-Session-Time < $Tmp-Integer-0) { ... }

or:

  if (${Event-Timestamp} - ${Acct-Session-Time} < ${Tmp-Integer-0}) { ... }

> I originally argued that string literals must all be wrapped in single quotes,
> but this would have meant boolean values and enumerated values would also have
> been required to be wrapped.
> 
> i.e.
> 
> update request {
> 	Service-Type := 'Framed-User'
> }
> 
> update control {
> 	Fall-Through := 'no'
> }

Yes I see, that's another way it could disambiguate attribute names from
literals.  It's a bit odd, if something which you know to be an enumeration
constant representing an integer, has to be quoted as a string.

Having said that, things like

    Service-Type := "%{sql...}"

are presumably still going to be allowed, so string->constant lookups can
take place dynamically.

So thinking aloud, the rules might be:

  - a quoted string is a string

  - an unquoted bareword which parses as an integer or an IP address has
    that type

  - otherwise, a bareword LHS is parsed as an attribute name reference, and
    a bareword RHS is parsed as an enumeration for to the dictionary type of
    the LHS

  - assignment or comparison where the RHS is a string but the LHS is an
    attribute with a non-string value causes the RHS to be converted to the
    type of the LHS (at parse-time if both LHS and RHS are constants,
    otherwise can be deferred to run-time)

And if the LHS is a string expansion, that has to be deferred too.  Not that
I expect anyone ever to write:

update control {
    "%{Tmp-String-0}" := "%{Tmp-String-1}"
}

or:

    $$Tmp-String-0 := $Tmp-String-1

Ugh :)

Regards,

Brian.


More information about the Freeradius-Devel mailing list