blob: 9b68863c63f1c3e3a6087f470cdefff25ed6c95f [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 {
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 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 */
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 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/**
81 * @brief Free the NETCONF session object.
82 *
83 * @param[in] session Object to free.
84 */
85void nc_session_free(struct nc_session *session);
86
Michal Vaskofb89d772016-01-08 12:25:35 +010087#ifdef ENABLE_SSH
88
Radek Krejci43390242015-10-08 15:34:04 +020089/**
Michal Vasko086311b2016-01-08 09:53:11 +010090 * @brief Initialize libssh so that libnetconf2 can safely use it in a multi-threaded environment.
Radek Krejcife0b3472015-10-12 13:43:42 +020091 *
Michal Vasko086311b2016-01-08 09:53:11 +010092 * Must be called before using any other functions. Afterwards can libssh be used in an application
93 * as well.
Radek Krejci5686ff72015-10-09 13:33:56 +020094 */
Michal Vasko086311b2016-01-08 09:53:11 +010095void nc_ssh_init(void);
Radek Krejci5686ff72015-10-09 13:33:56 +020096
97/**
Michal Vasko086311b2016-01-08 09:53:11 +010098 * @brief Free all the resources allocated by libssh.
Radek Krejcife0b3472015-10-12 13:43:42 +020099 *
Michal Vasko086311b2016-01-08 09:53:11 +0100100 * Must be called before nc_tls_destroy() as libssh uses libcrypto as well.
Radek Krejci5686ff72015-10-09 13:33:56 +0200101 */
Michal Vasko086311b2016-01-08 09:53:11 +0100102void nc_ssh_destroy(void);
Radek Krejcife0b3472015-10-12 13:43:42 +0200103
Michal Vaskofb89d772016-01-08 12:25:35 +0100104#endif /* ENABLE_SSH */
105
Michal Vaskoc14e3c82016-01-11 16:14:30 +0100106#ifdef ENABLE_TLS
107
108void nc_tls_init(void);
109
110void nc_tls_destroy(void);
111
112#endif /* ENABLE_TLS */
113
Radek Krejci43390242015-10-08 15:34:04 +0200114#endif /* NC_SESSION_H_ */