Parcourir la source

tmrec: new module for time recurrence matching

- recurrence definitions based on RFC2445
Daniel-Constantin Mierla il y a 13 ans
Parent
commit
bf692bcf47

+ 17 - 0
modules/tmrec/Makefile

@@ -0,0 +1,17 @@
+# $Id$
+#
+# 
+# WARNING: do not run this directly, it should be run by the master Makefile
+
+include ../../Makefile.defs
+auto_gen=
+NAME=tmrec.so
+DEFS +=
+LIBS +=
+
+DEFS+=-DOPENSER_MOD_INTERFACE
+
+SERLIBPATH=../../lib
+SER_LIBS+=$(SERLIBPATH)/srutils/srutils
+
+include ../../Makefile.modules

+ 231 - 0
modules/tmrec/README

@@ -0,0 +1,231 @@
+TMREC Module
+
+Daniel-Constantin Mierla
+
+   <[email protected]>
+
+Edited by
+
+Daniel-Constantin Mierla
+
+   <[email protected]>
+
+   Copyright © 2012 asipto.com
+     __________________________________________________________________
+
+   Table of Contents
+
+   1. Admin Guide
+
+        1. Overview
+        2. Dependencies
+
+              2.1. Kamailio Modules
+              2.2. External Libraries or Applications
+
+        3. Parameters
+
+              3.1. separator (str)
+
+        4. Functions
+
+              4.1. tmrec_match(timerec [, timestamp])
+              4.2. is_leap_year([year])
+
+   List of Examples
+
+   1.1. Set separator parameter
+   1.2. tmrec_match usage
+   1.3. is_leap_year usage
+
+Chapter 1. Admin Guide
+
+   Table of Contents
+
+   1. Overview
+   2. Dependencies
+
+        2.1. Kamailio Modules
+        2.2. External Libraries or Applications
+
+   3. Parameters
+
+        3.1. separator (str)
+
+   4. Functions
+
+        4.1. tmrec_match(timerec [, timestamp])
+        4.2. is_leap_year([year])
+
+1. Overview
+
+   This module provides time recurrence matching functions. Definitions of
+   recurrences are based on Internet Calendaring and Scheduling Core
+   Object Specification (Calendar COS - RFC 2445).
+
+2. Dependencies
+
+   2.1. Kamailio Modules
+   2.2. External Libraries or Applications
+
+2.1. Kamailio Modules
+
+   The following modules must be loaded before this module:
+     * None.
+
+2.2. External Libraries or Applications
+
+   The following libraries or applications must be installed before
+   running Kamailio with this module loaded:
+     * None
+
+3. Parameters
+
+   3.1. separator (str)
+
+3.1. separator (str)
+
+   Separator character used to delimit the attributes in time reccurence
+   definitions.
+
+   Default value is '|'.
+
+   Example 1.1. Set separator parameter
+...
+modparam("tmrec", "separator", ";")
+...
+
+4. Functions
+
+   4.1. tmrec_match(timerec [, timestamp])
+   4.2. is_leap_year([year])
+
+4.1. tmrec_match(timerec [, timestamp])
+
+   Match a time recurrence rules against the timestamp. If timestamp
+   parameter is missing, the value of current unix timestamp is used.
+
+   The parameters can include pseudo-variables.
+
+   The timerec paramter is a list of attributes defined by RFC2445,
+   delimited by 'separator' (module parameter) character. The format of
+   timerec parameter, using '|' as separator, is (all in one line without
+   white spaces):
+...
+[startdate]|[duration]|[frequency]|[until]|[interval]|[byday]
+  |[bymonthday]|[byyearday]|[byweekno]|[bymonth]
+...
+
+   When an attribute is not specified, the corresponding place must be
+   left empty, whenever another attribute that follows in the list has to
+   be specified.
+
+   Description of time recurrence attributes:
+     * startdate - date for the start of the first period.
+     * duration - the duration of the time period. For a recurring
+       interval, the "duration" parameter MUST be small enough such that
+       subsequent intervals do not overlap. For non-recurring intervals,
+       durations of any positive length are permitted, zero-length
+       duration means "forever". Negative-length durations are not
+       allowed.
+     * frequency - can be one of the following values: "daily" - specify
+       repeating periods based on an interval of a day or more; "weekly" -
+       specify repeating periods based on an interval of a week or more;
+       "monthly" - specify repeating periods based on an interval of a
+       month or more; "yearly" - specify repeating periods based on an
+       interval of a year or more. These values are case insensitive.
+     * until - defines an iCalendar COS DATE or DATE-TIME value which
+       bounds the recurrence rule in an inclusive manner. If the value
+       specified by "until" is synchronized with the specified recurrence,
+       this date or date-time becomes the last instance of the recurrence.
+       If not present, the recurrence is considered to repeat forever.
+     * interval - a positive integer representing how often the recurrence
+       rule repeats. The default value is "1", meaning every day for a
+       "daily" rule, every week for a "weekly" rule, every month for a
+       "monthly" rule and every year for a "yearly" rule.
+     * byday - a comma-separated list short codes of days of the week. The
+       days are specified as: "MO" for Monday; "TU" for Tuesday; "WE" for
+       Wednesday; "TH" for Thursday; "FR" for Friday; "SA" for Saturday;
+       "SU" for Sunday. These values are case insensitive.
+       Each "byday" value can also be prefixed by a positive (+n) or
+       negative (-n) integer. If present, this indicates the n-th
+       occurrence of the specific day within the "monthly" or "yearly"
+       recurrence. For example, within a "monthly" rule, +1MO (or simply
+       1MO) represents the first Monday within the month, whereas -1MO
+       represents the last Monday of the month. If an integer modifier is
+       not present, it means all days of this type within the specified
+       frequency. For example, within a "monthly" rule, MO represents all
+       Mondays within the month.
+     * bymonthday - a comma-separated list of days of the month. Valid
+       values are 1 to 31 or -31 to -1. For example, -10 represents the
+       tenth to the last day of the month.
+     * byyearday - a comma-separated list of days of the year. Valid
+       values are 1 to 366 or -366 to -1. For example, -1 represents the
+       last day of the year (December 31st) and -306 represents the 306th
+       day before the last day of the year (March 1st).
+     * byweekno - a comma-separated list of ordinals specifying weeks of
+       the year. Valid values are 1 to 53 or -53 to -1.
+     * bymonth - parameter specifies a comma-separated list of months of
+       the year. Valid values are 1 to 12.
+
+   A recurrence is specified by including the "frequency" parameter, which
+   indicates the type of recurrence rule. Parameters other than
+   "startdate" and "duration" SHOULD NOT be specified unless "frequency"
+   is set.
+
+   If byxxx parameter values are found which are beyond the available
+   scope (ie, bymonthday="30" in February), they are simply ignored.
+
+   Byxxx parameters modify the recurrence rule matching. Byxxx rule, as
+   attribute for a period of time which is the same or greater than the
+   frequency, generally reduces or limits the number of occurrences for
+   the recurrence definition. For example, frequency="daily" bymonth="3"
+   reduces the number of recurrence instances from all days (if the
+   "bymonth" parameter is not present) to all days in March. Byxxx
+   parameters for a period of time less than the frequency generally
+   increases or expands the number of occurrences of the recurrence. For
+   example, frequency="yearly" bymonth="8,9" increases the number of days
+   within the yearly recurrence set from 1 (if "bymonth" parameter is not
+   present) to 2.
+
+   If multiple Byxxx parameters are specified, then after evaluating the
+   specified "frequency" and "interval" parameters, the Byxxx parameters
+   are applied to the current set of evaluated occurrences in the
+   following order: "bymonth", "byweekno", "byyearday", "bymonthday",
+   "byday"; then "until" is evaluated.
+
+   Next is an example of evaluating multiple Byxxx parameters.
+
+   startdate="20100101T093000" duration="10H30M" frequency="yearly"
+   interval="4" bymonth="3" byday="SU"
+
+   First, the interval="4" would be applied to frequency="yearly" to match
+   on "every 4th year" . Then, bymonth="1" would be applied to match on
+   "every March, every 4th year". Then, byday="SU" would be applied to
+   match on "every Sunday in March, every 4th year, from 9:30 to 20:00 ".
+   The start and end hours:minutes have been retrieved from the
+   "startdate" and "duration" parameters.
+
+   This function can be used in ANY_ROUTE.
+
+   Example 1.2. tmrec_match usage
+...
+        if(tmrec_match("20120101T000000|24H|weekly|||SA,SU")
+        xdbg("it is weekend!\n");
+    if(tmrec_match("20120101T083000|10H|weekly|||MO,TU,WE,TH,FR")
+        xdbg("it is with working hours\n");
+...
+
+4.2. is_leap_year([year])
+
+   Return true if the value from parameter is a leap year. If the
+   parameter is missing, then the year from current time is taken.
+
+   The parameter can be pseudo-variable.
+
+   This function can be used in ANY_ROUTE.
+
+   Example 1.3. is_leap_year usage
+...
+if(is_leap_year("2010"))
+...

+ 4 - 0
modules/tmrec/doc/Makefile

@@ -0,0 +1,4 @@
+docs = tmrec.xml
+
+docbook_dir = ../../../docbook
+include $(docbook_dir)/Makefile.module

+ 37 - 0
modules/tmrec/doc/tmrec.xml

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding='ISO-8859-1'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
+
+<!-- Include general documentation entities -->
+<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
+%docentities;
+
+]>
+
+<book xmlns:xi="http://www.w3.org/2001/XInclude">
+    <bookinfo>
+	<title>TMREC Module</title>
+	<productname class="trade">sip-router.org</productname>
+	<authorgroup>
+	    <author>
+		<firstname>Daniel-Constantin</firstname>
+		<surname>Mierla</surname>
+		<email>[email protected]</email>
+	    </author>
+	    <editor>
+		<firstname>Daniel-Constantin</firstname>
+		<surname>Mierla</surname>
+		<email>[email protected]</email>
+	    </editor>
+	</authorgroup>
+	<copyright>
+	    <year>2012</year>
+	    <holder>asipto.com</holder>
+	</copyright>
+    </bookinfo>
+    <toc></toc>
+    
+    <xi:include href="tmrec_admin.xml"/>
+    
+    
+</book>

+ 311 - 0
modules/tmrec/doc/tmrec_admin.xml

@@ -0,0 +1,311 @@
+<?xml version="1.0" encoding='ISO-8859-1'?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+"http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
+
+<!-- Include general documentation entities -->
+<!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
+%docentities;
+
+]>
+<!-- Module User's Guide -->
+
+<chapter>
+	
+	<title>&adminguide;</title>
+	
+	<section>
+	<title>Overview</title>
+	<para>
+		This module provides time recurrence matching functions. Definitions
+		of recurrences are based on Internet Calendaring and Scheduling Core
+		Object Specification (Calendar COS - RFC 2445).
+	</para>
+	</section>
+
+	<section>
+	<title>Dependencies</title>
+	<section>
+		<title>&kamailio; Modules</title>
+		<para>
+		The following modules must be loaded before this module:
+			<itemizedlist>
+			<listitem>
+			<para>
+				<emphasis>None</emphasis>.
+			</para>
+			</listitem>
+			</itemizedlist>
+		</para>
+	</section>
+	<section>
+		<title>External Libraries or Applications</title>
+		<para>
+		The following libraries or applications must be installed before running
+		&kamailio; with this module loaded:
+			<itemizedlist>
+			<listitem>
+			<para>
+				<emphasis>None</emphasis>
+			</para>
+			</listitem>
+			</itemizedlist>
+		</para>
+	</section>
+	</section>
+	<section>
+	<title>Parameters</title>
+	<section>
+		<title><varname>separator</varname> (str)</title>
+		<para>
+			Separator character used to delimit the attributes in time
+			reccurence definitions.
+		</para>
+		<para>
+		<emphasis>
+			Default value is '|'.
+		</emphasis>
+		</para>
+		<example>
+		<title>Set <varname>separator</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("tmrec", "separator", ";")
+...
+</programlisting>
+		</example>
+	</section>
+	</section>
+
+	<section>
+	<title>Functions</title>
+	<section>
+	    <title>
+		<function moreinfo="none">tmrec_match(timerec [, timestamp])</function>
+	    </title>
+	    <para>
+			Match a time recurrence rules against the timestamp. If timestamp
+			parameter is missing, the value of current unix timestamp is used.
+		</para>
+		<para>
+			The parameters can include pseudo-variables.
+		</para>
+		<para>
+			The timerec paramter is a list of attributes defined by RFC2445,
+			delimited by 'separator' (module parameter) character. The format
+			of timerec parameter, using '|' as separator, is (all in one line
+			without white spaces):
+		</para>
+
+		<programlisting format="linespecific">
+...
+[startdate]|[duration]|[frequency]|[until]|[interval]|[byday]
+  |[bymonthday]|[byyearday]|[byweekno]|[bymonth]
+...
+</programlisting>
+
+		<para>
+		When an attribute is not specified, the corresponding place must be left
+		empty, whenever another attribute that follows in the list has to be
+		specified.
+		</para>
+		<para>
+		Description of time recurrence attributes:
+		</para>
+		<itemizedlist>
+		<listitem>
+			<para>
+			<emphasis>startdate</emphasis> - date for the start of the first 
+			period.
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+			<emphasis>duration</emphasis> - the duration of the time period.
+			For a recurring interval, the <quote>duration</quote> parameter MUST
+			be small enough such that subsequent intervals do not overlap. 
+			For non-recurring intervals, durations of any positive length are 
+			permitted, zero-length duration means <quote>forever</quote>. 
+			Negative-length durations are not allowed.
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+			<emphasis>frequency</emphasis> - can be one of the following values: 
+			<quote>daily</quote> -
+			specify repeating periods based on an interval of a day or more;
+			<quote>weekly</quote> - specify repeating periods based on an 
+			interval of a week or more; <quote>monthly</quote> - specify 
+			repeating periods based on an interval of a month or more; 
+			<quote>yearly</quote> - specify repeating periods based
+			on an interval of a year or more. These values are case insensitive.
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+			<emphasis>until</emphasis> - defines an iCalendar COS DATE or DATE-TIME
+			value which bounds the recurrence rule in an inclusive manner. If the
+			value specified by <quote>until</quote> is synchronized with the 
+			specified 
+			recurrence, this date or date-time becomes the last instance of the 
+			recurrence. If not present, the recurrence is considered to repeat 
+			forever.
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+			<emphasis>interval</emphasis> - a positive integer 
+			representing how often the recurrence rule repeats. The default value
+			is <quote>1</quote>, meaning every day for a <quote>daily</quote> rule,
+			every week for a <quote>weekly</quote>
+			rule, every month for a <quote>monthly</quote> rule and every year for
+			a <quote>yearly</quote> rule.
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+			<emphasis>byday</emphasis> - a comma-separated list short codes of days 
+			of the week. The days are specified as: <quote>MO</quote> for Monday;
+			<quote>TU</quote> for Tuesday; <quote>WE</quote> for Wednesday; 
+			<quote>TH</quote> for Thursday; <quote>FR</quote> for 
+			Friday; <quote>SA</quote> for Saturday; <quote>SU</quote> 
+			for Sunday. These values are case insensitive.
+			</para>
+			<para>
+			Each <quote>byday</quote> value can also be prefixed by a positive 
+			(+n) or negative (-n) integer. If present, this indicates the n-th 
+			occurrence of the specific day within the <quote>monthly</quote> or 
+			<quote>yearly</quote> recurrence. For example, within a 
+			<quote>monthly</quote> rule, +1MO (or simply 1MO) represents the first 
+			Monday within the month, whereas -1MO represents the last Monday of
+			the month. If an integer modifier is not present, it means all days
+			of this type within the specified frequency. For example, within a 
+			<quote>monthly</quote> rule, MO represents all Mondays within the month.
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+			<emphasis>bymonthday</emphasis> - a comma-separated
+			list of days of the month. Valid values are 1 to 31 or -31 to -1. For 
+			example, -10 represents the tenth to the last day of the month.
+			</para>
+		</listitem>
+
+		<listitem>
+			<para>
+			<emphasis>byyearday</emphasis> - a comma-separated list of 
+			days of the year. Valid values are 1 to 366 or -366 to -1. For example,
+			-1 represents the last day of the year (December 31st) and -306 
+			represents the 306th day before the last day of the year (March 1st).
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+			<emphasis>byweekno</emphasis> - a comma-separated list of 
+			ordinals specifying weeks of the year. Valid values are 1 to 53 or 
+			-53 to -1.
+			</para>
+		</listitem>
+		<listitem>
+			<para>
+			<emphasis>bymonth</emphasis> - parameter specifies a comma-separated
+			list of months of the year. Valid values are 1 to 12.
+		</para>
+		</listitem>
+		</itemizedlist>
+		
+		<para>
+		A recurrence is specified by including the <quote>frequency</quote> 
+		parameter, which indicates the type of recurrence rule. Parameters 
+		other than <quote>startdate</quote>
+		and <quote>duration</quote> SHOULD NOT be specified unless 
+		<quote>frequency</quote> is set.
+		</para>
+		<para>
+		If byxxx parameter values are found which are beyond the available 
+		scope (ie, bymonthday=<quote>30</quote> in February), they are simply
+		ignored. 
+		</para>
+		<para>
+		Byxxx parameters modify the recurrence rule matching. Byxxx rule, as
+		attribute for a period of time which is the same or greater than the 
+		frequency, generally reduces or limits the number of occurrences for the 
+		recurrence definition. For example, frequency=<quote>daily</quote> 
+		bymonth=<quote>3</quote> reduces the number of
+		recurrence instances from all days (if the <quote>bymonth</quote> 
+		parameter is not present) to all days in March. Byxxx parameters for 
+		a period of time less than the frequency generally increases or expands 
+		the number of occurrences of the recurrence. For example, 
+		frequency=<quote>yearly</quote> bymonth=<quote>8,9</quote>
+		increases the number of days within the yearly recurrence set from 1 
+		(if <quote>bymonth</quote> parameter is not present) to 2.
+		</para>
+		<para>
+		If multiple Byxxx parameters are specified, then after evaluating the
+		specified <quote>frequency</quote> and <quote>interval</quote> parameters,
+		the Byxxx parameters are 
+		applied to the current set of evaluated occurrences in the following
+		order: <quote>bymonth</quote>, <quote>byweekno</quote>, 
+		<quote>byyearday</quote>, <quote>bymonthday</quote>, 
+		<quote>byday</quote>; then <quote>until</quote> is  evaluated.
+		</para>
+		<para>
+		Next is an example of evaluating multiple Byxxx parameters.
+		</para>
+		<para>
+		startdate=<quote>20100101T093000</quote> duration=<quote>10H30M</quote>
+		frequency=<quote>yearly</quote> interval=<quote>4</quote> 
+		bymonth=<quote>3</quote> byday=<quote>SU</quote>
+		</para>
+		<para>
+		First, the interval=<quote>4</quote> would be applied to 
+		frequency=<quote>yearly</quote> to match on <quote>every 4th year</quote>
+		. Then, bymonth=<quote>1</quote> would be applied to match on 
+		<quote>every March, every 4th year</quote>. Then,
+		byday=<quote>SU</quote> would be applied to match on <quote>every 
+		Sunday in March, every 4th year, from 9:30 to 20:00 </quote>. The start
+		and end hours:minutes have been retrieved from the
+		<quote>startdate</quote> and <quote>duration</quote> parameters.
+		</para>
+
+		<para>
+		This function can be used in ANY_ROUTE.
+		</para>
+		<example>
+		<title><function>tmrec_match</function> usage</title>
+		<programlisting format="linespecific">
+...
+	if(tmrec_match("20120101T000000|24H|weekly|||SA,SU")
+        xdbg("it is weekend!\n");
+    if(tmrec_match("20120101T083000|10H|weekly|||MO,TU,WE,TH,FR")
+        xdbg("it is with working hours\n");
+...
+</programlisting>
+	    </example>
+	</section>
+
+	<section>
+	    <title>
+		<function moreinfo="none">is_leap_year([year])</function>
+	    </title>
+	    <para>
+			Return true if the value from parameter is a leap year. If the
+			parameter is missing, then the year from current time is taken.
+		</para>
+		<para>
+		The parameter can be pseudo-variable.
+		</para>
+		<para>
+		This function can be used in ANY_ROUTE.
+		</para>
+		<example>
+		<title><function>is_leap_year</function> usage</title>
+		<programlisting format="linespecific">
+...
+if(is_leap_year("2010"))
+...
+</programlisting>
+	    </example>
+	</section>
+	</section>
+</chapter>
+

+ 222 - 0
modules/tmrec/tmrec_mod.c

@@ -0,0 +1,222 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2012 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../sr_module.h"
+#include "../../dprint.h"
+#include "../../ut.h"
+#include "../../pvar.h"
+#include "../../mod_fix.h"
+#include "../../lib/srutils/tmrec.h"
+
+
+MODULE_VERSION
+
+static int  mod_init(void);
+static int  child_init(int);
+static void mod_destroy(void);
+
+static int w_tmrec_match(struct sip_msg* msg, char* rec, char* t);
+static int fixup_tmrec_match(void** param, int param_no);
+static int w_is_leap_year(struct sip_msg* msg, char* t, char* p2);
+static int fixup_is_leap_year(void** param, int param_no);
+
+int tmrec_wday = 0;
+char tmrec_separator = '|';
+char *tmrec_separator_param = NULL;
+
+static cmd_export_t cmds[]={
+	{"tmrec_match", (cmd_function)w_tmrec_match, 1, fixup_tmrec_match,
+		0, ANY_ROUTE},
+	{"tmrec_match", (cmd_function)w_tmrec_match, 2, fixup_tmrec_match,
+		0, ANY_ROUTE},
+	{"is_leap_year", (cmd_function)w_is_leap_year, 0, fixup_is_leap_year,
+		0, ANY_ROUTE},
+	{"is_leap_year", (cmd_function)w_is_leap_year, 1, fixup_is_leap_year,
+		0, ANY_ROUTE},
+	{0, 0, 0, 0, 0, 0}
+};
+
+static param_export_t params[]={
+	{"wday",		INT_PARAM,   &tmrec_wday},
+	{"separator",   STR_PARAM,   &tmrec_separator_param},
+	{0, 0, 0}
+};
+
+struct module_exports exports = {
+	"tmrec",
+	DEFAULT_DLFLAGS, /* dlopen flags */
+	cmds,
+	params,
+	0,
+	0,              /* exported MI functions */
+	0,              /* exported pseudo-variables */
+	0,              /* extra processes */
+	mod_init,       /* module initialization function */
+	0,              /* response function */
+	mod_destroy,    /* destroy function */
+	child_init      /* per child init function */
+};
+
+
+
+/**
+ * init module function
+ */
+static int mod_init(void)
+{
+	if(tmrec_separator_param!=NULL)
+		tmrec_separator = tmrec_separator_param[0];
+	return 0;
+}
+
+/**
+ * @brief Initialize async module children
+ */
+static int child_init(int rank)
+{
+	if (rank!=PROC_MAIN)
+		return 0;
+
+	return 0;
+}
+/**
+ * destroy module function
+ */
+static void mod_destroy(void)
+{
+	return;
+}
+
+static int w_is_leap_year(struct sip_msg* msg, char* t, char* str2)
+{
+	time_t tv;
+	struct tm *tb;
+	int y;
+	
+	if(msg==NULL)
+		return -1;
+
+	if(t!=NULL)
+	{
+		if(fixup_get_ivalue(msg, (gparam_t*)t, &y)!=0)
+		{
+			LM_ERR("invalid time parameter value\n");
+			return -1;
+		}
+	} else {
+		tv = time(NULL);
+		tb = localtime(&tv);
+		y = 1900 + tb->tm_year;
+	}
+
+	if(tr_is_leap_year(y))
+		return 1;
+	return -1;
+}
+
+static int fixup_is_leap_year(void** param, int param_no)
+{
+	if(param_no==1)
+		return fixup_igp_null(param, param_no);
+
+	return 0;
+}
+
+static int w_tmrec_match(struct sip_msg* msg, char* rec, char* t)
+{
+	str rv;
+	time_t tv;
+	int ti;
+	ac_tm_t act;
+	tmrec_t tmr;
+
+	if(msg==NULL)
+		return -1;
+
+	if(fixup_get_svalue(msg, (gparam_t*)rec, &rv)!=0)
+	{
+		LM_ERR("invalid time recurrence parameter value\n");
+		return -1;
+	}
+
+	if(t!=NULL)
+	{
+		if(fixup_get_ivalue(msg, (gparam_t*)t, &ti)!=0)
+		{
+			LM_ERR("invalid time stamp parameter value\n");
+			return -1;
+		}
+		tv = (time_t)ti;
+	} else {
+		tv = time(NULL);
+	}
+
+	memset(&act, 0, sizeof(act));
+	memset(&tmr, 0, sizeof(tmr));
+
+	/* parse time recurrence definition */
+	if(tr_parse_recurrence_string(&tmr, rv.s, tmrec_separator)<0)
+		return -1;
+
+	/* if there is no dstart, timerec is valid */
+	if (tmr.dtstart==0)
+		goto done;
+
+	/* set current time */
+	if (ac_tm_set_time(&act, tv)<0)
+		goto error;
+
+	/* match the specified recurence */
+	if (tr_check_recurrence(&tmr, &act, 0)!=0)
+		goto error;
+
+done:
+	tmrec_destroy(&tmr);
+	ac_tm_destroy(&act);
+	return 1;
+
+error:
+	tmrec_destroy(&tmr);
+	ac_tm_destroy(&act);
+	return -1;
+}
+
+static int fixup_tmrec_match(void** param, int param_no)
+{
+	if(param_no==1)
+	{
+		if(fixup_spve_null(param, 1)<0)
+			return -1;
+		return 0;
+	} else if(param_no==2) {
+		if(fixup_igp_null(param, 1)<0)
+			return -1;
+	}
+	return 0;
+}