2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: attr.c /main/1 1996/04/21 19:21:41 drk $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Novell, Inc.
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
31 #include <EUSCompat.h>
35 #include <sys/types.h>
46 * calendar attributes defined by the library
47 * Note: index zero is not used
49 char *_CSA_calendar_attribute_names[] = {
51 "-//XAPIA/CSA/CALATTR//NONSGML Access List//EN",
52 "-//XAPIA/CSA/CALATTR//NONSGML Calendar Name//EN",
53 "-//XAPIA/CSA/CALATTR//NONSGML Calendar Owner//EN",
54 "-//XAPIA/CSA/CALATTR//NONSGML Calendar Size//EN",
55 "-//XAPIA/CSA/CALATTR//NONSGML Character Set//EN",
56 "-//XAPIA/CSA/CALATTR//NONSGML Country//EN",
57 "-//XAPIA/CSA/CALATTR//NONSGML Date Created//EN",
58 "-//XAPIA/CSA/CALATTR//NONSGML Language//EN",
59 "-//XAPIA/CSA/CALATTR//NONSGML Number Entries//EN",
60 "-//XAPIA/CSA/CALATTR//NONSGML Product Identifier//EN",
61 "-//XAPIA/CSA/CALATTR//NONSGML Time Zone//EN",
62 "-//XAPIA/CSA/CALATTR//NONSGML Version//EN",
63 "-//XAPIA/CSA/CALATTR//NONSGML Work Schedule//EN",
64 "-//CDE_XAPIA_PRIVATE/CSA/CALATTR//NONSGML Server Version//EN",
65 "-//CDE_XAPIA_PRIVATE/CSA/CALATTR//NONSGML Data Version//EN",
66 "-//CDE_XAPIA_PRIVATE/CSA/CALATTR//NONSGML Calendar Delimiter//EN"
70 * entry attributes defined by the library
71 * Note: index zero is not used
73 char *_CSA_entry_attribute_names[] = {
75 "-//XAPIA/CSA/ENTRYATTR//NONSGML Attendee List//EN",
76 "-//XAPIA/CSA/ENTRYATTR//NONSGML Audio Reminder//EN",
77 "-//XAPIA/CSA/ENTRYATTR//NONSGML Classification//EN",
78 "-//XAPIA/CSA/ENTRYATTR//NONSGML Date Completed//EN",
79 "-//XAPIA/CSA/ENTRYATTR//NONSGML Date Created//EN",
80 "-//XAPIA/CSA/ENTRYATTR//NONSGML Description//EN",
81 "-//XAPIA/CSA/ENTRYATTR//NONSGML Due Date//EN",
82 "-//XAPIA/CSA/ENTRYATTR//NONSGML End Date//EN",
83 "-//XAPIA/CSA/ENTRYATTR//NONSGML Exception Dates//EN",
84 "-//XAPIA/CSA/ENTRYATTR//NONSGML Exception Rule//EN",
85 "-//XAPIA/CSA/ENTRYATTR//NONSGML Flashing Reminder//EN",
86 "-//XAPIA/CSA/ENTRYATTR//NONSGML Last Update//EN",
87 "-//XAPIA/CSA/ENTRYATTR//NONSGML Mail Reminder//EN",
88 "-//XAPIA/CSA/ENTRYATTR//NONSGML Number Recurrences//EN",
89 "-//XAPIA/CSA/ENTRYATTR//NONSGML Organizer//EN",
90 "-//XAPIA/CSA/ENTRYATTR//NONSGML Popup Reminder//EN",
91 "-//XAPIA/CSA/ENTRYATTR//NONSGML Priority//EN",
92 "-//XAPIA/CSA/ENTRYATTR//NONSGML Recurrence Rule//EN",
93 "-//XAPIA/CSA/ENTRYATTR//NONSGML Recurring Dates//EN",
94 "-//XAPIA/CSA/ENTRYATTR//NONSGML Reference Identifier//EN",
95 "-//XAPIA/CSA/ENTRYATTR//NONSGML Sequence Number//EN",
96 "-//XAPIA/CSA/ENTRYATTR//NONSGML Sponsor//EN",
97 "-//XAPIA/CSA/ENTRYATTR//NONSGML Start Date//EN",
98 "-//XAPIA/CSA/ENTRYATTR//NONSGML Status//EN",
99 "-//XAPIA/CSA/ENTRYATTR//NONSGML Subtype//EN",
100 "-//XAPIA/CSA/ENTRYATTR//NONSGML Summary//EN",
101 "-//XAPIA/CSA/ENTRYATTR//NONSGML Time Transparency//EN",
102 "-//XAPIA/CSA/ENTRYATTR//NONSGML Type//EN",
103 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Show Time//EN",
104 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Type//EN",
105 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Times//EN",
106 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Interval//EN",
107 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Repeat Occurrence Number//EN",
108 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Sequence End Date//EN",
109 "-//CDE_XAPIA_PRIVATE/CSA/ENTRYATTR//NONSGML Entry Delimiter//EN"
113 * Values for entry attribute CSA_ENTRY_ATTR_SUBTYPE
115 char *_CSA_entry_subtype_values[] = {
116 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Appointment//EN",
117 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Class//EN",
118 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Holiday//EN",
119 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Meeting//EN",
120 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Miscellaneous//EN",
121 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Phone Call//EN",
122 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Sick Day//EN",
123 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Special Occasion//EN",
124 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Travel//EN",
125 "-//XAPIA/CSA/SUBTYPE//NONSGML Subtype Vacation//EN",
128 /* list of calendar attributes and value type */
129 _DtCmAttrInfo _CSA_cal_attr_info[] =
131 /* first element is not used */
132 { 0, -1, 0, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
133 { CSA_CAL_ATTR_ACCESS_LIST_I, CSA_VALUE_ACCESS_LIST, 1,
134 _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
135 { CSA_CAL_ATTR_CALENDAR_NAME_I, CSA_VALUE_STRING, 1,
136 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
137 { CSA_CAL_ATTR_CALENDAR_OWNER_I, CSA_VALUE_CALENDAR_USER, 1,
138 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
139 { CSA_CAL_ATTR_CALENDAR_SIZE_I, CSA_VALUE_UINT32, 4,
140 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
141 { CSA_CAL_ATTR_CHARACTER_SET_I, CSA_VALUE_STRING, 4,
142 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
143 { CSA_CAL_ATTR_COUNTRY_I, CSA_VALUE_STRING, 0,
144 _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
145 { CSA_CAL_ATTR_DATE_CREATED_I, CSA_VALUE_DATE_TIME, 4,
146 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
147 { CSA_CAL_ATTR_LANGUAGE_I, CSA_VALUE_STRING, 0,
148 _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
149 { CSA_CAL_ATTR_NUMBER_ENTRIES_I, CSA_VALUE_UINT32, 1,
150 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
151 { CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I, CSA_VALUE_STRING, 1,
152 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
153 { CSA_CAL_ATTR_TIME_ZONE_I, CSA_VALUE_STRING, 4,
154 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
155 { CSA_CAL_ATTR_VERSION_I, CSA_VALUE_STRING, 1,
156 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
157 { CSA_CAL_ATTR_WORK_SCHEDULE_I, CSA_VALUE_OPAQUE_DATA, 0,
158 _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
159 { CSA_X_DT_CAL_ATTR_SERVER_VERSION_I, CSA_VALUE_UINT32, 1,
160 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
161 { CSA_X_DT_CAL_ATTR_DATA_VERSION_I, CSA_VALUE_UINT32, 1,
162 _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
163 { CSA_X_DT_CAL_ATTR_CAL_DELIMITER_I, CSA_VALUE_STRING, -1,
164 _DtCm_old_attr_unknown, B_TRUE, B_TRUE }
167 /* list of entry attributes and value type */
168 _DtCmAttrInfo _CSA_entry_attr_info[] =
170 /* first element is not used */
171 { 0, -1, 0, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
172 { CSA_ENTRY_ATTR_ATTENDEE_LIST_I, CSA_VALUE_ATTENDEE_LIST,
173 0, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
174 { CSA_ENTRY_ATTR_AUDIO_REMINDER_I, CSA_VALUE_REMINDER,
175 1, _DtCm_old_attr_beep_reminder, B_FALSE, B_FALSE },
176 { CSA_ENTRY_ATTR_CLASSIFICATION_I, CSA_VALUE_UINT32,
177 2, _DtCm_old_attr_privacy, B_FALSE, B_FALSE },
178 { CSA_ENTRY_ATTR_DATE_COMPLETED_I, CSA_VALUE_DATE_TIME,
179 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
180 { CSA_ENTRY_ATTR_DATE_CREATED_I, CSA_VALUE_DATE_TIME,
181 4, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
182 { CSA_ENTRY_ATTR_DESCRIPTION_I, CSA_VALUE_STRING,
183 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
184 { CSA_ENTRY_ATTR_DUE_DATE_I, CSA_VALUE_DATE_TIME,
185 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
186 { CSA_ENTRY_ATTR_END_DATE_I, CSA_VALUE_DATE_TIME,
187 1, _DtCm_old_attr_duration, B_FALSE, B_FALSE },
188 { CSA_ENTRY_ATTR_EXCEPTION_DATES_I, CSA_VALUE_DATE_TIME_LIST,
189 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
190 { CSA_ENTRY_ATTR_EXCEPTION_RULE_I, CSA_VALUE_STRING,
191 0, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
192 { CSA_ENTRY_ATTR_FLASHING_REMINDER_I, CSA_VALUE_REMINDER,
193 1, _DtCm_old_attr_flash_reminder, B_FALSE, B_FALSE },
194 { CSA_ENTRY_ATTR_LAST_UPDATE_I, CSA_VALUE_DATE_TIME,
195 4, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
196 { CSA_ENTRY_ATTR_MAIL_REMINDER_I, CSA_VALUE_REMINDER,
197 1, _DtCm_old_attr_mail_reminder, B_FALSE, B_FALSE },
198 { CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I, CSA_VALUE_UINT32,
199 4, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
200 { CSA_ENTRY_ATTR_ORGANIZER_I, CSA_VALUE_CALENDAR_USER,
201 1, _DtCm_old_attr_author, B_TRUE, B_TRUE },
202 { CSA_ENTRY_ATTR_POPUP_REMINDER_I, CSA_VALUE_REMINDER,
203 1, _DtCm_old_attr_popup_reminder, B_FALSE, B_FALSE },
204 { CSA_ENTRY_ATTR_PRIORITY_I, CSA_VALUE_UINT32,
205 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
206 { CSA_ENTRY_ATTR_RECURRENCE_RULE_I, CSA_VALUE_STRING,
207 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
208 { CSA_ENTRY_ATTR_RECURRING_DATES_I, CSA_VALUE_DATE_TIME_LIST,
209 0, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
210 { CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I, CSA_VALUE_OPAQUE_DATA,
211 1, _DtCm_old_attr_id, B_TRUE, B_TRUE },
212 { CSA_ENTRY_ATTR_SEQUENCE_NUMBER_I, CSA_VALUE_UINT32,
213 0, _DtCm_old_attr_unknown, B_TRUE, B_TRUE },
214 { CSA_ENTRY_ATTR_SPONSOR_I, CSA_VALUE_CALENDAR_USER,
215 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
216 { CSA_ENTRY_ATTR_START_DATE_I, CSA_VALUE_DATE_TIME,
217 1, _DtCm_old_attr_time, B_FALSE, B_FALSE },
218 { CSA_ENTRY_ATTR_STATUS_I, CSA_VALUE_UINT32,
219 2, _DtCm_old_attr_status, B_FALSE, B_FALSE },
220 { CSA_ENTRY_ATTR_SUBTYPE_I, CSA_VALUE_STRING,
221 1, _DtCm_old_attr_type2, B_FALSE, B_FALSE },
222 { CSA_ENTRY_ATTR_SUMMARY_I, CSA_VALUE_STRING,
223 1, _DtCm_old_attr_what, B_FALSE, B_FALSE },
224 { CSA_ENTRY_ATTR_TIME_TRANSPARENCY_I, CSA_VALUE_SINT32,
225 4, _DtCm_old_attr_unknown, B_FALSE, B_FALSE },
226 { CSA_ENTRY_ATTR_TYPE_I, CSA_VALUE_UINT32,
227 1, _DtCm_old_attr_type, B_FALSE, B_FALSE },
228 { CSA_X_DT_ENTRY_ATTR_SHOWTIME_I, CSA_VALUE_SINT32,
229 2, _DtCm_old_attr_showtime, B_FALSE, B_FALSE },
230 { CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I, CSA_VALUE_SINT32,
231 1, _DtCm_old_attr_repeat_type, B_FALSE, B_TRUE },
232 { CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I, CSA_VALUE_UINT32,
233 1, _DtCm_old_attr_repeat_times, B_FALSE, B_TRUE },
234 { CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I, CSA_VALUE_UINT32,
235 3, _DtCm_old_attr_repeat_nth_interval, B_FALSE, B_TRUE },
236 { CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I, CSA_VALUE_SINT32,
237 3, _DtCm_old_attr_repeat_nth_weeknum, B_FALSE, B_TRUE },
238 { CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I, CSA_VALUE_DATE_TIME,
239 3, _DtCm_old_attr_end_date, B_FALSE, B_TRUE },
240 { CSA_X_DT_ENTRY_ATTR_ENTRY_DELIMITER_I, CSA_VALUE_STRING,
241 -1, _DtCm_old_attr_unknown, B_TRUE, B_TRUE }
244 /*****************************************************************************
245 * forward declaration of static functions used within the file
246 *****************************************************************************/
247 static CSA_return_code check_predefined_attrs(
250 cms_attribute *attrs,
251 boolean_t checkreadonly,
254 _DtCmAttrInfo *our_attrs);
256 static CSA_return_code convert_cms_user_to_csa_user(char *from,
257 CSA_calendar_user **to);
259 static CSA_return_code hash_entry_attrs(uint num_attrs, CSA_attribute *csaattrs,
260 cms_attribute *cmsattrs, uint *hnum, cms_attribute **hattrs, uint *num);
262 static CSA_return_code hash_cal_attrs(uint num_attrs, CSA_attribute *csaattrs,
263 cms_attribute *cmsattrs, uint *hnum, cms_attribute **hattrs, uint *num);
265 static CSA_return_code _DtCm_check_hashed_entry_attributes(
268 cms_attribute *attrs,
271 static CSA_return_code _DtCm_check_hashed_cal_attributes(
274 cms_attribute *attrs,
277 boolean_t checkreadonly,
281 static CSA_return_code _CheckNameAtHost(char *owner, char *value);
283 static CSA_return_code _CheckCalendarOwner(char *owner, int type, char *name);
285 static CSA_return_code _CheckCalendarName(char *owner, char *cname,
286 cms_attribute_value *val);
288 /*****************************************************************************
289 * extern functions used in the library
290 *****************************************************************************/
293 * For each calendar attribute, if it is a predefined attribute,
294 * check that the data type is correct.
295 * If checkreadonly is B_TRUE, also check that it's not readonly.
297 extern CSA_return_code
298 _DtCm_check_cal_csa_attributes(
301 CSA_attribute *attrs,
303 boolean_t checkreadonly,
305 boolean_t checkattrnum)
307 CSA_return_code stat;
309 cms_attribute *hattrs;
312 if ((stat = hash_cal_attrs(num_attrs, attrs, NULL, &hnum, &hattrs,
313 &realnum)) != CSA_SUCCESS)
316 if (checkattrnum == B_TRUE && realnum == 0) {
318 return (CSA_E_INVALID_PARAMETER);
321 stat = _DtCm_check_hashed_cal_attributes(fvers, hnum, hattrs,
322 NULL, cname, checkreadonly, firsttime, B_TRUE);
329 extern CSA_return_code
330 _DtCm_check_cal_cms_attributes(
333 cms_attribute *attrs,
336 boolean_t checkreadonly,
338 boolean_t checkattrnum)
340 CSA_return_code stat;
342 cms_attribute *hattrs;
345 if ((stat = hash_cal_attrs(num_attrs, NULL, attrs, &hnum, &hattrs,
346 &realnum)) != CSA_SUCCESS)
349 if (checkattrnum == B_TRUE && realnum == 0) {
351 return (CSA_E_INVALID_PARAMETER);
354 stat = _DtCm_check_hashed_cal_attributes(fvers, hnum, hattrs,
355 owner, cname, checkreadonly, firsttime, B_FALSE);
362 extern CSA_return_code
363 _DtCm_check_entry_attributes(
366 CSA_attribute *attrs,
368 boolean_t checkattrnum)
370 CSA_return_code stat;
372 cms_attribute *hattrs;
375 if ((stat = hash_entry_attrs(num_attrs, attrs, NULL, &hnum, &hattrs,
376 &realnum)) != CSA_SUCCESS)
379 if (checkattrnum == B_TRUE && realnum == 0) {
381 return (CSA_E_INVALID_PARAMETER);
384 stat = _DtCm_check_hashed_entry_attributes(fvers, hnum, hattrs,
392 extern CSA_return_code
393 _DtCm_check_entry_cms_attributes(
396 cms_attribute *attrs,
398 boolean_t checkattrnum)
400 CSA_return_code stat;
402 cms_attribute *hattrs;
405 if ((stat = hash_entry_attrs(num_attrs, NULL, attrs, &hnum, &hattrs,
406 &realnum)) != CSA_SUCCESS)
409 if (checkattrnum == B_TRUE && realnum == 0) {
411 return (CSA_E_INVALID_PARAMETER);
414 stat = _DtCm_check_hashed_entry_attributes(fvers, hnum, hattrs,
424 * attributes with a name but NULL value is allowed
425 * attributes with null names are ignored
426 * validity of attributes should be checked before calling this routine
428 * Note: the first entry is not used
430 extern CSA_return_code
431 _DtCm_copy_cms_attributes(
433 cms_attribute *srcattrs,
435 cms_attribute **dstattrs)
438 CSA_return_code stat = CSA_SUCCESS;
439 cms_attribute *attrs;
441 if (dstsize == NULL || dstattrs == NULL)
442 return (CSA_E_INVALID_PARAMETER);
448 return (CSA_SUCCESS);
450 if ((attrs = calloc(1, sizeof(cms_attribute) * (srcsize + 1))) == NULL)
451 return (CSA_E_INSUFFICIENT_MEMORY);
453 /* firstr element is not used */
454 for (i = 1, j = 1; i <= srcsize; i++) {
455 if (srcattrs[i].name.name != NULL) {
456 if ((stat = _DtCm_copy_cms_attribute(&attrs[j],
457 &srcattrs[i], B_TRUE)) != CSA_SUCCESS)
464 if (stat != CSA_SUCCESS && j > 1) {
465 _DtCm_free_cms_attributes(j, attrs);
476 * Frees the name and value field of the array, but not
478 * note: element 0 is not used
481 _DtCm_free_cms_attributes(uint size, cms_attribute *attrs)
485 for (i = 0; i < size; i++) {
486 if (attrs[i].name.name) {
487 free(attrs[i].name.name);
488 attrs[i].name.name = NULL;
490 if (attrs[i].value) {
491 _DtCm_free_cms_attribute_value(attrs[i].value);
492 attrs[i].value = NULL;
499 * Frees the name and value field of the array, but not
503 _DtCm_free_attributes(uint size, CSA_attribute * attrs)
507 for (i = 0; i < size; i++) {
510 attrs[i].name = NULL;
512 if (attrs[i].value) {
513 _DtCm_free_attribute_value(attrs[i].value);
514 attrs[i].value = NULL;
521 * Free the value part of the cms_attribute structure.
522 * note: element 0 is not used
525 _DtCm_free_cms_attribute_values(uint size, cms_attribute *attrs)
529 for (i = 1; i <= size; i++) {
530 if (attrs[i].value) {
531 _DtCm_free_cms_attribute_value(attrs[i].value);
532 attrs[i].value = NULL;
538 * Free the value part of the the attribute structure.
541 _DtCm_free_attribute_values(uint size, CSA_attribute * attrs)
545 for (i = 0; i < size; i++) {
546 if (attrs[i].value) {
547 _DtCm_free_attribute_value(attrs[i].value);
548 attrs[i].value = NULL;
554 _DtCm_old_reminder_name_to_name(char *oldname)
556 if (strcmp(oldname, _DtCM_OLD_ATTR_BEEP_REMINDER) == 0)
557 return (CSA_ENTRY_ATTR_AUDIO_REMINDER);
558 else if (strcmp(oldname, _DtCM_OLD_ATTR_FLASH_REMINDER) == 0)
559 return (CSA_ENTRY_ATTR_FLASHING_REMINDER);
560 else if (strcmp(oldname, _DtCM_OLD_ATTR_MAIL_REMINDER) == 0)
561 return (CSA_ENTRY_ATTR_MAIL_REMINDER);
562 else if (strcmp(oldname, _DtCM_OLD_ATTR_POPUP_REMINDER) == 0)
563 return (CSA_ENTRY_ATTR_POPUP_REMINDER);
569 _DtCm_old_reminder_name_to_index(char *oldname)
573 name = _DtCm_old_reminder_name_to_name(oldname);
575 return (_DtCm_get_index_from_table(_DtCm_entry_name_tbl, name));
579 * Given an attribute name, return the corresponding
580 * attribute number that's supported by old backends (v4 and before).
582 extern CSA_return_code
583 _DtCm_get_old_attr_by_name(char *name, _DtCm_old_attrs *attr)
587 index = _DtCm_get_index_from_table(_DtCm_entry_name_tbl, name);
588 if (index > 0 && index <= _DtCM_DEFINED_ENTRY_ATTR_SIZE) {
590 if (_CSA_entry_attr_info[index].oldattr
591 != _DtCm_old_attr_unknown) {
592 *attr = _CSA_entry_attr_info[index].oldattr;
593 return (CSA_SUCCESS);
595 return (CSA_E_UNSUPPORTED_ATTRIBUTE);
597 return (CSA_E_INVALID_ATTRIBUTE);
601 * Given an attribute index, return the corresponding
602 * attribute number that's supported by old backends (v4 and before).
604 extern CSA_return_code
605 _DtCm_get_old_attr_by_index(int index, _DtCm_old_attrs *attr)
607 if (index <= _DtCM_DEFINED_ENTRY_ATTR_SIZE) {
608 if (_CSA_entry_attr_info[index].oldattr
609 != _DtCm_old_attr_unknown) {
610 *attr = _CSA_entry_attr_info[index].oldattr;
611 return (CSA_SUCCESS);
613 return (CSA_E_UNSUPPORTED_ATTRIBUTE);
615 return (CSA_E_INVALID_ATTRIBUTE);
620 * the attribute structure should contain valid value
621 * a NULL attribute value is valid
623 extern CSA_return_code
624 _DtCm_copy_cms_attribute(
629 CSA_return_code stat = CSA_SUCCESS;
633 return (CSA_E_INVALID_PARAMETER);
635 /* copy the attribute name */
637 if ((name = strdup(from->name.name)) == NULL)
638 return(CSA_E_INSUFFICIENT_MEMORY);
641 if ((stat = _DtCm_copy_cms_attr_val(from->value, &to->value))
644 to->name.name = name;
645 to->name.num = from->name.num;
653 extern CSA_return_code
654 _DtCm_copy_cms_attr_val(cms_attribute_value *from, cms_attribute_value **to)
656 CSA_return_code stat = CSA_SUCCESS;
657 cms_attribute_value *val;
660 return (CSA_E_INVALID_PARAMETER);
662 /* copy the attribute value */
666 if ((val = (cms_attribute_value *)calloc(1,
667 sizeof(cms_attribute_value))) == NULL)
668 return (CSA_E_INSUFFICIENT_MEMORY);
670 switch (from->type) {
671 case CSA_VALUE_BOOLEAN:
672 case CSA_VALUE_ENUMERATED:
673 case CSA_VALUE_FLAGS:
674 case CSA_VALUE_UINT32:
675 case CSA_VALUE_SINT32:
676 val->item.uint32_value = from->item.uint32_value;
679 case CSA_VALUE_STRING:
680 case CSA_VALUE_DATE_TIME:
681 case CSA_VALUE_DATE_TIME_RANGE:
682 case CSA_VALUE_TIME_DURATION:
683 case CSA_VALUE_CALENDAR_USER:
684 if (from->item.string_value)
685 val->item.string_value =
686 strdup(from->item.string_value);
688 val->item.string_value = calloc(1, 1);
689 if (val->item.string_value == NULL)
690 stat = CSA_E_INSUFFICIENT_MEMORY;
693 case CSA_VALUE_REMINDER:
694 if (from->item.reminder_value == NULL)
695 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
697 stat = _DtCm_copy_reminder(
698 from->item.reminder_value,
699 &val->item.reminder_value);
701 case CSA_VALUE_ATTENDEE_LIST:
702 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
704 case CSA_VALUE_ACCESS_LIST:
705 if (from->item.access_list_value &&
706 (val->item.access_list_value =
707 _DtCm_copy_cms_access_list(
708 from->item.access_list_value)) == NULL) {
710 stat = CSA_E_INSUFFICIENT_MEMORY;
713 case CSA_VALUE_DATE_TIME_LIST:
714 if (from->item.date_time_list_value &&
715 (val->item.date_time_list_value =
716 _DtCm_copy_date_time_list(
717 from->item.date_time_list_value)) == NULL) {
719 stat = CSA_E_INSUFFICIENT_MEMORY;
722 case CSA_VALUE_OPAQUE_DATA:
723 if (from->item.opaque_data_value) {
724 stat = _DtCm_copy_opaque_data(
725 from->item.opaque_data_value,
726 &val->item.opaque_data_value);
730 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
734 if (stat != CSA_SUCCESS)
737 val->type = from->type;
740 if (stat == CSA_SUCCESS) {
748 * copy the attribute name, and convert the attribute value
750 extern CSA_return_code
751 _DtCm_cms2csa_attribute(cms_attribute from, CSA_attribute *to)
753 CSA_return_code stat;
755 CSA_attribute_value *val;
757 if ((name = strdup(from.name.name)) == NULL)
758 return (CSA_E_INSUFFICIENT_MEMORY);
760 if ((stat = _DtCm_cms2csa_attrval(from.value, &val)) == CSA_SUCCESS) {
769 extern CSA_return_code
770 _DtCm_cms2csa_attrval(cms_attribute_value *from, CSA_attribute_value **to)
772 CSA_return_code stat = CSA_SUCCESS;
773 CSA_attribute_value *val;
776 return (CSA_E_INVALID_PARAMETER);
778 /* copy the attribute value */
782 if ((val = (CSA_attribute_value *)calloc(1,
783 sizeof(CSA_attribute_value))) == NULL)
784 return (CSA_E_INSUFFICIENT_MEMORY);
786 switch (from->type) {
787 case CSA_VALUE_BOOLEAN:
788 case CSA_VALUE_ENUMERATED:
789 case CSA_VALUE_FLAGS:
790 case CSA_VALUE_UINT32:
791 case CSA_VALUE_SINT32:
792 val->item.uint32_value = from->item.uint32_value;
795 case CSA_VALUE_STRING:
796 case CSA_VALUE_DATE_TIME:
797 case CSA_VALUE_DATE_TIME_RANGE:
798 case CSA_VALUE_TIME_DURATION:
799 if (from->item.string_value)
800 val->item.string_value =
801 strdup(from->item.string_value);
803 val->item.string_value = calloc(1, 1);
804 if (val->item.string_value == NULL)
805 stat = CSA_E_INSUFFICIENT_MEMORY;
808 case CSA_VALUE_REMINDER:
809 if (from->item.reminder_value == NULL)
810 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
812 stat = _DtCm_copy_reminder(
813 from->item.reminder_value,
814 &val->item.reminder_value);
816 case CSA_VALUE_CALENDAR_USER:
817 if (from->item.calendar_user_value == NULL)
818 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
820 stat = convert_cms_user_to_csa_user(
821 from->item.calendar_user_value,
822 &val->item.calendar_user_value);
824 case CSA_VALUE_ACCESS_LIST:
825 stat = _DtCm_cms2csa_access_list(
826 from->item.access_list_value,
827 &val->item.access_list_value);
829 case CSA_VALUE_ATTENDEE_LIST:
830 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
832 case CSA_VALUE_DATE_TIME_LIST:
833 if (from->item.date_time_list_value &&
834 (val->item.date_time_list_value =
835 _DtCm_copy_date_time_list(
836 from->item.date_time_list_value)) == NULL) {
837 stat = CSA_E_INSUFFICIENT_MEMORY;
840 case CSA_VALUE_OPAQUE_DATA:
841 if (from->item.opaque_data_value) {
842 stat = _DtCm_copy_opaque_data(
843 from->item.opaque_data_value,
844 &val->item.opaque_data_value);
846 val->item.opaque_data_value = NULL;
849 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
853 if (stat != CSA_SUCCESS)
856 val->type = from->type;
859 if (stat == CSA_SUCCESS) {
867 _DtCm_free_cms_attribute_value(cms_attribute_value *val)
873 case CSA_VALUE_STRING:
874 case CSA_VALUE_DATE_TIME:
875 case CSA_VALUE_DATE_TIME_RANGE:
876 case CSA_VALUE_TIME_DURATION:
877 case CSA_VALUE_CALENDAR_USER:
878 if (val->item.string_value)
879 free(val->item.string_value);
882 case CSA_VALUE_REMINDER:
883 if (val->item.reminder_value)
884 _DtCm_free_reminder(val->item.reminder_value);
886 case CSA_VALUE_ACCESS_LIST:
887 if (val->item.access_list_value)
888 _DtCm_free_cms_access_entry(val->item.access_list_value);
890 case CSA_VALUE_DATE_TIME_LIST:
891 if (val->item.date_time_list_value)
892 _DtCm_free_date_time_list(
893 val->item.date_time_list_value);
895 case CSA_VALUE_OPAQUE_DATA:
896 if (val->item.opaque_data_value) {
897 _DtCm_free_opaque_data(val->item.opaque_data_value);
905 _DtCm_free_attribute_value(CSA_attribute_value *val)
911 case CSA_VALUE_STRING:
912 case CSA_VALUE_DATE_TIME:
913 case CSA_VALUE_DATE_TIME_RANGE:
914 case CSA_VALUE_TIME_DURATION:
915 if (val->item.string_value)
916 free(val->item.string_value);
919 case CSA_VALUE_REMINDER:
920 if (val->item.reminder_value)
921 _DtCm_free_reminder(val->item.reminder_value);
923 case CSA_VALUE_ACCESS_LIST:
924 if (val->item.access_list_value)
925 _DtCm_free_csa_access_list(val->item.access_list_value);
927 case CSA_VALUE_CALENDAR_USER:
928 if (val->item.calendar_user_value) {
929 if (val->item.calendar_user_value->user_name)
930 free(val->item.calendar_user_value->user_name);
931 if (val->item.calendar_user_value->calendar_address)
932 free(val->item.calendar_user_value->user_name);
933 free(val->item.calendar_user_value);
936 case CSA_VALUE_DATE_TIME_LIST:
937 if (val->item.date_time_list_value)
938 _DtCm_free_date_time_list(
939 val->item.date_time_list_value);
941 case CSA_VALUE_OPAQUE_DATA:
942 if (val->item.opaque_data_value) {
943 _DtCm_free_opaque_data(val->item.opaque_data_value);
950 extern CSA_return_code
951 _DtCm_set_uint32_attrval(uint numval, cms_attribute_value **attrval)
953 cms_attribute_value *val;
955 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
957 return (CSA_E_INSUFFICIENT_MEMORY);
960 val->type = CSA_VALUE_UINT32;
961 val->item.uint32_value = numval;
965 return (CSA_SUCCESS);
968 extern CSA_return_code
969 _DtCm_set_sint32_attrval(int numval, cms_attribute_value **attrval)
971 cms_attribute_value *val;
973 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
975 return (CSA_E_INSUFFICIENT_MEMORY);
978 val->type = CSA_VALUE_SINT32;
979 val->item.sint32_value = numval;
983 return (CSA_SUCCESS);
986 extern CSA_return_code
987 _DtCm_set_string_attrval(
989 cms_attribute_value **attrval,
992 cms_attribute_value *val;
994 if (type != CSA_VALUE_STRING && type != CSA_VALUE_DATE_TIME &&
995 type != CSA_VALUE_DATE_TIME_RANGE &&
996 type != CSA_VALUE_TIME_DURATION && type != CSA_VALUE_CALENDAR_USER)
997 return (CSA_E_INVALID_PARAMETER);
999 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
1001 return (CSA_E_INSUFFICIENT_MEMORY);
1006 if (strval == NULL) {
1007 val->item.string_value = NULL;
1008 } else if ((val->item.string_value = strdup(strval)) == NULL) {
1010 return (CSA_E_INSUFFICIENT_MEMORY);
1015 return (CSA_SUCCESS);
1018 extern CSA_return_code
1019 _DtCm_set_user_attrval(
1021 cms_attribute_value **attrval)
1023 cms_attribute_value *val;
1027 return (CSA_SUCCESS);
1030 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
1032 return (CSA_E_INSUFFICIENT_MEMORY);
1035 val->type = CSA_VALUE_CALENDAR_USER;
1037 if ((val->item.calendar_user_value = strdup(user)) == NULL) {
1039 return (CSA_E_INSUFFICIENT_MEMORY);
1044 return (CSA_SUCCESS);
1047 extern CSA_return_code
1048 _DtCm_set_reminder_attrval(CSA_reminder *remval, cms_attribute_value **attrval)
1050 cms_attribute_value *val;
1051 CSA_return_code stat;
1054 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1056 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
1058 return (CSA_E_INSUFFICIENT_MEMORY);
1061 val->type = CSA_VALUE_REMINDER;
1063 if ((stat = _DtCm_copy_reminder(remval, &val->item.reminder_value))
1071 return (CSA_SUCCESS);
1075 extern CSA_return_code
1076 _DtCm_set_csa_access_attrval(
1077 cms_access_entry *aval,
1078 CSA_attribute_value **attrval)
1080 CSA_attribute_value *val;
1081 CSA_return_code stat = CSA_SUCCESS;
1083 if ((val = (CSA_attribute_value *)malloc(sizeof(CSA_attribute_value)))
1085 return (CSA_E_INSUFFICIENT_MEMORY);
1088 val->type = CSA_VALUE_ACCESS_LIST;
1092 val->item.access_list_value = NULL;
1096 stat = _DtCm_cms2csa_access_list(aval,
1097 &val->item.access_list_value);
1101 if (stat == CSA_SUCCESS)
1109 extern CSA_return_code
1110 _DtCm_set_opaque_attrval(CSA_opaque_data *data, cms_attribute_value **attrval)
1112 CSA_return_code stat;
1113 cms_attribute_value *val;
1116 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1118 if ((val = (cms_attribute_value *)malloc(sizeof(cms_attribute_value)))
1120 return (CSA_E_INSUFFICIENT_MEMORY);
1123 val->type = CSA_VALUE_OPAQUE_DATA;
1125 if ((stat = _DtCm_copy_opaque_data(data, &val->item.opaque_data_value))
1132 return (CSA_SUCCESS);
1136 extern CSA_return_code
1137 _DtCm_set_csa_uint32_attrval(uint numval, CSA_attribute_value **attrval)
1139 CSA_attribute_value *val;
1141 if ((val = (CSA_attribute_value *)malloc(sizeof(CSA_attribute_value)))
1143 return (CSA_E_INSUFFICIENT_MEMORY);
1146 val->type = CSA_VALUE_UINT32;
1147 val->item.uint32_value = numval;
1151 return (CSA_SUCCESS);
1154 extern CSA_return_code
1155 _DtCm_set_csa_string_attrval(
1157 CSA_attribute_value **attrval,
1160 CSA_attribute_value *val;
1162 if (type != CSA_VALUE_STRING && type != CSA_VALUE_DATE_TIME &&
1163 type != CSA_VALUE_DATE_TIME_RANGE &&
1164 type != CSA_VALUE_TIME_DURATION && type != CSA_VALUE_CALENDAR_USER)
1165 return (CSA_E_INVALID_PARAMETER);
1167 if ((val = (CSA_attribute_value *)malloc(sizeof(CSA_attribute_value)))
1169 return (CSA_E_INSUFFICIENT_MEMORY);
1174 if (strval == NULL) {
1175 val->item.string_value = NULL;
1176 } else if ((val->item.string_value = strdup(strval)) == NULL) {
1178 return (CSA_E_INSUFFICIENT_MEMORY);
1183 return (CSA_SUCCESS);
1187 _DtCm_free_csa_access_list(CSA_access_list alist)
1189 CSA_access_list nptr;
1191 while (alist != NULL) {
1195 if (alist->user->user_name) {
1196 free(alist->user->user_name);
1198 if (alist->user->calendar_address) {
1199 free(alist->user->calendar_address);
1211 _DtCm_free_date_time_list(CSA_date_time_list list)
1213 CSA_date_time_entry *nptr;
1215 while (list != NULL) {
1218 if (list->date_time) {
1219 free(list->date_time);
1229 _DtCm_free_cms_access_entry(cms_access_entry *list)
1231 cms_access_entry *nptr;
1233 while (list != NULL) {
1246 extern cms_access_entry *
1247 _DtCm_copy_cms_access_list(cms_access_entry *alist)
1249 cms_access_entry *l, *head, *prev;
1250 boolean_t cleanup = B_FALSE;
1253 while (alist != NULL) {
1254 if ((l = (cms_access_entry *)calloc(1, sizeof(cms_access_entry)))
1260 if ((l->user = strdup(alist->user)) == NULL) {
1266 l->rights = alist->rights;
1275 alist = alist->next;
1278 if (cleanup == B_TRUE) {
1279 _DtCm_free_cms_access_entry(head);
1285 extern CSA_return_code
1286 _DtCm_cms2csa_access_list(
1287 cms_access_entry *cmslist,
1288 CSA_access_rights **csalist)
1290 CSA_return_code stat = CSA_SUCCESS;
1291 CSA_access_rights *to, *head, *prev;
1294 while (cmslist != NULL) {
1295 if ((to = (CSA_access_rights *)calloc(1,
1296 sizeof(CSA_access_rights))) == NULL) {
1297 stat = CSA_E_INSUFFICIENT_MEMORY;
1301 if ((to->user = (CSA_calendar_user *)calloc(1,
1302 sizeof(CSA_calendar_user))) == NULL) {
1304 stat = CSA_E_INSUFFICIENT_MEMORY;
1308 if ((to->user->user_name = strdup(cmslist->user)) == NULL) {
1311 stat = CSA_E_INSUFFICIENT_MEMORY;
1315 to->rights = cmslist->rights;
1325 cmslist = cmslist->next;
1328 if (stat != CSA_SUCCESS) {
1329 _DtCm_free_csa_access_list(head);
1337 extern CSA_return_code
1338 _DtCm_csa2cms_access_list(
1339 CSA_access_rights *csalist,
1340 cms_access_entry **cmslist)
1342 CSA_return_code stat = CSA_SUCCESS;
1343 cms_access_entry *to, *head, *prev;
1346 while (csalist != NULL) {
1347 if ((to = (cms_access_entry *)calloc(1,
1348 sizeof(cms_access_entry))) == NULL) {
1349 stat = CSA_E_INSUFFICIENT_MEMORY;
1353 if (csalist->user->user_name) {
1354 if ((to->user = strdup(csalist->user->user_name))
1356 stat = CSA_E_INSUFFICIENT_MEMORY;
1361 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
1366 to->rights = csalist->rights;
1376 csalist = csalist->next;
1379 if (stat != CSA_SUCCESS) {
1380 _DtCm_free_cms_access_entry(head);
1388 extern CSA_date_time_list
1389 _DtCm_copy_date_time_list(CSA_date_time_list dlist)
1391 CSA_date_time_entry *l, *head, *prev;
1392 boolean_t cleanup = B_FALSE;
1395 while (dlist != NULL) {
1396 if ((l = (CSA_date_time_entry *)calloc(1,
1397 sizeof(CSA_date_time_entry))) == NULL) {
1402 if ((l->date_time = strdup(dlist->date_time)) == NULL) {
1416 dlist = dlist->next;
1419 if (cleanup == B_TRUE) {
1420 _DtCm_free_date_time_list(head);
1426 extern CSA_return_code
1427 _DtCm_copy_reminder(CSA_reminder *from, CSA_reminder **to)
1429 CSA_reminder *newval;
1431 if ((newval = (CSA_reminder *)calloc(1, sizeof(CSA_reminder))) == NULL)
1432 return (CSA_E_INSUFFICIENT_MEMORY);
1434 if (from->lead_time) {
1435 if ((newval->lead_time = strdup(from->lead_time)) == NULL) {
1437 return (CSA_E_INSUFFICIENT_MEMORY);
1441 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1444 if (from->snooze_time)
1445 newval->snooze_time = strdup(from->snooze_time);
1447 newval->snooze_time = calloc(1, 1);
1449 if (newval->snooze_time == NULL) {
1450 _DtCm_free_reminder(newval);
1451 return (CSA_E_INSUFFICIENT_MEMORY);
1454 newval->repeat_count = from->repeat_count;
1456 if (from->reminder_data.size > 0) {
1457 newval->reminder_data.size = from->reminder_data.size;
1458 if ((newval->reminder_data.data = malloc(
1459 newval->reminder_data.size)) == NULL) {
1460 _DtCm_free_reminder(newval);
1461 return (CSA_E_INSUFFICIENT_MEMORY);
1463 memcpy(newval->reminder_data.data, from->reminder_data.data,
1464 from->reminder_data.size);
1468 return (CSA_SUCCESS);
1472 _DtCm_free_reminder(CSA_reminder *val)
1474 if (val == NULL) return;
1477 free(val->lead_time);
1479 if (val->snooze_time)
1480 free(val->snooze_time);
1482 if (val->reminder_data.size > 0)
1483 free(val->reminder_data.data);
1488 extern CSA_return_code
1489 _DtCm_copy_opaque_data(CSA_opaque_data *from, CSA_opaque_data **to)
1491 CSA_opaque_data *val;
1493 if ((val = (CSA_opaque_data *)calloc(1, sizeof(CSA_opaque_data)))
1495 return (CSA_E_INSUFFICIENT_MEMORY);
1498 if (from->size > 0) {
1499 val->size = from->size;
1500 if ((val->data = malloc(from->size)) == NULL) {
1502 return (CSA_E_INSUFFICIENT_MEMORY);
1504 memcpy(val->data, from->data, from->size);
1512 return (CSA_SUCCESS);
1516 _DtCm_free_opaque_data(CSA_opaque_data *val)
1518 if (val == NULL) return;
1526 _DtCm_get_attribute_types(uint size, int *types)
1530 for (i = 1; i <= size; i++) {
1531 types[i] = _CSA_entry_attr_info[i].type;
1535 /******************************************************************************
1536 * static functions used within the file
1537 ******************************************************************************/
1540 * The passed in attributes are hashed.
1541 * For each attribute, check
1542 * 1. type is valid and supported
1543 * 2. if it's a date time value type, check validity of date time.
1544 * 3. if it's a reminder value type, check validity of lead time.
1545 * 4. if it is a defined attribute, check that the data type is correct.
1546 * 5. if it is a defined attribute and checkreadonly is set, check
1547 * that it's not readonly.
1549 static CSA_return_code
1550 check_predefined_attrs(
1553 cms_attribute *attrs,
1554 boolean_t checkreadonly,
1555 _DtCmNameTable *tbl,
1557 _DtCmAttrInfo *our_attrs)
1563 for (i = 0; i < num_attrs; i++) {
1565 if (attrs[i].name.name == NULL)
1571 index = _DtCm_get_index_from_table(tbl,
1572 attrs[i].name.name);
1574 if (index > 0 && index <= num_defined) {
1576 /* check whether the attribute is supported
1579 if (our_attrs[index].fst_vers == 0 ||
1580 (fver < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
1581 fver < our_attrs[index].fst_vers))
1582 return (CSA_E_UNSUPPORTED_ATTRIBUTE);
1583 else if (our_attrs[index].fst_vers == -1)
1584 return (CSA_E_INVALID_ATTRIBUTE);
1586 /* check whether the attribute is readonly */
1587 if (checkreadonly &&
1588 ((fver < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
1589 our_attrs[index].nex_ro) ||
1590 (fver >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
1591 our_attrs[index].ex_ro)))
1592 return (CSA_E_READONLY);
1594 /* check data type */
1595 if (attrs[i].value &&
1596 attrs[i].value->type != our_attrs[index].type)
1597 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1599 if (index == CSA_ENTRY_ATTR_CLASSIFICATION_I) {
1600 cl = attrs[i].value->item.uint32_value;
1601 if (cl < CSA_CLASS_PUBLIC ||
1602 cl > CSA_CLASS_CONFIDENTIAL)
1603 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1606 if (index == CSA_ENTRY_ATTR_TYPE_I) {
1607 cl = attrs[i].value->item.uint32_value;
1608 if (cl < CSA_TYPE_EVENT ||
1609 cl > CSA_X_DT_TYPE_OTHER)
1610 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1613 } else if (fver < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
1614 return (CSA_E_INVALID_ATTRIBUTE);
1617 /* check validity of value type */
1618 if (attrs[i].value) {
1619 if (attrs[i].value->type < CSA_VALUE_BOOLEAN ||
1620 attrs[i].value->type > CSA_VALUE_OPAQUE_DATA)
1621 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1623 /* cast the sint32_value element to the desired
1624 * type to be safe since the value part could
1625 * actually be a pointer to a CSA_attribute_value
1627 switch (attrs[i].value->type) {
1628 case CSA_VALUE_DATE_TIME:
1629 if (attrs[i].value->item.sint32_value == 0
1630 || _csa_iso8601_to_tick(
1631 (char *)attrs[i].value->item.sint32_value,
1633 return (CSA_E_INVALID_DATE_TIME);
1635 case CSA_VALUE_REMINDER:
1636 rptr = (CSA_reminder *)
1637 attrs[i].value->item.sint32_value;
1638 if (rptr == NULL || rptr->lead_time == NULL ||
1639 _csa_iso8601_to_duration(rptr->lead_time,
1641 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1643 case CSA_VALUE_ATTENDEE_LIST:
1644 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1649 return (CSA_SUCCESS);
1652 static CSA_return_code
1653 convert_cms_user_to_csa_user(char *from, CSA_calendar_user **to)
1655 CSA_calendar_user *newval;
1657 if ((newval = (CSA_calendar_user *)calloc(1,
1658 sizeof(CSA_calendar_user))) == NULL)
1659 return (CSA_E_INSUFFICIENT_MEMORY);
1662 if ((newval->user_name = strdup(from)) == NULL) {
1664 return (CSA_E_INSUFFICIENT_MEMORY);
1669 return (CSA_SUCCESS);
1672 static CSA_return_code
1675 CSA_attribute *csaattrs,
1676 cms_attribute *cmsattrs,
1678 cms_attribute **hattrs,
1681 int i, j, index, count = 0;
1682 cms_attribute *nattrs;
1684 cms_attribute_value *val;
1686 if ((nattrs = (cms_attribute *)calloc(1,
1687 sizeof(cms_attribute)*(num_attrs+_DtCM_DEFINED_ENTRY_ATTR_SIZE+1)))
1689 return (CSA_E_INSUFFICIENT_MEMORY);
1691 for (i = 0, j = _DtCM_DEFINED_ENTRY_ATTR_SIZE + 1; i < num_attrs; i++) {
1692 name = (csaattrs ? csaattrs[i].name : cmsattrs[i].name.name);
1698 ((cms_attribute_value *)csaattrs[i].value) :
1702 index = _DtCm_get_index_from_table(_DtCm_entry_name_tbl, name);
1705 if (cmsattrs) cmsattrs[i].name.num = index;
1707 nattrs[index].name.name = name;
1708 nattrs[index].value = val;
1710 nattrs[j].name.name = name;
1711 nattrs[j++].value = val;
1715 if (num) *num = count;
1718 return (CSA_SUCCESS);
1721 static CSA_return_code
1724 CSA_attribute *csaattrs,
1725 cms_attribute *cmsattrs,
1727 cms_attribute **hattrs,
1730 int i, j, index, count = 0;
1731 cms_attribute *nattrs;
1733 cms_attribute_value *val;
1735 if ((nattrs = (cms_attribute *)calloc(1,
1736 sizeof(cms_attribute)*(num_attrs+_DtCM_DEFINED_CAL_ATTR_SIZE+1)))
1738 return (CSA_E_INSUFFICIENT_MEMORY);
1740 for (i = 0, j = _DtCM_DEFINED_CAL_ATTR_SIZE + 1; i < num_attrs; i++) {
1741 name = (csaattrs ? csaattrs[i].name : cmsattrs[i].name.name);
1747 ((cms_attribute_value *)csaattrs[i].value) :
1751 index = _DtCm_get_index_from_table(_DtCm_cal_name_tbl, name);
1754 if (cmsattrs) cmsattrs[i].name.num = index;
1756 nattrs[index].name.name = name;
1757 nattrs[index].value = val;
1759 nattrs[j].name.name = name;
1760 nattrs[j++].value = val;
1764 if (num) *num = count;
1767 return (CSA_SUCCESS);
1770 static CSA_return_code
1771 _DtCm_check_hashed_cal_attributes(
1774 cms_attribute *attrs,
1777 boolean_t checkreadonly,
1778 boolean_t firsttime,
1781 CSA_return_code stat;
1782 CSA_attribute_value *csaval;
1783 cms_attribute_value *cmsval;
1784 char *nattr = NULL; /* calendar name */
1785 char *oattr = NULL; /* calendar owner */
1786 char *cattr = NULL; /* character set */
1787 char *tattr = NULL; /* time zone */
1790 if (attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name) {
1791 if (attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value == NULL
1792 || attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value->\
1793 item.calendar_user_value == NULL)
1794 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1797 csaval = (CSA_attribute_value *)attrs[\
1798 CSA_CAL_ATTR_CALENDAR_OWNER_I].value;
1799 stat = _CheckCalendarOwner(owner, csaval->type,
1800 (csaval && csaval->item.calendar_user_value?
1801 csaval->item.calendar_user_value->user_name:
1804 cmsval = attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
1806 stat = _CheckCalendarOwner(owner, cmsval->type,
1808 cmsval->item.calendar_user_value:NULL);
1811 if (stat != CSA_SUCCESS)
1814 oattr = attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name;
1815 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name = NULL;
1818 if (attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name) {
1819 if (attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value == NULL ||
1820 attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value->\
1821 item.string_value == NULL) {
1823 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
1825 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1828 if ((stat = _CheckCalendarName(owner, cname,
1829 attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value))
1832 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
1837 nattr = attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name;
1838 attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name = NULL;
1841 if (attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name) {
1842 cattr = attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name;
1843 attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name = NULL;
1846 if (attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name) {
1847 tattr = attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name;
1848 attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name = NULL;
1852 stat = check_predefined_attrs(fvers, num_attrs+1, attrs,
1853 checkreadonly, NULL, _DtCM_DEFINED_CAL_ATTR_SIZE,
1854 _CSA_cal_attr_info);
1857 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].name.name = oattr;
1860 attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].name.name = nattr;
1863 attrs[CSA_CAL_ATTR_CHARACTER_SET_I].name.name = oattr;
1866 attrs[CSA_CAL_ATTR_TIME_ZONE_I].name.name = nattr;
1871 static CSA_return_code
1872 _DtCm_check_hashed_entry_attributes(
1875 cms_attribute *attrs,
1878 CSA_return_code stat;
1880 if ((stat = check_predefined_attrs(fvers, num_attrs+1, attrs,
1881 (utype == 0 ? B_FALSE : B_TRUE), NULL,
1882 _DtCM_DEFINED_ENTRY_ATTR_SIZE, _CSA_entry_attr_info))
1888 if (utype == CSA_CB_ENTRY_ADDED) {
1890 /* make sure the minimum set of attribute is specified */
1891 if (attrs[CSA_ENTRY_ATTR_START_DATE_I].value == NULL ||
1892 attrs[CSA_ENTRY_ATTR_TYPE_I].value == NULL)
1893 return (CSA_E_INVALID_PARAMETER);
1895 } else if (utype == CSA_CB_ENTRY_UPDATED) {
1897 /* type can only be set at insertion time */
1898 if (attrs[CSA_ENTRY_ATTR_TYPE_I].name.name)
1899 return (CSA_E_READONLY);
1902 return (CSA_SUCCESS);
1905 static CSA_return_code
1906 _CheckNameAtHost(char *owner, char *value)
1911 /* check name part first */
1912 if (owner == NULL) {
1913 /* get user name of user running the application */
1914 if ((owner = _DtCmGetUserName()) == NULL)
1915 return (CSA_E_FAILURE);
1918 if (optr = strchr(owner, '@')) *optr = '\0';
1919 if (ptr = strchr(value, '@')) *ptr = '\0';
1920 res = strcmp(value, owner);
1921 if (optr) *optr = '@';
1922 if (ptr) *ptr = '@';
1925 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1927 /* check host too if it's specified */
1929 return (CSA_SUCCESS);
1932 if (strcmp(ptr, (optr ? ++optr : _DtCmGetLocalHost())) == 0)
1933 return (CSA_SUCCESS);
1935 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1939 * check the data type and validity of calendar owner attribute
1941 static CSA_return_code
1942 _CheckCalendarOwner(char *owner, int type, char *user)
1944 if (type != CSA_VALUE_CALENDAR_USER || user == NULL)
1945 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1947 /* make sure user is the same as the one running the application */
1948 return (_CheckNameAtHost(owner, user));
1952 * check the data type and validity of calendar name attribute
1954 static CSA_return_code
1955 _CheckCalendarName(char *owner, char *cname, cms_attribute_value *val)
1957 CSA_return_code stat;
1962 if (val->type != CSA_VALUE_STRING)
1963 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
1965 /* check that the attribute value is the same as the given
1968 if ((stat = _CheckNameAtHost(cname, val->item.string_value))
1972 /* now make sure if cal name is a user name, it's
1973 * the same as that of the calling user
1975 if (ptr = strchr(val->item.string_value, '@')) *ptr = '\0';
1976 isuser = _DtCmIsUserName(val->item.string_value);
1977 if (ptr) *ptr = '@';
1979 /* make sure it's the same as the user running the application */
1980 if (isuser == B_TRUE) {
1981 sprintf(user, "%s%s", val->item.string_value, (ptr ? ptr : ""));
1982 return (_CheckNameAtHost(owner, user));
1985 /* check the host part */
1987 return (CSA_SUCCESS);
1991 if (owner && (optr = strchr(owner, '@')))
1994 optr = _DtCmGetLocalHost();
1996 if (strcmp(ptr, optr) == 0)
1997 return (CSA_SUCCESS);
1999 return (CSA_E_INVALID_ATTRIBUTE_VALUE);