Get user id when hook for monitoring session events

Questions regarding the use of the High Perfomance SDK for Server development

Moderator: uasdkhpc

Post Reply
AnnieFYWu
Full Member
Full Member
Posts: 5
Joined: 18 May 2018, 09:54

Get user id when hook for monitoring session events

Post by AnnieFYWu »

Hi,

I'm trying to get user id in the function uaprovider_demo_session_hook(enum uasession_event_type type, uint32_t channel_id, struct uasession_session *session) in server_demo by session->user_ctx.uid. But it always return 0 even I use the user "john" as username.
Is that the correct way to get the user id when session is creating?
Thanks.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3068
Joined: 18 Mar 2011, 15:09

Re: Get user id when hook for monitoring session events

Post by Support Team »

Hello Annie,

I just tried it and it works for me.
I added the following code to the example:

Code: Select all

    case UASESSION_EVENT_ACTIVATESESSION:
        TRACE_INFO(TRACE_FAC_PROVIDER, "A session with session_id=%u was activated on channel with channel_id=%u.\n", session->session_id, channel_id);
#ifdef UA_AUTHORIZATION_SUPPORT
        TRACE_INFO(TRACE_FAC_PROVIDER, "uid=%u.\n", session->user_ctx.uid);
#endif
        break;
Please ensure that you have enabled UA_AUTHORIZATION_SUPPORT and that you entered the correct password.

When starting the server by filtering the trace

Code: Select all

./uaserverhp -d 4 -f 512
I get this output:

Code: Select all

I|15:11:41.558771|10844|  A session with session_id=3166477824 was activated on channel with channel_id=3025033216.
I|15:11:41.558789|10844|  uid=3.
Best regards
Unified Automation Support Team

AnnieFYWu
Full Member
Full Member
Posts: 5
Joined: 18 May 2018, 09:54

Re: Get user id when hook for monitoring session events

Post by AnnieFYWu »

It works. Thanks.

Post Reply