Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 1 | /** |
| 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 Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 8 | * 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 Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef NC_SESSION_H_ |
| 16 | #define NC_SESSION_H_ |
| 17 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 18 | #ifdef NC_ENABLED_SSH |
Michal Vasko | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 19 | |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 20 | /** |
| 21 | * @brief Enumeration of NETCONF SSH authentication methods |
| 22 | */ |
Michal Vasko | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 23 | typedef enum { |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 24 | 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 Vasko | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 27 | } NC_SSH_AUTH_TYPE; |
| 28 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 29 | #endif /* NC_ENABLED_SSH */ |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 30 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 31 | #ifdef NC_ENABLED_TLS |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 32 | |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 33 | /** |
| 34 | * @brief Enumeration of cert-to-name mapping types |
| 35 | */ |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 36 | typedef enum { |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 37 | 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 Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 44 | } NC_TLS_CTN_MAPTYPE; |
| 45 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 46 | #endif /* NC_ENABLED_TLS */ |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 47 | |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 48 | /** |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 49 | * @brief Enumeration of possible session statuses |
| 50 | */ |
| 51 | typedef enum { |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 52 | NC_STATUS_STARTING = 0, /**< session is not yet fully initiated */ |
| 53 | NC_STATUS_CLOSING, /**< session is being closed */ |
Michal Vasko | 428087d | 2016-01-14 16:04:28 +0100 | [diff] [blame] | 54 | NC_STATUS_INVALID, /**< session is not running and is supposed to be closed (nc_session_free()) */ |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 55 | NC_STATUS_RUNNING /**< up and running */ |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 56 | } NC_STATUS; |
| 57 | |
| 58 | /** |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 59 | * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol) |
| 60 | */ |
| 61 | typedef 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 Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 65 | #ifdef NC_ENABLED_SSH |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 66 | NC_TI_LIBSSH, /**< libssh - use libssh library, only for NETCONF over SSH transport */ |
| 67 | #endif |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 68 | #ifdef NC_ENABLED_TLS |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 69 | NC_TI_OPENSSL /**< OpenSSL - use OpenSSL library, only for NETCONF over TLS transport */ |
| 70 | #endif |
| 71 | } NC_TRANSPORT_IMPL; |
| 72 | |
| 73 | /** |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 74 | * @brief NETCONF session object |
| 75 | */ |
| 76 | struct nc_session; |
| 77 | |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 78 | /** |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 79 | * @brief Get session status. |
| 80 | * |
| 81 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 82 | * @return Session status. |
| 83 | */ |
| 84 | NC_STATUS nc_session_get_status(const struct nc_session *session); |
| 85 | |
| 86 | /** |
| 87 | * @brief Get session ID. |
| 88 | * |
| 89 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 90 | * @return Session ID. |
| 91 | */ |
| 92 | uint32_t nc_session_get_id(const struct nc_session *session); |
| 93 | |
| 94 | /** |
Michal Vasko | 174fe8e | 2016-02-17 15:38:09 +0100 | [diff] [blame] | 95 | * @brief Get session NETCONF version. |
| 96 | * |
| 97 | * @param[in] session Session to get the information from. |
| 98 | * @return 0 for version 1.0, non-zero for version 1.1. |
| 99 | */ |
| 100 | int nc_session_get_version(const struct nc_session *session); |
| 101 | |
| 102 | /** |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 103 | * @brief Get session transport used. |
| 104 | * |
| 105 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 106 | * @return Session transport. |
| 107 | */ |
| 108 | NC_TRANSPORT_IMPL nc_session_get_ti(const struct nc_session *session); |
| 109 | |
| 110 | /** |
| 111 | * @brief Get session username. |
| 112 | * |
| 113 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 114 | * @return Session username. |
| 115 | */ |
| 116 | const char *nc_session_get_username(const struct nc_session *session); |
| 117 | |
| 118 | /** |
| 119 | * @brief Get session host. |
| 120 | * |
| 121 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 122 | * @return Session host. |
| 123 | */ |
| 124 | const char *nc_session_get_host(const struct nc_session *session); |
| 125 | |
| 126 | /** |
| 127 | * @brief Get session port. |
| 128 | * |
| 129 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 130 | * @return Session port. |
| 131 | */ |
| 132 | uint16_t nc_session_get_port(const struct nc_session *session); |
| 133 | |
| 134 | /** |
Michal Vasko | 9a25e93 | 2016-02-01 10:36:42 +0100 | [diff] [blame] | 135 | * @brief Get session context. |
| 136 | * |
| 137 | * @param[in] session Session to get the information from. |
| 138 | * @return Session context. |
| 139 | */ |
| 140 | struct ly_ctx *nc_session_get_ctx(const struct nc_session *session); |
| 141 | |
| 142 | /** |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 143 | * @brief Get session capabilities. |
| 144 | * |
| 145 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 146 | * @return Session capabilities. |
| 147 | */ |
| 148 | const char **nc_session_get_cpblts(const struct nc_session *session); |
| 149 | |
| 150 | /** |
| 151 | * @brief Check capability presence in a session. |
| 152 | * |
| 153 | * @param[in] session Session to check. |
| 154 | * @param[in] capab Capability to look for, capability with any additional suffix will match. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 155 | * @return Matching capability, NULL if none found. |
| 156 | */ |
| 157 | const char *nc_session_cpblt(const struct nc_session *session, const char *capab); |
| 158 | |
| 159 | /** |
Michal Vasko | 2cc4c68 | 2016-03-01 09:16:48 +0100 | [diff] [blame] | 160 | * @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 | */ |
| 165 | void 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 | */ |
| 173 | void *nc_session_get_data(const struct nc_session *session); |
| 174 | |
| 175 | /** |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 176 | * @brief Free the NETCONF session object. |
| 177 | * |
| 178 | * @param[in] session Object to free. |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 179 | * @param[in] data_free Session user data destructor. |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 180 | */ |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 181 | void nc_session_free(struct nc_session *session, void (*data_free)(void *)); |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 182 | |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 183 | #endif /* NC_SESSION_H_ */ |