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 | 4ef1493 | 2015-12-04 11:09:10 +0100 | [diff] [blame] | 28 | typedef 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 Vasko | fb2fb76 | 2015-10-27 11:44:32 +0100 | [diff] [blame] | 34 | #endif /* ENABLE_SSH */ |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 35 | |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame^] | 36 | #ifdef ENABLE_TLS |
| 37 | |
| 38 | typedef enum { |
| 39 | NC_TLS_CTN_UNKNOWN, |
| 40 | 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 Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 50 | /** |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 51 | * @brief Enumeration of possible session statuses |
| 52 | */ |
| 53 | typedef enum { |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 54 | NC_STATUS_STARTING = 0, /**< session is not yet fully initiated */ |
| 55 | NC_STATUS_CLOSING, /**< session is being closed */ |
| 56 | NC_STATUS_INVALID, /**< session is corrupted and it is supposed to be closed (nc_session_free()) */ |
| 57 | NC_STATUS_RUNNING /**< up and running */ |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 58 | } NC_STATUS; |
| 59 | |
| 60 | /** |
Michal Vasko | 38a7c6c | 2015-12-04 12:29:20 +0100 | [diff] [blame] | 61 | * @brief Enumeration of transport implementations (ways how libnetconf implements NETCONF transport protocol) |
| 62 | */ |
| 63 | typedef 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 Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 76 | * @brief NETCONF session object |
| 77 | */ |
| 78 | struct nc_session; |
| 79 | |
Radek Krejci | 695d4fa | 2015-10-22 13:23:54 +0200 | [diff] [blame] | 80 | /** |
| 81 | * @brief Free the NETCONF session object. |
| 82 | * |
| 83 | * @param[in] session Object to free. |
| 84 | */ |
| 85 | void nc_session_free(struct nc_session *session); |
| 86 | |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 87 | #ifdef ENABLE_SSH |
| 88 | |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 89 | /** |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 90 | * @brief Initialize libssh so that libnetconf2 can safely use it in a multi-threaded environment. |
Radek Krejci | fe0b347 | 2015-10-12 13:43:42 +0200 | [diff] [blame] | 91 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 92 | * Must be called before using any other functions. Afterwards can libssh be used in an application |
| 93 | * as well. |
Radek Krejci | 5686ff7 | 2015-10-09 13:33:56 +0200 | [diff] [blame] | 94 | */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 95 | void nc_ssh_init(void); |
Radek Krejci | 5686ff7 | 2015-10-09 13:33:56 +0200 | [diff] [blame] | 96 | |
| 97 | /** |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 98 | * @brief Free all the resources allocated by libssh. |
Radek Krejci | fe0b347 | 2015-10-12 13:43:42 +0200 | [diff] [blame] | 99 | * |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 100 | * Must be called before nc_tls_destroy() as libssh uses libcrypto as well. |
Radek Krejci | 5686ff7 | 2015-10-09 13:33:56 +0200 | [diff] [blame] | 101 | */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 102 | void nc_ssh_destroy(void); |
Radek Krejci | fe0b347 | 2015-10-12 13:43:42 +0200 | [diff] [blame] | 103 | |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 104 | #endif /* ENABLE_SSH */ |
| 105 | |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame^] | 106 | #ifdef ENABLE_TLS |
| 107 | |
| 108 | void nc_tls_init(void); |
| 109 | |
| 110 | void nc_tls_destroy(void); |
| 111 | |
| 112 | #endif /* ENABLE_TLS */ |
| 113 | |
Radek Krejci | 4339024 | 2015-10-08 15:34:04 +0200 | [diff] [blame] | 114 | #endif /* NC_SESSION_H_ */ |