zabbix-agent2/src/zabbix_server/reporter/report_manager.c
/******************************************************************************
 *                                                                            *
 * Function: rm_get_session                                                   *
 *                                                                            *
 * Purpose: get specified user session, creating one if necessary             *
 *                                                                            *
 * Parameters: manager - [IN] the manager                                     *
 *             userid  - [IN] the userid                                      *
 *                                                                            *
 * Return value: session                                                      *
 *                                                                            *
 * Comments: When returning new session it's cached and also stored in        *
 *           database.                                                        *
 *           When returning cached session database is checked if the session *
 *           is not removed. In that case a new session is created.           *
 *                                                                            *
 ******************************************************************************/
rm_get_session

Purpose: get specified user session, creating one if necessary

Parameters: manager - [IN] the manager
userid  - [IN] the userid

Return value: session

Comments: When returning new session it's cached and also stored in
database.
When returning cached session database is checked if the session
is not removed. In that case a new session is created.
rm_get_session Purpose : get specified user session creating one if necessary Parameters : manager - [ IN ] the manager userid - [ IN ] the userid Return value : session Comments : When returning new session it ' s cached and also stored in database . When returning cached session database is checked if the session is not removed . In that case a new session is created .
static	zbx_rm_session_t	*rm_get_session(zbx_rm_t *manager, zbx_uint64_t userid)
{
	zbx_rm_session_t	*session;
	int			now;
	now = (int)time(NULL);
	if (NULL != (session = (zbx_rm_session_t *)zbx_hashset_search(&manager->sessions, &userid)))
	{
		DB_RESULT	result;
		result = DBselect("select NULL from sessions where sessionid='%s'", session->sid);
		if (NULL == DBfetch(result))
		{
			zbx_hashset_remove_direct(&manager->sessions, session);
			session = NULL;
		}
		DBfree_result(result);
	}
	if (NULL == session)
	{
		zbx_rm_session_t	session_local;
		zbx_db_insert_t		db_insert;
		session_local.userid = userid;
		session = (zbx_rm_session_t *)zbx_hashset_insert(&manager->sessions, &session_local,
				sizeof(session_local));
		session->sid = zbx_create_token(0);
		session->cookie = report_create_cookie(manager, session->sid);
		session->db_lastaccess = now;
		zbx_db_insert_prepare(&db_insert, "sessions", "sessionid", "userid", "lastaccess", "status", NULL);
		zbx_db_insert_add_values(&db_insert, session->sid, userid, now, ZBX_SESSION_ACTIVE);
		zbx_db_insert_execute(&db_insert);
		zbx_db_insert_clean(&db_insert);
	}
	session->lastaccess = now;
	return session;
}
static zbx_rm_session_t * rm_get_session ( zbx_rm_t * manager , zbx_uint64_t userid ) { zbx_rm_session_t * session ; int now ; now = ( int ) time ( NULL ) ; if ( NULL != ( session = ( zbx_rm_session_t * ) zbx_hashset_search ( & manager -> sessions , & userid ) ) ) { DB_RESULT result ; result = DBselect ( " " , session -> sid ) ; if ( NULL == DBfetch ( result ) ) { zbx_hashset_remove_direct ( & manager -> sessions , session ) ; session = NULL ; } DBfree_result ( result ) ; } if ( NULL == session ) { zbx_rm_session_t session_local ; zbx_db_insert_t db_insert ; session_local . userid = userid ; session = ( zbx_rm_session_t * ) zbx_hashset_insert ( & manager -> sessions , & session_local , sizeof ( session_local ) ) ; session -> sid = zbx_create_token ( 0 ) ; session -> cookie = report_create_cookie ( manager , session -> sid ) ; session -> db_lastaccess = now ; zbx_db_insert_prepare ( & db_insert , " " , " " , " " , " " , " " , NULL ) ; zbx_db_insert_add_values ( & db_insert , session -> sid , userid , now , ZBX_SESSION_ACTIVE ) ; zbx_db_insert_execute ( & db_insert ) ; zbx_db_insert_clean ( & db_insert ) ; } session -> lastaccess = now ; return session ; }
Function: rm_get_session                                                   
                                                                            
 Purpose: get specified user session, creating one if necessary             
                                                                            
 Parameters: manager - [IN] the manager                                     
             userid  - [IN] the userid                                      
                                                                            
 Return value: session                                                      
                                                                            
 Comments: When returning new session it's cached and also stored in        
           database.
Function : rm_get_session Purpose : get specified user session creating one if necessary Parameters : manager - [ IN ] the manager userid - [ IN ] the userid Return value : session Comments : When returning new session it ' s cached and also stored in database .