On Sun, May 12, 2013 at 08:40:14AM -0400, Alan DeKok wrote:
1. Why is <ipaddr> necessary before the literal? Surely an unquoted 127.0.0.1 can't be parsed as anything else.
See my other example for why it's necessary.
In *some* cases, you know the data type of an expression. In those cases, you can easily do type-specific comparisons. That's what unlang does today:
if (Framed-IP-Address == 127.0.0.1) {
The type is "ipaddr", because of Framed-IP-Address. The RHS is in fact parsed into a second Framed-IP-Address attribute, and the two are compared.
So if I understand you rightly, you're saying that the unlang expressions Framed-IP-Address == 127.0.0.1 and Framed-IP-Address == "127.0.0.1" are treated identically - it's the type of the LHS which makes a difference, and no distinction is made between an IP literal and a string literal. Is that correct? Is there a fundamental reason why literal values can't have types? The canonical example would be the difference between 1 and "1". Say: if (Acct-Session-Time < 100) But presumably if (Acct-Session-Time < "100") is handled the same today (i.e. the "100" is converted to an integer because of the LHS type).
However... you can't currently do a type-safe comparison like:
if (127.0.0.1 < 127.0.0.2) {
The interpretor does *string* comparisons. Which is wrong for IP addresses.
... which again implies this is parsed exactly the same as if ("127.0.0.1" < "127.0.0.2") But there must be something else going on, because on the LHS at least, Framed-IP-Address is not parsed the same as "Framed-IP-Address"
2. What does the & in front of Framed-IP-Address do?
$ man unlang :)
It's a reference.
if (&User-Name == &Filter-Id) {
Does type-safe comparisons on the *values* of the two attributes.
That's pretty different to most languages though, were A == B compares the values of A and B, and & gives you a reference to the variable; you want to compare the values, not the references. Having said that, I seem to remember that C++ does magic dereferencing, converting references to values where required. But the main purpose of taking a reference is to allow a variable to be assigned to at a distance.
The v2 unlang code would require you to do:
if (User-Name == "%{Filter-Id}") {
Ah yes, because of things like Acct-Status-Type == Start, where the RHS has to be considered as an enumerated value rather than another attribute. Regards, Brian.