1 /* $XConsortium: convert5-4.c /main/2 1996/10/07 15:57:11 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 "convert4-5.h"
14 #include "convert5-4.h"
20 * Routines to convert data types used in version 5 to version 4.
23 /*****************************************************************************
25 *****************************************************************************/
28 * attributes are checked before calling this routine
29 * so all attributes should be supported in v4
31 extern CSA_return_code
32 _DtCm_cmsattrs_to_apptdata(uint size, cms_attribute *attrs, Appt_4 *appt)
34 CSA_return_code stat = CSA_SUCCESS;
41 * this routine is called to convert valid v2 to v4 attributes
42 * so no checking of CSA_E_INVALID_ATTRIBUTE and
43 * CSA_E_UNSUPPORTED_ATTRIBUTE is necessary
46 /* assuming all appt data is available */
49 if (_csa_iso8601_to_tick(
50 attrs[CSA_ENTRY_ATTR_START_DATE_I].value->item.date_time_value,
52 return (CSA_E_INVALID_DATE_TIME);
55 aptr = &attrs[CSA_ENTRY_ATTR_END_DATE_I];
56 if (aptr->value && aptr->value->item.date_time_value &&
57 *(aptr->value->item.date_time_value))
59 if (_csa_iso8601_to_tick(aptr->value->item.date_time_value,
61 return (CSA_E_INVALID_DATE_TIME);
63 appt->duration = endtick - appt->appt_id.tick;
67 aptr = &attrs[CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I];
68 if (aptr->value && aptr->value->item.opaque_data_value &&
69 aptr->value->item.opaque_data_value->size > 0)
71 strncpy(buf, (char *)aptr->value->item.opaque_data_value->data,
72 aptr->value->item.opaque_data_value->size);
73 buf[aptr->value->item.opaque_data_value->size] = NULL;
75 ptr = strchr(buf, ':');
79 appt->appt_id.key = atol(buf);
82 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
84 /* _DtCm_old_attr_type */
85 if ((stat = _DtCm_attrs_to_eventtype4(
86 attrs[CSA_ENTRY_ATTR_TYPE_I].value,
87 attrs[CSA_ENTRY_ATTR_SUBTYPE_I].value, appt->tag)) != CSA_SUCCESS)
90 /* _DtCm_old_attr_what */
91 aptr = &attrs[CSA_ENTRY_ATTR_SUMMARY_I];
92 if (aptr->value->item.string_value) {
93 if ((string = strdup(aptr->value->item.string_value)) == NULL)
94 return (CSA_E_INSUFFICIENT_MEMORY);
102 /* _DtCm_old_attr_author */
103 aptr = &attrs[CSA_ENTRY_ATTR_ORGANIZER_I];
104 if (aptr->value && aptr->value->item.calendar_user_value) {
105 if ((string = strdup(aptr->value->item.calendar_user_value))
107 return (CSA_E_INSUFFICIENT_MEMORY);
111 appt->author = string;
115 /* _DtCm_old_attr_beep_reminder */
116 aptr = &attrs[CSA_ENTRY_ATTR_AUDIO_REMINDER_I];
117 if (aptr->value && aptr->value->item.reminder_value) {
118 if ((stat = _DtCm_add_reminder(_DtCM_OLD_ATTR_BEEP_REMINDER,
119 aptr->value->item.reminder_value, appt)) != CSA_SUCCESS)
123 /* _DtCm_old_attr_flash_reminder */
124 aptr = &attrs[CSA_ENTRY_ATTR_FLASHING_REMINDER_I];
125 if (aptr->value && aptr->value->item.reminder_value) {
126 if ((stat = _DtCm_add_reminder(_DtCM_OLD_ATTR_FLASH_REMINDER,
127 aptr->value->item.reminder_value, appt)) != CSA_SUCCESS)
131 /* _DtCm_old_attr_mail_reminder */
132 aptr = &attrs[CSA_ENTRY_ATTR_MAIL_REMINDER_I];
133 if (aptr->value && aptr->value->item.reminder_value) {
134 if ((stat = _DtCm_add_reminder(_DtCM_OLD_ATTR_MAIL_REMINDER,
135 aptr->value->item.reminder_value, appt)) != CSA_SUCCESS)
139 /* _DtCm_old_attr_popup_reminder */
140 aptr = &attrs[CSA_ENTRY_ATTR_POPUP_REMINDER_I];
141 if (aptr->value && aptr->value->item.reminder_value) {
142 if ((stat = _DtCm_add_reminder(_DtCM_OLD_ATTR_POPUP_REMINDER,
143 aptr->value->item.reminder_value, appt)) != CSA_SUCCESS)
147 /* _DtCm_old_attr_repeat_type */
148 if (_DtCm_rtype_to_interval4(
149 attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I].value->item.sint32_value,
150 &appt->period.period))
151 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
153 /* _DtCm_old_attr_repeat_times */
154 aptr = &attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I];
156 appt->ntimes = aptr->value->item.uint32_value;
158 if (appt->period.period != single_4 &&
159 appt->ntimes == CSA_X_DT_DT_REPEAT_FOREVER) {
160 appt->ntimes = _DtCM_OLD_REPEAT_FOREVER;
163 /* _DtCm_old_attr_showtime */
164 aptr = &attrs[CSA_X_DT_ENTRY_ATTR_SHOWTIME_I];
166 appt->tag->showtime = aptr->value->item.sint32_value;
168 /* _DtCm_old_attr_status */
169 if (_DtCm_status_to_apptstatus4(
170 attrs[CSA_ENTRY_ATTR_STATUS_I].value->item.uint32_value,
172 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
174 /* _DtCm_old_attr_privacy */
175 if (_DtCm_classification_to_privacy4(
176 attrs[CSA_ENTRY_ATTR_CLASSIFICATION_I].value->item.uint32_value,
178 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
180 /* _DtCm_old_attr_end_date */
181 aptr = &attrs[CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I];
182 if (aptr->value && aptr->value->item.date_time_value &&
183 *(aptr->value->item.date_time_value))
185 if (_csa_iso8601_to_tick(aptr->value->item.date_time_value,
186 &appt->period.enddate))
187 return (CSA_E_INVALID_DATE_TIME);
190 switch (appt->period.period) {
192 /* _DtCm_old_attr_repeat_nth_weeknum */
193 aptr = &attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I];
195 appt->period.nth = aptr->value->item.sint32_value;
199 case everyNthMonth_4:
200 /* _DtCm_old_attr_repeat_nth_interval */
201 aptr = &attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I];
203 appt->period.nth = aptr->value->item.uint32_value;
206 appt->period.nth = 0;
213 * ** need to check whether value is valid
215 extern CSA_return_code
216 _DtCm_attrs_to_apptdata(uint size, CSA_attribute *attrs, Appt_4 *appt)
218 CSA_return_code stat = CSA_SUCCESS;
219 _DtCm_old_attrs oldattr;
221 int interval = 0, week_num = 0, i;
222 boolean_t set_interval = B_FALSE, set_weeknum = B_FALSE;
224 int tindex = 0, stindex = 0;
225 CSA_attribute_value otype;
227 for (i = 0; i < size && stat == CSA_SUCCESS; i++) {
229 if (attrs[i].name == NULL)
232 if ((stat = _DtCm_get_old_attr_by_name(attrs[i].name, &oldattr))
237 case _DtCm_old_attr_id:
238 stat = CSA_E_READONLY;
241 case _DtCm_old_attr_time:
242 if (attrs[i].value == NULL ||
243 attrs[i].value->item.date_time_value == NULL ||
244 _csa_iso8601_to_tick(
245 attrs[i].value->item.date_time_value,
246 &appt->appt_id.tick))
247 stat = CSA_E_INVALID_DATE_TIME;
249 case _DtCm_old_attr_type:
250 if (attrs[i].value == NULL)
251 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
255 case _DtCm_old_attr_type2:
258 case _DtCm_old_attr_duration:
259 if (attrs[i].value == NULL)
261 else if (attrs[i].value->item.date_time_value
262 == NULL || _csa_iso8601_to_tick(
263 attrs[i].value->item.date_time_value,
265 stat = CSA_E_INVALID_DATE_TIME;
267 case _DtCm_old_attr_what:
268 if (attrs[i].value && attrs[i].value->item.string_value)
270 if ((string = strdup(
271 attrs[i].value->item.string_value))
273 stat = CSA_E_INSUFFICIENT_MEMORY;
281 case _DtCm_old_attr_author:
282 stat = CSA_E_READONLY;
285 case _DtCm_old_attr_beep_reminder:
286 if (attrs[i].value == NULL)
287 stat = _DtCm_remove_reminder(
288 _DtCM_OLD_ATTR_BEEP_REMINDER, appt);
289 else if (attrs[i].value->item.reminder_value == NULL)
290 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
292 stat = _DtCm_add_reminder(
293 _DtCM_OLD_ATTR_BEEP_REMINDER,
294 attrs[i].value->item.reminder_value,
298 case _DtCm_old_attr_flash_reminder:
299 if (attrs[i].value == NULL)
300 stat = _DtCm_remove_reminder(
301 _DtCM_OLD_ATTR_FLASH_REMINDER, appt);
302 else if (attrs[i].value->item.reminder_value == NULL)
303 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
305 stat = _DtCm_add_reminder(
306 _DtCM_OLD_ATTR_FLASH_REMINDER,
307 attrs[i].value->item.reminder_value,
311 case _DtCm_old_attr_mail_reminder:
312 if (attrs[i].value == NULL)
313 stat = _DtCm_remove_reminder(
314 _DtCM_OLD_ATTR_MAIL_REMINDER, appt);
315 else if (attrs[i].value->item.reminder_value == NULL)
316 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
318 stat = _DtCm_add_reminder(
319 _DtCM_OLD_ATTR_MAIL_REMINDER,
320 attrs[i].value->item.reminder_value,
324 case _DtCm_old_attr_popup_reminder:
325 if (attrs[i].value == NULL)
326 stat = _DtCm_remove_reminder(
327 _DtCM_OLD_ATTR_POPUP_REMINDER, appt);
328 else if (attrs[i].value->item.reminder_value == NULL)
329 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
331 stat = _DtCm_add_reminder(
332 _DtCM_OLD_ATTR_POPUP_REMINDER,
333 attrs[i].value->item.reminder_value,
337 case _DtCm_old_attr_repeat_type:
338 if (attrs[i].value == NULL)
339 appt->period.period = single_4;
340 else if (_DtCm_rtype_to_interval4(
341 attrs[i].value->item.sint32_value,
342 &appt->period.period))
343 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
345 case _DtCm_old_attr_repeat_times:
346 if (attrs[i].value == NULL)
350 attrs[i].value->item.uint32_value;
352 case _DtCm_old_attr_showtime:
353 if (attrs[i].value == NULL)
354 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
356 appt->tag->showtime =
357 attrs[i].value->item.sint32_value;
359 case _DtCm_old_attr_status:
360 if (attrs[i].value == NULL)
361 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
362 else if (_DtCm_status_to_apptstatus4(
363 attrs[i].value->item.sint32_value,
365 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
367 case _DtCm_old_attr_privacy:
368 if (attrs[i].value == NULL)
369 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
370 else if (_DtCm_classification_to_privacy4(
371 attrs[i].value->item.sint32_value,
373 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
375 case _DtCm_old_attr_repeat_nth_interval:
376 if (attrs[i].value != NULL) {
377 set_interval = B_TRUE;
378 interval = attrs[i].value->item.uint32_value;
381 case _DtCm_old_attr_repeat_nth_weeknum:
382 if (attrs[i].value != NULL) {
383 set_weeknum = B_TRUE;
384 week_num = attrs[i].value->item.sint32_value;
387 case _DtCm_old_attr_end_date:
388 if (attrs[i].value == NULL)
389 appt->period.enddate = 0;
390 else if (attrs[i].value->item.date_time_value == NULL ||
391 _csa_iso8601_to_tick(
392 attrs[i].value->item.date_time_value,
393 &appt->period.enddate))
394 stat = CSA_E_INVALID_DATE_TIME;
397 stat = CSA_E_INVALID_PARAMETER;
401 if (stat == CSA_SUCCESS) {
403 if (tindex || stindex) {
405 otype.type = CSA_VALUE_SINT32;
406 switch (appt->tag->tag) {
409 otype.item.sint32_value =
413 otype.item.sint32_value = CSA_TYPE_TODO;
417 otype.item.sint32_value =
422 stat = _DtCm_attrs_to_eventtype4(
423 (cms_attribute_value *)
424 (tindex ? attrs[tindex].value : &otype),
425 (cms_attribute_value *)
426 (stindex ? attrs[stindex].value : NULL),
430 if (stat == CSA_SUCCESS) {
432 appt->duration = endtick - appt->appt_id.tick;
433 /* make sure duration is positive */
434 if (appt->duration < 0)
435 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
438 if (appt->period.period != single_4 &&
439 appt->ntimes == CSA_X_DT_DT_REPEAT_FOREVER) {
440 appt->ntimes = _DtCM_OLD_REPEAT_FOREVER;
443 switch (appt->period.period) {
445 if (set_weeknum == B_TRUE)
446 appt->period.nth = week_num;
450 case everyNthMonth_4:
451 if (set_interval == B_TRUE)
452 appt->period.nth = interval;
455 appt->period.nth = 0;
463 extern CSA_return_code
464 _DtCm_cms_entry_to_appt4(cms_entry *entry, Appt_4 **appt4_r)
466 CSA_return_code stat;
469 if (entry == NULL || appt4_r == NULL)
470 return (CSA_E_INVALID_PARAMETER);
472 if ((appt = _DtCm_make_appt4(B_TRUE)) == NULL)
473 return (CSA_E_INSUFFICIENT_MEMORY);
475 if ((stat = _DtCm_cmsattrs_to_apptdata(entry->num_attrs, entry->attrs,
476 appt)) != CSA_SUCCESS) {
477 _DtCm_free_appt4(appt);
481 return (CSA_SUCCESS);
485 extern CSA_return_code
486 _DtCm_attrs_to_appt4(uint num_attrs, CSA_attribute *attrs, Appt_4 **appt4_r)
488 CSA_return_code stat;
492 return (CSA_E_INVALID_PARAMETER);
494 if ((appt = _DtCm_make_appt4(B_TRUE)) == NULL)
495 return (CSA_E_INSUFFICIENT_MEMORY);
497 if ((stat = _DtCm_attrs_to_apptdata(num_attrs, attrs, appt)) != CSA_SUCCESS) {
498 _DtCm_free_appt4(appt);
502 return (CSA_SUCCESS);
506 extern CSA_return_code
507 _DtCm_scope_to_options4(CSA_enum scope, Options_4 *opt)
510 return (CSA_E_INVALID_PARAMETER);
519 case CSA_SCOPE_FORWARD:
523 return (CSA_E_INVALID_ENUM);
526 return (CSA_SUCCESS);
529 extern CSA_return_code
530 _DtCm_csaaccesslist_toaccessentry4(CSA_access_list alist, Access_Entry_4 **a4)
532 CSA_return_code stat = CSA_SUCCESS;
533 Access_Entry_4 *to, *prev, *head;
536 while (alist != NULL) {
537 if ((to = (Access_Entry_4 *)calloc(1, sizeof(Access_Entry_4)))
539 stat = CSA_E_INSUFFICIENT_MEMORY;
543 if ((to->access_type = _DtCmAccessRightToV4AccessType(
544 alist->rights)) < 0) {
545 stat = CSA_E_INVALID_FLAG;
549 if (alist->user == NULL || alist->user->user_name == NULL) {
550 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
554 if ((to->who = strdup(alist->user->user_name)) == NULL) {
556 stat = CSA_E_INSUFFICIENT_MEMORY;
570 if (stat != CSA_SUCCESS) {
571 _DtCm_free_access_list4(head);
580 _DtCm_rtype_to_interval4(int val, Interval_4 *period)
583 case CSA_X_DT_REPEAT_ONETIME:
586 case CSA_X_DT_REPEAT_WEEKLY:
589 case CSA_X_DT_REPEAT_DAILY:
592 case CSA_X_DT_REPEAT_BIWEEKLY:
593 *period = biweekly_4;
595 case CSA_X_DT_REPEAT_MONTHLY_BY_DATE:
598 case CSA_X_DT_REPEAT_YEARLY:
601 case CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY:
602 *period = nthWeekday_4;
604 case CSA_X_DT_REPEAT_EVERY_NDAY:
605 *period = everyNthDay_4;
607 case CSA_X_DT_REPEAT_EVERY_NWEEK:
608 *period = everyNthWeek_4;
610 case CSA_X_DT_REPEAT_EVERY_NMONTH:
611 *period = everyNthMonth_4;
613 case CSA_X_DT_REPEAT_MON_TO_FRI:
614 *period = monThruFri_4;
616 case CSA_X_DT_REPEAT_MONWEDFRI:
617 *period = monWedFri_4;
619 case CSA_X_DT_REPEAT_TUETHUR:
622 case CSA_X_DT_REPEAT_WEEKDAYCOMBO:
623 *period = daysOfWeek_4;
625 case CSA_X_DT_REPEAT_OTHER:
626 *period = otherPeriod_4;
635 _DtCm_status_to_apptstatus4(int val, Appt_Status_4 *astat)
638 case CSA_X_DT_STATUS_ACTIVE:
641 case CSA_STATUS_COMPLETED:
642 *astat = completed_4;
644 case CSA_X_DT_STATUS_CANCELLED:
645 *astat = cancelled_4;
647 case CSA_X_DT_STATUS_COMMITTED:
648 *astat = committed_4;
650 case CSA_X_DT_STATUS_ADD_PENDING:
651 *astat = pendingAdd_4;
653 case CSA_X_DT_STATUS_DELETE_PENDING:
654 *astat = pendingDelete_4;
664 _DtCm_classification_to_privacy4(int val, Privacy_Level_4 *privacy)
667 case CSA_CLASS_PUBLIC:
670 case CSA_CLASS_CONFIDENTIAL:
671 *privacy = semiprivate_4;
673 case CSA_CLASS_PRIVATE:
674 *privacy = private_4;
683 extern CSA_return_code
684 _DtCm_attrs_to_eventtype4(
685 cms_attribute_value *type,
686 cms_attribute_value *stype,
689 CSA_return_code stat = CSA_SUCCESS;
692 switch (type->item.uint32_value) {
695 if (stype && stype->item.string_value) {
696 if (strcmp(stype->item.string_value,
697 CSA_SUBTYPE_APPOINTMENT) == 0)
698 tag->tag = appointment_4;
699 else if (strcmp(stype->item.string_value,
700 CSA_SUBTYPE_HOLIDAY) == 0)
701 tag->tag = holiday_4;
703 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
705 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
711 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
716 case CSA_X_DT_TYPE_OTHER:
719 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
721 tag->tag = otherTag_4;
725 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
728 stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
734 * Get rid of the given reminder in the appt.
736 extern CSA_return_code
737 _DtCm_remove_reminder(char *rem, Appt_4 *appt)
739 Attribute_4 *attr, *prev;
741 for (attr = prev = appt->attr; attr != NULL; attr = attr->next) {
742 if (strcmp(attr->attr, rem) == 0) {
744 appt->attr = attr->next;
746 prev->next = attr->next;
749 _DtCm_free_attr4(attr);
754 return (CSA_SUCCESS);
758 * If the corresponding attribute exists already, replace it.
760 extern CSA_return_code
761 _DtCm_add_reminder(char *rem, CSA_reminder * val, Appt_4 *appt)
763 Attribute_4 *newattr, *attrs, *prev = NULL;
769 if ((val->snooze_time && val->snooze_time[0] != NULL)
770 || val->repeat_count > 1)
771 return (CSA_E_INVALID_ATTRIBUTE_VALUE);
774 if ((newattr = calloc(1, sizeof(Attribute_4))) == NULL)
775 return (CSA_E_INSUFFICIENT_MEMORY);
777 if ((newattr->attr = strdup(rem)) == NULL) {
779 return (CSA_E_INSUFFICIENT_MEMORY);
782 /* convert lead_time to advance value */
784 _csa_iso8601_to_duration(val->lead_time, <ime);
785 sprintf(adv, "%d", ltime);
787 if ((newattr->value = strdup(adv)) == NULL) {
788 _DtCm_free_attr4(newattr);
789 return (CSA_E_INSUFFICIENT_MEMORY);
792 if (val->reminder_data.size > 0) {
793 if ((newattr->clientdata = malloc(val->reminder_data.size + 1))
795 _DtCm_free_attr4(newattr);
796 return (CSA_E_INSUFFICIENT_MEMORY);
798 memcpy(newattr->clientdata, val->reminder_data.data,
799 val->reminder_data.size);
800 newattr->clientdata[val->reminder_data.size] = NULL;
802 } else if ((newattr->clientdata = calloc(1,1)) == NULL) {
803 _DtCm_free_attr4(newattr);
804 return (CSA_E_INSUFFICIENT_MEMORY);
807 for (attrs = appt->attr; attrs != NULL; attrs = attrs->next) {
808 if (strcmp(attrs->attr, rem) == 0) {
810 newattr->next = attrs->next;
812 appt->attr = newattr;
814 prev->next = newattr;
817 _DtCm_free_attr4(attrs);
825 newattr->next = appt->attr;
826 appt->attr = newattr;
829 return (CSA_SUCCESS);
833 _DtCmAccessRightToV4AccessType(unsigned int access)
835 int newaccess = access_none_4;
838 access & ~(CSA_X_DT_BROWSE_ACCESS | CSA_X_DT_INSERT_ACCESS |
839 CSA_X_DT_DELETE_ACCESS))
842 if (access & CSA_X_DT_BROWSE_ACCESS)
843 newaccess |= access_read_4;
844 if (access & CSA_X_DT_INSERT_ACCESS)
845 newaccess |= access_write_4;
846 if (access & CSA_X_DT_DELETE_ACCESS)
847 newaccess |= access_delete_4;