[SR-Users] Suggestions for time utils

Daniel-Constantin Mierla miconda at gmail.com
Mon Dec 19 19:29:06 CET 2011


Hello,

On 12/19/11 1:58 PM, Andreas Granig wrote:
> Hi,
>
> I'd like to implement a couple of helper functions for time handling,
> e.g. checking day of week, day of month etc. from within the kamailio
> config file. What would you prefer, a new module ("timeutils" maybe?) or
> adding it to cfgutils (there are already time-based functions there like
> sleep and usleep)?
>
> The idea is to implement time based call-forwards, and an approach could
> be to provision various time-related values in usr_preferences table,
> and then check it in the config. For example, when doing call-forwards
> from Monday to Friday only, I could put this into usr_preferences:
>
> attribute: cf_weekday
> value: [1, 2, 3, 4, 5] (each entry is a separate row in usr_preferences)
>
> And in kamailio config, I'd call this:
>
> avp_db_load(...);
> if(is_weekday("$avp(s:cf_weekday)")) { do CF }
>
> So is_weekday would iterate over the entries in the avp list and return
> true if the weekday at the time of routing matches an entry in the list.
> A module config param could control whether to use gmtime or localtime
> for matching.
>
> Does this make sense? Suggestions for other approaches? I'd rather
> prefer to do it directly in config instead of using some external
> interpreter like lua, python etc.
I don't know what are all the functions you think of, but for the 
example provided above, config file does it easy right now. There is a 
pseudo-variable that gives broken-time attribute that can be used with 
avp_check(), iirc, should be:

avp_db_load(...);
if(avp_check("$time(wday)", "eq/$avp(s:cf_weekday)/g")) { do CF }

Of course there is the option of doing while loop, but maybe gets to large for desired config file.

For me does not matter if it is new module or not, it is up to developer 
convenience. The only thing here I would comment a bit about, is the 
plan to apply on avp lists always? The maybe its better in avpops (if 
you want to do it in an old module), also use avp somehow in the name, 
e.g., is_avp_weekday().

Cheers,
Daniel

-- 
Daniel-Constantin Mierla -- http://www.asipto.com
http://linkedin.com/in/miconda -- http://twitter.com/miconda




More information about the sr-users mailing list