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_CLASS_H
25 #define CFENGINE_CLASS_H
26 
27 #include <cf3.defs.h>
28 #include <set.h>
29 
30 typedef struct
31 {
32     char *ns;                          /* NULL in case of default namespace */
33     char *name;                        /* class name */
34 
35     ContextScope scope;
36     bool is_soft;
37     StringSet *tags;
38     char *comment;
39 } Class;
40 
41 
42 typedef struct ClassTable_ ClassTable;
43 typedef struct ClassTableIterator_ ClassTableIterator;
44 
45 ClassTable *ClassTableNew(void);
46 void ClassTableDestroy(ClassTable *table);
47 
48 bool ClassTablePut(ClassTable *table, const char *ns, const char *name, bool is_soft, ContextScope scope,
49                    StringSet *tags, const char *comment);
50 Class *ClassTableGet(const ClassTable *table, const char *ns, const char *name);
51 Class *ClassTableMatch(const ClassTable *table, const char *regex);
52 bool ClassTableRemove(ClassTable *table, const char *ns, const char *name);
53 
54 bool ClassTableClear(ClassTable *table);
55 
56 ClassTableIterator *ClassTableIteratorNew(const ClassTable *table, const char *ns, bool is_hard, bool is_soft);
57 Class *ClassTableIteratorNext(ClassTableIterator *iter);
58 void ClassTableIteratorDestroy(ClassTableIterator *iter);
59 
60 typedef struct
61 {
62     char *ns;
63     char *name;
64 } ClassRef;
65 
66 ClassRef ClassRefParse(const char *expr);
67 char *ClassRefToString(const char *ns, const char *name);
68 bool ClassRefIsQualified(ClassRef ref);
69 void ClassRefQualify(ClassRef *ref, const char *ns);
70 void ClassRefDestroy(ClassRef ref);
71 
72 #endif
73