[Home]

Summary:ASTERISK-03646: [patch] New variable FIELDQTY
Reporter:Tilghman Lesher (tilghman)Labels:
Date Opened:2005-03-07 16:20:06.000-0600Date Closed:2008-01-15 15:30:01.000-0600
Priority:MajorRegression?No
Status:Closed/CompleteComponents:Core/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) 20050331__fieldqty_function.diff.txt
Description:Creates a new variable called FIELDQTY, which allows an inline calculation of the number of fields inside a variable, with delimiters as specified.

The reason why this is necessary is for the following case:

CHANNEL=IAX2/oink-57
CHANNEL=IAX2/moo-foo-goo-61

In order to strip the integer at the end of the channel name reliably, even for names which include the dash character, we need a way to calculate the number of fields.  The resulting syntax (with this patch) would be:

Cut(mychan=CHANNEL|-|1-$[${FIELDQTY(CHANNEL|-)} - 1])

which is to say, count the number of fields in the channel name, as delimited by the dash character, subtract one, and let Cut grab fields 1 through that number.

****** ADDITIONAL INFORMATION ******

Disclaimer on file.
Comments:By: Leif Madsen (lmadsen) 2005-03-07 18:47:43.000-0600

Just tested this patch, and it works for me!

[cut-test]
exten => 4000,1,SetVar(mychan=1000&1337&5195915119)
exten => 4000,n,SetVar(count=1)
exten => 4000,n,While($[${count} <= ${FIELDQTY(mychan|&)}])
exten => 4000,n,Cut(var${count}=mychan|&|${count})
exten => 4000,n,NoOp(${var${count}})
exten => 4000,n,SetVar(count=$[1 + ${count}])
exten => 4000,n,EndWhile()
exten => 4000,n,Hangup()

By: Jared Smith (jsmith) 2005-03-07 22:14:45.000-0600

Two comments... I'm not trying to be picky, but this is what I've noticed:

1) Your code only looks for the | to seperate arguments, instead of their the pipe or the comma.  Aren't both supposed to be accepted?

2) Why are you changing the line in README.variables from SetVar() to SetCDRVar()?

Anyway, just my two cents...

By: Tilghman Lesher (tilghman) 2005-03-07 22:23:34.000-0600

1.  Commas are transparently converted to pipes by Asterisk.
2.  It's a piece of anthm's patch that was rejected by Mark in favor of SetCDRVar(), though the documentation was never changed to reflect it.  I suppose it could be its own bug, but I figured while I'm modifying the file, I might as well fix that, too.

By: Mark Spencer (markster) 2005-03-08 02:04:28.000-0600

Would it not be easier to just allow cut to take a negative number?

By: Tilghman Lesher (tilghman) 2005-03-08 08:49:29.000-0600

I looked at doing that [negative numbers], but that syntax is incredibly confusing.  I thought this would be the simpler approach.  And see blitzrage's example, where he's using FIELDQTY outside of Cut.

By: Tilghman Lesher (tilghman) 2005-03-08 08:56:42.000-0600

To clarify, negative syntax for my case would be:
Cut(mychan=CHANNEL,-,1--1)

I also considered doing an embedded L for length and doing:
Cut(mychan=CHANNEL,-,1-(L-1))

but that entails doing expression parsing.  Since we already have an expression parser in Asterisk, we might as well make use of it:
Cut(mychan=CHANNEL,-,1-$[${FIELDQTY(CHANNEL,-)} - 1])

edited on: 03-08-05 08:57

By: Mark Spencer (markster) 2005-03-24 14:43:20.000-0600

I think this should be implemented after 2278 is in.

By: Kevin P. Fleming (kpfleming) 2005-03-31 15:11:20.000-0600

OK, 2278 is in now (although it's been modified), can we get this one updated?

By: Tilghman Lesher (tilghman) 2005-04-01 15:49:30.000-0600

New implementation uploaded and tested.

By: Kevin P. Fleming (kpfleming) 2005-04-01 16:10:10.000-0600

Committed to CVS, thsnks!

By: Kevin P. Fleming (kpfleming) 2005-04-01 16:10:45.000-0600

Not for stable.

By: Digium Subversion (svnbot) 2008-01-15 15:30:01.000-0600

Repository: asterisk
Revision: 5353

U   trunk/apps/app_cut.c

------------------------------------------------------------------------
r5353 | kpfleming | 2008-01-15 15:30:00 -0600 (Tue, 15 Jan 2008) | 2 lines

add FIELDQTY function to split variable contents and get any desired field (bug ASTERISK-3646)

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=5353