cpl_time.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 FhG Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * Kamailio is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. *
  23. * History:
  24. * -------
  25. * 2003-06-24: file imported from tmrec (bogdan)
  26. * 2003-xx-xx: file Created (daniel)
  27. */
  28. #ifndef _CPL_TIME_H_
  29. #define _CPL_TIME_H_
  30. /************************ imported from "ac_tm.h" ***************************/
  31. #include <time.h>
  32. /* USE_YWEEK_U -- Sunday system - see strftime %U
  33. * USE_YWEEK_V -- ISO 8601 - see strftime %V
  34. * USE_YWEEK_W -- Monday system - see strftime %W
  35. */
  36. #ifndef USE_YWEEK_U
  37. # ifndef USE_YWEEK_V
  38. # ifndef USE_YWEEK_W
  39. # define USE_YWEEK_W
  40. # endif
  41. # endif
  42. #endif
  43. #define is_leap_year(yyyy) ((((yyyy)%400))?(((yyyy)%100)?(((yyyy)%4)?0:1):0):1)
  44. typedef struct _ac_maxval
  45. {
  46. int yweek;
  47. int yday;
  48. int ywday;
  49. int mweek;
  50. int mday;
  51. int mwday;
  52. } ac_maxval_t, *ac_maxval_p;
  53. typedef struct _ac_tm
  54. {
  55. time_t time;
  56. struct tm t;
  57. int mweek;
  58. int yweek;
  59. int ywday;
  60. int mwday;
  61. ac_maxval_p mv;
  62. } ac_tm_t, *ac_tm_p;
  63. ac_tm_p ac_tm_new(void);
  64. int ac_tm_set_time(ac_tm_p, time_t);
  65. int ac_tm_reset(ac_tm_p);
  66. int ac_tm_free(ac_tm_p);
  67. int ac_get_mweek(struct tm*);
  68. int ac_get_yweek(struct tm*);
  69. ac_maxval_p ac_get_maxval(ac_tm_p);
  70. int ac_get_wkst(void);
  71. int ac_print(ac_tm_p);
  72. /************************ imported from "tmrec.h" ***************************/
  73. #define FREQ_NOFREQ 0
  74. #define FREQ_YEARLY 1
  75. #define FREQ_MONTHLY 2
  76. #define FREQ_WEEKLY 3
  77. #define FREQ_DAILY 4
  78. #define WDAY_SU 0
  79. #define WDAY_MO 1
  80. #define WDAY_TU 2
  81. #define WDAY_WE 3
  82. #define WDAY_TH 4
  83. #define WDAY_FR 5
  84. #define WDAY_SA 6
  85. #define WDAY_NU 7
  86. #define TSW_TSET 1
  87. #define TSW_RSET 2
  88. typedef struct _tr_byxxx
  89. {
  90. int nr;
  91. int *xxx;
  92. int *req;
  93. } tr_byxxx_t, *tr_byxxx_p;
  94. typedef struct _tmrec
  95. {
  96. time_t dtstart;
  97. struct tm ts;
  98. time_t dtend;
  99. time_t duration;
  100. time_t until;
  101. int freq;
  102. int interval;
  103. tr_byxxx_p byday;
  104. tr_byxxx_p bymday;
  105. tr_byxxx_p byyday;
  106. tr_byxxx_p bymonth;
  107. tr_byxxx_p byweekno;
  108. int wkst;
  109. } tmrec_t, *tmrec_p;
  110. typedef struct _tr_res
  111. {
  112. int flag;
  113. time_t rest;
  114. } tr_res_t, *tr_res_p;
  115. tr_byxxx_p tr_byxxx_new(void);
  116. int tr_byxxx_init(tr_byxxx_p, int);
  117. int tr_byxxx_free(tr_byxxx_p);
  118. tmrec_p tmrec_new(void);
  119. int tmrec_free(tmrec_p);
  120. int tr_parse_dtstart(tmrec_p, char*);
  121. int tr_parse_dtend(tmrec_p, char*);
  122. int tr_parse_duration(tmrec_p, char*);
  123. int tr_parse_until(tmrec_p, char*);
  124. int tr_parse_freq(tmrec_p, char*);
  125. int tr_parse_interval(tmrec_p, char*);
  126. int tr_parse_byday(tmrec_p, char*);
  127. int tr_parse_bymday(tmrec_p, char*);
  128. int tr_parse_byyday(tmrec_p, char*);
  129. int tr_parse_bymonth(tmrec_p, char*);
  130. int tr_parse_byweekno(tmrec_p, char*);
  131. int tr_parse_wkst(tmrec_p, char*);
  132. int tr_print(tmrec_p);
  133. time_t ic_parse_datetime(char*,struct tm*);
  134. time_t ic_parse_duration(char*);
  135. tr_byxxx_p ic_parse_byday(char*);
  136. tr_byxxx_p ic_parse_byxxx(char*);
  137. int ic_parse_wkst(char*);
  138. int check_tmrec(tmrec_p, ac_tm_p, tr_res_p);
  139. #endif