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: cmsfunc.c /main/4 1995/11/09 12:42:12 rswiston $ */
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>
38 #include <sys/resource.h>
46 #include "cmscalendar.h"
47 #include "updateattrs.h"
51 #include "rpcextras.h"
64 #include "convert4-5.h"
65 #include "convert5-4.h"
67 #include "cmsconvert.h"
71 /******************************************************************************
72 * forward declaration of static functions used within the file
73 ******************************************************************************/
75 static CSA_return_code _DtCmsCreateCallog(char *user, cms_create_args *args,
76 _DtCmsCalendar **cal);
77 static CSA_return_code _ListCalendarNames(uint *num_names, char ***names);
78 static void * _grow_char_array(void *ptr, uint oldcount, uint newcount);
79 static void _free_char_array(uint num_elem, char **ptr);
80 static CSA_return_code _DtCmsGetOldCalAttrNames(_DtCmsCalendar *cal,
81 uint *num_names_r, cms_attr_name **names_r);
83 /*****************************************************************************
84 * extern functions used in the library
85 *****************************************************************************/
88 cms_ping_5_svc(void *args, struct svc_req *svcrq)
91 fprintf(stderr, "cms_ping_5_svc called\n");
93 return(NULL); /* for RPC reply */
97 extern cms_list_calendars_res *
98 cms_list_calendars_5_svc(void *dummy, struct svc_req *svcrq)
100 static cms_list_calendars_res res;
103 fprintf(stderr, "cms_list_calendars_5_svc called\n");
105 if (res.num_names > 0) {
106 _free_char_array(res.num_names, res.names);
110 res.stat = _ListCalendarNames(&res.num_names, &res.names);
115 extern cms_open_res *
116 cms_open_calendar_5_svc(cms_open_args *args, struct svc_req *svcrq)
118 static cms_open_res res;
119 static char sversion[80];
124 fprintf(stderr, "cms_open_calendar_5_svc called\n");
126 if (res.num_attrs > 0) {
127 _DtCm_free_cms_attributes(res.num_attrs, res.attrs);
132 /* check parameter */
133 if (args->cal == NULL) {
134 res.stat = CSA_E_INVALID_PARAMETER;
138 if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
139 &res.user_access, &cal)) == CSA_SUCCESS) {
141 res.svr_vers = TABLEVERS;
143 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
145 res.file_vers = cal->fversion;
148 /* old format data */
149 res.file_vers = _DtCM_FIRST_EXTENSIBLE_DATA_VERSION - 1;
152 /* return attribute names */
153 res.stat = _DtCmsGetAllCalAttrs(cal, &res.num_attrs,
154 &res.attrs, B_FALSE);
157 if (res.stat == CSA_SUCCESS) {
159 cal->rlist = _DtCmsDoOpenCalCallback(cal->rlist,
160 cal->calendar, user, args->pid);
167 extern CSA_return_code *
168 cms_create_calendar_5_svc(cms_create_args *args, struct svc_req *svcrq)
170 static CSA_return_code res;
175 fprintf(stderr, "cms_create_calendar_5_svc called\n");
177 /* check parameter */
178 if (args->cal == NULL) {
179 res = CSA_E_INVALID_PARAMETER;
183 /* need to check whether we know about the sender,
184 * if not, fail the request
186 if ((res = _DtCmsGetClientInfo(svcrq, &user)) != CSA_SUCCESS) {
190 if ((res = _DtCm_check_cal_cms_attributes(_DtCMS_VERSION4,
191 args->num_attrs, args->attrs, user, args->cal, B_TRUE, B_TRUE,
192 B_FALSE)) != CSA_SUCCESS)
195 if ((res = _DtCmsGetCalendarByName(args->cal, B_FALSE, &cal))
196 == CSA_SUCCESS && cal != NULL) {
198 res = CSA_E_CALENDAR_EXISTS;
202 /* create callog file for new calendar */
203 res = _DtCmsCreateCallog(user, args, &cal);
209 extern CSA_return_code *
210 cms_remove_calendar_5_svc(cms_remove_args *args, struct svc_req *svcrq)
212 static CSA_return_code res;
218 fprintf(stderr, "cms_remove_calendar_5_svc called\n");
220 if ((res = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
221 &access, &cal)) != CSA_SUCCESS)
224 if (!(access & CSA_OWNER_RIGHTS)) {
226 res = CSA_E_NO_AUTHORITY;
230 /* move callog.name file to calrm.name */
231 res = _DtCmsRemoveLog(cal->calendar, user);
233 if (res != CSA_SUCCESS)
237 cal->rlist = _DtCmsDoRemoveCalCallback(cal->rlist,
238 cal->calendar, user, args->pid);
240 /* free up internal structures */
241 _DtCmsFreeCalendar(cal);
247 extern CSA_return_code *
248 cms_register_5_svc(cms_register_args *args, struct svc_req *svcrq)
250 static CSA_return_code res;
253 _DtCmsRegistrationInfo *rinfo;
256 fprintf(stderr, "cms_register_5_svc called\n");
258 if (args->cal == NULL ||
259 args->update_type >= (CSA_CB_ENTRY_UPDATED << 1)) {
260 res = CSA_E_INVALID_PARAMETER;
264 if ((res = _DtCmsGetClientInfo(svcrq, &user)) != CSA_SUCCESS)
267 if ((res = _DtCmsGetCalendarByName(args->cal, B_TRUE, &cal))
271 if ((rinfo = _DtCmsGetRegistration(&(cal->rlist), user, args->prognum,
272 args->versnum, args->procnum, args->pid)) == NULL) {
273 /* this client has not registered */
275 if ((rinfo = _DtCmsMakeRegistrationInfo(user,
276 args->update_type, args->prognum, args->versnum,
277 args->procnum, args->pid)) == NULL) {
278 res = CSA_E_INSUFFICIENT_MEMORY;
282 /* put in the calendar's registration list */
283 rinfo->next = cal->rlist;
287 fprintf(stderr, "%s registered on %s, old types = %d\n",
288 user, args->cal, rinfo->types);
291 /* add new type to the registration */
292 rinfo->types = rinfo->types | args->update_type;
296 fprintf(stderr, "%s registered on %s, types = %d\n",
297 user, args->cal, rinfo->types);
304 extern CSA_return_code *
305 cms_unregister_5_svc(cms_register_args *args, struct svc_req *svcrq)
307 static CSA_return_code res;
310 _DtCmsRegistrationInfo *rinfo;
313 fprintf(stderr, "cms_unregister_5_svc called\n");
315 if (args->cal == NULL ||
316 args->update_type >= (CSA_CB_ENTRY_UPDATED << 1)) {
317 res = CSA_E_INVALID_PARAMETER;
321 if ((res = _DtCmsGetClientInfo(svcrq, &user)) != CSA_SUCCESS)
324 if ((res = _DtCmsGetCalendarByName(args->cal, B_FALSE, &cal))
328 if (cal == NULL || (rinfo = _DtCmsGetRegistration(&(cal->rlist), user,
329 args->prognum, args->versnum, args->procnum, args->pid)) == NULL) {
330 res = CSA_E_CALLBACK_NOT_REGISTERED;
334 /* update registration info */
336 fprintf(stderr, "%s registered on %s, old types = %d\n",
337 user, args->cal, rinfo->types);
340 /* registered bits are cleared, unregistered bits are ignored */
341 rinfo->types = (rinfo->types | args->update_type) ^ args->update_type;
344 fprintf(stderr, "%s unregistered types %d on %s, new types = %d\n",
345 user, args->update_type, args->cal, rinfo->types);
348 if (rinfo->types == 0) {
349 cal->rlist = _DtCmsRemoveRegistration(cal->rlist, rinfo);
356 extern cms_enumerate_calendar_attr_res *
357 cms_enumerate_calendar_attr_5_svc(buffer *args, struct svc_req *svcrq)
359 static cms_enumerate_calendar_attr_res res;
366 fprintf(stderr, "cms_enumerate_calendar_attr_5_svc called\n");
368 if (res.num_names > 0) {
369 _DtCmsFreeCmsAttrNames(res.num_names, res.names);
373 if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, *args, &user,
374 &access, &cal)) != CSA_SUCCESS)
377 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
378 if (!_DTCMS_HAS_VIEW_CALENDAR_ATTR_ACCESS(access)) {
379 res.stat = CSA_E_NO_AUTHORITY;
383 res.stat = _DtCmsGetCalAttrNames(cal, &res.num_names,
386 res.stat = _DtCmsGetOldCalAttrNames(cal, &res.num_names,
393 extern cms_get_cal_attr_res *
394 cms_get_calendar_attr_5_svc(cms_get_cal_attr_args *args, struct svc_req *svcrq)
396 static cms_get_cal_attr_res res;
402 fprintf(stderr, "cms_get_calendar_attr_5_svc called\n");
404 if (res.num_attrs > 0) {
405 _DtCm_free_cms_attributes(res.num_attrs, res.attrs);
410 if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
411 &access, &cal)) != CSA_SUCCESS)
414 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
415 !_DTCMS_HAS_VIEW_CALENDAR_ATTR_ACCESS(access)) {
416 res.stat = CSA_E_NO_AUTHORITY;
420 if (args->num_names > 0)
421 res.stat = _DtCmsGetCalAttrsByName(cal, args->num_names,
422 args->names, &res.num_attrs, &res.attrs);
424 res.stat = _DtCmsGetAllCalAttrs(cal, &res.num_attrs,
430 extern CSA_return_code *
431 cms_set_calendar_attr_5_svc(cms_set_cal_attr_args *args, struct svc_req *svcrq)
433 static CSA_return_code res;
439 fprintf(stderr, "cms_set_calendar_attr_5_svc called\n");
441 if ((res = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
442 &access, &cal)) != CSA_SUCCESS)
445 if ((cal->fversion < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
446 !(access & CSA_OWNER_RIGHTS)) ||
447 (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
448 !(access & (CSA_OWNER_RIGHTS | CSA_INSERT_CALENDAR_ATTRIBUTES |
449 CSA_CHANGE_CALENDAR_ATTRIBUTES)))) {
450 res = CSA_E_NO_AUTHORITY;
455 if (args->cal == NULL || args->num_attrs == 0) {
456 res = CSA_E_INVALID_PARAMETER;
460 /* check validity of attribute values */
461 if ((res = _DtCm_check_cal_cms_attributes(
462 (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
463 cal->fversion : _DtCM_FIRST_EXTENSIBLE_DATA_VERSION - 1),
464 args->num_attrs, args->attrs, NULL, NULL, B_TRUE, B_FALSE, B_TRUE))
468 if (cal->fversion >=_DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
469 if ((res = _DtCmsUpdateCalAttributesAndLog(cal, args->num_attrs,
470 args->attrs, access)) != CSA_SUCCESS)
476 Access_Entry_4 *v4list;
478 /* for old format file, the only settable calendar attribute
481 for (i = args->num_attrs - 1; i >= 0; i--) {
482 if (args->attrs[i].name.name)
486 if (args->attrs[i].value == NULL ||
487 args->attrs[i].value->item.access_list_value == NULL) {
488 res = _DtCmsSetV4AccessListAndLog(cal, NULL);
490 if ((res = _DtCmsCmsAccessToV4Access(
491 args->attrs[i].value->item.access_list_value,
492 &v4list)) == CSA_SUCCESS)
493 res = _DtCmsSetV4AccessListAndLog(cal, v4list);
496 if (res != CSA_SUCCESS)
501 cal->rlist = _DtCmsDoUpdateCalAttrsCallback(cal->rlist, cal->calendar,
502 user, args->num_attrs, args->attrs, args->pid);
510 extern cms_archive_res *
511 cms_archive_5_svc(cms_archive_args *args, struct svc_req *svcrq)
513 static cms_archive_res res;
516 fprintf(stderr, "cms_archive_5_svc called\n");
518 res.stat = CSA_E_NOT_SUPPORTED;
522 extern CSA_return_code *
523 cms_restore_5_svc(cms_restore_args *args, struct svc_req *svcrq)
525 static CSA_return_code res;
528 fprintf(stderr, "cms_restore_5_svc called\n");
530 res = CSA_E_NOT_SUPPORTED;
534 extern cms_reminder_res *
535 cms_lookup_reminder_5_svc(cms_reminder_args *args, struct svc_req *svcrq)
537 static cms_reminder_res res;
543 fprintf(stderr, "cms_lookup_reminder_5_svc called\n");
545 if (res.rems != NULL) {
546 _DtCmsFreeReminderRef(res.rems);
550 if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
551 &access, &cal)) != CSA_SUCCESS)
554 if ((access & CSA_OWNER_RIGHTS) == 0) {
555 res.stat = CSA_E_NO_AUTHORITY;
559 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
560 res.stat = _DtCmsLookupReminder(cal->remq, args->tick,
561 args->num_names, args->names, &res.rems);
566 if ((res.stat = _DtCmsGetV4Reminders(cal, time(0), &v4rem,
567 &ids)) == CSA_SUCCESS) {
568 res.stat = _DtCmsV4ReminderToReminderRef(cal->calendar,
569 v4rem, ids, &res.rems);
570 _DtCm_free_reminder4(v4rem);
571 _DtCmsFreeEntryIds(ids);
578 extern cms_entries_res *
579 cms_lookup_entries_5_svc(cms_lookup_entries_args *args, struct svc_req *svcrq)
581 static cms_entries_res res;
585 time_t start1, start2, end1, end2;
588 boolean_t no_start_time_range, no_end_time_range;
590 cms_attribute *hattrs;
594 fprintf(stderr, "cms_lookup_entries_5_svc called\n");
597 _DtCm_free_cms_entries(res.entries);
601 if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
602 &access, &cal)) != CSA_SUCCESS)
605 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
606 !_DTCMS_HAS_VIEW_ACCESS(access)) {
607 res.stat = CSA_E_NO_AUTHORITY;
612 if ((res.stat = _DtCm_check_operator(args->num_attrs, NULL,
613 args->attrs, args->ops)) != CSA_SUCCESS)
617 if ((res.stat = _DtCmHashCriteria(
618 cal->fversion < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
619 _DtCm_entry_name_tbl : cal->entry_tbl, args->num_attrs,
620 NULL, args->attrs, args->ops, &no_match, &no_start_time_range,
621 &no_end_time_range, &start1, &start2, &end1, &end2, &id,
622 &hnum, &hattrs, &hops)) == CSA_E_INVALID_ATTRIBUTE) {
624 /* attribute not defined in this calendar specified,
627 res.stat = CSA_SUCCESS;
630 } else if (res.stat != CSA_SUCCESS || no_match == B_TRUE)
634 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
636 res.stat = _DtCmsLookupEntriesById(cal, user, access,
637 no_start_time_range, no_end_time_range,
638 start1, start2, end1, end2, id, hnum,
639 hattrs, hops, &res.entries);
641 res.stat = _DtCmsLookupEntries(cal, user, access,
642 start1, start2, no_end_time_range,
643 end1, end2, hnum, hattrs, hops,
647 Appt_4 *appt = NULL;;
650 res.stat = _DtCmsLookupKeyrangeV4(cal, user, access,
651 no_start_time_range, no_end_time_range,
652 start1, start2, end1, end2, id,
653 _DtCm_match_one_appt, hnum, hattrs,
656 prange.key1 = start1;
657 prange.key2 = start2;
659 res.stat = _DtCmsLookupRangeV4(cal, user, access,
660 &prange, no_end_time_range, end1, end2,
661 _DtCm_match_one_appt, hnum,
662 hattrs, hops, &appt, NULL);
665 if (res.stat == CSA_SUCCESS && appt) {
666 res.stat = _DtCmsAppt4ToCmsentriesForClient(args->cal,
668 _DtCm_free_appt4(appt);
672 _DtCmFreeHashedArrays(hnum, hattrs, hops);
677 extern cms_entries_res *
678 cms_enumerate_sequence_5_svc(cms_enumerate_args *args, struct svc_req *svcrq)
680 static cms_entries_res res;
686 fprintf(stderr, "cms_enumerate_sequence_5_svc called\n");
689 _DtCm_free_cms_entries(res.entries);
693 if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
694 &access, &cal)) != CSA_SUCCESS)
697 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
698 !_DTCMS_HAS_VIEW_ACCESS(access)) {
699 res.stat = CSA_E_NO_AUTHORITY;
704 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
705 res.stat = _DtCmsEnumerateSequenceById(cal, user, access,
706 B_FALSE, B_TRUE, args->start, args->end,
707 0, 0, args->id, 0, NULL, NULL, &res.entries);
711 res.stat = _DtCmsLookupKeyrangeV4(cal, user, access,
712 B_FALSE, B_TRUE, args->start, args->end,
713 0, 0, args->id, NULL, 0, NULL, NULL, &appt,
716 if (res.stat == CSA_SUCCESS && appt) {
717 res.stat = _DtCmsAppt4ToCmsentriesForClient(args->cal,
719 _DtCm_free_appt4(appt);
726 extern cms_get_entry_attr_res *
727 cms_get_entry_attr_5_svc(cms_get_entry_attr_args *args, struct svc_req *svcrq)
729 static cms_get_entry_attr_res res;
735 fprintf(stderr, "cms_get_entry_attr_5_svc called\n");
738 _DtCmsFreeEntryAttrResItem(res.entries);
742 if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
743 &access, &cal)) != CSA_SUCCESS)
746 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
747 !_DTCMS_HAS_VIEW_ACCESS(access)) {
748 res.stat = CSA_E_NO_AUTHORITY;
753 if (args->num_keys == 0) {
754 res.stat = CSA_E_INVALID_PARAMETER;
758 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
759 res.stat = _DtCmsLookupEntriesByKey(cal, user, access,
760 args->num_keys, args->keys, args->num_names,
761 args->names, &res.entries);
763 res.stat = CSA_E_NOT_SUPPORTED;
769 extern cms_entry_res *
770 cms_insert_entry_5_svc(cms_insert_args *args, struct svc_req *svcrq)
772 static cms_entry_res res;
777 uint access, needaccess;
781 fprintf(stderr, "cms_insert_entry_5_svc called\n");
783 if (res.entry != NULL) {
784 res.entry->num_attrs--;
785 _DtCm_free_cms_entry(res.entry);
789 if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
790 &access, &cal)) != CSA_SUCCESS)
793 if ((cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
794 !_DTCMS_HAS_INSERT_ACCESS(access)) ||
795 (cal->fversion < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
796 !_DTCMS_HAS_V4_WRITE_ACCESS(access))) {
797 res.stat = CSA_E_NO_AUTHORITY;
802 if (args->cal == NULL || args->num_attrs == 0) {
803 res.stat = CSA_E_INVALID_PARAMETER;
807 /* check validity of attribute values */
808 if ((res.stat = _DtCm_check_entry_cms_attributes(
809 (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
810 cal->fversion : _DtCM_FIRST_EXTENSIBLE_DATA_VERSION - 1),
811 args->num_attrs, args->attrs, CSA_CB_ENTRY_ADDED, B_TRUE))
815 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
816 if ((res.stat = _DtCmsMakeHashedEntry(cal, args->num_attrs,
817 args->attrs, &entry)) != CSA_SUCCESS)
820 if ((res.stat = _DtCmsCheckInitialAttributes(entry))
822 _DtCm_free_cms_entry(entry);
826 /* check access rights */
827 needaccess = _DtCmsClassToInsertAccess(entry);
828 if ((access & (CSA_OWNER_RIGHTS | needaccess)) == 0) {
829 _DtCm_free_cms_entry(entry);
830 res.stat = CSA_E_NO_AUTHORITY;
835 if ((res.stat = _DtCm_set_string_attrval(user,
836 &entry->attrs[CSA_ENTRY_ATTR_ORGANIZER_I].value,
837 CSA_VALUE_CALENDAR_USER)) != CSA_SUCCESS) {
838 _DtCm_free_cms_entry(entry);
842 /* insert entry and log it */
843 if ((res.stat = _DtCmsInsertEntryAndLog(cal, entry))
845 _DtCm_free_cms_entry(entry);
851 if ((appt = _DtCm_make_appt4(B_TRUE)) == NULL) {
852 res.stat = CSA_E_INSUFFICIENT_MEMORY;
856 if ((res.stat = _DtCmsAttrsToAppt4(args->num_attrs,
857 args->attrs, appt, B_TRUE)) != CSA_SUCCESS) {
858 _DtCm_free_appt4(appt);
862 if (appt->author) free(appt->author);
863 if ((appt->author = strdup(user)) == NULL) {
864 _DtCm_free_appt4(appt);
869 * calculate the correct start day,
871 _DtCms_adjust_appt_startdate(appt);
873 if ((res.stat = _DtCmsInsertApptAndLog(cal, appt))
875 _DtCm_free_appt4(appt);
879 key.id = appt->appt_id.key;
880 key.time = appt->appt_id.tick;
883 if (res.stat == CSA_SUCCESS)
884 cal->modified = B_TRUE;
889 cal->rlist = _DtCmsDoV1CbForV4Data(cal->rlist, user, args->pid,
892 cal->rlist = _DtCmsDoInsertEntryCallback(cal->rlist, cal->calendar,
893 user, key.id, args->pid);
896 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ||
897 (cal->fversion < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
898 (res.stat = _DtCmsAppt4ToCmsentriesForClient(cal->calendar, appt,
899 &entry)) == CSA_SUCCESS)) {
901 res.stat = _DtCmsGetCmsEntryForClient(entry, &res.entry, B_FALSE);
903 _DtCm_free_cms_entry(entry);
909 extern cms_entry_res *
910 cms_update_entry_5_svc(cms_update_args *args, struct svc_req *svcrq)
912 static cms_entry_res res;
917 uint access, needaccess;
921 fprintf(stderr, "cms_update_entry_5_svc called\n");
923 if (res.entry != NULL) {
924 res.entry->num_attrs--;
925 _DtCm_free_cms_entry(res.entry);
929 if ((res.stat = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
930 &access, &cal)) != CSA_SUCCESS)
933 if ((cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
934 !_DTCMS_HAS_CHANGE_ACCESS(access)) ||
935 (cal->fversion < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
936 !_DTCMS_HAS_V4_WRITE_ACCESS(access))) {
937 res.stat = CSA_E_NO_AUTHORITY;
942 if (args->cal == NULL || args->entry.id <= 0 || args->num_attrs == 0) {
943 res.stat = CSA_E_INVALID_PARAMETER;
947 if (args->scope < CSA_SCOPE_ALL || args->scope > CSA_SCOPE_FORWARD) {
948 res.stat = CSA_E_INVALID_ENUM;
952 /* check validity of attribute values */
953 if ((res.stat = _DtCm_check_entry_cms_attributes(
954 (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
955 cal->fversion : _DtCM_FIRST_EXTENSIBLE_DATA_VERSION - 1),
956 args->num_attrs, args->attrs, CSA_CB_ENTRY_UPDATED, B_TRUE))
960 /* get event from one-time event tree */
961 event = (caddr_t)rb_lookup(cal->tree, (caddr_t)&args->entry);
963 /* update entry and log it */
964 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
965 if (event != NULL || args->scope == CSA_SCOPE_ALL) {
966 res.stat = _DtCmsUpdateEntry(cal, user, access,
967 &args->entry, args->num_attrs,
968 args->attrs, NULL, &newentry);
970 res.stat = _DtCmsUpdateInstances(cal, user, access,
971 &args->entry, args->scope,
972 args->num_attrs, args->attrs, NULL,
978 if (event != NULL || args->scope == CSA_SCOPE_ALL)
981 opt = (args->scope == CSA_SCOPE_ONE) ?
982 do_one_4 : do_forward_4;
984 if (event == NULL && (event = hc_lookup(cal->list,
985 (caddr_t)&args->entry)) == NULL) {
987 res.stat = CSA_X_DT_E_ENTRY_NOT_FOUND;
989 } else if ((appt = _DtCm_copy_one_appt4((Appt_4 *)event))
992 res.stat = CSA_E_INSUFFICIENT_MEMORY;
995 /* get rid of exceptions */
996 _DtCm_free_excpt4(appt->exception);
997 appt->exception = NULL;
999 if ((res.stat = _DtCmsAttrsToAppt4(args->num_attrs,
1000 args->attrs, appt, B_TRUE)) == CSA_SUCCESS) {
1002 if (opt == do_all_4)
1003 res.stat = _DtCmsChangeAll(cal, user,
1004 access, (Id_4 *)&args->entry,
1007 res.stat = _DtCmsChangeSome(cal, user,
1008 access, (Id_4 *)&args->entry,
1015 if (res.stat == CSA_SUCCESS)
1016 cal->modified = B_TRUE;
1021 cal->rlist = _DtCmsDoV1CbForV4Data(cal->rlist, user, args->pid,
1023 (appt ? (cms_key *)&appt->appt_id : &newentry->key));
1025 cal->rlist = _DtCmsDoUpdateEntryCallback(cal->rlist, cal->calendar,
1026 user, (appt ? appt->appt_id.key : newentry->key.id),
1027 args->entry.id, args->scope, args->entry.time,
1031 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ||
1032 (cal->fversion < _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
1033 (res.stat = _DtCmsAppt4ToCmsentriesForClient(cal->calendar, appt,
1034 &newentry)) == CSA_SUCCESS)) {
1036 res.stat = _DtCmsGetCmsEntryForClient(newentry, &res.entry, B_FALSE);
1038 _DtCm_free_cms_entry(newentry);
1044 extern CSA_return_code *
1045 cms_delete_entry_5_svc(cms_delete_args *args, struct svc_req *svcrq)
1047 static CSA_return_code res;
1048 _DtCmsCalendar *cal;
1051 uint access, needaccess;
1054 fprintf(stderr, "cms_delete_entry_5_svc called\n");
1056 if ((res = _DtCmsV5LoadAndCheckAccess(svcrq, args->cal, &user,
1057 &access, &cal)) != CSA_SUCCESS)
1060 /* for v3 data, authority check is done in the routines doing the
1061 * deletion since we may need to check the organizer
1063 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION &&
1064 !_DTCMS_HAS_CHANGE_ACCESS(access)) {
1065 res = CSA_E_NO_AUTHORITY;
1069 /* check argument */
1070 if (args->cal == NULL || args->entry.id <= 0) {
1071 res = CSA_E_INVALID_PARAMETER;
1075 if (args->scope < CSA_SCOPE_ALL || args->scope > CSA_SCOPE_FORWARD) {
1076 res = CSA_E_INVALID_ENUM;
1081 /* get event from one-time event tree */
1082 event = (caddr_t)rb_lookup(cal->tree, (caddr_t)&args->entry);
1084 /* delete entry and log it */
1085 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
1086 if (event != NULL || args->scope == CSA_SCOPE_ALL) {
1087 res = _DtCmsDeleteEntryAndLog(cal, user, access,
1088 &args->entry, NULL);
1090 res = _DtCmsDeleteInstancesAndLog(cal, user, access,
1091 &args->entry, args->scope, NULL, NULL);
1094 if (event != NULL || args->scope == CSA_SCOPE_ALL) {
1095 res = _DtCmsDeleteApptAndLog(cal, user, access,
1096 (Id_4 *)&args->entry, NULL);
1098 res = _DtCmsDeleteApptInstancesAndLog(cal, user, access,
1099 (Id_4 *)&args->entry,
1100 ((args->scope == CSA_SCOPE_ONE) ? do_one_4 :
1101 do_forward_4), NULL, NULL);
1105 if (res == CSA_SUCCESS)
1106 cal->modified = B_TRUE;
1111 cal->rlist = _DtCmsDoV1CbForV4Data(cal->rlist, user, args->pid,
1112 &args->entry, NULL);
1114 cal->rlist = _DtCmsDoDeleteEntryCallback(cal->rlist, cal->calendar,
1115 user, args->entry.id, args->scope, args->entry.time,
1122 void initfunctable(program_handle ph)
1124 ph->program_num = TABLEPROG;
1125 ph->prog[TABLEVERS].vers = &tableprog_5_table[0];
1126 ph->prog[TABLEVERS].nproc = sizeof(tableprog_5_table)/sizeof(tableprog_5_table[0]);
1129 /*****************************************************************************
1130 * static functions used within the file
1131 *****************************************************************************/
1133 static CSA_return_code
1134 _DtCmsCreateCallog(char *user, cms_create_args *args, _DtCmsCalendar **newcal)
1136 CSA_return_code stat;
1137 _DtCmsCalendar *cal;
1143 cms_attribute_value val;
1144 cms_access_entry aentry;
1145 int nidx = 0, oidx = 0;
1149 * if calendar name is a user name, make sure that
1150 * it's the same as the sender.
1152 calname = _DtCmGetPrefix(args->cal, '@');
1153 username = _DtCmGetPrefix(user, '@');
1155 if (_DtCmIsUserName(calname) && strcmp(calname, username)) {
1158 return (CSA_E_NO_AUTHORITY);
1160 log = _DtCmsGetLogFN(calname);
1164 /* create internal calendar data structure */
1165 if ((cal = _DtCmsMakeCalendar(user, args->cal)) == NULL) {
1167 return (CSA_E_INSUFFICIENT_MEMORY);
1170 /* fill in information */
1171 _csa_tick_to_iso8601(time(0), datestr);
1173 if ((stat = _DtCm_set_string_attrval(datestr,
1174 &cal->attrs[CSA_CAL_ATTR_DATE_CREATED_I].value,
1175 CSA_VALUE_DATE_TIME)) != CSA_SUCCESS) {
1176 _DtCmsFreeCalendar(cal);
1181 /* initialize access list to be "WORLD", VIEW_PUBLIC */
1182 aentry.user = WORLD;
1183 aentry.rights = CSA_VIEW_PUBLIC_ENTRIES;
1185 val.item.access_list_value = &aentry;
1186 val.type = CSA_VALUE_ACCESS_LIST;
1188 if ((stat = _DtCmUpdateAccessListAttrVal(&val,
1189 &cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I].value)) != CSA_SUCCESS) {
1190 _DtCmsFreeCalendar(cal);
1195 /* set product identifier */
1196 if ((stat = _DtCm_set_string_attrval(_DtCM_PRODUCT_IDENTIFIER,
1197 &cal->attrs[CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I].value,
1198 CSA_VALUE_STRING)) != CSA_SUCCESS) {
1199 _DtCmsFreeCalendar(cal);
1204 /* set CSA version */
1205 if ((stat = _DtCm_set_string_attrval(_DtCM_SPEC_VERSION_SUPPORTED,
1206 &cal->attrs[CSA_CAL_ATTR_VERSION_I].value, CSA_VALUE_STRING))
1208 _DtCmsFreeCalendar(cal);
1213 /* we dont use the values specified by client */
1214 for (i = 0; i < args->num_attrs; i++) {
1215 if (strcmp(args->attrs[i].name.name,
1216 CSA_CAL_ATTR_CALENDAR_NAME) == 0) {
1218 name = args->attrs[i].name.name;
1219 args->attrs[i].name.name = NULL;
1220 } else if (strcmp(args->attrs[i].name.name,
1221 CSA_CAL_ATTR_CALENDAR_OWNER) == 0) {
1223 owner = args->attrs[i].name.name;
1224 args->attrs[i].name.name = NULL;
1228 /* initialize calendar attribute with info provided by caller */
1229 if ((stat = _DtCmUpdateAttributes(args->num_attrs, args->attrs,
1230 &cal->num_attrs, &cal->attrs, &cal->cal_tbl, B_TRUE,
1231 NULL, B_FALSE)) != CSA_SUCCESS) {
1232 _DtCmsFreeCalendar(cal);
1237 if (nidx) args->attrs[nidx].name.name = name;
1238 if (oidx) args->attrs[oidx].name.name = owner;
1240 /* use passed in char set if client does not supply one */
1241 if (cal->attrs[CSA_CAL_ATTR_CHARACTER_SET_I].value == NULL &&
1242 args->char_set && *args->char_set != NULL) {
1243 if ((stat = _DtCm_set_string_attrval(args->char_set,
1244 &cal->attrs[CSA_CAL_ATTR_CHARACTER_SET_I].value,
1245 CSA_VALUE_STRING)) != CSA_SUCCESS) {
1246 _DtCmsFreeCalendar(cal);
1253 if ((stat = _DtCmsCreateLogV2(user, log)) != CSA_SUCCESS) {
1254 _DtCmsFreeCalendar(cal);
1260 if ((stat = _DtCmsAppendCalAttrsByFN(log, cal->num_attrs, cal->attrs))
1264 _DtCmsFreeCalendar(cal);
1269 _DtCmsPutInCalList(cal);
1276 #define _NAME_INCREMENT 10
1278 static CSA_return_code
1279 _ListCalendarNames(uint *num_names, char ***names)
1281 uint num = 0, count = 0;
1282 char **names_r = NULL;
1286 if ((dirp = opendir(".")) == NULL)
1287 return (CSA_E_FAILURE);
1290 if ((dp = (struct dirent *)malloc(sizeof(struct dirent) + FILENAME_MAX))
1293 return (CSA_E_INSUFFICIENT_MEMORY);
1296 while (dp = readdir_r(dirp, dp)) {
1298 while (dp = readdir(dirp)) {
1300 if (strncmp(dp->d_name, "callog.", strlen("callog.")) == 0) {
1302 count += _NAME_INCREMENT;
1303 if ((names_r = (char **)_grow_char_array(
1304 names_r, sizeof(char *) * count,
1305 sizeof(char *) * (count + _NAME_INCREMENT)))
1312 return (CSA_E_INSUFFICIENT_MEMORY);
1315 if ((names_r[num++] = strdup(dp->d_name)) == NULL) {
1316 _free_char_array(num, names_r);
1318 return (CSA_E_INSUFFICIENT_MEMORY);
1326 } else if (count > 0)
1329 return (CSA_SUCCESS);
1333 _grow_char_array(void *ptr, uint oldcount, uint newcount)
1337 if (nptr = realloc(ptr, newcount)) {
1338 memset((void *)((char *)nptr + oldcount), NULL,
1339 newcount - oldcount);
1346 _free_char_array(uint num_elem, char **ptr)
1353 for (i = 0; i < num_elem; i++) {
1364 * This routine assumes that the attributes are hashed already
1366 static CSA_return_code
1367 _DtCmsGetOldCalAttrNames(
1368 _DtCmsCalendar *cal,
1370 cms_attr_name **names_r)
1372 CSA_return_code stat = CSA_SUCCESS;
1373 cms_attr_name *names;
1376 if ((names = (cms_attr_name *)calloc(1,
1377 sizeof(cms_attr_name)*_DtCM_OLD_CAL_ATTR_SIZE)) == NULL)
1378 return (CSA_E_INSUFFICIENT_MEMORY);
1380 for (i = 1, j = 0; i <= _DtCM_DEFINED_CAL_ATTR_SIZE; i++) {
1381 if ((_CSA_cal_attr_info[i].fst_vers > 0 &&
1382 _CSA_cal_attr_info[i].fst_vers <= cal->fversion)
1383 || i == CSA_CAL_ATTR_CALENDAR_SIZE_I) {
1384 if ((names[j].name =
1385 strdup(_CSA_calendar_attribute_names[i])) == NULL)
1387 _DtCmsFreeCmsAttrNames(j, names);
1388 return (CSA_E_INSUFFICIENT_MEMORY);
1399 return (CSA_SUCCESS);