2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: log.c /main/8 1996/11/21 19:45:13 drk $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Novell, Inc.
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
31 #include <EUSCompat.h>
40 #define XOS_USE_NO_LOCKING
41 #define X_INCLUDE_TIME_H
42 #include <X11/Xos_r.h>
48 extern uid_t daemon_uid;
49 extern gid_t daemon_gid;
52 static char *spool_dir = _DtCMS_DEFAULT_DIR;
54 char *tag_string[] = {
74 * forward declaration of functions used within this file
76 static char * cr_to_str(char *s, int size);
77 static void periodtostr(Interval_4 i, char *q);
78 static void privacytostr(Privacy_Level_4 p, char *q);
79 static void apptstatustostr(Appt_Status_4 p, char *q);
80 static void apptstatustostr(Appt_Status_4 p, char *q);
81 static void tagstostr(Event_Type_4 p, char *q);
82 static char * get_fname (char *dir, char *fname, char *who);
83 static CSA_return_code append_log(int f, char *buf);
84 static CSA_return_code create_log(char *owner, char *file, int version);
85 static char *attrs_to_attrliststr(int len, cms_attribute *attrs,
86 boolean_t write_hash, boolean_t entryattrs);
87 static char *grow_n_concat(char *base, char *newstr, int newcount);
88 static char *get_access_list_string(cms_access_entry *list);
89 static char *get_date_time_list_string(CSA_date_time_list list);
97 _DtCmsGetLogFN(char *who)
99 return (get_fname (spool_dir, _DtCMS_DEFAULT_LOG, who));
103 _DtCmsGetBakFN(char *who)
105 return (get_fname (spool_dir, _DtCMS_DEFAULT_BAK, who));
109 _DtCmsGetTmpFN(char *who)
111 return (get_fname (spool_dir, _DtCMS_DEFAULT_TMP, who));
115 _DtCmsGetDelFN(char *who)
117 return (get_fname (spool_dir, _DtCMS_DEFAULT_DEL, who));
120 extern CSA_return_code
121 _DtCmsCreateLogV1(char *owner, char *file)
123 return (create_log(owner, file, _DtCMS_VERSION1));
127 extern CSA_return_code
128 _DtCmsAppendHTableByFN(char *file, uint size, char **names, int *types)
131 CSA_return_code stat;
133 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
135 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
138 stat = _DtCmsAppendHTableByFD(f, size, names, types);
145 * the first element of the arrays is not used
147 extern CSA_return_code
148 _DtCmsAppendHTableByFD(int fd, uint size, char **names, int *types)
150 CSA_return_code stat;
151 char *tptr, *buf, tmpbuf[BUFSIZ/4];
152 int i, tcount, count = 15; /* strlen("(entrytable )\n") + 1 */
154 if ((buf = malloc(BUFSIZ)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY);
156 strcpy(buf, "(entrytable ");
158 for (i = 1; i <= size; i++) {
159 sprintf(tmpbuf, "(%d \"%s\" \"%s\")\n", i, names[i],
160 tag_string[types[i]]);
162 count += strlen(tmpbuf);
163 if (tcount < count) {
164 if ((tptr = grow_n_concat(buf, tmpbuf, tcount + BUFSIZ))
167 return (CSA_E_INSUFFICIENT_MEMORY);
177 stat = append_log(fd, buf);
183 extern CSA_return_code
184 _DtCmsAppendEntryByFN(char *file, cms_entry *entry, _DtCmsLogOps op)
187 CSA_return_code stat;
189 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
191 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
194 stat = _DtCmsAppendEntryByFD(f, entry, op);
200 extern CSA_return_code
201 _DtCmsAppendEntryByFD(int f, cms_entry *entry, _DtCmsLogOps op)
203 CSA_return_code stat;
205 char *cptr, *tptr, *buf;
208 if ((buf = malloc(100)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY);
210 _csa_tick_to_iso8601(entry->key.time, isotime);
211 sprintf(buf, "(%s \"%s\" key: %ld%s",
212 (op == _DtCmsLogAdd ? "add" : "remove"),
213 isotime, entry->key.id,
214 (op == _DtCmsLogAdd ? "\nhashedattributes: (" : ""));
215 count = strlen(buf) + 4;
217 if (op == _DtCmsLogAdd && entry->num_attrs > 0) {
218 if ((cptr = attrs_to_attrliststr(entry->num_attrs,
219 entry->attrs, B_TRUE, B_TRUE)) == NULL) {
221 return (CSA_E_INSUFFICIENT_MEMORY);
223 count += strlen(cptr);
224 if ((tptr = grow_n_concat(buf, cptr, count)) == NULL) {
227 return (CSA_E_INSUFFICIENT_MEMORY);
233 /* closing for attr list and closing for entry */
234 if (op == _DtCmsLogAdd)
239 stat = append_log(f, buf);
245 extern CSA_return_code
246 _DtCmsAppendCalAttrsByFN(char *file, int size, cms_attribute * attrs)
249 CSA_return_code stat;
251 if (file == NULL || size <= 0)
252 return (CSA_E_INVALID_PARAMETER);
254 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
256 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
259 stat = _DtCmsAppendCalAttrsByFD(f, size, attrs);
265 extern CSA_return_code
266 _DtCmsAppendCalAttrsByFD(int f, int size, cms_attribute * attrs)
268 CSA_return_code stat;
270 char *prefix = "(calendarattributes ";
271 char *subfix = ")\n";
274 if ((attrstr = attrs_to_attrliststr(size, attrs, B_FALSE, B_FALSE))
276 return (CSA_E_INSUFFICIENT_MEMORY);
278 count = strlen(prefix) + strlen(attrstr) + strlen(subfix) + 1;
279 if ((buf = malloc(count)) == NULL) {
281 return (CSA_E_INSUFFICIENT_MEMORY);
283 sprintf(buf, "%s%s%s", prefix, attrstr, subfix);
285 stat = append_log(f, buf);
292 extern CSA_return_code
293 _DtCmsAppendAppt4ByFN(char *file, Appt_4 *appt, _DtCmsLogOps op)
296 CSA_return_code stat;
298 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
300 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
303 stat = _DtCmsAppendAppt4ByFD(f, appt, op);
309 extern CSA_return_code
310 _DtCmsAppendAppt4ByFD(int f, Appt_4 *appt, _DtCmsLogOps op)
314 char buf[BUFSIZ*3], buf2[BUFSIZ*2]; /* 1 BUFSIZ for what fields,
315 1 BUFSIZ for mailto field,
316 and 1 BUFSIZ for the rest */
318 cptr = ctime (&appt->appt_id.tick);
319 cptr[24] = NULL; /* strip off CR */
324 sprintf(buf, "(add \"%s\" key: %ld ", cptr, appt->appt_id.key);
326 cptr = cr_to_str(appt->what, strlen(appt->what));
328 sprintf(buf2, "what: \"%s\" ", cptr);
332 return (CSA_E_INSUFFICIENT_MEMORY);
335 if (appt->client_data) {
336 sprintf(buf2, "details: \"%s\" ", appt->client_data);
339 if (appt->duration) {
340 sprintf(buf2, "duration: %d ", appt->duration);
344 periodtostr (appt->period.period, tmpbuf);
345 sprintf(buf2, "period: %s ", tmpbuf);
348 if (appt->period.nth != 0) {
349 sprintf (buf2, "nth: %d ", appt->period.nth);
352 if (appt->period.enddate != 0) {
353 cptr = ctime (&(appt->period.enddate));
354 cptr[24] = NULL; /* strip off CR */
355 sprintf(buf2, "enddate: \"%s\" ", cptr);
359 sprintf(buf2, "ntimes: %d ", appt->ntimes);
362 if (appt->exception != NULL) {
363 struct Except_4 *e = appt->exception;
364 strcat(buf, "exceptions: (");
366 sprintf(buf2, "%d ", e->ordinal);
373 if (appt->author != NULL) {
374 sprintf(buf2, "author: \"%s\" ", appt->author);
377 if (appt->attr != NULL) {
378 struct Attribute_4 *item = appt->attr;
379 strcat(buf, "attributes: (");
380 while(item != NULL) {
381 sprintf(buf2, "(\"%s\",\"%s\",\"%s\")",
382 item->attr, item->value,
389 if (appt->tag != NULL) {
390 struct Tag_4 *item = appt->tag;
391 strcat(buf, "tags: (");
392 while(item != NULL) {
393 tagstostr(item->tag, tmpbuf);
394 sprintf(buf2, "(%s , %d)", tmpbuf,
402 apptstatustostr(appt->appt_status, tmpbuf);
403 sprintf(buf2, "apptstat: %s ", tmpbuf);
406 privacytostr(appt->privacy, tmpbuf);
407 sprintf(buf2, "privacy: %s )\n", tmpbuf);
412 case _DtCmsLogRemove:
413 sprintf(buf, "(remove \"%s\" key: %ld)\n", cptr,
418 return (append_log(f, buf));
421 extern CSA_return_code
422 _DtCmsAppendAccessByFN(char *file, int type, Access_Entry_4 *p)
425 CSA_return_code stat;
427 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
429 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
432 stat = _DtCmsAppendAccessByFD(f, type, p);
438 extern CSA_return_code
439 _DtCmsAppendAccessByFD(int f, int type, Access_Entry_4 *p)
441 CSA_return_code stat;
442 int count = 12; /* (access )\n */
446 if (type == access_read_4)
448 else if (type == access_write_4)
450 else if (type == access_delete_4)
452 else if (type == access_exec_4)
455 return (CSA_E_INVALID_PARAMETER);
457 count = count + strlen(p_type);
458 if ((buf = malloc(count)) == NULL)
459 return (CSA_E_INSUFFICIENT_MEMORY);
461 sprintf(buf, "(access %s ", p_type);
464 if (p->who != NULL) {
465 count = count + strlen(p->who) + 3;
466 if ((buf = realloc(buf, count)) == NULL)
467 return (CSA_E_INSUFFICIENT_MEMORY);
478 stat = append_log(f, buf);
485 _DtCmsPrintAppt4(caddr_t data)
487 Appt_4 *appt = (Appt_4 *)data;
491 fprintf(stderr, "*** V4 appointement: ***\n\n");
493 tmstr = ctime (&appt->appt_id.tick);
494 tmstr[24] = NULL; /* strip off CR */
496 if (fprintf(stderr, "(add \"%s\" ", tmstr)==EOF) {
499 if (fprintf(stderr, "key: %ld ", appt->appt_id.key)==EOF) {
503 tmstr = cr_to_str(appt->what, strlen(appt->what));
504 if (fprintf(stderr, "what: \"%s\" ", tmstr) == EOF) {
510 if (appt->client_data) {
511 if (fprintf(stderr, "details: \"%s\" ", appt->client_data)
515 if (appt->duration) {
516 if (fprintf(stderr, "duration: %d ", appt->duration) == EOF)
521 periodtostr (appt->period.period, buf);
522 if (fprintf(stderr, "period: %s ", buf) == EOF)
525 if (appt->period.nth != 0) {
526 if (fprintf (stderr, "nth: %d ", appt->period.nth) == EOF)
529 if (appt->period.enddate != 0) {
530 tmstr = ctime (&(appt->period.enddate));
531 tmstr[24] = NULL; /* strip off CR */
532 if (fprintf(stderr, "enddate: \"%s\" ", tmstr) == EOF)
536 if (fprintf(stderr, "ntimes: %d ", appt->ntimes) == EOF)
539 if (appt->exception != NULL) {
540 struct Except_4 *e = appt->exception;
541 if (fprintf(stderr, "exceptions: (") == EOF)
544 if (fprintf(stderr, "%d ", e->ordinal) == EOF)
548 if (fprintf(stderr, ") ") == EOF)
551 if (appt->author != NULL) {
552 if (fprintf(stderr, "author: \"%s\" ", appt->author) == EOF)
555 if (appt->attr != NULL) {
556 struct Attribute_4 *item = appt->attr;
557 if (fprintf(stderr, "attributes: (") == EOF)
559 while(item != NULL) {
560 if (fprintf(stderr, "(\"%s\",\"%s\",\"%s\")",
561 item->attr, item->value, item->clientdata) == EOF)
565 if (fprintf(stderr, ") ") == EOF)
568 if (appt->tag != NULL) {
569 struct Tag_4 *item = appt->tag;
570 if (fprintf(stderr, "tags: (") == EOF)
572 while(item != NULL) {
574 tagstostr(item->tag, buf);
575 if (fprintf(stderr, "(%s , %d)", buf, item->showtime)
580 if (fprintf(stderr, ") ") == EOF)
586 apptstatustostr(appt->appt_status, buf);
587 if (fprintf(stderr, "apptstat: %s ", buf) == EOF)
591 privacytostr(appt->privacy, buf);
592 if (fprintf(stderr, "privacy: %s )\n", buf) == EOF)
599 _DtCmsPrintExceptions(int len, int *exceptions)
603 fprintf(stderr, "\nexception part:\n");
604 fprintf(stderr, "number of exception = %d\n", len);
605 fprintf(stderr, "exceptions:");
606 for (i = 0; i < len; i++) {
607 fprintf(stderr, " %d", exceptions[i]);
609 fprintf(stderr, "\n");
612 extern CSA_return_code
613 _DtCmsCreateLogV2(char *owner, char *file)
615 return (create_log(owner, file, _DtCMS_VERSION4));
618 extern CSA_return_code
619 _DtCmsGetFileSize(char *calendar, int *size)
624 if ((log = _DtCmsGetLogFN(calendar)) == NULL)
625 return (CSA_E_INSUFFICIENT_MEMORY);
627 if (stat(log, &info) != 0) {
629 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
631 *size = info.st_size;
633 return (CSA_SUCCESS);
638 _DtCmsTruncateFile(char *calendar, int size)
643 if ((log = _DtCmsGetLogFN(calendar)) == NULL)
646 /* truncate log file to specified size */
647 if ((f = open(log, O_RDWR | O_APPEND | O_SYNC)) >= 0)
653 extern CSA_return_code
654 _DtCmsRemoveLog(char *calendar, char *user)
656 CSA_return_code stat = CSA_SUCCESS;
659 if ((log = _DtCmsGetLogFN(calendar)) == NULL)
660 return (CSA_E_INSUFFICIENT_MEMORY);
662 if ((dlog = _DtCmsGetDelFN(calendar)) == NULL) {
664 return (CSA_E_INSUFFICIENT_MEMORY);
667 if (rename(log, dlog) < 0)
668 stat = CSA_X_DT_E_BACKING_STORE_PROBLEM;
676 extern CSA_return_code
677 _DtCmsWriteVersionString(char *file, int version)
684 CSA_return_code stat = CSA_SUCCESS;
685 _Xltimeparams localtime_buf;
686 _Xatimeparams asctime_buf;
688 tmval = time((time_t *) 0);
689 tm = _XLocaltime(&tmval, localtime_buf);
690 tmstr = _XAsctime(tm, asctime_buf);
691 tmstr[24] = NULL; /* strip off CR */
693 if ((fd = open(file, O_WRONLY|O_TRUNC|O_SYNC)) < 0) {
695 fprintf(stderr, "%s: failed to open %s in %s\n",
696 pgname, file, _DtCmsWriteVersionString);
697 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
700 sprintf(buf, "Version: %d\n**** start of log on %s ****\n\n",
704 if (write(fd, buf, len) != len) {
706 stat = CSA_X_DT_E_BACKING_STORE_PROBLEM;
714 * if everything works fine, return 0; otherwise, return -1
722 boolean_t changeeuid,
728 if (changeeuid == B_TRUE) {
738 if (chmod (file, mode) < 0) {
739 if (printerr == B_TRUE) {
741 sprintf (buff, "%s: chmod %s to %lo failed.\n%s: System error",
742 pgname, file, (long)mode, pgname);
749 if (chown (file, uid, gid) < 0) {
750 if (printerr == B_TRUE) {
752 sprintf (buff, "%s: chown %s to (uid=%ld,gid=%ld) failed.\n%s%s",
753 pgname, file, (long)uid, (long)gid, pgname, ": System error");
762 if (changeeuid == B_TRUE && setuid (daemon_uid) < 0)
764 if (changeeuid == B_TRUE && seteuid (daemon_uid) < 0)
767 if (printerr == B_TRUE) {
769 sprintf (buff, "%s: Can't switch process uid back to daemon.\n%s%s",
770 pgname, pgname, ": System error");
781 periodtostr(Interval_4 i, char *q)
787 strcpy (q, "single");
793 strcpy (q, "weekly");
796 strcpy (q, "biweekly");
799 strcpy (q, "monthly");
802 strcpy (q, "yearly");
805 strcpy (q, "nthWeekday");
808 strcpy (q, "everyNthDay");
811 strcpy (q, "everyNthWeek");
813 case everyNthMonth_4:
814 strcpy (q, "everyNthMonth");
817 strcpy (q, "monThruFri");
820 strcpy (q, "monWedFri");
823 strcpy (q, "tueThur");
826 strcpy (q, "daysOfWeek");
829 strcpy (q, "single");
835 privacytostr(Privacy_Level_4 p, char *q)
844 strcpy(q, "private");
847 strcpy(q, "semiprivate");
856 apptstatustostr(Appt_Status_4 p, char *q)
865 strcpy(q, "pendingAdd");
867 case pendingDelete_4:
868 strcpy(q, "pendingDelete");
871 strcpy(q, "committed");
874 strcpy(q, "cancelled");
877 strcpy(q, "completed");
886 tagstostr(Event_Type_4 p, char *q)
892 strcpy(q, "appointment");
895 strcpy(q, "reminder");
898 strcpy(q, "otherTag");
901 strcpy(q, "holiday");
907 strcpy(q, "appointment");
913 get_fname (char *dir, char *fname, char *who)
917 buf = (char *)malloc(strlen(dir) + strlen(fname) + strlen(who) + 3);
919 sprintf (buf, "%s/%s.%s", dir, fname, who);
923 static CSA_return_code
924 create_log(char *owner, char *file, int version)
930 CSA_return_code stat;
932 ptr = strchr(owner, '@');
933 if (ptr) *ptr = NULL;
934 pw = getpwnam (owner);
937 return(CSA_E_FAILURE);
941 /* Read by owner and Read/Write by group (gid must be daemon) */
942 fd = open(file, O_WRONLY|O_CREAT|O_EXCL, _DtCMS_DEFAULT_MODE);
945 fprintf(stderr, "%s: can't create %s\n", pgname, file);
948 return(CSA_E_CALENDAR_EXISTS);
950 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
953 if (_DtCmsSetFileMode(file, uid, daemon_gid, _DtCMS_DEFAULT_MODE,
954 B_TRUE, B_TRUE) < 0) {
957 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
961 if ((stat = _DtCmsWriteVersionString(file, version)) != CSA_SUCCESS) {
968 static CSA_return_code
969 append_log(int f, char *buf)
971 CSA_return_code status;
973 int file_size = 0, nbytes_written = 0, nbytes_towrite = 0;
976 return (CSA_E_INVALID_PARAMETER);
978 if (fstat(f, &finfo) < 0) {
980 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
982 file_size = finfo.st_size;
984 nbytes_towrite = strlen(buf);
985 nbytes_written = write(f, buf, nbytes_towrite);
986 if (nbytes_written != nbytes_towrite) {
988 status = CSA_E_DISK_FULL;
990 status = CSA_X_DT_E_BACKING_STORE_PROBLEM;
993 ftruncate(f, file_size);
1001 grow_n_concat(char *base, char *newstr, int newcount)
1005 if ((ptr = realloc(base, newcount)) == NULL)
1009 strcat(ptr, newstr);
1011 strcpy(ptr, newstr);
1017 * format of attributes:
1018 * CSA_VALUE_BOOLEAN: ("name","type","number")
1019 * CSA_VALUE_ENUMERATED: ("name","type","number")
1020 * CSA_VALUE_FLAGS: ("name","type","number")
1021 * CSA_VALUE_SINT32: ("name","type","number")
1022 * CSA_VALUE_UINT32: ("name","type","number")
1023 * CSA_VALUE_STRING: ("name","type","string")
1024 * CSA_VALUE_ACCESS_LIST: ("name","type","user:rights [user:rights]")
1025 * CSA_VALUE_CALENDAR_USER: ("name","type","string")
1026 * CSA_VALUE_DATE_TIME: ("name","type","datetime")
1027 * CSA_VALUE_DATE_TIME_RANGE: ("name","type","datetimerange")
1028 * CSA_VALUE_TIME_DURATION: ("name","type","timeduration")
1029 * CSA_VALUE_DATE_TIME_LIST: ("name","type","datetime [datetime]")
1030 * CSA_VALUE_REMINDER: ("name","type","string:number:string") or
1031 * ("name","type","string:string:number:number:string")
1032 * CSA_VALUE_OPAQUE_DATA: ("name","type","number:string")
1034 * format of attributes (when only hashed number is written):
1035 * CSA_VALUE_BOOLEAN: (hash_number "number")
1036 * CSA_VALUE_ENUMERATED: (hash_number "number")
1037 * CSA_VALUE_FLAGS: (hash_number "number")
1038 * CSA_VALUE_SINT32: (hash_number "number")
1039 * CSA_VALUE_UINT32: (hash_number "number")
1040 * CSA_VALUE_STRING: (hash_number "string")
1041 * CSA_VALUE_ACCESS_LIST: (hash_number "user:rights [user:rights]")
1042 * CSA_VALUE_CALENDAR_USER: (hash_number "string")
1043 * CSA_VALUE_DATE_TIME: (hash_number "datetime")
1044 * CSA_VALUE_DATE_TIME_RANGE: (hash_number "datetimerange")
1045 * CSA_VALUE_TIME_DURATION: (hash_number "timeduration")
1046 * CSA_VALUE_DATE_TIME_LIST: (hash_number "datetime [datetime]")
1047 * CSA_VALUE_REMINDER: (hash_number "string:number:string") or
1048 * (hash_number "string:string:number:number:string")
1049 * CSA_VALUE_OPAQUE_DATA: (hash_number "number:string")
1051 * Note: element 0 of the array is not used
1054 attrs_to_attrliststr(
1056 cms_attribute *attrs,
1057 boolean_t write_hash,
1058 boolean_t entryattrs)
1060 int i, count, tcount;
1061 char *ptr, *buf = NULL;
1062 char tmpbuf[BUFSIZ/2], tmpbuf2[BUFSIZ/2], *body;
1063 CSA_opaque_data *opq;
1065 if ((buf = malloc(BUFSIZ+1)) == NULL) return (NULL);
1068 for (i = 1, count = 0, *buf = NULL; i <= num_attr; i++) {
1070 if (attrs[i].value == NULL || (entryattrs &&
1071 (i == CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I ||
1072 i == CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I ||
1073 i == CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I ||
1074 i == CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I ||
1075 i == CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I ||
1076 i == CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I)))
1080 /* open_bracket hash_number open quote for value */
1081 sprintf(tmpbuf, "(%d \"", attrs[i].name.num);
1083 /* open bracket name, type, open quote for value */
1084 sprintf(tmpbuf, "(\"%s\",\"%s\",\"", attrs[i].name.name,
1085 tag_string[attrs[i].value->type]);
1090 switch (attrs[i].value->type) {
1091 case CSA_VALUE_ENUMERATED:
1092 case CSA_VALUE_SINT32:
1093 sprintf(tmpbuf2, "%ld",
1094 attrs[i].value->item.sint32_value);
1097 case CSA_VALUE_BOOLEAN:
1098 case CSA_VALUE_FLAGS:
1099 case CSA_VALUE_UINT32:
1100 sprintf(tmpbuf2, "%lu",
1101 attrs[i].value->item.uint32_value);
1104 case CSA_VALUE_STRING:
1105 case CSA_VALUE_DATE_TIME:
1106 case CSA_VALUE_DATE_TIME_RANGE:
1107 case CSA_VALUE_TIME_DURATION:
1108 case CSA_VALUE_CALENDAR_USER:
1109 if (attrs[i].value->item.string_value) {
1110 if ((ptr = cr_to_str(attrs[i].value->\
1112 strlen(attrs[i].value->item.string_value)))
1123 case CSA_VALUE_REMINDER:
1124 opq = &attrs[i].value->item.reminder_value->\
1126 if (attrs[i].value->item.reminder_value->repeat_count
1129 sprintf(tmpbuf2, "%s:%s:%lu:%lu:",
1130 attrs[i].value->item.reminder_value->lead_time,
1131 (attrs[i].value->item.reminder_value->snooze_time ?
1132 attrs[i].value->item.reminder_value->snooze_time:""),
1133 attrs[i].value->item.reminder_value->repeat_count,
1136 sprintf(tmpbuf2, "%s:%lu:",
1137 attrs[i].value->item.reminder_value->lead_time,
1141 if (opq->size > 0) {
1142 if ((ptr = cr_to_str((char *)opq->data,
1143 opq->size)) == NULL) {
1153 case CSA_VALUE_OPAQUE_DATA:
1154 opq = attrs[i].value->item.opaque_data_value;
1155 sprintf(tmpbuf2, "%lu:", opq->size);
1157 if (opq->size > 0) {
1158 if ((ptr = cr_to_str((char *)opq->data,
1159 opq->size)) == NULL) {
1168 case CSA_VALUE_ACCESS_LIST:
1169 if (attrs[i].value->item.access_list_value) {
1170 if ((ptr = get_access_list_string(
1171 attrs[i].value->item.access_list_value))
1181 case CSA_VALUE_DATE_TIME_LIST:
1182 if (attrs[i].value->item.date_time_list_value) {
1183 if ((ptr = get_date_time_list_string(
1184 attrs[i].value->item.date_time_list_value))
1195 count += strlen(tmpbuf) + strlen(tmpbuf2) +
1196 (body ? strlen(body) : 0) + 3; /* closing */
1197 if (tcount < count) {
1198 if ((ptr = realloc(buf, tcount+BUFSIZ)) == NULL) {
1199 if (body) free(body);
1206 strcat(buf, tmpbuf);
1207 if (*tmpbuf2 != NULL) strcat(buf, tmpbuf2);
1208 if (body) strcat(buf, body);
1209 strcat(buf, "\")\n");
1210 if (body) free(body);
1217 get_access_list_string(cms_access_entry *list)
1219 char *ptr = NULL, *tptr, buf[BUFSIZ/4];
1222 /* do the first one */
1223 if ((ptr = malloc(BUFSIZ+1)) == NULL) return (NULL);
1225 sprintf(ptr, "%s:%u", list->user, list->rights);
1226 count = strlen(ptr);
1228 while (list->next) {
1230 sprintf(buf, " %s:%u", list->user, list->rights);
1232 count += strlen(buf);
1233 if (tcount < count) {
1234 if ((tptr = grow_n_concat(ptr, buf, tcount+BUFSIZ))
1248 cr_to_str(char *s, int size)
1256 if ((newstr = (char *) calloc(1, (unsigned)((2 * size) + 2))) == NULL)
1259 for (j=0; j<size; j++) {
1265 else if (s[j]=='\\') {
1270 else if (s[j]=='\"') {
1285 get_date_time_list_string(CSA_date_time_list list)
1287 char *ptr = NULL, *tptr, buf[80];
1288 int count, datestrlen, tcount;
1290 /* do the first one */
1291 sprintf(buf, "%s", list->date_time);
1292 if ((ptr = strdup(buf)) == NULL)
1295 if ((ptr = malloc(BUFSIZ+1)) == NULL) return (NULL);
1297 strcpy(ptr, list->date_time);
1298 count = strlen(ptr);
1300 datestrlen = count + 1;
1301 while (list->next) {
1303 sprintf(buf, " %s", list->date_time);
1305 count += datestrlen;
1306 if (tcount < count) {
1307 if ((tptr = grow_n_concat(ptr, buf, tcount+BUFSIZ))