1 /*
2   Copyright 2021 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 #ifndef CFENGINE_VARIABLE_H
25 #define CFENGINE_VARIABLE_H
26 
27 #include <cf3.defs.h>
28 
29 #include <var_expressions.h>
30 
31 typedef struct Variable_ Variable;
32 typedef struct VariableTable_ VariableTable;
33 typedef struct VariableTableIterator_ VariableTableIterator;
34 
35 const VarRef *VariableGetRef(const Variable *var);
36 DataType VariableGetType(const Variable *var);
37 RvalType VariableGetRvalType(const Variable *var);
38 StringSet *VariableGetTags(const Variable *var);
39 const char *VariableGetComment(const Variable *var);
40 const Promise *VariableGetPromise(const Variable *var);
41 
42 /**
43  * Get the variable's value.
44  *
45  * @param get_secret Whether to get the secret value in case the variable is tagged as secret
46  *
47  * @note #get_secret should only be %true if the potentially secret value is
48  *       really required, i.e. being actually used not logged, reported,...
49  */
50 Rval VariableGetRval(const Variable *var, bool get_secret);
51 
52 /**
53  * Set new value of variable.
54  *
55  * @note Destroys the old variable's value.
56  */
57 void VariableSetRval(Variable *var, Rval new_rval);
58 
59 /**
60  * Whether the variable is marked as secret or not.
61  */
62 bool VariableIsSecret(const Variable *var);
63 
64 VariableTable *VariableTableNew(void);
65 void VariableTableDestroy(VariableTable *table);
66 
67 bool VariableTablePut(VariableTable *table, const VarRef *ref,
68                       const Rval *rval, DataType type,
69                       StringSet *tags, char *comment, const Promise *promise);
70 Variable *VariableTableGet(const VariableTable *table, const VarRef *ref);
71 bool VariableTableRemove(VariableTable *table, const VarRef *ref);
72 
73 size_t VariableTableCount(const VariableTable *table, const char *ns, const char *scope, const char *lval);
74 bool VariableTableClear(VariableTable *table, const char *ns, const char *scope, const char *lval);
75 
76 VariableTableIterator *VariableTableIteratorNew(const VariableTable *table, const char *ns, const char *scope, const char *lval);
77 VariableTableIterator *VariableTableIteratorNewFromVarRef(const VariableTable *table, const VarRef *ref);
78 Variable *VariableTableIteratorNext(VariableTableIterator *iter);
79 void VariableTableIteratorDestroy(VariableTableIterator *iter);
80 
81 VariableTable *VariableTableCopyLocalized(const VariableTable *table, const char *ns, const char *scope);
82 
83 #endif
84