1 /* $XConsortium: cmscalendar.c /main/4 1995/11/09 12:40:39 rswiston $ */
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.
20 #include <sys/systeminfo.h>
22 #include "cmscalendar.h"
30 #include "appt4.h" /* Internal appointment data structure */
39 #include "updateattrs.h"
42 #include "convert4-5.h"
48 /******************************************************************************
49 * forward declaration of static functions used within the file
50 ******************************************************************************/
52 static CSA_return_code get_file_owner(char *log, char **owner);
53 static char * get_calname(char *target);
54 static CSA_return_code init_cal_attrs(_DtCmsCalendar *cal);
55 static CSA_return_code _GetCalendarSize(_DtCmsCalendar *cal, int index,
57 static CSA_return_code _GetNumberEntries(_DtCmsCalendar *cal, int index,
59 static CSA_return_code _GetAccessList(_DtCmsCalendar *cal, int index,
61 static CSA_return_code _GetCalendarName(_DtCmsCalendar *cal, int index,
63 static CSA_return_code _GetCalendarOwner(_DtCmsCalendar *cal, int index,
65 static CSA_return_code _GetServerVersion(_DtCmsCalendar *cal, int index,
67 static CSA_return_code _GetDataVersion(_DtCmsCalendar *cal, int index,
69 static CSA_return_code _GetProductId(_DtCmsCalendar *cal, int index,
71 static CSA_return_code _GetSupportedVersion(_DtCmsCalendar *cal, int index,
73 static CSA_return_code _CopyCalendarAttr(_DtCmsCalendar *cal, int index,
76 /* global variable shared with parser.y */
77 _DtCmsCalendar *currentCalendar;
79 /* static variables used within the file */
80 static _DtCmsCalendar *calendar_list = NULL;
82 static _DtCmGetAttrFunc _GetAttrFuncPtrs[] =
101 /*****************************************************************************
103 *****************************************************************************/
105 extern _DtCmsCalendar *
106 _DtCmsMakeCalendar(char *owner, char *name)
110 if ((cal = (_DtCmsCalendar *)calloc(1, sizeof(_DtCmsCalendar)))
115 cal->fversion = _DtCMS_VERSION4;
117 if (init_cal_attrs(cal) != CSA_SUCCESS) {
122 if (_DtCm_set_string_attrval(owner,
123 &cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value,
124 CSA_VALUE_CALENDAR_USER)) {
125 _DtCmsFreeCalendar(cal);
128 if ((cal->owner = strdup(cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
129 value->item.string_value)) == NULL) {
130 _DtCmsFreeCalendar(cal);
134 if (_DtCm_set_string_attrval(name,
135 &cal->attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value, CSA_VALUE_STRING))
137 _DtCmsFreeCalendar(cal);
140 if ((cal->calendar = get_calname(name)) == NULL) {
141 _DtCmsFreeCalendar(cal);
145 if ((cal->types = (int *)calloc(1, sizeof(int) *
146 (_DtCm_entry_name_tbl->size + 1))) == NULL) {
147 _DtCmsFreeCalendar(cal);
150 _DtCm_get_attribute_types(_DtCm_entry_name_tbl->size,
153 if (!(cal->tree = rb_create(_DtCmsGetEntryKey, _DtCmsCompareEntry))) {
154 _DtCmsFreeCalendar(cal);
158 if (!(cal->list = hc_create(_DtCmsGetEntryKey, _DtCmsCompareRptEntry)))
160 _DtCmsFreeCalendar(cal);
164 cal->cal_tbl = _DtCm_cal_name_tbl;
165 cal->entry_tbl = _DtCm_entry_name_tbl;
166 cal->num_entry_attrs = _DtCm_entry_name_tbl->size;
167 cal->getattrfuncs = _GetAttrFuncPtrs;
173 _DtCmsPutInCalList(_DtCmsCalendar *cal)
175 /* link with other calendar structures */
176 cal->next = calendar_list;
181 _DtCmsFreeCalendar(_DtCmsCalendar *cal)
183 _DtCmsCalendar *clist, *prev;
185 if (cal == NULL) return;
187 for (clist = calendar_list, prev = NULL; clist != NULL;
188 clist = clist->next) {
192 calendar_list = clist->next;
194 prev->next = clist->next;
207 if (cal->fversion == 1) {
208 _DtCm_free_access_list4(GET_R_ACCESS ((cal)));
209 _DtCm_free_access_list4(GET_W_ACCESS ((cal)));
210 _DtCm_free_access_list4(GET_D_ACCESS ((cal)));
211 _DtCm_free_access_list4(GET_X_ACCESS ((cal)));
212 _DtCm_free_access_list4(cal->alist);
214 if (cal->cal_tbl != _DtCm_cal_name_tbl)
215 _DtCm_free_name_table(cal->cal_tbl);
217 if (cal->entry_tbl != _DtCm_entry_name_tbl)
218 _DtCm_free_name_table(cal->entry_tbl);
220 if (cal->types) free(cal->types);
222 if (cal->num_attrs) {
223 _DtCm_free_cms_attributes(cal->num_attrs + 1,
230 rb_destroy(cal->tree, NULL);
233 hc_destroy(cal->list, NULL);
237 * Called when loading data from callog file.
238 * Types of data to be stored in the tree and list structures
239 * depends on the version of the callog file.
241 extern CSA_return_code
242 _DtCmsSetFileVersion(_DtCmsCalendar *cal, int version)
244 cal->fversion = version;
247 if (!(cal->tree = rb_create(_DtCmsGetApptKey,
248 _DtCmsCompareAppt))) {
249 return (CSA_E_INSUFFICIENT_MEMORY);
252 if (!(cal->list = hc_create(_DtCmsGetApptKey,
253 _DtCmsCompareRptAppt))) {
254 return (CSA_E_INSUFFICIENT_MEMORY);
257 if (!(cal->tree = rb_create(_DtCmsGetEntryKey,
258 _DtCmsCompareEntry))) {
259 return (CSA_E_INSUFFICIENT_MEMORY);
262 if (!(cal->list = hc_create(_DtCmsGetEntryKey,
263 _DtCmsCompareRptEntry))) {
264 return (CSA_E_INSUFFICIENT_MEMORY);
267 if (init_cal_attrs(cal) != CSA_SUCCESS)
268 return (CSA_E_INSUFFICIENT_MEMORY);
270 if ((cal->types = (int *)calloc(1, sizeof(int) *
271 (_DtCm_entry_name_tbl->size + 1))) == NULL) {
272 _DtCmsFreeCalendar(cal);
275 _DtCm_get_attribute_types(_DtCm_entry_name_tbl->size,
280 cal->cal_tbl = _DtCm_cal_name_tbl;
281 cal->entry_tbl = _DtCm_entry_name_tbl;
283 return (CSA_SUCCESS);
287 * 0 - file loaded successfully
288 * FILEERROR - file does not exist
289 * CERROR - something goes wrong
291 extern CSA_return_code
292 start_log(_DtCmsCalendar *cal, char *filename)
296 char firstline[80], *numptr;
300 extern void setinput(FILE *);
301 extern int yyyparse();
302 extern int yyywrap(FILE *);
304 if (cal == NULL || filename == NULL)
305 return(CSA_E_FAILURE);
307 if ((f = fopen(filename, "r")) == NULL) {
309 return(CSA_E_CALENDAR_NOT_EXIST);
311 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
315 currentCalendar = cal;
316 if (yyyparse() == -1) {
317 fprintf(stderr, "%s: unable to parse %s\n", pgname, filename);
319 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
327 * Load calendar data into memory from callog file.
329 extern CSA_return_code
330 _DtCmsLoadCalendar(char *target, _DtCmsCalendar **infoptr)
332 CSA_return_code stat;
335 _DtCmsCalendar *cal = NULL;
337 if (target == NULL || infoptr == NULL)
338 return (CSA_E_FAILURE);
342 if ((calname = get_calname(target)) == NULL)
343 return(CSA_E_INSUFFICIENT_MEMORY);
345 if ((log = _DtCmsGetLogFN(calname)) == NULL)
348 return(CSA_E_INSUFFICIENT_MEMORY);
351 if ((cal = (_DtCmsCalendar *)calloc(1, sizeof(_DtCmsCalendar)))
353 stat = CSA_E_INSUFFICIENT_MEMORY;
357 if (!(cal->calendar = (char *)strdup(calname))) {
358 stat = CSA_E_INSUFFICIENT_MEMORY;
362 /* load data from file */
363 if ((stat = start_log(cal, log)) != CSA_SUCCESS) {
368 * get file owner after the file is loaded since file
369 * ownership might be fixed in start_log()
371 if (cal->fversion == _DtCMS_VERSION1) {
372 if ((stat = get_file_owner(calname, &cal->owner))
376 cal->alist = _DtCmsCalendarAccessList(cal);
378 if (cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value)
379 cal->owner = strdup(cal->\
380 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
381 value->item.calendar_user_value);
383 stat = CSA_X_DT_E_BACKING_STORE_PROBLEM;
384 fprintf(stderr, "%s: %s\n", pgname,
385 "calendar owner attribute is missing from callog file");
389 if (cal->attrs[CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I].value == NULL)
391 if ((stat = _DtCm_set_string_attrval(
392 _DtCM_PRODUCT_IDENTIFIER, &cal->\
393 attrs[CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I].value,
394 CSA_VALUE_STRING)) != CSA_SUCCESS) {
399 if (cal->attrs[CSA_CAL_ATTR_VERSION_I].value == NULL) {
400 if ((stat = _DtCm_set_string_attrval(
401 _DtCM_SPEC_VERSION_SUPPORTED,
402 &cal->attrs[CSA_CAL_ATTR_VERSION_I].value,
403 CSA_VALUE_STRING)) != CSA_SUCCESS) {
408 cal->num_entry_attrs = cal->entry_tbl->size;
411 cal->getattrfuncs = _GetAttrFuncPtrs;
413 /* link with other calendar structures */
414 cal->next = calendar_list;
421 return (CSA_SUCCESS);
426 _DtCmsFreeCalendar(cal);
431 _DtCmsGetCalendarOwner(char *target)
434 _DtCmsCalendar *clist = calendar_list;
436 if ((name = get_calname(target)) == NULL)
439 while (clist != NULL) {
440 if (strcmp(name, clist->calendar) == 0) {
442 return(clist->owner);
450 extern CSA_return_code
451 _DtCmsGetCalendarByName(char *target, boolean_t load, _DtCmsCalendar **cal)
454 _DtCmsCalendar *clist = calendar_list;
456 if ((name = get_calname(target)) == NULL)
459 while (clist != NULL) {
460 if (strcmp (name, clist->calendar) == 0) {
463 return (CSA_SUCCESS);
470 return (_DtCmsLoadCalendar(target, cal));
473 return (CSA_SUCCESS);
480 extern CSA_return_code
481 _DtCmsInsertAppt_for_parser(_DtCmsCalendar *cal, Appt_4 *appt)
483 return (_DtCmsInsertAppt(cal, appt));
489 extern CSA_return_code
490 _DtCmsInsertEntry4Parser(_DtCmsCalendar *cal, cms_entry *entry)
493 CSA_return_code stat;
495 if ((stat = _DtCmsMakeHashedEntry(cal, entry->num_attrs,
496 entry->attrs, &eptr)) != CSA_SUCCESS)
499 eptr->key = entry->key;
501 stat = _DtCmsInsertEntry(cal, eptr);
503 _DtCm_free_cms_entry(eptr);
509 _DtCmsGenerateKey(_DtCmsCalendar *cal, long *key)
512 *key = ++(cal->lastkey);
513 } else if (*key > cal->lastkey)
517 extern CSA_return_code
518 _DtCmsEnumerateUp(_DtCmsCalendar *cal, _DtCmsEnumerateProc doit)
520 if (cal == NULL || doit == NULL)
521 return (CSA_E_INVALID_PARAMETER);
522 if (rb_enumerate_up (APPT_TREE(cal), doit) != rb_ok ||
523 hc_enumerate_up (REPT_LIST(cal), doit) != rb_ok)
524 return (CSA_E_FAILURE);
526 return (CSA_SUCCESS);
530 _DtCmsEnumerateDown(_DtCmsCalendar *cal, _DtCmsEnumerateProc doit)
532 if (cal == NULL || doit == NULL)
534 rb_enumerate_down (APPT_TREE(cal), doit);
535 hc_enumerate_down (REPT_LIST(cal), doit);
542 _DtCmsSetAccess4Parser(
544 Access_Entry_4 *list,
547 if (type == access_read_4)
548 SET_R_ACCESS(cal, list);
549 else if (type == access_write_4)
550 SET_W_ACCESS(cal, list);
551 else if (type == access_delete_4)
552 SET_D_ACCESS(cal, list);
553 else if (type == access_exec_4)
554 SET_X_ACCESS(cal, list);
558 _DtCmsSetCalendarAttrs4Parser(
561 cms_attribute *attrs)
563 cms_attribute_value *val;
565 /* we don't want to free the value part of the access list
566 * attribute even it may be an empty list
568 val = cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I].value;
569 cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I].value = NULL;
570 _DtCm_free_cms_attribute_values(cal->num_attrs, cal->attrs);
571 cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I].value = val;
573 (void)_DtCmUpdateAttributes(len, attrs, &cal->num_attrs, &cal->attrs,
574 &cal->cal_tbl, B_TRUE, NULL, B_FALSE);
577 extern CSA_return_code
578 _DtCmsRbToCsaStat(Rb_Status rb_stat)
582 return (CSA_SUCCESS);
588 return (CSA_E_FAILURE);
596 _DtCmsCalendar *clist = calendar_list;
598 while (clist != NULL) {
600 /* deregister stale client */
601 clist->rlist = _DtCmsCheckRegistrationList(clist->rlist);
604 _DtCmsUpdateReminders(clist->remq);
606 if (clist->modified == B_TRUE) {
608 fprintf(stderr, "rpc.csmd: %s%s\n",
609 "do garbage collection on ",
611 _DtCmsCollectOne(clist);
612 clist->modified = B_FALSE;
618 if ((remain = (unsigned) alarm((unsigned) 0)) == 0)
619 alarm ((unsigned) (3600L * 24L));
627 _DtCmsCalendar *clist = calendar_list;
631 fprintf (stderr, "Debug Mode is %s\n", debug ? "ON" : "OFF");
634 while (clist != NULL) {
635 _DtCmsPrintReminderListV4(clist->rm_queue);
637 if ((l = _DtCmsCalendarAccessList(clist)) != NULL) {
638 _DtCmsShowAccessList(l);
639 _DtCm_free_access_list4(l);
646 extern CSA_return_code
647 _DtCmsGetCalAttrsByName(
650 cms_attr_name *names,
652 cms_attribute **attrs_r)
654 CSA_return_code stat = CSA_SUCCESS;
656 cms_attribute *attrs;
658 if ((attrs = calloc(1, sizeof(cms_attribute)*num_names)) == NULL)
659 return (CSA_E_INSUFFICIENT_MEMORY);
662 for (i = 0, j = 0; i < num_names; i++) {
663 if (names[i].name == NULL)
666 if (names[i].num <= 0)
667 index = names[i].num = _DtCm_get_index_from_table(
668 cal->cal_tbl, names[i].name);
671 if (index <= _DtCM_DEFINED_CAL_ATTR_SIZE) {
672 if (_CSA_cal_attr_info[index].fst_vers
674 || index == CSA_CAL_ATTR_CALENDAR_SIZE_I) {
675 stat = cal->getattrfuncs[index](cal,
678 } else if (cal->attrs && cal->attrs[index].value) {
679 stat = _DtCm_copy_cms_attribute(&attrs[j],
680 &cal->attrs[index], B_TRUE);
683 if (stat != CSA_SUCCESS) {
684 _DtCm_free_cms_attributes(j, attrs);
687 } else if (attrs[j].name.name)
701 return (CSA_SUCCESS);
704 extern CSA_return_code
705 _DtCmsGetAllCalAttrs(
708 cms_attribute **attrs_r,
711 CSA_return_code stat = CSA_SUCCESS;
712 cms_attribute *attrs, *cattrs = cal->attrs;
713 int i, j, num_cal_attrs = cal->num_attrs;
715 num_cal_attrs = cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
716 cal->num_attrs : _DtCM_OLD_CAL_ATTR_SIZE;
718 if ((attrs = calloc(1, sizeof(cms_attribute)*num_cal_attrs)) == NULL)
719 return (CSA_E_INSUFFICIENT_MEMORY);
721 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
722 /* first element is not used */
723 for (i = 1, j = 0; i <= num_cal_attrs; i++) {
724 if (i <= _DtCM_DEFINED_CAL_ATTR_SIZE) {
725 if ((stat = cal->getattrfuncs[i](cal, i,
726 &attrs[j])) != CSA_SUCCESS) {
727 _DtCm_free_cms_attributes(j, attrs);
730 } else if (attrs[j].name.name)
732 } else if (cattrs[i].value) {
734 stat = _DtCm_copy_cms_attribute(
735 &attrs[j], &cal->attrs[i],
738 /* just return the attribute name */
739 if (attrs[j].name.name = strdup(
740 cattrs[i].name.name)) {
744 stat =CSA_E_INSUFFICIENT_MEMORY;
747 if (stat == CSA_SUCCESS)
750 _DtCm_free_cms_attributes(j, attrs);
757 for (i = 1, j = 0; i <= _DtCM_DEFINED_CAL_ATTR_SIZE; i++) {
758 if (_CSA_cal_attr_info[i].fst_vers <= cal->fversion ||
759 i == CSA_CAL_ATTR_CALENDAR_SIZE_I)
761 if ((stat = cal->getattrfuncs[i](cal, i,
762 &attrs[j])) != CSA_SUCCESS) {
763 _DtCm_free_cms_attributes(j, attrs);
766 } else if (attrs[j].name.name)
781 return (CSA_SUCCESS);
784 extern CSA_return_code
785 _DtCmsGetCalAttrNames(
788 cms_attr_name **names_r)
790 CSA_return_code stat = CSA_SUCCESS;
791 cms_attribute *attrs = cal->attrs;
792 cms_attr_name *names;
793 uint i, j, num_attrs = cal->num_attrs;
795 if ((names = calloc(1, sizeof(cms_attr_name)*num_attrs)) == NULL)
796 return (CSA_E_INSUFFICIENT_MEMORY);
798 /* first element is not used */
799 for (i = 1, j = 0; i <= num_attrs; i++) {
800 if (attrs[i].value || (i == CSA_CAL_ATTR_CALENDAR_SIZE_I ||
801 i == CSA_CAL_ATTR_NUMBER_ENTRIES_I ||
802 i == CSA_X_DT_CAL_ATTR_SERVER_VERSION_I ||
803 i == CSA_X_DT_CAL_ATTR_DATA_VERSION_I ||
804 i == CSA_CAL_ATTR_ACCESS_LIST_I))
806 if (names[j].name = strdup(attrs[i].name.name)) {
807 names[j].num = attrs[i].name.num;
810 _DtCmsFreeCmsAttrNames(j, names);
811 return (CSA_E_INSUFFICIENT_MEMORY);
825 return (CSA_SUCCESS);
829 _DtCmsFreeCmsAttrNames(uint num, cms_attr_name *names)
833 for (i = 0; i < num; i++)
834 if (names[i].name) free(names[i].name);
839 extern CSA_return_code
840 _DtCmsUpdateCalAttributesAndLog(
843 cms_attribute *srcattrs,
846 CSA_return_code stat = CSA_SUCCESS;
848 cms_attribute *oldattrs = NULL;
851 /* we didn't use _DtCmUpdateAttributes because we need
852 * to check access rights here
855 /* copy original attributes for rollback if update fails */
856 if (cal->attrs && (stat = _DtCm_copy_cms_attributes(cal->num_attrs,
857 cal->attrs, &oldnum, &oldattrs)) != CSA_SUCCESS)
860 for (i = 0; i < numsrc && stat == CSA_SUCCESS; i++) {
861 if (srcattrs[i].name.name == NULL)
864 if (srcattrs[i].name.num <= 0)
865 srcattrs[i].name.num = _DtCm_get_index_from_table(
867 srcattrs[i].name.name);
869 if (srcattrs[i].name.num < 0) {
870 if (!_DTCMS_HAS_INSERT_CALENDAR_ATTR_ACCESS(access))
871 stat = CSA_E_NO_AUTHORITY;
873 if ((stat = _DtCmExtendNameTable(
874 srcattrs[i].name.name, 0, 0,
876 _DtCM_DEFINED_CAL_ATTR_SIZE,
877 _CSA_calendar_attribute_names,
878 &cal->cal_tbl, NULL)) == CSA_SUCCESS) {
879 srcattrs[i].name.num =
881 stat = _DtCmGrowAttrArray(
882 &cal->num_attrs, &cal->attrs,
887 } else if (!_DTCMS_HAS_CHANGE_CALENDAR_ATTR_ACCESS(access)) {
889 stat = CSA_E_NO_AUTHORITY;
891 cms_attribute_value val;
893 if (srcattrs[i].name.num == CSA_CAL_ATTR_ACCESS_LIST_I
894 && srcattrs[i].value == NULL) {
895 val.type = CSA_VALUE_ACCESS_LIST;
896 val.item.access_list_value = NULL;
897 srcattrs[i].value = &val;
899 stat = _DtCmUpdateAttribute(&srcattrs[i],
900 &cal->attrs[srcattrs[i].name.num]);
904 if (stat == CSA_SUCCESS) {
905 log = _DtCmsGetLogFN(cal->calendar);
908 stat = _DtCmsAppendCalAttrsByFN(log, cal->num_attrs,
913 if (stat == CSA_SUCCESS) {
914 cal->modified = B_TRUE;
916 _DtCm_free_cms_attributes(oldnum + 1, oldattrs);
919 _DtCm_free_cms_attributes(cal->num_attrs+1, cal->attrs);
921 cal->num_attrs = oldnum;
922 cal->attrs = oldattrs;
928 extern CSA_return_code
929 _DtCmsV5TransactLog(_DtCmsCalendar *cal, cms_entry *e, _DtCmsLogOps op)
931 CSA_return_code stat;
934 if ((log = _DtCmsGetLogFN(cal->calendar)) == NULL)
935 return (CSA_E_INSUFFICIENT_MEMORY);
937 if (cal->hashed == B_FALSE ||
938 cal->num_entry_attrs < cal->entry_tbl->size) {
939 if ((stat = _DtCmsAppendHTableByFN(log, cal->entry_tbl->size,
940 cal->entry_tbl->names, cal->types)) != CSA_SUCCESS) {
944 cal->hashed = B_TRUE;
945 cal->num_entry_attrs = cal->entry_tbl->size;
948 stat = _DtCmsAppendEntryByFN(log, e, op);
953 /*****************************************************************************
954 * static functions used within the file
955 *****************************************************************************/
958 * return user name of file owner
959 * If the calendar name is the same as a user account name, the
960 * calendar name is return; otherwise, the owner name is derived from
961 * the owner of the calendar file
963 static CSA_return_code
964 get_file_owner(char *calname, char **owner)
972 if (calname == NULL || owner == NULL)
973 return (CSA_E_FAILURE);
977 if (_DtCmIsUserName(calname) == B_TRUE) {
978 strcpy(buf, calname);
980 if ((log = _DtCmsGetLogFN(calname)) == NULL)
981 return (CSA_E_INSUFFICIENT_MEMORY);
983 res = stat(log, &info);
988 if (pw = getpwuid(info.st_uid))
989 strcpy(buf, pw->pw_name);
991 return (CSA_E_FAILURE);
993 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
996 if (((*owner) = (char *)strdup(buf)) == NULL)
997 return (CSA_E_INSUFFICIENT_MEMORY);
999 return (CSA_SUCCESS);
1003 get_calname(char *target)
1010 ptr = strchr(target, '@');
1012 return (strdup(target));
1015 name = strdup(target);
1021 static CSA_return_code
1022 init_cal_attrs(_DtCmsCalendar *cal)
1026 /* initialize the calendar with predefined attribute names */
1027 if ((cal->attrs = (cms_attribute *)calloc(1,
1028 sizeof(cms_attribute)*(_DtCm_cal_name_tbl->size + 1))) == NULL) {
1029 return (CSA_E_INSUFFICIENT_MEMORY);
1032 for (i = 1; i <= _DtCm_cal_name_tbl->size; i++) {
1033 if ((cal->attrs[i].name.name =
1034 strdup(_DtCm_cal_name_tbl->names[i])) == NULL) {
1035 _DtCm_free_cms_attributes(i, cal->attrs);
1037 return (CSA_E_INSUFFICIENT_MEMORY);
1040 cal->attrs[i].name.num = i;
1042 cal->num_attrs = _DtCm_cal_name_tbl->size;
1044 return (CSA_SUCCESS);
1047 static CSA_return_code
1048 _CopyCalendarAttr(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1051 cms_attribute_value tmpval;
1053 if (cal->attrs && cal->attrs[index].value)
1054 return (_DtCm_copy_cms_attribute(attr,
1055 &cal->attrs[index], B_TRUE));
1057 return (CSA_SUCCESS);
1060 static CSA_return_code
1061 _GetCalendarSize(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1063 CSA_return_code stat;
1066 if ((stat = _DtCmsGetFileSize(cal->calendar, &size)) == CSA_SUCCESS) {
1067 attr->name.num = CSA_CAL_ATTR_CALENDAR_SIZE_I;
1068 if (attr->name.name = strdup(CSA_CAL_ATTR_CALENDAR_SIZE))
1069 return (_DtCm_set_uint32_attrval((uint)size,
1072 return (CSA_E_INSUFFICIENT_MEMORY);
1077 static CSA_return_code
1078 _GetNumberEntries(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1082 size = rb_size(cal->tree) + hc_size(cal->list);
1084 attr->name.num = CSA_CAL_ATTR_NUMBER_ENTRIES_I;
1085 if (attr->name.name = strdup(CSA_CAL_ATTR_NUMBER_ENTRIES))
1086 return (_DtCm_set_uint32_attrval(size, &attr->value));
1088 return (CSA_E_INSUFFICIENT_MEMORY);
1091 static CSA_return_code
1092 _GetAccessList(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1094 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
1095 return (_DtCm_copy_cms_attribute(attr,
1096 &cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I], B_TRUE));
1098 Access_Entry_4 *alist;
1099 CSA_return_code stat;
1100 cms_attribute tmpattr;
1101 cms_attribute_value tmpval;
1103 alist = _DtCmsCalendarAccessList(cal);
1104 if ((stat = _DtCm_accessentry4_to_cmsaccesslist(alist,
1105 &tmpval.item.access_list_value)) == CSA_SUCCESS) {
1106 tmpattr.name.num = CSA_CAL_ATTR_ACCESS_LIST_I;
1107 tmpattr.name.name = CSA_CAL_ATTR_ACCESS_LIST;
1108 tmpattr.value = &tmpval;
1109 tmpval.type = CSA_VALUE_ACCESS_LIST;
1111 return (_DtCm_copy_cms_attribute(attr, &tmpattr,
1118 static CSA_return_code
1119 _GetCalendarName(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1121 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
1122 return (_DtCm_copy_cms_attribute(attr,
1123 &cal->attrs[CSA_CAL_ATTR_CALENDAR_NAME_I], B_TRUE));
1125 attr->name.num = CSA_CAL_ATTR_CALENDAR_NAME_I;
1126 if (attr->name.name = strdup(CSA_CAL_ATTR_CALENDAR_NAME)) {
1127 return (_DtCm_set_string_attrval(cal->calendar,
1128 &attr->value, CSA_VALUE_STRING));
1130 return (CSA_E_INSUFFICIENT_MEMORY);
1135 static CSA_return_code
1136 _GetCalendarOwner(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1138 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
1139 return (_DtCm_copy_cms_attribute(attr,
1140 &cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I], B_TRUE));
1142 attr->name.num = CSA_CAL_ATTR_CALENDAR_OWNER_I;
1143 if (attr->name.name = strdup(CSA_CAL_ATTR_CALENDAR_OWNER)) {
1144 return (_DtCm_set_user_attrval(cal->owner,
1147 return (CSA_E_INSUFFICIENT_MEMORY);
1152 static CSA_return_code
1153 _GetServerVersion(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1155 attr->name.num = CSA_X_DT_CAL_ATTR_SERVER_VERSION_I;
1156 if (attr->name.name = strdup(CSA_X_DT_CAL_ATTR_SERVER_VERSION))
1157 return (_DtCm_set_uint32_attrval((uint)TABLEVERS, &attr->value));
1159 return (CSA_E_INSUFFICIENT_MEMORY);
1162 static CSA_return_code
1163 _GetDataVersion(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1167 version = cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
1168 cal->fversion : _DtCM_FIRST_EXTENSIBLE_DATA_VERSION - 1;
1170 attr->name.num = CSA_X_DT_CAL_ATTR_DATA_VERSION_I;
1171 if (attr->name.name = strdup(CSA_X_DT_CAL_ATTR_DATA_VERSION))
1172 return (_DtCm_set_uint32_attrval(version, &attr->value));
1174 return (CSA_E_INSUFFICIENT_MEMORY);
1177 static CSA_return_code
1178 _GetProductId(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1180 attr->name.num = CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I;
1181 if (attr->name.name = strdup(CSA_CAL_ATTR_PRODUCT_IDENTIFIER)) {
1182 return (_DtCm_set_string_attrval(_DtCM_PRODUCT_IDENTIFIER,
1183 &attr->value, CSA_VALUE_STRING));
1185 return (CSA_E_INSUFFICIENT_MEMORY);
1189 static CSA_return_code
1190 _GetSupportedVersion(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1192 attr->name.num = CSA_CAL_ATTR_VERSION_I;
1193 if (attr->name.name = strdup(CSA_CAL_ATTR_VERSION)) {
1194 return (_DtCm_set_string_attrval(_DtCM_SPEC_VERSION_SUPPORTED,
1195 &attr->value, CSA_VALUE_STRING));
1197 return (CSA_E_INSUFFICIENT_MEMORY);