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 | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 6 | * Copyright (c) 2015-2021 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 | 488f480 | 2018-09-07 13:04:41 +0200 | [diff] [blame] | 22 | #include <libyang/libyang.h> |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 23 | #include <stdint.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 | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 101 | * @param[in] paramtype Determines how the @p data parameter is treated. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 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 | f1c26c2 | 2021-04-12 16:34:33 +0200 | [diff] [blame] | 124 | * @brief Get last error from an ERROR rpc-reply object. |
Michal Vasko | aa2e5a7 | 2017-03-16 09:48:44 +0100 | [diff] [blame] | 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 | /** |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 173 | * @brief Get the \<error-type\> of a server error. |
| 174 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 175 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 176 | * @return Server error type, 0 on error. |
| 177 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 178 | NC_ERR_TYPE nc_err_get_type(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * @brief Get the \<error-tag\> of a server error. |
| 182 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 183 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 184 | * @return Server error tag, 0 on error. |
| 185 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 186 | NC_ERR nc_err_get_tag(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 187 | |
| 188 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 189 | * @brief Set the \<error-app-tag\> element of an error. Any previous value will be overwritten. |
| 190 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 191 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 192 | * @param[in] error_app_tag New value of \<error-app-tag\>. |
| 193 | * @return 0 on success, -1 on error. |
| 194 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 195 | 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] | 196 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 197 | /** |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 198 | * @brief Get the \<error-app-tag\> of a server error. |
| 199 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 200 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 201 | * @return Server error app tag, NULL on error. |
| 202 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 203 | const char *nc_err_get_app_tag(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 204 | |
| 205 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 206 | * @brief Set the \<error-path\> element of an error. Any previous value will be overwritten. |
| 207 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 208 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 209 | * @param[in] error_path New value of \<error-path\>. |
| 210 | * @return 0 on success, -1 on error. |
| 211 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 212 | 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] | 213 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 214 | /** |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 215 | * @brief Get the \<error-path\> of a server error. |
| 216 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 217 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 218 | * @return Server error path, NULL on error. |
| 219 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 220 | const char *nc_err_get_path(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 221 | |
| 222 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 223 | * @brief Set the \<error-message\> element of an error. Any previous value will be overwritten. |
| 224 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 225 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 226 | * @param[in] error_message New value of \<error-message\>. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 227 | * @param[in] lang Optional language of @p error_message. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 228 | * @return 0 on success, -1 on error. |
| 229 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 230 | 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] | 231 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 232 | /** |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 233 | * @brief Get the \<error-message\> of a server error. |
| 234 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 235 | * @param[in] err Error opaque data node tree to read from. |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 236 | * @return Server error message, NULL on error. |
| 237 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 238 | const char *nc_err_get_msg(const struct lyd_node *err); |
Michal Vasko | 8f3198f | 2016-05-04 10:45:28 +0200 | [diff] [blame] | 239 | |
| 240 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 241 | * @brief Set the \<session-id\> element of an error. Any previous value will be overwritten. |
| 242 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 243 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 244 | * @param[in] session_id New value of \<session-id\>. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 245 | * @return 0 on success, -1 on error. |
| 246 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 247 | 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] | 248 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 249 | /** |
| 250 | * @brief Add a \<bad-attribute\> element to an error. |
| 251 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 252 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 253 | * @param[in] attr_name Value of the new \<bad-attribute\> element. |
| 254 | * @return 0 on success, -1 on error. |
| 255 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 256 | 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] | 257 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 258 | /** |
| 259 | * @brief Add a \<bad-element\> element to an error. |
| 260 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 261 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 262 | * @param[in] elem_name Value of the new \<bad-element\> element. |
| 263 | * @return 0 on success, -1 on error. |
| 264 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 265 | 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] | 266 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 267 | /** |
| 268 | * @brief Add a \<bad-namespace\> element to an error. |
| 269 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 270 | * @param[in] err Error opaque data node tree to modify. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 271 | * @param[in] ns_name Value of the new \<bad-namespace\> element. |
| 272 | * @return 0 on success, -1 on error. |
| 273 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 274 | 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] | 275 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 276 | /** |
| 277 | * @brief Add an additional custom element to an error. |
| 278 | * |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 279 | * @param[in] err Error opaque data node tree to modify. |
| 280 | * @param[in] other Other error opaque data node tree. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 281 | * @return 0 on success, -1 on error. |
| 282 | */ |
Michal Vasko | 7736745 | 2021-02-16 16:32:18 +0100 | [diff] [blame] | 283 | 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] | 284 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 285 | /** |
| 286 | * @brief Free a server rpc-reply object. |
| 287 | * |
| 288 | * @param[in] reply Server rpc-reply object to free. |
| 289 | */ |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 290 | void nc_server_reply_free(struct nc_server_reply *reply); |
| 291 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 292 | /** |
Radek Krejci | 93e8022 | 2016-10-03 13:34:25 +0200 | [diff] [blame] | 293 | * @brief Create Event Notification object to be sent to the subscribed client(s). |
| 294 | * |
| 295 | * @param[in] event Notification data tree (valid as LYD_OPT_NOTIF) from libyang. The tree is directly used in created |
| 296 | * object, so the caller is supposed to not free the tree on its own, but only via freeng the created object. |
| 297 | * @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] | 298 | * 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] | 299 | * @param[in] paramtype How to further manage data parameters. |
Radek Krejci | 93e8022 | 2016-10-03 13:34:25 +0200 | [diff] [blame] | 300 | * @return Newly created structure of the Event Notification object to be sent to the clients via nc_server_send_notif() |
| 301 | * and freed using nc_server_notif_free(). |
| 302 | */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 303 | 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] | 304 | |
| 305 | /** |
| 306 | * @brief Send NETCONF Event Notification via the session. |
| 307 | * |
| 308 | * @param[in] session NETCONF session where the Event Notification will be written. |
| 309 | * @param[in] notif NETCOFN Notification object to send via specified session. Object can be created by |
| 310 | * nc_notif_new() function. |
| 311 | * @param[in] timeout Timeout for writing in milliseconds. Use negative value for infinite |
| 312 | * waiting and 0 for return if data cannot be sent immediately. |
| 313 | * @return #NC_MSG_NOTIF on success, |
| 314 | * #NC_MSG_WOULDBLOCK in case of a busy session, and |
| 315 | * #NC_MSG_ERROR on error. |
| 316 | */ |
| 317 | NC_MSG_TYPE nc_server_notif_send(struct nc_session *session, struct nc_server_notif *notif, int timeout); |
| 318 | |
| 319 | /** |
| 320 | * @brief Free a server Event Notification object. |
| 321 | * |
| 322 | * @param[in] notif Server Event Notification object to free. |
| 323 | */ |
| 324 | void nc_server_notif_free(struct nc_server_notif *notif); |
| 325 | |
Michal Vasko | 9a2e4d2 | 2017-03-17 09:44:49 +0100 | [diff] [blame] | 326 | /** |
| 327 | * @brief Get the notification timestamp. |
| 328 | * |
| 329 | * @param[in] notif Server notification to read from. |
| 330 | * @return Datetime timestamp of the notification, NULL on error. |
| 331 | */ |
| 332 | const char *nc_server_notif_get_time(const struct nc_server_notif *notif); |
| 333 | |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 334 | /** @} Client Messages */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 335 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 336 | #ifdef __cplusplus |
| 337 | } |
| 338 | #endif |
| 339 | |
Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame] | 340 | #endif /* NC_MESSAGES_SERVER_H_ */ |