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 librararies 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: table.c /main/1 1996/04/21 19:24:46 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.
31 #include <EUSCompat.h>
43 #include "convert4-2.h"
44 #include "convert2-4.h"
45 #include "convert4-3.h"
46 #include "convert3-4.h"
47 #include "convert4-5.h"
48 #include "convert5-4.h"
49 #include "connection.h"
57 extern u_long _DtCm_transient;
59 #define MAXDAY_LOOKUP 15
60 #define MAXDAY_LOOKUP_SECS ((DAYSEC*MAXDAY_LOOKUP)+1)
62 static char *errfmt = "cm: %s() unexpected return status %d.\n";
64 /*****************************************************************************
65 * forward declaration of static functions
66 *****************************************************************************/
67 static CSA_return_code tablestat_to_dtcmstat(
69 CSA_return_code *dtcmstat);
71 /*****************************************************************************
72 * extern functions used in the library
73 *****************************************************************************/
75 extern CSA_return_code
76 _DtCm_table_create(Calendar *cal)
79 Table_Status_4 *res = NULL;
80 _DtCm_Connection *conn;
82 DP(("table.c: _DtCm_table_create\n"));
85 return (CSA_E_INVALID_PARAMETER);
90 switch(conn->ci->vers_out) {
94 return(CSA_E_NOT_SUPPORTED);
96 a4.target = cal->name;
97 a4.new_target = calloc(1, 1);
98 res = _DtCm_rtable_create_4(&a4, conn);
102 return(CSA_E_FAILURE);
105 if (tablestat_to_dtcmstat(*res, &stat) != CSA_SUCCESS)
106 DP((errfmt, "table.c:", "_DtCm_table_create", *res));
108 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
109 _DtCm_clntstat_to_csastat(conn->stat);
115 extern CSA_return_code
116 _DtCm_table_get_access(Calendar *cal, cms_access_entry **alist)
118 CSA_return_code stat = CSA_SUCCESS;
119 Access_Args_4 *res = NULL;
120 _DtCm_Connection *conn;
122 DP(("table.c: _DtCm_table_get_access\n"));
124 if (cal == NULL || alist == NULL)
125 return (CSA_E_INVALID_PARAMETER);
131 switch(conn->ci->vers_out) {
138 a2.target = cal->name;
139 a2.access_list = NULL;
140 res2 = _DtCm_rtable_get_access_2(&a2, conn);
141 res = _DtCm_accargs2_to_accargs4(res2);
143 xdr_free((xdrproc_t)_DtCm_xdr_Access_Args_2, (char*)res2);
146 a3.target = cal->name;
147 a3.access_list = NULL;
148 res3 = _DtCm_rtable_get_access_3(&a3, conn);
149 res = _DtCm_accargs3_to_accargs4(res3);
151 xdr_free((xdrproc_t)_DtCm_xdr_Access_Args_3, (char*)res3);
154 a4.target = cal->name;
155 a4.access_list = NULL;
156 res = _DtCm_rtable_get_access_4(&a4, conn);
159 stat = CSA_E_FAILURE;
164 stat = _DtCm_accessentry4_to_cmsaccesslist(res->access_list, alist);
165 xdr_free ((xdrproc_t)_DtCm_xdr_Access_Args_4, (char*)res);
167 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
168 _DtCm_clntstat_to_csastat(conn->stat);
174 extern CSA_return_code
175 _DtCm_table_set_access(Calendar *cal, CSA_access_list alist)
177 CSA_return_code stat = CSA_SUCCESS;
178 Access_Status_4 s = access_other_4;
179 Access_Status_4 *res;
180 _DtCm_Connection *conn;
181 boolean_t nullreturned = B_FALSE;
182 Access_Entry_4 *alist4;
184 DP(("table.c: _DtCm_table_set_access\n"));
187 return (CSA_E_INVALID_PARAMETER);
189 if ((stat = _DtCm_csaaccesslist_toaccessentry4(alist, &alist4))
194 conn->retry = B_FALSE;
196 switch(conn->ci->vers_out) {
203 a2.target = cal->name;
204 a2.access_list = _DtCm_acclist4_to_acclist2(alist4);
205 s2 = _DtCm_rtable_set_access_2(&a2, conn);
207 s = _DtCm_accstat2_to_accstat4(*s2);
209 nullreturned = B_TRUE;
210 if (a2.access_list != NULL)
211 _DtCm_free_access_list4((Access_Entry_4 *)a2.access_list);
214 a3.target = cal->name;
215 a3.access_list = _DtCm_acclist4_to_acclist3(alist4);
216 s3 = _DtCm_rtable_set_access_3(&a3, conn);
218 s = _DtCm_accstat3_to_accstat4(*s3);
220 nullreturned = B_TRUE;
221 if (a3.access_list != NULL)
222 _DtCm_free_access_list4((Access_Entry_4 *)a3.access_list);
225 a4.target = cal->name;
226 a4.access_list = alist4;
227 res = _DtCm_rtable_set_access_4(&a4, conn);
231 nullreturned = B_TRUE;
234 stat = CSA_E_FAILURE;
239 _DtCm_free_access_list4(alist4);
242 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
243 _DtCm_clntstat_to_csastat(conn->stat);
249 case access_failed_4:
250 stat = CSA_E_NO_AUTHORITY;
252 case access_notable_4:
253 stat = CSA_E_CALENDAR_NOT_EXIST;
256 DP((errfmt, "table_set_access", s));
257 stat = CSA_E_FAILURE;
265 extern CSA_return_code
266 _DtCm_table_lookup(Calendar *cal, _DtCm_libentry *entry)
268 CSA_return_code stat = CSA_SUCCESS;
269 Table_Res_4 *res = NULL;
270 _DtCm_Connection *conn;
274 DP(("table.c: call to _DtCm_table_lookup\n"));
276 if ((cal == NULL) || entry == NULL)
277 return (CSA_E_INVALID_PARAMETER);
279 key.appt_id.tick = entry->e->key.time;
280 key.appt_id.key = entry->e->key.id;
284 conn->retry = B_TRUE;
286 switch(conn->ci->vers_out) {
293 a2.target = cal->name;
295 a2.args.Args_2_u.key = _DtCm_uid4_to_uid2(&key);
296 res2 = _DtCm_rtable_lookup_2(&a2, conn);
297 res = _DtCm_tableres2_to_tableres4(res2);
298 if (a2.args.Args_2_u.key != NULL)
299 free(a2.args.Args_2_u.key);
301 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_2, (char*)res2);
304 a3.target = cal->name;
306 a3.args.Args_3_u.key = _DtCm_uid4_to_uid3(&key);
308 res3 = _DtCm_rtable_lookup_3(&a3, conn);
309 res = _DtCm_tableres3_to_tableres4(res3);
310 if (a3.args.Args_3_u.key != NULL)
311 free(a3.args.Args_3_u.key);
313 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_3, (char*)res3);
316 a4.target = cal->name;
318 a4.args.Args_4_u.key = &key;
320 res = _DtCm_rtable_lookup_4(&a4, conn);
323 stat = CSA_E_FAILURE;
328 switch(res->status) {
330 case access_failed_4:
331 if ((appt = res->res.Table_Res_List_4_u.a) == NULL)
332 stat = CSA_X_DT_E_ENTRY_NOT_FOUND |
333 CSA_E_INVALID_ENTRY_HANDLE;
335 if (stat == CSA_SUCCESS) {
336 if (entry->filled == B_TRUE)
337 _DtCm_free_cms_attribute_values(
340 if ((stat = _DtCm_appt4_to_attrs(
343 entry->e->attrs, B_FALSE))
345 entry->filled = B_TRUE;
350 stat = CSA_E_FAILURE;
352 case access_notable_4:
353 stat = CSA_E_CALENDAR_NOT_EXIST;
356 /* remote system error */
357 DP((errfmt, "_DtCm_table_lookup", res->status));
358 stat = CSA_E_FAILURE;
361 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_4, (char*)res);
363 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
364 _DtCm_clntstat_to_csastat(conn->stat);
370 extern CSA_return_code
371 _DtCm_table_lookup_range(
375 boolean_t no_end_time_range,
380 cms_attribute *attrs,
382 _DtCm_libentry **entries)
384 CSA_return_code stat = CSA_SUCCESS;
385 Table_Res_4 *res = NULL;
386 _DtCm_Connection *conn;
387 Range_4 new_range, old_range;
388 Appt_4 *appts = NULL, *lptr = NULL, *tptr = NULL, *rptr = NULL;
389 boolean_t need_matching = B_FALSE;
392 DP(("table.c: _DtCm_table_lookup_range\n"));
394 if (cal == NULL || entries == NULL)
395 return (CSA_E_INVALID_PARAMETER);
399 old_range.key1 = start1;
400 old_range.key2 = start2;
402 new_range.key1 = old_range.key1;
403 new_range.key2 = old_range.key2;
404 new_range.next = NULL;
407 conn->retry = B_TRUE;
409 if (conn->use == udp_transport)
410 if ((new_range.key1 + MAXDAY_LOOKUP_SECS) < old_range.key2)
411 new_range.key2 = new_range.key1 + MAXDAY_LOOKUP_SECS;
414 switch(conn->ci->vers_out) {
421 a2.target = cal->name;
422 a2.args.tag = RANGE_2;
423 a2.args.Args_2_u.range = _DtCm_range4_to_range2(&new_range);
424 res2 = _DtCm_rtable_lookup_range_2(&a2, conn);
425 res = _DtCm_tableres2_to_tableres4(res2);
426 if (a2.args.Args_2_u.range != NULL)
427 free(a2.args.Args_2_u.range);
429 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_2, (char*)res2);
432 a3.target = cal->name;
433 a3.args.tag = RANGE_3;
434 a3.args.Args_3_u.range = _DtCm_range4_to_range3(&new_range);
436 res3 = _DtCm_rtable_lookup_range_3(&a3, conn);
437 res = _DtCm_tableres3_to_tableres4(res3);
438 if (a3.args.Args_3_u.range != NULL)
439 free(a3.args.Args_3_u.range);
441 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_3, (char*)res3);
444 a4.target = cal->name;
445 a4.args.tag = RANGE_4;
446 a4.args.Args_4_u.range = &new_range;
448 res = _DtCm_rtable_lookup_range_4(&a4, conn);
451 stat = CSA_E_FAILURE;
456 switch(res->status) {
458 case access_failed_4:
459 tptr = _DtCm_copy_appt4(res->res.Table_Res_List_4_u.a);
460 if (stat == CSA_SUCCESS) {
461 if (conn->use == tcp_transport)
463 else { /* udp transport */
467 /* traverse from the last res ptr */
468 for (rptr = lptr; rptr != NULL &&
469 rptr->next != NULL; rptr = rptr->next);
471 rptr->next = lptr = tptr;
479 stat = CSA_E_INVALID_PARAMETER;
481 case access_notable_4:
482 stat = CSA_E_CALENDAR_NOT_EXIST;
485 /* remote system error */
486 DP ((errfmt, "table_lookup_range", res->status));
487 stat = CSA_E_FAILURE;
490 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_4, (char*)res); res = NULL;
492 /* range must encompass interested ticks */
493 new_range.key1 = new_range.key2-1;
494 if ((new_range.key2 =
495 (new_range.key1+MAXDAY_LOOKUP_SECS)) >
497 new_range.key2 = old_range.key2;
498 } else { /* res == NULL */
499 stat = (conn->stat == RPC_SUCCESS) ?
500 CSA_E_SERVICE_UNAVAILABLE :
501 _DtCm_clntstat_to_csastat(conn->stat);
503 } while (stat == CSA_SUCCESS && new_range.key1 < old_range.key2 &&
504 (new_range.key1+1) != old_range.key2);
506 if (stat == CSA_SUCCESS) {
508 * if attrs are specified, return only those
509 * appts that matches the values
511 if (id > 0 || num_attrs > 0 || !no_end_time_range)
512 appts = _DtCm_match_appts(appts, id, no_end_time_range,
513 end1, end2, num_attrs, attrs, ops);
515 stat = _DtCm_appt4_to_libentries(cal->name, appts, entries);
516 _DtCm_free_appt4(appts);
518 } else if (appts != NULL) {
519 /* this happens if udp is used and some rpc calls succeeded */
520 _DtCm_free_appt4(appts);
527 * This routine looks up events of a repeating sequence.
528 * The caller either specifies entry and elist_r or
530 * If entry is specified, events are converted to cms_entry structures
531 * and returned in elist_r, otherwise; the caller is interested only
532 * in the key of the first entry which will be returned in the cms_key
533 * structure pointed to by key.
535 extern CSA_return_code
536 _DtCm_table_lookup_key_range(
538 _DtCm_libentry *entry,
543 _DtCm_libentry **elist_r)
545 CSA_return_code stat = CSA_SUCCESS;
546 Table_Res_4 *res=NULL;
547 _DtCm_Connection *conn;
550 _DtCm_libentry *head, *prev, *eptr;
552 DP(("table.c: _DtCm_table_lookup_key_range\n"));
554 if (cal == NULL || (entry == NULL && key == NULL) ||
555 (entry && elist_r == NULL))
556 return (CSA_E_INVALID_PARAMETER);
558 keyrange.next = NULL;
559 keyrange.key = (entry ? entry->e->key.id : id);
560 keyrange.tick1 = start;
561 keyrange.tick2 = end;
564 conn->retry = B_TRUE;
566 switch(conn->ci->vers_out) {
571 return (CSA_E_NOT_SUPPORTED);
574 a3.target = cal->name;
575 a3.args.tag = KEYRANGE_3;
576 a3.args.Args_3_u.keyrange = _DtCm_keyrange4_to_keyrange3(&keyrange);
578 res3 = _DtCm_rtable_abbreviated_lookup_key_range_3(&a3, conn);
579 res = _DtCm_tableres3_to_tableres4(res3);
580 if (a3.args.Args_3_u.keyrange != NULL)
581 free(a3.args.Args_3_u.keyrange);
583 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_3, (char*)res3);
586 a4.target = cal->name;
587 a4.args.tag = KEYRANGE_4;
588 a4.args.Args_4_u.keyrange = &keyrange;
590 res = _DtCm_rtable_abbreviated_lookup_key_range_4(&a4, conn);
593 return (CSA_E_FAILURE);
597 switch(res->status) {
599 case access_failed_4:
600 abbs = res->res.Table_Res_List_4_u.b;
602 /* caller is only interested in the first key */
604 key->id = abbs->appt_id.key;
605 key->time = abbs->appt_id.tick;
611 /* we just copy the time from the returned data */
613 while (abbs != NULL) {
614 if ((stat = _DtCm_make_libentry(entry->e,
615 &eptr)) != CSA_SUCCESS)
618 /* change time to the time of the instance */
619 eptr->e->key.time = abbs->appt_id.tick;
620 _csa_tick_to_iso8601(eptr->e->key.time,
622 attrs[CSA_ENTRY_ATTR_START_DATE_I].\
623 value->item.string_value);
635 if (stat == CSA_SUCCESS)
637 else if (head != NULL)
638 _DtCm_free_libentries(head);
642 stat = CSA_E_FAILURE;
644 case access_notable_4:
645 stat = CSA_E_CALENDAR_NOT_EXIST;
648 /* remote system error */
649 DP((errfmt, "_DtCm_table_lookup_key_range", res->status));
650 stat = CSA_E_FAILURE;
653 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_4, (char*)res);
655 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
656 _DtCm_clntstat_to_csastat(conn->stat);
662 extern CSA_return_code
666 CSA_attribute * attrs,
667 _DtCm_libentry **entry_r)
669 CSA_return_code stat = CSA_SUCCESS;
670 Table_Res_4 *res = NULL;
671 _DtCm_Connection *conn;
675 DP(("table.c: _DtCm_table_insert\n"));
677 if (cal == NULL || num_attrs == 0 || attrs == NULL || entry_r == NULL)
678 return (CSA_E_INVALID_PARAMETER);
680 if ((stat = _DtCm_attrs_to_appt4(num_attrs, attrs, &appt4)) != CSA_SUCCESS)
683 /* if the backend's version is less than 4, then it
684 * does not support repeating event types beyond yearly
687 if (conn->ci->vers_out < TABLEVERS_4 && appt4->period.period > yearly_4) {
688 _DtCm_free_appt4(appt4);
689 return (CSA_E_NOT_SUPPORTED);
692 /* for old backend, insert one appt at a time
693 * in order to match appointments with the new id
696 conn->retry = B_FALSE;
698 switch(conn->ci->vers_out) {
705 a2.target = cal->name;
706 a2.args.tag = APPT_2;
707 a2.args.Args_2_u.appt = _DtCm_appt4_to_appt2(appt4);
708 res2 = _DtCm_rtable_insert_2(&a2, conn);
709 res = _DtCm_tableres2_to_tableres4(res2);
710 if (a2.args.Args_2_u.appt != NULL)
711 _DtCm_free_appt2(a2.args.Args_2_u.appt);
713 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_2, (char*)res2);
716 a3.target = cal->name;
717 a3.args.tag = APPT_3;
718 a3.args.Args_3_u.appt = _DtCm_appt4_to_appt3(appt4);
720 res3 = _DtCm_rtable_insert_3(&a3, conn);
721 res = _DtCm_tableres3_to_tableres4(res3);
722 if (a3.args.Args_3_u.appt != NULL)
723 _DtCm_free_appt3(a3.args.Args_3_u.appt);
725 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_3, (char*)res3);
728 a4.target = cal->name;
729 a4.args.tag = APPT_4;
730 a4.args.Args_4_u.appt = appt4;
732 res = _DtCm_rtable_insert_4(&a4, conn);
735 stat = CSA_E_FAILURE;
740 switch(res->status) {
742 if (res->res.Table_Res_List_4_u.a) {
743 stat = _DtCm_appt4_to_libentries(cal->name,
744 res->res.Table_Res_List_4_u.a, entry_r);
747 case access_failed_4:
748 stat = CSA_E_NO_AUTHORITY;
751 stat = CSA_E_INVALID_PARAMETER;
753 case access_notable_4:
754 stat = CSA_E_CALENDAR_NOT_EXIST;
756 case access_partial_4:
757 case access_incomplete_4:
758 stat = CSA_E_FAILURE;
761 /* remote system error */
762 DP((errfmt, "table_insert_one", res->status));
763 stat = CSA_E_FAILURE;
766 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_4, (char*)res);
768 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
769 _DtCm_clntstat_to_csastat(conn->stat);
772 _DtCm_free_appt4(appt4);
777 extern CSA_return_code
780 _DtCm_libentry *oentry,
782 CSA_attribute * attrs,
784 _DtCm_libentry **nentry)
786 CSA_return_code stat = CSA_SUCCESS;
787 Table_Res_4 *res = NULL;
788 _DtCm_Connection *conn;
793 _DtCm_libentry *temp;
795 DP(("table.c: _DtCm_table_update_one\n"));
797 if (cal == NULL || oentry == NULL || nentry == NULL)
798 return (CSA_E_INVALID_PARAMETER);
800 /* convert scope to option */
801 if ((stat = _DtCm_scope_to_options4(scope, &opt)) != CSA_SUCCESS)
804 _csa_iso8601_to_tick(oentry->e->attrs[CSA_ENTRY_ATTR_START_DATE_I].\
805 value->item.string_value, &key.tick);
806 key.key = oentry->e->key.id;
808 /* create new appt4 from old entry and new attribute values */
811 stat = _DtCm_libentries_to_appt4(oentry, &appt4);
814 if (stat != CSA_SUCCESS)
817 /* use do_all for old backends */
818 if (appt4->period.period == single_4)
821 /* apply the new attribute values to the appointment */
822 if ((stat = _DtCm_attrs_to_apptdata(num_attrs, attrs, appt4))
824 _DtCm_free_appt4(appt4);
829 /* if the backend's version is less than 4, then it does
830 * not support repeating event types beyond yearly
831 * nor does it support do_forward
834 if (conn->ci->vers_out < TABLEVERS_4 &&
835 (appt4->period.period > yearly_4 || scope >= CSA_SCOPE_FORWARD)) {
836 _DtCm_free_appt4(appt4);
837 return (CSA_E_NOT_SUPPORTED);
840 conn->retry = B_FALSE;
841 switch(conn->ci->vers_out) {
848 a2.target = cal->name;
849 a2.args.tag = APPTID_2;
850 a2.args.Args_2_u.apptid.oid = (Id_2 *)calloc(1, sizeof(Id_2));
851 _DtCm_id4_to_id2(&key, a2.args.Args_2_u.apptid.oid);
852 a2.args.Args_2_u.apptid.new_appt = _DtCm_appt4_to_appt2(appt4);
855 res2 = _DtCm_rtable_change_2(&a2, conn);
857 res2 = _DtCm_rtable_change_instance_2(&a2, conn);
859 res = _DtCm_tableres2_to_tableres4(res2);
860 free(a2.args.Args_2_u.apptid.oid);
861 if (a2.args.Args_2_u.apptid.new_appt != NULL)
862 _DtCm_free_appt2(a2.args.Args_2_u.apptid.new_appt);
864 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_2, (char*)res2);
867 a3.target = cal->name;
868 a3.args.tag = APPTID_3;
869 a3.args.Args_3_u.apptid.oid = (Id_3 *)calloc(1, sizeof(Id_3));
870 _DtCm_id4_to_id3(&key, a3.args.Args_3_u.apptid.oid);
871 a3.args.Args_3_u.apptid.new_appt = _DtCm_appt4_to_appt3(appt4);
875 res3 = _DtCm_rtable_change_3(&a3, conn);
877 res3 = _DtCm_rtable_change_instance_3(&a3, conn);
879 res = _DtCm_tableres3_to_tableres4(res3);
880 free(a3.args.Args_3_u.apptid.oid);
881 if (a3.args.Args_3_u.apptid.new_appt != NULL)
882 _DtCm_free_appt3(a3.args.Args_3_u.apptid.new_appt);
884 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_3, (char*)res3);
887 a4.target = cal->name;
888 a4.args.tag = APPTID_4;
889 a4.args.Args_4_u.apptid.oid = &key;
890 a4.args.Args_4_u.apptid.new_appt = appt4;
891 a4.args.Args_4_u.apptid.option = opt;
893 res = _DtCm_rtable_change_4(&a4, conn);
896 stat = CSA_E_FAILURE;
899 _DtCm_free_appt4(appt4);
902 switch(res->status) {
904 if (res->res.Table_Res_List_4_u.a) {
905 stat = _DtCm_appt4_to_libentries(cal->name,
906 res->res.Table_Res_List_4_u.a, nentry);
909 case access_failed_4:
910 stat = CSA_E_NO_AUTHORITY;
912 case access_notable_4:
913 stat = CSA_E_CALENDAR_NOT_EXIST;
916 case access_partial_4:
917 case access_incomplete_4:
918 stat = CSA_E_FAILURE;
921 /* remote system error */
922 DP((errfmt, "_DtCm_table_update", res->status));
923 stat = CSA_E_FAILURE;
926 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_4, (char*)res);
928 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
929 _DtCm_clntstat_to_csastat(conn->stat);
935 extern CSA_return_code
938 _DtCm_libentry *entry,
941 CSA_return_code stat = CSA_SUCCESS;
942 Table_Res_4 *res = NULL;
943 _DtCm_Connection *conn;
946 cms_attribute *rtype;
948 DP(("table.c: _DtCm_table_delete\n"));
950 if (cal == NULL || entry == NULL)
951 return (CSA_E_INVALID_PARAMETER);
953 _csa_iso8601_to_tick(entry->e->attrs[CSA_ENTRY_ATTR_START_DATE_I].\
954 value->item.string_value, &key.appt_id.tick);
956 /* if this is an one-time appt, make sure the scope is do_all */
957 rtype = &entry->e->attrs[CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I];
958 if (rtype->value == NULL ||
959 rtype->value->item.sint32_value == CSA_X_DT_REPEAT_ONETIME)
960 scope = CSA_SCOPE_ALL;
962 if ((stat = _DtCm_scope_to_options4(scope, &key.option)) != CSA_SUCCESS)
965 key.appt_id.key = entry->e->key.id;
969 if ((key.option == do_forward_4) && (conn->ci->vers_out < TABLEVERS_4))
970 return (CSA_E_NOT_SUPPORTED);
972 conn->retry = B_FALSE;
974 switch(conn->ci->vers_out) {
981 a2.target = cal->name;
983 a2.args.Args_2_u.key = _DtCm_uidopt4_to_uid2(&key);
985 if (key.option == do_all_4)
986 res2 = _DtCm_rtable_delete_2(&a2, conn);
988 res2 = _DtCm_rtable_delete_instance_2(&a2, conn);
990 res = _DtCm_tableres2_to_tableres4(res2);
991 if (a2.args.Args_2_u.key != NULL)
992 free(a2.args.Args_2_u.key);
994 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_2, (char*)res2);
997 a3.target = cal->name;
999 a3.args.Args_3_u.key = _DtCm_uidopt4_to_uid3(&key);
1002 if (key.option == do_all_4)
1003 res3 = _DtCm_rtable_delete_3(&a3, conn);
1005 res3 = _DtCm_rtable_delete_instance_3(&a3, conn);
1007 res = _DtCm_tableres3_to_tableres4(res3);
1008 if (a3.args.Args_3_u.key != NULL)
1009 free(a3.args.Args_3_u.key);
1011 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_3, (char*)res3);
1014 a4.target = cal->name;
1015 a4.args.tag = UIDOPT_4;
1016 a4.args.Args_4_u.uidopt = &key;
1018 res = _DtCm_rtable_delete_4(&a4, conn);
1021 stat = CSA_E_FAILURE;
1026 switch(res->status) {
1028 if (res->res.Table_Res_List_4_u.a == NULL)
1029 stat = CSA_X_DT_E_ENTRY_NOT_FOUND |
1030 CSA_E_INVALID_ENTRY_HANDLE;
1032 case access_failed_4:
1033 stat = CSA_E_NO_AUTHORITY;
1035 case access_other_4:
1036 stat = CSA_E_INVALID_PARAMETER;
1038 case access_notable_4:
1039 case access_partial_4:
1040 case access_incomplete_4:
1041 stat = CSA_E_FAILURE;
1044 /* remote system error */
1045 DP((errfmt, "table_delete", res->status));
1046 stat = CSA_E_FAILURE;
1049 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_4, (char*)res);
1052 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
1053 _DtCm_clntstat_to_csastat(conn->stat);
1059 extern CSA_return_code
1060 _DtCm_table_size(Calendar *cal, int *size)
1063 CSA_return_code stat = CSA_SUCCESS;
1064 _DtCm_Connection *conn;
1066 DP(("table.c: _DtCm_table_size\n"));
1068 if (cal == NULL || size == NULL)
1069 return (CSA_E_INVALID_PARAMETER);
1072 conn->retry = B_TRUE;
1074 switch(conn->ci->vers_out) {
1079 a2.target = cal->name;
1080 a2.args.tag = TICK_2;
1081 a2.args.Args_2_u.tick = 0;
1082 res = _DtCm_rtable_size_2(&a2, conn);
1085 a3.target = cal->name;
1086 a3.args.tag = TICK_3;
1087 a3.args.Args_3_u.tick = 0;
1089 res = _DtCm_rtable_size_3(&a3, conn);
1092 a4.target = cal->name;
1093 a4.args.tag = TICK_4;
1094 a4.args.Args_4_u.tick = 0;
1096 res = _DtCm_rtable_size_4(&a4, conn);
1099 stat = CSA_E_FAILURE;
1106 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
1107 _DtCm_clntstat_to_csastat(conn->stat);
1113 extern CSA_return_code
1114 _DtCm_table_lookup_reminder(
1116 CSA_uint32 num_names,
1117 char **reminder_names,
1118 CSA_uint32 *num_rems,
1119 CSA_reminder_reference **rems)
1121 CSA_return_code stat = CSA_SUCCESS;
1122 Table_Res_4 *res = NULL;
1123 _DtCm_Connection *conn;
1127 DP(("table.c: _DtCm_table_lookup_reminder\n"));
1129 if (cal == NULL || num_rems == 0 || rems == NULL)
1130 return (CSA_E_INVALID_PARAMETER);
1133 * Due to the implementation of existing backends which
1134 * will unmanage any reminders that happens before the
1135 * the given tick, the user specified tick is ignore and
1136 * we will pass in the current time.
1141 conn->retry = B_TRUE;
1143 switch(conn->ci->vers_out) {
1150 a2.target = cal->name;
1151 a2.args.tag = TICK_2;
1152 a2.args.Args_2_u.tick = tick;
1153 res2 = _DtCm_rtable_lookup_next_reminder_2(&a2, conn);
1154 res = _DtCm_tableres2_to_tableres4(res2);
1156 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_2, (char*)res2);
1159 a3.target = cal->name;
1160 a3.args.tag = TICK_3;
1161 a3.args.Args_3_u.tick = tick;
1163 res3 = _DtCm_rtable_lookup_next_reminder_3(&a3, conn);
1164 res = _DtCm_tableres3_to_tableres4(res3);
1166 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_3, (char*)res3);
1169 a4.target = cal->name;
1170 a4.args.tag = TICK_4;
1171 a4.args.Args_4_u.tick = tick;
1173 res = _DtCm_rtable_lookup_next_reminder_4(&a4, conn);
1176 stat = CSA_E_FAILURE;
1181 switch(res->status) {
1184 * if reminder names are specified,
1185 * return only those that match
1187 rptr = _DtCm_copy_reminder4(res->res.Table_Res_List_4_u.r);
1188 xdr_free((xdrproc_t)_DtCm_xdr_Table_Res_4, (char*)res);
1190 if (num_names > 0 && reminder_names != NULL) {
1191 rptr = _DtCm_match_reminders(rptr, num_names,
1195 stat = _DtCm_reminder4_to_csareminder(rptr, num_rems,
1199 _DtCm_free_reminder4(rptr);
1201 case access_notable_4:
1202 stat = CSA_E_CALENDAR_NOT_EXIST;
1204 case access_failed_4:
1205 case access_other_4:
1206 stat = CSA_E_FAILURE;
1209 /* remote system error */
1210 DP ((errfmt, "_DtCm_table_lookup_reminder", res->status));
1211 stat = CSA_E_FAILURE;
1215 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
1216 _DtCm_clntstat_to_csastat(conn->stat);
1222 extern CSA_return_code
1223 _DtCm_table_unregister_target(
1224 _DtCm_Connection *conn,
1227 CSA_return_code stat;
1228 Registration_Status_4 res;
1229 boolean_t nullreturned = B_FALSE;
1231 DP(("table.c: _DtCm_table_unregister_target\n"));
1233 switch(conn->ci->vers_out) {
1237 Registration_Status_2 *stat2;
1238 Registration_Status_3 *stat3;
1239 Registration_Status_4 *stat4;
1242 r2.target = calendar;
1243 r2.prognum = _DtCm_transient;
1244 r2.versnum = AGENTVERS;
1245 r2.procnum = update_callback;
1247 stat2 = _DtCm_deregister_callback_2(&r2, conn);
1249 res = _DtCm_regstat2_to_regstat4(*stat2);
1251 nullreturned = B_TRUE;
1255 r3.target = calendar;
1256 r3.prognum = _DtCm_transient;
1257 r3.versnum = AGENTVERS;
1258 r3.procnum = update_callback;
1261 stat3 = _DtCm_deregister_callback_3(&r3, conn);
1263 res = _DtCm_regstat3_to_regstat4(*stat3);
1265 nullreturned = B_TRUE;
1269 r4.target = calendar;
1270 r4.prognum = _DtCm_transient;
1271 r4.versnum = AGENTVERS;
1272 r4.procnum = update_callback;
1275 stat4 = _DtCm_deregister_callback_4(&r4, conn);
1279 nullreturned = B_TRUE;
1282 stat = CSA_E_FAILURE;
1286 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
1287 _DtCm_clntstat_to_csastat(conn->stat);
1290 case deregistered_4:
1295 stat = CSA_E_CALENDAR_NOT_EXIST;
1299 stat = CSA_E_FAILURE;
1307 extern CSA_return_code
1308 _DtCm_table_register_target(
1309 _DtCm_Connection *conn,
1312 CSA_return_code stat;
1313 Registration_Status_4 res;
1314 boolean_t nullreturned = B_FALSE;
1316 DP(("table.c: _DtCm_table_register_target\n"));
1318 switch(conn->ci->vers_out) {
1322 Registration_Status_2 *stat2;
1323 Registration_Status_3 *stat3;
1324 Registration_Status_4 *stat4;
1327 r2.target = calendar;
1328 r2.prognum = _DtCm_transient;
1329 r2.versnum = AGENTVERS;
1330 r2.procnum = update_callback;
1332 stat2 = _DtCm_register_callback_2(&r2, conn);
1334 res = _DtCm_regstat2_to_regstat4(*stat2);
1336 nullreturned = B_TRUE;
1340 r3.target = calendar;
1341 r3.prognum = _DtCm_transient;
1342 r3.versnum = AGENTVERS;
1343 r3.procnum = update_callback;
1346 stat3 = _DtCm_register_callback_3(&r3, conn);
1348 res = _DtCm_regstat3_to_regstat4(*stat3);
1350 nullreturned = B_TRUE;
1354 r4.target = calendar;
1355 r4.prognum = _DtCm_transient;
1356 r4.versnum = AGENTVERS;
1357 r4.procnum = update_callback;
1360 stat4 = _DtCm_register_callback_4(&r4, conn);
1364 nullreturned = B_TRUE;
1367 stat = CSA_E_FAILURE;
1371 stat = (conn->stat == RPC_SUCCESS) ? CSA_E_SERVICE_UNAVAILABLE :
1372 _DtCm_clntstat_to_csastat(conn->stat);
1380 stat = CSA_E_CALENDAR_NOT_EXIST;
1384 stat = CSA_E_FAILURE;
1391 /*****************************************************************************
1392 * static functions used within the file
1393 *****************************************************************************/
1396 * Returns 1 if stat contains an invalid status
1398 static CSA_return_code
1399 tablestat_to_dtcmstat(Table_Status_4 stat, CSA_return_code *dtcmstat)
1403 *dtcmstat = CSA_SUCCESS;
1406 *dtcmstat = CSA_E_CALENDAR_EXISTS;
1409 *dtcmstat = CSA_E_CALENDAR_NOT_EXIST;
1412 *dtcmstat = CSA_E_NO_AUTHORITY;
1416 *dtcmstat = CSA_E_FAILURE;
1418 case tbl_not_owner_4:
1419 *dtcmstat = CSA_E_NO_AUTHORITY;
1422 *dtcmstat = CSA_E_CALENDAR_EXISTS;
1424 case tbl_notsupported_4:
1425 *dtcmstat = CSA_E_NOT_SUPPORTED;
1428 *dtcmstat = CSA_E_FAILURE;
1429 return (CSA_E_FAILURE);
1432 return (CSA_SUCCESS);