libnetconf2 2.0.24
NETCONF server and client library in C.
Loading...
Searching...
No Matches
Client Session

Client-side NETCONF session manipulation. More...

Collaboration diagram for Client Session:

Functions

void nc_client_session_set_not_strict (struct nc_session *session)
 Make a session not strict when sending RPCs and receiving RPC replies. In other words, it will silently skip unknown nodes without an error.
 
struct nc_session * nc_connect_inout (int fdin, int fdout, struct ly_ctx *ctx)
 Connect to the NETCONF server via proviaded input/output file descriptors.
 
struct nc_session * nc_connect_unix (const char *address, struct ly_ctx *ctx)
 Connect to the NETCONF server via unix socket.
 
NC_MSG_TYPE nc_recv_notif (struct nc_session *session, int timeout, struct lyd_node **envp, struct lyd_node **op)
 Receive NETCONF Notification.
 
int nc_recv_notif_dispatch (struct nc_session *session, void(*notif_clb)(struct nc_session *session, const struct lyd_node *envp, const struct lyd_node *op))
 Receive NETCONF Notifications in a separate thread until the session is terminated or <notificationComplete> is received.
 
NC_MSG_TYPE nc_recv_reply (struct nc_session *session, struct nc_rpc *rpc, uint64_t msgid, int timeout, struct lyd_node **envp, struct lyd_node **op)
 Receive NETCONF RPC reply.
 
NC_MSG_TYPE nc_send_rpc (struct nc_session *session, struct nc_rpc *rpc, int timeout, uint64_t *msgid)
 Send NETCONF RPC message via the session.
 
const char * nc_session_cpblt (const struct nc_session *session, const char *capab)
 Check capability presence in a session.
 
const char *const * nc_session_get_cpblts (const struct nc_session *session)
 Get session capabilities.
 
int nc_session_ntf_thread_running (const struct nc_session *session)
 Check whether the session has a notification thread running.
 

Detailed Description

Client-side NETCONF session manipulation.

Function Documentation

◆ nc_client_session_set_not_strict()

void nc_client_session_set_not_strict ( struct nc_session *  session)

Make a session not strict when sending RPCs and receiving RPC replies. In other words, it will silently skip unknown nodes without an error.

Generally, no such data should be worked with, so use this function only when you know what you are doing and you understand the consequences.

Parameters
[in]sessionNETCONF client session.

◆ nc_connect_inout()

struct nc_session * nc_connect_inout ( int  fdin,
int  fdout,
struct ly_ctx *  ctx 
)

Connect to the NETCONF server via proviaded input/output file descriptors.

Transport layer is supposed to be already set. Function do not cover authentication or any other manipulation with the transport layer, it only establish NETCONF session by sending and processing NETCONF <hello> messages.

Parameters
[in]fdinInput file descriptor for reading (clear) data from NETCONF server.
[in]fdoutOutput file descriptor for writing (clear) data for NETCONF server.
[in]ctxOptional parameter. If set, provides strict YANG context for the session (ignoring what is actually supported by the server side). If not set, YANG context is created for the session using <get-schema> (if supported by the server side) or/and by searching for YANG schemas in the searchpath (see nc_client_schema_searchpath()). In every case except not providing context to connect to a server supporting <get-schema> it is possible that the session context will not include all the models supported by the server.
Returns
Created NETCONF session object or NULL in case of error.

◆ nc_connect_unix()

struct nc_session * nc_connect_unix ( const char *  address,
struct ly_ctx *  ctx 
)

Connect to the NETCONF server via unix socket.

Connect to netconf server via an unix socket. Function do not cover authentication or any other manipulation with the transport layer, it only establish NETCONF session by sending and processing NETCONF <hello> messages.

Parameters
[in]addressPath to the unix socket.
[in]ctxOptional parameter. If set, provides strict YANG context for the session (ignoring what is actually supported by the server side). If not set, YANG context is created for the session using <get-schema> (if supported by the server side) or/and by searching for YANG schemas in the searchpath (see nc_client_schema_searchpath()). In every case except not providing context to connect to a server supporting <get-schema> it is possible that the session context will not include all the models supported by the server.
Returns
Created NETCONF session object or NULL in case of error.

◆ nc_recv_notif()

NC_MSG_TYPE nc_recv_notif ( struct nc_session *  session,
int  timeout,
struct lyd_node **  envp,
struct lyd_node **  op 
)

Receive NETCONF Notification.

Parameters
[in]sessionNETCONF session from which the function gets data. It must be the client side session object.
[in]timeoutTimeout for reading in milliseconds. Use negative value for infinite waiting and 0 for immediate return if data are not available on the wire.
[out]envpNETCONF notification XML envelopes.
[out]opParsed NETCONF notification data.
Returns
NC_MSG_NOTIF for success, NC_MSG_WOULDBLOCK if timeout has elapsed, NC_MSG_ERROR if reading has failed, and NC_MSG_REPLY if a reply was read instead (call this function again to get a notification).

◆ nc_recv_notif_dispatch()

int nc_recv_notif_dispatch ( struct nc_session *  session,
void(*)(struct nc_session *session, const struct lyd_node *envp, const struct lyd_node *op)  notif_clb 
)

Receive NETCONF Notifications in a separate thread until the session is terminated or <notificationComplete> is received.

Parameters
[in]sessionNetconf session to read notifications from.
[in]notif_clbFunction that is called for every received notification (including <notificationComplete>). Parameters are the session the notification was received on and the notification data.
Returns
0 if the thread was successfully created, -1 on error.

◆ nc_recv_reply()

NC_MSG_TYPE nc_recv_reply ( struct nc_session *  session,
struct nc_rpc rpc,
uint64_t  msgid,
int  timeout,
struct lyd_node **  envp,
struct lyd_node **  op 
)

Receive NETCONF RPC reply.

Note
This function can be called in a single thread only.
Parameters
[in]sessionNETCONF session from which the function gets data. It must be the client side session object.
[in]rpcOriginal RPC this should be the reply to.
[in]msgidExpected message ID of the reply.
[in]timeoutTimeout for reading in milliseconds. Use negative value for infinite waiting and 0 for immediate return if data are not available on the wire.
[out]envpNETCONF rpc-reply XML envelopes.
[out]opParsed NETCONF reply data, if any (none for <ok> or error replies). Set only on NC_MSG_REPLY and NC_MSG_REPLY_ERR_MSGID return.
Returns
NC_MSG_REPLY for success, NC_MSG_WOULDBLOCK if timeout has elapsed, NC_MSG_ERROR if reading has failed, NC_MSG_NOTIF if a notification was read instead (call this function again to get the reply), and NC_MSG_REPLY_ERR_MSGID if a reply with missing or wrong message-id was received.

◆ nc_send_rpc()

NC_MSG_TYPE nc_send_rpc ( struct nc_session *  session,
struct nc_rpc rpc,
int  timeout,
uint64_t *  msgid 
)

Send NETCONF RPC message via the session.

Parameters
[in]sessionNETCONF session where the RPC will be written.
[in]rpcNETCONF RPC object to send via the specified session.
[in]timeoutTimeout for writing in milliseconds. Use negative value for infinite waiting and 0 for return if data cannot be sent immediately.
[out]msgidIf RPC was successfully sent, this is it's message ID.
Returns
NC_MSG_RPC on success, NC_MSG_WOULDBLOCK in case of a busy session, and NC_MSG_ERROR on error.

◆ nc_session_cpblt()

const char * nc_session_cpblt ( const struct nc_session *  session,
const char *  capab 
)

Check capability presence in a session.

Parameters
[in]sessionSession to check.
[in]capabCapability to look for, capability with any additional suffix will match.
Returns
Matching capability, NULL if none found.

◆ nc_session_get_cpblts()

const char *const * nc_session_get_cpblts ( const struct nc_session *  session)

Get session capabilities.

Parameters
[in]sessionSession to get the information from.
Returns
NULL-terminated array of the session capabilities.

◆ nc_session_ntf_thread_running()

int nc_session_ntf_thread_running ( const struct nc_session *  session)

Check whether the session has a notification thread running.

Parameters
[in]sessionSession to check.
Returns
1 if notfication thread is running, 0 otherwise.