1 /*
2  *
3   ***** BEGIN LICENSE BLOCK *****
4 
5   Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
6   Copyright (C) 2017-2019 Olof Hagsand
7   Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC(Netgate)
8 
9   This file is part of CLIXON.
10 
11   Licensed under the Apache License, Version 2.0 (the "License");
12   you may not use this file except in compliance with the License.
13   You may obtain a copy of the License at
14 
15     http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22 
23   Alternatively, the contents of this file may be used under the terms of
24   the GNU General Public License Version 3 or later (the "GPL"),
25   in which case the provisions of the GPL are applicable instead
26   of those above. If you wish to allow use of your version of this file only
27   under the terms of the GPL, and not to allow others to
28   use your version of this file under the terms of Apache License version 2,
29   indicate your decision by deleting the provisions above and replace them with
30   the  notice and other provisions required by the GPL. If you do not delete
31   the provisions above, a recipient may use your version of this file under
32   the terms of any one of the Apache License version 2 or the GPL.
33 
34   ***** END LICENSE BLOCK *****
35 
36  * Netconf library functions. See RFC6241
37  * Functions to generate a netconf error message come in two forms: xml-tree and
38  * cbuf. XML tree is preferred.
39  */
40 #ifndef _CLIXON_NETCONF_LIB_H
41 #define _CLIXON_NETCONF_LIB_H
42 
43 /*
44  * Types
45  */
46 /*! Content query parameter RFC 8040 Sec 4.8.1
47  * Clixon extention: content so that RFC8040 content attribute can be conveyed
48  * internally used in <get>
49  */
50 enum netconf_content{
51     CONTENT_CONFIG,    /* config data only */
52     CONTENT_NONCONFIG, /* state data only */
53     CONTENT_ALL        /* default */
54 };
55 typedef enum netconf_content netconf_content;
56 
57 /*
58  * Macros
59  */
60 /*! Generate textual error log from Netconf error message
61  * @param[in]  xerr     Netconf error xml tree on the form: <rpc-error>
62  * @param[in]  format   Format string
63  * @param[in]  arg      String argument to format (optional)
64  */
65 #define clixon_netconf_error(x, f, a) clixon_netconf_error_fn(__FUNCTION__, __LINE__, (x), (f), (a))
66 
67 /*
68  * Prototypes
69  */
70 int netconf_in_use(cbuf *cb, char *type, char *message);
71 int netconf_invalid_value(cbuf *cb, char *type, char *message);
72 int netconf_invalid_value_xml(cxobj **xret, char *type, char *message);
73 int netconf_too_big(cbuf *cb, char *type, char *message);
74 int netconf_missing_attribute(cbuf *cb,	char *type, char *info, char *message);
75 int netconf_bad_attribute(cbuf *cb, char *type, char *info, char *message);
76 int netconf_bad_attribute_xml(cxobj **xret, char *type, char *info, char *message);
77 int netconf_unknown_attribute(cbuf *cb,	char *type, char *info, char *message);
78 int netconf_missing_element(cbuf *cb, char *type, char *element, char *message);
79 int netconf_missing_element_xml(cxobj **xret, char *type, char *element, char *message);
80 int netconf_bad_element(cbuf *cb, char *type, char *info, char *element);
81 int netconf_bad_element_xml(cxobj **xret, char *type, char *info, char *element);
82 int netconf_unknown_element(cbuf *cb, char *type, char *element, char *message);
83 int netconf_unknown_element_xml(cxobj **xret, char *type, char *element, char *message);
84 int netconf_unknown_namespace(cbuf *cb, char *type, char *ns, char *message);
85 int netconf_unknown_namespace_xml(cxobj **xret, char *type, char *ns, char *message);
86 int netconf_access_denied(cbuf *cb, char *type, char *message);
87 int netconf_access_denied_xml(cxobj **xret, char *type, char *message);
88 int netconf_lock_denied(cbuf *cb, char *info, char *message);
89 int netconf_resource_denied(cbuf *cb, char *type, char *message);
90 int netconf_rollback_failed(cbuf *cb, char *type, char *message);
91 int netconf_data_exists(cbuf *cb, char *message);
92 int netconf_data_missing(cbuf *cb, char *missing_choice, char *message);
93 int netconf_data_missing_xml(cxobj **xret, char *missing_choice, char *message);
94 int netconf_operation_not_supported(cbuf *cb, char *type, char *message);
95 int netconf_operation_failed(cbuf *cb, char *type, char *message);
96 int netconf_operation_failed_xml(cxobj **xret, char *type, char *message);
97 int netconf_malformed_message(cbuf *cb, char *message);
98 int netconf_malformed_message_xml(cxobj **xret, char *message);
99 int netconf_data_not_unique_xml(cxobj **xret, cxobj *x,	cvec *cvk);
100 int netconf_minmax_elements_xml(cxobj **xret, cxobj *xp, char *name, int max);
101 int netconf_trymerge(cxobj *x, yang_stmt *yspec, cxobj **xret);
102 int netconf_module_features(clicon_handle h);
103 int netconf_module_load(clicon_handle h);
104 char *netconf_db_find(cxobj *xn, char *name);
105 int netconf_err2cb(cxobj *xerr, cbuf *cberr);
106 const netconf_content netconf_content_str2int(char *str);
107 const char *netconf_content_int2str(netconf_content nr);
108 int netconf_hello_server(clicon_handle h, cbuf *cb, uint32_t session_id);
109 int netconf_hello_req(clicon_handle h, cbuf *cb);
110 int clixon_netconf_error_fn(const char *fn, const int line, cxobj *xerr, const char *fmt, const char *arg);
111 int clixon_netconf_internal_error(cxobj *xerr, char *msg, char *arg);
112 
113 #endif /* _CLIXON_NETCONF_LIB_H */
114