Michal Vasko | 7bcb48e | 2016-01-15 10:28:54 +0100 | [diff] [blame^] | 1 | /** |
| 2 | * \file messages_client.h |
| 3 | * \author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * \author Michal Vasko <mvasko@cesnet.cz> |
| 5 | * \brief libnetconf2's public functions and structures of NETCONF client messages. |
| 6 | * |
| 7 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * 3. Neither the name of the Company nor the names of its contributors |
| 19 | * may be used to endorse or promote products derived from this |
| 20 | * software without specific prior written permission. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #ifndef NC_MESSAGES_CLIENT_H_ |
| 25 | #define NC_MESSAGES_CLIENT_H_ |
| 26 | |
| 27 | #include <stdint.h> |
| 28 | |
| 29 | #include "netconf.h" |
| 30 | |
| 31 | typedef enum { |
| 32 | NC_RPC_GENERIC, /**< user-defined generic RPC. */ |
| 33 | |
| 34 | /* ietf-netconf */ |
| 35 | NC_RPC_GETCONFIG, /**< \<get-config\> RPC. */ |
| 36 | NC_RPC_EDIT, /**< \<edit-config\> RPC. */ |
| 37 | NC_RPC_COPY, /**< \<copy-config\> RPC. */ |
| 38 | NC_RPC_DELETE, /**< \<delete-config\> RPC. */ |
| 39 | NC_RPC_LOCK, /**< \<lock\> RPC. */ |
| 40 | NC_RPC_UNLOCK, /**< \<unlock\> RPC. */ |
| 41 | NC_RPC_GET, /**< \<get\> RPC. */ |
| 42 | /* NC_RPC_CLOSE is not defined since sending \<close-session\> is done by nc_session_free() */ |
| 43 | NC_RPC_KILL, /**< \<kill-session\> RPC. */ |
| 44 | NC_RPC_COMMIT, /**< \<commit\> RPC. */ |
| 45 | NC_RPC_DISCARD, /**< \<discard-changes\> RPC. */ |
| 46 | NC_RPC_CANCEL, /**< \<cancel-commit\> RPC. */ |
| 47 | NC_RPC_VALIDATE, /**< \<validate\> RPC. */ |
| 48 | |
| 49 | /* ietf-netconf-monitoring */ |
| 50 | NC_RPC_GETSCHEMA, /**< \<get-schema\> RPC. */ |
| 51 | |
| 52 | /* notifications */ |
| 53 | NC_RPC_SUBSCRIBE /**< \<create-subscription\> RPC. */ |
| 54 | } NC_RPC_TYPE; |
| 55 | |
| 56 | typedef enum { |
| 57 | NC_RPC_EDIT_DFLTOP_UNKNOWN = 0, |
| 58 | NC_RPC_EDIT_DFLTOP_MERGE, |
| 59 | NC_RPC_EDIT_DFLTOP_REPLACE, |
| 60 | NC_RPC_EDIT_DFLTOP_NONE |
| 61 | } NC_RPC_EDIT_DFLTOP; |
| 62 | |
| 63 | typedef enum { |
| 64 | NC_RPC_EDIT_TESTOPT_UNKNOWN = 0, |
| 65 | NC_RPC_EDIT_TESTOPT_TESTSET, |
| 66 | NC_RPC_EDIT_TESTOPT_SET, |
| 67 | NC_RPC_EDIT_TESTOPT_TEST |
| 68 | } NC_RPC_EDIT_TESTOPT; |
| 69 | |
| 70 | typedef enum { |
| 71 | NC_RPC_EDIT_ERROPT_UNKNOWN = 0, |
| 72 | NC_RPC_EDIT_ERROPT_STOP, |
| 73 | NC_RPC_EDIT_ERROPT_CONTINUE, |
| 74 | NC_RPC_EDIT_ERROPT_ROLLBACK |
| 75 | } NC_RPC_EDIT_ERROPT; |
| 76 | |
| 77 | /** |
| 78 | * @brief NETCONF error structure representation |
| 79 | */ |
| 80 | struct nc_err { |
| 81 | /** |
| 82 | * @brief \<error-type\>, error layer where the error occurred. |
| 83 | */ |
| 84 | const char *type; |
| 85 | /** |
| 86 | * @brief \<error-tag\>. |
| 87 | */ |
| 88 | const char *tag; |
| 89 | /** |
| 90 | * @brief \<error-severity\>. |
| 91 | */ |
| 92 | const char *severity; |
| 93 | /** |
| 94 | * @brief \<error-app-tag\>, the data-model-specific or implementation-specific error condition, if one exists. |
| 95 | */ |
| 96 | const char *apptag; |
| 97 | /** |
| 98 | * @brief \<error-path\>, XPATH expression identifying the element with the error. |
| 99 | */ |
| 100 | const char *path; |
| 101 | /** |
| 102 | * @brief \<error-message\>, Human-readable description of the error. |
| 103 | */ |
| 104 | const char *message; |
| 105 | const char *message_lang; |
| 106 | |
| 107 | /* <error-info> */ |
| 108 | |
| 109 | /** |
| 110 | * @brief \<session-id\>, session ID of the session holding the requested lock. |
| 111 | */ |
| 112 | const char *sid; |
| 113 | /** |
| 114 | * @brief \<bad-attr\>, the name of the data-model-specific XML attribute that caused the error. |
| 115 | */ |
| 116 | const char **attr; |
| 117 | uint16_t attr_count; |
| 118 | /** |
| 119 | * @brief \<bad-element\>, the name of the data-model-specific XML element that caused the error. |
| 120 | */ |
| 121 | const char **elem; |
| 122 | uint16_t elem_count; |
| 123 | /** |
| 124 | * @brief \<bad-namespace\>, the name of the unexpected XML namespace that caused the error. |
| 125 | */ |
| 126 | const char **ns; |
| 127 | uint16_t ns_count; |
| 128 | /** |
| 129 | * @brief Remaining non-standard elements. |
| 130 | */ |
| 131 | struct lyxml_elem **other; |
| 132 | uint16_t other_count; |
| 133 | }; |
| 134 | |
| 135 | /** |
| 136 | * @brief NETCONF client RPC object |
| 137 | */ |
| 138 | struct nc_rpc; |
| 139 | |
| 140 | struct nc_reply { |
| 141 | NC_RPL type; |
| 142 | }; |
| 143 | |
| 144 | struct nc_reply_data { |
| 145 | NC_RPL type; /**< NC_RPL_DATA */ |
| 146 | struct lyd_node *data; /**< libyang data tree */ |
| 147 | }; |
| 148 | |
| 149 | struct nc_reply_error { |
| 150 | NC_RPL type; /**< NC_RPL_ERROR */ |
| 151 | struct ly_ctx *ctx; |
| 152 | struct nc_err *err; /**< errors, any of the values inside can be NULL */ |
| 153 | uint32_t count; |
| 154 | }; |
| 155 | |
| 156 | struct nc_notif { |
| 157 | NC_RPL type; /**< NC_RPL_NOTIF */ |
| 158 | const char *datetime; /**< eventTime of the notification */ |
| 159 | struct lyd_node *tree; /**< libyang data tree of the message */ |
| 160 | }; |
| 161 | |
| 162 | /** |
| 163 | * @brief Get the type of the RPC |
| 164 | * |
| 165 | * @param[in] rpc RPC to check the type of. |
| 166 | * @return Type of \p rpc. |
| 167 | */ |
| 168 | NC_RPC_TYPE nc_rpc_get_type(const struct nc_rpc *rpc); |
| 169 | |
| 170 | /** |
| 171 | * @brief Create a generic NETCONF RPC |
| 172 | * |
| 173 | * Note that created object can be sent via any NETCONF session that shares the context |
| 174 | * of the \p data. |
| 175 | * |
| 176 | * @param[in] data NETCONF RPC data as a data tree. |
| 177 | * @param[in] paramtype How to further manage data parameters. |
| 178 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 179 | */ |
| 180 | struct nc_rpc *nc_rpc_generic(const struct lyd_node *data, NC_PARAMTYPE paramtype); |
| 181 | |
| 182 | /** |
| 183 | * @brief Create a generic NETCONF RPC from an XML string |
| 184 | * |
| 185 | * Note that functions to create any RPC object do not check validity of the provided |
| 186 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 187 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 188 | * check. Created object can be sent via any NETCONF session which supports all the |
| 189 | * needed NETCONF capabilities for the RPC. |
| 190 | * |
| 191 | * @param[in] xml_str NETCONF RPC data as an XML string. |
| 192 | * @param[in] paramtype How to further manage data parameters. |
| 193 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 194 | */ |
| 195 | struct nc_rpc *nc_rpc_generic_xml(const char *xml_str, NC_PARAMTYPE paramtype); |
| 196 | |
| 197 | /** |
| 198 | * @brief Create NETCONF RPC \<get-config\> |
| 199 | * |
| 200 | * Note that functions to create any RPC object do not check validity of the provided |
| 201 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 202 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 203 | * check. Created object can be sent via any NETCONF session which supports all the |
| 204 | * needed NETCONF capabilities for the RPC. |
| 205 | * |
| 206 | * @param[in] source Source datastore being queried. |
| 207 | * @param[in] filter Optional filter data, an XML subtree or XPath expression. |
| 208 | * @param[in] wd_mode Optional with-defaults capability mode. |
| 209 | * @param[in] paramtype How to further manage data parameters. |
| 210 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 211 | */ |
| 212 | struct nc_rpc *nc_rpc_getconfig(NC_DATASTORE source, const char *filter, NC_WD_MODE wd_mode, |
| 213 | NC_PARAMTYPE paramtype); |
| 214 | |
| 215 | /** |
| 216 | * @brief Create NETCONF RPC \<edit-config\> |
| 217 | * |
| 218 | * Note that functions to create any RPC object do not check validity of the provided |
| 219 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 220 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 221 | * check. Created object can be sent via any NETCONF session which supports all the |
| 222 | * needed NETCONF capabilities for the RPC. |
| 223 | * |
| 224 | * @param[in] target Target datastore being edited. |
| 225 | * @param[in] default_op Optional default operation. |
| 226 | * @param[in] test_opt Optional test option. |
| 227 | * @param[in] error_opt Optional error option. |
| 228 | * @param[in] edit_content Config or URL where the config to perform is to be found. |
| 229 | * @param[in] paramtype How to further manage data parameters. |
| 230 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 231 | */ |
| 232 | struct nc_rpc *nc_rpc_edit(NC_DATASTORE target, NC_RPC_EDIT_DFLTOP default_op, NC_RPC_EDIT_TESTOPT test_opt, |
| 233 | NC_RPC_EDIT_ERROPT error_opt, const char *edit_content, NC_PARAMTYPE paramtype); |
| 234 | |
| 235 | /** |
| 236 | * @brief Create NETCONF RPC \<copy-config\> |
| 237 | * |
| 238 | * Note that functions to create any RPC object do not check validity of the provided |
| 239 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 240 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 241 | * check. Created object can be sent via any NETCONF session which supports all the |
| 242 | * needed NETCONF capabilities for the RPC. |
| 243 | * |
| 244 | * @param[in] target Target datastore. |
| 245 | * @param[in] url_trg Used instead \p target if the target is an URL. |
| 246 | * @param[in] source Source datastore. |
| 247 | * @param[in] url_or_config_src Used instead \p source if the source is an URL or a config. |
| 248 | * @param[in] wd_mode Optional with-defaults capability mode. |
| 249 | * @param[in] paramtype How to further manage data parameters. |
| 250 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 251 | */ |
| 252 | struct nc_rpc *nc_rpc_copy(NC_DATASTORE target, const char *url_trg, NC_DATASTORE source, |
| 253 | const char *url_or_config_src, NC_WD_MODE wd_mode, NC_PARAMTYPE paramtype); |
| 254 | |
| 255 | /** |
| 256 | * @brief Create NETCONF RPC \<delete-config\> |
| 257 | * |
| 258 | * Note that functions to create any RPC object do not check validity of the provided |
| 259 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 260 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 261 | * check. Created object can be sent via any NETCONF session which supports all the |
| 262 | * needed NETCONF capabilities for the RPC. |
| 263 | * |
| 264 | * @param[in] target Target datastore to delete. |
| 265 | * @param[in] url Used instead \p target if the target is an URL. |
| 266 | * @param[in] paramtype How to further manage data parameters. |
| 267 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 268 | */ |
| 269 | struct nc_rpc *nc_rpc_delete(NC_DATASTORE target, const char *url, NC_PARAMTYPE paramtype); |
| 270 | |
| 271 | /** |
| 272 | * @brief Create NETCONF RPC \<lock\> |
| 273 | * |
| 274 | * Note that functions to create any RPC object do not check validity of the provided |
| 275 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 276 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 277 | * check. Created object can be sent via any NETCONF session which supports all the |
| 278 | * needed NETCONF capabilities for the RPC. |
| 279 | * |
| 280 | * @param[in] target Target datastore of the operation. |
| 281 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 282 | */ |
| 283 | struct nc_rpc *nc_rpc_lock(NC_DATASTORE target); |
| 284 | |
| 285 | /** |
| 286 | * @brief Create NETCONF RPC \<unlock\> |
| 287 | * |
| 288 | * Note that functions to create any RPC object do not check validity of the provided |
| 289 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 290 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 291 | * check. Created object can be sent via any NETCONF session which supports all the |
| 292 | * needed NETCONF capabilities for the RPC. |
| 293 | * |
| 294 | * @param[in] target Target datastore of the operation. |
| 295 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 296 | */ |
| 297 | struct nc_rpc *nc_rpc_unlock(NC_DATASTORE target); |
| 298 | |
| 299 | /** |
| 300 | * @brief Create NETCONF RPC \<get\> |
| 301 | * |
| 302 | * Note that functions to create any RPC object do not check validity of the provided |
| 303 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 304 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 305 | * check. Created object can be sent via any NETCONF session which supports all the |
| 306 | * needed NETCONF capabilities for the RPC. |
| 307 | * |
| 308 | * @param[in] filter Optional filter data, an XML subtree or XPath expression. |
| 309 | * @param[in] wd_mode Optional with-defaults capability mode. |
| 310 | * @param[in] paramtype How to further manage data parameters. |
| 311 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 312 | */ |
| 313 | struct nc_rpc *nc_rpc_get(const char *filter, NC_WD_MODE wd_mode, NC_PARAMTYPE paramtype); |
| 314 | |
| 315 | /** |
| 316 | * @brief Create NETCONF RPC \<kill-session\> |
| 317 | * |
| 318 | * Note that functions to create any RPC object do not check validity of the provided |
| 319 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 320 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 321 | * check. Created object can be sent via any NETCONF session which supports all the |
| 322 | * needed NETCONF capabilities for the RPC. |
| 323 | * |
| 324 | * @param[in] session_id Session ID of the session to kill. |
| 325 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 326 | */ |
| 327 | struct nc_rpc *nc_rpc_kill(uint32_t session_id); |
| 328 | |
| 329 | /** |
| 330 | * @brief Create NETCONF RPC \<commit\> |
| 331 | * |
| 332 | * Note that functions to create any RPC object do not check validity of the provided |
| 333 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 334 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 335 | * check. Created object can be sent via any NETCONF session which supports all the |
| 336 | * needed NETCONF capabilities for the RPC. |
| 337 | * |
| 338 | * @param[in] confirmed Whether the commit is to be confirmed. |
| 339 | * @param[in] confirm_timeout Optional confirm timeout. |
| 340 | * @param[in] persist Optional identification string of a new persistent confirmed commit. |
| 341 | * @param[in] persist_id Optional identification string of a persistent confirmed commit to be commited. |
| 342 | * @param[in] paramtype How to further manage data parameters. |
| 343 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 344 | */ |
| 345 | struct nc_rpc *nc_rpc_commit(int confirmed, uint32_t confirm_timeout, const char *persist, const char *persist_id, |
| 346 | NC_PARAMTYPE paramtype); |
| 347 | |
| 348 | /** |
| 349 | * @brief Create NETCONF RPC \<discard-changes\> |
| 350 | * |
| 351 | * Note that functions to create any RPC object do not check validity of the provided |
| 352 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 353 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 354 | * check. Created object can be sent via any NETCONF session which supports all the |
| 355 | * needed NETCONF capabilities for the RPC. |
| 356 | * |
| 357 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 358 | */ |
| 359 | struct nc_rpc *nc_rpc_discard(void); |
| 360 | |
| 361 | /** |
| 362 | * @brief Create NETCONF RPC \<cancel-commit\> |
| 363 | * |
| 364 | * Note that functions to create any RPC object do not check validity of the provided |
| 365 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 366 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 367 | * check. Created object can be sent via any NETCONF session which supports all the |
| 368 | * needed NETCONF capabilities for the RPC. |
| 369 | * |
| 370 | * @param[in] persist_id Optional identification string of a persistent confirmed commit. |
| 371 | * @param[in] paramtype How to further manage data parameters. |
| 372 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 373 | */ |
| 374 | struct nc_rpc *nc_rpc_cancel(const char *persist_id, NC_PARAMTYPE paramtype); |
| 375 | |
| 376 | /** |
| 377 | * @brief Create NETCONF RPC \<validate\> |
| 378 | * |
| 379 | * Note that functions to create any RPC object do not check validity of the provided |
| 380 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 381 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 382 | * check. Created object can be sent via any NETCONF session which supports all the |
| 383 | * needed NETCONF capabilities for the RPC. |
| 384 | * |
| 385 | * @param[in] source Source datastore being validated. |
| 386 | * @param[in] url_or_config Usedn instead \p source if the source is an URL or a config. |
| 387 | * @param[in] paramtype How to further manage data parameters. |
| 388 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 389 | */ |
| 390 | struct nc_rpc *nc_rpc_validate(NC_DATASTORE source, const char *url_or_config, NC_PARAMTYPE paramtype); |
| 391 | |
| 392 | /** |
| 393 | * @brief Create NETCONF RPC \<get-schema\> |
| 394 | * |
| 395 | * Note that functions to create any RPC object do not check validity of the provided |
| 396 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 397 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 398 | * check. Created object can be sent via any NETCONF session which supports all the |
| 399 | * needed NETCONF capabilities for the RPC. |
| 400 | * |
| 401 | * @param[in] identifier Requested model identifier. |
| 402 | * @param[in] version Optional model version, either YANG version (1.0/1.1) or revision date. |
| 403 | * @param[in] format Optional format of the model (default is YANG). |
| 404 | * @param[in] paramtype How to further manage data parameters. |
| 405 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 406 | */ |
| 407 | struct nc_rpc *nc_rpc_getschema(const char *identifier, const char *version, const char *format, NC_PARAMTYPE paramtype); |
| 408 | |
| 409 | /** |
| 410 | * @brief Create NETCONF RPC \<create-subscription\> |
| 411 | * |
| 412 | * Note that functions to create any RPC object do not check validity of the provided |
| 413 | * parameters. It is checked later while sending the RPC via a specific NETCONF session |
| 414 | * (nc_send_rpc()) since the NETCONF capabilities of the session are needed for such a |
| 415 | * check. Created object can be sent via any NETCONF session which supports all the |
| 416 | * needed NETCONF capabilities for the RPC. |
| 417 | * |
| 418 | * @param[in] stream_name Optional name of a NETCONF stream to subscribe to. |
| 419 | * @param[in] filter Optional filter data, an XML subtree or XPath expression. |
| 420 | * @param[in] start_time Optional YANG datetime identifying the start of the subscription. |
| 421 | * @param[in] stop_time Optional YANG datetime identifying the end of the subscription. |
| 422 | * @param[in] paramtype How to further manage data parameters. |
| 423 | * @return Created RPC object to send via a NETCONF session or NULL in case of (memory allocation) error. |
| 424 | */ |
| 425 | struct nc_rpc *nc_rpc_subscribe(const char *stream_name, const char *filter, const char *start_time, |
| 426 | const char *stop_time, NC_PARAMTYPE paramtype); |
| 427 | |
| 428 | /** |
| 429 | * @brief Free the NETCONF RPC object. |
| 430 | * @param[in] rpc Object to free. |
| 431 | */ |
| 432 | void nc_rpc_free(struct nc_rpc *rpc); |
| 433 | |
| 434 | /** |
| 435 | * @brief Free the NETCONF RPC reply object. |
| 436 | * @param[in] rpc Object to free. |
| 437 | */ |
| 438 | void nc_reply_free(struct nc_reply *reply); |
| 439 | |
| 440 | #endif /* NC_MESSAGES_CLIENT_H_ */ |