| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright 2016 Philippe Proulx <pproulx@efficios.com> |
| 5 | * |
| 6 | * Babeltrace trace converter - parameter parsing |
| 7 | */ |
| 8 | |
| 9 | #include "common/common.h" |
| 10 | #include <babeltrace2/babeltrace.h> |
| 11 | #include <glib.h> |
| 12 | #include "babeltrace2-cfg.h" |
| 13 | |
| 14 | static |
| 15 | void destroy_gstring(void *data) |
| 16 | { |
| 17 | g_string_free(data, TRUE); |
| 18 | } |
| 19 | |
| 20 | /* |
| 21 | * Extracts the various paths from the string arg, delimited by ':' on UNIX, |
| 22 | * ';' on Windows, and appends them to the array value object `plugin_paths`. |
| 23 | */ |
| 24 | int bt_config_append_plugin_paths( |
| 25 | bt_value *plugin_paths, const char *arg) |
| 26 | { |
| 27 | int ret = 0; |
| 28 | GPtrArray *dirs = g_ptr_array_new_with_free_func(destroy_gstring); |
| 29 | size_t i; |
| 30 | |
| 31 | if (!dirs) { |
| 32 | ret = -1; |
| 33 | goto end; |
| 34 | } |
| 35 | |
| 36 | ret = bt_common_append_plugin_path_dirs(arg, dirs); |
| 37 | if (ret) { |
| 38 | ret = -1; |
| 39 | goto end; |
| 40 | } |
| 41 | |
| 42 | for (i = 0; i < dirs->len; i++) { |
| 43 | GString *dir = g_ptr_array_index(dirs, i); |
| 44 | |
| 45 | ret = bt_value_array_append_string_element( |
| 46 | plugin_paths, dir->str); |
| 47 | if (ret < 0) { |
| 48 | ret = -1; |
| 49 | goto end; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | end: |
| 54 | g_ptr_array_free(dirs, TRUE); |
| 55 | return ret; |
| 56 | } |
| 57 | |
| 58 | void bt_config_connection_destroy(struct bt_config_connection *connection) |
| 59 | { |
| 60 | if (!connection) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | if (connection->upstream_comp_name) { |
| 65 | g_string_free(connection->upstream_comp_name, TRUE); |
| 66 | } |
| 67 | |
| 68 | if (connection->downstream_comp_name) { |
| 69 | g_string_free(connection->downstream_comp_name, TRUE); |
| 70 | } |
| 71 | |
| 72 | if (connection->upstream_port_glob) { |
| 73 | g_string_free(connection->upstream_port_glob, TRUE); |
| 74 | } |
| 75 | |
| 76 | if (connection->downstream_port_glob) { |
| 77 | g_string_free(connection->downstream_port_glob, TRUE); |
| 78 | } |
| 79 | |
| 80 | if (connection->arg) { |
| 81 | g_string_free(connection->arg, TRUE); |
| 82 | } |
| 83 | |
| 84 | g_free(connection); |
| 85 | } |