session CHANGE new killed-by atrribute of every session
Also 2 new setters added.
diff --git a/src/session.c b/src/session.c
index 88eb17d..6ee961e 100644
--- a/src/session.c
+++ b/src/session.c
@@ -294,7 +294,7 @@
}
API NC_SESSION_TERM_REASON
-nc_session_get_termreason(const struct nc_session *session)
+nc_session_get_term_reason(const struct nc_session *session)
{
if (!session) {
ERRARG("session");
@@ -305,6 +305,17 @@
}
API uint32_t
+nc_session_get_killed_by(const struct nc_session *session)
+{
+ if (!session) {
+ ERRARG("session");
+ return 0;
+ }
+
+ return session->killed_by;
+}
+
+API uint32_t
nc_session_get_id(const struct nc_session *session)
{
if (!session) {
diff --git a/src/session.h b/src/session.h
index 2d35243..0ac4908 100644
--- a/src/session.h
+++ b/src/session.h
@@ -119,7 +119,15 @@
* @param[in] session Session to get the information from.
* @return Session termination reason enum value.
*/
-NC_SESSION_TERM_REASON nc_session_get_termreason(const struct nc_session *session);
+NC_SESSION_TERM_REASON nc_session_get_term_reason(const struct nc_session *session);
+
+/**
+ * @brief Get session killer session ID.
+ *
+ * @param[in] session Session to get the information from.
+ * @return Session killer ID.
+ */
+uint32_t nc_session_get_killed_by(const struct nc_session *session);
/**
* @brief Get session ID.
diff --git a/src/session_p.h b/src/session_p.h
index 916f2c2..333eb09 100644
--- a/src/session_p.h
+++ b/src/session_p.h
@@ -334,6 +334,7 @@
struct nc_session {
NC_STATUS status; /**< status of the session */
NC_SESSION_TERM_REASON term_reason; /**< reason of termination, if status is NC_STATUS_INVALID */
+ uint32_t killed_by; /**< session responsible for termination, if term_reason is NC_SESSION_TERM_KILLED */
NC_SIDE side; /**< side of the session: client or server */
/* NETCONF data */
diff --git a/src/session_server.c b/src/session_server.c
index a66ddad..bd610d9 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -126,9 +126,40 @@
return;
}
+ if ((reason != NC_SESSION_TERM_KILLED) && (session->term_reason == NC_SESSION_TERM_KILLED)) {
+ session->killed_by = 0;
+ }
session->term_reason = reason;
}
+API void
+nc_session_set_killed_by(struct nc_session *session, uint32_t sid)
+{
+ if (!session || (session->term_reason != NC_SESSION_TERM_KILLED)) {
+ ERRARG("session");
+ return;
+ } else if (!sid) {
+ ERRARG("sid");
+ return;
+ }
+
+ session->killed_by = sid;
+}
+
+API void
+nc_session_set_status(struct nc_session *session, NC_STATUS status)
+{
+ if (!session) {
+ ERRARG("session");
+ return;
+ } else if (!status) {
+ ERRARG("status");
+ return;
+ }
+
+ session->status = status;
+}
+
int
nc_sock_listen(const char *address, uint16_t port)
{
diff --git a/src/session_server.h b/src/session_server.h
index 04037a4..bf4da3e 100644
--- a/src/session_server.h
+++ b/src/session_server.h
@@ -56,6 +56,22 @@
void nc_session_set_term_reason(struct nc_session *session, NC_SESSION_TERM_REASON reason);
/**
+ * @brief Set the session-id of the session responsible for this session's termination.
+ *
+ * @param[in] session Session to modify. Must have term_reason set to #NC_SESSION_TERM_KILLED.
+ * @param[in] sid SID of the killing session.
+ */
+void nc_session_set_killed_by(struct nc_session *session, uint32_t sid);
+
+/**
+ * @brief Set the status of a session.
+ *
+ * @param[in] session Session to modify.
+ * @param[in] status Status of the session.
+ */
+void nc_session_set_status(struct nc_session *session, NC_STATUS status);
+
+/**
* @brief Set a global nc_rpc_clb that is called if the particular RPC request is
* received and the private field in the corresponding RPC schema node is NULL.
*