125 const char *text,
const char *reply_to,
const char *encoding,
126 const char *afilename1,
const char *buffer1,
INT buffer_size1,
127 const char *afilename2,
const char *buffer2,
INT buffer_size2,
128 const char *afilename3,
const char *buffer3,
INT buffer_size3,
char *tag,
INT tag_size)
132 text, reply_to, encoding,
133 afilename1, buffer1, buffer_size1,
134 afilename2, buffer2, buffer_size2, afilename3, buffer3, buffer_size3, tag, tag_size);
140 char afile_name[3][256+256];
142 char start_str[80], end_str[80], last[80], date[80],
thread[80], attachment[256];
147 size_t message_size = 0;
153 bedit = (tag[0] != 0);
159 cm_msg(
MERROR,
"el_submit",
"Cannot lock experiment semaphore, ss_semaphore_wait_for() status %d",
status);
178 for (idx = 0; idx < 3; idx++) {
183 const char* buffer = NULL;
187 mstrlcpy(afilename, afilename1,
sizeof(afilename));
189 buffer_size = buffer_size1;
190 }
else if (idx == 1) {
191 mstrlcpy(afilename, afilename2,
sizeof(afilename));
193 buffer_size = buffer_size2;
194 }
else if (idx == 2) {
195 mstrlcpy(afilename, afilename3,
sizeof(afilename));
197 buffer_size = buffer_size3;
203 while (strchr(p,
':'))
204 p = strchr(p,
':') + 1;
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;
217 memset(dir, 0, size);
228 localtime_r(&now, &tms);
231 mstrlcpy(
str, p,
sizeof(
str));
232 sprintf(afile_name[idx],
"%02d%02d%02d_%02d%02d%02d_%s",
233 tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday,
234 tms.tm_hour, tms.tm_min, tms.tm_sec,
str);
235 sprintf(
file_name,
"%s%02d%02d%02d_%02d%02d%02d_%s", dir,
236 tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday,
237 tms.tm_hour, tms.tm_min, tms.tm_sec,
str);
242 cm_msg(
MERROR,
"el_submit",
"Cannot write attachment file \"%s\", open() returned %d, errno %d (%s)",
file_name, fh, errno, strerror(errno));
255 memset(dir, 0, size);
270 mstrlcpy(
str, tag,
sizeof(
str));
271 if (strchr(
str,
'.')) {
273 *strchr(
str,
'.') = 0;
281 lseek(fh,
offset, SEEK_SET);
284 if (strncmp(
str,
"$Start$", 7) != 0) {
290 size = atoi(
str + 9);
293 cm_msg(
MERROR,
"el_submit",
"cannot read from \'%s\', corrupted file: bad size %d in \"%s\"",
file_name, size,
str);
301 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));
320 lseek(fh, 0, SEEK_END);
326 buffer = (
char *)
M_MALLOC(tail_size);
327 if (buffer == NULL) {
333 lseek(fh,
offset + size, SEEK_SET);
338 lseek(fh,
offset, SEEK_SET);
343 localtime_r(&now, &tms);
345 sprintf(
file_name,
"%s%02d%02d%02d.log", dir, tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
353 assert(
sizeof(date) >= 32);
358 sprintf(
thread,
"%16s %16s", reply_to,
"0");
360 sprintf(
thread,
"%16s %16s",
"0",
"0");
362 lseek(fh, 0, SEEK_END);
366 message_size += strlen(date);
367 message_size += strlen(author);
368 message_size += strlen(
type);
369 message_size += strlen(syst);
370 message_size += strlen(subject);
371 message_size += strlen(attachment);
372 message_size += strlen(afile_name[0]);
373 message_size += strlen(afile_name[1]);
374 message_size += strlen(afile_name[2]);
375 message_size += strlen(encoding);
376 message_size += strlen(text);
380 message = (
char*)malloc(message_size);
383 cm_msg(
MERROR,
"el_submit",
"cannot malloc() %d bytes: errno %d (%s)", size, errno, strerror(errno));
390 sprintf(
message,
"Date: %s\n", date);
399 if (bedit && afile_name[0][0] == 0 && afile_name[1][0] == 0 && afile_name[2][0] == 0)
402 sprintf(
message + strlen(
message),
"Attachment: %s", afile_name[0]);
403 if (afile_name[1][0])
405 if (afile_name[2][0])
411 sprintf(
message + strlen(
message),
"========================================\n");
414 assert(strlen(
message) < message_size);
417 sprintf(start_str,
"$Start$: %6d\n", size);
418 sprintf(end_str,
"$End$: %6d\n\f", size);
420 size = strlen(
message) + strlen(start_str) + strlen(end_str);
422 if (tag != NULL && !bedit) {
423 sprintf(tag,
"%02d%02d%02d.%d", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday, (
int)
TELL(fh));
427 assert(size < 999999);
429 sprintf(start_str,
"$Start$: %6d\n", size);
430 sprintf(end_str,
"$End$: %6d\n\f", size);
448 chsize(fh,
TELL(fh));
457 if (reply_to[0] && !bedit) {
458 strcpy(last, reply_to);
464 lseek(fh, 72, SEEK_CUR);
466 memset(
str, 0,
sizeof(
str));
468 lseek(fh, -16, SEEK_CUR);
471 if (atoi(
str) == 0) {
472 sprintf(
str,
"%16s", tag);
478 strcpy(last, strtok(
str,
" "));
504 time_t lt, ltime=0, lact;
512 if (xfilename && xfilename_size > 0)
519 memset(dir, 0, size);
529 if (strpbrk(tag,
"+-")) {
530 direction = atoi(strpbrk(tag,
"+-"));
531 *strpbrk(tag,
"+-") = 0;
537 memset(&tms, 0,
sizeof(
struct tm));
538 tms.tm_year = (tag[0] -
'0') * 10 + (tag[1] -
'0');
539 tms.tm_mon = (tag[2] -
'0') * 10 + (tag[3] -
'0') - 1;
540 tms.tm_mday = (tag[4] -
'0') * 10 + (tag[5] -
'0');
543 if (tms.tm_year < 90)
548 if (strchr(
str,
'.')) {
550 *strchr(
str,
'.') = 0;
555 localtime_r(<ime, &tms);
557 sprintf(
file_name,
"%s%02d%02d%02d.log", dir, tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
560 mstrlcpy(xfilename,
file_name, xfilename_size);
574 localtime_r(<ime, &tms);
575 sprintf(tag,
"%02d%02d%02d.0", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
579 if (direction != -1 && ltime > time(NULL) + 3600 * 24)
583 if (direction == -1 && abs((
INT) lt - (
INT) ltime) > 3600 * 24 * 365 * 10)
591 lseek(*fh,
offset, SEEK_SET);
600 if (strncmp(
str,
"$Start$: ", 9) != 0) {
605 lseek(*fh,
offset, SEEK_SET);
610 time((time_t *) <);
613 localtime_r(<ime, &tms);
615 sprintf(
file_name,
"%s%02d%02d%02d.log", dir, tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
618 mstrlcpy(xfilename,
file_name, xfilename_size);
625 }
while (*fh < 0 && (
INT) lt - (
INT) ltime < 3600 * 24 * 365);
631 sprintf(tag,
"%02d%02d%02d", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
633 lseek(*fh, 0, SEEK_END);
635 sprintf(tag + strlen(tag),
".%d", (
int)
TELL(*fh));
639 if (direction == -1) {
642 if (
TELL(*fh) == 0) {
649 localtime_r(<, &tms);
650 sprintf(
str,
"%02d%02d%02d.0", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
655 mstrlcpy(xfilename,
file_name, xfilename_size);
666 lseek(*fh, 0, SEEK_END);
670 lseek(*fh, -17, SEEK_CUR);
677 if (strncmp(
str,
"$End$: ", 7) != 0) {
687 size = atoi(
str + 7);
693 lseek(*fh, -size, SEEK_CUR);
696 sprintf(strchr(tag,
'.') + 1,
"%d", (
int)
TELL(*fh));
699 if (direction == 1) {
710 lseek(*fh, -15, SEEK_CUR);
712 if (strncmp(
str,
"$Start$: ", 9) != 0) {
722 size = atoi(
str + 9);
729 lseek(*fh, size, SEEK_CUR);
735 time((time_t *) &lact);
740 localtime_r(<, &tms);
741 sprintf(
str,
"%02d%02d%02d.0", tms.tm_year % 100, tms.tm_mon + 1, tms.tm_mday);
746 mstrlcpy(xfilename,
file_name, xfilename_size);
757 lseek(*fh, 0, SEEK_SET);
759 lseek(*fh, -15, SEEK_CUR);
762 sprintf(strchr(tag,
'.') + 1,
"%d", (
int)
TELL(*fh));
771 char *syst,
char *subject,
char *text,
int *
textsize,
772 char *orig_tag,
char *reply_tag,
773 char *attachment1,
char *attachment2,
char *attachment3,
char *encoding)
805 int size, fh = 0, search_status, rd;
808 char attachment_all[3*256+100];
810 size_t message_size = 0;
816 return search_status;
822 return search_status;
837 size = atoi(
str + 9);
839 if ((strncmp(
str,
"$Start$:", 8) != 0) || (size <= 15)) {
840 cm_msg(
MERROR,
"el_retrieve",
"cannot read from \'%s\', corrupted file: no $Start$ or bad size in \"%s\"", filename,
str);
845 message_size = size + 1;
846 message = (
char*)malloc(message_size);
849 cm_msg(
MERROR,
"el_retrieve",
"cannot read from \'%s\', cannot malloc() %d bytes, errno %d (%s)", filename, (
int)message_size, errno, strerror(errno));
855 memset(
message, 0, message_size);
858 if (rd <= 0 || !((rd + 15 == size) || (rd == size))) {
859 cm_msg(
MERROR,
"el_retrieve",
"cannot read from \'%s\', read(%d) returned %d, errno %d (%s)", filename, size, rd, errno, strerror(errno));
881 if (attachment1 && attachment2 && attachment3) {
882 attachment1[0] = attachment2[0] = attachment3[0] = 0;
883 p = strtok(attachment_all,
",");
885 mstrlcpy(attachment1, p, 256);
886 p = strtok(NULL,
",");
888 mstrlcpy(attachment2, p, 256);
889 p = strtok(NULL,
",");
891 mstrlcpy(attachment3, p, 256);
897 if (orig_tag != NULL && reply_tag != NULL) {
898 p = strtok(
thread,
" \r");
902 strcpy(orig_tag,
"");
903 p = strtok(NULL,
" \r");
905 strcpy(reply_tag, p);
907 strcpy(reply_tag,
"");
908 if (atoi(orig_tag) == 0)
910 if (atoi(reply_tag) == 0)
914 p = strstr(
message,
"========================================\n");
928 if (strstr(text,
"$End$"))
929 *strstr(text,
"$End$") = 0;
969 int actual_run=0, fh,
status;
972 tag[0] = return_tag[0] = 0;
984 if (strchr(tag,
'.') != NULL)
985 strcpy(strchr(tag,
'.'),
".0");
988 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
989 }
while (actual_run >=
run);
991 while (actual_run <
run) {
1001 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
1004 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)