Libical API Documentation 4.0 UNRELEASED Go to the stable 3.0 documentation
Loading...
Searching...
No Matches
icaltypes.c
Go to the documentation of this file.
1/*======================================================================
2 FILE: icaltypes.c
3 CREATOR: eric 16 May 1999
4
5 SPDX-FileCopyrightText: 2000, Eric Busboom <eric@civicknowledge.com>
6 SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
7 ======================================================================*/
8
13
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include "icaltypes.h"
19#include "icalerror_p.h"
20#include "icalmemory.h"
21
23#define TMP_BUF_SIZE 1024
25
26#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
27#include <pthread.h>
28static pthread_mutex_t unk_token_mutex = PTHREAD_MUTEX_INITIALIZER;
29#endif
30#include <ctype.h>
31static ICAL_GLOBAL_VAR ical_unknown_token_handling unknownTokenHandling = ICAL_TREAT_AS_ERROR;
32
34{
36 return true;
37 }
38
39 return false;
40}
41
43{
45 return true;
46 }
47
48 return false;
49}
50
52{
53 struct icaltriggertype tr;
54
57
58 return tr;
59}
60
62{
63 struct icaltriggertype tr;
66
69
70 /* Suppress errors so a failure in icaltime_from_string() does not cause an abort */
72 if (str == 0) {
73 goto error;
74 }
76 e = icalerrno;
78
79 tr.time = icaltime_from_string(str);
80
83
85 goto error;
86 }
87 }
88
91 return tr;
92
93error:
96 return tr;
97}
98
100{
101 const char *s, *p1, *p2;
102 struct icalreqstattype stat;
103 short major = 0, minor = 0;
104
105 icalerror_check_arg((str != 0), "str");
106
108 stat.debug = 0;
109 stat.desc = 0;
110
111 // Don't allow (fuzzer) garbage chars anywhere in the reqstat string
112 s = str;
113 /* cppcheck-suppress nullPointerRedundantCheck */
114 while (*s && isprint((unsigned char)*s)) {
115 ++s;
116 }
117 if (*s != '\0') {
118 // garbage encountered. return the empty stat
119 return stat;
120 }
121
122 /* Get the status numbers */
123
124 sscanf(str, "%hd.%hd", &major, &minor);
125
126 if (major <= 0 || minor < 0) {
128 return stat;
129 }
130
131 stat.code = icalenum_num_to_reqstat(major, minor);
132
133 if (stat.code == ICAL_UNKNOWN_STATUS) {
135 return stat;
136 }
137
138 p1 = strchr(str, ';');
139
140 if (p1 == 0) {
141 /* icalerror_set_errno(ICAL_BADARG_ERROR);*/
142 return stat;
143 }
144
145 /* Just ignore the second clause; it will be taken from inside the library
146 */
147
148 p2 = strchr(p1 + 1, ';');
149 if (p2 != 0 && *(p2 + 1) != 0) { // skipping empty debug strings
150 stat.debug = icalmemory_tmp_copy(p2 + 1);
151 }
152
153 return stat;
154}
155
157{
158 char *buf;
159
160 buf = icalreqstattype_as_string_r(stat);
162 return buf;
163}
164
166{
167 char *temp;
168
169 icalerror_check_arg_rz((stat.code != ICAL_UNKNOWN_STATUS), "Status");
170
171 temp = (char *)icalmemory_new_buffer(TMP_BUF_SIZE);
172
173 if (stat.desc == 0) {
174 stat.desc = icalenum_reqstat_desc(stat.code);
175 }
176
177 if (stat.debug != 0) {
178 snprintf(temp, TMP_BUF_SIZE, "%d.%d;%s;%s", icalenum_reqstat_major(stat.code),
179 icalenum_reqstat_minor(stat.code), stat.desc, stat.debug);
180 } else {
181 snprintf(temp, TMP_BUF_SIZE, "%d.%d;%s", icalenum_reqstat_major(stat.code),
182 icalenum_reqstat_minor(stat.code), stat.desc);
183 }
184
185 return temp;
186}
187
189{
191
192#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
193 pthread_mutex_lock(&unk_token_mutex);
194#endif
195
196 myHandling = unknownTokenHandling;
197
198#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
199 pthread_mutex_unlock(&unk_token_mutex);
200#endif
201
202 return myHandling;
203}
204
206{
207#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
208 pthread_mutex_lock(&unk_token_mutex);
209#endif
210
211 unknownTokenHandling = newSetting;
212
213#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
214 pthread_mutex_unlock(&unk_token_mutex);
215#endif
216}
bool icaldurationtype_is_bad_duration(struct icaldurationtype d)
Checks if a duration is a bad duration.
struct icaldurationtype icaldurationtype_from_seconds(int seconds)
Creates a new icaldurationtype from a duration in seconds.
struct icaldurationtype icaldurationtype_from_string(const char *str)
Creates a new icaldurationtype from a duration given as a string.
bool icaldurationtype_is_null_duration(struct icaldurationtype d)
Checks if a duration is a null duration.
const char * icalenum_reqstat_desc(icalrequeststatus stat)
Definition icalenums.c:75
short icalenum_reqstat_major(icalrequeststatus stat)
Definition icalenums.c:114
icalrequeststatus icalenum_num_to_reqstat(short major, short minor)
Definition icalenums.c:140
short icalenum_reqstat_minor(icalrequeststatus stat)
Definition icalenums.c:127
@ ICAL_UNKNOWN_STATUS
Definition icalenums.h:80
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Definition icalerror.c:90
icalerrorstate
Determine if an error is fatal or non-fatal.
Definition icalerror.h:86
@ ICAL_ERROR_NONFATAL
Definition icalerror.h:91
icalerrorstate icalerror_get_error_state(icalerrorenum error)
Gets the error state (severity) for a given error.
icalerrorenum
Represents the different types of errors that can be triggered in libical.
Definition icalerror.h:42
@ ICAL_NO_ERROR
Definition icalerror.h:44
@ ICAL_MALFORMEDDATA_ERROR
Definition icalerror.h:56
void icalerror_set_error_state(icalerrorenum error, icalerrorstate state)
Sets the icalerrorstate for a given icalerrorenum error.
#define icalerrno
Access the current icalerrno value.
Definition icalerror.h:130
void * icalmemory_new_buffer(size_t size)
Creates new buffer with the specified size.
Definition icalmemory.c:313
char * icalmemory_tmp_copy(const char *str)
Creates a copy of the given string, stored on the ring buffer, and returns it.
Definition icalmemory.c:220
void icalmemory_add_tmp_buffer(void *buf)
Adds an externally allocated buffer to the ring.
Definition icalmemory.c:156
Common memory management routines.
struct icaltimetype icaltime_from_string(const char *str)
Definition icaltime.c:374
bool icaltime_is_null_time(const struct icaltimetype t)
Definition icaltime.c:626
struct icaltimetype icaltime_null_time(void)
Definition icaltime.c:575
void ical_set_unknown_token_handling_setting(ical_unknown_token_handling newSetting)
Definition icaltypes.c:205
struct icaltriggertype icaltriggertype_from_string(const char *str)
Definition icaltypes.c:61
const char * icalreqstattype_as_string(struct icalreqstattype stat)
Definition icaltypes.c:156
struct icaltriggertype icaltriggertype_from_seconds(const int reltime)
Definition icaltypes.c:51
ical_unknown_token_handling ical_get_unknown_token_handling_setting(void)
Definition icaltypes.c:188
bool icaltriggertype_is_null_trigger(struct icaltriggertype tr)
Definition icaltypes.c:33
bool icaltriggertype_is_bad_trigger(struct icaltriggertype tr)
Definition icaltypes.c:42
struct icalreqstattype icalreqstattype_from_string(const char *str)
Definition icaltypes.c:99
char * icalreqstattype_as_string_r(struct icalreqstattype stat)
Definition icaltypes.c:165
Define internal types and provide functions to manipulate them.
ical_unknown_token_handling
Definition icaltypes.h:155
@ ICAL_TREAT_AS_ERROR
Definition icaltypes.h:161
const char * desc
Definition icaltypes.h:112
const char * debug
Definition icaltypes.h:113
icalrequeststatus code
Definition icaltypes.h:111
struct icaldurationtype duration
Definition icaltypes.h:51
struct icaltimetype time
Definition icaltypes.h:50