Open SCAP Library
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
_sexp-parser.h
1 /*
2  * Copyright 2009 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors:
20  * "Daniel Kopecek" <dkopecek@redhat.com>
21  */
22 #pragma once
23 #ifndef SEXP_PARSER_H
24 #define SEXP_PARSER_H
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 #include "public/sexp-parser.h"
29 #include "_sexp-manip.h"
30 #include "generic/spb.h"
31 
32 OSCAP_HIDDEN_START;
33 
34 /* Number classes */
35 #define SEXP_NUMCLASS_INV 0
36 #define SEXP_NUMCLASS_INT 1
37 #define SEXP_NUMCLASS_UINT 2
38 #define SEXP_NUMCLASS_FLT 3
39 #define SEXP_NUMCLASS_EXP 4
40 #define SEXP_NUMCLASS_FRA 5
41 #define SEXP_NUMCLASS_PRE 6
42 
43 #define SEXP_PFUNC_COUNT 8
44 
45 /*
46  * Parser state
47  */
48 struct SEXP_pstate {
49  /*
50  * Input data
51  */
52  spb_t *p_buffer; /* input buffer */
53  spb_size_t p_bufoff; /* start index - everything before this index in the buffer is already parsed */
54  spb_size_t p_explen; /* length of already parsed/checked part of the expression */
55  SEXP_pflags_t p_flags; /* current parser flags */
56  SEXP_t *p_sexp; /* last S-exp object */
57  SEXP_pflags_t p_flags0; /* initial parser flags */
58 
59  void *sp_data; /* subparser data */
60  void (*sp_free)(void *); /* function for freeing the subparser data */
61 
62  void *sp_shptr[SEXP_PFUNC_COUNT]; /* subparser shared pointer */
63  void (*sp_shfree[SEXP_PFUNC_COUNT])(void *); /* functions for freeing subparser shared pointer */
64 
65  uint8_t p_label; /* where to jump if p_explen > 0 */
66 
67  uint8_t p_numclass; /* number class */
68  uint8_t p_numbase; /* number base */
69  uint8_t p_numstage; /* number parsing stage */
70 
71  /*
72  * Output data
73  */
74  SEXP_lstack_t l_stack; /* output list stack */
75 
76  /*
77  * Value cache
78  */
79  uintptr_t v_bool[2]; /* true, false pre-allocated values */
80  uint8_t p_error;
81 };
82 
83 struct SEXP_pext_dsc {
84  spb_t *p_buffer;
85  spb_size_t p_bufoff;
86  spb_size_t p_explen;
87  SEXP_pflags_t p_flags;
88  SEXP_t *s_exp;
89  void *sp_data; /* subparser data */
90  void (*sp_free)(void *); /* function for freeing the subparser data */
91  void *sp_shptr[SEXP_PFUNC_COUNT];
92  void (*sp_shfree[SEXP_PFUNC_COUNT])(void *);
93 
94  uint8_t p_label;
95  uint8_t p_numclass;
96  uint8_t p_numbase;
97  uint8_t p_numstage;
98 
99  uintptr_t *v_bool;
100 };
101 
102 #define PEXT_DSC_INITIALIZER { NULL, 0, 0, NULL }
103 
104 #define __PARSE_RT int
105 #define __PARSE_PT(n1) struct SEXP_pext_dsc *n1
106 
107 typedef __PARSE_RT (SEXP_pfunc_t)(__PARSE_PT());
108 
109 
110 struct SEXP_psetup {
111  SEXP_format_t p_format; /* expected or required format (depends on p_flags) */
112  SEXP_pflags_t p_flags; /* initial parser flags */
113  SEXP_pfunc_t *p_funcp[SEXP_PFUNC_COUNT];
114 };
115 
116 #define SEXP_PFUNC_UL_STRING_SI 0
117 #define SEXP_PFUNC_UL_STRING_DQ 1
118 #define SEXP_PFUNC_UL_STRING_SQ 2
119 #define SEXP_PFUNC_KL_STRING 3
120 #define SEXP_PFUNC_UL_STRING_B64 4
121 #define SEXP_PFUNC_KL_STRING_B64 5
122 #define SEXP_PFUNC_UL_DATATYPE 6
123 #define SEXP_PFUNC_KL_DATATYPE 7
124 #define SEXP_PFUNC_BOOL 8
125 
126 __PARSE_RT SEXP_parse_ul_string_si (__PARSE_PT(dsc));
127 __PARSE_RT SEXP_parse_ul_string_dq (__PARSE_PT(dsc));
128 __PARSE_RT SEXP_parse_ul_string_sq (__PARSE_PT(dsc));
129 __PARSE_RT SEXP_parse_kl_string (__PARSE_PT(dsc));
130 __PARSE_RT SEXP_parse_ul_string_b64 (__PARSE_PT(dsc));
131 __PARSE_RT SEXP_parse_kl_string_b64 (__PARSE_PT(dsc));
132 __PARSE_RT SEXP_parse_ul_datatype (__PARSE_PT(dsc));
133 __PARSE_RT SEXP_parse_kl_datatype (__PARSE_PT(dsc));
134 __PARSE_RT SEXP_parse_bool (__PARSE_PT(dsc), bool val);
135 
136 #define SEXP_PSLOT_MAX 1024
137 
138 #define SEXP_PRET_SUCCESS 0
139 #define SEXP_PRET_EUNFIN 1 /* incomplete token */
140 #define SEXP_PRET_EINVAL 2 /* syntax error, invalid token */
141 #define SEXP_PRET_EUNDEF 255 /* unknown, unexpected error */
142 
143 #ifdef __GNUC__
144 # define __predict(expr, v) __builtin_expect (expr, v)
145 #else
146 # define __predict(expr, v) expr
147 #endif /* __GNUC__ */
148 
149 /*
150  * TODO: make this function public in the future
151  */
152 int SEXP_psetup_setpfunc(SEXP_psetup_t *psetup, int pfunctype, SEXP_pfunc_t *pfunc);
153 
154 OSCAP_HIDDEN_END;
155 
156 #endif /* SEXP_PARSER_H */
Definition: _sexp-manip.h:36
Definition: _sexp-parser.h:48
Definition: spb.h:48
Definition: sexp-types.h:82
Definition: _sexp-parser.h:110
Definition: _sexp-parser.h:83