Index is not an integer

Franks Andy (IT Technical Architecture Manager) Andy.Franks at sath.nhs.uk
Tue Dec 15 14:54:59 CET 2015


Hi Alan,
  First of all thanks for the reply, that helps me understand "xlat's place".

My real struggle was with what Arran provided yesterday, can't get it to work:

"%{xlat:%%{control:Tmp-String-3[%{control:Tmp-Integer-0}]%}}"

It use is to refer to the index of Tmp-String-3 via the dynamic integer Tmp-Integer-0. Trouble is, it comes back with an empty string. Is it because of what you mentioned ; that 

control:Tmp-String-3[%{3}] != control:Tmp-String-3[3]

Do I need to do some regex matching and plug the integer value into the corresponding group by building, for example, a delimited string? Would that work?
The apparent downside to that would be to only match a preset number of groups my expression contained, and, if possible, I'd like to match any number of previous "things", within reason. I'm guessing I'm on the edge of what should maybe done in perl / python / whatever, it just seems the tricky bit has been done with the import of mapped sql stuff, can't get over how useful that is, and now I just want to iterate over things in turn, literally the last thing to be done.

Thanks again, appreciate the input a lot!
Andy


-----Original Message-----
From: Freeradius-Users [mailto:freeradius-users-bounces+andy.franks=sath.nhs.uk at lists.freeradius.org] On Behalf Of Alan DeKok
Sent: 15 December 2015 13:25
To: FreeRadius users mailing list
Subject: Re: Index is not an integer

On Dec 15, 2015, at 8:17 AM, Franks Andy (IT Technical Architecture Manager) <Andy.Franks at sath.nhs.uk> wrote:
> Has anyone had any direct experience with using "%{xlat:..}". I can't seem to find much about using it directly, obviously xlats are used in ldap/sql/files etc a lot, any time you want to do anything directly outside a module, and they are super-useful but I haven't seen this used before to allow resolution of various levels of variable.

  The "%{foo}" thing is a normal expansion.  The difficulty is that sometimes you want to build custom expansions at run-time, and the server doesn't allow for that.

  e.g. if you build the expansion like this:

	update request {
		Tmp-String-0 := "sql:SELECT ..."
	}

  Then doing this:

	Foo = "%{Tmp-String-0}"

  will get you the *string value* of Tmp-String-0.  It won't run the expansion you've put into that string.

  The solution is %{xlat:...}.  It does *another* round of expansion on the input string.  So if "%{Tmp-String-0}" gets you the string for the SQL expansion, then "%{xlat:%{Tmp-String-0}}" will run the SQL expansion, and call SQL.

> I can't get it to do much, tried a simple:
> 
> Update control {
>  Tmp-Integer-0 := 3
>  Tmp-String-1 := "%{control:Tmp-Integer-0}"
>  Tmp-String-1 := "%{xlat:%{control:Tmp-Integer-0}}"
> }

  Well, yes.  Integers aren't strings.  The xlat expansion of "3" is equivalent to "%{3}".  Which is empty if you haven't done any regular expression matching.

> .. the first works as it should, but this xlat one is a mystery. Sorry for being a bit thick, possibly got it completely wrong.
> I could do a switch .. case dependent on a tracked variable, but it's not very nice and would result it lots of identical code blocks to maintain.
> 
> Sorry to be a pain, I did search around first even had a look at the source code, but it hurts my head.

  No worries.  Sometimes it hurts *my* head, and I've been doing this for almost 20 years.

  Alan DeKok.


-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html



More information about the Freeradius-Users mailing list