1 /*
2  *
3   ***** BEGIN LICENSE BLOCK *****
4 
5   Copyright (C) 2009-2019 Olof Hagsand
6   Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC(Netgate)
7 
8   This file is part of CLIXON.
9 
10   Licensed under the Apache License, Version 2.0 (the "License");
11   you may not use this file except in compliance with the License.
12   You may obtain a copy of the License at
13 
14     http://www.apache.org/licenses/LICENSE-2.0
15 
16   Unless required by applicable law or agreed to in writing, software
17   distributed under the License is distributed on an "AS IS" BASIS,
18   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   See the License for the specific language governing permissions and
20   limitations under the License.
21 
22   Alternatively, the contents of this file may be used under the terms of
23   the GNU General Public License Version 3 or later (the "GPL"),
24   in which case the provisions of the GPL are applicable instead
25   of those above. If you wish to allow use of your version of this file only
26   under the terms of the GPL, and not to allow others to
27   use your version of this file under the terms of Apache License version 2,
28   indicate your decision by deleting the provisions above and replace them with
29   the  notice and other provisions required by the GPL. If you do not delete
30   the provisions above, a recipient may use your version of this file under
31   the terms of any one of the Apache License version 2 or the GPL.
32 
33   ***** END LICENSE BLOCK *****
34 
35  * Yang module and feature handling
36  * @see https://tools.ietf.org/html/rfc7895
37  */
38 
39 #ifndef _CLIXON_YANG_MODULE_H_
40 #define _CLIXON_YANG_MODULE_H_
41 
42 /*
43  * Constants
44  */
45 
46 /*
47  * Types
48  */
49 
50 /* Struct containing module state differences between two modules or two
51  * revisions of same module.
52  * The most significant usecase is one module-state is a loaded datastore and the other
53  * is the one loaded by the server by its YANG files.
54  */
55 typedef struct {
56     int    md_status; /* 0 if no module-state in a datastore, 1 if there is */
57     char  *md_set_id; /* server-specific identifier */
58     cxobj *md_diff;   /* yang module state containing revisions and XML_FLAG_ADD|DEL|CHANGE */
59 } modstate_diff_t;
60 
61 /*
62  * Prototypes
63  */
64 modstate_diff_t * modstate_diff_new(void);
65 int modstate_diff_free(modstate_diff_t *);
66 
67 int yang_modules_init(clicon_handle h);
68 char *yang_modules_revision(clicon_handle h);
69 
70 int yang_modules_state_get(clicon_handle h, yang_stmt *yspec, char *xpath,
71 			   cvec *nsc, int brief, cxobj **xret);
72 int clixon_module_upgrade(clicon_handle h, cxobj *xt, modstate_diff_t *msd, cbuf *cb);
73 yang_stmt *yang_find_module_by_prefix(yang_stmt *ys, char *prefix);
74 yang_stmt *yang_find_module_by_prefix_yspec(yang_stmt *yspec, char *prefix);
75 yang_stmt *yang_find_module_by_namespace(yang_stmt *yspec, char *ns);
76 yang_stmt *yang_find_module_by_name(yang_stmt *yspec, char *name);
77 
78 #endif  /* _CLIXON_YANG_MODULE_H_ */
79