Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file messages_server.h |
| 3 | * \author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * \brief libnetconf2's functions and structures of server NETCONF messages. |
| 5 | * |
Michal Vasko | fc9dbdd | 2017-03-17 09:27:57 +0100 | [diff] [blame] | 6 | * Copyright (c) 2015-2017 CESNET, z.s.p.o. |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 7 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Michal Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef NC_MESSAGES_SERVER_H_ |
| 16 | #define NC_MESSAGES_SERVER_H_ |
| 17 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 22 | #include <stdint.h> |
Michal Vasko | 488f480 | 2018-09-07 13:04:41 +0200 | [diff] [blame] | 23 | #include <libyang/libyang.h> |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 24 | |
| 25 | #include "netconf.h" |
Radek Krejci | 93e8022 | 2016-10-03 13:34:25 +0200 | [diff] [blame] | 26 | #include "session.h" |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 27 | |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 28 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 29 | * @defgroup server_msg Server Messages |
| 30 | * @ingroup server |
| 31 | * |
| 32 | * @brief Functions to create NETCONF Event notifications and replies to the NETCONF RPCs (or actions). |
| 33 | * @{ |
| 34 | */ |
| 35 | |
| 36 | /** |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 37 | * @brief Enumeration of NETCONF errors |
| 38 | */ |
Michal Vasko | 495c946 | 2016-01-15 11:27:43 +0100 | [diff] [blame] | 39 | typedef enum NC_ERROR { |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 40 | NC_ERR_UNKNOWN = 0, /**< unknown error */ |
| 41 | NC_ERR_IN_USE, /**< in-use error */ |
| 42 | NC_ERR_INVALID_VALUE, /**< invalid-value error */ |
| 43 | NC_ERR_TOO_BIG, /**< too-big error */ |
| 44 | NC_ERR_MISSING_ATTR, /**< missing-attribute error */ |
| 45 | NC_ERR_BAD_ATTR, /**< bad-attribute error */ |
| 46 | NC_ERR_UNKNOWN_ATTR, /**< unknown-attribute error */ |
| 47 | NC_ERR_MISSING_ELEM, /**< missing-element error */ |
| 48 | NC_ERR_BAD_ELEM, /**< bad-element error */ |
| 49 | NC_ERR_UNKNOWN_ELEM, /**< unknown-element error */ |
| 50 | NC_ERR_UNKNOWN_NS, /**< unknown-namespace error */ |
| 51 | NC_ERR_ACCESS_DENIED, /**< access-denied error */ |
| 52 | NC_ERR_LOCK_DENIED, /**< lock-denied error */ |
| 53 | NC_ERR_RES_DENIED, /**< resource-denied error */ |
| 54 | NC_ERR_ROLLBACK_FAILED, /**< rollback-failed error */ |
| 55 | NC_ERR_DATA_EXISTS, /**< data-exists error */ |
| 56 | NC_ERR_DATA_MISSING, /**< data-missing error */ |
| 57 | NC_ERR_OP_NOT_SUPPORTED, /**< operation-not-supported error */ |
| 58 | NC_ERR_OP_FAILED, /**< operation-failed error */ |
| 59 | NC_ERR_MALFORMED_MSG /**< malformed-message error */ |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 60 | } NC_ERR; |
| 61 | |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 62 | /** |
| 63 | * @brief Enumeration of NETCONF error type (layer) |
| 64 | */ |
Michal Vasko | 495c946 | 2016-01-15 11:27:43 +0100 | [diff] [blame] | 65 | typedef enum NC_ERROR_TYPE { |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 66 | NC_ERR_TYPE_UNKNOWN = 0, /**< unknown layer */ |
| 67 | NC_ERR_TYPE_TRAN, /**< transport layer */ |
| 68 | NC_ERR_TYPE_RPC, /**< RPC layer */ |
| 69 | NC_ERR_TYPE_PROT, /**< protocol layer */ |
| 70 | NC_ERR_TYPE_APP /**< application layer */ |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 71 | } NC_ERR_TYPE; |
| 72 | |
| 73 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 74 | * @brief NETCONF server rpc-reply object |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 75 | */ |
| 76 | struct nc_server_reply; |
| 77 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 78 | /** |
Radek Krejci | 93e8022 | 2016-10-03 13:34:25 +0200 | [diff] [blame] | 79 | * @brief NETCONF server Event Notification object |
| 80 | */ |
| 81 | struct nc_server_notif; |
| 82 | |
| 83 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 84 | * @brief NETCONF server error structure |
| 85 | */ |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 86 | struct nc_server_error; |
| 87 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 88 | /** |
| 89 | * @brief Create an OK rpc-reply object. |
| 90 | * |
| 91 | * @return rpc-reply object, NULL on error. |
| 92 | */ |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 93 | struct nc_server_reply *nc_server_reply_ok(void); |
| 94 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 95 | /** |
| 96 | * @brief Create a DATA rpc-reply object. |
| 97 | * |
Michal Vasko | b08743b | 2016-04-13 14:23:49 +0200 | [diff] [blame] | 98 | * @param[in] data Reply data tree. This tree must be valid according to |
| 99 | * the RPC output of the RPC this is a reply to. |
Radek Krejci | 36dfdb3 | 2016-09-01 16:56:35 +0200 | [diff] [blame] | 100 | * @param[in] wd with-default mode if applicable |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 101 | * @param[in] paramtype Determines how the \p data parameter is treated. |
| 102 | * @return rpc-reply object, NULL on error. |
| 103 | */ |
Radek Krejci | 36dfdb3 | 2016-09-01 16:56:35 +0200 | [diff] [blame] | 104 | struct nc_server_reply *nc_server_reply_data(struct lyd_node *data, NC_WD_MODE wd, NC_PARAMTYPE paramtype); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 105 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 106 | /** |
| 107 | * @brief Create an ERROR rpc-reply object. |
| 108 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 109 | * @param[in] err Errors as opaque data node tree. It will be freed with the returned object. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 110 | * @return rpc-reply object, NULL on error. |
| 111 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 112 | struct nc_server_reply *nc_server_reply_err(struct lyd_node *err); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 113 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 114 | /** |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 115 | * @brief Add another error opaque data node tree to an ERROR rpc-reply object. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 116 | * |
| 117 | * @param[in] reply ERROR reply to add to. |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 118 | * @param[in] err Error as opaque data node tree. It will be freed with the returned object. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 119 | * @return 0 on success, -1 on errror. |
| 120 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 121 | int nc_server_reply_add_err(struct nc_server_reply *reply, struct lyd_node *err); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 122 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 123 | /** |
Michal Vasko | aa2e5a7 | 2017-03-16 09:48:44 +0100 | [diff] [blame] | 124 | * @brief Get last error from an ERROR rpy-reply object. |
| 125 | * |
| 126 | * @param[in] reply ERROR reply to read from. |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 127 | * @return Last error opaque data tree, NULL on failure. |
Michal Vasko | aa2e5a7 | 2017-03-16 09:48:44 +0100 | [diff] [blame] | 128 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 129 | const struct lyd_node *nc_server_reply_get_last_err(const struct nc_server_reply *reply); |
Michal Vasko | aa2e5a7 | 2017-03-16 09:48:44 +0100 | [diff] [blame] | 130 | |
| 131 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 132 | * @brief Create a server error structure. Its \<error-message\> is filled with |
| 133 | * a general description of the specific error. |
| 134 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 135 | * @param[in] ctx libyang context to use. |
Radek Krejci | 127f895 | 2016-10-12 14:57:16 +0200 | [diff] [blame] | 136 | * @param[in] tag \<error-tag\> of the server error specified as #NC_ERR value. According to the tag, the |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 137 | * specific additional parameters are required: |
| 138 | * - #NC_ERR_IN_USE |
| 139 | * - #NC_ERR_INVALID_VALUE |
| 140 | * - #NC_ERR_ACCESS_DENIED |
| 141 | * - #NC_ERR_ROLLBACK_FAILED |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 142 | * - #NC_ERR_OP_NOT_SUPPORTED |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 143 | * - #NC_ERR_TOO_BIG |
| 144 | * - #NC_ERR_RES_DENIED |
| 145 | * - #NC_ERR_OP_FAILED |
| 146 | * - `NC_ERR_TYPE type;` - type (layer) of the error. |
| 147 | * - #NC_ERR_MISSING_ATTR |
| 148 | * - #NC_ERR_BAD_ATTR |
| 149 | * - #NC_ERR_UNKNOWN_ATTR |
| 150 | * - `NC_ERR_TYPE type;` - type (layer) of the error. |
| 151 | * - `const char *attr_name;` - error \<bad-attribute\> value. |
| 152 | * - `const char *elem_name;` - error \<bad-element\> value. |
| 153 | * - #NC_ERR_MISSING_ELEM |
| 154 | * - #NC_ERR_BAD_ELEM |
| 155 | * - #NC_ERR_UNKNOWN_ELEM |
| 156 | * - `NC_ERR_TYPE type;` - type (layer) of the error. |
| 157 | * - `const char *elem_name;` - error \<bad-element\> value. |
| 158 | * - #NC_ERR_UNKNOWN_NS |
| 159 | * - `NC_ERR_TYPE type;` - type (layer) of the error. |
| 160 | * - `const char *elem_name;` - error \<bad-element\> value. |
| 161 | * - `const char *nc_name;` - error \<bad-namespace\> value. |
| 162 | * - #NC_ERR_LOCK_DENIED |
| 163 | * - `uint32_t session_id;` - error \<session-id\> value. |
| 164 | * - #NC_ERR_DATA_EXISTS |
| 165 | * - #NC_ERR_DATA_MISSING |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 166 | * - #NC_ERR_MALFORMED_MSG |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 167 | * - no additional arguments |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 168 | * @return Opaque data node tree representing the error. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 169 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 170 | struct lyd_node *nc_err(const struct ly_ctx *ctx, NC_ERR tag, ...); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 171 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 172 | /** |
Radek Krejci | 877e182 | 2016-04-06 16:37:43 +0200 | [diff] [blame] | 173 | * @brief Create a server error structure based on libyang error. |
| 174 | * |
| 175 | * The function should be used immediately when a libyang function fails to generate |
| 176 | * NETCONF error structure based on internal libyang error information (ly_errno, ly_errmsg, ...) |
| 177 | * |
Michal Vasko | c997024 | 2018-02-14 16:03:35 +0100 | [diff] [blame] | 178 | * @param[in] ctx Libyang context to read the error from. |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 179 | * @return Error opaque data node tree. |
Radek Krejci | 877e182 | 2016-04-06 16:37:43 +0200 | [diff] [blame] | 180 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 181 | struct lyd_node *nc_err_libyang(struct ly_ctx *ctx); |
Radek Krejci | 877e182 | 2016-04-06 16:37:43 +0200 | [diff] [blame] | 182 | |
| 183 | /** |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 184 | * @brief Get the \<error-type\> of a server error. |
| 185 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 186 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 187 | * @return Server error type, 0 on error. |
| 188 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 189 | NC_ERR_TYPE nc_err_get_type(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * @brief Get the \<error-tag\> of a server error. |
| 193 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 194 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 195 | * @return Server error tag, 0 on error. |
| 196 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 197 | NC_ERR nc_err_get_tag(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 198 | |
| 199 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 200 | * @brief Set the \<error-app-tag\> element of an error. Any previous value will be overwritten. |
| 201 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 202 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 203 | * @param[in] error_app_tag New value of \<error-app-tag\>. |
| 204 | * @return 0 on success, -1 on error. |
| 205 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 206 | int nc_err_set_app_tag(struct lyd_node *err, const char *error_app_tag); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 207 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 208 | /** |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 209 | * @brief Get the \<error-app-tag\> of a server error. |
| 210 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 211 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 212 | * @return Server error app tag, NULL on error. |
| 213 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 214 | const char *nc_err_get_app_tag(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 215 | |
| 216 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 217 | * @brief Set the \<error-path\> element of an error. Any previous value will be overwritten. |
| 218 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 219 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 220 | * @param[in] error_path New value of \<error-path\>. |
| 221 | * @return 0 on success, -1 on error. |
| 222 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 223 | int nc_err_set_path(struct lyd_node *err, const char *error_path); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 224 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 225 | /** |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 226 | * @brief Get the \<error-path\> of a server error. |
| 227 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 228 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 229 | * @return Server error path, NULL on error. |
| 230 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 231 | const char *nc_err_get_path(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 232 | |
| 233 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 234 | * @brief Set the \<error-message\> element of an error. Any previous value will be overwritten. |
| 235 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 236 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 237 | * @param[in] error_message New value of \<error-message\>. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 238 | * @param[in] lang Optional language of \p error_message. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 239 | * @return 0 on success, -1 on error. |
| 240 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 241 | int nc_err_set_msg(struct lyd_node *err, const char *error_message, const char *lang); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 242 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 243 | /** |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 244 | * @brief Get the \<error-message\> of a server error. |
| 245 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 246 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 247 | * @return Server error message, NULL on error. |
| 248 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 249 | const char *nc_err_get_msg(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 250 | |
| 251 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 252 | * @brief Set the \<session-id\> element of an error. Any previous value will be overwritten. |
| 253 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 254 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 255 | * @param[in] session_id New value of \<session-id\>. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 256 | * @return 0 on success, -1 on error. |
| 257 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 258 | int nc_err_set_sid(struct lyd_node *err, uint32_t session_id); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 259 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 260 | /** |
| 261 | * @brief Add a \<bad-attribute\> element to an error. |
| 262 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 263 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 264 | * @param[in] attr_name Value of the new \<bad-attribute\> element. |
| 265 | * @return 0 on success, -1 on error. |
| 266 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 267 | int nc_err_add_bad_attr(struct lyd_node *err, const char *attr_name); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 268 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 269 | /** |
| 270 | * @brief Add a \<bad-element\> element to an error. |
| 271 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 272 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 273 | * @param[in] elem_name Value of the new \<bad-element\> element. |
| 274 | * @return 0 on success, -1 on error. |
| 275 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 276 | int nc_err_add_bad_elem(struct lyd_node *err, const char *elem_name); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 277 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 278 | /** |
| 279 | * @brief Add a \<bad-namespace\> element to an error. |
| 280 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 281 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 282 | * @param[in] ns_name Value of the new \<bad-namespace\> element. |
| 283 | * @return 0 on success, -1 on error. |
| 284 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 285 | int nc_err_add_bad_ns(struct lyd_node *err, const char *ns_name); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 286 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 287 | /** |
| 288 | * @brief Add an additional custom element to an error. |
| 289 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 290 | * @param[in] err Error opaque data node tree to modify. |
| 291 | * @param[in] other Other error opaque data node tree. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 292 | * @return 0 on success, -1 on error. |
| 293 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame^] | 294 | int nc_err_add_info_other(struct lyd_node *err, struct lyd_node *other); |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 295 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 296 | /** |
| 297 | * @brief Free a server rpc-reply object. |
| 298 | * |
| 299 | * @param[in] reply Server rpc-reply object to free. |
| 300 | */ |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 301 | void nc_server_reply_free(struct nc_server_reply *reply); |
| 302 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 303 | /** |
Radek Krejci | 93e8022 | 2016-10-03 13:34:25 +0200 | [diff] [blame] | 304 | * @brief Create Event Notification object to be sent to the subscribed client(s). |
| 305 | * |
| 306 | * @param[in] event Notification data tree (valid as LYD_OPT_NOTIF) from libyang. The tree is directly used in created |
| 307 | * object, so the caller is supposed to not free the tree on its own, but only via freeng the created object. |
| 308 | * @param[in] eventtime YANG dateTime format value of the time when the event was generated by the event source. |
Michal Vasko | fc9dbdd | 2017-03-17 09:27:57 +0100 | [diff] [blame] | 309 | * Caller can use nc_time2datetime() to create the value from the time_t value. |
| 310 | * @param[in] paramtype How to further manage data parameters. |
Radek Krejci | 93e8022 | 2016-10-03 13:34:25 +0200 | [diff] [blame] | 311 | * @return Newly created structure of the Event Notification object to be sent to the clients via nc_server_send_notif() |
| 312 | * and freed using nc_server_notif_free(). |
| 313 | */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 314 | struct nc_server_notif *nc_server_notif_new(struct lyd_node *event, char *eventtime, NC_PARAMTYPE paramtype); |
Radek Krejci | 93e8022 | 2016-10-03 13:34:25 +0200 | [diff] [blame] | 315 | |
| 316 | /** |
| 317 | * @brief Send NETCONF Event Notification via the session. |
| 318 | * |
| 319 | * @param[in] session NETCONF session where the Event Notification will be written. |
| 320 | * @param[in] notif NETCOFN Notification object to send via specified session. Object can be created by |
| 321 | * nc_notif_new() function. |
| 322 | * @param[in] timeout Timeout for writing in milliseconds. Use negative value for infinite |
| 323 | * waiting and 0 for return if data cannot be sent immediately. |
| 324 | * @return #NC_MSG_NOTIF on success, |
| 325 | * #NC_MSG_WOULDBLOCK in case of a busy session, and |
| 326 | * #NC_MSG_ERROR on error. |
| 327 | */ |
| 328 | NC_MSG_TYPE nc_server_notif_send(struct nc_session *session, struct nc_server_notif *notif, int timeout); |
| 329 | |
| 330 | /** |
| 331 | * @brief Free a server Event Notification object. |
| 332 | * |
| 333 | * @param[in] notif Server Event Notification object to free. |
| 334 | */ |
| 335 | void nc_server_notif_free(struct nc_server_notif *notif); |
| 336 | |
Michal Vasko | 9a2e4d2 | 2017-03-17 09:44:49 +0100 | [diff] [blame] | 337 | /** |
| 338 | * @brief Get the notification timestamp. |
| 339 | * |
| 340 | * @param[in] notif Server notification to read from. |
| 341 | * @return Datetime timestamp of the notification, NULL on error. |
| 342 | */ |
| 343 | const char *nc_server_notif_get_time(const struct nc_server_notif *notif); |
| 344 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 345 | /**@} Client Messages */ |
| 346 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 347 | #ifdef __cplusplus |
| 348 | } |
| 349 | #endif |
| 350 | |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 351 | #endif /* NC_MESSAGES_SERVER_H_ */ |