| 1 |
/** @file translate.h |
| 2 |
* @brief Interfaces for canonical config translation. |
| 3 |
* |
| 4 |
* Copyright 2026 Rainer Gerhards and Adiscon GmbH. |
| 5 |
* |
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
* you may not use this file except in compliance with the License. |
| 8 |
* You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* -or- |
| 12 |
* see COPYING.ASL20 in the source distribution |
| 13 |
* |
| 14 |
* Unless required by applicable law or agreed to in writing, software |
| 15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
* See the License for the specific language governing permissions and |
| 18 |
* limitations under the License. |
| 19 |
*/ |
| 20 |
#ifndef RUNTIME_TRANSLATE_H_INCLUDED |
| 21 |
#define RUNTIME_TRANSLATE_H_INCLUDED |
| 22 |
|
| 23 |
#include "rsyslog.h" |
| 24 |
#include "grammar/rainerscript.h" |
| 25 |
|
| 26 |
/** @brief Supported translation output formats. */ |
| 27 |
enum rsconfTranslateFormat { RSCONF_TRANSLATE_NONE = 0, RSCONF_TRANSLATE_RAINERSCRIPT, RSCONF_TRANSLATE_YAML }; |
| 28 |
|
| 29 |
/** |
| 30 |
* @brief Configure translation mode for the current validation run. |
| 31 |
* |
| 32 |
* Resets any previously retained translation state before enabling the |
| 33 |
* selected output format. |
| 34 |
* |
| 35 |
* @param fmt Translation output format, or @c RSCONF_TRANSLATE_NONE to disable. |
| 36 |
*/ |
| 37 |
void rsconfTranslateConfigure(enum rsconfTranslateFormat fmt); |
| 38 |
|
| 39 |
/** |
| 40 |
* @brief Release all retained translation state. |
| 41 |
*/ |
| 42 |
void rsconfTranslateCleanup(void); |
| 43 |
|
| 44 |
/** |
| 45 |
* @brief Check whether translation capture is enabled. |
| 46 |
* |
| 47 |
* @return Non-zero when config translation is active. |
| 48 |
*/ |
| 49 |
int rsconfTranslateEnabled(void); |
| 50 |
|
| 51 |
/** |
| 52 |
* @brief Check whether translation capture hit a fatal error. |
| 53 |
* |
| 54 |
* @return Non-zero when translation should fail instead of writing output. |
| 55 |
*/ |
| 56 |
int rsconfTranslateHasFatal(void); |
| 57 |
|
| 58 |
/** |
| 59 |
* @brief Clone a name-value list for later translation output. |
| 60 |
* |
| 61 |
* @param lst List head to clone. |
| 62 |
* @return Cloned list, or NULL on allocation failure. |
| 63 |
*/ |
| 64 |
struct nvlst *rsconfTranslateCloneNvlst(const struct nvlst *lst); |
| 65 |
|
| 66 |
/** |
| 67 |
* @brief Capture a config object before normal processing consumes it. |
| 68 |
* |
| 69 |
* @param o Parsed config object. |
| 70 |
* @param source Source file name, if known. |
| 71 |
* @param line Source line number. |
| 72 |
*/ |
| 73 |
void rsconfTranslateCaptureObj(const struct cnfobj *o, const char *source, int line); |
| 74 |
|
| 75 |
/** |
| 76 |
* @brief Capture executable script statements for later emission. |
| 77 |
* |
| 78 |
* @param script Statement tree to serialize. |
| 79 |
* @param source Source file name, if known. |
| 80 |
* @param line Source line number. |
| 81 |
*/ |
| 82 |
void rsconfTranslateCaptureScript(const struct cnfstmt *script, const char *source, int line); |
| 83 |
|
| 84 |
/** |
| 85 |
* @brief Record a fatal unsupported construct for translation. |
| 86 |
* |
| 87 |
* @param source Source file name, if known. |
| 88 |
* @param line Source line number. |
| 89 |
* @param fmt Printf-style explanation of the unsupported construct. |
| 90 |
*/ |
| 91 |
void rsconfTranslateAddUnsupported(const char *source, int line, const char *fmt, ...) |
| 92 |
__attribute__((format(printf, 3, 4))); |
| 93 |
|
| 94 |
/** |
| 95 |
* @brief Write the translated configuration document. |
| 96 |
* |
| 97 |
* @param path Output path, or "-" for stdout. |
| 98 |
* @return rsyslog status code for the write operation. |
| 99 |
*/ |
| 100 |
rsRetVal rsconfTranslateWriteFile(const char *path); |
| 101 |
|
| 102 |
#endif |