blob: 4ee1d116717c7e9844be4a286f9348b44ce0abb5 [file] [log] [blame]
Michal Vasko7bcb48e2016-01-15 10:28:54 +01001/**
2 * \file messages_server.h
3 * \author Michal Vasko <mvasko@cesnet.cz>
4 * \brief libnetconf2's functions and structures of server NETCONF messages.
5 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of the Company nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 */
22
23#ifndef NC_MESSAGES_SERVER_H_
24#define NC_MESSAGES_SERVER_H_
25
26#include <stdint.h>
27
28#include "netconf.h"
29
Michal Vaskof0537d82016-01-29 14:42:38 +010030/**
31 * @brief Enumeration of NETCONF errors
32 */
Michal Vasko495c9462016-01-15 11:27:43 +010033typedef enum NC_ERROR {
Michal Vaskof0537d82016-01-29 14:42:38 +010034 NC_ERR_UNKNOWN = 0, /**< unknown error */
35 NC_ERR_IN_USE, /**< in-use error */
36 NC_ERR_INVALID_VALUE, /**< invalid-value error */
37 NC_ERR_TOO_BIG, /**< too-big error */
38 NC_ERR_MISSING_ATTR, /**< missing-attribute error */
39 NC_ERR_BAD_ATTR, /**< bad-attribute error */
40 NC_ERR_UNKNOWN_ATTR, /**< unknown-attribute error */
41 NC_ERR_MISSING_ELEM, /**< missing-element error */
42 NC_ERR_BAD_ELEM, /**< bad-element error */
43 NC_ERR_UNKNOWN_ELEM, /**< unknown-element error */
44 NC_ERR_UNKNOWN_NS, /**< unknown-namespace error */
45 NC_ERR_ACCESS_DENIED, /**< access-denied error */
46 NC_ERR_LOCK_DENIED, /**< lock-denied error */
47 NC_ERR_RES_DENIED, /**< resource-denied error */
48 NC_ERR_ROLLBACK_FAILED, /**< rollback-failed error */
49 NC_ERR_DATA_EXISTS, /**< data-exists error */
50 NC_ERR_DATA_MISSING, /**< data-missing error */
51 NC_ERR_OP_NOT_SUPPORTED, /**< operation-not-supported error */
52 NC_ERR_OP_FAILED, /**< operation-failed error */
53 NC_ERR_MALFORMED_MSG /**< malformed-message error */
Michal Vasko7bcb48e2016-01-15 10:28:54 +010054} NC_ERR;
55
Michal Vaskof0537d82016-01-29 14:42:38 +010056/**
57 * @brief Enumeration of NETCONF error type (layer)
58 */
Michal Vasko495c9462016-01-15 11:27:43 +010059typedef enum NC_ERROR_TYPE {
Michal Vaskof0537d82016-01-29 14:42:38 +010060 NC_ERR_TYPE_UNKNOWN = 0, /**< unknown layer */
61 NC_ERR_TYPE_TRAN, /**< transport layer */
62 NC_ERR_TYPE_RPC, /**< RPC layer */
63 NC_ERR_TYPE_PROT, /**< protocol layer */
64 NC_ERR_TYPE_APP /**< application layer */
Michal Vasko7bcb48e2016-01-15 10:28:54 +010065} NC_ERR_TYPE;
66
67/**
Michal Vasko1a38c862016-01-15 15:50:07 +010068 * @brief NETCONF server rpc-reply object
Michal Vasko7bcb48e2016-01-15 10:28:54 +010069 */
70struct nc_server_reply;
71
Michal Vasko1a38c862016-01-15 15:50:07 +010072/**
73 * @brief NETCONF server error structure
74 */
Michal Vasko7bcb48e2016-01-15 10:28:54 +010075struct nc_server_error;
76
Michal Vasko1a38c862016-01-15 15:50:07 +010077/**
78 * @brief Create an OK rpc-reply object.
79 *
80 * @return rpc-reply object, NULL on error.
81 */
Michal Vasko7bcb48e2016-01-15 10:28:54 +010082struct nc_server_reply *nc_server_reply_ok(void);
83
Michal Vasko1a38c862016-01-15 15:50:07 +010084/**
85 * @brief Create a DATA rpc-reply object.
86 *
87 * @param[in] data Tree with the data.
88 * @param[in] paramtype Determines how the \p data parameter is treated.
89 * @return rpc-reply object, NULL on error.
90 */
Michal Vasko7bcb48e2016-01-15 10:28:54 +010091struct nc_server_reply *nc_server_reply_data(struct lyd_node *data, NC_PARAMTYPE paramtype);
92
Michal Vasko1a38c862016-01-15 15:50:07 +010093/**
94 * @brief Create an ERROR rpc-reply object.
95 *
96 * @param[in] err Structure holding the error information. It will be freed with the returned object.
97 * @return rpc-reply object, NULL on error.
98 */
99struct nc_server_reply *nc_server_reply_err(struct nc_server_error *err);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100100
Michal Vasko1a38c862016-01-15 15:50:07 +0100101/**
102 * @brief Add another error to an ERROR rpc-reply object. It will be freed with the returned object.
103 *
104 * @param[in] reply ERROR reply to add to.
105 * @param[in] err Structure holding the additional error information.
106 * @return 0 on success, -1 on errror.
107 */
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100108int nc_server_reply_add_err(struct nc_server_reply *reply, struct nc_server_error *err);
109
Michal Vasko1a38c862016-01-15 15:50:07 +0100110/**
111 * @brief Create a server error structure. Its \<error-message\> is filled with
112 * a general description of the specific error.
113 *
114 * @param[in] tag \<error-tag\> of the server error. According to the tag, the
115 * specific additional parameters are required:
116 * - #NC_ERR_IN_USE
117 * - #NC_ERR_INVALID_VALUE
118 * - #NC_ERR_ACCESS_DENIED
119 * - #NC_ERR_ROLLBACK_FAILED
Michal Vaskof0537d82016-01-29 14:42:38 +0100120 * - #NC_ERR_OP_NOT_SUPPORTED
Michal Vasko1a38c862016-01-15 15:50:07 +0100121 * - #NC_ERR_TOO_BIG
122 * - #NC_ERR_RES_DENIED
123 * - #NC_ERR_OP_FAILED
124 * - `NC_ERR_TYPE type;` - type (layer) of the error.
125 * - #NC_ERR_MISSING_ATTR
126 * - #NC_ERR_BAD_ATTR
127 * - #NC_ERR_UNKNOWN_ATTR
128 * - `NC_ERR_TYPE type;` - type (layer) of the error.
129 * - `const char *attr_name;` - error \<bad-attribute\> value.
130 * - `const char *elem_name;` - error \<bad-element\> value.
131 * - #NC_ERR_MISSING_ELEM
132 * - #NC_ERR_BAD_ELEM
133 * - #NC_ERR_UNKNOWN_ELEM
134 * - `NC_ERR_TYPE type;` - type (layer) of the error.
135 * - `const char *elem_name;` - error \<bad-element\> value.
136 * - #NC_ERR_UNKNOWN_NS
137 * - `NC_ERR_TYPE type;` - type (layer) of the error.
138 * - `const char *elem_name;` - error \<bad-element\> value.
139 * - `const char *nc_name;` - error \<bad-namespace\> value.
140 * - #NC_ERR_LOCK_DENIED
141 * - `uint32_t session_id;` - error \<session-id\> value.
142 * - #NC_ERR_DATA_EXISTS
143 * - #NC_ERR_DATA_MISSING
Michal Vaskof0537d82016-01-29 14:42:38 +0100144 * - #NC_ERR_MALFORMED_MSG
Michal Vasko1a38c862016-01-15 15:50:07 +0100145 * - no additional arguments
146 * @return Server error structure, NULL on error.
147 */
148struct nc_server_error *nc_err(NC_ERR tag, ...);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100149
Michal Vasko1a38c862016-01-15 15:50:07 +0100150/**
151 * @brief Set the \<error-app-tag\> element of an error. Any previous value will be overwritten.
152 *
153 * @param[in] err Error to modify.
154 * @param[in] error_app_tag New value of \<error-app-tag\>.
155 * @return 0 on success, -1 on error.
156 */
157int nc_err_set_app_tag(struct nc_server_error *err, const char *error_app_tag);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100158
Michal Vasko1a38c862016-01-15 15:50:07 +0100159/**
160 * @brief Set the \<error-path\> element of an error. Any previous value will be overwritten.
161 *
162 * @param[in] err Error to modify.
163 * @param[in] error_path New value of \<error-path\>.
164 * @return 0 on success, -1 on error.
165 */
166int nc_err_set_path(struct nc_server_error *err, const char *error_path);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100167
Michal Vasko1a38c862016-01-15 15:50:07 +0100168/**
169 * @brief Set the \<error-message\> element of an error. Any previous value will be overwritten.
170 *
171 * @param[in] err Error to modify.
172 * @param[in] error_message New value of \<error-message\>.
Michal Vaskof0537d82016-01-29 14:42:38 +0100173 * @param[in] lang Optional language of \p error_message.
Michal Vasko1a38c862016-01-15 15:50:07 +0100174 * @return 0 on success, -1 on error.
175 */
176int nc_err_set_msg(struct nc_server_error *err, const char *error_message, const char *lang);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100177
Michal Vasko1a38c862016-01-15 15:50:07 +0100178/**
179 * @brief Set the \<session-id\> element of an error. Any previous value will be overwritten.
180 *
181 * @param[in] err Error to modify.
Michal Vaskof0537d82016-01-29 14:42:38 +0100182 * @param[in] session_id New value of \<session-id\>.
Michal Vasko1a38c862016-01-15 15:50:07 +0100183 * @return 0 on success, -1 on error.
184 */
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100185int nc_err_set_sid(struct nc_server_error *err, uint32_t session_id);
186
Michal Vasko1a38c862016-01-15 15:50:07 +0100187/**
188 * @brief Add a \<bad-attribute\> element to an error.
189 *
190 * @param[in] err Error to modify.
191 * @param[in] attr_name Value of the new \<bad-attribute\> element.
192 * @return 0 on success, -1 on error.
193 */
194int nc_err_add_bad_attr(struct nc_server_error *err, const char *attr_name);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100195
Michal Vasko1a38c862016-01-15 15:50:07 +0100196/**
197 * @brief Add a \<bad-element\> element to an error.
198 *
199 * @param[in] err Error to modify.
200 * @param[in] elem_name Value of the new \<bad-element\> element.
201 * @return 0 on success, -1 on error.
202 */
203int nc_err_add_bad_elem(struct nc_server_error *err, const char *elem_name);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100204
Michal Vasko1a38c862016-01-15 15:50:07 +0100205/**
206 * @brief Add a \<bad-namespace\> element to an error.
207 *
208 * @param[in] err Error to modify.
209 * @param[in] ns_name Value of the new \<bad-namespace\> element.
210 * @return 0 on success, -1 on error.
211 */
212int nc_err_add_bad_ns(struct nc_server_error *err, const char *ns_name);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100213
Michal Vasko1a38c862016-01-15 15:50:07 +0100214/**
215 * @brief Add an additional custom element to an error.
216 *
217 * @param[in] err Error to modify.
218 * @param[in] other New custom XML element.
219 * @return 0 on success, -1 on error.
220 */
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100221int nc_err_add_info_other(struct nc_server_error *err, struct lyxml_elem *other);
222
Michal Vasko1a38c862016-01-15 15:50:07 +0100223/**
224 * @brief Free a server rpc-reply object.
225 *
226 * @param[in] reply Server rpc-reply object to free.
227 */
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100228void nc_server_reply_free(struct nc_server_reply *reply);
229
Michal Vasko1a38c862016-01-15 15:50:07 +0100230/**
231 * @brief Free a server error structure.
232 *
233 * @param[in] err Error structure to free.
234 */
235void nc_err_free(struct nc_server_error *err);
Michal Vasko7bcb48e2016-01-15 10:28:54 +0100236
237#endif /* NC_MESSAGES_SERVER_H_ */