1 /*
2 This module provides some helper APIs for creating
3 a VCalendar object.
4
5 Note on APIs:
6 1. The APIs does not attempt to verify if the arguments
7 passed are correct.
8 2. Where the argument to an API is not applicable, pass
9 the value 0.
10 3. See the test program at the bottom of this file as an
11 example of usage.
12 4. This code calls APIs in vobject.c.
13
14 */
15
16 /***************************************************************************
17 (C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International
18 Business Machines Corporation and Siemens Rolm Communications Inc.
19
20 For purposes of this license notice, the term Licensors shall mean,
21 collectively, Apple Computer, Inc., AT&T Corp., International
22 Business Machines Corporation and Siemens Rolm Communications Inc.
23 The term Licensor shall mean any of the Licensors.
24
25 Subject to acceptance of the following conditions, permission is hereby
26 granted by Licensors without the need for written agreement and without
27 license or royalty fees, to use, copy, modify and distribute this
28 software for any purpose.
29
30 The above copyright notice and the following four paragraphs must be
31 reproduced in all copies of this software and any software including
32 this software.
33
34 THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE
35 ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR
36 MODIFICATIONS.
37
38 IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,
39 INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
40 OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
41 DAMAGE.
42
43 EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,
44 INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE
45 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
46 PURPOSE.
47
48 The software is provided with RESTRICTED RIGHTS. Use, duplication, or
49 disclosure by the government are subject to restrictions set forth in
50 DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.
51
52 ***************************************************************************/
53
54 #ifdef HAVE_CONFIG_H
55 #include <config.h>
56 #endif
57
58 #include "vcaltmp.h"
59
vcsCreateVCal(char * date_created,char * location,char * product_id,char * time_zone,char * version)60 VObject* vcsCreateVCal(
61 char *date_created,
62 char *location,
63 char *product_id,
64 char *time_zone,
65 char *version
66 )
67 {
68 VObject *vcal = newVObject(VCCalProp);
69 #define Z(p,v) if (v) (void)addPropValue(vcal,p,v);
70 Z(VCDCreatedProp, date_created);
71 Z(VCLocationProp, location)
72 Z(VCProdIdProp, product_id)
73 Z(VCTimeZoneProp, time_zone)
74 Z(VCVersionProp, version)
75 #undef Z
76 return vcal;
77 }
78
79
vcsAddEvent(VObject * vcal,char * start_date_time,char * end_date_time,char * description,char * summary,char * categories,char * classification,char * status,char * transparency,char * uid,char * url)80 VObject* vcsAddEvent(
81 VObject *vcal,
82 char *start_date_time,
83 char *end_date_time,
84 char *description,
85 char *summary,
86 char *categories,
87 char *classification,
88 char *status,
89 char *transparency,
90 char *uid,
91 char *url
92 )
93 {
94 VObject *vevent = addProp(vcal,VCEventProp);
95 #define Z(p,v) if (v) (void)addPropValue(vevent,p,v);
96 Z(VCDTstartProp,start_date_time);
97 Z(VCDTendProp,end_date_time);
98 if (description) {
99 VObject *p = addPropValue(vevent,VCDescriptionProp,description);
100 if (strchr(description,'\n'))
101 (void)addProp(p,VCQuotedPrintableProp);
102 }
103 Z(VCSummaryProp,summary);
104 Z(VCCategoriesProp,categories);
105 Z(VCClassProp,classification);
106 Z(VCStatusProp,status);
107 Z(VCTranspProp,transparency);
108 Z(VCUniqueStringProp,uid);
109 Z(VCURLProp,url);
110 #undef Z
111 return vevent;
112 }
113
114
vcsAddTodo(VObject * vcal,char * start_date_time,char * due_date_time,char * date_time_complete,char * description,char * summary,char * priority,char * classification,char * status,char * uid,char * url)115 VObject* vcsAddTodo(
116 VObject *vcal,
117 char *start_date_time,
118 char *due_date_time,
119 char *date_time_complete,
120 char *description,
121 char *summary,
122 char *priority,
123 char *classification,
124 char *status,
125 char *uid,
126 char *url
127 )
128 {
129 VObject *vtodo = addProp(vcal,VCTodoProp);
130 #define Z(p,v) if (v) (void)addPropValue(vtodo,p,v);
131 Z(VCDTstartProp,start_date_time);
132 Z(VCDueProp,due_date_time);
133 Z(VCCompletedProp,date_time_complete);
134 if (description) {
135 VObject *p = addPropValue(vtodo,VCDescriptionProp,description);
136 if (strchr(description,'\n'))
137 (void)addProp(p,VCQuotedPrintableProp);
138 }
139 Z(VCSummaryProp,summary);
140 Z(VCPriorityProp,priority);
141 Z(VCClassProp,classification);
142 Z(VCStatusProp,status);
143 Z(VCUniqueStringProp,uid);
144 Z(VCURLProp,url);
145 #undef Z
146 return vtodo;
147 }
148
149
vcsAddAAlarm(VObject * vevent,char * run_time,char * snooze_time,char * repeat_count,char * audio_content)150 VObject* vcsAddAAlarm(
151 VObject *vevent,
152 char *run_time,
153 char *snooze_time,
154 char *repeat_count,
155 char *audio_content
156 )
157 {
158 VObject *aalarm= addProp(vevent,VCAAlarmProp);
159 #define Z(p,v) if (v) (void)addPropValue(aalarm,p,v);
160 Z(VCRunTimeProp,run_time);
161 Z(VCSnoozeTimeProp,snooze_time);
162 Z(VCRepeatCountProp,repeat_count);
163 Z(VCAudioContentProp,audio_content);
164 #undef Z
165 return aalarm;
166 }
167
168
vcsAddMAlarm(VObject * vevent,char * run_time,char * snooze_time,char * repeat_count,char * email_address,char * note)169 VObject* vcsAddMAlarm(
170 VObject *vevent,
171 char *run_time,
172 char *snooze_time,
173 char *repeat_count,
174 char *email_address,
175 char *note
176 )
177 {
178 VObject *malarm= addProp(vevent,VCMAlarmProp);
179 #define Z(p,v) if (v) (void)addPropValue(malarm,p,v);
180 Z(VCRunTimeProp,run_time);
181 Z(VCSnoozeTimeProp,snooze_time);
182 Z(VCRepeatCountProp,repeat_count);
183 Z(VCEmailAddressProp,email_address);
184 Z(VCNoteProp,note);
185 #undef Z
186 return malarm;
187 }
188
189
vcsAddDAlarm(VObject * vevent,char * run_time,char * snooze_time,char * repeat_count,char * display_string)190 VObject* vcsAddDAlarm(
191 VObject *vevent,
192 char *run_time,
193 char *snooze_time,
194 char *repeat_count,
195 char *display_string
196 )
197 {
198 VObject *dalarm= addProp(vevent,VCDAlarmProp);
199 #define Z(p,v) if (v) (void)addPropValue(dalarm,p,v);
200 Z(VCRunTimeProp,run_time);
201 Z(VCSnoozeTimeProp,snooze_time);
202 Z(VCRepeatCountProp,repeat_count);
203 Z(VCDisplayStringProp,display_string);
204 #undef Z
205 return dalarm;
206 }
207
208
vcsAddPAlarm(VObject * vevent,char * run_time,char * snooze_time,char * repeat_count,char * procedure_name)209 VObject* vcsAddPAlarm(
210 VObject *vevent,
211 char *run_time,
212 char *snooze_time,
213 char *repeat_count,
214 char *procedure_name
215 )
216 {
217 VObject *palarm= addProp(vevent,VCPAlarmProp);
218 #define Z(p,v) if (v) (void)addPropValue(palarm,p,v);
219 Z(VCRunTimeProp,run_time);
220 Z(VCSnoozeTimeProp,snooze_time);
221 Z(VCRepeatCountProp,repeat_count);
222 Z(VCProcedureNameProp,procedure_name);
223 #undef Z
224 return palarm;
225 }
226
227
228 #ifdef _TEST
229
230 #if 0
231 This testcase would generate a file call "frankcal.vcf" with
232 the following content:
233
234 BEGIN:VCALENDAR
235 DCREATED:19960523T100522
236 GEO:37.24,-17.87
237 PRODID:-//Frank Dawson/Hand Crafted In North Carolina//NONSGML Made By Hand//EN
238 VERSION:0.3
239 BEGIN:VEVENT
240 DTSTART:19960523T120000
241 DTEND:19960523T130000
242 DESCRIPTION;QUOTED-PRINTABLE:VERSIT PDI PR Teleconference/Interview =0A=
243 With Tom Streeter and Frank Dawson - Discuss VERSIT PDI project and vCard and vCalendar=0A=
244 activities with European Press representatives.
245 SUMMARY:VERSIT PDI PR Teleconference/Interview
246 CATEGORIES:PHONE CALL
247 STATUS:CONFIRMED
248 TRANSP:19960523T100522-4000F100582713-009251
249 UID:https://www.ibm.com/raleigh/fdawson/~c:\or2\orgfiles\versit.or2
250 DALARM:19960523T114500;5;3;Your Telecon Starts At Noon!!!;
251 MALARM:19960522T120000;;;fdawson@raleigh.ibm.com;Remember 05/23 Noon Telecon!!!;
252 PALARM:19960523T115500;;;c:\or2\organize.exe c:\or2\orgfiles\versit.or2;
253 X-LDC-OR2-OLE:c:\temp\agenda.doc
254 END:VEVENT
255
256 BEGIN:VTODO
257 DUE:19960614T0173000
258 DESCRIPTION:Review VCalendar helper API.
259 END:VTODO
260
261 END:VCALENDAR
262
263 #endif
264
testVcalAPIs()265 void testVcalAPIs() {
266 FILE *fp;
267 VObject *vcal = vcsCreateVCal(
268 "19960523T100522",
269 "37.24,-17.87",
270 "-//Frank Dawson/Hand Crafted In North Carolina//NONSGML Made By Hand//EN",
271 0,
272 "0.3"
273 );
274
275 VObject *vevent = vcsAddEvent(
276 vcal,
277 "19960523T120000",
278 "19960523T130000",
279 "VERSIT PDI PR Teleconference/Interview \nWith Tom Streeter and Frank Dawson - Discuss VERSIT PDI project and vCard and vCalendar\nactivities with European Press representatives.",
280 "VERSIT PDI PR Teleconference/Interview",
281 "PHONE CALL",
282 0,
283 "CONFIRMED",
284 "19960523T100522-4000F100582713-009251",
285 "https://www.ibm.com/raleigh/fdawson/~c:\\or2\\orgfiles\\versit.or2",
286 0
287 );
288
289 vcsAddDAlarm(vevent, "19960523T114500", "5", "3",
290 "Your Telecon Starts At Noon!!!");
291 vcsAddMAlarm(vevent, "19960522T120000", 0, 0, "fdawson@raleigh.ibm.com",
292 "Remember 05/23 Noon Telecon!!!");
293 vcsAddPAlarm(vevent, "19960523T115500", 0 ,0,
294 "c:\\or2\\organize.exe c:\\or2\\orgfiles\\versit.or2");
295
296 addPropValue(vevent, "X-LDC-OR2-OLE", "c:\\temp\\agenda.doc");
297
298 vcsAddTodo(
299 vcal,
300 0,
301 "19960614T0173000",
302 0,
303 "Review VCalendar helper API.",
304 0,
305 0,
306 0,
307 0,
308 0,
309 0
310 );
311
312 /* now do something to the resulting VObject */
313 /* pretty print on stdout for fun */
314 printVObject(vcal);
315 /* open the output text file */
316
317 #define OUTFILE "frankcal.vcf"
318
319 fp = fopen(OUTFILE, "w");
320 if (fp) {
321 /* write it in text form */
322 writeVObject(fp,vcal);
323 fclose(fp);
324 }
325 else {
326 printf("open output file '%s' failed\n", OUTFILE);
327 }
328 }
329
main()330 void main() {
331 testVcalAPIs();
332 }
333
334 #endif
335
336
337 /* end of source file vcaltmp.c */
338