blob: b38a7c10cfdb367cf06e2e04910807dd6ae3a69c [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 Krejcid0d19522015-09-02 13:49:25 +020035/**
36 * @brief Enumeration of reasons of the NETCONF session termination as defined in RFC 6470.
37 */
38typedef enum NC_SESSION_TERM_REASON {
39 NC_SESSION_TERM_CLOSED, /**< closed by client in a normal fashion */
40 NC_SESSION_TERM_KILLED, /**< session was terminated by \<kill-session\> operation */
41 NC_SESSION_TERM_DROPPED, /**< transport layer connection was unexpectedly closed */
42 NC_SESSION_TERM_TIMEOUT, /**< terminated because of inactivity */
43 NC_SESSION_TERM_BADHELLO, /**< \<hello\> message was invalid */
44 NC_SESSION_TERM_OTHER /**< terminated for some other reason */
45} NC_SESSION_TERM_REASON;
46
47/**
48 * @brief Supported NETCONF transport protocols enumeration. To change currently
49 * used transport protocol, call nc_transport().
50 */
51typedef enum NC_TRANSPORT {
52 NC_OVER_ERROR = -1, /**< Used as an error return value, this is not acceptable as input value */
53 NC_OVER_SSH, /**< NETCONF over SSH, default value */
54 NC_OVER_TLS /**< NETCONF over TLS */
55} NC_TRANSPORT;
56
57/**
Radek Krejci43390242015-10-08 15:34:04 +020058 * @brief Enumeration of NETCONF message types.
59 */
60typedef enum NC_MSG_TYPE {
61 NC_MSG_ERROR, /**< error return value */
62 NC_MSG_WOULDBLOCK, /**< timeout return value */
63 NC_MSG_NONE, /**< no message at input or message was processed internally */
64 NC_MSG_HELLO, /**< \<hello\> message */
65 NC_MSG_RPC, /**< \<rpc\> message */
66 NC_MSG_REPLY, /**< \<rpc-reply\> message */
Radek Krejci5686ff72015-10-09 13:33:56 +020067 NC_MSG_NOTIF /**< \<notification\> message */
Radek Krejci43390242015-10-08 15:34:04 +020068} NC_MSG_TYPE;
69
70/**
Radek Krejcid0d19522015-09-02 13:49:25 +020071 * @brief Transform given time_t (seconds since the epoch) into the RFC 3339 format
72 * accepted by NETCONF functions.
73 *
74 * This is a reverse function to nc_datetime2time().
75 *
76 * @param[in] time time_t type value returned e.g. by time().
77 * @param[in] tz timezone name for the result. See tzselect(1) for list of
78 * correct values. If not specified (NULL), the result is provided in UTC (Zulu).
79 * @return Printed string in a format compliant to RFC 3339. It is up to the
80 * caller to free the returned string.
81 */
82char* nc_time2datetime(time_t time, const char* tz);
83
84/**
85 * @brief Transform given string in RFC 3339 compliant format to the time_t
86 * (seconds since the epoch) accepted by most Linux functions.
87 *
88 * This is a reverse function to nc_time2datetime().
89 *
90 * @param[in] datetime Time structure returned e.g. by localtime().
91 * @return time_t value of the given string.
92 */
93time_t nc_datetime2time(const char* datetime);
94
95/**
96 * @brief Set \<hello\> timeout - how long libnetconf will wait for the \<hello\>
97 * message from the other side. Default value is -1 (infinite timeout).
98 *
99 * TODO: not implemented
100 *
101 * @param[in] timeout Timeout in milliseconds, -1 for infinite timeout, 0 for non-blocking.
102 */
103void nc_hello_timeout(int timeout);
104
105#ifdef __cplusplus
106}
107#endif
108
109#endif /* NC_NETCONF_H_ */