2 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
10 #include <common/error.hpp>
11 #include <common/macros.hpp>
16 int parse_application_context(const char *str
, char **out_provider_name
, char **out_ctx_name
)
18 const char app_ctx_prefix
[] = "$app.";
19 char *provider_name
= nullptr, *ctx_name
= nullptr;
20 size_t i
, len
, colon_pos
= 0, provider_name_len
, ctx_name_len
;
22 if (!str
|| !out_provider_name
|| !out_ctx_name
) {
27 if (len
<= sizeof(app_ctx_prefix
) - 1) {
31 /* String starts with $app. */
32 if (strncmp(str
, app_ctx_prefix
, sizeof(app_ctx_prefix
) - 1) != 0) {
36 /* Validate that the ':' separator is present. */
37 for (i
= sizeof(app_ctx_prefix
); i
< len
; i
++) {
38 const char c
= str
[i
];
47 * No colon found or no ctx name ("$app.provider:") or no provider name
48 * given ("$app.:..."), which is invalid.
50 if (!colon_pos
|| colon_pos
== len
|| colon_pos
== sizeof(app_ctx_prefix
)) {
54 provider_name_len
= colon_pos
- sizeof(app_ctx_prefix
) + 2;
55 provider_name
= calloc
<char>(provider_name_len
);
57 PERROR("malloc provider_name");
60 strncpy(provider_name
, str
+ sizeof(app_ctx_prefix
) - 1, provider_name_len
- 1);
62 ctx_name_len
= len
- colon_pos
;
63 ctx_name
= calloc
<char>(ctx_name_len
);
65 PERROR("malloc ctx_name");
68 strncpy(ctx_name
, str
+ colon_pos
+ 1, ctx_name_len
- 1);
70 *out_provider_name
= provider_name
;
71 *out_ctx_name
= ctx_name
;
This page took 0.030043 seconds and 4 git commands to generate.