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: convert4-5.c /main/1 1996/04/21 19:22:49 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.
32 * Routines to convert data types used in version 4 to version 5.
35 #include <EUSCompat.h>
42 #include "convert4-5.h"
47 #define V4_ATTR_NUM 13
50 * forward declaration of static functions
52 static unsigned int accesstype4_to_accessright(int access);
53 static CSA_return_code eventtype4_to_attrs(Event_Type_4 tag, uint num_attrs,
54 cms_attribute *attrs);
55 static CSA_return_code _RepeatInfoToRule(Appt_4 *a4,
56 cms_attribute_value **attrval);
58 /*****************************************************************************
60 *****************************************************************************/
62 extern CSA_return_code
63 _DtCm_accessentry4_to_cmsaccesslist(
65 cms_access_entry **alist)
67 CSA_return_code stat = CSA_SUCCESS;
68 cms_access_entry *to, *head, *prev;
72 if ((to = (cms_access_entry *)calloc(1,
73 sizeof(cms_access_entry))) == NULL) {
74 stat = CSA_E_INSUFFICIENT_MEMORY;
78 if (a4->who && (to->user = strdup(a4->who)) == NULL) {
80 stat = CSA_E_INSUFFICIENT_MEMORY;
84 to->rights = accesstype4_to_accessright(a4->access_type);
97 if (stat != CSA_SUCCESS) {
98 _DtCm_free_cms_access_entry(head);
106 extern CSA_return_code
107 _DtCm_appt4_to_attrs(
111 cms_attribute *attrs,
114 CSA_return_code stat = CSA_SUCCESS;
115 Attribute_4 *reminders = a4->attr;
121 if (a4 == NULL || num_attrs < _DtCM_DEFINED_ENTRY_ATTR_SIZE)
122 return (CSA_E_INVALID_PARAMETER);
124 /* exception info is not converted since it's not used
125 * and we don't have an attribute for it yet
128 while (stat == CSA_SUCCESS && reminders != NULL) {
130 _DtCm_old_reminder_name_to_index(reminders->attr)) >= 0) {
131 if ((stat = _DtCmAttr4ToReminderValue(reminders,
132 &attrs[index].value)) != CSA_SUCCESS) {
136 reminders = reminders->next;
139 /* only contains the id now, need to
140 * add calendar name and location info
142 if (a4->appt_id.key > 0) {
143 ptr1 = strchr(calname, '@');
144 ptr2 = (ptr1 ? strchr(ptr1, '.') : NULL);
147 snprintf(buf, sizeof buf, "%ld:%s%s%s", a4->appt_id.key, calname,
148 (ptr2 == NULL ? "." : ""),
149 (ptr2 == NULL ? _DtCmGetLocalDomain(ptr1+1) :
152 snprintf(buf, sizeof buf, "%ld:%s@%s", a4->appt_id.key, calname,
153 _DtCmGetHostAtDomain());
155 opq.size = strlen(buf);
156 opq.data = (unsigned char *)buf;
159 if (a4->period.period != single_4 &&
160 a4->ntimes == _DtCM_OLD_REPEAT_FOREVER)
161 ntimes = CSA_X_DT_DT_REPEAT_FOREVER;
165 /* convert tick to iso8601 */
167 if (stat != CSA_SUCCESS || (a4->appt_id.key > 0 &&
168 (stat = _DtCm_set_opaque_attrval(&opq,
169 &attrs[CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I].value))))
171 else if ((stat = _csa_tick_to_iso8601(a4->appt_id.tick, buf) ?
172 CSA_E_INVALID_DATE_TIME : CSA_SUCCESS) ||
173 (stat = _DtCm_set_string_attrval(buf,
174 &attrs[CSA_ENTRY_ATTR_START_DATE_I].value,CSA_VALUE_DATE_TIME)))
176 else if (stat = eventtype4_to_attrs(a4->tag->tag, num_attrs, attrs))
178 else if (stat = _DtCm_set_sint32_attrval(a4->tag->showtime,
179 &attrs[CSA_X_DT_ENTRY_ATTR_SHOWTIME_I].value))
181 else if ((stat = _csa_tick_to_iso8601(a4->appt_id.tick + a4->duration,
182 buf) ? CSA_E_INVALID_DATE_TIME : CSA_SUCCESS) ||
183 (stat = _DtCm_set_string_attrval(buf,
184 &attrs[CSA_ENTRY_ATTR_END_DATE_I].value, CSA_VALUE_DATE_TIME)))
186 else if (stat = _DtCm_set_string_attrval(a4->what,
187 &attrs[CSA_ENTRY_ATTR_SUMMARY_I].value, CSA_VALUE_STRING))
189 else if (stat = _DtCm_set_user_attrval(a4->author,
190 &attrs[CSA_ENTRY_ATTR_ORGANIZER_I].value))
192 else if (stat = _DtCm_set_uint32_attrval(_DtCm_apptstatus4_to_status(
193 a4->appt_status), &attrs[CSA_ENTRY_ATTR_STATUS_I].value))
195 else if (stat = _DtCm_set_uint32_attrval(
196 _DtCm_privacy4_to_classification(a4->privacy),
197 &attrs[CSA_ENTRY_ATTR_CLASSIFICATION_I].value))
199 else if (rerule && (stat = _RepeatInfoToRule(a4,
200 &attrs[CSA_ENTRY_ATTR_RECURRENCE_RULE_I].value)))
203 ((stat = _DtCm_set_uint32_attrval(ntimes,
204 &attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I].value)) ||
205 (stat = _DtCm_set_sint32_attrval(_DtCm_interval4_to_rtype(
207 &attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I].value)) ||
208 (a4->period.period == nthWeekday_4 &&
209 (stat = _DtCm_set_sint32_attrval(a4->period.nth, &attrs\
210 [CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I].value))) ||
211 (a4->period.period >= everyNthDay_4 &&
212 a4->period.period <= everyNthMonth_4 &&
213 (stat = _DtCm_set_uint32_attrval(a4->period.nth, &attrs\
214 [CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I].value))) ||
215 (a4->period.enddate != 0 &&
216 ((stat = _csa_tick_to_iso8601(a4->period.enddate, buf) ?
217 CSA_E_INVALID_DATE_TIME : CSA_SUCCESS) ||
218 (stat = _DtCm_set_string_attrval(buf, &attrs\
219 [CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I].value,
220 CSA_VALUE_DATE_TIME))))))
223 return (CSA_SUCCESS);
226 /* something wrong, need cleanup */
227 /* free up all attribute values set so far */
233 _DtCm_eventtype4_to_type(Event_Type_4 tag)
238 return (CSA_TYPE_EVENT);
241 return (CSA_TYPE_TODO);
246 return (CSA_X_DT_TYPE_OTHER);
251 _DtCm_eventtype4_to_subtype(Event_Type_4 tag)
255 return (CSA_SUBTYPE_APPOINTMENT);
257 return (CSA_SUBTYPE_HOLIDAY);
267 _DtCm_interval4_to_rtype(Interval_4 val)
271 return (CSA_X_DT_REPEAT_ONETIME);
273 return (CSA_X_DT_REPEAT_WEEKLY);
275 return (CSA_X_DT_REPEAT_DAILY);
277 return (CSA_X_DT_REPEAT_BIWEEKLY);
279 return (CSA_X_DT_REPEAT_MONTHLY_BY_DATE);
281 return (CSA_X_DT_REPEAT_YEARLY);
283 return (CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY);
285 return (CSA_X_DT_REPEAT_EVERY_NDAY);
287 return (CSA_X_DT_REPEAT_EVERY_NWEEK);
288 case everyNthMonth_4:
289 return (CSA_X_DT_REPEAT_EVERY_NMONTH);
291 return (CSA_X_DT_REPEAT_MON_TO_FRI);
293 return (CSA_X_DT_REPEAT_MONWEDFRI);
295 return (CSA_X_DT_REPEAT_TUETHUR);
297 return (CSA_X_DT_REPEAT_WEEKDAYCOMBO);
300 return (CSA_X_DT_REPEAT_OTHER);
305 _DtCm_apptstatus4_to_status(Appt_Status_4 stat)
309 return (CSA_X_DT_STATUS_ACTIVE);
311 return (CSA_STATUS_COMPLETED);
313 return (CSA_X_DT_STATUS_ADD_PENDING);
314 case pendingDelete_4:
315 return (CSA_X_DT_STATUS_DELETE_PENDING);
317 return (CSA_X_DT_STATUS_COMMITTED);
319 return (CSA_X_DT_STATUS_CANCELLED);
321 return (CSA_X_DT_STATUS_ACTIVE);
326 _DtCm_privacy4_to_classification(Privacy_Level_4 p)
330 return (CSA_CLASS_PUBLIC);
332 return (CSA_CLASS_CONFIDENTIAL);
334 return (CSA_CLASS_PRIVATE);
336 return (CSA_CLASS_PUBLIC);
340 /******************************************************************************
341 * static functions used within the file
342 ******************************************************************************/
345 * Static functions used within the file.
349 * DtCM_PERMIT_ACCESS is added for backward compatibility
352 accesstype4_to_accessright(int access)
354 unsigned int newaccess = 0;
356 if (access & access_read_4)
357 newaccess |= CSA_X_DT_BROWSE_ACCESS;
358 if (access & access_write_4)
359 newaccess |= CSA_X_DT_INSERT_ACCESS;
360 if (access & access_delete_4)
361 newaccess |= CSA_X_DT_DELETE_ACCESS;
366 extern CSA_return_code
367 _DtCmAttr4ToReminderValue(
369 cms_attribute_value **attrval)
372 char timestr[BUFSIZ];
375 * rval is just a place holder, values will be
376 * copied in _DtCm_set_reminder_attrval
378 _csa_duration_to_iso8601(atoi(remval->value), timestr);
379 rval.lead_time = timestr;
381 if (remval->clientdata && *remval->clientdata != '\0') {
382 rval.reminder_data.size = strlen(remval->clientdata);
383 rval.reminder_data.data = (unsigned char *)remval->clientdata;
385 rval.reminder_data.size = 0;
386 rval.reminder_data.data = NULL;
389 rval.snooze_time = NULL;
390 rval.repeat_count = 0;
392 return (_DtCm_set_reminder_attrval(&rval, attrval));
395 static CSA_return_code
396 eventtype4_to_attrs(Event_Type_4 tag, uint num_attrs, cms_attribute *attrs)
398 CSA_return_code stat;
402 if ((stat = _DtCm_set_uint32_attrval(CSA_TYPE_EVENT,
403 &attrs[CSA_ENTRY_ATTR_TYPE_I].value)) != CSA_SUCCESS)
406 return (_DtCm_set_string_attrval(CSA_SUBTYPE_APPOINTMENT,
407 &attrs[CSA_ENTRY_ATTR_SUBTYPE_I].value,
411 return (_DtCm_set_uint32_attrval(CSA_TYPE_TODO,
412 &attrs[CSA_ENTRY_ATTR_TYPE_I].value));
415 if ((stat = _DtCm_set_uint32_attrval(CSA_TYPE_EVENT,
416 &attrs[CSA_ENTRY_ATTR_TYPE_I].value)) != CSA_SUCCESS)
419 return (_DtCm_set_string_attrval(CSA_SUBTYPE_HOLIDAY,
420 &attrs[CSA_ENTRY_ATTR_SUBTYPE_I].value,
426 return (_DtCm_set_uint32_attrval(CSA_X_DT_TYPE_OTHER,
427 &attrs[CSA_ENTRY_ATTR_TYPE_I].value));
431 static CSA_return_code
432 _RepeatInfoToRule(Appt_4 *a4, cms_attribute_value **attrval)
434 char buf[BUFSIZ], datestr[25];
437 if (a4->period.period == single_4 || a4->period.period == otherPeriod_4) {
439 return (CSA_SUCCESS);
442 if (a4->ntimes == _DtCM_OLD_REPEAT_FOREVER) {
444 } else if (a4->period.period >= everyNthDay_4 &&
445 a4->period.period <= everyNthMonth_4) {
446 duration = ((a4->ntimes % a4->period.nth) ? 1 : 0) +
447 a4->ntimes/a4->period.nth;
449 duration = a4->ntimes;
451 switch (a4->period.period) {
453 snprintf(buf, sizeof buf, "D1 #%d ", duration);
456 snprintf(buf, sizeof buf, "W1 #%d ", duration);
459 snprintf(buf, sizeof buf, "W2 #%d ", duration);
462 snprintf(buf, sizeof buf, "MD1 #%d ", duration);
465 snprintf(buf, sizeof buf, "YM1 #%d ", duration);
468 snprintf(buf, sizeof buf, "MP1 #%d ", duration);
471 snprintf(buf, sizeof buf, "D%d #%d ", a4->period.nth, duration);
474 snprintf(buf, sizeof buf, "W%d #%d ", a4->period.nth, duration);
476 case everyNthMonth_4:
477 snprintf(buf, sizeof buf, "MD%d #%d ", a4->period.nth, duration);
480 snprintf(buf, sizeof buf, "W1 MO TU WE TH FR #%d ", duration);
483 snprintf(buf, sizeof buf, "W1 MO WE FR #%d ", duration);
486 snprintf(buf, sizeof buf, "W1 TU TH #%d ", duration);
489 snprintf(buf, sizeof buf, "W1 #%d ", duration);
490 /* XXX strcat is unsafe here */
491 if (a4->period.nth & 0x1) strcat(buf, "SU ");
492 if (a4->period.nth & 0x2) strcat(buf, "MO ");
493 if (a4->period.nth & 0x4) strcat(buf, "TU ");
494 if (a4->period.nth & 0x8) strcat(buf, "WE ");
495 if (a4->period.nth & 0x10) strcat(buf, "TH ");
496 if (a4->period.nth & 0x20) strcat(buf, "FR ");
497 if (a4->period.nth & 0x40) strcat(buf, "SA ");
501 if (a4->period.enddate) {
502 if (_csa_tick_to_iso8601(a4->period.enddate, datestr))
503 return (CSA_E_INVALID_DATE_TIME);
504 strcat(buf, datestr);
507 return (_DtCm_set_string_attrval(buf, attrval, CSA_VALUE_STRING));