ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
log.c
Go to the documentation of this file.
1#include <unistd.h>
2#include "buffer.h"
3#include "readwrite.h"
4#include "stralloc.h"
5#include "logaddr.h"
6#include "now.h"
7#include "fmt.h"
8#include "open.h"
9
10#define WHO "log"
11
22
23
24static buffer bl;
25static char logbuf[128];
26static char num[FMT_ULONG];
27static stralloc line = {0};
28static stralloc fn = {0};
29
30void logaddr(const char *dir,const char *event,const char *addr,const char *comment)
31{
32 char ch;
33 int fd;
34
35 if (!stralloc_copyb(&line,num,fmt_ulong(num,(unsigned long) now()))) return;
36 if (!stralloc_cats(&line," ")) return;
37 if (!stralloc_cats(&line,event)) return;
38 if (!stralloc_cats(&line," ")) return;
39 while ((ch = *addr++)) {
40 if ((ch < 33) || (ch > 126)) ch = '?';
41 if (!stralloc_append(&line,&ch)) return;
42 }
43 if (comment && *comment) {
44 if (!stralloc_cats(&line," ")) return;
45 while ((ch = *comment++)) {
46 if (ch == '\t')
47 ch = ' ';
48 else
49 if ((ch < 32) || (ch > 126)) ch = '?';
50 if (!stralloc_append(&line,&ch)) return;
51 }
52 }
53 if (!stralloc_cats(&line,"\n")) return;
54
55 if (!stralloc_copys(&fn,dir)) return;
56 if (!stralloc_cats(&fn,"/Log")) return;
57 if (!stralloc_0(&fn)) return;
58
59 fd = open_append(fn.s);
60 if (fd == -1) return;
61 buffer_init(&bl,buffer_unixwrite,fd,logbuf,sizeof(logbuf));
62 buffer_putflush(&bl,line.s,line.len);
63 close(fd);
64
65 return;
66}
datetime_sec now(void)
Definition now.c:5
stralloc fn
stralloc num
char * dir
stralloc addr
Definition ezmlm-cron.c:45
int fd
Definition ezmlm-cgi.c:141
stralloc comment
void logaddr(const char *dir, const char *event, const char *addr, const char *comment)
Definition log.c:30