xref: /freebsd/contrib/pkgconf/cli/spdxtool/util.h (revision 592efe252472a3385acf36b1f49ecf710a7f3d9c)
1 /*
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  *​ Copyright (c) 2025 The FreeBSD Foundation
5  *​
6  *​ Portions of this software were developed by
7  * Tuukka Pasanen <tuukka.pasanen@ilmi.fi> under sponsorship from
8  * the FreeBSD Foundation
9  */
10 
11 #ifndef CLI__SPDXTOOL__UTIL_H
12 #define CLI__SPDXTOOL__UTIL_H
13 
14 #include <libpkgconf/libpkgconf.h>
15 #include <time.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #define SPDXTOOL_SEPARATOR_COLON	0x80
22 
23 typedef struct spdxtool_core_agent_
24 {
25 	char *spdx_id;
26 	const char *type;
27 	char *creation_info;
28 	char *name;
29 } spdxtool_core_agent_t;
30 
31 typedef struct spdxtool_core_creation_info_
32 {
33 	char *id;
34 	const char *type;
35 	char *created;
36 	char *created_by;
37 	const char *created_using;
38 	char *spec_version;
39 } spdxtool_core_creation_info_t;
40 
41 typedef struct spdxtool_core_spdx_document
42 {
43 	const char *type;
44 	char *spdx_id;
45 	char *creation_info;
46 	char *agent;
47 	pkgconf_list_t licenses;
48 	pkgconf_list_t element;
49 	pkgconf_list_t rootElement;
50 	pkgconf_list_t relationships;
51 	pkgconf_list_t packages;
52 	pkgconf_list_t maintainers;
53 } spdxtool_core_spdx_document_t;
54 
55 typedef struct spdxtool_software_sbom_
56 {
57 	char *spdx_id;
58 	const char *type;
59 	char *creation_info;
60 	char *sbom_type;
61 	spdxtool_core_spdx_document_t *spdx_document;
62 	pkgconf_pkg_t *rootElement;
63 } spdxtool_software_sbom_t;
64 
65 typedef struct spdxtool_simplelicensing_license_expression_
66 {
67 	const char *type;
68 	char *spdx_id;
69 	char *license_expression;
70 } spdxtool_simplelicensing_license_expression_t;
71 
72 typedef struct spdxtool_core_relationship_
73 {
74 	const char *type;
75 	char *spdx_id;
76 	char *creation_info;
77 	char *from;
78 	pkgconf_list_t *to;
79 	char *relationship_type;
80 	char *scope;
81 } spdxtool_core_relationship_t;
82 
83 void
84 spdxtool_util_set_key(pkgconf_client_t *client, const char *key, const char *key_value, const char *key_default);
85 
86 void
87 spdxtool_util_set_uri_root(pkgconf_client_t *client, const char *uri_root);
88 
89 void
90 spdxtool_util_set_uri_separator_colon(pkgconf_client_t *client, bool sep);
91 
92 char
93 spdxtool_util_get_uri_separator(pkgconf_client_t *client);
94 
95 const char *
96 spdxtool_util_get_uri_root(pkgconf_client_t *client);
97 
98 void
99 spdxtool_util_set_spdx_version(pkgconf_client_t *client, const char *spdx_version);
100 
101 const char *
102 spdxtool_util_get_spdx_version(pkgconf_client_t *client);
103 
104 void
105 spdxtool_util_set_spdx_license(pkgconf_client_t *client, const char *spdx_license);
106 
107 char *
108 spdxtool_util_get_spdx_id_int(pkgconf_client_t *client, const char *part);
109 
110 char *
111 spdxtool_util_get_spdx_id_string(pkgconf_client_t *client, const char *part, const char *string_id);
112 
113 char *
114 spdxtool_util_get_iso8601_time(time_t *wanted_time);
115 
116 char *
117 spdxtool_util_get_current_iso8601_time(void);
118 
119 char *
120 spdxtool_util_string_correction(char *str);
121 
122 char *
123 spdxtool_util_tuple_lookup(pkgconf_client_t *client, pkgconf_list_t *vars, const char *key);
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif
130