Commit | Line | Data |
---|---|---|
1670bffd PP |
1 | #ifndef BABELTRACE_COMMON_INTERNAL_H |
2 | #define BABELTRACE_COMMON_INTERNAL_H | |
3 | ||
c55a9f58 | 4 | #include <stdbool.h> |
1670bffd PP |
5 | #include <babeltrace/babeltrace-internal.h> |
6 | ||
ad96d936 PP |
7 | #define BT_COMMON_COLOR_RESET "\033[0m" |
8 | #define BT_COMMON_COLOR_BOLD "\033[1m" | |
9 | #define BT_COMMON_COLOR_FG_DEFAULT "\033[39m" | |
10 | #define BT_COMMON_COLOR_FG_RED "\033[31m" | |
11 | #define BT_COMMON_COLOR_FG_GREEN "\033[32m" | |
12 | #define BT_COMMON_COLOR_FG_YELLOW "\033[33m" | |
13 | #define BT_COMMON_COLOR_FG_BLUE "\033[34m" | |
14 | #define BT_COMMON_COLOR_FG_MAGENTA "\033[35m" | |
15 | #define BT_COMMON_COLOR_FG_CYAN "\033[36m" | |
16 | #define BT_COMMON_COLOR_FG_LIGHT_GRAY "\033[37m" | |
17 | #define BT_COMMON_COLOR_BG_DEFAULT "\033[49m" | |
18 | #define BT_COMMON_COLOR_BG_RED "\033[41m" | |
19 | #define BT_COMMON_COLOR_BG_GREEN "\033[42m" | |
20 | #define BT_COMMON_COLOR_BG_YELLOW "\033[43m" | |
21 | #define BT_COMMON_COLOR_BG_BLUE "\033[44m" | |
22 | #define BT_COMMON_COLOR_BG_MAGENTA "\033[45m" | |
23 | #define BT_COMMON_COLOR_BG_CYAN "\033[46m" | |
24 | #define BT_COMMON_COLOR_BG_LIGHT_GRAY "\033[47m" | |
25 | ||
db0f160a PP |
26 | struct bt_common_lttng_live_url_parts { |
27 | GString *proto; | |
28 | GString *hostname; | |
29 | GString *target_hostname; | |
30 | GString *session_name; | |
31 | ||
32 | /* -1 means default port */ | |
33 | int port; | |
34 | }; | |
35 | ||
6eecdc5f PP |
36 | /* |
37 | * Checks if the current process has setuid or setgid access rights. | |
38 | * Returns `true` if so. | |
39 | */ | |
1670bffd PP |
40 | BT_HIDDEN |
41 | bool bt_common_is_setuid_setgid(void); | |
42 | ||
6eecdc5f PP |
43 | /* |
44 | * Returns the system-wide plugin path, e.g. | |
45 | * `/usr/lib/babeltrace/plugins`. Do not free the return value. | |
46 | */ | |
1670bffd PP |
47 | BT_HIDDEN |
48 | const char *bt_common_get_system_plugin_path(void); | |
49 | ||
6eecdc5f PP |
50 | /* |
51 | * Returns the user plugin path, e.g. | |
52 | * `/home/user/.local/lib/babeltrace/plugins`. You need to free the | |
53 | * return value. | |
54 | */ | |
1670bffd PP |
55 | BT_HIDDEN |
56 | char *bt_common_get_home_plugin_path(void); | |
57 | ||
6eecdc5f PP |
58 | /* |
59 | * Appends the list of directories in `paths` to the array `dirs`. | |
60 | * `paths` is a list of directories separated by `:`. Returns 0 on | |
61 | * success. | |
62 | */ | |
1670bffd PP |
63 | BT_HIDDEN |
64 | int bt_common_append_plugin_path_dirs(const char *paths, GPtrArray *dirs); | |
65 | ||
6eecdc5f PP |
66 | /* |
67 | * Returns `true` if terminal color codes are supported for this | |
68 | * process. | |
69 | */ | |
ad96d936 PP |
70 | BT_HIDDEN |
71 | bool bt_common_colors_supported(void); | |
72 | ||
290725f7 PP |
73 | BT_HIDDEN |
74 | const char *bt_common_color_reset(void); | |
75 | ||
76 | BT_HIDDEN | |
77 | const char *bt_common_color_bold(void); | |
78 | ||
79 | BT_HIDDEN | |
80 | const char *bt_common_color_fg_default(void); | |
81 | ||
82 | BT_HIDDEN | |
83 | const char *bt_common_color_fg_red(void); | |
84 | ||
85 | BT_HIDDEN | |
86 | const char *bt_common_color_fg_green(void); | |
87 | ||
88 | BT_HIDDEN | |
89 | const char *bt_common_color_fg_yellow(void); | |
90 | ||
91 | BT_HIDDEN | |
92 | const char *bt_common_color_fg_blue(void); | |
93 | ||
94 | BT_HIDDEN | |
95 | const char *bt_common_color_fg_magenta(void); | |
96 | ||
97 | BT_HIDDEN | |
98 | const char *bt_common_color_fg_cyan(void); | |
99 | ||
100 | BT_HIDDEN | |
101 | const char *bt_common_color_fg_light_gray(void); | |
102 | ||
103 | BT_HIDDEN | |
104 | const char *bt_common_color_bg_default(void); | |
105 | ||
106 | BT_HIDDEN | |
107 | const char *bt_common_color_bg_red(void); | |
108 | ||
109 | BT_HIDDEN | |
110 | const char *bt_common_color_bg_green(void); | |
111 | ||
112 | BT_HIDDEN | |
113 | const char *bt_common_color_bg_yellow(void); | |
114 | ||
115 | BT_HIDDEN | |
116 | const char *bt_common_color_bg_blue(void); | |
117 | ||
118 | BT_HIDDEN | |
119 | const char *bt_common_color_bg_magenta(void); | |
120 | ||
121 | BT_HIDDEN | |
122 | const char *bt_common_color_bg_cyan(void); | |
123 | ||
124 | BT_HIDDEN | |
125 | const char *bt_common_color_bg_light_gray(void); | |
126 | ||
6eecdc5f PP |
127 | /* |
128 | * Returns the substring from `input` to the first character found | |
129 | * in the list of characters `end_chars`, unescaping any character | |
130 | * found in `escapable_chars`, and sets `*end_pos` to the position of | |
131 | * the end (from `input`). The caller owns the returned GString. | |
132 | */ | |
db0f160a PP |
133 | BT_HIDDEN |
134 | GString *bt_common_string_until(const char *input, const char *escapable_chars, | |
135 | const char *end_chars, size_t *end_pos); | |
136 | ||
6eecdc5f PP |
137 | /* |
138 | * Returns the quoted version of `input` for a shell. If | |
139 | * `with_single_quotes` is `true`, prepends and appends the `'` prefix | |
140 | * and suffix to the returned string; otherwise the caller should | |
141 | * prepend and append them manually, although they are not always | |
142 | * required. The caller owns the returned GString. | |
143 | */ | |
db0f160a | 144 | BT_HIDDEN |
36b405c6 | 145 | GString *bt_common_shell_quote(const char *input, bool with_single_quotes); |
db0f160a | 146 | |
6eecdc5f PP |
147 | /* |
148 | * Returns `true` if `input` is a string made only of printable | |
149 | * characters. | |
150 | */ | |
db0f160a PP |
151 | BT_HIDDEN |
152 | bool bt_common_string_is_printable(const char *input); | |
153 | ||
6eecdc5f PP |
154 | /* |
155 | * Destroys the parts of an LTTng live URL as returned by | |
156 | * bt_common_parse_lttng_live_url(). | |
157 | */ | |
db0f160a PP |
158 | BT_HIDDEN |
159 | void bt_common_destroy_lttng_live_url_parts( | |
160 | struct bt_common_lttng_live_url_parts *parts); | |
161 | ||
6eecdc5f PP |
162 | /* |
163 | * Parses the LTTng live URL `url` and returns its different parts. | |
164 | * If there's an error, writes the error message into `*error_buf` | |
165 | * up to `error_buf_size` bytes. You must destroy the returned value | |
166 | * with bt_common_destroy_lttng_live_url_parts(). | |
167 | */ | |
db0f160a PP |
168 | BT_HIDDEN |
169 | struct bt_common_lttng_live_url_parts bt_common_parse_lttng_live_url( | |
170 | const char *url, char *error_buf, size_t error_buf_size); | |
171 | ||
6eecdc5f PP |
172 | /* |
173 | * Normalizes (in place) a star globbing pattern to be used with | |
174 | * bt_common_star_glob_match(). This function always succeeds. | |
175 | */ | |
9009cc24 PP |
176 | BT_HIDDEN |
177 | void bt_common_normalize_star_glob_pattern(char *pattern); | |
178 | ||
6eecdc5f PP |
179 | /* |
180 | * Returns `true` if `candidate` (of size `candidate_len`) matches | |
181 | * the star globbing pattern `pattern` (of size `pattern_len`). | |
182 | */ | |
9009cc24 PP |
183 | BT_HIDDEN |
184 | bool bt_common_star_glob_match(const char *pattern, size_t pattern_len, | |
185 | const char *candidate, size_t candidate_len); | |
186 | ||
6eecdc5f PP |
187 | /* |
188 | * Normalizes the path `path`: | |
189 | * | |
190 | * * If it's a relative path, converts it to an absolute path using | |
191 | * `wd` as the working directory (or the current working directory | |
192 | * if `wd` is NULL). | |
193 | * * Removes consecutive and trailing slashes. | |
194 | * * Resolves `..` and `.` in the path (both in `path` and in `wd`). | |
195 | * * Does NOT resolve symbolic links. | |
196 | * | |
197 | * The caller owns the returned GString. | |
198 | */ | |
e49a18d1 PP |
199 | BT_HIDDEN |
200 | GString *bt_common_normalize_path(const char *path, const char *wd); | |
201 | ||
108e5a1e MJ |
202 | /* |
203 | * Return the system page size. | |
204 | */ | |
205 | BT_HIDDEN | |
206 | size_t bt_common_get_page_size(void); | |
207 | ||
1670bffd | 208 | #endif /* BABELTRACE_COMMON_INTERNAL_H */ |