blob: 40fcc024740889ab741af232d4c4c57d808ecba6 [file] [log] [blame]
Michal Vasko086311b2016-01-08 09:53:11 +01001/**
2 * \file session_client.h
3 * \author Michal Vasko <mvasko@cesnet.cz>
4 * \brief libnetconf2 session client manipulation
5 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01008 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
Michal Vaskoafd416b2016-02-25 14:51:46 +010011 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010012 * https://opensource.org/licenses/BSD-3-Clause
Michal Vasko086311b2016-01-08 09:53:11 +010013 */
14
15#ifndef NC_SESSION_CLIENT_H_
16#define NC_SESSION_CLIENT_H_
17
18#include <libyang/libyang.h>
19
Radek Krejci53691be2016-02-22 13:58:37 +010020#ifdef NC_ENABLED_SSH
Michal Vasko086311b2016-01-08 09:53:11 +010021
22#include <libssh/libssh.h>
23
24#endif
25
Radek Krejci53691be2016-02-22 13:58:37 +010026#ifdef NC_ENABLED_TLS
Michal Vasko086311b2016-01-08 09:53:11 +010027
28#include <openssl/ssl.h>
29
30#endif
31
32#include "session.h"
33#include "netconf.h"
Michal Vasko7bcb48e2016-01-15 10:28:54 +010034#include "messages_client.h"
Michal Vasko086311b2016-01-08 09:53:11 +010035
36/**
37 * @brief Set location where libnetconf tries to search for YANG/YIN schemas.
38 *
Michal Vasko7f1c0ef2016-03-11 11:13:06 +010039 * The location is searched when connecting to a NETCONF server and building
Michal Vasko086311b2016-01-08 09:53:11 +010040 * YANG context for further processing of the NETCONF messages and data.
41 *
Michal Vasko086311b2016-01-08 09:53:11 +010042 * @param[in] path Directory where to search for YANG/YIN schemas.
43 * @return 0 on success, 1 on (memory allocation) failure.
44 */
Michal Vasko7f1c0ef2016-03-11 11:13:06 +010045int nc_client_set_schema_searchpath(const char *path);
46
47/**
48 * @brief Get schema searchpath that was set by nc_client_set_schema_searchpath().
49 *
50 * @return Schema searchpath directory, NULL if not set.
51 */
52const char *nc_client_get_schema_searchpath(void);
Michal Vasko086311b2016-01-08 09:53:11 +010053
54/**
Michal Vaskoa7b8ca52016-03-01 12:09:29 +010055 * @brief Initialize libssh and/or libssl/libcrypto for use in the client.
56 */
57void nc_client_init(void);
58
59/**
60 * @brief Destroy all libssh and/or libssl/libcrypto dynamic memory and
61 * the client options, for both SSH and TLS, and for Call Home too.
Michal Vaskob7558c52016-02-26 15:04:19 +010062 */
63void nc_client_destroy(void);
64
65/**
Michal Vasko086311b2016-01-08 09:53:11 +010066 * @brief Connect to the NETCONF server via proviaded input/output file descriptors.
67 *
68 * Transport layer is supposed to be already set. Function do not cover authentication
69 * or any other manipulation with the transport layer, it only establish NETCONF session
70 * by sending and processing NETCONF \<hello\> messages.
71 *
Michal Vasko086311b2016-01-08 09:53:11 +010072 * @param[in] fdin Input file descriptor for reading (clear) data from NETCONF server.
73 * @param[in] fdout Output file descriptor for writing (clear) data for NETCONF server.
74 * @param[in] ctx Optional parameter. If set, provides strict YANG context for the session
75 * (ignoring what is actually supported by the server side). If not set,
76 * YANG context is created for the session using \<get-schema\> (if supported
77 * by the server side) or/and by searching for YANG schemas in the searchpath
Radek Krejcic9a6d252016-03-04 14:50:34 +010078 * (see nc_client_schema_searchpath()). In every case except not providing context
Michal Vasko086311b2016-01-08 09:53:11 +010079 * to connect to a server supporting \<get-schema\> it is possible that
80 * the session context will not include all the models supported by the server.
81 * @return Created NETCONF session object or NULL in case of error.
82 */
83struct nc_session *nc_connect_inout(int fdin, int fdout, struct ly_ctx *ctx);
84
Radek Krejci53691be2016-02-22 13:58:37 +010085#ifdef NC_ENABLED_SSH
Michal Vasko086311b2016-01-08 09:53:11 +010086
87/**
Michal Vaskoef112d72016-02-18 13:28:25 +010088 * @brief Set SSH authentication hostkey check (knownhosts) callback.
89 *
90 * @param[in] auth_hostkey_check Function to call, returns 0 on success, non-zero in error.
91 * If NULL, the default callback is set.
92 */
93void nc_client_ssh_set_auth_hostkey_check_clb(int (*auth_hostkey_check)(const char *hostname, ssh_session session));
94
95/**
Michal Vasko30e2c872016-02-18 10:03:21 +010096 * @brief Set SSH password authentication callback.
97 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010098 * @param[in] auth_password Function to call, returns the password for username\@hostname.
Michal Vasko30e2c872016-02-18 10:03:21 +010099 * If NULL, the default callback is set.
100 */
101void nc_client_ssh_set_auth_password_clb(char *(*auth_password)(const char *username, const char *hostname));
102
103/**
104 * @brief Set SSH interactive authentication callback.
105 *
106 * @param[in] auth_interactive Function to call for every question, returns the answer for
107 * authentication name with instruction and echoing prompt.
108 * If NULL, the default callback is set.
109 */
110void nc_client_ssh_set_auth_interactive_clb(char *(*auth_interactive)(const char *auth_name, const char *instruction,
111 const char *prompt, int echo));
112
113/**
114 * @brief Set SSH publickey authentication encrypted private key passphrase callback.
115 *
116 * @param[in] auth_privkey_passphrase Function to call for every question, returns
117 * the passphrase for the specific private key.
118 */
119void nc_client_ssh_set_auth_privkey_passphrase_clb(char *(*auth_privkey_passphrase)(const char *privkey_path));
120
121/**
Michal Vasko3031aae2016-01-27 16:07:18 +0100122 * @brief Add an SSH public and private key pair to be used for client authentication.
123 *
124 * Private key can be encrypted, the passphrase will be asked for before using it.
125 *
Michal Vasko3031aae2016-01-27 16:07:18 +0100126 * @param[in] pub_key Path to the public key.
127 * @param[in] priv_key Path to the private key.
Michal Vaskof0537d82016-01-29 14:42:38 +0100128 * @return 0 on success, -1 on error.
Michal Vasko3031aae2016-01-27 16:07:18 +0100129 */
130int nc_client_ssh_add_keypair(const char *pub_key, const char *priv_key);
131
132/**
133 * @brief Remove an SSH public and private key pair that was used for client authentication.
134 *
Michal Vasko3031aae2016-01-27 16:07:18 +0100135 * @param[in] idx Index of the keypair starting with 0.
Michal Vasko3031aae2016-01-27 16:07:18 +0100136 * @return 0 on success, -1 on error.
137 */
138int nc_client_ssh_del_keypair(int idx);
139
140/**
141 * @brief Get the number of public an private key pairs set to be used for client authentication.
142 *
143 * @return Keypair count.
144 */
145int nc_client_ssh_get_keypair_count(void);
146
147/**
148 * @brief Get a specific keypair set to be used for client authentication.
149 *
150 * @param[in] idx Index of the specific keypair.
151 * @param[out] pub_key Path to the public key.
152 * @param[out] priv_key Path to the private key.
Michal Vasko3031aae2016-01-27 16:07:18 +0100153 * @return 0 on success, -1 on error.
154 */
155int nc_client_ssh_get_keypair(int idx, const char **pub_key, const char **priv_key);
156
157/**
158 * @brief Set SSH authentication method preference.
159 *
Michal Vasko3031aae2016-01-27 16:07:18 +0100160 * @param[in] auth_type Authentication method to modify the prefrence of.
161 * @param[in] pref Preference of \p auth_type. Negative values disable the method.
162 */
163void nc_client_ssh_set_auth_pref(NC_SSH_AUTH_TYPE auth_type, int16_t pref);
164
165/**
166 * @brief Get SSH authentication method preference.
167 *
Michal Vasko3031aae2016-01-27 16:07:18 +0100168 * @param[in] auth_type Authentication method to retrieve the prefrence of.
Michal Vasko3031aae2016-01-27 16:07:18 +0100169 * @return Preference of the \p auth_type.
170 */
171int16_t nc_client_ssh_get_auth_pref(NC_SSH_AUTH_TYPE auth_type);
172
173/**
174 * @brief Set client SSH username used for authentication.
175 *
176 * @param[in] username Username to use.
177 * @return 0 on success, -1 on error.
178 */
179int nc_client_ssh_set_username(const char *username);
180
Michal Vasko3031aae2016-01-27 16:07:18 +0100181/**
Michal Vaskoe22c6732016-01-29 11:03:02 +0100182 * @brief Get client SSH username used for authentication.
183 *
184 * @return Username used.
185 */
186const char *nc_client_ssh_get_username(void);
187
188/**
Michal Vasko086311b2016-01-08 09:53:11 +0100189 * @brief Connect to the NETCONF server using SSH transport (via libssh).
190 *
191 * SSH session is created with default options. If the caller needs to use specific SSH session properties,
192 * they are supposed to use nc_connect_libssh().
193 *
Michal Vasko086311b2016-01-08 09:53:11 +0100194 * @param[in] host Hostname or address (both Ipv4 and IPv6 are accepted) of the target server.
195 * 'localhost' is used by default if NULL is specified.
196 * @param[in] port Port number of the target server. Default value 830 is used if 0 is specified.
Michal Vasko086311b2016-01-08 09:53:11 +0100197 * @param[in] ctx Optional parameter. If set, provides strict YANG context for the session
198 * (ignoring what is actually supported by the server side). If not set,
199 * YANG context is created for the session using \<get-schema\> (if supported
200 * by the server side) or/and by searching for YANG schemas in the searchpath
Radek Krejcic9a6d252016-03-04 14:50:34 +0100201 * (see nc_client_schema_searchpath()). In every case except not providing context
Michal Vasko086311b2016-01-08 09:53:11 +0100202 * to connect to a server supporting \<get-schema\> it is possible that
203 * the session context will not include all the models supported by the server.
204 * @return Created NETCONF session object or NULL on error.
205 */
Michal Vasko3031aae2016-01-27 16:07:18 +0100206struct nc_session *nc_connect_ssh(const char *host, uint16_t port, struct ly_ctx *ctx);
Michal Vasko086311b2016-01-08 09:53:11 +0100207
208/**
209 * @brief Connect to the NETCONF server using the provided SSH (libssh) session.
210 *
211 * SSH session can have any options set, they will not be modified. If no options were set,
212 * host 'localhost', port 22, and the username detected from the EUID is used. If socket is
213 * set and connected only the host and the username must be set/is detected. Or the \p ssh_session
214 * can already be authenticated in which case it is used directly.
215 *
Michal Vasko086311b2016-01-08 09:53:11 +0100216 * @param[in] ssh_session libssh structure representing SSH session object. After passing it
217 * to libnetconf2 this way, it is fully managed by it (including freeing!).
218 * @param[in] ctx Optional parameter. If set, provides strict YANG context for the session
219 * (ignoring what is actually supported by the server side). If not set,
220 * YANG context is created for the session using \<get-schema\> (if supported
221 * by the server side) or/and by searching for YANG schemas in the searchpath
Radek Krejcic9a6d252016-03-04 14:50:34 +0100222 * (see nc_client_schema_searchpath()). In every case except not providing context
Michal Vasko086311b2016-01-08 09:53:11 +0100223 * to connect to a server supporting \<get-schema\> it is possible that
224 * the session context will not include all the models supported by the server.
225 * @return Created NETCONF session object or NULL on error.
226 */
227struct nc_session *nc_connect_libssh(ssh_session ssh_session, struct ly_ctx *ctx);
228
229/**
230 * @brief Create another NETCONF session on existing SSH session using separated SSH channel.
231 *
Michal Vasko086311b2016-01-08 09:53:11 +0100232 * @param[in] session Existing NETCONF session. The session has to be created on SSH transport layer using libssh -
233 * it has to be created by nc_connect_ssh(), nc_connect_libssh() or nc_connect_ssh_channel().
234 * @param[in] ctx Optional parameter. If set, provides strict YANG context for the session
235 * (ignoring what is actually supported by the server side). If not set,
236 * YANG context is created for the session using \<get-schema\> (if supported
237 * by the server side) or/and by searching for YANG schemas in the searchpath
Radek Krejcic9a6d252016-03-04 14:50:34 +0100238 * (see nc_client_schema_searchpath()). In every case except not providing context
Michal Vasko086311b2016-01-08 09:53:11 +0100239 * to connect to a server supporting \<get-schema\> it is possible that
240 * the session context will not include all the models supported by the server.
241 * @return Created NETCONF session object or NULL on error.
242 */
243struct nc_session *nc_connect_ssh_channel(struct nc_session *session, struct ly_ctx *ctx);
244
Radek Krejci53691be2016-02-22 13:58:37 +0100245#endif /* NC_ENABLED_SSH */
Michal Vasko086311b2016-01-08 09:53:11 +0100246
Radek Krejci53691be2016-02-22 13:58:37 +0100247#ifdef NC_ENABLED_TLS
Michal Vasko086311b2016-01-08 09:53:11 +0100248
249/**
Michal Vasko3031aae2016-01-27 16:07:18 +0100250 * @brief Set client authentication identity - a certificate and a private key.
Michal Vasko086311b2016-01-08 09:53:11 +0100251 *
Michal Vaskoe22c6732016-01-29 11:03:02 +0100252 * @param[in] client_cert Path to the file containing the client certificate.
Michal Vasko086311b2016-01-08 09:53:11 +0100253 * @param[in] client_key Path to the file containing the private key for the \p client_cert.
254 * If NULL, key is expected to be stored with \p client_cert.
Michal Vasko3031aae2016-01-27 16:07:18 +0100255 * @return 0 on success, -1 on error.
256 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100257int nc_client_tls_set_cert_key_paths(const char *client_cert, const char *client_key);
Michal Vasko3031aae2016-01-27 16:07:18 +0100258
259/**
Michal Vaskoe22c6732016-01-29 11:03:02 +0100260 * @brief Get client authentication identity - a certificate and a private key.
261 *
Michal Vaskoe22c6732016-01-29 11:03:02 +0100262 * @param[out] client_cert Path to the file containing the client certificate. Can be NULL.
263 * @param[out] client_key Path to the file containing the private key for the \p client_cert. Can be NULL.
264 */
265void nc_client_tls_get_cert_key_paths(const char **client_cert, const char **client_key);
266
267/**
268 * @brief Set client trusted CA certificates paths.
Michal Vasko3031aae2016-01-27 16:07:18 +0100269 *
Michal Vasko086311b2016-01-08 09:53:11 +0100270 * @param[in] ca_file Location of the CA certificate file used to verify server certificates.
271 * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL.
272 * @param[in] ca_dir Location of the CA certificates directory used to verify the server certificates.
273 * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL.
Michal Vasko3031aae2016-01-27 16:07:18 +0100274 * @return 0 on success, -1 on error.
275 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100276int nc_client_tls_set_trusted_ca_paths(const char *ca_file, const char *ca_dir);
Michal Vasko3031aae2016-01-27 16:07:18 +0100277
278/**
Michal Vaskoe22c6732016-01-29 11:03:02 +0100279 * @brief Get client trusted CA certificates paths.
280 *
281 * @param[out] ca_file Location of the CA certificate file used to verify server certificates.
282 * Can be NULL.
283 * @param[out] ca_dir Location of the CA certificates directory used to verify the server certificates.
284 * Can be NULL.
285 */
286void nc_client_tls_get_trusted_ca_paths(const char **ca_file, const char **ca_dir);
287
288/**
289 * @brief Set client Certificate Revocation List paths.
Michal Vasko3031aae2016-01-27 16:07:18 +0100290 *
Michal Vasko086311b2016-01-08 09:53:11 +0100291 * @param[in] crl_file Location of the CRL certificate file used to check for revocated certificates.
292 * @param[in] crl_dir Location of the CRL certificate directory used to check for revocated certificates.
Michal Vasko3031aae2016-01-27 16:07:18 +0100293 * @return 0 on success, -1 on error.
294 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100295int nc_client_tls_set_crl_paths(const char *crl_file, const char *crl_dir);
296
297/**
298 * @brief Get client Certificate Revocation List paths.
299 *
300 * @param[out] crl_file Location of the CRL certificate file used to check for revocated certificates.
301 * @param[out] crl_dir Location of the CRL certificate directory used to check for revocated certificates.
302 */
303void nc_client_tls_get_crl_paths(const char **crl_file, const char **crl_dir);
Michal Vasko3031aae2016-01-27 16:07:18 +0100304
Michal Vasko3031aae2016-01-27 16:07:18 +0100305/**
Michal Vasko086311b2016-01-08 09:53:11 +0100306 * @brief Connect to the NETCONF server using TLS transport (via libssl)
307 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +0100308 * TLS session is created with the certificates set using nc_client_tls_* functions, which must be called beforehand!
Michal Vasko086311b2016-01-08 09:53:11 +0100309 * If the caller needs to use specific TLS session properties, they are supposed to use nc_connect_libssl().
310 *
Michal Vasko086311b2016-01-08 09:53:11 +0100311 * @param[in] host Hostname or address (both Ipv4 and IPv6 are accepted) of the target server.
312 * 'localhost' is used by default if NULL is specified.
313 * @param[in] port Port number of the target server. Default value 6513 is used if 0 is specified.
314 * @param[in] ctx Optional parameter. If set, provides strict YANG context for the session
315 * (ignoring what is actually supported by the server side). If not set,
316 * YANG context is created for the session using \<get-schema\> (if supported
317 * by the server side) or/and by searching for YANG schemas in the searchpath
Radek Krejcic9a6d252016-03-04 14:50:34 +0100318 * (see nc_client_schema_searchpath()). In every case except not providing context
Michal Vasko086311b2016-01-08 09:53:11 +0100319 * to connect to a server supporting \<get-schema\> it is possible that
320 * the session context will not include all the models supported by the server.
321 * @return Created NETCONF session object or NULL on error.
322 */
323struct nc_session *nc_connect_tls(const char *host, uint16_t port, struct ly_ctx *ctx);
324
325/**
326 * @brief Connect to the NETCONF server using the provided TLS (libssl) session.
327 *
328 * The TLS session supplied is expected to be fully connected and authenticated!
329 *
Michal Vasko086311b2016-01-08 09:53:11 +0100330 * @param[in] tls libssl structure representing the TLS session object.
331 * @param[in] ctx Optional parameter. If set, provides strict YANG context for the session
332 * (ignoring what is actually supported by the server side). If not set,
333 * YANG context is created for the session using \<get-schema\> (if supported
334 * by the server side) or/and by searching for YANG schemas in the searchpath
Radek Krejcic9a6d252016-03-04 14:50:34 +0100335 * (see nc_client_schema_searchpath()). In every case except not providing context
Michal Vasko086311b2016-01-08 09:53:11 +0100336 * to connect to a server supporting \<get-schema\> it is possible that
337 * the session context will not include all the models supported by the server.
338 * @return Created NETCONF session object or NULL on error.
339 */
340struct nc_session *nc_connect_libssl(SSL *tls, struct ly_ctx *ctx);
341
Radek Krejci53691be2016-02-22 13:58:37 +0100342#endif /* NC_ENABLED_TLS */
Michal Vasko086311b2016-01-08 09:53:11 +0100343
344/**
Michal Vaskobdfb5242016-05-24 09:11:01 +0200345 * @brief Get session capabilities.
346 *
347 * @param[in] session Session to get the information from.
348 * @return Session capabilities.
349 */
350const char **nc_session_get_cpblts(const struct nc_session *session);
351
352/**
353 * @brief Check capability presence in a session.
354 *
355 * @param[in] session Session to check.
356 * @param[in] capab Capability to look for, capability with any additional suffix will match.
357 * @return Matching capability, NULL if none found.
358 */
359const char *nc_session_cpblt(const struct nc_session *session, const char *capab);
360
361/**
Michal Vasko9cd26a82016-05-31 08:58:48 +0200362 * @brief Check whether the session has a notification thread running.
363 *
364 * @param[in] session Session to check.
365 * @return 1 if notfication thread is running, 0 otherwise.
366 */
367int nc_session_ntf_thread_running(const struct nc_session *session);
368
369/**
Michal Vasko086311b2016-01-08 09:53:11 +0100370 * @brief Receive NETCONF RPC reply.
371 *
Michal Vasko12257e92016-11-22 09:30:37 +0100372 * Be careful, normally there is a whole RPC reply (output) of an RPC in the \p reply.
373 * However, if a reply to \<get\> or \<get-config\> RPC is received, the \p reply is
374 * actually the configuration (with either state data or not). This means, for example,
375 * that the reply data in these cases should not be validated with #LYD_OPT_RPCREPLY,
376 * but #LYD_OPT_GET and #LYD_OPT_GETCONFIG, respectively.
Michal Vasko086311b2016-01-08 09:53:11 +0100377 *
378 * @param[in] session NETCONF session from which the function gets data. It must be the
379 * client side session object.
380 * @param[in] rpc Original RPC this should be the reply to.
381 * @param[in] msgid Expected message ID of the reply.
382 * @param[in] timeout Timeout for reading in milliseconds. Use negative value for infinite
Michal Vasko71ba2da2016-05-04 10:53:16 +0200383 * waiting and 0 for immediate return if data are not available on the wire.
Michal Vaskoeb7080e2016-02-18 13:27:05 +0100384 * @param[in] parseroptions libyang parseroptions flags, do not set the data type, it is set
385 * internally. LYD_OPT_DESTRUCT and LYD_OPT_NOSIBLINGS is ignored.
Michal Vasko086311b2016-01-08 09:53:11 +0100386 * @param[out] reply Resulting object of NETCONF RPC reply.
Michal Vasko71ba2da2016-05-04 10:53:16 +0200387 * @return #NC_MSG_REPLY for success,
388 * #NC_MSG_WOULDBLOCK if \p timeout has elapsed,
389 * #NC_MSG_ERROR if reading has failed,
390 * #NC_MSG_NOTIF if a notification was read instead (call this function again to get the reply), and
391 * #NC_MSG_REPLY_ERR_MSGID if a reply with missing or wrong message-id was received.
Michal Vasko086311b2016-01-08 09:53:11 +0100392 */
Michal Vaskod083db62016-01-19 10:31:29 +0100393NC_MSG_TYPE nc_recv_reply(struct nc_session *session, struct nc_rpc *rpc, uint64_t msgid, int timeout,
Michal Vaskoeb7080e2016-02-18 13:27:05 +0100394 int parseroptions, struct nc_reply **reply);
Michal Vasko086311b2016-01-08 09:53:11 +0100395
396/**
397 * @brief Receive NETCONF Notification.
398 *
399 * @param[in] session NETCONF session from which the function gets data. It must be the
400 * client side session object.
401 * @param[in] timeout Timeout for reading in milliseconds. Use negative value for infinite
Michal Vasko71ba2da2016-05-04 10:53:16 +0200402 * waiting and 0 for immediate return if data are not available on the wire.
Michal Vasko086311b2016-01-08 09:53:11 +0100403 * @param[out] notif Resulting object of NETCONF Notification.
Michal Vasko71ba2da2016-05-04 10:53:16 +0200404 * @return #NC_MSG_NOTIF for success,
405 * #NC_MSG_WOULDBLOCK if \p timeout has elapsed,
406 * #NC_MSG_ERROR if reading has failed, and
407 * #NC_MSG_REPLY if a reply was read instead (call this function again to get a notification).
Michal Vasko086311b2016-01-08 09:53:11 +0100408 */
Michal Vaskod083db62016-01-19 10:31:29 +0100409NC_MSG_TYPE nc_recv_notif(struct nc_session* session, int timeout, struct nc_notif **notif);
Michal Vasko086311b2016-01-08 09:53:11 +0100410
411/**
Michal Vaskoa8ad4482016-01-28 14:25:54 +0100412 * @brief Receive NETCONF Notifications in a separate thread until the session is terminated
413 * or \<notificationComplete\> is received.
414 *
415 * @param[in] session Netconf session to read notifications from.
416 * @param[in] notif_clb Function that is called for every received notification (including
417 * \<notificationComplete\>). Parameters are the session the notification was received on
418 * and the notification itself.
419 * @return 0 if the thread was successfully created, -1 on error.
420 */
421int nc_recv_notif_dispatch(struct nc_session *session,
422 void (*notif_clb)(struct nc_session *session, const struct nc_notif *notif));
423
424/**
Michal Vasko086311b2016-01-08 09:53:11 +0100425 * @brief Send NETCONF RPC message via the session.
426 *
427 * @param[in] session NETCONF session where the RPC will be written.
428 * @param[in] rpc NETCOFN RPC object to send via specified session. Object can be created by
429 * nc_rpc_lock(), nc_rpc_unlock() and nc_rpc_generic() functions.
430 * @param[in] timeout Timeout for writing in milliseconds. Use negative value for infinite
431 * waiting and 0 for return if data cannot be sent immediately.
432 * @param[out] msgid If RPC was successfully sent, this is it's message ID.
Michal Vasko71ba2da2016-05-04 10:53:16 +0200433 * @return #NC_MSG_RPC on success,
434 * #NC_MSG_WOULDBLOCK in case of a busy session, and
435 * #NC_MSG_ERROR on error.
Michal Vasko086311b2016-01-08 09:53:11 +0100436 */
Michal Vaskod083db62016-01-19 10:31:29 +0100437NC_MSG_TYPE nc_send_rpc(struct nc_session *session, struct nc_rpc *rpc, int timeout, uint64_t *msgid);
Michal Vasko086311b2016-01-08 09:53:11 +0100438
439#endif /* NC_SESSION_CLIENT_H_ */