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
45 #include <X11/Xos_r.h>
51 extern uid_t daemon_uid;
52 extern gid_t daemon_gid;
55 static char *spool_dir = _DtCMS_DEFAULT_DIR;
57 char *tag_string[] = {
77 * forward declaration of functions used within this file
79 static char * cr_to_str(char *s, int size);
80 static void periodtostr(Interval_4 i, char *q);
81 static void privacytostr(Privacy_Level_4 p, char *q);
82 static void apptstatustostr(Appt_Status_4 p, char *q);
83 static void apptstatustostr(Appt_Status_4 p, char *q);
84 static void tagstostr(Event_Type_4 p, char *q);
85 static char * get_fname (char *dir, char *fname, char *who);
86 static CSA_return_code append_log(int f, char *buf);
87 static CSA_return_code create_log(char *owner, char *file, int version);
88 static char *attrs_to_attrliststr(int len, cms_attribute *attrs,
89 boolean_t write_hash, boolean_t entryattrs);
90 static char *grow_n_concat(char *base, char *newstr, int newcount);
91 static char *get_access_list_string(cms_access_entry *list);
92 static char *get_date_time_list_string(CSA_date_time_list list);
100 _DtCmsGetLogFN(char *who)
102 return (get_fname (spool_dir, _DtCMS_DEFAULT_LOG, who));
106 _DtCmsGetBakFN(char *who)
108 return (get_fname (spool_dir, _DtCMS_DEFAULT_BAK, who));
112 _DtCmsGetTmpFN(char *who)
114 return (get_fname (spool_dir, _DtCMS_DEFAULT_TMP, who));
118 _DtCmsGetDelFN(char *who)
120 return (get_fname (spool_dir, _DtCMS_DEFAULT_DEL, who));
123 extern CSA_return_code
124 _DtCmsCreateLogV1(char *owner, char *file)
126 return (create_log(owner, file, _DtCMS_VERSION1));
130 extern CSA_return_code
131 _DtCmsAppendHTableByFN(char *file, uint size, char **names, int *types)
134 CSA_return_code stat;
136 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
138 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
141 stat = _DtCmsAppendHTableByFD(f, size, names, types);
148 * the first element of the arrays is not used
150 extern CSA_return_code
151 _DtCmsAppendHTableByFD(int fd, uint size, char **names, int *types)
153 CSA_return_code stat;
154 char *tptr, *buf, tmpbuf[BUFSIZ/4];
155 int i, tcount, count = 15; /* strlen("(entrytable )\n") + 1 */
157 if ((buf = malloc(BUFSIZ)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY);
159 strcpy(buf, "(entrytable ");
161 for (i = 1; i <= size; i++) {
162 sprintf(tmpbuf, "(%d \"%s\" \"%s\")\n", i, names[i],
163 tag_string[types[i]]);
165 count += strlen(tmpbuf);
166 if (tcount < count) {
167 if ((tptr = grow_n_concat(buf, tmpbuf, tcount + BUFSIZ))
170 return (CSA_E_INSUFFICIENT_MEMORY);
180 stat = append_log(fd, buf);
186 extern CSA_return_code
187 _DtCmsAppendEntryByFN(char *file, cms_entry *entry, _DtCmsLogOps op)
190 CSA_return_code stat;
192 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
194 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
197 stat = _DtCmsAppendEntryByFD(f, entry, op);
203 extern CSA_return_code
204 _DtCmsAppendEntryByFD(int f, cms_entry *entry, _DtCmsLogOps op)
206 CSA_return_code stat;
208 char *cptr, *tptr, *buf;
211 if ((buf = malloc(100)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY);
213 _csa_tick_to_iso8601(entry->key.time, isotime);
214 sprintf(buf, "(%s \"%s\" key: %ld%s",
215 (op == _DtCmsLogAdd ? "add" : "remove"),
216 isotime, entry->key.id,
217 (op == _DtCmsLogAdd ? "\nhashedattributes: (" : ""));
218 count = strlen(buf) + 4;
220 if (op == _DtCmsLogAdd && entry->num_attrs > 0) {
221 if ((cptr = attrs_to_attrliststr(entry->num_attrs,
222 entry->attrs, B_TRUE, B_TRUE)) == NULL) {
224 return (CSA_E_INSUFFICIENT_MEMORY);
226 count += strlen(cptr);
227 if ((tptr = grow_n_concat(buf, cptr, count)) == NULL) {
230 return (CSA_E_INSUFFICIENT_MEMORY);
236 /* closing for attr list and closing for entry */
237 if (op == _DtCmsLogAdd)
242 stat = append_log(f, buf);
248 extern CSA_return_code
249 _DtCmsAppendCalAttrsByFN(char *file, int size, cms_attribute * attrs)
252 CSA_return_code stat;
254 if (file == NULL || size <= 0)
255 return (CSA_E_INVALID_PARAMETER);
257 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
259 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
262 stat = _DtCmsAppendCalAttrsByFD(f, size, attrs);
268 extern CSA_return_code
269 _DtCmsAppendCalAttrsByFD(int f, int size, cms_attribute * attrs)
271 CSA_return_code stat;
273 char *prefix = "(calendarattributes ";
274 char *subfix = ")\n";
277 if ((attrstr = attrs_to_attrliststr(size, attrs, B_FALSE, B_FALSE))
279 return (CSA_E_INSUFFICIENT_MEMORY);
281 count = strlen(prefix) + strlen(attrstr) + strlen(subfix) + 1;
282 if ((buf = malloc(count)) == NULL) {
284 return (CSA_E_INSUFFICIENT_MEMORY);
286 sprintf(buf, "%s%s%s", prefix, attrstr, subfix);
288 stat = append_log(f, buf);
295 extern CSA_return_code
296 _DtCmsAppendAppt4ByFN(char *file, Appt_4 *appt, _DtCmsLogOps op)
299 CSA_return_code stat;
301 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
303 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
306 stat = _DtCmsAppendAppt4ByFD(f, appt, op);
312 extern CSA_return_code
313 _DtCmsAppendAppt4ByFD(int f, Appt_4 *appt, _DtCmsLogOps op)
317 char buf[BUFSIZ*3], buf2[BUFSIZ*2]; /* 1 BUFSIZ for what fields,
318 1 BUFSIZ for mailto field,
319 and 1 BUFSIZ for the rest */
321 cptr = ctime (&appt->appt_id.tick);
322 cptr[24] = NULL; /* strip off CR */
327 sprintf(buf, "(add \"%s\" key: %ld ", cptr, appt->appt_id.key);
329 cptr = cr_to_str(appt->what, strlen(appt->what));
331 sprintf(buf2, "what: \"%s\" ", cptr);
335 return (CSA_E_INSUFFICIENT_MEMORY);
338 if (appt->client_data) {
339 sprintf(buf2, "details: \"%s\" ", appt->client_data);
342 if (appt->duration) {
343 sprintf(buf2, "duration: %d ", appt->duration);
347 periodtostr (appt->period.period, tmpbuf);
348 sprintf(buf2, "period: %s ", tmpbuf);
351 if (appt->period.nth != 0) {
352 sprintf (buf2, "nth: %d ", appt->period.nth);
355 if (appt->period.enddate != 0) {
356 cptr = ctime (&(appt->period.enddate));
357 cptr[24] = NULL; /* strip off CR */
358 sprintf(buf2, "enddate: \"%s\" ", cptr);
362 sprintf(buf2, "ntimes: %d ", appt->ntimes);
365 if (appt->exception != NULL) {
366 struct Except_4 *e = appt->exception;
367 strcat(buf, "exceptions: (");
369 sprintf(buf2, "%d ", e->ordinal);
376 if (appt->author != NULL) {
377 sprintf(buf2, "author: \"%s\" ", appt->author);
380 if (appt->attr != NULL) {
381 struct Attribute_4 *item = appt->attr;
382 strcat(buf, "attributes: (");
383 while(item != NULL) {
384 sprintf(buf2, "(\"%s\",\"%s\",\"%s\")",
385 item->attr, item->value,
392 if (appt->tag != NULL) {
393 struct Tag_4 *item = appt->tag;
394 strcat(buf, "tags: (");
395 while(item != NULL) {
396 tagstostr(item->tag, tmpbuf);
397 sprintf(buf2, "(%s , %d)", tmpbuf,
405 apptstatustostr(appt->appt_status, tmpbuf);
406 sprintf(buf2, "apptstat: %s ", tmpbuf);
409 privacytostr(appt->privacy, tmpbuf);
410 sprintf(buf2, "privacy: %s )\n", tmpbuf);
415 case _DtCmsLogRemove:
416 sprintf(buf, "(remove \"%s\" key: %ld)\n", cptr,
421 return (append_log(f, buf));
424 extern CSA_return_code
425 _DtCmsAppendAccessByFN(char *file, int type, Access_Entry_4 *p)
428 CSA_return_code stat;
430 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
432 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
435 stat = _DtCmsAppendAccessByFD(f, type, p);
441 extern CSA_return_code
442 _DtCmsAppendAccessByFD(int f, int type, Access_Entry_4 *p)
444 CSA_return_code stat;
445 int count = 12; /* (access )\n */
449 if (type == access_read_4)
451 else if (type == access_write_4)
453 else if (type == access_delete_4)
455 else if (type == access_exec_4)
458 return (CSA_E_INVALID_PARAMETER);
460 count = count + strlen(p_type);
461 if ((buf = malloc(count)) == NULL)
462 return (CSA_E_INSUFFICIENT_MEMORY);
464 sprintf(buf, "(access %s ", p_type);
467 if (p->who != NULL) {
468 count = count + strlen(p->who) + 3;
469 if ((buf = realloc(buf, count)) == NULL)
470 return (CSA_E_INSUFFICIENT_MEMORY);
481 stat = append_log(f, buf);
488 _DtCmsPrintAppt4(caddr_t data)
490 Appt_4 *appt = (Appt_4 *)data;
494 fprintf(stderr, "*** V4 appointement: ***\n\n");
496 tmstr = ctime (&appt->appt_id.tick);
497 tmstr[24] = NULL; /* strip off CR */
499 if (fprintf(stderr, "(add \"%s\" ", tmstr)==EOF) {
502 if (fprintf(stderr, "key: %ld ", appt->appt_id.key)==EOF) {
506 tmstr = cr_to_str(appt->what, strlen(appt->what));
507 if (fprintf(stderr, "what: \"%s\" ", tmstr) == EOF) {
513 if (appt->client_data) {
514 if (fprintf(stderr, "details: \"%s\" ", appt->client_data)
518 if (appt->duration) {
519 if (fprintf(stderr, "duration: %d ", appt->duration) == EOF)
524 periodtostr (appt->period.period, buf);
525 if (fprintf(stderr, "period: %s ", buf) == EOF)
528 if (appt->period.nth != 0) {
529 if (fprintf (stderr, "nth: %d ", appt->period.nth) == EOF)
532 if (appt->period.enddate != 0) {
533 tmstr = ctime (&(appt->period.enddate));
534 tmstr[24] = NULL; /* strip off CR */
535 if (fprintf(stderr, "enddate: \"%s\" ", tmstr) == EOF)
539 if (fprintf(stderr, "ntimes: %d ", appt->ntimes) == EOF)
542 if (appt->exception != NULL) {
543 struct Except_4 *e = appt->exception;
544 if (fprintf(stderr, "exceptions: (") == EOF)
547 if (fprintf(stderr, "%d ", e->ordinal) == EOF)
551 if (fprintf(stderr, ") ") == EOF)
554 if (appt->author != NULL) {
555 if (fprintf(stderr, "author: \"%s\" ", appt->author) == EOF)
558 if (appt->attr != NULL) {
559 struct Attribute_4 *item = appt->attr;
560 if (fprintf(stderr, "attributes: (") == EOF)
562 while(item != NULL) {
563 if (fprintf(stderr, "(\"%s\",\"%s\",\"%s\")",
564 item->attr, item->value, item->clientdata) == EOF)
568 if (fprintf(stderr, ") ") == EOF)
571 if (appt->tag != NULL) {
572 struct Tag_4 *item = appt->tag;
573 if (fprintf(stderr, "tags: (") == EOF)
575 while(item != NULL) {
577 tagstostr(item->tag, buf);
578 if (fprintf(stderr, "(%s , %d)", buf, item->showtime)
583 if (fprintf(stderr, ") ") == EOF)
589 apptstatustostr(appt->appt_status, buf);
590 if (fprintf(stderr, "apptstat: %s ", buf) == EOF)
594 privacytostr(appt->privacy, buf);
595 if (fprintf(stderr, "privacy: %s )\n", buf) == EOF)
602 _DtCmsPrintExceptions(int len, int *exceptions)
606 fprintf(stderr, "\nexception part:\n");
607 fprintf(stderr, "number of exception = %d\n", len);
608 fprintf(stderr, "exceptions:");
609 for (i = 0; i < len; i++) {
610 fprintf(stderr, " %d", exceptions[i]);
612 fprintf(stderr, "\n");
615 extern CSA_return_code
616 _DtCmsCreateLogV2(char *owner, char *file)
618 return (create_log(owner, file, _DtCMS_VERSION4));
621 extern CSA_return_code
622 _DtCmsGetFileSize(char *calendar, int *size)
627 if ((log = _DtCmsGetLogFN(calendar)) == NULL)
628 return (CSA_E_INSUFFICIENT_MEMORY);
630 if (stat(log, &info) != 0) {
632 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
634 *size = info.st_size;
636 return (CSA_SUCCESS);
641 _DtCmsTruncateFile(char *calendar, int size)
646 if ((log = _DtCmsGetLogFN(calendar)) == NULL)
649 /* truncate log file to specified size */
650 if ((f = open(log, O_RDWR | O_APPEND | O_SYNC)) >= 0)
656 extern CSA_return_code
657 _DtCmsRemoveLog(char *calendar, char *user)
659 CSA_return_code stat = CSA_SUCCESS;
662 if ((log = _DtCmsGetLogFN(calendar)) == NULL)
663 return (CSA_E_INSUFFICIENT_MEMORY);
665 if ((dlog = _DtCmsGetDelFN(calendar)) == NULL) {
667 return (CSA_E_INSUFFICIENT_MEMORY);
670 if (rename(log, dlog) < 0)
671 stat = CSA_X_DT_E_BACKING_STORE_PROBLEM;
679 extern CSA_return_code
680 _DtCmsWriteVersionString(char *file, int version)
687 CSA_return_code stat = CSA_SUCCESS;
688 _Xltimeparams localtime_buf;
689 _Xatimeparams asctime_buf;
691 tmval = time((time_t *) 0);
692 tm = _XLocaltime(&tmval, localtime_buf);
693 tmstr = _XAsctime(tm, asctime_buf);
694 tmstr[24] = NULL; /* strip off CR */
696 if ((fd = open(file, O_WRONLY|O_TRUNC|O_SYNC)) < 0) {
698 fprintf(stderr, "%s: failed to open %s in %s\n",
699 pgname, file, _DtCmsWriteVersionString);
700 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
703 sprintf(buf, "Version: %d\n**** start of log on %s ****\n\n",
707 if (write(fd, buf, len) != len) {
709 stat = CSA_X_DT_E_BACKING_STORE_PROBLEM;
717 * if everything works fine, return 0; otherwise, return -1
725 boolean_t changeeuid,
731 if (changeeuid == B_TRUE) {
741 if (chmod (file, mode) < 0) {
742 if (printerr == B_TRUE) {
744 sprintf (buff, "%s: chmod %s to %lo failed.\n%s: System error",
745 pgname, file, (long)mode, pgname);
752 if (chown (file, uid, gid) < 0) {
753 if (printerr == B_TRUE) {
755 sprintf (buff, "%s: chown %s to (uid=%ld,gid=%ld) failed.\n%s%s",
756 pgname, file, (long)uid, (long)gid, pgname, ": System error");
765 if (changeeuid == B_TRUE && setuid (daemon_uid) < 0)
767 if (changeeuid == B_TRUE && seteuid (daemon_uid) < 0)
770 if (printerr == B_TRUE) {
772 sprintf (buff, "%s: Can't switch process uid back to daemon.\n%s%s",
773 pgname, pgname, ": System error");
784 periodtostr(Interval_4 i, char *q)
790 strcpy (q, "single");
796 strcpy (q, "weekly");
799 strcpy (q, "biweekly");
802 strcpy (q, "monthly");
805 strcpy (q, "yearly");
808 strcpy (q, "nthWeekday");
811 strcpy (q, "everyNthDay");
814 strcpy (q, "everyNthWeek");
816 case everyNthMonth_4:
817 strcpy (q, "everyNthMonth");
820 strcpy (q, "monThruFri");
823 strcpy (q, "monWedFri");
826 strcpy (q, "tueThur");
829 strcpy (q, "daysOfWeek");
832 strcpy (q, "single");
838 privacytostr(Privacy_Level_4 p, char *q)
847 strcpy(q, "private");
850 strcpy(q, "semiprivate");
859 apptstatustostr(Appt_Status_4 p, char *q)
868 strcpy(q, "pendingAdd");
870 case pendingDelete_4:
871 strcpy(q, "pendingDelete");
874 strcpy(q, "committed");
877 strcpy(q, "cancelled");
880 strcpy(q, "completed");
889 tagstostr(Event_Type_4 p, char *q)
895 strcpy(q, "appointment");
898 strcpy(q, "reminder");
901 strcpy(q, "otherTag");
904 strcpy(q, "holiday");
910 strcpy(q, "appointment");
916 get_fname (char *dir, char *fname, char *who)
920 buf = (char *)malloc(strlen(dir) + strlen(fname) + strlen(who) + 3);
922 sprintf (buf, "%s/%s.%s", dir, fname, who);
926 static CSA_return_code
927 create_log(char *owner, char *file, int version)
933 CSA_return_code stat;
935 ptr = strchr(owner, '@');
936 if (ptr) *ptr = NULL;
937 pw = getpwnam (owner);
940 return(CSA_E_FAILURE);
944 /* Read by owner and Read/Write by group (gid must be daemon) */
945 fd = open(file, O_WRONLY|O_CREAT|O_EXCL, _DtCMS_DEFAULT_MODE);
948 fprintf(stderr, "%s: can't create %s\n", pgname, file);
951 return(CSA_E_CALENDAR_EXISTS);
953 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
956 if (_DtCmsSetFileMode(file, uid, daemon_gid, _DtCMS_DEFAULT_MODE,
957 B_TRUE, B_TRUE) < 0) {
960 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
964 if ((stat = _DtCmsWriteVersionString(file, version)) != CSA_SUCCESS) {
971 static CSA_return_code
972 append_log(int f, char *buf)
974 CSA_return_code status;
976 int file_size = 0, nbytes_written = 0, nbytes_towrite = 0;
979 return (CSA_E_INVALID_PARAMETER);
981 if (fstat(f, &finfo) < 0) {
983 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
985 file_size = finfo.st_size;
987 nbytes_towrite = strlen(buf);
988 nbytes_written = write(f, buf, nbytes_towrite);
989 if (nbytes_written != nbytes_towrite) {
991 status = CSA_E_DISK_FULL;
993 status = CSA_X_DT_E_BACKING_STORE_PROBLEM;
996 ftruncate(f, file_size);
1000 return(CSA_SUCCESS);
1004 grow_n_concat(char *base, char *newstr, int newcount)
1008 if ((ptr = realloc(base, newcount)) == NULL)
1012 strcat(ptr, newstr);
1014 strcpy(ptr, newstr);
1020 * format of attributes:
1021 * CSA_VALUE_BOOLEAN: ("name","type","number")
1022 * CSA_VALUE_ENUMERATED: ("name","type","number")
1023 * CSA_VALUE_FLAGS: ("name","type","number")
1024 * CSA_VALUE_SINT32: ("name","type","number")
1025 * CSA_VALUE_UINT32: ("name","type","number")
1026 * CSA_VALUE_STRING: ("name","type","string")
1027 * CSA_VALUE_ACCESS_LIST: ("name","type","user:rights [user:rights]")
1028 * CSA_VALUE_CALENDAR_USER: ("name","type","string")
1029 * CSA_VALUE_DATE_TIME: ("name","type","datetime")
1030 * CSA_VALUE_DATE_TIME_RANGE: ("name","type","datetimerange")
1031 * CSA_VALUE_TIME_DURATION: ("name","type","timeduration")
1032 * CSA_VALUE_DATE_TIME_LIST: ("name","type","datetime [datetime]")
1033 * CSA_VALUE_REMINDER: ("name","type","string:number:string") or
1034 * ("name","type","string:string:number:number:string")
1035 * CSA_VALUE_OPAQUE_DATA: ("name","type","number:string")
1037 * format of attributes (when only hashed number is written):
1038 * CSA_VALUE_BOOLEAN: (hash_number "number")
1039 * CSA_VALUE_ENUMERATED: (hash_number "number")
1040 * CSA_VALUE_FLAGS: (hash_number "number")
1041 * CSA_VALUE_SINT32: (hash_number "number")
1042 * CSA_VALUE_UINT32: (hash_number "number")
1043 * CSA_VALUE_STRING: (hash_number "string")
1044 * CSA_VALUE_ACCESS_LIST: (hash_number "user:rights [user:rights]")
1045 * CSA_VALUE_CALENDAR_USER: (hash_number "string")
1046 * CSA_VALUE_DATE_TIME: (hash_number "datetime")
1047 * CSA_VALUE_DATE_TIME_RANGE: (hash_number "datetimerange")
1048 * CSA_VALUE_TIME_DURATION: (hash_number "timeduration")
1049 * CSA_VALUE_DATE_TIME_LIST: (hash_number "datetime [datetime]")
1050 * CSA_VALUE_REMINDER: (hash_number "string:number:string") or
1051 * (hash_number "string:string:number:number:string")
1052 * CSA_VALUE_OPAQUE_DATA: (hash_number "number:string")
1054 * Note: element 0 of the array is not used
1057 attrs_to_attrliststr(
1059 cms_attribute *attrs,
1060 boolean_t write_hash,
1061 boolean_t entryattrs)
1063 int i, count, tcount;
1064 char *ptr, *buf = NULL;
1065 char tmpbuf[BUFSIZ/2], tmpbuf2[BUFSIZ/2], *body;
1066 CSA_opaque_data *opq;
1068 if ((buf = malloc(BUFSIZ+1)) == NULL) return (NULL);
1071 for (i = 1, count = 0, *buf = NULL; i <= num_attr; i++) {
1073 if (attrs[i].value == NULL || (entryattrs &&
1074 (i == CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I ||
1075 i == CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I ||
1076 i == CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I ||
1077 i == CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I ||
1078 i == CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I ||
1079 i == CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I)))
1083 /* open_bracket hash_number open quote for value */
1084 sprintf(tmpbuf, "(%d \"", attrs[i].name.num);
1086 /* open bracket name, type, open quote for value */
1087 sprintf(tmpbuf, "(\"%s\",\"%s\",\"", attrs[i].name.name,
1088 tag_string[attrs[i].value->type]);
1093 switch (attrs[i].value->type) {
1094 case CSA_VALUE_ENUMERATED:
1095 case CSA_VALUE_SINT32:
1096 sprintf(tmpbuf2, "%ld",
1097 attrs[i].value->item.sint32_value);
1100 case CSA_VALUE_BOOLEAN:
1101 case CSA_VALUE_FLAGS:
1102 case CSA_VALUE_UINT32:
1103 sprintf(tmpbuf2, "%lu",
1104 attrs[i].value->item.uint32_value);
1107 case CSA_VALUE_STRING:
1108 case CSA_VALUE_DATE_TIME:
1109 case CSA_VALUE_DATE_TIME_RANGE:
1110 case CSA_VALUE_TIME_DURATION:
1111 case CSA_VALUE_CALENDAR_USER:
1112 if (attrs[i].value->item.string_value) {
1113 if ((ptr = cr_to_str(attrs[i].value->\
1115 strlen(attrs[i].value->item.string_value)))
1126 case CSA_VALUE_REMINDER:
1127 opq = &attrs[i].value->item.reminder_value->\
1129 if (attrs[i].value->item.reminder_value->repeat_count
1132 sprintf(tmpbuf2, "%s:%s:%lu:%lu:",
1133 attrs[i].value->item.reminder_value->lead_time,
1134 (attrs[i].value->item.reminder_value->snooze_time ?
1135 attrs[i].value->item.reminder_value->snooze_time:""),
1136 attrs[i].value->item.reminder_value->repeat_count,
1139 sprintf(tmpbuf2, "%s:%lu:",
1140 attrs[i].value->item.reminder_value->lead_time,
1144 if (opq->size > 0) {
1145 if ((ptr = cr_to_str((char *)opq->data,
1146 opq->size)) == NULL) {
1156 case CSA_VALUE_OPAQUE_DATA:
1157 opq = attrs[i].value->item.opaque_data_value;
1158 sprintf(tmpbuf2, "%lu:", opq->size);
1160 if (opq->size > 0) {
1161 if ((ptr = cr_to_str((char *)opq->data,
1162 opq->size)) == NULL) {
1171 case CSA_VALUE_ACCESS_LIST:
1172 if (attrs[i].value->item.access_list_value) {
1173 if ((ptr = get_access_list_string(
1174 attrs[i].value->item.access_list_value))
1184 case CSA_VALUE_DATE_TIME_LIST:
1185 if (attrs[i].value->item.date_time_list_value) {
1186 if ((ptr = get_date_time_list_string(
1187 attrs[i].value->item.date_time_list_value))
1198 count += strlen(tmpbuf) + strlen(tmpbuf2) +
1199 (body ? strlen(body) : 0) + 3; /* closing */
1200 if (tcount < count) {
1201 if ((ptr = realloc(buf, tcount+BUFSIZ)) == NULL) {
1202 if (body) free(body);
1209 strcat(buf, tmpbuf);
1210 if (*tmpbuf2 != NULL) strcat(buf, tmpbuf2);
1211 if (body) strcat(buf, body);
1212 strcat(buf, "\")\n");
1213 if (body) free(body);
1220 get_access_list_string(cms_access_entry *list)
1222 char *ptr = NULL, *tptr, buf[BUFSIZ/4];
1225 /* do the first one */
1226 if ((ptr = malloc(BUFSIZ+1)) == NULL) return (NULL);
1228 sprintf(ptr, "%s:%u", list->user, list->rights);
1229 count = strlen(ptr);
1231 while (list->next) {
1233 sprintf(buf, " %s:%u", list->user, list->rights);
1235 count += strlen(buf);
1236 if (tcount < count) {
1237 if ((tptr = grow_n_concat(ptr, buf, tcount+BUFSIZ))
1251 cr_to_str(char *s, int size)
1259 if ((newstr = (char *) calloc(1, (unsigned)((2 * size) + 2))) == NULL)
1262 for (j=0; j<size; j++) {
1268 else if (s[j]=='\\') {
1273 else if (s[j]=='\"') {
1288 get_date_time_list_string(CSA_date_time_list list)
1290 char *ptr = NULL, *tptr, buf[80];
1291 int count, datestrlen, tcount;
1293 /* do the first one */
1294 sprintf(buf, "%s", list->date_time);
1295 if ((ptr = strdup(buf)) == NULL)
1298 if ((ptr = malloc(BUFSIZ+1)) == NULL) return (NULL);
1300 strcpy(ptr, list->date_time);
1301 count = strlen(ptr);
1303 datestrlen = count + 1;
1304 while (list->next) {
1306 sprintf(buf, " %s", list->date_time);
1308 count += datestrlen;
1309 if (tcount < count) {
1310 if ((tptr = grow_n_concat(ptr, buf, tcount+BUFSIZ))