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 libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*******************************************************************************
27 ** $XConsortium: util.c /main/12 1996/11/21 19:44:40 drk $
29 ** RESTRICTED CONFIDENTIAL INFORMATION:
31 ** The information in this document is subject to special
32 ** restrictions in a confidential disclosure agreement between
33 ** HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 ** document outside HP, IBM, Sun, USL, SCO, or Univel without
35 ** Sun's specific written approval. This document and all copies
36 ** and derivative works thereof must be returned or destroyed at
39 ** Copyright 1993 Sun Microsystems, Inc. All rights reserved.
41 *******************************************************************************/
44 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
45 * (c) Copyright 1993, 1994 International Business Machines Corp. *
46 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
47 * (c) Copyright 1993, 1994 Novell, Inc. *
53 #include <EUSCompat.h>
61 #include <sys/utsname.h> /* SYS_NMLN */
63 #include <sys/systeminfo.h>
64 #elif defined(CSRG_BASED)
65 #include <sys/dirent.h>
69 #include <sys/param.h>
71 #define X_INCLUDE_STRING_H
72 #define X_INCLUDE_TIME_H
73 #define XOS_USE_NO_LOCKING
74 #if defined(__linux__)
77 #include <X11/Xos_r.h>
87 extern int _csa_tick_to_iso8601(time_t, char *);
88 extern int _csa_iso8601_to_tick(char *, time_t*);
90 extern FILE *popen(const char *, const char *);
91 extern int pclose(FILE *);
95 * Function: cm_def_printer
97 * Purpose: get the default printer name for SVR4
101 * Returns: char* (printer name)
110 char *printer_name=NULL;
113 tmp = (char*)getenv("LPDEST");
114 if (tmp != NULL && *tmp != NULL) {
115 printer_name = (char*)malloc(strlen(tmp)+1);
116 strcpy(printer_name, tmp);
120 /* This is really nasty. lpstat -d does *not* work on the AIX
121 machines. Just fall back to "lp" here */
124 _Xstrtokparams strtok_buf;
126 fp = (FILE *)popen("lpstat -d", "r");
127 fread(message, 256, 1, fp);
128 tmp = (char *)_XStrtok(message, ":", strtok_buf);
129 tmp = (char *)_XStrtok((char *)NULL, "\n", strtok_buf);
130 if (tmp != NULL && *tmp != NULL) {
131 printer_name = (char*)malloc(strlen(tmp)+1);
132 strcpy(printer_name, tmp);
135 printer_name = (char*)malloc(3);
136 strcpy(printer_name, "lp");
139 /* close the process connection */
142 printer_name = (char*)malloc(3);
143 strcpy(printer_name, "lp");
147 tmp = (char*)getenv("PRINTER");
148 if (tmp != NULL && *tmp != '\0') {
149 printer_name = (char*)malloc(strlen(tmp)+1);
150 strcpy(printer_name, tmp);
153 printer_name = (char*)malloc(3);
154 strcpy(printer_name, "lw");
160 /*--------------------------------------------------------------------------
161 * THE FOLLOWING STRING FUNCTION redefinitions are a HACK !
163 * The cm code should be changed so that
164 * a) the redefined functions use the same headers as in <string.h>
165 * b) no redefinition of these library function is necessary
167 * The cm definitions use different function headers than in <string.h>
168 * Prefixing the functions will get rid of the resulting compiler error.
169 * Now cm functions will use the cm_ string functions, but library functions,
170 * e.g. fprintf, will use strlen etc. which leads to core dumps.
171 * As part of the bootstrapping process, I am including the below redefinitions
172 * of the system functions. This should be fixed later.
174 *--------------------------------------------------------------------------*/
177 cm_strcpy(register char *s1, register char *s2)
179 if (s1==NULL || s2==NULL) return(NULL);
185 cm_strlen(register char *s)
189 if (s==NULL) return 0;
197 if (s1 == NULL) return NULL;
198 s2 = (char *) strdup(s1);
203 cm_strcat(char *s1, char *s2)
205 if (s1==NULL || s2==NULL) return(s1);
210 /* transform string patterns of \\ into \
211 \n into carriage returns and
220 if (s==NULL) return(NULL);
223 newstr= (char *) ckalloc((unsigned)i + 1);
225 for (j=0; j<i; j++) {
231 else if (s[j+1]=='\\') {
235 else if (s[j+1]=='\"') {
252 /* transform string patterns of \ into \\
253 carriage returns into \n, and
262 if (s==NULL) return(NULL);
265 newstr = (char *) ckalloc((unsigned)((2 * i) + 1));
267 for (j=0; j<i; j++) {
273 else if (s[j]=='\\') {
278 else if (s[j]=='\"') {
294 syserr(char *msg, int a1, int a2, int a3)
296 /* Taken from Unix World, July 1989, p. 66 */
299 /* save the error number so fprintf doesn't step on it */
302 (void) fprintf(stderr, "cm: ");
303 /* print the actual message itself */
304 (void) fprintf(stderr, msg, a1, a2, a3);
307 /* print the error, if any */
309 if (saveerr < 0 || saveerr > sys_nerr)
310 (void) fprintf(stderr, ":Unknown error %d", saveerr);
312 (void) fprintf(stderr, ":%s", sys_errlist[saveerr]);
316 /* thow a newline on the end */
317 (void) fprintf(stderr, "\n");
319 /* exit with an error */
326 /* Wrapper around standard storage allocation, to localize errors.
327 Taken from Unix World, July 1989, p. 66 */
329 ckalloc(unsigned int size)
333 /* try to get the memory */
334 p = (char *)calloc(1, size);
336 /* if it worked, return the memory directly */
337 if (p != NULL) return(p);
339 /* try allocation again */
340 p = (char *)calloc(1, size);
342 /* see if it worked the second time */
343 if (p != NULL) return(p);
345 /* no recovery available */
346 syserr("ckalloc: cannot allocate %d bytes", size, 0, 0);
347 return((char *)NULL);
355 _Xctimeparams ctime_buf;
357 a = _XCtime(&t, ctime_buf);
358 (void) fprintf (stderr, "%ld %s\n", (long)t, a);
364 if (i1 > i2) return(i2);
365 if (i1 < i2) return(i1);
372 if (i1 > i2) return(i1);
373 if (i1 < i2) return(i2);
378 text_to_lines(char *s, int n)
381 Lines *prev_l = NULL, *l = NULL, *head= NULL;
386 if (s == NULL || n <= 0) return NULL;
388 string = cm_strdup(s);
390 * Here, look for \n, which is (in)famous character in IBM-932.
391 * Therefore, don't use strtok(). It is not i18n'ed.
393 for ( _p = string; *_p != '\0'; _p += clen ) {
394 clen = mblen( _p, MB_CUR_MAX );
399 if ( ( clen == 1 ) && ( *_p == '\n' ) ) {
407 if (line == NULL) break;
408 l = (Lines*)ckalloc(sizeof(Lines));
409 if (head == NULL) head = l;
410 if (prev_l != NULL) prev_l->next = l;
411 l->s = cm_strdup(line);
414 if ( ( *_p == '\0' ) || ( clen == -1 ) )
417 for ( ; *_p != '\0'; _p += clen ) {
418 clen = mblen( _p, MB_CUR_MAX );
423 if ( ( clen == 1 ) && ( *_p == '\n' ) ) {
437 destroy_lines(Lines *l)
442 free(l->s); l->s=NULL;
445 free((char *)p); p=NULL;
450 * Expand any escape characters in passed string
453 expand_esc_chars(char *string) {
457 while (from && *from) {
458 int len = mblen(from, MB_CUR_MAX);
460 if (len <= 0) break; /* invalid char */
461 if (len > 1) { /* move over multibyte char */
491 get_head(char *str, char sep)
493 static char buf[BUFSIZ];
500 while (*str && *str != sep)
506 return(cm_strdup(buf));
511 get_tail(char *str, char sep)
518 while (*str && *str != sep)
521 return(cm_strdup(++str));
527 cm_get_credentials(void)
530 static char *login = NULL;
534 name = (char*)cm_get_uname();
535 host = (char*)cm_get_local_host();
536 login = (char *) ckalloc (cm_strlen(name) + cm_strlen(host) + 2);
537 sprintf(login, "%s@%s", name, host);
543 cm_get_local_host(void)
545 static char *local_host;
547 if (local_host == NULL) {
549 local_host = (char *)ckalloc(MAXHOSTNAMELEN);
550 (void) sysinfo(SI_HOSTNAME, local_host, MAXHOSTNAMELEN);
552 local_host = (char *)ckalloc(MAXHOSTNAMELEN);
553 (void) gethostname(local_host, MAXHOSTNAMELEN);
566 if ((pw = (struct passwd *)getpwuid(geteuid())) == NULL)
567 name = (char *) cm_strdup("nobody");
569 name = (char *) cm_strdup(pw->pw_name);
576 cm_get_local_domain(void)
578 static char *local_domain;
580 if (local_domain == NULL) {
581 local_domain = ckalloc(BUFSIZ);
583 sysinfo(SI_SRPC_DOMAIN, local_domain, DOM_NM_LN);
585 if(-1 == getdomainname(local_domain, BUFSIZ)) {
586 fprintf(stderr, "getdomainname() failed %d '%s'\n", errno, strerror(errno));
591 return(local_domain);
594 /* partially qualified target */
596 cm_pqtarget(char *name)
598 char *host, *target=NULL;
600 host = (char*)strchr(name, '@');
602 host = (char*)cm_get_local_host();
603 target = (char *)ckalloc(cm_strlen(name) +
604 cm_strlen(host) + 2);
605 sprintf(target, "%s@%s", name, host);
608 target = (char *) cm_strdup(name);
613 * calendar_name@host[.domain] -> calendar_name
616 cm_target2name(char *target)
618 return(get_head(target, '@'));
622 * calendar_name@host[.domain] -> host[.domain]
625 cm_target2location(char *target)
627 return(get_tail(target, '@'));
631 * calendar_name@host[.domain] -> host
634 cm_target2host(char *target)
636 char *location, *host;
638 location = get_tail(target, '@');
639 if (location != NULL) {
640 host = get_head(location, '.');
647 * calendar_name@host[.domain] -> domain
650 cm_target2domain(char *target)
652 char *location, *domain;
654 location = get_tail(target, '@');
655 if (location != NULL) {
656 domain = get_tail(location, '.');
664 * str consists of components separated by token
665 * get and copy the first component into comp and
666 * strip it out of str, so str would point to the first
667 * token or the null terminator.
670 get_component(char **str, char *comp, char token)
681 while (ptr && *ptr != 0 && *ptr != token)
690 * head and tail points to the first and last character
691 * of a string which consists of components separated by token.
692 * get and copy the last component into comp and
693 * strip it out of the string, so tail would point to the last
694 * token or the head of the string.
697 get_last_component(char *head, char **tail, char *comp, char token)
708 while (cptr != head && *cptr != token)
716 while (ptr != (*tail + 1))
725 match_forward(char *str1, char *str2)
727 char com1[BUFSIZ], com2[BUFSIZ];
729 if (str1 == NULL || str2 == NULL)
733 get_component(&str1, com1, '.');
734 get_component(&str2, com2, '.');
746 if (strcasecmp(com1, com2) != 0)
749 /* take care of case: a.b a. */
750 if (strcmp(str2, ".") == 0
751 && (strcmp(str1, ".") != 0 || *str1 != '\0'))
762 } else if (strcmp(str2, ".") == 0 || *str2 == '\0')
770 match_backward(char *str1, char *str2)
774 char com1[BUFSIZ], com2[BUFSIZ];
776 if (str1 == NULL || str2 == NULL)
786 ptr1 = (len1 ? (str1 + len1 - 1) : str1);
787 ptr2 = (len2 ? (str2 + len2 - 1) : str2);
789 if (*ptr1 == '.' && ptr1 != str1)
792 if (*ptr2 == '.' && ptr2 != str2)
796 get_last_component(str1, &ptr1, com1, '.');
797 get_last_component(str2, &ptr2, com2, '.');
809 if (strcasecmp(com1, com2) != 0)
817 return (B_FALSE); /* bad format */
819 return (B_TRUE); /* done */
825 return (B_FALSE); /* bad format */
827 return (B_TRUE); /* done */
832 * Correct format assumed, i.e. str = label1[.label2 ...]
833 * Compare str2 against str1 which should be more fully qualified than str2
836 same_path(char *str1, char *str2)
842 if (str1 == NULL || str2 == NULL)
846 if (*str1 == '.' || *str2 == '.')
847 return (B_FALSE); /* bad format */
849 if (match_forward(str1, str2) == B_TRUE)
852 return (match_backward(str1, str2));
856 * compare user1 and user2
857 * user1 = user@host[.domain]
858 * user2 = any format in (user, user@host[.domain], user@domain)
861 same_user(char *user1, char *user2)
868 if (user1 == NULL || user2 == NULL)
871 /* compare user name */
872 str1 = get_head(user1, '@');
873 str2 = get_head(user2, '@');
875 if (str1 == NULL || str2 == NULL)
878 if (strcmp(str1, str2)) {
886 /* if only user name is specified, don't need to check domain */
887 str2 = strchr(user2, '@');
891 /* first assume user2=user@domain */
892 str1 = strchr(user1, '.');
894 if (same_path(cm_get_local_domain(), ++str2))
897 if (same_path(++str1, ++str2))
901 /* assume user2=user@host[.domain] */
903 str1 = strchr(user1, '@');
904 sprintf(buf, "%s.%s", ++str1, cm_get_local_domain());
907 str1 = strchr(user1, '@');
911 if (same_path(str1, str2))
918 * A blank line is one that consists of only \b, \t or \n.
925 if (ptr == NULL) return B_TRUE;
926 while (ptr && (*ptr == ' ' || *ptr == '\t' || *ptr == '\n'))
935 embedded_blank(char *buf)
939 if (ptr == NULL) return B_TRUE;
940 while (ptr && *ptr) {
941 if ((*ptr == ' ') || (*ptr == '\t'))
950 get_data_version(CSA_session_handle session) {
953 CSA_attribute_reference names[1];
954 CSA_uint32 number_attrs_returned;
955 CSA_attribute *attrs_returned;
957 names[0] = CSA_X_DT_CAL_ATTR_DATA_VERSION;
960 if (csa_read_calendar_attributes(session,
963 &number_attrs_returned,
965 NULL) == CSA_SUCCESS) {
966 ver = attrs_returned[0].value->item.uint32_value;
967 csa_free(attrs_returned);
974 get_server_version(CSA_session_handle session) {
977 CSA_attribute_reference names[1];
978 CSA_uint32 number_attrs_returned;
979 CSA_attribute *attrs_returned;
981 names[0] = CSA_X_DT_CAL_ATTR_SERVER_VERSION;
983 if (csa_read_calendar_attributes(session,
986 &number_attrs_returned,
988 NULL) == CSA_SUCCESS) {
989 ver = attrs_returned[0].value->item.uint32_value;
990 csa_free(attrs_returned);
997 privacy_set(Dtcm_appointment *appt) {
999 CSA_sint32 privacy = CSA_CLASS_PUBLIC;
1007 if (!appt->private->value)
1010 privacy = appt->private->value->item.sint32_value;
1016 showtime_set(Dtcm_appointment *appt) {
1018 CSA_sint32 showtime = 0;
1023 if (!appt->show_time)
1026 if (!appt->show_time->value)
1029 showtime = appt->show_time->value->item.sint32_value;
1035 ** Parse the date string and get the month, day, and year
1038 parse_date(OrderingType order, SeparatorType sep, char *datestr, char *m,
1041 char *first, *second, *third;
1042 char *tmp_date, *str = separator_str(sep);
1043 _Xstrtokparams strtok_buf;
1049 if (datestr == NULL)
1052 tmp_date = cm_strdup(datestr);
1053 first = _XStrtok(tmp_date, str, strtok_buf);
1055 ** Check to see if the date entered has legit separator
1057 if ( strcoll(first, datestr) == 0 ) {
1061 second = _XStrtok(NULL, str, strtok_buf);
1062 third = _XStrtok(NULL, str, strtok_buf);
1067 cm_strcpy(m, second);
1069 cm_strcpy(d, first);
1071 cm_strcpy(y, third);
1075 cm_strcpy(m, second);
1077 cm_strcpy(d, third);
1079 cm_strcpy(y, first);
1084 cm_strcpy(m, first);
1086 cm_strcpy(d, second);
1088 cm_strcpy(y, third);
1096 ** Reformat the date string into m/d/y format and write it into the buffer
1099 datestr2mdy(char *datestr, OrderingType order, SeparatorType sep, char *buf) {
1100 char m[3], d[3], y[5];
1103 if (datestr == NULL)
1106 if (order == ORDER_MDY && sep == SEPARATOR_SLASH)
1107 cm_strcpy(buf, datestr);
1109 if ( parse_date(order, sep, datestr, m, d, y) ) {
1110 sprintf(buf, "%s/%s/%s", m, d, y);
1120 ** Format the date according to display property and write it into buffer
1123 format_tick(Tick tick, OrderingType order, SeparatorType sep, char *buff) {
1124 char *str = separator_str(sep);
1126 _Xltimeparams localtime_buf;
1129 tm = _XLocaltime(&tick, localtime_buf);
1133 sprintf(buff, "%d%s%d%s%d", tm->tm_mday, str,
1134 tm->tm_mon+1, str, tm->tm_year+1900);
1137 sprintf(buff, "%d%s%d%s%d", tm->tm_year+1900, str,
1138 tm->tm_mon+1, str, tm->tm_mday);
1142 sprintf(buff, "%d%s%d%s%d", tm->tm_mon+1, str,
1143 tm->tm_mday, str, tm->tm_year+1900);
1149 format_time(Tick t, DisplayType dt, char *buffer) {
1156 } else if (dt == HOUR12) {
1157 am = adjust_hour(&hr);
1158 sprintf(buffer, "%2d:%02d%s",
1159 hr, minute(t), (am) ? "am" : "pm");
1161 sprintf(buffer, "%02d%02d", hr, minute(t));
1165 * The V5 back end uses arrays to pass attributes back and forth. However,
1166 * keeping hard coded references into those arrays (i.e. declaring the tick
1167 * value will always be into position 0 of the array, the what value in
1168 * position 3, etc.) is a bad idea and hard to maintain.
1170 * Thus these convenience functions will translate from an attribute array
1171 * received from the back end into defined structure which the front end can
1174 * IF YOU UPDATE THE STRUCTURES, MAKE SURE YOU UPDATE THESE COUNT CONSTANTS!!
1176 static const int APPT_ATTR_COUNT = 35;
1177 static const int RW_APPT_ATTR_COUNT = 15;
1178 static const int CAL_ATTR_COUNT = 12;
1179 static const int RW_CAL_ATTR_COUNT = 2;
1180 static const int DEF_V5_APPT_ATTR_COUNT = 22;
1181 static const int DEF_V4_APPT_ATTR_COUNT = 20;
1182 static const int DEF_V3_APPT_ATTR_COUNT = 17;
1183 static const int DEF_CAL_ATTR_COUNT = 6;
1184 static const int default_appt_attrs[] = {CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I,
1185 CSA_ENTRY_ATTR_LAST_UPDATE_I,
1186 CSA_ENTRY_ATTR_ORGANIZER_I,
1187 CSA_ENTRY_ATTR_START_DATE_I,
1188 CSA_ENTRY_ATTR_TYPE_I,
1189 CSA_ENTRY_ATTR_SUBTYPE_I,
1190 CSA_ENTRY_ATTR_CLASSIFICATION_I,
1191 CSA_ENTRY_ATTR_END_DATE_I,
1192 CSA_X_DT_ENTRY_ATTR_SHOWTIME_I,
1193 CSA_ENTRY_ATTR_SUMMARY_I,
1194 CSA_ENTRY_ATTR_STATUS_I,
1195 CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I,
1196 CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I,
1197 CSA_ENTRY_ATTR_AUDIO_REMINDER_I,
1198 CSA_ENTRY_ATTR_FLASHING_REMINDER_I,
1199 CSA_ENTRY_ATTR_MAIL_REMINDER_I,
1200 CSA_ENTRY_ATTR_POPUP_REMINDER_I,
1201 CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I,
1202 CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I,
1203 CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I,
1204 CSA_ENTRY_ATTR_RECURRENCE_RULE_I,
1205 CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I
1207 static const int default_cal_attrs[] = {CSA_CAL_ATTR_ACCESS_LIST_I,
1208 CSA_CAL_ATTR_CALENDAR_NAME_I,
1209 CSA_CAL_ATTR_CALENDAR_SIZE_I,
1210 CSA_CAL_ATTR_NUMBER_ENTRIES_I,
1211 CSA_CAL_ATTR_TIME_ZONE_I,
1212 CSA_X_DT_CAL_ATTR_DATA_VERSION_I
1216 * NOTE that this loop is dependent on the first appointment attribute define
1217 * (DT_CM_ATTR_IDENTIFER_I) in the api - if that is changed and is no longer
1218 * the first appointment define, this needs to be changed.
1220 * NOTE that this function checks if the api indexes specified are read-only:
1221 * This assumes that if you need value space (and have set the need_value_space
1222 * flag to B_TRUE), you're setting attributes and since you can't set read-only
1223 * attributes, it will ignore read-only attributes if the need_value_space flag
1226 Dtcm_appointment *allocate_appt_struct (Allocation_reason reason, int version, ...) {
1227 int idx = 0, api_idx;
1229 CmDataList *api_ids = CmDataListCreate();
1230 Dtcm_appointment *appt;
1234 * The Dtcm_appointment wrapper array
1236 idx = sizeof(Dtcm_appointment);
1237 appt = (Dtcm_appointment *)ckalloc(idx);
1238 memset(appt, 0, idx);
1239 appt->reason = reason;
1240 appt->version = version;
1243 * Step through the variable argument list and build the list of
1244 * attributes we're looking for
1246 va_start(pvar, version);
1247 api_idx = va_arg(pvar, int);
1249 if ((reason == appt_read) || !entry_ident_index_ro(api_idx, version))
1250 CmDataListAdd(api_ids, (void *) (intptr_t) api_idx, 0);
1251 api_idx = va_arg(pvar, int);
1256 * No attributes specified, assume the caller wanted all of them
1258 if (api_ids->count <= 0) {
1260 if ((version == DATAVER2) || (version == DATAVER1))
1261 def_attr_count = DEF_V3_APPT_ATTR_COUNT;
1262 else if (version == DATAVER3)
1263 def_attr_count = DEF_V4_APPT_ATTR_COUNT;
1264 else if (version == DATAVER4)
1265 def_attr_count = DEF_V5_APPT_ATTR_COUNT;
1266 else if (version == DATAVER_ARCHIVE)
1267 def_attr_count = DEF_V5_APPT_ATTR_COUNT;
1269 for (idx = 0; idx < def_attr_count; idx++) {
1270 if ((reason == appt_write) && entry_ident_index_ro(default_appt_attrs[idx], version))
1272 CmDataListAdd(api_ids, (void *) (intptr_t) default_appt_attrs[idx], 0);
1277 * We've determined the number of attributes we're retrieving, so
1278 * allocate the name array, and the attribute array (if we are
1279 * going to be writing attributes).
1282 appt->num_names = api_ids->count;
1283 idx = sizeof(CSA_attribute_reference *) * appt->num_names;
1284 appt->names = (CSA_attribute_reference *)ckalloc(idx);
1285 memset(appt->names, 0, idx);
1287 appt->count = api_ids->count;
1288 if (reason == appt_write) {
1289 idx = sizeof(CSA_attribute) * appt->count;
1290 appt->attrs = (CSA_attribute *)ckalloc(idx);
1291 memset(appt->attrs, 0, idx);
1295 * Now loop through and set the names and initialize the attributes
1297 for (idx = 0; idx < appt->count; idx++) {
1298 api_idx = (int) (intptr_t) CmDataListGetData(api_ids, idx + 1);
1299 appt->names[idx] = strdup(_CSA_entry_attribute_names[api_idx]);
1300 if (reason == appt_write)
1301 initialize_entry_attr(api_idx, &appt->attrs[idx], reason, version);
1304 if (reason == appt_write)
1305 set_appt_links(appt);
1307 CmDataListDestroy(api_ids, 0);
1312 query_appt_struct(CSA_session_handle session,
1313 CSA_entry_handle entry_handle,
1314 Dtcm_appointment *appt) {
1316 CSA_return_code status;
1318 /* if there is old query material laying around, toss it */
1321 csa_free(appt->attrs);
1322 appt->filled = False;
1326 if ((status = csa_read_entry_attributes(session,
1332 NULL)) == CSA_SUCCESS) {
1333 set_appt_links(appt);
1334 appt->filled = True;
1342 * NOTE that this function checks if the api indexes specified are read-only:
1343 * This assumes that if you need value space (and have set the need_value_space
1344 * flag to B_TRUE), you're setting attributes and since you can't set read-only
1345 * attributes, it will ignore read-only attributes if the need_value_space flag
1349 allocate_cal_struct(Allocation_reason reason, int version, ...) {
1350 int idx = 0, api_idx;
1352 CmDataList *api_ids = CmDataListCreate();
1356 * The Dtcm_apopintment wrapper array
1358 idx = sizeof(Dtcm_calendar);
1359 cal = (Dtcm_calendar *)ckalloc(idx);
1360 memset(cal, 0, idx);
1361 cal->reason = reason;
1362 cal->version = version;
1365 * Step through the variable argument list and build the list of
1366 * attributes we're looking for
1368 va_start(pvar, version);
1369 api_idx = va_arg(pvar, int);
1371 if ((reason == appt_read) || !cal_ident_index_ro(api_idx, version))
1372 CmDataListAdd(api_ids, (void *) (intptr_t) api_idx, 0);
1373 api_idx = va_arg(pvar, int);
1378 * No attributes specified, assume the caller wanted all of them
1380 if (api_ids->count <= 0) {
1381 for (idx = 0; idx < DEF_CAL_ATTR_COUNT; idx++) {
1382 if ((reason == appt_write) && cal_ident_index_ro(default_cal_attrs[idx], version))
1384 CmDataListAdd(api_ids, (void *) (intptr_t) default_cal_attrs[idx], 0);
1389 * We've determined the number of attributes we're retrieving, so
1390 * allocate the name arrya, and the attribute array (if we are
1391 * going to be writing attributes).
1394 cal->num_names = api_ids->count;
1395 idx = sizeof(CSA_attribute_reference) * cal->num_names;
1396 cal->names = (CSA_attribute_reference *)ckalloc(idx);
1397 memset(cal->names, 0, idx);
1399 cal->count = api_ids->count;
1400 if (reason == appt_write) {
1401 idx = sizeof(CSA_attribute) * cal->count;
1402 cal->attrs = (CSA_attribute *)ckalloc(idx);
1403 memset(cal->attrs, 0, idx);
1407 * Now loop through and set the names and initialize the attributes
1409 for (idx = 0; idx < cal->count; idx++) {
1410 api_idx = (int) (intptr_t) CmDataListGetData(api_ids, idx + 1);
1411 cal->names[idx] = strdup(_CSA_calendar_attribute_names[api_idx]);
1412 if (reason == appt_write)
1413 initialize_cal_attr(api_idx, &cal->attrs[idx], reason, version);
1416 if (reason == appt_write)
1419 CmDataListDestroy(api_ids, 0);
1426 query_cal_struct(CSA_session_handle session,
1427 Dtcm_calendar *cal) {
1429 CSA_return_code status;
1431 /* if there is old query material laying around, toss it */
1434 csa_free(cal->attrs);
1435 cal->filled = False;
1438 if ((status = csa_read_calendar_attributes(session,
1443 NULL)) == CSA_SUCCESS) {
1452 scrub_cal_attr_list(Dtcm_calendar *cal) {
1456 for (i = 0; i < cal->count; i++) {
1457 if (cal->attrs[i].value->type == CSA_VALUE_REMINDER) {
1458 if ((cal->attrs[i].value->item.reminder_value->lead_time == NULL) ||
1459 (cal->attrs[i].value->item.reminder_value->lead_time[0] == '\0')) {
1460 free(cal->attrs[i].name);
1461 cal->attrs[i].name = NULL;
1464 else if ((cal->attrs[i].value->type == CSA_VALUE_ACCESS_LIST) && (cal->attrs[i].value->item.access_list_value == NULL)) {
1465 free(cal->attrs[i].name);
1466 cal->attrs[i].name = NULL;
1468 else if ((cal->attrs[i].value->type == CSA_VALUE_STRING) && (cal->attrs[i].value->item.string_value == NULL)) {
1469 free(cal->attrs[i].name);
1470 cal->attrs[i].name = NULL;
1472 else if ((cal->attrs[i].value->type == CSA_VALUE_DATE_TIME) && (cal->attrs[i].value->item.date_time_value == NULL)) {
1473 free(cal->attrs[i].name);
1474 cal->attrs[i].name = NULL;
1480 cal_ident_index_ro(int id, int version) {
1484 case CSA_CAL_ATTR_CALENDAR_NAME_I:
1485 case CSA_CAL_ATTR_CALENDAR_OWNER_I:
1486 case CSA_CAL_ATTR_CALENDAR_SIZE_I:
1487 case CSA_CAL_ATTR_CHARACTER_SET_I:
1488 case CSA_CAL_ATTR_NUMBER_ENTRIES_I:
1489 case CSA_CAL_ATTR_DATE_CREATED_I:
1490 case CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I:
1491 case CSA_X_DT_CAL_ATTR_DATA_VERSION_I:
1492 case CSA_CAL_ATTR_TIME_ZONE_I:
1504 entry_ident_index_ro(int id, int version) {
1508 case CSA_ENTRY_ATTR_DATE_CREATED_I:
1509 case CSA_ENTRY_ATTR_LAST_UPDATE_I:
1510 case CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I:
1511 case CSA_ENTRY_ATTR_ORGANIZER_I:
1512 case CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I:
1513 case CSA_ENTRY_ATTR_SEQUENCE_NUMBER_I:
1516 case CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I:
1517 case CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I:
1518 case CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I:
1519 case CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I:
1520 case CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I:
1521 if (version >= DATAVER4)
1535 cal_ident_index_tag(int id) {
1539 case CSA_CAL_ATTR_CALENDAR_NAME_I:
1540 case CSA_CAL_ATTR_CHARACTER_SET_I:
1541 case CSA_CAL_ATTR_COUNTRY_I:
1542 case CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I:
1543 case CSA_CAL_ATTR_TIME_ZONE_I:
1544 case CSA_CAL_ATTR_LANGUAGE_I:
1545 r_tag = CSA_VALUE_STRING;
1547 case CSA_CAL_ATTR_CALENDAR_OWNER_I:
1548 r_tag = CSA_VALUE_CALENDAR_USER;
1550 case CSA_CAL_ATTR_DATE_CREATED_I:
1551 r_tag = CSA_VALUE_DATE_TIME;
1553 case CSA_CAL_ATTR_CALENDAR_SIZE_I:
1554 case CSA_CAL_ATTR_NUMBER_ENTRIES_I:
1555 case CSA_X_DT_CAL_ATTR_DATA_VERSION_I:
1556 r_tag = CSA_VALUE_UINT32;
1558 case CSA_CAL_ATTR_ACCESS_LIST_I:
1559 r_tag = CSA_VALUE_ACCESS_LIST;
1561 case CSA_CAL_ATTR_WORK_SCHEDULE_I:
1563 r_tag = CSA_VALUE_OPAQUE_DATA;
1571 entry_ident_index_tag(int id) {
1575 case CSA_ENTRY_ATTR_DESCRIPTION_I:
1576 case CSA_ENTRY_ATTR_EXCEPTION_RULE_I:
1577 case CSA_ENTRY_ATTR_RECURRENCE_RULE_I:
1578 case CSA_ENTRY_ATTR_SUBTYPE_I:
1579 case CSA_ENTRY_ATTR_SUMMARY_I:
1580 r_tag = CSA_VALUE_STRING;
1582 case CSA_ENTRY_ATTR_DATE_COMPLETED_I:
1583 case CSA_ENTRY_ATTR_DATE_CREATED_I:
1584 case CSA_ENTRY_ATTR_DUE_DATE_I:
1585 case CSA_ENTRY_ATTR_END_DATE_I:
1586 case CSA_ENTRY_ATTR_LAST_UPDATE_I:
1587 case CSA_ENTRY_ATTR_START_DATE_I:
1588 case CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I:
1589 r_tag = CSA_VALUE_DATE_TIME;
1591 case CSA_ENTRY_ATTR_EXCEPTION_DATES_I:
1592 case CSA_ENTRY_ATTR_RECURRING_DATES_I:
1593 r_tag = CSA_VALUE_DATE_TIME_LIST;
1595 case CSA_ENTRY_ATTR_CLASSIFICATION_I:
1596 case CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I:
1597 case CSA_ENTRY_ATTR_PRIORITY_I:
1598 case CSA_ENTRY_ATTR_SEQUENCE_NUMBER_I:
1599 case CSA_ENTRY_ATTR_STATUS_I:
1600 case CSA_ENTRY_ATTR_TYPE_I:
1601 case CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I:
1602 case CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I:
1603 r_tag = CSA_VALUE_UINT32;
1605 case CSA_ENTRY_ATTR_TIME_TRANSPARENCY_I:
1606 case CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I:
1607 case CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I:
1608 case CSA_X_DT_ENTRY_ATTR_SHOWTIME_I:
1609 r_tag = CSA_VALUE_SINT32;
1611 case CSA_ENTRY_ATTR_AUDIO_REMINDER_I:
1612 case CSA_ENTRY_ATTR_FLASHING_REMINDER_I:
1613 case CSA_ENTRY_ATTR_MAIL_REMINDER_I:
1614 case CSA_ENTRY_ATTR_POPUP_REMINDER_I:
1615 r_tag = CSA_VALUE_REMINDER;
1617 case CSA_ENTRY_ATTR_ORGANIZER_I:
1618 case CSA_ENTRY_ATTR_SPONSOR_I:
1619 r_tag = CSA_VALUE_CALENDAR_USER;
1621 case CSA_ENTRY_ATTR_ATTENDEE_LIST_I:
1622 r_tag = CSA_VALUE_ATTENDEE_LIST;
1624 case CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I:
1626 r_tag = CSA_VALUE_OPAQUE_DATA;
1634 ident_name_ro(char *name, int version) {
1635 boolean_t r_ro = B_FALSE;
1637 if (strcmp(name, CSA_CAL_ATTR_CALENDAR_NAME) == 0 ||
1638 strcmp(name, CSA_CAL_ATTR_CALENDAR_OWNER) == 0 ||
1639 strcmp(name, CSA_CAL_ATTR_CALENDAR_SIZE) == 0 ||
1640 strcmp(name, CSA_CAL_ATTR_DATE_CREATED) == 0 ||
1641 strcmp(name, CSA_CAL_ATTR_PRODUCT_IDENTIFIER) == 0 ||
1642 strcmp(name, CSA_X_DT_CAL_ATTR_DATA_VERSION) == 0 ||
1643 strcmp(name, CSA_ENTRY_ATTR_SEQUENCE_NUMBER) == 0 ||
1644 strcmp(name, CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER) == 0 ||
1645 strcmp(name, CSA_ENTRY_ATTR_ORGANIZER) == 0 ||
1646 strcmp(name, CSA_ENTRY_ATTR_LAST_UPDATE) == 0 ||
1647 strcmp(name, CSA_ENTRY_ATTR_DATE_CREATED) == 0 ||
1648 strcmp(name, CSA_ENTRY_ATTR_NUMBER_RECURRENCES) == 0)
1651 if ((version >= DATAVER4) &&
1652 (strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE) == 0 ||
1653 strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES) == 0 ||
1654 strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL) == 0 ||
1655 strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM) == 0))
1662 initialize_cal_attr(int id, CSA_attribute *attrs, Allocation_reason reason, int version) {
1665 attrs->name = cm_strdup(_CSA_calendar_attribute_names[id]);
1666 if ((reason == appt_write) && !cal_ident_index_ro(id, version)) {
1667 size = sizeof(CSA_attribute_value);
1668 attrs->value = (CSA_attribute_value *)ckalloc(size);
1669 memset(attrs->value, 0, size);
1670 attrs->value->type = cal_ident_index_tag(id);
1671 if (attrs->value->type == CSA_VALUE_REMINDER)
1672 attrs->value->item.reminder_value = (CSA_reminder *) calloc(sizeof(CSA_reminder), 1);
1677 free_attr(CSA_attribute *attr) {
1687 if ((attr->value->type == CSA_VALUE_STRING) && attr->value->item.string_value != NULL)
1688 free(attr->value->item.string_value);
1689 else if ((attr->value->type == CSA_VALUE_DATE_TIME) && attr->value->item.date_time_value != NULL)
1690 free(attr->value->item.date_time_value);
1691 else if ((attr->value->type == CSA_VALUE_REMINDER) && attr->value->item.reminder_value != NULL) {
1692 if (attr->value->item.reminder_value->lead_time)
1693 free(attr->value->item.reminder_value->lead_time);
1694 if (attr->value->item.reminder_value->reminder_data.data)
1695 free(attr->value->item.reminder_value->reminder_data.data);
1697 free(attr->value->item.reminder_value);
1706 initialize_entry_attr(int id, CSA_attribute *attrs, Allocation_reason reason, int version) {
1709 attrs->name = cm_strdup(_CSA_entry_attribute_names[id]);
1710 if ((reason == appt_write) && !entry_ident_index_ro(id, version)) {
1711 size = sizeof(CSA_attribute_value);
1712 attrs->value = (CSA_attribute_value *)ckalloc(size);
1713 memset(attrs->value, 0, size);
1714 attrs->value->type = entry_ident_index_tag(id);
1715 if (attrs->value->type == CSA_VALUE_REMINDER)
1716 attrs->value->item.reminder_value = (CSA_reminder *) calloc(sizeof(CSA_reminder), 1);
1721 free_appt_struct(Dtcm_appointment **appt) {
1727 if ((*appt)->names) {
1728 for (i = 0; i < (*appt)->num_names; i++)
1729 if ((*appt)->names[i])
1730 free((*appt)->names[i]);
1732 free((*appt)->names);
1735 /* potential memory leak here. We must be careful, as results
1736 from querys should be thrown away with csa_free(), while
1737 structures we've set up to do update/write operations were
1738 allocated by the client, and need to be freed by that client. */
1740 if (((*appt)->reason == appt_read) && ((*appt)->filled == True))
1741 csa_free((*appt)->attrs);
1743 if ((*appt)->attrs) {
1744 for (i = 0; i < (*appt)->count; i++)
1745 free_attr(&((*appt)->attrs[i]));
1747 free((*appt)->attrs);
1755 free_cal_struct(Dtcm_calendar **cal) {
1761 if ((*cal)->names) {
1762 for (i = 0; i < (*cal)->num_names; i++)
1763 if ((*cal)->names[i])
1764 free((*cal)->names[i]);
1766 free((*cal)->names);
1769 /* potential memory leak here. We must be careful, as results
1770 from querys should be thrown away with csa_free(), while
1771 structures we've set up to do update/write operations were
1772 allocated by the client, and need to be freed by that client. */
1774 if (((*cal)->reason == appt_read) && ((*cal)->filled == True))
1775 csa_free((*cal)->attrs);
1777 if ((*cal)->attrs) {
1778 for (i = 0; i < (*cal)->count; i++)
1779 free_attr(&((*cal)->attrs[i]));
1780 free((*cal)->attrs);
1788 set_appt_links(Dtcm_appointment *appt) {
1792 appt->identifier = NULL;
1793 appt->modified_time = NULL;
1794 appt->author = NULL;
1795 appt->number_recurrence = NULL;
1798 appt->subtype = NULL;
1799 appt->private = NULL;
1800 appt->end_time = NULL;
1801 appt->show_time = NULL;
1804 appt->repeat_type = NULL;
1805 appt->repeat_times = NULL;
1806 appt->repeat_interval = NULL;
1807 appt->repeat_week_num = NULL;
1808 appt->recurrence_rule = NULL;
1813 appt->sequence_end_date = NULL;
1815 for (idx = 0; idx < appt->count; idx++) {
1816 idx_name = appt->attrs[idx].name;
1819 else if (strcmp(idx_name, CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER) == 0)
1820 appt->identifier = &appt->attrs[idx];
1821 else if (strcmp(idx_name, CSA_ENTRY_ATTR_LAST_UPDATE) == 0)
1822 appt->modified_time = &appt->attrs[idx];
1823 else if (strcmp(idx_name, CSA_ENTRY_ATTR_ORGANIZER) == 0)
1824 appt->author = &appt->attrs[idx];
1825 else if (strcmp(idx_name, CSA_ENTRY_ATTR_NUMBER_RECURRENCES) == 0)
1826 appt->number_recurrence = &appt->attrs[idx];
1827 else if (strcmp(idx_name, CSA_ENTRY_ATTR_START_DATE) == 0)
1828 appt->time = &appt->attrs[idx];
1829 else if (strcmp(idx_name, CSA_ENTRY_ATTR_TYPE) == 0)
1830 appt->type = &appt->attrs[idx];
1831 else if (strcmp(idx_name, CSA_ENTRY_ATTR_SUBTYPE) == 0)
1832 appt->subtype = &appt->attrs[idx];
1833 else if (strcmp(idx_name, CSA_ENTRY_ATTR_CLASSIFICATION) == 0)
1834 appt->private = &appt->attrs[idx];
1835 else if (strcmp(idx_name, CSA_ENTRY_ATTR_END_DATE) == 0)
1836 appt->end_time = &appt->attrs[idx];
1837 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_SHOWTIME) == 0)
1838 appt->show_time = &appt->attrs[idx];
1839 else if (strcmp(idx_name, CSA_ENTRY_ATTR_SUMMARY) == 0)
1840 appt->what = &appt->attrs[idx];
1841 else if (strcmp(idx_name, CSA_ENTRY_ATTR_STATUS) == 0)
1842 appt->state = &appt->attrs[idx];
1843 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE) == 0)
1844 appt->repeat_type = &appt->attrs[idx];
1845 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES) == 0)
1846 appt->repeat_times = &appt->attrs[idx];
1847 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL) == 0)
1848 appt->repeat_interval = &appt->attrs[idx];
1849 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM) == 0)
1850 appt->repeat_week_num = &appt->attrs[idx];
1851 else if (strcmp(idx_name, CSA_ENTRY_ATTR_RECURRENCE_RULE) == 0)
1852 appt->recurrence_rule = &appt->attrs[idx];
1853 else if (strcmp(idx_name, CSA_ENTRY_ATTR_AUDIO_REMINDER) == 0)
1854 appt->beep = &appt->attrs[idx];
1855 else if (strcmp(idx_name, CSA_ENTRY_ATTR_FLASHING_REMINDER) == 0)
1856 appt->flash = &appt->attrs[idx];
1857 else if (strcmp(idx_name, CSA_ENTRY_ATTR_MAIL_REMINDER) == 0)
1858 appt->mail = &appt->attrs[idx];
1859 else if (strcmp(idx_name, CSA_ENTRY_ATTR_POPUP_REMINDER) == 0)
1860 appt->popup = &appt->attrs[idx];
1861 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE) == 0)
1862 appt->sequence_end_date = &appt->attrs[idx];
1867 set_cal_links(Dtcm_calendar *cal) {
1871 for (idx = 0; idx < cal->count; idx++) {
1872 idx_name = cal->attrs[idx].name;
1873 if (strcmp(idx_name, CSA_CAL_ATTR_CALENDAR_NAME) == 0)
1874 cal->cal_name = &cal->attrs[idx];
1875 else if (strcmp(idx_name, CSA_X_DT_CAL_ATTR_DATA_VERSION) == 0)
1876 cal->server_version = &cal->attrs[idx];
1877 else if (strcmp(idx_name, CSA_CAL_ATTR_NUMBER_ENTRIES) == 0)
1878 cal->num_entries = &cal->attrs[idx];
1879 else if (strcmp(idx_name, CSA_CAL_ATTR_CALENDAR_SIZE) == 0)
1880 cal->cal_size = &cal->attrs[idx];
1881 else if (strcmp(idx_name, CSA_CAL_ATTR_ACCESS_LIST) == 0)
1882 cal->access_list = &cal->attrs[idx];
1883 else if (strcmp(idx_name, CSA_CAL_ATTR_TIME_ZONE) == 0)
1884 cal->time_zone = &cal->attrs[idx];
1889 setup_range(CSA_attribute **attrs, CSA_enum **ops, int *count, time_t start,
1890 time_t stop, CSA_sint32 type, CSA_sint32 state, boolean_t use_state,
1894 CSA_attribute *attr_ptr;
1902 a_size = sizeof(CSA_attribute) * (*count);
1903 attr_ptr = (CSA_attribute *)ckalloc(a_size);
1904 memset(attr_ptr, 0, a_size);
1906 o_size = sizeof(CSA_enum) * (*count);
1907 op_ptr = (CSA_enum *)ckalloc(o_size);
1908 memset(op_ptr, 0, o_size);
1910 initialize_entry_attr(CSA_ENTRY_ATTR_START_DATE_I, &attr_ptr[0], appt_write, version);
1911 attr_ptr[0].value->item.string_value = malloc(BUFSIZ);
1912 _csa_tick_to_iso8601(start, attr_ptr[0].value->item.string_value);
1914 op_ptr[0] = CSA_MATCH_GREATER_THAN_OR_EQUAL_TO;
1916 initialize_entry_attr(CSA_ENTRY_ATTR_START_DATE_I, &attr_ptr[1], appt_write, version);
1917 attr_ptr[1].value->item.string_value = malloc(BUFSIZ);
1918 _csa_tick_to_iso8601(stop, attr_ptr[1].value->item.string_value);
1919 op_ptr[1] = CSA_MATCH_LESS_THAN_OR_EQUAL_TO;
1921 initialize_entry_attr(CSA_ENTRY_ATTR_TYPE_I, &attr_ptr[2], appt_write, version);
1922 attr_ptr[2].value->item.sint32_value = type;
1923 op_ptr[2] = CSA_MATCH_EQUAL_TO;
1926 initialize_entry_attr(CSA_ENTRY_ATTR_STATUS_I, &attr_ptr[3], appt_write, version);
1927 attr_ptr[3].value->item.sint32_value = state;
1928 op_ptr[3] = CSA_MATCH_EQUAL_TO;
1936 free_range(CSA_attribute **attrs, CSA_enum **ops, int count) {
1939 for (i = 0; i < count; i++) {
1940 free((*attrs)[i].name);
1941 if (((*attrs)[i].value->type == CSA_VALUE_STRING) ||
1942 ((*attrs)[i].value->type == CSA_VALUE_DATE_TIME))
1943 if ((*attrs)[i].value->item.string_value)
1944 free((*attrs)[i].value->item.string_value);
1946 free((*attrs)[i].value);
1949 /* This memory was allocated by the client, and must be freed
1961 * In Motif you can't associate user data with items in a list. To get around
1962 * this we have the following simple functions (CmDataList*) that maintain
1963 * a list of user data. We follow the intrinscs coding style to re-inforce
1964 * the relationship these routines have to the XmList* functions.
1968 * Create a list to store user data
1971 CmDataListCreate(void)
1974 return (CmDataList *)calloc(1, sizeof(CmDataList));
1981 CmDataListDestroy(CmDataList *list, int free_data)
1984 CmDataListDeleteAll(list, free_data);
1989 * Create node to hold data in list.
1992 CmDataItemCreate(void)
1995 return (CmDataItem *)calloc(1, sizeof(CmDataItem));
1999 * Add user data to list at specified position. Note that this
2000 * routine must be called for every item added to a list.
2001 * If the item has no user data, just pass NULL.
2003 * list List to add data to
2004 * data User data. NULL for no data.
2005 * position Where to insert data, starting with 1 for the
2006 * first item. 0 to append to end of list.
2010 * -1 Invalid position
2013 CmDataListAdd(CmDataList *list, void *data, int position)
2016 CmDataItem *item, *p;
2019 /* Create new node to hold data */
2020 item = CmDataItemCreate();
2023 /* Insert node into list at appropriate spot */
2024 if (list->head == NULL) {
2026 } else if (position == 0) {
2027 /* Special case. 0 means append to end */
2028 list->tail->next = item;
2029 } else if (position == 1) {
2030 item->next = list->head;
2033 for (n = 2, p = list->head; p != NULL && n < position;
2041 item->next = p->next;
2045 /* If new item is at the end of the list, update tail */
2046 if (item->next == NULL) {
2056 * Delete user data from a position in the list. If free_data is
2057 * True then this routine will call free(3C) on the user data, otherwise
2058 * the user data is returned so that the caller can dispose of it.
2059 * This routine should be called anytime you delete an item from a
2062 * list List to delete data from
2063 * position Location of item to delete. 0 for last item
2064 * free_data True if you want this routine to call free()
2065 * on the data for you. Otherwise this routine
2066 * will return the address of the data.
2069 * NULL No data found for item at the specified position
2070 * 1 Success (free_data was True)
2071 * other Address of data for item at the specified position.
2072 * (free_data was False)
2075 CmDataListDeletePos(CmDataList *list, int position, int free_data)
2079 CmDataItem *p, *item;
2082 /* Special case. 0 means delete last item */
2083 if (position == 0) {
2084 position = list->count;
2087 if (list->head == NULL) {
2089 } else if (position == 1) {
2091 list->head = item->next;
2092 if (list->tail == item) {
2093 list->tail = item->next;
2096 for (n = 2, p = list->head; p->next != NULL && n < position;
2100 if (p->next == NULL) {
2105 p->next = item->next;
2106 if (list->tail == item) {
2126 * Delete all nodes in the list.
2128 * list List to delete nodes from
2129 * free_data True if you want this routine to call free()
2130 * on the data for you.
2133 CmDataListDeleteAll(CmDataList *list, int free_data)
2136 CmDataItem *p, *tmp;
2140 if (free_data && p->data != NULL) {
2157 * Get data for the item at a particular position in a list.
2160 CmDataListGetData(CmDataList *list, int position)
2164 CmDataItem *p, *item;
2167 if (list->head == NULL) {
2169 } else if (position == 0) {
2170 data = list->tail->data;
2172 for (n = 1, p = list->head; p != NULL && n < position;
2186 * For dumping contents of list
2189 CmDataListDump(CmDataList *list)
2195 printf("***** %d items:\n", list->count);
2197 for (p = list->head, n = 1; p != NULL; p = p->next, n++) {
2198 printf("%3d: %s\n", n, p->data ? (char *)p->data : "<nil>");