mirror of
https://gitea.psi.ch/ELOG/elog.git
synced 2026-09-27 02:57:22 +00:00
Changed indent style
SVN revision: 648
This commit is contained in:
parent
862faeb750
commit
dac9eaa2c4
3
Makefile
3
Makefile
@ -35,6 +35,9 @@ all: $(EXECS)
|
|||||||
%: src/%.c
|
%: src/%.c
|
||||||
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
||||||
|
|
||||||
|
indent:
|
||||||
|
find . -name "*.[hc]" -exec indent -kr -nut -i3 {} \;
|
||||||
|
|
||||||
install: $(EXECS)
|
install: $(EXECS)
|
||||||
$(INSTALL) -m 0755 -d $(DESTDIR) $(SDESTDIR) $(MANDIR)/man1/ $(MANDIR)/man8/
|
$(INSTALL) -m 0755 -d $(DESTDIR) $(SDESTDIR) $(MANDIR)/man1/ $(MANDIR)/man8/
|
||||||
$(INSTALL) -m 0755 -o bin -g bin elog elconv $(DESTDIR)
|
$(INSTALL) -m 0755 -o bin -g bin elog elconv $(DESTDIR)
|
||||||
|
|||||||
309
src/elconv.c
309
src/elconv.c
@ -6,6 +6,9 @@
|
|||||||
Contents: Conversion program for ELOG messages
|
Contents: Conversion program for ELOG messages
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.2 2004/01/06 13:21:34 midas
|
||||||
|
Changed indent style
|
||||||
|
|
||||||
Revision 1.1 2003/01/30 14:45:07 midas
|
Revision 1.1 2003/01/30 14:45:07 midas
|
||||||
Moved files to src/ subdirectory
|
Moved files to src/ subdirectory
|
||||||
|
|
||||||
@ -143,9 +146,9 @@ char *pc;
|
|||||||
|
|
||||||
*result = 0;
|
*result = 0;
|
||||||
|
|
||||||
if (strstr(message, key))
|
if (strstr(message, key)) {
|
||||||
{
|
for (pc = strstr(message, key) + strlen(key);
|
||||||
for (pc=strstr(message, key)+strlen(key) ; *pc != '\n' && *pc != '\r' ; )
|
*pc != '\n' && *pc != '\r';)
|
||||||
*result++ = *pc++;
|
*result++ = *pc++;
|
||||||
*result = 0;
|
*result = 0;
|
||||||
}
|
}
|
||||||
@ -182,8 +185,7 @@ char c, test;
|
|||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
/* General case, use recursion. */
|
/* General case, use recursion. */
|
||||||
while ((test = *string) != EOS)
|
while ((test = *string) != EOS) {
|
||||||
{
|
|
||||||
if (!fnmatch1(pattern, string))
|
if (!fnmatch1(pattern, string))
|
||||||
return (0);
|
return (0);
|
||||||
++string;
|
++string;
|
||||||
@ -229,12 +231,11 @@ INT ss_file_find(char * path, char * pattern, char **plist)
|
|||||||
return 0;
|
return 0;
|
||||||
*plist = (char *) malloc(MAX_PATH_LENGTH);
|
*plist = (char *) malloc(MAX_PATH_LENGTH);
|
||||||
i = 0;
|
i = 0;
|
||||||
for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer))
|
for (dp = readdir(dir_pointer); dp != NULL; dp = readdir(dir_pointer)) {
|
||||||
{
|
if (fnmatch1(pattern, dp->d_name) == 0) {
|
||||||
if (fnmatch1(pattern, dp->d_name) == 0)
|
|
||||||
{
|
|
||||||
*plist = (char *) realloc(*plist, (i + 1) * MAX_PATH_LENGTH);
|
*plist = (char *) realloc(*plist, (i + 1) * MAX_PATH_LENGTH);
|
||||||
strncpy(*plist+(i*MAX_PATH_LENGTH), dp->d_name, strlen(dp->d_name));
|
strncpy(*plist + (i * MAX_PATH_LENGTH), dp->d_name,
|
||||||
|
strlen(dp->d_name));
|
||||||
*(*plist + (i * MAX_PATH_LENGTH) + strlen(dp->d_name)) = '\0';
|
*(*plist + (i * MAX_PATH_LENGTH) + strlen(dp->d_name)) = '\0';
|
||||||
i++;
|
i++;
|
||||||
seekdir(dir_pointer, telldir(dir_pointer));
|
seekdir(dir_pointer, telldir(dir_pointer));
|
||||||
@ -261,14 +262,16 @@ INT ss_file_find(char * path, char * pattern, char **plist)
|
|||||||
return 0;
|
return 0;
|
||||||
first = 0;
|
first = 0;
|
||||||
*plist = (char *) realloc(*plist, (i + 1) * MAX_PATH_LENGTH);
|
*plist = (char *) realloc(*plist, (i + 1) * MAX_PATH_LENGTH);
|
||||||
strncpy(*plist+(i*MAX_PATH_LENGTH), lpfdata->cFileName, strlen(lpfdata->cFileName));
|
strncpy(*plist + (i * MAX_PATH_LENGTH), lpfdata->cFileName,
|
||||||
|
strlen(lpfdata->cFileName));
|
||||||
*(*plist + (i * MAX_PATH_LENGTH) + strlen(lpfdata->cFileName)) = '\0';
|
*(*plist + (i * MAX_PATH_LENGTH) + strlen(lpfdata->cFileName)) = '\0';
|
||||||
i++;
|
i++;
|
||||||
while (FindNextFile(pffile, lpfdata))
|
while (FindNextFile(pffile, lpfdata)) {
|
||||||
{
|
|
||||||
*plist = (char *) realloc(*plist, (i + 1) * MAX_PATH_LENGTH);
|
*plist = (char *) realloc(*plist, (i + 1) * MAX_PATH_LENGTH);
|
||||||
strncpy(*plist+(i*MAX_PATH_LENGTH), lpfdata->cFileName, strlen(lpfdata->cFileName));
|
strncpy(*plist + (i * MAX_PATH_LENGTH), lpfdata->cFileName,
|
||||||
*(*plist+(i*MAX_PATH_LENGTH)+strlen(lpfdata->cFileName)) = '\0';
|
strlen(lpfdata->cFileName));
|
||||||
|
*(*plist + (i * MAX_PATH_LENGTH) + strlen(lpfdata->cFileName)) =
|
||||||
|
'\0';
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
free(lpfdata);
|
free(lpfdata);
|
||||||
@ -280,7 +283,8 @@ INT ss_file_find(char * path, char * pattern, char **plist)
|
|||||||
|
|
||||||
INT el_search_message(char *tag, int *fh, BOOL walk, BOOL first)
|
INT el_search_message(char *tag, int *fh, BOOL walk, BOOL first)
|
||||||
{
|
{
|
||||||
int lfh, i, n, d, min, max, size, offset, direction, last, status, did_walk;
|
int lfh, i, n, d, min, max, size, offset, direction, last, status,
|
||||||
|
did_walk;
|
||||||
struct tm *tms, ltms;
|
struct tm *tms, ltms;
|
||||||
time_t lt, ltime, lact;
|
time_t lt, ltime, lact;
|
||||||
char str[256], file_name[256], dir[256];
|
char str[256], file_name[256], dir[256];
|
||||||
@ -294,15 +298,13 @@ char *file_list;
|
|||||||
|
|
||||||
/* check tag for direction */
|
/* check tag for direction */
|
||||||
direction = 0;
|
direction = 0;
|
||||||
if (strpbrk(tag, "+-"))
|
if (strpbrk(tag, "+-")) {
|
||||||
{
|
|
||||||
direction = atoi(strpbrk(tag, "+-"));
|
direction = atoi(strpbrk(tag, "+-"));
|
||||||
*strpbrk(tag, "+-") = 0;
|
*strpbrk(tag, "+-") = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if tag is given, open file directly */
|
/* if tag is given, open file directly */
|
||||||
if (tag[0])
|
if (tag[0]) {
|
||||||
{
|
|
||||||
/* extract time structure from tag */
|
/* extract time structure from tag */
|
||||||
tms = <ms;
|
tms = <ms;
|
||||||
memset(tms, 0, sizeof(struct tm));
|
memset(tms, 0, sizeof(struct tm));
|
||||||
@ -319,24 +321,20 @@ char *file_list;
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strcpy(str, tag);
|
strcpy(str, tag);
|
||||||
if (strchr(str, '.'))
|
if (strchr(str, '.')) {
|
||||||
{
|
|
||||||
offset = atoi(strchr(str, '.') + 1);
|
offset = atoi(strchr(str, '.') + 1);
|
||||||
*strchr(str, '.') = 0;
|
*strchr(str, '.') = 0;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
tms = localtime(<ime);
|
tms = localtime(<ime);
|
||||||
|
|
||||||
sprintf(file_name, "%s%02d%02d%02d.log", dir,
|
sprintf(file_name, "%s%02d%02d%02d.log", dir,
|
||||||
tms->tm_year % 100, tms->tm_mon + 1, tms->tm_mday);
|
tms->tm_year % 100, tms->tm_mon + 1, tms->tm_mday);
|
||||||
lfh = open(file_name, O_RDWR | O_BINARY, 0644);
|
lfh = open(file_name, O_RDWR | O_BINARY, 0644);
|
||||||
|
|
||||||
if (lfh < 0)
|
if (lfh < 0) {
|
||||||
{
|
|
||||||
if (!walk)
|
if (!walk)
|
||||||
return EL_FILE_ERROR;
|
return EL_FILE_ERROR;
|
||||||
|
|
||||||
@ -349,7 +347,8 @@ char *file_list;
|
|||||||
|
|
||||||
/* set new tag */
|
/* set new tag */
|
||||||
tms = localtime(<ime);
|
tms = localtime(<ime);
|
||||||
sprintf(tag, "%02d%02d%02d.0", tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday);
|
sprintf(tag, "%02d%02d%02d.0", tms->tm_year % 100,
|
||||||
|
tms->tm_mon + 1, tms->tm_mday);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* in forward direction, stop today */
|
/* in forward direction, stop today */
|
||||||
@ -357,7 +356,8 @@ char *file_list;
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* in backward direction, go back 10 years */
|
/* in backward direction, go back 10 years */
|
||||||
if (direction == -1 && abs((int)(lt-ltime)) > 3600*24*365*10)
|
if (direction == -1
|
||||||
|
&& abs((int) (lt - ltime)) > 3600 * 24 * 365 * 10)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} while (lfh < 0);
|
} while (lfh < 0);
|
||||||
@ -372,23 +372,19 @@ char *file_list;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* open most recent file if no tag given */
|
/* open most recent file if no tag given */
|
||||||
if (tag[0] == 0)
|
if (tag[0] == 0) {
|
||||||
{
|
if (first) {
|
||||||
if (first)
|
|
||||||
{
|
|
||||||
/* go through whole directory, find first file */
|
/* go through whole directory, find first file */
|
||||||
|
|
||||||
file_list = NULL;
|
file_list = NULL;
|
||||||
n = ss_file_find(dir, "??????.log", &file_list);
|
n = ss_file_find(dir, "??????.log", &file_list);
|
||||||
if (n == 0)
|
if (n == 0) {
|
||||||
{
|
|
||||||
if (file_list)
|
if (file_list)
|
||||||
free(file_list);
|
free(file_list);
|
||||||
return EL_FILE_ERROR;
|
return EL_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0,min=9999999 ; i<n ; i++)
|
for (i = 0, min = 9999999; i < n; i++) {
|
||||||
{
|
|
||||||
d = atoi(file_list + i * MAX_PATH_LENGTH);
|
d = atoi(file_list + i * MAX_PATH_LENGTH);
|
||||||
if (d == 0)
|
if (d == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -411,22 +407,18 @@ char *file_list;
|
|||||||
/* on tag "+1", don't go to next message */
|
/* on tag "+1", don't go to next message */
|
||||||
if (direction == 1)
|
if (direction == 1)
|
||||||
direction = 0;
|
direction = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* go through whole directory, find last file */
|
/* go through whole directory, find last file */
|
||||||
|
|
||||||
file_list = NULL;
|
file_list = NULL;
|
||||||
n = ss_file_find(dir, "??????.log", &file_list);
|
n = ss_file_find(dir, "??????.log", &file_list);
|
||||||
if (n == 0)
|
if (n == 0) {
|
||||||
{
|
|
||||||
if (file_list)
|
if (file_list)
|
||||||
free(file_list);
|
free(file_list);
|
||||||
return EL_NO_MSG;
|
return EL_NO_MSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0,max=0 ; i<n ; i++)
|
for (i = 0, max = 0; i < n; i++) {
|
||||||
{
|
|
||||||
d = atoi(file_list + i * MAX_PATH_LENGTH);
|
d = atoi(file_list + i * MAX_PATH_LENGTH);
|
||||||
if (d < 900000)
|
if (d < 900000)
|
||||||
d += 1000000; /* last century */
|
d += 1000000; /* last century */
|
||||||
@ -447,18 +439,15 @@ char *file_list;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction == -1)
|
if (direction == -1) {
|
||||||
{
|
|
||||||
/* seek previous message */
|
/* seek previous message */
|
||||||
|
|
||||||
if (TELL(lfh) == 0)
|
if (TELL(lfh) == 0) {
|
||||||
{
|
|
||||||
/* go back one day */
|
/* go back one day */
|
||||||
close(lfh);
|
close(lfh);
|
||||||
|
|
||||||
lt = ltime;
|
lt = ltime;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
lt -= 3600 * 24;
|
lt -= 3600 * 24;
|
||||||
tms = localtime(<);
|
tms = localtime(<);
|
||||||
sprintf(str, "%02d%02d%02d.0",
|
sprintf(str, "%02d%02d%02d.0",
|
||||||
@ -469,8 +458,7 @@ char *file_list;
|
|||||||
} while (status != SUCCESS &&
|
} while (status != SUCCESS &&
|
||||||
(INT) ltime - (INT) lt < 3600 * 24 * 365);
|
(INT) ltime - (INT) lt < 3600 * 24 * 365);
|
||||||
|
|
||||||
if (status != EL_SUCCESS)
|
if (status != EL_SUCCESS) {
|
||||||
{
|
|
||||||
if (fh)
|
if (fh)
|
||||||
*fh = lfh;
|
*fh = lfh;
|
||||||
else
|
else
|
||||||
@ -488,19 +476,15 @@ char *file_list;
|
|||||||
/* read previous message size */
|
/* read previous message size */
|
||||||
lseek(lfh, -17, SEEK_CUR);
|
lseek(lfh, -17, SEEK_CUR);
|
||||||
i = read(lfh, str, 17);
|
i = read(lfh, str, 17);
|
||||||
if (i <= 0)
|
if (i <= 0) {
|
||||||
{
|
|
||||||
close(lfh);
|
close(lfh);
|
||||||
return EL_FILE_ERROR;
|
return EL_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(str, "$End$: ", 7) == 0)
|
if (strncmp(str, "$End$: ", 7) == 0) {
|
||||||
{
|
|
||||||
size = atoi(str + 7);
|
size = atoi(str + 7);
|
||||||
lseek(lfh, -size, SEEK_CUR);
|
lseek(lfh, -size, SEEK_CUR);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
close(lfh);
|
close(lfh);
|
||||||
return EL_FILE_ERROR;
|
return EL_FILE_ERROR;
|
||||||
}
|
}
|
||||||
@ -509,42 +493,35 @@ char *file_list;
|
|||||||
sprintf(strchr(tag, '.') + 1, "%d", (int) (TELL(lfh)));
|
sprintf(strchr(tag, '.') + 1, "%d", (int) (TELL(lfh)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction == 1)
|
if (direction == 1) {
|
||||||
{
|
|
||||||
/* seek next message */
|
/* seek next message */
|
||||||
|
|
||||||
/* read current message size */
|
/* read current message size */
|
||||||
last = TELL(lfh);
|
last = TELL(lfh);
|
||||||
|
|
||||||
i = read(lfh, str, 15);
|
i = read(lfh, str, 15);
|
||||||
if (i <= 0)
|
if (i <= 0) {
|
||||||
{
|
|
||||||
close(lfh);
|
close(lfh);
|
||||||
return EL_FILE_ERROR;
|
return EL_FILE_ERROR;
|
||||||
}
|
}
|
||||||
lseek(lfh, -15, SEEK_CUR);
|
lseek(lfh, -15, SEEK_CUR);
|
||||||
|
|
||||||
if (strncmp(str, "$Start$: ", 9) == 0)
|
if (strncmp(str, "$Start$: ", 9) == 0) {
|
||||||
{
|
|
||||||
size = atoi(str + 9);
|
size = atoi(str + 9);
|
||||||
lseek(lfh, size, SEEK_CUR);
|
lseek(lfh, size, SEEK_CUR);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
close(lfh);
|
close(lfh);
|
||||||
return EL_FILE_ERROR;
|
return EL_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if EOF, goto next day */
|
/* if EOF, goto next day */
|
||||||
i = read(lfh, str, 15);
|
i = read(lfh, str, 15);
|
||||||
if (i < 15)
|
if (i < 15) {
|
||||||
{
|
|
||||||
close(lfh);
|
close(lfh);
|
||||||
time(&lact);
|
time(&lact);
|
||||||
|
|
||||||
lt = ltime;
|
lt = ltime;
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
lt += 3600 * 24;
|
lt += 3600 * 24;
|
||||||
tms = localtime(<);
|
tms = localtime(<);
|
||||||
sprintf(str, "%02d%02d%02d.0",
|
sprintf(str, "%02d%02d%02d.0",
|
||||||
@ -555,8 +532,7 @@ char *file_list;
|
|||||||
} while (status != EL_SUCCESS &&
|
} while (status != EL_SUCCESS &&
|
||||||
(INT) lt - (INT) lact < 3600 * 24);
|
(INT) lt - (INT) lact < 3600 * 24);
|
||||||
|
|
||||||
if (status != EL_SUCCESS)
|
if (status != EL_SUCCESS) {
|
||||||
{
|
|
||||||
if (fh)
|
if (fh)
|
||||||
*fh = lfh;
|
*fh = lfh;
|
||||||
else
|
else
|
||||||
@ -569,8 +545,7 @@ char *file_list;
|
|||||||
|
|
||||||
/* go to beginning of current file */
|
/* go to beginning of current file */
|
||||||
lseek(lfh, 0, SEEK_SET);
|
lseek(lfh, 0, SEEK_SET);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
lseek(lfh, -15, SEEK_CUR);
|
lseek(lfh, -15, SEEK_CUR);
|
||||||
|
|
||||||
/* adjust tag */
|
/* adjust tag */
|
||||||
@ -592,8 +567,7 @@ INT el_submit(char attr_name[MAX_N_ATTR][NAME_LENGTH],
|
|||||||
int n_attr, char *text, char *reply_to, char *encoding,
|
int n_attr, char *text, char *reply_to, char *encoding,
|
||||||
char afilename[MAX_ATTACHMENTS][256],
|
char afilename[MAX_ATTACHMENTS][256],
|
||||||
char *buffer[MAX_ATTACHMENTS],
|
char *buffer[MAX_ATTACHMENTS],
|
||||||
INT buffer_size[MAX_ATTACHMENTS],
|
INT buffer_size[MAX_ATTACHMENTS], char *tag, INT tag_size)
|
||||||
char *tag, INT tag_size)
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
|
|
||||||
Routine: el_submit
|
Routine: el_submit
|
||||||
@ -626,28 +600,24 @@ INT el_submit(char attr_name[MAX_N_ATTR][NAME_LENGTH],
|
|||||||
{
|
{
|
||||||
INT n, i, size, fh, status, index, offset, tail_size;
|
INT n, i, size, fh, status, index, offset, tail_size;
|
||||||
struct tm *tms;
|
struct tm *tms;
|
||||||
char file_name[256], afile_name[MAX_ATTACHMENTS][256], dir[256], str[256],
|
char file_name[256], afile_name[MAX_ATTACHMENTS][256], dir[256],
|
||||||
start_str[80], end_str[80], last[80], date[80], thread[80], attachment_all[64*MAX_ATTACHMENTS];
|
str[256], start_str[80], end_str[80], last[80], date[80],
|
||||||
|
thread[80], attachment_all[64 * MAX_ATTACHMENTS];
|
||||||
time_t now;
|
time_t now;
|
||||||
char message[TEXT_SIZE + 100], *p;
|
char message[TEXT_SIZE + 100], *p;
|
||||||
BOOL bedit;
|
BOOL bedit;
|
||||||
|
|
||||||
bedit = (tag[0] != 0);
|
bedit = (tag[0] != 0);
|
||||||
|
|
||||||
for (index = 0 ; index < MAX_ATTACHMENTS ; index++)
|
for (index = 0; index < MAX_ATTACHMENTS; index++) {
|
||||||
{
|
|
||||||
/* generate filename for attachment */
|
/* generate filename for attachment */
|
||||||
afile_name[index][0] = file_name[0] = 0;
|
afile_name[index][0] = file_name[0] = 0;
|
||||||
|
|
||||||
if (afilename[index][0] && buffer_size[index] == 0)
|
if (afilename[index][0] && buffer_size[index] == 0) {
|
||||||
{
|
|
||||||
/* resubmission of existing attachment */
|
/* resubmission of existing attachment */
|
||||||
strcpy(afile_name[index], afilename[index]);
|
strcpy(afile_name[index], afilename[index]);
|
||||||
}
|
} else {
|
||||||
else
|
if (afilename[index][0]) {
|
||||||
{
|
|
||||||
if (afilename[index][0])
|
|
||||||
{
|
|
||||||
/* strip directory, add date and time to filename */
|
/* strip directory, add date and time to filename */
|
||||||
|
|
||||||
strcpy(file_name, afilename[index]);
|
strcpy(file_name, afilename[index]);
|
||||||
@ -660,8 +630,7 @@ BOOL bedit;
|
|||||||
p = strchr(p, '/') + 1; /* Unix */
|
p = strchr(p, '/') + 1; /* Unix */
|
||||||
|
|
||||||
/* assemble ELog filename */
|
/* assemble ELog filename */
|
||||||
if (p[0])
|
if (p[0]) {
|
||||||
{
|
|
||||||
strcpy(dir, data_dir);
|
strcpy(dir, data_dir);
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
@ -677,12 +646,9 @@ BOOL bedit;
|
|||||||
|
|
||||||
/* save attachment */
|
/* save attachment */
|
||||||
fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644);
|
fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644);
|
||||||
if (fh < 0)
|
if (fh < 0) {
|
||||||
{
|
|
||||||
printf("Cannot write attachment file \"%s\"", file_name);
|
printf("Cannot write attachment file \"%s\"", file_name);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
write(fh, buffer[index], buffer_size[index]);
|
write(fh, buffer[index], buffer_size[index]);
|
||||||
close(fh);
|
close(fh);
|
||||||
}
|
}
|
||||||
@ -694,12 +660,10 @@ BOOL bedit;
|
|||||||
/* generate new file name YYMMDD.log in data directory */
|
/* generate new file name YYMMDD.log in data directory */
|
||||||
strcpy(dir, data_dir);
|
strcpy(dir, data_dir);
|
||||||
|
|
||||||
if (bedit)
|
if (bedit) {
|
||||||
{
|
|
||||||
/* edit existing message */
|
/* edit existing message */
|
||||||
strcpy(str, tag);
|
strcpy(str, tag);
|
||||||
if (strchr(str, '.'))
|
if (strchr(str, '.')) {
|
||||||
{
|
|
||||||
offset = atoi(strchr(str, '.') + 1);
|
offset = atoi(strchr(str, '.') + 1);
|
||||||
*strchr(str, '.') = 0;
|
*strchr(str, '.') = 0;
|
||||||
}
|
}
|
||||||
@ -721,11 +685,9 @@ BOOL bedit;
|
|||||||
lseek(fh, 0, SEEK_END);
|
lseek(fh, 0, SEEK_END);
|
||||||
tail_size = TELL(fh) - (offset + size);
|
tail_size = TELL(fh) - (offset + size);
|
||||||
|
|
||||||
if (tail_size > 0)
|
if (tail_size > 0) {
|
||||||
{
|
|
||||||
buffer = malloc(tail_size);
|
buffer = malloc(tail_size);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL) {
|
||||||
{
|
|
||||||
close(fh);
|
close(fh);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -734,9 +696,7 @@ BOOL bedit;
|
|||||||
n = read(fh, buffer, tail_size);
|
n = read(fh, buffer, tail_size);
|
||||||
}
|
}
|
||||||
lseek(fh, offset, SEEK_SET);
|
lseek(fh, offset, SEEK_SET);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* create new message */
|
/* create new message */
|
||||||
time(&now);
|
time(&now);
|
||||||
tms = localtime(&now);
|
tms = localtime(&now);
|
||||||
@ -765,54 +725,44 @@ BOOL bedit;
|
|||||||
sprintf(message + strlen(message), "Thread: %s\n", thread);
|
sprintf(message + strlen(message), "Thread: %s\n", thread);
|
||||||
|
|
||||||
for (i = 0; i < n_attr; i++)
|
for (i = 0; i < n_attr; i++)
|
||||||
sprintf(message+strlen(message), "%s: %s\n", attr_name[i], attr_value[i]);
|
sprintf(message + strlen(message), "%s: %s\n", attr_name[i],
|
||||||
|
attr_value[i]);
|
||||||
|
|
||||||
/* keep original attachment if edit and no new attachment */
|
/* keep original attachment if edit and no new attachment */
|
||||||
|
|
||||||
if (bedit)
|
if (bedit) {
|
||||||
{
|
for (i = n = 0; i < MAX_ATTACHMENTS; i++) {
|
||||||
for (i=n=0 ; i<MAX_ATTACHMENTS ; i++)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
p = strtok(attachment_all, ",");
|
p = strtok(attachment_all, ",");
|
||||||
else
|
else if (p != NULL)
|
||||||
if (p != NULL)
|
|
||||||
p = strtok(NULL, ",");
|
p = strtok(NULL, ",");
|
||||||
|
|
||||||
if (p && (afile_name[i][0]))
|
if (p && (afile_name[i][0])) {
|
||||||
{
|
|
||||||
/* delete old attachment */
|
/* delete old attachment */
|
||||||
strcpy(str, data_dir);
|
strcpy(str, data_dir);
|
||||||
strcat(str, p);
|
strcat(str, p);
|
||||||
remove(str);
|
remove(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (afile_name[i][0])
|
if (afile_name[i][0]) {
|
||||||
{
|
if (n == 0) {
|
||||||
if (n == 0)
|
sprintf(message + strlen(message), "Attachment: %s",
|
||||||
{
|
afile_name[i]);
|
||||||
sprintf(message+strlen(message), "Attachment: %s", afile_name[i]);
|
|
||||||
n++;
|
n++;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
sprintf(message + strlen(message), ",%s", afile_name[i]);
|
sprintf(message + strlen(message), ",%s", afile_name[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (p)
|
else if (p) {
|
||||||
{
|
if (n == 0) {
|
||||||
if (n == 0)
|
|
||||||
{
|
|
||||||
sprintf(message + strlen(message), "Attachment: %s", p);
|
sprintf(message + strlen(message), "Attachment: %s", p);
|
||||||
n++;
|
n++;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
sprintf(message + strlen(message), ",%s", p);
|
sprintf(message + strlen(message), ",%s", p);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sprintf(message + strlen(message), "Attachment: %s", afile_name[0]);
|
sprintf(message + strlen(message), "Attachment: %s", afile_name[0]);
|
||||||
for (i = 1; i < MAX_ATTACHMENTS; i++)
|
for (i = 1; i < MAX_ATTACHMENTS; i++)
|
||||||
if (afile_name[i][0])
|
if (afile_name[i][0])
|
||||||
@ -821,7 +771,8 @@ BOOL bedit;
|
|||||||
sprintf(message + strlen(message), "\n");
|
sprintf(message + strlen(message), "\n");
|
||||||
|
|
||||||
sprintf(message + strlen(message), "Encoding: %s\n", encoding);
|
sprintf(message + strlen(message), "Encoding: %s\n", encoding);
|
||||||
sprintf(message+strlen(message), "========================================\n");
|
sprintf(message + strlen(message),
|
||||||
|
"========================================\n");
|
||||||
strcat(message, text);
|
strcat(message, text);
|
||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
@ -831,7 +782,8 @@ BOOL bedit;
|
|||||||
size = strlen(message) + strlen(start_str) + strlen(end_str);
|
size = strlen(message) + strlen(start_str) + strlen(end_str);
|
||||||
|
|
||||||
if (tag != NULL && !bedit)
|
if (tag != NULL && !bedit)
|
||||||
sprintf(tag, "%02d%02d%02d.%d", tms->tm_year % 100, tms->tm_mon+1, tms->tm_mday, (int) (TELL(fh)));
|
sprintf(tag, "%02d%02d%02d.%d", tms->tm_year % 100, tms->tm_mon + 1,
|
||||||
|
tms->tm_mday, (int) (TELL(fh)));
|
||||||
|
|
||||||
sprintf(start_str, "$Start$: %6d\n", size);
|
sprintf(start_str, "$Start$: %6d\n", size);
|
||||||
sprintf(end_str, "$End$: %6d\n\f", size);
|
sprintf(end_str, "$End$: %6d\n\f", size);
|
||||||
@ -840,10 +792,8 @@ BOOL bedit;
|
|||||||
write(fh, message, strlen(message));
|
write(fh, message, strlen(message));
|
||||||
write(fh, end_str, strlen(end_str));
|
write(fh, end_str, strlen(end_str));
|
||||||
|
|
||||||
if (bedit)
|
if (bedit) {
|
||||||
{
|
if (tail_size > 0) {
|
||||||
if (tail_size > 0)
|
|
||||||
{
|
|
||||||
n = write(fh, buffer, tail_size);
|
n = write(fh, buffer, tail_size);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
}
|
}
|
||||||
@ -859,14 +809,11 @@ BOOL bedit;
|
|||||||
close(fh);
|
close(fh);
|
||||||
|
|
||||||
/* if reply, mark original message */
|
/* if reply, mark original message */
|
||||||
if (reply_to[0] && !bedit)
|
if (reply_to[0] && !bedit) {
|
||||||
{
|
|
||||||
strcpy(last, reply_to);
|
strcpy(last, reply_to);
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
status = el_search_message(last, &fh, FALSE, FALSE);
|
status = el_search_message(last, &fh, FALSE, FALSE);
|
||||||
if (status == EL_SUCCESS)
|
if (status == EL_SUCCESS) {
|
||||||
{
|
|
||||||
/* position to next thread location */
|
/* position to next thread location */
|
||||||
lseek(fh, 72, SEEK_CUR);
|
lseek(fh, 72, SEEK_CUR);
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
@ -874,21 +821,17 @@ BOOL bedit;
|
|||||||
lseek(fh, -16, SEEK_CUR);
|
lseek(fh, -16, SEEK_CUR);
|
||||||
|
|
||||||
/* if no reply yet, set it */
|
/* if no reply yet, set it */
|
||||||
if (atoi(str) == 0)
|
if (atoi(str) == 0) {
|
||||||
{
|
|
||||||
sprintf(str, "%16s", tag);
|
sprintf(str, "%16s", tag);
|
||||||
write(fh, str, 16);
|
write(fh, str, 16);
|
||||||
close(fh);
|
close(fh);
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* if reply set, find last one in chain */
|
/* if reply set, find last one in chain */
|
||||||
strcpy(last, strtok(str, " "));
|
strcpy(last, strtok(str, " "));
|
||||||
close(fh);
|
close(fh);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
/* stop on error */
|
/* stop on error */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -926,14 +869,11 @@ INT el_get_v1(char *tag, char *message, int *bufsize)
|
|||||||
int i, size, fh, offset, search_status;
|
int i, size, fh, offset, search_status;
|
||||||
char str[256];
|
char str[256];
|
||||||
|
|
||||||
if (tag[0])
|
if (tag[0]) {
|
||||||
{
|
|
||||||
search_status = el_search_message(tag, &fh, TRUE, FALSE);
|
search_status = el_search_message(tag, &fh, TRUE, FALSE);
|
||||||
if (search_status != EL_SUCCESS)
|
if (search_status != EL_SUCCESS)
|
||||||
return search_status;
|
return search_status;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
/* open most recent message */
|
/* open most recent message */
|
||||||
strcpy(tag, "-1");
|
strcpy(tag, "-1");
|
||||||
search_status = el_search_message(tag, &fh, TRUE, FALSE);
|
search_status = el_search_message(tag, &fh, TRUE, FALSE);
|
||||||
@ -944,16 +884,14 @@ char str[256];
|
|||||||
/* extract message size */
|
/* extract message size */
|
||||||
offset = TELL(fh);
|
offset = TELL(fh);
|
||||||
i = read(fh, str, 16);
|
i = read(fh, str, 16);
|
||||||
if (i <= 0)
|
if (i <= 0) {
|
||||||
{
|
|
||||||
close(fh);
|
close(fh);
|
||||||
return EL_FILE_ERROR;
|
return EL_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strncmp(str, "$Start$: ", 9) == 0)
|
if (strncmp(str, "$Start$: ", 9) == 0)
|
||||||
size = atoi(str + 9);
|
size = atoi(str + 9);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
close(fh);
|
close(fh);
|
||||||
return EL_FILE_ERROR;
|
return EL_FILE_ERROR;
|
||||||
}
|
}
|
||||||
@ -986,8 +924,7 @@ THREAD *thread_list;
|
|||||||
/* search first message */
|
/* search first message */
|
||||||
status = el_search_message(tag, NULL, TRUE, TRUE);
|
status = el_search_message(tag, NULL, TRUE, TRUE);
|
||||||
|
|
||||||
if (status == EL_FILE_ERROR)
|
if (status == EL_FILE_ERROR) {
|
||||||
{
|
|
||||||
printf("Cannot find any ??????.log file in this directory.\n");
|
printf("Cannot find any ??????.log file in this directory.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1002,8 +939,7 @@ THREAD *thread_list;
|
|||||||
free(file_list);
|
free(file_list);
|
||||||
|
|
||||||
/* build thread_list */
|
/* build thread_list */
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
size = sizeof(message);
|
size = sizeof(message);
|
||||||
status = el_get_v1(tag, message, &size);
|
status = el_get_v1(tag, message, &size);
|
||||||
|
|
||||||
@ -1017,8 +953,7 @@ THREAD *thread_list;
|
|||||||
thread_list[message_id - 1].message_id = message_id;
|
thread_list[message_id - 1].message_id = message_id;
|
||||||
|
|
||||||
/* extract thread */
|
/* extract thread */
|
||||||
if (strstr(message, "Thread:"))
|
if (strstr(message, "Thread:")) {
|
||||||
{
|
|
||||||
ps = strstr(message, "Thread:") + 7;
|
ps = strstr(message, "Thread:") + 7;
|
||||||
while (*ps && !isdigit(*ps))
|
while (*ps && !isdigit(*ps))
|
||||||
ps++;
|
ps++;
|
||||||
@ -1054,8 +989,7 @@ THREAD *thread_list;
|
|||||||
/* search first message */
|
/* search first message */
|
||||||
status = el_search_message(tag, NULL, TRUE, TRUE);
|
status = el_search_message(tag, NULL, TRUE, TRUE);
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
size = sizeof(message);
|
size = sizeof(message);
|
||||||
status = el_get_v1(tag, message, &size);
|
status = el_get_v1(tag, message, &size);
|
||||||
|
|
||||||
@ -1068,18 +1002,15 @@ THREAD *thread_list;
|
|||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
printf("Converting %s -> %s, ID %d\n", tag, str, message_id);
|
printf("Converting %s -> %s, ID %d\n", tag, str, message_id);
|
||||||
else
|
else {
|
||||||
{
|
if (!equal_ustring(str, last_file)) {
|
||||||
if (!equal_ustring(str, last_file))
|
|
||||||
{
|
|
||||||
printf("Converting %s.log to %sa.log\n", str, str);
|
printf("Converting %s.log to %sa.log\n", str, str);
|
||||||
strcpy(last_file, str);
|
strcpy(last_file, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644);
|
fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644);
|
||||||
if (fh < 0)
|
if (fh < 0) {
|
||||||
{
|
|
||||||
printf("Error: Cannot open file %s for writing.\n", file_name);
|
printf("Error: Cannot open file %s for writing.\n", file_name);
|
||||||
free(thread_list);
|
free(thread_list);
|
||||||
return;
|
return;
|
||||||
@ -1092,29 +1023,28 @@ THREAD *thread_list;
|
|||||||
write(fh, str, strlen(str));
|
write(fh, str, strlen(str));
|
||||||
|
|
||||||
/* write reply-to and in-reply-to */
|
/* write reply-to and in-reply-to */
|
||||||
if (atoi(thread_list[message_id-1].reply) > 0)
|
if (atoi(thread_list[message_id - 1].reply) > 0) {
|
||||||
{
|
|
||||||
/* search id for reply */
|
/* search id for reply */
|
||||||
for (i = 0; i < n_messages; i++)
|
for (i = 0; i < n_messages; i++)
|
||||||
if (strstr(thread_list[i].v1_tag, thread_list[message_id-1].reply))
|
if (strstr
|
||||||
|
(thread_list[i].v1_tag, thread_list[message_id - 1].reply))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (i < n_messages)
|
if (i < n_messages) {
|
||||||
{
|
|
||||||
sprintf(str, "Reply to: %d\n", thread_list[i].message_id);
|
sprintf(str, "Reply to: %d\n", thread_list[i].message_id);
|
||||||
write(fh, str, strlen(str));
|
write(fh, str, strlen(str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atoi(thread_list[message_id-1].in_reply_to) > 0)
|
if (atoi(thread_list[message_id - 1].in_reply_to) > 0) {
|
||||||
{
|
|
||||||
/* search id for reply */
|
/* search id for reply */
|
||||||
for (i = 0; i < n_messages; i++)
|
for (i = 0; i < n_messages; i++)
|
||||||
if (strstr(thread_list[i].v1_tag, thread_list[message_id-1].in_reply_to))
|
if (strstr
|
||||||
|
(thread_list[i].v1_tag,
|
||||||
|
thread_list[message_id - 1].in_reply_to))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (i < n_messages)
|
if (i < n_messages) {
|
||||||
{
|
|
||||||
sprintf(str, "In reply to: %d\n", thread_list[i].message_id);
|
sprintf(str, "In reply to: %d\n", thread_list[i].message_id);
|
||||||
write(fh, str, strlen(str));
|
write(fh, str, strlen(str));
|
||||||
}
|
}
|
||||||
@ -1145,16 +1075,13 @@ int main(int argc, char *argv[])
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* parse command line parameters */
|
/* parse command line parameters */
|
||||||
for (i=1 ; i<argc ; i++)
|
for (i = 1; i < argc; i++) {
|
||||||
{
|
|
||||||
if (argv[i][0] == '-' && argv[i][1] == 'v')
|
if (argv[i][0] == '-' && argv[i][1] == 'v')
|
||||||
verbose = TRUE;
|
verbose = TRUE;
|
||||||
else if (argv[i][0] == '-')
|
else if (argv[i][0] == '-') {
|
||||||
{
|
|
||||||
if (i + 1 >= argc || argv[i + 1][0] == '-')
|
if (i + 1 >= argc || argv[i + 1][0] == '-')
|
||||||
goto usage;
|
goto usage;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
usage:
|
usage:
|
||||||
printf("usage: %s ", argv[0]);
|
printf("usage: %s ", argv[0]);
|
||||||
printf(" -v debugging output\n");
|
printf(" -v debugging output\n");
|
||||||
|
|||||||
381
src/elog.c
381
src/elog.c
@ -6,6 +6,9 @@
|
|||||||
Contents: Electronic logbook utility
|
Contents: Electronic logbook utility
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.12 2004/01/06 13:21:34 midas
|
||||||
|
Changed indent style
|
||||||
|
|
||||||
Revision 1.11 2003/11/11 12:31:34 midas
|
Revision 1.11 2003/11/11 12:31:34 midas
|
||||||
Added '-s' flag for email suppression
|
Added '-s' flag for email suppression
|
||||||
|
|
||||||
@ -104,7 +107,8 @@ char text[TEXT_SIZE], old_text[TEXT_SIZE], new_text[TEXT_SIZE];
|
|||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
/*------------------------------------------------------------------*/
|
||||||
|
|
||||||
char *map= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
char *map =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
|
||||||
void base64_encode(char *s, char *d)
|
void base64_encode(char *s, char *d)
|
||||||
{
|
{
|
||||||
@ -113,8 +117,7 @@ unsigned int t, pad;
|
|||||||
pad = 3 - strlen(s) % 3;
|
pad = 3 - strlen(s) % 3;
|
||||||
if (pad == 3)
|
if (pad == 3)
|
||||||
pad = 0;
|
pad = 0;
|
||||||
while (*s)
|
while (*s) {
|
||||||
{
|
|
||||||
t = (*s++) << 16;
|
t = (*s++) << 16;
|
||||||
if (*s)
|
if (*s)
|
||||||
t |= (*s++) << 8;
|
t |= (*s++) << 8;
|
||||||
@ -171,18 +174,15 @@ const char *s = src;
|
|||||||
size_t n = size;
|
size_t n = size;
|
||||||
|
|
||||||
/* Copy as many bytes as will fit */
|
/* Copy as many bytes as will fit */
|
||||||
if (n != 0 && --n != 0)
|
if (n != 0 && --n != 0) {
|
||||||
{
|
do {
|
||||||
do
|
|
||||||
{
|
|
||||||
if ((*d++ = *s++) == 0)
|
if ((*d++ = *s++) == 0)
|
||||||
break;
|
break;
|
||||||
} while (--n != 0);
|
} while (--n != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||||
if (n == 0)
|
if (n == 0) {
|
||||||
{
|
|
||||||
if (size != 0)
|
if (size != 0)
|
||||||
*d = '\0'; /* NUL-terminate dst */
|
*d = '\0'; /* NUL-terminate dst */
|
||||||
while (*s++);
|
while (*s++);
|
||||||
@ -231,8 +231,7 @@ void sgets(char *string, int size)
|
|||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
p = fgets(string, size, stdin);
|
p = fgets(string, size, stdin);
|
||||||
} while (p == NULL);
|
} while (p == NULL);
|
||||||
|
|
||||||
@ -247,8 +246,7 @@ char request[100000], response[100000], *content;
|
|||||||
INT retrieve_elog(char *host, int port, char *subdir, char *experiment,
|
INT retrieve_elog(char *host, int port, char *subdir, char *experiment,
|
||||||
char *passwd, char *uname, char *upwd, int message_id,
|
char *passwd, char *uname, char *upwd, int message_id,
|
||||||
char attrib_name[MAX_N_ATTR][NAME_LENGTH],
|
char attrib_name[MAX_N_ATTR][NAME_LENGTH],
|
||||||
char attrib[MAX_N_ATTR][NAME_LENGTH],
|
char attrib[MAX_N_ATTR][NAME_LENGTH], char *text)
|
||||||
char *text)
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
|
|
||||||
Routine: retrive_elog
|
Routine: retrive_elog
|
||||||
@ -291,14 +289,12 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
gethostname(host_name, sizeof(host_name));
|
gethostname(host_name, sizeof(host_name));
|
||||||
|
|
||||||
phe = gethostbyname(host_name);
|
phe = gethostbyname(host_name);
|
||||||
if (phe == NULL)
|
if (phe == NULL) {
|
||||||
{
|
|
||||||
perror("Cannot retrieve host name");
|
perror("Cannot retrieve host name");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
phe = gethostbyaddr(phe->h_addr, sizeof(int), AF_INET);
|
phe = gethostbyaddr(phe->h_addr, sizeof(int), AF_INET);
|
||||||
if (phe == NULL)
|
if (phe == NULL) {
|
||||||
{
|
|
||||||
perror("Cannot retrieve host name");
|
perror("Cannot retrieve host name");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -308,8 +304,7 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
strcpy(host_name, phe->h_name);
|
strcpy(host_name, phe->h_name);
|
||||||
|
|
||||||
/* create socket */
|
/* create socket */
|
||||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||||
{
|
|
||||||
perror("cannot create socket");
|
perror("cannot create socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -321,8 +316,7 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
bind_addr.sin_port = htons((unsigned short) port);
|
bind_addr.sin_port = htons((unsigned short) port);
|
||||||
|
|
||||||
phe = gethostbyname(host);
|
phe = gethostbyname(host);
|
||||||
if (phe == NULL)
|
if (phe == NULL) {
|
||||||
{
|
|
||||||
perror("cannot get host name");
|
perror("cannot get host name");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -330,8 +324,7 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
|
|
||||||
/* connect to server */
|
/* connect to server */
|
||||||
status = connect(sock, (void *) &bind_addr, sizeof(bind_addr));
|
status = connect(sock, (void *) &bind_addr, sizeof(bind_addr));
|
||||||
if (status != 0)
|
if (status != 0) {
|
||||||
{
|
|
||||||
printf("Cannot connect to host %s, port %d\n", host, port);
|
printf("Cannot connect to host %s, port %d\n", host, port);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -342,17 +335,18 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
/* compose request */
|
/* compose request */
|
||||||
strcpy(request, "GET /");
|
strcpy(request, "GET /");
|
||||||
if (subdir[0])
|
if (subdir[0])
|
||||||
sprintf(request+strlen(request), "%s/%d?cmd=download", subdir, message_id);
|
sprintf(request + strlen(request), "%s/%d?cmd=download", subdir,
|
||||||
|
message_id);
|
||||||
if (experiment[0])
|
if (experiment[0])
|
||||||
sprintf(request+strlen(request), "%s/%d?cmd=download", experiment, message_id);
|
sprintf(request + strlen(request), "%s/%d?cmd=download", experiment,
|
||||||
|
message_id);
|
||||||
strcat(request, " HTTP/1.0\r\n");
|
strcat(request, " HTTP/1.0\r\n");
|
||||||
|
|
||||||
sprintf(request + strlen(request), "Host: %s\r\n", host_name);
|
sprintf(request + strlen(request), "Host: %s\r\n", host_name);
|
||||||
sprintf(request + strlen(request), "User-Agent: ELOG\r\n");
|
sprintf(request + strlen(request), "User-Agent: ELOG\r\n");
|
||||||
|
|
||||||
first = 1;
|
first = 1;
|
||||||
if (passwd[0])
|
if (passwd[0]) {
|
||||||
{
|
|
||||||
if (first)
|
if (first)
|
||||||
sprintf(request + strlen(request), "Cookie: ");
|
sprintf(request + strlen(request), "Cookie: ");
|
||||||
first = 0;
|
first = 0;
|
||||||
@ -361,8 +355,7 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
sprintf(request + strlen(request), "wpwd=%s;", str);
|
sprintf(request + strlen(request), "wpwd=%s;", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uname[0])
|
if (uname[0]) {
|
||||||
{
|
|
||||||
if (first)
|
if (first)
|
||||||
sprintf(request + strlen(request), "Cookie: ");
|
sprintf(request + strlen(request), "Cookie: ");
|
||||||
first = 0;
|
first = 0;
|
||||||
@ -370,8 +363,7 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
sprintf(request + strlen(request), "unm=%s;", uname);
|
sprintf(request + strlen(request), "unm=%s;", uname);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (upwd[0])
|
if (upwd[0]) {
|
||||||
{
|
|
||||||
if (first)
|
if (first)
|
||||||
sprintf(request + strlen(request), "Cookie: ");
|
sprintf(request + strlen(request), "Cookie: ");
|
||||||
first = 0;
|
first = 0;
|
||||||
@ -388,23 +380,20 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
|
|
||||||
/* send request */
|
/* send request */
|
||||||
send(sock, request, strlen(request), 0);
|
send(sock, request, strlen(request), 0);
|
||||||
if (verbose)
|
if (verbose) {
|
||||||
{
|
|
||||||
printf("Request sent to host:\n");
|
printf("Request sent to host:\n");
|
||||||
puts(request);
|
puts(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* receive response */
|
/* receive response */
|
||||||
i = recv(sock, response, sizeof(response), 0);
|
i = recv(sock, response, sizeof(response), 0);
|
||||||
if (i < 0)
|
if (i < 0) {
|
||||||
{
|
|
||||||
perror("Cannot receive response");
|
perror("Cannot receive response");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = i;
|
n = i;
|
||||||
while (i > 0)
|
while (i > 0) {
|
||||||
{
|
|
||||||
i = recv(sock, response + n, sizeof(response) - n, 0);
|
i = recv(sock, response + n, sizeof(response) - n, 0);
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
n += i;
|
n += i;
|
||||||
@ -413,15 +402,13 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
|
|
||||||
closesocket(sock);
|
closesocket(sock);
|
||||||
|
|
||||||
if (verbose)
|
if (verbose) {
|
||||||
{
|
|
||||||
printf("Response received:\n");
|
printf("Response received:\n");
|
||||||
puts(response);
|
puts(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check response status */
|
/* check response status */
|
||||||
if (strstr(response, "$@MID@$:"))
|
if (strstr(response, "$@MID@$:")) {
|
||||||
{
|
|
||||||
/* separate attributes and message */
|
/* separate attributes and message */
|
||||||
|
|
||||||
ph = strstr(response, "========================================\n");
|
ph = strstr(response, "========================================\n");
|
||||||
@ -433,8 +420,7 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
while (*ps && (*ps == '\n' || *ps == '\r'))
|
while (*ps && (*ps == '\n' || *ps == '\r'))
|
||||||
ps++;
|
ps++;
|
||||||
|
|
||||||
for (index = 0; index<MAX_N_ATTR ; index++)
|
for (index = 0; index < MAX_N_ATTR; index++) {
|
||||||
{
|
|
||||||
if (ps >= ph)
|
if (ps >= ph)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -445,8 +431,7 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
ps += strlen(attrib_name[index]) + 2;
|
ps += strlen(attrib_name[index]) + 2;
|
||||||
strlcpy(attrib[index], ps, NAME_LENGTH);
|
strlcpy(attrib[index], ps, NAME_LENGTH);
|
||||||
|
|
||||||
for (i=0 ; i<NAME_LENGTH ; i++)
|
for (i = 0; i < NAME_LENGTH; i++) {
|
||||||
{
|
|
||||||
if (attrib[index][i] == '\r' || attrib[index][i] == '\n')
|
if (attrib[index][i] == '\r' || attrib[index][i] == '\n')
|
||||||
attrib[index][i] = 0;
|
attrib[index][i] = 0;
|
||||||
|
|
||||||
@ -471,16 +456,13 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(response, "302 Found"))
|
if (strstr(response, "302 Found")) {
|
||||||
{
|
if (strstr(response, "Location:")) {
|
||||||
if (strstr(response, "Location:"))
|
|
||||||
{
|
|
||||||
if (strstr(response, "wpwd"))
|
if (strstr(response, "wpwd"))
|
||||||
printf("Error: Invalid password\n");
|
printf("Error: Invalid password\n");
|
||||||
else if (strstr(response, "wusr"))
|
else if (strstr(response, "wusr"))
|
||||||
printf("Error: Invalid user name\n");
|
printf("Error: Invalid user name\n");
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
strncpy(str, strstr(response, "Location:") + 10, sizeof(str));
|
strncpy(str, strstr(response, "Location:") + 10, sizeof(str));
|
||||||
if (strchr(str, '?'))
|
if (strchr(str, '?'))
|
||||||
*strchr(str, '?') = 0;
|
*strchr(str, '?') = 0;
|
||||||
@ -490,13 +472,13 @@ char host_name[256], str[80], *ph, *ps;
|
|||||||
*strchr(str, '\r') = 0;
|
*strchr(str, '\r') = 0;
|
||||||
|
|
||||||
if (strrchr(str, '/'))
|
if (strrchr(str, '/'))
|
||||||
printf("Message successfully transmitted, ID=%s\n", strrchr(str, '/')+1);
|
printf("Message successfully transmitted, ID=%s\n",
|
||||||
|
strrchr(str, '/') + 1);
|
||||||
else
|
else
|
||||||
printf("Message successfully transmitted, ID=%s\n", str);
|
printf("Message successfully transmitted, ID=%s\n", str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (strstr(response, "Logbook Selection"))
|
||||||
else if (strstr(response, "Logbook Selection"))
|
|
||||||
printf("Error: No logbook specified\n");
|
printf("Error: No logbook specified\n");
|
||||||
else if (strstr(response, "enter password"))
|
else if (strstr(response, "enter password"))
|
||||||
printf("Error: Missing or invalid password\n");
|
printf("Error: Missing or invalid password\n");
|
||||||
@ -556,7 +538,8 @@ int status, sock, i, n, header_length, content_length, index;
|
|||||||
struct hostent *phe;
|
struct hostent *phe;
|
||||||
struct sockaddr_in bind_addr;
|
struct sockaddr_in bind_addr;
|
||||||
char host_name[256], boundary[80], str[80], *encoding, *p;
|
char host_name[256], boundary[80], str[80], *encoding, *p;
|
||||||
char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_ATTR][NAME_LENGTH];
|
char old_attrib_name[MAX_N_ATTR][NAME_LENGTH],
|
||||||
|
old_attrib[MAX_N_ATTR][NAME_LENGTH];
|
||||||
|
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
{
|
{
|
||||||
@ -568,17 +551,16 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (edit)
|
if (edit) {
|
||||||
{
|
status =
|
||||||
status = retrieve_elog(host, port, subdir, experiment, passwd, uname, upwd, edit,
|
retrieve_elog(host, port, subdir, experiment, passwd, uname,
|
||||||
old_attrib_name, old_attrib, old_text);
|
upwd, edit, old_attrib_name, old_attrib, old_text);
|
||||||
|
|
||||||
if (status != 1)
|
if (status != 1)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
/* update attributes */
|
/* update attributes */
|
||||||
for (index=0 ; index<n_attr ; index++)
|
for (index = 0; index < n_attr; index++) {
|
||||||
{
|
|
||||||
for (i = 0; i < MAX_N_ATTR && old_attrib_name[i][0]; i++)
|
for (i = 0; i < MAX_N_ATTR && old_attrib_name[i][0]; i++)
|
||||||
if (equal_ustring(attrib_name[index], old_attrib_name[i]))
|
if (equal_ustring(attrib_name[index], old_attrib_name[i]))
|
||||||
break;
|
break;
|
||||||
@ -588,8 +570,7 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* copy attributes */
|
/* copy attributes */
|
||||||
for (i=0 ; i<MAX_N_ATTR && old_attrib_name[i][0] ; i++)
|
for (i = 0; i < MAX_N_ATTR && old_attrib_name[i][0]; i++) {
|
||||||
{
|
|
||||||
strlcpy(attrib_name[i], old_attrib_name[i], NAME_LENGTH);
|
strlcpy(attrib_name[i], old_attrib_name[i], NAME_LENGTH);
|
||||||
strlcpy(attrib[i], old_attrib[i], NAME_LENGTH);
|
strlcpy(attrib[i], old_attrib[i], NAME_LENGTH);
|
||||||
}
|
}
|
||||||
@ -600,17 +581,17 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
strlcpy(text, old_text, TEXT_SIZE);
|
strlcpy(text, old_text, TEXT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply)
|
if (reply) {
|
||||||
{
|
status =
|
||||||
status = retrieve_elog(host, port, subdir, experiment, passwd, uname, upwd, reply,
|
retrieve_elog(host, port, subdir, experiment, passwd, uname,
|
||||||
old_attrib_name, old_attrib, old_text);
|
upwd, reply, old_attrib_name, old_attrib,
|
||||||
|
old_text);
|
||||||
|
|
||||||
if (status != 1)
|
if (status != 1)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
/* update attributes */
|
/* update attributes */
|
||||||
for (index=0 ; index<n_attr ; index++)
|
for (index = 0; index < n_attr; index++) {
|
||||||
{
|
|
||||||
for (i = 0; i < MAX_N_ATTR && old_attrib_name[i][0]; i++)
|
for (i = 0; i < MAX_N_ATTR && old_attrib_name[i][0]; i++)
|
||||||
if (equal_ustring(attrib_name[index], old_attrib_name[i]))
|
if (equal_ustring(attrib_name[index], old_attrib_name[i]))
|
||||||
break;
|
break;
|
||||||
@ -620,8 +601,7 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* copy attributes */
|
/* copy attributes */
|
||||||
for (i=0 ; i<MAX_N_ATTR && old_attrib_name[i][0] ; i++)
|
for (i = 0; i < MAX_N_ATTR && old_attrib_name[i][0]; i++) {
|
||||||
{
|
|
||||||
strlcpy(attrib_name[i], old_attrib_name[i], NAME_LENGTH);
|
strlcpy(attrib_name[i], old_attrib_name[i], NAME_LENGTH);
|
||||||
strlcpy(attrib[i], old_attrib[i], NAME_LENGTH);
|
strlcpy(attrib[i], old_attrib[i], NAME_LENGTH);
|
||||||
}
|
}
|
||||||
@ -645,20 +625,15 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
text[0] = 0;
|
text[0] = 0;
|
||||||
p = old_text;
|
p = old_text;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
if (strchr(p, '\n')) {
|
||||||
if (strchr(p, '\n'))
|
|
||||||
{
|
|
||||||
*strchr(p, '\n') = 0;
|
*strchr(p, '\n') = 0;
|
||||||
|
|
||||||
if (encoding[0] == 'H')
|
if (encoding[0] == 'H') {
|
||||||
{
|
|
||||||
strlcat(text, "> ", TEXT_SIZE);
|
strlcat(text, "> ", TEXT_SIZE);
|
||||||
strlcat(text, p, TEXT_SIZE);
|
strlcat(text, p, TEXT_SIZE);
|
||||||
strlcat(text, "<br>\n", TEXT_SIZE);
|
strlcat(text, "<br>\n", TEXT_SIZE);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
strlcat(text, "> ", TEXT_SIZE);
|
strlcat(text, "> ", TEXT_SIZE);
|
||||||
strlcat(text, p, TEXT_SIZE);
|
strlcat(text, p, TEXT_SIZE);
|
||||||
strlcat(text, "\n", TEXT_SIZE);
|
strlcat(text, "\n", TEXT_SIZE);
|
||||||
@ -667,17 +642,12 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
p += strlen(p) + 1;
|
p += strlen(p) + 1;
|
||||||
if (*p == '\n')
|
if (*p == '\n')
|
||||||
p++;
|
p++;
|
||||||
}
|
} else {
|
||||||
else
|
if (encoding[0] == 'H') {
|
||||||
{
|
|
||||||
if (encoding[0] == 'H')
|
|
||||||
{
|
|
||||||
strlcat(text, "> ", TEXT_SIZE);
|
strlcat(text, "> ", TEXT_SIZE);
|
||||||
strlcat(text, p, TEXT_SIZE);
|
strlcat(text, p, TEXT_SIZE);
|
||||||
strlcat(text, "<p>\n", TEXT_SIZE);
|
strlcat(text, "<p>\n", TEXT_SIZE);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
strlcat(text, "> ", TEXT_SIZE);
|
strlcat(text, "> ", TEXT_SIZE);
|
||||||
strlcat(text, p, TEXT_SIZE);
|
strlcat(text, p, TEXT_SIZE);
|
||||||
strlcat(text, "\n\n", TEXT_SIZE);
|
strlcat(text, "\n\n", TEXT_SIZE);
|
||||||
@ -695,14 +665,12 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
gethostname(host_name, sizeof(host_name));
|
gethostname(host_name, sizeof(host_name));
|
||||||
|
|
||||||
phe = gethostbyname(host_name);
|
phe = gethostbyname(host_name);
|
||||||
if (phe == NULL)
|
if (phe == NULL) {
|
||||||
{
|
|
||||||
perror("Cannot retrieve host name");
|
perror("Cannot retrieve host name");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
phe = gethostbyaddr(phe->h_addr, sizeof(int), AF_INET);
|
phe = gethostbyaddr(phe->h_addr, sizeof(int), AF_INET);
|
||||||
if (phe == NULL)
|
if (phe == NULL) {
|
||||||
{
|
|
||||||
perror("Cannot retrieve host name");
|
perror("Cannot retrieve host name");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -712,8 +680,7 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
strcpy(host_name, phe->h_name);
|
strcpy(host_name, phe->h_name);
|
||||||
|
|
||||||
/* create socket */
|
/* create socket */
|
||||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||||
{
|
|
||||||
perror("cannot create socket");
|
perror("cannot create socket");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -725,8 +692,7 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
bind_addr.sin_port = htons((unsigned short) port);
|
bind_addr.sin_port = htons((unsigned short) port);
|
||||||
|
|
||||||
phe = gethostbyname(host);
|
phe = gethostbyname(host);
|
||||||
if (phe == NULL)
|
if (phe == NULL) {
|
||||||
{
|
|
||||||
perror("cannot get host name");
|
perror("cannot get host name");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -734,8 +700,7 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
|
|
||||||
/* connect to server */
|
/* connect to server */
|
||||||
status = connect(sock, (void *) &bind_addr, sizeof(bind_addr));
|
status = connect(sock, (void *) &bind_addr, sizeof(bind_addr));
|
||||||
if (status != 0)
|
if (status != 0) {
|
||||||
{
|
|
||||||
printf("Cannot connect to host %s, port %d\n", host, port);
|
printf("Cannot connect to host %s, port %d\n", host, port);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -748,59 +713,67 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
if (afilename[i][0])
|
if (afilename[i][0])
|
||||||
content_length += buffer_size[i];
|
content_length += buffer_size[i];
|
||||||
content = malloc(content_length);
|
content = malloc(content_length);
|
||||||
if (content == NULL)
|
if (content == NULL) {
|
||||||
{
|
|
||||||
printf("Not enough memory\n");
|
printf("Not enough memory\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compose content */
|
/* compose content */
|
||||||
srand((unsigned) time(NULL));
|
srand((unsigned) time(NULL));
|
||||||
sprintf(boundary, "---------------------------%04X%04X%04X", rand(), rand(), rand());
|
sprintf(boundary, "---------------------------%04X%04X%04X", rand(),
|
||||||
|
rand(), rand());
|
||||||
strcpy(content, boundary);
|
strcpy(content, boundary);
|
||||||
strcat(content, "\r\nContent-Disposition: form-data; name=\"cmd\"\r\n\r\nSubmit\r\n");
|
strcat(content,
|
||||||
|
"\r\nContent-Disposition: form-data; name=\"cmd\"\r\n\r\nSubmit\r\n");
|
||||||
|
|
||||||
if (uname[0])
|
if (uname[0])
|
||||||
sprintf(content + strlen(content),
|
sprintf(content + strlen(content),
|
||||||
"%s\r\nContent-Disposition: form-data; name=\"unm\"\r\n\r\n%s\r\n", boundary, uname);
|
"%s\r\nContent-Disposition: form-data; name=\"unm\"\r\n\r\n%s\r\n",
|
||||||
|
boundary, uname);
|
||||||
|
|
||||||
if (upwd[0])
|
if (upwd[0]) {
|
||||||
{
|
|
||||||
base64_encode(upwd, str);
|
base64_encode(upwd, str);
|
||||||
sprintf(content + strlen(content),
|
sprintf(content + strlen(content),
|
||||||
"%s\r\nContent-Disposition: form-data; name=\"upwd\"\r\n\r\n%s\r\n", boundary, str);
|
"%s\r\nContent-Disposition: form-data; name=\"upwd\"\r\n\r\n%s\r\n",
|
||||||
|
boundary, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (experiment[0])
|
if (experiment[0])
|
||||||
sprintf(content + strlen(content),
|
sprintf(content + strlen(content),
|
||||||
"%s\r\nContent-Disposition: form-data; name=\"exp\"\r\n\r\n%s\r\n", boundary, experiment);
|
"%s\r\nContent-Disposition: form-data; name=\"exp\"\r\n\r\n%s\r\n",
|
||||||
|
boundary, experiment);
|
||||||
|
|
||||||
if (reply)
|
if (reply)
|
||||||
sprintf(content + strlen(content),
|
sprintf(content + strlen(content),
|
||||||
"%s\r\nContent-Disposition: form-data; name=\"reply_to\"\r\n\r\n%d\r\n", boundary, reply);
|
"%s\r\nContent-Disposition: form-data; name=\"reply_to\"\r\n\r\n%d\r\n",
|
||||||
|
boundary, reply);
|
||||||
|
|
||||||
if (edit)
|
if (edit)
|
||||||
sprintf(content + strlen(content),
|
sprintf(content + strlen(content),
|
||||||
"%s\r\nContent-Disposition: form-data; name=\"edit_id\"\r\n\r\n%d\r\n", boundary, edit);
|
"%s\r\nContent-Disposition: form-data; name=\"edit_id\"\r\n\r\n%d\r\n",
|
||||||
|
boundary, edit);
|
||||||
|
|
||||||
if (suppress)
|
if (suppress)
|
||||||
sprintf(content + strlen(content),
|
sprintf(content + strlen(content),
|
||||||
"%s\r\nContent-Disposition: form-data; name=\"suppress\"\r\n\r\n1\r\n", boundary);
|
"%s\r\nContent-Disposition: form-data; name=\"suppress\"\r\n\r\n1\r\n",
|
||||||
|
boundary);
|
||||||
|
|
||||||
for (i = 0; i < n_attr; i++)
|
for (i = 0; i < n_attr; i++)
|
||||||
sprintf(content + strlen(content),
|
sprintf(content + strlen(content),
|
||||||
"%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n", boundary, attrib_name[i], attrib[i]);
|
"%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n",
|
||||||
|
boundary, attrib_name[i], attrib[i]);
|
||||||
|
|
||||||
sprintf(content + strlen(content),
|
sprintf(content + strlen(content),
|
||||||
"%s\r\nContent-Disposition: form-data; name=\"Text\"\r\n\r\n%s\r\n%s\r\n", boundary, text, boundary);
|
"%s\r\nContent-Disposition: form-data; name=\"Text\"\r\n\r\n%s\r\n%s\r\n",
|
||||||
|
boundary, text, boundary);
|
||||||
|
|
||||||
content_length = strlen(content);
|
content_length = strlen(content);
|
||||||
p = content + content_length;
|
p = content + content_length;
|
||||||
|
|
||||||
for (i = 0; i < MAX_ATTACHMENTS; i++)
|
for (i = 0; i < MAX_ATTACHMENTS; i++)
|
||||||
if (afilename[i][0])
|
if (afilename[i][0]) {
|
||||||
{
|
sprintf(p,
|
||||||
sprintf(p, "Content-Disposition: form-data; name=\"attfile%d\"; filename=\"%s\"\r\n\r\n",
|
"Content-Disposition: form-data; name=\"attfile%d\"; filename=\"%s\"\r\n\r\n",
|
||||||
i + 1, afilename[i]);
|
i + 1, afilename[i]);
|
||||||
|
|
||||||
content_length += strlen(p);
|
content_length += strlen(p);
|
||||||
@ -822,13 +795,14 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
sprintf(request + strlen(request), "%s/", experiment);
|
sprintf(request + strlen(request), "%s/", experiment);
|
||||||
strcat(request, " HTTP/1.0\r\n");
|
strcat(request, " HTTP/1.0\r\n");
|
||||||
|
|
||||||
sprintf(request+strlen(request), "Content-Type: multipart/form-data; boundary=%s\r\n", boundary);
|
sprintf(request + strlen(request),
|
||||||
|
"Content-Type: multipart/form-data; boundary=%s\r\n", boundary);
|
||||||
sprintf(request + strlen(request), "Host: %s\r\n", host_name);
|
sprintf(request + strlen(request), "Host: %s\r\n", host_name);
|
||||||
sprintf(request + strlen(request), "User-Agent: ELOG\r\n");
|
sprintf(request + strlen(request), "User-Agent: ELOG\r\n");
|
||||||
sprintf(request+strlen(request), "Content-Length: %d\r\n", content_length);
|
sprintf(request + strlen(request), "Content-Length: %d\r\n",
|
||||||
|
content_length);
|
||||||
|
|
||||||
if (passwd[0])
|
if (passwd[0]) {
|
||||||
{
|
|
||||||
base64_encode(passwd, str);
|
base64_encode(passwd, str);
|
||||||
sprintf(request + strlen(request), "Cookie: wpwd=%s\r\n", str);
|
sprintf(request + strlen(request), "Cookie: wpwd=%s\r\n", str);
|
||||||
}
|
}
|
||||||
@ -848,8 +822,7 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
|
|
||||||
/* send request */
|
/* send request */
|
||||||
send(sock, request, header_length, 0);
|
send(sock, request, header_length, 0);
|
||||||
if (verbose)
|
if (verbose) {
|
||||||
{
|
|
||||||
printf("Request sent to host:\n");
|
printf("Request sent to host:\n");
|
||||||
puts(request);
|
puts(request);
|
||||||
}
|
}
|
||||||
@ -861,16 +834,14 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
|
|
||||||
/* receive response */
|
/* receive response */
|
||||||
i = recv(sock, response, 10000, 0);
|
i = recv(sock, response, 10000, 0);
|
||||||
if (i < 0)
|
if (i < 0) {
|
||||||
{
|
|
||||||
perror("Cannot receive response");
|
perror("Cannot receive response");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* discard remainder of response */
|
/* discard remainder of response */
|
||||||
n = i;
|
n = i;
|
||||||
while (i > 0)
|
while (i > 0) {
|
||||||
{
|
|
||||||
i = recv(sock, response + n, 10000, 0);
|
i = recv(sock, response + n, 10000, 0);
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
n += i;
|
n += i;
|
||||||
@ -879,23 +850,19 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
|
|
||||||
closesocket(sock);
|
closesocket(sock);
|
||||||
|
|
||||||
if (verbose)
|
if (verbose) {
|
||||||
{
|
|
||||||
printf("Response received:\n");
|
printf("Response received:\n");
|
||||||
puts(response);
|
puts(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check response status */
|
/* check response status */
|
||||||
if (strstr(response, "302 Found"))
|
if (strstr(response, "302 Found")) {
|
||||||
{
|
if (strstr(response, "Location:")) {
|
||||||
if (strstr(response, "Location:"))
|
|
||||||
{
|
|
||||||
if (strstr(response, "wpwd"))
|
if (strstr(response, "wpwd"))
|
||||||
printf("Error: Invalid password\n");
|
printf("Error: Invalid password\n");
|
||||||
else if (strstr(response, "wusr"))
|
else if (strstr(response, "wusr"))
|
||||||
printf("Error: Invalid user name\n");
|
printf("Error: Invalid user name\n");
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
strncpy(str, strstr(response, "Location:") + 10, sizeof(str));
|
strncpy(str, strstr(response, "Location:") + 10, sizeof(str));
|
||||||
if (strchr(str, '?'))
|
if (strchr(str, '?'))
|
||||||
*strchr(str, '?') = 0;
|
*strchr(str, '?') = 0;
|
||||||
@ -905,28 +872,25 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
*strchr(str, '\r') = 0;
|
*strchr(str, '\r') = 0;
|
||||||
|
|
||||||
if (strrchr(str, '/'))
|
if (strrchr(str, '/'))
|
||||||
printf("Message successfully transmitted, ID=%s\n", strrchr(str, '/')+1);
|
printf("Message successfully transmitted, ID=%s\n",
|
||||||
|
strrchr(str, '/') + 1);
|
||||||
else
|
else
|
||||||
printf("Message successfully transmitted, ID=%s\n", str);
|
printf("Message successfully transmitted, ID=%s\n", str);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
printf("Message successfully transmitted\n");
|
printf("Message successfully transmitted\n");
|
||||||
}
|
} else if (strstr(response, "Logbook Selection"))
|
||||||
else if (strstr(response, "Logbook Selection"))
|
|
||||||
printf("Error: No logbook specified\n");
|
printf("Error: No logbook specified\n");
|
||||||
else if (strstr(response, "enter password"))
|
else if (strstr(response, "enter password"))
|
||||||
printf("Error: Missing or invalid password\n");
|
printf("Error: Missing or invalid password\n");
|
||||||
else if (strstr(response, "form name=form1"))
|
else if (strstr(response, "form name=form1"))
|
||||||
printf("Error: Missing or invalid user name/password\n");
|
printf("Error: Missing or invalid user name/password\n");
|
||||||
else if (strstr(response, "Error: Attribute"))
|
else if (strstr(response, "Error: Attribute")) {
|
||||||
{
|
|
||||||
strncpy(str, strstr(response, "Error: Attribute") + 20, sizeof(str));
|
strncpy(str, strstr(response, "Error: Attribute") + 20, sizeof(str));
|
||||||
if (strchr(str, '<'))
|
if (strchr(str, '<'))
|
||||||
*strchr(str, '<') = 0;
|
*strchr(str, '<') = 0;
|
||||||
printf("Error: Missing required attribute \"%s\"\n", str);
|
printf("Error: Missing required attribute \"%s\"\n", str);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
printf("Error transmitting message\n");
|
printf("Error transmitting message\n");
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@ -937,34 +901,33 @@ char old_attrib_name[MAX_N_ATTR][NAME_LENGTH], old_attrib[MAX_N_
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char str[1000], uname[80], upwd[80];
|
char str[1000], uname[80], upwd[80];
|
||||||
char host_name[256], logbook[32], textfile[256], password[80], subdir[256];
|
char host_name[256], logbook[32], textfile[256], password[80],
|
||||||
|
subdir[256];
|
||||||
char *buffer[MAX_ATTACHMENTS], attachment[MAX_ATTACHMENTS][256];
|
char *buffer[MAX_ATTACHMENTS], attachment[MAX_ATTACHMENTS][256];
|
||||||
INT att_size[MAX_ATTACHMENTS];
|
INT att_size[MAX_ATTACHMENTS];
|
||||||
INT i, n, fh, n_att, n_attr, size, port, reply, edit, suppress;
|
INT i, n, fh, n_att, n_attr, size, port, reply, edit, suppress;
|
||||||
char attr_name[MAX_N_ATTR][NAME_LENGTH], attrib[MAX_N_ATTR][NAME_LENGTH];
|
char attr_name[MAX_N_ATTR][NAME_LENGTH],
|
||||||
|
attrib[MAX_N_ATTR][NAME_LENGTH];
|
||||||
|
|
||||||
text[0] = textfile[0] = uname[0] = upwd[0] = suppress = 0;
|
text[0] = textfile[0] = uname[0] = upwd[0] = suppress = 0;
|
||||||
host_name[0] = logbook[0] = password[0] = subdir[0] = n_att = n_attr = reply = edit = 0;
|
host_name[0] = logbook[0] = password[0] = subdir[0] = n_att = n_attr =
|
||||||
|
reply = edit = 0;
|
||||||
port = 80;
|
port = 80;
|
||||||
|
|
||||||
for (i=0 ; i<MAX_ATTACHMENTS ; i++)
|
for (i = 0; i < MAX_ATTACHMENTS; i++) {
|
||||||
{
|
|
||||||
attachment[i][0] = 0;
|
attachment[i][0] = 0;
|
||||||
buffer[i] = NULL;
|
buffer[i] = NULL;
|
||||||
att_size[i] = 0;
|
att_size[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse command line parameters */
|
/* parse command line parameters */
|
||||||
for (i=1 ; i<argc ; i++)
|
for (i = 1; i < argc; i++) {
|
||||||
{
|
|
||||||
if (argv[i][0] == '-' && argv[i][1] == 'v')
|
if (argv[i][0] == '-' && argv[i][1] == 'v')
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
else if (argv[i][0] == '-' && argv[i][1] == 's')
|
else if (argv[i][0] == '-' && argv[i][1] == 's')
|
||||||
suppress = 1;
|
suppress = 1;
|
||||||
else
|
else {
|
||||||
{
|
if (argv[i][0] == '-') {
|
||||||
if (argv[i][0] == '-')
|
|
||||||
{
|
|
||||||
if (i + 1 >= argc || argv[i + 1][0] == '-')
|
if (i + 1 >= argc || argv[i + 1][0] == '-')
|
||||||
goto usage;
|
goto usage;
|
||||||
if (argv[i][1] == 'h')
|
if (argv[i][1] == 'h')
|
||||||
@ -977,28 +940,22 @@ char attr_name[MAX_N_ATTR][NAME_LENGTH], attrib[MAX_N_ATTR][NAME_LENGTH];
|
|||||||
strcpy(password, argv[++i]);
|
strcpy(password, argv[++i]);
|
||||||
else if (argv[i][1] == 's')
|
else if (argv[i][1] == 's')
|
||||||
strcpy(subdir, argv[++i]);
|
strcpy(subdir, argv[++i]);
|
||||||
else if (argv[i][1] == 'u')
|
else if (argv[i][1] == 'u') {
|
||||||
{
|
|
||||||
strcpy(uname, argv[++i]);
|
strcpy(uname, argv[++i]);
|
||||||
strcpy(upwd, argv[++i]);
|
strcpy(upwd, argv[++i]);
|
||||||
}
|
} else if (argv[i][1] == 'a') {
|
||||||
else if (argv[i][1] == 'a')
|
|
||||||
{
|
|
||||||
strcpy(str, argv[++i]);
|
strcpy(str, argv[++i]);
|
||||||
if (strchr(str, '='))
|
if (strchr(str, '=')) {
|
||||||
{
|
|
||||||
strcpy(attrib[n_attr], strchr(str, '=') + 1);
|
strcpy(attrib[n_attr], strchr(str, '=') + 1);
|
||||||
*strchr(str, '=') = 0;
|
*strchr(str, '=') = 0;
|
||||||
strcpy(attr_name[n_attr], str);
|
strcpy(attr_name[n_attr], str);
|
||||||
n_attr++;
|
n_attr++;
|
||||||
}
|
} else {
|
||||||
else
|
printf
|
||||||
{
|
("Error: Attributes must be supplied in the form \"-a <attribute>=<value>\".\n");
|
||||||
printf("Error: Attributes must be supplied in the form \"-a <attribute>=<value>\".\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
} else if (argv[i][1] == 'f')
|
||||||
else if (argv[i][1] == 'f')
|
|
||||||
strcpy(attachment[n_att++], argv[++i]);
|
strcpy(attachment[n_att++], argv[++i]);
|
||||||
else if (argv[i][1] == 'r')
|
else if (argv[i][1] == 'r')
|
||||||
reply = atoi(argv[++i]);
|
reply = atoi(argv[++i]);
|
||||||
@ -1006,59 +963,68 @@ char attr_name[MAX_N_ATTR][NAME_LENGTH], attrib[MAX_N_ATTR][NAME_LENGTH];
|
|||||||
edit = atoi(argv[++i]);
|
edit = atoi(argv[++i]);
|
||||||
else if (argv[i][1] == 'm')
|
else if (argv[i][1] == 'm')
|
||||||
strcpy(textfile, argv[++i]);
|
strcpy(textfile, argv[++i]);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
usage:
|
usage:
|
||||||
printf("\nusage: elog\n");
|
printf("\nusage: elog\n");
|
||||||
printf(" -h <hostname> [-p port] [-s subdir]\n");
|
printf(" -h <hostname> [-p port] [-s subdir]\n");
|
||||||
printf(" Location where elogd is running\n");
|
printf
|
||||||
printf(" -l logbook/experiment Name of logbook or experiment\n");
|
(" Location where elogd is running\n");
|
||||||
printf(" [-v] for verbose output\n");
|
printf
|
||||||
printf(" [-w password] write password defined on server\n");
|
(" -l logbook/experiment Name of logbook or experiment\n");
|
||||||
printf(" [-u username password] user name and password\n");
|
printf
|
||||||
printf(" [-f <attachment>] (up to %d times)\n", MAX_ATTACHMENTS);
|
(" [-v] for verbose output\n");
|
||||||
printf(" -a <attribute>=<value> (up to %d times)\n", MAX_N_ATTR);
|
printf
|
||||||
printf(" [-r <id>] Reply to existing message\n");
|
(" [-w password] write password defined on server\n");
|
||||||
printf(" [-e <id>] Edit existing message\n");
|
printf
|
||||||
printf(" [-s] Suppress email notification\n");
|
(" [-u username password] user name and password\n");
|
||||||
|
printf
|
||||||
|
(" [-f <attachment>] (up to %d times)\n",
|
||||||
|
MAX_ATTACHMENTS);
|
||||||
|
printf
|
||||||
|
(" -a <attribute>=<value> (up to %d times)\n",
|
||||||
|
MAX_N_ATTR);
|
||||||
|
printf
|
||||||
|
(" [-r <id>] Reply to existing message\n");
|
||||||
|
printf
|
||||||
|
(" [-e <id>] Edit existing message\n");
|
||||||
|
printf
|
||||||
|
(" [-s] Suppress email notification\n");
|
||||||
printf(" -m <textfile>] | <text>\n");
|
printf(" -m <textfile>] | <text>\n");
|
||||||
printf("\nArguments with blanks must be enclosed in quotes\n");
|
printf
|
||||||
printf("The elog message can either be submitted on the command line, piped in like\n");
|
("\nArguments with blanks must be enclosed in quotes\n");
|
||||||
printf("\"cat text | elog -h ... -l ... -a ...\" or in a file with the -m flag.\n");
|
printf
|
||||||
printf("Multiple attributes and attachments can be supplied\n");
|
("The elog message can either be submitted on the command line, piped in like\n");
|
||||||
|
printf
|
||||||
|
("\"cat text | elog -h ... -l ... -a ...\" or in a file with the -m flag.\n");
|
||||||
|
printf
|
||||||
|
("Multiple attributes and attachments can be supplied\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
strcpy(text, argv[i]);
|
strcpy(text, argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host_name[0] == 0)
|
if (host_name[0] == 0) {
|
||||||
{
|
|
||||||
printf("Please specify hostname.\n");
|
printf("Please specify hostname.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logbook[0] == 0)
|
if (logbook[0] == 0) {
|
||||||
{
|
|
||||||
printf("Please specify logbook with the \"-l\" flag.\n");
|
printf("Please specify logbook with the \"-l\" flag.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n_attr == 0 && !edit && !reply)
|
if (n_attr == 0 && !edit && !reply) {
|
||||||
{
|
|
||||||
printf("Please specify attribute(s) with the \"-a\" flag.\n");
|
printf("Please specify attribute(s) with the \"-a\" flag.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fh = -1;
|
fh = -1;
|
||||||
|
|
||||||
if (textfile[0])
|
if (textfile[0]) {
|
||||||
{
|
|
||||||
fh = open(textfile, O_RDONLY | O_BINARY);
|
fh = open(textfile, O_RDONLY | O_BINARY);
|
||||||
if (fh < 0)
|
if (fh < 0) {
|
||||||
{
|
|
||||||
printf("Message file \"%s\" does not exist.\n", textfile);
|
printf("Message file \"%s\" does not exist.\n", textfile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1066,16 +1032,15 @@ char attr_name[MAX_N_ATTR][NAME_LENGTH], attrib[MAX_N_ATTR][NAME_LENGTH];
|
|||||||
size = lseek(fh, 0, SEEK_END);
|
size = lseek(fh, 0, SEEK_END);
|
||||||
lseek(fh, 0, SEEK_SET);
|
lseek(fh, 0, SEEK_SET);
|
||||||
|
|
||||||
if (size > sizeof(text)-1)
|
if (size > sizeof(text) - 1) {
|
||||||
{
|
printf("Message file \"%s\" is too long (%d bytes max).\n",
|
||||||
printf("Message file \"%s\" is too long (%d bytes max).\n", textfile, sizeof(text));
|
textfile, sizeof(text));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = read(fh, text, size);
|
i = read(fh, text, size);
|
||||||
|
|
||||||
if (i < size)
|
if (i < size) {
|
||||||
{
|
|
||||||
printf("Cannot fully read message from file %s.\n", textfile);
|
printf("Cannot fully read message from file %s.\n", textfile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1083,14 +1048,12 @@ char attr_name[MAX_N_ATTR][NAME_LENGTH], attrib[MAX_N_ATTR][NAME_LENGTH];
|
|||||||
close(fh);
|
close(fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text[0] == 0 && textfile[0] == 0 && !edit)
|
if (text[0] == 0 && textfile[0] == 0 && !edit) {
|
||||||
{
|
|
||||||
/* read from stdin */
|
/* read from stdin */
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
do
|
do {
|
||||||
{
|
|
||||||
i = getchar();
|
i = getchar();
|
||||||
|
|
||||||
text[n++] = i;
|
text[n++] = i;
|
||||||
@ -1103,14 +1066,12 @@ char attr_name[MAX_N_ATTR][NAME_LENGTH], attrib[MAX_N_ATTR][NAME_LENGTH];
|
|||||||
|
|
||||||
/*---- open attachment file ----*/
|
/*---- open attachment file ----*/
|
||||||
|
|
||||||
for (i = 0 ; i<MAX_ATTACHMENTS ; i++)
|
for (i = 0; i < MAX_ATTACHMENTS; i++) {
|
||||||
{
|
|
||||||
if (!attachment[i][0])
|
if (!attachment[i][0])
|
||||||
break;
|
break;
|
||||||
|
|
||||||
fh = open(attachment[i], O_RDONLY | O_BINARY);
|
fh = open(attachment[i], O_RDONLY | O_BINARY);
|
||||||
if (fh < 0)
|
if (fh < 0) {
|
||||||
{
|
|
||||||
printf("Attachment file \"%s\" does not exist.\n", attachment[i]);
|
printf("Attachment file \"%s\" does not exist.\n", attachment[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1121,9 +1082,9 @@ char attr_name[MAX_N_ATTR][NAME_LENGTH], attrib[MAX_N_ATTR][NAME_LENGTH];
|
|||||||
buffer[i] = malloc(att_size[i] + 1);
|
buffer[i] = malloc(att_size[i] + 1);
|
||||||
|
|
||||||
n = read(fh, buffer[i], att_size[i]);
|
n = read(fh, buffer[i], att_size[i]);
|
||||||
if (n < att_size[i])
|
if (n < att_size[i]) {
|
||||||
{
|
printf("Cannot fully read attachment file \"%s\".\n",
|
||||||
printf("Cannot fully read attachment file \"%s\".\n", attachment[i]);
|
attachment[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
buffer[i][n] = 0;
|
buffer[i][n] = 0;
|
||||||
|
|||||||
6476
src/elogd.c
6476
src/elogd.c
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user