convert2-4.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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: convert2-4.c /main/1 1996/04/21 19:22:26 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 <string.h>
  32. #include <stdlib.h>
  33. #include "rtable2.h"
  34. #include "rtable4.h"
  35. #include "convert2-4.h"
  36. /*
  37. * forward declaration of static functions
  38. */
  39. static Buffer_4 buffer2_to_buffer4(Buffer_2 b);
  40. static void period2_to_period4(Period_2 p2, Period_4 *p4);
  41. static void tag2_to_tag4(Tag_2 t2, Tag_4 *t4);
  42. static Attribute_4 * attr2_to_attr4(Attribute_2 *a2);
  43. static Except_4 * except2_to_except4(Except_2 *e2);
  44. static void id2_to_id4(Id_2 *from, Id_4 *to);
  45. static Uid_4 * uid2_to_uid4(Uid_2 *ui2);
  46. static Appt_4 * appt2_to_appt4(Appt_2 *a2);
  47. static Abb_Appt_4 * abb2_to_abb4(Abb_Appt_2 *a2);
  48. static void apptid2_to_apptid4(Apptid_2 *from, Apptid_4 *to);
  49. static Reminder_4 * reminder2_to_reminder4(Reminder_2 *r2);
  50. static Table_Res_Type_4 tablerestype2_to_tablerestype4(Table_Res_Type_2 t);
  51. static void tablereslist2_to_tablereslist4(Table_Res_List_2 *from,
  52. Table_Res_List_4 *to);
  53. static Access_Entry_4 * acclist2_to_acclist4(Access_Entry_2 *l2);
  54. static Range_4 * range2_to_range4(Range_2 *r2);
  55. static Table_Args_Type_4 argstag2_to_argstag4(Table_Args_Type_2 t);
  56. static void args2_to_args4(Args_2 *from, Args_4 *to);
  57. static Uidopt_4 * uid2_to_uidopt(Uid_2 *uid2, Options_4 opt);
  58. /**************** DATA TYPE (2->4) CONVERSION ROUTINES **************/
  59. extern Access_Status_4
  60. _DtCm_accstat2_to_accstat4(Access_Status_2 s)
  61. {
  62. switch (s) {
  63. case access_ok_2:
  64. return(access_ok_4);
  65. case access_added_2:
  66. return(access_added_4);
  67. case access_removed_2:
  68. return(access_removed_4);
  69. case access_failed_2:
  70. return(access_failed_4);
  71. case access_exists_2:
  72. return(access_exists_4);
  73. case access_partial_2:
  74. return(access_partial_4);
  75. case access_other_2:
  76. default:
  77. return(access_other_4);
  78. }
  79. }
  80. extern Table_Res_4 *
  81. _DtCm_tableres2_to_tableres4(Table_Res_2 *r2)
  82. {
  83. Table_Res_4 *r4;
  84. if (r2==NULL) return((Table_Res_4 *)NULL);
  85. r4 = (Table_Res_4 *)calloc(1, sizeof(Table_Res_4));
  86. r4->status = _DtCm_accstat2_to_accstat4(r2->status);
  87. tablereslist2_to_tablereslist4(&(r2->res), &(r4->res));
  88. return(r4);
  89. }
  90. extern Access_Args_4 *
  91. _DtCm_accargs2_to_accargs4(Access_Args_2 *a2)
  92. {
  93. Access_Args_4 *a4;
  94. if (a2==NULL) return((Access_Args_4 *)NULL);
  95. a4 = (Access_Args_4 *)calloc(1, sizeof(Access_Args_4));
  96. a4->target = buffer2_to_buffer4(a2->target);
  97. a4->access_list = acclist2_to_acclist4(a2->access_list);
  98. return(a4);
  99. }
  100. extern Table_Args_4 *
  101. _DtCm_tableargs2_to_tableargs4(Table_Args_2 *a2)
  102. {
  103. Table_Args_4 *a4;
  104. if (a2==NULL) return((Table_Args_4 *)NULL);
  105. a4 = (Table_Args_4 *)calloc(1, sizeof(Table_Args_4));
  106. a4->target = buffer2_to_buffer4(a2->target);
  107. args2_to_args4(&(a2->args), &(a4->args));
  108. a4->pid = VOIDPID;
  109. return(a4);
  110. }
  111. extern Table_Args_4 *
  112. _DtCm_tabledelargs2_to_tabledelargs4(Table_Args_2 *a2, Options_4 opt)
  113. {
  114. Table_Args_4 *a4;
  115. if (a2 == NULL)
  116. return((Table_Args_4 *)NULL);
  117. a4 = (Table_Args_4 *)calloc(1, sizeof(Table_Args_4));
  118. a4->target = buffer2_to_buffer4(a2->target);
  119. a4->pid = VOIDPID;
  120. a4->args.tag = UIDOPT_4;
  121. a4->args.Args_4_u.uidopt = uid2_to_uidopt(a2->args.Args_2_u.key, opt);
  122. return(a4);
  123. }
  124. extern Registration_Status_4
  125. _DtCm_regstat2_to_regstat4(Registration_Status_2 s)
  126. {
  127. switch(s) {
  128. case registered_2:
  129. return(registered_4);
  130. case failed_2:
  131. return(failed_4);
  132. case deregistered_2:
  133. return(deregistered_4);
  134. case confused_2:
  135. return(confused_4);
  136. default:
  137. return(failed_4);
  138. }
  139. }
  140. extern Registration_4 *
  141. _DtCm_reg2_to_reg4(Registration_2 *r2)
  142. {
  143. Registration_4 *r4, *head, *prev;
  144. prev = head = NULL;
  145. while (r2 != NULL) {
  146. r4 = (Registration_4 *)calloc(1, sizeof(Registration_4));
  147. r4->target = buffer2_to_buffer4(r2->target);
  148. r4->prognum = r2->prognum;
  149. r4->versnum = r2->versnum;
  150. r4->procnum = r2->procnum;
  151. r4->next = NULL;
  152. r4->pid = VOIDPID;
  153. if (head == NULL)
  154. head = r4;
  155. else
  156. prev->next = r4;
  157. prev = r4;
  158. r2 = r2->next;
  159. }
  160. return(head);
  161. }
  162. extern Table_Status_4
  163. _DtCm_tablestat2_to_tablestat4(Table_Status_2 s)
  164. {
  165. switch(s) {
  166. case ok_2:
  167. return(ok_4);
  168. case duplicate_2:
  169. return(duplicate_4);
  170. case badtable_2:
  171. return(badtable_4);
  172. case notable_2:
  173. return(notable_4);
  174. case denied_2:
  175. return(denied_4);
  176. case other_2:
  177. default:
  178. return(other_4);
  179. }
  180. }
  181. static Buffer_4
  182. buffer2_to_buffer4(Buffer_2 b)
  183. {
  184. Buffer_4 copy;
  185. if (b!=NULL)
  186. copy = strdup(b);
  187. else
  188. copy = calloc(1,1);
  189. return(copy);
  190. }
  191. static void
  192. period2_to_period4(Period_2 p2, Period_4 *p4)
  193. {
  194. if (p4==NULL) return;
  195. switch (p2) {
  196. case single_2:
  197. p4->period = single_4;
  198. p4->nth = 0;
  199. break;
  200. case daily_2:
  201. p4->period = daily_4;
  202. p4->nth = 0;
  203. break;
  204. case weekly_2:
  205. p4->period = weekly_4;
  206. p4->nth = 0;
  207. break;
  208. case biweekly_2:
  209. p4->period = biweekly_4;
  210. p4->nth = 0;
  211. break;
  212. case monthly_2:
  213. p4->period = monthly_4;
  214. p4->nth = 0;
  215. break;
  216. case yearly_2:
  217. p4->period = yearly_4;
  218. p4->nth = 0;
  219. break;
  220. case nthWeekday_2:
  221. p4->period = nthWeekday_4;
  222. p4->nth = 0;
  223. break;
  224. case everyNthDay_2:
  225. p4->period = everyNthDay_4;
  226. p4->nth = 0;
  227. break;
  228. case everyNthWeek_2:
  229. p4->period = everyNthWeek_4;
  230. p4->nth = 0;
  231. break;
  232. case everyNthMonth_2:
  233. p4->period = everyNthMonth_4;
  234. p4->nth = 0;
  235. break;
  236. case otherPeriod_2:
  237. p4->period = otherPeriod_4;
  238. p4->nth = 0;
  239. break;
  240. default:
  241. p4->period = single_4;
  242. p4->nth = 0;
  243. break;
  244. }
  245. }
  246. static void
  247. tag2_to_tag4(Tag_2 t2, Tag_4 *t4)
  248. {
  249. if (t4==NULL) return;
  250. switch(t2) {
  251. case appointment_2:
  252. t4->tag = appointment_4;
  253. t4->showtime = B_TRUE;
  254. t4->next = NULL;
  255. break;
  256. case reminder_2:
  257. t4->tag = reminder_4;
  258. t4->showtime = B_FALSE;
  259. t4->next = NULL;
  260. break;
  261. case otherTag_2:
  262. t4->tag = otherTag_4;
  263. t4->showtime = B_FALSE;
  264. t4->next = NULL;
  265. break;
  266. default:
  267. t4->tag = appointment_4;
  268. t4->showtime = B_TRUE;
  269. t4->next = NULL;
  270. break;
  271. }
  272. }
  273. static Attribute_4 *
  274. attr2_to_attr4(Attribute_2 *a2)
  275. {
  276. Attribute_4 *a4, *head, *prev;
  277. prev = head = NULL;
  278. while (a2 != NULL) {
  279. a4 = (Attribute_4 *)calloc(1, sizeof(Attribute_4));
  280. a4->next = NULL;
  281. a4->attr = strdup(a2->attr);
  282. a4->value = strdup(a2->value);
  283. a4->clientdata = NULL;
  284. if (head == NULL)
  285. head = a4;
  286. else
  287. prev->next = a4;
  288. prev = a4;
  289. a2 = a2->next;
  290. }
  291. return(head);
  292. }
  293. static Except_4 *
  294. except2_to_except4(Except_2 *e2)
  295. {
  296. Except_4 *e4, *head, *prev;
  297. prev = head = NULL;
  298. while (e2 != NULL) {
  299. e4 = (Except_4 *)calloc(1, sizeof(Except_4));
  300. e4->ordinal = e2->ordinal;
  301. e4->next=NULL;
  302. if (head == NULL)
  303. head = e4;
  304. else
  305. prev->next = e4;
  306. prev = e4;
  307. e2 = e2->next;
  308. }
  309. return(head);
  310. }
  311. static void
  312. id2_to_id4(Id_2 *from, Id_4 *to)
  313. {
  314. if ((from==NULL) || (to==NULL)) return;
  315. to->tick = from->tick;
  316. to->key = from->key;
  317. }
  318. static Uid_4 *
  319. uid2_to_uid4(Uid_2 *ui2)
  320. {
  321. Uid_4 *ui4, *head, *prev;
  322. prev = head = NULL;
  323. while (ui2 != NULL) {
  324. ui4 = (Uid_4 *)calloc(1, sizeof(Uid_4));
  325. id2_to_id4(&(ui2->appt_id), &(ui4->appt_id));
  326. ui4->next = NULL;
  327. if (head == NULL)
  328. head = ui4;
  329. else
  330. prev->next = ui4;
  331. prev = ui4;
  332. ui2 = ui2->next;
  333. }
  334. return(head);
  335. }
  336. static Appt_4 *
  337. appt2_to_appt4(Appt_2 *a2)
  338. {
  339. Appt_4 *a4, *head, *prev;
  340. prev = head = NULL;
  341. while (a2 != NULL) {
  342. a4 = (Appt_4 *)calloc(1, sizeof(Appt_4));
  343. a4->tag = (Tag_4 *)calloc(1, sizeof(Tag_4));
  344. id2_to_id4(&(a2->appt_id), &(a4->appt_id));
  345. tag2_to_tag4(a2->tag, a4->tag);
  346. a4->duration = a2->duration;
  347. a4->ntimes = a2->ntimes;
  348. a4->what = buffer2_to_buffer4(a2->what);
  349. period2_to_period4(a2->period, &(a4->period));
  350. a4->author = buffer2_to_buffer4(a2->author);
  351. a4->client_data = buffer2_to_buffer4(a2->client_data);
  352. a4->attr = attr2_to_attr4(a2->attr);
  353. /* mailto is being removed from the appt struct proper,
  354. and held instead as client data on the "ml" attribute */
  355. if (a2->mailto != NULL) {
  356. struct Attribute_4 *item = a4->attr;
  357. while(item!=NULL) {
  358. if(strcmp(item->attr, "ml")==0) {
  359. item->clientdata=buffer2_to_buffer4(a2->mailto);
  360. break;
  361. }
  362. item=item->next;
  363. }
  364. }
  365. a4->exception = except2_to_except4(a2->exception);
  366. a4->appt_status = active_4;
  367. a4->privacy = public_4;
  368. a4->next = NULL;
  369. if (head == NULL)
  370. head = a4;
  371. else
  372. prev->next = a4;
  373. prev = a4;
  374. a2 = a2->next;
  375. }
  376. return(head);
  377. }
  378. static Abb_Appt_4 *
  379. abb2_to_abb4(Abb_Appt_2 *a2)
  380. {
  381. Abb_Appt_4 *a4, *head, *prev;
  382. prev = head = NULL;
  383. while (a2 != NULL) {
  384. a4 = (Abb_Appt_4 *)calloc(1, sizeof(Abb_Appt_4));
  385. a4->tag = (Tag_4 *)calloc(1, sizeof(Tag_4));
  386. id2_to_id4(&(a2->appt_id), &(a4->appt_id));
  387. a4->tag->tag = appointment_4;
  388. a4->tag->showtime = B_TRUE;
  389. a4->tag->next = NULL;
  390. a4->what = buffer2_to_buffer4(a2->what);
  391. a4->duration = a2->duration;
  392. period2_to_period4(a2->period, &(a4->period));
  393. a4->appt_status = active_4;
  394. a4->privacy = public_4;
  395. a4->next = NULL;
  396. if (head == NULL)
  397. head = a4;
  398. else
  399. prev->next = a4;
  400. prev = a4;
  401. a2 = a2->next;
  402. }
  403. return(head);
  404. }
  405. static void
  406. apptid2_to_apptid4(Apptid_2 *from, Apptid_4 *to)
  407. {
  408. if (from==NULL || to==NULL) return;
  409. id2_to_id4(from->oid, to->oid);
  410. to->new_appt = appt2_to_appt4(from->new_appt);
  411. /* do_all is the default, the caller needs to
  412. * modify it to the appropriate value
  413. */
  414. to->option = do_all_4;
  415. }
  416. static Reminder_4 *
  417. reminder2_to_reminder4(Reminder_2 *r2)
  418. {
  419. Reminder_4 *r4, *head, *prev;
  420. Attribute_4 *attr4;
  421. prev = head = NULL;
  422. while (r2 != NULL) {
  423. r4 = (Reminder_4 *)calloc(1, sizeof(Reminder_4));
  424. id2_to_id4(&(r2->appt_id), &(r4->appt_id));
  425. r4->tick = r2->tick;
  426. attr4 = attr2_to_attr4(&(r2->attr));
  427. r4->attr = *attr4;
  428. free(attr4);
  429. r4->next = NULL;
  430. if (head == NULL)
  431. head = r4;
  432. else
  433. prev->next = r4;
  434. prev = r4;
  435. r2 = r2->next;
  436. }
  437. return(head);
  438. }
  439. static Table_Res_Type_4
  440. tablerestype2_to_tablerestype4(Table_Res_Type_2 t)
  441. {
  442. switch(t) {
  443. case AP_2:
  444. return(AP_4);
  445. case RM_2:
  446. return(RM_4);
  447. case AB_2:
  448. return(AB_4);
  449. case ID_2:
  450. return(ID_4);
  451. default:
  452. return(AP_4);
  453. }
  454. }
  455. static void
  456. tablereslist2_to_tablereslist4(Table_Res_List_2 *from, Table_Res_List_4 *to)
  457. {
  458. if (from==NULL || to==NULL) return;
  459. to->tag = tablerestype2_to_tablerestype4(from->tag);
  460. switch (from->tag) {
  461. case AP_2:
  462. to->Table_Res_List_4_u.a = appt2_to_appt4(
  463. from->Table_Res_List_2_u.a);
  464. break;
  465. case RM_2:
  466. to->Table_Res_List_4_u.r = reminder2_to_reminder4(
  467. from->Table_Res_List_2_u.r);
  468. break;
  469. case AB_2:
  470. to->Table_Res_List_4_u.b = abb2_to_abb4(
  471. from->Table_Res_List_2_u.b);
  472. break;
  473. case ID_2:
  474. to->Table_Res_List_4_u.i = uid2_to_uid4(
  475. from->Table_Res_List_2_u.i);
  476. break;
  477. default:
  478. return;
  479. }
  480. }
  481. static Access_Entry_4 *
  482. acclist2_to_acclist4(Access_Entry_2 *l2)
  483. {
  484. Access_Entry_4 *l4, *head, *prev;
  485. prev = head = NULL;
  486. while (l2 != NULL) {
  487. l4 = (Access_Entry_4 *)calloc(1, sizeof(Access_Entry_4));
  488. l4->who = buffer2_to_buffer4(l2->who);
  489. l4->access_type = l2->access_type;
  490. l4->next = NULL;
  491. if (head == NULL)
  492. head = l4;
  493. else
  494. prev->next = l4;
  495. prev = l4;
  496. l2 = l2->next;
  497. }
  498. return(head);
  499. }
  500. static Range_4 *
  501. range2_to_range4(Range_2 *r2)
  502. {
  503. Range_4 *r4, *head, *prev;
  504. prev = head = NULL;
  505. while (r2 != NULL) {
  506. r4 = (Range_4 *)calloc(1, sizeof(Range_4));
  507. r4->key1 = r2->key1;
  508. r4->key2 = r2->key2;
  509. r4->next = NULL;
  510. if (head == NULL)
  511. head = r4;
  512. else
  513. prev->next = r4;
  514. prev = r4;
  515. r2 = r2->next;
  516. }
  517. return(head);
  518. }
  519. static Table_Args_Type_4
  520. argstag2_to_argstag4(Table_Args_Type_2 t)
  521. {
  522. switch(t) {
  523. case TICK_2:
  524. return(TICK_4);
  525. case APPTID_2:
  526. return(APPTID_4);
  527. case UID_2:
  528. return(UID_4);
  529. case APPT_2:
  530. return(APPT_4);
  531. case RANGE_2:
  532. return(RANGE_4);
  533. default:
  534. return(TICK_4);
  535. }
  536. }
  537. static void
  538. args2_to_args4(Args_2 *from, Args_4 *to)
  539. {
  540. if (from==NULL || to==NULL) return;
  541. to->tag = argstag2_to_argstag4(from->tag);
  542. switch(from->tag) {
  543. case TICK_2:
  544. to->Args_4_u.tick = from->Args_2_u.tick;
  545. break;
  546. case APPTID_2:
  547. to->Args_4_u.apptid.oid = (Id_4 *)calloc(1, sizeof(Id_4));
  548. apptid2_to_apptid4(
  549. &(from->Args_2_u.apptid),
  550. &(to->Args_4_u.apptid));
  551. break;
  552. case UID_2:
  553. to->Args_4_u.key = uid2_to_uid4(from->Args_2_u.key);
  554. break;
  555. case APPT_2:
  556. to->Args_4_u.appt = appt2_to_appt4(from->Args_2_u.appt);
  557. break;
  558. case RANGE_2:
  559. to->Args_4_u.range = range2_to_range4(from->Args_2_u.range);
  560. break;
  561. default:
  562. break;
  563. }
  564. }
  565. static Uidopt_4 *
  566. uid2_to_uidopt(Uid_2 *uid2, Options_4 opt)
  567. {
  568. Uidopt_4 *uidopt, *head, *prev;
  569. prev = head = NULL;
  570. while (uid2 != NULL) {
  571. uidopt = (Uidopt_4 *)calloc(1, sizeof(Uidopt_4));
  572. id2_to_id4(&(uid2->appt_id), &(uidopt->appt_id));
  573. uidopt->option = opt;
  574. uidopt->next = NULL;
  575. if (head == NULL)
  576. head = uidopt;
  577. else
  578. prev->next = uidopt;
  579. prev = uidopt;
  580. uid2 = uid2->next;
  581. }
  582. return(head);
  583. }