diff options
| author | Igor Ryzhov <iryzhov@nfware.com> | 2024-02-23 18:53:46 +0200 |
|---|---|---|
| committer | Igor Ryzhov <iryzhov@nfware.com> | 2024-02-23 18:53:46 +0200 |
| commit | 13359c5cc9b8fd84c62b30443e063d96e9a73034 (patch) | |
| tree | a320c58fb1dd6592e0676d246d687c05cbdaec5a | |
| parent | eae228c52d4256542ab94038be263a29dbffa4ce (diff) | |
lib: fix processing of notifications on mgmt fe client
Notifications are sent by mgmtd for each session of a client, so they
should be processed once per each session.
Also, add session_id parameter to an async_notification callback as all
other callbacks have this parameter.
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
| -rw-r--r-- | lib/mgmt_fe_client.c | 30 | ||||
| -rw-r--r-- | lib/mgmt_fe_client.h | 3 |
2 files changed, 16 insertions, 17 deletions
diff --git a/lib/mgmt_fe_client.c b/lib/mgmt_fe_client.c index bfdecedc4e..a107582bea 100644 --- a/lib/mgmt_fe_client.c +++ b/lib/mgmt_fe_client.c @@ -510,14 +510,11 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client, debug_fe_client("Got native message for session-id %" PRIu64, msg->refer_id); - if (msg->code != MGMT_MSG_CODE_NOTIFY) { - session = mgmt_fe_find_session_by_session_id(client, - msg->refer_id); - if (!session || !session->client) { - log_err_fe_client("No session for received native msg session-id %" PRIu64, - msg->refer_id); - return; - } + session = mgmt_fe_find_session_by_session_id(client, msg->refer_id); + if (!session || !session->client) { + log_err_fe_client("No session for received native msg session-id %" PRIu64, + msg->refer_id); + return; } switch (msg->code) { @@ -558,6 +555,9 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client, tree_msg->partial_error); break; case MGMT_MSG_CODE_NOTIFY: + if (!session->client->cbs.async_notification) + return; + notify_msg = (typeof(notify_msg))msg; if (msg_len < sizeof(*notify_msg)) { log_err_fe_client("Corrupt notify-data msg recv"); @@ -579,15 +579,13 @@ static void fe_client_handle_native_msg(struct mgmt_fe_client *client, notify_msg->result_type); return; } - FOREACH_SESSION_IN_LIST (client, session) { - if (!session->client->cbs.async_notification) - continue; - session->client->cbs - .async_notification(client, client->user_data, - session->client_id, - session->user_ctx, data); - } + session->client->cbs.async_notification(client, + client->user_data, + session->client_id, + msg->refer_id, + session->user_ctx, data); + if (notify_msg->result_type != LYD_JSON) darr_free(data); break; diff --git a/lib/mgmt_fe_client.h b/lib/mgmt_fe_client.h index 7af1270071..eee4594e17 100644 --- a/lib/mgmt_fe_client.h +++ b/lib/mgmt_fe_client.h @@ -117,7 +117,8 @@ struct mgmt_fe_client_cbs { /* Called with asynchronous notifications from backends */ int (*async_notification)(struct mgmt_fe_client *client, uintptr_t user_data, uint64_t client_id, - uintptr_t session_ctx, const char *result); + uint64_t session_id, uintptr_t session_ctx, + const char *result); /* Called when new native error is returned */ int (*error_notify)(struct mgmt_fe_client *client, uintptr_t user_data, |
