modules_s/cpl-c/cpl_time.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  * ser 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  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * ser is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  *
00027  *
00028  * History:
00029  * -------
00030  * 2003-06-24: file imported from tmrec (bogdan)
00031  * 2003-xx-xx: file Created (daniel)
00032  */
00033 
00034 #ifndef _CPL_TIME_H_
00035 #define _CPL_TIME_H_
00036 
00037 
00038 /************************ imported from "ac_tm.h"  ***************************/
00039 
00040 #include <time.h>
00041 
00042 
00043 /* USE_YWEEK_U  -- Sunday system - see strftime %U
00044  * USE_YWEEK_V  -- ISO 8601 - see strftime %V
00045  * USE_YWEEK_W  -- Monday system - see strftime %W
00046 */
00047 
00048 #ifndef USE_YWEEK_U
00049 # ifndef USE_YWEEK_V
00050 #  ifndef USE_YWEEK_W
00051 #   define USE_YWEEK_W
00052 #  endif
00053 # endif
00054 #endif
00055 
00056 #define is_leap_year(yyyy) ((((yyyy)%400))?(((yyyy)%100)?(((yyyy)%4)?0:1):0):1)
00057 
00058 
00059 typedef struct _ac_maxval
00060 {
00061         int yweek;
00062         int yday;
00063         int ywday;
00064         int mweek;
00065         int mday;
00066         int mwday;
00067 } ac_maxval_t, *ac_maxval_p;
00068 
00069 typedef struct _ac_tm
00070 {
00071         time_t time;
00072         struct tm t;
00073         int mweek;
00074         int yweek;
00075         int ywday;
00076         int mwday;
00077         ac_maxval_p mv;
00078 } ac_tm_t, *ac_tm_p;
00079 
00080 ac_tm_p ac_tm_new();
00081 
00082 int ac_tm_set(ac_tm_p, struct tm*);
00083 int ac_tm_set_time(ac_tm_p, time_t);
00084 
00085 int ac_tm_reset(ac_tm_p);
00086 int ac_tm_free(ac_tm_p);
00087 
00088 int ac_get_mweek(struct tm*);
00089 int ac_get_yweek(struct tm*);
00090 ac_maxval_p ac_get_maxval(ac_tm_p);
00091 int ac_get_wkst();
00092 
00093 int ac_print(ac_tm_p);
00094 
00095 
00096 
00097 
00098 /************************ imported from "tmrec.h"  ***************************/
00099 
00100 
00101 #define FREQ_NOFREQ  0
00102 #define FREQ_YEARLY  1
00103 #define FREQ_MONTHLY 2
00104 #define FREQ_WEEKLY  3
00105 #define FREQ_DAILY   4
00106 
00107 #define WDAY_SU 0
00108 #define WDAY_MO 1
00109 #define WDAY_TU 2
00110 #define WDAY_WE 3
00111 #define WDAY_TH 4
00112 #define WDAY_FR 5
00113 #define WDAY_SA 6
00114 #define WDAY_NU 7
00115 
00116 #define TSW_TSET        1
00117 #define TSW_RSET        2
00118 
00119 typedef struct _tr_byxxx
00120 {
00121         int nr;
00122         int *xxx;
00123         int *req;
00124 } tr_byxxx_t, *tr_byxxx_p;
00125 
00126 typedef struct _tmrec
00127 {
00128         time_t dtstart;
00129         struct tm ts;
00130         time_t dtend;
00131         time_t duration;
00132         time_t until;
00133         int freq;
00134         int interval;
00135         tr_byxxx_p byday;
00136         tr_byxxx_p bymday;
00137         tr_byxxx_p byyday;
00138         tr_byxxx_p bymonth;
00139         tr_byxxx_p byweekno;
00140         int wkst;
00141 } tmrec_t, *tmrec_p;
00142 
00143 typedef struct _tr_res
00144 {
00145         int flag;
00146         time_t rest;
00147 } tr_res_t, *tr_res_p;
00148 
00149 tr_byxxx_p tr_byxxx_new();
00150 int tr_byxxx_init(tr_byxxx_p, int);
00151 int tr_byxxx_free(tr_byxxx_p);
00152 
00153 tmrec_p tmrec_new();
00154 int tmrec_free(tmrec_p);
00155 
00156 int tr_parse_dtstart(tmrec_p, char*);
00157 int tr_parse_dtend(tmrec_p, char*);
00158 int tr_parse_duration(tmrec_p, char*);
00159 int tr_parse_until(tmrec_p, char*);
00160 int tr_parse_freq(tmrec_p, char*);
00161 int tr_parse_interval(tmrec_p, char*);
00162 int tr_parse_byday(tmrec_p, char*);
00163 int tr_parse_bymday(tmrec_p, char*);
00164 int tr_parse_byyday(tmrec_p, char*);
00165 int tr_parse_bymonth(tmrec_p, char*);
00166 int tr_parse_byweekno(tmrec_p, char*);
00167 int tr_parse_wkst(tmrec_p, char*);
00168 
00169 int tr_print(tmrec_p);
00170 time_t ic_parse_datetime(char*,struct tm*);
00171 time_t ic_parse_duration(char*);
00172 
00173 tr_byxxx_p ic_parse_byday(char*);
00174 tr_byxxx_p ic_parse_byxxx(char*);
00175 int ic_parse_wkst(char*);
00176 
00177 int check_tmrec(tmrec_p, ac_tm_p, tr_res_p);
00178 
00179 
00180 #endif
00181