appt4.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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: appt4.c /main/1 1996/04/21 19:21:34 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. /*
  31. * this file contains allocate and free routines for v4 data structures
  32. */
  33. #include <EUSCompat.h>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include "appt4.h"
  38. #define FAUX_STRING "Appointment"
  39. /*
  40. * forward declaration of static functions used within the file
  41. */
  42. static void free_tag4(Tag_4 *t);
  43. static Attribute_4 *copy_attr4(Attribute_4 *a4);
  44. static Tag_4 *copy_tag4(Tag_4 *t4);
  45. /*****************************************************************************
  46. * extern functions
  47. *****************************************************************************/
  48. extern Appt_4 *
  49. _DtCm_make_appt4(boolean_t alloc)
  50. {
  51. Appt_4 *a;
  52. if ((a = (Appt_4 *)calloc(1, sizeof(Appt_4))) == NULL)
  53. return NULL;
  54. if ((a->tag = (Tag_4 *)calloc(1, sizeof(Tag_4))) == NULL) {
  55. free(a);
  56. return NULL;
  57. }
  58. a->tag->tag = appointment_4;
  59. a->tag->next = NULL;
  60. a->tag->showtime = B_TRUE;
  61. a->period.period = single_4;
  62. a->appt_status = active_4;
  63. a->privacy = public_4;
  64. if (alloc) {
  65. a->what = calloc(1, sizeof(1));
  66. a->author = calloc(1, sizeof(1));
  67. a->client_data = calloc(1, sizeof(1));
  68. }
  69. a->next = NULL;
  70. return(a);
  71. }
  72. extern Appt_4 *
  73. _DtCm_copy_one_appt4(Appt_4 *a4)
  74. {
  75. Appt_4 *ptr, *copy;
  76. if (a4 == NULL)
  77. return NULL;
  78. ptr = a4->next;
  79. a4->next = NULL;
  80. copy = _DtCm_copy_appt4(a4);
  81. a4->next = ptr;
  82. return (copy);
  83. }
  84. extern Appt_4 *
  85. _DtCm_copy_appt4(Appt_4 *a4)
  86. {
  87. Appt_4 *a, *head, *prev;
  88. boolean_t cleanup = B_FALSE;
  89. prev = head = NULL;
  90. while (a4 != NULL) {
  91. if ((a = (Appt_4 *)calloc(1, sizeof(Appt_4))) == NULL) {
  92. cleanup = B_TRUE;
  93. break;
  94. }
  95. a->appt_id.tick = a4->appt_id.tick;
  96. a->appt_id.key = a4->appt_id.key;
  97. a->duration = a4->duration;
  98. a->ntimes = a4->ntimes;
  99. if (a4->what) {
  100. if ((a->what = strdup(a4->what)) == NULL) {
  101. _DtCm_free_appt4(a);
  102. cleanup = B_TRUE;
  103. break;
  104. }
  105. } else if ((a->what = (char *)calloc(1, 1)) == NULL) {
  106. _DtCm_free_appt4(a);
  107. cleanup = B_TRUE;
  108. break;
  109. }
  110. a->period.period = a4->period.period;
  111. a->period.nth = a4->period.nth;
  112. a->period.enddate = a4->period.enddate;
  113. if (a4->author) {
  114. if ((a->author = strdup(a4->author)) == NULL) {
  115. _DtCm_free_appt4(a);
  116. cleanup = B_TRUE;
  117. break;
  118. }
  119. } else if ((a->author = (char *)calloc(1, 1)) == NULL) {
  120. _DtCm_free_appt4(a);
  121. cleanup = B_TRUE;
  122. break;
  123. }
  124. if (a4->client_data) {
  125. if ((a->client_data = strdup(a4->client_data)) == NULL) {
  126. _DtCm_free_appt4(a);
  127. cleanup = B_TRUE;
  128. break;
  129. }
  130. } else if ((a->client_data = (char *)calloc(1, 1)) == NULL) {
  131. _DtCm_free_appt4(a);
  132. cleanup = B_TRUE;
  133. break;
  134. }
  135. if (a4->exception &&
  136. (a->exception = _DtCm_copy_excpt4(a4->exception)) == NULL) {
  137. _DtCm_free_appt4(a);
  138. cleanup = B_TRUE;
  139. break;
  140. }
  141. if (a4->attr && (a->attr = copy_attr4(a4->attr)) == NULL) {
  142. _DtCm_free_appt4(a);
  143. cleanup = B_TRUE;
  144. break;
  145. }
  146. if (a4->tag) {
  147. if ((a->tag = copy_tag4(a4->tag)) == NULL) {
  148. free(a);
  149. cleanup = B_TRUE;
  150. break;
  151. }
  152. } else if ((a->tag = (Tag_4 *)calloc(1, sizeof(Tag_4))) == NULL) {
  153. free(a);
  154. cleanup = B_TRUE;
  155. break;
  156. } else {
  157. a->tag->tag = appointment_4;
  158. a->tag->showtime = B_TRUE;
  159. a->tag->next = NULL;
  160. }
  161. a->appt_status = a4->appt_status;
  162. a->privacy = a4->privacy;
  163. a->next = NULL;
  164. if (head == NULL)
  165. head = a;
  166. else
  167. prev->next = a;
  168. prev = a;
  169. a4 = a4->next;
  170. }
  171. if (cleanup == B_TRUE) {
  172. _DtCm_free_appt4(head);
  173. head = NULL;
  174. }
  175. return (head);
  176. }
  177. /*
  178. * Copy one appointment.
  179. * The what field is set to "Appointment".
  180. */
  181. extern Appt_4 *
  182. _DtCm_copy_semiprivate_appt4(Appt_4 *original)
  183. {
  184. Appt_4 *temp, *copy = NULL;
  185. if (original != NULL) {
  186. temp = original->next;
  187. original->next = NULL;
  188. if ((copy = _DtCm_copy_appt4(original)) != NULL) {
  189. if (copy->what != NULL)
  190. free(copy->what);
  191. if ((copy->what = (char *)strdup(FAUX_STRING)) == NULL)
  192. {
  193. _DtCm_free_appt4(copy);
  194. copy = NULL;
  195. }
  196. }
  197. original->next = temp;
  198. }
  199. return(copy);
  200. }
  201. extern Abb_Appt_4 *
  202. _DtCm_appt_to_abbrev4(Appt_4 *original)
  203. {
  204. Abb_Appt_4 *new = NULL;
  205. if (original != NULL) {
  206. if ((new = (Abb_Appt_4 *)calloc(1, sizeof(Abb_Appt_4))) == NULL)
  207. return NULL;
  208. if ((new->tag = copy_tag4(original->tag)) == NULL) {
  209. free(new);
  210. return NULL;
  211. }
  212. new->appt_id.tick = original->appt_id.tick;
  213. new->appt_id.key = original->appt_id.key;
  214. if ((new->what = (char *)strdup(original->what)) == NULL) {
  215. _DtCm_free_abbrev_appt4(new);
  216. return NULL;
  217. }
  218. new->duration = original->duration;
  219. new->period.period = original->period.period;
  220. new->period.nth = original->period.nth;
  221. new->period.enddate = original->period.enddate;
  222. new->appt_status = original->appt_status;
  223. new->privacy = original->privacy;
  224. new->next=NULL;
  225. }
  226. return(new);
  227. }
  228. /*
  229. * The what field is set to "Appointment".
  230. */
  231. extern Abb_Appt_4 *
  232. _DtCm_appt_to_semiprivate_abbrev4(Appt_4 *original)
  233. {
  234. Abb_Appt_4 *new = _DtCm_appt_to_abbrev4(original);
  235. if (new != NULL) {
  236. if (new->what != NULL)
  237. free(new->what);
  238. if ((new->what = strdup(FAUX_STRING)) == NULL) {
  239. _DtCm_free_abbrev_appt4(new);
  240. new = NULL;
  241. }
  242. }
  243. return(new);
  244. }
  245. extern void
  246. _DtCm_free_appt4(Appt_4 *a)
  247. {
  248. Appt_4 *ptr;
  249. while (a != NULL) {
  250. ptr = a->next;
  251. if (a->what != NULL)
  252. free(a->what);
  253. if (a->author != NULL)
  254. free(a->author);
  255. if (a->tag != NULL)
  256. free_tag4(a->tag);
  257. if (a->attr != NULL)
  258. _DtCm_free_attr4(a->attr);
  259. if (a->exception != NULL)
  260. _DtCm_free_excpt4(a->exception);
  261. free(a);
  262. a = ptr;
  263. }
  264. }
  265. extern void
  266. _DtCm_free_abbrev_appt4(Abb_Appt_4 *a)
  267. {
  268. Abb_Appt_4 *ptr;
  269. while (a != NULL) {
  270. ptr = a->next;
  271. if (a->what != NULL) {
  272. free(a->what);
  273. }
  274. if (a->tag != NULL) {
  275. free_tag4(a->tag);
  276. }
  277. free(a);
  278. a = ptr;
  279. }
  280. }
  281. Attribute_4 *
  282. _DtCm_make_attr4(void)
  283. {
  284. Attribute_4 *a;
  285. if ((a = (Attribute_4 *)calloc(1, sizeof(Attribute_4))) == NULL)
  286. return NULL;
  287. if ((a->attr = (char *)calloc(1, 1)) == NULL) {
  288. free(a);
  289. return NULL;
  290. }
  291. if ((a->value = (char *)calloc(1, 1)) == NULL) {
  292. _DtCm_free_attr4(a);
  293. return NULL;
  294. }
  295. if ((a->clientdata = (char *)calloc(1, 1)) == NULL) {
  296. _DtCm_free_attr4(a);
  297. return NULL;
  298. }
  299. return(a);
  300. }
  301. extern void
  302. _DtCm_free_attr4(Attribute_4 *a)
  303. {
  304. Attribute_4 *ptr;
  305. while (a != NULL) {
  306. ptr = a->next;
  307. if (a->attr != NULL)
  308. free(a->attr);
  309. if (a->value != NULL)
  310. free(a->value);
  311. if (a->clientdata != NULL)
  312. free(a->clientdata);
  313. free(a);
  314. a = ptr;
  315. }
  316. }
  317. extern Reminder_4 *
  318. _DtCm_copy_reminder4(Reminder_4 *r4)
  319. {
  320. Reminder_4 *rem, *head, *prev;
  321. prev = head = NULL;
  322. while (r4 != NULL) {
  323. rem = (Reminder_4 *)calloc(1, sizeof(Reminder_4));
  324. rem->appt_id = r4->appt_id;
  325. rem->tick = r4->tick;
  326. rem->attr.next = NULL;
  327. rem->attr.attr = strdup(r4->attr.attr);
  328. rem->attr.value = strdup(r4->attr.value);
  329. rem->attr.clientdata = strdup(r4->attr.clientdata);
  330. rem->next = NULL;
  331. if (head == NULL)
  332. head = rem;
  333. else
  334. prev->next = rem;
  335. prev = rem;
  336. r4 = r4->next;
  337. }
  338. return(head);
  339. }
  340. extern void
  341. _DtCm_free_reminder4(Reminder_4 *r)
  342. {
  343. Reminder_4 *ptr;
  344. while (r != NULL) {
  345. ptr = r->next;
  346. if (r->attr.attr != NULL)
  347. free (r->attr.attr);
  348. if (r->attr.value != NULL)
  349. free (r->attr.value);
  350. if (r->attr.clientdata != NULL)
  351. free (r->attr.clientdata);
  352. free (r);
  353. r = ptr;
  354. }
  355. }
  356. extern void
  357. _DtCm_free_keyentry4(Uid_4 *k)
  358. {
  359. Uid_4 *ptr;
  360. while (k != NULL) {
  361. ptr = k->next;
  362. free(k);
  363. k = ptr;
  364. }
  365. }
  366. extern Access_Entry_4 *
  367. _DtCm_make_access_entry4(char *who, int perms)
  368. {
  369. Access_Entry_4 *e;
  370. if (who==NULL) return((Access_Entry_4 *)NULL);
  371. if ((e = (Access_Entry_4 *)calloc(1, sizeof(Access_Entry_4))) == NULL)
  372. return NULL;
  373. if ((e->who = strdup(who)) == NULL) {
  374. free(e);
  375. return NULL;
  376. }
  377. e->access_type = perms;
  378. e->next = NULL;
  379. return(e);
  380. }
  381. extern void
  382. _DtCm_free_access_list4(Access_Entry_4 *e)
  383. {
  384. Access_Entry_4 *ptr;
  385. while (e != NULL) {
  386. ptr = e->next;
  387. if (e->who != NULL)
  388. free(e->who);
  389. free(e);
  390. e = ptr;
  391. }
  392. }
  393. extern void
  394. _DtCm_free_excpt4(Except_4 *e)
  395. {
  396. Except_4 *ptr;
  397. while (e != NULL) {
  398. ptr = e->next;
  399. free(e);
  400. e = ptr;
  401. }
  402. }
  403. extern Except_4 *
  404. _DtCm_copy_excpt4(Except_4 *e4)
  405. {
  406. Except_4 *e, *head, *prev;
  407. boolean_t cleanup = B_FALSE;
  408. prev = head = NULL;
  409. while (e4 != NULL) {
  410. if ((e = (Except_4 *)calloc(1, sizeof(Except_4))) == NULL) {
  411. cleanup = B_TRUE;
  412. break;
  413. }
  414. e->ordinal = e4->ordinal;
  415. e->next = NULL;
  416. if (head == NULL)
  417. head = e;
  418. else
  419. prev->next = e;
  420. prev = e;
  421. e4 = e4->next;
  422. }
  423. if (cleanup == B_TRUE) {
  424. _DtCm_free_excpt4(head);
  425. head = NULL;
  426. }
  427. return (head);
  428. }
  429. /******************************************************************************
  430. * static functions used within the file
  431. ******************************************************************************/
  432. static void
  433. free_tag4(Tag_4 *t)
  434. {
  435. Tag_4 *ptr;
  436. while (t != NULL) {
  437. ptr = t->next;
  438. free(t);
  439. t = ptr;
  440. }
  441. }
  442. /* Copy an attribute list recursively */
  443. static Attribute_4 *
  444. copy_attr4(Attribute_4 *a4)
  445. {
  446. Attribute_4 *a, *head, *prev;
  447. boolean_t cleanup = B_FALSE;
  448. prev = head = NULL;
  449. while (a4 != NULL) {
  450. if ((a = (Attribute_4 *)calloc(1, sizeof(Attribute_4)))
  451. == NULL) {
  452. cleanup = B_TRUE;
  453. break;
  454. }
  455. if ((a->attr = strdup(a4->attr)) == NULL) {
  456. free(a);
  457. cleanup = B_TRUE;
  458. break;
  459. }
  460. if ((a->value = strdup(a4->value)) == NULL) {
  461. _DtCm_free_attr4(a);
  462. cleanup = B_TRUE;
  463. break;
  464. }
  465. if ((a->clientdata = strdup(a4->clientdata)) == NULL) {
  466. _DtCm_free_attr4(a);
  467. cleanup = B_TRUE;
  468. break;
  469. }
  470. if (head == NULL)
  471. head = a;
  472. else
  473. prev->next = a;
  474. prev = a;
  475. a4 = a4->next;
  476. }
  477. if (cleanup == B_TRUE) {
  478. _DtCm_free_attr4(head);
  479. head = NULL;
  480. }
  481. return (head);
  482. }
  483. static Tag_4 *
  484. copy_tag4(Tag_4 *t4)
  485. {
  486. Tag_4 *t, *head, *prev;
  487. boolean_t cleanup = B_FALSE;
  488. prev = head = NULL;
  489. while (t4 != NULL) {
  490. if ((t = (Tag_4 *)calloc(1, sizeof(Tag_4))) == NULL) {
  491. cleanup = B_TRUE;
  492. break;
  493. }
  494. t->tag = t4->tag;
  495. t->showtime = t4->showtime;
  496. t->next = NULL;
  497. if (head == NULL)
  498. head = t;
  499. else
  500. prev->next = t;
  501. prev = t;
  502. t4 = t4->next;
  503. }
  504. if (cleanup == B_TRUE) {
  505. free_tag4(head);
  506. head = NULL;
  507. }
  508. return (head);
  509. }