127 const char *text,
const char *reply_to,
const char *encoding,
128 const char *afilename1,
const char *buffer1,
INT buffer_size1,
129 const char *afilename2,
const char *buffer2,
INT buffer_size2,
130 const char *afilename3,
const char *buffer3,
INT buffer_size3,
char *tag,
INT tag_size)
134 text, reply_to, encoding,
135 afilename1, buffer1, buffer_size1,
136 afilename2, buffer2, buffer_size2, afilename3, buffer3, buffer_size3, tag, tag_size);
142 char afile_name[3][256+256];
144 char start_str[80], end_str[80], last[80], date[80],
thread[80], attachment[256];
149 size_t message_size = 0;
155 bedit = (tag[0] != 0);
161 cm_msg(
MERROR,
"el_submit",
"Cannot lock experiment semaphore, ss_semaphore_wait_for() status %d",
status);
180 for (idx = 0; idx < 3; idx++) {
185 const char* buffer = NULL;
189 mstrlcpy(afilename, afilename1,
sizeof(afilename));
191 buffer_size = buffer_size1;
192 }
else if (idx == 1) {
193 mstrlcpy(afilename, afilename2,
sizeof(afilename));
195 buffer_size = buffer_size2;
196 }
else if (idx == 2) {
197 mstrlcpy(afilename, afilename3,
sizeof(afilename));
199 buffer_size = buffer_size3;
205 while (strchr(p,
':'))
206 p = strchr(p,
':') + 1;
207 while (strchr(p,
'\\'))
208 p = strchr(p,
'\\') + 1;
209 while (strchr(p,
'/'))
210 p = strchr(p,
'/') + 1;
211 while (strchr(p,
']'))
212 p = strchr(p,
']') + 1;
219 memset(dir, 0, size);
230 localtime_r(&now, &tms);
233 mstrlcpy(
str, p,
sizeof(
str));
234 sprintf(afile_name[idx],
"%02d%02d%02d_%02d%02d%02d_%s",
235 tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday,
236 tms.tm_hour, tms.tm_min, tms.tm_sec,
str);
237 sprintf(
file_name,
"%s%02d%02d%02d_%02d%02d%02d_%s", dir,
238 tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday,
239 tms.tm_hour, tms.tm_min, tms.tm_sec,
str);
244 cm_msg(
MERROR,
"el_submit",
"Cannot write attachment file \"%s\", open() returned %d, errno %d (%s)",
file_name, fh, errno, strerror(errno));
257 memset(dir, 0, size);
272 mstrlcpy(
str, tag,
sizeof(
str));
273 if (strchr(
str,
'.')) {
275 *strchr(
str,
'.') = 0;
283 lseek(fh,
offset, SEEK_SET);
286 if (strncmp(
str,
"$Start$", 7) != 0) {
292 size = atoi(
str + 9);
295 cm_msg(
MERROR,
"el_submit",
"cannot read from \'%s\', corrupted file: bad size %d in \"%s\"",
file_name, size,
str);
303 cm_msg(
MERROR,
"el_submit",
"cannot read from \'%s\', corrupted file: bad size %d in \"%s\", cannot malloc(%d): errno %d (%s)",
file_name, size,
str, size, errno, strerror(errno));
322 lseek(fh, 0, SEEK_END);
328 buffer = (
char *)
M_MALLOC(tail_size);
329 if (buffer == NULL) {
335 lseek(fh,
offset + size, SEEK_SET);
340 lseek(fh,
offset, SEEK_SET);
345 localtime_r(&now, &tms);
347 sprintf(
file_name,
"%s%02d%02d%02d.log", dir, tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
355 assert(
sizeof(date) >= 32);
360 sprintf(
thread,
"%16s %16s", reply_to,
"0");
362 sprintf(
thread,
"%16s %16s",
"0",
"0");
364 lseek(fh, 0, SEEK_END);
368 message_size += strlen(date);
369 message_size += strlen(author);
370 message_size += strlen(
type);
371 message_size += strlen(syst);
372 message_size += strlen(subject);
373 message_size += strlen(attachment);
374 message_size += strlen(afile_name[0]);
375 message_size += strlen(afile_name[1]);
376 message_size += strlen(afile_name[2]);
377 message_size += strlen(encoding);
378 message_size += strlen(text);
382 message = (
char*)malloc(message_size);
385 cm_msg(
MERROR,
"el_submit",
"cannot malloc() %d bytes: errno %d (%s)", size, errno, strerror(errno));
392 sprintf(
message,
"Date: %s\n", date);
401 if (bedit && afile_name[0][0] == 0 && afile_name[1][0] == 0 && afile_name[2][0] == 0)
404 sprintf(
message + strlen(
message),
"Attachment: %s", afile_name[0]);
405 if (afile_name[1][0])
407 if (afile_name[2][0])
413 sprintf(
message + strlen(
message),
"========================================\n");
416 assert(strlen(
message) < message_size);
419 sprintf(start_str,
"$Start$: %6d\n", size);
420 sprintf(end_str,
"$End$: %6d\n\f", size);
422 size = strlen(
message) + strlen(start_str) + strlen(end_str);
424 if (tag != NULL && !bedit) {
425 sprintf(tag,
"%02d%02d%02d.%d", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday, (
int)
TELL(fh));
429 assert(size < 999999);
431 sprintf(start_str,
"$Start$: %6d\n", size);
432 sprintf(end_str,
"$End$: %6d\n\f", size);
450 chsize(fh,
TELL(fh));
459 if (reply_to[0] && !bedit) {
460 strcpy(last, reply_to);
466 lseek(fh, 72, SEEK_CUR);
468 memset(
str, 0,
sizeof(
str));
470 lseek(fh, -16, SEEK_CUR);
473 if (atoi(
str) == 0) {
474 sprintf(
str,
"%16s", tag);
480 strcpy(last, strtok(
str,
" "));
506 time_t lt, ltime=0, lact;
516 if (xfilename && xfilename_size > 0)
523 memset(dir, 0, size);
533 if (strpbrk(tag,
"+-")) {
534 direction = atoi(strpbrk(tag,
"+-"));
535 *strpbrk(tag,
"+-") = 0;
541 memset(&tms, 0,
sizeof(
struct tm));
542 tms.tm_year = (tag[0] -
'0') * 10 + (tag[1] -
'0');
543 tms.tm_mon = (tag[2] -
'0') * 10 + (tag[3] -
'0') - 1;
544 tms.tm_mday = (tag[4] -
'0') * 10 + (tag[5] -
'0');
547 if (tms.tm_year < 90)
552 if (strchr(
str,
'.')) {
554 *strchr(
str,
'.') = 0;
559 localtime_r(<ime, &tms);
561 sprintf(
file_name,
"%s%02d%02d%02d.log", dir, tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
564 mstrlcpy(xfilename,
file_name, xfilename_size);
578 localtime_r(<ime, &tms);
579 sprintf(tag,
"%02d%02d%02d.0", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
583 if (direction != -1 && ltime > time(NULL) + 3600 * 24)
587 if (direction == -1 && abs((
INT) lt - (
INT) ltime) > 3600 * 24 * 365 * 10)
595 lseek(*fh,
offset, SEEK_SET);
604 if (strncmp(
str,
"$Start$: ", 9) != 0) {
609 lseek(*fh,
offset, SEEK_SET);
614 time((time_t *) <);
617 localtime_r(<ime, &tms);
619 sprintf(
file_name,
"%s%02d%02d%02d.log", dir, tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
622 mstrlcpy(xfilename,
file_name, xfilename_size);
629 }
while (*fh < 0 && (
INT) lt - (
INT) ltime < 3600 * 24 * 365);
635 sprintf(tag,
"%02d%02d%02d", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
637 lseek(*fh, 0, SEEK_END);
639 sprintf(tag + strlen(tag),
".%d", (
int)
TELL(*fh));
643 if (direction == -1) {
646 if (
TELL(*fh) == 0) {
653 localtime_r(<, &tms);
654 sprintf(
str,
"%02d%02d%02d.0", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
659 mstrlcpy(xfilename,
file_name, xfilename_size);
670 lseek(*fh, 0, SEEK_END);
674 lseek(*fh, -17, SEEK_CUR);
681 if (strncmp(
str,
"$End$: ", 7) != 0) {
691 size = atoi(
str + 7);
697 lseek(*fh, -size, SEEK_CUR);
700 sprintf(strchr(tag,
'.') + 1,
"%d", (
int)
TELL(*fh));
703 if (direction == 1) {
714 lseek(*fh, -15, SEEK_CUR);
716 if (strncmp(
str,
"$Start$: ", 9) != 0) {
726 size = atoi(
str + 9);
733 lseek(*fh, size, SEEK_CUR);
739 time((time_t *) &lact);
744 localtime_r(<, &tms);
745 sprintf(
str,
"%02d%02d%02d.0", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
750 mstrlcpy(xfilename,
file_name, xfilename_size);
761 lseek(*fh, 0, SEEK_SET);
763 lseek(*fh, -15, SEEK_CUR);
766 sprintf(strchr(tag,
'.') + 1,
"%d", (
int)
TELL(*fh));
775 char *syst,
char *subject,
char *text,
int *
textsize,
776 char *orig_tag,
char *reply_tag,
777 char *attachment1,
char *attachment2,
char *attachment3,
char *encoding)
809 int size, fh = 0, search_status, rd;
812 char attachment_all[3*256+100];
814 size_t message_size = 0;
820 return search_status;
826 return search_status;
841 size = atoi(
str + 9);
843 if ((strncmp(
str,
"$Start$:", 8) != 0) || (size <= 15)) {
844 cm_msg(
MERROR,
"el_retrieve",
"cannot read from \'%s\', corrupted file: no $Start$ or bad size in \"%s\"", filename,
str);
849 message_size = size + 1;
850 message = (
char*)malloc(message_size);
853 cm_msg(
MERROR,
"el_retrieve",
"cannot read from \'%s\', cannot malloc() %d bytes, errno %d (%s)", filename, (
int)message_size, errno, strerror(errno));
859 memset(
message, 0, message_size);
862 if (rd <= 0 || !((rd + 15 == size) || (rd == size))) {
863 cm_msg(
MERROR,
"el_retrieve",
"cannot read from \'%s\', read(%d) returned %d, errno %d (%s)", filename, size, rd, errno, strerror(errno));
885 if (attachment1 && attachment2 && attachment3) {
886 attachment1[0] = attachment2[0] = attachment3[0] = 0;
887 p = strtok(attachment_all,
",");
889 mstrlcpy(attachment1, p, 256);
890 p = strtok(NULL,
",");
892 mstrlcpy(attachment2, p, 256);
893 p = strtok(NULL,
",");
895 mstrlcpy(attachment3, p, 256);
901 if (orig_tag != NULL && reply_tag != NULL) {
902 p = strtok(
thread,
" \r");
906 strcpy(orig_tag,
"");
907 p = strtok(NULL,
" \r");
909 strcpy(reply_tag, p);
911 strcpy(reply_tag,
"");
912 if (atoi(orig_tag) == 0)
914 if (atoi(reply_tag) == 0)
918 p = strstr(
message,
"========================================\n");
932 if (strstr(text,
"$End$"))
933 *strstr(text,
"$End$") = 0;
973 int actual_run=0, fh,
status;
976 tag[0] = return_tag[0] = 0;
988 if (strchr(tag,
'.') != NULL)
989 strcpy(strchr(tag,
'.'),
".0");
992 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
993 }
while (actual_run >=
run);
995 while (actual_run <
run) {
1005 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1008 strcpy(return_tag, tag);
INT el_retrieve(char *tag, char *date, int *run, char *author, char *type, char *syst, char *subject, char *text, int *textsize, char *orig_tag, char *reply_tag, char *attachment1, char *attachment2, char *attachment3, char *encoding)
INT el_submit(int run, const char *author, const char *type, const char *syst, const char *subject, const char *text, const char *reply_to, const char *encoding, const char *afilename1, const char *buffer1, INT buffer_size1, const char *afilename2, const char *buffer2, INT buffer_size2, const char *afilename3, const char *buffer3, INT buffer_size3, char *tag, INT tag_size)