original files of m241

This commit is contained in:
neelimap
2026-07-30 11:19:44 +05:30
parent 170c2b3f3a
commit afc7070c1f
12254 changed files with 7655111 additions and 0 deletions
@@ -0,0 +1,491 @@
/* wmbSessionLib.c - RCB session session library */
/*
* Copyright (c) 2001, 2007 Wind River Systems, Inc.
*
* The right to copy, distribute, modify or otherwise make use
* of this software may be licensed only pursuant to the terms
* of an applicable Wind River license agreement.
*/
/*
modification history
--------------------
01d,09jul10,m_z remove compile warning
01c,14apr08,m_z declare semSession as PUBLIC (WIND00116756)
01b,24feb07,msa Correct the apigen comments so they match the actual
routines. Also fix any apigen errors.
01a,01aug01,pns written
*/
/*
DESCRIPTION
This module implements transaction processing for RCB objects
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#include "wm.h"
#include "wmb.h"
#ifdef __SNMP_API_ENABLED__
#include "mibway.h"
#include "wmmErrorLog.h"
#endif
STATUS wmbSessionValidate
(
WMB_SESSION_T * pCliEnv,
ubyte * pName,
ubyte * pPassword
);
OS_SEM_T semSession;
LOCAL ubyte4 sessionID;
#ifdef __ENABLE_CUSTOM_STRUCT__
LOCAL WMB_CUSTOM_CONSTRUCT gp_funcConstructCustom = NULL;
LOCAL WMB_CUSTOM_DESTRUCT gp_funcDestructCustom = NULL;
#endif
STATUS wmbSessionStart
(
void
)
{
sessionID = 0;
#ifdef __ENABLE_CUSTOM_STRUCT__
gp_funcConstructCustom = NULL;
gp_funcDestructCustom = NULL;
#endif
return wmosSemCreate(&semSession, 1, 0);
}
STATUS wmbSessionStop
(
void
)
{
return wmosSemDestroy(semSession);
}
LOCAL ubyte4 wmbSessionIdCreate
(
void
)
{
wmosSemTake(semSession, WAIT_FOREVER_K);
sessionID++;
wmosSemGive(semSession);
return sessionID;
}
/**************************************************************************
*
* wmbSessionCreate - create a new session
*
* RETURNS: OK
*
*/
STATUS wmbSessionCreate
(
WMB_CID_T component,
OS_SOCKET_T sock,
ubyte4 flags,
WMB_SESSION_T ** ppSession
)
{
if (! wmNew (*ppSession))
return wmError(ERROR_MEMMGR_NO_MEMORY, "no memory");
wmbSessionBless (*ppSession);
wmbSessionSockSet(*ppSession, sock);
(*ppSession)->flags = flags;
wmbSessionIdSet(*ppSession, wmbSessionIdCreate());
if (! wmbComponentBad(component))
{
wmbSessionComponentSet (*ppSession, component);
wmbSessionPoolSet (*ppSession, wmbComponentPoolGet(component));
}
/* Every session has a default transaction */
if (0 == ((*ppSession)->flags & WMB_SESSION_NO_DEF_TRANSACTION))
if (OK != wmbTransactionCreate(*ppSession, 0, 0, &(*ppSession)->tid))
{
wmFree(*ppSession);
return ERROR;
}
#ifdef __ENABLE_CUSTOM_STRUCT__
if (NULL != gp_funcConstructCustom)
if (OK != gp_funcConstructCustom(*ppSession, &((*ppSession)->pCustomData)))
{
if (0 == ((*ppSession)->flags & WMB_SESSION_NO_DEF_TRANSACTION))
wmbTransactionEnd((*ppSession)->tid);
wmFree(*ppSession);
return ERROR;
}
#endif
#ifdef __SNMP_API_ENABLED__
if (OK != wmmSnmpInit(*ppSession))
{
#ifdef __ENABLE_CUSTOM_STRUCT__
if (NULL != gp_funcDestructCustom)
gp_funcDestructCustom((*ppSession)->pCustomData);
#endif
if (0 == ((*ppSession)->flags & WMB_SESSION_NO_DEF_TRANSACTION))
wmbTransactionEnd((*ppSession)->tid);
wmFree(*ppSession);
return ERROR;
}
if (OK != wmmErrorLogStart((INT32)wmbSessionIdGet(*ppSession)))
wmLogPrintf ("unable to start SNMP error logger\n");
#endif
return OK;
}
/**************************************************************************
*
* wmbSessionDestroy - release session memory and resources
*
* RETURNS: OK
*
*/
STATUS wmbSessionDestroy
(
WMB_SESSION_T *pSession
)
{
WMB_TID_T tid1, tid2;
if (wmbSessionBad(pSession))
return wmError(ERROR_WMB_SESSION_INVALID, "wmbSessionDestroy: invalid session");
#ifdef __ENABLE_CUSTOM_STRUCT__
if (NULL != gp_funcDestructCustom)
gp_funcDestructCustom(pSession->pCustomData);
#endif
tid1 = wmbSessionTidGet(pSession);
while (!wmbTransactionBad(tid1))
{
tid2 = wmbTransactionSessionNextGet(tid1);
wmbTransactionEnd(tid1);
tid1 = tid2;
}
#ifdef __SNMP_API_ENABLED__
if (OK != wmmErrorLogEnd((INT32)wmbSessionIdGet(pSession)))
wmLogPrintf ("failed to end SNMP error logger\n");
#ifdef ENVOY_STACK_K
OCSNMP_DestructSnmpEnviron(pSession, NULL);
#else
OCSNMP_DestructSnmpEnviron(pSession);
#endif
#endif
wmFree(pSession);
return OK;
}
/**************************************************************************
*
* wmbSessionBackplaneGet - return backplane for <pSession>
*
* RETURNS: WMB_ID_T
*
*
* NOMANUAL
*/
WMB_ID_T wmbSessionBackplaneGet
(
WMB_SESSION_T * pSession
)
{
WMB_CID_T cid;
if (wmbSessionBad(pSession))
return wmbBackplaneGet();
cid = wmbSessionComponentGet(pSession);
if (wmbComponentBad(cid))
return wmbBackplaneGet();
return wmbComponentBackplaneGet(cid);
}
/**************************************************************************
*
* wmbSessionValidate - validate user login and password
*
* RETURNS: OK, ERROR
*
*
* NOMANUAL
*/
STATUS wmbSessionValidate
(
WMB_SESSION_T * pCliEnv,
ubyte * pName,
ubyte * pPassword
)
{
return OK;
}
#if 0
sbyte * wmbSessionEnvironmentGet
(
WMB_SESSION_T * pEnv,
sbyte4 index
)
{
if ((NULL == pEnv) || (SESSION_MAX_ENV <= index))
return NULL;
return pEnv->variables[index];
}
#endif /* 0 */
ubyte4 wmbSessionAddressGet
(
WMB_SESSION_T * pSession
)
{
OS_SOCKET_T sock;
ubyte4 addr;
if (wmbSessionBad(pSession))
return 0;
sock = wmbSessionSockGet(pSession);
if (OK != wmnetClientAddrGet(sock, &addr))
addr = 0;
return addr;
}
/**************************************************************************
*
* wmbSessionPrintf - printf to client connection
*
* RETURNS: OK, ERROR
*
*
* NOMANUAL
*/
sbyte4 wmbSessionPrintf
(
WMB_SESSION_T * pSession, /* session pointer */
sbyte * pFormat, /* format string */
...
)
{
va_list args;
OS_SOCKET_T sock;
sbyte4 bytes;
bytes = 0;
if (wmbSessionBad(pSession))
sock = 0;
else
sock = wmbSessionSockGet(pSession);
va_start (args, pFormat);
if (0 < sock)
wmnetSocketVprintf(sock, pFormat, args, &bytes);
else
bytes = vprintf(pFormat, args);
va_end (args);
return bytes;
}
/**************************************************************************
*
* wmbSessionAccessSet - Sets a user's access level (options?)
*
* Sets a user's access level (options?) to <newAccess>.
*
*
* RETURNS:
*\is
*\i OK
*\i ERROR (!rws specific?)
*
*\ie
*/
STATUS wmbSessionAccessSet
(
WMB_SESSION_T * pEnv, /* user environment struct pointer */
sbyte * pAccessStr /* access level string pointer !rws */
)
{
WM_ACCESS_T newAccess;
if (OK != wmAccessFromString(pAccessStr, &newAccess.read))
return ERROR;
if (OK != wmAccessFromString(pAccessStr, &newAccess.write))
return ERROR;
pEnv->access = newAccess;
return OK;
}
#if defined __WMB_VIEW_ACCESS_MODEL__
/**************************************************************************
*
* wmbSessionViewSet - Sets a user's accessible views
*
*
*
* RETURNS: STATUS
*
* NOMANUAL
*/
STATUS wmbSessionViewSet
(
WMB_SESSION_T *pSession, /* [in] Pointer to the session structure */
sbyte *userName /* [in] Pointer to the user name to set views for */
)
{
STATUS rc = OK;
WMB_VACM_GROUP_T *pGroup;
WMB_VACM_ACCESS_T *pAccess;
if (wmbSessionBad(pSession))
return wmError(ERROR_GENERAL_NOT_FOUND, "wmbSessionViewSet: Session Not Found");
rc = wmbVACMGroupLookup(ETC_SEC_MODEL_WMB_DEFAULT, userName, (sbyte2)(STRLEN(userName) + 1), &pGroup);
if ((OK == rc) && (NULL != pGroup))
{
rc = wmbVACMAccessFind(pGroup->grp_name, (ubyte2)STRLEN(pGroup->grp_name), NULL, 0,
ETC_SEC_MODEL_WMB_DEFAULT, ETC_SEC_LEVEL_WMB_DEFAULT, &pAccess);
if ((OK == rc) && (NULL != pAccess))
{
pSession->viewList.viewReadList = WMB_VACM_Access_ReadViewGet(pAccess);
pSession->viewList.viewWriteList = WMB_VACM_Access_WriteViewGet(pAccess);
}
}
return rc;
}
#endif /* __WMB_VIEW_ACCESS_MODEL__ */
/**************************************************************************
*
* wmbSessionTidSet - Sets TID
*
*
*
* RETURNS: none
*
* NOMANUAL
*/
void wmbSessionTidSet
(
WMB_SESSION_T *pSession, /* [in] Session structure to set */
WMB_TID_T tid /* [in] TID to append */
)
{
if (wmbTransactionBad(pSession->tid))
pSession->tid = tid;
else
{
if (tid != pSession->tid)
wmbTransactionSessionTidAppend(tid, pSession->tid);
}
}
sbyte * wmbSessionCwdGet
(
WMB_SESSION_T * pSession
)
{
WM_DIR_T * pDir;
if (NULL == (pDir = wmbSessionDirGet(pSession)))
return NULL;
return pDir->cwd;
}
#ifdef __ENABLE_CUSTOM_STRUCT__
/**************************************************************************
*
* wmbSessionCustomVectorSetup - Sets Custom data creation and destruction functions.
*
* RETURNS: none
*
* NOMANUAL
*/
void wmbSessionCustomVectorSetup
(
WMB_CUSTOM_CONSTRUCT p_funcConstructCustom, /* [in] Pointer to the custom construct function */
WMB_CUSTOM_DESTRUCT p_funcDestructCustom /* [in] Pointer to the custom destruct function */
)
{
gp_funcConstructCustom = p_funcConstructCustom;
gp_funcDestructCustom = p_funcDestructCustom;
}
/**************************************************************************
*
* wmbSessionCustomDataPointerGet - Returns custom data pointer.
*
* RETURNS: none
*
* NOMANUAL
*/
void *wmbSessionCustomDataPointerGet
(
WMB_SESSION_T* pSession /* [in] Pointer to the session record from which custom data is retrieved */
)
{
return (pSession != NULL ? pSession->pCustomData : NULL);
}
#endif
/* eof wmbSessionLib.c */