1 /* $XConsortium: attr.c /main/1 1996/04/21 19:21:41 drk $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994 International Business Machines Corp.
5 * (c) Copyright 1993, 1994 Novell, Inc.
6 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
13 #include <sys/types.h>
24 * calendar attributes defined by the library
25 * Note: index zero is not used
27 char *_CSA_calendar_attribute_names[] = {
29 "-//XAPIA/CSA/CALATTR//NONSGML Access List//EN",
30 "-//XAPIA/CSA/CALATTR//NONSGML Calendar Name//EN",
31 "-//XAPIA/CSA/CALATTR//NONSGML Calendar Owner//EN",
32 "-//XAPIA/CSA/CALATTR//NONSGML Calendar Size//EN",
33 "-//XAPIA/CSA/CALATTR//NONSGML Character Set//EN",
34 "-//XAPIA/CSA/CALATTR//NONSGML Country//EN",
35 "-//XAPIA/CSA/CALATTR//NONSGML Date Created//EN",
36 "-//XAPIA/CSA/CALATTR//NONSGML Language//EN",
37 "-//XAPIA/CSA/CALATTR//NONSGML Number Entries//EN",
38 "-//XAPIA/CSA/CALATTR//NONSGML Product Identifier//EN",
39 "-//XAPIA/CSA/CALATTR//NONSGML Time Zone//EN",
40 "-//XAPIA/CSA/CALATTR//NONSGML Version//EN",
41 "-//XAPIA/CSA/CALATTR//NONSGML Work Schedule//EN",
42 "-//CDE_XAPIA_PRIVATE/CSA/CALATTR//NONSGML Server Version//EN",
43 "-//CDE_XAPIA_PRIVATE/CSA/CALATTR//NONSGML Data Version//EN",
44 "-//CDE_XAPIA_PRIVATE/CSA/CALATTR//NONSGML Calendar Delimiter//EN"
48 * entry attributes defined by the library
49 * Note: index zero is not used
51 char *_CSA_entry_attribute_names[] = {
53 "-//XAPIA/CSA/ENTRYATTR//NONSGML Attendee List//EN",
54 "-//XAPIA/CSA/ENTRYATTR//NONSGML Audio Reminder//EN",
55 "-//XAPIA/CSA/ENTRYATTR//NONSGML Classification//EN",
56 "-//XAPIA/CSA/ENTRYATTR//NONSGML Date Completed//EN",
57 "-//XAPIA/CSA/ENTRYATTR//NONSGML Date Created//EN",
58 "-//XAPIA/CSA/ENTRYATTR//NONSGML Description//EN",
59 "-//XAPIA/CSA/ENTRYATTR//NONSGML Due Date//EN",
60 "-//XAPIA/CSA/ENTRYATTR//NONSGML End Date//EN",
61 "-//XAPIA/CSA/ENTRYATTR//NONSGML Exception Dates//EN",
62 "-//XAPIA/CSA/ENTRYATTR//NONSGML Exception Rule//EN",
63 "-//XAPIA/CSA/ENTRYATTR//NONSGML Flashing Reminder//EN",
64 "-//XAPIA/CSA/ENTRYATTR//NONSGML Last Update//EN",
65 "-//XAPIA/CSA/ENTRYATTR//NONSGML Mail Reminder//EN",
66 "-//XAPIA/CSA/ENTRYATTR//NONSGML Number Recurrences//EN",
67 "-//XAPIA/CSA/ENTRYATTR//NONSGML Organizer//EN",
68 "-//XAPIA/CSA/ENTRYATTR//NONSGML Popup Reminder//EN",
69 "-//XAPIA/CSA/ENTRYATTR//NONSGML Priority//EN",
70 "-//XAPIA/CSA/ENTRYATTR//NONSGML Recurrence Rule//EN",
71 "-//XAPIA/CSA/ENTRYATTR//NONSGML Recurring Dates//EN",
72 "-//XAPIA/CSA/ENTRYATTR//NONSGML Reference Identifier//EN",
73 "-//XAPIA/CSA/ENTRYATTR//NONSGML Sequence Number//EN",
74 "-//XAPIA/CSA/ENTRYATTR//NONSGML Sponsor//EN",
75 "-//XAPIA/CSA/ENTRYATTR//NONSGML Start Date//EN",
76 "-//XAPIA/CSA/ENTRYATTR//NONSGML Status//EN",
77 "-//XAPIA/CSA/ENTRYATTR//NONSGML Subtype//EN",
78 "-//XAPIA/CSA/ENTRYATTR//NONSGML Summary//EN",
79 "-//XAPIA/CSA/ENTRYATTR//NONSGML Time Transparency//EN",
80 "-//XAPIA/CSA/ENTRYATTR//NONSGML Type//EN",
81 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Show Time//EN",
82 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Type//EN",
83 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Times//EN",
84 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Interval//EN",
85 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Occurrence Number//EN",
86 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Sequence End Date//EN",
87 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN"
91 * Values for entry attribute CSA_ENTRY_ATTR_SUBTYPE
93 char *_CSA_entry_subtype_values[] = {
94 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Appointment//EN",
95 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Class//EN",
96 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Holiday//EN",
97 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Meeting//EN",
98 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Miscellaneous//EN",
99 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Phone Call//EN",
100 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Sick Day//EN",
101 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Special Occasion//EN",
102 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Travel//EN",
103 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Vacation//EN",
106 /* list of calendar attributes and value type */
107 _DtCmAttrInfo _CSA_cal_attr_info[] =
109 /* first element is not used */
110 { 0, -1, 0, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
111 { CSA_CAL_ATTR_ACCESS_LIST_I, CSA_VALUE_ACCESS_LIST, 1,
112 _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
113 { CSA_CAL_ATTR_CALENDAR_NAME_I, CSA_VALUE_STRING, 1,
114 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
115 { CSA_CAL_ATTR_CALENDAR_OWNER_I, CSA_VALUE_CALENDAR_USER, 1,
116 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
117 { CSA_CAL_ATTR_CALENDAR_SIZE_I, CSA_VALUE_UINT32, 4,
118 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
119 { CSA_CAL_ATTR_CHARACTER_SET_I, CSA_VALUE_STRING, 4,
120 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
121 { CSA_CAL_ATTR_COUNTRY_I, CSA_VALUE_STRING, 0,
122 _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
123 { CSA_CAL_ATTR_DATE_CREATED_I, CSA_VALUE_DATE_TIME, 4,
124 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
125 { CSA_CAL_ATTR_LANGUAGE_I, CSA_VALUE_STRING, 0,
126 _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
127 { CSA_CAL_ATTR_NUMBER_ENTRIES_I, CSA_VALUE_UINT32, 1,
128 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
129 { CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I, CSA_VALUE_STRING, 1,
130 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
131 { CSA_CAL_ATTR_TIME_ZONE_I, CSA_VALUE_STRING, 4,
132 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
133 { CSA_CAL_ATTR_VERSION_I, CSA_VALUE_STRING, 1,
134 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
135 { CSA_CAL_ATTR_WORK_SCHEDULE_I, CSA_VALUE_OPAQUE_DATA, 0,
136 _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
137 { CSA_X_DT_CAL_ATTR_SERVER_VERSION_I, CSA_VALUE_UINT32, 1,
138 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
139 { CSA_X_DT_CAL_ATTR_DATA_VERSION_I, CSA_VALUE_UINT32, 1,
140 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
141 { CSA_X_DT_CAL_ATTR_CAL_DELIMITER_I, CSA_VALUE_STRING, -1,
142 _DtCm_old_attr_unknown, B_TRUE, B_TRUE }
145 /* list of entry attributes and value type */
146 _DtCmAttrInfo _CSA_entry_attr_info[] =
148 /* first element is not used */
149 { 0, -1, 0, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
150 { CSA_ENTRY_ATTR_ATTENDEE_LIST_I, CSA_VALUE_ATTENDEE_LIST,
151 0, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
152 { CSA_ENTRY_ATTR_AUDIO_REMINDER_I, CSA_VALUE_REMINDER,
153 1, _DtCm_old_attr_beep_reminder, B_FALSE, B_FALSE },
154 { CSA_ENTRY_ATTR_CLASSIFICATION_I, CSA_VALUE_UINT32,
155 2, _DtCm_old_attr_privacy, B_FALSE, B_FALSE },
156 { CSA_ENTRY_ATTR_DATE_COMPLETED_I, CSA_VALUE_DATE_TIME,
157 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
158 { CSA_ENTRY_ATTR_DATE_CREATED_I, CSA_VALUE_DATE_TIME,
159 4, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
160 { CSA_ENTRY_ATTR_DESCRIPTION_I, CSA_VALUE_STRING,
161 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
162 { CSA_ENTRY_ATTR_DUE_DATE_I, CSA_VALUE_DATE_TIME,
163 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
164 { CSA_ENTRY_ATTR_END_DATE_I, CSA_VALUE_DATE_TIME,
165 1, _DtCm_old_attr_duration, B_FALSE, B_FALSE },
166 { CSA_ENTRY_ATTR_EXCEPTION_DATES_I, CSA_VALUE_DATE_TIME_LIST,
167 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
168 { CSA_ENTRY_ATTR_EXCEPTION_RULE_I, CSA_VALUE_STRING,
169 0, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
170 { CSA_ENTRY_ATTR_FLASHING_REMINDER_I, CSA_VALUE_REMINDER,
171 1, _DtCm_old_attr_flash_reminder, B_FALSE, B_FALSE },
172 { CSA_ENTRY_ATTR_LAST_UPDATE_I, CSA_VALUE_DATE_TIME,
173 4, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
174 { CSA_ENTRY_ATTR_MAIL_REMINDER_I, CSA_VALUE_REMINDER,
175 1, _DtCm_old_attr_mail_reminder, B_FALSE, B_FALSE },
176 { CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I, CSA_VALUE_UINT32,
177 4, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
178 { CSA_ENTRY_ATTR_ORGANIZER_I, CSA_VALUE_CALENDAR_USER,
179 1, _DtCm_old_attr_author, B_TRUE, B_TRUE },
180 { CSA_ENTRY_ATTR_POPUP_REMINDER_I, CSA_VALUE_REMINDER,
181 1, _DtCm_old_attr_popup_reminder, B_FALSE, B_FALSE },
182 { CSA_ENTRY_ATTR_PRIORITY_I, CSA_VALUE_UINT32,
183 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
184 { CSA_ENTRY_ATTR_RECURRENCE_RULE_I, CSA_VALUE_STRING,
185 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
186 { CSA_ENTRY_ATTR_RECURRING_DATES_I, CSA_VALUE_DATE_TIME_LIST,
187 0, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
188 { CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I, CSA_VALUE_OPAQUE_DATA,
189 1, _DtCm_old_attr_id, B_TRUE, B_TRUE },
190 { CSA_ENTRY_ATTR_SEQUENCE_NUMBER_I, CSA_VALUE_UINT32,
191 0, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
192 { CSA_ENTRY_ATTR_SPONSOR_I, CSA_VALUE_CALENDAR_USER,
193 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
194 { CSA_ENTRY_ATTR_START_DATE_I, CSA_VALUE_DATE_TIME,
195 1, _DtCm_old_attr_time, B_FALSE, B_FALSE },
196 { CSA_ENTRY_ATTR_STATUS_I, CSA_VALUE_UINT32,
197 2, _DtCm_old_attr_status, B_FALSE, B_FALSE },
198 { CSA_ENTRY_ATTR_SUBTYPE_I, CSA_VALUE_STRING,
199 1, _DtCm_old_attr_type2, B_FALSE, B_FALSE },
200 { CSA_ENTRY_ATTR_SUMMARY_I, CSA_VALUE_STRING,
201 1, _DtCm_old_attr_what, B_FALSE, B_FALSE },
202 { CSA_ENTRY_ATTR_TIME_TRANSPARENCY_I, CSA_VALUE_SINT32,
203 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
204 { CSA_ENTRY_ATTR_TYPE_I, CSA_VALUE_UINT32,
205 1, _DtCm_old_attr_type, B_FALSE, B_FALSE },
206 { CSA_X_DT_ENTRY_ATTR_SHOWTIME_I, CSA_VALUE_SINT32,
207 2, _DtCm_old_attr_showtime, B_FALSE, B_FALSE },
208 { CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I, CSA_VALUE_SINT32,
209 1, _DtCm_old_attr_repeat_type, B_FALSE, B_TRUE },
210 { CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I, CSA_VALUE_UINT32,
211 1, _DtCm_old_attr_repeat_times, B_FALSE, B_TRUE },
212 { CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I, CSA_VALUE_UINT32,
213 3, _DtCm_old_attr_repeat_nth_interval, B_FALSE, B_TRUE },
214 { CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I, CSA_VALUE_SINT32,
215 3, _DtCm_old_attr_repeat_nth_weeknum, B_FALSE, B_TRUE },
216 { CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I, CSA_VALUE_DATE_TIME,
217 3, _DtCm_old_attr_end_date, B_FALSE, B_TRUE },
218 { CSA_X_DT_ENTRY_ATTR_ENTRY_DELIMITER_I, CSA_VALUE_STRING,
219 -1, _DtCm_old_attr_unknown, B_TRUE, B_TRUE }
222 /*****************************************************************************
223 * forward declaration of static functions used within the file
224 *****************************************************************************/
225 static CSA_return_code check_predefined_attrs(
228 cms_attribute *attrs,
229 boolean_t checkreadonly,
232 _DtCmAttrInfo *our_attrs);
234 static CSA_return_code convert_cms_user_to_csa_user(char *from,
235 CSA_calendar_user **to);
237 static CSA_return_code hash_entry_attrs(uint num_attrs, CSA_attribute *csaattrs,
238 cms_attribute *cmsattrs, uint *hnum, cms_attribute **hattrs, uint *num);
240 static CSA_return_code hash_cal_attrs(uint num_attrs, CSA_attribute *csaattrs,
241 cms_attribute *cmsattrs, uint *hnum, cms_attribute **hattrs, uint *num);
243 static CSA_return_code _DtCm_check_hashed_entry_attributes(
246 cms_attribute *attrs,
249 static CSA_return_code _DtCm_check_hashed_cal_attributes(
252 cms_attribute *attrs,
255 boolean_t checkreadonly,
259 static CSA_return_code _CheckNameAtHost(char *owner, char *value);
261 static CSA_return_code _CheckCalendarOwner(char *owner, int type, char *name);
263 static CSA_return_code _CheckCalendarName(char *owner, char *cname,
264 cms_attribute_value *val);
266 /*****************************************************************************
267 * extern functions used in the library
268 *****************************************************************************/
271 * For each calendar attribute, if it is a predefined attribute,
272 * check that the data type is correct.
273 * If checkreadonly is B_TRUE, also check that it's not readonly.
275 extern CSA_return_code
276 _DtCm_check_cal_csa_attributes(
279 CSA_attribute *attrs,
281 boolean_t checkreadonly,
283 boolean_t checkattrnum)
285 CSA_return_code stat;
287 cms_attribute *hattrs;
290 if ((stat = hash_cal_attrs(num_attrs, attrs, NULL, &hnum, &hattrs,
291 &realnum)) != CSA_SUCCESS)
294 if (checkattrnum == B_TRUE && realnum == 0)
295 return (CSA_E_INVALID_PARAMETER);
297 stat = _DtCm_check_hashed_cal_attributes(fvers, hnum, hattrs,
298 NULL, cname, checkreadonly, firsttime, B_TRUE);
305 extern CSA_return_code
306 _DtCm_check_cal_cms_attributes(
309 cms_attribute *attrs,
312 boolean_t checkreadonly,
314 boolean_t checkattrnum)
316 CSA_return_code stat;
318 cms_attribute *hattrs;
321 if ((stat = hash_cal_attrs(num_attrs, NULL, attrs, &hnum, &hattrs,
322 &realnum)) != CSA_SUCCESS)
325 if (checkattrnum == B_TRUE && realnum == 0)
326 return (CSA_E_INVALID_PARAMETER);
328 stat = _DtCm_check_hashed_cal_attributes(fvers, hnum, hattrs,
329 owner, cname, checkreadonly, firsttime, B_FALSE);
336 extern CSA_return_code
337 _DtCm_check_entry_attributes(
340 CSA_attribute *attrs,
342 boolean_t checkattrnum)
344 CSA_return_code stat;
346 cms_attribute *hattrs;
349 if ((stat = hash_entry_attrs(num_attrs, attrs, NULL, &hnum, &hattrs,
350 &realnum)) != CSA_SUCCESS)
353 if (checkattrnum == B_TRUE && realnum == 0)
354 return (CSA_E_INVALID_PARAMETER);
356 stat = _DtCm_check_hashed_entry_attributes(fvers, hnum, hattrs,
364 extern CSA_return_code
365 _DtCm_check_entry_cms_attributes(
368 cms_attribute *attrs,
370 boolean_t checkattrnum)
372 CSA_return_code stat;
374 cms_attribute *hattrs;
377 if ((stat = hash_entry_attrs(num_attrs, NULL, attrs, &hnum, &hattrs,
378 &realnum)) != CSA_SUCCESS)
381 if (checkattrnum == B_TRUE && realnum == 0)
382 return (CSA_E_INVALID_PARAMETER);
384 stat = _DtCm_check_hashed_entry_attributes(fvers, hnum, hattrs,
394 * attributes with a name but NULL value is allowed
395 * attributes with null names are ignored
396 * validity of attributes should be checked before calling this routine
398 * Note: the first entry is not used
400 extern CSA_return_code
401 _DtCm_copy_cms_attributes(
403 cms_attribute *srcattrs,
405 cms_attribute **dstattrs)
408 CSA_return_code stat = CSA_SUCCESS;
409 cms_attribute *attrs;
411 if (dstsize == NULL || dstattrs == NULL)
412 return (CSA_E_INVALID_PARAMETER);
418 return (CSA_SUCCESS);
420 if ((attrs = calloc(1, sizeof(cms_attribute) * (srcsize + 1))) == NULL)
421 return (CSA_E_INSUFFICIENT_MEMORY);
423 /* firstr element is not used */
424 for (i = 1, j = 1; i <= srcsize; i++) {
425 if (srcattrs[i].name.name != NULL) {
426 if ((stat = _DtCm_copy_cms_attribute(&attrs[j],
427 &srcattrs[i], B_TRUE)) != CSA_SUCCESS)
434 if (stat != CSA_SUCCESS && j > 1) {
435 _DtCm_free_cms_attributes(j, attrs);
446 * Frees the name and value field of the array, but not
448 * note: element 0 is not used
451 _DtCm_free_cms_attributes(uint size, cms_attribute *attrs)
455 for (i = 0; i < size; i++) {
456 if (attrs[i].name.name) {
457 free(attrs[i].name.name);
458 attrs[i].name.name = NULL;
460 if (attrs[i].value) {
461 _DtCm_free_cms_attribute_value(attrs[i].value);
462 attrs[i].value = NULL;
469 * Frees the name and value field of the array, but not
473 _DtCm_free_attributes(uint size, CSA_attribute * attrs)
477 for (i = 0; i < size; i++) {
480 attrs[i].name = NULL;
482 if (attrs[i].value) {
483 _DtCm_free_attribute_value(attrs[i].value);
484 attrs[i].value = NULL;
491 * Free the value part of the cms_attribute structure.
492 * note: element 0 is not used
495 _DtCm_free_cms_attribute_values(uint size, cms_attribute *attrs)
499 for (i = 1; i <= size; i++) {
500 if (attrs[i].value) {
501 _DtCm_free_cms_attribute_value(attrs[i].value);
502 attrs[i].value = NULL;
508 * Free the value part of the the attribute structure.
511 _DtCm_free_attribute_values(uint size, CSA_attribute * attrs)
515 for (i = 0; i < size; i++) {
516 if (attrs[i].value) {
517 _DtCm_free_attribute_value(attrs[i].value);
518 attrs[i].value = NULL;
524 _DtCm_old_reminder_name_to_name(char *oldname)
526 if (strcmp(oldname, _DtCM_OLD_ATTR_BEEP_REMINDER) == 0)
527 return (CSA_ENTRY_ATTR_AUDIO_REMINDER);
528 else if (strcmp(oldname, _DtCM_OLD_ATTR_FLASH_REMINDER) == 0)
529 return (CSA_ENTRY_ATTR_FLASHING_REMINDER);
530 else if (strcmp(oldname, _DtCM_OLD_ATTR_MAIL_REMINDER) == 0)
531 return (CSA_ENTRY_ATTR_MAIL_REMINDER);
532 else if (strcmp(oldname, _DtCM_OLD_ATTR_POPUP_REMINDER) == 0)
533 return (CSA_ENTRY_ATTR_POPUP_REMINDER);
539 _DtCm_old_reminder_name_to_index(char *oldname)
543 name = _DtCm_old_reminder_name_to_name(oldname);
545 return (_DtCm_get_index_from_table(_DtCm_entry_name_tbl, name));
549 * Given an attribute name, return the corresponding
550 * attribute number that's supported by old backends (v4 and before).
552 extern CSA_return_code
553 _DtCm_get_old_attr_by_name(char *name, _DtCm_old_attrs *attr)
557 index = _DtCm_get_index_from_table(_DtCm_entry_name_tbl, name);
558 if (index > 0 && index <= _DtCM_DEFINED_ENTRY_ATTR_SIZE) {
560 if (_CSA_entry_attr_info[index].oldattr
561 != _DtCm_old_attr_unknown) {
562 *attr = _CSA_entry_attr_info[index].oldattr;
563 return (CSA_SUCCESS);
565 return (CSA_E_UNSUPPORTED_ATTRIBUTE);
567 return (CSA_E_INVALID_ATTRIBUTE);
571 * Given an attribute index, return the corresponding
572 * attribute number that's supported by old backends (v4 and before).
574 extern CSA_return_code
575 _DtCm_get_old_attr_by_index(int index, _DtCm_old_attrs *attr)
577 if (index <= _DtCM_DEFINED_ENTRY_ATTR_SIZE) {
578 if (_CSA_entry_attr_info[index].oldattr
579 != _DtCm_old_attr_unknown) {
580 *attr = _CSA_entry_attr_info[index].oldattr;
581 return (CSA_SUCCESS);
583 return (CSA_E_UNSUPPORTED_ATTRIBUTE);
585 return (CSA_E_INVALID_ATTRIBUTE);
590 * the attribute structure should contain valid value
591 * a NULL attribute value is valid
593 extern CSA_return_code
594 _DtCm_copy_cms_attribute(
599 CSA_return_code stat = CSA_SUCCESS;
603 return (CSA_E_INVALID_PARAMETER);
605 /* copy the attribute name */
607 if ((name = strdup(from->name.name)) == NULL)
608 return(CSA_E_INSUFFICIENT_MEMORY);
611 if ((stat = _DtCm_copy_cms_attr_val(from->value, &to->value))
614 to->name.name = name;
615 to->name.num = from->name.num;
623 extern CSA_return_code
624 _DtCm_copy_cms_attr_val(cms_attribute_value *from, cms_attribute_value **to)
626 CSA_return_code stat = CSA_SUCCESS;
627 cms_attribute_value *val;
630 return (CSA_E_INVALID_PARAMETER);
632 /* copy the attribute value */
636 if ((val = (cms_attribute_value *)calloc(1,
637 sizeof(cms_attribute_value))) == NULL)
638 return (CSA_E_INSUFFICIENT_MEMORY);
640 switch (from->type) {
641 case CSA_VALUE_BOOLEAN:
642 case CSA_VALUE_ENUMERATED:
643 case CSA_VALUE_FLAGS:
644 case CSA_VALUE_UINT32:
645 case CSA_VALUE_SINT32:
646 val->item.uint32_value = from->item.uint32_value;
649 case CSA_VALUE_STRING:
650 case CSA_VALUE_DATE_TIME:
651 case CSA_VALUE_DATE_TIME_RANGE:
652 case CSA_VALUE_TIME_DURATION:
653 case CSA_VALUE_CALENDAR_USER:
654 if (from->item.string_value)
655 val->item.string_value =
656 strdup(from->item.string_value);
658 val->item.string_value = calloc(1, 1);
659 if (val->item.string_value == NULL)
660 stat = CSA_E_INSUFFICIENT_MEMORY;
663 case CSA_VALUE_REMINDER:
664 if (from->item.reminder_value == NULL)
665 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
667 stat = _DtCm_copy_reminder(
668 from->item.reminder_value,
669 &val->item.reminder_value);
671 case CSA_VALUE_ATTENDEE_LIST:
672 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
674 case CSA_VALUE_ACCESS_LIST:
675 if (from->item.access_list_value &&
676 (val->item.access_list_value =
677 _DtCm_copy_cms_access_list(
678 from->item.access_list_value)) == NULL) {
680 stat = CSA_E_INSUFFICIENT_MEMORY;
683 case CSA_VALUE_DATE_TIME_LIST:
684 if (from->item.date_time_list_value &&
685 (val->item.date_time_list_value =
686 _DtCm_copy_date_time_list(
687 from->item.date_time_list_value)) == NULL) {
689 stat = CSA_E_INSUFFICIENT_MEMORY;
692 case CSA_VALUE_OPAQUE_DATA:
693 if (from->item.opaque_data_value) {
694 stat = _DtCm_copy_opaque_data(
695 from->item.opaque_data_value,
696 &val->item.opaque_data_value);
700 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
704 if (stat != CSA_SUCCESS)
707 val->type = from->type;
710 if (stat == CSA_SUCCESS) {
718 * copy the attribute name, and convert the attribute value
720 extern CSA_return_code
721 _DtCm_cms2csa_attribute(cms_attribute from, CSA_attribute *to)
723 CSA_return_code stat;
725 CSA_attribute_value *val;
727 if ((name = strdup(from.name.name)) == NULL)
728 return (CSA_E_INSUFFICIENT_MEMORY);
730 if ((stat = _DtCm_cms2csa_attrval(from.value, &val)) == CSA_SUCCESS) {
739 extern CSA_return_code
740 _DtCm_cms2csa_attrval(cms_attribute_value *from, CSA_attribute_value **to)
742 CSA_return_code stat = CSA_SUCCESS;
743 CSA_attribute_value *val;
746 return (CSA_E_INVALID_PARAMETER);
748 /* copy the attribute value */
752 if ((val = (CSA_attribute_value *)calloc(1,
753 sizeof(CSA_attribute_value))) == NULL)
754 return (CSA_E_INSUFFICIENT_MEMORY);
756 switch (from->type) {
757 case CSA_VALUE_BOOLEAN:
758 case CSA_VALUE_ENUMERATED:
759 case CSA_VALUE_FLAGS:
760 case CSA_VALUE_UINT32:
761 case CSA_VALUE_SINT32:
762 val->item.uint32_value = from->item.uint32_value;
765 case CSA_VALUE_STRING:
766 case CSA_VALUE_DATE_TIME:
767 case CSA_VALUE_DATE_TIME_RANGE:
768 case CSA_VALUE_TIME_DURATION:
769 if (from->item.string_value)
770 val->item.string_value =
771 strdup(from->item.string_value);
773 val->item.string_value = calloc(1, 1);
774 if (val->item.string_value == NULL)
775 stat = CSA_E_INSUFFICIENT_MEMORY;
778 case CSA_VALUE_REMINDER:
779 if (from->item.reminder_value == NULL)
780 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
782 stat = _DtCm_copy_reminder(
783 from->item.reminder_value,
784 &val->item.reminder_value);
786 case CSA_VALUE_CALENDAR_USER:
787 if (from->item.calendar_user_value == NULL)
788 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
790 stat = convert_cms_user_to_csa_user(
791 from->item.calendar_user_value,
792 &val->item.calendar_user_value);
794 case CSA_VALUE_ACCESS_LIST:
795 stat = _DtCm_cms2csa_access_list(
796 from->item.access_list_value,
797 &val->item.access_list_value);
799 case CSA_VALUE_ATTENDEE_LIST:
800 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
802 case CSA_VALUE_DATE_TIME_LIST:
803 if (from->item.date_time_list_value &&
804 (val->item.date_time_list_value =
805 _DtCm_copy_date_time_list(
806 from->item.date_time_list_value)) == NULL) {
807 stat = CSA_E_INSUFFICIENT_MEMORY;
810 case CSA_VALUE_OPAQUE_DATA:
811 if (from->item.opaque_data_value) {
812 stat = _DtCm_copy_opaque_data(
813 from->item.opaque_data_value,
814 &val->item.opaque_data_value);
816 val->item.opaque_data_value = NULL;
819 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
823 if (stat != CSA_SUCCESS)
826 val->type = from->type;
829 if (stat == CSA_SUCCESS) {
837 _DtCm_free_cms_attribute_value(cms_attribute_value *val)
843 case CSA_VALUE_STRING:
844 case CSA_VALUE_DATE_TIME:
845 case CSA_VALUE_DATE_TIME_RANGE:
846 case CSA_VALUE_TIME_DURATION:
847 case CSA_VALUE_CALENDAR_USER:
848 if (val->item.string_value)
849 free(val->item.string_value);
852 case CSA_VALUE_REMINDER:
853 if (val->item.reminder_value)
854 _DtCm_free_reminder(val->item.reminder_value);
856 case CSA_VALUE_ACCESS_LIST:
857 if (val->item.access_list_value)
858 _DtCm_free_cms_access_entry(val->item.access_list_value);
860 case CSA_VALUE_DATE_TIME_LIST:
861 if (val->item.date_time_list_value)
862 _DtCm_free_date_time_list(
863 val->item.date_time_list_value);
865 case CSA_VALUE_OPAQUE_DATA:
866 if (val->item.opaque_data_value) {
867 _DtCm_free_opaque_data(val->item.opaque_data_value);
875 _DtCm_free_attribute_value(CSA_attribute_value *val)
881 case CSA_VALUE_STRING:
882 case CSA_VALUE_DATE_TIME:
883 case CSA_VALUE_DATE_TIME_RANGE:
884 case CSA_VALUE_TIME_DURATION:
885 if (val->item.string_value)
886 free(val->item.string_value);
889 case CSA_VALUE_REMINDER:
890 if (val->item.reminder_value)
891 _DtCm_free_reminder(val->item.reminder_value);
893 case CSA_VALUE_ACCESS_LIST:
894 if (val->item.access_list_value)
895 _DtCm_free_csa_access_list(val->item.access_list_value);
897 case CSA_VALUE_CALENDAR_USER:
898 if (val->item.calendar_user_value) {
899 if (val->item.calendar_user_value->user_name)
900 free(val->item.calendar_user_value->user_name);
901 if (val->item.calendar_user_value->calendar_address)
902 free(val->item.calendar_user_value->user_name);
903 free(val->item.calendar_user_value);
906 case CSA_VALUE_DATE_TIME_LIST:
907 if (val->item.date_time_list_value)
908 _DtCm_free_date_time_list(
909 val->item.date_time_list_value);
911 case CSA_VALUE_OPAQUE_DATA:
912 if (val->item.opaque_data_value) {
913 _DtCm_free_opaque_data(val->item.opaque_data_value);
920 extern CSA_return_code
921 _DtCm_set_uint32_attrval(uint numval, cms_attribute_value **attrval)
923 cms_attribute_value *val;
925 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
927 return (CSA_E_INSUFFICIENT_MEMORY);
930 val->type = CSA_VALUE_UINT32;
931 val->item.uint32_value = numval;
935 return (CSA_SUCCESS);
938 extern CSA_return_code
939 _DtCm_set_sint32_attrval(int numval, cms_attribute_value **attrval)
941 cms_attribute_value *val;
943 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
945 return (CSA_E_INSUFFICIENT_MEMORY);
948 val->type = CSA_VALUE_SINT32;
949 val->item.sint32_value = numval;
953 return (CSA_SUCCESS);
956 extern CSA_return_code
957 _DtCm_set_string_attrval(
959 cms_attribute_value **attrval,
962 cms_attribute_value *val;
964 if (type != CSA_VALUE_STRING && type != CSA_VALUE_DATE_TIME &&
965 type != CSA_VALUE_DATE_TIME_RANGE &&
966 type != CSA_VALUE_TIME_DURATION && type != CSA_VALUE_CALENDAR_USER)
967 return (CSA_E_INVALID_PARAMETER);
969 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
971 return (CSA_E_INSUFFICIENT_MEMORY);
976 if (strval == NULL) {
977 val->item.string_value = NULL;
978 } else if ((val->item.string_value = strdup(strval)) == NULL) {
980 return (CSA_E_INSUFFICIENT_MEMORY);
985 return (CSA_SUCCESS);
988 extern CSA_return_code
989 _DtCm_set_user_attrval(
991 cms_attribute_value **attrval)
993 cms_attribute_value *val;
997 return (CSA_SUCCESS);
1000 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
1002 return (CSA_E_INSUFFICIENT_MEMORY);
1005 val->type = CSA_VALUE_CALENDAR_USER;
1007 if ((val->item.calendar_user_value = strdup(user)) == NULL) {
1009 return (CSA_E_INSUFFICIENT_MEMORY);
1014 return (CSA_SUCCESS);
1017 extern CSA_return_code
1018 _DtCm_set_reminder_attrval(CSA_reminder *remval, cms_attribute_value **attrval)
1020 cms_attribute_value *val;
1021 CSA_return_code stat;
1024 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1026 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
1028 return (CSA_E_INSUFFICIENT_MEMORY);
1031 val->type = CSA_VALUE_REMINDER;
1033 if ((stat = _DtCm_copy_reminder(remval, &val->item.reminder_value))
1041 return (CSA_SUCCESS);
1045 extern CSA_return_code
1046 _DtCm_set_csa_access_attrval(
1047 cms_access_entry *aval,
1048 CSA_attribute_value **attrval)
1050 CSA_attribute_value *val;
1051 CSA_return_code stat = CSA_SUCCESS;
1053 if ((val = (CSA_attribute_value *)malloc(sizeof(CSA_attribute_value)))
1055 return (CSA_E_INSUFFICIENT_MEMORY);
1058 val->type = CSA_VALUE_ACCESS_LIST;
1062 val->item.access_list_value = NULL;
1066 stat = _DtCm_cms2csa_access_list(aval,
1067 &val->item.access_list_value);
1071 if (stat == CSA_SUCCESS)
1079 extern CSA_return_code
1080 _DtCm_set_opaque_attrval(CSA_opaque_data *data, cms_attribute_value **attrval)
1082 CSA_return_code stat;
1083 cms_attribute_value *val;
1086 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1088 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
1090 return (CSA_E_INSUFFICIENT_MEMORY);
1093 val->type = CSA_VALUE_OPAQUE_DATA;
1095 if ((stat = _DtCm_copy_opaque_data(data, &val->item.opaque_data_value))
1102 return (CSA_SUCCESS);
1106 extern CSA_return_code
1107 _DtCm_set_csa_uint32_attrval(uint numval, CSA_attribute_value **attrval)
1109 CSA_attribute_value *val;
1111 if ((val = (CSA_attribute_value *)malloc(sizeof(CSA_attribute_value)))
1113 return (CSA_E_INSUFFICIENT_MEMORY);
1116 val->type = CSA_VALUE_UINT32;
1117 val->item.uint32_value = numval;
1121 return (CSA_SUCCESS);
1124 extern CSA_return_code
1125 _DtCm_set_csa_string_attrval(
1127 CSA_attribute_value **attrval,
1130 CSA_attribute_value *val;
1132 if (type != CSA_VALUE_STRING && type != CSA_VALUE_DATE_TIME &&
1133 type != CSA_VALUE_DATE_TIME_RANGE &&
1134 type != CSA_VALUE_TIME_DURATION && type != CSA_VALUE_CALENDAR_USER)
1135 return (CSA_E_INVALID_PARAMETER);
1137 if ((val = (CSA_attribute_value *)malloc(sizeof(CSA_attribute_value)))
1139 return (CSA_E_INSUFFICIENT_MEMORY);
1144 if (strval == NULL) {
1145 val->item.string_value = NULL;
1146 } else if ((val->item.string_value = strdup(strval)) == NULL) {
1148 return (CSA_E_INSUFFICIENT_MEMORY);
1153 return (CSA_SUCCESS);
1157 _DtCm_free_csa_access_list(CSA_access_list alist)
1159 CSA_access_list nptr;
1161 while (alist != NULL) {
1165 if (alist->user->user_name)
1166 free(alist->user->user_name);
1167 if (alist->user->calendar_address);
1168 free(alist->user->calendar_address);
1179 _DtCm_free_date_time_list(CSA_date_time_list list)
1181 CSA_date_time_entry *nptr;
1183 while (list != NULL) {
1186 if (list->date_time) {
1187 free(list->date_time);
1197 _DtCm_free_cms_access_entry(cms_access_entry *list)
1199 cms_access_entry *nptr;
1201 while (list != NULL) {
1214 extern cms_access_entry *
1215 _DtCm_copy_cms_access_list(cms_access_entry *alist)
1217 cms_access_entry *l, *head, *prev;
1218 boolean_t cleanup = B_FALSE;
1221 while (alist != NULL) {
1222 if ((l = (cms_access_entry *)calloc(1, sizeof(cms_access_entry)))
1228 if ((l->user = strdup(alist->user)) == NULL) {
1234 l->rights = alist->rights;
1243 alist = alist->next;
1246 if (cleanup == B_TRUE) {
1247 _DtCm_free_cms_access_entry(head);
1253 extern CSA_return_code
1254 _DtCm_cms2csa_access_list(
1255 cms_access_entry *cmslist,
1256 CSA_access_rights **csalist)
1258 CSA_return_code stat = CSA_SUCCESS;
1259 CSA_access_rights *to, *head, *prev;
1262 while (cmslist != NULL) {
1263 if ((to = (CSA_access_rights *)calloc(1,
1264 sizeof(CSA_access_rights))) == NULL) {
1265 stat = CSA_E_INSUFFICIENT_MEMORY;
1269 if ((to->user = (CSA_calendar_user *)calloc(1,
1270 sizeof(CSA_calendar_user))) == NULL) {
1272 stat = CSA_E_INSUFFICIENT_MEMORY;
1276 if ((to->user->user_name = strdup(cmslist->user)) == NULL) {
1279 stat = CSA_E_INSUFFICIENT_MEMORY;
1283 to->rights = cmslist->rights;
1293 cmslist = cmslist->next;
1296 if (stat != CSA_SUCCESS) {
1297 _DtCm_free_csa_access_list(head);
1305 extern CSA_return_code
1306 _DtCm_csa2cms_access_list(
1307 CSA_access_rights *csalist,
1308 cms_access_entry **cmslist)
1310 CSA_return_code stat = CSA_SUCCESS;
1311 cms_access_entry *to, *head, *prev;
1314 while (csalist != NULL) {
1315 if ((to = (cms_access_entry *)calloc(1,
1316 sizeof(cms_access_entry))) == NULL) {
1317 stat = CSA_E_INSUFFICIENT_MEMORY;
1321 if (csalist->user->user_name) {
1322 if ((to->user = strdup(csalist->user->user_name))
1324 stat = CSA_E_INSUFFICIENT_MEMORY;
1329 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
1334 to->rights = csalist->rights;
1344 csalist = csalist->next;
1347 if (stat != CSA_SUCCESS) {
1348 _DtCm_free_cms_access_entry(head);
1356 extern CSA_date_time_list
1357 _DtCm_copy_date_time_list(CSA_date_time_list dlist)
1359 CSA_date_time_entry *l, *head, *prev;
1360 boolean_t cleanup = B_FALSE;
1363 while (dlist != NULL) {
1364 if ((l = (CSA_date_time_entry *)calloc(1,
1365 sizeof(CSA_date_time_entry))) == NULL) {
1370 if ((l->date_time = strdup(dlist->date_time)) == NULL) {
1384 dlist = dlist->next;
1387 if (cleanup == B_TRUE) {
1388 _DtCm_free_date_time_list(head);
1394 extern CSA_return_code
1395 _DtCm_copy_reminder(CSA_reminder *from, CSA_reminder **to)
1397 CSA_reminder *newval;
1399 if ((newval = (CSA_reminder *)calloc(1, sizeof(CSA_reminder))) == NULL)
1400 return (CSA_E_INSUFFICIENT_MEMORY);
1402 if (from->lead_time) {
1403 if ((newval->lead_time = strdup(from->lead_time)) == NULL) {
1405 return (CSA_E_INSUFFICIENT_MEMORY);
1409 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1412 if (from->snooze_time)
1413 newval->snooze_time = strdup(from->snooze_time);
1415 newval->snooze_time = calloc(1, 1);
1417 if (newval->snooze_time == NULL) {
1418 _DtCm_free_reminder(newval);
1419 return (CSA_E_INSUFFICIENT_MEMORY);
1422 newval->repeat_count = from->repeat_count;
1424 if (from->reminder_data.size > 0) {
1425 newval->reminder_data.size = from->reminder_data.size;
1426 if ((newval->reminder_data.data = malloc(
1427 newval->reminder_data.size)) == NULL) {
1428 _DtCm_free_reminder(newval);
1429 return (CSA_E_INSUFFICIENT_MEMORY);
1431 memcpy(newval->reminder_data.data, from->reminder_data.data,
1432 from->reminder_data.size);
1436 return (CSA_SUCCESS);
1440 _DtCm_free_reminder(CSA_reminder *val)
1442 if (val == NULL) return;
1445 free(val->lead_time);
1447 if (val->snooze_time)
1448 free(val->snooze_time);
1450 if (val->reminder_data.size > 0)
1451 free(val->reminder_data.data);
1456 extern CSA_return_code
1457 _DtCm_copy_opaque_data(CSA_opaque_data *from, CSA_opaque_data **to)
1459 CSA_opaque_data *val;
1461 if ((val = (CSA_opaque_data *)calloc(1, sizeof(CSA_opaque_data)))
1463 return (CSA_E_INSUFFICIENT_MEMORY);
1466 if (from->size > 0) {
1467 val->size = from->size;
1468 if ((val->data = malloc(from->size)) == NULL) {
1470 return (CSA_E_INSUFFICIENT_MEMORY);
1472 memcpy(val->data, from->data, from->size);
1480 return (CSA_SUCCESS);
1484 _DtCm_free_opaque_data(CSA_opaque_data *val)
1486 if (val == NULL) return;
1494 _DtCm_get_attribute_types(uint size, int *types)
1498 for (i = 1; i <= size; i++) {
1499 types[i] = _CSA_entry_attr_info[i].type;
1503 /******************************************************************************
1504 * static functions used within the file
1505 ******************************************************************************/
1508 * The passed in attributes are hashed.
1509 * For each attribute, check
1510 * 1. type is valid and supported
1511 * 2. if it's a date time value type, check validity of date time.
1512 * 3. if it's a reminder value type, check validity of lead time.
1513 * 4. if it is a defined attribute, check that the data type is correct.
1514 * 5. if it is a defined attribute and checkreadonly is set, check
1515 * that it's not readonly.
1517 static CSA_return_code
1518 check_predefined_attrs(
1521 cms_attribute *attrs,
1522 boolean_t checkreadonly,
1523 _DtCmNameTable *tbl,
1525 _DtCmAttrInfo *our_attrs)
1531 for (i = 0; i < num_attrs; i++) {
1533 if (attrs[i].name.name == NULL)
1539 index = _DtCm_get_index_from_table(tbl,
1540 attrs[i].name.name);
1542 if (index > 0 && index <= num_defined) {
1544 /* check whether the attribute is supported
1547 if (our_attrs[index].fst_vers == 0 ||
1548 (fver < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
1549 fver < our_attrs[index].fst_vers))
1550 return (CSA_E_UNSUPPORTED_ATTRIBUTE);
1551 else if (our_attrs[index].fst_vers == -1)
1552 return (CSA_E_INVALID_ATTRIBUTE);
1554 /* check whether the attribute is readonly */
1555 if (checkreadonly &&
1556 ((fver < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
1557 our_attrs[index].nex_ro) ||
1558 (fver >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
1559 our_attrs[index].ex_ro)))
1560 return (CSA_E_READONLY);
1562 /* check data type */
1563 if (attrs[i].value &&
1564 attrs[i].value->type != our_attrs[index].type)
1565 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1567 if (index == CSA_ENTRY_ATTR_CLASSIFICATION_I) {
1568 cl = attrs[i].value->item.uint32_value;
1569 if (cl < CSA_CLASS_PUBLIC ||
1570 cl > CSA_CLASS_CONFIDENTIAL)
1571 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1574 if (index == CSA_ENTRY_ATTR_TYPE_I) {
1575 cl = attrs[i].value->item.uint32_value;
1576 if (cl < CSA_TYPE_EVENT ||
1577 cl > CSA_X_DT_TYPE_OTHER)
1578 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1581 } else if (fver < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
1582 return (CSA_E_INVALID_ATTRIBUTE);
1585 /* check validity of value type */
1586 if (attrs[i].value) {
1587 if (attrs[i].value->type < CSA_VALUE_BOOLEAN ||
1588 attrs[i].value->type > CSA_VALUE_OPAQUE_DATA)
1589 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1591 /* cast the sint32_value element to the desired
1592 * type to be safe since the value part could
1593 * actually be a pointer to a CSA_attribute_value
1595 switch (attrs[i].value->type) {
1596 case CSA_VALUE_DATE_TIME:
1597 if (attrs[i].value->item.sint32_value == 0
1598 || _csa_iso8601_to_tick(
1599 (char *)attrs[i].value->item.sint32_value,
1601 return (CSA_E_INVALID_DATE_TIME);
1603 case CSA_VALUE_REMINDER:
1604 rptr = (CSA_reminder *)
1605 attrs[i].value->item.sint32_value;
1606 if (rptr == NULL || rptr->lead_time == NULL ||
1607 _csa_iso8601_to_duration(rptr->lead_time,
1609 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1611 case CSA_VALUE_ATTENDEE_LIST:
1612 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1617 return (CSA_SUCCESS);
1620 static CSA_return_code
1621 convert_cms_user_to_csa_user(char *from, CSA_calendar_user **to)
1623 CSA_calendar_user *newval;
1625 if ((newval = (CSA_calendar_user *)calloc(1,
1626 sizeof(CSA_calendar_user))) == NULL)
1627 return (CSA_E_INSUFFICIENT_MEMORY);
1630 if ((newval->user_name = strdup(from)) == NULL) {
1632 return (CSA_E_INSUFFICIENT_MEMORY);
1637 return (CSA_SUCCESS);
1640 static CSA_return_code
1643 CSA_attribute *csaattrs,
1644 cms_attribute *cmsattrs,
1646 cms_attribute **hattrs,
1649 CSA_return_code stat;
1650 int i, j, index, count = 0;
1651 cms_attribute *nattrs;
1653 cms_attribute_value *val;
1655 if ((nattrs = (cms_attribute *)calloc(1,
1656 sizeof(cms_attribute)*(num_attrs+_DtCM_DEFINED_ENTRY_ATTR_SIZE+1)))
1658 return (CSA_E_INSUFFICIENT_MEMORY);
1660 for (i = 0, j = _DtCM_DEFINED_ENTRY_ATTR_SIZE + 1; i < num_attrs; i++) {
1661 name = (csaattrs ? csaattrs[i].name : cmsattrs[i].name.name);
1667 ((cms_attribute_value *)csaattrs[i].value) :
1671 index = _DtCm_get_index_from_table(_DtCm_entry_name_tbl, name);
1674 if (cmsattrs) cmsattrs[i].name.num = index;
1676 nattrs[index].name.name = name;
1677 nattrs[index].value = val;
1679 nattrs[j].name.name = name;
1680 nattrs[j++].value = val;
1684 if (num) *num = count;
1687 return (CSA_SUCCESS);
1690 static CSA_return_code
1693 CSA_attribute *csaattrs,
1694 cms_attribute *cmsattrs,
1696 cms_attribute **hattrs,
1699 CSA_return_code stat;
1700 int i, j, index, count = 0;
1701 cms_attribute *nattrs;
1703 cms_attribute_value *val;
1705 if ((nattrs = (cms_attribute *)calloc(1,
1706 sizeof(cms_attribute)*(num_attrs+_DtCM_DEFINED_CAL_ATTR_SIZE+1)))
1708 return (CSA_E_INSUFFICIENT_MEMORY);
1710 for (i = 0, j = _DtCM_DEFINED_CAL_ATTR_SIZE + 1; i < num_attrs; i++) {
1711 name = (csaattrs ? csaattrs[i].name : cmsattrs[i].name.name);
1717 ((cms_attribute_value *)csaattrs[i].value) :
1721 index = _DtCm_get_index_from_table(_DtCm_cal_name_tbl, name);
1724 if (cmsattrs) cmsattrs[i].name.num = index;
1726 nattrs[index].name.name = name;
1727 nattrs[index].value = val;
1729 nattrs[j].name.name = name;
1730 nattrs[j++].value = val;
1734 if (num) *num = count;
1737 return (CSA_SUCCESS);
1740 static CSA_return_code
1741 _DtCm_check_hashed_cal_attributes(
1744 cms_attribute *attrs,
1747 boolean_t checkreadonly,
1748 boolean_t firsttime,
1751 CSA_return_code stat;
1752 CSA_attribute_value *csaval;
1753 cms_attribute_value *cmsval;
1754 char *nattr = NULL; /* calendar name */
1755 char *oattr = NULL; /* calendar owner */
1756 char *cattr = NULL; /* character set */
1757 char *tattr = NULL; /* time zone */
1760 if (attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name) {
1761 if (attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value == NULL
1762 || attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value->\
1763 item.calendar_user_value == NULL)
1764 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1767 csaval = (CSA_attribute_value *)attrs[\
1768 CSA_CAL_ATTR_CALENDAR_OWNER_I].value;
1769 stat = _CheckCalendarOwner(owner, csaval->type,
1770 (csaval && csaval->item.calendar_user_value?
1771 csaval->item.calendar_user_value->user_name:
1774 cmsval = attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
1776 stat = _CheckCalendarOwner(owner, cmsval->type,
1778 cmsval->item.calendar_user_value:NULL);
1781 if (stat != CSA_SUCCESS)
1784 oattr = attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name;
1785 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name = NULL;
1788 if (attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name) {
1789 if (attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value == NULL ||
1790 attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value->\
1791 item.string_value == NULL) {
1793 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
1795 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1798 if ((stat = _CheckCalendarName(owner, cname,
1799 attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value))
1802 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
1807 nattr = attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name;
1808 attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name = NULL;
1811 if (attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name) {
1812 cattr = attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name;
1813 attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name = NULL;
1816 if (attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name) {
1817 tattr = attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name;
1818 attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name = NULL;
1822 stat = check_predefined_attrs(fvers, num_attrs+1, attrs,
1823 checkreadonly, NULL, _DtCM_DEFINED_CAL_ATTR_SIZE,
1824 _CSA_cal_attr_info);
1827 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name = oattr;
1830 attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name = nattr;
1833 attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name = oattr;
1836 attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name = nattr;
1841 static CSA_return_code
1842 _DtCm_check_hashed_entry_attributes(
1845 cms_attribute *attrs,
1848 CSA_return_code stat;
1850 if ((stat = check_predefined_attrs(fvers, num_attrs+1, attrs,
1851 (utype == 0 ? B_FALSE : B_TRUE), NULL,
1852 _DtCM_DEFINED_ENTRY_ATTR_SIZE, _CSA_entry_attr_info))
1858 if (utype == CSA_CB_ENTRY_ADDED) {
1860 /* make sure the minimum set of attribute is specified */
1861 if (attrs[CSA_ENTRY_ATTR_START_DATE_I].value == NULL ||
1862 attrs[CSA_ENTRY_ATTR_TYPE_I].value == NULL)
1863 return (CSA_E_INVALID_PARAMETER);
1865 } else if (utype == CSA_CB_ENTRY_UPDATED) {
1867 /* type can only be set at insertion time */
1868 if (attrs[CSA_ENTRY_ATTR_TYPE_I].name.name)
1869 return (CSA_E_READONLY);
1872 return (CSA_SUCCESS);
1875 static CSA_return_code
1876 _CheckNameAtHost(char *owner, char *value)
1881 /* check name part first */
1882 if (owner == NULL) {
1883 /* get user name of user running the application */
1884 if ((owner = _DtCmGetUserName()) == NULL)
1885 return (CSA_E_FAILURE);
1888 if (optr = strchr(owner, '@')) *optr = NULL;
1889 if (ptr = strchr(value, '@')) *ptr = NULL;
1890 res = strcmp(value, owner);
1891 if (optr) *optr = '@';
1892 if (ptr) *ptr = '@';
1895 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1897 /* check host too if it's specified */
1899 return (CSA_SUCCESS);
1902 if (strcmp(ptr, (optr ? ++optr : _DtCmGetLocalHost())) == 0)
1903 return (CSA_SUCCESS);
1905 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1909 * check the data type and validity of calendar owner attribute
1911 static CSA_return_code
1912 _CheckCalendarOwner(char *owner, int type, char *user)
1914 if (type != CSA_VALUE_CALENDAR_USER || user == NULL)
1915 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1917 /* make sure user is the same as the one running the application */
1918 return (_CheckNameAtHost(owner, user));
1922 * check the data type and validity of calendar name attribute
1924 static CSA_return_code
1925 _CheckCalendarName(char *owner, char *cname, cms_attribute_value *val)
1927 CSA_return_code stat;
1933 if (val->type != CSA_VALUE_STRING)
1934 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1936 /* check that the attribute value is the same as the given
1939 if ((stat = _CheckNameAtHost(cname, val->item.string_value))
1943 /* now make sure if cal name is a user name, it's
1944 * the same as that of the calling user
1946 if (ptr = strchr(val->item.string_value, '@')) *ptr = NULL;
1947 isuser = _DtCmIsUserName(val->item.string_value);
1948 if (ptr) *ptr = '@';
1950 /* make sure it's the same as the user running the application */
1951 if (isuser == B_TRUE) {
1952 sprintf(user, "%s%s", val->item.string_value, (ptr ? ptr : ""));
1953 return (_CheckNameAtHost(owner, user));
1956 /* check the host part */
1958 return (CSA_SUCCESS);
1962 if (owner && (optr = strchr(owner, '@')))
1965 optr = _DtCmGetLocalHost();
1967 if (strcmp(ptr, optr) == 0)
1968 return (CSA_SUCCESS);
1970 return (CSA_E_INVALID_ATTRIBUTE_VALUE);