sysrepo  2.11.7
YANG-based system repository for all-around configuration management.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Connection and Session API

Functions

struct ly_ctx * sr_acquire_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. More...
 
int sr_connect (const sr_conn_options_t opts, sr_conn_ctx_t **conn)
 Connects to the sysrepo datastore. More...
 
int sr_discard_oper_changes (sr_conn_ctx_t *conn, sr_session_ctx_t *session, const char *xpath, uint32_t timeout_ms)
 Deprecated, use sr_discard_items(). More...
 
int sr_disconnect (sr_conn_ctx_t *conn)
 Disconnect from the sysrepo datastore. More...
 
uint32_t sr_get_content_id (sr_conn_ctx_t *conn)
 Get content ID of the current YANG module set. It conforms to the requirements for ietf-yang-library "content-id" node value. More...
 
int sr_get_error_data (const sr_error_info_err_t *err, uint32_t idx, uint32_t *size, const void **data)
 Get a specific chunk of error data. More...
 
int sr_get_plugins (sr_conn_ctx_t *conn, const char ***ds_plugins, const char ***ntf_plugins)
 Get loaded plugins of a connection. More...
 
uid_t sr_get_su_uid (void)
 Get the sysrepo SUPERUSER UID. More...
 
void sr_release_context (sr_conn_ctx_t *conn)
 Release libyang context obtained from a session/connection. More...
 
struct ly_ctx * sr_session_acquire_context (sr_session_ctx_t *session)
 Get the libyang context used by a connection. Can be used in an application for working with data and schemas. More...
 
void sr_session_del_orig_data (sr_session_ctx_t *session)
 Remove all pushed event originator data. More...
 
int sr_session_dup_error (sr_session_ctx_t *src_session, sr_session_ctx_t *trg_session)
 Copy the first error (if any) from a session to a callback session. More...
 
sr_conn_ctx_tsr_session_get_connection (sr_session_ctx_t *session)
 Get the connection the session was created on. More...
 
sr_datastore_t sr_session_get_ds (sr_session_ctx_t *session)
 Learn the datastore a session operates on. More...
 
int sr_session_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...
 
uint32_t sr_session_get_id (sr_session_ctx_t *session)
 Return the assigned session ID of the sysrepo session. More...
 
int sr_session_get_orig_data (sr_session_ctx_t *session, uint32_t idx, uint32_t *size, const void **data)
 Get a specific chunk of event originator data in a callback. More...
 
const char * sr_session_get_orig_name (sr_session_ctx_t *session)
 Get event originator name. More...
 
const char * sr_session_get_user (sr_session_ctx_t *session)
 Get the effective user of a session. More...
 
int sr_session_notif_buffer (sr_session_ctx_t *session)
 Use notification buffering for the session. More...
 
int sr_session_push_error_data (sr_session_ctx_t *session, uint32_t size, const void *data)
 Push (add) another chunk of error data for a failed callback communicated back to the originator. Its meaning is specific to the error data format (which must be set prior to calling this function) identifier and can be read from the error structure by the originator using sr_get_error_data(). More...
 
int sr_session_push_orig_data (sr_session_ctx_t *session, uint32_t size, const void *data)
 Push (add) another chunk of event originator data used for all events sent on this session. Its meaning is specific to the originator name (which must be set prior to calling this function) and can be read from the implicit event session in the callbacks using sr_session_get_orig_data(). More...
 
void sr_session_release_context (sr_session_ctx_t *session)
 Release libyang context obtained from a session/connection. More...
 
int sr_session_set_error (sr_session_ctx_t *session, const char *err_format_name, sr_error_t err_code, const char *err_msg_format,...)
 Set an error for a failed callback communicated back to the originator. Does not print the message. More...
 
int sr_session_set_error_format (sr_session_ctx_t *session, const char *error_format)
 Deprecated, use sr_session_set_error(). More...
 
int sr_session_set_error_message (sr_session_ctx_t *session, const char *format,...)
 Deprecated, use sr_session_set_error(). More...
 
int sr_session_set_orig_name (sr_session_ctx_t *session, const char *orig_name)
 Set event originator name used for all events sent on this session. It can then be read from the implicit event session in the callbacks using sr_session_get_orig_name(). This name should be used for interpreting the data set by sr_session_push_orig_data(). 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 than the process owner. 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 the session and releases resources tied to it. 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...
 
int sr_session_unsubscribe (sr_session_ctx_t *session)
 Unsubscribe all subscriptions created by this session. More...
 
typedef struct sr_conn_ctx_s sr_conn_ctx_t
 Sysrepo connection. More...
 

Detailed Description

Typedef Documentation

typedef struct sr_conn_ctx_s sr_conn_ctx_t

Sysrepo connection.

Definition at line 89 of file sysrepo_types.h.

Function Documentation

struct ly_ctx* sr_acquire_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.

Note
This context must not be changed. Also, to prevent the context from being destroyed by sysrepo, it is locked and after no longer needing the context sr_release_context() must be called. Otherwise, API functions changing the context will fail with time out.
Parameters
[in]connConnection to use.
Returns
Const libyang context.
int sr_connect ( const sr_conn_options_t  opts,
sr_conn_ctx_t **  conn 
)

Connects to the sysrepo datastore.

Note
Do not use fork(2) 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]optsConnection options.
[out]connCreated connection.
Returns
Error code (SR_ERR_OK on success).
int sr_discard_oper_changes ( sr_conn_ctx_t conn,
sr_session_ctx_t session,
const char *  xpath,
uint32_t  timeout_ms 
)

Deprecated, use sr_discard_items().

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 to free.
Returns
Error code (SR_ERR_OK on success).
uint32_t sr_get_content_id ( sr_conn_ctx_t conn)

Get content ID of the current YANG module set. It conforms to the requirements for ietf-yang-library "content-id" node value.

Parameters
[in]connConnection to use.
Returns
Content ID.
int sr_get_error_data ( const sr_error_info_err_t err,
uint32_t  idx,
uint32_t *  size,
const void **  data 
)

Get a specific chunk of error data.

If the error is a well-known one, it is possible to use helper utility functions instead of repeatedly calling this function.

Parameters
[in]errError structure to use.
[in]idxIndex of the error data chunk, starts at 0.
[out]sizeOptional size of the error data chunk.
[out]dataPointer to an opaque error data chunk.
Returns
Error code (SR_ERR_OK on success).
int sr_get_plugins ( sr_conn_ctx_t conn,
const char ***  ds_plugins,
const char ***  ntf_plugins 
)

Get loaded plugins of a connection.

Parameters
[in]connConnection to use.
[out]ds_pluginsOptional pointer to array of datastore plugins ended by NULL.
[out]ntf_pluginsOptional pointer to array of notification plugins ended by NULL.
Returns
Error code (SR_ERR_OK on success).
uid_t sr_get_su_uid ( void  )

Get the sysrepo SUPERUSER UID.

Returns
Sysrepo SU UID.
void sr_release_context ( sr_conn_ctx_t conn)

Release libyang context obtained from a session/connection.

Note
Must be called for each sr_acquire_context() call.
Parameters
[in]connConnection to use.
struct ly_ctx* sr_session_acquire_context ( sr_session_ctx_t session)

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

Similar to and interchangeable with sr_acquire_context().

Parameters
[in]sessionSession whose connection to use.
Returns
Const libyang context.
void sr_session_del_orig_data ( sr_session_ctx_t session)

Remove all pushed event originator data.

Parameters
[in]sessionSession (not DS-specific) to use.
int sr_session_dup_error ( sr_session_ctx_t src_session,
sr_session_ctx_t trg_session 
)

Copy the first error (if any) from a session to a callback session.

Parameters
[in]src_sessionSession (not DS-specific) to read the error from.
[in]trg_sessionImplicit session provided in a callback.
Returns
Error code (SR_ERR_OK on success).
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.
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_session_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).
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.
int sr_session_get_orig_data ( sr_session_ctx_t session,
uint32_t  idx,
uint32_t *  size,
const void **  data 
)

Get a specific chunk of event originator data in a callback.

Parameters
[in]sessionImplicit session provided in a callback.
[in]idxIndex of the data chunk, starts at 0.
[out]sizeOptional size of the data chunk.
[out]dataPointer to an opaque data chunk.
Returns
Error code (SR_ERR_OK on success).
const char* sr_session_get_orig_name ( sr_session_ctx_t session)

Get event originator name.

Parameters
[in]sessionImplicit session provided in a callback.
Returns
Originator name if set, empty string "" otherwise.
const char* sr_session_get_user ( sr_session_ctx_t session)

Get the effective user of a session.

Parameters
[in]sessionSession (not DS-specific) to use.
Returns
Session user.
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_push_error_data ( sr_session_ctx_t session,
uint32_t  size,
const void *  data 
)

Push (add) another chunk of error data for a failed callback communicated back to the originator. Its meaning is specific to the error data format (which must be set prior to calling this function) identifier and can be read from the error structure by the originator using sr_get_error_data().

Parameters
[in]sessionImplicit session provided in a callback.
[in]sizeSize of the error data chunk.
[in]dataPointer to an opaque error data chunk.
Returns
Error code (SR_ERR_OK on success).
int sr_session_push_orig_data ( sr_session_ctx_t session,
uint32_t  size,
const void *  data 
)

Push (add) another chunk of event originator data used for all events sent on this session. Its meaning is specific to the originator name (which must be set prior to calling this function) and can be read from the implicit event session in the callbacks using sr_session_get_orig_data().

Parameters
[in]sessionSession (not DS-specific) to use.
[in]sizeSize of the data chunk.
[in]dataPointer to an opaque data chunk.
Returns
Error code (SR_ERR_OK on success).
void sr_session_release_context ( sr_session_ctx_t session)

Release libyang context obtained from a session/connection.

Similar to and interchangeable with sr_release_context().

Parameters
[in]sessionSession whose connection to use.
int sr_session_set_error ( sr_session_ctx_t session,
const char *  err_format_name,
sr_error_t  err_code,
const char *  err_msg_format,
  ... 
)

Set an error for a failed callback communicated back to the originator. Does not print the message.

Note
Intended for diff-check, change, RPC/action, or operational callbacks to be used on the provided session.
Error format err_format_name should be used for interpreting the error data set by sr_session_push_error_data(). There are some well-known error formats defined and those errors can be written/read using helper utility functions.
Parameters
[in]sessionImplicit session provided in a callback.
[in]err_format_nameOptional arbitrary error format identifier, set its error data using sr_session_push_error_data().
[in]err_codeError code of the error.
[in]err_msg_formatError message format.
[in]...Error message format arguments.
int sr_session_set_error_format ( sr_session_ctx_t session,
const char *  error_format 
)

Deprecated, use sr_session_set_error().

int sr_session_set_error_message ( sr_session_ctx_t session,
const char *  format,
  ... 
)

Deprecated, use sr_session_set_error().

int sr_session_set_orig_name ( sr_session_ctx_t session,
const char *  orig_name 
)

Set event originator name used for all events sent on this session. It can then be read from the implicit event session in the callbacks using sr_session_get_orig_name(). This name should be used for interpreting the data set by sr_session_push_orig_data().

The following originator names are well-known:

Parameters
[in]sessionSession (not DS-specific) to use.
[in]orig_nameArbitrary originator name.
Returns
Error code (SR_ERR_OK on success).
int sr_session_set_user ( sr_session_ctx_t session,
const char *  user 
)

Set the effective user of a session to a different one than 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).
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 to use.
[in]datastoreDatastore on which to operate, can be later changed using sr_session_switch_ds().
[out]sessionCreated session.
Returns
Error code (SR_ERR_OK on success).
int sr_session_stop ( sr_session_ctx_t session)

Stop the session and releases resources tied to it.

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 freed manually using sr_unsubscribe.
Parameters
[in]sessionSession to free.
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).
int sr_session_unsubscribe ( sr_session_ctx_t session)

Unsubscribe all subscriptions created by this session.

Note
Subscriptions, even if they no longer handle any events are never freed and should be freed manually using sr_unsubscribe.
Parameters
[in]sessionSession to use.
Returns
Error code (SR_ERR_OK on success).