blob: 59fcd44bb54933bb3f909f533d5475e70d273789 [file] [log] [blame]
Radek Krejcid0d19522015-09-02 13:49:25 +02001/**
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
29extern "C" {
30#endif
31
Radek Krejci206fcd62015-10-07 15:42:48 +020032#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 Krejciac6d3472015-10-22 15:47:18 +020035/** @brief Default NETCONF over SSH port */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010036#define NC_PORT_SSH 830
37/** @brief Default NETCONF over SSH Call Home port */
38#define NC_PORT_CH_SSH 6666
39
Radek Krejciac6d3472015-10-22 15:47:18 +020040/** @brief Default NETCONF over TLS port */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010041#define NC_PORT_TLS 6513
42/** @brief Default NETCONF over TLS Call Home port */
43#define NC_PORT_CH_TLS 6667
Radek Krejciac6d3472015-10-22 15:47:18 +020044
Michal Vasko086311b2016-01-08 09:53:11 +010045/** @brief Microseconds after which tasks are repeated until the full timeout elapses */
46#define NC_TIMEOUT_STEP 10
47
Radek Krejcid0d19522015-09-02 13:49:25 +020048/**
49 * @brief Enumeration of reasons of the NETCONF session termination as defined in RFC 6470.
50 */
51typedef enum NC_SESSION_TERM_REASON {
52 NC_SESSION_TERM_CLOSED, /**< closed by client in a normal fashion */
53 NC_SESSION_TERM_KILLED, /**< session was terminated by \<kill-session\> operation */
54 NC_SESSION_TERM_DROPPED, /**< transport layer connection was unexpectedly closed */
55 NC_SESSION_TERM_TIMEOUT, /**< terminated because of inactivity */
56 NC_SESSION_TERM_BADHELLO, /**< \<hello\> message was invalid */
57 NC_SESSION_TERM_OTHER /**< terminated for some other reason */
58} NC_SESSION_TERM_REASON;
59
60/**
61 * @brief Supported NETCONF transport protocols enumeration. To change currently
62 * used transport protocol, call nc_transport().
63 */
64typedef enum NC_TRANSPORT {
65 NC_OVER_ERROR = -1, /**< Used as an error return value, this is not acceptable as input value */
66 NC_OVER_SSH, /**< NETCONF over SSH, default value */
67 NC_OVER_TLS /**< NETCONF over TLS */
68} NC_TRANSPORT;
69
70/**
Radek Krejci43390242015-10-08 15:34:04 +020071 * @brief Enumeration of NETCONF message types.
72 */
73typedef enum NC_MSG_TYPE {
74 NC_MSG_ERROR, /**< error return value */
75 NC_MSG_WOULDBLOCK, /**< timeout return value */
76 NC_MSG_NONE, /**< no message at input or message was processed internally */
77 NC_MSG_HELLO, /**< \<hello\> message */
78 NC_MSG_RPC, /**< \<rpc\> message */
79 NC_MSG_REPLY, /**< \<rpc-reply\> message */
Radek Krejci5686ff72015-10-09 13:33:56 +020080 NC_MSG_NOTIF /**< \<notification\> message */
Radek Krejci43390242015-10-08 15:34:04 +020081} NC_MSG_TYPE;
82
83/**
Radek Krejci695d4fa2015-10-22 13:23:54 +020084 * @brief Enumeration of the supported types of datastores defined by NETCONF
85 */
86typedef enum NC_DATASTORE_TYPE {
87 NC_DATASTORE_ERROR, /**< error state of functions returning the datastore type */
88 NC_DATASTORE_CONFIG, /**< value describing that the datastore is set as config */
89 NC_DATASTORE_URL, /**< value describing that the datastore data should be given from the URL */
90 NC_DATASTORE_RUNNING, /**< base NETCONF's datastore containing the current device configuration */
91 NC_DATASTORE_STARTUP, /**< separated startup datastore as defined in Distinct Startup Capability */
92 NC_DATASTORE_CANDIDATE /**< separated working datastore as defined in Candidate Configuration Capability */
93} NC_DATASTORE;
94
95/**
Radek Krejcid0d19522015-09-02 13:49:25 +020096 * @brief Transform given time_t (seconds since the epoch) into the RFC 3339 format
97 * accepted by NETCONF functions.
98 *
99 * This is a reverse function to nc_datetime2time().
100 *
101 * @param[in] time time_t type value returned e.g. by time().
102 * @param[in] tz timezone name for the result. See tzselect(1) for list of
103 * correct values. If not specified (NULL), the result is provided in UTC (Zulu).
104 * @return Printed string in a format compliant to RFC 3339. It is up to the
105 * caller to free the returned string.
106 */
107char* nc_time2datetime(time_t time, const char* tz);
108
109/**
110 * @brief Transform given string in RFC 3339 compliant format to the time_t
111 * (seconds since the epoch) accepted by most Linux functions.
112 *
113 * This is a reverse function to nc_time2datetime().
114 *
115 * @param[in] datetime Time structure returned e.g. by localtime().
116 * @return time_t value of the given string.
117 */
118time_t nc_datetime2time(const char* datetime);
119
Radek Krejcid0d19522015-09-02 13:49:25 +0200120#ifdef __cplusplus
121}
122#endif
123
124#endif /* NC_NETCONF_H_ */