root/src/libsir/src/sir.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sir_makeinit
  2. sir_init
  3. sir_cleanup
  4. sir_isinitialized
  5. sir_geterror
  6. sir_geterrorinfo
  7. PRINTF_FORMAT_ATTR
  8. PRINTF_FORMAT_ATTR
  9. PRINTF_FORMAT_ATTR
  10. PRINTF_FORMAT_ATTR
  11. PRINTF_FORMAT_ATTR
  12. PRINTF_FORMAT_ATTR
  13. PRINTF_FORMAT_ATTR
  14. PRINTF_FORMAT_ATTR
  15. sir_addfile
  16. sir_remfile
  17. sir_loadplugin
  18. sir_unloadplugin
  19. sir_filelevels
  20. sir_fileopts
  21. sir_settextstyle
  22. sir_resettextstyles
  23. sir_makergb
  24. sir_setcolormode
  25. sir_stdoutlevels
  26. sir_stdoutopts
  27. sir_stderrlevels
  28. sir_stderropts
  29. sir_sysloglevels
  30. sir_syslogopts
  31. sir_syslogid
  32. sir_syslogcat
  33. sir_getversionstring
  34. sir_getversionhex
  35. sir_isprerelease

   1 /**
   2  * @file sir.c
   3  *
   4  * @brief Public interface to libsir
   5  *
   6  * The functions and types defined here comprise the entire set intended for
   7  * use by an implementer of the library-unless modification is desired.
   8  *
   9  * @version 2.2.5
  10  *
  11  * -----------------------------------------------------------------------------
  12  *
  13  * SPDX-License-Identifier: MIT
  14  *
  15  * Copyright (c) 2018-2024 Ryan M. Lederman <lederman@gmail.com>
  16  *
  17  * Permission is hereby granted, free of charge, to any person obtaining a copy of
  18  * this software and associated documentation files (the "Software"), to deal in
  19  * the Software without restriction, including without limitation the rights to
  20  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  21  * the Software, and to permit persons to whom the Software is furnished to do so,
  22  * subject to the following conditions:
  23  *
  24  * The above copyright notice and this permission notice shall be included in all
  25  * copies or substantial portions of the Software.
  26  *
  27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  29  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  30  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  31  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  33  *
  34  * -----------------------------------------------------------------------------
  35  */
  36 
  37 #include "sir.h"
  38 #include "sir/internal.h"
  39 #include "sir/filecache.h"
  40 #include "sir/plugins.h"
  41 #include "sir/textstyle.h"
  42 #include "sir/defaults.h"
  43 
  44 bool sir_makeinit(sirinit* si) {
     /* [previous][next][first][last][top][bottom][index][help] */
  45     return _sir_makeinit(si);
  46 }
  47 
  48 bool sir_init(sirinit* si) {
     /* [previous][next][first][last][top][bottom][index][help] */
  49     return _sir_init(si);
  50 }
  51 
  52 bool sir_cleanup(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  53     return _sir_cleanup();
  54 }
  55 
  56 bool sir_isinitialized(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
  57     return _sir_isinitialized();
  58 }
  59 
  60 uint16_t sir_geterror(char message[SIR_MAXERROR]) {
     /* [previous][next][first][last][top][bottom][index][help] */
  61     return _sir_geterrcode(_sir_geterror(message));
  62 }
  63 
  64 void sir_geterrorinfo(sir_errorinfo* err) {
     /* [previous][next][first][last][top][bottom][index][help] */
  65     _sir_geterrorinfo(err);
  66 }
  67 
  68 PRINTF_FORMAT_ATTR(1, 2)
     /* [previous][next][first][last][top][bottom][index][help] */
  69 bool sir_debug(PRINTF_FORMAT const char* format, ...) {
  70     _SIR_L_START(format);
  71     ret = _sir_logv(SIRL_DEBUG, format, args);
  72     _SIR_L_END();
  73     return ret;
  74 }
  75 
  76 PRINTF_FORMAT_ATTR(1, 2)
     /* [previous][next][first][last][top][bottom][index][help] */
  77 bool sir_info(PRINTF_FORMAT const char* format, ...) {
  78     _SIR_L_START(format);
  79     ret = _sir_logv(SIRL_INFO, format, args);
  80     _SIR_L_END();
  81     return ret;
  82 }
  83 
  84 PRINTF_FORMAT_ATTR(1, 2)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 bool sir_notice(PRINTF_FORMAT const char* format, ...) {
  86     _SIR_L_START(format);
  87     ret = _sir_logv(SIRL_NOTICE, format, args);
  88     _SIR_L_END();
  89     return ret;
  90 }
  91 
  92 PRINTF_FORMAT_ATTR(1, 2)
     /* [previous][next][first][last][top][bottom][index][help] */
  93 bool sir_warn(PRINTF_FORMAT const char* format, ...) {
  94     _SIR_L_START(format);
  95     ret = _sir_logv(SIRL_WARN, format, args);
  96     _SIR_L_END();
  97     return ret;
  98 }
  99 
 100 PRINTF_FORMAT_ATTR(1, 2)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 bool sir_error(PRINTF_FORMAT const char* format, ...) {
 102     _SIR_L_START(format);
 103     ret = _sir_logv(SIRL_ERROR, format, args);
 104     _SIR_L_END();
 105     return ret;
 106 }
 107 
 108 PRINTF_FORMAT_ATTR(1, 2)
     /* [previous][next][first][last][top][bottom][index][help] */
 109 bool sir_crit(PRINTF_FORMAT const char* format, ...) {
 110     _SIR_L_START(format);
 111     ret = _sir_logv(SIRL_CRIT, format, args);
 112     _SIR_L_END();
 113     return ret;
 114 }
 115 
 116 PRINTF_FORMAT_ATTR(1, 2)
     /* [previous][next][first][last][top][bottom][index][help] */
 117 bool sir_alert(PRINTF_FORMAT const char* format, ...) {
 118     _SIR_L_START(format);
 119     ret = _sir_logv(SIRL_ALERT, format, args);
 120     _SIR_L_END();
 121     return ret;
 122 }
 123 
 124 PRINTF_FORMAT_ATTR(1, 2)
     /* [previous][next][first][last][top][bottom][index][help] */
 125 bool sir_emerg(PRINTF_FORMAT const char* format, ...) {
 126     _SIR_L_START(format);
 127     ret = _sir_logv(SIRL_EMERG, format, args);
 128     _SIR_L_END();
 129     return ret;
 130 }
 131 
 132 sirfileid sir_addfile(const char* path, sir_levels levels, sir_options opts) {
     /* [previous][next][first][last][top][bottom][index][help] */
 133     return _sir_addfile(path, levels, opts);
 134 }
 135 
 136 bool sir_remfile(sirfileid id) {
     /* [previous][next][first][last][top][bottom][index][help] */
 137     return _sir_remfile(id);
 138 }
 139 
 140 sirpluginid sir_loadplugin(const char* path) {
     /* [previous][next][first][last][top][bottom][index][help] */
 141 #if !defined(SIR_NO_PLUGINS)
 142     return _sir_plugin_load(path);
 143 #else
 144     SIR_UNUSED(path);
 145     return _sir_seterror(_SIR_E_UNAVAIL);
 146 #endif
 147 }
 148 
 149 bool sir_unloadplugin(sirpluginid id) {
     /* [previous][next][first][last][top][bottom][index][help] */
 150 #if !defined(SIR_NO_PLUGINS)
 151     return _sir_plugin_rem(id);
 152 #else
 153     SIR_UNUSED(id);
 154     return _sir_seterror(_SIR_E_UNAVAIL);
 155 #endif
 156 }
 157 
 158 bool sir_filelevels(sirfileid id, sir_levels levels) {
     /* [previous][next][first][last][top][bottom][index][help] */
 159     _sir_defaultlevels(&levels, sir_file_def_lvls);
 160     sir_update_config_data data = {SIRU_LEVELS, &levels, NULL, NULL, NULL};
 161     return _sir_updatefile(id, &data);
 162 }
 163 
 164 bool sir_fileopts(sirfileid id, sir_options opts) {
     /* [previous][next][first][last][top][bottom][index][help] */
 165     _sir_defaultopts(&opts, sir_file_def_opts);
 166     sir_update_config_data data = {SIRU_OPTIONS, NULL, &opts, NULL, NULL};
 167     return _sir_updatefile(id, &data);
 168 }
 169 
 170 bool sir_settextstyle(sir_level level, sir_textattr attr, sir_textcolor fg,
     /* [previous][next][first][last][top][bottom][index][help] */
 171     sir_textcolor bg) {
 172     sir_textstyle style = {
 173         attr,
 174         fg,
 175         bg
 176     };
 177 
 178     return _sir_settextstyle(level, &style);
 179 }
 180 
 181 bool sir_resettextstyles(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
 182     return _sir_resettextstyles();
 183 }
 184 
 185 sir_textcolor sir_makergb(sir_textcolor r, sir_textcolor g, sir_textcolor b) {
     /* [previous][next][first][last][top][bottom][index][help] */
 186     return _sir_makergb(r, g, b);
 187 }
 188 
 189 bool sir_setcolormode(sir_colormode mode) {
     /* [previous][next][first][last][top][bottom][index][help] */
 190     return _sir_setcolormode(mode);
 191 }
 192 
 193 bool sir_stdoutlevels(sir_levels levels) {
     /* [previous][next][first][last][top][bottom][index][help] */
 194     _sir_defaultlevels(&levels, sir_stdout_def_lvls);
 195     sir_update_config_data data = {SIRU_LEVELS, &levels, NULL, NULL, NULL};
 196     return _sir_writeinit(&data, _sir_stdoutlevels);
 197 }
 198 
 199 bool sir_stdoutopts(sir_options opts) {
     /* [previous][next][first][last][top][bottom][index][help] */
 200     _sir_defaultopts(&opts, sir_stdout_def_opts);
 201     sir_update_config_data data = {SIRU_OPTIONS, NULL, &opts, NULL, NULL};
 202     return _sir_writeinit(&data, _sir_stdoutopts);
 203 }
 204 
 205 bool sir_stderrlevels(sir_levels levels) {
     /* [previous][next][first][last][top][bottom][index][help] */
 206     _sir_defaultlevels(&levels, sir_stderr_def_lvls);
 207     sir_update_config_data data = {SIRU_LEVELS, &levels, NULL, NULL, NULL};
 208     return _sir_writeinit(&data, _sir_stderrlevels);
 209 }
 210 
 211 bool sir_stderropts(sir_options opts) {
     /* [previous][next][first][last][top][bottom][index][help] */
 212     _sir_defaultopts(&opts, sir_stderr_def_opts);
 213     sir_update_config_data data = {SIRU_OPTIONS, NULL, &opts, NULL, NULL};
 214     return _sir_writeinit(&data, _sir_stderropts);
 215 }
 216 
 217 bool sir_sysloglevels(sir_levels levels) {
     /* [previous][next][first][last][top][bottom][index][help] */
 218 #if !defined(SIR_NO_SYSTEM_LOGGERS)
 219     _sir_defaultlevels(&levels, sir_syslog_def_lvls);
 220     sir_update_config_data data = {SIRU_LEVELS, &levels, NULL, NULL, NULL};
 221     return _sir_writeinit(&data, _sir_sysloglevels);
 222 #else
 223     SIR_UNUSED(levels);
 224     return _sir_seterror(_SIR_E_UNAVAIL);
 225 #endif
 226 }
 227 
 228 bool sir_syslogopts(sir_options opts) {
     /* [previous][next][first][last][top][bottom][index][help] */
 229 #if !defined(SIR_NO_SYSTEM_LOGGERS)
 230     _sir_defaultopts(&opts, sir_syslog_def_opts);
 231     sir_update_config_data data = {SIRU_OPTIONS, NULL, &opts, NULL, NULL};
 232     return _sir_writeinit(&data, _sir_syslogopts);
 233 #else
 234     SIR_UNUSED(opts);
 235     return _sir_seterror(_SIR_E_UNAVAIL);
 236 #endif
 237 }
 238 
 239 bool sir_syslogid(const char* identity) {
     /* [previous][next][first][last][top][bottom][index][help] */
 240 #if !defined(SIR_NO_SYSTEM_LOGGERS)
 241     sir_update_config_data data = {SIRU_SYSLOG_ID, NULL, NULL, identity, NULL};
 242     return _sir_writeinit(&data, _sir_syslogid);
 243 #else
 244     SIR_UNUSED(identity);
 245     return _sir_seterror(_SIR_E_UNAVAIL);
 246 #endif
 247 }
 248 
 249 bool sir_syslogcat(const char* category) {
     /* [previous][next][first][last][top][bottom][index][help] */
 250 #if !defined(SIR_NO_SYSTEM_LOGGERS)
 251     sir_update_config_data data = {SIRU_SYSLOG_CAT, NULL, NULL, NULL, category};
 252     return _sir_writeinit(&data, _sir_syslogcat);
 253 #else
 254     SIR_UNUSED(category);
 255     return _sir_seterror(_SIR_E_UNAVAIL);
 256 #endif
 257 }
 258 
 259 const char* sir_getversionstring(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
 260     return _SIR_MK_VER_STR(SIR_VERSION_MAJOR, SIR_VERSION_MINOR, SIR_VERSION_PATCH);
 261 }
 262 
 263 uint32_t sir_getversionhex(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
 264     return SIR_VERSION_HEX;
 265 }
 266 
 267 bool sir_isprerelease(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
 268     return (!SIR_VERSION_IS_RELEASE);
 269 }

/* [previous][next][first][last][top][bottom][index][help] */