Rename C++ header files to .hpp
[lttng-tools.git] / src / common / config / session-config.cpp
index 4d57d581a8548674b34cc1093dec81690110fba9..dfbddf2913d25550c7058ca96b9d7e54757501e9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * SPDX-License-Identifier: GPL-2.0-only
+ * SPDX-License-Identifier: LGPL-2.1-only
  *
  */
 
 #include <sys/stat.h>
 #include <stdbool.h>
 
-#include <common/defaults.h>
-#include <common/error.h>
-#include <common/macros.h>
-#include <common/utils.h>
-#include <common/dynamic-buffer.h>
-#include <common/compat/getenv.h>
+#include <common/defaults.hpp>
+#include <common/error.hpp>
+#include <common/macros.hpp>
+#include <common/utils.hpp>
+#include <common/dynamic-buffer.hpp>
+#include <common/compat/getenv.hpp>
 #include <lttng/lttng-error.h>
 #include <libxml/parser.h>
 #include <libxml/valid.h>
 #include <lttng/rotation.h>
 #include <lttng/userspace-probe.h>
 
-#include "session-config.h"
-#include "config-internal.h"
+#include "session-config.hpp"
+#include "config-internal.hpp"
 
 #define CONFIG_USERSPACE_PROBE_LOOKUP_METHOD_NAME_MAX_LEN 7
 
-struct handler_filter_args {
-       const char* section;
-       config_entry_handler_cb handler;
-       void *user_data;
-};
-
 struct session_config_validation_ctx {
        xmlSchemaParserCtxtPtr parser_ctx;
        xmlSchemaPtr schema;
@@ -52,12 +46,6 @@ struct session_config_validation_ctx {
 };
 
 const char * const config_element_all = "all";
-LTTNG_EXPORT const char *config_str_yes = "yes";
-LTTNG_EXPORT const char *config_str_true = "true";
-LTTNG_EXPORT const char *config_str_on = "on";
-LTTNG_EXPORT const char *config_str_no = "no";
-LTTNG_EXPORT const char *config_str_false = "false";
-LTTNG_EXPORT const char *config_str_off = "off";
 LTTNG_EXPORT const char *config_xml_encoding = "UTF-8";
 LTTNG_EXPORT size_t config_xml_encoding_bytes_per_char = 2;    /* Size of the encoding's largest character */
 LTTNG_EXPORT const char *config_xml_indent_string = "\t";
@@ -252,151 +240,6 @@ struct consumer_output {
        char *data_uri;
 };
 
-static int config_entry_handler_filter(struct handler_filter_args *args,
-               const char *section, const char *name, const char *value)
-{
-       int ret = 0;
-       struct config_entry entry = { section, name, value };
-
-       LTTNG_ASSERT(args);
-
-       if (!section || !name || !value) {
-               ret = -EIO;
-               goto end;
-       }
-
-       if (args->section) {
-               if (strcmp(args->section, section)) {
-                       goto end;
-               }
-       }
-
-       ret = args->handler(&entry, args->user_data);
-end:
-       return ret;
-}
-
-int config_get_section_entries(const char *override_path, const char *section,
-               config_entry_handler_cb handler, void *user_data)
-{
-       int ret = 0;
-       const char *path;
-       FILE *config_file = NULL;
-       struct handler_filter_args filter = { section, handler, user_data };
-
-       /* First, try system-wide conf. file. */
-       path = DEFAULT_DAEMON_SYSTEM_CONFIGPATH;
-
-       config_file = fopen(path, "r");
-       if (config_file) {
-               DBG("Loading daemon conf file at %s", path);
-               /*
-                * Return value is not very important here since error or not, we
-                * continue and try the next possible conf. file.
-                */
-               (void) ini_parse_file(config_file,
-                               (ini_entry_handler) config_entry_handler_filter,
-                               (void *) &filter);
-               fclose(config_file);
-       }
-
-       /* Second is the user local configuration. */
-       path = utils_get_home_dir();
-       if (path) {
-               char fullpath[PATH_MAX];
-
-               ret = snprintf(fullpath, sizeof(fullpath),
-                               DEFAULT_DAEMON_HOME_CONFIGPATH, path);
-               if (ret < 0) {
-                       PERROR("snprintf user conf. path");
-                       goto error;
-               }
-
-               config_file = fopen(fullpath, "r");
-               if (config_file) {
-                       DBG("Loading daemon user conf file at %s", path);
-                       /*
-                        * Return value is not very important here since error or not, we
-                        * continue and try the next possible conf. file.
-                        */
-                       (void) ini_parse_file(config_file,
-                                       (ini_entry_handler) config_entry_handler_filter,
-                                       (void *) &filter);
-                       fclose(config_file);
-               }
-       }
-
-       /* Final path is the one that the user might have provided. */
-       if (override_path) {
-               config_file = fopen(override_path, "r");
-               if (config_file) {
-                       DBG("Loading daemon command line conf file at %s", override_path);
-                       (void) ini_parse_file(config_file,
-                                       (ini_entry_handler) config_entry_handler_filter,
-                                       (void *) &filter);
-                       fclose(config_file);
-               } else {
-                       ERR("Failed to open daemon configuration file at %s",
-                               override_path);
-                       ret = -ENOENT;
-                       goto error;
-               }
-       }
-
-       /* Everything went well. */
-       ret = 0;
-
-error:
-       return ret;
-}
-
-int config_parse_value(const char *value)
-{
-       int i, ret = 0;
-       char *endptr, *lower_str;
-       size_t len;
-       unsigned long v;
-
-       len = strlen(value);
-       if (!len) {
-               ret = -1;
-               goto end;
-       }
-
-       v = strtoul(value, &endptr, 10);
-       if (endptr != value) {
-               ret = v;
-               goto end;
-       }
-
-       lower_str = (char *) zmalloc(len + 1);
-       if (!lower_str) {
-               PERROR("zmalloc");
-               ret = -errno;
-               goto end;
-       }
-
-       for (i = 0; i < len; i++) {
-               lower_str[i] = tolower(value[i]);
-       }
-
-       if (!strcmp(lower_str, config_str_yes) ||
-               !strcmp(lower_str, config_str_true) ||
-               !strcmp(lower_str, config_str_on)) {
-               ret = 1;
-       } else if (!strcmp(lower_str, config_str_no) ||
-               !strcmp(lower_str, config_str_false) ||
-               !strcmp(lower_str, config_str_off)) {
-               ret = 0;
-       } else {
-               ret = -1;
-       }
-
-       free(lower_str);
-end:
-       return ret;
-}
-
 /*
  * Returns a xmlChar string which must be released using xmlFree().
  */
@@ -685,8 +528,8 @@ end:
        return ret >= 0 ? 0 : ret;
 }
 
-static
-void xml_error_handler(void *ctx, const char *format, ...)
+static ATTR_FORMAT_PRINTF(2, 3)
+void xml_error_handler(void *ctx __attribute__((unused)), const char *format, ...)
 {
        char *errMsg;
        va_list args;
@@ -1360,7 +1203,7 @@ int create_snapshot_session(const char *session_name, xmlNodePtr output_node,
                        xmlNextElementSibling(snapshot_output_node)) {
                char *name = NULL;
                uint64_t max_size = UINT64_MAX;
-               struct consumer_output output = { 0 };
+               struct consumer_output output = {};
                struct lttng_snapshot_output *snapshot_output = NULL;
                const char *control_uri = NULL;
                const char *data_uri = NULL;
@@ -1486,7 +1329,7 @@ int create_session(const char *name,
        const struct config_load_session_override_attr *overrides)
 {
        int ret;
-       struct consumer_output output = { 0 };
+       struct consumer_output output = {};
        xmlNodePtr consumer_output_node;
        const char *control_uri = NULL;
        const char *data_uri = NULL;
@@ -4016,7 +3859,7 @@ int config_load_session(const char *path, const char *session_name,
        int ret;
        bool session_loaded = false;
        const char *path_ptr = NULL;
-       struct session_config_validation_ctx validation_ctx = { 0 };
+       struct session_config_validation_ctx validation_ctx = {};
 
        ret = init_session_config_validation_ctx(&validation_ctx);
        if (ret) {
This page took 0.026545 seconds and 4 git commands to generate.