blob: 4c1cf7007cdc94d2d8d8872ac3a7c99587188cbf [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 *
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_SESSION_H_
24#define NC_SESSION_H_
25
Michal Vaskofb2fb762015-10-27 11:44:32 +010026#ifdef ENABLE_SSH
Michal Vasko4ef14932015-12-04 11:09:10 +010027
Michal Vasko4ef14932015-12-04 11:09:10 +010028typedef enum {
29 NC_SSH_AUTH_PUBLICKEY = 0x01,
30 NC_SSH_AUTH_PASSWORD = 0x02,
31 NC_SSH_AUTH_INTERACTIVE = 0x04
32} NC_SSH_AUTH_TYPE;
33
Michal Vaskofb2fb762015-10-27 11:44:32 +010034#endif /* ENABLE_SSH */
Radek Krejci695d4fa2015-10-22 13:23:54 +020035
Michal Vaskoc14e3c82016-01-11 16:14:30 +010036#ifdef ENABLE_TLS
37
38typedef enum {
Michal Vasko1a38c862016-01-15 15:50:07 +010039 NC_TLS_CTN_UNKNOWN = 0,
Michal Vaskoc14e3c82016-01-11 16:14:30 +010040 NC_TLS_CTN_SPECIFIED,
41 NC_TLS_CTN_SAN_RFC822_NAME,
42 NC_TLS_CTN_SAN_DNS_NAME,
43 NC_TLS_CTN_SAN_IP_ADDRESS,
44 NC_TLS_CTN_SAN_ANY,
45 NC_TLS_CTN_COMMON_NAME
46} NC_TLS_CTN_MAPTYPE;
47
48#endif /* ENABLE_TLS */
49
Radek Krejci43390242015-10-08 15:34:04 +020050/**
Radek Krejci695d4fa2015-10-22 13:23:54 +020051 * @brief Enumeration of possible session statuses
52 */
53typedef enum {
Michal Vasko38a7c6c2015-12-04 12:29:20 +010054 NC_STATUS_STARTING = 0, /**< session is not yet fully initiated */
55 NC_STATUS_CLOSING, /**< session is being closed */
Michal Vasko428087d2016-01-14 16:04:28 +010056 NC_STATUS_INVALID, /**< session is not running and is supposed to be closed (nc_session_free()) */
Michal Vasko38a7c6c2015-12-04 12:29:20 +010057 NC_STATUS_RUNNING /**< up and running */
Radek Krejci695d4fa2015-10-22 13:23:54 +020058} NC_STATUS;
59
60/**
Michal Vasko38a7c6c2015-12-04 12:29:20 +010061 * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol)
62 */
63typedef enum {
64 NC_TI_NONE = 0, /**< none - session is not connected yet */
65 NC_TI_FD, /**< file descriptors - use standard input/output, transport protocol is implemented
66 outside the current application */
67#ifdef ENABLE_SSH
68 NC_TI_LIBSSH, /**< libssh - use libssh library, only for NETCONF over SSH transport */
69#endif
70#ifdef ENABLE_TLS
71 NC_TI_OPENSSL /**< OpenSSL - use OpenSSL library, only for NETCONF over TLS transport */
72#endif
73} NC_TRANSPORT_IMPL;
74
75/**
Radek Krejci43390242015-10-08 15:34:04 +020076 * @brief NETCONF session object
77 */
78struct nc_session;
79
Radek Krejci695d4fa2015-10-22 13:23:54 +020080/**
Michal Vasko8dadf782016-01-15 10:29:36 +010081 * @brief Get session status.
82 *
83 * @param[in] session Session to get the information from.
84 *
85 * @return Session status.
86 */
87NC_STATUS nc_session_get_status(const struct nc_session *session);
88
89/**
90 * @brief Get session ID.
91 *
92 * @param[in] session Session to get the information from.
93 *
94 * @return Session ID.
95 */
96uint32_t nc_session_get_id(const struct nc_session *session);
97
98/**
99 * @brief Get session transport used.
100 *
101 * @param[in] session Session to get the information from.
102 *
103 * @return Session transport.
104 */
105NC_TRANSPORT_IMPL nc_session_get_ti(const struct nc_session *session);
106
107/**
108 * @brief Get session username.
109 *
110 * @param[in] session Session to get the information from.
111 *
112 * @return Session username.
113 */
114const char *nc_session_get_username(const struct nc_session *session);
115
116/**
117 * @brief Get session host.
118 *
119 * @param[in] session Session to get the information from.
120 *
121 * @return Session host.
122 */
123const char *nc_session_get_host(const struct nc_session *session);
124
125/**
126 * @brief Get session port.
127 *
128 * @param[in] session Session to get the information from.
129 *
130 * @return Session port.
131 */
132uint16_t nc_session_get_port(const struct nc_session *session);
133
134/**
135 * @brief Get session capabilities.
136 *
137 * @param[in] session Session to get the information from.
138 *
139 * @return Session capabilities.
140 */
141const char **nc_session_get_cpblts(const struct nc_session *session);
142
143/**
144 * @brief Check capability presence in a session.
145 *
146 * @param[in] session Session to check.
147 * @param[in] capab Capability to look for, capability with any additional suffix will match.
148 *
149 * @return Matching capability, NULL if none found.
150 */
151const char *nc_session_cpblt(const struct nc_session *session, const char *capab);
152
153/**
Radek Krejci695d4fa2015-10-22 13:23:54 +0200154 * @brief Free the NETCONF session object.
155 *
156 * @param[in] session Object to free.
157 */
158void nc_session_free(struct nc_session *session);
159
Radek Krejci43390242015-10-08 15:34:04 +0200160#endif /* NC_SESSION_H_ */