libsir 2.2.5
Standard Incident Reporter
Loading...
Searching...
No Matches
types.h
1/*
2 * types.h
3 *
4 * Version: 2.2.5
5 *
6 * -----------------------------------------------------------------------------
7 *
8 * SPDX-License-Identifier: MIT
9 *
10 * Copyright (c) 2018-2024 Ryan M. Lederman <lederman@gmail.com>
11 * Copyright (c) 2018-2024 Jeffrey H. Johnson <trnsz@pobox.com>
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining a copy of
14 * this software and associated documentation files (the "Software"), to deal in
15 * the Software without restriction, including without limitation the rights to
16 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
17 * the Software, and to permit persons to whom the Software is furnished to do so,
18 * subject to the following conditions:
19 *
20 * The above copyright notice and this permission notice shall be included in all
21 * copies or substantial portions of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
26 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
27 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 *
30 * -----------------------------------------------------------------------------
31 */
32
33#ifndef _SIR_TYPES_H_INCLUDED
34# define _SIR_TYPES_H_INCLUDED
35
36# include "sir/platform.h"
37# include "sir/config.h"
38# include "sir/ansimacros.h"
39
49typedef uint32_t sirfileid;
50
52typedef uint32_t sirpluginid;
53
54/*
55 * The following define the available levels of logging output.
56 */
57
58# define SIRL_NONE 0x0000U
59# define SIRL_EMERG 0x0001U
60# define SIRL_ALERT 0x0002U
61# define SIRL_CRIT 0x0004U
62# define SIRL_ERROR 0x0008U
63# define SIRL_WARN 0x0010U
64# define SIRL_NOTICE 0x0020U
65# define SIRL_INFO 0x0040U
66# define SIRL_DEBUG 0x0080U
67# define SIRL_ALL 0x00ffU
68# define SIRL_DEFAULT 0x0100U
71typedef uint16_t sir_level;
72
74typedef uint16_t sir_levels;
75
76/*
77 * Formatting options for a destination.
78 */
79
80# define SIRO_ALL 0x00000000U
81# define SIRO_NOTIME 0x00000100U
82# define SIRO_NOMSEC 0x00000200U
83# define SIRO_NOHOST 0x00000400U
84# define SIRO_NOLEVEL 0x00000800U
85# define SIRO_NONAME 0x00001000U
86# define SIRO_NOPID 0x00002000U
87# define SIRO_NOTID 0x00004000U
88# define SIRO_NOHDR 0x00010000U
89# define SIRO_MSGONLY 0x00007f00U
90# define SIRO_DEFAULT 0x00100000U
93typedef uint32_t sir_option;
94
96typedef uint32_t sir_options;
97
105
114
116enum {
117 /* 4-bit (16-color). */
134 /* 8-bit (256-color) and 24-bit (RGB color) modes:
135 * use the numeric representation (16..255) instead of an enum.
136 * these colors do not have defined names like the above. */
137 SIRTC_DEFAULT = 256
139
141typedef uint32_t sir_textcolor;
142
150typedef struct {
151 const char* func;
152 const char* file;
153 uint32_t line;
155 char os_msg[SIR_MAXERROR];
156 uint16_t code;
157 char msg[SIR_MAXERROR];
159
174
188
195typedef struct {
213
215 struct {
216 uint32_t mask;
217 void* logger;
218 } _state;
219
224 char identity[SIR_MAX_SYSLOG_ID];
225
230 char category[SIR_MAX_SYSLOG_CAT];
232
255
262# define _SIR_MAGIC 0x60906090U
263
265# define SIRSL_IS_OPEN 0x00000001U
266# define SIRSL_LEVELS 0x00000002U
267# define SIRSL_OPTIONS 0x00000004U
268# define SIRSL_CATEGORY 0x00000008U
269# define SIRSL_IDENTITY 0x00000010U
270# define SIRSL_UPDATED 0x00000020U
271# define SIRSL_IS_INIT 0x00000040U
273# if defined(__WIN__)
276typedef void (*invalparamfn)(const wchar_t*, const wchar_t*, const wchar_t*,
277 unsigned int, uintptr_t);
278# endif
279
281typedef struct {
282# if !defined(__WIN__)
283 time_t sec;
284 long msec;
285# else /* __WIN__ */
286 LARGE_INTEGER counter;
287# endif
288} sir_time;
289
291typedef struct {
292 sirinit si;
293 struct {
294 char hostname[SIR_MAXHOST];
295 time_t last_hname_chk;
296 char pidbuf[SIR_MAXPID];
297 pid_t pid;
298 char timestamp[SIR_MAXTIME];
299
301 struct {
302 bool squelch;
303 uint64_t hash;
304 char prefix[2];
305 sir_level level;
306 size_t counter;
307 size_t threshold;
308 } last;
309 } state;
310} sirconfig;
311
313typedef struct {
314 const char* path;
315 sir_levels levels;
316 sir_options opts;
317 FILE* f;
318 sirfileid id;
319 int writes_since_size_chk;
320} sirfile;
321
323typedef struct {
324 sirfile* files[SIR_MAXFILES];
325 size_t count;
326} sirfcache;
327
329typedef struct {
330 uint8_t iface_ver;
331 uint8_t maj_ver;
332 uint8_t min_ver;
333 uint8_t bld_ver;
336 const char* author;
337 const char* desc;
338 uint64_t caps;
340
342# define SIR_PLUGIN_V1 1
343# define SIR_PLUGIN_VCURRENT SIR_PLUGIN_V1
344
346# define SIR_PLUGIN_EXPORT_QUERY "sir_plugin_query"
347# define SIR_PLUGIN_EXPORT_INIT "sir_plugin_init"
348# define SIR_PLUGIN_EXPORT_WRITE "sir_plugin_write"
349# define SIR_PLUGIN_EXPORT_CLEANUP "sir_plugin_cleanup"
350
352typedef bool (*sir_plugin_queryfn)(sir_plugininfo*);
353typedef bool (*sir_plugin_initfn)(void);
354typedef bool (*sir_plugin_writefn)(sir_level, const char*);
355typedef bool (*sir_plugin_cleanupfn)(void);
356
358typedef struct {
359 sir_plugin_queryfn query;
360 sir_plugin_initfn init;
361 sir_plugin_writefn write;
362 sir_plugin_cleanupfn cleanup;
364
366
368typedef struct {
369 const char* path;
370 sir_pluginhandle handle;
371 sir_plugininfo info;
372 bool loaded;
373 bool valid;
374 sir_pluginiface iface;
375 sirpluginid id;
376} sir_plugin;
377
379typedef struct {
380 sir_plugin* plugins[SIR_MAXPLUGINS];
381 size_t count;
383
385typedef struct _sir_queue_node {
386 struct _sir_queue_node* next;
387 void* data;
389
391typedef struct {
393} sir_queue;
394
396typedef struct {
397 bool (*fn)(void*);
398 void* data;
400
402typedef struct {
403 sir_thread* threads;
404 size_t num_threads;
406 sir_condition cond;
407 sir_mutex mutex;
408 bool cancel;
410
412typedef struct {
413 char style[SIR_MAXSTYLE];
414 char* timestamp;
415 char msec[SIR_MAXMSEC];
416 const char* hostname;
417 const char* pid;
418 const char* level;
419 const char* name;
420 char tid[SIR_MAXPID];
421 char message[SIR_MAXMESSAGE];
422 char output[SIR_MAXOUTPUT];
423 size_t output_len;
424} sirbuf;
425
432
434typedef struct {
436 sir_colormode* color_mode;
438
440typedef struct {
442 const char* fmt;
444
446typedef enum {
447 SIRMI_CONFIG = 0,
448 SIRMI_FILECACHE,
449 SIRMI_PLUGINCACHE,
450# if !defined(SIR_NO_TEXT_STYLING)
451 SIRMI_TEXTSTYLE,
452# endif
453} sir_mutex_id;
454
456typedef struct {
457 uint32_t lasterror;
458 int os_code;
459 char os_msg[SIR_MAXERROR];
460
461 struct {
462 const char* func;
463 const char* file;
464 uint32_t line;
465 } loc;
467
469typedef uint32_t sir_config_data_field;
470
471# define SIRU_LEVELS 0x00000001U
472# define SIRU_OPTIONS 0x00000002U
473# define SIRU_SYSLOG_ID 0x00000004U
474# define SIRU_SYSLOG_CAT 0x00000008U
475# define SIRU_ALL 0x0000000fU
478typedef struct {
479 uint32_t fields;
482 const char* sl_identity;
483 const char* sl_category;
485
486#endif /* !_SIR_TYPES_H_INCLUDED */
ANSI escape sequence macros.
Compile-time configuration.
#define SIR_MAX_SYSLOG_ID
The size, in characters, of the buffer used to hold system logger identity strings.
Definition config.h:373
#define SIR_MAXSTYLE
The size, in characters, of the buffer used to hold a sequence of styling data in any color mode (the...
Definition config.h:397
#define SIR_MAXMESSAGE
The maximum number of characters allowable in one log message.
Definition config.h:342
#define SIR_MAXNAME
The size, in characters, of the buffer used to hold process/appname format strings.
Definition config.h:365
#define SIR_MAXPLUGINS
The maximum number of plugin modules that may be loaded at one time.
Definition config.h:329
#define SIR_MAXFILES
The maximum number of log files that may be registered at one time.
Definition config.h:324
#define SIR_MAXMSEC
The size, in characters, of the buffer used to hold millisecond strings.
Definition config.h:352
#define SIR_MAXOUTPUT
The maximum size, in characters, of final formatted output.
Definition config.h:413
#define SIR_MAXTIME
The size, in characters, of the buffer used to hold time format strings.
Definition config.h:347
#define SIR_MAX_SYSLOG_CAT
The size, in characters, of the buffer used to hold system logger category strings.
Definition config.h:381
#define SIR_MAXERROR
The maximum size, in characters, of an error message.
Definition config.h:419
const char * file
Name of the file in which the error occurred.
Definition types.h:152
uint16_t code
Numeric error code (see sir_errorcode).
Definition types.h:156
int os_code
If an OS/libc error, the relevant code.
Definition types.h:154
sir_levels levels
sir_level bitmask defining levels to register for.
Definition types.h:196
sir_levels levels
sir_level bitmask defining output levels to register for.
Definition types.h:183
sir_textcolor bg
Background color.
Definition types.h:172
sir_textattr attr
Text attributes.
Definition types.h:170
sir_options opts
sir_option bitmask defining the formatting of output.
Definition types.h:186
sir_syslog_dest d_syslog
System logger configuration.
Definition types.h:247
uint32_t line
Line number at which the error occurred.
Definition types.h:153
sir_stdio_dest d_stdout
stdout configuration.
Definition types.h:245
sir_stdio_dest d_stderr
stderr configuration.
Definition types.h:246
sir_textcolor fg
Foreground color.
Definition types.h:171
sir_options opts
sir_option bitmask defining the formatting of output.
Definition types.h:212
const char * func
Name of the function in which the error occurred.
Definition types.h:151
uint16_t sir_level
The sir_level type.
Definition types.h:71
uint32_t sirfileid
Log file identifier type.
Definition types.h:49
sir_textattr
Attributes for stdio output.
Definition types.h:107
sir_colormode
Color mode selection.
Definition types.h:99
uint16_t sir_levels
sir_level bitmask type.
Definition types.h:74
uint32_t sir_textcolor
stdio text color type.
Definition types.h:141
uint32_t sir_option
The sir_option type.
Definition types.h:93
uint32_t sirpluginid
Plugin module identifier type.
Definition types.h:52
uint32_t sir_options
sir_option bitmask type.
Definition types.h:96
@ SIRTA_EMPH
Italicized/emphasized text.
Definition types.h:111
@ SIRTA_DIM
Dimmed text.
Definition types.h:110
@ SIRTA_ULINE
Underlined text.
Definition types.h:112
@ SIRTA_NORMAL
Normal text.
Definition types.h:108
@ SIRTA_BOLD
Bold text.
Definition types.h:109
@ SIRCM_16
4-bit 16-color mode.
Definition types.h:100
@ SIRCM_RGB
24-bit RGB-color mode.
Definition types.h:102
@ SIRCM_INVALID
Represents the invalid color mode.
Definition types.h:103
@ SIRCM_256
8-bit 256-color mode.
Definition types.h:101
@ SIRTC_LGRAY
Light gray.
Definition types.h:125
@ SIRTC_BYELLOW
Bright yellow.
Definition types.h:129
@ SIRTC_CYAN
Cyan.
Definition types.h:124
@ SIRTC_YELLOW
Yellow.
Definition types.h:121
@ SIRTC_BLUE
Blue.
Definition types.h:122
@ SIRTC_BGREEN
Bright green.
Definition types.h:128
@ SIRTC_DEFAULT
Represents the default color.
Definition types.h:137
@ SIRTC_BLACK
Black.
Definition types.h:118
@ SIRTC_WHITE
White.
Definition types.h:133
@ SIRTC_BMAGENTA
Bright magenta.
Definition types.h:131
@ SIRTC_BCYAN
Bright cyan.
Definition types.h:132
@ SIRTC_MAGENTA
Magenta.
Definition types.h:123
@ SIRTC_RED
Red.
Definition types.h:119
@ SIRTC_BBLUE
Bright blue.
Definition types.h:130
@ SIRTC_BRED
Bright red.
Definition types.h:127
@ SIRTC_GREEN
Green.
Definition types.h:120
@ SIRTC_DGRAY
Dark gray.
Definition types.h:126
Information about an error that occurred.
Definition types.h:150
Configuration for stdio destinations (stdout and stderr).
Definition types.h:181
Configuration for the system logger destination.
Definition types.h:195
Container for all the information associated with the appearance of text in the context of stdio.
Definition types.h:169
libsir initialization and configuration data.
Definition types.h:244
sir_level <-> human-readable string form.
Definition types.h:440
const sir_level level
The level for which the string applies.
Definition types.h:441
const char * fmt
The formatted string representation.
Definition types.h:442
sir_level <-> sir_textstyle mapping.
Definition types.h:427
sir_textstyle style
The un-formatted representation.
Definition types.h:429
const sir_level level
The level for which the style applies.
Definition types.h:428
Internally-used plugin module data.
Definition types.h:368
Plugin module cache.
Definition types.h:379
Plugin interface for v1.
Definition types.h:358
sir_plugin_cleanupfn cleanup
Address of sir_plugin_cleanup.
Definition types.h:362
sir_plugin_queryfn query
Address of sir_plugin_query.
Definition types.h:359
sir_plugin_writefn write
Address of sir_plugin_write.
Definition types.h:361
sir_plugin_initfn init
Address of sir_plugin_init.
Definition types.h:360
The libsir-to-plugin query data structure.
Definition types.h:329
uint8_t iface_ver
Plugin interface version.
Definition types.h:330
uint8_t bld_ver
Build/patch version number.
Definition types.h:333
uint8_t min_ver
Minor version number.
Definition types.h:332
uint64_t caps
Plugin capabilities bitmask.
Definition types.h:338
const char * desc
Plugin description.
Definition types.h:337
const char * author
Plugin author information.
Definition types.h:336
sir_levels levels
Level registration bitmask.
Definition types.h:334
uint8_t maj_ver
Major version number.
Definition types.h:331
sir_options opts
Formatting options bitmask.
Definition types.h:335
A node in a sir_queue.
Definition types.h:385
FIFO queue.
Definition types.h:391
sir_queue_node * head
The first node in the linked list.
Definition types.h:392
Container for text style related data that is mutex protected.
Definition types.h:434
Per-thread error type.
Definition types.h:456
Job used by a job queue.
Definition types.h:396
void * data
Data to pass to the callback.
Definition types.h:398
Thread pool/job queue data container.
Definition types.h:402
size_t num_threads
The number of threads in the pool.
Definition types.h:404
sir_queue * jobs
A queue of jobs to run (FIFO).
Definition types.h:405
sir_condition cond
A condition which indicates that a job is ready.
Definition types.h:406
sir_thread * threads
A list of thread handles.
Definition types.h:403
sir_mutex mutex
A mutex to be paired with the condition variable.
Definition types.h:407
bool cancel
Causes threads in the pool to exit when true.
Definition types.h:408
Internally-used time value type.
Definition types.h:281
Encapsulates dynamic updating of current configuration.
Definition types.h:478
const char * sl_identity
System logger identity.
Definition types.h:482
sir_levels * levels
Level registrations.
Definition types.h:480
sir_options * opts
Formatting options.
Definition types.h:481
const char * sl_category
System logger category.
Definition types.h:483
uint32_t fields
sir_config_data_field bitmask.
Definition types.h:479
Formatted output container.
Definition types.h:412
Internally-used global config container.
Definition types.h:291
Log file cache.
Definition types.h:323
Internally-used log file data.
Definition types.h:313