extern "C" {
#endif
-int __log_limiter_initialize(void);
+#include <logconfig.h>
void __log_limiter_destroy(void);
int __log_limiter_pass_log(const char* tag, int prio);
-int __log_limiter_add_rule(const char* tag, int prio, int limit);
+int __configure_limiter(struct log_config *config, int default_limiter);
#ifdef __cplusplus
}
return DLOG_ERROR_NOT_PERMITTED; // LCOV_EXCL_LINE
}
-/**
- * @brief Limiter rule from config
- * @details Adds a limiter rule from a config entry, if one exists inside
- * @param[in] key The entry key
- * @param[in] value The entry value
- * @param[in,out] u Userdata (unused)
- */
-// LCOV_EXCL_START
-static void __config_iteration(const char* key, const char* value, void *u)
-{
- assert(key);
- assert(value);
-
- static const int prefix_len = sizeof("limiter|") - 1;
- char * delimiter_pos;
- char limiter_tag[MAX_CONF_KEY_LEN];
- int limit;
-
- if (strncmp(key, "limiter|", prefix_len))
- return;
-
- delimiter_pos = strchr(key + prefix_len + 1, '|');
- if (!delimiter_pos || (delimiter_pos + 1 == key + strlen(key)))
- return;
-
- snprintf(limiter_tag, delimiter_pos - (key + prefix_len) + 1, "%s", key + prefix_len);
-
- if (!strcmp(value, "allow"))
- limit = __LOG_LIMITER_LIMIT_MAX + 1;
- else if (!strcmp(value, "deny"))
- limit = 0;
- else
- limit = atoi(value);
-
- __log_limiter_add_rule(limiter_tag, *(delimiter_pos + 1), limit);
-}
-// LCOV_EXCL_STOP
-
-static int __configure_limiter(struct log_config *config)
-{
- assert(config);
-
- int enabled = log_config_get_int(config, "limiter", DEFAULT_CONFIG_LIMITER);
- if (!enabled)
- return 0;
-
- log_config_foreach(config, __config_iteration, NULL); // LCOV_EXCL_LINE
-
- return (__log_limiter_initialize() == 0); // LCOV_EXCL_LINE
-}
-
static int __configure_backend(struct log_config *config)
{
assert(config);
plog = log_config_get_int(config, "plog", DEFAULT_CONFIG_PLOG);
debugmode = log_config_get_int(config, "debugmode", DEFAULT_CONFIG_DEBUGMODE);
fatal_assert = access(DEBUGMODE_FILE, F_OK) != -1;
- limiter = __configure_limiter(config);
+ limiter = __configure_limiter(config, DEFAULT_CONFIG_LIMITER);
}
/**
* limitations under the License.
*/
+#include <assert.h>
#include <stddef.h>
#include <limits.h>
#include <sys/types.h>
}
}
// LCOV_EXCL_STOP
+
+/**
+ * @brief Limiter rule from config
+ * @details Adds a limiter rule from a config entry, if one exists inside
+ * @param[in] key The entry key
+ * @param[in] value The entry value
+ * @param[in,out] u Userdata (unused)
+ */
+// LCOV_EXCL_START
+static void __config_iteration(const char* key, const char* value, void *u)
+{
+ assert(key);
+ assert(value);
+
+ static const int prefix_len = sizeof("limiter|") - 1;
+ char * delimiter_pos;
+ char limiter_tag[MAX_CONF_KEY_LEN];
+ int limit;
+
+ if (strncmp(key, "limiter|", prefix_len))
+ return;
+
+ delimiter_pos = strchr(key + prefix_len + 1, '|');
+ if (!delimiter_pos || (delimiter_pos + 1 == key + strlen(key)))
+ return;
+
+ snprintf(limiter_tag, delimiter_pos - (key + prefix_len) + 1, "%s", key + prefix_len);
+
+ if (!strcmp(value, "allow"))
+ limit = __LOG_LIMITER_LIMIT_MAX + 1;
+ else if (!strcmp(value, "deny"))
+ limit = 0;
+ else
+ limit = atoi(value);
+
+ __log_limiter_add_rule(limiter_tag, *(delimiter_pos + 1), limit);
+}
+// LCOV_EXCL_STOP
+
+int __configure_limiter(struct log_config *config, int default_limiter)
+{
+ assert(config);
+
+ int enabled = log_config_get_int(config, "limiter", default_limiter);
+ if (!enabled)
+ return 0;
+
+ log_config_foreach(config, __config_iteration, NULL); // LCOV_EXCL_LINE
+
+ return (__log_limiter_initialize() == 0); // LCOV_EXCL_LINE
+}