blob: 00617f506aee5af511a5409e99874e646714a141 [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
Radek Krejcid0d19522015-09-02 13:49:25 +020045/**
46 * @brief Enumeration of reasons of the NETCONF session termination as defined in RFC 6470.
47 */
48typedef enum NC_SESSION_TERM_REASON {
49 NC_SESSION_TERM_CLOSED, /**< closed by client in a normal fashion */
50 NC_SESSION_TERM_KILLED, /**< session was terminated by \<kill-session\> operation */
51 NC_SESSION_TERM_DROPPED, /**< transport layer connection was unexpectedly closed */
52 NC_SESSION_TERM_TIMEOUT, /**< terminated because of inactivity */
53 NC_SESSION_TERM_BADHELLO, /**< \<hello\> message was invalid */
54 NC_SESSION_TERM_OTHER /**< terminated for some other reason */
55} NC_SESSION_TERM_REASON;
56
57/**
58 * @brief Supported NETCONF transport protocols enumeration. To change currently
59 * used transport protocol, call nc_transport().
60 */
61typedef enum NC_TRANSPORT {
62 NC_OVER_ERROR = -1, /**< Used as an error return value, this is not acceptable as input value */
63 NC_OVER_SSH, /**< NETCONF over SSH, default value */
64 NC_OVER_TLS /**< NETCONF over TLS */
65} NC_TRANSPORT;
66
67/**
Radek Krejci43390242015-10-08 15:34:04 +020068 * @brief Enumeration of NETCONF message types.
69 */
70typedef enum NC_MSG_TYPE {
71 NC_MSG_ERROR, /**< error return value */
72 NC_MSG_WOULDBLOCK, /**< timeout return value */
73 NC_MSG_NONE, /**< no message at input or message was processed internally */
74 NC_MSG_HELLO, /**< \<hello\> message */
75 NC_MSG_RPC, /**< \<rpc\> message */
76 NC_MSG_REPLY, /**< \<rpc-reply\> message */
Radek Krejci5686ff72015-10-09 13:33:56 +020077 NC_MSG_NOTIF /**< \<notification\> message */
Radek Krejci43390242015-10-08 15:34:04 +020078} NC_MSG_TYPE;
79
80/**
Radek Krejci695d4fa2015-10-22 13:23:54 +020081 * @brief Enumeration of the supported types of datastores defined by NETCONF
82 */
83typedef enum NC_DATASTORE_TYPE {
84 NC_DATASTORE_ERROR, /**< error state of functions returning the datastore type */
85 NC_DATASTORE_CONFIG, /**< value describing that the datastore is set as config */
86 NC_DATASTORE_URL, /**< value describing that the datastore data should be given from the URL */
87 NC_DATASTORE_RUNNING, /**< base NETCONF's datastore containing the current device configuration */
88 NC_DATASTORE_STARTUP, /**< separated startup datastore as defined in Distinct Startup Capability */
89 NC_DATASTORE_CANDIDATE /**< separated working datastore as defined in Candidate Configuration Capability */
90} NC_DATASTORE;
91
92/**
Radek Krejcid0d19522015-09-02 13:49:25 +020093 * @brief Transform given time_t (seconds since the epoch) into the RFC 3339 format
94 * accepted by NETCONF functions.
95 *
96 * This is a reverse function to nc_datetime2time().
97 *
98 * @param[in] time time_t type value returned e.g. by time().
99 * @param[in] tz timezone name for the result. See tzselect(1) for list of
100 * correct values. If not specified (NULL), the result is provided in UTC (Zulu).
101 * @return Printed string in a format compliant to RFC 3339. It is up to the
102 * caller to free the returned string.
103 */
104char* nc_time2datetime(time_t time, const char* tz);
105
106/**
107 * @brief Transform given string in RFC 3339 compliant format to the time_t
108 * (seconds since the epoch) accepted by most Linux functions.
109 *
110 * This is a reverse function to nc_time2datetime().
111 *
112 * @param[in] datetime Time structure returned e.g. by localtime().
113 * @return time_t value of the given string.
114 */
115time_t nc_datetime2time(const char* datetime);
116
117/**
118 * @brief Set \<hello\> timeout - how long libnetconf will wait for the \<hello\>
119 * message from the other side. Default value is -1 (infinite timeout).
120 *
121 * TODO: not implemented
122 *
123 * @param[in] timeout Timeout in milliseconds, -1 for infinite timeout, 0 for non-blocking.
124 */
125void nc_hello_timeout(int timeout);
126
127#ifdef __cplusplus
128}
129#endif
130
131#endif /* NC_NETCONF_H_ */