dr_time.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2005-2009 Voice Sistem SRL
  5. *
  6. * This file is part of Kamailio, 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. * History:
  23. * ---------
  24. * 2005-02-27 ported to 0.9.0 (bogdan)
  25. */
  26. #ifndef _DR_TIME_H_
  27. #define _DR_TIME_H_
  28. /************************ imported from "ac_tm.h" ***************************/
  29. #include <time.h>
  30. /* USE_YWEEK_U -- Sunday system - see strftime %U
  31. * USE_YWEEK_V -- ISO 8601 - see strftime %V
  32. * USE_YWEEK_W -- Monday system - see strftime %W
  33. */
  34. #ifndef USE_YWEEK_U
  35. # ifndef USE_YWEEK_V
  36. # ifndef USE_YWEEK_W
  37. # define USE_YWEEK_W
  38. # endif
  39. # endif
  40. #endif
  41. #define is_leap_year(yyyy) ((((yyyy)%400))?(((yyyy)%100)?(((yyyy)%4)?0:1):0):1)
  42. typedef struct _ac_maxval
  43. {
  44. int yweek;
  45. int yday;
  46. int ywday;
  47. int mweek;
  48. int mday;
  49. int mwday;
  50. } ac_maxval_t, *ac_maxval_p;
  51. typedef struct _ac_tm
  52. {
  53. time_t time;
  54. struct tm t;
  55. int mweek;
  56. int yweek;
  57. int ywday;
  58. int mwday;
  59. ac_maxval_p mv;
  60. } ac_tm_t, *ac_tm_p;
  61. ac_tm_p ac_tm_new();
  62. int ac_tm_set_time(ac_tm_p, time_t);
  63. int ac_tm_reset(ac_tm_p);
  64. int ac_tm_free(ac_tm_p);
  65. int ac_get_mweek(struct tm*);
  66. int ac_get_yweek(struct tm*);
  67. ac_maxval_p ac_get_maxval(ac_tm_p);
  68. int ac_get_wkst();
  69. int ac_print(ac_tm_p);
  70. /************************ imported from "tmrec.h" ***************************/
  71. #define FREQ_NOFREQ 0
  72. #define FREQ_YEARLY 1
  73. #define FREQ_MONTHLY 2
  74. #define FREQ_WEEKLY 3
  75. #define FREQ_DAILY 4
  76. #define WDAY_SU 0
  77. #define WDAY_MO 1
  78. #define WDAY_TU 2
  79. #define WDAY_WE 3
  80. #define WDAY_TH 4
  81. #define WDAY_FR 5
  82. #define WDAY_SA 6
  83. #define WDAY_NU 7
  84. #define TSW_TSET 1
  85. #define TSW_RSET 2
  86. typedef struct _tr_byxxx
  87. {
  88. int nr;
  89. int *xxx;
  90. int *req;
  91. } tr_byxxx_t, *tr_byxxx_p;
  92. typedef struct _tmrec
  93. {
  94. time_t dtstart;
  95. struct tm ts;
  96. time_t dtend;
  97. time_t duration;
  98. time_t until;
  99. int freq;
  100. int interval;
  101. tr_byxxx_p byday;
  102. tr_byxxx_p bymday;
  103. tr_byxxx_p byyday;
  104. tr_byxxx_p bymonth;
  105. tr_byxxx_p byweekno;
  106. int wkst;
  107. } tmrec_t, *tmrec_p;
  108. typedef struct _tr_res
  109. {
  110. int flag;
  111. time_t rest;
  112. } tr_res_t, *tr_res_p;
  113. tr_byxxx_p tr_byxxx_new();
  114. int tr_byxxx_init(tr_byxxx_p, int);
  115. int tr_byxxx_free(tr_byxxx_p);
  116. tmrec_p tmrec_new();
  117. int tmrec_free(tmrec_p);
  118. int tr_parse_dtstart(tmrec_p, char*);
  119. int tr_parse_dtend(tmrec_p, char*);
  120. int tr_parse_duration(tmrec_p, char*);
  121. int tr_parse_until(tmrec_p, char*);
  122. int tr_parse_freq(tmrec_p, char*);
  123. int tr_parse_interval(tmrec_p, char*);
  124. int tr_parse_byday(tmrec_p, char*);
  125. int tr_parse_bymday(tmrec_p, char*);
  126. int tr_parse_byyday(tmrec_p, char*);
  127. int tr_parse_bymonth(tmrec_p, char*);
  128. int tr_parse_byweekno(tmrec_p, char*);
  129. int tr_parse_wkst(tmrec_p, char*);
  130. int tr_print(tmrec_p);
  131. time_t ic_parse_datetime(char*,struct tm*);
  132. time_t ic_parse_duration(char*);
  133. tr_byxxx_p ic_parse_byday(char*);
  134. tr_byxxx_p ic_parse_byxxx(char*);
  135. int ic_parse_wkst(char*);
  136. int check_tmrec(tmrec_p, ac_tm_p, tr_res_p);
  137. #endif