Coverage Report

Created: 2026-01-09 06:43

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
WINPR_ATTR_MALLOC(free, 1)
31
static char* freerdp_settings_get_legacy_config_path(const char* filename)
32
0
{
33
0
  char product[sizeof(FREERDP_PRODUCT_STRING)] = { 0 };
34
35
0
  for (size_t i = 0; i < sizeof(product); i++)
36
0
    product[i] = (char)tolower(FREERDP_PRODUCT_STRING[i]);
37
38
0
  char* path = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, product);
39
40
0
  if (!path)
41
0
    return NULL;
42
43
0
  char* filepath = GetCombinedPath(path, filename);
44
0
  free(path);
45
0
  return filepath;
46
0
}
47
#endif
48
49
char* freerdp_GetConfigFilePath(BOOL system, const char* filename)
50
0
{
51
0
  eKnownPathTypes id = system ? KNOWN_PATH_SYSTEM_CONFIG_HOME : KNOWN_PATH_XDG_CONFIG_HOME;
52
53
#if defined(FREERDP_USE_VENDOR_PRODUCT_CONFIG_DIR)
54
  char* vendor = GetKnownSubPath(id, FREERDP_VENDOR_STRING);
55
#else
56
0
#if !defined(WITH_FULL_CONFIG_PATH)
57
0
  if (!system && (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING) == 0))
58
0
    return freerdp_settings_get_legacy_config_path(filename);
59
0
#endif
60
61
0
  char* vendor = GetKnownPath(id);
62
0
#endif
63
0
  if (!vendor)
64
0
    return NULL;
65
66
#if defined(WITH_RESOURCE_VERSIONING)
67
  const char* verstr = FREERDP_PRODUCT_STRING FREERDP_API_VERSION;
68
#else
69
0
  const char* verstr = FREERDP_PRODUCT_STRING;
70
0
#endif
71
72
0
  char* base = GetCombinedPath(vendor, verstr);
73
0
  free(vendor);
74
75
0
  if (!base)
76
0
    return NULL;
77
78
0
  if (!filename)
79
0
    return base;
80
81
0
  char* path = GetCombinedPath(base, filename);
82
0
  free(base);
83
0
  return path;
84
0
}
85
86
WINPR_JSON* freerdp_GetJSONConfigFile(BOOL system, const char* filename)
87
0
{
88
0
  char* path = freerdp_GetConfigFilePath(system, filename);
89
0
  if (!path)
90
0
    return NULL;
91
92
0
  WINPR_JSON* json = WINPR_JSON_ParseFromFile(path);
93
0
  free(path);
94
0
  return json;
95
0
}