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 /*******************************************************************************
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>
60 #include <sys/utsname.h> /* SYS_NMLN */
61 #if defined(sun) || defined(USL) || defined(__uxp__)
62 #include <sys/systeminfo.h>
65 #endif /* sun || USL || __uxp__ */
66 #include <sys/param.h>
68 #if (defined(USL) || defined(__uxp__)) && !defined(DOM_NM_LN)
69 #define DOM_NM_LN BUFSIZ
72 #define X_INCLUDE_STRING_H
73 #define X_INCLUDE_TIME_H
74 #define XOS_USE_NO_LOCKING
75 #include <X11/Xos_r.h>
85 extern int _csa_tick_to_iso8601(time_t, char *);
86 extern int _csa_iso8601_to_tick(char *, time_t*);
88 extern FILE *popen(const char *, const char *);
89 extern int pclose(FILE *);
93 * Function: cm_def_printer
95 * Purpose: get the default printer name for SVR4
99 * Returns: char* (printer name)
108 char *printer_name=NULL;
111 tmp = (char*)getenv("LPDEST");
112 if (tmp != NULL && *tmp != NULL) {
113 printer_name = (char*)malloc(strlen(tmp)+1);
114 strcpy(printer_name, tmp);
118 /* This is really nasty. lpstat -d does *not* work on the AIX
119 machines. Just fall back to "lp" here */
122 _Xstrtokparams strtok_buf;
124 fp = (FILE *)popen("lpstat -d", "r");
125 fread(message, 256, 1, fp);
126 tmp = (char *)_XStrtok(message, ":", strtok_buf);
127 tmp = (char *)_XStrtok((char *)NULL, "\n", strtok_buf);
128 if (tmp != NULL && *tmp != NULL) {
129 printer_name = (char*)malloc(strlen(tmp)+1);
130 strcpy(printer_name, tmp);
133 printer_name = (char*)malloc(3);
134 strcpy(printer_name, "lp");
137 /* close the process connection */
140 printer_name = (char*)malloc(3);
141 strcpy(printer_name, "lp");
145 tmp = (char*)getenv("PRINTER");
146 if (tmp != NULL && *tmp != NULL) {
147 printer_name = (char*)malloc(strlen(tmp)+1);
148 strcpy(printer_name, tmp);
151 printer_name = (char*)malloc(3);
152 strcpy(printer_name, "lw");
158 /*--------------------------------------------------------------------------
159 * THE FOLLOWING STRING FUNCTION redefinitions are a HACK !
161 * The cm code should be changed so that
162 * a) the redefined functions use the same headers as in <string.h>
163 * b) no redefinition of these library function is necessary
165 * The cm definitions use different function headers than in <string.h>
166 * Prefixing the functions will get rid of the resulting compiler error.
167 * Now cm functions will use the cm_ string functions, but library functions,
168 * e.g. fprintf, will use strlen etc. which leads to core dumps.
169 * As part of the bootstrapping process, I am including the below redefinitions
170 * of the system functions. This should be fixed later.
172 *--------------------------------------------------------------------------*/
175 cm_strcpy(register char *s1, register char *s2)
177 if (s1==NULL || s2==NULL) return(NULL);
183 cm_strlen(register char *s)
187 if (s==NULL) return NULL;
195 if (s1 == NULL) return NULL;
196 s2 = (char *) strdup(s1);
201 cm_strcat(char *s1, char *s2)
203 if (s1==NULL || s2==NULL) return(s1);
208 /* transform string patterns of \\ into \
209 \n into carriage returns and
218 if (s==NULL) return(NULL);
221 newstr= (char *) ckalloc((unsigned)i + 1);
223 for (j=0; j<i; j++) {
229 else if (s[j+1]=='\\') {
233 else if (s[j+1]=='\"') {
250 /* transform string patterns of \ into \\
251 carriage returns into \n, and
260 if (s==NULL) return(NULL);
263 newstr = (char *) ckalloc((unsigned)((2 * i) + 1));
265 for (j=0; j<i; j++) {
271 else if (s[j]=='\\') {
276 else if (s[j]=='\"') {
292 syserr(msg, a1, a2, a3)
295 /* Taken from Unix World, July 1989, p. 66 */
298 /* save the error number so fprintf doesn't step on it */
301 (void) fprintf(stderr, "cm: ");
302 /* print the actual message itself */
303 (void) fprintf(stderr, msg, a1, a2, a3);
306 /* print the error, if any */
308 if (saveerr < 0 || saveerr > sys_nerr)
309 (void) fprintf(stderr, ":Unknown error %d", saveerr);
311 (void) fprintf(stderr, ":%s", sys_errlist[saveerr]);
315 /* thow a newline on the end */
316 (void) fprintf(stderr, "\n");
318 /* exit with an error */
325 /* Wrapper around standard storage allocation, to localize errors.
326 Taken from Unix World, July 1989, p. 66 */
328 ckalloc(unsigned int size)
332 /* try to get the memory */
333 p = (char *)calloc(1, size);
335 /* if it worked, return the memory directly */
336 if (p != NULL) return(p);
338 /* try allocation again */
339 p = (char *)calloc(1, size);
341 /* see if it worked the second time */
342 if (p != NULL) return(p);
344 /* no recovery available */
345 syserr("ckalloc: cannot allocate %d bytes", size, 0, 0);
346 return((char *)NULL);
354 _Xctimeparams ctime_buf;
356 a = _XCtime(&t, ctime_buf);
357 (void) fprintf (stderr, "%ld %s\n", (long)t, a);
363 if (i1 > i2) return(i2);
364 if (i1 < i2) return(i1);
371 if (i1 > i2) return(i1);
372 if (i1 < i2) return(i2);
377 text_to_lines(char *s, int n)
380 Lines *prev_l = NULL, *l = NULL, *head= NULL;
385 if (s == NULL || n <= 0) return NULL;
387 string = cm_strdup(s);
389 * Here, look for \n, which is (in)famous character in IBM-932.
390 * Therefore, don't use strtok(). It is not i18n'ed.
392 for ( _p = string; *_p != '\0'; _p += clen ) {
393 clen = mblen( _p, MB_CUR_MAX );
398 if ( ( clen == 1 ) && ( *_p == '\n' ) ) {
406 if (line == NULL) break;
407 l = (Lines*)ckalloc(sizeof(Lines));
408 if (head == NULL) head = l;
409 if (prev_l != NULL) prev_l->next = l;
410 l->s = cm_strdup(line);
413 if ( ( *_p == '\0' ) || ( clen == -1 ) )
416 for ( ; *_p != '\0'; _p += clen ) {
417 clen = mblen( _p, MB_CUR_MAX );
422 if ( ( clen == 1 ) && ( *_p == '\n' ) ) {
436 destroy_lines(Lines *l)
441 free(l->s); l->s=NULL;
444 free((char *)p); p=NULL;
449 * Expand any escape characters in passed string
452 expand_esc_chars(char *string) {
456 while (from && *from) {
457 int len = mblen(from, MB_CUR_MAX);
459 if (len <= 0) break; /* invalid char */
460 if (len > 1) { /* move over multibyte char */
490 get_head(char *str, char sep)
492 static char buf[BUFSIZ];
499 while (*str && *str != sep)
505 return(cm_strdup(buf));
510 get_tail(char *str, char sep)
517 while (*str && *str != sep)
520 return(cm_strdup(++str));
529 static char *login = NULL;
533 name = (char*)cm_get_uname();
534 host = (char*)cm_get_local_host();
535 login = (char *) ckalloc (cm_strlen(name) + cm_strlen(host) + 2);
536 sprintf(login, "%s@%s", name, host);
544 static char *local_host;
546 if (local_host == NULL) {
547 #if defined(sun) || defined(USL) || defined(__uxp__)
548 local_host = (char *)ckalloc(MAXHOSTNAMELEN);
549 (void) sysinfo(SI_HOSTNAME, local_host, MAXHOSTNAMELEN);
551 local_host = (char *)ckalloc(MAXHOSTNAMELEN);
552 (void) gethostname(local_host, MAXHOSTNAMELEN);
553 #endif /* sun || USL || __uxp__ */
565 if ((pw = (struct passwd *)getpwuid(geteuid())) == NULL)
566 name = (char *) cm_strdup("nobody");
568 name = (char *) cm_strdup(pw->pw_name);
575 cm_get_local_domain()
577 static char *local_domain;
579 if (local_domain == NULL) {
580 local_domain = ckalloc(BUFSIZ);
581 #if defined(sun) || defined(USL) || defined(__uxp__)
582 sysinfo(SI_SRPC_DOMAIN, local_domain, DOM_NM_LN);
584 (void) getdomainname(local_domain, BUFSIZ);
585 #endif /* sun || USL || __uxp__ */
587 return(local_domain);
590 /* partially qualified target */
592 cm_pqtarget(char *name)
594 char *host, *target=NULL;
596 host = (char*)strchr(name, '@');
598 host = (char*)cm_get_local_host();
599 target = (char *)ckalloc(cm_strlen(name) +
600 cm_strlen(host) + 2);
601 sprintf(target, "%s@%s", name, host);
604 target = (char *) cm_strdup(name);
609 * calendar_name@host[.domain] -> calendar_name
612 cm_target2name(char *target)
614 return(get_head(target, '@'));
618 * calendar_name@host[.domain] -> host[.domain]
621 cm_target2location(char *target)
623 return(get_tail(target, '@'));
627 * calendar_name@host[.domain] -> host
630 cm_target2host(char *target)
632 char *location, *host;
634 location = get_tail(target, '@');
635 if (location != NULL) {
636 host = get_head(location, '.');
643 * calendar_name@host[.domain] -> domain
646 cm_target2domain(char *target)
648 char *location, *domain;
650 location = get_tail(target, '@');
651 if (location != NULL) {
652 domain = get_tail(location, '.');
660 * str consists of components separated by token
661 * get and copy the first component into comp and
662 * strip it out of str, so str would point to the first
663 * token or the null terminator.
666 get_component(char **str, char *comp, char token)
677 while (ptr && *ptr != 0 && *ptr != token)
686 * head and tail points to the first and last character
687 * of a string which consists of components separated by token.
688 * get and copy the last component into comp and
689 * strip it out of the string, so tail would point to the last
690 * token or the head of the string.
693 get_last_component(char *head, char **tail, char *comp, char token)
704 while (cptr != head && *cptr != token)
712 while (ptr != (*tail + 1))
721 match_forward(char *str1, char *str2)
723 char com1[BUFSIZ], com2[BUFSIZ];
725 if (str1 == NULL || str2 == NULL)
729 get_component(&str1, com1, '.');
730 get_component(&str2, com2, '.');
742 if (strcasecmp(com1, com2) != 0)
745 /* take care of case: a.b a. */
746 if (strcmp(str2, ".") == 0
747 && (strcmp(str1, ".") != 0 || *str1 != NULL))
758 } else if (strcmp(str2, ".") == 0 || *str2 == NULL)
766 match_backward(char *str1, char *str2)
770 char com1[BUFSIZ], com2[BUFSIZ];
772 if (str1 == NULL || str2 == NULL)
782 ptr1 = (len1 ? (str1 + len1 - 1) : str1);
783 ptr2 = (len2 ? (str2 + len2 - 1) : str2);
785 if (*ptr1 == '.' && ptr1 != str1)
788 if (*ptr2 == '.' && ptr2 != str2)
792 get_last_component(str1, &ptr1, com1, '.');
793 get_last_component(str2, &ptr2, com2, '.');
805 if (strcasecmp(com1, com2) != 0)
813 return (B_FALSE); /* bad format */
815 return (B_TRUE); /* done */
821 return (B_FALSE); /* bad format */
823 return (B_TRUE); /* done */
828 * Correct format assumed, i.e. str = label1[.label2 ...]
829 * Compare str2 against str1 which should be more fully qualified than str2
832 same_path(char *str1, char *str2)
838 if (str1 == NULL || str2 == NULL)
842 if (*str1 == '.' || *str2 == '.')
843 return (B_FALSE); /* bad format */
845 if (match_forward(str1, str2) == B_TRUE)
848 return (match_backward(str1, str2));
852 * compare user1 and user2
853 * user1 = user@host[.domain]
854 * user2 = any format in (user, user@host[.domain], user@domain)
857 same_user(char *user1, char *user2)
864 if (user1 == NULL || user2 == NULL)
867 /* compare user name */
868 str1 = get_head(user1, '@');
869 str2 = get_head(user2, '@');
871 if (str1 == NULL || str2 == NULL)
874 if (strcmp(str1, str2)) {
882 /* if only user name is specified, don't need to check domain */
883 str2 = strchr(user2, '@');
887 /* first assume user2=user@domain */
888 str1 = strchr(user1, '.');
890 if (same_path(cm_get_local_domain(), ++str2))
893 if (same_path(++str1, ++str2))
897 /* assume user2=user@host[.domain] */
899 str1 = strchr(user1, '@');
900 sprintf(buf, "%s.%s", ++str1, cm_get_local_domain());
903 str1 = strchr(user1, '@');
907 if (same_path(str1, str2))
914 * A blank line is one that consists of only \b, \t or \n.
921 if (ptr == NULL) return B_TRUE;
922 while (ptr && (*ptr == ' ' || *ptr == '\t' || *ptr == '\n'))
931 embedded_blank(char *buf)
935 if (ptr == NULL) return B_TRUE;
936 while (ptr && *ptr) {
937 if ((*ptr == ' ') || (*ptr == '\t'))
946 get_data_version(CSA_session_handle session) {
949 CSA_attribute_reference names[1];
950 CSA_uint32 number_attrs_returned;
951 CSA_attribute *attrs_returned;
953 names[0] = CSA_X_DT_CAL_ATTR_DATA_VERSION;
956 if (csa_read_calendar_attributes(session,
959 &number_attrs_returned,
961 NULL) == CSA_SUCCESS) {
962 ver = attrs_returned[0].value->item.uint32_value;
963 csa_free(attrs_returned);
970 get_server_version(CSA_session_handle session) {
973 CSA_attribute_reference names[1];
974 CSA_uint32 number_attrs_returned;
975 CSA_attribute *attrs_returned;
977 names[0] = CSA_X_DT_CAL_ATTR_SERVER_VERSION;
979 if (csa_read_calendar_attributes(session,
982 &number_attrs_returned,
984 NULL) == CSA_SUCCESS) {
985 ver = attrs_returned[0].value->item.uint32_value;
986 csa_free(attrs_returned);
993 privacy_set(Dtcm_appointment *appt) {
995 CSA_sint32 privacy = CSA_CLASS_PUBLIC;
1003 if (!appt->private->value)
1006 privacy = appt->private->value->item.sint32_value;
1012 showtime_set(Dtcm_appointment *appt) {
1014 CSA_sint32 showtime = 0;
1019 if (!appt->show_time)
1022 if (!appt->show_time->value)
1025 showtime = appt->show_time->value->item.sint32_value;
1031 ** Parse the date string and get the month, day, and year
1034 parse_date(OrderingType order, SeparatorType sep, char *datestr, char *m,
1037 char *first, *second, *third;
1038 char *tmp_date, *str = separator_str(sep);
1039 _Xstrtokparams strtok_buf;
1045 if (datestr == NULL)
1048 tmp_date = cm_strdup(datestr);
1049 first = _XStrtok(tmp_date, str, strtok_buf);
1051 ** Check to see if the date entered has legit separator
1053 if ( strcoll(first, datestr) == 0 ) {
1057 second = _XStrtok(NULL, str, strtok_buf);
1058 third = _XStrtok(NULL, str, strtok_buf);
1063 cm_strcpy(m, second);
1065 cm_strcpy(d, first);
1067 cm_strcpy(y, third);
1071 cm_strcpy(m, second);
1073 cm_strcpy(d, third);
1075 cm_strcpy(y, first);
1080 cm_strcpy(m, first);
1082 cm_strcpy(d, second);
1084 cm_strcpy(y, third);
1092 ** Reformat the date string into m/d/y format and write it into the buffer
1095 datestr2mdy(char *datestr, OrderingType order, SeparatorType sep, char *buf) {
1096 char m[3], d[3], y[5];
1099 if (datestr == NULL)
1102 if (order == ORDER_MDY && sep == SEPARATOR_SLASH)
1103 cm_strcpy(buf, datestr);
1105 if ( parse_date(order, sep, datestr, m, d, y) ) {
1106 sprintf(buf, "%s/%s/%s", m, d, y);
1116 ** Format the date according to display property and write it into buffer
1119 format_tick(Tick tick, OrderingType order, SeparatorType sep, char *buff) {
1120 char *str = separator_str(sep);
1122 _Xltimeparams localtime_buf;
1125 tm = _XLocaltime(&tick, localtime_buf);
1129 sprintf(buff, "%d%s%d%s%d", tm->tm_mday, str,
1130 tm->tm_mon+1, str, tm->tm_year+1900);
1133 sprintf(buff, "%d%s%d%s%d", tm->tm_year+1900, str,
1134 tm->tm_mon+1, str, tm->tm_mday);
1138 sprintf(buff, "%d%s%d%s%d", tm->tm_mon+1, str,
1139 tm->tm_mday, str, tm->tm_year+1900);
1145 format_time(Tick t, DisplayType dt, char *buffer) {
1150 sprintf(buffer, "\0");
1152 } else if (dt == HOUR12) {
1153 am = adjust_hour(&hr);
1154 sprintf(buffer, "%2d:%02d%s",
1155 hr, minute(t), (am) ? "am" : "pm");
1157 sprintf(buffer, "%02d%02d", hr, minute(t));
1161 * The V5 back end uses arrays to pass attributes back and forth. However,
1162 * keeping hard coded references into those arrays (i.e. declaring the tick
1163 * value will always be into position 0 of the array, the what value in
1164 * position 3, etc.) is a bad idea and hard to maintain.
1166 * Thus these convenience functions will translate from an attribute array
1167 * received from the back end into defined structure which the front end can
1170 * IF YOU UPDATE THE STRUCTURES, MAKE SURE YOU UPDATE THESE COUNT CONSTANTS!!
1172 static const int APPT_ATTR_COUNT = 35;
1173 static const int RW_APPT_ATTR_COUNT = 15;
1174 static const int CAL_ATTR_COUNT = 12;
1175 static const int RW_CAL_ATTR_COUNT = 2;
1176 static const int DEF_V5_APPT_ATTR_COUNT = 22;
1177 static const int DEF_V4_APPT_ATTR_COUNT = 20;
1178 static const int DEF_V3_APPT_ATTR_COUNT = 17;
1179 static const int DEF_CAL_ATTR_COUNT = 6;
1180 static const int default_appt_attrs[] = {CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I,
1181 CSA_ENTRY_ATTR_LAST_UPDATE_I,
1182 CSA_ENTRY_ATTR_ORGANIZER_I,
1183 CSA_ENTRY_ATTR_START_DATE_I,
1184 CSA_ENTRY_ATTR_TYPE_I,
1185 CSA_ENTRY_ATTR_SUBTYPE_I,
1186 CSA_ENTRY_ATTR_CLASSIFICATION_I,
1187 CSA_ENTRY_ATTR_END_DATE_I,
1188 CSA_X_DT_ENTRY_ATTR_SHOWTIME_I,
1189 CSA_ENTRY_ATTR_SUMMARY_I,
1190 CSA_ENTRY_ATTR_STATUS_I,
1191 CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I,
1192 CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I,
1193 CSA_ENTRY_ATTR_AUDIO_REMINDER_I,
1194 CSA_ENTRY_ATTR_FLASHING_REMINDER_I,
1195 CSA_ENTRY_ATTR_MAIL_REMINDER_I,
1196 CSA_ENTRY_ATTR_POPUP_REMINDER_I,
1197 CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I,
1198 CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I,
1199 CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I,
1200 CSA_ENTRY_ATTR_RECURRENCE_RULE_I,
1201 CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I
1203 static const int default_cal_attrs[] = {CSA_CAL_ATTR_ACCESS_LIST_I,
1204 CSA_CAL_ATTR_CALENDAR_NAME_I,
1205 CSA_CAL_ATTR_CALENDAR_SIZE_I,
1206 CSA_CAL_ATTR_NUMBER_ENTRIES_I,
1207 CSA_CAL_ATTR_TIME_ZONE_I,
1208 CSA_X_DT_CAL_ATTR_DATA_VERSION_I
1212 * NOTE that this loop is dependent on the first appointment attribute define
1213 * (DT_CM_ATTR_IDENTIFER_I) in the api - if that is changed and is no longer
1214 * the first appointment define, this needs to be changed.
1216 * NOTE that this function checks if the api indexes specified are read-only:
1217 * This assumes that if you need value space (and have set the need_value_space
1218 * flag to B_TRUE), you're setting attributes and since you can't set read-only
1219 * attributes, it will ignore read-only attributes if the need_value_space flag
1222 Dtcm_appointment *allocate_appt_struct (Allocation_reason reason, int version, ...) {
1223 int idx = 0, api_idx;
1225 CmDataList *api_ids = CmDataListCreate();
1226 Dtcm_appointment *appt;
1230 * The Dtcm_appointment wrapper array
1232 idx = sizeof(Dtcm_appointment);
1233 appt = (Dtcm_appointment *)ckalloc(idx);
1234 memset(appt, NULL, idx);
1235 appt->reason = reason;
1236 appt->version = version;
1239 * Step through the variable argument list and build the list of
1240 * attributes we're looking for
1242 va_start(pvar, version);
1243 api_idx = va_arg(pvar, int);
1245 if ((reason == appt_read) || !entry_ident_index_ro(api_idx, version))
1246 CmDataListAdd(api_ids, (void *)api_idx, 0);
1247 api_idx = va_arg(pvar, int);
1252 * No attributes specified, assume the caller wanted all of them
1254 if (api_ids->count <= 0) {
1256 if ((version == DATAVER2) || (version == DATAVER1))
1257 def_attr_count = DEF_V3_APPT_ATTR_COUNT;
1258 else if (version == DATAVER3)
1259 def_attr_count = DEF_V4_APPT_ATTR_COUNT;
1260 else if (version == DATAVER4)
1261 def_attr_count = DEF_V5_APPT_ATTR_COUNT;
1262 else if (version == DATAVER_ARCHIVE)
1263 def_attr_count = DEF_V5_APPT_ATTR_COUNT;
1265 for (idx = 0; idx < def_attr_count; idx++) {
1266 if ((reason == appt_write) && entry_ident_index_ro(default_appt_attrs[idx], version))
1268 CmDataListAdd(api_ids, (void *)default_appt_attrs[idx], 0);
1273 * We've determined the number of attributes we're retrieving, so
1274 * allocate the name array, and the attribute array (if we are
1275 * going to be writing attributes).
1278 appt->num_names = api_ids->count;
1279 idx = sizeof(CSA_attribute_reference *) * appt->num_names;
1280 appt->names = (CSA_attribute_reference *)ckalloc(idx);
1281 memset(appt->names, NULL, idx);
1283 appt->count = api_ids->count;
1284 if (reason == appt_write) {
1285 idx = sizeof(CSA_attribute) * appt->count;
1286 appt->attrs = (CSA_attribute *)ckalloc(idx);
1287 memset(appt->attrs, NULL, idx);
1291 * Now loop through and set the names and initialize the attributes
1293 for (idx = 0; idx < appt->count; idx++) {
1294 api_idx = (int)CmDataListGetData(api_ids, idx + 1);
1295 appt->names[idx] = strdup(_CSA_entry_attribute_names[api_idx]);
1296 if (reason == appt_write)
1297 initialize_entry_attr(api_idx, &appt->attrs[idx], reason, version);
1300 if (reason == appt_write)
1301 set_appt_links(appt);
1303 CmDataListDestroy(api_ids, NULL);
1308 query_appt_struct(CSA_session_handle session,
1309 CSA_entry_handle entry_handle,
1310 Dtcm_appointment *appt) {
1312 CSA_return_code status;
1314 /* if there is old query material laying around, toss it */
1317 csa_free(appt->attrs);
1318 appt->filled = False;
1322 if ((status = csa_read_entry_attributes(session,
1328 NULL)) == CSA_SUCCESS) {
1329 set_appt_links(appt);
1330 appt->filled = True;
1338 * NOTE that this function checks if the api indexes specified are read-only:
1339 * This assumes that if you need value space (and have set the need_value_space
1340 * flag to B_TRUE), you're setting attributes and since you can't set read-only
1341 * attributes, it will ignore read-only attributes if the need_value_space flag
1345 allocate_cal_struct(Allocation_reason reason, int version, ...) {
1346 int idx = 0, api_idx;
1348 CmDataList *api_ids = CmDataListCreate();
1352 * The Dtcm_apopintment wrapper array
1354 idx = sizeof(Dtcm_calendar);
1355 cal = (Dtcm_calendar *)ckalloc(idx);
1356 memset(cal, NULL, idx);
1357 cal->reason = reason;
1358 cal->version = version;
1361 * Step through the variable argument list and build the list of
1362 * attributes we're looking for
1364 va_start(pvar, version);
1365 api_idx = va_arg(pvar, int);
1367 if ((reason == appt_read) || !cal_ident_index_ro(api_idx, version))
1368 CmDataListAdd(api_ids, (void *)api_idx, 0);
1369 api_idx = va_arg(pvar, int);
1374 * No attributes specified, assume the caller wanted all of them
1376 if (api_ids->count <= 0) {
1377 for (idx = 0; idx < DEF_CAL_ATTR_COUNT; idx++) {
1378 if ((reason == appt_write) && cal_ident_index_ro(default_cal_attrs[idx], version))
1380 CmDataListAdd(api_ids, (void *)default_cal_attrs[idx], 0);
1385 * We've determined the number of attributes we're retrieving, so
1386 * allocate the name arrya, and the attribute array (if we are
1387 * going to be writing attributes).
1390 cal->num_names = api_ids->count;
1391 idx = sizeof(CSA_attribute_reference) * cal->num_names;
1392 cal->names = (CSA_attribute_reference *)ckalloc(idx);
1393 memset(cal->names, NULL, idx);
1395 cal->count = api_ids->count;
1396 if (reason == appt_write) {
1397 idx = sizeof(CSA_attribute) * cal->count;
1398 cal->attrs = (CSA_attribute *)ckalloc(idx);
1399 memset(cal->attrs, NULL, idx);
1403 * Now loop through and set the names and initialize the attributes
1405 for (idx = 0; idx < cal->count; idx++) {
1406 api_idx = (int)CmDataListGetData(api_ids, idx + 1);
1407 cal->names[idx] = strdup(_CSA_calendar_attribute_names[api_idx]);
1408 if (reason == appt_write)
1409 initialize_cal_attr(api_idx, &cal->attrs[idx], reason, version);
1412 if (reason == appt_write)
1415 CmDataListDestroy(api_ids, NULL);
1422 query_cal_struct(CSA_session_handle session,
1423 Dtcm_calendar *cal) {
1425 CSA_return_code status;
1427 /* if there is old query material laying around, toss it */
1430 csa_free(cal->attrs);
1431 cal->filled = False;
1434 if ((status = csa_read_calendar_attributes(session,
1439 NULL)) == CSA_SUCCESS) {
1448 scrub_cal_attr_list(Dtcm_calendar *cal) {
1452 for (i = 0; i < cal->count; i++) {
1453 if (cal->attrs[i].value->type == CSA_VALUE_REMINDER) {
1454 if ((cal->attrs[i].value->item.reminder_value->lead_time == NULL) ||
1455 (cal->attrs[i].value->item.reminder_value->lead_time[0] == NULL)) {
1456 free(cal->attrs[i].name);
1457 cal->attrs[i].name = NULL;
1460 else if ((cal->attrs[i].value->type == CSA_VALUE_ACCESS_LIST) && (cal->attrs[i].value->item.access_list_value == NULL)) {
1461 free(cal->attrs[i].name);
1462 cal->attrs[i].name = NULL;
1464 else if ((cal->attrs[i].value->type == CSA_VALUE_STRING) && (cal->attrs[i].value->item.string_value == NULL)) {
1465 free(cal->attrs[i].name);
1466 cal->attrs[i].name = NULL;
1468 else if ((cal->attrs[i].value->type == CSA_VALUE_DATE_TIME) && (cal->attrs[i].value->item.date_time_value == NULL)) {
1469 free(cal->attrs[i].name);
1470 cal->attrs[i].name = NULL;
1476 cal_ident_index_ro(int id, int version) {
1480 case CSA_CAL_ATTR_CALENDAR_NAME_I:
1481 case CSA_CAL_ATTR_CALENDAR_OWNER_I:
1482 case CSA_CAL_ATTR_CALENDAR_SIZE_I:
1483 case CSA_CAL_ATTR_CHARACTER_SET_I:
1484 case CSA_CAL_ATTR_NUMBER_ENTRIES_I:
1485 case CSA_CAL_ATTR_DATE_CREATED_I:
1486 case CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I:
1487 case CSA_X_DT_CAL_ATTR_DATA_VERSION_I:
1488 case CSA_CAL_ATTR_TIME_ZONE_I:
1500 entry_ident_index_ro(int id, int version) {
1504 case CSA_ENTRY_ATTR_DATE_CREATED_I:
1505 case CSA_ENTRY_ATTR_LAST_UPDATE_I:
1506 case CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I:
1507 case CSA_ENTRY_ATTR_ORGANIZER_I:
1508 case CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I:
1509 case CSA_ENTRY_ATTR_SEQUENCE_NUMBER_I:
1512 case CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I:
1513 case CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I:
1514 case CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I:
1515 case CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I:
1516 case CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I:
1517 if (version >= DATAVER4)
1531 cal_ident_index_tag(int id) {
1535 case CSA_CAL_ATTR_CALENDAR_NAME_I:
1536 case CSA_CAL_ATTR_CHARACTER_SET_I:
1537 case CSA_CAL_ATTR_COUNTRY_I:
1538 case CSA_CAL_ATTR_PRODUCT_IDENTIFIER_I:
1539 case CSA_CAL_ATTR_TIME_ZONE_I:
1540 case CSA_CAL_ATTR_LANGUAGE_I:
1541 r_tag = CSA_VALUE_STRING;
1543 case CSA_CAL_ATTR_CALENDAR_OWNER_I:
1544 r_tag = CSA_VALUE_CALENDAR_USER;
1546 case CSA_CAL_ATTR_DATE_CREATED_I:
1547 r_tag = CSA_VALUE_DATE_TIME;
1549 case CSA_CAL_ATTR_CALENDAR_SIZE_I:
1550 case CSA_CAL_ATTR_NUMBER_ENTRIES_I:
1551 case CSA_X_DT_CAL_ATTR_DATA_VERSION_I:
1552 r_tag = CSA_VALUE_UINT32;
1554 case CSA_CAL_ATTR_ACCESS_LIST_I:
1555 r_tag = CSA_VALUE_ACCESS_LIST;
1557 case CSA_CAL_ATTR_WORK_SCHEDULE_I:
1559 r_tag = CSA_VALUE_OPAQUE_DATA;
1567 entry_ident_index_tag(int id) {
1571 case CSA_ENTRY_ATTR_DESCRIPTION_I:
1572 case CSA_ENTRY_ATTR_EXCEPTION_RULE_I:
1573 case CSA_ENTRY_ATTR_RECURRENCE_RULE_I:
1574 case CSA_ENTRY_ATTR_SUBTYPE_I:
1575 case CSA_ENTRY_ATTR_SUMMARY_I:
1576 r_tag = CSA_VALUE_STRING;
1578 case CSA_ENTRY_ATTR_DATE_COMPLETED_I:
1579 case CSA_ENTRY_ATTR_DATE_CREATED_I:
1580 case CSA_ENTRY_ATTR_DUE_DATE_I:
1581 case CSA_ENTRY_ATTR_END_DATE_I:
1582 case CSA_ENTRY_ATTR_LAST_UPDATE_I:
1583 case CSA_ENTRY_ATTR_START_DATE_I:
1584 case CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I:
1585 r_tag = CSA_VALUE_DATE_TIME;
1587 case CSA_ENTRY_ATTR_EXCEPTION_DATES_I:
1588 case CSA_ENTRY_ATTR_RECURRING_DATES_I:
1589 r_tag = CSA_VALUE_DATE_TIME_LIST;
1591 case CSA_ENTRY_ATTR_CLASSIFICATION_I:
1592 case CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I:
1593 case CSA_ENTRY_ATTR_PRIORITY_I:
1594 case CSA_ENTRY_ATTR_SEQUENCE_NUMBER_I:
1595 case CSA_ENTRY_ATTR_STATUS_I:
1596 case CSA_ENTRY_ATTR_TYPE_I:
1597 case CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I:
1598 case CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I:
1599 r_tag = CSA_VALUE_UINT32;
1601 case CSA_ENTRY_ATTR_TIME_TRANSPARENCY_I:
1602 case CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I:
1603 case CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I:
1604 case CSA_X_DT_ENTRY_ATTR_SHOWTIME_I:
1605 r_tag = CSA_VALUE_SINT32;
1607 case CSA_ENTRY_ATTR_AUDIO_REMINDER_I:
1608 case CSA_ENTRY_ATTR_FLASHING_REMINDER_I:
1609 case CSA_ENTRY_ATTR_MAIL_REMINDER_I:
1610 case CSA_ENTRY_ATTR_POPUP_REMINDER_I:
1611 r_tag = CSA_VALUE_REMINDER;
1613 case CSA_ENTRY_ATTR_ORGANIZER_I:
1614 case CSA_ENTRY_ATTR_SPONSOR_I:
1615 r_tag = CSA_VALUE_CALENDAR_USER;
1617 case CSA_ENTRY_ATTR_ATTENDEE_LIST_I:
1618 r_tag = CSA_VALUE_ATTENDEE_LIST;
1620 case CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER_I:
1622 r_tag = CSA_VALUE_OPAQUE_DATA;
1630 ident_name_ro(char *name, int version) {
1631 boolean_t r_ro = B_FALSE;
1633 if (strcmp(name, CSA_CAL_ATTR_CALENDAR_NAME) == 0 ||
1634 strcmp(name, CSA_CAL_ATTR_CALENDAR_OWNER) == 0 ||
1635 strcmp(name, CSA_CAL_ATTR_CALENDAR_SIZE) == 0 ||
1636 strcmp(name, CSA_CAL_ATTR_DATE_CREATED) == 0 ||
1637 strcmp(name, CSA_CAL_ATTR_PRODUCT_IDENTIFIER) == 0 ||
1638 strcmp(name, CSA_X_DT_CAL_ATTR_DATA_VERSION) == 0 ||
1639 strcmp(name, CSA_ENTRY_ATTR_SEQUENCE_NUMBER) == 0 ||
1640 strcmp(name, CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER) == 0 ||
1641 strcmp(name, CSA_ENTRY_ATTR_ORGANIZER) == 0 ||
1642 strcmp(name, CSA_ENTRY_ATTR_LAST_UPDATE) == 0 ||
1643 strcmp(name, CSA_ENTRY_ATTR_DATE_CREATED) == 0 ||
1644 strcmp(name, CSA_ENTRY_ATTR_NUMBER_RECURRENCES) == 0)
1647 if ((version >= DATAVER4) &&
1648 (strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE) == 0 ||
1649 strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES) == 0 ||
1650 strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL) == 0 ||
1651 strcmp(name, CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM) == 0))
1658 initialize_cal_attr(int id, CSA_attribute *attrs, Allocation_reason reason, int version) {
1661 attrs->name = cm_strdup(_CSA_calendar_attribute_names[id]);
1662 if ((reason == appt_write) && !cal_ident_index_ro(id, version)) {
1663 size = sizeof(CSA_attribute_value);
1664 attrs->value = (CSA_attribute_value *)ckalloc(size);
1665 memset(attrs->value, NULL, size);
1666 attrs->value->type = cal_ident_index_tag(id);
1667 if (attrs->value->type == CSA_VALUE_REMINDER)
1668 attrs->value->item.reminder_value = (CSA_reminder *) calloc(sizeof(CSA_reminder), 1);
1673 free_attr(CSA_attribute *attr) {
1683 if ((attr->value->type == CSA_VALUE_STRING) && attr->value->item.string_value != NULL)
1684 free(attr->value->item.string_value);
1685 else if ((attr->value->type == CSA_VALUE_DATE_TIME) && attr->value->item.date_time_value != NULL)
1686 free(attr->value->item.date_time_value);
1687 else if ((attr->value->type == CSA_VALUE_REMINDER) && attr->value->item.reminder_value != NULL) {
1688 if (attr->value->item.reminder_value->lead_time)
1689 free(attr->value->item.reminder_value->lead_time);
1690 if (attr->value->item.reminder_value->reminder_data.data)
1691 free(attr->value->item.reminder_value->reminder_data.data);
1693 free(attr->value->item.reminder_value);
1702 initialize_entry_attr(int id, CSA_attribute *attrs, Allocation_reason reason, int version) {
1705 attrs->name = cm_strdup(_CSA_entry_attribute_names[id]);
1706 if ((reason == appt_write) && !entry_ident_index_ro(id, version)) {
1707 size = sizeof(CSA_attribute_value);
1708 attrs->value = (CSA_attribute_value *)ckalloc(size);
1709 memset(attrs->value, NULL, size);
1710 attrs->value->type = entry_ident_index_tag(id);
1711 if (attrs->value->type == CSA_VALUE_REMINDER)
1712 attrs->value->item.reminder_value = (CSA_reminder *) calloc(sizeof(CSA_reminder), 1);
1717 free_appt_struct(Dtcm_appointment **appt) {
1723 if ((*appt)->names) {
1724 for (i = 0; i < (*appt)->num_names; i++)
1725 if ((*appt)->names[i])
1726 free((*appt)->names[i]);
1728 free((*appt)->names);
1731 /* potential memory leak here. We must be careful, as results
1732 from querys should be thrown away with csa_free(), while
1733 structures we've set up to do update/write operations were
1734 allocated by the client, and need to be freed by that client. */
1736 if (((*appt)->reason == appt_read) && ((*appt)->filled == True))
1737 csa_free((*appt)->attrs);
1739 if ((*appt)->attrs) {
1740 for (i = 0; i < (*appt)->count; i++)
1741 free_attr(&((*appt)->attrs[i]));
1743 free((*appt)->attrs);
1751 free_cal_struct(Dtcm_calendar **cal) {
1757 if ((*cal)->names) {
1758 for (i = 0; i < (*cal)->num_names; i++)
1759 if ((*cal)->names[i])
1760 free((*cal)->names[i]);
1762 free((*cal)->names);
1765 /* potential memory leak here. We must be careful, as results
1766 from querys should be thrown away with csa_free(), while
1767 structures we've set up to do update/write operations were
1768 allocated by the client, and need to be freed by that client. */
1770 if (((*cal)->reason == appt_read) && ((*cal)->filled == True))
1771 csa_free((*cal)->attrs);
1773 if ((*cal)->attrs) {
1774 for (i = 0; i < (*cal)->count; i++)
1775 free_attr(&((*cal)->attrs[i]));
1776 free((*cal)->attrs);
1784 set_appt_links(Dtcm_appointment *appt) {
1788 appt->identifier = NULL;
1789 appt->modified_time = NULL;
1790 appt->author = NULL;
1791 appt->number_recurrence = NULL;
1794 appt->subtype = NULL;
1795 appt->private = NULL;
1796 appt->end_time = NULL;
1797 appt->show_time = NULL;
1800 appt->repeat_type = NULL;
1801 appt->repeat_times = NULL;
1802 appt->repeat_interval = NULL;
1803 appt->repeat_week_num = NULL;
1804 appt->recurrence_rule = NULL;
1809 appt->sequence_end_date = NULL;
1811 for (idx = 0; idx < appt->count; idx++) {
1812 idx_name = appt->attrs[idx].name;
1815 else if (strcmp(idx_name, CSA_ENTRY_ATTR_REFERENCE_IDENTIFIER) == 0)
1816 appt->identifier = &appt->attrs[idx];
1817 else if (strcmp(idx_name, CSA_ENTRY_ATTR_LAST_UPDATE) == 0)
1818 appt->modified_time = &appt->attrs[idx];
1819 else if (strcmp(idx_name, CSA_ENTRY_ATTR_ORGANIZER) == 0)
1820 appt->author = &appt->attrs[idx];
1821 else if (strcmp(idx_name, CSA_ENTRY_ATTR_NUMBER_RECURRENCES) == 0)
1822 appt->number_recurrence = &appt->attrs[idx];
1823 else if (strcmp(idx_name, CSA_ENTRY_ATTR_START_DATE) == 0)
1824 appt->time = &appt->attrs[idx];
1825 else if (strcmp(idx_name, CSA_ENTRY_ATTR_TYPE) == 0)
1826 appt->type = &appt->attrs[idx];
1827 else if (strcmp(idx_name, CSA_ENTRY_ATTR_SUBTYPE) == 0)
1828 appt->subtype = &appt->attrs[idx];
1829 else if (strcmp(idx_name, CSA_ENTRY_ATTR_CLASSIFICATION) == 0)
1830 appt->private = &appt->attrs[idx];
1831 else if (strcmp(idx_name, CSA_ENTRY_ATTR_END_DATE) == 0)
1832 appt->end_time = &appt->attrs[idx];
1833 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_SHOWTIME) == 0)
1834 appt->show_time = &appt->attrs[idx];
1835 else if (strcmp(idx_name, CSA_ENTRY_ATTR_SUMMARY) == 0)
1836 appt->what = &appt->attrs[idx];
1837 else if (strcmp(idx_name, CSA_ENTRY_ATTR_STATUS) == 0)
1838 appt->state = &appt->attrs[idx];
1839 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE) == 0)
1840 appt->repeat_type = &appt->attrs[idx];
1841 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES) == 0)
1842 appt->repeat_times = &appt->attrs[idx];
1843 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL) == 0)
1844 appt->repeat_interval = &appt->attrs[idx];
1845 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM) == 0)
1846 appt->repeat_week_num = &appt->attrs[idx];
1847 else if (strcmp(idx_name, CSA_ENTRY_ATTR_RECURRENCE_RULE) == 0)
1848 appt->recurrence_rule = &appt->attrs[idx];
1849 else if (strcmp(idx_name, CSA_ENTRY_ATTR_AUDIO_REMINDER) == 0)
1850 appt->beep = &appt->attrs[idx];
1851 else if (strcmp(idx_name, CSA_ENTRY_ATTR_FLASHING_REMINDER) == 0)
1852 appt->flash = &appt->attrs[idx];
1853 else if (strcmp(idx_name, CSA_ENTRY_ATTR_MAIL_REMINDER) == 0)
1854 appt->mail = &appt->attrs[idx];
1855 else if (strcmp(idx_name, CSA_ENTRY_ATTR_POPUP_REMINDER) == 0)
1856 appt->popup = &appt->attrs[idx];
1857 else if (strcmp(idx_name, CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE) == 0)
1858 appt->sequence_end_date = &appt->attrs[idx];
1863 set_cal_links(Dtcm_calendar *cal) {
1867 for (idx = 0; idx < cal->count; idx++) {
1868 idx_name = cal->attrs[idx].name;
1869 if (strcmp(idx_name, CSA_CAL_ATTR_CALENDAR_NAME) == 0)
1870 cal->cal_name = &cal->attrs[idx];
1871 else if (strcmp(idx_name, CSA_X_DT_CAL_ATTR_DATA_VERSION) == 0)
1872 cal->server_version = &cal->attrs[idx];
1873 else if (strcmp(idx_name, CSA_CAL_ATTR_NUMBER_ENTRIES) == 0)
1874 cal->num_entries = &cal->attrs[idx];
1875 else if (strcmp(idx_name, CSA_CAL_ATTR_CALENDAR_SIZE) == 0)
1876 cal->cal_size = &cal->attrs[idx];
1877 else if (strcmp(idx_name, CSA_CAL_ATTR_ACCESS_LIST) == 0)
1878 cal->access_list = &cal->attrs[idx];
1879 else if (strcmp(idx_name, CSA_CAL_ATTR_TIME_ZONE) == 0)
1880 cal->time_zone = &cal->attrs[idx];
1885 setup_range(CSA_attribute **attrs, CSA_enum **ops, int *count, time_t start,
1886 time_t stop, CSA_sint32 type, CSA_sint32 state, boolean_t use_state,
1890 CSA_attribute *attr_ptr;
1898 a_size = sizeof(CSA_attribute) * (*count);
1899 attr_ptr = (CSA_attribute *)ckalloc(a_size);
1900 memset(attr_ptr, NULL, a_size);
1902 o_size = sizeof(CSA_enum) * (*count);
1903 op_ptr = (CSA_enum *)ckalloc(o_size);
1904 memset(op_ptr, NULL, o_size);
1906 initialize_entry_attr(CSA_ENTRY_ATTR_START_DATE_I, &attr_ptr[0], appt_write, version);
1907 attr_ptr[0].value->item.string_value = malloc(BUFSIZ);
1908 _csa_tick_to_iso8601(start, attr_ptr[0].value->item.string_value);
1910 op_ptr[0] = CSA_MATCH_GREATER_THAN_OR_EQUAL_TO;
1912 initialize_entry_attr(CSA_ENTRY_ATTR_START_DATE_I, &attr_ptr[1], appt_write, version);
1913 attr_ptr[1].value->item.string_value = malloc(BUFSIZ);
1914 _csa_tick_to_iso8601(stop, attr_ptr[1].value->item.string_value);
1915 op_ptr[1] = CSA_MATCH_LESS_THAN_OR_EQUAL_TO;
1917 initialize_entry_attr(CSA_ENTRY_ATTR_TYPE_I, &attr_ptr[2], appt_write, version);
1918 attr_ptr[2].value->item.sint32_value = type;
1919 op_ptr[2] = CSA_MATCH_EQUAL_TO;
1922 initialize_entry_attr(CSA_ENTRY_ATTR_STATUS_I, &attr_ptr[3], appt_write, version);
1923 attr_ptr[3].value->item.sint32_value = state;
1924 op_ptr[3] = CSA_MATCH_EQUAL_TO;
1932 free_range(CSA_attribute **attrs, CSA_enum **ops, int count) {
1935 for (i = 0; i < count; i++) {
1936 free((*attrs)[i].name);
1937 if (((*attrs)[i].value->type == CSA_VALUE_STRING) ||
1938 ((*attrs)[i].value->type == CSA_VALUE_DATE_TIME))
1939 if ((*attrs)[i].value->item.string_value)
1940 free((*attrs)[i].value->item.string_value);
1942 free((*attrs)[i].value);
1945 /* This memory was allocated by the client, and must be freed
1957 * In Motif you can't associate user data with items in a list. To get around
1958 * this we have the following simple functions (CmDataList*) that maintain
1959 * a list of user data. We follow the intrinscs coding style to re-inforce
1960 * the relationship these routines have to the XmList* functions.
1964 * Create a list to store user data
1967 CmDataListCreate(void)
1970 return (CmDataList *)calloc(1, sizeof(CmDataList));
1977 CmDataListDestroy(CmDataList *list, int free_data)
1980 CmDataListDeleteAll(list, free_data);
1985 * Create node to hold data in list.
1988 CmDataItemCreate(void)
1991 return (CmDataItem *)calloc(1, sizeof(CmDataItem));
1995 * Add user data to list at specified position. Note that this
1996 * routine must be called for every item added to a list.
1997 * If the item has no user data, just pass NULL.
1999 * list List to add data to
2000 * data User data. NULL for no data.
2001 * position Where to insert data, starting with 1 for the
2002 * first item. 0 to append to end of list.
2006 * -1 Invalid position
2009 CmDataListAdd(CmDataList *list, void *data, int position)
2012 CmDataItem *item, *p;
2015 /* Create new node to hold data */
2016 item = CmDataItemCreate();
2019 /* Insert node into list at appropriate spot */
2020 if (list->head == NULL) {
2022 } else if (position == 0) {
2023 /* Special case. 0 means append to end */
2024 list->tail->next = item;
2025 } else if (position == 1) {
2026 item->next = list->head;
2029 for (n = 2, p = list->head; p != NULL && n < position;
2037 item->next = p->next;
2041 /* If new item is at the end of the list, update tail */
2042 if (item->next == NULL) {
2052 * Delete user data from a position in the list. If free_data is
2053 * True then this routine will call free(3C) on the user data, otherwise
2054 * the user data is returned so that the caller can dispose of it.
2055 * This routine should be called anytime you delete an item from a
2058 * list List to delete data from
2059 * position Location of item to delete. 0 for last item
2060 * free_data True if you want this routine to call free()
2061 * on the data for you. Otherwise this routine
2062 * will return the address of the data.
2065 * NULL No data found for item at the specified position
2066 * 1 Success (free_data was True)
2067 * other Address of data for item at the specified position.
2068 * (free_data was False)
2071 CmDataListDeletePos(CmDataList *list, int position, int free_data)
2075 CmDataItem *p, *item;
2078 /* Special case. 0 means delete last item */
2079 if (position == 0) {
2080 position = list->count;
2083 if (list->head == NULL) {
2085 } else if (position == 1) {
2087 list->head = item->next;
2088 if (list->tail == item) {
2089 list->tail = item->next;
2092 for (n = 2, p = list->head; p->next != NULL && n < position;
2096 if (p->next == NULL) {
2101 p->next = item->next;
2102 if (list->tail == item) {
2122 * Delete all nodes in the list.
2124 * list List to delete nodes from
2125 * free_data True if you want this routine to call free()
2126 * on the data for you.
2129 CmDataListDeleteAll(CmDataList *list, int free_data)
2132 CmDataItem *p, *tmp;
2136 if (free_data && p->data != NULL) {
2153 * Get data for the item at a particular position in a list.
2156 CmDataListGetData(CmDataList *list, int position)
2160 CmDataItem *p, *item;
2163 if (list->head == NULL) {
2165 } else if (position == 0) {
2166 data = list->tail->data;
2168 for (n = 1, p = list->head; p != NULL && n < position;
2182 * For dumping contents of list
2185 CmDataListDump(CmDataList *list)
2191 printf("***** %d items:\n", list->count);
2193 for (p = list->head, n = 1; p != NULL; p = p->next, n++) {
2194 printf("%3d: %s\n", n, p->data ? (char *)p->data : "<nil>");