Coverage Report

Created: 2025-07-01 06:46

/src/FreeRDP/libfreerdp/utils/helpers.c
Line
Count
Source (jump to first uncovered line)
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 <freerdp/utils/helpers.h>
22
23
#include <winpr/path.h>
24
#include <freerdp/version.h>
25
#include <freerdp/build-config.h>
26
27
#if defined(WITH_RESOURCE_VERSIONING)
28
#define STR(x) #x
29
#endif
30
31
char* freerdp_GetConfigFilePath(BOOL system, const char* filename)
32
0
{
33
0
  eKnownPathTypes id = system ? KNOWN_PATH_SYSTEM_CONFIG_HOME : KNOWN_PATH_XDG_CONFIG_HOME;
34
35
#if defined(FREERDP_USE_VENDOR_PRODUCT_CONFIG_DIR)
36
  char* vendor = GetKnownSubPath(id, FREERDP_VENDOR_STRING);
37
#else
38
0
  char* vendor = GetKnownPath(id);
39
0
#endif
40
0
  if (!vendor)
41
0
    return NULL;
42
43
#if defined(WITH_RESOURCE_VERSIONING)
44
  char* verstr = FREERDP_PRODUCT_STRING STR(FREERDP_VERSION_MAJOR);
45
#else
46
0
  char* verstr = FREERDP_PRODUCT_STRING;
47
0
#endif
48
49
0
  char* base = GetCombinedPath(vendor, verstr);
50
0
  free(vendor);
51
52
0
  if (!base)
53
0
    return NULL;
54
55
0
  if (!filename)
56
0
    return base;
57
58
0
  char* path = GetCombinedPath(base, filename);
59
0
  free(base);
60
0
  return path;
61
0
}
62
63
WINPR_JSON* freerdp_GetJSONConfigFile(BOOL system, const char* filename)
64
0
{
65
0
  char* path = freerdp_GetConfigFilePath(system, filename);
66
0
  if (!path)
67
0
    return NULL;
68
69
0
  WINPR_JSON* json = WINPR_JSON_ParseFromFile(path);
70
0
  free(path);
71
0
  return json;
72
0
}