2 ======================================================================
4 CREATOR: eric 16 May 1999
10 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of either:
15 The LGPL as published by the Free Software Foundation, version
16 2.1, available at: http://www.fsf.org/copyleft/lesser.html
20 The Mozilla Public License Version 1.0. You may obtain a copy of
21 the License at http://www.mozilla.org/MPL/
23 The original code is icaltypes.c
25 ======================================================================*/
30 #include "icaltypes.h"
31 #include "icalerror.h"
32 #include "icalmemory.h"
33 #include <stdlib.h> /* for malloc and abs() */
34 #include <errno.h> /* for errno */
35 #include <string.h> /* for icalmemory_strdup */
41 icalattachtype_get_data (struct icalattachtype* type);
43 struct icalattachtype*
46 struct icalattachtype* v;
48 if ( ( v = (struct icalattachtype*)
49 malloc(sizeof(struct icalattachtype))) == 0) {
69 icalattachtype_free(struct icalattachtype* v)
71 icalerror_check_arg( (v!=0),"v");
75 if (v->refcount <= 0){
77 if (v->base64 != 0 && v->owns_base64 != 0){
81 if (v->binary != 0 && v->owns_binary != 0){
93 void icalattachtype_add_reference(struct icalattachtype* v)
95 icalerror_check_arg( (v!=0),"v");
99 void icalattachtype_set_url(struct icalattachtype* v, char* url)
101 icalerror_check_arg( (v!=0),"v");
107 v->url = icalmemory_strdup(url);
109 /* HACK This routine should do something if icalmemory_strdup returns NULL */
113 char* icalattachtype_get_url(struct icalattachtype* v)
115 icalerror_check_arg( (v!=0),"v");
119 void icalattachtype_set_base64(struct icalattachtype* v, char* base64,
122 icalerror_check_arg( (v!=0),"v");
125 v->owns_base64 = !(owns != 0 );
129 char* icalattachtype_get_base64(struct icalattachtype* v)
131 icalerror_check_arg( (v!=0),"v");
135 void icalattachtype_set_binary(struct icalattachtype* v, char* binary,
138 icalerror_check_arg( (v!=0),"v");
141 v->owns_binary = !(owns != 0 );
145 void* icalattachtype_get_binary(struct icalattachtype* v)
147 icalerror_check_arg( (v!=0),"v");
152 struct icaltriggertype icaltriggertype_from_string(const char* str)
156 struct icaltriggertype tr, null_tr;
157 int old_ieaf = icalerror_errors_are_fatal;
159 tr.time= icaltime_null_time();
160 tr.duration = icaldurationtype_from_int(0);
164 if(str == 0) goto error;
167 icalerror_errors_are_fatal = 0;
169 tr.time = icaltime_from_string(str);
171 icalerror_errors_are_fatal = old_ieaf;
173 if (icaltime_is_null_time(tr.time)){
175 tr.duration = icaldurationtype_from_string(str);
177 if(icaldurationtype_as_int(tr.duration) == 0) goto error;
183 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
189 struct icalreqstattype icalreqstattype_from_string(char* str)
192 struct icalreqstattype stat;
195 icalerror_check_arg((str != 0),"str");
197 stat.code = ICAL_UNKNOWN_STATUS;
201 /* Get the status numbers */
203 sscanf(str, "%d.%d",&major, &minor);
205 if (major <= 0 || minor < 0){
206 icalerror_set_errno(ICAL_BADARG_ERROR);
210 stat.code = icalenum_num_to_reqstat(major, minor);
212 if (stat.code == ICAL_UNKNOWN_STATUS){
213 icalerror_set_errno(ICAL_BADARG_ERROR);
218 p1 = strchr(str,';');
221 /* icalerror_set_errno(ICAL_BADARG_ERROR);*/
225 /* Just ignore the second clause; it will be taken from inside the library
230 p2 = strchr(p1+1,';');
231 if (p2 != 0 && *p2 != 0){
239 char* icalreqstattype_as_string(struct icalreqstattype stat)
243 temp = (char*)icalmemory_tmp_buffer(TEMP_MAX);
245 icalerror_check_arg_rz((stat.code != ICAL_UNKNOWN_STATUS),"Status");
248 stat.desc = icalenum_reqstat_desc(stat.code);
252 snprintf(temp,TEMP_MAX,"%d.%d;%s;%s", icalenum_reqstat_major(stat.code),
253 icalenum_reqstat_minor(stat.code),
254 stat.desc, stat.debug);
257 snprintf(temp,TEMP_MAX,"%d.%d;%s", icalenum_reqstat_major(stat.code),
258 icalenum_reqstat_minor(stat.code),