Open SCAP Library
|
00001 /* 00002 * Copyright 2009 Red Hat Inc., Durham, North Carolina. 00003 * All Rights Reserved. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 * Authors: 00020 * "Daniel Kopecek" <dkopecek@redhat.com> 00021 */ 00022 #pragma once 00023 #ifndef SEXP_PARSER_H 00024 #define SEXP_PARSER_H 00025 00026 #include <stddef.h> 00027 #include <stdint.h> 00028 #include "public/sexp-parser.h" 00029 #include "_sexp-manip.h" 00030 #include "generic/spb.h" 00031 00032 OSCAP_HIDDEN_START; 00033 00034 /* Number classes */ 00035 #define SEXP_NUMCLASS_INV 0 00036 #define SEXP_NUMCLASS_INT 1 00037 #define SEXP_NUMCLASS_UINT 2 00038 #define SEXP_NUMCLASS_FLT 3 00039 #define SEXP_NUMCLASS_EXP 4 00040 #define SEXP_NUMCLASS_FRA 5 00041 #define SEXP_NUMCLASS_PRE 6 00042 00043 #define SEXP_PFUNC_COUNT 8 00044 00045 /* 00046 * Parser state 00047 */ 00048 struct SEXP_pstate { 00049 /* 00050 * Input data 00051 */ 00052 spb_t *p_buffer; /* input buffer */ 00053 spb_size_t p_bufoff; /* start index - everything before this index in the buffer is already parsed */ 00054 spb_size_t p_explen; /* length of already parsed/checked part of the expression */ 00055 SEXP_pflags_t p_flags; /* current parser flags */ 00056 SEXP_t *p_sexp; /* last S-exp object */ 00057 SEXP_pflags_t p_flags0; /* initial parser flags */ 00058 00059 void *sp_data; /* subparser data */ 00060 void (*sp_free)(void *); /* function for freeing the subparser data */ 00061 00062 void *sp_shptr[SEXP_PFUNC_COUNT]; /* subparser shared pointer */ 00063 void (*sp_shfree[SEXP_PFUNC_COUNT])(void *); /* functions for freeing subparser shared pointer */ 00064 00065 uint8_t p_label; /* where to jump if p_explen > 0 */ 00066 00067 uint8_t p_numclass; /* number class */ 00068 uint8_t p_numbase; /* number base */ 00069 uint8_t p_numstage; /* number parsing stage */ 00070 00071 /* 00072 * Output data 00073 */ 00074 SEXP_lstack_t l_stack; /* output list stack */ 00075 00076 /* 00077 * Value cache 00078 */ 00079 uintptr_t v_bool[2]; /* true, false pre-allocated values */ 00080 uint8_t p_error; 00081 }; 00082 00083 struct SEXP_pext_dsc { 00084 spb_t *p_buffer; 00085 spb_size_t p_bufoff; 00086 spb_size_t p_explen; 00087 SEXP_pflags_t p_flags; 00088 SEXP_t *s_exp; 00089 void *sp_data; /* subparser data */ 00090 void (*sp_free)(void *); /* function for freeing the subparser data */ 00091 void *sp_shptr[SEXP_PFUNC_COUNT]; 00092 void (*sp_shfree[SEXP_PFUNC_COUNT])(void *); 00093 00094 uint8_t p_label; 00095 uint8_t p_numclass; 00096 uint8_t p_numbase; 00097 uint8_t p_numstage; 00098 00099 uintptr_t *v_bool; 00100 }; 00101 00102 #define PEXT_DSC_INITIALIZER { NULL, 0, 0, NULL } 00103 00104 #define __PARSE_RT int 00105 #define __PARSE_PT(n1) struct SEXP_pext_dsc *n1 00106 00107 typedef __PARSE_RT (SEXP_pfunc_t)(__PARSE_PT()); 00108 00109 00110 struct SEXP_psetup { 00111 SEXP_format_t p_format; /* expected or required format (depends on p_flags) */ 00112 SEXP_pflags_t p_flags; /* initial parser flags */ 00113 SEXP_pfunc_t *p_funcp[SEXP_PFUNC_COUNT]; 00114 }; 00115 00116 #define SEXP_PFUNC_UL_STRING_SI 0 00117 #define SEXP_PFUNC_UL_STRING_DQ 1 00118 #define SEXP_PFUNC_UL_STRING_SQ 2 00119 #define SEXP_PFUNC_KL_STRING 3 00120 #define SEXP_PFUNC_UL_STRING_B64 4 00121 #define SEXP_PFUNC_KL_STRING_B64 5 00122 #define SEXP_PFUNC_UL_DATATYPE 6 00123 #define SEXP_PFUNC_KL_DATATYPE 7 00124 #define SEXP_PFUNC_BOOL 8 00125 00126 __PARSE_RT SEXP_parse_ul_string_si (__PARSE_PT(dsc)); 00127 __PARSE_RT SEXP_parse_ul_string_dq (__PARSE_PT(dsc)); 00128 __PARSE_RT SEXP_parse_ul_string_sq (__PARSE_PT(dsc)); 00129 __PARSE_RT SEXP_parse_kl_string (__PARSE_PT(dsc)); 00130 __PARSE_RT SEXP_parse_ul_string_b64 (__PARSE_PT(dsc)); 00131 __PARSE_RT SEXP_parse_kl_string_b64 (__PARSE_PT(dsc)); 00132 __PARSE_RT SEXP_parse_ul_datatype (__PARSE_PT(dsc)); 00133 __PARSE_RT SEXP_parse_kl_datatype (__PARSE_PT(dsc)); 00134 __PARSE_RT SEXP_parse_bool (__PARSE_PT(dsc), bool val); 00135 00136 #define SEXP_PSLOT_MAX 1024 00137 00138 #define SEXP_PRET_SUCCESS 0 00139 #define SEXP_PRET_EUNFIN 1 /* incomplete token */ 00140 #define SEXP_PRET_EINVAL 2 /* syntax error, invalid token */ 00141 #define SEXP_PRET_EUNDEF 255 /* unknown, unexpected error */ 00142 00143 #ifdef __GNUC__ 00144 # define __predict(expr, v) __builtin_expect (expr, v) 00145 #else 00146 # define __predict(expr, v) expr 00147 #endif /* __GNUC__ */ 00148 00149 /* 00150 * TODO: make this function public in the future 00151 */ 00152 int SEXP_psetup_setpfunc(SEXP_psetup_t *psetup, int pfunctype, SEXP_pfunc_t *pfunc); 00153 00154 OSCAP_HIDDEN_END; 00155 00156 #endif /* SEXP_PARSER_H */