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 
25 #ifndef CFENGINE_CONVERSION_H
26 #define CFENGINE_CONVERSION_H
27 
28 #include <cf3.defs.h>
29 
30 // Type-String conversion
31 MeasurePolicy MeasurePolicyFromString(const char *s);
32 EnvironmentState EnvironmentStateFromString(const char *s);
33 InsertMatchType InsertMatchTypeFromString(const char *s);
34 Interval IntervalFromString(const char *s);
35 DatabaseType DatabaseTypeFromString(const char *s);
36 UserState UserStateFromString(const char *s);
37 PasswordFormat PasswordFormatFromString(const char *s);
38 ContextScope ContextScopeFromString(const char *scope_str);
39 FileComparator FileComparatorFromString(const char *s);
40 FileLinkType FileLinkTypeFromString(const char *s);
41 DataType DataTypeFromString(const char *name);
42 const char *DataTypeToString(DataType dtype);
43 PackageActionPolicy PackageActionPolicyFromString(const char *s);
44 PackageVersionComparator PackageVersionComparatorFromString(const char *s);
45 PackageAction PackageActionFromString(const char *s);
46 NewPackageAction GetNewPackagePolicy(const char *s, const char **action_types);
47 AclMethod AclMethodFromString(const char *string);
48 AclType AclTypeFromString(const char *string);
49 AclDefault AclDefaultFromString(const char *string);
50 AclInherit AclInheritFromString(const char *string);
51 int SignalFromString(const char *s);
52 int SyslogPriorityFromString(const char *s);
53 ShellType ShellTypeFromString(const char *s);
54 
55 // Date/Time conversion
56 void TimeToDateStr(time_t t, char *outStr, int outStrSz);
57 int Month2Int(const char *string);
58 
59 // Evalaution conversion
60 bool BooleanFromString(const char *val);
61 long IntFromString(const char *s);
62 bool DoubleFromString(const char *s, double *value_out);
63 bool IntegerRangeFromString(const char *intrange, long *min_out, long *max_out);
64 bool IsRealNumber(const char *s);
65 
66 
67 // Misc.
68 char *Rlist2String(Rlist *list, char *sep); // TODO: Yet another Rlist serialization scheme.. Found 5 so far.
69 DataType ConstraintSyntaxGetDataType(const ConstraintSyntax *body_syntax, const char *lval);
70 const char *MapAddress(const char *addr);
71 const char *CommandArg0(const char *execstr);
72 size_t CommandArg0_bound(char *dst, const char *src, size_t dst_size);
73 void CommandPrefix(char *execstr, char *comm);
74 const char *DataTypeShortToType(char *short_type);
75 bool DataTypeIsIterable(DataType t);
76 
77 bool CoarseLaterThan(const char *key, const char *from);
78 int FindTypeInArray(const char *const haystack[], const char *needle, int default_value, int null_value);
79 
80 void UidListDestroy(UidList *uids);
81 void GidListDestroy(GidList *gids);
82 UidList *Rlist2UidList(Rlist *uidnames, const Promise *pp);
83 GidList *Rlist2GidList(Rlist *gidnames, const Promise *pp);
84 #ifndef __MINGW32__
85 uid_t Str2Uid(const char *uidbuff, char *copy, const Promise *pp);
86 gid_t Str2Gid(const char *gidbuff, char *copy, const Promise *pp);
87 #endif /* !__MINGW32__ */
88 
89 #endif
90