sysrepo  1.4.168
YANG datastore
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Connection and Session API

Data Structures

struct  sr_error_info_msg_s
 A single, detailed error message. Used in sr_error_info_s. More...
 
struct  sr_error_info_s
 Detailed sysrepo session error information. More...
 

Typedefs

typedef struct sr_conn_ctx_s sr_conn_ctx_t
 Sysrepo connection. More...
 
typedef struct sr_session_ctx_s sr_session_ctx_t
 Sysrepo session on a connection. More...
 
typedef enum sr_conn_flag_e sr_conn_flag_t
 Flags used to override default connection handling by sr_connect call. More...
 
typedef uint32_t sr_conn_options_t
 Options overriding default connection handling by sr_connect call, it is supposed to be bitwise OR-ed value of any sr_conn_flag_t flags. More...
 
typedef enum sr_datastore_e sr_datastore_t
 Datastores that sysrepo supports. To change which datastore a session operates on, use sr_session_switch_ds. More...
 
typedef struct sr_error_info_msg_s sr_error_info_msg_t
 A single, detailed error message. Used in sr_error_info_s. More...
 
typedef struct sr_error_info_s sr_error_info_t
 Detailed sysrepo session error information. More...
 
typedef int(* sr_diff_check_cb )(sr_session_ctx_t *session, const struct lyd_node *diff)
 Callback to be called before applying a diff. Set it using sr_set_diff_check_callback. More...
 

Enumerations

enum  sr_conn_flag_e { SR_CONN_DEFAULT = 0, SR_CONN_CACHE_RUNNING = 1, SR_CONN_NO_SCHED_CHANGES = 2, SR_CONN_ERR_ON_SCHED_FAIL = 4 }
 Flags used to override default connection handling by sr_connect call. More...
 
enum  sr_datastore_e { SR_DS_STARTUP = 0, SR_DS_RUNNING = 1, SR_DS_CANDIDATE = 2, SR_DS_OPERATIONAL = 3 }
 Datastores that sysrepo supports. To change which datastore a session operates on, use sr_session_switch_ds. More...
 

Functions

int sr_connect (const sr_conn_options_t opts, sr_conn_ctx_t **conn)
 Connects to the sysrepo datastore. If possible (no other connections exist), also apply any scheduled changes. More...
 
int sr_disconnect (sr_conn_ctx_t *conn)
 Disconnect from the sysrepo datastore. More...
 
int sr_connection_count (uint32_t *conn_count)
 Learn the current global number of alive connections. More...
 
struct ly_ctx * sr_get_context (sr_conn_ctx_t *conn)
 Get the libyang context used by a connection. Can be used in an application for working with data and schemas. Do NOT change this context! More...
 
void sr_set_diff_check_callback (sr_conn_ctx_t *conn, sr_diff_check_cb callback)
 Set callback for checking every diff before it is applied on the datastore. The diff is final (only CRUD operations) but without any implicit changes caused by validation. This callback is primarily meant to allow full NACM (NETCONF Access Control) to be performed by a NETCONF server. More...
 
int sr_session_start (sr_conn_ctx_t *conn, const sr_datastore_t datastore, sr_session_ctx_t **session)
 Start a new session. More...
 
int sr_session_stop (sr_session_ctx_t *session)
 Stop current session and releases resources tied to the session. More...
 
int sr_session_notif_buffer (sr_session_ctx_t *session)
 Use notification buffering for the session. More...
 
int sr_session_switch_ds (sr_session_ctx_t *session, sr_datastore_t ds)
 Change datastore which the session operates on. All subsequent calls will be issued on the chosen datastore. Previous calls are not affected. More...
 
sr_datastore_t sr_session_get_ds (sr_session_ctx_t *session)
 Learn the datastore a session operates on. More...
 
int sr_get_error (sr_session_ctx_t *session, const sr_error_info_t **error_info)
 Retrieve information about the error that has occurred during the last operation executed within provided session. More...
 
int sr_set_error (sr_session_ctx_t *session, const char *path, const char *format,...)
 Set detailed error information into provided session. Used to notify the client library about errors that occurred in the application code. Does not print the message. More...
 
uint32_t sr_session_get_id (sr_session_ctx_t *session)
 Return the assigned session ID of the sysrepo session. More...
 
uint32_t sr_session_get_event_sr_id (sr_session_ctx_t *session)
 Return the session ID of the event originator sysrepo session. Should be used on the implicit session in event callbacks. More...
 
void sr_session_set_nc_id (sr_session_ctx_t *session, uint32_t nc_sid)
 Set a NETCONF session ID for a sysrepo session. Any application callbacks handling operations initiated by this session will be able to read this ID from the session provided. More...
 
uint32_t sr_session_get_nc_id (sr_session_ctx_t *session)
 Learn NETCONF session ID set for a sysrepo session. More...
 
uint32_t sr_session_get_event_nc_id (sr_session_ctx_t *session)
 Learn NETCONF session ID set for the event originator sysrepo session. Should be used on the implicit session in event callbacks. More...
 
int sr_session_set_user (sr_session_ctx_t *session, const char *user)
 Set the effective user of a session to a different one that the process owner. More...
 
const char * sr_session_get_user (sr_session_ctx_t *session)
 Get the effective user of a session. More...
 
const char * sr_session_get_event_user (sr_session_ctx_t *session)
 Get the effective user of the event originator sysrepo session. Should be used on the implicit session in event callbacks. More...
 
sr_conn_ctx_tsr_session_get_connection (sr_session_ctx_t *session)
 Get the connection the session was created on. More...
 

Detailed Description


Data Structure Documentation

struct sr_error_info_msg_s

A single, detailed error message. Used in sr_error_info_s.

Definition at line 209 of file sysrepo.h.

Data Fields
char * message

Error message.

char * xpath

XPath (or rather path) to the node where the error has been discovered.

struct sr_error_info_s

Detailed sysrepo session error information.

Definition at line 217 of file sysrepo.h.

Data Fields
sr_error_t err_code

Error code.

sr_error_info_msg_t * err

Array of all generated errors.

size_t err_count

Error message count.

Typedef Documentation

typedef struct sr_conn_ctx_s sr_conn_ctx_t

Sysrepo connection.

Definition at line 169 of file sysrepo.h.

typedef struct sr_session_ctx_s sr_session_ctx_t

Sysrepo session on a connection.

Definition at line 174 of file sysrepo.h.

Flags used to override default connection handling by sr_connect call.

typedef uint32_t sr_conn_options_t

Options overriding default connection handling by sr_connect call, it is supposed to be bitwise OR-ed value of any sr_conn_flag_t flags.

Definition at line 193 of file sysrepo.h.

Datastores that sysrepo supports. To change which datastore a session operates on, use sr_session_switch_ds.

A single, detailed error message. Used in sr_error_info_s.

Detailed sysrepo session error information.

typedef int(* sr_diff_check_cb)(sr_session_ctx_t *session, const struct lyd_node *diff)

Callback to be called before applying a diff. Set it using sr_set_diff_check_callback.

Parameters
[in]sessionImplicit session (do not stop) with information about the event originator session IDs.
[in]diffDiff to be applied.
Returns
Error code (SR_ERR_OK on success).

Definition at line 274 of file sysrepo.h.

Enumeration Type Documentation

Flags used to override default connection handling by sr_connect call.

Enumerator
SR_CONN_DEFAULT 

No special behaviour.

SR_CONN_CACHE_RUNNING 

Always cache running datastore data which makes mainly repeated retrieval of data much faster. Affects all sessions created on this connection.

SR_CONN_NO_SCHED_CHANGES 

Do not parse internal modules data and apply any scheduled changes. Makes creating the connection faster but, obviously, scheduled changes are not applied.

SR_CONN_ERR_ON_SCHED_FAIL 

If applying any of the scheduled changes fails, do not create a connection and return an error.

Definition at line 179 of file sysrepo.h.

Datastores that sysrepo supports. To change which datastore a session operates on, use sr_session_switch_ds.

Enumerator
SR_DS_STARTUP 

Contains configuration data that will be loaded when a device starts.

SR_DS_RUNNING 

Contains current configuration data.

SR_DS_CANDIDATE 

Contains prepared configuration data that do not affect actual configuration.

SR_DS_OPERATIONAL 

Contains currently used configuration (see operational datastore).

Definition at line 199 of file sysrepo.h.

Function Documentation

int sr_connect ( const sr_conn_options_t  opts,
sr_conn_ctx_t **  conn 
)

Connects to the sysrepo datastore. If possible (no other connections exist), also apply any scheduled changes.

Note
Do not use fork() after creating a connection. Sysrepo internally stores the connection ID of every connection. Forking will duplicate the connection and ID resulting in a mismatch.
Parameters
[in]optsOptions overriding default connection handling by this call.
[out]connConnection that can be used for subsequent API calls (automatically allocated, it is supposed to be released by the caller using sr_disconnect).
Returns
Error code (SR_ERR_OK on success).
int sr_disconnect ( sr_conn_ctx_t conn)

Disconnect from the sysrepo datastore.

Cleans up and frees connection context allocated by sr_connect. All sessions and subscriptions started within the connection will be automatically stopped and cleaned up too.

Note
On error the function should be retried and must eventually succeed.
Parameters
[in]connConnection acquired with sr_connect call.
Returns
Error code (SR_ERR_OK on success).
int sr_connection_count ( uint32_t *  conn_count)

Learn the current global number of alive connections.

Parameters
[out]conn_countCurrent number of connections.
Returns
Error code (SR_ERR_OK on success).
struct ly_ctx* sr_get_context ( sr_conn_ctx_t conn)

Get the libyang context used by a connection. Can be used in an application for working with data and schemas. Do NOT change this context!

Parameters
[in]connConnection to use.
Returns
Const libyang context.
void sr_set_diff_check_callback ( sr_conn_ctx_t conn,
sr_diff_check_cb  callback 
)

Set callback for checking every diff before it is applied on the datastore. The diff is final (only CRUD operations) but without any implicit changes caused by validation. This callback is primarily meant to allow full NACM (NETCONF Access Control) to be performed by a NETCONF server.

Required SUPERUSER access.

Parameters
[in]connConnection, whose all sessions diffs will be passed to this callback.
[in]callbackCallback to call for every diff.
int sr_session_start ( sr_conn_ctx_t conn,
const sr_datastore_t  datastore,
sr_session_ctx_t **  session 
)

Start a new session.

Parameters
[in]connConnection acquired with sr_connect call.
[in]datastoreDatastore on which all sysrepo functions within this session will operate. Later on, datastore can be later changed using sr_session_switch_ds call. Functionality of some sysrepo calls does not depend on datastore. If your session will contain just calls like these, you can pass any valid value (e.g. SR_DS_RUNNING).
[out]sessionSession context that can be used for subsequent API calls (automatically allocated, can be released by calling sr_session_stop).
Returns
Error code (SR_ERR_OK on success).
int sr_session_stop ( sr_session_ctx_t session)

Stop current session and releases resources tied to the session.

Also releases any locks held and frees subscriptions created (only) by this session.

Note
On error the function should be retried and must eventually succeed. Subscriptions, even if they no longer handle any events are never freed and should be manually freed using sr_unsubscribe.
Parameters
[in]sessionSession context acquired with sr_session_start call.
Returns
Error code (SR_ERR_OK on success).
int sr_session_notif_buffer ( sr_session_ctx_t session)

Use notification buffering for the session.

When a notification is sent using this session for a module that supports replay (notification should be stored), the notification function does not wait until it is stored but delegates this work to a special thread and returns.

Parameters
[in]sessionSession (not DS-specific) whose notifications will be buffered.
Returns
Error code (SR_ERR_OK on success).
int sr_session_switch_ds ( sr_session_ctx_t session,
sr_datastore_t  ds 
)

Change datastore which the session operates on. All subsequent calls will be issued on the chosen datastore. Previous calls are not affected.

Parameters
[in]sessionSession to modify.
[in]dsNew datastore that will be operated on.
Returns
Error code (SR_ERR_OK on success).
sr_datastore_t sr_session_get_ds ( sr_session_ctx_t session)

Learn the datastore a session operates on.

Parameters
[in]sessionSession to use.
Returns
Datastore of the session.
int sr_get_error ( sr_session_ctx_t session,
const sr_error_info_t **  error_info 
)

Retrieve information about the error that has occurred during the last operation executed within provided session.

Parameters
[in]sessionSession (not DS-specific) to use.
[out]error_infoDetailed error information. Be aware that returned pointer may change by the next API call executed within the provided session. Do not free or modify returned values.
Returns
Error code (SR_ERR_OK on success).
int sr_set_error ( sr_session_ctx_t session,
const char *  path,
const char *  format,
  ... 
)

Set detailed error information into provided session. Used to notify the client library about errors that occurred in the application code. Does not print the message.

Note
Intended for change, RPC/action, or operational callbacks to be used on the provided session.
Parameters
[in]sessionImplicit session provided in a callback.
[in]pathOptional path of the node where the error has occurred.
[in]formatHuman-readable format of the error message.
[in]...Format parameters.
Returns
Error code (SR_ERR_OK on success).
uint32_t sr_session_get_id ( sr_session_ctx_t session)

Return the assigned session ID of the sysrepo session.

Parameters
[in]sessionSession (not DS-specific) to use.
Returns
sysrepo SID or 0 in case of error.
uint32_t sr_session_get_event_sr_id ( sr_session_ctx_t session)

Return the session ID of the event originator sysrepo session. Should be used on the implicit session in event callbacks.

Parameters
[in]sessionEvent session (not DS-specific) to use.
Returns
sysrepo SID or 0 in case of error.
void sr_session_set_nc_id ( sr_session_ctx_t session,
uint32_t  nc_sid 
)

Set a NETCONF session ID for a sysrepo session. Any application callbacks handling operations initiated by this session will be able to read this ID from the session provided.

Parameters
[in]sessionSession (not DS-specific) to change.
[in]nc_sidNETCONF session ID of a NETCONF session running on top of this session.
uint32_t sr_session_get_nc_id ( sr_session_ctx_t session)

Learn NETCONF session ID set for a sysrepo session.

Parameters
[in]sessionSession (not DS-specific) to use.
Returns
Session NETCONF SID.
uint32_t sr_session_get_event_nc_id ( sr_session_ctx_t session)

Learn NETCONF session ID set for the event originator sysrepo session. Should be used on the implicit session in event callbacks.

Parameters
[in]sessionEvent session (not DS-specific) to use.
Returns
Session NETCONF SID.
int sr_session_set_user ( sr_session_ctx_t session,
const char *  user 
)

Set the effective user of a session to a different one that the process owner.

Required SUPERUSER access.

Parameters
[in]sessionSession (not DS-specific) to change.
[in]userSystem user.
Returns
Error code (SR_ERR_OK on success).
const char* sr_session_get_user ( sr_session_ctx_t session)

Get the effective user of a session.

Required SUPERUSER access.

Parameters
[in]sessionSession (not DS-specific) to use.
Returns
Session user.
const char* sr_session_get_event_user ( sr_session_ctx_t session)

Get the effective user of the event originator sysrepo session. Should be used on the implicit session in event callbacks.

Parameters
[in]sessionEvent session (not DS-specific) to use.
Returns
Session user.
sr_conn_ctx_t* sr_session_get_connection ( sr_session_ctx_t session)

Get the connection the session was created on.

Parameters
[in]sessionSession (not DS-specific) to use.
Returns
Sysrepo connection.