Debian Codegraph @

src/DS/public/ds_sds_session.h

raw symbols SCIP
1 /*
2 * Copyright 2014 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Author:
20 * Šimon Lukašík
21 */
22 #ifndef DS_SDS_SESSION_H
23 #define DS_SDS_SESSION_H
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include "oscap.h"
30 #include "oscap_source.h"
31 #include "scap_ds.h"
32 #include "oscap_download_cb.h"
33 #include "oscap_export.h"
34
35 /**
36 * The ds_sds_session is structure tight closely to oscap_source.
37 *
38 * The ds_sds_session represents opened DataStream collection file.
39 * It caches certain data to facilitate common queries and use cases
40 * of DataStream consumers. The ds_sds_session caches DataStream
41 * components in a form of oscap_source structure.
42 *
43 * The cache relates to selected XCCDF component and selected CPE
44 * dictionaries. When another XCCDF is selected, the cache needs to
45 * be invalidated. All cached oscap_sources are owned by ds_sds_session.
46 * The reset function will invalidate user pointers to them.
47 */
48 struct ds_sds_session;
49
50 /**
51 * Create new ds_sds_session from existing oscap_source. This assumes that
52 * the given oscap_source represents source DataStream. This function does
53 * not own the oscap_source, but it needs it for operation.
54 * @memberof ds_sds_session
55 * @param source The oscap_source representing a source datastream
56 * @returns newly created ds_sds_session structure
57 */
58 OSCAP_API struct ds_sds_session *ds_sds_session_new_from_source(struct oscap_source *source);
59
60 /**
61 * Get Source DataStream index
62 * @memberof ds_sds_session
63 * @param session Registry to query SDS index from
64 * @returns source DataStream owned by session
65 */
66 OSCAP_API struct ds_sds_index *ds_sds_session_get_sds_idx(struct ds_sds_session *session);
67
68 /**
69 * Dispose ds_sds_session structure.
70 * @param sds_session Registry to dispose
71 */
72 OSCAP_API void ds_sds_session_free(struct ds_sds_session *sds_session);
73
74 /**
75 * Select Checklist (XCCDF presumably) from DataStream collection. Parameters may be
76 * skipped (passing NULL) to let the ds_sds_session guess them.
77 * @memberof ds_sds_session
78 * @param session Source DataStream session to choose from
79 * @param datastream_id ID of DataStream within collection
80 * @param component_id ID of (XCCDF) checklist within datastream
81 * @param benchmark_id ID of Benchmark element within checklist
82 * @returns XCCDF checklist in form of oscap_source
83 */
84 OSCAP_API struct oscap_source *ds_sds_session_select_checklist(struct ds_sds_session *session, const char *datastream_id, const char *component_id, const char *benchmark_id);
85
86 /**
87 * Select XCCDF Tailoring from DataStream collection. The ds_sds_session_select_checklist
88 * needs to be called first. To determine what datastream should be used within collection.
89 * @memberof ds_sds_session
90 * @param session Source DataStream session to choose from
91 * @param component_id ID of tailoring file within checklist container
92 * @returns XCCdF tailoring in form of oscap_source
93 */
94 OSCAP_API struct oscap_source *ds_sds_session_select_tailoring(struct ds_sds_session *session, const char *component_id);
95
96 /**
97 * Set the ID of DataStream within collection to use. Note that
98 * ds_sds_session_select_checklist may set this automatically.
99 * @memberof ds_sds_session
100 * @param session Source DataStream session
101 * @param datastream_id DataStream ID to set
102 * @returns 0 on success
103 */
104 OSCAP_API int ds_sds_session_set_datastream_id(struct ds_sds_session *session, const char *datastream_id);
105
106 /**
107 * Return ID of currently selected DataStream within the DataStream collection.
108 * @memberof ds_sds_session
109 * @param session The Source DataStream sesssion
110 * @returns ID of selected datastream or NULL
111 */
112 OSCAP_API const char *ds_sds_session_get_datastream_id(const struct ds_sds_session *session);
113
114 /**
115 * Return ID of currently selected component representing XCCDF within the DataStream
116 * @memberof ds_sds_session
117 * @param session The Source DataStream session
118 * @returns ID of selected component or NULL
119 */
120 OSCAP_API const char *ds_sds_session_get_checklist_id(const struct ds_sds_session *session);
121
122 /**
123 * Return URI of currently selected component representing XCCDF within the DataStream
124 * @memberof ds_sds_session
125 * @param session The Source DataStream session
126 * @returns URI of selected component or NULL
127 */
128 OSCAP_API const char *ds_sds_session_get_checklist_uri(const struct ds_sds_session *session);
129
130 /**
131 * Get component from Source DataStream by its href. This assumes that the component
132 * has been already cached by the session. You can cache component or its dependencies
133 * by calling ds_sds_session_select_checklist or ds_sds_session_register_component_with_dependencies.
134 * Returned oscap_source is owned by ds_sds_session.
135 * @memberof ds_sds_session
136 * @param session The Source DataStream session
137 * @param href The href of the component. The href refers to either file name from the catalogue
138 * element or the target name provided previously by caller of upper mentioned functions.
139 * @returns oscap_source representing the component or NULL
140 */
141 OSCAP_API struct oscap_source *ds_sds_session_get_component_by_href(struct ds_sds_session *session, const char *href);
142
143 /**
144 * Check whether given component can be registered.
145 * @param session The Source DataStream session
146 * @param container_name The name of container like: "checks", "checklists", or "dictionaries".
147 * @param component_id Id of component within selected datastream or NULL
148 * @returns true if at least one matching component exists, false otherwise
149 * @see ds_sds_session_register_component_with_dependencies
150 */
151 OSCAP_API bool ds_sds_session_can_register_component(struct ds_sds_session *session, const char *container_name, const char *component_id);
152
153 /**
154 * Register component and its dependencies to internal cache. This functions extracts
155 * component from selected datastream within collection and all it dependencies.
156 * The components may be later queried by ds_sds_session_get_component_by_href.
157 * @memberof ds_sds_session
158 * @param session The Source DataStream session
159 * @param container_name The name of container like: "checks", "checklists", or "dictionaries".
160 * @param component_id Id of component within selected datastream or NULL
161 * @param target filename or NULL
162 * @returns 0 on success
163 */
164 OSCAP_API int ds_sds_session_register_component_with_dependencies(struct ds_sds_session *session, const char *container_name, const char *component_id, const char *target_filename);
165
166 /**
167 * Store cached component files to the disc.
168 * @memberof ds_sds_session
169 * @param session The Source DataStream session
170 * @returns 0 on success
171 */
172 OSCAP_API int ds_sds_session_dump_component_files(struct ds_sds_session *session);
173
174 /**
175 * Set target directory for the component files
176 * @memberof ds_sds_session
177 * @param session The Source DataStream session
178 * @param target_dir Path to the target storage dir
179 * @returns 0 on success
180 */
181 OSCAP_API int ds_sds_session_set_target_dir(struct ds_sds_session *session, const char *target_dir);
182
183 /**
184 * Reset session for further use.
185 * Rationale: The ds_sds_session is not versatile structure that would allow
186 * to work with all the DataStream content at once. The ds_sds_session structure
187 * remembers certain selections like: selected datastream within collection,
188 * selected checklist, and cached catalogue files. If caller wants to open different
189 * checklist with different catalogue, they need to reset the session.
190 * @memberof ds_sds_session
191 * @param session The Source DataStream session to reset
192 */
193 OSCAP_API void ds_sds_session_reset(struct ds_sds_session *session);
194
195 /**
196 * Set property of remote content.
197 * @memberof ds_sds_session
198 * @param session The source data stream session
199 * @param allowed Whether is download of remote resources allowed in this
200 * session (defaults to false)
201 * @param local_files Allows to use a locally downloaded copy of the remote
202 * resources. Contains a path to a directory where the files are stored
203 * (defaults to NULL).
204 * @param callback used to notify user about download proceeds. This might be
205 * safely set to NULL -- ignoring user notification.
206 */
207 OSCAP_API void ds_sds_session_configure_remote_resources(struct ds_sds_session *session, bool allowed, const char *local_files, download_progress_calllback_t callback);
208
209 #endif