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 | * |
| 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 Vasko | fb2fb76 | 2015-10-27 11:44:32 +0100 | [diff] [blame] | 26 | #ifdef ENABLE_SSH |
Michal Vasko | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 27 | |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 28 | /** |
| 29 | * @brief Enumeration of NETCONF SSH authentication methods |
| 30 | */ |
Michal Vasko | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 31 | typedef enum { |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 32 | NC_SSH_AUTH_PUBLICKEY = 0x01, /**< publickey SSH authentication */ |
| 33 | NC_SSH_AUTH_PASSWORD = 0x02, /**< password SSH authentication */ |
| 34 | NC_SSH_AUTH_INTERACTIVE = 0x04 /**< interactive SSH authentication */ |
Michal Vasko | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 35 | } NC_SSH_AUTH_TYPE; |
| 36 | |
Michal Vasko | fb2fb76 | 2015-10-27 11:44:32 +0100 | [diff] [blame] | 37 | #endif /* ENABLE_SSH */ |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 38 | |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 39 | #ifdef ENABLE_TLS |
| 40 | |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 41 | /** |
| 42 | * @brief Enumeration of cert-to-name mapping types |
| 43 | */ |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 44 | typedef enum { |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 45 | NC_TLS_CTN_UNKNOWN = 0, /**< unknown mapping */ |
| 46 | NC_TLS_CTN_SPECIFIED, /**< username explicitly specified */ |
| 47 | NC_TLS_CTN_SAN_RFC822_NAME, /**< email address as username */ |
| 48 | NC_TLS_CTN_SAN_DNS_NAME, /**< DNS name as username */ |
| 49 | NC_TLS_CTN_SAN_IP_ADDRESS, /**< IP address as username */ |
| 50 | NC_TLS_CTN_SAN_ANY, /**< any certificate Subject Alternative Name as username */ |
| 51 | NC_TLS_CTN_COMMON_NAME /**< common name as username */ |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 52 | } NC_TLS_CTN_MAPTYPE; |
| 53 | |
| 54 | #endif /* ENABLE_TLS */ |
| 55 | |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 56 | /** |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 57 | * @brief Enumeration of possible session statuses |
| 58 | */ |
| 59 | typedef enum { |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 60 | NC_STATUS_STARTING = 0, /**< session is not yet fully initiated */ |
| 61 | NC_STATUS_CLOSING, /**< session is being closed */ |
Michal Vasko | 428087d | 2016-01-14 16:04:28 +0100 | [diff] [blame] | 62 | 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] | 63 | NC_STATUS_RUNNING /**< up and running */ |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 64 | } NC_STATUS; |
| 65 | |
| 66 | /** |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 67 | * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol) |
| 68 | */ |
| 69 | typedef enum { |
| 70 | NC_TI_NONE = 0, /**< none - session is not connected yet */ |
| 71 | NC_TI_FD, /**< file descriptors - use standard input/output, transport protocol is implemented |
| 72 | outside the current application */ |
| 73 | #ifdef ENABLE_SSH |
| 74 | NC_TI_LIBSSH, /**< libssh - use libssh library, only for NETCONF over SSH transport */ |
| 75 | #endif |
| 76 | #ifdef ENABLE_TLS |
| 77 | NC_TI_OPENSSL /**< OpenSSL - use OpenSSL library, only for NETCONF over TLS transport */ |
| 78 | #endif |
| 79 | } NC_TRANSPORT_IMPL; |
| 80 | |
| 81 | /** |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 82 | * @brief NETCONF session object |
| 83 | */ |
| 84 | struct nc_session; |
| 85 | |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 86 | /** |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 87 | * @brief Get session status. |
| 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 status. |
| 91 | */ |
| 92 | NC_STATUS nc_session_get_status(const struct nc_session *session); |
| 93 | |
| 94 | /** |
| 95 | * @brief Get session ID. |
| 96 | * |
| 97 | * @param[in] session Session to get the information from. |
Michal Vasko | 8dadf78 | 2016-01-15 10:29:36 +0100 | [diff] [blame] | 98 | * @return Session ID. |
| 99 | */ |
| 100 | uint32_t nc_session_get_id(const struct nc_session *session); |
| 101 | |
| 102 | /** |
| 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 | /** |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 160 | * @brief Free the NETCONF session object. |
| 161 | * |
| 162 | * @param[in] session Object to free. |
| 163 | */ |
| 164 | void nc_session_free(struct nc_session *session); |
| 165 | |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 166 | #endif /* NC_SESSION_H_ */ |