VirtualBox

source: vbox/trunk/include/iprt/manifest.h@ 59567

Last change on this file since 59567 was 59567, checked in by vboxsync, 9 years ago

RTManifestSetAttr,RTManifestEntrySetAttr: Allow the attribute name to be NULL when there is a distinctive fType value given.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.9 KB
Line 
1/** @file
2 * IPRT - Manifest file handling.
3 */
4
5/*
6 * Copyright (C) 2009-2015 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_manifest_h
27#define ___iprt_manifest_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31
32RT_C_DECLS_BEGIN
33
34/** @defgroup grp_rt_manifest RTManifest - Manifest file creation and checking
35 * @ingroup grp_rt
36 * @{
37 */
38
39/** @name Manifest attribute types.
40 * The types can be ORed together to form a set.
41 * @{ */
42/** For use with other attributes. Representation unknown. */
43#define RTMANIFEST_ATTR_UNKNOWN 0
44/** The size of the content. Represented as a decimal number. */
45#define RTMANIFEST_ATTR_SIZE RT_BIT_32(0)
46/** The MD5 of the content. Represented as a hex string. */
47#define RTMANIFEST_ATTR_MD5 RT_BIT_32(1)
48/** The SHA-1 of the content. Represented as a hex string. */
49#define RTMANIFEST_ATTR_SHA1 RT_BIT_32(2)
50/** The SHA-256 of the content. Represented as a hex string. */
51#define RTMANIFEST_ATTR_SHA256 RT_BIT_32(3)
52/** The SHA-512 of the content. Represented as a hex string. */
53#define RTMANIFEST_ATTR_SHA512 RT_BIT_32(4)
54/** The end of the valid values. */
55#define RTMANIFEST_ATTR_END RT_BIT_32(5)
56/** Wildcard for use in queries. */
57#define RTMANIFEST_ATTR_ANY UINT32_C(0xffffffff)
58/** @} */
59
60
61/**
62 * Creates an empty manifest.
63 *
64 * @returns IPRT status code.
65 * @param fFlags Flags, MBZ.
66 * @param phManifest Where to return the handle to the manifest.
67 */
68RTDECL(int) RTManifestCreate(uint32_t fFlags, PRTMANIFEST phManifest);
69
70/**
71 * Retains a reference to the manifest handle.
72 *
73 * @returns The new reference count, UINT32_MAX if the handle is invalid.
74 * @param hManifest The handle to retain.
75 */
76RTDECL(uint32_t) RTManifestRetain(RTMANIFEST hManifest);
77
78/**
79 * Releases a reference to the manifest handle.
80 *
81 * @returns The new reference count, 0 if free. UINT32_MAX is returned if the
82 * handle is invalid.
83 * @param hManifest The handle to release.
84 * NIL is quietly ignored (returns 0).
85 */
86RTDECL(uint32_t) RTManifestRelease(RTMANIFEST hManifest);
87
88/**
89 * Creates a duplicate of the specified manifest.
90 *
91 * @returns IPRT status code
92 * @param hManifestSrc The manifest to clone.
93 * @param phManifestDst Where to store the handle to the duplicate.
94 */
95RTDECL(int) RTManifestDup(RTMANIFEST hManifestSrc, PRTMANIFEST phManifestDst);
96
97/**
98 * Compares two manifests for equality.
99 *
100 * @returns IPRT status code.
101 * @retval VINF_SUCCESS if equal.
102 * @retval VERR_NOT_EQUAL if not equal.
103 *
104 * @param hManifest1 The first manifest.
105 * @param hManifest2 The second manifest.
106 * @param papszIgnoreEntries Entries to ignore. Ends with a NULL entry.
107 * @param papszIgnoreAttrs Attributes to ignore. Ends with a NULL entry.
108 * @param fFlags A combination of RTMANIFEST_EQUALS_XXX values.
109 * @param pszError Where to store the name of the mismatching
110 * entry, or as much of the name as there is room
111 * for. This is always set. Optional.
112 * @param cbError The size of the buffer pointed to by @a
113 * pszError.
114 */
115RTDECL(int) RTManifestEqualsEx(RTMANIFEST hManifest1, RTMANIFEST hManifest2, const char * const *papszIgnoreEntries,
116 const char * const *papszIgnoreAttrs, uint32_t fFlags, char *pszError, size_t cbError);
117
118/** @defgroup RTMANIFEST_EQUALS_XXX RTManifestEqualsEx flags
119 * @{ */
120/** Ignore missing attributes if there is one or more to compare. */
121#define RTMANIFEST_EQUALS_IGN_MISSING_ATTRS RT_BIT_32(0)
122/** Ignore attributes missing in the 1st manifest.
123 * @todo implement this */
124#define RTMANIFEST_EQUALS_IGN_MISSING_ATTRS_1ST RT_BIT_32(1)
125/** Mask of valid flags. */
126#define RTMANIFEST_EQUALS_VALID_MASK UINT32_C(0x00000003)
127/** @} */
128
129/**
130 * Compares two manifests for equality.
131 *
132 * @returns IPRT status code.
133 * @retval VINF_SUCCESS if equal.
134 * @retval VERR_NOT_EQUAL if not equal.
135 *
136 * @param hManifest1 The first manifest.
137 * @param hManifest2 The second manifest.
138 */
139RTDECL(int) RTManifestEquals(RTMANIFEST hManifest1, RTMANIFEST hManifest2);
140
141/**
142 * Sets a manifest attribute.
143 *
144 * @returns IPRT status code.
145 * @param hManifest The manifest handle.
146 * @param pszAttr The attribute name, if NULL it will be termined from @a
147 * fType gives it. If this already exists, its value will
148 * be replaced.
149 * @param pszValue The value string.
150 * @param fType The attribute type. If not know, pass
151 * RTMANIFEST_ATTR_UNKNOWN with a valid attribute
152 * name string (@a pszAttr).
153 */
154RTDECL(int) RTManifestSetAttr(RTMANIFEST hManifest, const char *pszAttr, const char *pszValue, uint32_t fType);
155
156/**
157 * Unsets (removes) a manifest attribute if it exists.
158 *
159 * @returns IPRT status code.
160 * @retval VWRN_NOT_FOUND if not found.
161 *
162 * @param hManifest The manifest handle.
163 * @param pszAttr The attribute name.
164 */
165RTDECL(int) RTManifestUnsetAttr(RTMANIFEST hManifest, const char *pszAttr);
166
167/**
168 * Query a manifest attribute.
169 *
170 * @returns IPRT status code.
171 * @retval VERR_BUFFER_OVERFLOW if the value buffer is too small. The @a
172 * pszValue buffer will not be modified.
173 * @retval VERR_MANIFEST_ATTR_NOT_FOUND
174 * @retval VERR_MANIFEST_ATTR_TYPE_NOT_FOUND
175 * @retval VERR_MANIFEST_ATTR_TYPE_MISMATCH
176 *
177 * @param hManifest The manifest handle.
178 * @param pszAttr The attribute name. If NULL, it will be
179 * selected by @a fType alone.
180 * @param fType The attribute types the entry should match. Pass
181 * Pass RTMANIFEST_ATTR_ANY match any. If more
182 * than one is given, the first matching one is
183 * returned.
184 * @param pszValue Where to return value.
185 * @param cbValue The size of the buffer @a pszValue points to.
186 * @param pfType Where to return the attribute type value.
187 */
188RTDECL(int) RTManifestQueryAttr(RTMANIFEST hManifest, const char *pszAttr, uint32_t fType,
189 char *pszValue, size_t cbValue, uint32_t *pfType);
190
191/**
192 * Sets an attribute of a manifest entry.
193 *
194 * @returns IPRT status code.
195 * @param hManifest The manifest handle.
196 * @param pszEntry The entry name. This will automatically be
197 * added if there was no previous call to
198 * RTManifestEntryAdd for this name. See
199 * RTManifestEntryAdd for the entry name rules.
200 * @param pszAttr The attribute name, if NULL it will be termined from @a
201 * fType gives it. If this already exists, its value will
202 * be replaced.
203 * @param pszValue The value string.
204 * @param fType The attribute type. If not know, pass
205 * RTMANIFEST_ATTR_UNKNOWN with a valid attribute
206 * name string (@a pszAttr).
207 */
208RTDECL(int) RTManifestEntrySetAttr(RTMANIFEST hManifest, const char *pszEntry, const char *pszAttr,
209 const char *pszValue, uint32_t fType);
210
211/**
212 * Unsets (removes) an attribute of a manifest entry if they both exist.
213 *
214 * @returns IPRT status code.
215 * @retval VWRN_NOT_FOUND if not found.
216 *
217 * @param hManifest The manifest handle.
218 * @param pszEntry The entry name.
219 * @param pszAttr The attribute name.
220 */
221RTDECL(int) RTManifestEntryUnsetAttr(RTMANIFEST hManifest, const char *pszEntry, const char *pszAttr);
222
223/**
224 * Query a manifest entry attribute.
225 *
226 * @returns IPRT status code.
227 * @retval VERR_BUFFER_OVERFLOW if the value buffer is too small. The @a
228 * pszValue buffer will not be modified.
229 * @retval VERR_NOT_FOUND if the entry was not found.
230 * @retval VERR_MANIFEST_ATTR_NOT_FOUND
231 * @retval VERR_MANIFEST_ATTR_TYPE_NOT_FOUND
232 * @retval VERR_MANIFEST_ATTR_TYPE_MISMATCH
233 *
234 * @param hManifest The manifest handle.
235 * @param pszEntry The entry name.
236 * @param pszAttr The attribute name. If NULL, it will be
237 * selected by @a fType alone.
238 * @param fType The attribute types the entry should match. Pass
239 * Pass RTMANIFEST_ATTR_ANY match any. If more
240 * than one is given, the first matching one is
241 * returned.
242 * @param pszValue Where to return value.
243 * @param cbValue The size of the buffer @a pszValue points to.
244 * @param pfType Where to return the attribute type value.
245 */
246RTDECL(int) RTManifestEntryQueryAttr(RTMANIFEST hManifest, const char *pszEntry, const char *pszAttr, uint32_t fType,
247 char *pszValue, size_t cbValue, uint32_t *pfType);
248
249/**
250 * Adds a new entry to a manifest.
251 *
252 * The entry name rules:
253 * - The entry name can contain any character defined by unicode, except
254 * control characters, ':', '(' and ')'. The exceptions are mainly there
255 * because of uncertainty around how various formats handles these.
256 * - It is considered case sensitive.
257 * - Forward (unix) and backward (dos) slashes are considered path
258 * separators and converted to forward slashes.
259 *
260 * @returns IPRT status code.
261 * @retval VWRN_ALREADY_EXISTS if the entry already exists.
262 *
263 * @param hManifest The manifest handle.
264 * @param pszEntry The entry name (UTF-8).
265 *
266 * @remarks Some manifest formats will not be able to store an entry without
267 * any attributes. So, this is just here in case it comes in handy
268 * when dealing with formats which can.
269 */
270RTDECL(int) RTManifestEntryAdd(RTMANIFEST hManifest, const char *pszEntry);
271
272/**
273 * Removes an entry.
274 *
275 * @returns IPRT status code.
276 * @param hManifest The manifest handle.
277 * @param pszEntry The entry name.
278 */
279RTDECL(int) RTManifestEntryRemove(RTMANIFEST hManifest, const char *pszEntry);
280
281/**
282 * Add an entry for an I/O stream using a passthru stream.
283 *
284 * The passthru I/O stream will hash all the data read from or written to the
285 * stream and automatically add an entry to the manifest with the desired
286 * attributes when it is released. Alternatively one can call
287 * RTManifestPtIosAddEntryNow() to have more control over exactly when this
288 * action is performed and which status it yields.
289 *
290 * @returns IPRT status code.
291 * @param hManifest The manifest to add the entry to.
292 * @param hVfsIos The I/O stream to pass thru to/from.
293 * @param pszEntry The entry name.
294 * @param fAttrs The attributes to create for this stream.
295 * @param fReadOrWrite Whether it's a read or write I/O stream.
296 * @param phVfsIosPassthru Where to return the new handle.
297 */
298RTDECL(int) RTManifestEntryAddPassthruIoStream(RTMANIFEST hManifest, RTVFSIOSTREAM hVfsIos, const char *pszEntry,
299 uint32_t fAttrs, bool fReadOrWrite, PRTVFSIOSTREAM phVfsIosPassthru);
300
301/**
302 * Adds the entry to the manifest right now.
303 *
304 * @returns IPRT status code.
305 * @param hVfsPtIos The manifest passthru I/O stream returned by
306 * RTManifestEntryAddPassthruIoStream().
307 */
308RTDECL(int) RTManifestPtIosAddEntryNow(RTVFSIOSTREAM hVfsPtIos);
309
310/**
311 * Adds an entry for a file with the specified set of attributes.
312 *
313 * @returns IPRT status code.
314 *
315 * @param hManifest The manifest handle.
316 * @param hVfsIos The I/O stream handle of the entry. This will
317 * be processed to its end on successful return.
318 * (Must be positioned at the start to get
319 * the expected results.)
320 * @param pszEntry The entry name.
321 * @param fAttrs The attributes to create for this stream. See
322 * RTMANIFEST_ATTR_XXX.
323 */
324RTDECL(int) RTManifestEntryAddIoStream(RTMANIFEST hManifest, RTVFSIOSTREAM hVfsIos, const char *pszEntry, uint32_t fAttrs);
325
326/**
327 * Checks if there is a manifest entry by the given name.
328 *
329 * @returns true if there is, false if not or if the handle is invalid.
330 * @param hManifest The manifest handle.
331 * @param pszEntry The entry name.
332 */
333RTDECL(bool) RTManifestEntryExists(RTMANIFEST hManifest, const char *pszEntry);
334
335/**
336 * Reads in a "standard" manifest.
337 *
338 * This reads the format used by OVF, the distinfo in FreeBSD ports, and
339 * others.
340 *
341 * @returns IPRT status code.
342 * @param hManifest The handle to the manifest where to add the
343 * manifest that's read in.
344 * @param hVfsIos The I/O stream to read the manifest from.
345 */
346RTDECL(int) RTManifestReadStandard(RTMANIFEST hManifest, RTVFSIOSTREAM hVfsIos);
347
348/**
349 * Reads in a "standard" manifest.
350 *
351 * This reads the format used by OVF, the distinfo in FreeBSD ports, and
352 * others.
353 *
354 * @returns IPRT status code.
355 * @param hManifest The handle to the manifest where to add the
356 * manifest that's read in.
357 * @param hVfsIos The I/O stream to read the manifest from.
358 * @param pszErr Where to return extended error info on failure.
359 * Optional.
360 * @param cbErr The size of the buffer @a pszErr points to.
361 */
362RTDECL(int) RTManifestReadStandardEx(RTMANIFEST hManifest, RTVFSIOSTREAM hVfsIos, char *pszErr, size_t cbErr);
363
364/**
365 * Reads in a "standard" manifest from the specified file.
366 *
367 * This reads the format used by OVF, the distinfo in FreeBSD ports, and
368 * others.
369 *
370 * @returns IPRT status code.
371 * @param hManifest The handle to the manifest where to add the
372 * manifest that's read in.
373 * @param pszFilename The name of the file to read in.
374 */
375RTDECL(int) RTManifestReadStandardFromFile(RTMANIFEST hManifest, const char *pszFilename);
376
377/**
378 * Writes a "standard" manifest.
379 *
380 * This writes the format used by OVF, the distinfo in FreeBSD ports, and
381 * others.
382 *
383 * @returns IPRT status code.
384 * @param hManifest The handle to the manifest to write.
385 * @param hVfsIos The I/O stream to read the manifest from.
386 */
387RTDECL(int) RTManifestWriteStandard(RTMANIFEST hManifest, RTVFSIOSTREAM hVfsIos);
388
389/**
390 * Writes a "standard" manifest to the specified file.
391 *
392 * @returns IPRT status code.
393 * @param hManifest The handle to the manifest to write.
394 * @param pszFilename The name of the file.
395 */
396RTDECL(int) RTManifestWriteStandardToFile(RTMANIFEST hManifest, const char *pszFilename);
397
398
399
400
401
402/**
403 * Input structure for RTManifestVerify() which contains the filename & the
404 * SHA1/SHA256 digest.
405 */
406typedef struct RTMANIFESTTEST
407{
408 /** The filename. */
409 const char *pszTestFile;
410 /** The SHA1/SHA256 digest of the file. */
411 const char *pszTestDigest;
412} RTMANIFESTTEST;
413/** Pointer to the input structure. */
414typedef RTMANIFESTTEST* PRTMANIFESTTEST;
415
416
417/**
418 * Verify the given SHA1 digests against the entries in the manifest file.
419 *
420 * Please note that not only the various digest have to match, but the
421 * filenames as well. If there are more or even less files listed in the
422 * manifest file than provided by paTests, VERR_MANIFEST_FILE_MISMATCH will be
423 * returned.
424 *
425 * @returns iprt status code.
426 *
427 * @param pszManifestFile Filename of the manifest file to verify.
428 * @param paTests Array of files & SHA1 sums.
429 * @param cTests Number of entries in paTests.
430 * @param piFailed A index to paTests in the
431 * VERR_MANIFEST_DIGEST_MISMATCH error case
432 * (optional).
433 * @deprecated Use the RTMANIFEST based API instead.
434 */
435RTR3DECL(int) RTManifestVerify(const char *pszManifestFile, PRTMANIFESTTEST paTests, size_t cTests, size_t *piFailed);
436
437/**
438 * This is analogous to function RTManifestVerify(), but calculates the SHA1
439 * sums of the given files itself.
440 *
441 * @returns iprt status code.
442 *
443 * @param pszManifestFile Filename of the manifest file to verify.
444 * @param papszFiles Array of files to check SHA1 sums.
445 * @param cFiles Number of entries in papszFiles.
446 * @param piFailed A index to papszFiles in the
447 * VERR_MANIFEST_DIGEST_MISMATCH error case
448 * (optional).
449 * @param pfnProgressCallback optional callback for the progress indication
450 * @param pvUser user defined pointer for the callback
451 * @deprecated Use the RTMANIFEST based API instead.
452 */
453RTR3DECL(int) RTManifestVerifyFiles(const char *pszManifestFile, const char * const *papszFiles, size_t cFiles, size_t *piFailed,
454 PFNRTPROGRESS pfnProgressCallback, void *pvUser);
455
456/**
457 * Creates a manifest file for a set of files. The manifest file contains SHA1
458 * sums of every provided file and could be used to verify the data integrity
459 * of them.
460 *
461 * @returns iprt status code.
462 *
463 * @param pszManifestFile Filename of the manifest file to create.
464 * @param enmDigestType The digest type (RTDIGESTTYPE_*)
465 * @param papszFiles Array of files to create SHA1 sums for.
466 * @param cFiles Number of entries in papszFiles.
467 * @param pfnProgressCallback optional callback for the progress indication
468 * @param pvUser user defined pointer for the callback
469 * @deprecated Use the RTMANIFEST based API instead.
470 */
471RTR3DECL(int) RTManifestWriteFiles(const char *pszManifestFile, RTDIGESTTYPE enmDigestType,
472 const char * const *papszFiles, size_t cFiles,
473 PFNRTPROGRESS pfnProgressCallback, void *pvUser);
474
475/**
476 * Queries the first digest type found in the given manifest.
477 *
478 * @returns iprt status code.
479 *
480 * @param pvBuf Pointer to memory buffer of the manifest file.
481 * @param cbSize Size of the memory buffer.
482 * @param penmDigestType Where to return the first digest type found in
483 * the manifest.
484 * @deprecated Use the RTMANIFEST based API instead.
485 */
486RTR3DECL(int) RTManifestVerifyDigestType(void const *pvBuf, size_t cbSize, RTDIGESTTYPE *penmDigestType);
487
488/**
489 * Verify the given SHA1 digests against the entries in the manifest file in
490 * memory.
491 *
492 * @returns iprt status code.
493 *
494 * @param pvBuf Pointer to memory buffer of the manifest file.
495 * @param cbSize Size of the memory buffer.
496 * @param paTests Array of file names and digests.
497 * @param cTests Number of entries in paTests.
498 * @param piFailed A index to paTests in the
499 * VERR_MANIFEST_DIGEST_MISMATCH error case
500 * (optional).
501 * @deprecated Use the RTMANIFEST based API instead.
502 */
503RTR3DECL(int) RTManifestVerifyFilesBuf(void *pvBuf, size_t cbSize, PRTMANIFESTTEST paTests, size_t cTests, size_t *piFailed);
504
505/**
506 * Creates a manifest file in memory for a set of files. The manifest file
507 * contains SHA1 sums of every provided file and could be used to verify the
508 * data integrity of them.
509 *
510 * @returns iprt status code.
511 *
512 * @param ppvBuf Pointer to resulting memory buffer.
513 * @param pcbSize Pointer for the size of the memory buffer.
514 * @param enmDigestType Which type of digest ("SHA1", "SHA256", ...)
515 * @param paFiles Array of file names and digests.
516 * @param cFiles Number of entries in paFiles.
517 * @deprecated Use the RTMANIFEST based API instead.
518 */
519RTR3DECL(int) RTManifestWriteFilesBuf(void **ppvBuf, size_t *pcbSize, RTDIGESTTYPE enmDigestType, PRTMANIFESTTEST paFiles, size_t cFiles);
520
521/** @} */
522
523RT_C_DECLS_END
524
525#endif
526
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette