Coverage Report

Created: 2025-07-11 06:28

/src/opensips/time_rec.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2001-2003 FhG Fokus
3
 * Copyright (C) 2020 OpenSIPS Solutions
4
 *
5
 * This file is part of opensips, a free SIP server.
6
 *
7
 * opensips is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version
11
 *
12
 * opensips is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
 */
21
22
#ifndef _TIME_REC_H_
23
#define _TIME_REC_H_
24
25
#include <time.h>
26
27
#include "mem/common.h"
28
#include "lib/list.h"
29
30
typedef void tmrec;
31
typedef void tmrec_expr;
32
33
#define SHM_ALLOC    1
34
0
#define PKG_ALLOC    2
35
0
#define TR_BYXXX     4
36
37
tmrec *tmrec_parse(const char *tr, char alloc_type);
38
39
int _tmrec_check(const tmrec *tr, time_t check_time);
40
static inline int tmrec_check(const tmrec *tr)
41
0
{
42
0
  return _tmrec_check(tr, time(NULL));
43
0
}
Unexecuted instantiation: transformations.c:tmrec_check
Unexecuted instantiation: time_rec.c:tmrec_check
44
45
void tmrec_free(tmrec *tr);
46
47
int tmrec_print(const tmrec *tr);
48
49
/**
50
 * _tmrec_check_str() - verify that a time recurrence string matches, at the
51
 *                      given point in time
52
 *
53
 * Return:
54
 *    1 - match
55
 *   -1 - no match
56
 *   -2 - parse error (bad input)
57
 *   -3 - internal error
58
 *
59
 * FIXME: @tr must be write-able memory, otherwise I will segfault!
60
 */
61
int _tmrec_check_str(const char *tr, time_t check_time);
62
static inline int tmrec_check_str(const char *tr)
63
0
{
64
0
  return _tmrec_check_str(tr, time(NULL));
65
0
}
Unexecuted instantiation: transformations.c:tmrec_check_str
Unexecuted instantiation: time_rec.c:tmrec_check_str
66
67
68
tmrec_expr *tmrec_expr_parse(const char *trx, char alloc_type);
69
70
int _tmrec_expr_check(const tmrec_expr *trx, time_t check_time);
71
static inline int tmrec_expr_check(const tmrec_expr *trx)
72
0
{
73
0
  return _tmrec_expr_check(trx, time(NULL));
74
0
}
Unexecuted instantiation: transformations.c:tmrec_expr_check
Unexecuted instantiation: time_rec.c:tmrec_expr_check
75
76
void tmrec_expr_free(tmrec_expr *trx);
77
78
int tmrec_expr_print(const tmrec_expr *trx);
79
80
/**
81
 * This function expects the @trx string to be trim()'ed beforehand.
82
 *
83
 * Return:
84
 *     1: match
85
 *    -1: no match
86
 *    -2: parse error (bad input)
87
 *    -3: internal error
88
 */
89
int _tmrec_expr_check_str(const char *trx, time_t check_time);
90
static inline int tmrec_expr_check_str(const char *trx)
91
0
{
92
0
  return _tmrec_expr_check_str(trx, time(NULL));
93
0
}
Unexecuted instantiation: transformations.c:tmrec_expr_check_str
Unexecuted instantiation: time_rec.c:tmrec_expr_check_str
94
95
96
/**
97
 * Set the current timezone to @tz while also making sure to back up the
98
 * existing timezone such that tz_reset() can be later used to restore it.
99
 *
100
 * If @tz is an invalid timezone, no change will be made.
101
 */
102
void tz_set(const str *tz);
103
void _tz_set(const char *tz);
104
105
106
/**
107
 * Restore the timezone to the value stored by the last tz_set() call and clear
108
 * the currently backed up timezone (i.e. subsequent calls to this function
109
 * without calling tz_set() again will be NOPs).
110
 */
111
void tz_reset(void);
112
113
114
/**
115
 * Obtain an equivalent to the @unix_time UNIX timestamp
116
 * that matches the @tz timezone, including the current DST status
117
 *
118
 * Note: If @tz == NULL, @unix_time will be ajusted to local time
119
 */
120
time_t tz_adjust_ts(time_t unix_time, const str *tz);
121
122
123
/**
124
 * tz_offset() - fetch the GMT offset of the given @tz timezone at the
125
 *               current point in time or at the @t UNIX timestamp
126
 */
127
int _tz_offset(const char *tz, time_t t);
128
static inline int tz_offset(const char *tz)
129
0
{
130
0
  return _tz_offset(tz, time(NULL));
131
0
}
Unexecuted instantiation: transformations.c:tz_offset
Unexecuted instantiation: time_rec.c:tz_offset
132
133
134
/*************** RFC 2445/5545 low-level abstractions ****************/
135
136
0
#define FREQ_NOFREQ  0
137
0
#define FREQ_YEARLY  1
138
0
#define FREQ_MONTHLY 2
139
0
#define FREQ_WEEKLY  3
140
0
#define FREQ_DAILY   4
141
142
0
#define TR_NOVAL ((time_t)-1)
143
144
typedef struct _tr_byxxx
145
{
146
  int nr;
147
  int *xxx;
148
  int *req;
149
  char flags;
150
} tr_byxxx_t, *tr_byxxx_p;
151
152
tr_byxxx_p tr_byxxx_new(char);
153
int tr_byxxx_init(tr_byxxx_p, int);
154
int tr_byxxx_free(tr_byxxx_p);
155
156
typedef struct _tmrec
157
{
158
  time_t dtstart;
159
  struct tm ts;
160
  time_t dtend;
161
  time_t duration;
162
  time_t until;
163
  int freq;
164
  int interval;
165
  tr_byxxx_p byday;
166
  tr_byxxx_p bymday;
167
  tr_byxxx_p byyday;
168
  tr_byxxx_p bymonth;
169
  tr_byxxx_p byweekno;
170
  int wkst;
171
  char flags;
172
  char *tz;
173
} tmrec_t, *tmrec_p;
174
175
typedef struct _tmrec_expr
176
{
177
  char is_leaf;
178
  char flags;
179
180
  char op;
181
  struct list_head operands;
182
  char inverted;
183
184
  tmrec_t tr;
185
  struct list_head list;
186
} tmrec_expr_t;
187
188
tmrec_p tmrec_new(char);
189
void tmrec_init(tmrec_p t);
190
191
int tr_parse_tz(tmrec_p, char*);
192
int tr_parse_dtstart(tmrec_p, char*);
193
int tr_parse_dtend(tmrec_p, char*);
194
int tr_parse_duration(tmrec_p, char*);
195
int tr_parse_until(tmrec_p, char*);
196
int tr_parse_freq(tmrec_p, char*);
197
int tr_parse_interval(tmrec_p, char*);
198
int tr_parse_byday(tmrec_p, char*);
199
int tr_parse_bymday(tmrec_p, char*);
200
int tr_parse_byyday(tmrec_p, char*);
201
int tr_parse_bymonth(tmrec_p, char*);
202
int tr_parse_byweekno(tmrec_p, char*);
203
int tr_parse_wkst(tmrec_p, char*);
204
205
206
#endif