blob: 105b809300552367077b7a3597b6b640b3e47783 [file] [log] [blame]
Radek Krejci43390242015-10-08 15:34:04 +02001/**
2 * \file session.h
3 * \author Radek Krejci <rkrejci@cesnet.cz>
4 * \brief libnetconf2 session manipulation
5 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01008 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
Michal Vaskoafd416b2016-02-25 14:51:46 +010011 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010012 * https://opensource.org/licenses/BSD-3-Clause
Radek Krejci43390242015-10-08 15:34:04 +020013 */
14
15#ifndef NC_SESSION_H_
16#define NC_SESSION_H_
17
Radek Krejci53691be2016-02-22 13:58:37 +010018#ifdef NC_ENABLED_SSH
Michal Vasko4ef14932015-12-04 11:09:10 +010019
Michal Vaskof0537d82016-01-29 14:42:38 +010020/**
21 * @brief Enumeration of NETCONF SSH authentication methods
22 */
Michal Vasko4ef14932015-12-04 11:09:10 +010023typedef enum {
Michal Vaskof0537d82016-01-29 14:42:38 +010024 NC_SSH_AUTH_PUBLICKEY = 0x01, /**< publickey SSH authentication */
25 NC_SSH_AUTH_PASSWORD = 0x02, /**< password SSH authentication */
26 NC_SSH_AUTH_INTERACTIVE = 0x04 /**< interactive SSH authentication */
Michal Vasko4ef14932015-12-04 11:09:10 +010027} NC_SSH_AUTH_TYPE;
28
Radek Krejci53691be2016-02-22 13:58:37 +010029#endif /* NC_ENABLED_SSH */
Radek Krejci695d4fa2015-10-22 13:23:54 +020030
Radek Krejci53691be2016-02-22 13:58:37 +010031#ifdef NC_ENABLED_TLS
Michal Vaskoc14e3c82016-01-11 16:14:30 +010032
Michal Vaskof0537d82016-01-29 14:42:38 +010033/**
34 * @brief Enumeration of cert-to-name mapping types
35 */
Michal Vaskoc14e3c82016-01-11 16:14:30 +010036typedef enum {
Michal Vaskof0537d82016-01-29 14:42:38 +010037 NC_TLS_CTN_UNKNOWN = 0, /**< unknown mapping */
38 NC_TLS_CTN_SPECIFIED, /**< username explicitly specified */
39 NC_TLS_CTN_SAN_RFC822_NAME, /**< email address as username */
40 NC_TLS_CTN_SAN_DNS_NAME, /**< DNS name as username */
41 NC_TLS_CTN_SAN_IP_ADDRESS, /**< IP address as username */
42 NC_TLS_CTN_SAN_ANY, /**< any certificate Subject Alternative Name as username */
43 NC_TLS_CTN_COMMON_NAME /**< common name as username */
Michal Vaskoc14e3c82016-01-11 16:14:30 +010044} NC_TLS_CTN_MAPTYPE;
45
Radek Krejci53691be2016-02-22 13:58:37 +010046#endif /* NC_ENABLED_TLS */
Michal Vaskoc14e3c82016-01-11 16:14:30 +010047
Radek Krejci43390242015-10-08 15:34:04 +020048/**
Radek Krejci695d4fa2015-10-22 13:23:54 +020049 * @brief Enumeration of possible session statuses
50 */
51typedef enum {
Michal Vasko38a7c6c2015-12-04 12:29:20 +010052 NC_STATUS_STARTING = 0, /**< session is not yet fully initiated */
53 NC_STATUS_CLOSING, /**< session is being closed */
Michal Vasko428087d2016-01-14 16:04:28 +010054 NC_STATUS_INVALID, /**< session is not running and is supposed to be closed (nc_session_free()) */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010055 NC_STATUS_RUNNING /**< up and running */
Radek Krejci695d4fa2015-10-22 13:23:54 +020056} NC_STATUS;
57
58/**
Michal Vasko38a7c6c2015-12-04 12:29:20 +010059 * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol)
60 */
61typedef enum {
62 NC_TI_NONE = 0, /**< none - session is not connected yet */
63 NC_TI_FD, /**< file descriptors - use standard input/output, transport protocol is implemented
64 outside the current application */
Radek Krejci53691be2016-02-22 13:58:37 +010065#ifdef NC_ENABLED_SSH
Michal Vasko38a7c6c2015-12-04 12:29:20 +010066 NC_TI_LIBSSH, /**< libssh - use libssh library, only for NETCONF over SSH transport */
67#endif
Radek Krejci53691be2016-02-22 13:58:37 +010068#ifdef NC_ENABLED_TLS
Michal Vasko38a7c6c2015-12-04 12:29:20 +010069 NC_TI_OPENSSL /**< OpenSSL - use OpenSSL library, only for NETCONF over TLS transport */
70#endif
71} NC_TRANSPORT_IMPL;
72
73/**
Michal Vasko2e6defd2016-10-07 15:48:15 +020074 * @brief Enumeration of Call Home connection types.
75 */
76typedef enum {
77 NC_CH_CT_NOT_SET = 0,
78 NC_CH_PERSIST,
79 NC_CH_PERIOD
80} NC_CH_CONN_TYPE;
81
82/**
83 * @brief Enumeration of Call Home client priority policy.
84 */
85typedef enum {
86 NC_CH_FIRST_LISTED = 0, //default
87 NC_CH_LAST_CONNECTED
88} NC_CH_START_WITH;
89
90/**
Radek Krejci43390242015-10-08 15:34:04 +020091 * @brief NETCONF session object
92 */
93struct nc_session;
94
Radek Krejci695d4fa2015-10-22 13:23:54 +020095/**
Michal Vasko8dadf782016-01-15 10:29:36 +010096 * @brief Get session status.
97 *
98 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +010099 * @return Session status.
100 */
101NC_STATUS nc_session_get_status(const struct nc_session *session);
102
103/**
104 * @brief Get session ID.
105 *
106 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100107 * @return Session ID.
108 */
109uint32_t nc_session_get_id(const struct nc_session *session);
110
111/**
Michal Vasko174fe8e2016-02-17 15:38:09 +0100112 * @brief Get session NETCONF version.
113 *
114 * @param[in] session Session to get the information from.
115 * @return 0 for version 1.0, non-zero for version 1.1.
116 */
117int nc_session_get_version(const struct nc_session *session);
118
119/**
Michal Vasko8dadf782016-01-15 10:29:36 +0100120 * @brief Get session transport used.
121 *
122 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100123 * @return Session transport.
124 */
125NC_TRANSPORT_IMPL nc_session_get_ti(const struct nc_session *session);
126
127/**
128 * @brief Get session username.
129 *
130 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100131 * @return Session username.
132 */
133const char *nc_session_get_username(const struct nc_session *session);
134
135/**
136 * @brief Get session host.
137 *
138 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100139 * @return Session host.
140 */
141const char *nc_session_get_host(const struct nc_session *session);
142
143/**
144 * @brief Get session port.
145 *
146 * @param[in] session Session to get the information from.
Michal Vasko8dadf782016-01-15 10:29:36 +0100147 * @return Session port.
148 */
149uint16_t nc_session_get_port(const struct nc_session *session);
150
151/**
Michal Vasko9a25e932016-02-01 10:36:42 +0100152 * @brief Get session context.
153 *
154 * @param[in] session Session to get the information from.
155 * @return Session context.
156 */
157struct ly_ctx *nc_session_get_ctx(const struct nc_session *session);
158
159/**
Michal Vasko2cc4c682016-03-01 09:16:48 +0100160 * @brief Assign arbitrary data to a session.
161 *
162 * @param[in] session Session to modify.
163 * @param[in] data Data to be stored in the session.
164 */
165void nc_session_set_data(struct nc_session *session, void *data);
166
167/**
168 * @brief Get the data assigned to a session.
169 *
170 * @param[in] session Session to get the data from.
171 * @return Session-specific data.
172 */
173void *nc_session_get_data(const struct nc_session *session);
174
175/**
Radek Krejci695d4fa2015-10-22 13:23:54 +0200176 * @brief Free the NETCONF session object.
177 *
178 * @param[in] session Object to free.
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100179 * @param[in] data_free Session user data destructor.
Radek Krejci695d4fa2015-10-22 13:23:54 +0200180 */
Michal Vaskoe1a64ec2016-03-01 12:21:58 +0100181void nc_session_free(struct nc_session *session, void (*data_free)(void *));
Radek Krejci695d4fa2015-10-22 13:23:54 +0200182
Radek Krejci43390242015-10-08 15:34:04 +0200183#endif /* NC_SESSION_H_ */