Debian Codegraph @

src/modules/tmrec/README

raw
1 TMREC Module
2
3 Daniel-Constantin Mierla
4
5 <[email protected]>
6
7 Edited by
8
9 Daniel-Constantin Mierla
10
11 <[email protected]>
12
13 Alex Balashov
14
15 <[email protected]>
16
17 Richard Fuchs
18
19 <[email protected]>
20
21 Copyright © 2012 asipto.com
22
23 Copyright © 2012 Sipwise GmbH
24 __________________________________________________________________
25
26 Table of Contents
27
28 1. Admin Guide
29
30 1. Overview
31 2. Dependencies
32
33 2.1. Kamailio Modules
34 2.2. External Libraries or Applications
35
36 3. Parameters
37
38 3.1. separator (str)
39
40 4. Functions
41
42 4.1. tmrec_match(timerec [, timestamp])
43 4.2. is_leap_year([year])
44 4.3. time_period_match(period [, timestamp])
45
46 List of Examples
47
48 1.1. Set separator parameter
49 1.2. tmrec_match usage
50 1.3. is_leap_year usage
51 1.4. time_period_match usage
52
53 Chapter 1. Admin Guide
54
55 Table of Contents
56
57 1. Overview
58 2. Dependencies
59
60 2.1. Kamailio Modules
61 2.2. External Libraries or Applications
62
63 3. Parameters
64
65 3.1. separator (str)
66
67 4. Functions
68
69 4.1. tmrec_match(timerec [, timestamp])
70 4.2. is_leap_year([year])
71 4.3. time_period_match(period [, timestamp])
72
73 1. Overview
74
75 This module provides time recurrence matching functions. The format of
76 recurrence definitions is based on Internet Calendaring and Scheduling
77 Core Object Specification (Calendar COS - RFC 2445). It also provides a
78 port of the Perl Time::Period module for generic time period matching.
79
80 2. Dependencies
81
82 2.1. Kamailio Modules
83 2.2. External Libraries or Applications
84
85 2.1. Kamailio Modules
86
87 The following modules must be loaded before this module:
88 * None.
89
90 2.2. External Libraries or Applications
91
92 The following libraries or applications must be installed before
93 running Kamailio with this module loaded:
94 * None
95
96 3. Parameters
97
98 3.1. separator (str)
99
100 3.1. separator (str)
101
102 Separator character used to delimit attributes in time recurrence
103 definitions.
104
105 Default value is '|'.
106
107 Example 1.1. Set separator parameter
108 ...
109 modparam("tmrec", "separator", ";")
110 ...
111
112 4. Functions
113
114 4.1. tmrec_match(timerec [, timestamp])
115 4.2. is_leap_year([year])
116 4.3. time_period_match(period [, timestamp])
117
118 4.1. tmrec_match(timerec [, timestamp])
119
120 Match a time recurrence rule against the timestamp (UNIX epoch format).
121 If the timestamp parameter is missing, the current UNIX epoch time is
122 used.
123
124 The parameters can include pseudo-variables.
125
126 The timerec parameter is a list of attributes defined by RFC2445,
127 delimited by the 'separator' (module parameter) character. The format
128 of timerec parameter, using '|' as the separator, is (all in one line
129 without white spaces):
130 ...
131 [startdate]|[duration]|[frequency]|[until]|[interval]|[byday]
132 |[bymonthday]|[byyearday]|[byweekno]|[bymonth]
133 ...
134
135 When an attribute is not specified, the corresponding place must be
136 left empty, provided that one or more additional attributes follow.
137
138 Description of time recurrence attributes:
139 * startdate - date for the start of the first period.
140 * duration - the duration of the time period. For a recurring
141 interval, the “duration” parameter MUST be small enough such that
142 subsequent intervals do not overlap. For non-recurring intervals,
143 durations of any positive length are permitted. Zero-length
144 duration means “forever”. Negative-length durations are not
145 allowed.
146 See RFC 2445 for the format of duration. In short for common cases
147 when the duration doesn't exceed a data, it must start with PT
148 followed by the value for hours, minutes or seconds - e.g., a
149 duration of 8 hours must be written as PT8H.
150 * frequency - can be one of the following values: “daily” - specify
151 repeating periods based on an interval of a day or more; “weekly” -
152 specify repeating periods based on an interval of a week or more;
153 “monthly” - specify repeating periods based on an interval of a
154 month or more; “yearly” - specify repeating periods based on an
155 interval of a year or more. These values are case-insensitive.
156 * until - defines an iCalendar COS DATE or DATE-TIME value which
157 bounds the recurrence rule in an inclusive manner. If the value
158 specified by “until” is synchronized with the specified recurrence,
159 this date or date-time becomes the last instance of the recurrence.
160 If it is not present, the recurrence is considered to repeat
161 forever.
162 * interval - a positive integer representing how often the recurrence
163 rule repeats. The default value is “1”, meaning every day for a
164 “daily” rule, every week for a “weekly” rule, every month for a
165 “monthly” rule and every year for a “yearly” rule.
166 * byday - a comma-separated list short codes of days of the week. The
167 days are specified as: “MO” for Monday; “TU” for Tuesday; “WE” for
168 Wednesday; “TH” for Thursday; “FR” for Friday; “SA” for Saturday;
169 “SU” for Sunday. These values are case insensitive.
170 Each “byday” value can also be prefixed by a positive (+n) or
171 negative (-n) integer. If present, this indicates the n-th
172 occurrence of the specific day within the “monthly” or “yearly”
173 recurrence. For example, within a “monthly” rule, +1MO (or simply
174 1MO) represents the first Monday within the month, whereas -1MO
175 represents the last Monday of the month. If an integer modifier is
176 not present, it means all days of this type within the specified
177 frequency. For example, within a “monthly” rule, MO represents all
178 Mondays within the month.
179 * bymonthday - a comma-separated list of days of the month. Valid
180 values are 1 to 31 or -31 to -1. For example, -10 represents the
181 tenth to the last day of the month.
182 * byyearday - a comma-separated list of days of the year. Valid
183 values are 1 to 366 or -366 to -1. For example, -1 represents the
184 last day of the year (December 31st) and -306 represents the 306th
185 day before the last day of the year (March 1st).
186 * byweekno - a comma-separated list of ordinals specifying weeks of
187 the year. Valid values are 1 to 53 or -53 to -1.
188 * bymonth - parameter specifies a comma-separated list of months of
189 the year. Valid values are 1 to 12.
190
191 A recurrence is specified by including the “frequency” parameter, which
192 indicates the type of the recurrence rule. Parameters other than
193 “startdate” and “duration” SHOULD NOT be specified unless “frequency”
194 is set.
195
196 If invalid byxxx parameter values are found (ie, bymonthday=“30” in
197 February), they are simply ignored.
198
199 Byxxx parameters modify the recurrence rule matching. The Byxxx rule,
200 as an attribute for a period of time which is greater than or equal to
201 the frequency, generally reduces or limits the number of occurrences
202 for the recurrence definition. For example, frequency=“daily”
203 bymonth=“3” reduces the number of recurrence instances from all days
204 (if the “bymonth” parameter is not present) to all days in March. Byxxx
205 parameters for a period of time less than the frequency generally
206 increases or expands the number of occurrences of the recurrence. For
207 example, frequency=“yearly” bymonth=“8,9” increases the number of days
208 within the yearly recurrence set from 1 (if “bymonth” parameter is not
209 present) to 2.
210
211 If multiple Byxxx parameters are specified, then after evaluating the
212 specified “frequency” and “interval” parameters, the Byxxx parameters
213 are applied to the current set of evaluated occurrences in the
214 following order: “bymonth”, “byweekno”, “byyearday”, “bymonthday”,
215 “byday”; then “until” is evaluated.
216
217 Next is an example of evaluating multiple Byxxx parameters.
218
219 startdate=“20100101T093000” duration=“PT10H30M” frequency=“yearly”
220 interval=“4” bymonth=“3” byday=“SU”
221
222 First, the interval=“4” would be applied to frequency=“yearly” to match
223 on “every 4th year” . Then, bymonth=“1” would be applied to match on
224 “every March, every 4th year”. Then, byday=“SU” would be applied to
225 match on “every Sunday in March, every 4th year, from 9:30 to 20:00 ”.
226 The start and end hours:minutes have been retrieved from the
227 “startdate” and “duration” parameters.
228
229 This function can be used in ANY_ROUTE.
230
231 Example 1.2. tmrec_match usage
232 ...
233 if(tmrec_match("20120101T000000|PT24H|weekly|||SA,SU")
234 xdbg("it is weekend!\n");
235 if(tmrec_match("20120101T083000|PT10H|weekly|||MO,TU,WE,TH,FR")
236 xdbg("it is with working hours\n");
237 ...
238
239 4.2. is_leap_year([year])
240
241 Return true if the value from parameter is a leap year. If the
242 parameter is missing, then the year from the current time is taken.
243
244 The parameter can be pseudo-variable.
245
246 This function can be used in ANY_ROUTE.
247
248 Example 1.3. is_leap_year usage
249 ...
250 if(is_leap_year("2010"))
251 ...
252
253 4.3. time_period_match(period [, timestamp])
254
255 Matches the point in time specified by the timestamp parameter, or the
256 current time if the parameter is missing, against the given period
257 specification. Returns 1 if it matches, -1 if it doesn't, and a value
258 <= -2 if there was an error.
259
260 The time period specification follows the Perl Time::Period module. It
261 is a string and consists of zero or more sub-period specifications,
262 separated by commas. The period matches if at least one of the
263 sub-periods matches, or if no sub-periods were given at all (an empty
264 string).
265
266 Each sub-period is a list of one or more scale definitions, optionally
267 separated by space characters. The sub-period matches if all of the
268 given scales within that sub-period match. For each scale given, a
269 single value or a range of values (which is two values separated by a
270 hyphen) can be specified. Multiple values or multiple ranges (or a
271 combination thereof) within a single scale is also possible. If a
272 certain scale is specified more than once, the previous values or
273 ranges for that scale are extended by the newly given ones. If a
274 particular scale is not mentioned at all within a sub-period, then no
275 matching is performed for that scale.
276
277 The following scales are supported and understood. Each scale also has
278 a respective short code, either one can be used. A single scale
279 definition consists of the scale name, followed by an opening brace,
280 followed by the list of values, followed by a closing brace.
281 * year or yr - Either given as a full 4-digit number >= 1970, or as a
282 2-digit number, in which case it will be understood to be within
283 the current century.
284 * month or mo - Month of the year, either a number between 1 and 12,
285 or at least the first 3 letters of a spelled out month name, e.g.
286 “jan”, “janua” or “january” will all work.
287 * week or wk - Week of the month, a number between 1 and 6. The first
288 day of the week is Sunday.
289 * yday or yd - Day of the year, a number between 1 and 366.
290 * mday or md - Day of the month, a number between 1 and 31.
291 * wday or wd - Day of the week, either a number between 1 and 7, or
292 at least the first 2 letters of a spelled out weekday name
293 (analogous to the “month” scale). Sunday is the first day of the
294 week.
295 * hour or hr - A number between 0 and 23. Unlike the Perl
296 Time::Period module, “am” or “pm” specifications are not supported.
297 * minute or min - A number between 0 and 59.
298 * second or sec - A number between 0 and 60 (to allow for leap
299 seconds).
300
301 The parameters can include pseudo-variables. Whitespace (more
302 precisely, the space character only) can occur anywhere, but is
303 optional. Ranges in all scales (with the exception of the “year” scale)
304 are allowed to wrap-around, e.g. a weekday scale of “{fri-tue}” is
305 equivalent to “{fri-sat,sun-tue}”.
306
307 Example 1.4. time_period_match usage
308 ...
309 if(time_period_match("wd{2-6} hr{8-16}, wd{2-6} hr{17} min{0-29}"))
310 xdbg("Monday to Friday, 8:00 to 17:30\n");
311
312 if(time_period_match("wday { sat sun }, wday {mo-fr} hr {17-8},wd{mo-wed}hr{15 1
313 6 9}"))
314 xdbg("We're closed - open only Monday to Wednesday 10:00-15:00, Thursday
315 and Friday 9:00-17:00");
316 ...