using openser 1.3, is there a way to get a count of how many items there are in an avp variable other than: while ( is_avp_set("$avp(s:fork_uri)") ) { $var(fork_uri_count) = $var(fork_uri_count) + 1 ; avp_copy("$avp(s:fork_uri)", "$avp(s:fork_uri_rev_order)/d") ; } then if you wanted things in the same order as they were originally you would also have to: while ( is_avp_set("$avp(s:fork_uri_rev_order)") ) { avp_copy("$avp(s:fork_uri_rev_order)", "$avp(s:fork_uri)/d") ; }
talk about an expensive counting
Several ways I could see this implimented: New function avp_count("$avp(s:myvar)", "$avp(s:count_result)") or avp_count("$avp(s:myvar)") where $rc contains the result. is_avp_set("$avp(s:myvar)") where $rc is set to the count, probably best as you could test if exitst and the go right to processing. avp_check("$avp(s:myvar)", "cn/g") where $rc is set to the count. It could always set $rc to count of found matches for when the g flag is used. Of course using $rc for is_avp_set() or avp_check() depends on if setting that to non-zero makes a test like if( is_avp_set("$avp(s:myvar)") ) always trigger as false.
also on getting a count ...
another place I need to get a count is how many times a character(s) (or shoot the moon, a regex) occurs in a string. for handeling things like transformations like {s.select,index,seperator}, eg: $(var(findme){ s.select,$var(count),,}) sidenote ... (not sure what values for seperator are valid) a transformation like {s.count,seperator}
Here is an example of something I was trying to do that would have benifited from knowing the count of seperator. I think that I got a warning or error when the test for the while indexed past the end of the string.
xlog("L_INFO", "Original findme list to parse: $avp(s:findme)\n"); if ( $avp(s:findme) =~ "|" ) { $var(findme) = $(avp(s:findme){s.select,0,|}) ; $var(findme_tm_out) = $(avp(s:findme){s.select,1,|}) ; xlog("L_INFO", "This findme has a timeout: $var(findme_tm_out)\n"); } else { $var(findme) = $avp(s:findme) ; } xlog("L_INFO", "findme list to parse: $var(findme)\n"); $var(findme_cnt) = 0 ; while ($(var(findme){s.select,$var(findme_cnt),,}{s.len }) > 0 ) { xlog("L_INFO", "Loop $var(findme_cnt), Adding $(var(findme){s.select,$var(findme_cnt),,}) to TO_list\n"); $avp(s:TO_list) = $(var(findme){s.select,$var(findme_cnt),,}) ; $var(findme_cnt) = $var(findme_cnt) + 1 ; }
can/do $var()'s stack like $avp()'s?
Thanks Dave
On Wednesday 12 December 2007, Dave Singer wrote:
using openser 1.3, is there a way to get a count of how many items there are in an avp variable other than: while ( is_avp_set("$avp(s:fork_uri)") ) { $var(fork_uri_count) = $var(fork_uri_count) + 1 ; avp_copy("$avp(s:fork_uri)", "$avp(s:fork_uri_rev_order)/d") ; } then if you wanted things in the same order as they were originally you would also have to: while ( is_avp_set("$avp(s:fork_uri_rev_order)") ) { avp_copy("$avp(s:fork_uri_rev_order)", "$avp(s:fork_uri)/d") ; }
talk about an expensive counting
Hello Dave,
i think the best way to implement this would be as a transformation, see http://www.openser.org/dokuwiki/doku.php/transformations:devel
You could implement a operation like $avp(..){s.count} that return the wanted number.
Cheers,
Henning
I'm a little confused. Are you saying there is a transformation {s.count} that can be applied to avp's to get the number of items in an avp list/stack? I don't see any documentation for one at the link that you sent me. I had already scoured it looking for something to help me, but checked again in case something had changed. It sound more like you are saying that there is no such functionality and suggesting that I code/create a new transformation. Unfortunately my "Programing" experience is quite rusty, the last time I looked at C/C++ was in College almost 15 years ago. Not to mention already not enough time in a day to get done what I'm supposed to do. Maybe some time in the future I/we will be able to contribute code to openser and/or modules, but not now. We are pushing hard to have a quality sell able product/service. Or company is planning to contribute back to openser in several ways. When we get our servers setup and working, providing a stable, load-balanced, scalable platform that our sales team can sell our services with confidence, we are planning to post our openser.cfg files highly commented, along with database structure changes(added tables, views, colums, indexes...), example data, and a way to manage the data.
So for now (assuming you are saying there isn't something there now) I'll have to use what is currently available and hope that someone else with more experience and time finds these features valuable enough to implement them. I like the idea of a transformation but maybe like this: $var(step_count) = $(avp(s:list){ary.count}) while ( $var(step_count) != 0 ) { $var(working_var) = $(avp(s:list){ary.index,$var(step_count)}); # do some stuff on this reverse process list. # also we are not deleting list items to get to other list items. } and later used like... $var(step_count) = $(di{ary.count}); # if $di was a list/array of all the Diversion headers # same as in avp example above with other PV that could be lists/arrays
Also as the original email for this conversation stated, we need a {s.count,seperator} to compliment {s.select,index,seperator}
Thanks Dave
On 12/13/07, Henning Westerholt henning.westerholt@1und1.de wrote:
Hello Dave,
i think the best way to implement this would be as a transformation, see http://www.openser.org/dokuwiki/doku.php/transformations:devel
You could implement a operation like $avp(..){s.count} that return the wanted number.
Cheers,
Henning
On Thursday 13 December 2007, Dave Singer wrote:
I'm a little confused. Are you saying there is a transformation {s.count} that can be applied to avp's to get the number of items in an avp list/stack? I don't see any documentation for one at the link that you sent me. I had already scoured it looking for something to help me, but checked again in case something had changed. It sound more like you are saying that there is no such functionality and suggesting that I code/create a new transformation.
Hi Dave,
yes, i wanted to say something like that. :-) Just wanted to start a discussion about the possibility of a new transformation function.
Unfortunately my "Programing" experience is quite rusty, the last time I looked at C/C++ was in College almost 15 years ago. Not to mention already not enough time in a day to get done what I'm supposed to do. Maybe some time in the future I/we will be able to contribute code to openser and/or modules, but not now. We are pushing hard to have a quality sell able product/service. Or company is planning to contribute back to openser in several ways. When we get our servers setup and working, providing a stable, load-balanced, scalable platform that our sales team can sell our services with confidence, we are planning to post our openser.cfg files highly commented, along with database structure changes(added tables, views, colums, indexes...), example data, and a way to manage the data.
Sounds great!
So for now (assuming you are saying there isn't something there now) I'll have to use what is currently available and hope that someone else with more experience and time finds these features valuable enough to implement them. I like the idea of a transformation but maybe like this: $var(step_count) = $(avp(s:list){ary.count}) while ( $var(step_count) != 0 ) { $var(working_var) = $(avp(s:list){ary.index,$var(step_count)}); # do some stuff on this reverse process list. # also we are not deleting list items to get to other list items. } and later used like... $var(step_count) = $(di{ary.count}); # if $di was a list/array of all the Diversion headers # same as in avp example above with other PV that could be lists/arrays
Also as the original email for this conversation stated, we need a {s.count,seperator} to compliment {s.select,index,seperator}
You could open a feature request on the tracker [1] with the proposed enchancements.
Cheers,
Henning
[1] https://sourceforge.net/tracker/?group_id=139143&atid=743023
Thanks
I will make some feature requests including some I came up with over night: {s.subst,/regex/replace/flags} {s.regex,/regex/} avp_delete("$avp(s:name)/index")
Dave
On 12/14/07, Henning Westerholt henning.westerholt@1und1.de wrote:
On Thursday 13 December 2007, Dave Singer wrote:
I'm a little confused. Are you saying there is a transformation {s.count
}
that can be applied to avp's to get the number of items in an avp list/stack? I don't see any documentation for one at the link that you sent me. I
had
already scoured it looking for something to help me, but checked again
in
case something had changed. It sound more like you are saying that there is no such functionality
and
suggesting that I code/create a new transformation.
Hi Dave,
yes, i wanted to say something like that. :-) Just wanted to start a discussion about the possibility of a new transformation function.
Unfortunately my "Programing" experience is quite rusty, the last time I looked at C/C++ was in College almost 15 years ago. Not to mention
already
not enough time in a day to get done what I'm supposed to do. Maybe some
time in the future I/we will be able to contribute code to openser
and/or
modules, but not now. We are pushing hard to have a quality sell able product/service. Or company is planning to contribute back to openser in several ways.
When
we get our servers setup and working, providing a stable, load-balanced, scalable platform that our sales team can sell our services with confidence, we are planning to post our openser.cfg files highly
commented,
along with database structure changes(added tables, views, colums, indexes...), example data, and a way to manage the data.
Sounds great!
So for now (assuming you are saying there isn't something there now)
I'll
have to use what is currently available and hope that someone else with more experience and time finds these features valuable enough to
implement
them. I like the idea of a transformation but maybe like this: $var(step_count) = $(avp(s:list){ary.count}) while ( $var(step_count) != 0 ) { $var(working_var) = $(avp(s:list){ary.index,$var(step_count)}); # do some stuff on this reverse process list. # also we are not deleting list items to get to other list items. } and later used like... $var(step_count) = $(di{ary.count}); # if $di was a list/array of all the Diversion headers # same as in avp example above with other PV that could be
lists/arrays
Also as the original email for this conversation stated, we need a {s.count,seperator} to compliment {s.select,index,seperator}
You could open a feature request on the tracker [1] with the proposed enchancements.
Cheers,
Henning
[1] https://sourceforge.net/tracker/?group_id=139143&atid=743023