convert5-4.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* $XConsortium: convert5-4.c /main/2 1996/10/07 15:57:11 drk $ */
  24. /*
  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.
  29. */
  30. #include <EUSCompat.h>
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include "convert4-5.h"
  35. #include "convert5-4.h"
  36. #include "attr.h"
  37. #include "appt4.h"
  38. #include "iso8601.h"
  39. /*
  40. * Routines to convert data types used in version 5 to version 4.
  41. */
  42. /*****************************************************************************
  43. * extern functions
  44. *****************************************************************************/
  45. /*
  46. * attributes are checked before calling this routine
  47. * so all attributes should be supported in v4
  48. */
  49. extern CSA_return_code
  50. _DtCm_cmsattrs_to_apptdata(uint size, cms_attribute *attrs, Appt_4 *appt)
  51. {
  52. CSA_return_code stat = CSA_SUCCESS;
  53. char *string, *ptr;
  54. time_t endtick;
  55. cms_attribute *aptr;
  56. char buf[BUFSIZ];
  57. /*
  58. * this routine is called to convert valid v2 to v4 attributes
  59. * so no checking of CSA_E_INVALID_ATTRIBUTE and
  60. * CSA_E_UNSUPPORTED_ATTRIBUTE is necessary
  61. */
  62. /* assuming all appt data is available */
  63. /* start time */
  64. if (_csa_iso8601_to_tick(
  65. attrs[CSA_ENTRY_ATTR_START_DATE_I].value->item.date_time_value,
  66. &appt->appt_id.tick))
  67. return (CSA_E_INVALID_DATE_TIME);
  68. /* duration */
  69. aptr = &attrs[CSA_ENTRY_ATTR_END_DATE_I];
  70. if (aptr->value && aptr->value->item.date_time_value &&
  71. *(aptr->value->item.date_time_value))
  72. {
  73. if (_csa_iso8601_to_tick(aptr->value->item.date_time_value,
  74. &endtick))
  75. return (CSA_E_INVALID_DATE_TIME);
  76. else
  77. appt->duration = endtick - appt->appt_id.tick;
  78. }
  79. /* id */
  80. aptr = &attrs[CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I];
  81. if (aptr->value && aptr->value->item.opaque_data_value &&
  82. aptr->value->item.opaque_data_value->size > 0)
  83. {
  84. strncpy(buf, (char *)aptr->value->item.opaque_data_value->data,
  85. aptr->value->item.opaque_data_value->size);
  86. buf[aptr->value->item.opaque_data_value->size] = '\0';
  87. ptr = strchr(buf, ':');
  88. if (ptr != NULL)
  89. *ptr = '\0';
  90. appt->appt_id.key = atol(buf);
  91. } else
  92. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  93. /* _DtCm_old_attr_type */
  94. if ((stat = _DtCm_attrs_to_eventtype4(
  95. attrs[CSA_ENTRY_ATTR_TYPE_I].value,
  96. attrs[CSA_ENTRY_ATTR_SUBTYPE_I].value, appt->tag)) != CSA_SUCCESS)
  97. return (stat);
  98. /* _DtCm_old_attr_what */
  99. aptr = &attrs[CSA_ENTRY_ATTR_SUMMARY_I];
  100. if (aptr->value->item.string_value) {
  101. if ((string = strdup(aptr->value->item.string_value)) == NULL)
  102. return (CSA_E_INSUFFICIENT_MEMORY);
  103. else {
  104. if (appt->what)
  105. free(appt->what);
  106. appt->what = string;
  107. }
  108. }
  109. /* _DtCm_old_attr_author */
  110. aptr = &attrs[CSA_ENTRY_ATTR_ORGANIZER_I];
  111. if (aptr->value && aptr->value->item.calendar_user_value) {
  112. if ((string = strdup(aptr->value->item.calendar_user_value))
  113. == NULL)
  114. return (CSA_E_INSUFFICIENT_MEMORY);
  115. else {
  116. if (appt->author)
  117. free(appt->author);
  118. appt->author = string;
  119. }
  120. }
  121. /* _DtCm_old_attr_beep_reminder */
  122. aptr = &attrs[CSA_ENTRY_ATTR_AUDIO_REMINDER_I];
  123. if (aptr->value && aptr->value->item.reminder_value) {
  124. if ((stat = _DtCm_add_reminder(_DtCM_OLD_ATTR_BEEP_REMINDER,
  125. aptr->value->item.reminder_value, appt)) != CSA_SUCCESS)
  126. return (stat);
  127. }
  128. /* _DtCm_old_attr_flash_reminder */
  129. aptr = &attrs[CSA_ENTRY_ATTR_FLASHING_REMINDER_I];
  130. if (aptr->value && aptr->value->item.reminder_value) {
  131. if ((stat = _DtCm_add_reminder(_DtCM_OLD_ATTR_FLASH_REMINDER,
  132. aptr->value->item.reminder_value, appt)) != CSA_SUCCESS)
  133. return (stat);
  134. }
  135. /* _DtCm_old_attr_mail_reminder */
  136. aptr = &attrs[CSA_ENTRY_ATTR_MAIL_REMINDER_I];
  137. if (aptr->value && aptr->value->item.reminder_value) {
  138. if ((stat = _DtCm_add_reminder(_DtCM_OLD_ATTR_MAIL_REMINDER,
  139. aptr->value->item.reminder_value, appt)) != CSA_SUCCESS)
  140. return (stat);
  141. }
  142. /* _DtCm_old_attr_popup_reminder */
  143. aptr = &attrs[CSA_ENTRY_ATTR_POPUP_REMINDER_I];
  144. if (aptr->value && aptr->value->item.reminder_value) {
  145. if ((stat = _DtCm_add_reminder(_DtCM_OLD_ATTR_POPUP_REMINDER,
  146. aptr->value->item.reminder_value, appt)) != CSA_SUCCESS)
  147. return (stat);
  148. }
  149. /* _DtCm_old_attr_repeat_type */
  150. if (_DtCm_rtype_to_interval4(
  151. attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I].value->item.sint32_value,
  152. &appt->period.period))
  153. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  154. /* _DtCm_old_attr_repeat_times */
  155. aptr = &attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I];
  156. if (aptr->value)
  157. 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;
  161. }
  162. /* _DtCm_old_attr_showtime */
  163. aptr = &attrs[CSA_X_DT_ENTRY_ATTR_SHOWTIME_I];
  164. if (aptr->value)
  165. appt->tag->showtime = aptr->value->item.sint32_value;
  166. /* _DtCm_old_attr_status */
  167. if (_DtCm_status_to_apptstatus4(
  168. attrs[CSA_ENTRY_ATTR_STATUS_I].value->item.uint32_value,
  169. &appt->appt_status))
  170. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  171. /* _DtCm_old_attr_privacy */
  172. if (_DtCm_classification_to_privacy4(
  173. attrs[CSA_ENTRY_ATTR_CLASSIFICATION_I].value->item.uint32_value,
  174. &appt->privacy))
  175. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  176. /* _DtCm_old_attr_end_date */
  177. aptr = &attrs[CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I];
  178. if (aptr->value && aptr->value->item.date_time_value &&
  179. *(aptr->value->item.date_time_value))
  180. {
  181. if (_csa_iso8601_to_tick(aptr->value->item.date_time_value,
  182. &appt->period.enddate))
  183. return (CSA_E_INVALID_DATE_TIME);
  184. }
  185. switch (appt->period.period) {
  186. case nthWeekday_4:
  187. /* _DtCm_old_attr_repeat_nth_weeknum */
  188. aptr = &attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I];
  189. if (aptr->value)
  190. appt->period.nth = aptr->value->item.sint32_value;
  191. break;
  192. case everyNthDay_4:
  193. case everyNthWeek_4:
  194. case everyNthMonth_4:
  195. /* _DtCm_old_attr_repeat_nth_interval */
  196. aptr = &attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I];
  197. if (aptr->value)
  198. appt->period.nth = aptr->value->item.uint32_value;
  199. break;
  200. default:
  201. appt->period.nth = 0;
  202. }
  203. return (stat);
  204. }
  205. /*
  206. * ** need to check whether value is valid
  207. */
  208. extern CSA_return_code
  209. _DtCm_attrs_to_apptdata(uint size, CSA_attribute *attrs, Appt_4 *appt)
  210. {
  211. CSA_return_code stat = CSA_SUCCESS;
  212. _DtCm_old_attrs oldattr;
  213. char *string;
  214. int interval = 0, week_num = 0, i;
  215. boolean_t set_interval = B_FALSE, set_weeknum = B_FALSE;
  216. time_t endtick = -1;
  217. int tindex = 0, stindex = 0;
  218. CSA_attribute_value otype;
  219. for (i = 0; i < size && stat == CSA_SUCCESS; i++) {
  220. if (attrs[i].name == NULL)
  221. continue;
  222. if ((stat = _DtCm_get_old_attr_by_name(attrs[i].name, &oldattr))
  223. != CSA_SUCCESS)
  224. break;
  225. switch (oldattr) {
  226. case _DtCm_old_attr_id:
  227. stat = CSA_E_READONLY;
  228. break;
  229. case _DtCm_old_attr_time:
  230. if (attrs[i].value == NULL ||
  231. attrs[i].value->item.date_time_value == NULL ||
  232. _csa_iso8601_to_tick(
  233. attrs[i].value->item.date_time_value,
  234. &appt->appt_id.tick))
  235. stat = CSA_E_INVALID_DATE_TIME;
  236. break;
  237. case _DtCm_old_attr_type:
  238. if (attrs[i].value == NULL)
  239. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  240. else
  241. tindex = i;
  242. break;
  243. case _DtCm_old_attr_type2:
  244. stindex = i;
  245. break;
  246. case _DtCm_old_attr_duration:
  247. if (attrs[i].value == NULL)
  248. appt->duration = 0;
  249. else if (attrs[i].value->item.date_time_value
  250. == NULL || _csa_iso8601_to_tick(
  251. attrs[i].value->item.date_time_value,
  252. &endtick))
  253. stat = CSA_E_INVALID_DATE_TIME;
  254. break;
  255. case _DtCm_old_attr_what:
  256. if (attrs[i].value && attrs[i].value->item.string_value)
  257. {
  258. if ((string = strdup(
  259. attrs[i].value->item.string_value))
  260. == NULL)
  261. stat = CSA_E_INSUFFICIENT_MEMORY;
  262. else {
  263. if (appt->what)
  264. free(appt->what);
  265. appt->what = string;
  266. }
  267. }
  268. break;
  269. case _DtCm_old_attr_author:
  270. stat = CSA_E_READONLY;
  271. break;
  272. case _DtCm_old_attr_beep_reminder:
  273. if (attrs[i].value == NULL)
  274. stat = _DtCm_remove_reminder(
  275. _DtCM_OLD_ATTR_BEEP_REMINDER, appt);
  276. else if (attrs[i].value->item.reminder_value == NULL)
  277. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  278. else
  279. stat = _DtCm_add_reminder(
  280. _DtCM_OLD_ATTR_BEEP_REMINDER,
  281. attrs[i].value->item.reminder_value,
  282. appt);
  283. break;
  284. case _DtCm_old_attr_flash_reminder:
  285. if (attrs[i].value == NULL)
  286. stat = _DtCm_remove_reminder(
  287. _DtCM_OLD_ATTR_FLASH_REMINDER, appt);
  288. else if (attrs[i].value->item.reminder_value == NULL)
  289. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  290. else
  291. stat = _DtCm_add_reminder(
  292. _DtCM_OLD_ATTR_FLASH_REMINDER,
  293. attrs[i].value->item.reminder_value,
  294. appt);
  295. break;
  296. case _DtCm_old_attr_mail_reminder:
  297. if (attrs[i].value == NULL)
  298. stat = _DtCm_remove_reminder(
  299. _DtCM_OLD_ATTR_MAIL_REMINDER, appt);
  300. else if (attrs[i].value->item.reminder_value == NULL)
  301. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  302. else
  303. stat = _DtCm_add_reminder(
  304. _DtCM_OLD_ATTR_MAIL_REMINDER,
  305. attrs[i].value->item.reminder_value,
  306. appt);
  307. break;
  308. case _DtCm_old_attr_popup_reminder:
  309. if (attrs[i].value == NULL)
  310. stat = _DtCm_remove_reminder(
  311. _DtCM_OLD_ATTR_POPUP_REMINDER, appt);
  312. else if (attrs[i].value->item.reminder_value == NULL)
  313. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  314. else
  315. stat = _DtCm_add_reminder(
  316. _DtCM_OLD_ATTR_POPUP_REMINDER,
  317. attrs[i].value->item.reminder_value,
  318. appt);
  319. break;
  320. case _DtCm_old_attr_repeat_type:
  321. if (attrs[i].value == NULL)
  322. appt->period.period = single_4;
  323. else if (_DtCm_rtype_to_interval4(
  324. attrs[i].value->item.sint32_value,
  325. &appt->period.period))
  326. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  327. break;
  328. case _DtCm_old_attr_repeat_times:
  329. if (attrs[i].value == NULL)
  330. appt->ntimes = 1;
  331. else
  332. appt->ntimes =
  333. attrs[i].value->item.uint32_value;
  334. break;
  335. case _DtCm_old_attr_showtime:
  336. if (attrs[i].value == NULL)
  337. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  338. else
  339. appt->tag->showtime =
  340. attrs[i].value->item.sint32_value;
  341. break;
  342. case _DtCm_old_attr_status:
  343. if (attrs[i].value == NULL)
  344. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  345. else if (_DtCm_status_to_apptstatus4(
  346. attrs[i].value->item.sint32_value,
  347. &appt->appt_status))
  348. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  349. break;
  350. case _DtCm_old_attr_privacy:
  351. if (attrs[i].value == NULL)
  352. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  353. else if (_DtCm_classification_to_privacy4(
  354. attrs[i].value->item.sint32_value,
  355. &appt->privacy))
  356. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  357. break;
  358. case _DtCm_old_attr_repeat_nth_interval:
  359. if (attrs[i].value != NULL) {
  360. set_interval = B_TRUE;
  361. interval = attrs[i].value->item.uint32_value;
  362. }
  363. break;
  364. case _DtCm_old_attr_repeat_nth_weeknum:
  365. if (attrs[i].value != NULL) {
  366. set_weeknum = B_TRUE;
  367. week_num = attrs[i].value->item.sint32_value;
  368. }
  369. break;
  370. case _DtCm_old_attr_end_date:
  371. if (attrs[i].value == NULL)
  372. appt->period.enddate = 0;
  373. else if (attrs[i].value->item.date_time_value == NULL ||
  374. _csa_iso8601_to_tick(
  375. attrs[i].value->item.date_time_value,
  376. &appt->period.enddate))
  377. stat = CSA_E_INVALID_DATE_TIME;
  378. break;
  379. default:
  380. stat = CSA_E_INVALID_PARAMETER;
  381. }
  382. }
  383. if (stat == CSA_SUCCESS) {
  384. if (tindex || stindex) {
  385. if (tindex == 0) {
  386. otype.type = CSA_VALUE_SINT32;
  387. switch (appt->tag->tag) {
  388. case appointment_4:
  389. case holiday_4:
  390. otype.item.sint32_value =
  391. CSA_TYPE_EVENT;
  392. break;
  393. case toDo_4:
  394. otype.item.sint32_value = CSA_TYPE_TODO;
  395. break;
  396. case reminder_4:
  397. case otherTag_4:
  398. otype.item.sint32_value =
  399. CSA_X_DT_TYPE_OTHER;
  400. }
  401. }
  402. stat = _DtCm_attrs_to_eventtype4(
  403. (cms_attribute_value *)
  404. (tindex ? attrs[tindex].value : &otype),
  405. (cms_attribute_value *)
  406. (stindex ? attrs[stindex].value : NULL),
  407. appt->tag);
  408. }
  409. if (stat == CSA_SUCCESS) {
  410. if (endtick >= 0) {
  411. appt->duration = endtick - appt->appt_id.tick;
  412. /* make sure duration is positive */
  413. if (appt->duration < 0)
  414. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  415. }
  416. if (appt->period.period != single_4 &&
  417. appt->ntimes == CSA_X_DT_DT_REPEAT_FOREVER) {
  418. appt->ntimes = _DtCM_OLD_REPEAT_FOREVER;
  419. }
  420. switch (appt->period.period) {
  421. case nthWeekday_4:
  422. if (set_weeknum == B_TRUE)
  423. appt->period.nth = week_num;
  424. break;
  425. case everyNthDay_4:
  426. case everyNthWeek_4:
  427. case everyNthMonth_4:
  428. if (set_interval == B_TRUE)
  429. appt->period.nth = interval;
  430. break;
  431. default:
  432. appt->period.nth = 0;
  433. }
  434. }
  435. }
  436. return (stat);
  437. }
  438. extern CSA_return_code
  439. _DtCm_cms_entry_to_appt4(cms_entry *entry, Appt_4 **appt4_r)
  440. {
  441. CSA_return_code stat;
  442. Appt_4 *appt;
  443. if (entry == NULL || appt4_r == NULL)
  444. return (CSA_E_INVALID_PARAMETER);
  445. if ((appt = _DtCm_make_appt4(B_TRUE)) == NULL)
  446. return (CSA_E_INSUFFICIENT_MEMORY);
  447. if ((stat = _DtCm_cmsattrs_to_apptdata(entry->num_attrs, entry->attrs,
  448. appt)) != CSA_SUCCESS) {
  449. _DtCm_free_appt4(appt);
  450. return (stat);
  451. } else {
  452. *appt4_r = appt;
  453. return (CSA_SUCCESS);
  454. }
  455. }
  456. extern CSA_return_code
  457. _DtCm_attrs_to_appt4(uint num_attrs, CSA_attribute *attrs, Appt_4 **appt4_r)
  458. {
  459. CSA_return_code stat;
  460. Appt_4 *appt;
  461. if (appt4_r == NULL)
  462. return (CSA_E_INVALID_PARAMETER);
  463. if ((appt = _DtCm_make_appt4(B_TRUE)) == NULL)
  464. return (CSA_E_INSUFFICIENT_MEMORY);
  465. if ((stat = _DtCm_attrs_to_apptdata(num_attrs, attrs, appt)) != CSA_SUCCESS) {
  466. _DtCm_free_appt4(appt);
  467. return (stat);
  468. } else {
  469. *appt4_r = appt;
  470. return (CSA_SUCCESS);
  471. }
  472. }
  473. extern CSA_return_code
  474. _DtCm_scope_to_options4(CSA_enum scope, Options_4 *opt)
  475. {
  476. if (opt == NULL)
  477. return (CSA_E_INVALID_PARAMETER);
  478. switch (scope) {
  479. case CSA_SCOPE_ONE:
  480. *opt = do_one_4;
  481. break;
  482. case CSA_SCOPE_ALL:
  483. *opt = do_all_4;
  484. break;
  485. case CSA_SCOPE_FORWARD:
  486. *opt = do_forward_4;
  487. break;
  488. default:
  489. return (CSA_E_INVALID_ENUM);
  490. }
  491. return (CSA_SUCCESS);
  492. }
  493. extern CSA_return_code
  494. _DtCm_csaaccesslist_toaccessentry4(CSA_access_list alist, Access_Entry_4 **a4)
  495. {
  496. CSA_return_code stat = CSA_SUCCESS;
  497. Access_Entry_4 *to, *prev, *head;
  498. head = prev = NULL;
  499. while (alist != NULL) {
  500. if ((to = (Access_Entry_4 *)calloc(1, sizeof(Access_Entry_4)))
  501. == NULL) {
  502. stat = CSA_E_INSUFFICIENT_MEMORY;
  503. break;
  504. }
  505. if ((to->access_type = _DtCmAccessRightToV4AccessType(
  506. alist->rights)) < 0) {
  507. stat = CSA_E_INVALID_FLAG;
  508. break;
  509. }
  510. if (alist->user == NULL || alist->user->user_name == NULL) {
  511. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  512. break;
  513. }
  514. if ((to->who = strdup(alist->user->user_name)) == NULL) {
  515. free(to);
  516. stat = CSA_E_INSUFFICIENT_MEMORY;
  517. break;
  518. }
  519. if (head == NULL)
  520. head = to;
  521. else
  522. prev->next = to;
  523. prev = to;
  524. alist = alist->next;
  525. }
  526. if (stat != CSA_SUCCESS) {
  527. _DtCm_free_access_list4(head);
  528. head = NULL;
  529. }
  530. *a4 = head;
  531. return (stat);
  532. }
  533. extern int
  534. _DtCm_rtype_to_interval4(int val, Interval_4 *period)
  535. {
  536. switch (val) {
  537. case CSA_X_DT_REPEAT_ONETIME:
  538. *period = single_4;
  539. break;
  540. case CSA_X_DT_REPEAT_WEEKLY:
  541. *period = weekly_4;
  542. break;
  543. case CSA_X_DT_REPEAT_DAILY:
  544. *period = daily_4;
  545. break;
  546. case CSA_X_DT_REPEAT_BIWEEKLY:
  547. *period = biweekly_4;
  548. break;
  549. case CSA_X_DT_REPEAT_MONTHLY_BY_DATE:
  550. *period = monthly_4;
  551. break;
  552. case CSA_X_DT_REPEAT_YEARLY:
  553. *period = yearly_4;
  554. break;
  555. case CSA_X_DT_REPEAT_MONTHLY_BY_WEEKDAY:
  556. *period = nthWeekday_4;
  557. break;
  558. case CSA_X_DT_REPEAT_EVERY_NDAY:
  559. *period = everyNthDay_4;
  560. break;
  561. case CSA_X_DT_REPEAT_EVERY_NWEEK:
  562. *period = everyNthWeek_4;
  563. break;
  564. case CSA_X_DT_REPEAT_EVERY_NMONTH:
  565. *period = everyNthMonth_4;
  566. break;
  567. case CSA_X_DT_REPEAT_MON_TO_FRI:
  568. *period = monThruFri_4;
  569. break;
  570. case CSA_X_DT_REPEAT_MONWEDFRI:
  571. *period = monWedFri_4;
  572. break;
  573. case CSA_X_DT_REPEAT_TUETHUR:
  574. *period = tueThur_4;
  575. break;
  576. case CSA_X_DT_REPEAT_WEEKDAYCOMBO:
  577. *period = daysOfWeek_4;
  578. break;
  579. case CSA_X_DT_REPEAT_OTHER:
  580. *period = otherPeriod_4;
  581. break;
  582. default:
  583. return (-1);
  584. }
  585. return (0);
  586. }
  587. extern int
  588. _DtCm_status_to_apptstatus4(int val, Appt_Status_4 *astat)
  589. {
  590. switch (val) {
  591. case CSA_X_DT_STATUS_ACTIVE:
  592. *astat = active_4;
  593. break;
  594. case CSA_STATUS_COMPLETED:
  595. *astat = completed_4;
  596. break;
  597. case CSA_X_DT_STATUS_CANCELLED:
  598. *astat = cancelled_4;
  599. break;
  600. case CSA_X_DT_STATUS_COMMITTED:
  601. *astat = committed_4;
  602. break;
  603. case CSA_X_DT_STATUS_ADD_PENDING:
  604. *astat = pendingAdd_4;
  605. break;
  606. case CSA_X_DT_STATUS_DELETE_PENDING:
  607. *astat = pendingDelete_4;
  608. break;
  609. default:
  610. return (-1);
  611. }
  612. return (0);
  613. }
  614. extern int
  615. _DtCm_classification_to_privacy4(int val, Privacy_Level_4 *privacy)
  616. {
  617. switch (val) {
  618. case CSA_CLASS_PUBLIC:
  619. *privacy = public_4;
  620. break;
  621. case CSA_CLASS_CONFIDENTIAL:
  622. *privacy = semiprivate_4;
  623. break;
  624. case CSA_CLASS_PRIVATE:
  625. *privacy = private_4;
  626. break;
  627. default:
  628. return (-1);
  629. }
  630. return (0);
  631. }
  632. extern CSA_return_code
  633. _DtCm_attrs_to_eventtype4(
  634. cms_attribute_value *type,
  635. cms_attribute_value *stype,
  636. Tag_4 *tag)
  637. {
  638. CSA_return_code stat = CSA_SUCCESS;
  639. if (type) {
  640. switch (type->item.uint32_value) {
  641. case CSA_TYPE_EVENT:
  642. if (stype && stype->item.string_value) {
  643. if (strcmp(stype->item.string_value,
  644. CSA_SUBTYPE_APPOINTMENT) == 0)
  645. tag->tag = appointment_4;
  646. else if (strcmp(stype->item.string_value,
  647. CSA_SUBTYPE_HOLIDAY) == 0)
  648. tag->tag = holiday_4;
  649. else
  650. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  651. } else
  652. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  653. break;
  654. case CSA_TYPE_TODO:
  655. if (stype)
  656. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  657. else
  658. tag->tag = toDo_4;
  659. break;
  660. case CSA_X_DT_TYPE_OTHER:
  661. if (stype)
  662. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  663. else
  664. tag->tag = otherTag_4;
  665. break;
  666. default:
  667. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  668. }
  669. } else
  670. stat = CSA_E_INVALID_ATTRIBUTE_VALUE;
  671. return (stat);
  672. }
  673. /*
  674. * Get rid of the given reminder in the appt.
  675. */
  676. extern CSA_return_code
  677. _DtCm_remove_reminder(char *rem, Appt_4 *appt)
  678. {
  679. Attribute_4 *attr, *prev;
  680. for (attr = prev = appt->attr; attr != NULL; attr = attr->next) {
  681. if (strcmp(attr->attr, rem) == 0) {
  682. if (prev == attr)
  683. appt->attr = attr->next;
  684. else
  685. prev->next = attr->next;
  686. attr->next = NULL;
  687. _DtCm_free_attr4(attr);
  688. } else
  689. prev = attr;
  690. }
  691. return (CSA_SUCCESS);
  692. }
  693. /*
  694. * If the corresponding attribute exists already, replace it.
  695. */
  696. extern CSA_return_code
  697. _DtCm_add_reminder(char *rem, CSA_reminder * val, Appt_4 *appt)
  698. {
  699. Attribute_4 *newattr, *attrs, *prev = NULL;
  700. char adv[80];
  701. time_t ltime = 0;
  702. /*
  703. if ((val->snooze_time && val->snooze_time[0] != NULL)
  704. || val->repeat_count > 1)
  705. return (CSA_E_INVALID_ATTRIBUTE_VALUE);
  706. */
  707. if ((newattr = calloc(1, sizeof(Attribute_4))) == NULL)
  708. return (CSA_E_INSUFFICIENT_MEMORY);
  709. if ((newattr->attr = strdup(rem)) == NULL) {
  710. free(newattr);
  711. return (CSA_E_INSUFFICIENT_MEMORY);
  712. }
  713. /* convert lead_time to advance value */
  714. if (val->lead_time)
  715. _csa_iso8601_to_duration(val->lead_time, &ltime);
  716. sprintf(adv, "%ld", ltime);
  717. if ((newattr->value = strdup(adv)) == NULL) {
  718. _DtCm_free_attr4(newattr);
  719. return (CSA_E_INSUFFICIENT_MEMORY);
  720. }
  721. if (val->reminder_data.size > 0) {
  722. if ((newattr->clientdata = malloc(val->reminder_data.size + 1))
  723. == NULL) {
  724. _DtCm_free_attr4(newattr);
  725. return (CSA_E_INSUFFICIENT_MEMORY);
  726. }
  727. memcpy(newattr->clientdata, val->reminder_data.data,
  728. val->reminder_data.size);
  729. newattr->clientdata[val->reminder_data.size] = '\0';
  730. } else if ((newattr->clientdata = calloc(1,1)) == NULL) {
  731. _DtCm_free_attr4(newattr);
  732. return (CSA_E_INSUFFICIENT_MEMORY);
  733. }
  734. for (attrs = appt->attr; attrs != NULL; attrs = attrs->next) {
  735. if (strcmp(attrs->attr, rem) == 0) {
  736. newattr->next = attrs->next;
  737. if (prev == NULL)
  738. appt->attr = newattr;
  739. else
  740. prev->next = newattr;
  741. attrs->next = NULL;
  742. _DtCm_free_attr4(attrs);
  743. break;
  744. } else
  745. prev = attrs;
  746. }
  747. if (attrs == NULL) {
  748. newattr->next = appt->attr;
  749. appt->attr = newattr;
  750. }
  751. return (CSA_SUCCESS);
  752. }
  753. extern int
  754. _DtCmAccessRightToV4AccessType(unsigned int access)
  755. {
  756. int newaccess = access_none_4;
  757. if (access < 0 ||
  758. access & ~(CSA_X_DT_BROWSE_ACCESS | CSA_X_DT_INSERT_ACCESS |
  759. CSA_X_DT_DELETE_ACCESS))
  760. return (-1);
  761. if (access & CSA_X_DT_BROWSE_ACCESS)
  762. newaccess |= access_read_4;
  763. if (access & CSA_X_DT_INSERT_ACCESS)
  764. newaccess |= access_write_4;
  765. if (access & CSA_X_DT_DELETE_ACCESS)
  766. newaccess |= access_delete_4;
  767. return (newaccess);
  768. }