libdlog: move limiter functions to loglimiter.c 42/184742/7
authorMichal Bloch <m.bloch@samsung.com>
Wed, 1 Aug 2018 16:55:58 +0000 (18:55 +0200)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 21 Aug 2018 02:49:05 +0000 (02:49 +0000)
Change-Id: I6ce8da53239257e1491b4cc184352f2bc596c0e2
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
include/loglimiter.h
src/libdlog/log.c
src/libdlog/loglimiter.c

index 1b0df75..056fd09 100644 (file)
 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
 }
index 71403af..678a877 100644 (file)
@@ -67,57 +67,6 @@ static int __write_to_log_null(log_id_t log_id, log_priority prio, const char *t
        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);
@@ -143,7 +92,7 @@ static void __configure_parameters(struct log_config *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);
 }
 
 /**
index 115af3a..af0f8dc 100644 (file)
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 
+#include <assert.h>
 #include <stddef.h>
 #include <limits.h>
 #include <sys/types.h>
@@ -383,3 +384,54 @@ int __log_limiter_pass_log(const char* tag, int prio)
        }
 }
 // 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
+}