diff --git a/src/elogd.c b/src/elogd.c index ddf5f829..1bf65689 100755 --- a/src/elogd.c +++ b/src/elogd.c @@ -43,8 +43,8 @@ const char *_git_revision = GIT_REVISION; BOOL running_as_daemon; /* Running as a daemon/service? */ int elog_tcp_port; /* Server's TCP port */ -static void (*printf_handler) (const char *); /* Handler to printf for logging */ -static void (*fputs_handler) (const char *); /* Handler to fputs for logging */ +static void (*printf_handler)(const char *); /* Handler to printf for logging */ +static void (*fputs_handler)(const char *); /* Handler to fputs for logging */ static FILE *current_output_stream = NULL; /* Currently used output stream */ char *return_buffer; @@ -90,116 +90,177 @@ LOGBOOK *lb_list = NULL; SSL *_ssl_con; #endif -char *mname[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", - "October", "November", "December" +char *mname[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", + "October", "November", "December" }; char attr_list[MAX_N_ATTR][NAME_LENGTH]; char attr_options[MAX_N_ATTR][MAX_N_LIST][NAME_LENGTH]; int attr_flags[MAX_N_ATTR]; -char attr_list_default[][NAME_LENGTH] = { "Author", "Type", "Category", "Subject", "" }; +char attr_list_default[][NAME_LENGTH] = {"Author", "Type", "Category", "Subject", ""}; -char attr_options_default[][MAX_N_LIST][NAME_LENGTH] = { {""}, {"Routine", "Other"}, -{"General", "Other"}, {""} +char attr_options_default[][MAX_N_LIST][NAME_LENGTH] = {{""}, + {"Routine", "Other"}, + {"General", "Other"}, + {""} }; -int attr_flags_default[] = { AF_REQUIRED, 0, 0, 0 }; +int attr_flags_default[] = {AF_REQUIRED, 0, 0, 0}; struct { char ext[32]; char type[80]; } filetype[] = { - { - ".AI", "application/postscript"}, { - ".ASC", "text/plain"}, { - ".BZ2", "application/x-bzip2"}, { - ".CFG", "text/plain"}, { - ".CHRT", "application/x-kchart"}, { - ".CONF", "text/plain"}, { - ".CSH", "application/x-csh"}, { - ".CSS", "text/css"}, { - ".DOC", "application/msword"}, { - ".DVI", "application/x-dvi"}, { - ".EPS", "application/postscript"}, { - ".GIF", "image/gif"}, { - ".GZ", "application/x-gzip"}, { - ".HTM", "text/html"}, { - ".HTML", "text/html"}, { - ".ICO", "image/x-icon"}, { - ".JPEG", "image/jpeg"}, { - ".JPG", "image/jpeg"}, { - ".JS", "application/x-javascript"}, { - ".KPR", "application/x-kpresenter"}, { - ".KSP", "application/x-kspread"}, { - ".KWD", "application/x-kword"}, { - ".MP3", "audio/mpeg"}, { - ".OGG", "application/x-ogg"}, { - ".PDF", "application/pdf"}, { - ".PNG", "image/png"}, { - ".PS", "application/postscript"}, { - ".RAM", "audio/x-pn-realaudio"}, { - ".RM", "audio/x-pn-realaudio"}, { - ".RM", "audio/x-pn-realaudio"}, { - ".RM", "audio/x-pn-realaudio"}, { - ".RPM", "application/x-rpm"}, { - ".RTF", "application/rtf"}, { - ".SH", "application/x-sh"}, { - ".SVG", "image/svg+xml"}, { - ".TAR", "application/x-tar"}, { - ".TCL", "application/x-tcl"}, { - ".TEX", "application/x-tex"}, { - ".TGZ", "application/x-gzip"}, { - ".TIF", "image/tiff"}, { - ".TIFF", "image/tiff"}, { - ".TXT", "text/plain"}, { - ".WAV", "audio/x-wav"}, { - ".XLS", "application/x-msexcel"}, { - ".XML", "text/xml"}, { - ".XSL", "text/xml"}, { - ".ZIP", "application/x-zip-compressed"}, { + { + ".AI", "application/postscript"}, + { + ".ASC", "text/plain"}, + { + ".BZ2", "application/x-bzip2"}, + { + ".CFG", "text/plain"}, + { + ".CHRT", "application/x-kchart"}, + { + ".CONF", "text/plain"}, + { + ".CSH", "application/x-csh"}, + { + ".CSS", "text/css"}, + { + ".DOC", "application/msword"}, + { + ".DVI", "application/x-dvi"}, + { + ".EPS", "application/postscript"}, + { + ".GIF", "image/gif"}, + { + ".GZ", "application/x-gzip"}, + { + ".HTM", "text/html"}, + { + ".HTML", "text/html"}, + { + ".ICO", "image/x-icon"}, + { + ".JPEG", "image/jpeg"}, + { + ".JPG", "image/jpeg"}, + { + ".JS", "application/x-javascript"}, + { + ".KPR", "application/x-kpresenter"}, + { + ".KSP", "application/x-kspread"}, + { + ".KWD", "application/x-kword"}, + { + ".MP3", "audio/mpeg"}, + { + ".OGG", "application/x-ogg"}, + { + ".PDF", "application/pdf"}, + { + ".PNG", "image/png"}, + { + ".PS", "application/postscript"}, + { + ".RAM", "audio/x-pn-realaudio"}, + { + ".RM", "audio/x-pn-realaudio"}, + { + ".RM", "audio/x-pn-realaudio"}, + { + ".RM", "audio/x-pn-realaudio"}, + { + ".RPM", "application/x-rpm"}, + { + ".RTF", "application/rtf"}, + { + ".SH", "application/x-sh"}, + { + ".SVG", "image/svg+xml"}, + { + ".TAR", "application/x-tar"}, + { + ".TCL", "application/x-tcl"}, + { + ".TEX", "application/x-tex"}, + { + ".TGZ", "application/x-gzip"}, + { + ".TIF", "image/tiff"}, + { + ".TIFF", "image/tiff"}, + { + ".TXT", "text/plain"}, + { + ".WAV", "audio/x-wav"}, + { + ".XLS", "application/x-msexcel"}, + { + ".XML", "text/xml"}, + { + ".XSL", "text/xml"}, + { + ".ZIP", "application/x-zip-compressed"}, + { - /* Open XML file types */ - ".DOCM", "application/vnd.ms-word.document.macroEnabled.12"}, { - ".DOCX", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, { - ".DOTM", "application/vnd.ms-word.template.macroEnabled.12"}, { - ".DOTX", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"}, { - ".PPSM", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12"}, { - ".PPSX", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"}, { - ".PPTM", "application/vnd.ms-powerpoint.presentation.macroEnabled.12"}, { - ".PPTX", "application/vnd.openxmlformats-officedocument.presentationml.presentation"}, { - ".XLSB", "application/vnd.ms-excel.sheet.binary.macroEnabled.12"}, { - ".XLSM", "application/vnd.ms-excel.sheet.macroEnabled.12"}, { - ".XLSX", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, { - ".XPS", "application/vnd.ms-xpsdocument"}, { + /* Open XML file types */ + ".DOCM", "application/vnd.ms-word.document.macroEnabled.12"}, + { + ".DOCX", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}, + { + ".DOTM", "application/vnd.ms-word.template.macroEnabled.12"}, + { + ".DOTX", "application/vnd.openxmlformats-officedocument.wordprocessingml.template"}, + { + ".PPSM", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12"}, + { + ".PPSX", "application/vnd.openxmlformats-officedocument.presentationml.slideshow"}, + { + ".PPTM", "application/vnd.ms-powerpoint.presentation.macroEnabled.12"}, + { + ".PPTX", "application/vnd.openxmlformats-officedocument.presentationml.presentation"}, + { + ".XLSB", "application/vnd.ms-excel.sheet.binary.macroEnabled.12"}, + { + ".XLSM", "application/vnd.ms-excel.sheet.macroEnabled.12"}, + { + ".XLSX", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}, + { + ".XPS", "application/vnd.ms-xpsdocument"}, + { -"", ""},}; + "", ""},}; struct { char language[32]; char abbrev[32]; } lang_table[] = { - - { "brazilian", "br"}, - { "bulgarian", "bg"}, - { "czech", "cz"}, - { "danish", "dk"}, - { "dutch", "nl"}, - { "french", "fr"}, - { "german", "de"}, - { "indonesia", "id"}, - { "italian", "it"}, - { "japanese", "jp"}, - { "polish", "pl"}, - { "ru_CP1251", "ru"}, - { "slowak", "sk"}, - { "spanish", "es"}, - { "swedish", "se"}, - { "turkish", "tr"}, - { "zh_CN-GB2314", "zh"}, - { "zh_CN-UTF8", "zh"}, - { "", "" } + + {"brazilian", "br"}, + {"bulgarian", "bg"}, + {"czech", "cz"}, + {"danish", "dk"}, + {"dutch", "nl"}, + {"french", "fr"}, + {"german", "de"}, + {"indonesia", "id"}, + {"italian", "it"}, + {"japanese", "jp"}, + {"polish", "pl"}, + {"ru_CP1251", "ru"}, + {"slowak", "sk"}, + {"spanish", "es"}, + {"swedish", "se"}, + {"turkish", "tr"}, + {"zh_CN-GB2314", "zh"}, + {"zh_CN-UTF8", "zh"}, + {"", ""} }; char _convert_cmd[256]; @@ -224,8 +285,7 @@ long _timezone; #define my_toupper(_c) ( ((_c)>='a' && (_c)<='z') ? ((_c)-'a'+'A') : (_c) ) #define my_tolower(_c) ( ((_c)>='A' && (_c)<='Z') ? ((_c)-'A'+'a') : (_c) ) -BOOL strieq(const char *str1, const char *str2) -{ +BOOL strieq(const char *str1, const char *str2) { char c1, c2; if (str1 == NULL && str2 == NULL) @@ -248,8 +308,7 @@ BOOL strieq(const char *str1, const char *str2) return TRUE; } -BOOL strnieq(const char *str1, const char *str2, int n) -{ +BOOL strnieq(const char *str1, const char *str2, int n) { char c1, c2; int i; @@ -273,8 +332,7 @@ BOOL strnieq(const char *str1, const char *str2, int n) return TRUE; } -char *stristr(const char *str, const char *pattern) -{ +char *stristr(const char *str, const char *pattern) { char c1, c2, *ps, *pp; if (str == NULL || pattern == NULL) @@ -316,8 +374,7 @@ void strextract(const char *str, char delim, char *extr, int size) extr[i] = 0; } -static BOOL chkext(const char *str, const char *ext) -{ +static BOOL chkext(const char *str, const char *ext) { int extl, strl; char c1, c2; @@ -338,25 +395,21 @@ static BOOL chkext(const char *str, const char *ext) return TRUE; } -int get_verbose(void) -{ +int get_verbose(void) { return _verbose_level; } -void set_verbose(int v) -{ +void set_verbose(int v) { _verbose_level = v; } /* workaround for some gcc versions bug for "%c" format (see strftime(3) */ -size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) -{ +size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) { return strftime(s, max, fmt, tm); } /* signal save read function */ -int my_read(int fh, void *buffer, unsigned int bytes) -{ +int my_read(int fh, void *buffer, unsigned int bytes) { #ifdef OS_UNIX int i, n = 0; @@ -386,8 +439,7 @@ int my_read(int fh, void *buffer, unsigned int bytes) } /* workaround for wong timezone under MAX OSX */ -long my_timezone() -{ +long my_timezone() { #if defined(OS_MACOSX) || defined(__FreeBSD__) || defined(__OpenBSD__) time_t tp; time(&tp); @@ -399,8 +451,7 @@ long my_timezone() /*---- Compose RFC2822 compliant date ---*/ -void get_rfc2822_date(char *date, int size, time_t ltime) -{ +void get_rfc2822_date(char *date, int size, time_t ltime) { time_t now; char buf[256]; int offset; @@ -425,8 +476,7 @@ void get_rfc2822_date(char *date, int size, time_t ltime) /*---- Safe malloc wrappers with out of memory checking from GNU ---*/ -static void memory_error_and_abort(char *func) -{ +static void memory_error_and_abort(char *func) { eprintf("%s: not enough memory\n", func); exit(EXIT_FAILURE); } @@ -434,8 +484,7 @@ static void memory_error_and_abort(char *func) /* Return a pointer to free()able block of memory large enough to hold BYTES number of bytes. If the memory cannot be allocated, print an error message and abort. */ -void *xmalloc(size_t bytes) -{ +void *xmalloc(size_t bytes) { char *temp; /* Align buffer on 4 byte boundery for HP UX and other 64 bit systems to prevent Bus error (core dump) */ @@ -454,8 +503,7 @@ void *xmalloc(size_t bytes) return (temp + 8); } -void *xcalloc(size_t count, size_t bytes) -{ +void *xcalloc(size_t count, size_t bytes) { char *temp; /* Align buffer on 4 byte boundery for HP UX and other 64 bit systems to prevent Bus error (core dump) */ @@ -475,8 +523,7 @@ void *xcalloc(size_t count, size_t bytes) return (temp + 8); } -void *xrealloc(void *pointer, size_t bytes) -{ +void *xrealloc(void *pointer, size_t bytes) { char *temp; int old_size; @@ -506,8 +553,7 @@ void *xrealloc(void *pointer, size_t bytes) return (temp + 8); } -void xfree(void *pointer) -{ +void xfree(void *pointer) { char *temp; int old_size; @@ -523,8 +569,7 @@ void xfree(void *pointer) free(temp - 8); } -char *xstrdup(const char *string) -{ +char *xstrdup(const char *string) { char *s; s = (char *) xmalloc(strlen(string) + 1); @@ -540,10 +585,10 @@ char *xstrdup(const char *string) #endif #ifndef HAVE_VASPRintF + /* vasprintf implementation taken (and adapted) from GNU libiberty */ -static int int_vasprintf(char **result, const char *format, va_list args) -{ +static int int_vasprintf(char **result, const char *format, va_list args) { const char *p = format; /* Add one to make sure that it is never zero, which might cause malloc to return NULL. */ @@ -581,34 +626,34 @@ static int int_vasprintf(char **result, const char *format, va_list args) */ total_width += 30; switch (*p) { - case 'd': - case 'i': - case 'o': - case 'u': - case 'x': - case 'X': - case 'c': - (void) va_arg(ap, int); - break; - case 'f': - case 'e': - case 'E': - case 'g': - case 'G': - (void) va_arg(ap, double); - /* + case 'd': + case 'i': + case 'o': + case 'u': + case 'x': + case 'X': + case 'c': + (void) va_arg(ap, int); + break; + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + (void) va_arg(ap, double); + /* * Since an ieee double can have an exponent of 307, we'll * make the buffer wide enough to cover the gross case. */ - total_width += 307; - break; - case 's': - total_width += strlen(va_arg(ap, char *)); - break; - case 'p': - case 'n': - (void) va_arg(ap, char *); - break; + total_width += 307; + break; + case 's': + total_width += strlen(va_arg(ap, char *)); + break; + case 'p': + case 'n': + (void) va_arg(ap, char *); + break; } p++; } @@ -626,23 +671,24 @@ static int int_vasprintf(char **result, const char *format, va_list args) #if defined (_BSD_VA_LIST_) && defined (__FreeBSD__) int vasprintf(char **result, const char *format, _BSD_VA_LIST_ args) #else + int vasprintf(char **result, const char *format, va_list args) #endif { return int_vasprintf(result, format, args); } + #endif /* ! HAVE_VASPRintF */ /* Safe replacement for vasprintf (adapted code from Samba) */ -int xvasprintf(char **ptr, const char *format, va_list ap) -{ +int xvasprintf(char **ptr, const char *format, va_list ap) { int n; va_list save; #ifdef va_copy va_copy(save, ap); #else -#ifdef __va_copy + #ifdef __va_copy __va_copy(save, ap); #else save = ap; @@ -660,8 +706,7 @@ int xvasprintf(char **ptr, const char *format, va_list ap) } /* Driver for printf_handler, drop-in replacement for printf */ -void eprintf(const char *format, ...) -{ +void eprintf(const char *format, ...) { va_list ap; char *msg; @@ -669,34 +714,31 @@ void eprintf(const char *format, ...) xvasprintf(&msg, format, ap); va_end(ap); - (*printf_handler) (msg); + (*printf_handler)(msg); free(msg); } /* Driver for fputs_handler, drop-in replacement for fputs(buf, fd) */ -void efputs(const char *buf) -{ - (*fputs_handler) (buf); +void efputs(const char *buf) { + (*fputs_handler)(buf); } /* Dump with the newline, drop-in replacement for puts(buf) */ -void eputs(const char *buf) -{ +void eputs(const char *buf) { char *p; p = xmalloc(strlen(buf) + 2); strcpy(p, buf); strcat(p, "\n"); - (*fputs_handler) (p); + (*fputs_handler)(p); xfree(p); } /* Flush the current output stream */ -void eflush(void) -{ +void eflush(void) { /* Do this only for non-NULL streams (uninitiated stream or a syslog) */ if (current_output_stream != NULL) fflush(current_output_stream); @@ -707,8 +749,7 @@ HANDLE hEventLog; #endif /* Print MSG to syslog */ -void print_syslog(const char *msg) -{ +void print_syslog(const char *msg) { char *p; /* strip trailing \r and \n */ @@ -726,14 +767,12 @@ void print_syslog(const char *msg) } /* Print MSG to stderr */ -void print_stderr(const char *msg) -{ +void print_stderr(const char *msg) { fprintf(stderr, "%s", msg); } /* Dump BUF to syslog */ -void fputs_syslog(const char *buf) -{ +void fputs_syslog(const char *buf) { char *p; /* strip trailing \r and \n */ @@ -751,15 +790,13 @@ void fputs_syslog(const char *buf) } /* Dump BUF to stderr */ -void fputs_stderr(const char *buf) -{ +void fputs_stderr(const char *buf) { fputs(buf, stderr); } /* Redirect all messages handled with eprintf/efputs to syslog (Unix) or event log (Windows) */ -void redirect_to_syslog(void) -{ +void redirect_to_syslog(void) { static int has_inited = 0; /* initiate syslog */ @@ -781,8 +818,7 @@ void redirect_to_syslog(void) } /* Redirect all messages handled with eprintf/efputs to stderr */ -void redirect_to_stderr(void) -{ +void redirect_to_stderr(void) { printf_handler = print_stderr; fputs_handler = fputs_stderr; @@ -791,11 +827,10 @@ void redirect_to_stderr(void) /*------------------------------------------------------------------*/ -int my_shell(char *cmd, char *result, int size) -{ +int my_shell(char *cmd, char *result, int size) { #ifdef OS_WINNT - HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup, + HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup, hChildStdoutRd, hChildStdoutWr, hChildStderrRd, hChildStderrWr, hSaveStdin, hSaveStdout, hSaveStderr; SECURITY_ATTRIBUTES saAttr; @@ -939,7 +974,7 @@ int my_shell(char *cmd, char *result, int size) return 0; } close(fh); - + if ((child_pid = fork()) < 0) return 0; else if (child_pid > 0) { @@ -947,12 +982,12 @@ int my_shell(char *cmd, char *result, int size) do { wait_status = waitpid(child_pid, &status, 0); } while (wait_status == -1 && errno == EINTR); - + /* read back result */ memset(result, 0, size); fh = open(tmp_filename, O_RDONLY); if (fh > 0) { - read(fh, result, size-1); + read(fh, result, size - 1); close(fh); } @@ -1302,8 +1337,7 @@ void stou(char *str) char *map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -int cind(char c) -{ +int cind(char c) { int i; if (c == '=') @@ -1316,8 +1350,7 @@ int cind(char c) return -1; } -void base64_decode(char *s, char *d) -{ +void base64_decode(char *s, char *d) { unsigned int t; while (s && *s) { @@ -1341,8 +1374,7 @@ void base64_decode(char *s, char *d) *d = 0; } -void base64_encode(unsigned char *s, unsigned char *d, int size) -{ +void base64_encode(unsigned char *s, unsigned char *d, int size) { unsigned int t, pad; unsigned char *p; @@ -1374,8 +1406,7 @@ void base64_encode(unsigned char *s, unsigned char *d, int size) *(--d) = '='; } -void base64_bufenc(unsigned char *s, int len, char *d) -{ +void base64_bufenc(unsigned char *s, int len, char *d) { unsigned int t, pad; int i; @@ -1406,8 +1437,7 @@ void base64_bufenc(unsigned char *s, int len, char *d) char *sha256_crypt(const char *key, const char *salt); -void do_crypt(const char *s, char *d, int size) -{ +void do_crypt(const char *s, char *d, int size) { strlcpy(d, sha256_crypt(s, "$5$") + 4, size); } @@ -1426,8 +1456,11 @@ typedef struct { /* prototypes of the support routines */ void _MD5_update(MD5_CONTEXT *, const void *, unsigned int); + void _MD5_transform(unsigned int[4], unsigned char[64]); + void _MD5_encode(unsigned char *, unsigned int *, unsigned int); + void _MD5_decode(unsigned int *, unsigned char *, unsigned int); /* F, G, H and I are basic MD5 functions */ @@ -1466,16 +1499,16 @@ void _MD5_decode(unsigned int *, unsigned char *, unsigned int); /* main MD5 checksum routine, returns digest from pdata buffer */ -void MD5_checksum(const void *pdata, unsigned int len, unsigned char digest[16]) -{ +void MD5_checksum(const void *pdata, unsigned int len, unsigned char digest[16]) { MD5_CONTEXT ctx; unsigned char bits[8]; unsigned int i, padlen; /* to allow multithreading we have to locate the padding memory here */ - unsigned char PADDING[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0 + unsigned char PADDING[64] = {0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0 }; memset(&ctx, 0, sizeof(MD5_CONTEXT)); @@ -1506,8 +1539,7 @@ void MD5_checksum(const void *pdata, unsigned int len, unsigned char digest[16]) /*------------------------------------------------------------------*/ -void _MD5_update(MD5_CONTEXT * pctx, const void *pdata, unsigned int len) -{ +void _MD5_update(MD5_CONTEXT *pctx, const void *pdata, unsigned int len) { unsigned char *pin; unsigned int i, index, partlen; @@ -1542,8 +1574,7 @@ void _MD5_update(MD5_CONTEXT * pctx, const void *pdata, unsigned int len) /*------------------------------------------------------------------*/ /* basic transformation, transforms state based on block */ -void _MD5_transform(unsigned int state[4], unsigned char block[64]) -{ +void _MD5_transform(unsigned int state[4], unsigned char block[64]) { unsigned int lA = state[0], lB = state[1], lC = state[2], lD = state[3]; unsigned int x[16]; @@ -1634,8 +1665,7 @@ void _MD5_transform(unsigned int state[4], unsigned char block[64]) /* encodes input (unsigned int) into output (unsigned char), assumes that lLen is a multiple of 4 */ -void _MD5_encode(unsigned char *pout, unsigned int *pin, unsigned int len) -{ +void _MD5_encode(unsigned char *pout, unsigned int *pin, unsigned int len) { unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) { @@ -1650,20 +1680,18 @@ void _MD5_encode(unsigned char *pout, unsigned int *pin, unsigned int len) /* encodes input (unsigned char) into output (unsigned int), assumes that lLen is a multiple of 4 */ -void _MD5_decode(unsigned int *pout, unsigned char *pin, unsigned int len) -{ +void _MD5_decode(unsigned int *pout, unsigned char *pin, unsigned int len) { unsigned int i, j; for (i = 0, j = 0; j < len; i++, j += 4) pout[i] = ((unsigned int) pin[j]) | (((unsigned int) pin[j + 1]) << 8) | (((unsigned int) pin[j + 2]) - << 16) | (((unsigned int) - pin[j + 3]) << 24); + << 16) | (((unsigned int) + pin[j + 3]) << 24); } /*------------------------------------------------------------------*/ -BOOL file_exist(char *file_name) -{ +BOOL file_exist(char *file_name) { int fh; fh = open(file_name, O_RDONLY); @@ -1704,8 +1732,8 @@ double date2serialdate(int day, int month, int year) ((month - 14) / 12))) / 12) - - (int) ((3 * ((int) ((year + 4900 + (int) ((month - 14) / 12)) - / 100))) / 4) + day - 2415019 - 32075; + (int) ((3 * ((int) ((year + 4900 + (int) ((month - 14) / 12)) + / 100))) / 4) + day - 2415019 - 32075; return serialdate; } @@ -1713,8 +1741,7 @@ double date2serialdate(int day, int month, int year) /*------------------------------------------------------------------*/ /* Wrapper for setegid. */ -int setegroup(char *str) -{ +int setegroup(char *str) { #ifdef OS_UNIX struct group *gr; @@ -1738,8 +1765,7 @@ int setegroup(char *str) } /* Wrapper for seteuid. */ -int seteuser(char *str) -{ +int seteuser(char *str) { #ifdef OS_UNIX struct passwd *pw; @@ -1763,8 +1789,7 @@ int seteuser(char *str) } /* Wrapper for setgid. */ -int setgroup(char *str) -{ +int setgroup(char *str) { #ifdef OS_UNIX struct group *gr; @@ -1776,7 +1801,8 @@ int setgroup(char *str) else { eprintf("Cannot set effective GID to group \"%s\"\n", gr->gr_name); eprintf("setgroup: %s\n", strerror(errno)); - } else + } + else eprintf("Group \"%s\" not found\n", str); return -1; @@ -1786,8 +1812,7 @@ int setgroup(char *str) } /* Wrapper for setuid. */ -int setuser(char *str) -{ +int setuser(char *str) { #ifdef OS_UNIX struct passwd *pw; @@ -1799,7 +1824,8 @@ int setuser(char *str) else { eprintf("Cannot set effective UID to user \"%s\"\n", str); eprintf("setuser: %s\n", strerror(errno)); - } else + } + else eprintf("User \"%s\" not found\n", str); return -1; @@ -1810,8 +1836,7 @@ int setuser(char *str) /*-------------------------------------------------------------------*/ -int send_with_timeout(void *p, int sock, char *buf, int buf_size) -{ +int send_with_timeout(void *p, int sock, char *buf, int buf_size) { int status, sent, send_size, send_packet; time_t start, now; char *pbuf; @@ -1824,53 +1849,52 @@ int send_with_timeout(void *p, int sock, char *buf, int buf_size) send_size = buf_size; pbuf = p; // fix compiler warning pbuf = buf; - + do { if (send_size > 65536) send_packet = 65536; else send_packet = send_size; - + #ifdef HAVE_SSL - ssl = (SSL *)p; + ssl = (SSL *) p; if (ssl) status = SSL_write(ssl, pbuf, send_packet); else #endif status = send(sock, pbuf, send_packet, 0); - + // abort after 30 seconds time(&now); - if (now > start+30) { + if (now > start + 30) { printf("Timeout after 30 seconds\n"); break; } - + // repeat if we were interrupted by alarm() signal if (status == -1 && errno == EINTR) { continue; } - + if (status == -1) break; - + if (status > 0) sent += status; - + if (status > 0 && sent < buf_size) { pbuf += status; send_size -= status; } - + } while (sent < buf_size); - + return sent; } /*-------------------------------------------------------------------*/ -int recv_string(int sock, char *buffer, int buffer_size, int millisec) -{ +int recv_string(int sock, char *buffer, int buffer_size, int millisec) { int i, n; fd_set readfds; struct timeval timeout; @@ -1912,8 +1936,7 @@ int recv_string(int sock, char *buffer, int buffer_size, int millisec) SESSION_ID *_sid = NULL; int _n_sid; -int sid_new(LOGBOOK * lbs, const char *user, const char *host, char *sid) -{ +int sid_new(LOGBOOK *lbs, const char *user, const char *host, char *sid) { double exp; time_t now; int i, new_i; @@ -1968,8 +1991,7 @@ int sid_new(LOGBOOK * lbs, const char *user, const char *host, char *sid) /*-------------------------------------------------------------------*/ -int sid_check(char *sid, char *user_name) -{ +int sid_check(char *sid, char *user_name) { int i; time_t now; @@ -1990,8 +2012,7 @@ int sid_check(char *sid, char *user_name) /*-------------------------------------------------------------------*/ -int sid_remove(char *sid) -{ +int sid_remove(char *sid) { int i; if (sid == NULL) @@ -2009,10 +2030,9 @@ int sid_remove(char *sid) /*-------------------------------------------------------------------*/ -void compose_email_header(LOGBOOK * lbs, char *subject, char *from, char *to, char *url, char *mail_text, +void compose_email_header(LOGBOOK *lbs, char *subject, char *from, char *to, char *url, char *mail_text, int size, int mail_encoding, int n_attachments, char *multipart_boundary, - int message_id, int reply_id) -{ + int message_id, int reply_id) { char buffer[256], charset[256], subject_enc[5000]; char buf[80], str[256]; int i, offset, multipart; @@ -2138,8 +2158,7 @@ void compose_email_header(LOGBOOK * lbs, char *subject, char *from, char *to, ch /*-------------------------------------------------------------------*/ -int check_smtp_error(char *str, int expected, char *error, int error_size) -{ +int check_smtp_error(char *str, int expected, char *error, int error_size) { if (atoi(str) != expected) { if (error) strlcpy(error, str + 4, error_size); @@ -2151,8 +2170,7 @@ int check_smtp_error(char *str, int expected, char *error, int error_size) /*-------------------------------------------------------------------*/ -int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, char *error, int error_size) -{ +int sendmail(LOGBOOK *lbs, char *smtp_host, char *from, char *to, char *text, char *error, int error_size) { struct sockaddr_in bind_addr; struct hostent *phe; int i, n, s, strsize; @@ -2160,7 +2178,7 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c char list[MAX_N_EMAIL][NAME_LENGTH], buffer[10000], decoded[256]; memset(error, 0, error_size); - + if (get_verbose() >= VERBOSE_INFO) eprintf("\n\nEmail from %s to %s, SMTP host %s:\n", from, to, smtp_host); sprintf(buffer, "Email from %s to ", from); @@ -2177,12 +2195,12 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c strsize = MAX_CONTENT_LENGTH + 1000; str = xmalloc(strsize); - + /* connect to remote node port on SMTP port */ int smtp_port = 25; if (getcfg(lbs->name, "SMTP port", str, strsize)) smtp_port = atoi(str); - + memset(&bind_addr, 0, sizeof(bind_addr)); bind_addr.sin_family = AF_INET; bind_addr.sin_port = htons((short) smtp_port); @@ -2395,7 +2413,7 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c xfree(str); return 1; - smtp_error: + smtp_error: closesocket(s); xfree(str); @@ -2405,8 +2423,7 @@ int sendmail(LOGBOOK * lbs, char *smtp_host, char *from, char *to, char *text, c /*------------------------------------------------------------------*/ -int elog_connect(char *host, int port) -{ +int elog_connect(char *host, int port) { int status, sock; struct hostent *phe; struct sockaddr_in bind_addr; @@ -2441,40 +2458,40 @@ int elog_connect(char *host, int port) /*------------------------------------------------------------------*/ #ifdef HAVE_SSL -int ssl_connect(int sock, SSL ** ssl_con) -{ + +int ssl_connect(int sock, SSL **ssl_con) { SSL_METHOD *meth; SSL_CTX *ctx; X509 *cert = NULL; int i; - + SSL_library_init(); SSL_load_error_strings(); - + meth = (SSL_METHOD *) TLSv1_2_method(); ctx = SSL_CTX_new(meth); - + *ssl_con = SSL_new(ctx); SSL_set_fd(*ssl_con, sock); if (SSL_connect(*ssl_con) <= 0) return -1; - + cert = SSL_get_peer_certificate(*ssl_con); if (cert == NULL) return -1; - + i = SSL_get_verify_result(*ssl_con); if (i != X509_V_OK) printf("Possibly invalid certificate, continue on your own risk!\n"); - + return 0; } + #endif /*-------------------------------------------------------------------*/ -void split_url(const char *url, char *host, int *port, char *subdir, char *param) -{ +void split_url(const char *url, char *host, int *port, char *subdir, char *param) { const char *p; char str[256]; @@ -2528,8 +2545,7 @@ void split_url(const char *url, char *host, int *port, char *subdir, char *param /*-------------------------------------------------------------------*/ -int retrieve_url(LOGBOOK * lbs, const char *url, UNUSED(int ssl), char **buffer) -{ +int retrieve_url(LOGBOOK *lbs, const char *url, UNUSED(int ssl), char **buffer) { char str[1000], unm[256], upwd[256], host[256], subdir[256], param[256]; int port, bufsize; int i, n; @@ -2608,8 +2624,8 @@ int retrieve_url(LOGBOOK * lbs, const char *url, UNUSED(int ssl), char **buffer) strcat(str, "\r\n"); - send_with_timeout(ssl_con, sock, (char *)str, strlen(str)); - + send_with_timeout(ssl_con, sock, (char *) str, strlen(str)); + bufsize = TEXT_SIZE + 1000; *buffer = xmalloc(bufsize); memset(*buffer, 0, bufsize); @@ -2661,8 +2677,7 @@ int retrieve_url(LOGBOOK * lbs, const char *url, UNUSED(int ssl), char **buffer) /*-------------------------------------------------------------------*/ -int ss_daemon_init() -{ +int ss_daemon_init() { #ifdef OS_UNIX /* only implemented for UNIX */ @@ -2726,8 +2741,7 @@ time_t cfgfile_mtime = 0; /*-------------------------------------------------------------------*/ -void check_config_file(BOOL force) -{ +void check_config_file(BOOL force) { struct stat cfg_stat; if (force) { @@ -2747,13 +2761,11 @@ void check_config_file(BOOL force) /*-------------------------------------------------------------------*/ -void setcfg_topgroup(char *topgroup) -{ +void setcfg_topgroup(char *topgroup) { strcpy(_topgroup, topgroup); } -char *getcfg_topgroup() -{ +char *getcfg_topgroup() { if (_topgroup[0]) return _topgroup; @@ -2762,8 +2774,7 @@ char *getcfg_topgroup() /*------------------------------------------------------------------*/ -int is_logbook(char *logbook) -{ +int is_logbook(char *logbook) { char str[256]; if (strieq(logbook, "global")) @@ -2777,15 +2788,13 @@ int is_logbook(char *logbook) /*-------------------------------------------------------------------*/ -void set_condition(char *c) -{ +void set_condition(char *c) { strlcpy(_condition, c, sizeof(_condition)); } /*-------------------------------------------------------------------*/ -void evaluate_conditions(LOGBOOK * lbs, char attrib[MAX_N_ATTR][NAME_LENGTH]) -{ +void evaluate_conditions(LOGBOOK *lbs, char attrib[MAX_N_ATTR][NAME_LENGTH]) { char condition[256], str[256]; int index, i; @@ -2821,8 +2830,7 @@ void evaluate_conditions(LOGBOOK * lbs, char attrib[MAX_N_ATTR][NAME_LENGTH]) /*-------------------------------------------------------------------*/ -BOOL match_param(char *str, char *param, int conditional_only) -{ +BOOL match_param(char *str, char *param, int conditional_only) { int ncl, npl, nand, i, j, k; char *p, pcond[256], clist[10][NAME_LENGTH], plist[10][NAME_LENGTH], alist[10][NAME_LENGTH]; @@ -2876,15 +2884,13 @@ BOOL match_param(char *str, char *param, int conditional_only) /*-------------------------------------------------------------------*/ -int param_compare(const void *p1, const void *p2) -{ +int param_compare(const void *p1, const void *p2) { return stricmp(((CONFIG_PARAM *) p1)->uparam, ((CONFIG_PARAM *) p2)->uparam); } /*------------------------------------------------------------------*/ -void free_config() -{ +void free_config() { int i, j; for (i = 0; i < n_lb_config; i++) { @@ -3029,8 +3035,7 @@ int parse_config_file(char *file_name) /*-------------------------------------------------------------------*/ -int getcfg_simple(char *group, char *param, char *value, int vsize, int conditional) -{ +int getcfg_simple(char *group, char *param, char *value, int vsize, int conditional) { int i, j, status; char uparam[256]; @@ -3061,8 +3066,7 @@ int getcfg_simple(char *group, char *param, char *value, int vsize, int conditio /*-------------------------------------------------------------------*/ -int enumgrp(int index, char *group) -{ +int enumgrp(int index, char *group) { if (index < n_lb_config) { strcpy(group, lb_config[index].section_name); return 1; @@ -3119,8 +3123,7 @@ int getcfg(char *group, char *param, char *value, int vsize) /*-------------------------------------------------------------------*/ -char *find_param(char *buf, char *group, char *param) -{ +char *find_param(char *buf, char *group, char *param) { char *str, *p, *pstr, *pstart; /* search group */ @@ -3176,8 +3179,7 @@ char *find_param(char *buf, char *group, char *param) /*-------------------------------------------------------------------*/ -int is_group(char *group) -{ +int is_group(char *group) { int i; for (i = 0; i < n_lb_config; i++) @@ -3188,8 +3190,7 @@ int is_group(char *group) /*------------------------------------------------------------------*/ -int enumcfg(char *group, char *param, int psize, char *value, int vsize, int index) -{ +int enumcfg(char *group, char *param, int psize, char *value, int vsize, int index) { int i; for (i = 0; i < n_lb_config; i++) @@ -3210,8 +3211,7 @@ int enumcfg(char *group, char *param, int psize, char *value, int vsize, int ind /*-------------------------------------------------------------------*/ -int exist_top_group() -{ +int exist_top_group() { int i; char str[256]; @@ -3233,8 +3233,7 @@ char **_porig, **_ptrans; time_t _locfile_mtime = 0; /* check if language file changed and if so reload it */ -int check_language() -{ +int check_language() { char language[256], file_name[256], *p; int fh, length, n; struct stat cfg_stat; @@ -3340,8 +3339,7 @@ int check_language() /*-------------------------------------------------------------------*/ /* localization support */ -char *loc(char *orig) -{ +char *loc(char *orig) { int n; char language[256]; static char result[256]; @@ -3379,8 +3377,7 @@ char *loc(char *orig) /* translate back from localized string to english */ -char *unloc(char *orig) -{ +char *unloc(char *orig) { int n; if (!_locbuffer) @@ -3419,8 +3416,7 @@ char *month_name(int m) /*-------------------------------------------------------------------*/ -time_t date_to_ltime(char *date) -{ +time_t date_to_ltime(char *date) { struct tm tms; int i, date_zone, local_zone; time_t ltime; @@ -3487,16 +3483,14 @@ time_t date_to_ltime(char *date) /*-------------------------------------------------------------------*/ -void check_config() -{ +void check_config() { check_config_file(FALSE); check_language(); } /*-------------------------------------------------------------------*/ -void retrieve_domain(char *ret, int size) -{ +void retrieve_domain(char *ret, int size) { char smtp_host[80]; strlcpy(ret, "tmp.org", size); @@ -3508,11 +3502,10 @@ void retrieve_domain(char *ret, int size) /*-------------------------------------------------------------------*/ -void retrieve_email_from(LOGBOOK * lbs, char *ret, char *ret_name, char attrib[MAX_N_ATTR][NAME_LENGTH]) -{ +void retrieve_email_from(LOGBOOK *lbs, char *ret, char *ret_name, char attrib[MAX_N_ATTR][NAME_LENGTH]) { char email_from[256], email_from_name[256], str[256], *p, login_name[256], - slist[MAX_N_ATTR + 10][NAME_LENGTH], svalue[MAX_N_ATTR + 10][NAME_LENGTH], - full_name[256], user_email[256]; + slist[MAX_N_ATTR + 10][NAME_LENGTH], svalue[MAX_N_ATTR + 10][NAME_LENGTH], + full_name[256], user_email[256]; int i; if (getcfg(lbs->name, "Use Email from", str, sizeof(str))) { @@ -3577,8 +3570,7 @@ void retrieve_email_from(LOGBOOK * lbs, char *ret, char *ret_name, char attrib[M /*------------------------------------------------------------------*/ -void el_decode(char *message, char *key, char *result, int size) -{ +void el_decode(char *message, char *key, char *result, int size) { char *pc, *ph; int i; @@ -3621,8 +3613,7 @@ void el_decode(char *message, char *key, char *result, int size) /*------------------------------------------------------------------*/ -void el_decode_int(char *message, char *key, char *result, int size) -{ +void el_decode_int(char *message, char *key, char *result, int size) { char str[80]; if (result == NULL) @@ -3637,8 +3628,7 @@ void el_decode_int(char *message, char *key, char *result, int size) /*------------------------------------------------------------------*/ -void el_decode_intlist(char *message, char *key, char *result, int size) -{ +void el_decode_intlist(char *message, char *key, char *result, int size) { int i; if (result == NULL) @@ -3655,8 +3645,7 @@ void el_decode_intlist(char *message, char *key, char *result, int size) /*------------------------------------------------------------------*/ -void el_enum_attr(char *message, int n, char *attr_name, char *attr_value) -{ +void el_enum_attr(char *message, int n, char *attr_name, char *attr_value) { char *p, str[NAME_LENGTH], tmp[NAME_LENGTH]; int i; @@ -3706,42 +3695,41 @@ void el_enum_attr(char *message, int n, char *attr_name, char *attr_value) #define EOS '\0' -int fnmatch1(const char *pattern, const char *string) -{ +int fnmatch1(const char *pattern, const char *string) { char c, test; for (;;) switch (c = *pattern++) { - case EOS: - return (*string == EOS ? 0 : 1); - case '?': - if (*string == EOS) - return (1); - ++string; - break; - case '*': - c = *pattern; - /* Collapse multiple stars. */ - while (c == '*') - c = *++pattern; - - /* Optimize for pattern with * at end or before /. */ - if (c == EOS) - return (0); - - /* General case, use recursion. */ - while ((test = *string) != EOS) { - if (!fnmatch1(pattern, string)) - return (0); + case EOS: + return (*string == EOS ? 0 : 1); + case '?': + if (*string == EOS) + return (1); ++string; - } - return (1); - /* FALLTHROUGH */ - default: - if (c != *string) + break; + case '*': + c = *pattern; + /* Collapse multiple stars. */ + while (c == '*') + c = *++pattern; + + /* Optimize for pattern with * at end or before /. */ + if (c == EOS) + return (0); + + /* General case, use recursion. */ + while ((test = *string) != EOS) { + if (!fnmatch1(pattern, string)) + return (0); + ++string; + } return (1); - string++; - break; + /* FALLTHROUGH */ + default: + if (c != *string) + return (1); + string++; + break; } } @@ -3787,7 +3775,7 @@ int ss_file_find(const char *path, char *pattern, char **plist) #endif #ifdef OS_WINNT - HANDLE pffile; + HANDLE pffile; LPWIN32_FIND_DATA lpfdata; char str[255]; int i, first; @@ -3820,8 +3808,7 @@ int ss_file_find(const char *path, char *pattern, char **plist) /*------------------------------------------------------------------*/ -int eli_compare(const void *e1, const void *e2) -{ +int eli_compare(const void *e1, const void *e2) { if (((EL_INDEX *) e1)->file_time < ((EL_INDEX *) e2)->file_time) return -1; @@ -3832,43 +3819,41 @@ int eli_compare(const void *e1, const void *e2) /*------------------------------------------------------------------*/ -void generate_subdir_name(char *file_name, char *subdir, int size) -{ +void generate_subdir_name(char *file_name, char *subdir, int size) { char fn[MAX_PATH_LENGTH], path[MAX_PATH_LENGTH]; int year; - + // extract path from file_name strlcpy(path, file_name, size); if (strrchr(path, DIR_SEPARATOR)) - *(strrchr(path, DIR_SEPARATOR)+1) = 0; - + *(strrchr(path, DIR_SEPARATOR) + 1) = 0; + // extract file name if (strrchr(file_name, DIR_SEPARATOR)) - strlcpy(fn, strrchr(file_name, DIR_SEPARATOR)+1, sizeof(fn)); + strlcpy(fn, strrchr(file_name, DIR_SEPARATOR) + 1, sizeof(fn)); else strlcpy(fn, file_name, sizeof(fn)); - + // create subdir from name - year = (fn[0]-'0')*10+(fn[1]-'0'); + year = (fn[0] - '0') * 10 + (fn[1] - '0'); // month = (fn[2]-'0')*10+(fn[3]-'0'); if (year < 80) sprintf(subdir, "20%02d", year); else sprintf(subdir, "19%02d", year); - + strlcat(subdir, DIR_SEPARATOR_STR, size); } /*------------------------------------------------------------------*/ -int restructure_dir(char *dir) -{ +int restructure_dir(char *dir) { char *file_list; int n1, n2, index, status; char old_path[MAX_PATH_LENGTH], new_path[MAX_PATH_LENGTH], - subdir[MAX_PATH_LENGTH]; + subdir[MAX_PATH_LENGTH]; static int first = TRUE; - + /* go through all entry files */ n1 = ss_file_find(dir, "??????a.log", &file_list); for (index = 0; index < n1; index++) { @@ -3877,13 +3862,13 @@ int restructure_dir(char *dir) // create new subdir strlcpy(new_path, dir, MAX_PATH_LENGTH); strlcat(new_path, subdir, MAX_PATH_LENGTH); - + #ifdef OS_WINNT status = mkdir(new_path); #else status = mkdir(new_path, 0755); #endif - + if (status == 0) { if (first) { eprintf("\nFound old directory structure. Creating subdirectories and moving files...\n"); @@ -3896,18 +3881,18 @@ int restructure_dir(char *dir) eprintf("Cannot create directory \"%s\"\n", new_path); } } - + strlcpy(old_path, dir, sizeof(old_path)); strlcat(old_path, file_list + index * MAX_PATH_LENGTH, sizeof(old_path)); strlcpy(new_path, dir, sizeof(new_path)); strlcat(new_path, subdir, sizeof(new_path)); strlcat(new_path, file_list + index * MAX_PATH_LENGTH, sizeof(new_path)); - + rename(old_path, new_path); } if (file_list) xfree(file_list); - + /* go through all attachment files */ n2 = ss_file_find(dir, "??????_??????_*", &file_list); for (index = 0; index < n2; index++) { @@ -3916,126 +3901,124 @@ int restructure_dir(char *dir) // create new subdir strlcpy(new_path, dir, MAX_PATH_LENGTH); strlcat(new_path, subdir, MAX_PATH_LENGTH); - + #ifdef OS_WINNT status = mkdir(new_path); #else status = mkdir(new_path, 0755); #endif - + strlcpy(old_path, dir, sizeof(old_path)); strlcat(old_path, file_list + index * MAX_PATH_LENGTH, sizeof(old_path)); strlcpy(new_path, dir, sizeof(new_path)); strlcat(new_path, subdir, sizeof(new_path)); strlcat(new_path, file_list + index * MAX_PATH_LENGTH, sizeof(new_path)); - + rename(old_path, new_path); } if (file_list) xfree(file_list); - return n1+n2; + return n1 + n2; } /*------------------------------------------------------------------*/ -int parse_file(LOGBOOK *lbs, char *file_name) -{ +int parse_file(LOGBOOK *lbs, char *file_name) { char str[256], date[256], *buffer, *p, *pn, in_reply_to[80]; int length, i, fh, len; - + fh = open(file_name, O_RDONLY | O_BINARY, 0644); - + if (fh < 0) { sprintf(str, "Cannot open file \"%s\"", file_name); eprintf("%s; %s\n", str, strerror(errno)); return EL_FILE_ERROR; } - + /* read file into buffer */ length = lseek(fh, 0, SEEK_END); - + if (length > 0) { buffer = xmalloc(length + 1); lseek(fh, 0, SEEK_SET); read(fh, buffer, length); buffer[length] = 0; close(fh); - + /* go through buffer */ p = buffer; - + do { p = strstr(p, "$@MID@$:"); - + if (p) { lbs->el_index = xrealloc(lbs->el_index, sizeof(EL_INDEX) * (*lbs->n_el_index + 1)); if (lbs->el_index == NULL) { eprintf("Not enough memory to allocate entry index\n"); return EL_MEM_ERROR; } - - strlcpy(lbs->el_index[*lbs->n_el_index].subdir, file_name+strlen(lbs->data_dir), 256); + + strlcpy(lbs->el_index[*lbs->n_el_index].subdir, file_name + strlen(lbs->data_dir), 256); if (strrchr(lbs->el_index[*lbs->n_el_index].subdir, DIR_SEPARATOR)) - *(strrchr(lbs->el_index[*lbs->n_el_index].subdir, DIR_SEPARATOR)+1) = 0; - + *(strrchr(lbs->el_index[*lbs->n_el_index].subdir, DIR_SEPARATOR) + 1) = 0; + if (strrchr(file_name, DIR_SEPARATOR)) - strlcpy(str, strrchr(file_name, DIR_SEPARATOR)+1, sizeof(str)); + strlcpy(str, strrchr(file_name, DIR_SEPARATOR) + 1, sizeof(str)); else strlcpy(str, file_name, sizeof(str)); strcpy(lbs->el_index[*lbs->n_el_index].file_name, str); - + el_decode(p, "Date: ", date, sizeof(date)); el_decode_int(p, "In reply to: ", in_reply_to, sizeof(in_reply_to)); - + lbs->el_index[*lbs->n_el_index].file_time = date_to_ltime(date); - + lbs->el_index[*lbs->n_el_index].message_id = atoi(p + 8); lbs->el_index[*lbs->n_el_index].offset = p - buffer; lbs->el_index[*lbs->n_el_index].in_reply_to = atoi(in_reply_to); - + pn = strstr(p + 8, "$@MID@$:"); if (pn) len = pn - p; else len = strlen(p); - + MD5_checksum(p, len, lbs->el_index[*lbs->n_el_index].md5_digest); - + if (lbs->el_index[*lbs->n_el_index].message_id > 0) { if (get_verbose() == VERBOSE_DEBUG) { eprintf(" ID %3d, %s, ofs %5d, %s, MD5=", lbs->el_index[*lbs->n_el_index].message_id, str, lbs->el_index[*lbs->n_el_index].offset, lbs->el_index[*lbs->n_el_index].in_reply_to ? "reply" : "thead"); - + for (i = 0; i < 16; i++) eprintf("%02X", lbs->el_index[*lbs->n_el_index].md5_digest[i]); eprintf("\n"); } - + /* valid ID */ (*lbs->n_el_index)++; } - + p += 8; } - + } while (p); - + xfree(buffer); } - + return SUCCESS; } /*------------------------------------------------------------------*/ -int scan_dir_tree(LOGBOOK *lbs, const char *dir, char **file_list, int *n) -{ - int index, n_files; +int scan_dir_tree(LOGBOOK *lbs, const char *dir, char **file_list, int *n) { + int index, n_files; char str[MAX_PATH_LENGTH]; char *fl, *p; - + fl = NULL; n_files = ss_file_find(dir, "*", &fl); if (n_files == 0) { @@ -4043,24 +4026,24 @@ int scan_dir_tree(LOGBOOK *lbs, const char *dir, char **file_list, int *n) xfree(fl); return 0; } - + if (*file_list == NULL) - *file_list = (char *)xmalloc(n_files*MAX_PATH_LENGTH); + *file_list = (char *) xmalloc(n_files * MAX_PATH_LENGTH); else - *file_list = (char *)xrealloc(*file_list, ((*n)+n_files)*MAX_PATH_LENGTH); - + *file_list = (char *) xrealloc(*file_list, ((*n) + n_files) * MAX_PATH_LENGTH); + /* go through all files */ for (index = 0; index < n_files; index++) { if (fnmatch1("??????a.log", &fl[index * MAX_PATH_LENGTH]) == 0) { p = *file_list + ((*n) * MAX_PATH_LENGTH); strlcpy(p, dir, MAX_PATH_LENGTH); - if (p[strlen(p)-1] != DIR_SEPARATOR) + if (p[strlen(p) - 1] != DIR_SEPARATOR) strlcat(p, DIR_SEPARATOR_STR, MAX_PATH_LENGTH); strlcat(p, fl + index * MAX_PATH_LENGTH, MAX_PATH_LENGTH); (*n)++; } } - + /* go through all sub-directories */ for (index = 0; index < n_files; index++) { if (fnmatch1("????", &fl[index * MAX_PATH_LENGTH]) == 0 || @@ -4068,22 +4051,22 @@ int scan_dir_tree(LOGBOOK *lbs, const char *dir, char **file_list, int *n) if (strieq(fl + index * MAX_PATH_LENGTH, "..")) continue; strlcpy(str, dir, sizeof(str)); - if (str[strlen(str)-1] != DIR_SEPARATOR) + if (str[strlen(str) - 1] != DIR_SEPARATOR) strlcat(str, DIR_SEPARATOR_STR, sizeof(str)); strlcat(str, fl + index * MAX_PATH_LENGTH, sizeof(str)); scan_dir_tree(lbs, str, file_list, n); } } - + if (fl) xfree(fl); - + return *n; } /*------------------------------------------------------------------*/ -int el_build_index(LOGBOOK * lbs, BOOL rebuild) +int el_build_index(LOGBOOK *lbs, BOOL rebuild) /* scan all ??????a.log files and build an index table in eli[] */ { char *file_list, error_str[256], base_dir[256], *buffer; @@ -4124,17 +4107,17 @@ int el_build_index(LOGBOOK * lbs, BOOL rebuild) if (get_verbose() >= VERBOSE_DEBUG) eprintf("Entries:\n"); - + // move files to directories if (new layout to reduce number of files per directory) restructure_dir(base_dir); file_list = NULL; n = 0; scan_dir_tree(lbs, base_dir, &file_list, &n); - + /* go through all files */ for (index = 0; index < n; index++) { - status = parse_file(lbs, file_list+index*MAX_PATH_LENGTH); + status = parse_file(lbs, file_list + index * MAX_PATH_LENGTH); if (status != SUCCESS) { if (file_list) xfree(file_list); @@ -4159,14 +4142,13 @@ int el_build_index(LOGBOOK * lbs, BOOL rebuild) eprintf("Logbook files seem to have disappeared, aborting program.\n"); assert(rebuild && n > 0); } - + return EL_SUCCESS; } /*------------------------------------------------------------------*/ -int el_index_logbooks() -{ +int el_index_logbooks() { char str[256], data_dir[256], logbook[256], cwd[256], *p; int i, j, n, status = 0; @@ -4355,7 +4337,7 @@ int el_index_logbooks() /*------------------------------------------------------------------*/ -int el_search_message(LOGBOOK * lbs, int mode, int message_id, BOOL head_only) +int el_search_message(LOGBOOK *lbs, int mode, int message_id, BOOL head_only) /******************************************************************** Routine: el_search_message @@ -4450,7 +4432,7 @@ int el_search_message(LOGBOOK * lbs, int mode, int message_id, BOOL head_only) /*------------------------------------------------------------------*/ -int el_retrieve(LOGBOOK * lbs, int message_id, char *date, char attr_list[MAX_N_ATTR][NAME_LENGTH], +int el_retrieve(LOGBOOK *lbs, int message_id, char *date, char attr_list[MAX_N_ATTR][NAME_LENGTH], char attrib[MAX_N_ATTR][NAME_LENGTH], int n_attr, char *text, int *textsize, char *in_reply_to, char *reply_to, char attachment[MAX_ATTACHMENTS][MAX_PATH_LENGTH], char *encoding, char *locked_by, char *draft) @@ -4488,7 +4470,7 @@ int el_retrieve(LOGBOOK * lbs, int message_id, char *date, char attr_list[MAX_N_ \********************************************************************/ { int i, index, size, fh; - char str[NAME_LENGTH], file_name[MAX_PATH_LENGTH*3], *p; + char str[NAME_LENGTH], file_name[MAX_PATH_LENGTH * 3], *p; char *message, attachment_all[64 * MAX_ATTACHMENTS]; if (message_id == 0) @@ -4505,7 +4487,8 @@ int el_retrieve(LOGBOOK * lbs, int message_id, char *date, char attr_list[MAX_N_ if (index == *lbs->n_el_index) return EL_NO_MSG; - snprintf(file_name, sizeof(file_name), "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); + snprintf(file_name, sizeof(file_name), "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, + lbs->el_index[index].file_name); fh = open(file_name, O_RDONLY | O_BINARY, 0644); if (fh < 0) { /* file might have been deleted, rebuild index */ @@ -4644,10 +4627,10 @@ int el_retrieve(LOGBOOK * lbs, int message_id, char *date, char attr_list[MAX_N_ /*------------------------------------------------------------------*/ -int el_submit_attachment(LOGBOOK * lbs, const char *afilename, const char *buffer, int buffer_size, - char *full_name) -{ - char file_name[MAX_PATH_LENGTH], ext_file_name[MAX_PATH_LENGTH + 100], str[MAX_PATH_LENGTH], *p, subdir[MAX_PATH_LENGTH]; +int el_submit_attachment(LOGBOOK *lbs, const char *afilename, const char *buffer, int buffer_size, + char *full_name) { + char file_name[MAX_PATH_LENGTH], ext_file_name[ + MAX_PATH_LENGTH + 100], str[MAX_PATH_LENGTH], *p, subdir[MAX_PATH_LENGTH]; int fh; time_t now; struct tm tms; @@ -4682,15 +4665,15 @@ int el_submit_attachment(LOGBOOK * lbs, const char *afilename, const char *buffe strlcpy(str, lbs->data_dir, sizeof(str)); generate_subdir_name(ext_file_name, subdir, sizeof(subdir)); strlcat(str, subdir, sizeof(str)); - if (strlen(str) > 0 && str[strlen(str)-1] == DIR_SEPARATOR) - str[strlen(str)-1] = 0; - + if (strlen(str) > 0 && str[strlen(str) - 1] == DIR_SEPARATOR) + str[strlen(str) - 1] = 0; + #ifdef OS_WINNT mkdir(str); #else mkdir(str, 0755); #endif - + strlcat(str, DIR_SEPARATOR_STR, sizeof(str)); strlcat(str, ext_file_name, sizeof(str)); @@ -4712,8 +4695,7 @@ int el_submit_attachment(LOGBOOK * lbs, const char *afilename, const char *buffe /*------------------------------------------------------------------*/ -void el_delete_attachment(LOGBOOK * lbs, char *file_name) -{ +void el_delete_attachment(LOGBOOK *lbs, char *file_name) { int i; char str[MAX_PATH_LENGTH], subdir[MAX_PATH_LENGTH]; @@ -4750,10 +4732,9 @@ void el_delete_attachment(LOGBOOK * lbs, char *file_name) /*------------------------------------------------------------------*/ -int el_retrieve_attachment(LOGBOOK * lbs, int message_id, int n, char name[MAX_PATH_LENGTH]) -{ +int el_retrieve_attachment(LOGBOOK *lbs, int message_id, int n, char name[MAX_PATH_LENGTH]) { int i, index, size, fh; - char file_name[MAX_PATH_LENGTH*3], *p; + char file_name[MAX_PATH_LENGTH * 3], *p; char message[TEXT_SIZE + 1000], attachment_all[64 * MAX_ATTACHMENTS]; if (message_id == 0) @@ -4766,7 +4747,8 @@ int el_retrieve_attachment(LOGBOOK * lbs, int message_id, int n, char name[MAX_P if (index == *lbs->n_el_index) return EL_NO_MSG; - snprintf(file_name, sizeof(file_name), "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); + snprintf(file_name, sizeof(file_name), "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, + lbs->el_index[index].file_name); fh = open(file_name, O_RDONLY | O_BINARY, 0644); if (fh < 0) { /* file might have been deleted, rebuild index */ @@ -4825,7 +4807,7 @@ int el_retrieve_attachment(LOGBOOK * lbs, int message_id, int n, char name[MAX_P /*------------------------------------------------------------------*/ -int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit, char *date, char attr_name[MAX_N_ATTR][NAME_LENGTH], +int el_submit(LOGBOOK *lbs, int message_id, BOOL bedit, char *date, char attr_name[MAX_N_ATTR][NAME_LENGTH], char attr_value[MAX_N_ATTR][NAME_LENGTH], int n_attr, char *text, char *in_reply_to, char *reply_to, char *encoding, char afilename[MAX_ATTACHMENTS][256], BOOL mark_original, char *locked_by, char *draft) @@ -4854,16 +4836,16 @@ int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit, char *date, char attr_n BOOL mark_original Tag original message for replies char *locked_by User/Host which locked message for edit char *draft User which drafted message - + Function value: int New message ID \********************************************************************/ { int n, i, j, size, fh, index, tail_size, orig_size, delta, reply_id; - char file_name[MAX_PATH_LENGTH*3], dir[256], str[NAME_LENGTH], date1[256], attrib[MAX_N_ATTR][NAME_LENGTH], - reply_to1[MAX_REPLY_TO * 10], in_reply_to1[MAX_REPLY_TO * 10], encoding1[80], *message, *p, - *old_text, *buffer, locked_by1[256]; + char file_name[MAX_PATH_LENGTH * 3], dir[256], str[NAME_LENGTH], date1[256], attrib[MAX_N_ATTR][NAME_LENGTH], + reply_to1[MAX_REPLY_TO * 10], in_reply_to1[MAX_REPLY_TO * 10], encoding1[80], *message, *p, + *old_text, *buffer, locked_by1[256]; char attachment_all[64 * MAX_ATTACHMENTS], subdir[MAX_PATH_LENGTH]; time_t ltime; @@ -4896,7 +4878,8 @@ int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit, char *date, char attr_n return -1; } - snprintf(file_name, sizeof(file_name), "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); + snprintf(file_name, sizeof(file_name), "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, + lbs->el_index[index].file_name); fh = open(file_name, O_CREAT | O_RDWR | O_BINARY, 0644); if (fh < 0) { xfree(message); @@ -5002,15 +4985,15 @@ int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit, char *date, char attr_n generate_subdir_name(file_name, subdir, sizeof(subdir)); sprintf(str, "%s%s", dir, subdir); - if (strlen(str) > 0 && str[strlen(str)-1] == DIR_SEPARATOR) - str[strlen(str)-1] = 0; - + if (strlen(str) > 0 && str[strlen(str) - 1] == DIR_SEPARATOR) + str[strlen(str) - 1] = 0; + #ifdef OS_WINNT mkdir(str); #else mkdir(str, 0755); #endif - + sprintf(str, "%s%s%s", dir, subdir, file_name); fh = open(str, O_CREAT | O_RDWR | O_BINARY, 0644); if (fh < 0) { @@ -5139,7 +5122,7 @@ int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit, char *date, char attr_n if (mark_original && in_reply_to[0] && !bedit && atoi(in_reply_to) > 0) { char date[80], attr[MAX_N_ATTR][NAME_LENGTH], enc[80], att[MAX_ATTACHMENTS][256], - reply_to[MAX_REPLY_TO * 10], in_reply_to[MAX_REPLY_TO * 10], lock[256], draft[256]; + reply_to[MAX_REPLY_TO * 10], in_reply_to[MAX_REPLY_TO * 10], lock[256], draft[256]; /* retrieve original message */ size = TEXT_SIZE + 100; @@ -5161,10 +5144,9 @@ int el_submit(LOGBOOK * lbs, int message_id, BOOL bedit, char *date, char attr_n /*------------------------------------------------------------------*/ -void remove_reference(LOGBOOK * lbs, int message_id, int remove_id, BOOL reply_to_flag) -{ +void remove_reference(LOGBOOK *lbs, int message_id, int remove_id, BOOL reply_to_flag) { char date[80], attr[MAX_N_ATTR][NAME_LENGTH], enc[80], in_reply_to[80], reply_to[MAX_REPLY_TO * 10], - att[MAX_ATTACHMENTS][256], lock[256], draft[256], *p, *ps, *message; + att[MAX_ATTACHMENTS][256], lock[256], draft[256], *p, *ps, *message; int size, status; /* retrieve original message */ @@ -5207,7 +5189,7 @@ void remove_reference(LOGBOOK * lbs, int message_id, int remove_id, BOOL reply_t /*------------------------------------------------------------------*/ -int el_delete_message(LOGBOOK * lbs, int message_id, BOOL delete_attachments, +int el_delete_message(LOGBOOK *lbs, int message_id, BOOL delete_attachments, char attachment[MAX_ATTACHMENTS][MAX_PATH_LENGTH], BOOL delete_bw_ref, BOOL delete_reply_to) /******************************************************************** @@ -5232,7 +5214,7 @@ int el_delete_message(LOGBOOK * lbs, int message_id, BOOL delete_attachments, \********************************************************************/ { int i, index, size, fh, tail_size, old_offset; - char str[MAX_PATH_LENGTH], file_name[MAX_PATH_LENGTH*3], reply_to[MAX_REPLY_TO * 10], in_reply_to[256]; + char str[MAX_PATH_LENGTH], file_name[MAX_PATH_LENGTH * 3], reply_to[MAX_REPLY_TO * 10], in_reply_to[256]; char *buffer, *p; char *message, attachment_all[64 * MAX_ATTACHMENTS]; char attrib[MAX_N_ATTR][NAME_LENGTH]; @@ -5244,7 +5226,8 @@ int el_delete_message(LOGBOOK * lbs, int message_id, BOOL delete_attachments, if (index == *lbs->n_el_index) return -1; - snprintf(file_name, sizeof(file_name), "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, lbs->el_index[index].file_name); + snprintf(file_name, sizeof(file_name), "%s%s%s", lbs->data_dir, lbs->el_index[index].subdir, + lbs->el_index[index].file_name); fh = open(file_name, O_RDWR | O_BINARY, 0644); if (fh < 0) return EL_FILE_ERROR; @@ -5414,13 +5397,13 @@ int el_delete_message(LOGBOOK * lbs, int message_id, BOOL delete_attachments, /*------------------------------------------------------------------*/ -int el_correct_links(LOGBOOK * lbs, int old_id, int new_id) +int el_correct_links(LOGBOOK *lbs, int old_id, int new_id) /* If a message gets resubmitted, the links to that message are wrong. This routine corrects that. */ { int i, i1, n, n1, size; - char date[80], *attrib, *text, in_reply_to[80], reply_to[MAX_REPLY_TO * 10], encoding[80], - locked_by[256], draft[256]; + char date[80], *attrib, *text, in_reply_to[80], reply_to[MAX_REPLY_TO * 10], encoding[80], + locked_by[256], draft[256]; char list[MAX_N_ATTR][NAME_LENGTH], list1[MAX_N_ATTR][NAME_LENGTH]; char *att_file; @@ -5491,11 +5474,10 @@ int el_correct_links(LOGBOOK * lbs, int old_id, int new_id) /*------------------------------------------------------------------*/ -int el_move_message_thread(LOGBOOK * lbs, int message_id) -{ +int el_move_message_thread(LOGBOOK *lbs, int message_id) { int i, n, size, new_id; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], *text, in_reply_to[80], reply_to[MAX_REPLY_TO * 10], - encoding[80], locked_by[256], draft[256]; + encoding[80], locked_by[256], draft[256]; char list[MAX_N_ATTR][NAME_LENGTH], str[256]; char att_file[MAX_ATTACHMENTS][256]; @@ -5532,11 +5514,10 @@ int el_move_message_thread(LOGBOOK * lbs, int message_id) /*------------------------------------------------------------------*/ -int el_move_message(LOGBOOK * lbs, int old_id, int new_id) -{ +int el_move_message(LOGBOOK *lbs, int old_id, int new_id) { int status, size; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], *text, in_reply_to[80], reply_to[MAX_REPLY_TO * 10], - encoding[80], locked_by[256], draft[256], att_file[MAX_ATTACHMENTS][256]; + encoding[80], locked_by[256], draft[256], att_file[MAX_ATTACHMENTS][256]; /* retrieve message */ text = xmalloc(TEXT_SIZE); @@ -5566,12 +5547,12 @@ int el_move_message(LOGBOOK * lbs, int old_id, int new_id) /*------------------------------------------------------------------*/ -int el_lock_message(LOGBOOK * lbs, int message_id, char *user, BOOL lock) +int el_lock_message(LOGBOOK *lbs, int message_id, char *user, BOOL lock) /* lock message for editing */ { int size; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], text[TEXT_SIZE], in_reply_to[80], - reply_to[MAX_REPLY_TO * 10], encoding[80], locked_by[256], draft[256]; + reply_to[MAX_REPLY_TO * 10], encoding[80], locked_by[256], draft[256]; char att_file[MAX_ATTACHMENTS][256]; /* retrieve message */ @@ -5588,30 +5569,29 @@ int el_lock_message(LOGBOOK * lbs, int message_id, char *user, BOOL lock) /*------------------------------------------------------------------*/ -int el_draft_message(LOGBOOK * lbs, int message_id, char *user, BOOL bdraft) +int el_draft_message(LOGBOOK *lbs, int message_id, char *user, BOOL bdraft) /* lock message for editing */ { int size; char date[80], attrib[MAX_N_ATTR][NAME_LENGTH], text[TEXT_SIZE], in_reply_to[80], - reply_to[MAX_REPLY_TO * 10], encoding[80], locked_by[256], draft[256]; + reply_to[MAX_REPLY_TO * 10], encoding[80], locked_by[256], draft[256]; char att_file[MAX_ATTACHMENTS][256]; - + /* retrieve message */ size = sizeof(text); el_retrieve(lbs, message_id, date, attr_list, attrib, lbs->n_attr, text, &size, in_reply_to, reply_to, att_file, encoding, locked_by, draft); - + /* submit message, undraft if bdraft == FALSE */ el_submit(lbs, message_id, TRUE, date, attr_list, attrib, lbs->n_attr, text, in_reply_to, reply_to, encoding, att_file, FALSE, locked_by, bdraft ? user : NULL); - + return EL_SUCCESS; } /*------------------------------------------------------------------*/ -void write_logfile(LOGBOOK * lbs, const char *text) -{ +void write_logfile(LOGBOOK *lbs, const char *text) { char file_name[MAX_PATH_LENGTH]; char str[MAX_PATH_LENGTH], unm[256]; int fh; @@ -5658,7 +5638,7 @@ void write_logfile(LOGBOOK * lbs, const char *text) strlcat(buf, text, sizeof(buf) - 1); #ifdef OS_WINNT - if (strlen(buf) > 0 && buf[strlen(buf) - 1] != '\n') + if (strlen(buf) > 0 && buf[strlen(buf) - 1] != '\n') strlcat(buf, "\r\n", sizeof(buf)); else if (strlen(buf) > 1 && buf[strlen(buf) - 2] != '\r') strlcpy(buf + strlen(buf) - 2, "\r\n", sizeof(buf) - (strlen(buf) - 2)); @@ -5708,10 +5688,9 @@ void write_logfile(LOGBOOK * lbs, const char *text) /*------------------------------------------------------------------*/ -char *html_tags[] = { "", "", "

", "
", "


", "" }; +char *html_tags[] = {"
", "", "

", "
", "


", ""}; -int is_html(char *s) -{ +int is_html(char *s) { char *str, *p; int i; @@ -5733,15 +5712,14 @@ int is_html(char *s) xfree(str); return TRUE; } - + xfree(str); return FALSE; } /*------------------------------------------------------------------*/ -int html_allowed(LOGBOOK * lbs) -{ +int html_allowed(LOGBOOK *lbs) { char str[80]; return (getcfg(lbs->name, "Allow HTML", str, sizeof(str)) && atoi(str) == 1); @@ -5750,13 +5728,12 @@ int html_allowed(LOGBOOK * lbs) /*------------------------------------------------------------------*/ -char *script_tags[] = { "onerror", "onabort", "onchange", "onclick", "ondblclick", "onfocus", "onkeydown", - "onkeyup", "onload", "onmousedonw", "onmousemove", "onmouseover", "onmouseup", - "onreset", "onselect", "onsubmit", "onunload", "javascript", NULL +char *script_tags[] = {"onerror", "onabort", "onchange", "onclick", "ondblclick", "onfocus", "onkeydown", + "onkeyup", "onload", "onmousedonw", "onmousemove", "onmouseover", "onmouseup", + "onreset", "onselect", "onsubmit", "onunload", "javascript", NULL }; -int is_script(char *s) -{ +int is_script(char *s) { char *str; int i; @@ -5779,10 +5756,9 @@ int is_script(char *s) /*------------------------------------------------------------------*/ -char *full_html_tags[] = { "", "", "", "" }; +char *full_html_tags[] = {"", "", "", ""}; -int is_full_html(char *file_name) -{ +int is_full_html(char *file_name) { char *str, *p; int i, fh, length; unsigned char *buf; @@ -5821,8 +5797,7 @@ int is_full_html(char *file_name) /*------------------------------------------------------------------*/ -int is_ascii(char *file_name) -{ +int is_ascii(char *file_name) { int i, fh, length; unsigned char *buf; @@ -5851,16 +5826,14 @@ int is_ascii(char *file_name) /*------------------------------------------------------------------*/ -int is_image(char *att) -{ +int is_image(char *att) { return (stristr(att, ".GIF") != NULL) || (stristr(att, ".JPG") != NULL) || (stristr(att, ".JPEG") != NULL) - || (stristr(att, ".PNG") != NULL) || (stristr(att, ".SVG") != NULL); + || (stristr(att, ".PNG") != NULL) || (stristr(att, ".SVG") != NULL); } /*------------------------------------------------------------------*/ -void strip_html(char *s) -{ +void strip_html(char *s) { char *p; while ((p = strchr(s, '<')) != NULL) { @@ -5873,8 +5846,7 @@ void strip_html(char *s) /*------------------------------------------------------------------*/ -int line_break(char *str, char *encoding) -{ +int line_break(char *str, char *encoding) { if (strieq(encoding, "plain") || strieq(encoding, "ELCode")) { return str[0] == '\n'; } @@ -5887,8 +5859,7 @@ int line_break(char *str, char *encoding) /*------------------------------------------------------------------*/ -void insert_breaks(char *str, int n, int size) -{ +void insert_breaks(char *str, int n, int size) { int i, j, i_last; i_last = 0; @@ -5920,8 +5891,7 @@ void insert_breaks(char *str, int n, int size) /*------------------------------------------------------------------*/ -void replace_inline_img(LOGBOOK * lbs, char *str) -{ +void replace_inline_img(LOGBOOK *lbs, char *str) { char *p, *pn, *pa, old[256], link[256], base_url[256], domain[256]; int index; @@ -5970,9 +5940,8 @@ void replace_inline_img(LOGBOOK * lbs, char *str) /*------------------------------------------------------------------*/ -void convert_elog_link(LOGBOOK * lbs, char *link, char *link_text, char *result, int absolute_link, - int message_id) -{ +void convert_elog_link(LOGBOOK *lbs, char *link, char *link_text, char *result, int absolute_link, + int message_id) { char str[256], base_url[256]; int i; @@ -6009,8 +5978,7 @@ void convert_elog_link(LOGBOOK * lbs, char *link, char *link_text, char *result, /*------------------------------------------------------------------*/ -void rsputs(const char *str) -{ +void rsputs(const char *str) { if (strlen_retbuf + (int) strlen(str) + 1 >= return_buffer_size) { return_buffer = xrealloc(return_buffer, return_buffer_size + (int) strlen(str) + 100000); memset(return_buffer + return_buffer_size, 0, (int) strlen(str) + 100000); @@ -6023,10 +5991,9 @@ void rsputs(const char *str) /*------------------------------------------------------------------*/ -char *key_list[] = { "http://", "https://", "ftp://", "mailto:", "elog:", "file://", "" }; +char *key_list[] = {"http://", "https://", "ftp://", "mailto:", "elog:", "file://", ""}; -void rsputs2(LOGBOOK * lbs, int absolute_link, const char *str) -{ +void rsputs2(LOGBOOK *lbs, int absolute_link, const char *str) { int i, j, k, l, n; char *p, *pd, link[1000], link_text[1000]; @@ -6089,18 +6056,18 @@ void rsputs2(LOGBOOK * lbs, int absolute_link, const char *str) for (n = 0; n < (int) strlen(link_text); n++) { switch (link_text[n]) { /* the translation for the search highliting */ - case '\001': - link_text[n] = '<'; - break; - case '\002': - link_text[n] = '>'; - break; - case '\003': - link_text[n] = '\"'; - break; - case '\004': - link_text[n] = ' '; - break; + case '\001': + link_text[n] = '<'; + break; + case '\002': + link_text[n] = '>'; + break; + case '\003': + link_text[n] = '\"'; + break; + case '\004': + link_text[n] = ' '; + break; } } @@ -6142,45 +6109,45 @@ void rsputs2(LOGBOOK * lbs, int absolute_link, const char *str) i += 3; } else switch (str[i]) { - case '&': - strcat(return_buffer, "&"); - j += 5; - break; - case '<': - strcat(return_buffer, "<"); - j += 4; - break; - case '>': - strcat(return_buffer, ">"); - j += 4; - break; + case '&': + strcat(return_buffer, "&"); + j += 5; + break; + case '<': + strcat(return_buffer, "<"); + j += 4; + break; + case '>': + strcat(return_buffer, ">"); + j += 4; + break; - /* suppress escape character '\' in front of HTML or ELCode tag */ - case '\\': - if (str[i + 1] != '<' && str[i + 1] != '[') + /* suppress escape character '\' in front of HTML or ELCode tag */ + case '\\': + if (str[i + 1] != '<' && str[i + 1] != '[') + return_buffer[j++] = str[i]; + break; + + /* the translation for the search highliting */ + case '\001': + strcat(return_buffer, "<"); + j++; + break; + case '\002': + strcat(return_buffer, ">"); + j++; + break; + case '\003': + strcat(return_buffer, "\""); + j++; + break; + case '\004': + strcat(return_buffer, " "); + j++; + break; + + default: return_buffer[j++] = str[i]; - break; - - /* the translation for the search highliting */ - case '\001': - strcat(return_buffer, "<"); - j++; - break; - case '\002': - strcat(return_buffer, ">"); - j++; - break; - case '\003': - strcat(return_buffer, "\""); - j++; - break; - case '\004': - strcat(return_buffer, " "); - j++; - break; - - default: - return_buffer[j++] = str[i]; } } } @@ -6191,30 +6158,29 @@ void rsputs2(LOGBOOK * lbs, int absolute_link, const char *str) /*------------------------------------------------------------------*/ -void rsputs3(const char *text) -{ +void rsputs3(const char *text) { int i; char str[2]; str[1] = 0; for (i = 0; i < (int) strlen(text); i++) { switch (text[i]) { - case '<': - rsputs("<"); - break; - case '>': - rsputs(">"); - break; - case '&': - rsputs("&"); - break; - case '\"': - rsputs("""); - break; + case '<': + rsputs("<"); + break; + case '>': + rsputs(">"); + break; + case '&': + rsputs("&"); + break; + case '\"': + rsputs("""); + break; - default: - str[0] = text[i]; - rsputs(str); + default: + str[0] = text[i]; + rsputs(str); } } } @@ -6228,112 +6194,111 @@ typedef struct { PATTERN_LIST pattern_list[] = { - /* smileys */ - {":))", "\"Happy\""}, - {":-))", "\"Happy\""}, - {":)", "\"Smile\""}, - {":-)", "\"Smile\""}, - {":(", "\"Frown\""}, - {":-(", "\"Frown\""}, - {";)", "\"Wink\""}, - {";-)", "\"Wink\""}, - {":d", "\"Big"}, - {"?-)", "\"Confused\""}, - {";(", "\"Crying\""}, - {";-(", "\"Crying\""}, - {":]", "\"Pleased\""}, - {":-]", "\"Pleased\""}, - {":o", "\"Yawn\""}, - {":-o", "\"Yawn\""}, - {"8-)", "\"Cool\""}, - {"8o", "\"Astonished\""}, - {"x-(", "\"Mad\""}, - {":p", "\"Tongue\""}, - {":-p", "\"Tongue\""}, + /* smileys */ + {":))", "\"Happy\""}, + {":-))", "\"Happy\""}, + {":)", "\"Smile\""}, + {":-)", "\"Smile\""}, + {":(", "\"Frown\""}, + {":-(", "\"Frown\""}, + {";)", "\"Wink\""}, + {";-)", "\"Wink\""}, + {":d", "\"Big"}, + {"?-)", "\"Confused\""}, + {";(", "\"Crying\""}, + {";-(", "\"Crying\""}, + {":]", "\"Pleased\""}, + {":-]", "\"Pleased\""}, + {":o", "\"Yawn\""}, + {":-o", "\"Yawn\""}, + {"8-)", "\"Cool\""}, + {"8o", "\"Astonished\""}, + {"x-(", "\"Mad\""}, + {":p", "\"Tongue\""}, + {":-p", "\"Tongue\""}, - /* formatting */ - {"[b]", ""}, - {"[/b]", ""}, - {"[u]", ""}, - {"[/u]", ""}, - {"[i]", ""}, - {"[/i]", ""}, - {"[center]", "
"}, - {"[/center]", "
"}, - {"[color=", ""}, - {"[/color]", ""}, - {"[size=", ""}, - {"[/size]", ""}, - {"[font=", ""}, - {"[/font]", ""}, - {"\r\n[code]", "
"},
-   {"[code]", "
"},
-   {"[/code]\r\n", "
"}, - {"[/code]", "
"}, - {"\r\n[code1]", "
"},
-   {"[code1]", "
"},
-   {"[/code1]\r\n", "
"}, - {"[/code1]", "
"}, + /* formatting */ + {"[b]", ""}, + {"[/b]", ""}, + {"[u]", ""}, + {"[/u]", ""}, + {"[i]", ""}, + {"[/i]", ""}, + {"[center]", "
"}, + {"[/center]", "
"}, + {"[color=", ""}, + {"[/color]", ""}, + {"[size=", ""}, + {"[/size]", ""}, + {"[font=", ""}, + {"[/font]", ""}, + {"\r\n[code]", "
"},
+        {"[code]",       "
"},
+        {"[/code]\r\n",  "
"}, + {"[/code]", "
"}, + {"\r\n[code1]", "
"},
+        {"[code1]",      "
"},
+        {"[/code1]\r\n", "
"}, + {"[/code1]", "
"}, - /* lists */ - {"[list]\r", "