Coverage Report

Created: 2025-10-10 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/libfreerdp/utils/helpers.c
Line
Count
Source
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * common helper utilities
4
 *
5
 * Copyright 2024 Armin Novak <anovak@thincast.com>
6
 * Copyright 2024 Thincast Technologies GmbH
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
#include <ctype.h>
22
23
#include <freerdp/utils/helpers.h>
24
25
#include <winpr/path.h>
26
#include <freerdp/version.h>
27
#include <freerdp/build-config.h>
28
29
#if !defined(WITH_FULL_CONFIG_PATH)
30
static char* freerdp_settings_get_legacy_config_path(void)
31
52.4k
{
32
52.4k
  char product[sizeof(FREERDP_PRODUCT_STRING)] = { 0 };
33
34
472k
  for (size_t i = 0; i < sizeof(product); i++)
35
419k
    product[i] = (char)tolower(FREERDP_PRODUCT_STRING[i]);
36
37
52.4k
  return GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, product);
38
52.4k
}
39
#endif
40
41
char* freerdp_GetConfigFilePath(BOOL system, const char* filename)
42
52.4k
{
43
52.4k
  eKnownPathTypes id = system ? KNOWN_PATH_SYSTEM_CONFIG_HOME : KNOWN_PATH_XDG_CONFIG_HOME;
44
45
#if defined(FREERDP_USE_VENDOR_PRODUCT_CONFIG_DIR)
46
  char* vendor = GetKnownSubPath(id, FREERDP_VENDOR_STRING);
47
#else
48
52.4k
#if !defined(WITH_FULL_CONFIG_PATH)
49
52.4k
  if (!system && (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING) == 0))
50
52.4k
    return freerdp_settings_get_legacy_config_path();
51
0
#endif
52
53
0
  char* vendor = GetKnownPath(id);
54
0
#endif
55
0
  if (!vendor)
56
0
    return NULL;
57
58
#if defined(WITH_RESOURCE_VERSIONING)
59
  const char* verstr = FREERDP_PRODUCT_STRING FREERDP_API_VERSION;
60
#else
61
0
  const char* verstr = FREERDP_PRODUCT_STRING;
62
0
#endif
63
64
0
  char* base = GetCombinedPath(vendor, verstr);
65
0
  free(vendor);
66
67
0
  if (!base)
68
0
    return NULL;
69
70
0
  if (!filename)
71
0
    return base;
72
73
0
  char* path = GetCombinedPath(base, filename);
74
0
  free(base);
75
0
  return path;
76
0
}
77
78
WINPR_JSON* freerdp_GetJSONConfigFile(BOOL system, const char* filename)
79
0
{
80
0
  char* path = freerdp_GetConfigFilePath(system, filename);
81
0
  if (!path)
82
0
    return NULL;
83
84
0
  WINPR_JSON* json = WINPR_JSON_ParseFromFile(path);
85
0
  free(path);
86
0
  return json;
87
0
}