Watt-32 tcp/ip  2.2 dev-rel.10
syslog2.c
Go to the documentation of this file.
1 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <stdarg.h>
38 #include <sys/syslog.h>
39 #include <errno.h>
40 #include <fcntl.h>
41 #include <string.h>
42 #include <time.h>
43 
44 #include "wattcp.h"
45 #include "printk.h"
46 #include "pcconfig.h"
47 #include "strings.h"
48 #include "syslog2.h"
49 
50 #if defined(USE_BSD_API)
51 
52 static void (W32_CALL *prev_hook) (const char*, const char*) = NULL;
53 
54 char syslog_file_name [MAX_NAMELEN] = ""; /* name of logfile */
55 char syslog_host_name [MAX_HOSTLEN] = ""; /* name of loghost */
56 WORD syslog_port = 514; /* udp port to use */
57 int syslog_mask = LOG_UPTO(-1); /* log everything */
58 
59 static int get_log_mask (const char *value)
60 {
61  int mask = 0;
62 
63  if (!strcmp(value, "all"))
64  return (LOG_PRIMASK); /* LOG_UPTO (LOG_EMERG); */
65 
66  if (strstr(value, "emerg")) mask |= LOG_EMERG;
67  if (strstr(value, "alert")) mask |= LOG_ALERT;
68  if (strstr(value, "crit")) mask |= LOG_CRIT;
69  if (strstr(value, "error")) mask |= LOG_ERR;
70  if (strstr(value, "warn")) mask |= LOG_WARNING;
71  if (strstr(value, "notice")) mask |= LOG_NOTICE;
72  if (strstr(value, "info")) mask |= LOG_INFO;
73  if (strstr(value, "debug")) mask |= LOG_DEBUG;
74  return (mask);
75 }
76 
77 static void set_syslog_mask (const char *value)
78 {
79  char val[100];
80 
81  _strlcpy (val, value, sizeof(val));
82  strlwr (val);
83  syslog_mask = get_log_mask (val);
84 }
85 
86 static void W32_CALL syslog2_init (const char *name, const char *value)
87 {
88  static const struct config_table syslog_cfg[] = {
89  { "FILE", ARG_STRCPY, (void*)&syslog_file_name },
90  { "HOST", ARG_STRCPY, (void*)&syslog_host_name },
91  { "PORT", ARG_ATOI, (void*)&syslog_port },
92  { "LEVEL", ARG_FUNC, (void*)set_syslog_mask },
93  { NULL, 0, NULL }
94  };
95  if (!parse_config_table(&syslog_cfg[0], "SYSLOG.", name, value) && prev_hook)
96  (*prev_hook) (name, value);
97 }
98 
99 void syslog_init (void)
100 {
101  prev_hook = usr_init;
102  usr_init = syslog2_init;
103 }
104 #endif /* USE_BSD_API */
int W32_CALL parse_config_table(const struct config_table *tab, const char *section, const char *name, const char *value)
Parse the config-table and if a match is found for ('section'+'.
Definition: pcconfig.c:379
convert to int
Definition: tcp.h:424
call convertion function
Definition: tcp.h:434
copy string value
Definition: tcp.h:432
Core definitions.
char * _strlcpy(char *dst, const char *src, size_t len)
Similar to strncpy(), but always returns 'dst' with 0-termination.
Definition: strings.c:226