1 /* $XConsortium: log.c /main/8 1996/11/21 19:45:13 drk $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994 International Business Machines Corp.
5 * (c) Copyright 1993, 1994 Novell, Inc.
6 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
18 #define XOS_USE_NO_LOCKING
19 #define X_INCLUDE_TIME_H
20 #include <X11/Xos_r.h>
26 extern uid_t daemon_uid;
27 extern gid_t daemon_gid;
30 static char *spool_dir = _DtCMS_DEFAULT_DIR;
32 char *tag_string[] = {
52 * forward declaration of functions used within this file
54 static char * cr_to_str(char *s, int size);
55 static void periodtostr(Interval_4 i, char *q);
56 static void privacytostr(Privacy_Level_4 p, char *q);
57 static void apptstatustostr(Appt_Status_4 p, char *q);
58 static void apptstatustostr(Appt_Status_4 p, char *q);
59 static void tagstostr(Event_Type_4 p, char *q);
60 static char * get_fname (char *dir, char *fname, char *who);
61 static CSA_return_code append_log(int f, char *buf);
62 static CSA_return_code create_log(char *owner, char *file, int version);
63 static char *attrs_to_attrliststr(int len, cms_attribute *attrs,
64 boolean_t write_hash, boolean_t entryattrs);
65 static char *grow_n_concat(char *base, char *newstr, int newcount);
66 static char *get_access_list_string(cms_access_entry *list);
67 static char *get_date_time_list_string(CSA_date_time_list list);
75 _DtCmsGetLogFN(char *who)
77 return (get_fname (spool_dir, _DtCMS_DEFAULT_LOG, who));
81 _DtCmsGetBakFN(char *who)
83 return (get_fname (spool_dir, _DtCMS_DEFAULT_BAK, who));
87 _DtCmsGetTmpFN(char *who)
89 return (get_fname (spool_dir, _DtCMS_DEFAULT_TMP, who));
93 _DtCmsGetDelFN(char *who)
95 return (get_fname (spool_dir, _DtCMS_DEFAULT_DEL, who));
98 extern CSA_return_code
99 _DtCmsCreateLogV1(char *owner, char *file)
101 return (create_log(owner, file, _DtCMS_VERSION1));
105 extern CSA_return_code
106 _DtCmsAppendHTableByFN(char *file, uint size, char **names, int *types)
109 CSA_return_code stat;
111 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
113 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
116 stat = _DtCmsAppendHTableByFD(f, size, names, types);
123 * the first element of the arrays is not used
125 extern CSA_return_code
126 _DtCmsAppendHTableByFD(int fd, uint size, char **names, int *types)
128 CSA_return_code stat;
129 char *tptr, *buf, tmpbuf[BUFSIZ/4];
130 int i, tcount, count = 15; /* strlen("(entrytable )\n") + 1 */
132 if ((buf = malloc(BUFSIZ)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY);
134 strcpy(buf, "(entrytable ");
136 for (i = 1; i <= size; i++) {
137 sprintf(tmpbuf, "(%d \"%s\" \"%s\")\n", i, names[i],
138 tag_string[types[i]]);
140 count += strlen(tmpbuf);
141 if (tcount < count) {
142 if ((tptr = grow_n_concat(buf, tmpbuf, tcount + BUFSIZ))
145 return (CSA_E_INSUFFICIENT_MEMORY);
155 stat = append_log(fd, buf);
161 extern CSA_return_code
162 _DtCmsAppendEntryByFN(char *file, cms_entry *entry, _DtCmsLogOps op)
165 CSA_return_code stat;
167 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
169 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
172 stat = _DtCmsAppendEntryByFD(f, entry, op);
178 extern CSA_return_code
179 _DtCmsAppendEntryByFD(int f, cms_entry *entry, _DtCmsLogOps op)
181 CSA_return_code stat;
183 char *cptr, *tptr, *buf;
186 if ((buf = malloc(100)) == NULL) return (CSA_E_INSUFFICIENT_MEMORY);
188 _csa_tick_to_iso8601(entry->key.time, isotime);
189 sprintf(buf, "(%s \"%s\" key: %ld%s",
190 (op == _DtCmsLogAdd ? "add" : "remove"),
191 isotime, entry->key.id,
192 (op == _DtCmsLogAdd ? "\nhashedattributes: (" : ""));
193 count = strlen(buf) + 4;
195 if (op == _DtCmsLogAdd && entry->num_attrs > 0) {
196 if ((cptr = attrs_to_attrliststr(entry->num_attrs,
197 entry->attrs, B_TRUE, B_TRUE)) == NULL) {
199 return (CSA_E_INSUFFICIENT_MEMORY);
201 count += strlen(cptr);
202 if ((tptr = grow_n_concat(buf, cptr, count)) == NULL) {
205 return (CSA_E_INSUFFICIENT_MEMORY);
211 /* closing for attr list and closing for entry */
212 if (op == _DtCmsLogAdd)
217 stat = append_log(f, buf);
223 extern CSA_return_code
224 _DtCmsAppendCalAttrsByFN(char *file, int size, cms_attribute * attrs)
227 CSA_return_code stat;
229 if (file == NULL || size <= 0)
230 return (CSA_E_INVALID_PARAMETER);
232 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
234 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
237 stat = _DtCmsAppendCalAttrsByFD(f, size, attrs);
243 extern CSA_return_code
244 _DtCmsAppendCalAttrsByFD(int f, int size, cms_attribute * attrs)
246 CSA_return_code stat;
248 char *prefix = "(calendarattributes ";
249 char *subfix = ")\n";
252 if ((attrstr = attrs_to_attrliststr(size, attrs, B_FALSE, B_FALSE))
254 return (CSA_E_INSUFFICIENT_MEMORY);
256 count = strlen(prefix) + strlen(attrstr) + strlen(subfix) + 1;
257 if ((buf = malloc(count)) == NULL) {
259 return (CSA_E_INSUFFICIENT_MEMORY);
261 sprintf(buf, "%s%s%s", prefix, attrstr, subfix);
263 stat = append_log(f, buf);
270 extern CSA_return_code
271 _DtCmsAppendAppt4ByFN(char *file, Appt_4 *appt, _DtCmsLogOps op)
274 CSA_return_code stat;
276 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
278 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
281 stat = _DtCmsAppendAppt4ByFD(f, appt, op);
287 extern CSA_return_code
288 _DtCmsAppendAppt4ByFD(int f, Appt_4 *appt, _DtCmsLogOps op)
292 char buf[BUFSIZ*3], buf2[BUFSIZ*2]; /* 1 BUFSIZ for what fields,
293 1 BUFSIZ for mailto field,
294 and 1 BUFSIZ for the rest */
296 cptr = ctime (&appt->appt_id.tick);
297 cptr[24] = NULL; /* strip off CR */
302 sprintf(buf, "(add \"%s\" key: %ld ", cptr, appt->appt_id.key);
304 cptr = cr_to_str(appt->what, strlen(appt->what));
306 sprintf(buf2, "what: \"%s\" ", cptr);
310 return (CSA_E_INSUFFICIENT_MEMORY);
313 if (appt->client_data) {
314 sprintf(buf2, "details: \"%s\" ", appt->client_data);
317 if (appt->duration) {
318 sprintf(buf2, "duration: %d ", appt->duration);
322 periodtostr (appt->period.period, tmpbuf);
323 sprintf(buf2, "period: %s ", tmpbuf);
326 if (appt->period.nth != 0) {
327 sprintf (buf2, "nth: %d ", appt->period.nth);
330 if (appt->period.enddate != 0) {
331 cptr = ctime (&(appt->period.enddate));
332 cptr[24] = NULL; /* strip off CR */
333 sprintf(buf2, "enddate: \"%s\" ", cptr);
337 sprintf(buf2, "ntimes: %d ", appt->ntimes);
340 if (appt->exception != NULL) {
341 struct Except_4 *e = appt->exception;
342 strcat(buf, "exceptions: (");
344 sprintf(buf2, "%d ", e->ordinal);
351 if (appt->author != NULL) {
352 sprintf(buf2, "author: \"%s\" ", appt->author);
355 if (appt->attr != NULL) {
356 struct Attribute_4 *item = appt->attr;
357 strcat(buf, "attributes: (");
358 while(item != NULL) {
359 sprintf(buf2, "(\"%s\",\"%s\",\"%s\")",
360 item->attr, item->value,
367 if (appt->tag != NULL) {
368 struct Tag_4 *item = appt->tag;
369 strcat(buf, "tags: (");
370 while(item != NULL) {
371 tagstostr(item->tag, tmpbuf);
372 sprintf(buf2, "(%s , %d)", tmpbuf,
380 apptstatustostr(appt->appt_status, tmpbuf);
381 sprintf(buf2, "apptstat: %s ", tmpbuf);
384 privacytostr(appt->privacy, tmpbuf);
385 sprintf(buf2, "privacy: %s )\n", tmpbuf);
390 case _DtCmsLogRemove:
391 sprintf(buf, "(remove \"%s\" key: %ld)\n", cptr,
396 return (append_log(f, buf));
399 extern CSA_return_code
400 _DtCmsAppendAccessByFN(char *file, int type, Access_Entry_4 *p)
403 CSA_return_code stat;
405 if ((f = open(file, O_WRONLY | O_APPEND | O_SYNC)) < 0) {
407 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
410 stat = _DtCmsAppendAccessByFD(f, type, p);
416 extern CSA_return_code
417 _DtCmsAppendAccessByFD(int f, int type, Access_Entry_4 *p)
419 CSA_return_code stat;
420 int count = 12; /* (access )\n */
424 if (type == access_read_4)
426 else if (type == access_write_4)
428 else if (type == access_delete_4)
430 else if (type == access_exec_4)
433 return (CSA_E_INVALID_PARAMETER);
435 count = count + strlen(p_type);
436 if ((buf = malloc(count)) == NULL)
437 return (CSA_E_INSUFFICIENT_MEMORY);
439 sprintf(buf, "(access %s ", p_type);
442 if (p->who != NULL) {
443 count = count + strlen(p->who) + 3;
444 if ((buf = realloc(buf, count)) == NULL)
445 return (CSA_E_INSUFFICIENT_MEMORY);
456 stat = append_log(f, buf);
463 _DtCmsPrintAppt4(caddr_t data)
465 Appt_4 *appt = (Appt_4 *)data;
469 fprintf(stderr, "*** V4 appointement: ***\n\n");
471 tmstr = ctime (&appt->appt_id.tick);
472 tmstr[24] = NULL; /* strip off CR */
474 if (fprintf(stderr, "(add \"%s\" ", tmstr)==EOF) {
477 if (fprintf(stderr, "key: %ld ", appt->appt_id.key)==EOF) {
481 tmstr = cr_to_str(appt->what, strlen(appt->what));
482 if (fprintf(stderr, "what: \"%s\" ", tmstr) == EOF) {
488 if (appt->client_data) {
489 if (fprintf(stderr, "details: \"%s\" ", appt->client_data)
493 if (appt->duration) {
494 if (fprintf(stderr, "duration: %d ", appt->duration) == EOF)
499 periodtostr (appt->period.period, buf);
500 if (fprintf(stderr, "period: %s ", buf) == EOF)
503 if (appt->period.nth != 0) {
504 if (fprintf (stderr, "nth: %d ", appt->period.nth) == EOF)
507 if (appt->period.enddate != 0) {
508 tmstr = ctime (&(appt->period.enddate));
509 tmstr[24] = NULL; /* strip off CR */
510 if (fprintf(stderr, "enddate: \"%s\" ", tmstr) == EOF)
514 if (fprintf(stderr, "ntimes: %d ", appt->ntimes) == EOF)
517 if (appt->exception != NULL) {
518 struct Except_4 *e = appt->exception;
519 if (fprintf(stderr, "exceptions: (") == EOF)
522 if (fprintf(stderr, "%d ", e->ordinal) == EOF)
526 if (fprintf(stderr, ") ") == EOF)
529 if (appt->author != NULL) {
530 if (fprintf(stderr, "author: \"%s\" ", appt->author) == EOF)
533 if (appt->attr != NULL) {
534 struct Attribute_4 *item = appt->attr;
535 if (fprintf(stderr, "attributes: (") == EOF)
537 while(item != NULL) {
538 if (fprintf(stderr, "(\"%s\",\"%s\",\"%s\")",
539 item->attr, item->value, item->clientdata) == EOF)
543 if (fprintf(stderr, ") ") == EOF)
546 if (appt->tag != NULL) {
547 struct Tag_4 *item = appt->tag;
548 if (fprintf(stderr, "tags: (") == EOF)
550 while(item != NULL) {
552 tagstostr(item->tag, buf);
553 if (fprintf(stderr, "(%s , %d)", buf, item->showtime)
558 if (fprintf(stderr, ") ") == EOF)
564 apptstatustostr(appt->appt_status, buf);
565 if (fprintf(stderr, "apptstat: %s ", buf) == EOF)
569 privacytostr(appt->privacy, buf);
570 if (fprintf(stderr, "privacy: %s )\n", buf) == EOF)
577 _DtCmsPrintExceptions(int len, int *exceptions)
581 fprintf(stderr, "\nexception part:\n");
582 fprintf(stderr, "number of exception = %d\n", len);
583 fprintf(stderr, "exceptions:");
584 for (i = 0; i < len; i++) {
585 fprintf(stderr, " %d", exceptions[i]);
587 fprintf(stderr, "\n");
590 extern CSA_return_code
591 _DtCmsCreateLogV2(char *owner, char *file)
593 return (create_log(owner, file, _DtCMS_VERSION4));
596 extern CSA_return_code
597 _DtCmsGetFileSize(char *calendar, int *size)
602 if ((log = _DtCmsGetLogFN(calendar)) == NULL)
603 return (CSA_E_INSUFFICIENT_MEMORY);
605 if (stat(log, &info) != 0) {
607 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
609 *size = info.st_size;
611 return (CSA_SUCCESS);
616 _DtCmsTruncateFile(char *calendar, int size)
621 if ((log = _DtCmsGetLogFN(calendar)) == NULL)
624 /* truncate log file to specified size */
625 if ((f = open(log, O_RDWR | O_APPEND | O_SYNC)) >= 0)
631 extern CSA_return_code
632 _DtCmsRemoveLog(char *calendar, char *user)
634 CSA_return_code stat = CSA_SUCCESS;
637 if ((log = _DtCmsGetLogFN(calendar)) == NULL)
638 return (CSA_E_INSUFFICIENT_MEMORY);
640 if ((dlog = _DtCmsGetDelFN(calendar)) == NULL) {
642 return (CSA_E_INSUFFICIENT_MEMORY);
645 if (rename(log, dlog) < 0)
646 stat = CSA_X_DT_E_BACKING_STORE_PROBLEM;
654 extern CSA_return_code
655 _DtCmsWriteVersionString(char *file, int version)
662 CSA_return_code stat = CSA_SUCCESS;
663 _Xltimeparams localtime_buf;
664 _Xatimeparams asctime_buf;
666 tmval = time((time_t *) 0);
667 tm = _XLocaltime(&tmval, localtime_buf);
668 tmstr = _XAsctime(tm, asctime_buf);
669 tmstr[24] = NULL; /* strip off CR */
671 if ((fd = open(file, O_WRONLY|O_TRUNC|O_SYNC)) < 0) {
673 fprintf(stderr, "%s: failed to open %s in %s\n",
674 pgname, file, _DtCmsWriteVersionString);
675 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
678 sprintf(buf, "Version: %d\n**** start of log on %s ****\n\n",
682 if (write(fd, buf, len) != len) {
684 stat = CSA_X_DT_E_BACKING_STORE_PROBLEM;
692 * if everything works fine, return 0; otherwise, return -1
700 boolean_t changeeuid,
706 if (changeeuid == B_TRUE) {
716 if (chmod (file, mode) < 0) {
717 if (printerr == B_TRUE) {
719 sprintf (buff, "%s: chmod %s to %lo failed.\n%s: System error",
720 pgname, file, (long)mode, pgname);
727 if (chown (file, uid, gid) < 0) {
728 if (printerr == B_TRUE) {
730 sprintf (buff, "%s: chown %s to (uid=%ld,gid=%ld) failed.\n%s%s",
731 pgname, file, (long)uid, (long)gid, pgname, ": System error");
740 if (changeeuid == B_TRUE && setuid (daemon_uid) < 0)
742 if (changeeuid == B_TRUE && seteuid (daemon_uid) < 0)
745 if (printerr == B_TRUE) {
747 sprintf (buff, "%s: Can't switch process uid back to daemon.\n%s%s",
748 pgname, pgname, ": System error");
759 periodtostr(Interval_4 i, char *q)
765 strcpy (q, "single");
771 strcpy (q, "weekly");
774 strcpy (q, "biweekly");
777 strcpy (q, "monthly");
780 strcpy (q, "yearly");
783 strcpy (q, "nthWeekday");
786 strcpy (q, "everyNthDay");
789 strcpy (q, "everyNthWeek");
791 case everyNthMonth_4:
792 strcpy (q, "everyNthMonth");
795 strcpy (q, "monThruFri");
798 strcpy (q, "monWedFri");
801 strcpy (q, "tueThur");
804 strcpy (q, "daysOfWeek");
807 strcpy (q, "single");
813 privacytostr(Privacy_Level_4 p, char *q)
822 strcpy(q, "private");
825 strcpy(q, "semiprivate");
834 apptstatustostr(Appt_Status_4 p, char *q)
843 strcpy(q, "pendingAdd");
845 case pendingDelete_4:
846 strcpy(q, "pendingDelete");
849 strcpy(q, "committed");
852 strcpy(q, "cancelled");
855 strcpy(q, "completed");
864 tagstostr(Event_Type_4 p, char *q)
870 strcpy(q, "appointment");
873 strcpy(q, "reminder");
876 strcpy(q, "otherTag");
879 strcpy(q, "holiday");
885 strcpy(q, "appointment");
891 get_fname (char *dir, char *fname, char *who)
895 buf = (char *)malloc(strlen(dir) + strlen(fname) + strlen(who) + 3);
897 sprintf (buf, "%s/%s.%s", dir, fname, who);
901 static CSA_return_code
902 create_log(char *owner, char *file, int version)
908 CSA_return_code stat;
910 ptr = strchr(owner, '@');
911 if (ptr) *ptr = NULL;
912 pw = getpwnam (owner);
915 return(CSA_E_FAILURE);
919 /* Read by owner and Read/Write by group (gid must be daemon) */
920 fd = open(file, O_WRONLY|O_CREAT|O_EXCL, _DtCMS_DEFAULT_MODE);
923 fprintf(stderr, "%s: can't create %s\n", pgname, file);
926 return(CSA_E_CALENDAR_EXISTS);
928 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
931 if (_DtCmsSetFileMode(file, uid, daemon_gid, _DtCMS_DEFAULT_MODE,
932 B_TRUE, B_TRUE) < 0) {
935 return(CSA_X_DT_E_BACKING_STORE_PROBLEM);
939 if ((stat = _DtCmsWriteVersionString(file, version)) != CSA_SUCCESS) {
946 static CSA_return_code
947 append_log(int f, char *buf)
949 CSA_return_code status;
951 int file_size = 0, nbytes_written = 0, nbytes_towrite = 0;
954 return (CSA_E_INVALID_PARAMETER);
956 if (fstat(f, &finfo) < 0) {
958 return (CSA_X_DT_E_BACKING_STORE_PROBLEM);
960 file_size = finfo.st_size;
962 nbytes_towrite = strlen(buf);
963 nbytes_written = write(f, buf, nbytes_towrite);
964 if (nbytes_written != nbytes_towrite) {
966 status = CSA_E_DISK_FULL;
968 status = CSA_X_DT_E_BACKING_STORE_PROBLEM;
971 ftruncate(f, file_size);
979 grow_n_concat(char *base, char *newstr, int newcount)
983 if ((ptr = realloc(base, newcount)) == NULL)
995 * format of attributes:
996 * CSA_VALUE_BOOLEAN: ("name","type","number")
997 * CSA_VALUE_ENUMERATED: ("name","type","number")
998 * CSA_VALUE_FLAGS: ("name","type","number")
999 * CSA_VALUE_SINT32: ("name","type","number")
1000 * CSA_VALUE_UINT32: ("name","type","number")
1001 * CSA_VALUE_STRING: ("name","type","string")
1002 * CSA_VALUE_ACCESS_LIST: ("name","type","user:rights [user:rights]")
1003 * CSA_VALUE_CALENDAR_USER: ("name","type","string")
1004 * CSA_VALUE_DATE_TIME: ("name","type","datetime")
1005 * CSA_VALUE_DATE_TIME_RANGE: ("name","type","datetimerange")
1006 * CSA_VALUE_TIME_DURATION: ("name","type","timeduration")
1007 * CSA_VALUE_DATE_TIME_LIST: ("name","type","datetime [datetime]")
1008 * CSA_VALUE_REMINDER: ("name","type","string:number:string") or
1009 * ("name","type","string:string:number:number:string")
1010 * CSA_VALUE_OPAQUE_DATA: ("name","type","number:string")
1012 * format of attributes (when only hashed number is written):
1013 * CSA_VALUE_BOOLEAN: (hash_number "number")
1014 * CSA_VALUE_ENUMERATED: (hash_number "number")
1015 * CSA_VALUE_FLAGS: (hash_number "number")
1016 * CSA_VALUE_SINT32: (hash_number "number")
1017 * CSA_VALUE_UINT32: (hash_number "number")
1018 * CSA_VALUE_STRING: (hash_number "string")
1019 * CSA_VALUE_ACCESS_LIST: (hash_number "user:rights [user:rights]")
1020 * CSA_VALUE_CALENDAR_USER: (hash_number "string")
1021 * CSA_VALUE_DATE_TIME: (hash_number "datetime")
1022 * CSA_VALUE_DATE_TIME_RANGE: (hash_number "datetimerange")
1023 * CSA_VALUE_TIME_DURATION: (hash_number "timeduration")
1024 * CSA_VALUE_DATE_TIME_LIST: (hash_number "datetime [datetime]")
1025 * CSA_VALUE_REMINDER: (hash_number "string:number:string") or
1026 * (hash_number "string:string:number:number:string")
1027 * CSA_VALUE_OPAQUE_DATA: (hash_number "number:string")
1029 * Note: element 0 of the array is not used
1032 attrs_to_attrliststr(
1034 cms_attribute *attrs,
1035 boolean_t write_hash,
1036 boolean_t entryattrs)
1038 int i, count, tcount;
1039 char *ptr, *buf = NULL;
1040 char tmpbuf[BUFSIZ/2], tmpbuf2[BUFSIZ/2], *body;
1041 CSA_opaque_data *opq;
1043 if ((buf = malloc(BUFSIZ+1)) == NULL) return (NULL);
1046 for (i = 1, count = 0, *buf = NULL; i <= num_attr; i++) {
1048 if (attrs[i].value == NULL || (entryattrs &&
1049 (i == CSA_ENTRY_ATTR_NUMBER_RECURRENCES_I ||
1050 i == CSA_X_DT_ENTRY_ATTR_REPEAT_TYPE_I ||
1051 i == CSA_X_DT_ENTRY_ATTR_REPEAT_TIMES_I ||
1052 i == CSA_X_DT_ENTRY_ATTR_REPEAT_INTERVAL_I ||
1053 i == CSA_X_DT_ENTRY_ATTR_REPEAT_OCCURRENCE_NUM_I ||
1054 i == CSA_X_DT_ENTRY_ATTR_SEQUENCE_END_DATE_I)))
1058 /* open_bracket hash_number open quote for value */
1059 sprintf(tmpbuf, "(%d \"", attrs[i].name.num);
1061 /* open bracket name, type, open quote for value */
1062 sprintf(tmpbuf, "(\"%s\",\"%s\",\"", attrs[i].name.name,
1063 tag_string[attrs[i].value->type]);
1068 switch (attrs[i].value->type) {
1069 case CSA_VALUE_ENUMERATED:
1070 case CSA_VALUE_SINT32:
1071 sprintf(tmpbuf2, "%ld",
1072 attrs[i].value->item.sint32_value);
1075 case CSA_VALUE_BOOLEAN:
1076 case CSA_VALUE_FLAGS:
1077 case CSA_VALUE_UINT32:
1078 sprintf(tmpbuf2, "%lu",
1079 attrs[i].value->item.uint32_value);
1082 case CSA_VALUE_STRING:
1083 case CSA_VALUE_DATE_TIME:
1084 case CSA_VALUE_DATE_TIME_RANGE:
1085 case CSA_VALUE_TIME_DURATION:
1086 case CSA_VALUE_CALENDAR_USER:
1087 if (attrs[i].value->item.string_value) {
1088 if ((ptr = cr_to_str(attrs[i].value->\
1090 strlen(attrs[i].value->item.string_value)))
1101 case CSA_VALUE_REMINDER:
1102 opq = &attrs[i].value->item.reminder_value->\
1104 if (attrs[i].value->item.reminder_value->repeat_count
1107 sprintf(tmpbuf2, "%s:%s:%lu:%lu:",
1108 attrs[i].value->item.reminder_value->lead_time,
1109 (attrs[i].value->item.reminder_value->snooze_time ?
1110 attrs[i].value->item.reminder_value->snooze_time:""),
1111 attrs[i].value->item.reminder_value->repeat_count,
1114 sprintf(tmpbuf2, "%s:%lu:",
1115 attrs[i].value->item.reminder_value->lead_time,
1119 if (opq->size > 0) {
1120 if ((ptr = cr_to_str((char *)opq->data,
1121 opq->size)) == NULL) {
1131 case CSA_VALUE_OPAQUE_DATA:
1132 opq = attrs[i].value->item.opaque_data_value;
1133 sprintf(tmpbuf2, "%lu:", opq->size);
1135 if (opq->size > 0) {
1136 if ((ptr = cr_to_str((char *)opq->data,
1137 opq->size)) == NULL) {
1146 case CSA_VALUE_ACCESS_LIST:
1147 if (attrs[i].value->item.access_list_value) {
1148 if ((ptr = get_access_list_string(
1149 attrs[i].value->item.access_list_value))
1159 case CSA_VALUE_DATE_TIME_LIST:
1160 if (attrs[i].value->item.date_time_list_value) {
1161 if ((ptr = get_date_time_list_string(
1162 attrs[i].value->item.date_time_list_value))
1173 count += strlen(tmpbuf) + strlen(tmpbuf2) +
1174 (body ? strlen(body) : 0) + 3; /* closing */
1175 if (tcount < count) {
1176 if ((ptr = realloc(buf, tcount+BUFSIZ)) == NULL) {
1177 if (body) free(body);
1184 strcat(buf, tmpbuf);
1185 if (*tmpbuf2 != NULL) strcat(buf, tmpbuf2);
1186 if (body) strcat(buf, body);
1187 strcat(buf, "\")\n");
1188 if (body) free(body);
1195 get_access_list_string(cms_access_entry *list)
1197 char *ptr = NULL, *tptr, buf[BUFSIZ/4];
1200 /* do the first one */
1201 if ((ptr = malloc(BUFSIZ+1)) == NULL) return (NULL);
1203 sprintf(ptr, "%s:%u", list->user, list->rights);
1204 count = strlen(ptr);
1206 while (list->next) {
1208 sprintf(buf, " %s:%u", list->user, list->rights);
1210 count += strlen(buf);
1211 if (tcount < count) {
1212 if ((tptr = grow_n_concat(ptr, buf, tcount+BUFSIZ))
1226 cr_to_str(char *s, int size)
1234 if ((newstr = (char *) calloc(1, (unsigned)((2 * size) + 2))) == NULL)
1237 for (j=0; j<size; j++) {
1243 else if (s[j]=='\\') {
1248 else if (s[j]=='\"') {
1263 get_date_time_list_string(CSA_date_time_list list)
1265 char *ptr = NULL, *tptr, buf[80];
1266 int count, datestrlen, tcount;
1268 /* do the first one */
1269 sprintf(buf, "%s", list->date_time);
1270 if ((ptr = strdup(buf)) == NULL)
1273 if ((ptr = malloc(BUFSIZ+1)) == NULL) return (NULL);
1275 strcpy(ptr, list->date_time);
1276 count = strlen(ptr);
1278 datestrlen = count + 1;
1279 while (list->next) {
1281 sprintf(buf, " %s", list->date_time);
1283 count += datestrlen;
1284 if (tcount < count) {
1285 if ((tptr = grow_n_concat(ptr, buf, tcount+BUFSIZ))