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(char *s1, char *s2)
179 if (s1==NULL || s2==NULL) return(NULL);
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) {
877 free(str2); /* Handle if only one alloc success */
881 if (strcmp(str1, str2)) {
889 /* if only user name is specified, don't need to check domain */
890 str2 = strchr(user2, '@');
894 /* first assume user2=user@domain */
895 str1 = strchr(user1, '.');
897 if (same_path(cm_get_local_domain(), ++str2))
900 if (same_path(++str1, ++str2))
904 /* assume user2=user@host[.domain] */
906 str1 = strchr(user1, '@');
907 sprintf(buf, "%s.%s", ++str1, cm_get_local_domain());
910 str1 = strchr(user1, '@');
914 if (same_path(str1, str2))
921 * A blank line is one that consists of only \b, \t or \n.
928 if (ptr == NULL) return B_TRUE;
929 while (ptr && (*ptr == ' ' || *ptr == '\t' || *ptr == '\n'))
938 embedded_blank(char *buf)
942 if (ptr == NULL) return B_TRUE;
943 while (ptr && *ptr) {
944 if ((*ptr == ' ') || (*ptr == '\t'))
953 get_data_version(CSA_session_handle session) {
956 CSA_attribute_reference names[1];
957 CSA_uint32 number_attrs_returned;
958 CSA_attribute *attrs_returned;
960 names[0] = CSA_X_DT_CAL_ATTR_DATA_VERSION;
963 if (csa_read_calendar_attributes(session,
966 &number_attrs_returned,
968 NULL) == CSA_SUCCESS) {
969 ver = attrs_returned[0].value->item.uint32_value;
970 csa_free(attrs_returned);
977 get_server_version(CSA_session_handle session) {
980 CSA_attribute_reference names[1];
981 CSA_uint32 number_attrs_returned;
982 CSA_attribute *attrs_returned;
984 names[0] = CSA_X_DT_CAL_ATTR_SERVER_VERSION;
986 if (csa_read_calendar_attributes(session,
989 &number_attrs_returned,
991 NULL) == CSA_SUCCESS) {
992 ver = attrs_returned[0].value->item.uint32_value;
993 csa_free(attrs_returned);
1000 privacy_set(Dtcm_appointment *appt) {
1002 CSA_sint32 privacy = CSA_CLASS_PUBLIC;
1010 if (!appt->private->value)
1013 privacy = appt->private->value->item.sint32_value;
1019 showtime_set(Dtcm_appointment *appt) {
1021 CSA_sint32 showtime = 0;
1026 if (!appt->show_time)
1029 if (!appt->show_time->value)
1032 showtime = appt->show_time->value->item.sint32_value;
1038 ** Parse the date string and get the month, day, and year
1041 parse_date(OrderingType order, SeparatorType sep, char *datestr, char *m,
1044 char *first, *second, *third;
1045 char *tmp_date, *str = separator_str(sep);
1046 _Xstrtokparams strtok_buf;
1052 if (datestr == NULL)
1055 tmp_date = cm_strdup(datestr);
1056 first = _XStrtok(tmp_date, str, strtok_buf);
1058 ** Check to see if the date entered has legit separator
1060 if ( strcoll(first, datestr) == 0 ) {
1064 second = _XStrtok(NULL, str, strtok_buf);
1065 third = _XStrtok(NULL, str, strtok_buf);
1070 cm_strcpy(m, second);
1072 cm_strcpy(d, first);
1074 cm_strcpy(y, third);
1078 cm_strcpy(m, second);
1080 cm_strcpy(d, third);
1082 cm_strcpy(y, first);
1087 cm_strcpy(m, first);
1089 cm_strcpy(d, second);
1091 cm_strcpy(y, third);
1099 ** Reformat the date string into m/d/y format and write it into the buffer
1102 datestr2mdy(char *datestr, OrderingType order, SeparatorType sep, char *buf) {
1103 char m[3], d[3], y[5];
1106 if (datestr == NULL)
1109 if (order == ORDER_MDY && sep == SEPARATOR_SLASH)
1110 cm_strcpy(buf, datestr);
1112 if ( parse_date(order, sep, datestr, m, d, y) ) {
1113 sprintf(buf, "%s/%s/%s", m, d, y);
1123 ** Format the date according to display property and write it into buffer
1126 format_tick(Tick tick, OrderingType order, SeparatorType sep, char *buff) {
1127 char *str = separator_str(sep);
1129 _Xltimeparams localtime_buf;
1132 tm = _XLocaltime(&tick, localtime_buf);
1136 sprintf(buff, "%d%s%d%s%d", tm->tm_mday, str,
1137 tm->tm_mon+1, str, tm->tm_year+1900);
1140 sprintf(buff, "%d%s%d%s%d", tm->tm_year+1900, str,
1141 tm->tm_mon+1, str, tm->tm_mday);
1145 sprintf(buff, "%d%s%d%s%d", tm->tm_mon+1, str,
1146 tm->tm_mday, str, tm->tm_year+1900);
1152 format_time(Tick t, DisplayType dt, char *buffer) {
1159 } else if (dt == HOUR12) {
1160 am = adjust_hour(&hr);
1161 sprintf(buffer, "%2d:%02d%s",
1162 hr, minute(t), (am) ? "am" : "pm");
1164 sprintf(buffer, "%02d%02d", hr, minute(t));
1168 * The V5 back end uses arrays to pass attributes back and forth. However,
1169 * keeping hard coded references into those arrays (i.e. declaring the tick
1170 * value will always be into position 0 of the array, the what value in
1171 * position 3, etc.) is a bad idea and hard to maintain.
1173 * Thus these convenience functions will translate from an attribute array
1174 * received from the back end into defined structure which the front end can
1177 * IF YOU UPDATE THE STRUCTURES, MAKE SURE YOU UPDATE THESE COUNT CONSTANTS!!
1179 static const int APPT_ATTR_COUNT = 35;
1180 static const int RW_APPT_ATTR_COUNT = 15;
1181 static const int CAL_ATTR_COUNT = 12;
1182 static const int RW_CAL_ATTR_COUNT = 2;
1183 static const int DEF_V5_APPT_ATTR_COUNT = 22;
1184 static const int DEF_V4_APPT_ATTR_COUNT = 20;
1185 static const int DEF_V3_APPT_ATTR_COUNT = 17;
1186 static const int DEF_CAL_ATTR_COUNT = 6;
1187 static const int default_appt_attrs[] = {CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I,
1188 CSA_ENTRY_ATTR_LAST_UPDATE_I,
1189 CSA_ENTRY_ATTR_ORGANIZER_I,
1190 CSA_ENTRY_ATTR_START_DATE_I,
1191 CSA_ENTRY_ATTR_TYPE_I,
1192 CSA_ENTRY_ATTR_SUBTYPE_I,
1193 CSA_ENTRY_ATTR_CLASSIFICATION_I,
1194 CSA_ENTRY_ATTR_END_DATE_I,
1195 CSA_X_DT_ENTRY_ATTR_SHOWTIME_I,
1196 CSA_ENTRY_ATTR_SUMMARY_I,
1197 CSA_ENTRY_ATTR_STATUS_I,
1198 CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I,
1199 CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I,
1200 CSA_ENTRY_ATTR_AUDIO_REMINDER_I,
1201 CSA_ENTRY_ATTR_FLASHING_REMINDER_I,
1202 CSA_ENTRY_ATTR_MAIL_REMINDER_I,
1203 CSA_ENTRY_ATTR_POPUP_REMINDER_I,
1204 CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I,
1205 CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I,
1206 CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I,
1207 CSA_ENTRY_ATTR_RECURRENCE_RULE_I,
1208 CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I
1210 static const int default_cal_attrs[] = {CSA_CAL_ATTR_ACCESS_LIST_I,
1211 CSA_CAL_ATTR_CALENDAR_NAME_I,
1212 CSA_CAL_ATTR_CALENDAR_SIZE_I,
1213 CSA_CAL_ATTR_NUMBER_ENTRIES_I,
1214 CSA_CAL_ATTR_TIME_ZONE_I,
1215 CSA_X_DT_CAL_ATTR_DATA_VERSION_I
1219 * NOTE that this loop is dependent on the first appointment attribute define
1220 * (DT_CM_ATTR_IDENTIFER_I) in the api - if that is changed and is no longer
1221 * the first appointment define, this needs to be changed.
1223 * NOTE that this function checks if the api indexes specified are read-only:
1224 * This assumes that if you need value space (and have set the need_value_space
1225 * flag to B_TRUE), you're setting attributes and since you can't set read-only
1226 * attributes, it will ignore read-only attributes if the need_value_space flag
1229 Dtcm_appointment *allocate_appt_struct (Allocation_reason reason, int version, ...) {
1230 int idx = 0, api_idx;
1232 CmDataList *api_ids = CmDataListCreate();
1233 Dtcm_appointment *appt;
1237 * The Dtcm_appointment wrapper array
1239 idx = sizeof(Dtcm_appointment);
1240 appt = (Dtcm_appointment *)ckalloc(idx);
1241 memset(appt, 0, idx);
1242 appt->reason = reason;
1243 appt->version = version;
1246 * Step through the variable argument list and build the list of
1247 * attributes we're looking for
1249 va_start(pvar, version);
1250 api_idx = va_arg(pvar, int);
1252 if ((reason == appt_read) || !entry_ident_index_ro(api_idx, version))
1253 CmDataListAdd(api_ids, (void *) (intptr_t) api_idx, 0);
1254 api_idx = va_arg(pvar, int);
1259 * No attributes specified, assume the caller wanted all of them
1261 if (api_ids->count <= 0) {
1263 if ((version == DATAVER2) || (version == DATAVER1))
1264 def_attr_count = DEF_V3_APPT_ATTR_COUNT;
1265 else if (version == DATAVER3)
1266 def_attr_count = DEF_V4_APPT_ATTR_COUNT;
1267 else if (version == DATAVER4)
1268 def_attr_count = DEF_V5_APPT_ATTR_COUNT;
1269 else if (version == DATAVER_ARCHIVE)
1270 def_attr_count = DEF_V5_APPT_ATTR_COUNT;
1272 for (idx = 0; idx < def_attr_count; idx++) {
1273 if ((reason == appt_write) && entry_ident_index_ro(default_appt_attrs[idx], version))
1275 CmDataListAdd(api_ids, (void *) (intptr_t) default_appt_attrs[idx], 0);
1280 * We've determined the number of attributes we're retrieving, so
1281 * allocate the name array, and the attribute array (if we are
1282 * going to be writing attributes).
1285 appt->num_names = api_ids->count;
1286 idx = sizeof(CSA_attribute_reference *) * appt->num_names;
1287 appt->names = (CSA_attribute_reference *)ckalloc(idx);
1288 memset(appt->names, 0, idx);
1290 appt->count = api_ids->count;
1291 if (reason == appt_write) {
1292 idx = sizeof(CSA_attribute) * appt->count;
1293 appt->attrs = (CSA_attribute *)ckalloc(idx);
1294 memset(appt->attrs, 0, idx);
1298 * Now loop through and set the names and initialize the attributes
1300 for (idx = 0; idx < appt->count; idx++) {
1301 api_idx = (int) (intptr_t) CmDataListGetData(api_ids, idx + 1);
1302 appt->names[idx] = strdup(_CSA_entry_attribute_names[api_idx]);
1303 if (reason == appt_write)
1304 initialize_entry_attr(api_idx, &appt->attrs[idx], reason, version);
1307 if (reason == appt_write)
1308 set_appt_links(appt);
1310 CmDataListDestroy(api_ids, 0);
1315 query_appt_struct(CSA_session_handle session,
1316 CSA_entry_handle entry_handle,
1317 Dtcm_appointment *appt) {
1319 CSA_return_code status;
1321 /* if there is old query material laying around, toss it */
1324 csa_free(appt->attrs);
1325 appt->filled = False;
1329 if ((status = csa_read_entry_attributes(session,
1335 NULL)) == CSA_SUCCESS) {
1336 set_appt_links(appt);
1337 appt->filled = True;
1345 * NOTE that this function checks if the api indexes specified are read-only:
1346 * This assumes that if you need value space (and have set the need_value_space
1347 * flag to B_TRUE), you're setting attributes and since you can't set read-only
1348 * attributes, it will ignore read-only attributes if the need_value_space flag
1352 allocate_cal_struct(Allocation_reason reason, int version, ...) {
1353 int idx = 0, api_idx;
1355 CmDataList *api_ids = CmDataListCreate();
1359 * The Dtcm_apopintment wrapper array
1361 idx = sizeof(Dtcm_calendar);
1362 cal = (Dtcm_calendar *)ckalloc(idx);
1363 memset(cal, 0, idx);
1364 cal->reason = reason;
1365 cal->version = version;
1368 * Step through the variable argument list and build the list of
1369 * attributes we're looking for
1371 va_start(pvar, version);
1372 api_idx = va_arg(pvar, int);
1374 if ((reason == appt_read) || !cal_ident_index_ro(api_idx, version))
1375 CmDataListAdd(api_ids, (void *) (intptr_t) api_idx, 0);
1376 api_idx = va_arg(pvar, int);
1381 * No attributes specified, assume the caller wanted all of them
1383 if (api_ids->count <= 0) {
1384 for (idx = 0; idx < DEF_CAL_ATTR_COUNT; idx++) {
1385 if ((reason == appt_write) && cal_ident_index_ro(default_cal_attrs[idx], version))
1387 CmDataListAdd(api_ids, (void *) (intptr_t) default_cal_attrs[idx], 0);
1392 * We've determined the number of attributes we're retrieving, so
1393 * allocate the name arrya, and the attribute array (if we are
1394 * going to be writing attributes).
1397 cal->num_names = api_ids->count;
1398 idx = sizeof(CSA_attribute_reference) * cal->num_names;
1399 cal->names = (CSA_attribute_reference *)ckalloc(idx);
1400 memset(cal->names, 0, idx);
1402 cal->count = api_ids->count;
1403 if (reason == appt_write) {
1404 idx = sizeof(CSA_attribute) * cal->count;
1405 cal->attrs = (CSA_attribute *)ckalloc(idx);
1406 memset(cal->attrs, 0, idx);
1410 * Now loop through and set the names and initialize the attributes
1412 for (idx = 0; idx < cal->count; idx++) {
1413 api_idx = (int) (intptr_t) CmDataListGetData(api_ids, idx + 1);
1414 cal->names[idx] = strdup(_CSA_calendar_attribute_names[api_idx]);
1415 if (reason == appt_write)
1416 initialize_cal_attr(api_idx, &cal->attrs[idx], reason, version);
1419 if (reason == appt_write)
1422 CmDataListDestroy(api_ids, 0);
1429 query_cal_struct(CSA_session_handle session,
1430 Dtcm_calendar *cal) {
1432 CSA_return_code status;
1434 /* if there is old query material laying around, toss it */
1437 csa_free(cal->attrs);
1438 cal->filled = False;
1441 if ((status = csa_read_calendar_attributes(session,
1446 NULL)) == CSA_SUCCESS) {
1455 scrub_cal_attr_list(Dtcm_calendar *cal) {
1459 for (i = 0; i < cal->count; i++) {
1460 if (cal->attrs[i].value->type == CSA_VALUE_REMINDER) {
1461 if ((cal->attrs[i].value->item.reminder_value->lead_time == NULL) ||
1462 (cal->attrs[i].value->item.reminder_value->lead_time[0] == '\0')) {
1463 free(cal->attrs[i].name);
1464 cal->attrs[i].name = NULL;
1467 else if ((cal->attrs[i].value->type == CSA_VALUE_ACCESS_LIST) && (cal->attrs[i].value->item.access_list_value == NULL)) {
1468 free(cal->attrs[i].name);
1469 cal->attrs[i].name = NULL;
1471 else if ((cal->attrs[i].value->type == CSA_VALUE_STRING) && (cal->attrs[i].value->item.string_value == NULL)) {
1472 free(cal->attrs[i].name);
1473 cal->attrs[i].name = NULL;
1475 else if ((cal->attrs[i].value->type == CSA_VALUE_DATE_TIME) && (cal->attrs[i].value->item.date_time_value == NULL)) {
1476 free(cal->attrs[i].name);
1477 cal->attrs[i].name = NULL;
1483 cal_ident_index_ro(int id, int version) {
1487 case CSA_CAL_ATTR_CALENDAR_NAME_I:
1488 case CSA_CAL_ATTR_CALENDAR_OWNER_I:
1489 case CSA_CAL_ATTR_CALENDAR_SIZE_I:
1490 case CSA_CAL_ATTR_CHARACTER_SET_I:
1491 case CSA_CAL_ATTR_NUMBER_ENTRIES_I:
1492 case CSA_CAL_ATTR_DATE_CREATED_I:
1493 case CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I:
1494 case CSA_X_DT_CAL_ATTR_DATA_VERSION_I:
1495 case CSA_CAL_ATTR_TIME_ZONE_I:
1507 entry_ident_index_ro(int id, int version) {
1511 case CSA_ENTRY_ATTR_DATE_CREATED_I:
1512 case CSA_ENTRY_ATTR_LAST_UPDATE_I:
1513 case CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I:
1514 case CSA_ENTRY_ATTR_ORGANIZER_I:
1515 case CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I:
1516 case CSA_ENTRY_ATTR_SEQUENCE_NUMBER_I:
1519 case CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I:
1520 case CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I:
1521 case CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I:
1522 case CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I:
1523 case CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I:
1524 if (version >= DATAVER4)
1538 cal_ident_index_tag(int id) {
1542 case CSA_CAL_ATTR_CALENDAR_NAME_I:
1543 case CSA_CAL_ATTR_CHARACTER_SET_I:
1544 case CSA_CAL_ATTR_COUNTRY_I:
1545 case CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I:
1546 case CSA_CAL_ATTR_TIME_ZONE_I:
1547 case CSA_CAL_ATTR_LANGUAGE_I:
1548 r_tag = CSA_VALUE_STRING;
1550 case CSA_CAL_ATTR_CALENDAR_OWNER_I:
1551 r_tag = CSA_VALUE_CALENDAR_USER;
1553 case CSA_CAL_ATTR_DATE_CREATED_I:
1554 r_tag = CSA_VALUE_DATE_TIME;
1556 case CSA_CAL_ATTR_CALENDAR_SIZE_I:
1557 case CSA_CAL_ATTR_NUMBER_ENTRIES_I:
1558 case CSA_X_DT_CAL_ATTR_DATA_VERSION_I:
1559 r_tag = CSA_VALUE_UINT32;
1561 case CSA_CAL_ATTR_ACCESS_LIST_I:
1562 r_tag = CSA_VALUE_ACCESS_LIST;
1564 case CSA_CAL_ATTR_WORK_SCHEDULE_I:
1566 r_tag = CSA_VALUE_OPAQUE_DATA;
1574 entry_ident_index_tag(int id) {
1578 case CSA_ENTRY_ATTR_DESCRIPTION_I:
1579 case CSA_ENTRY_ATTR_EXCEPTION_RULE_I:
1580 case CSA_ENTRY_ATTR_RECURRENCE_RULE_I:
1581 case CSA_ENTRY_ATTR_SUBTYPE_I:
1582 case CSA_ENTRY_ATTR_SUMMARY_I:
1583 r_tag = CSA_VALUE_STRING;
1585 case CSA_ENTRY_ATTR_DATE_COMPLETED_I:
1586 case CSA_ENTRY_ATTR_DATE_CREATED_I:
1587 case CSA_ENTRY_ATTR_DUE_DATE_I:
1588 case CSA_ENTRY_ATTR_END_DATE_I:
1589 case CSA_ENTRY_ATTR_LAST_UPDATE_I:
1590 case CSA_ENTRY_ATTR_START_DATE_I:
1591 case CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I:
1592 r_tag = CSA_VALUE_DATE_TIME;
1594 case CSA_ENTRY_ATTR_EXCEPTION_DATES_I:
1595 case CSA_ENTRY_ATTR_RECURRING_DATES_I:
1596 r_tag = CSA_VALUE_DATE_TIME_LIST;
1598 case CSA_ENTRY_ATTR_CLASSIFICATION_I:
1599 case CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I:
1600 case CSA_ENTRY_ATTR_PRIORITY_I:
1601 case CSA_ENTRY_ATTR_SEQUENCE_NUMBER_I:
1602 case CSA_ENTRY_ATTR_STATUS_I:
1603 case CSA_ENTRY_ATTR_TYPE_I:
1604 case CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I:
1605 case CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I:
1606 r_tag = CSA_VALUE_UINT32;
1608 case CSA_ENTRY_ATTR_TIME_TRANSPARENCY_I:
1609 case CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I:
1610 case CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I:
1611 case CSA_X_DT_ENTRY_ATTR_SHOWTIME_I:
1612 r_tag = CSA_VALUE_SINT32;
1614 case CSA_ENTRY_ATTR_AUDIO_REMINDER_I:
1615 case CSA_ENTRY_ATTR_FLASHING_REMINDER_I:
1616 case CSA_ENTRY_ATTR_MAIL_REMINDER_I:
1617 case CSA_ENTRY_ATTR_POPUP_REMINDER_I:
1618 r_tag = CSA_VALUE_REMINDER;
1620 case CSA_ENTRY_ATTR_ORGANIZER_I:
1621 case CSA_ENTRY_ATTR_SPONSOR_I:
1622 r_tag = CSA_VALUE_CALENDAR_USER;
1624 case CSA_ENTRY_ATTR_ATTENDEE_LIST_I:
1625 r_tag = CSA_VALUE_ATTENDEE_LIST;
1627 case CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I:
1629 r_tag = CSA_VALUE_OPAQUE_DATA;
1637 ident_name_ro(char *name, int version) {
1638 boolean_t r_ro = B_FALSE;
1640 if (strcmp(name, CSA_CAL_ATTR_CALENDAR_NAME) == 0 ||
1641 strcmp(name, CSA_CAL_ATTR_CALENDAR_OWNER) == 0 ||
1642 strcmp(name, CSA_CAL_ATTR_CALENDAR_SIZE) == 0 ||
1643 strcmp(name, CSA_CAL_ATTR_DATE_CREATED) == 0 ||
1644 strcmp(name, CSA_CAL_ATTR_PRODUCT_IDENTIFIER) == 0 ||
1645 strcmp(name, CSA_X_DT_CAL_ATTR_DATA_VERSION) == 0 ||
1646 strcmp(name, CSA_ENTRY_ATTR_SEQUENCE_NUMBER) == 0 ||
1647 strcmp(name, CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER) == 0 ||
1648 strcmp(name, CSA_ENTRY_ATTR_ORGANIZER) == 0 ||
1649 strcmp(name, CSA_ENTRY_ATTR_LAST_UPDATE) == 0 ||
1650 strcmp(name, CSA_ENTRY_ATTR_DATE_CREATED) == 0 ||
1651 strcmp(name, CSA_ENTRY_ATTR_NUMBER_RECURRENCES) == 0)
1654 if ((version >= DATAVER4) &&
1655 (strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE) == 0 ||
1656 strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES) == 0 ||
1657 strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL) == 0 ||
1658 strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM) == 0))
1665 initialize_cal_attr(int id, CSA_attribute *attrs, Allocation_reason reason, int version) {
1668 attrs->name = cm_strdup(_CSA_calendar_attribute_names[id]);
1669 if ((reason == appt_write) && !cal_ident_index_ro(id, version)) {
1670 size = sizeof(CSA_attribute_value);
1671 attrs->value = (CSA_attribute_value *)ckalloc(size);
1672 memset(attrs->value, 0, size);
1673 attrs->value->type = cal_ident_index_tag(id);
1674 if (attrs->value->type == CSA_VALUE_REMINDER)
1675 attrs->value->item.reminder_value = (CSA_reminder *) calloc(sizeof(CSA_reminder), 1);
1680 free_attr(CSA_attribute *attr) {
1690 if ((attr->value->type == CSA_VALUE_STRING) && attr->value->item.string_value != NULL)
1691 free(attr->value->item.string_value);
1692 else if ((attr->value->type == CSA_VALUE_DATE_TIME) && attr->value->item.date_time_value != NULL)
1693 free(attr->value->item.date_time_value);
1694 else if ((attr->value->type == CSA_VALUE_REMINDER) && attr->value->item.reminder_value != NULL) {
1695 if (attr->value->item.reminder_value->lead_time)
1696 free(attr->value->item.reminder_value->lead_time);
1697 if (attr->value->item.reminder_value->reminder_data.data)
1698 free(attr->value->item.reminder_value->reminder_data.data);
1700 free(attr->value->item.reminder_value);
1709 initialize_entry_attr(int id, CSA_attribute *attrs, Allocation_reason reason, int version) {
1712 attrs->name = cm_strdup(_CSA_entry_attribute_names[id]);
1713 if ((reason == appt_write) && !entry_ident_index_ro(id, version)) {
1714 size = sizeof(CSA_attribute_value);
1715 attrs->value = (CSA_attribute_value *)ckalloc(size);
1716 memset(attrs->value, 0, size);
1717 attrs->value->type = entry_ident_index_tag(id);
1718 if (attrs->value->type == CSA_VALUE_REMINDER)
1719 attrs->value->item.reminder_value = (CSA_reminder *) calloc(sizeof(CSA_reminder), 1);
1724 free_appt_struct(Dtcm_appointment **appt) {
1730 if ((*appt)->names) {
1731 for (i = 0; i < (*appt)->num_names; i++)
1732 if ((*appt)->names[i])
1733 free((*appt)->names[i]);
1735 free((*appt)->names);
1738 /* potential memory leak here. We must be careful, as results
1739 from querys should be thrown away with csa_free(), while
1740 structures we've set up to do update/write operations were
1741 allocated by the client, and need to be freed by that client. */
1743 if (((*appt)->reason == appt_read) && ((*appt)->filled == True))
1744 csa_free((*appt)->attrs);
1746 if ((*appt)->attrs) {
1747 for (i = 0; i < (*appt)->count; i++)
1748 free_attr(&((*appt)->attrs[i]));
1750 free((*appt)->attrs);
1758 free_cal_struct(Dtcm_calendar **cal) {
1764 if ((*cal)->names) {
1765 for (i = 0; i < (*cal)->num_names; i++)
1766 if ((*cal)->names[i])
1767 free((*cal)->names[i]);
1769 free((*cal)->names);
1772 /* potential memory leak here. We must be careful, as results
1773 from querys should be thrown away with csa_free(), while
1774 structures we've set up to do update/write operations were
1775 allocated by the client, and need to be freed by that client. */
1777 if (((*cal)->reason == appt_read) && ((*cal)->filled == True))
1778 csa_free((*cal)->attrs);
1780 if ((*cal)->attrs) {
1781 for (i = 0; i < (*cal)->count; i++)
1782 free_attr(&((*cal)->attrs[i]));
1783 free((*cal)->attrs);
1791 set_appt_links(Dtcm_appointment *appt) {
1795 appt->identifier = NULL;
1796 appt->modified_time = NULL;
1797 appt->author = NULL;
1798 appt->number_recurrence = NULL;
1801 appt->subtype = NULL;
1802 appt->private = NULL;
1803 appt->end_time = NULL;
1804 appt->show_time = NULL;
1807 appt->repeat_type = NULL;
1808 appt->repeat_times = NULL;
1809 appt->repeat_interval = NULL;
1810 appt->repeat_week_num = NULL;
1811 appt->recurrence_rule = NULL;
1816 appt->sequence_end_date = NULL;
1818 for (idx = 0; idx < appt->count; idx++) {
1819 idx_name = appt->attrs[idx].name;
1822 else if (strcmp(idx_name, CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER) == 0)
1823 appt->identifier = &appt->attrs[idx];
1824 else if (strcmp(idx_name, CSA_ENTRY_ATTR_LAST_UPDATE) == 0)
1825 appt->modified_time = &appt->attrs[idx];
1826 else if (strcmp(idx_name, CSA_ENTRY_ATTR_ORGANIZER) == 0)
1827 appt->author = &appt->attrs[idx];
1828 else if (strcmp(idx_name, CSA_ENTRY_ATTR_NUMBER_RECURRENCES) == 0)
1829 appt->number_recurrence = &appt->attrs[idx];
1830 else if (strcmp(idx_name, CSA_ENTRY_ATTR_START_DATE) == 0)
1831 appt->time = &appt->attrs[idx];
1832 else if (strcmp(idx_name, CSA_ENTRY_ATTR_TYPE) == 0)
1833 appt->type = &appt->attrs[idx];
1834 else if (strcmp(idx_name, CSA_ENTRY_ATTR_SUBTYPE) == 0)
1835 appt->subtype = &appt->attrs[idx];
1836 else if (strcmp(idx_name, CSA_ENTRY_ATTR_CLASSIFICATION) == 0)
1837 appt->private = &appt->attrs[idx];
1838 else if (strcmp(idx_name, CSA_ENTRY_ATTR_END_DATE) == 0)
1839 appt->end_time = &appt->attrs[idx];
1840 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_SHOWTIME) == 0)
1841 appt->show_time = &appt->attrs[idx];
1842 else if (strcmp(idx_name, CSA_ENTRY_ATTR_SUMMARY) == 0)
1843 appt->what = &appt->attrs[idx];
1844 else if (strcmp(idx_name, CSA_ENTRY_ATTR_STATUS) == 0)
1845 appt->state = &appt->attrs[idx];
1846 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE) == 0)
1847 appt->repeat_type = &appt->attrs[idx];
1848 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES) == 0)
1849 appt->repeat_times = &appt->attrs[idx];
1850 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL) == 0)
1851 appt->repeat_interval = &appt->attrs[idx];
1852 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM) == 0)
1853 appt->repeat_week_num = &appt->attrs[idx];
1854 else if (strcmp(idx_name, CSA_ENTRY_ATTR_RECURRENCE_RULE) == 0)
1855 appt->recurrence_rule = &appt->attrs[idx];
1856 else if (strcmp(idx_name, CSA_ENTRY_ATTR_AUDIO_REMINDER) == 0)
1857 appt->beep = &appt->attrs[idx];
1858 else if (strcmp(idx_name, CSA_ENTRY_ATTR_FLASHING_REMINDER) == 0)
1859 appt->flash = &appt->attrs[idx];
1860 else if (strcmp(idx_name, CSA_ENTRY_ATTR_MAIL_REMINDER) == 0)
1861 appt->mail = &appt->attrs[idx];
1862 else if (strcmp(idx_name, CSA_ENTRY_ATTR_POPUP_REMINDER) == 0)
1863 appt->popup = &appt->attrs[idx];
1864 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE) == 0)
1865 appt->sequence_end_date = &appt->attrs[idx];
1870 set_cal_links(Dtcm_calendar *cal) {
1874 for (idx = 0; idx < cal->count; idx++) {
1875 idx_name = cal->attrs[idx].name;
1876 if (strcmp(idx_name, CSA_CAL_ATTR_CALENDAR_NAME) == 0)
1877 cal->cal_name = &cal->attrs[idx];
1878 else if (strcmp(idx_name, CSA_X_DT_CAL_ATTR_DATA_VERSION) == 0)
1879 cal->server_version = &cal->attrs[idx];
1880 else if (strcmp(idx_name, CSA_CAL_ATTR_NUMBER_ENTRIES) == 0)
1881 cal->num_entries = &cal->attrs[idx];
1882 else if (strcmp(idx_name, CSA_CAL_ATTR_CALENDAR_SIZE) == 0)
1883 cal->cal_size = &cal->attrs[idx];
1884 else if (strcmp(idx_name, CSA_CAL_ATTR_ACCESS_LIST) == 0)
1885 cal->access_list = &cal->attrs[idx];
1886 else if (strcmp(idx_name, CSA_CAL_ATTR_TIME_ZONE) == 0)
1887 cal->time_zone = &cal->attrs[idx];
1892 setup_range(CSA_attribute **attrs, CSA_enum **ops, int *count, time_t start,
1893 time_t stop, CSA_sint32 type, CSA_sint32 state, boolean_t use_state,
1897 CSA_attribute *attr_ptr;
1905 a_size = sizeof(CSA_attribute) * (*count);
1906 attr_ptr = (CSA_attribute *)ckalloc(a_size);
1907 memset(attr_ptr, 0, a_size);
1909 o_size = sizeof(CSA_enum) * (*count);
1910 op_ptr = (CSA_enum *)ckalloc(o_size);
1911 memset(op_ptr, 0, o_size);
1913 initialize_entry_attr(CSA_ENTRY_ATTR_START_DATE_I, &attr_ptr[0], appt_write, version);
1914 attr_ptr[0].value->item.string_value = malloc(BUFSIZ);
1915 _csa_tick_to_iso8601(start, attr_ptr[0].value->item.string_value);
1917 op_ptr[0] = CSA_MATCH_GREATER_THAN_OR_EQUAL_TO;
1919 initialize_entry_attr(CSA_ENTRY_ATTR_START_DATE_I, &attr_ptr[1], appt_write, version);
1920 attr_ptr[1].value->item.string_value = malloc(BUFSIZ);
1921 _csa_tick_to_iso8601(stop, attr_ptr[1].value->item.string_value);
1922 op_ptr[1] = CSA_MATCH_LESS_THAN_OR_EQUAL_TO;
1924 initialize_entry_attr(CSA_ENTRY_ATTR_TYPE_I, &attr_ptr[2], appt_write, version);
1925 attr_ptr[2].value->item.sint32_value = type;
1926 op_ptr[2] = CSA_MATCH_EQUAL_TO;
1929 initialize_entry_attr(CSA_ENTRY_ATTR_STATUS_I, &attr_ptr[3], appt_write, version);
1930 attr_ptr[3].value->item.sint32_value = state;
1931 op_ptr[3] = CSA_MATCH_EQUAL_TO;
1939 free_range(CSA_attribute **attrs, CSA_enum **ops, int count) {
1942 for (i = 0; i < count; i++) {
1943 free((*attrs)[i].name);
1944 if (((*attrs)[i].value->type == CSA_VALUE_STRING) ||
1945 ((*attrs)[i].value->type == CSA_VALUE_DATE_TIME))
1946 if ((*attrs)[i].value->item.string_value)
1947 free((*attrs)[i].value->item.string_value);
1949 free((*attrs)[i].value);
1952 /* This memory was allocated by the client, and must be freed
1964 * In Motif you can't associate user data with items in a list. To get around
1965 * this we have the following simple functions (CmDataList*) that maintain
1966 * a list of user data. We follow the intrinscs coding style to re-inforce
1967 * the relationship these routines have to the XmList* functions.
1971 * Create a list to store user data
1974 CmDataListCreate(void)
1977 return (CmDataList *)calloc(1, sizeof(CmDataList));
1984 CmDataListDestroy(CmDataList *list, int free_data)
1987 CmDataListDeleteAll(list, free_data);
1992 * Create node to hold data in list.
1995 CmDataItemCreate(void)
1998 return (CmDataItem *)calloc(1, sizeof(CmDataItem));
2002 * Add user data to list at specified position. Note that this
2003 * routine must be called for every item added to a list.
2004 * If the item has no user data, just pass NULL.
2006 * list List to add data to
2007 * data User data. NULL for no data.
2008 * position Where to insert data, starting with 1 for the
2009 * first item. 0 to append to end of list.
2013 * -1 Invalid position
2016 CmDataListAdd(CmDataList *list, void *data, int position)
2019 CmDataItem *item, *p;
2022 /* Create new node to hold data */
2023 item = CmDataItemCreate();
2026 /* Insert node into list at appropriate spot */
2027 if (list->head == NULL) {
2029 } else if (position == 0) {
2030 /* Special case. 0 means append to end */
2031 list->tail->next = item;
2032 } else if (position == 1) {
2033 item->next = list->head;
2036 for (n = 2, p = list->head; p != NULL && n < position;
2044 item->next = p->next;
2048 /* If new item is at the end of the list, update tail */
2049 if (item->next == NULL) {
2059 * Delete user data from a position in the list. If free_data is
2060 * True then this routine will call free(3C) on the user data, otherwise
2061 * the user data is returned so that the caller can dispose of it.
2062 * This routine should be called anytime you delete an item from a
2065 * list List to delete data from
2066 * position Location of item to delete. 0 for last item
2067 * free_data True if you want this routine to call free()
2068 * on the data for you. Otherwise this routine
2069 * will return the address of the data.
2072 * NULL No data found for item at the specified position
2073 * 1 Success (free_data was True)
2074 * other Address of data for item at the specified position.
2075 * (free_data was False)
2078 CmDataListDeletePos(CmDataList *list, int position, int free_data)
2082 CmDataItem *p, *item;
2085 /* Special case. 0 means delete last item */
2086 if (position == 0) {
2087 position = list->count;
2090 if (list->head == NULL) {
2092 } else if (position == 1) {
2094 list->head = item->next;
2095 if (list->tail == item) {
2096 list->tail = item->next;
2099 for (n = 2, p = list->head; p->next != NULL && n < position;
2103 if (p->next == NULL) {
2108 p->next = item->next;
2109 if (list->tail == item) {
2129 * Delete all nodes in the list.
2131 * list List to delete nodes from
2132 * free_data True if you want this routine to call free()
2133 * on the data for you.
2136 CmDataListDeleteAll(CmDataList *list, int free_data)
2139 CmDataItem *p, *tmp;
2143 if (free_data && p->data != NULL) {
2160 * Get data for the item at a particular position in a list.
2163 CmDataListGetData(CmDataList *list, int position)
2167 CmDataItem *p, *item;
2170 if (list->head == NULL) {
2172 } else if (position == 0) {
2173 data = list->tail->data;
2175 for (n = 1, p = list->head; p != NULL && n < position;
2189 * For dumping contents of list
2192 CmDataListDump(CmDataList *list)
2198 printf("***** %d items:\n", list->count);
2200 for (p = list->head, n = 1; p != NULL; p = p->next, n++) {
2201 printf("%3d: %s\n", n, p->data ? (char *)p->data : "<nil>");