aboutsummaryrefslogtreecommitdiffstats
path: root/libversit/vcaltmp.c
blob: ccb21a649a2fdd9d36243a7d38838745904d7fd7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
This module provides some helper APIs for creating
a VCalendar object.

Note on APIs:
    1.  The APIs does not attempt to verify if the arguments
        passed are correct.
    2.  Where the argument to an API is not applicable, pass
        the value 0.
    3.  See the test program at the bottom of this file as an
        example of usage.
    4.  This code calls APIs in vobject.c. 

*/

/***************************************************************************
(C) Copyright 1996 Apple Computer, Inc., AT&T Corp., International             
Business Machines Corporation and Siemens Rolm Communications Inc.             
                                                                               
For purposes of this license notice, the term Licensors shall mean,            
collectively, Apple Computer, Inc., AT&T Corp., International                  
Business Machines Corporation and Siemens Rolm Communications Inc.             
The term Licensor shall mean any of the Licensors.                             
                                                                               
Subject to acceptance of the following conditions, permission is hereby        
granted by Licensors without the need for written agreement and without        
license or royalty fees, to use, copy, modify and distribute this              
software for any purpose.                                                      
                                                                               
The above copyright notice and the following four paragraphs must be           
reproduced in all copies of this software and any software including           
this software.                                                                 
                                                                               
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS AND NO LICENSOR SHALL HAVE       
ANY OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR       
MODIFICATIONS.                                                                 
                                                                               
IN NO EVENT SHALL ANY LICENSOR BE LIABLE TO ANY PARTY FOR DIRECT,              
INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT         
OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH         
DAMAGE.                                                                        
                                                                               
EACH LICENSOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, EXPRESS OR IMPLIED,       
INCLUDING BUT NOT LIMITED TO ANY WARRANTY OF NONINFRINGEMENT OR THE            
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR             
PURPOSE.                                                                       

The software is provided with RESTRICTED RIGHTS.  Use, duplication, or         
disclosure by the government are subject to restrictions set forth in          
DFARS 252.227-7013 or 48 CFR 52.227-19, as applicable.                         

***************************************************************************/


#include <stdio.h>
#include <string.h>
#include "vcaltmp.h"

    
DLLEXPORT(VObject*) vcsCreateVCal(
    char *date_created,
    char *location,
    char *product_id,
    char *time_zone,
    char *version
    )
    {
    VObject *vcal = newVObject(VCCalProp);
#define Z(p,v) if (v) addPropValue(vcal,p,v);
    Z(VCDCreatedProp, date_created);
    Z(VCLocationProp, location)
    Z(VCProdIdProp, product_id)
    Z(VCTimeZoneProp, time_zone)
    Z(VCVersionProp, version)
#undef Z
    return vcal;
    }


DLLEXPORT(VObject*) 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
    )
    {
    VObject *vevent = addProp(vcal,VCEventProp);
#define Z(p,v) if (v) addPropValue(vevent,p,v);
    Z(VCDTstartProp,start_date_time);
    Z(VCDTendProp,end_date_time);
    if (description) {
    VObject *p = addPropValue(vevent,VCDescriptionProp,description);
    if (strchr(description,'\n'))
        addProp(p,VCQuotedPrintableProp);
    }
    Z(VCSummaryProp,summary);
    Z(VCCategoriesProp,categories);
    Z(VCClassProp,classification);
    Z(VCStatusProp,status);
    Z(VCTranspProp,transparency);
    Z(VCUniqueStringProp,uid);
    Z(VCURLProp,url);
#undef Z
    return vevent;
    }


DLLEXPORT(VObject*) 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
    )
    {
    VObject *vtodo = addProp(vcal,VCTodoProp);
#define Z(p,v) if (v) addPropValue(vtodo,p,v);
    Z(VCDTstartProp,start_date_time);
    Z(VCDueProp,due_date_time);
    Z(VCCompletedProp,date_time_complete);
    if (description) {
    VObject *p = addPropValue(vtodo,VCDescriptionProp,description);
    if (strchr(description,'\n'))
        addProp(p,VCQuotedPrintableProp);
    }
    Z(VCSummaryProp,summary);
    Z(VCPriorityProp,priority);
    Z(VCClassProp,classification);
    Z(VCStatusProp,status);
    Z(VCUniqueStringProp,uid);
    Z(VCURLProp,url);
#undef Z
    return vtodo;
    }


DLLEXPORT(VObject*) vcsAddAAlarm(
    VObject *vevent,
    char *run_time,
    char *snooze_time,
    char *repeat_count,
    char *audio_content
    )
    {
    VObject *aalarm= addProp(vevent,VCAAlarmProp);
#define Z(p,v) if (v) addPropValue(aalarm,p,v);
    Z(VCRunTimeProp,run_time);
    Z(VCSnoozeTimeProp,snooze_time);
    Z(VCRepeatCountProp,repeat_count);
    Z(VCAudioContentProp,audio_content);
#undef Z
    return aalarm;
    }


DLLEXPORT(VObject*) vcsAddMAlarm(
    VObject *vevent,
    char *run_time,
    char *snooze_time,
    char *repeat_count,
    char *email_address,
    char *note
    )
    {
    VObject *malarm= addProp(vevent,VCMAlarmProp);
#define Z(p,v) if (v) addPropValue(malarm,p,v);
    Z(VCRunTimeProp,run_time);
    Z(VCSnoozeTimeProp,snooze_time);
    Z(VCRepeatCountProp,repeat_count);
    Z(VCEmailAddressProp,email_address);
    Z(VCNoteProp,note);
#undef Z
    return malarm;
    }


DLLEXPORT(VObject*) vcsAddDAlarm(
    VObject *vevent,
    char *run_time,
    char *snooze_time,
    char *repeat_count,
    char *display_string
    )
    {
    VObject *dalarm= addProp(vevent,VCDAlarmProp);
#define Z(p,v) if (v) addPropValue(dalarm,p,v);
    Z(VCRunTimeProp,run_time);
    Z(VCSnoozeTimeProp,snooze_time);
    Z(VCRepeatCountProp,repeat_count);
    Z(VCDisplayStringProp,display_string);
#undef Z
    return dalarm;
    }


DLLEXPORT(VObject*) vcsAddPAlarm(
    VObject *vevent,
    char *run_time,
    char *snooze_time,
    char *repeat_count,
    char *procedure_name
    )
    {
    VObject *palarm= addProp(vevent,VCPAlarmProp);
#define Z(p,v) if (v) addPropValue(palarm,p,v);
    Z(VCRunTimeProp,run_time);
    Z(VCSnoozeTimeProp,snooze_time);
    Z(VCRepeatCountProp,repeat_count);
    Z(VCProcedureNameProp,procedure_name);
#undef Z
    return palarm;
    }

    
#ifdef _TEST

#if 0
This testcase would generate a file call "frankcal.vcf" with
the following content:

BEGIN:VCALENDAR
DCREATED:19960523T100522
GEO:37.24,-17.87
PRODID:-//Frank Dawson/Hand Crafted In North Carolina//NONSGML Made By Hand//EN
VERSION:0.3
BEGIN:VEVENT
DTSTART:19960523T120000
DTEND:19960523T130000
DESCRIPTION;QUOTED-PRINTABLE:VERSIT PDI PR Teleconference/Interview =0A=
With Tom Streeter and Frank Dawson - Discuss VERSIT PDI project and vCard and vCalendar=0A=
activities with European Press representatives.
SUMMARY:VERSIT PDI PR Teleconference/Interview
CATEGORIES:PHONE CALL
STATUS:CONFIRMED
TRANSP:19960523T100522-4000F100582713-009251
UID:http://www.ibm.com/raleigh/fdawson/~c:\or2\orgfiles\versit.or2
DALARM:19960523T114500;5;3;Your Telecon Starts At Noon!!!;
MALARM:19960522T120000;;;fdawson@raleigh.ibm.com;Remember 05/23 Noon Telecon!!!;
PALARM:19960523T115500;;;c:\or2\organize.exe c:\or2\orgfiles\versit.or2;
X-LDC-OR2-OLE:c:\temp\agenda.doc
END:VEVENT

BEGIN:VTODO
DUE:19960614T0173000
DESCRIPTION:Review VCalendar helper API.
END:VTODO

END:VCALENDAR

#endif

void testVcalAPIs() {
    FILE *fp;
    VObject *vcal = vcsCreateVCal(
    "19960523T100522",
    "37.24,-17.87",
    "-//Frank Dawson/Hand Crafted In North Carolina//NONSGML Made By Hand//EN",
    0,
    "0.3"
    );

    VObject *vevent = vcsAddEvent(
    vcal,
    "19960523T120000",
    "19960523T130000",
    "VERSIT PDI PR Teleconference/Interview \nWith Tom Streeter and Frank Dawson - Discuss VERSIT PDI project and vCard and vCalendar\nactivities with European Press representatives.",
    "VERSIT PDI PR Teleconference/Interview",
    "PHONE CALL",
    0,
    "CONFIRMED",
    "19960523T100522-4000F100582713-009251",
    "http://www.ibm.com/raleigh/fdawson/~c:\\or2\\orgfiles\\versit.or2",
    0
    );
    
    vcsAddDAlarm(vevent, "19960523T114500", "5", "3",
        "Your Telecon Starts At Noon!!!");
    vcsAddMAlarm(vevent, "19960522T120000", 0, 0, "fdawson@raleigh.ibm.com",
        "Remember 05/23 Noon Telecon!!!");
    vcsAddPAlarm(vevent, "19960523T115500", 0 ,0,
        "c:\\or2\\organize.exe c:\\or2\\orgfiles\\versit.or2");
    
    addPropValue(vevent, "X-LDC-OR2-OLE", "c:\\temp\\agenda.doc");

    vcsAddTodo(
    vcal,
    0,
    "19960614T0173000",
    0,
    "Review VCalendar helper API.",
    0,
    0,
    0,
    0,
    0,
    0
    );

    /* now do something to the resulting VObject */
    /* pretty print on stdout for fun */
    printVObject(vcal);
    /* open the output text file */

#define OUTFILE "frankcal.vcf"

    fp = fopen(OUTFILE, "w");
    if (fp) {
    /* write it in text form */
    writeVObject(fp,vcal);
    fclose(fp);
    }
    else {
    printf("open output file '%s' failed\n", OUTFILE);
    }
    }

void main() {
    testVcalAPIs();
    }

#endif


/* end of source file vcaltmp.c */