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)  

fncall.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_FNCALL_H
26 #define CFENGINE_FNCALL_H
27 
28 #include <cf3.defs.h>
29 
30 struct FnCall_
31 {
32  char *name;
34 
35  const Promise *caller;
36 };
37 
38 typedef enum FnCallStatus
39 {
43 
44 typedef struct
45 {
48 } FnCallResult;
49 
50 typedef struct
51 {
52  const char *pattern;
54  const char *description;
55 } FnCallArg;
56 
57 typedef enum
58 {
60  // Functions with variable arguments don't require a fixed number
61  // of arguments.
63  // Cached functions are evaluated once per run (memoized). The
64  // hash key is the function name and all the arguments.
66  // Collecting functions take a variable reference OR can accept a
67  // nested function call. Either way, those parameters are
68  // collected into a data container.
70  // Delayed-evaluation functions will evaluate their arguments directly,
71  // so they can do things like maplist(canonify($(this)), mylist)
74 
75 typedef struct
76 {
77  const char *name;
79  const FnCallArg *args;
80  FnCallResult (*impl)(EvalContext *, const Policy *, const FnCall *, const Rlist *);
81  const char *description;
85 } FnCallType;
86 
87 extern const FnCallType CF_FNCALL_TYPES[];
88 
89 bool FnCallIsBuiltIn(Rval rval);
90 
91 FnCall *FnCallNew(const char *name, Rlist *args);
92 FnCall *FnCallCopy(const FnCall *f);
94 void FnCallDestroy(FnCall *fp);
95 unsigned FnCallHash(const FnCall *fp, unsigned seed);
96 void FnCallWrite(Writer *writer, const FnCall *call);
97 
98 
99 FnCallResult FnCallEvaluate(EvalContext *ctx, const Policy *policy, FnCall *fp, const Promise *caller);
100 
101 const FnCallType *FnCallTypeGet(const char *name);
102 
103 FnCall *ExpandFnCall(EvalContext *ctx, const char *ns, const char *scope, const FnCall *f);
104 Rlist *NewExpArgs(EvalContext *ctx, const Policy *policy, const FnCall *fp, const FnCallType *fp_type);
105 
106 // TODO: should probably demolish this eventually
107 void FnCallShow(FILE *fout, const char *prefix, const FnCall *fp, const Rlist *args);
108 
109 #endif
FnCallCategory
Definition: cf3.defs.h:644
SyntaxStatus
Definition: cf3.defs.h:637
DataType
Definition: cf3.defs.h:368
const FnCallType * FnCallTypeGet(const char *name)
Definition: fncall.c:430
FnCall * FnCallNew(const char *name, Rlist *args)
Definition: fncall.c:161
FnCall * FnCallCopyRewriter(const FnCall *f, JsonElement *map)
Definition: fncall.c:173
FnCall * FnCallCopy(const FnCall *f)
Definition: fncall.c:178
FnCall * ExpandFnCall(EvalContext *ctx, const char *ns, const char *scope, const FnCall *f)
Definition: fncall.c:202
const FnCallType CF_FNCALL_TYPES[]
void FnCallDestroy(FnCall *fp)
Definition: fncall.c:185
unsigned FnCallHash(const FnCall *fp, unsigned seed)
Definition: fncall.c:195
void FnCallWrite(Writer *writer, const FnCall *call)
Definition: fncall.c:222
void FnCallShow(FILE *fout, const char *prefix, const FnCall *fp, const Rlist *args)
Rlist * NewExpArgs(EvalContext *ctx, const Policy *policy, const FnCall *fp, const FnCallType *fp_type)
Definition: fncall.c:61
FnCallStatus
Definition: fncall.h:39
@ FNCALL_SUCCESS
Definition: fncall.h:40
@ FNCALL_FAILURE
Definition: fncall.h:41
FnCallOption
Definition: fncall.h:58
@ FNCALL_OPTION_COLLECTING
Definition: fncall.h:69
@ FNCALL_OPTION_CACHED
Definition: fncall.h:65
@ FNCALL_OPTION_NONE
Definition: fncall.h:59
@ FNCALL_OPTION_DELAYED_EVALUATION
Definition: fncall.h:72
@ FNCALL_OPTION_VARARG
Definition: fncall.h:62
FnCallResult FnCallEvaluate(EvalContext *ctx, const Policy *policy, FnCall *fp, const Promise *caller)
Definition: fncall.c:309
bool FnCallIsBuiltIn(Rval rval)
Definition: fncall.c:138
const char * description
Definition: fncall.h:54
DataType dtype
Definition: fncall.h:53
const char * pattern
Definition: fncall.h:52
FnCallStatus status
Definition: fncall.h:46
Rval rval
Definition: fncall.h:47
const char * description
Definition: fncall.h:81
FnCallOption options
Definition: fncall.h:82
FnCallCategory category
Definition: fncall.h:83
SyntaxStatus status
Definition: fncall.h:84
const FnCallArg * args
Definition: fncall.h:79
const char * name
Definition: fncall.h:77
DataType dtype
Definition: fncall.h:78
Definition: fncall.h:31
const Promise * caller
Definition: fncall.h:35
char * name
Definition: fncall.h:32
Rlist * args
Definition: fncall.h:33
Definition: policy.h:53
Definition: rlist.h:35
Definition: cf3.defs.h:614
Definition: writer.c:45