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