Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file netconf.h |
| 3 | * \author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * \brief libnetconf2's general public functions and structures definitions. |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifndef NC_NETCONF_H_ |
| 24 | #define NC_NETCONF_H_ |
| 25 | |
| 26 | #include <time.h> |
| 27 | |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | |
Radek Krejci | 206fcd6 | 2015-10-07 15:42:48 +0200 | [diff] [blame] | 32 | #define NC_NS_BASE "urn:ietf:params:xml:ns:netconf:base:1.0" |
| 33 | #define NC_NS_NOTIF "urn:ietf:params:xml:ns:netconf:notification:1.0" |
| 34 | |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 35 | /** @brief Default NETCONF over SSH port */ |
| 36 | #define NC_PORT_SSH 830; |
| 37 | /** @brief Default NETCONF over TLS port */ |
| 38 | #define NC_PORT_TLS 6513; |
| 39 | |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 40 | /** |
| 41 | * @brief Enumeration of reasons of the NETCONF session termination as defined in RFC 6470. |
| 42 | */ |
| 43 | typedef enum NC_SESSION_TERM_REASON { |
| 44 | NC_SESSION_TERM_CLOSED, /**< closed by client in a normal fashion */ |
| 45 | NC_SESSION_TERM_KILLED, /**< session was terminated by \<kill-session\> operation */ |
| 46 | NC_SESSION_TERM_DROPPED, /**< transport layer connection was unexpectedly closed */ |
| 47 | NC_SESSION_TERM_TIMEOUT, /**< terminated because of inactivity */ |
| 48 | NC_SESSION_TERM_BADHELLO, /**< \<hello\> message was invalid */ |
| 49 | NC_SESSION_TERM_OTHER /**< terminated for some other reason */ |
| 50 | } NC_SESSION_TERM_REASON; |
| 51 | |
| 52 | /** |
| 53 | * @brief Supported NETCONF transport protocols enumeration. To change currently |
| 54 | * used transport protocol, call nc_transport(). |
| 55 | */ |
| 56 | typedef enum NC_TRANSPORT { |
| 57 | NC_OVER_ERROR = -1, /**< Used as an error return value, this is not acceptable as input value */ |
| 58 | NC_OVER_SSH, /**< NETCONF over SSH, default value */ |
| 59 | NC_OVER_TLS /**< NETCONF over TLS */ |
| 60 | } NC_TRANSPORT; |
| 61 | |
| 62 | /** |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 63 | * @brief Enumeration of NETCONF message types. |
| 64 | */ |
| 65 | typedef enum NC_MSG_TYPE { |
| 66 | NC_MSG_ERROR, /**< error return value */ |
| 67 | NC_MSG_WOULDBLOCK, /**< timeout return value */ |
| 68 | NC_MSG_NONE, /**< no message at input or message was processed internally */ |
| 69 | NC_MSG_HELLO, /**< \<hello\> message */ |
| 70 | NC_MSG_RPC, /**< \<rpc\> message */ |
| 71 | NC_MSG_REPLY, /**< \<rpc-reply\> message */ |
Radek Krejci | 5686ff7 | 2015-10-09 13:33:56 +0200 | [diff] [blame] | 72 | NC_MSG_NOTIF /**< \<notification\> message */ |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 73 | } NC_MSG_TYPE; |
| 74 | |
| 75 | /** |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 76 | * @brief Enumeration of the supported types of datastores defined by NETCONF |
| 77 | */ |
| 78 | typedef enum NC_DATASTORE_TYPE { |
| 79 | NC_DATASTORE_ERROR, /**< error state of functions returning the datastore type */ |
| 80 | NC_DATASTORE_CONFIG, /**< value describing that the datastore is set as config */ |
| 81 | NC_DATASTORE_URL, /**< value describing that the datastore data should be given from the URL */ |
| 82 | NC_DATASTORE_RUNNING, /**< base NETCONF's datastore containing the current device configuration */ |
| 83 | NC_DATASTORE_STARTUP, /**< separated startup datastore as defined in Distinct Startup Capability */ |
| 84 | NC_DATASTORE_CANDIDATE /**< separated working datastore as defined in Candidate Configuration Capability */ |
| 85 | } NC_DATASTORE; |
| 86 | |
| 87 | /** |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 88 | * @brief Transform given time_t (seconds since the epoch) into the RFC 3339 format |
| 89 | * accepted by NETCONF functions. |
| 90 | * |
| 91 | * This is a reverse function to nc_datetime2time(). |
| 92 | * |
| 93 | * @param[in] time time_t type value returned e.g. by time(). |
| 94 | * @param[in] tz timezone name for the result. See tzselect(1) for list of |
| 95 | * correct values. If not specified (NULL), the result is provided in UTC (Zulu). |
| 96 | * @return Printed string in a format compliant to RFC 3339. It is up to the |
| 97 | * caller to free the returned string. |
| 98 | */ |
| 99 | char* nc_time2datetime(time_t time, const char* tz); |
| 100 | |
| 101 | /** |
| 102 | * @brief Transform given string in RFC 3339 compliant format to the time_t |
| 103 | * (seconds since the epoch) accepted by most Linux functions. |
| 104 | * |
| 105 | * This is a reverse function to nc_time2datetime(). |
| 106 | * |
| 107 | * @param[in] datetime Time structure returned e.g. by localtime(). |
| 108 | * @return time_t value of the given string. |
| 109 | */ |
| 110 | time_t nc_datetime2time(const char* datetime); |
| 111 | |
| 112 | /** |
| 113 | * @brief Set \<hello\> timeout - how long libnetconf will wait for the \<hello\> |
| 114 | * message from the other side. Default value is -1 (infinite timeout). |
| 115 | * |
| 116 | * TODO: not implemented |
| 117 | * |
| 118 | * @param[in] timeout Timeout in milliseconds, -1 for infinite timeout, 0 for non-blocking. |
| 119 | */ |
| 120 | void nc_hello_timeout(int timeout); |
| 121 | |
| 122 | #ifdef __cplusplus |
| 123 | } |
| 124 | #endif |
| 125 | |
| 126 | #endif /* NC_NETCONF_H_ */ |