1 /* $XConsortium: convert4-3.c /main/1 1996/04/21 19:22:43 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.
15 #include "convert4-3.h"
18 * forward declaration of static functions
20 static void free_excpt3(Except_3 *e);
21 static Abb_Appt_3 * abb4_to_abb3(Abb_Appt_4 *a4);
22 static void apptid4_to_apptid3(Apptid_4 *from, Apptid_3 *to);
23 static Reminder_3 * reminder4_to_reminder3(Reminder_4 *r4);
24 static Table_Res_Type_3 tablerestype4_to_tablerestype3(Table_Res_Type_4 t);
25 static void tablereslist4_to_tablereslist3(Table_Res_List_4 *from,
26 Table_Res_List_3 *to);
27 static void period4_to_period3(Period_4 *p4, Period_3 *p3);
28 static void assign_tag4to3(Tag_4 *t4, Tag_3 *t3);
29 static void assign_status4to3(Appt_Status_4 *s4, Appt_Status_3 *s3);
30 static void assign_privacy4to3(Privacy_Level_4 *p4, Privacy_Level_3 *p3);
31 static Buffer_3 buffer4_to_buffer3(Buffer_4 b);
32 static Tag_3 * tag4_to_tag3(Tag_4 *t4);
33 static Attribute_3 * attr4_to_attr3(Attribute_4 *a4);
34 static Except_3 * except4_to_except3(Except_4 *e4);
35 static Table_Args_Type_3 argstag4_to_argstag3(Table_Args_Type_4 t);
36 static void args4_to_args3(Args_4 *from, Args_3 *to);
37 static Table_Args_3 * tableargs4_to_tableargs3(Table_Args_4 *a4);
38 static Registration_3 * reg4_to_reg3(Registration_4 *r4);
39 static void free_tag3(Tag_3 *t);
41 /**************** DATA TYPE (4->3) CONVERSION ROUTINES **************/
44 _DtCm_id4_to_id3(Id_4 *from, Id_3 *to)
46 if ((from==NULL) || (to==NULL)) return;
47 to->tick = from->tick;
52 _DtCm_uid4_to_uid3(Uid_4 *ui4)
54 Uid_3 *ui3, *head, *prev;
58 ui3 = (Uid_3 *)calloc(1, sizeof(Uid_3));
59 _DtCm_id4_to_id3(&(ui4->appt_id), &(ui3->appt_id));
74 _DtCm_appt4_to_appt3(Appt_4 *a4)
76 Appt_3 *a3, *head, *prev;
80 a3 = (Appt_3 *)calloc(1, sizeof(Appt_3));
81 _DtCm_id4_to_id3(&(a4->appt_id), &(a3->appt_id));
82 a3->tag = tag4_to_tag3(a4->tag);
83 a3->duration = a4->duration;
84 a3->ntimes = a4->ntimes;
85 a3->what = buffer4_to_buffer3(a4->what);
86 period4_to_period3(&(a4->period), &(a3->period));
87 a3->author = buffer4_to_buffer3(a4->author);
88 a3->client_data = buffer4_to_buffer3(a4->client_data);
89 a3->exception = except4_to_except3(a4->exception);
90 a3->attr = attr4_to_attr3(a4->attr);
91 assign_status4to3(&a4->appt_status, &a3->appt_status);
92 assign_privacy4to3(&a4->privacy, &a3->privacy);
107 _DtCm_free_appt3(Appt_3 *a)
120 if (a->author != NULL)
123 if (a->client_data != NULL)
124 free(a->client_data);
127 _DtCm_free_attr3(a->attr);
129 if (a->exception != NULL)
130 free_excpt3(a->exception);
139 _DtCm_free_attr3(Attribute_3 *a)
147 if (a->value != NULL)
149 if (a->clientdata != NULL)
158 free_excpt3(Except_3 *e)
170 abb4_to_abb3(Abb_Appt_4 *a4)
172 Abb_Appt_3 *a3, *head, *prev;
176 a3 = (Abb_Appt_3 *)calloc(1, sizeof(Abb_Appt_3));
177 _DtCm_id4_to_id3(&(a4->appt_id), &(a3->appt_id));
178 a3->tag = tag4_to_tag3(a4->tag);
179 a3->what = buffer4_to_buffer3(a4->what);
180 a3->duration = a4->duration;
181 period4_to_period3(&(a4->period), &(a3->period));
182 assign_status4to3(&a4->appt_status, &a3->appt_status);
183 assign_privacy4to3(&a4->privacy, &a3->privacy);
198 apptid4_to_apptid3(Apptid_4 *from, Apptid_3 *to)
200 if (from==NULL || to==NULL) return;
201 _DtCm_id4_to_id3(from->oid, to->oid);
202 to->new_appt = _DtCm_appt4_to_appt3(from->new_appt);
206 reminder4_to_reminder3(Reminder_4 *r4)
208 Reminder_3 *r3, *head, *prev;
213 r3 = (Reminder_3 *)calloc(1, sizeof(Reminder_3));
214 _DtCm_id4_to_id3(&(r4->appt_id), &(r3->appt_id));
216 attr3 = attr4_to_attr3(&(r4->attr));
232 static Table_Res_Type_3
233 tablerestype4_to_tablerestype3(Table_Res_Type_4 t)
250 tablereslist4_to_tablereslist3(Table_Res_List_4 *from, Table_Res_List_3 *to)
252 if (from==NULL || to==NULL) return;
253 to->tag = tablerestype4_to_tablerestype3(from->tag);
256 to->Table_Res_List_3_u.a = _DtCm_appt4_to_appt3(
257 from->Table_Res_List_4_u.a);
260 to->Table_Res_List_3_u.r = reminder4_to_reminder3(
261 from->Table_Res_List_4_u.r);
264 to->Table_Res_List_3_u.b = abb4_to_abb3(
265 from->Table_Res_List_4_u.b);
268 to->Table_Res_List_3_u.i = _DtCm_uid4_to_uid3(
269 from->Table_Res_List_4_u.i);
275 extern Access_Status_3
276 _DtCm_accstat4_to_accstat3(Access_Status_4 s)
282 return(access_added_3);
283 case access_removed_4:
284 return(access_removed_3);
285 case access_failed_4:
286 return(access_failed_3);
287 case access_exists_4:
288 return(access_exists_3);
289 case access_partial_4:
290 return(access_partial_3);
293 return(access_other_3);
298 _DtCm_tableres4_to_tableres3(Table_Res_4 *r4)
302 if (r4==NULL) return((Table_Res_3 *)NULL);
303 r3 = (Table_Res_3 *)calloc(1, sizeof(Table_Res_3));
304 r3->status = _DtCm_accstat4_to_accstat3(r4->status);
305 tablereslist4_to_tablereslist3(&(r4->res), &(r3->res));
309 extern Access_Entry_3 *
310 _DtCm_acclist4_to_acclist3(Access_Entry_4 *l4)
312 Access_Entry_3 *l3, *head, *prev;
316 l3 = (Access_Entry_3 *)calloc(1, sizeof(Access_Entry_3));
317 l3->who = buffer4_to_buffer3(l4->who);
318 l3->access_type = l4->access_type;
332 extern Access_Args_3 *
333 _DtCm_accargs4_to_accargs3(Access_Args_4 *a4)
337 if (a4==NULL) return((Access_Args_3 *)NULL);
338 a3 = (Access_Args_3 *)calloc(1, sizeof(Access_Args_3));
339 a3->target = buffer4_to_buffer3(a4->target);
340 a3->access_list = _DtCm_acclist4_to_acclist3(a4->access_list);
345 _DtCm_range4_to_range3(Range_4 *r4)
347 Range_3 *r3, *head, *prev;
351 r3 = (Range_3 *)calloc(1, sizeof(Range_3));
368 _DtCm_keyrange4_to_keyrange3(Keyrange_4 *r4)
370 Keyrange_3 *r3, *head, *prev;
374 r3 = (Keyrange_3 *)calloc(1, sizeof(Keyrange_3));
376 r3->tick1 = r4->tick1;
377 r3->tick2 = r4->tick2;
391 extern Registration_Status_3
392 _DtCm_regstat4_to_regstat3(Registration_Status_4 s)
396 return(registered_3);
400 return(deregistered_3);
409 extern Table_Status_3
410 _DtCm_tablestat4_to_tablestat3(Table_Status_4 s)
430 _DtCm_uidopt4_to_uid3(Uidopt_4 *uidopt)
432 Uid_3 *uid3, *head, *prev;
435 while (uidopt != NULL) {
436 uid3 = (Uid_3 *)calloc(1, sizeof(Uid_3));
437 _DtCm_id4_to_id3(&(uidopt->appt_id), &(uid3->appt_id));
446 uidopt = uidopt->next;
452 * Repeating event types beyond "yearly" are mapped to "single"
453 * because the old front end does not recognize any other types
454 * Worse yet it uses Interval to index into an array which
455 * contains strings up to "yearly", any period types beyond that
456 * would index beyond the array and cause the front end to dump core.
459 period4_to_period3(Period_4 *p4, Period_3 *p3)
461 if (p3 == NULL || p4 == NULL) return;
463 switch (p4->period) {
465 case single_4: p3->period = single_3;
469 case daily_4: p3->period = daily_3;
473 case weekly_4: p3->period = weekly_3;
477 case biweekly_4: p3->period = biweekly_3;
481 case monthly_4: p3->period = monthly_3;
485 case yearly_4: p3->period = yearly_3;
489 default: p3->period = single_3;
497 assign_tag4to3(Tag_4 *t4, Tag_3 *t3)
501 case appointment_4: t3->tag = appointment_3;
504 case reminder_4: t3->tag = reminder_3;
507 case otherTag_4: t3->tag = otherTag_3;
510 case holiday_4: t3->tag = holiday_3;
513 case toDo_4: t3->tag = toDo_3;
520 assign_status4to3(Appt_Status_4 *s4, Appt_Status_3 *s3)
524 case active_4: *s3 = active_3;
527 case pendingAdd_4: *s3 = pendingAdd_3;
530 case pendingDelete_4: *s3 = pendingDelete_3;
533 case committed_4: *s3 = committed_3;
536 case cancelled_4: *s3 = cancelled_3;
539 case completed_4: *s3 = completed_3;
546 assign_privacy4to3(Privacy_Level_4 *p4, Privacy_Level_3 *p3)
550 case public_4: *p3 = public_3;
553 case private_4: *p3 = private_3;
556 case semiprivate_4: *p3 = semiprivate_3;
565 buffer4_to_buffer3(Buffer_4 b)
576 tag4_to_tag3(Tag_4 *t4)
578 Tag_3 *t3, *head, *prev;
582 t3 = (Tag_3 *)calloc(1, sizeof(Tag_3));
583 assign_tag4to3(t4, t3);
584 t3->showtime = t4->showtime;
599 attr4_to_attr3(Attribute_4 *a4)
601 Attribute_3 *a3, *head, *prev;
605 a3 = (Attribute_3 *)calloc(1, sizeof(Attribute_3));
607 a3->attr = buffer4_to_buffer3(a4->attr);
608 a3->value = buffer4_to_buffer3(a4->value);
609 a3->clientdata = buffer4_to_buffer3(a4->clientdata);
623 except4_to_except3(Except_4 *e4)
625 Except_3 *e3, *head, *prev;
629 e3 = (Except_3 *)calloc(1, sizeof(Except_3));
630 e3->ordinal = e4->ordinal;
644 static Table_Args_Type_3
645 argstag4_to_argstag3(Table_Args_Type_4 t)
666 args4_to_args3(Args_4 *from, Args_3 *to)
668 if (from==NULL || to==NULL) return;
669 to->tag = argstag4_to_argstag3(from->tag);
672 to->Args_3_u.tick = from->Args_4_u.tick;
675 to->Args_3_u.apptid.oid = (Id_3 *)calloc(1, sizeof(Id_3));
677 &(from->Args_4_u.apptid),
678 &(to->Args_3_u.apptid));
681 to->Args_3_u.key = _DtCm_uid4_to_uid3(from->Args_4_u.key);
684 to->Args_3_u.appt = _DtCm_appt4_to_appt3(from->Args_4_u.appt);
687 to->Args_3_u.range = _DtCm_range4_to_range3(from->Args_4_u.range);
690 to->Args_3_u.keyrange = _DtCm_keyrange4_to_keyrange3(
691 from->Args_4_u.keyrange);
697 static Table_Args_3 *
698 tableargs4_to_tableargs3(Table_Args_4 *a4)
702 if (a4==NULL) return((Table_Args_3 *)NULL);
703 a3 = (Table_Args_3 *)calloc(1, sizeof(Table_Args_3));
704 a3->target = buffer4_to_buffer3(a4->target);
705 args4_to_args3(&(a4->args), &(a3->args));
710 static Registration_3 *
711 reg4_to_reg3(Registration_4 *r4)
713 Registration_3 *r3, *head, *prev;
717 r3 = (Registration_3 *)calloc(1, sizeof(Registration_3));
718 r3->target = buffer4_to_buffer3(r4->target);
719 r3->prognum = r4->prognum;
720 r3->versnum = r4->versnum;
721 r3->procnum = r4->procnum;