cfengine  3.15.4
About: CFEngine is a configuration management system for configuring and maintaining Unix-like computers (using an own high level policy language). Community version.
  Fossies Dox: cfengine-3.15.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

syntax.h
Go to the documentation of this file.
1 /*
2  Copyright 2019 Northern.tech AS
3 
4  This file is part of CFEngine 3 - written and maintained by Northern.tech AS.
5 
6  This program is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by the
8  Free Software Foundation; version 3.
9 
10  This program 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
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 
19  To the extent this program is licensed as part of the Enterprise
20  versions of CFEngine, the applicable Commercial Open Source License
21  (COSL) may apply to this file if you as a licensee so wish it. See
22  included file COSL.txt.
23 */
24 
25 #ifndef CFENGINE_SYNTAX_H
26 #define CFENGINE_SYNTAX_H
27 
28 #include <cf3.defs.h>
29 
30 #include <sequence.h>
31 #include <json.h>
32 
33 #include <stdio.h>
34 
35 /*
36  * WARNING: This file is in need of serious cleanup.
37  */
38 
39 
40 typedef enum
41 {
43 
50 
53 
55 
58 
61 
63 
66 
68 
70 
73 
74 const char *SyntaxTypeMatchToString(SyntaxTypeMatch result);
75 
76 bool CheckParseVariableName(const char *name);
77 SyntaxTypeMatch CheckConstraintTypeMatch(const char *lval, Rval rval, DataType dt, const char *range, int level);
78 SyntaxTypeMatch CheckParseContext(const char *context, const char *range);
79 DataType StringDataType(EvalContext *ctx, const char *string);
80 DataType ExpectedDataType(const char *lvalname);
81 
82 const PromiseTypeSyntax *PromiseTypeSyntaxGet(const char *bundle_type, const char *promise_type);
83 const ConstraintSyntax *PromiseTypeSyntaxGetConstraintSyntax(const PromiseTypeSyntax *promise_type_syntax, const char *lval);
84 
85 const BodySyntax *BodySyntaxGet(const char *body_type);
86 const ConstraintSyntax *BodySyntaxGetConstraintSyntax(const ConstraintSyntax *body_syntax, const char *lval);
87 
88 const char *SyntaxStatusToString(SyntaxStatus status);
89 
91 
92 #define ConstraintSyntaxNewNull() { NULL, CF_DATA_TYPE_NONE, .range.validation_string = NULL, .status = SYNTAX_STATUS_NORMAL }
93 #define ConstraintSyntaxNewBool(lval, description, status) { lval, CF_DATA_TYPE_OPTION, .range.validation_string = CF_BOOL, description, status }
94 
95 #define ConstraintSyntaxNewOption(lval, options, description, status) { lval, CF_DATA_TYPE_OPTION, .range.validation_string = options, description, status }
96 #define ConstraintSyntaxNewOptionList(lval, item_range, description, status) { lval, CF_DATA_TYPE_OPTION_LIST, .range.validation_string = item_range, description, status }
97 
98 #define ConstraintSyntaxNewString(lval, regex, description, status) { lval, CF_DATA_TYPE_STRING, .range.validation_string = regex, description, status }
99 #define ConstraintSyntaxNewStringList(lval, item_range, description, status) { lval, CF_DATA_TYPE_STRING_LIST, .range.validation_string = item_range, description, status }
100 
101 #define ConstraintSyntaxNewInt(lval, int_range, description, status) { lval, CF_DATA_TYPE_INT, .range.validation_string = int_range, description, status }
102 #define ConstraintSyntaxNewIntRange(lval, int_range, description, status ) { lval , CF_DATA_TYPE_INT_RANGE, .range.validation_string = int_range, description, status }
103 #define ConstraintSyntaxNewIntList(lval, description, status) { lval, CF_DATA_TYPE_INT_LIST, .range.validation_string = CF_INTRANGE, description, status }
104 
105 #define ConstraintSyntaxNewReal(lval, real_range, description, status) { lval, CF_DATA_TYPE_REAL, .range.validation_string = real_range, description, status }
106 #define ConstraintSyntaxNewRealList(lval, description, status) { lval, CF_DATA_TYPE_REAL_LIST, .range.validation_string = CF_REALRANGE, description, status }
107 
108 #define ConstraintSyntaxNewContext(lval, description, status) { lval, CF_DATA_TYPE_CONTEXT, .range.validation_string = CF_CLASSRANGE, description, status }
109 #define ConstraintSyntaxNewContextList(lval, description, status) { lval, CF_DATA_TYPE_CONTEXT_LIST, .range.validation_string = CF_CLASSRANGE, description, status }
110 
111 #define ConstraintSyntaxNewContainer(lval, description, status) { lval, CF_DATA_TYPE_CONTAINER, .range.validation_string = "", description, status }
112 
113 #define ConstraintSyntaxNewBody(lval, body_syntax, description, status) { lval, CF_DATA_TYPE_BODY, .range.body_type_syntax = body_syntax, description, status }
114 #define ConstraintSyntaxNewBundle(lval, description, status) { lval, CF_DATA_TYPE_BUNDLE, .range.validation_string = CF_BUNDLE, description, status }
115 
116 #define BodySyntaxNew(body_type, constraints, check_fn, status) { body_type, constraints, check_fn, status }
117 #define BodySyntaxNewNull() { NULL, NULL, NULL, SYNTAX_STATUS_NORMAL }
118 
119 #define PromiseTypeSyntaxNew(agent_type, promise_type, constraints, check_fn, status) { agent_type, promise_type, constraints, check_fn, status }
120 #define PromiseTypeSyntaxNewNull() PromiseTypeSyntaxNew(NULL, NULL, NULL, NULL, SYNTAX_STATUS_NORMAL)
121 
122 #define FnCallTypeNew(name, return_type, arguments, implementation, description, opts, category, status) { name, return_type, arguments, implementation, description, .options = opts, category, status }
123 #define FnCallTypeNewNull() FnCallTypeNew(NULL, CF_DATA_TYPE_NONE, NULL, NULL, NULL, false, FNCALL_CATEGORY_UTILS, SYNTAX_STATUS_NORMAL)
124 
125 #define CONSTRAINT_SYNTAX_GLOBAL { "meta", CF_DATA_TYPE_STRING_LIST, .range.validation_string = "", "Tags describing the body", SYNTAX_STATUS_NORMAL }, \
126  { "inherit_from", CF_DATA_TYPE_BODY, .range.validation_string = "", "Body from which attributes will be inherited", SYNTAX_STATUS_NORMAL }
127 
128 #endif
SyntaxStatus
Definition: cf3.defs.h:637
DataType
Definition: cf3.defs.h:368
Definition: cf3.defs.h:614
DataType StringDataType(EvalContext *ctx, const char *string)
Definition: syntax.c:426
const BodySyntax * BodySyntaxGet(const char *body_type)
Definition: syntax.c:149
const ConstraintSyntax * BodySyntaxGetConstraintSyntax(const ConstraintSyntax *body_syntax, const char *lval)
Definition: syntax.c:103
SyntaxTypeMatch CheckParseContext(const char *context, const char *range)
Definition: syntax.c:548
const PromiseTypeSyntax * PromiseTypeSyntaxGet(const char *bundle_type, const char *promise_type)
Definition: syntax.c:75
bool CheckParseVariableName(const char *name)
Definition: syntax.c:827
JsonElement * SyntaxToJson(void)
Definition: syntax.c:1277
SyntaxTypeMatch
Definition: syntax.h:41
@ SYNTAX_TYPE_MATCH_ERROR_REAL_OUT_OF_RANGE
Definition: syntax.h:60
@ SYNTAX_TYPE_MATCH_ERROR_INT_PARSE
Definition: syntax.h:56
@ SYNTAX_TYPE_MATCH_ERROR_EMPTY_SCALAR_OUT_OF_RANGE
Definition: syntax.h:52
@ SYNTAX_TYPE_MATCH_ERROR_RANGE_BRACKETED
Definition: syntax.h:45
@ SYNTAX_TYPE_MATCH_ERROR_OPTS_OUT_OF_RANGE
Definition: syntax.h:62
@ SYNTAX_TYPE_MATCH_ERROR_STRING_UNIX_PERMISSION
Definition: syntax.h:54
@ SYNTAX_TYPE_MATCH_ERROR_UNEXPANDED
Definition: syntax.h:44
@ SYNTAX_TYPE_MATCH_ERROR_CONTEXT_OUT_OF_RANGE
Definition: syntax.h:67
@ SYNTAX_TYPE_MATCH_ERROR_SCALAR_OUT_OF_RANGE
Definition: syntax.h:51
@ SYNTAX_TYPE_MATCH_ERROR_INT_OUT_OF_RANGE
Definition: syntax.h:57
@ SYNTAX_TYPE_MATCH_ERROR_RANGE_MULTIPLE_ITEMS
Definition: syntax.h:46
@ SYNTAX_TYPE_MATCH_ERROR_FNCALL_UNKNOWN
Definition: syntax.h:65
@ SYNTAX_TYPE_MATCH_ERROR_GOT_LIST
Definition: syntax.h:48
@ SYNTAX_TYPE_MATCH_ERROR_GOT_SCALAR
Definition: syntax.h:47
@ SYNTAX_TYPE_MATCH_MAX
Definition: syntax.h:71
@ SYNTAX_TYPE_MATCH_ERROR_REAL_INF
Definition: syntax.h:59
@ SYNTAX_TYPE_MATCH_ERROR_ABSOLUTE_PATH
Definition: syntax.h:69
@ SYNTAX_TYPE_MATCH_ERROR_GOT_NULL
Definition: syntax.h:49
@ SYNTAX_TYPE_MATCH_OK
Definition: syntax.h:42
@ SYNTAX_TYPE_MATCH_ERROR_FNCALL_RETURN_TYPE
Definition: syntax.h:64
const char * SyntaxTypeMatchToString(SyntaxTypeMatch result)
Definition: syntax.c:262
DataType ExpectedDataType(const char *lvalname)
Definition: syntax.c:203
SyntaxTypeMatch CheckConstraintTypeMatch(const char *lval, Rval rval, DataType dt, const char *range, int level)
Definition: syntax.c:300
const ConstraintSyntax * PromiseTypeSyntaxGetConstraintSyntax(const PromiseTypeSyntax *promise_type_syntax, const char *lval)
Definition: syntax.c:115
const char * SyntaxStatusToString(SyntaxStatus status)
Definition: syntax.c:182