1 /**
2  * Copyright(c) 2011 Trusted Logic.   All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *  * Neither the name Trusted Logic nor the names of its
15  *    contributors may be used to endorse or promote products derived
16  *    from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*
32  * This API allows parsing manifest files. A manifest is a text file that contains
33  * a property set. A property is a name-value pair.
34  *
35  * The BNF syntax of a manifest file is :
36  *
37  * See Spec of Client Authentication
38  *
39  * Note: for each property, trailing spaces and tabs between the ':' separator
40  * and the first character of the property value are discarded.
41  */
42 
43 
44 #ifndef __LIB_MANIFEST2_H__
45 #define __LIB_MANIFEST2_H__
46 
47 #include "s_error.h"
48 #include "s_type.h"
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 #if 0
54 }  /* balance curly quotes */
55 #endif
56 
57 /* The input file is a compiled manifest */
58 #define LIB_MANIFEST2_TYPE_COMPILED 1
59 /* The input file is a source manifest */
60 #define LIB_MANIFEST2_TYPE_SOURCE 2
61 /* The input file is a source manifest with sections */
62 #define LIB_MANIFEST2_TYPE_SOURCE_WITH_SECTIONS 3
63 
64 typedef struct
65 {
66    char* pManifestName;
67    uint32_t nType;
68    uint8_t* pManifestContent;
69    uint32_t nManifestLength;
70    uint32_t nOffset;
71    uint32_t nLine;
72    uint32_t nSectionStartOffset;
73 }
74 LIB_MANIFEST2_CONTEXT;
75 
76 /* Must be used before libManifest2GetNextItem.
77    The fields nType, pManifestContent, nManifestLength, and pManifestName (if applicable)
78    must be filled-in before.
79 */
80 void libManifest2InitContext(
81    LIB_MANIFEST2_CONTEXT* pContext);
82 
83 /**
84  * Returns S_ITEM_NOT_FOUND for the last itel
85  *
86  * If type is LIB_MANIFEST2_TYPE_SOURCE, supports comments, multiple newlines, and leading BOM,
87  * and checks that properties are not duplicated
88  *
89  * If type is LIB_MANIFEST2_TYPE_SOURCE_WITH_SECTIONS, returns *pValue == NULL for a section
90  * Check that the section name contains only ASCII characters and that there is no duplicate
91  * sections (same name, case insensitive)
92  **/
93 S_RESULT libManifest2GetNextItem(
94    LIB_MANIFEST2_CONTEXT* pContext,
95    OUT uint8_t** ppName,
96    OUT uint32_t* pNameLength,
97    OUT uint8_t** ppValue,
98    OUT uint32_t* pValueLength);
99 
100 S_RESULT libManifest2CheckFormat(
101    LIB_MANIFEST2_CONTEXT* pContext,
102    uint32_t* pnItemCount);
103 
104 #if 0
105 {  /* balance curly quotes */
106 #endif
107 #ifdef __cplusplus
108 }  /* closes extern "C" */
109 #endif
110 
111 #endif  /* !defined(__LIB_MANIFEST_H__) */
112