blob: 47dac1bad2d34ca475d55fe330edc279b3131dbf [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 */
36#define NC_PORT_SSH 830;
37/** @brief Default NETCONF over TLS port */
38#define NC_PORT_TLS 6513;
39
Radek Krejcid0d19522015-09-02 13:49:25 +020040/**
41 * @brief Enumeration of reasons of the NETCONF session termination as defined in RFC 6470.
42 */
43typedef 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 */
56typedef 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 Krejci43390242015-10-08 15:34:04 +020063 * @brief Enumeration of NETCONF message types.
64 */
65typedef 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 Krejci5686ff72015-10-09 13:33:56 +020072 NC_MSG_NOTIF /**< \<notification\> message */
Radek Krejci43390242015-10-08 15:34:04 +020073} NC_MSG_TYPE;
74
75/**
Radek Krejci695d4fa2015-10-22 13:23:54 +020076 * @brief Enumeration of the supported types of datastores defined by NETCONF
77 */
78typedef 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 Krejcid0d19522015-09-02 13:49:25 +020088 * @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 */
99char* 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 */
110time_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 */
120void nc_hello_timeout(int timeout);
121
122#ifdef __cplusplus
123}
124#endif
125
126#endif /* NC_NETCONF_H_ */