aboutsummaryrefslogtreecommitdiffstats
path: root/daemon/syslogd.h
blob: 7b41db88b3a7fc4a450da706aa221e6b58838590 (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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
 * 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 )

/* refcounted string */
struct string
{
    LONG refcount;
    GString *gstr;
};

extern struct string* string_new( const gchar* init );
extern struct string* string_new_len( const gchar* init, gssize len );
extern struct string* string_addref( struct string* s );
extern void string_release( struct string* s );
extern struct string* string_vprintf( gchar* fmt, va_list args );
extern struct string* string_printf( gchar* fmt, ... );
extern gsize string_concat( gchar** result, struct string* s, ... );
extern gboolean string_equal( struct string* s1, struct string* s2 );

/* misc global stuff */
extern HANDLE service_stop_event;

extern struct string *local_hostname;
extern struct string *self_program_name;
extern struct string *space;
extern struct string *line_feed;

extern char *str_month[];

extern void syslogd_main();

extern void log_internal( int pri, char* fmt, ... );

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

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

extern struct fifo *udp_message_queue;
extern HANDLE udp_queue_event;
extern CRITICAL_SECTION udp_queue_cs;

extern gboolean init_udp_listener();
extern void shutdown_udp_listener();
extern void fini_udp_listener();

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

extern struct message* create_message( struct source* source,
                                       struct string* sender,
                                       int facility, int priority,
                                       LPSYSTEMTIME timestamp,
                                       struct string* hostname,
                                       struct string* program,
                                       struct string* message );
extern struct message* duplicate_message( struct message* msg );
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;
    gchar *encoding;
    struct sockaddr_in udp;
};

extern unsigned number_of_sources( enum source_type type );

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;
    gchar *encoding;
    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;
    GIConv message_cd;  /* charset conversion descriptor for message */
    GIConv program_cd;  /* charset conversion descriptor for program name */
};

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;

extern struct fifo* fifo_create();
extern void fifo_destroy( struct fifo* queue );
extern gboolean 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 );