tmrec.h

00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of ser, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 #ifndef _SR_TMREC_H_
00025 #define _SR_TMREC_H_
00026 
00027 
00032 #include <time.h>
00033 
00034 
00035 /* USE_YWEEK_U  -- Sunday system - see strftime %U
00036  * USE_YWEEK_V  -- ISO 8601 - see strftime %V
00037  * USE_YWEEK_W  -- Monday system - see strftime %W
00038 */
00039 
00040 #ifndef USE_YWEEK_U
00041 # ifndef USE_YWEEK_V
00042 #  ifndef USE_YWEEK_W
00043 #   define USE_YWEEK_W
00044 #  endif
00045 # endif
00046 #endif
00047 
00048 #define tr_is_leap_year(yyyy) ((((yyyy)%400))?(((yyyy)%100)?(((yyyy)%4)?0:1):0):1)
00049 
00050 
00051 typedef struct _ac_maxval
00052 {
00053         int yweek;
00054         int yday;
00055         int ywday;
00056         int mweek;
00057         int mday;
00058         int mwday;
00059 } ac_maxval_t;
00060 
00061 typedef struct _ac_tm
00062 {
00063         time_t time;
00064         struct tm t;
00065         int mweek;
00066         int yweek;
00067         int ywday;
00068         int mwday;
00069         ac_maxval_t *mv;
00070 } ac_tm_t;
00071 
00072 ac_tm_t *ac_tm_new(void);
00073 
00074 int ac_tm_set_time(ac_tm_t*, time_t);
00075 
00076 int ac_tm_reset(ac_tm_t*);
00077 int ac_tm_free(ac_tm_t*);
00078 int ac_tm_destroy(ac_tm_t*);
00079 
00080 int ac_get_mweek(struct tm*);
00081 int ac_get_yweek(struct tm*);
00082 ac_maxval_t *ac_get_maxval(ac_tm_t*);
00083 int ac_get_wkst(void);
00084 
00085 int ac_print(ac_tm_t*);
00086 
00087 
00088 
00089 
00095 #define FREQ_NOFREQ  0
00096 #define FREQ_YEARLY  1
00097 #define FREQ_MONTHLY 2
00098 #define FREQ_WEEKLY  3
00099 #define FREQ_DAILY   4
00100 
00101 #define WDAY_SU 0
00102 #define WDAY_MO 1
00103 #define WDAY_TU 2
00104 #define WDAY_WE 3
00105 #define WDAY_TH 4
00106 #define WDAY_FR 5
00107 #define WDAY_SA 6
00108 #define WDAY_NU 7
00109 
00110 #define TSW_TSET        1
00111 #define TSW_RSET        2
00112 
00113 typedef struct _tr_byxxx
00114 {
00115         int nr;
00116         int *xxx;
00117         int *req;
00118 } tr_byxxx_t;
00119 
00120 typedef struct _tmrec
00121 {
00122         time_t dtstart;
00123         struct tm ts;
00124         time_t dtend;
00125         time_t duration;
00126         time_t until;
00127         int freq;
00128         int interval;
00129         tr_byxxx_t *byday;
00130         tr_byxxx_t *bymday;
00131         tr_byxxx_t *byyday;
00132         tr_byxxx_t *bymonth;
00133         tr_byxxx_t *byweekno;
00134         int wkst;
00135 } tmrec_t;
00136 
00137 typedef struct _tr_res
00138 {
00139         int flag;
00140         time_t rest;
00141 } tr_res_t;
00142 
00143 tr_byxxx_t *tr_byxxx_new(void);
00144 int tr_byxxx_init(tr_byxxx_t*, int);
00145 int tr_byxxx_free(tr_byxxx_t*);
00146 
00147 tmrec_t *tmrec_new(void);
00148 int tmrec_free(tmrec_t*);
00149 int tmrec_destroy(tmrec_t*);
00150 
00151 int tr_parse_dtstart(tmrec_t*, char*);
00152 int tr_parse_dtend(tmrec_t*, char*);
00153 int tr_parse_duration(tmrec_t*, char*);
00154 int tr_parse_until(tmrec_t*, char*);
00155 int tr_parse_freq(tmrec_t*, char*);
00156 int tr_parse_interval(tmrec_t*, char*);
00157 int tr_parse_byday(tmrec_t*, char*);
00158 int tr_parse_bymday(tmrec_t*, char*);
00159 int tr_parse_byyday(tmrec_t*, char*);
00160 int tr_parse_bymonth(tmrec_t*, char*);
00161 int tr_parse_byweekno(tmrec_t*, char*);
00162 int tr_parse_wkst(tmrec_t*, char*);
00163 
00164 int tr_print(tmrec_t*);
00165 time_t ic_parse_datetime(char*,struct tm*);
00166 time_t ic_parse_duration(char*);
00167 
00168 tr_byxxx_t *ic_parse_byday(char*);
00169 tr_byxxx_t *ic_parse_byxxx(char*);
00170 int ic_parse_wkst(char*);
00171 
00172 int tr_check_recurrence(tmrec_t*, ac_tm_t*, tr_res_t*);
00173 int tr_parse_recurrence_string(tmrec_t *trp, char *rdef, char sep);
00174 
00175 
00176 #endif
00177