aboutsummaryrefslogtreecommitdiffstats
path: root/daemon/syslogd.h
blob: 20dfa00c4f3d468e221c4a490cbfe0db4edc03a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
 * syslogd.h - syslogd implementation for windows, common definitions
 *
 * Created by Alexander Yaworsky
 *
 * THIS SOFTWARE IS NOT COPYRIGHTED
 *
 * This source code is offered for use in the public domain. You may
 * use, modify or distribute it freely.
 *
 * This code is distributed in the hope that it will be useful but
 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
 * DISCLAIMED. This includes but is not limited to warranties of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 */

extern int verbosity_level;
extern void display_message( FILE* fd, char* file, int line, const char* func, char* fmt, ... );

#ifdef HAVE_DEBUG
#  define DO_TRACE( verbosity, fmt... ) \
       do { \
           if( verbosity <= verbosity_level ) \
               display_message( stderr, __FILE__, __LINE__, __FUNCTION__, fmt ); \
       } while(0)
#  define TRACE_2( fmt... ) DO_TRACE( 2, fmt )
#  define TRACE( fmt... ) DO_TRACE( 1, fmt )
#else
#  define TRACE_2( fmt... )
#  define TRACE( fmt... )
#endif
#define TRACE_ENTER TRACE_2
#define TRACE_LEAVE TRACE_2
#define ERR( fmt... ) display_message( stderr, __FILE__, __LINE__, __FUNCTION__, fmt )

extern HANDLE service_stop_event;

extern char local_hostname[];

extern char *str_month[];

extern void syslogd_main();

/* options and their default values */
extern gboolean use_dns;
extern gchar *source_encoding;
extern gchar *destination_encoding;
extern int mark_interval;
extern gchar *mark_message;
extern int hold;
extern gchar *logdir;

/* listener */
enum listener_status
{
    LSNR_ERROR,
    LSNR_SHUTDOWN,
    LSNR_GOT_MESSAGE
};

struct raw_message
{
    gchar *msg;
    struct sockaddr_in sender_addr;
    struct source *source;
};

extern gboolean init_listener();
extern void fini_listener();
extern enum listener_status listener( struct raw_message** msg );
extern void log_internal( int pri, char* fmt, ... );

/* message */
struct message
{
    LONG refcount;
    struct source *source;
    gchar *sender;
    int facility;
    int priority;
    gchar *timestamp;
    gchar *hostname;
    gchar *program;
    gchar *message;
};

extern void reference_message( struct message* msg );
extern void release_message( struct message* msg );

/* sources, destinations, filters and logpaths */
enum source_type
{
    ST_UNDEFINED,
    ST_INTERNAL,
    ST_UDP
};

struct source
{
    gchar *name;
    enum source_type type;
    struct sockaddr_in udp;
};

enum destination_type
{
    DT_UNDEFINED,
    DT_FILE,
    DT_RELAY
};

enum rotation_period
{
    RP_UNDEFINED = 0,
    RP_INVALID,
    RP_DAILY,
    RP_WEEKLY,
    RP_MONTHLY
};

struct destination_file
{
    gchar *name_pattern;
    enum rotation_period rotate;
    int size;
    int backlogs;
    gboolean ifempty;
    gchar *olddir;
    gchar *compresscmd;
    gchar *compressoptions;
};

struct destination_relay
{
    gchar *collector;
    gboolean omit_hostname;
};

struct destination;

typedef void (*dest_put)( struct destination* destination, struct message* message );
typedef void (*dest_finalize)( struct destination* destination );

struct destination
{
    gchar *name;
    enum destination_type type;
    union
    {
      struct destination_file file;
      struct destination_relay relay;
    } u;
    void *extra;
    /* methods */
    dest_put put;
    dest_finalize fini;
};

struct filter
{
    gchar *name;
    gboolean facilities[ LOG_NFACILITIES ];
    gboolean priorities[ 8 ];
};

struct logpath
{
    struct source *source;
    struct filter *filter;
    struct destination *destination;
};

extern GList *sources;
extern GList *destinations;
extern GList *filters;
extern GList *logpaths;

extern gboolean read_configuration();

extern gboolean init_destination_file( struct destination* destination );
extern gboolean init_destination_relay( struct destination* destination );

/* queue */
struct fifo_item
{
    struct fifo_item *next;  /* queue is a single-linked list */
    void *payload;
};

struct fifo
{
    struct fifo_item *first;  /* first pushed item */
    struct fifo_item *last;   /* last pushed item */
};

extern struct fifo* fifo_create();
extern void fifo_destroy( struct fifo* queue );
extern void fifo_push( struct fifo* queue, void* data );
extern void* fifo_pop( struct fifo* queue );

/* logrotate */
extern void rotate_logfile( const gchar* pathname, struct destination* destination );

/* purger */
struct purger_dir
{
    gchar *directory;
    int keep_days;
};

extern GList *purger_dirs;

extern gboolean init_purger();
extern void fini_purger();
extern void purge_log_dirs();

/* pathnames */
extern gchar* make_absolute_log_pathname( char* path_appendix );
extern void create_directories( gchar* pathname );
extern gchar* normalize_pathname( const gchar* pathname );

/* workaround for syslog.h: included with SYSLOG_NAMES in names.c */
typedef struct _code {
	char	*c_name;
	int	c_val;
} CODE;

extern CODE prioritynames[];
extern CODE facilitynames[];

extern char* get_priority_name( int pri );
extern char* get_facility_name( int pri );