Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 1 | /** |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 2 | * @file session_server_ch.h |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief libnetconf2 Call Home session server manipulation |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 5 | * |
Michal Vasko | 95ea9ff | 2021-11-09 12:29:14 +0100 | [diff] [blame] | 6 | * @copyright |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2021 CESNET, z.s.p.o. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 8 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
Michal Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 12 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 13 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef NC_SESSION_SERVER_CH_H_ |
| 17 | #define NC_SESSION_SERVER_CH_H_ |
| 18 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 23 | #include <libyang/libyang.h> |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 24 | #include <stdint.h> |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 25 | #include <time.h> |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 26 | |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 27 | #include "netconf.h" |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 28 | #include "session.h" |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 29 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 30 | #ifdef NC_ENABLED_SSH_TLS |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 31 | |
| 32 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 33 | * @defgroup server_ch Server-side Call Home |
| 34 | * @ingroup server |
| 35 | * |
| 36 | * @brief Call Home functionality for server-side applications. |
| 37 | * @{ |
| 38 | */ |
| 39 | |
roman | 3512097 | 2023-08-08 10:39:12 +0200 | [diff] [blame] | 40 | /** @} Server-side Call Home */ |
| 41 | |
| 42 | /** |
| 43 | * @defgroup server_ch_functions Server-side Call Home Functions |
| 44 | * @ingroup server_ch |
| 45 | * |
| 46 | * @brief Server-side Call Home functions. |
| 47 | * @{ |
| 48 | */ |
| 49 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 50 | /** |
Michal Vasko | fb1724b | 2020-01-31 11:02:00 +0100 | [diff] [blame] | 51 | * @brief Check if a Call Home client exists. |
| 52 | * |
| 53 | * @param[in] name Client name. |
| 54 | * @return 0 if does not exists, non-zero otherwise. |
| 55 | */ |
| 56 | int nc_server_ch_is_client(const char *name); |
| 57 | |
| 58 | /** |
Michal Vasko | fb1724b | 2020-01-31 11:02:00 +0100 | [diff] [blame] | 59 | * @brief Check if an endpoint of a Call Home client exists. |
| 60 | * |
| 61 | * @param[in] client_name Client name. |
| 62 | * @param[in] endpt_name Endpoint name. |
| 63 | * @return 0 if does not exists, non-zero otherwise. |
| 64 | */ |
| 65 | int nc_server_ch_client_is_endpt(const char *client_name, const char *endpt_name); |
| 66 | |
| 67 | /** |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 68 | * @brief Callback for getting a locked context for new Call Home sessions. |
| 69 | * |
| 70 | * @param[in] cb_data Arbitrary ctx callback data. |
| 71 | * @return Context for the session to use during its lifetime; |
| 72 | * @return NULL on error and session fails to be created. |
| 73 | */ |
| 74 | typedef const struct ly_ctx *(*nc_server_ch_session_acquire_ctx_cb)(void *cb_data); |
| 75 | |
| 76 | /** |
| 77 | * @brief Callback for releasing a locked context for Call Home sessions. |
| 78 | * |
| 79 | * @param[in] cb_data Arbitrary ctx callback data. |
| 80 | */ |
| 81 | typedef void (*nc_server_ch_session_release_ctx_cb)(void *cb_data); |
| 82 | |
| 83 | /** |
| 84 | * @brief Callback for new Call Home sessions. |
| 85 | * |
| 86 | * @param[in] client_name Name of the CH client which established the session. |
| 87 | * @param[in] new_session New established CH session, the pointer is internally discarded afterwards. |
roman | 450c00b | 2023-11-02 10:31:45 +0100 | [diff] [blame] | 88 | * @param[in] user_data Arbitrary new session callback data. |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 89 | * @return 0 on success; |
| 90 | * @return non-zero on error and @p new_session is freed. |
| 91 | */ |
roman | 5cbb653 | 2023-06-22 12:53:17 +0200 | [diff] [blame] | 92 | typedef int (*nc_server_ch_new_session_cb)(const char *client_name, struct nc_session *new_session, void *user_data); |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * @brief Dispatch a thread connecting to a listening NETCONF client and creating Call Home sessions. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 96 | * |
| 97 | * @param[in] client_name Existing client name. |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 98 | * @param[in] acquire_ctx_cb Callback for acquiring new session context. |
| 99 | * @param[in] release_ctx_cb Callback for releasing session context. |
| 100 | * @param[in] ctx_cb_data Arbitrary user data passed to @p acquire_ctx_cb and @p release_ctx_cb. |
| 101 | * @param[in] new_session_cb Callback called for every established session on the client. |
roman | 5cbb653 | 2023-06-22 12:53:17 +0200 | [diff] [blame] | 102 | * @param[in] new_session_cb_data Arbitrary user data passed to @p new_session_cb. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 103 | * @return 0 if the thread was successfully created, -1 on error. |
| 104 | */ |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 105 | int nc_connect_ch_client_dispatch(const char *client_name, nc_server_ch_session_acquire_ctx_cb acquire_ctx_cb, |
roman | 5cbb653 | 2023-06-22 12:53:17 +0200 | [diff] [blame] | 106 | nc_server_ch_session_release_ctx_cb release_ctx_cb, void *ctx_cb_data, nc_server_ch_new_session_cb new_session_cb, |
| 107 | void *new_session_cb_data); |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 108 | |
roman | 450c00b | 2023-11-02 10:31:45 +0100 | [diff] [blame] | 109 | /** |
| 110 | * @brief Set callbacks and their data for Call Home threads. |
| 111 | * |
roman | 43ba651 | 2023-11-03 13:58:45 +0100 | [diff] [blame] | 112 | * If set, Call Home threads will be dispatched automatically upon creation of new Call Home clients. |
roman | 450c00b | 2023-11-02 10:31:45 +0100 | [diff] [blame] | 113 | * |
| 114 | * @param[in] acquire_ctx_cb Callback for acquiring new session context. |
| 115 | * @param[in] release_ctx_cb Callback for releasing session context. |
| 116 | * @param[in] ctx_cb_data Arbitrary user data passed to @p acquire_ctx_cb and @p release_ctx_cb. |
roman | 43ba651 | 2023-11-03 13:58:45 +0100 | [diff] [blame] | 117 | * @param[in] new_session_cb Callback called for every established Call Home session. |
roman | 450c00b | 2023-11-02 10:31:45 +0100 | [diff] [blame] | 118 | * @param[in] new_session_cb_data Arbitrary user data passed to @p new_session_cb. |
| 119 | */ |
| 120 | void nc_server_ch_set_dispatch_data(nc_server_ch_session_acquire_ctx_cb acquire_ctx_cb, |
| 121 | nc_server_ch_session_release_ctx_cb release_ctx_cb, void *ctx_cb_data, nc_server_ch_new_session_cb new_session_cb, |
| 122 | void *new_session_cb_data); |
| 123 | |
roman | 3512097 | 2023-08-08 10:39:12 +0200 | [diff] [blame] | 124 | /** @} Server-side Call Home Functions */ |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 125 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 126 | #endif /* NC_ENABLED_SSH_TLS */ |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 127 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 128 | #ifdef __cplusplus |
| 129 | } |
| 130 | #endif |
| 131 | |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 132 | #endif /* NC_SESSION_SERVER_CH_H_ */ |