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: cmscalendar.c /main/4 1995/11/09 12:40:39 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>
42 #include <sys/systeminfo.h>
44 #include "cmscalendar.h"
52 #include "appt4.h" /* Internal appointment data structure */
61 #include "updateattrs.h"
64 #include "convert4-5.h"
70 /******************************************************************************
71 * forward declaration of static functions used within the file
72 ******************************************************************************/
74 static CSA_return_code get_file_owner(char *log, char **owner);
75 static char * get_calname(char *target);
76 static CSA_return_code init_cal_attrs(_DtCmsCalendar *cal);
77 static CSA_return_code _GetCalendarSize(_DtCmsCalendar *cal, int index,
79 static CSA_return_code _GetNumberEntries(_DtCmsCalendar *cal, int index,
81 static CSA_return_code _GetAccessList(_DtCmsCalendar *cal, int index,
83 static CSA_return_code _GetCalendarName(_DtCmsCalendar *cal, int index,
85 static CSA_return_code _GetCalendarOwner(_DtCmsCalendar *cal, int index,
87 static CSA_return_code _GetServerVersion(_DtCmsCalendar *cal, int index,
89 static CSA_return_code _GetDataVersion(_DtCmsCalendar *cal, int index,
91 static CSA_return_code _GetProductId(_DtCmsCalendar *cal, int index,
93 static CSA_return_code _GetSupportedVersion(_DtCmsCalendar *cal, int index,
95 static CSA_return_code _CopyCalendarAttr(_DtCmsCalendar *cal, int index,
98 /* global variable shared with parser.y */
99 _DtCmsCalendar *currentCalendar;
101 /* static variables used within the file */
102 static _DtCmsCalendar *calendar_list = NULL;
104 static _DtCmGetAttrFunc _GetAttrFuncPtrs[] =
117 _GetSupportedVersion,
123 /*****************************************************************************
125 *****************************************************************************/
127 extern _DtCmsCalendar *
128 _DtCmsMakeCalendar(char *owner, char *name)
132 if ((cal = (_DtCmsCalendar *)calloc(1, sizeof(_DtCmsCalendar)))
137 cal->fversion = _DtCMS_VERSION4;
139 if (init_cal_attrs(cal) != CSA_SUCCESS) {
144 if (_DtCm_set_string_attrval(owner,
145 &cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value,
146 CSA_VALUE_CALENDAR_USER)) {
147 _DtCmsFreeCalendar(cal);
150 if ((cal->owner = strdup(cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
151 value->item.string_value)) == NULL) {
152 _DtCmsFreeCalendar(cal);
156 if (_DtCm_set_string_attrval(name,
157 &cal->attrs[CSA_CAL_ATTR_CALENDAR_NAME_I].value, CSA_VALUE_STRING))
159 _DtCmsFreeCalendar(cal);
162 if ((cal->calendar = get_calname(name)) == NULL) {
163 _DtCmsFreeCalendar(cal);
167 if ((cal->types = (int *)calloc(1, sizeof(int) *
168 (_DtCm_entry_name_tbl->size + 1))) == NULL) {
169 _DtCmsFreeCalendar(cal);
172 _DtCm_get_attribute_types(_DtCm_entry_name_tbl->size,
175 if (!(cal->tree = rb_create(_DtCmsGetEntryKey, _DtCmsCompareEntry))) {
176 _DtCmsFreeCalendar(cal);
180 if (!(cal->list = hc_create(_DtCmsGetEntryKey, _DtCmsCompareRptEntry)))
182 _DtCmsFreeCalendar(cal);
186 cal->cal_tbl = _DtCm_cal_name_tbl;
187 cal->entry_tbl = _DtCm_entry_name_tbl;
188 cal->num_entry_attrs = _DtCm_entry_name_tbl->size;
189 cal->getattrfuncs = _GetAttrFuncPtrs;
195 _DtCmsPutInCalList(_DtCmsCalendar *cal)
197 /* link with other calendar structures */
198 cal->next = calendar_list;
203 _DtCmsFreeCalendar(_DtCmsCalendar *cal)
205 _DtCmsCalendar *clist, *prev;
207 if (cal == NULL) return;
209 for (clist = calendar_list, prev = NULL; clist != NULL;
210 clist = clist->next) {
214 calendar_list = clist->next;
216 prev->next = clist->next;
229 if (cal->fversion == 1) {
230 _DtCm_free_access_list4(GET_R_ACCESS ((cal)));
231 _DtCm_free_access_list4(GET_W_ACCESS ((cal)));
232 _DtCm_free_access_list4(GET_D_ACCESS ((cal)));
233 _DtCm_free_access_list4(GET_X_ACCESS ((cal)));
234 _DtCm_free_access_list4(cal->alist);
236 if (cal->cal_tbl != _DtCm_cal_name_tbl)
237 _DtCm_free_name_table(cal->cal_tbl);
239 if (cal->entry_tbl != _DtCm_entry_name_tbl)
240 _DtCm_free_name_table(cal->entry_tbl);
242 if (cal->types) free(cal->types);
244 if (cal->num_attrs) {
245 _DtCm_free_cms_attributes(cal->num_attrs + 1,
252 rb_destroy(cal->tree, NULL);
255 hc_destroy(cal->list, NULL);
259 * Called when loading data from callog file.
260 * Types of data to be stored in the tree and list structures
261 * depends on the version of the callog file.
263 extern CSA_return_code
264 _DtCmsSetFileVersion(_DtCmsCalendar *cal, int version)
266 cal->fversion = version;
269 if (!(cal->tree = rb_create(_DtCmsGetApptKey,
270 _DtCmsCompareAppt))) {
271 return (CSA_E_INSUFFICIENT_MEMORY);
274 if (!(cal->list = hc_create(_DtCmsGetApptKey,
275 _DtCmsCompareRptAppt))) {
276 return (CSA_E_INSUFFICIENT_MEMORY);
279 if (!(cal->tree = rb_create(_DtCmsGetEntryKey,
280 _DtCmsCompareEntry))) {
281 return (CSA_E_INSUFFICIENT_MEMORY);
284 if (!(cal->list = hc_create(_DtCmsGetEntryKey,
285 _DtCmsCompareRptEntry))) {
286 return (CSA_E_INSUFFICIENT_MEMORY);
289 if (init_cal_attrs(cal) != CSA_SUCCESS)
290 return (CSA_E_INSUFFICIENT_MEMORY);
292 if ((cal->types = (int *)calloc(1, sizeof(int) *
293 (_DtCm_entry_name_tbl->size + 1))) == NULL) {
294 _DtCmsFreeCalendar(cal);
297 _DtCm_get_attribute_types(_DtCm_entry_name_tbl->size,
302 cal->cal_tbl = _DtCm_cal_name_tbl;
303 cal->entry_tbl = _DtCm_entry_name_tbl;
305 return (CSA_SUCCESS);
309 * 0 - file loaded successfully
310 * FILEERROR - file does not exist
311 * CERROR - something goes wrong
313 extern CSA_return_code
314 start_log(_DtCmsCalendar *cal, char *filename)
318 char firstline[80], *numptr;
322 extern void setinput(FILE *);
323 extern int yyyparse();
324 extern int yyywrap(FILE *);
326 if (cal == NULL || filename == NULL)
327 return(CSA_E_FAILURE);
329 if ((f = fopen(filename, "r")) == NULL) {
331 return(CSA_E_CALENDAR_NOT_EXIST);
333 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
337 currentCalendar = cal;
338 if (yyyparse() == -1) {
339 fprintf(stderr, "%s: unable to parse %s\n", pgname, filename);
341 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
349 * Load calendar data into memory from callog file.
351 extern CSA_return_code
352 _DtCmsLoadCalendar(char *target, _DtCmsCalendar **infoptr)
354 CSA_return_code stat;
357 _DtCmsCalendar *cal = NULL;
359 if (target == NULL || infoptr == NULL)
360 return (CSA_E_FAILURE);
364 if ((calname = get_calname(target)) == NULL)
365 return(CSA_E_INSUFFICIENT_MEMORY);
367 if ((log = _DtCmsGetLogFN(calname)) == NULL)
370 return(CSA_E_INSUFFICIENT_MEMORY);
373 if ((cal = (_DtCmsCalendar *)calloc(1, sizeof(_DtCmsCalendar)))
375 stat = CSA_E_INSUFFICIENT_MEMORY;
379 if (!(cal->calendar = (char *)strdup(calname))) {
380 stat = CSA_E_INSUFFICIENT_MEMORY;
384 /* load data from file */
385 if ((stat = start_log(cal, log)) != CSA_SUCCESS) {
390 * get file owner after the file is loaded since file
391 * ownership might be fixed in start_log()
393 if (cal->fversion == _DtCMS_VERSION1) {
394 if ((stat = get_file_owner(calname, &cal->owner))
398 cal->alist = _DtCmsCalendarAccessList(cal);
400 if (cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].value)
401 cal->owner = strdup(cal->\
402 attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I].\
403 value->item.calendar_user_value);
405 stat = CSA_X_DT_E_BACKING_STORE_PROBLEM;
406 fprintf(stderr, "%s: %s\n", pgname,
407 "calendar owner attribute is missing from callog file");
411 if (cal->attrs[CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I].value == NULL)
413 if ((stat = _DtCm_set_string_attrval(
414 _DtCM_PRODUCT_IDENTIFIER, &cal->\
415 attrs[CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I].value,
416 CSA_VALUE_STRING)) != CSA_SUCCESS) {
421 if (cal->attrs[CSA_CAL_ATTR_VERSION_I].value == NULL) {
422 if ((stat = _DtCm_set_string_attrval(
423 _DtCM_SPEC_VERSION_SUPPORTED,
424 &cal->attrs[CSA_CAL_ATTR_VERSION_I].value,
425 CSA_VALUE_STRING)) != CSA_SUCCESS) {
430 cal->num_entry_attrs = cal->entry_tbl->size;
433 cal->getattrfuncs = _GetAttrFuncPtrs;
435 /* link with other calendar structures */
436 cal->next = calendar_list;
443 return (CSA_SUCCESS);
448 _DtCmsFreeCalendar(cal);
453 _DtCmsGetCalendarOwner(char *target)
456 _DtCmsCalendar *clist = calendar_list;
458 if ((name = get_calname(target)) == NULL)
461 while (clist != NULL) {
462 if (strcmp(name, clist->calendar) == 0) {
464 return(clist->owner);
472 extern CSA_return_code
473 _DtCmsGetCalendarByName(char *target, boolean_t load, _DtCmsCalendar **cal)
476 _DtCmsCalendar *clist = calendar_list;
478 if ((name = get_calname(target)) == NULL)
481 while (clist != NULL) {
482 if (strcmp (name, clist->calendar) == 0) {
485 return (CSA_SUCCESS);
492 return (_DtCmsLoadCalendar(target, cal));
495 return (CSA_SUCCESS);
502 extern CSA_return_code
503 _DtCmsInsertAppt_for_parser(_DtCmsCalendar *cal, Appt_4 *appt)
505 return (_DtCmsInsertAppt(cal, appt));
511 extern CSA_return_code
512 _DtCmsInsertEntry4Parser(_DtCmsCalendar *cal, cms_entry *entry)
515 CSA_return_code stat;
517 if ((stat = _DtCmsMakeHashedEntry(cal, entry->num_attrs,
518 entry->attrs, &eptr)) != CSA_SUCCESS)
521 eptr->key = entry->key;
523 stat = _DtCmsInsertEntry(cal, eptr);
525 _DtCm_free_cms_entry(eptr);
531 _DtCmsGenerateKey(_DtCmsCalendar *cal, long *key)
534 *key = ++(cal->lastkey);
535 } else if (*key > cal->lastkey)
539 extern CSA_return_code
540 _DtCmsEnumerateUp(_DtCmsCalendar *cal, _DtCmsEnumerateProc doit)
542 if (cal == NULL || doit == NULL)
543 return (CSA_E_INVALID_PARAMETER);
544 if (rb_enumerate_up (APPT_TREE(cal), doit) != rb_ok ||
545 hc_enumerate_up (REPT_LIST(cal), doit) != rb_ok)
546 return (CSA_E_FAILURE);
548 return (CSA_SUCCESS);
552 _DtCmsEnumerateDown(_DtCmsCalendar *cal, _DtCmsEnumerateProc doit)
554 if (cal == NULL || doit == NULL)
556 rb_enumerate_down (APPT_TREE(cal), doit);
557 hc_enumerate_down (REPT_LIST(cal), doit);
564 _DtCmsSetAccess4Parser(
566 Access_Entry_4 *list,
569 if (type == access_read_4)
570 SET_R_ACCESS(cal, list);
571 else if (type == access_write_4)
572 SET_W_ACCESS(cal, list);
573 else if (type == access_delete_4)
574 SET_D_ACCESS(cal, list);
575 else if (type == access_exec_4)
576 SET_X_ACCESS(cal, list);
580 _DtCmsSetCalendarAttrs4Parser(
583 cms_attribute *attrs)
585 cms_attribute_value *val;
587 /* we don't want to free the value part of the access list
588 * attribute even it may be an empty list
590 val = cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I].value;
591 cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I].value = NULL;
592 _DtCm_free_cms_attribute_values(cal->num_attrs, cal->attrs);
593 cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I].value = val;
595 (void)_DtCmUpdateAttributes(len, attrs, &cal->num_attrs, &cal->attrs,
596 &cal->cal_tbl, B_TRUE, NULL, B_FALSE);
599 extern CSA_return_code
600 _DtCmsRbToCsaStat(Rb_Status rb_stat)
604 return (CSA_SUCCESS);
610 return (CSA_E_FAILURE);
618 _DtCmsCalendar *clist = calendar_list;
620 while (clist != NULL) {
622 /* deregister stale client */
623 clist->rlist = _DtCmsCheckRegistrationList(clist->rlist);
626 _DtCmsUpdateReminders(clist->remq);
628 if (clist->modified == B_TRUE) {
630 fprintf(stderr, "rpc.csmd: %s%s\n",
631 "do garbage collection on ",
633 _DtCmsCollectOne(clist);
634 clist->modified = B_FALSE;
640 if ((remain = (unsigned) alarm((unsigned) 0)) == 0)
641 alarm ((unsigned) (3600L * 24L));
649 _DtCmsCalendar *clist = calendar_list;
653 fprintf (stderr, "Debug Mode is %s\n", debug ? "ON" : "OFF");
656 while (clist != NULL) {
657 _DtCmsPrintReminderListV4(clist->rm_queue);
659 if ((l = _DtCmsCalendarAccessList(clist)) != NULL) {
660 _DtCmsShowAccessList(l);
661 _DtCm_free_access_list4(l);
668 extern CSA_return_code
669 _DtCmsGetCalAttrsByName(
672 cms_attr_name *names,
674 cms_attribute **attrs_r)
676 CSA_return_code stat = CSA_SUCCESS;
678 cms_attribute *attrs;
680 if ((attrs = calloc(1, sizeof(cms_attribute)*num_names)) == NULL)
681 return (CSA_E_INSUFFICIENT_MEMORY);
684 for (i = 0, j = 0; i < num_names; i++) {
685 if (names[i].name == NULL)
688 if (names[i].num <= 0)
689 index = names[i].num = _DtCm_get_index_from_table(
690 cal->cal_tbl, names[i].name);
693 if (index <= _DtCM_DEFINED_CAL_ATTR_SIZE) {
694 if (_CSA_cal_attr_info[index].fst_vers
696 || index == CSA_CAL_ATTR_CALENDAR_SIZE_I) {
697 stat = cal->getattrfuncs[index](cal,
700 } else if (cal->attrs && cal->attrs[index].value) {
701 stat = _DtCm_copy_cms_attribute(&attrs[j],
702 &cal->attrs[index], B_TRUE);
705 if (stat != CSA_SUCCESS) {
706 _DtCm_free_cms_attributes(j, attrs);
709 } else if (attrs[j].name.name)
723 return (CSA_SUCCESS);
726 extern CSA_return_code
727 _DtCmsGetAllCalAttrs(
730 cms_attribute **attrs_r,
733 CSA_return_code stat = CSA_SUCCESS;
734 cms_attribute *attrs, *cattrs = cal->attrs;
735 int i, j, num_cal_attrs = cal->num_attrs;
737 num_cal_attrs = cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
738 cal->num_attrs : _DtCM_OLD_CAL_ATTR_SIZE;
740 if ((attrs = calloc(1, sizeof(cms_attribute)*num_cal_attrs)) == NULL)
741 return (CSA_E_INSUFFICIENT_MEMORY);
743 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
744 /* first element is not used */
745 for (i = 1, j = 0; i <= num_cal_attrs; i++) {
746 if (i <= _DtCM_DEFINED_CAL_ATTR_SIZE) {
747 if ((stat = cal->getattrfuncs[i](cal, i,
748 &attrs[j])) != CSA_SUCCESS) {
749 _DtCm_free_cms_attributes(j, attrs);
752 } else if (attrs[j].name.name)
754 } else if (cattrs[i].value) {
756 stat = _DtCm_copy_cms_attribute(
757 &attrs[j], &cal->attrs[i],
760 /* just return the attribute name */
761 if (attrs[j].name.name = strdup(
762 cattrs[i].name.name)) {
766 stat =CSA_E_INSUFFICIENT_MEMORY;
769 if (stat == CSA_SUCCESS)
772 _DtCm_free_cms_attributes(j, attrs);
779 for (i = 1, j = 0; i <= _DtCM_DEFINED_CAL_ATTR_SIZE; i++) {
780 if (_CSA_cal_attr_info[i].fst_vers <= cal->fversion ||
781 i == CSA_CAL_ATTR_CALENDAR_SIZE_I)
783 if ((stat = cal->getattrfuncs[i](cal, i,
784 &attrs[j])) != CSA_SUCCESS) {
785 _DtCm_free_cms_attributes(j, attrs);
788 } else if (attrs[j].name.name)
803 return (CSA_SUCCESS);
806 extern CSA_return_code
807 _DtCmsGetCalAttrNames(
810 cms_attr_name **names_r)
812 CSA_return_code stat = CSA_SUCCESS;
813 cms_attribute *attrs = cal->attrs;
814 cms_attr_name *names;
815 uint i, j, num_attrs = cal->num_attrs;
817 if ((names = calloc(1, sizeof(cms_attr_name)*num_attrs)) == NULL)
818 return (CSA_E_INSUFFICIENT_MEMORY);
820 /* first element is not used */
821 for (i = 1, j = 0; i <= num_attrs; i++) {
822 if (attrs[i].value || (i == CSA_CAL_ATTR_CALENDAR_SIZE_I ||
823 i == CSA_CAL_ATTR_NUMBER_ENTRIES_I ||
824 i == CSA_X_DT_CAL_ATTR_SERVER_VERSION_I ||
825 i == CSA_X_DT_CAL_ATTR_DATA_VERSION_I ||
826 i == CSA_CAL_ATTR_ACCESS_LIST_I))
828 if (names[j].name = strdup(attrs[i].name.name)) {
829 names[j].num = attrs[i].name.num;
832 _DtCmsFreeCmsAttrNames(j, names);
833 return (CSA_E_INSUFFICIENT_MEMORY);
847 return (CSA_SUCCESS);
851 _DtCmsFreeCmsAttrNames(uint num, cms_attr_name *names)
855 for (i = 0; i < num; i++)
856 if (names[i].name) free(names[i].name);
861 extern CSA_return_code
862 _DtCmsUpdateCalAttributesAndLog(
865 cms_attribute *srcattrs,
868 CSA_return_code stat = CSA_SUCCESS;
870 cms_attribute *oldattrs = NULL;
873 /* we didn't use _DtCmUpdateAttributes because we need
874 * to check access rights here
877 /* copy original attributes for rollback if update fails */
878 if (cal->attrs && (stat = _DtCm_copy_cms_attributes(cal->num_attrs,
879 cal->attrs, &oldnum, &oldattrs)) != CSA_SUCCESS)
882 for (i = 0; i < numsrc && stat == CSA_SUCCESS; i++) {
883 if (srcattrs[i].name.name == NULL)
886 if (srcattrs[i].name.num <= 0)
887 srcattrs[i].name.num = _DtCm_get_index_from_table(
889 srcattrs[i].name.name);
891 if (srcattrs[i].name.num < 0) {
892 if (!_DTCMS_HAS_INSERT_CALENDAR_ATTR_ACCESS(access))
893 stat = CSA_E_NO_AUTHORITY;
895 if ((stat = _DtCmExtendNameTable(
896 srcattrs[i].name.name, 0, 0,
898 _DtCM_DEFINED_CAL_ATTR_SIZE,
899 _CSA_calendar_attribute_names,
900 &cal->cal_tbl, NULL)) == CSA_SUCCESS) {
901 srcattrs[i].name.num =
903 stat = _DtCmGrowAttrArray(
904 &cal->num_attrs, &cal->attrs,
909 } else if (!_DTCMS_HAS_CHANGE_CALENDAR_ATTR_ACCESS(access)) {
911 stat = CSA_E_NO_AUTHORITY;
913 cms_attribute_value val;
915 if (srcattrs[i].name.num == CSA_CAL_ATTR_ACCESS_LIST_I
916 && srcattrs[i].value == NULL) {
917 val.type = CSA_VALUE_ACCESS_LIST;
918 val.item.access_list_value = NULL;
919 srcattrs[i].value = &val;
921 stat = _DtCmUpdateAttribute(&srcattrs[i],
922 &cal->attrs[srcattrs[i].name.num]);
926 if (stat == CSA_SUCCESS) {
927 log = _DtCmsGetLogFN(cal->calendar);
930 stat = _DtCmsAppendCalAttrsByFN(log, cal->num_attrs,
935 if (stat == CSA_SUCCESS) {
936 cal->modified = B_TRUE;
938 _DtCm_free_cms_attributes(oldnum + 1, oldattrs);
941 _DtCm_free_cms_attributes(cal->num_attrs+1, cal->attrs);
943 cal->num_attrs = oldnum;
944 cal->attrs = oldattrs;
950 extern CSA_return_code
951 _DtCmsV5TransactLog(_DtCmsCalendar *cal, cms_entry *e, _DtCmsLogOps op)
953 CSA_return_code stat;
956 if ((log = _DtCmsGetLogFN(cal->calendar)) == NULL)
957 return (CSA_E_INSUFFICIENT_MEMORY);
959 if (cal->hashed == B_FALSE ||
960 cal->num_entry_attrs < cal->entry_tbl->size) {
961 if ((stat = _DtCmsAppendHTableByFN(log, cal->entry_tbl->size,
962 cal->entry_tbl->names, cal->types)) != CSA_SUCCESS) {
966 cal->hashed = B_TRUE;
967 cal->num_entry_attrs = cal->entry_tbl->size;
970 stat = _DtCmsAppendEntryByFN(log, e, op);
975 /*****************************************************************************
976 * static functions used within the file
977 *****************************************************************************/
980 * return user name of file owner
981 * If the calendar name is the same as a user account name, the
982 * calendar name is return; otherwise, the owner name is derived from
983 * the owner of the calendar file
985 static CSA_return_code
986 get_file_owner(char *calname, char **owner)
994 if (calname == NULL || owner == NULL)
995 return (CSA_E_FAILURE);
999 if (_DtCmIsUserName(calname) == B_TRUE) {
1000 strcpy(buf, calname);
1002 if ((log = _DtCmsGetLogFN(calname)) == NULL)
1003 return (CSA_E_INSUFFICIENT_MEMORY);
1005 res = stat(log, &info);
1010 if (pw = getpwuid(info.st_uid))
1011 strcpy(buf, pw->pw_name);
1013 return (CSA_E_FAILURE);
1015 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
1018 if (((*owner) = (char *)strdup(buf)) == NULL)
1019 return (CSA_E_INSUFFICIENT_MEMORY);
1021 return (CSA_SUCCESS);
1025 get_calname(char *target)
1032 ptr = strchr(target, '@');
1034 return (strdup(target));
1037 name = strdup(target);
1043 static CSA_return_code
1044 init_cal_attrs(_DtCmsCalendar *cal)
1048 /* initialize the calendar with predefined attribute names */
1049 if ((cal->attrs = (cms_attribute *)calloc(1,
1050 sizeof(cms_attribute)*(_DtCm_cal_name_tbl->size + 1))) == NULL) {
1051 return (CSA_E_INSUFFICIENT_MEMORY);
1054 for (i = 1; i <= _DtCm_cal_name_tbl->size; i++) {
1055 if ((cal->attrs[i].name.name =
1056 strdup(_DtCm_cal_name_tbl->names[i])) == NULL) {
1057 _DtCm_free_cms_attributes(i, cal->attrs);
1059 return (CSA_E_INSUFFICIENT_MEMORY);
1062 cal->attrs[i].name.num = i;
1064 cal->num_attrs = _DtCm_cal_name_tbl->size;
1066 return (CSA_SUCCESS);
1069 static CSA_return_code
1070 _CopyCalendarAttr(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1073 cms_attribute_value tmpval;
1075 if (cal->attrs && cal->attrs[index].value)
1076 return (_DtCm_copy_cms_attribute(attr,
1077 &cal->attrs[index], B_TRUE));
1079 return (CSA_SUCCESS);
1082 static CSA_return_code
1083 _GetCalendarSize(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1085 CSA_return_code stat;
1088 if ((stat = _DtCmsGetFileSize(cal->calendar, &size)) == CSA_SUCCESS) {
1089 attr->name.num = CSA_CAL_ATTR_CALENDAR_SIZE_I;
1090 if (attr->name.name = strdup(CSA_CAL_ATTR_CALENDAR_SIZE))
1091 return (_DtCm_set_uint32_attrval((uint)size,
1094 return (CSA_E_INSUFFICIENT_MEMORY);
1099 static CSA_return_code
1100 _GetNumberEntries(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1104 size = rb_size(cal->tree) + hc_size(cal->list);
1106 attr->name.num = CSA_CAL_ATTR_NUMBER_ENTRIES_I;
1107 if (attr->name.name = strdup(CSA_CAL_ATTR_NUMBER_ENTRIES))
1108 return (_DtCm_set_uint32_attrval(size, &attr->value));
1110 return (CSA_E_INSUFFICIENT_MEMORY);
1113 static CSA_return_code
1114 _GetAccessList(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1116 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
1117 return (_DtCm_copy_cms_attribute(attr,
1118 &cal->attrs[CSA_CAL_ATTR_ACCESS_LIST_I], B_TRUE));
1120 Access_Entry_4 *alist;
1121 CSA_return_code stat;
1122 cms_attribute tmpattr;
1123 cms_attribute_value tmpval;
1125 alist = _DtCmsCalendarAccessList(cal);
1126 if ((stat = _DtCm_accessentry4_to_cmsaccesslist(alist,
1127 &tmpval.item.access_list_value)) == CSA_SUCCESS) {
1128 tmpattr.name.num = CSA_CAL_ATTR_ACCESS_LIST_I;
1129 tmpattr.name.name = CSA_CAL_ATTR_ACCESS_LIST;
1130 tmpattr.value = &tmpval;
1131 tmpval.type = CSA_VALUE_ACCESS_LIST;
1133 return (_DtCm_copy_cms_attribute(attr, &tmpattr,
1140 static CSA_return_code
1141 _GetCalendarName(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1143 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
1144 return (_DtCm_copy_cms_attribute(attr,
1145 &cal->attrs[CSA_CAL_ATTR_CALENDAR_NAME_I], B_TRUE));
1147 attr->name.num = CSA_CAL_ATTR_CALENDAR_NAME_I;
1148 if (attr->name.name = strdup(CSA_CAL_ATTR_CALENDAR_NAME)) {
1149 return (_DtCm_set_string_attrval(cal->calendar,
1150 &attr->value, CSA_VALUE_STRING));
1152 return (CSA_E_INSUFFICIENT_MEMORY);
1157 static CSA_return_code
1158 _GetCalendarOwner(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1160 if (cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION) {
1161 return (_DtCm_copy_cms_attribute(attr,
1162 &cal->attrs[CSA_CAL_ATTR_CALENDAR_OWNER_I], B_TRUE));
1164 attr->name.num = CSA_CAL_ATTR_CALENDAR_OWNER_I;
1165 if (attr->name.name = strdup(CSA_CAL_ATTR_CALENDAR_OWNER)) {
1166 return (_DtCm_set_user_attrval(cal->owner,
1169 return (CSA_E_INSUFFICIENT_MEMORY);
1174 static CSA_return_code
1175 _GetServerVersion(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1177 attr->name.num = CSA_X_DT_CAL_ATTR_SERVER_VERSION_I;
1178 if (attr->name.name = strdup(CSA_X_DT_CAL_ATTR_SERVER_VERSION))
1179 return (_DtCm_set_uint32_attrval((uint)TABLEVERS, &attr->value));
1181 return (CSA_E_INSUFFICIENT_MEMORY);
1184 static CSA_return_code
1185 _GetDataVersion(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1189 version = cal->fversion >= _DtCM_FIRST_EXTENSIBLE_DATA_VERSION ?
1190 cal->fversion : _DtCM_FIRST_EXTENSIBLE_DATA_VERSION - 1;
1192 attr->name.num = CSA_X_DT_CAL_ATTR_DATA_VERSION_I;
1193 if (attr->name.name = strdup(CSA_X_DT_CAL_ATTR_DATA_VERSION))
1194 return (_DtCm_set_uint32_attrval(version, &attr->value));
1196 return (CSA_E_INSUFFICIENT_MEMORY);
1199 static CSA_return_code
1200 _GetProductId(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1202 attr->name.num = CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I;
1203 if (attr->name.name = strdup(CSA_CAL_ATTR_PRODUCT_IDENTIFIER)) {
1204 return (_DtCm_set_string_attrval(_DtCM_PRODUCT_IDENTIFIER,
1205 &attr->value, CSA_VALUE_STRING));
1207 return (CSA_E_INSUFFICIENT_MEMORY);
1211 static CSA_return_code
1212 _GetSupportedVersion(_DtCmsCalendar *cal, int index, cms_attribute *attr)
1214 attr->name.num = CSA_CAL_ATTR_VERSION_I;
1215 if (attr->name.name = strdup(CSA_CAL_ATTR_VERSION)) {
1216 return (_DtCm_set_string_attrval(_DtCM_SPEC_VERSION_SUPPORTED,
1217 &attr->value, CSA_VALUE_STRING));
1219 return (CSA_E_INSUFFICIENT_MEMORY);