blob: 6b5ff1978c76e5369ef972964c997d67eaa95741 [file] [log] [blame]
Michal Vasko45f298f2016-01-29 10:26:26 +01001/**
Michal Vaskoc446a382021-06-18 08:54:05 +02002 * @file session_server_ch.h
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief libnetconf2 Call Home session server manipulation
Michal Vasko45f298f2016-01-29 10:26:26 +01005 *
Michal Vasko95ea9ff2021-11-09 12:29:14 +01006 * @copyright
Michal Vaskoc446a382021-06-18 08:54:05 +02007 * Copyright (c) 2015 - 2021 CESNET, z.s.p.o.
Michal Vasko45f298f2016-01-29 10:26:26 +01008 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01009 * 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 Vaskoafd416b2016-02-25 14:51:46 +010012 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010013 * https://opensource.org/licenses/BSD-3-Clause
Michal Vasko45f298f2016-01-29 10:26:26 +010014 */
15
16#ifndef NC_SESSION_SERVER_CH_H_
17#define NC_SESSION_SERVER_CH_H_
18
Michal Vaskoc09730e2019-01-17 10:07:26 +010019#ifdef __cplusplus
20extern "C" {
21#endif
22
Michal Vasko45f298f2016-01-29 10:26:26 +010023#include <libyang/libyang.h>
Michal Vaskob83a3fa2021-05-26 09:53:42 +020024#include <stdint.h>
roman3f9b65c2023-06-05 14:26:58 +020025#include <time.h>
Michal Vasko45f298f2016-01-29 10:26:26 +010026
Michal Vasko45f298f2016-01-29 10:26:26 +010027#include "netconf.h"
Michal Vaskob83a3fa2021-05-26 09:53:42 +020028#include "session.h"
Michal Vasko45f298f2016-01-29 10:26:26 +010029
roman2eab4742023-06-06 10:00:26 +020030#ifdef NC_ENABLED_SSH_TLS
Michal Vasko45f298f2016-01-29 10:26:26 +010031
32/**
Radek Krejci6799a052017-05-19 14:23:23 +020033 * @defgroup server_ch Server-side Call Home
34 * @ingroup server
35 *
36 * @brief Call Home functionality for server-side applications.
37 * @{
38 */
39
roman35120972023-08-08 10:39:12 +020040/** @} 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 Krejci6799a052017-05-19 14:23:23 +020050/**
Michal Vaskofb1724b2020-01-31 11:02:00 +010051 * @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 */
56int nc_server_ch_is_client(const char *name);
57
58/**
Michal Vaskofb1724b2020-01-31 11:02:00 +010059 * @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 */
65int nc_server_ch_client_is_endpt(const char *client_name, const char *endpt_name);
66
67/**
Michal Vasko93224072021-11-09 12:14:28 +010068 * @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 */
74typedef 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 */
81typedef 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.
roman450c00b2023-11-02 10:31:45 +010088 * @param[in] user_data Arbitrary new session callback data.
Michal Vasko93224072021-11-09 12:14:28 +010089 * @return 0 on success;
90 * @return non-zero on error and @p new_session is freed.
91 */
roman5cbb6532023-06-22 12:53:17 +020092typedef int (*nc_server_ch_new_session_cb)(const char *client_name, struct nc_session *new_session, void *user_data);
Michal Vasko93224072021-11-09 12:14:28 +010093
94/**
95 * @brief Dispatch a thread connecting to a listening NETCONF client and creating Call Home sessions.
Michal Vasko2e6defd2016-10-07 15:48:15 +020096 *
97 * @param[in] client_name Existing client name.
Michal Vasko93224072021-11-09 12:14:28 +010098 * @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.
roman5cbb6532023-06-22 12:53:17 +0200102 * @param[in] new_session_cb_data Arbitrary user data passed to @p new_session_cb.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200103 * @return 0 if the thread was successfully created, -1 on error.
104 */
Michal Vasko93224072021-11-09 12:14:28 +0100105int nc_connect_ch_client_dispatch(const char *client_name, nc_server_ch_session_acquire_ctx_cb acquire_ctx_cb,
roman5cbb6532023-06-22 12:53:17 +0200106 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 Vasko2e6defd2016-10-07 15:48:15 +0200108
roman450c00b2023-11-02 10:31:45 +0100109/**
110 * @brief Set callbacks and their data for Call Home threads.
111 *
112 * If set, Call Home threads will be dispatched automatically upon creation of a new Call Home clients.
113 * Calling this will replace all the previously set callbacks and their data.
114 *
115 * @param[in] acquire_ctx_cb Callback for acquiring new session context.
116 * @param[in] release_ctx_cb Callback for releasing session context.
117 * @param[in] ctx_cb_data Arbitrary user data passed to @p acquire_ctx_cb and @p release_ctx_cb.
118 * @param[in] new_session_cb Callback called for every established session on the client.
119 * @param[in] new_session_cb_data Arbitrary user data passed to @p new_session_cb.
120 */
121void nc_server_ch_set_dispatch_data(nc_server_ch_session_acquire_ctx_cb acquire_ctx_cb,
122 nc_server_ch_session_release_ctx_cb release_ctx_cb, void *ctx_cb_data, nc_server_ch_new_session_cb new_session_cb,
123 void *new_session_cb_data);
124
roman35120972023-08-08 10:39:12 +0200125/** @} Server-side Call Home Functions */
Radek Krejci6799a052017-05-19 14:23:23 +0200126
roman2eab4742023-06-06 10:00:26 +0200127#endif /* NC_ENABLED_SSH_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +0100128
Michal Vaskoc09730e2019-01-17 10:07:26 +0100129#ifdef __cplusplus
130}
131#endif
132
Michal Vasko45f298f2016-01-29 10:26:26 +0100133#endif /* NC_SESSION_SERVER_CH_H_ */