4 * LTTng context utilities.
6 * Copyright 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <common/error.h>
26 #include <common/macros.h>
29 int parse_application_context(const char *str
, char **out_provider_name
,
32 const char app_ctx_prefix
[] = "$app.";
33 char *provider_name
= NULL
, *ctx_name
= NULL
;
34 size_t i
, len
, colon_pos
= 0, provider_name_len
, ctx_name_len
;
36 if (!str
|| !out_provider_name
|| !out_ctx_name
) {
41 if (len
<= sizeof(app_ctx_prefix
) - 1) {
45 /* String starts with $app. */
46 if (strncmp(str
, app_ctx_prefix
, sizeof(app_ctx_prefix
) - 1)) {
50 /* Validate that the ':' separator is present. */
51 for (i
= sizeof(app_ctx_prefix
); i
< len
; i
++) {
52 const char c
= str
[i
];
61 * No colon found or no ctx name ("$app.provider:") or no provider name
62 * given ("$app.:..."), which is invalid.
64 if (!colon_pos
|| colon_pos
== len
||
65 colon_pos
== sizeof(app_ctx_prefix
)) {
69 provider_name_len
= colon_pos
- sizeof(app_ctx_prefix
) + 2;
70 provider_name
= zmalloc(provider_name_len
);
72 PERROR("malloc provider_name");
75 strncpy(provider_name
, str
+ sizeof(app_ctx_prefix
) - 1,
76 provider_name_len
- 1);
78 ctx_name_len
= len
- colon_pos
;
79 ctx_name
= zmalloc(ctx_name_len
);
81 PERROR("malloc ctx_name");
84 strncpy(ctx_name
, str
+ colon_pos
+ 1, ctx_name_len
- 1);
86 *out_provider_name
= provider_name
;
87 *out_ctx_name
= ctx_name
;
This page took 0.033394 seconds and 5 git commands to generate.