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,883 @@
/* wmbBackplaneLib.c - backplane specific support */
/*
* Copyright (c) 2001-2010, 2012, 2016 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
--------------------
01k,16aug16,r_w check the pipe state by wmosNamedPipeOpen.(VXW6-1504)
01j,20jul12,r_w eliminate memory leak issue. defect WIND00359749
01i,17may12,h_l replace NO_STRING with NULL_STRING (WIND00032212)
01h,17dec10,m_z part of APIs changed
CQID: Fix WIND00247096
01g,09jul10,m_z remove compile warning
01f,01apr10,f_f vxWorks 64bit support (WIND00193649)
01e,24feb07,msa correct the apigen comments so they match the actual
routines.
01d,05mar04,adb create minimal database to avoid boundary condition crash
01c,21jan04,jws remove Event Manager ifdef's
01b,04feb03,jws fix compiler warnings (SPR84193)
01a,22oct01,pns written
*/
/*
DESCRIPTION
backplane specific support
INCLUDE FILES: 'wm.h' 'wmb.h'
*/
/* includes */
#include "wm.h"
#include "wmb.h"
#include <stdlib.h>
/* externals - will move to header file */
IMPORT void (*pWmbEventSubmit)(WMB_CID_T,WMB_EVENT_TYPE_T,ubyte4,
WMB_EVENT_SEVERITY_T,ubyte4,ubyte4 *);
void wmbBackplaneRegistration ( WMB_ID_T backplane);
MEM_POOL_ID wmbBackplanePooledGet ( WMB_ID_T backplane);
/* globals */
#ifdef __USE_MEMORY_BLOCKS__
WM_BLOCK_T * pBlockObjects;
WM_BLOCK_T * pBlockBuffers;
#endif
/* macros */
#define wmbBackplaneStartSet(x, y) wmbBackplane(x)->startTime = y
#define wmbBackplaneDBSet(x, y) wmbBackplane(x)->pDB = y
#define wmbBackplaneComponentCountSet(x,y) wmbBackplane(x)->componentCount = y
#define wmbBackplaneComponentsSet(x, y) wmbBackplane(x)->pComponents = y
#define wmbBackplaneAccessSet(x, y) wmbBackplane(x)->accessInfo = y
#define wmbBackplaneSessionSet(x, y) wmbBackplane(x)->pSession = y
#define wmbBackplaneObjectsSet(x, y) wmbBackplane(x)->pooled.pObjects = y
#define wmbBackplaneBuffersSet(x, y) wmbBackplane(x)->pooled.pBuffer = y
#define wmbBackplaneDataSet(x, y) wmbBackplane(x)->pooled.pData = y
#define wmbBackplaneTempSet(x,y) wmbBackplane(x)->pTemp = y
#define wmbBackplaneMemSet(x,y) wmbBackplane(x)->pooled.pool = y
LOCAL WMB_ID_T pAnchor;
LOCAL OS_SEM_T bpSem;
LOCAL sbyte4 starts = 0;
#ifdef __ENABLE_SHARED_MEMORY__
typedef struct SHARE_KEY_T
{
ubyte4 cmd; /* message command */
ubyte4 key; /* shared memory id */
long size; /* shared size */
}
SHARE_KEY_T;
void wmbBackplaneShareSend
(
OS_MSGQ_T qid
)
{
SHARE_KEY_T share;
WMB_ID_T backplane;
OS_MEM_SHARE_T * pMemory;
backplane = wmbBackplaneGet();
pMemory = wmbBackplaneSharedGet(backplane);
share.cmd = WMB_MSG_SHARE_K;
share.key = (ubyte4) pMemory->key;
share.size = pMemory->size;
wmosQueueSend(qid, (char *) &share, sizeof(share), 0, 0);
}
void wmbBackplaneShareSet
(
sbyte * pBuffer,
sbyte4 bufSize
)
{
OS_MEM_SHARE_T * pMemory;
SHARE_KEY_T * pShare;
WMB_ID_T backplane;
DEBUG_MSG_0("wmbBackplaneShareSet: starting\n");
if (NULL == (backplane = wmbBackplaneGet()))
return wmError(ERROR_WMB_BACKPLANE_INVALID, "wmbBackplaneShare: no backplane\n");
pShare = (SHARE_KEY_T *) pBuffer;
pMemory = wmbBackplaneSharedGet(backplane);
pMemory->key = (SHARED_DATA_T) pShare->key;
pMemory->size = pShare->size;
wmosSharedMemoryAttach(pMemory);
}
OS_MEM_SHARE_T * wmbBackplaneSharedGet
(
WMB_ID_T backplane
)
{
return &(wmbBackplane(backplane)->shared);
}
#endif /* __ENABLE_SHARED_MEMORY__ */
/*
STATUS wmbBackplaneDBAdd
(
WMB_ID_T wmb,
WMB_DB_T * pDB
)
{
WMB_DB_T * pHead;
wmbBackplaneDBGet(wmb, &pHead);
if (NULL == pHead)
{
wmbBackplaneDBSet(wmb, pDB);
return OK;
}
while (NULL != pHead->pNext)
pHead = pHead->pNext;
pHead->pNext = pDB;
return OK;
}
*/
void wmbBackplaneNameSet
(
WMB_ID_T wmb,
sbyte * pName
)
{
STRNCPY(wmbBackplane(wmb)->name, pName, sizeof(wmbBackplane(wmb)->name));
}
/**************************************************************************
*
* wmbBackplaneStart - initialize backplane support
*
* RETURNS: OK, or ERROR
*/
STATUS wmbBackplaneStart
(
void
)
{
STATUS rc;
pAnchor = NULL;
rc = wmosSemCreate(&bpSem, 1, 0);
return rc;
}
/**************************************************************************
*
* wmbBackplaneStop - clean up backplane support structures
*
* RETURNS: OK, or ERROR
*/
STATUS wmbBackplaneStop
(
void
)
{
wmosSemDestroy(bpSem);
pAnchor = NULL;
return OK;
}
/**************************************************************************
*
* wmbBackplaneDBGet - get the backplane DB
*
* RETURNS: OK, or ERROR
*
* NOMANUAL
*/
WMB_DB_T * wmbBackplaneDBGet
(
WMB_ID_T wmb_id
)
{
WMB_BACKPLANE_T * pBackplane;
pBackplane = (WMB_BACKPLANE_T * ) wmb_id;
return pBackplane->pDB;
}
/**************************************************************************
*
* wmbBackplaneGet - get current backplane
*
* RETURNS: backplane ID or NULL if failed
*
* NOMANUAL
*/
WMB_ID_T wmbBackplaneGet
(
void
)
{
return pAnchor;
}
/**************************************************************************
*
* wmbBackplaneComponentCreate - Creates a component registry entry.
*
* Creates a management component registry entry in the backplane instance
* referenced by <pBackplane>.
*
*
* RETURNS:\is
*\i OK
*\i ERROR
* If the registry pointer is NULL. !rws
*\ie
*
* NOMANUAL
*/
STATUS wmbBackplaneComponentCreate
(
WMB_ID_T backplane, /* backplane instance pointer */
WMB_CID_T * pComponent /* pointer to component pointer */
)
{
ubyte2 count;
WMB_COMPONENT_T ** ppEntries; /* pointer to component pointers */
WMB_COMPONENT_T * pEntry; /* pointer to component pointer */
count = wmbBackplaneComponentCountGet (backplane);
ppEntries = wmbBackplaneComponentsGet (backplane);
if (! wmNew(pEntry))
return wmError(ERROR_MEMMGR_NO_MEMORY, "no memory");
*pComponent = pEntry;
ppEntries[count] = pEntry;
wmbBackplaneComponentCountSet (backplane, ++count);
#if 0
/*
WM_BLOCK_T * pRegistry;
pRegistry = wmbBackplaneComponentsGet(backplane);
*/
/*
assert(!wmMemBlockBad(pRegistry));
*/
*ppComponent = (WMB_COMPONENT_T *) wmMemBlockEntryCreate(pRegistry);
if (NULL == *ppComponent)
return wmError(ERROR_MEMMGR_NO_MEMORY, "wmbComponentEntryCreate: no memory");
DATA_ZERO_M(*ppComponent);
wmbComponentBless(*ppComponent);
if (0 < itemCount)
{
}
#endif
return OK;
}
/**************************************************************************
*
* wmbBackplaneComponentDestroy - remove a component registry entry.
*
* Remove a management component registry entry from the backplane.
*
*
* RETURNS:\is
*\i OK
*\i ERROR
* If the registry pointer is NULL. !rws
*\ie
*
* NOMANUAL
*/
STATUS wmbBackplaneComponentDestroy
(
WMB_CID_T component /* pointer to component pointer */
)
{
ubyte2 count;
ubyte2 index;
WMB_ID_T backplane;
WMB_COMPONENT_T ** ppEntries;
backplane = wmbComponentBackplaneGet(component);
count = wmbBackplaneComponentCountGet (backplane);
ppEntries = wmbBackplaneComponentsGet(backplane);
for (index = 0; index < count; index++)
{
if (ppEntries[index] != component)
continue;
/* decrement here so we can use a proper array max offset */
count--;
/* slide "top" into vacated slot */
if (index < count)
ppEntries[index] = ppEntries[count];
ppEntries[count] = NULL;
/* adjust our tally and we're done! */
wmbBackplaneComponentCountSet (backplane, count);
wmInvalidate(wmbComponent(component));
wmFree(component);
return OK;
}
return wmError(ERROR_GENERAL_NOT_FOUND, "component not found");
}
/**************************************************************************
*
* wmbBackplaneMaster - do we live in "master backplane"
*
* RETURNS: OK, or ERROR if creation failed
*
* NOMANUAL
*/
BOOL wmbBackplaneMaster
(
void
)
{
WMB_ID_T pBackplane;
if (NULL == (pBackplane = wmbBackplaneGet()))
return FALSE;
return (0 == STRCMP(((WMB_BACKPLANE_T*)pBackplane)->name, WMB_NAME_K));
}
/**************************************************************************
*
* wmbBackplaneRegistration - listen for requests from new bp's,
* and add them as producers
*
* Used by backplanes on same CPU
*
* RETURNS: N/A
*
* NOMANUAL
*/
void wmbBackplaneRegistration
(
WMB_ID_T backplane
)
{
sbyte * pName;
sbyte * pTmp;
OS_MSGQ_T qid;
WMB_CID_T sub_component;
OS_PIPE_T pipe;
sbyte buffer[128];
size_t length;
long temp;
if (wmbBackplaneBad(backplane))
{
wmError(ERROR_WMB_BACKPLANE_INVALID, "wmbBackplaneRegistration: invalid backplane");
return;
}
pName = wmbBackplaneNameGet(backplane);
DEBUG_MSG_1("Pipe Listener startup for backplane %s.\n", pName);
/* can't delete named pipes, so don't create after restarting backplane */
/* check the Pipe state by wmosNamedPipeOpen(),even if wmosNamedPipeCreate() fails */
if (0 == starts++)
(void)wmosNamedPipeCreate(pName, 8, 64);
if (OK != wmosNamedPipeOpen(pName, OS_PIPE_IN, FALSE, &pipe))
return;
while (1)
{
#ifndef _WRS_CONFIG_LP64
if (OK != wmosNamedPipeRead(pipe, buffer, sizeof(buffer) - 1, (ubyte4*)&length))
#else
if (OK != wmosNamedPipeRead(pipe, buffer, sizeof(buffer) - 1, (ubyte8*)&length))
#endif
continue;
/* see if we're shutting down */
if (wmbQuit(buffer, length))
break;
/* null terminate string */
buffer[length] = 0;
if (NULL == (pTmp = STRCHR(buffer, '!')))
{
DEBUG_MSG_1("wmbBackplaneRegistration: invalid registration: %s.\n", buffer);
continue;
}
*pTmp = 0;
pTmp++;
temp = atol(pTmp);
qid = (OS_MSGQ_T)temp;
wmbComponentRegister(pName, buffer, NULL, NULL, &sub_component);
wmbComponentRemote(sub_component, qid);
}
DEBUG_MSG_0("wmbBackplaneRegistration: terminating\n");
wmosNamedPipeClose(pipe);
wmosNamedPipeDelete(pName);
starts = 0;
wmTaskEnd();
}
/**************************************************************************
*
* wmbBackplaneCreate - create a backplane structure
*
* RETURNS: OK, or ERROR if creation failed
*
* NOMANUAL
*/
STATUS wmbBackplaneCreate
(
sbyte * pName,
sbyte4 size,
sbyte4 dbRows,
sbyte4 tableSize,
DTTypeInfo * pAccessInfo,
WMB_ID_T * pID
)
{
WMB_BACKPLANE_T* pBackplane;
WMB_ID_T pNext;
void * pData;
MEM_POOL_ID pool;
WM_BLOCK_T * pBlock;
WMB_DB_T * pDB;
BOOL master;
WMB_CID_T component;
OS_THREAD_T tid;
/* first backplane started is Master */
master = (NULL == pAnchor);
if (! wmNew(pBackplane))
return wmError (ERROR, "wmbBackplaneCreate: no memory");
pData = NULL;
pool = wmMemoryGet();
DEBUG_MSG_1("wmbBackplaneCreate: memory: 0x%x\n", *((int *) pBackplane));
wmbBackplaneBless (pBackplane);
wmbBackplaneNameSet ((WMB_ID_T)pBackplane, pName);
wmbBackplaneStartSet (pBackplane, (ubyte4)wmosTimeGet());
wmbBackplaneMemSet (pBackplane, pool);
wmosSemTake(bpSem, WAIT_FOREVER_K);
if (NULL == (pNext = pAnchor))
pAnchor = (WMB_ID_T)pBackplane;
wmosSemGive(bpSem);
*pID = (WMB_ID_T) pBackplane;
if (master)
{
#ifdef __ENABLE_SHARED_MEMORY__
if (OK != wmosSharedMemoryCreate (WMB_SHARED_DATA_NAME_K,
WMB_SHARED_DATA_SIZE_K,
wmbBackplaneSharedGet(pBackplane)))
return ERROR;
#endif
/* set up shared data space for objects and their buffers */
wmbBackplaneDataSet (pBackplane, pool);
/* listen for other backplanes registering */
if (OK != wmosThreadCreate(wmbBackplaneRegistration,
"tBackplane", pBackplane,
0, 0, &tid))
{
return ERROR;
}
wmosTimeSleep(1);
}
else
wmbBackplaneRegister(pName);
wmbBackplaneAccessSet(pBackplane, pAccessInfo);
/* create database for WindMarks */
wmbDBConstruct (pool, dbRows, tableSize, pName, FALSE, &pDB);
wmbBackplaneDBSet(pBackplane, pDB);
pBlock = wmMemBlockCreate (pool, NULL, WMB_OBJECT_POOL_K, sizeof(WMB_OBJECT_T));
wmbBackplaneObjectsSet (pBackplane, pBlock);
pBlock = wmMemBlockCreate (pool, NULL, WMB_BUFFER_POOL_K, sizeof(WM_BUFFER_T));
wmbBackplaneBuffersSet (pBackplane, pBlock);
/* create database for session variables */
wmbDBConstruct (wmbBackplaneMemGet(pBackplane), WMB_SESSION_VARS_K, 1,
"temporary", TRUE, &pDB);
wmbBackplaneTempSet (pBackplane, pDB);
#if defined __WMB_VIEW_ACCESS_MODEL__
wmbBackplaneNumViewDBSet(pBackplane, 0);
wmbBackplaneViewDBSet(pBackplane, NULL);
#else
wmAccessInfoSet(pAccessInfo);
#endif /* __WMB_VIEW_ACCESS_MODEL__ */
/* create backplane component */
if (OK != wmbComponentRegister (pName, pName, NULL, NULL, &component))
return ERROR;
return OK;
}
/**************************************************************************
*
* wmbBackplaneLookup - find backplane ID by name
*
* RETURNS: OK, or ERROR if not found
*
* NOMANUAL
*/
WMB_ID_T wmbBackplaneLookup
(
sbyte * pLookup /* name to look up */
)
{
WMB_ID_T backplane;
sbyte * pName;
if (NULL_STRING(pLookup))
{
wmError(ERROR_GENERAL_BAD_NAME, "wmbBackplaneLookup: null pointer");
return NULL;
}
backplane = wmbBackplaneGet();
if (wmbBackplaneBad(backplane))
return NULL;
if (NULL == (pName = wmbBackplaneNameGet(backplane)))
{
wmError(ERROR_WMB_BACKPLANE_INVALID, "wmbBackplaneLookup: no backplane");
return NULL;
}
if (0 == STRCMP (pLookup, pName))
{
return backplane;
}
wmError(ERROR_WMB_BACKPLANE_INVALID, "wmbBackplaneLookup: no backplane");
return NULL;
}
/**************************************************************************
*
* wmbBackplaneComponentGet - get the component that represents a backplane
*
* RETURNS: OK, or ERROR if invalid
*
* NOMANUAL
*/
STATUS wmbBackplaneComponentGet
(
WMB_ID_T backplane, /* backplane name */
WMB_CID_T * pComponent /* returned component ID */
)
{
WMB_COMPONENT_T ** backComponent;
backComponent = wmbBackplaneComponentsGet(backplane);
*pComponent = backComponent[0];
return OK;
}
/**************************************************************************
*
* wmbBackplaneRegister - register with "main" backplane
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS wmbBackplaneRegister
(
sbyte * pName
)
{
OS_PIPE_T pipe;
WMB_REG_T reg;
WMB_CID_T component;
size_t written;
DEBUG_MSG_1("Registering secondary backplane: %s\n", pName);
/* get secondary backplane's component id */
component = wmbComponentLookup(pName);
if (wmbComponentBad(component))
return ERROR;
if (OK != wmosNamedPipeOpen(WMB_NAME_K, OS_PIPE_OUT, TRUE, &pipe))
return ERROR;
/* this backplane will appear as a "producer" in master backplane */
wmZero(&reg);
reg.cmd = WMB_MSG_REGISTER_K;
reg.qid = wmbComponentQidGet(component);
STRNCPY(reg.name, pName, sizeof(reg.name) - 1);
#ifndef _WRS_CONFIG_LP64
wmosNamedPipeWrite(pipe, (char *) &reg, sizeof(reg), (ubyte4*)&written);
#else
wmosNamedPipeWrite(pipe, (char *) &reg, sizeof(reg), (ubyte8*)&written);
#endif
wmosNamedPipeClose(pipe);
return OK;
}
MEM_POOL_ID wmbBackplanePooledGet
(
WMB_ID_T backplane
)
{
return wmbBackplane(backplane)->pooled.pool;
}
void wmbBackplaneClose
(
sbyte * pName
)
{
sbyte4 index;
sbyte4 count;
size_t written;
MEM_POOL_ID pool;
WMB_ID_T backplane;
OS_PIPE_T pipe;
WMB_COMPONENT_T ** ppComponents;
WMB_COMPONENT_T * pComponent;
WMB_CID_T component;
WMBFUNCPTR killFunc;
/* deregister named pipe listener */
if (OK == wmosNamedPipeOpen(pName, OS_PIPE_OUT, FALSE, &pipe))
{
#ifndef _WRS_CONFIG_LP64
wmosNamedPipeWrite(pipe, WMB_QUIT_K, sizeof(WMB_QUIT_K), (ubyte4*)&written);
#else
wmosNamedPipeWrite(pipe, WMB_QUIT_K, sizeof(WMB_QUIT_K), (ubyte8*)&written);
#endif
wmosNamedPipeClose(pipe);
}
/* change to look up by name!!! */
backplane = wmbBackplaneGet();
wmbBackplaneComponentGet(backplane, &component);
/* remove registered components */
count = wmbBackplaneComponentCountGet (backplane);
ppComponents = wmbBackplaneComponentsGet (backplane);
/* deregister in reverse order of registration */
for (index = count; index > 0; index--)
{
pComponent = ppComponents[index - 1];
/* kill the component itself */
/* should this be thread-pooled and async to deal w/ possible
misbehaving components that get stuck... */
if (NULL != (killFunc = wmbComponentDeregGet(pComponent)))
killFunc(wmbComponentCtrlGet(pComponent));
else
wmbComponentDeregister(pComponent);
}
/* shut down object database */
wmbDBDestruct(wmbBackplaneDBGet(backplane));
/* shut down session variables database */
wmbDBDestruct(wmbBackplaneTempGet(backplane));
/* free memory blocks for objects and buffers */
wmMemBlockDestroy(wmbBackplaneObjectsGet (backplane));
wmMemBlockDestroy(wmbBackplaneBuffersGet (backplane));
/* free backplane and it's memory pool */
pool = wmbBackplaneMemGet (backplane);
if (NULL != pool && wmMemoryGet() != pool)
{
wmPoolFree(pool, backplane);
wmosFree(memPoolDelete(pool));
}
else
wmFree(backplane);
if (pWmbEventSubmit)
pWmbEventSubmit(component, WMB_EVENT_TYPE_CONTROL,
WMB_BACKPLANE_DELETED_EVENT,
WMB_EVENT_SEV_INFO, (ubyte4)(STRLEN(pName)),
(ubyte4*)pName);
}
#if defined __WMB_VIEW_ACCESS_MODEL__
/**************************************************************************
*
* wmbBackplaneViewAdd - Add a VACM View to the backplane
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS wmbBackplaneViewAdd
(
WMB_ID_T backplane, /* [in] Backplane ID to add the entries */
WMB_VIEW_DB_T *viewDB /* [in] Pointer to the start of the ViewDB */
)
{
WMB_VIEW_DB_T *viewDB2;
viewDB2 = wmbBackplaneViewDBGet(backplane);
if (NULL == viewDB2)
wmbBackplaneViewDBSet(backplane, viewDB);
else
{
while (NULL != viewDB2->pNext)
{
viewDB2 = viewDB2->pNext;
}
viewDB2->pNext = viewDB;
}
viewDB->pNext = NULL;
return OK;
}
/**************************************************************************
*
* wmbBackplaneViewDelete - Delete a VACM table from the backplane
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS wmbBackplaneViewDelete
(
WMB_ID_T backplane, /* [in] Backplane ID to add the entries */
WMB_VIEW_DB_T * viewDB /* [in] Pointer to the start of the ViewDB */
)
{
WMB_VIEW_DB_T * viewDB2;
viewDB2 = wmbBackplaneViewDBGet(backplane);
if (viewDB2 == viewDB)
wmbBackplaneViewDBSet(backplane, viewDB2->pNext);
else
{
while (viewDB2->pNext != viewDB)
viewDB2 = viewDB2->pNext;
viewDB2->pNext = viewDB->pNext;
}
wmbBackplaneDecNumViewDB(backplane);
return OK;
}
#endif /* __WMB_VIEW_ACCESS_MODEL__ */
/* eof wmbBackplane.c */
@@ -0,0 +1,568 @@
/* wmbCommonHandlers.c - some WindMark handlers non blade specific */
/* Copyright 2003 - 2011 Wind River Systems, Inc. */
/*
modification history
--------------------
01m,02dec11,f_f SNMP DateAndTime type support
01l,29Mar10,shi VxWorks 64-bit support
01k,10oct07,msa Fix defect 107626
01j,24feb07,msa Correct the apigen comments so they match the actual
routines.
01i,20jul04,dkg Account for variable length instances at end, but without IMPLIED flag
01h,12feb04,dkg corrected wmbCommonTrimInstance for variable length,
multiple index objects for SPR 90318
01g,14oct03,adb corrected wmbGetIndexInstanceHandler
01f,18aug03,adb removed wmbFileIncludeHandler
01e,14aug03,adb added wmbFileIncludeHandler
01d,22jul03,adb added wmbGetColumnarHandler
01c,17jun03,jws modify wmbGetInstanceHandler() for SPR 87977 and 89055
01b,11mar03,dr updated trimInstance to wmbCommonTrimInstance w/ NULL
checks, session & Component ID
01a,09dec03,jc written
*/
/*
DESCRIPTION
This module contains the handlers for some WindMarks that are not specific
to any blade.
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#include "wm.h"
#include "wmb.h"
#include <string.h>
#include <stdlib.h>
/* defines */
/* typedefs */
/* globals */
/* locals */
LOCAL sbyte * frontNumbersTrim (sbyte ** ppDottedOID, ubyte4 numsToSkip);
/***************************************************************************
*
* wmbGetInstanceHandler - handler for the getInstance WindMark
*
* The getInstance WindMark takes one parameter, a table name, and returns
* the current row instance for that table. If the table name is missing
* or invalid, the innermost table is assumed (the one created by the last
* createTable call)
*
* This fuction implements the handler for getInstance WindMark. It updates
* the object data buffer with an instance string or "0". As a special case,
* "0" is also returned if the last attempt to get the next table row
* failed.
*
* NOTE: This handler only supports GET requests.
*
* RETURNS: ERROR or OK.
*
* NOMANUAL
*/
STATUS wmbGetInstanceHandler
(
WMB_TID_T tid, /* transaction id */
WMB_OBJ_T obj, /* the WindMark object */
COMMAND_T cmd /* handler command */
)
{
WM_BUFFER_T * pBuf;
sbyte * pTblName;
WMB_SESSION_T * pSession = wmbTransactionSessionGet(tid);
sbyte * pStrBuf;
size_t buffSize;
size_t bw;
if (CMD_GET_K != cmd)
return wmError (ERROR_GENERAL_READ_ONLY, "getInstance is read only");
while (wmbObjectGood (obj))
{
/* get the name of the table (NULL is a valid value) */
pTblName = wmbObjectInstancePtrGet(obj);
/* instead of allocating a temporary buffer, we'll use the object's own */
pBuf = wmbObjectValueGet (obj);
pStrBuf = wmBufferDataGet (pBuf);
buffSize = wmBufferMaxGet (pBuf);
pStrBuf[0] = 0;
/*
* If no instance information available, the handler should
* return "0". The if statement relies on left-to-right execution
* of the clauses. wmbTableFlagsGet() does not check for an
* error return because wmbTableInstanceGet() does.
*/
if (((wmbTableFlagsGet(pSession) & WMB_TABLE_GET_NEXT_FAILED) != 0)
|| (OK != wmbTableInstanceGet (pSession, pTblName, pStrBuf,
buffSize, &bw))
|| ( 0 == pStrBuf[0]))
{
strcpy (pStrBuf, "0"); /* string indicating no instance */
bw = 2; /* bytes in string */
}
wmBufferUsedSet (pBuf, bw); /* we already put the data in */
wmBufferTypeSet (pBuf, DATATYPE_STRING_K); /* just to be safe */
obj = wmbObjectNextGet (obj);
}
return OK;
}
/***************************************************************************
*
* wmbGetIndexInstanceHandler - handler for the getIndexInstance WindMark
*
* The getIndexInstance WindMark takes two parameters (a table name and
* one of the SNMP indices for that table) and returns the portion of
* the current instance that pertains to that SNMP index.
* If only parameter is passed, it is assumed to be the SNMP index, and
* the innermost table is used (the one created by the last
* createTable call)
*
* This fuction implements the handler for getIndexInstance WindMark.
*
* NOTE: This handler only supports GET requests.
*
* RETURNS: ERROR or OK.
*
* NOMANUAL
*/
STATUS wmbGetIndexInstanceHandler
(
WMB_TID_T tid, /* transaction id */
WMB_OBJ_T obj, /* the WindMark object */
COMMAND_T cmd /* handler command */
)
{
WM_BUFFER_T * pBuf;
sbyte * pTblName;
sbyte * pSnmpIndex = NULL;
WMB_SESSION_T * pSession = wmbTransactionSessionGet(tid);
sbyte * pStrBuf;
size_t buffSize;
size_t bw;
sbyte tableName[40];
if (CMD_GET_K != cmd)
return wmError (ERROR_GENERAL_READ_ONLY, "getIndexInstance is read only");
while (wmbObjectGood (obj))
{
/* get the name of the table */
pTblName = STRTOK_REENTRANT (wmbObjectInstancePtrGet(obj),",",
&pSnmpIndex);
if (NULL == pTblName)
return wmError (ERROR_GENERAL, "this handler needs at least 1 arg");
if (NULL == pSnmpIndex)
{
pSnmpIndex = pTblName;
if (OK != wmbTableInnermostGet (pSession, pTblName, tableName, 40, NULL))
return wmError (ERROR_GENERAL, "no open table");
pTblName = tableName;
}
/* instead of allocating a temporary buffer, we'll use the object's own */
pBuf = wmbObjectValueGet (obj);
pStrBuf = wmBufferDataGet (pBuf);
buffSize = wmBufferMaxGet (pBuf);
pStrBuf[0] = 0;
/* if no instance information available, the handler should return "0" */
if ((OK != wmbTableInstanceGet (pSession, pTblName, pStrBuf,
buffSize, &bw))
|| ( 0 == pStrBuf[0]))
{
strcpy (pStrBuf, "0");
}
else
{
pStrBuf = wmbCommonTrimInstance (pStrBuf,
pTblName,
pSnmpIndex,
NULL,
/* session independent search */
FALSE);
}
if (pStrBuf == NULL)
return wmError (ERROR_GENERAL, "invalid index object or instance");
bw = 1 + strlen (pStrBuf);
/* even though previously pStrBuf = wmBufferDataGet (pBuf) */
bcopy (pStrBuf, wmBufferDataGet (pBuf), bw);
wmBufferUsedSet (pBuf, bw); /* we already put the data in */
wmBufferTypeSet (pBuf, DATATYPE_STRING_K); /* just to be safe */
obj = wmbObjectNextGet (obj);
}
return OK;
}
/***************************************************************************
*
* wmbCommonTrimInstance - return substring of an instance suffix for an SNMP index
*
* Note: WindMarks are registered with either the Component ID as the parent ID
* or with a Session ID (e.g. WMW and createTable). Temporary WindMarks
* should be requested using the session ID to distinguish multiple sessions.
*
* RETURNS: NULL for error, else pointer to a string buffer with the requested Index OID piece.
*
* NOMANUAL
*/
sbyte * wmbCommonTrimInstance
(
sbyte * pInstanceSuffix, /*[in, modified] full instance in */
sbyte * pTableName, /*[in] table name containing the indices */
sbyte * pSnmpIndex, /*[in] name of index for which instance is request */
void * sessionOrComponent,/*[in] object's parent ID to match, or NULL for any */
BOOL previousArgIsSession /*[in] TRUE if previous argument is session ID */
)
{
DB_ENTRY_T * dbEntry;
DB_TABLE_T * dbTable;
WMB_DB_T * pDB;
WMB_ID_T backplane;
sbyte * pTmp;
sbyte * trimmedNumbers;
ubyte2 i;
ubyte4 numbersToSkip = 0; /* number = 4 byte integer in an OID */
WMB_OBJECT_T tmpObj;
WMB_CID_T compId;
backplane = wmbBackplaneGet();
if (NULL == (pDB = wmbBackplaneDBGet(backplane)))
return NULL;
if (NULL == (dbTable = wmbDBTableGet (pDB, pTableName, sessionOrComponent, previousArgIsSession)))
{
/* If the object is not found when using a ComponentID as parent, then we give up */
if (!previousArgIsSession)
return NULL;
/* If we were using a Session ID, then we should retry with its Component ID.
* We do not try a global match 'NULL' search, since we might pick up another session's object
*/
if ((wmbObjectInit (&tmpObj, NULL, pTableName, NULL, 0, FALSE) == ERROR) ||
(wmbObjectResolveSession ((WMB_SESSION_T *) sessionOrComponent, &tmpObj) == ERROR))
return NULL;
if (((compId = wmbObjectComponentGet (&tmpObj)) == NULL) ||
((dbTable = wmbDBTableGet (pDB, pTableName, compId, FALSE)) == NULL))
{
wmbObjectDelete (&tmpObj);
return NULL;
}
/* Delete the object anyway. */
wmbObjectDelete (&tmpObj);
/* Update our search criteria */
sessionOrComponent = compId;
previousArgIsSession = FALSE;
}
/* loop through all the table indices except last */
for (i=0; i <= wmbDBTableNxCountGet (dbTable); i++)
{
if (NULL == (dbEntry = wmbDBEntryGet (pDB, wmbDBTableNxNameGet(dbTable,i),
sessionOrComponent, previousArgIsSession)))
return NULL;
/*
* If this is the last index object, just return the remaining
* instance string.
*/
if ((i == wmbDBTableNxCountGet (dbTable) - 1) &&
(0 == strcmp (pSnmpIndex, wmbEntryNameGet (dbEntry))))
{
/* see if this is a variable length instance, but with no IMPLIED flag */
switch (wmbEntryTypeGet (dbEntry))
{ /* variable length types */
case DATATYPE_STRING_K:
case DATATYPE_PORT_LIST_K:
case DATATYPE_OCTETS_K:
case DATATYPE_DATEANDTIME_K:
case DATATYPE_LIST_K:
case DATATYPE_OPAQUE_K:
case DATATYPE_VOID_K:
case DATATYPE_OID_K:
/* If no IMPLIED flag, just skip the length number and return the rest */
if (!wmbEntryFlagGet(dbEntry,DB_FLAG_INDEX_IMPLIED_K))
frontNumbersTrim (&pInstanceSuffix, 1);
break;
default:
break;
}
return pInstanceSuffix;
}
switch (wmbEntryTypeGet (dbEntry))
{ /* variable length types */
case DATATYPE_STRING_K:
case DATATYPE_PORT_LIST_K:
case DATATYPE_OCTETS_K:
case DATATYPE_DATEANDTIME_K:
case DATATYPE_LIST_K:
case DATATYPE_OPAQUE_K:
case DATATYPE_VOID_K:
case DATATYPE_OID_K:
/* remove the length part from pInstanceSuffix */
numbersToSkip = (ubyte4)strtoul (pInstanceSuffix, &pTmp, 0);
/* skip '.' from pTmp */
pTmp++;
STRCPY (pInstanceSuffix, pTmp);
break;
case DATATYPE_CHAR_K: /* Not an OID type, but set skip to 1 just in case */
case DATATYPE_UCHAR_K: /* Not an OID type, but set skip to 1 just in case */
case DATATYPE_INTEGER_K:
case DATATYPE_COUNTER_K:
case DATATYPE_GAUGE_K:
case DATATYPE_TICKS_K:
case DATATYPE_LONG_K:
case DATATYPE_UINTEGER_K:
case DATATYPE_ULONG_K:
case DATATYPE_TIME_K:
case DATATYPE_ROW_STATUS_K:
case DATATYPE_BOOL_K:
case DATATYPE_ABSOLUTE_K:
case DATATYPE_ENUM_K:
case DATATYPE_FUNCPTR_K:
case DATATYPE_VOIDFUNCPTR_K:
case DATATYPE_SHORT_K:
case DATATYPE_USHORT_K:
numbersToSkip = 1;
break;
case DATATYPE_IPV4_K:
numbersToSkip = 4;
break;
case DATATYPE_IPV6_K:
numbersToSkip = 16;
break;
case DATATYPE_MACADDR_K:
numbersToSkip = 6;
break;
case DATATYPE_BRIDGE_ID_K:
numbersToSkip = 2;
break;
/* Can there really be index objects of these type ? */
case DATATYPE_COUNTER64_K:
case DATATYPE_INT64_K:
case DATATYPE_UINT64_K:
numbersToSkip = 2;
break;
/* Can there really be index objects of these type ? */
case DATATYPE_ACCESS_K:
case DATATYPE_NULL_K:
case BASE_DATATYPE_K:
case DATATYPE_INVALID_K:
default:
numbersToSkip = 0;
break;
}
trimmedNumbers = frontNumbersTrim (&pInstanceSuffix, numbersToSkip);
if (0 == strcmp (pSnmpIndex, wmbEntryNameGet (dbEntry)))
return trimmedNumbers;
}
/* if last index matches, just return the remaining numbers in the OID */
if (strcmp (pSnmpIndex, wmbDBTableNxNameGet (dbTable,i)))
strcpy (pInstanceSuffix, "0"); /* but if index not found, return 0 */
return pInstanceSuffix;
}
/***************************************************************************
*
* frontNumbersTrim - remove some numbers from the front of a dotted OID string
*
* This function takes a pointer to a pointer to a dotted oid string, and the
* number of numbers that need to be removed from the front. For example, if
* *ppDottedOID points to "123.45.67.89.00" and numsToSkip is 3, a pointer to
* "123.45.67" will be returned, and *pDottedOID will be left pointing to "89.00"
* When numsToSkip matches the numbers in pDottedOID, the entire string is
* returned and pDottedOID is NULLed. You can imagine this function as
* multiple iterations of strtok at once.
*
* If any problems are encountered the function will return NULL and leave the
* strings unchanged.
*
* RETURNS: a pointer to the discarded part of the string
*
* NOMANUAL
*/
LOCAL sbyte * frontNumbersTrim
(
sbyte ** ppDottedOID,
ubyte4 numsToSkip
)
{
ubyte4 i;
sbyte * pStr = *ppDottedOID;
sbyte * pRemovedStr = *ppDottedOID;
if (0 == numsToSkip)
return NULL;
/* skip all numbers but one */
for (i=0; i < numsToSkip - 1; i++)
if (NULL != (pStr = strchr (pStr, '.')))
pStr++;
else return NULL;
/* this is the last trimmed num, is it the last in pDottedOid as well? */
if (NULL != (pStr = strchr (pStr, '.')))
*pStr++ = 0; /* it's not the last, so its safe to increment pStr */
*(ppDottedOID) = pStr;
return pRemovedStr;
}
/***************************************************************************
*
* wmbGetColumnarHandler - handler for the getIndexInstance WindMark
*
* The getColumnar WindMark takes two parameters (a table name and a
* columnar object name) and returns the value of the columnar object.
*
* This function, wmbGetColumnarHandler, can be the getColumnar WindMark handler.
*
* NOTE: This handler only supports GET requests.
*
* RETURNS: ERROR or OK.
*
* NOMANUAL
*/
STATUS wmbGetColumnarHandler
(
WMB_TID_T tid, /* transaction id */
WMB_OBJ_T obj, /* the WindMark object */
COMMAND_T cmd /* handler command */
)
{
WMB_SESSION_T * pSession = NULL;
sbyte * pTableName = NULL;
sbyte * pColumnarObjectName = NULL;
WM_BUFFER_T * pBuffer = NULL;
sbyte * pBufferData = NULL;
size_t bufferDataSize = 0;
sbyte tempInstanceHolder[100];
size_t instanceSize = 0;
tempInstanceHolder[0] = 0;
if (NULL == (pSession = wmbTransactionSessionGet(tid)))
{
return (wmError (ERROR_GENERAL,
"wmbGetColumnarHandler: invalid session"));
}
if (CMD_GET_K != cmd)
{
return (wmError (ERROR_GENERAL_READ_ONLY,
"wmbGetColumnarHandler: getColumnar is read only"));
}
while (wmbObjectGood (obj))
{
/* get the name of the table */
pTableName = STRTOK_REENTRANT (wmbObjectInstancePtrGet(obj),
",",
&pColumnarObjectName);
if ((NULL == pTableName) || (NULL == pColumnarObjectName))
{
return (wmError (ERROR_GENERAL,
"wmbGetColumnarHandler: expected two arguments"));
}
/*
* A. SNMP tables may be indexed by a set of indices
* B. wmbTableInstanceGet returns currently active instance
*/
if (((wmbTableFlagsGet(pSession) & WMB_TABLE_GET_NEXT_FAILED) != 0) ||
(OK != wmbTableInstanceGet (pSession,
pTableName,
tempInstanceHolder,
100,
&instanceSize)) ||
(0 == tempInstanceHolder[0]))
{
return (wmError (ERROR_GENERAL_READ_ONLY,
"wmbGetColumnarHandler: failed to get instance"));
}
/* use the object's buffer to avoid buffer allocation */
pBuffer = wmbObjectValueGet (obj);
pBufferData = wmBufferDataGet (pBuffer);
bufferDataSize = wmBufferMaxGet (pBuffer);
pBufferData[0] = 0;
if (OK != wmbDataStringGet (pSession,
pColumnarObjectName,
tempInstanceHolder,
(sbyte4)instanceSize,
pBufferData,
(long)bufferDataSize,
NULL))
{
strcpy (pBufferData, "0");
}
bufferDataSize = 1 + strlen (pBufferData);
wmBufferUsedSet (pBuffer, bufferDataSize); /* data stored */
wmBufferTypeSet (pBuffer, DATATYPE_STRING_K); /* to be safe */
obj = wmbObjectNextGet (obj);
}
return OK;
} /* wmbGetColumnarHandler */
/* eof wmbCommonHandlers.c */
@@ -0,0 +1,838 @@
/* wmbComponentLib.c - Wind River CLI, Web, MIBway component library */
/*
* Copyright (c) 2001-2010, 2012 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
--------------------
01i,17may12,h_l replace NO_STRING with NULL_STRING (WIND00032212)
01h,19jul10,h_y modified for WIND00223629
01g,01apr10,f_f VxWorks 64bit support (WIND00193649)
01f,24feb07,msa Correct the apigen comments so they match the actual
routines.
01e,16feb06,ps changes for webcli on linux
01d,15sep04,gsr to enable listner task to be spawned only when event manager
is defined SPR#101289
01c,22aug03,jws fix compiler warnings, SPR 90282
01b,08oct01,rws comments modified
01a,01aug01,pns written
*/
/*
DESCRIPTION
This module provides routines for registering and managing RCB management
components. An RCB management component is an application--a group of data
producers, data consumers, event producers, and event consumers--that
communicates with the backplane to monitor, control, or configure a device.
Typical examples of RCB management components include Wind River Web Server,
for web-based device management, and Wind River CLI--a command line device
management interface.
INCLUDE FILES: wm.h wmb.h
*/
#undef __DEBUG_MESSAGES_OFF__ /* undefine to allow debugging messages */
/* includes */
#include "wrn/wm/common/wm.h"
#include "wrn/wm/backplane/wmb.h"
#ifndef WMB_QUEUE_SIZE_K
#define WMB_QUEUE_SIZE_K 32
#endif
#define wmbComponentBackplaneSet(x,y) wmbComponent(x)->backplane = y
#define wmbComponentNameSet(x,y) STRNCPY(wmbComponent(x)->name, y, WMB_COMPONENT_NAME_MAX_K)
#define wmbComponentCidSet(x,y) wmbComponent(x)->cid = y
#define wmbComponentFlagsSet(x,y) wmbComponent(x)->flags = y
#define wmbComponentDeregSet(x,y) wmbComponent(x)->deregister = y
#define wmbComponentCtrlSet(x,y) wmbComponent(x)->cookie = y
#define wmbComponentQidSet(x,y) wmbComponent(x)->qid = y
#define wmbComponentListenerSet(x,y) wmbComponent(x)->listener = (WMB_LISTENER_T) y
#define wmbComponentDBSet(x,y) wmbComponent(x)->pDB = y
/*
#define wmbComponentStateSet(x,y) wmbComponent(x)->pState = y
*/
#define wmbComponentObjectsSet(x,y) wmbComponent(x)->shares.pObjects = y
#define wmbComponentBuffersSet(x,y) wmbComponent(x)->shares.pBuffer = y
#define wmbComponentDataSet(x,y) wmbComponent(x)->shares.pool = y
#define wmbComponentMemSet(x,y) wmbComponent(x)->memID = y
/*
#define wmbComponentLockHeadSet(x,y) wmbComponent(x)->pLockHead = y
*/
#define wmbComponentHandlerSet(x,y) wmbComponent(x)->handler = y
LOCAL OS_SEM_T mComponentMutex;
LOCAL sbyte4 mCID;
LOCAL sbyte4 blockSize = 0;
#ifndef WMB_LISTENER_SUFFIX_K
#define WMB_LISTENER_SUFFIX_K "listener"
#endif
#define THREAD_NAME_SIZE_K WMB_COMPONENT_NAME_MAX_K + \
sizeof(WMB_LISTENER_SUFFIX_K) + \
2 /* for space between and null at end */
#define FLAG_COMPONENT_DOMAIN_K 0x0001
#define FLAG_COMPONENT_REMOTE_K 0x0002
/**************************************************************************
*
* wmbComponentMemGet - Return component's pool id.
*
* RETURNS: MEM_POOL_ID
*
* NOMANUAL
*/
MEM_POOL_ID wmbComponentMemGet
(
WMB_CID_T cid /* [in] Component ID */
)
{
WMB_ID_T backplane;
if ((! wmbComponentBad(cid)) && NULL != wmbComponent(cid)->pPooled)
return wmbComponent(cid)->pPooled->pool;
backplane = wmbBackplaneGet();
return wmbBackplaneMemGet(backplane);
}
/**************************************************************************
*
* wmbComponentLockHeadSet - Set the Lock queue head
*
* RETURNS: none
*
* NOMANUAL
*/
void wmbComponentLockHeadSet
(
WMB_CID_T component, /* [in] Component ID */
WMB_LOCK_HEAD_T * pHead /* [in] Lock Queue Head */
)
{
wmbComponent(component)->pLockHead = pHead;
}
/**************************************************************************
*
* wmbComponentStateSet - Set the cookie of the component.
*
* RETURNS: none
*
* NOMANUAL
*/
void wmbComponentStateSet
(
WMB_CID_T component, /* [in] component ID */
void * pState /* [in] Pointer to the cookie */
)
{
wmbComponent(component)->pState = pState;
}
/**************************************************************************
*
* wmbComponentDeregister - Handle deregister requests from components.
*
* If a component is restarting or being removed from the system,
* it should de-register using the following call. If the component
* has not already de-registered any associated resources, archives or events,
* they will be de-registered (using the calls passed in on registration) as a
* result of this call.
*
* RETURNS: OK or ERROR
*/
STATUS wmbComponentDeregister
(
WMB_CID_T cid /* [in] Component identifier */
)
{
STATUS status;
if (wmbComponentBad(cid))
return wmError(ERROR_GENERAL_INVALID, "invalid component");
/* remove any registered windmark resources */
wmbDBRemove(cid);
/* if there is a listener, tell it to stop */
wmbComponentSend(cid, WMB_QUIT_K, sizeof(WMB_QUIT_K));
/*
if (FLAG_SET(cid, FLAG_COMPONENT_DOMAIN_K))
wmosQueueDelete(wmbComponentQidGet(cid));
*/
/* remove ourselves from the backplane */
status = wmbBackplaneComponentDestroy(cid);
return status;
}
/**************************************************************************
*
* wmbComponentResourceLoad - Load an array of database entries.
*
* This routine loads an array of database entries [<pTable>,<rows>] into
* the database referenced by <pDB>, in the managament component referenced
* by <pComponent>.
*
* RETURNS: OK or ERROR
*
*
* NOMANUAL
*/
STATUS wmbComponentResourceLoad
(
WMB_CID_T component, /* [in] management component name pointer */
WMB_ENTRY_T * pEntries, /* [in] database table pointer */
sbyte4 rows, /* [in] number of rows in database */
sbyte * pPath /* [in] path is prepended to name */
)
{
WMB_ID_T backplane;
WMB_DB_T * pDB;
#if 0
DB_ENTRY_T * pEntry;
DB_NAMES_T * pFields;
sbyte4 index;
sbyte * pName;
WMB_HANDLER_T handler;
#endif
/* Is there anything to register? */
if (0 == rows)
return OK;
/* make sure starting with valid data */
backplane = wmbComponentBackplaneGet(component);
if wmbBackplaneBad(backplane)
return wmError(ERROR_WMB_BACKPLANE_INVALID, "wmbComponentResourceLoad: no backplane");
if (wmbComponentBad(component))
return wmError(ERROR_GENERAL_INVALID, "wmbComponentResourceLoad: no component");
if (NULL == pEntries)
return wmError(ERROR_GENERAL_NO_DATA, "wmbComponentResourceLoad: no entries");
if (NULL == (pDB = wmbBackplaneDBGet(backplane)))
return wmError(ERROR_DB_NO_DATABASE, "wmbComponentResourceLoad: no database");
return wmbDBAdd(pDB, component, pEntries, rows, pPath);
} /* wmbComponentResourceLoad */
/**************************************************************************
*
* wmbComponentTableLoad - Load an array of database entries.
*
* This routine loads an array of database entries [<pTable>,<rows>] into
* the database referenced by <pDB>, in the managament component referenced
* by <pComponent>.
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS wmbComponentTableLoad
(
WMB_CID_T component, /* [in] management component name pointer */
WMB_TABLE_T * pTable, /* [in] database table pointer */
sbyte4 tableSize, /* [in] number of rows in database */
sbyte * pPath /* [in] path is prepended to name */
)
{
WMB_ID_T backplane;
WMB_DB_T * pDB;
/* Is there anything to register? */
if (0 == tableSize)
return OK;
/* make sure starting with valid data */
backplane = wmbComponentBackplaneGet(component);
if wmbBackplaneBad(backplane)
return wmError(ERROR_WMB_BACKPLANE_INVALID, "wmbComponentTableLoad: no backplane");
if (wmbComponentBad(component))
return wmError(ERROR_GENERAL_INVALID, "wmbComponentTableLoad: no component");
if (NULL == pTable)
return wmError(ERROR_GENERAL_NO_DATA, "wmbComponentTableLoad: no table entries");
if (NULL == (pDB = wmbBackplaneDBGet(backplane)))
return wmError(ERROR_DB_NO_DATABASE, "wmbComponentTableLoad: no database");
return wmbDBTableAdd(pDB, component, pTable, tableSize,pPath);
} /* wmbComponentTableLoad */
/**************************************************************************
*
* wmbComponentStart - Initializes a management component.
*
* Initializes a registered management component. !rws
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS wmbComponentStart
(
sbyte4 block_size /* [in] Block size of pool */
)
{
blockSize = block_size;
/*
WM_BLOCK_T * pRegistry;
*/
mCID = 0;
/*
pRegistry = wmBlockCreate (wmbBackplaneMemGet(backplane), NULL, blocksize,
sizeof(WMB_COMPONENT_T));
wmbBackplaneComponentsSet(backplane, pRegistry);
*/
return wmosSemCreate(&mComponentMutex, 1, 0);
}
/**************************************************************************
*
* wmbComponentStop - Destroys the mutex sem when leaving the backplane.
*
* RETURNS: n/a
*
* NOMANUAL
*/
void wmbComponentStop
(
WMB_ID_T backplane /* [in] Backplane ID to stop */
)
{
wmosSemDestroy(mComponentMutex);
}
#ifdef __WM_EVENT_MANAGER__
/**************************************************************************
*
* wmbComponentListenerStart - Start a event listener thread.
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
LOCAL STATUS wmbComponentListenerStart
(
WMB_CID_T component /* [in] Component ID */
)
{
#ifndef __DEBUG_SINGLE_THREAD__
sbyte threadName[THREAD_NAME_SIZE_K];
ubyte4 nameSize = THREAD_NAME_SIZE_K;
sbyte * pName;
OS_THREAD_T tid;
OS_MSGQ_T qid;
/* create a unique name for the task */
pName = wmbComponentNameGet(component);
STRNCPY(threadName, pName, nameSize);
nameSize -= (ubyte4)STRLEN(pName);
STRNCAT(threadName, "_", nameSize);
nameSize--;
STRNCAT(threadName, WMB_LISTENER_SUFFIX_K, nameSize);
/*
* we create the queue here instead of wmbComponentListener,
* because that provides no visibility to the queue create failing
*/
if (OK != wmosQueueCreate (WMB_QUEUE_SIZE_K, sizeof(MSG_IPC_T), 0, &qid))
return ERROR;
wmbComponentQidSet (component, qid);
wmosThreadCreate ((VOIDFUNCPTR) wmbComponentListener, threadName,
component, 0, 0, &tid);
/* yield to give listener a chance to start */
#ifdef WEBCLI_ON_LINUX
sched_yield ();
#else
taskDelay(0);
#endif
DEBUG_MSG_3 ("wmbComponentListener: %s listening to %d in thread %d\n", pName, qid, tid);
#endif
return OK;
}
#endif
/**************************************************************************
*
* wmbComponentRegister - Initialize a management component.
*
* This routine registers (initializes) the management component <pName> with
* the backplane instance 'WMB_ID_T'. RCB management components must
* register with the RCB before any transactions can occur between the
* backplane and that component.
*
* RETURNS: OK or ERROR
*
*/
STATUS wmbComponentRegister
(
sbyte * pBackplane, /* [in] backplane name */
sbyte * pName, /* [in] component name */
WMBFUNCPTR pfDeregister, /* [in] deregistration handler */
void * deregCookie, /* [in] deregistration state */
WMB_CID_T * pComponent /* [out] Component identifier */
)
{
sbyte * pMaster;
#ifdef __WM_EVENT_MANAGER__
BOOL isLocal;
#endif
WMB_ID_T backplane;
sbyte4 queueSize; /* depth of message queue listener */
WMB_CID_T component;
queueSize = 0;
if (NULL_STRING(pBackplane))
return wmError(ERROR_GENERAL_BAD_NAME, "no name");
/* registering w/ default backplane as real component? */
backplane = wmbBackplaneGet();
if (wmbBackplaneBad(backplane))
return wmError(ERROR_WMB_BACKPLANE_INVALID, "no backplane");
if (NULL == (pMaster = wmbBackplaneNameGet(backplane)))
return wmError(ERROR_WMB_BACKPLANE_INVALID, "no backplane name");
#ifdef __WM_EVENT_MANAGER__
isLocal = (0 == STRCMP(pBackplane, pMaster));
#endif
if (OK != wmbBackplaneComponentCreate(backplane, &component))
return ERROR;
wmbComponentBless (component);
wmbComponentBackplaneSet (component, backplane);
wmbComponentNameSet (component, pName);
wmbComponentFlagsSet (component, 0);
wmbComponentDeregSet (component, pfDeregister);
wmbComponentPoolSet (component, wmbBackplanePoolGet(backplane));
DEBUG_MSG_2("component: 0x%x pool: 0x%x\n",
component, wmbComponentPoolGet(component));
#ifdef __WM_EVENT_MANAGER__
if (isLocal)
wmbComponentListenerStart(component);
#endif
if (NULL != pComponent)
*pComponent = component;
return OK;
}
/**************************************************************************
*
* wmbComponentBackplaneGet - Return backplane ID of a component.
*
* RETURNS: Component ID
*
*/
WMB_ID_T wmbComponentBackplaneGet
(
WMB_CID_T cid /* [in] Component ID */
)
{
if (wmbComponentBad(cid))
return NULL;
return wmbComponent(cid)->backplane;
}
/**************************************************************************
*
* wmbComponentListener - Management component listener.
*
* This routine initailizes the management component <pComponent> as an
* event consumer (listener). !rws
*
* RETURNS: n/a
*
* NOMANUAL
*/
void wmbComponentListener
(
WMB_CID_T component /*[in] management component pointer*/
)
{
OS_MSGQ_T qid;
MSG_IPC_T ipc;
long received;
sbyte * pName;
/* make sure component is still valid */
if (wmbComponentBad(component))
return;
if (0 == (qid = wmbComponentQidGet(component)))
{
DEBUG_MSG_0 ("No queue open for component listener!\n");
return;
}
pName = wmbComponentNameGet(component);
while (TRUE)
{
#ifndef _WRS_CONFIG_LP64
if (OK != wmosQueueReceive (qid, (sbyte *) &ipc, sizeof(ipc),
WAIT_FOREVER_K, (sbyte4 *)&received))
#else
if (OK != wmosQueueReceive (qid, (sbyte *) &ipc, sizeof(ipc),
WAIT_FOREVER_K, (sbyte8 *)&received))
#endif
{
DEBUG_MSG_0 ("wmbComponentListener: error \n");
break;
}
if (wmbQuit(&ipc, received))
break;
DEBUG_MSG_2 ("wmbComponentListener: %s received %d bytes\n",
pName, received);
if (OK == wmbRequest(component, (sbyte *) &ipc, (sbyte4)received))
continue;
if (ERROR_GENERAL_QUIT == wmErrNo())
break;
}
wmosQueueDelete (qid);
wmTaskEnd();
}
#ifdef __WM_DEBUG__
/**************************************************************************
*
* wmbComponentShow - Show registered components.
*
* This routine shows all management components registered with the
* backplane instance <pSession>.
*
* RETURNS: n/a
*
* NOMANUAL
*/
void wmbComponentShow
(
WMB_SESSION_T * pSession /* backplane instance (session) pointer */
)
{
WMB_ID_T backplane;
WMB_COMPONENT_T * * pComponent;
/*
WM_BLOCK_T * pBlock;
*/
sbyte4 index;
sbyte4 count;
backplane = wmbBackplaneGet();
/*
pBlock = wmbBackplaneComponentsGet(backplane);
pComponent = pBlock->pData;
count = pBlock->count;
*/
pComponent = wmbBackplaneComponentsGet(backplane);
count = wmbBackplaneComponentCountGet(backplane);
for (index = 0; index < count; index++)
{
printf("Component: %s\r\n", pComponent[index]->name);
}
}
#endif
/**************************************************************************
*
* wmbComponentLookup - Find component by name.
*
* This routine returns the component registered with current backplane
*
* RETURNS: OK or ERROR if not found
*
* NOMANUAL
*/
WMB_CID_T wmbComponentLookup
(
sbyte * pName /* [in] component name */
)
{
WMB_ID_T backplane;
WMB_CID_T component;
WMB_COMPONENT_T * * ppList;
sbyte4 index;
sbyte4 count;
sbyte * pComponentName;
DEBUG_MSG_1("wmbComponentLookup: looking for : %s\n", pName);
backplane = wmbBackplaneGet();
ppList = wmbBackplaneComponentsGet(backplane);
count = wmbBackplaneComponentCountGet(backplane);
for (index = 0; index < count; index++)
{
component = ppList[index];
DEBUG_MSG_1("wmbComponentLookup: component: 0x%x?\n", component);
if (wmbComponentBad(component))
continue;
if (NULL == (pComponentName = wmbComponentNameGet(component)))
continue;
DEBUG_MSG_1("wmbComponentLookup: is it: %s?\n", pComponentName);
if (0 != STRCMP(pName, pComponentName))
continue;
DEBUG_MSG_1("wmbComponentLookup: FOUND: %s!\n", pComponentName);
return component;
}
/* don't set error -- this may just be a query for existance */
DEBUG_MSG_1("wmbComponentLookup: BUMMER! missing : %s\n", pName);
return NULL;
}
/**************************************************************************
*
* wmbComponentRemote - Find component by name in default backplnae
*
* !!! right now REMOTE == DOMAINS -- need to add socket support !!!!
*
* RETURNS: OK or ERROR if not found
*
* NOMANUAL
*
*/
STATUS wmbComponentRemote
(
WMB_CID_T component, /* [in] Component ID */
OS_MSGQ_T queue /* [in] Queue to use */
)
{
wmbComponentQidSet(component, queue);
SET_FLAG(wmbComponent(component), FLAG_COMPONENT_REMOTE_K);
return OK;
}
/**************************************************************************
*
* wmbComponentLocal - component member of local backplnae
*
*
* !!! right now REMOTE == DOMAINS -- need to add socket support !!!!
*
*
* RETURNS: OK or ERROR if not found
*
* NOMANUAL
*/
BOOL wmbComponentLocal
(
WMB_CID_T component /* [in] Component ID */
)
{
return FLAG_SET(wmbComponent(component), FLAG_COMPONENT_DOMAIN_K);
}
/**************************************************************************
*
* wmbComponentSend - send data to remote component
*
* RETURNS: OK or ERROR if not found
*
* NOMANUAL
*/
STATUS wmbComponentSend
(
WMB_CID_T component, /* [in] Component ID */
void * pData, /* [in] Data to send */
size_t length /* [in] Data length */
)
{
OS_MSGQ_T qid;
if (wmbComponentBad(component))
return wmError(ERROR_GENERAL_INVALID, "wmbComponentSend: invalid component");
if (NULL == pData || 1 > length)
return wmError(ERROR_GENERAL_NO_DATA, "wmbComponentSend: no data");
if (0 == (qid = wmbComponentQidGet(component)))
return OK;
/*
return wmError(ERROR, "wmbComponentSend: no message queue");
*/
return wmosQueueSend(qid, pData, length, 0, 0);
}
void wmbComponentPoolSet
(
WMB_CID_T component,
WMB_POOL_T * pPool
)
{
if (wmbComponentBad(component))
return;
wmbComponent(component)->pPooled = pPool;
}
#if defined __WMB_VIEW_ACCESS_MODEL__
/**************************************************************************
*
* wmbComponentViewLoad - Load the views to the backplane.
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbComponentViewLoad
(
WMB_CID_T component, /* [in] Component */
WMB_VACM_VIEW_ENTRY_T * pEntry, /* [in] Pointer to the start of Entry array */
ubyte2 numEntries /* [in] Number of entries to register */
)
{
WMB_VIEW_DB_T * pViewDB;
if (wmbComponentBad(component))
return wmError(ERROR_GENERAL_NOT_FOUND, "wmbComponentViewLoad");
if (! wmNew(pViewDB))
return wmError(ERROR_MEMMGR_NO_MEMORY, "wmbComponentViewLoad");
pViewDB->numViews = numEntries;
pViewDB->pComponent = component;
pViewDB->pEntry = pEntry;
return wmbBackplaneViewAdd(wmbComponentBackplaneGet(component), pViewDB);
}
/**************************************************************************
*
* wmbComponentViewDelete - Delete the view for the component.
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbComponentViewDelete
(
WMB_CID_T component /* [in] Component */
)
{
WMB_VIEW_DB_T *pViewDB;
if (wmbComponentBad(component))
return wmError(ERROR_GENERAL_NOT_FOUND, "wmbComponentViewLoad");
pViewDB = wmbBackplaneViewDBGet(wmbComponentBackplaneGet(component));
while (NULL != pViewDB)
{
if (component == pViewDB->pComponent)
break;
pViewDB = pViewDB->pNext;
}
if (NULL != pViewDB)
{
wmbBackplaneViewDelete(wmbComponentBackplaneGet(component), pViewDB);
wmFree(pViewDB);
}
return OK;
}
#endif /* __WMB_VIEW_ACCESS_MODEL__ */
/* eof wmbComponentLib.c */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,505 @@
/* wmbDataLib.c - Backplane data access library */
/* Copyright 2004-2007,2010 Wind River Systems, Inc. */
/*
modification history
--------------------
01g,17dec10,m_z part of APIs changed
CQID: Fix WIND00247096
01f,29Mar10,shi VxWorks 64-bit support (WIND00193649)
01e 14jul04,gsr fix for null terminator SPR 99265
01d 14may04,dlr Update comments: instances are always in string form
01c 11feb04,dlr Added wmbDataNativeGetNext and wmbDataStringGetNext
01b 18sep02,pns break set out into test/commit
01a,01aug02,pns created
*/
/*
DESCRIPTION
This module contains interface routines for the backplane.
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#include "wm.h"
#include "wmb.h"
/* defines */
/* typedefs */
/* globals */
extern WMB_SESSION_T * gpTrustedSession;
/* locals */
/**************************************************************************
*
* wmbDataType - get windmark datatype
*
* <pType> will be the native data type of the object named <pName>
*
* RETURNS:
* \is
*
* \i OK
* Data successfully retrieved
*
* \i ERROR
* Windmark doesn't exist
* \ie
*/
STATUS wmbDataType
(
sbyte * pName,
DATATYPE_T * pType
)
{
WMB_OBJECT_T object;
if (OK != wmbObjectInit (&object, NULL, pName, NULL, 0, FALSE))
return ERROR;
if (OK != wmbObjectResolve(&object))
{
#ifdef __ENABLE_IPC__
if (ERROR_GENERAL_NOT_LOCAL != wmErrNo())
{
wmbObjectDelete(&object);
return ERROR;
}
if (OK != wmbObjectResolveRemote (&object))
{
wmbObjectDelete(&object);
return ERROR;
}
#else
return ERROR;
#endif
}
if (NULL != pType)
*pType = wmbObjectTypeNativeGet (&object);
/* even a static object can have allocated buffers */
wmbObjectDelete(&object);
return OK;
}
/**************************************************************************
*
* wmbDataNativeGet - get windmark native data
*
* <pValue> will be the native data type of the object
*
* RETURNS:
* \is
*
* \i OK
* Data successfully retrieved
*
* \i ERROR
* WindMark doesn't exist
* \ie
*/
STATUS wmbDataNativeGet
(
WMB_SESSION_T * pSession, /* session pointer */
sbyte * pName, /* WindMark name */
void * pInstance, /* NULL, or instance in string form */
sbyte4 instanceLength, /* Length of instance, including terminator */
void * pBuffer, /* location to copy WindMark's value */
ssize_t bufferLength, /* Maximum size of the dest buffer */
ssize_t * pWritten /* number of value bytes copied */
)
{
return wmbObjectGet(pSession, CMD_GET_K, pName, pInstance, instanceLength,
pBuffer, bufferLength, DATATYPE_INVALID_K, FALSE,(long*)pWritten);
}
/**************************************************************************
*
* wmbDataNativeGetNext - get windmark native data
*
* <pValue> will be the native data type of the object
* <pInstance> will be the instance of the data. The content will be updated.
*
* RETURNS:
* \is
*
* \i OK
* Data successfully retrieved
*
* \i ERROR
* Rapidmark doesn't exist
* \ie
*/
STATUS wmbDataNativeGetNext
(
WMB_SESSION_T * pSession, /* session pointer */
sbyte * pName, /* WindMark name */
void * pInstance, /* NULL, or instance in string form */
sbyte4 * pInstanceLength, /* Length of instance, including terminator */
sbyte4 maxInstanceLength, /* Maximum size of the inst buffer */
DATATYPE_T instanceType, /* Type form of the instance (DATATYPE_STRING_K) */
void * pBuffer, /* location to copy WindMark's value */
ssize_t bufferLength, /* Maximum size of the dest buffer */
ssize_t * pWritten /* number of value bytes copied */
)
{
return wmbObjectGetNext(pSession, pName, pInstance, pInstanceLength, maxInstanceLength,instanceType,
pBuffer, bufferLength, DATATYPE_INVALID_K, FALSE, (long*)pWritten);
}
/**************************************************************************
*
* wmbDataNativeSet - set native value of windmark
*
* <pValue> must be the native data type of the object
*
* RETURNS:
* \is
*
* \i OK
* Data successfully set
*
* \i ERROR
* WindMark doesn't exist
* \ie
*/
STATUS wmbDataNativeSet
(
WMB_SESSION_T * pSession, /* session pointer */
sbyte * pName, /* WindMark name */
void * pInstance, /* NULL, or instance in string form */
sbyte4 instanceLength, /* Length of instance, including terminator */
void * pValue, /* location of new value */
ssize_t valueLength /* number of value bytes to copy */
)
{
return wmbObjectSet (pSession, pName, pInstance,
instanceLength, pValue, valueLength,
DATATYPE_INVALID_K);
}
/**************************************************************************
*
* wmbDataStringGet - get value windmark data as string
*
* <pValue> will be a string copy of the data
*
* RETURNS:
* \is
*
* \i OK
* Data successfully retrieved
*
* \i ERROR
* WindMark doesn't exist
* \ie
*/
STATUS wmbDataStringGet
(
WMB_SESSION_T * pSession, /* session pointer */
sbyte * pName, /* WindMark name */
void * pInstance, /* NULL, or instance in string form */
sbyte4 instanceLength, /* Length of instance, including terminator */
sbyte * pBuffer, /* location to copy WindMark's value */
ssize_t bufferLength, /* Maximum size of the dest buffer */
ssize_t * pWritten /* number of value bytes copied */
)
{
return wmbObjectGet(pSession, CMD_GET_K, pName, pInstance, instanceLength,
pBuffer, bufferLength, DATATYPE_STRING_K, FALSE, (long*)pWritten);
}
/**************************************************************************
*
* wmbDataStringGetNext - get value windmark data as string
*
* <pValue> will be a string copy of the data
* <pInstance> will be the instance of the data. The content will be updated.
*
* RETURNS:
* \is
*
* \i OK
* Data successfully retrieved
*
* \i ERROR
* WindMark doesn't exist
* \ie
*/
STATUS wmbDataStringGetNext
(
WMB_SESSION_T * pSession, /* session pointer */
sbyte * pName, /* WindMark name */
void * pInstance, /* NULL, or instance in string form */
sbyte4 * pInstanceLength, /* Length of instance, including terminator */
sbyte4 maxInstanceLength, /* Maximum size of the inst buffer */
DATATYPE_T instanceType, /* Type form of the instance (DATATYPE_STRING_K) */
sbyte * pBuffer, /* location to copy WindMark's value */
ssize_t bufferLength, /* Maximum size of the dest buffer */
ssize_t * pWritten /* number of value bytes copied */
)
{
return wmbObjectGetNext(pSession, pName, pInstance, pInstanceLength, maxInstanceLength,instanceType,
pBuffer, bufferLength, DATATYPE_STRING_K, FALSE, (long*)pWritten);
}
/**************************************************************************
*
* wmbDataStringSet - set value of windmark
*
* <pValue> must be a string, and will be saved as native data type of the object
*
* RETURNS:
* \is
*
* \i OK
* Data successfully set
*
* \i ERROR
* WindMark doesn't exist
* \ie
*/
STATUS wmbDataStringSet
(
WMB_SESSION_T * pSession, /* session pointer */
sbyte * pName, /* WindMark name */
void * pInstance, /* NULL, or instance in string form */
sbyte4 instanceLength, /* Length of instance, including terminator */
sbyte * pValue, /* location of new value */
ssize_t valueLength /* number of value bytes to copy */
)
{
if (valueLength == (long)STRLEN(pValue))
{
valueLength = (long)STRLEN(pValue) + 1; /*adjust for the null termination */
#ifdef __WM_DEBUG__
printf("\nwmbDataStringSet()- buffer size too small, size corrected!!\n");
#endif
}
return wmbObjectSet (pSession, pName, pInstance,
instanceLength, pValue, valueLength,
DATATYPE_STRING_K);
}
/**************************************************************************
*
* wmbDataTrustedGet - direct data retrieval function - Deprecated
*
* RETURNS:
* \is
*
* \i OK
* Data successfully retrieved
*
* \i ERROR
* WindMark doesn't exist
* \ie
* NOMANUAL
*/
STATUS wmbDataTrustedGet
(
sbyte * pName,
void * pInstance,
sbyte4 instanceLength,
void * pBuffer,
ssize_t bufferLength
)
{
return wmbObjectGet(gpTrustedSession, CMD_GET_K, pName, pInstance, instanceLength,
pBuffer, bufferLength, DATATYPE_INVALID_K, FALSE, NULL);
}
/**************************************************************************
*
* wmbDataTrustedSet - trusted data set function - Deprecated
*
* RETURNS:
* \is
*
* \i OK
* Data successfully set
*
* \i ERROR
* WindMark doesn't exist
* \ie
* NOMANUAL
*/
STATUS wmbDataTrustedSet
(
sbyte * pName,
void * pInstance,
sbyte4 instanceLength,
void * pValue,
ssize_t valueLength
)
{
return wmbObjectSet (gpTrustedSession, pName, pInstance,
instanceLength, pValue, valueLength,
DATATYPE_INVALID_K);
}
/**************************************************************************
*
* wmbDataTrustedGetNext - legacy get next function - Deprecated
*
* RETURNS:
* \is
*
* \i OK
* Next element successfully retrieved
*
* \i ERROR
* WindMark doesn't exist
* \ie
* NOMANUAL
*/
STATUS wmbDataTrustedGetNext
(
sbyte * pName,
void * pInstance,
sbyte4 * pInstanceLength,
sbyte4 maxInstanceLength,
DATATYPE_T instanceType,
void * pBuffer,
ssize_t bufferLength,
ssize_t * pWritten
)
{
return wmbObjectGetNext(gpTrustedSession, pName, pInstance, pInstanceLength, maxInstanceLength,instanceType,
pBuffer, bufferLength, DATATYPE_INVALID_K, FALSE, (long*)pWritten);
}
/**************************************************************************
*
* wmbDataTrustedNvmSet - save to non-volatile memory - Deprecated
*
* RETURNS:
* \is
*
* \i OK
* Data saved successfully
*
* \i ERROR
* WindMark doesn't exist
* \ie
* NOMANUAL
*/
STATUS wmbDataTrustedNvmSet
(
sbyte * pName,
void * pInstance,
sbyte4 instanceLength,
void * pValue,
ssize_t valueLength
)
{
return OK;
}
/**************************************************************************
*
* wmbDataExists - does a valid WindMark exist with this name?
*
* RETURNS: TRUE if found, otherwise FALSE
*
*/
BOOL wmbDataExists
(
WMB_SESSION_T * pSession, /* current session, or NULL */
sbyte * pName /* name of windmark to verify */
)
{
WMB_DB_T * pDB;
DB_ENTRY_T * pEntry;
BOOL absolute;
WMB_ID_T rid;
void * pID;
rid = wmbSessionBackplaneGet(pSession);
if (wmbBackplaneBad(rid))
rid = wmbBackplaneGet();
if (wmbSessionBad(pSession))
pSession = (WMB_SESSION_T *) wmbBackplaneSessionGet(rid);
absolute = FALSE;
pDB = NULL;
pEntry = NULL;
pID = NULL;
switch (*pName)
{
case WMB_DELIM_K:
absolute = TRUE;
pName++;
break;
case WMB_LOCAL_PREFIX_K:
pName++;
pID = pSession;
break;
default:
break;
}
if (NULL == (pDB = (wmbBackplaneDBGet(rid))))
{
wmError (ERROR_DB_NO_DATABASE, "no backplane db");
return (FALSE);
}
if (NULL != wmbDBEntryGet(pDB, pName, pID, (NULL != pID)))
{
return (TRUE);
}
else
{
wmError (ERROR_GENERAL_OBJECT_NOT_FOUND, "object not found");
return (FALSE);
}
}
@@ -0,0 +1,172 @@
/* wmbEventLib.c - event manager interface for WMB */
/* Copyright 2002-2010 Wind River Systems, Inc. */
/*
modification history
--------------------
01d,01apr10,f_f VxWorks 64bit support (WIND00193649)
01c,12may04,jws __WM_EVENT_MANAGER__ ifdef put back in because it is needed
for non-library builds
01b,20jan04,jws __WM_EVENT_MANAGER__ ifdef removed
01a,15aug02,bk written
*/
/*
DESCRIPTION
This module implements event processing for the WM backplane
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#include "wrn/wm/common/wm.h"
#include "wrn/wm/backplane/wmb.h"
/*
* __WM_EVENT_MANAGER__ is defined if this file is part of an archive.
* If not, wm_options.h either def's or undef's it.
*/
#if defined(__WM_EVENT_MANAGER__)
#include "wrn/em/emLib.h"
#include "wrn/em/emEventEngineLib.h"
/* Local types */
/* WMB_EVENT_DESCR_T describes the event names and identifiers */
typedef struct WMB_EVENT_DESCR_S
{
sbyte *name; /* registered name */
uint32_t evId; /* Assigend ID */
}WMB_EVENT_DESCR_T;
/* Local variables */
EM_CONFIG_DATA emConfig;
EM_ID eventManagerId;
EM_PRODUCER_CONTEXT producerContext;
WMB_EVENT_DESCR_T wmbEventList[WMB_MAX_EVENT_TYPES_K] ={
{WMB_EVENT_TYPE_CONTROL_NAME_K, 0},
{WMB_EVENT_TYPE_PORTFOLIO_NAME_K, 0}
};
/**************************************************************************
*
* wmbEventManagerStart - Start the Event Manager.
*
* RETURNS: STATUS
*
* NOMANUAL
*/
STATUS wmbEventManagerStart
(
void
)
{
STATUS rc;
int i;
int maxNumEventTypes = WMB_MAX_EVENT_TYPES_K;
int maxEventPayloadSize = sizeof(WMB_EVENT_T);
int maxListenersPerEvent = 128;
int maxProducersPerEvent = WMB_MAX_PRODUCERS_K;
int maxNumListeners = 128;
int maxNumProducers = WMB_MAX_PRODUCERS_K;
if (wmbBackplaneBad(wmbBackplaneGet()))
return ERROR;
/* Initiate the Event Engine (creates a task accepting events via a message queue */
/* emEventEngineLibInit(); */
rc = emEventManagerConfigInit(
&emConfig, /* Returned event manager config */
WMB_EM_NAME_K, /* Event Manager Name */
maxNumEventTypes,
maxEventPayloadSize,
maxListenersPerEvent,
maxProducersPerEvent,
maxNumListeners,
maxNumProducers,
95,
NONE
);
/* Resetting of default parms and creating the Event Manager */
emConfig.maxBacklogSubmittedEvents = 48;
emConfig.strictChecking = TRUE;
if (OK == rc)
{
eventManagerId = emEventManagerCreate(&emConfig);
if (NULL == eventManagerId)
rc = ERROR;
else
{
rc = emProducerRegister(wmbBackplaneNameGet(wmbBackplaneGet()), WMB_EM_NAME_K, &producerContext);
if (OK != rc)
emEventManagerDestroy(eventManagerId);
else
{
for (i = 0; i < WMB_MAX_EVENT_TYPES_K; i++)
emProducerEventRegister(&producerContext, wmbEventList[i].name, &(wmbEventList[i].evId));
}
}
}
return rc;
}
/**************************************************************************
*
* wmbEventManagerStop - Stop the Event Manager.
*
* RETURNS: STATUS
*
* NOMANUAL
*/
STATUS wmbEventManagerStop
(
void
)
{
emProducerUnregister(&producerContext);
emEventManagerDestroy(eventManagerId);
return OK;
}
/**************************************************************************
*
* wmbEventSubmit - Send an event.
*
* RETURNS: none
*
* NOMANUAL
*/
void wmbEventSubmit
(
WMB_CID_T producer, /* [in] Event Producer */
WMB_EVENT_TYPE_T eventType, /* [in] WMB event type */
ubyte4 eventId, /* [in] Internal ID */
WMB_EVENT_SEVERITY_T severity, /* [in] Event severity */
ubyte4 infoSize, /* [in] Event info size */
ubyte4 *eventInfo /* [in] Pointer to the additional info */
)
{
WMB_EM_EVENT_T emEvent;
if (eventType >= WMB_MAX_EVENT_TYPES_K)
return;
emEvent.wmbEvent.producer = producer;
emEvent.wmbEvent.eventTime = (ubyte4)wmosTimeGet();
emEvent.wmbEvent.eventType = eventType;
emEvent.wmbEvent.eventID = eventId;
emEvent.wmbEvent.eventSeverity = severity;
MEMCPY(emEvent.wmbEvent.eventInfo, eventInfo, min(infoSize, sizeof(ubyte4)*4));
emEvent.emEvent.payloadSize = sizeof(WMB_EVENT_T);
emEvent.emEvent.eventTypeId = wmbEventList[eventType].evId;
emEventSubmitAsync (&producerContext, (EM_EVENT_DATA*)&emEvent, 0);
}
#endif
@@ -0,0 +1,848 @@
/* wmbLib.c - Backplane library */
/* Copyright (c) 2002-2010, 2012-2013 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
--------------------
01l,21feb13,r_w fix coverity issue(defect WIND0040409, WIND00411995)
01k,31jan13,r_w disable portfolio feature
01j,20jul12,r_w eliminate memory leak issue. defect WIND00359749
01i,09jul10,m_z remove compile warning
01h,01apr10,f_f VxWorks 64bit support (WIND00193649)
01g,07sep09,m_z eliminate unused parameter for parameter custom validator
(WIN00174035)
01f,24feb07,msa Correct the apigen comments so they match the actual
routines.
01e,01jun05,gsr LogMgrInit routine to create semaphores for Lock Manager
SPR#109131
01d,21jan04,jws remove Event Manager ifdef's
01c,23sep03,jws fix compiler warnings, SPR 90282
01b,06feb03,jws fix resource leaks SPR 85762
01a,13mar01,pns written
*/
/*
DESCRIPTION
This module contains interface routines for the backplane.
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#include "wm.h"
#include "wmb.h"
#include "wmbSystem.h"
#include <string.h>
#include <ctype.h>
#include <signal.h>
STATUS wmmHandler (WMB_TID_T tid, WMB_OBJ_T obj, COMMAND_T command);
STATUS wmbObjectExecLookup ( sbyte * pName, COMMAND_T * pCommand);
#if 0
STATUS wmbCmd
(
WMB_CMD_T cmd, void * pInput,
sbyte4 inputSize,
sbyte * pBuffer,
long bufSize,
sbyte4 * pLength
);
#endif
STATUS wmbAction
(
WMB_ID_T backplane, /* requestee */
sbyte * pRequestor, /* requestor's name */
ubyte4 domain, /* requestor's domain */
ubyte4 address, /* reply ip address */
ubyte4 port, /* reply port */
ubyte4 command, /* action to perform */
sbyte * pData
);
void wmbIpcDone ( MSG_IPC_T * pIpc);
/* defines */
#define RM_CHAR_LEFT_0 kMagicMarkupStartChar0
#define RM_CHAR_LEFT_1 kMagicMarkupStartChar1
#define RM_CHAR_RIGHT_0 kMagicMarkupEndChar0
#define RM_CHAR_RIGHT_1 kMagicMarkupEndChar1
#undef WMB_BACKPLANE_MEMORY_K
#define WMB_BACKPLANE_MEMORY_K 0
/* typedefs */
enum RM_K
{
RM_INVALID_K,
RM_BEGIN_K,
RM_START_K,
RM_MID_K,
RM_END_K,
RM_FINAL_K
};
/* globals */
WMB_SESSION_T * gpTrustedSession = NULL;
/* locals */
LOCAL WMB_CMD_PAIR_T gCmdPairs[WMB_MAX_CMD_NAMES_K] =
{
{CMD_INVALID_K, "Invalid"},
{CMD_GET_K, "GET"},
{CMD_SET_K, "SET"},
{CMD_GET_NEXT_K, "NEXT"},
{CMD_COMMIT_K, "COMMIT"},
{CMD_UNDO_K, "UNDO"}
};
LOCAL ubyte4 gCmdPairCount = ARRAY_SIZE(gCmdPairs);
/* externals - will be moved to header file */
IMPORT STATUS (*pWmbEventManagerStart)(void);
IMPORT void (*pWmbEventSubmit)(WMB_CID_T,WMB_EVENT_TYPE_T,ubyte4,
WMB_EVENT_SEVERITY_T,
ubyte4,ubyte4 *);
IMPORT STATUS (*pWmbEventManagerStop)(void);
#ifdef __ENABLE_SHARED_MEMORY__
/**************************************************************************
*
* wmbSharedPool - get shared memory pool for current backplane
*
* RETURNS: OK, or ERROR if message send failed
*
* NOMANUAL
*/
MEM_POOL_ID wmbSharedPool
(
void
)
{
WMB_ID_T backplane;
OS_MEM_SHARE_T * pMemory;
if (NULL == (backplane = wmbBackplaneGet()))
return NULL;
pMemory = wmbBackplaneSharedGet(backplane);
return pMemory->pool;
}
#endif
/**************************************************************************
*
* wmbObjectExecLookup - find a command by name
*
* RETURNS: OK, or ERROR if initialization failed
*/
STATUS wmbObjectExecLookup
(
sbyte * pName,
COMMAND_T * pCommand
)
{
ubyte4 index;
WMB_CMD_PAIR_T * pPair;
pPair = &gCmdPairs[1];
for (index = 1; index < gCmdPairCount; index++, pPair++)
{
if (0 != strcmp (pName, pPair->name))
continue;
*pCommand = pPair->cmd;
return OK;
}
*pCommand = CMD_INVALID_K;
return wmError(ERROR_GENERAL_BAD_NAME, "invalid command name");
}
/**************************************************************************
*
* wmbCidByName - find CID (Component ID) of a component by name
*
* RETURNS: OK, or ERROR if initialization failed
*
* NOMANUAL
*/
STATUS wmbCidByName
(
sbyte * pBackplane,
sbyte * pNameOfInterest,
WMB_CID_T * pCid
)
{
return OK;
}
/**************************************************************************
*
* wmosThreadCreate - spawn a new thread
*
* RETURNS: OK, or ERROR_GENERAL if thread creation failed
*
* NOMANUAL
*/
STATUS wmbExec
(
VOIDFUNCPTR pHandlerFcn, /* Function to run in thread */
sbyte * pTaskName, /* Thread name */
void * pArg, /* Argument to thread function */
sbyte4 priority, /* Priority for thread to run */
size_t stackSize, /* not used */
OS_THREAD_T * pTid /* Returned thread ID */
)
{
#ifdef __DEBUG_SINGLE_THREAD__
pHandlerFcn(pArg);
return OK;
#else
return wmosThreadCreate (pHandlerFcn, pTaskName, pArg, priority,
stackSize, pTid);
#endif
}
#ifdef __POSIX_OS__
void wmbSignalHandler
(
int sig
)
{
DEBUG_MSG_1("signal received: 0x%x\n", sig);
}
#endif /* posix */
/**************************************************************************
*
* wmbStop - release global backplane resources
*
* RETURNS: OK, or ERROR if stop failed
*/
STATUS wmbStop
(
sbyte * pName
)
{
#if 0 /* disable portfolio feature */
wmbPortfolioStop();
#endif
wmbComponentStop(wmbBackplaneGet());
wmbTransactionStop();
wmbBackplaneClose(pName);
if (pWmbEventManagerStop) pWmbEventManagerStop();
wmbSessionDestroy(gpTrustedSession);
wmbSessionStop();
wmbBackplaneStop();
wmbLockMgrStop();
wmStop();
return OK;
}
/**************************************************************************
*
* wmbStart - main entry point for the Wind River CLI, Web, MIBway system
*
* Starts up a backplane and associated managers
*
* RETURNS: OK, or ERROR if initialization failed
*/
STATUS wmbStart
(
sbyte * pName, /* backplane name */
sbyte4 defaultComponents, /* number of components per block */
sbyte4 dbSize, /* default database size */
sbyte4 tableSize, /* default table size */
WMBFUNCPTR fnDereg,
void * pCookie,
DTTypeInfo * pAccessInfo
)
{
WMB_ID_T backplane;
WMB_CID_T component;
STATUS status;
if (OK != wmStart())
return ERROR;
if (OK != wmbBackplaneStart())
return ERROR;
if (OK != wmbSessionStart())
return ERROR;
if (OK != wmbTransactionStart())
{
wmbSessionStop();
wmbBackplaneStop();
return ERROR;
}
if (OK != wmbComponentStart (defaultComponents))
{
wmbTransactionStop();
wmbSessionStop();
wmbBackplaneStop();
return ERROR;
}
#if 0 /* disable portfolio feature */
if (OK != wmbPortfolioStart())
{
wmbComponentStop(wmbBackplaneGet());
wmbSessionStop();
wmbTransactionStop();
wmbBackplaneStop();
return ERROR;
}
#endif
DEBUG_MSG_1("creating backplane: %s\n", pName);
if (OK != (status = wmbBackplaneCreate (pName, 2000000 /* WMB_BACKPLANE_MEMORY_K */,
dbSize, tableSize, pAccessInfo, &backplane)))
{
#if 0 /* disable portfolio feature */
wmbPortfolioStop();
#endif
wmbComponentStop(wmbBackplaneGet());
wmbSessionStop();
wmbTransactionStop();
wmbBackplaneClose(pName);
wmbBackplaneStop();
return ERROR;
}
if (pWmbEventManagerStart != NULL && OK != pWmbEventManagerStart())
{
wmbStop(pName);
return ERROR;
}
/* load "built-in" names */
DEBUG_MSG_0("load wmb system data\n");
if (OK != wmbSystemLoad(pName))
{
wmbStop(pName);
return ERROR;
}
wmbLockMgrInit();
#ifdef __SNMP_API_ENABLED__
DEBUG_MSG_0("Mibway startup\n");
wmmMain(pName);
#endif
/* create a default "all powerful" session for trusted access */
if (OK != wmbBackplaneComponentGet(backplane, &component))
{
wmbStop(pName);
return ERROR;
}
if (OK != wmbSessionCreate (component, 0, 0, &gpTrustedSession))
{
wmbStop(pName);
return ERROR;
}
SET_FLAG(gpTrustedSession, FLAG_SESSION_ALL_ACCESS);
if (pWmbEventSubmit)
pWmbEventSubmit (component, WMB_EVENT_TYPE_CONTROL,
WMB_BACKPLANE_CREATED_EVENT, WMB_EVENT_SEV_INFO,
(ubyte4)(STRLEN(pName)+1), (ubyte4*)pName);
DEBUG_MSG_0("WMB start successful\n");
return OK;
}
#ifdef __WM_DEBUG__
void wmbDumpSizes
(
void
)
{
/*
printf("Structure Size\n");
printf("--------- ----\n");
printf("WMB_BACKPLANE_T %5d\n", sizeof(WMB_BACKPLANE_T));
printf("WMB_SESSION_T %5d\n", sizeof(WMB_SESSION_T));
printf("WMB_TRANSACTION_T %5d\n", sizeof(WMB_TRANSACTION_T));
printf("WMB_OBJECT_T %5d\n", sizeof(WMB_OBJECT_T));
printf("WMB_EVENT_T %5d\n", sizeof(WMB_EVENT_T));
*/
}
#endif
#if 0
/**************************************************************************
*
* wmbCmd - execute a singular backplane command
*
* RETURNS:
* \is
*
* \i OK
* Command executed successfully
*
* \i ERROR
* Invalid command
* \ie
*
* NOMANUAL
*/
STATUS wmbCmd
(
WMB_CMD_T cmd,
void * pInput,
sbyte4 inputSize,
sbyte * pBuffer,
long bufSize,
sbyte4 * pLength
)
{
ubyte4 msgCmd;
sbyte * pInstance;
COMMAND_T command;
sbyte * pWindMark;
sbyte * pValue;
ubyte4 rmSize;
sbyte4 iSize;
if (NULL == pInput)
return wmError(ERROR_GENERAL_NO_DATA, "null input");
if (wmbQuit(pInput, inputSize))
return wmError(ERROR_GENERAL_QUIT, "wmbRequest: QUIT requested");
*pLength = 0;
/* check for msg header type */
msgCmd = *((unsigned int *) pInput);
if (' ' <= msgCmd)
msgCmd = 0;
if (0 < msgCmd)
return wmbRequest (NULL, pInput, inputSize);
/* must be valid text message */
if (! isprint((int) *((sbyte *) pInput)))
return wmError (ERROR, "not valid text message");
/* separate command from data */
pWindMark = strstr(pInput, " ");
if (NULL != pWindMark)
{
*pWindMark = 0;
pWindMark++;
}
if (OK != wmbObjectExecLookup(pInput, &command))
return ERROR;
pInstance = strstr(pWindMark, ".");
if (NULL != pInstance)
*(pInstance++) = 0;
pValue = pInstance;
pValue = (NULL != pInstance) ? (sbyte *) pInstance : pWindMark;
pValue = strstr(pValue, " ");
if (NULL != pValue)
*(pValue++) = 0;
rmSize = (ubyte4)STRLEN(pWindMark);
iSize = (NULL == pInstance) ? 0 : (sbyte4)STRLEN(pInstance);
switch (command)
{
case CMD_GET_K:
wmbDataTrustedGet(pWindMark, pInstance, iSize, pBuffer, bufSize);
break;
case CMD_SET_K:
if (NULL != pValue)
{
strncpy(pBuffer, pValue, (size_t)bufSize);
wmbDataTrustedSet(pWindMark, NULL, iSize, pBuffer, bufSize);
}
break;
default:
break;
}
*pLength = (sbyte4)STRLEN(pBuffer);
return OK;
}
#endif
/**************************************************************************
*
* wmbAction - act on a command
*
* For IPC requests
*
* RETURNS: N/A
*
* NOMANUAL
*/
STATUS wmbAction
(
WMB_ID_T backplane, /* requestee */
sbyte * pRequestor, /* requestor's name */
ubyte4 domain, /* requestor's domain */
ubyte4 address, /* reply ip address */
ubyte4 port, /* reply port */
ubyte4 command, /* action to perform */
sbyte * pData
)
{
/*
WMB_CID_T component;
switch (command)
{
case WMB_MSG_REGISTER_K:
case WMB_MSG_DEREGISTER_K:
case WMB_MSG_SHUTDOWN_K:
break;
case WMB_MSG_JOIN_K:
wmbComponentRegister (wmbBackplaneNameGet(backplane), pRequestor,
0, NULL, NULL, &component);
wmbComponentQidSet (component, pData);
break;
default:
return ERROR;
}
*/
return OK;
}
typedef struct WM_HEAD_T
{
ubyte4 type;
char data;
}
WM_HEAD_T;
#ifndef WM_PIPESIZE_K
#define WM_PIPESIZE_K 128
#endif
void wmbIpcDone
(
MSG_IPC_T * pIpc
)
{
if (NULL == pIpc)
return;
DEBUG_MSG_1("IPC done. Sem: %d\n", pIpc->sem);
wmosSemGive(pIpc->sem);
wmosSemGive(pIpc->sem);
wmosSemGive(pIpc->sem);
}
STATUS wmbRequest
(
WMB_CID_T component,
sbyte * pMessage,
sbyte4 msgSize
)
{
/*WMB_ID_T backplane;*/
WM_HEAD_T * pHead;
#ifdef __ENABLE_IPC__
WMB_REG_T * pReg;
OS_MSGQ_T qid;
sbyte * pName;
MSG_IPC_T * pIpc;
#endif
if (NULL == pMessage || 1 > msgSize)
return wmError(ERROR_GENERAL_NO_DATA, "wmbRequest: invalid request");
/*backplane = wmbBackplaneGet();*/
pHead = (WM_HEAD_T *) pMessage;
#ifdef __ENABLE_IPC__
pIpc = (MSG_IPC_T *) pMessage;
#endif
switch (pHead->type)
{
#ifdef __ENABLE_IPC__
case WMB_MSG_REGISTER_K:
pReg = (WMB_REG_T *) pMessage;
pName = pReg->name;
qid = pReg->qid;
DEBUG_MSG_2("wmbRequest: registering component: %s, qid: %d\n", pName, qid);
wmbComponentRegister(pName, pName, NULL, NULL, (void *) qid, &component);
/* give child backplane shared memory, ipc info, etc */
wmbBackplaneShareSend(qid);
break;
case WMB_MSG_COMMAND_K:
wmbObjectExecFar(component, pIpc);
wmbIpcDone(pIpc);
break;
case WMB_MSG_SHARE_K:
DEBUG_MSG_0("wmbRequest: sharing!\n");
wmbBackplaneShareSet (pMessage, msgSize);
break;
case WMB_MSG_RESOLVE_K:
DEBUG_MSG_0("wmbRequest: resolve remote object\n");
return wmbObjectResolveFar (component, pMessage, msgSize);
case WMB_MSG_FOUND_K:
DEBUG_MSG_0("wmbRequest: return from remote resolve\n");
return wmbObjectFound (component, pMessage, msgSize);
case WMB_MSG_EXEC_K:
return wmbObjectGoFar (component, pMessage, msgSize);
case WMB_MSG_DONE_K:
return wmbObjectDone (component, pMessage, msgSize);
#endif
case WMB_MSG_EVENT_K:
case WMB_MSG_DEREGISTER_K:
case WMB_MSG_SHUTDOWN_K:
case WMB_MSG_JOIN_K:
break;
default:
DEBUG_MSG_1 ("Bad command number: %d\n", pHead->type);
return wmError(ERROR_TM_NOT_HANDLED, "wmbRequest: not handled");
}
return OK;
}
/**************************************************************************
*
* wmbShareCreate - "alloc" shared memory object
*
* RETURNS: TRUE if found, otherwise FALSE
*
*
* NOMANUAL
*/
STATUS wmbShareCreate
(
WMB_ID_T backplane,
sbyte4 type,
void ** ppData
)
{
WM_BLOCK_T * pBlock;
WMB_BACKPLANE_T * pBackplane;
if (NULL == ppData)
return wmError(ERROR_GENERAL_NULL_POINTER,NULL);
if (wmbBackplaneBad(backplane))
return ERROR;
pBackplane = (WMB_BACKPLANE_T *) backplane;
switch (type)
{
case WMB_SHARE_OBJECT_K:
pBlock = wmbBackplaneObjectsGet(backplane);
break;
case WMB_SHARE_BUFFER_K:
pBlock = wmbBackplaneBuffersGet(backplane);
break;
default:
return wmError(ERROR_GENERAL_INVALID_TYPE,NULL);
}
if (wmMemBlockBad(pBlock))
return wmError(ERROR_GENERAL_NULL_POINTER,NULL);
*ppData = wmMemBlockEntryCreate(pBlock);
memset(*ppData, 0, (size_t)pBlock->size);
return OK;
}
/**************************************************************************
*
* wmbShareFree - "free" shared memory object
*
* RETURNS: TRUE if found, otherwise FALSE
*
*
* NOMANUAL
*/
STATUS wmbShareFree
(
WMB_ID_T backplane,
sbyte4 type,
void * pData
)
{
WM_BLOCK_T * pBlock;
if (wmbBackplaneBad(backplane))
return wmError(ERROR_WMB_BACKPLANE_INVALID, "wmbShareFree: invalid backplane");
switch (type)
{
case WMB_SHARE_OBJECT_K:
pBlock = wmbBackplaneObjectsGet(backplane);
break;
case WMB_SHARE_BUFFER_K:
pBlock = wmbBackplaneBuffersGet(backplane);
break;
case WMB_SHARE_DATA_K:
wmPoolFree(wmbBackplaneDataGet(backplane), pData);
return OK;
default:
return wmError(ERROR_GENERAL_INVALID_TYPE,"wmbShareCreate: invalid type");
}
return wmMemBlockFree(pBlock, pData);
}
/**************************************************************************
*
* wmbValidate - validate session data
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i ERROR_CONVERSION_INCORRECT_TYPE
*\i ERROR_GENERAL_OUT_OF_RANGE
*\i OK
*\ie
*
* NOMANUAL
*/
STATUS wmbValidate
(
WMB_SESSION_T * pEnv,
sbyte * pString,
DTTypeInfo * pTypeInfo,
BOOL errorMsg
)
{
DTTypeInfo tempInfo;
ValidateHandler * pCustomValidator;
if ((NULL == pTypeInfo) || (NULL == pString))
return ERROR_GENERAL_NOT_FOUND;
/* if there is a custom validator, call that instead */
pCustomValidator = (ValidateHandler *) pTypeInfo->pCustomValidate;
if (NULL != pCustomValidator)
{
/* BLock circular loops in case that validator calls this one */
tempInfo = *pTypeInfo;
tempInfo.pCustomValidate = NULL;
return pCustomValidator(pString, &tempInfo);
}
return wmConvertValidate (pString, pTypeInfo, errorMsg);
}
STATUS wmbResourceRegister
(
sbyte * pComponent, /* Component Name */
sbyte * pPath, /* Path name registered under */
WMB_ENTRY_T * pEntries, /* Resource Entry Array */
sbyte4 entryCount, /* Resource Entry Count */
WMB_TABLE_T * pTable, /* Table Entry Array */
sbyte4 tableSize, /* Resource Entry Count */
WMB_HANDLER_T handler /* Default Handler */
)
{
WMB_CID_T component;
component = wmbComponentLookup(pComponent);
if (NULL != pEntries)
{
if (OK != wmbComponentResourceLoad (component, pEntries, entryCount, pPath))
return ERROR;
}
return wmbComponentTableLoad (component, pTable, tableSize, pPath);
}
/* eof wmbLib.c */
@@ -0,0 +1,595 @@
/* wmbLockMgrCore.c - Lock Manager core functions */
/* Copyright (c) 2002-2007, 2013 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
--------------------
01a,08apr13,r_w fix coverity issues for defect WIND00411995
*/
/*
DESCRIPTION
This file implements Lock Manager
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#include "wm.h"
#include "wmb.h"
/* defines */
/* typedefs */
/* locals */
#ifndef __WM_NO_LOCKS__
LOCAL void wmbLockCleanup (WMB_LOCK_REQ_T * pLock);
LOCAL BOOL wmbLockIsCompatible (WMB_LOCK_MODE_T mode1, WMB_LOCK_MODE_T mode2);
LOCAL STATUS wmbLockRelease (WMB_LOCK_REQ_T * pLock, BOOL all);
LOCAL STATUS wmbLockConvert (WMB_LOCK_REQ_T * pLock, WMB_LOCK_MODE_T mode);
LOCAL STATUS wmbLockSharedWait (WMB_LOCK_REQ_T * pLock);
LOCAL STATUS wmbLockExclusiveWait (WMB_LOCK_REQ_T * pLock);
LOCAL STATUS wmbLockNewAdd (WMB_LOCK_HEAD_T * pHead, WMB_TID_T tid,
WMB_LOCK_MODE_T mode, WMB_LOCK_REQ_T * * ppLock);
/**************************************************************************
*
* wmbLockHeadNew - Find and initialize a Lock Head.
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS wmbLockHeadNew
(
WMB_LOCK_HEAD_T **ppLockHead /* [out] In return points to the new Lock Head structure */
)
{
if (! wmNew(*ppLockHead))
return wmError(ERROR_MEMMGR_NO_MEMORY, "no memory");
(*ppLockHead)->numLocks = 0;
(*ppLockHead)->pLockReq = NULL;
(*ppLockHead)->granted = WMB_MODE_FREE;
if (OK != wmosSemCreate(&((*ppLockHead)->semHead), 1, 0))
{
wmDelete(*ppLockHead);
return ERROR;
}
if (OK != wmosSemCreate(&((*ppLockHead)->semExclusive), 1, 0))
{
wmosSemDestroy((*ppLockHead)->semHead);
wmDelete(*ppLockHead);
return ERROR;
}
if (OK != wmosSemBinaryCreate(&((*ppLockHead)->semShared), 0))
{
wmosSemDestroy((*ppLockHead)->semExclusive);
wmosSemDestroy((*ppLockHead)->semHead);
wmDelete(*ppLockHead);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* wmbLockHeadFree - Free a lock head.
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS wmbLockHeadFree
(
WMB_LOCK_HEAD_T *pLockHead /* [in] Lock head to be freed */
)
{
STATUS rc = OK;
wmosSemDestroy(pLockHead->semExclusive);
wmosSemDestroy(pLockHead->semHead);
wmosSemDestroy(pLockHead->semShared);
wmbFree(pLockHead);
return rc;
}
/**************************************************************************
*
* wmbLockFromTIDFind - Find a Lock request structure, given its TID.
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
WMB_LOCK_REQ_T *wmbLockFromTIDFind
(
WMB_LOCK_HEAD_T *pHead, /* [in] Pointer to the head of the lock queue */
WMB_TID_T tid /* [in] Transaction ID to search for */
)
{
WMB_LOCK_REQ_T *pLockReq;
pLockReq = pHead->pLockReq;
while (NULL != pLockReq)
{
if (pLockReq->tid == tid)
break;
pLockReq = pLockReq->pNextLock;
}
return pLockReq;
}
/**************************************************************************
*
* wmbLockCleanup - Delete a Lock Request and do other related cleanup.
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
LOCAL void wmbLockCleanup
(
WMB_LOCK_REQ_T *pLock /* [in] Pointer to the Lock Request stucture to delete */
)
{
WMB_LOCK_HEAD_T *pHead;
WMB_LOCK_REQ_T *pLock2;
pHead = pLock->pHead;
wmosSemTake(pHead->semHead, WAIT_FOREVER_K);
pLock2 = pHead->pLockReq;
if (pLock2 == pLock)
pHead->pLockReq = pLock2->pNextLock;
else
{
while ((pLock2->pNextLock != NULL) && (pLock2->pNextLock != pLock))
pLock2 = pLock2->pNextLock;
pLock2->pNextLock = pLock->pNextLock;
}
pHead->numLocks =(ubyte2)(pHead->numLocks - pLock->lockCount);
wmosSemGive(pHead->semHead);
wmbTransactionLockDelete(pLock->tid, pLock);
wmbFree(pLock);
}
/**************************************************************************
*
* wmbLockIsCompatible - Determine if the two lock modes are compatible.
*
* RETURNS: TRUE or FALSE
*
* NOMANUAL
*/
LOCAL BOOL wmbLockIsCompatible
(
WMB_LOCK_MODE_T mode1, /* [in] mode to compare with */
WMB_LOCK_MODE_T mode2 /* [in] mode to compare */
)
{
BOOL compatible = FALSE;
switch (mode1)
{
case WMB_MODE_FREE:
compatible = TRUE;
break;
case WMB_MODE_INTENT:
case WMB_MODE_SHARED:
if (WMB_MODE_EXCLUSIVE != mode2)
compatible = TRUE;
break;
case WMB_MODE_EXCLUSIVE:
default:
break;
}
return compatible;
}
/**************************************************************************
*
* wmbLockRelease - Release a lock that was granted.
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
LOCAL STATUS wmbLockRelease
(
WMB_LOCK_REQ_T *pLock, /* [in] Pointer to the Lock Request stucture to release */
BOOL bAll /* [in] If TRUE, all locks of this request are released. */
)
{
STATUS rc = OK;
ubyte2 count = 1;
WMB_LOCK_HEAD_T *pHead;
WMB_LOCK_REQ_T *pLock2;
pHead = pLock->pHead;
if (pLock->lockStatus != WMB_STATUS_GRANTED)
return wmError(ERROR_LM_LOCK_NOT_GRANTED, "wmbLockRelease: Lock status is not granted");
if (TRUE == bAll)
{
count = pLock->lockCount;
pLock->lockCount = 0;
}
else
pLock->lockCount--;
wmosSemTake(pHead->semHead, WAIT_FOREVER_K);
pHead->numLocks = (ubyte2)(pHead->numLocks - count);
wmosSemGive(pHead->semHead);
if (0 == pLock->lockCount)
{
pLock->lockStatus = WMB_STATUS_NULL;
pLock2 = pHead->pLockReq;
while (NULL != pLock2)
{
if (pLock2->lockStatus == WMB_STATUS_GRANTED)
break;
pLock2 = pLock2->pNextLock;
}
if (NULL == pLock2)
{
wmosSemTake(pHead->semHead, WAIT_FOREVER_K);
pHead->granted = WMB_MODE_FREE;
if (pLock->lockMode == WMB_MODE_EXCLUSIVE)
wmosSemGive(pHead->semExclusive);
wmosSemFlush(pHead->semShared);
wmosSemGive(pHead->semHead);
}
}
return rc;
}
/**************************************************************************
*
* wmbLockConvert - Add a new lock for the transaction. Convert the lock if needed
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
LOCAL STATUS wmbLockConvert
(
WMB_LOCK_REQ_T *pLock, /* [in] Pointer to the Lock Request stucture to convert */
WMB_LOCK_MODE_T mode /* [in] Mode to convert to */
)
{
STATUS rc = OK;
WMB_LOCK_HEAD_T *pHead;
ubyte2 count;
pHead = pLock->pHead;
if (pLock->lockMode != mode)
{
if (wmbLockIsCompatible(pLock->lockMode, mode))
{
pLock->lockMode = mode;
pLock->lockCount++;
}
else
{
count = pLock->lockCount;
if (WMB_STATUS_GRANTED == pLock->lockStatus)
{
rc = wmbLockRelease(pLock, TRUE);
if (OK == rc)
{
pLock->lockMode = mode;
if (WMB_MODE_EXCLUSIVE == mode)
rc = wmbLockExclusiveWait(pLock);
else
rc = wmbLockSharedWait(pLock);
}
}
else
{
pLock->lockMode = mode;
pLock->lockStatus = WMB_STATUS_CONVERT;
}
if (OK == rc)
{
pLock->lockCount = count;
wmosSemTake(pHead->semHead, WAIT_FOREVER_K);
pHead->numLocks = (ubyte2)(pHead->numLocks + count);
wmosSemGive(pHead->semHead);
}
}
}
if (OK == rc)
{
pLock->lockCount++;
wmosSemTake(pHead->semHead, WAIT_FOREVER_K);
pHead->numLocks++;
wmosSemGive(pHead->semHead);
}
return rc;
}
/**************************************************************************
*
* wmbLockSharedWait - Wait until the shared mode is granted
*
* RETURNS: OK or ERROR
*
*
* NOMANUAL
*/
LOCAL STATUS wmbLockSharedWait
(
WMB_LOCK_REQ_T *pLock /* [in] Pointer to the Lock Request stucture to wait */
)
{
STATUS rc = OK;
WMB_LOCK_HEAD_T *pHead;
pHead = pLock->pHead;
pLock->lockStatus = WMB_STATUS_WAITING;
wmosSemTake(pHead->semHead, WAIT_FOREVER_K);
if (wmbLockIsCompatible(pHead->granted, pLock->lockMode))
{
pLock->lockStatus = WMB_STATUS_GRANTED;
}
wmosSemGive(pHead->semHead);
while (pLock->lockStatus == WMB_STATUS_WAITING)
{
wmosSemBinaryTake(pHead->semShared, WAIT_FOREVER_K);
wmosSemTake(pHead->semHead, WAIT_FOREVER_K);
if (wmbLockIsCompatible(pHead->granted, pLock->lockMode))
{
pHead->granted = pLock->lockMode;
pLock->lockStatus = WMB_STATUS_GRANTED;
}
wmosSemGive(pHead->semHead);
}
return rc;
}
/**************************************************************************
*
* wmbLockExclusiveWait - Wait until the exclusive mode is granted
*
* RETURNS: OK or ERROR
*
*
* NOMANUAL
*/
LOCAL STATUS wmbLockExclusiveWait
(
WMB_LOCK_REQ_T *pLock /* [in] Pointer to the Lock Request stucture to wait */
)
{
STATUS rc = OK;
WMB_LOCK_HEAD_T *pHead;
pHead = pLock->pHead;
pLock->lockStatus = WMB_STATUS_WAITING;
wmosSemTake(pHead->semExclusive, WAIT_FOREVER_K);
do
{
wmosSemTake(pHead->semHead, WAIT_FOREVER_K);
if (wmbLockIsCompatible(pHead->granted, pLock->lockMode))
{
pLock->lockStatus = WMB_STATUS_GRANTED;
pHead->granted = pLock->lockMode;
}
wmosSemGive(pHead->semHead);
if (WMB_STATUS_GRANTED != pLock->lockStatus)
wmosSemBinaryTake(pHead->semShared, WAIT_FOREVER_K);
}while (WMB_STATUS_GRANTED != pLock->lockStatus);
return rc;
}
/**************************************************************************
*
* wmbLockAdd - Add a Lock request to the lock head.
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbLockAdd
(
WMB_LOCK_HEAD_T *pHead, /* [in] Pointer to the head of the lock queue */
WMB_TID_T tid, /* [in] Transaction that requests the lock */
WMB_LOCK_MODE_T mode, /* [in] Read or Write Lock */
WMB_LOCK_REQ_T **ppLock /* [out] In return points to the new Lock request in the quueue */
)
{
#ifdef __WM_DEBUG__
WMB_LOCK_REQ_T *pLock2;
#endif
*ppLock = wmbLockFromTIDFind(pHead, tid);
#ifdef __WM_DEBUG__
pLock2 = pHead->pLockReq;
while (NULL != pLock2)
{
if (wmbTransactionBad(pLock2->tid))
printf("LEFT OVER LOCK detected, TID: 0x%x\n", (unsigned int) pLock2->tid);
pLock2 = pLock2->pNextLock;
}
#endif
if (NULL == *ppLock)
return wmbLockNewAdd(pHead, tid, mode, ppLock);
return wmbLockConvert(*ppLock, mode);
}
/**************************************************************************
*
* wmbLockNewAdd - Add a new Lock request to the lock head.
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
LOCAL STATUS wmbLockNewAdd
(
WMB_LOCK_HEAD_T *pHead, /* [in] Pointer to the head of the lock queue */
WMB_TID_T tid, /* [in] Transaction that requests the lock */
WMB_LOCK_MODE_T mode, /* [in] Read or Write Lock */
WMB_LOCK_REQ_T **ppLock /* [out] In return points to the new Lock request in the quueue */
)
{
STATUS rc = OK;
WMB_LOCK_REQ_T *pLockReq;
WMB_LOCK_REQ_T *pLock2;
*ppLock = NULL;
if (! wmNew(pLockReq))
return wmError(SYS_ERROR_NO_MEMORY, "wmbLockAddNew: no memory");
pLockReq->lockCount = 1;
pLockReq->lockMode = mode;
pLockReq->lockStatus = WMB_STATUS_NULL;
pLockReq->pHead = pHead;
pLockReq->pNextLock = NULL;
pLockReq->tid = tid;
wmosSemTake(pHead->semHead, WAIT_FOREVER_K);
if (NULL == pHead->pLockReq)
pHead->pLockReq = pLockReq;
else
{
pLock2 = pHead->pLockReq;
while (NULL != pLock2->pNextLock)
pLock2 = pLock2->pNextLock;
pLock2->pNextLock = pLockReq;
}
pHead->numLocks++;
rc = wmbTransactionLockAdd(tid, pLockReq);
wmosSemGive(pHead->semHead);
if (OK != rc)
pLockReq->lockStatus = WMB_STATUS_ERROR;
else
{
switch (pLockReq->lockMode)
{
case WMB_MODE_SHARED:
rc = wmbLockSharedWait(pLockReq);
break;
case WMB_MODE_EXCLUSIVE:
rc = wmbLockExclusiveWait(pLockReq);
break;
case WMB_MODE_INTENT:
if (wmbLockIsCompatible(pHead->granted, pLockReq->lockMode))
{
pHead->granted = pLockReq->lockMode;
pLockReq->lockStatus = WMB_STATUS_GRANTED;
}
else
{
rc = wmError(ERROR_LM_INTENT_MODE_FAILED, "wmbLockAddNew: Intent mode incompatible");
pLockReq->lockStatus = WMB_STATUS_ERROR;
}
break;
default:
break;
}
}
if (OK != rc)
{
if (WMB_STATUS_ERROR == pLockReq->lockStatus)
wmbLockCleanup(pLockReq);
pLockReq = NULL;
}
*ppLock = pLockReq;
return rc;
}
/**************************************************************************
*
* wmbLockRemove - Remove a lock.
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbLockRemove
(
WMB_LOCK_HEAD_T *pHead, /* [in] Pointer to the head of the lock queue */
WMB_TID_T tid /* [in] Transaction that requests the unlock */
)
{
STATUS rc;
WMB_LOCK_REQ_T *pLockReq;
pLockReq = wmbLockFromTIDFind(pHead, tid);
if (NULL == pLockReq)
return wmError(ERROR_LM_LOCK_NOT_FOUND, "wmbLockRemove: Lock not found");
rc = wmbLockRelease(pLockReq, FALSE);
if (0 == pLockReq->lockCount)
wmbLockCleanup(pLockReq);
return rc;
}
#endif /* __WM_NO_LOCKS__ */
@@ -0,0 +1,654 @@
/* wmbLockMgrLib.c - Lock Manager functions */
/* Copyright (c) 2001-2007, 2011-2012 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
--------------------
01e,20jul12,r_w eliminate memory leak issue. defect WIND00359749
01d,21mar11,r_w fix defect WIND00237303
01c,24feb07,msa Correct the apigen comments so they match the actual
routines.
01b,16feb06,ps changes for webcli on linux
01a,01jun05,gsr semaphore protection for pHead, SPR#109131
*/
/*
DESCRIPTION
This file implements Lock Manager
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#include "wm.h"
#include "wmb.h"
/* defines */
/* typedefs */
/* globals */
OS_SEM_T g_semObjLock;
/* locals */
#ifndef __WM_NO_LOCKS__
LOCAL STATUS wmbWindMarkLevelLock(WMB_OBJ_T obj, WMB_TID_T tid, WMB_LOCK_MODE_T mode);
LOCAL STATUS wmbTableLevelLock(WMB_OBJ_T obj, WMB_TID_T tid, WMB_LOCK_MODE_T mode);
LOCAL STATUS wmbComponentLevelLock(WMB_OBJ_T obj, WMB_TID_T tid, WMB_LOCK_MODE_T mode);
LOCAL STATUS wmbWindMarkLevelUnlock(WMB_OBJ_T obj, WMB_TID_T tid);
LOCAL STATUS wmbTableLevelUnlock(WMB_OBJ_T obj, WMB_TID_T tid);
LOCAL STATUS wmbComponentLevelUnlock(WMB_OBJ_T obj, WMB_TID_T tid);
LOCAL BOOL wmbLockIsDeadlock(WMB_LOCK_REQ_T *pLockAnchor, WMB_LOCK_REQ_T *pLockTr);
LOCAL BOOL wmbLockIsDeadlockPotential(WMB_LOCK_REQ_T *pLock);
LOCAL OS_SEM_T semLockMgr;
/**************************************************************************
*
* wmbLockMgrInit - Initialize the Lock Manager.
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbLockMgrInit(void)
{
STATUS rc = OK;
if (semLockMgr == 0)
wmosSemMCreate (&semLockMgr, 0);
if (g_semObjLock == 0)
wmosSemMCreate (&g_semObjLock, 0);
return rc;
}
/**************************************************************************
*
* wmbLockMgrStop - Stop the Lock Manager.
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbLockMgrStop(void)
{
STATUS rc = OK;
if (semLockMgr != NULL)
{
wmosSemDestroy(semLockMgr);
semLockMgr = NULL;
}
if (g_semObjLock != NULL)
{
wmosSemDestroy(g_semObjLock);
g_semObjLock = NULL;
}
return rc;
}
/**************************************************************************
*
* wmbLock - Lock the object.
*
* The Object can be locked at the table, producer or WindMark level.
*
* RETURNS: ERROR, OK
*
* errno:
* ERROR_WMB_OBJECT_INVALID
*/
STATUS wmbLock
(
WMB_OBJ_T obj, /* [in] Pointer to the object to lock */
WMB_TID_T tid, /* [in] Transaction that requests the lock */
WMB_LOCK_MODE_T mode /* [in] Read or Write Lock */
)
{
STATUS rc;
WMB_LOCK_LEVEL_T level;
if (wmbObjectBad(obj))
return wmError(ERROR_WMB_OBJECT_INVALID, "wmbtLock: Bad Object Pointer");
/* Determine at which level the lock should be placed */
level = wmbObjectLevelGet(obj);
switch (level)
{
case WMB_LOCK_LEVEL_TABLE_K:
wmosSemTake(semLockMgr, WAIT_FOREVER_K);
rc = wmbTableLevelLock(obj, tid, mode);
wmosSemGive(semLockMgr);
break;
case WMB_LOCK_LEVEL_OBJECT_K:
wmosSemTake(semLockMgr, WAIT_FOREVER_K);
rc = wmbWindMarkLevelLock(obj, tid, mode);
wmosSemGive(semLockMgr);
break;
default:
case WMB_LOCK_LEVEL_COMP_K:
wmosSemTake(semLockMgr, WAIT_FOREVER_K);
rc = wmbComponentLevelLock(obj, tid, mode);
wmosSemGive(semLockMgr);
break;
}
return rc;
}
/**************************************************************************
*
* wmbUnlock - Unlock the object.
*
* Unlocks the Object that was previously locked by wmbLock() function.
*
* RETURNS: ERROR, OK
*
* errno:
* ERROR_WMB_OBJECT_INVALID
*/
STATUS wmbUnlock
(
WMB_OBJ_T obj, /* [in] Pointer to the object to unlock */
WMB_TID_T tid /* [in] Transaction that requests to unlock */
)
{
WMB_LOCK_LEVEL_T level;
STATUS rc;
if (wmbObjectBad(obj))
return wmError(ERROR_WMB_OBJECT_INVALID,
"wmbUnlock: Bad Object Pointer");
/* Determine at which level the lock should be placed */
level = wmbObjectLevelGet(obj);
switch (level)
{
case WMB_LOCK_LEVEL_TABLE_K:
wmosSemTake(semLockMgr, WAIT_FOREVER_K);
rc = wmbTableLevelUnlock(obj, tid);
wmosSemGive(semLockMgr);
break;
case WMB_LOCK_LEVEL_OBJECT_K:
wmosSemTake(semLockMgr, WAIT_FOREVER_K);
rc = wmbWindMarkLevelUnlock(obj, tid);
wmosSemGive(semLockMgr);
break;
default:
case WMB_LOCK_LEVEL_COMP_K:
wmosSemTake(semLockMgr, WAIT_FOREVER_K);
rc = wmbComponentLevelUnlock(obj, tid);
wmosSemGive(semLockMgr);
break;
}
return OK;
}
/**************************************************************************
*
* wmbLockAllUnlock - Unlock all the objects of a transaction
*
* This is a fast-track routine to unlock all objects of a Transaction.
*
* RETURNS: OK
*
* errno:
* none.
*
* NOMANUAL
*/
STATUS wmbAllUnlock
(
WMB_TID_T tid /* [in] Transaction that requests to unlock */
)
{
WMB_LOCK_REQ_T *pLock, *pLock2;
WMB_LOCK_HEAD_T *pHead;
if (wmbTransactionBad(tid))
return OK;
wmosSemTake(semLockMgr, WAIT_FOREVER_K);
pLock = wmbTransactionLockGet(tid);
while (NULL != pLock)
{
pLock2 = pLock->pTranNext;
pHead = pLock->pHead;
if (NULL != pHead)
wmbLockRemove(pHead, tid);
pLock = pLock2;
}
wmosSemGive(semLockMgr);
return OK;
}
/**************************************************************************
*
* wmbWindMarkLevelLock - Lock the WindMark object.
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
LOCAL STATUS wmbWindMarkLevelLock
(
WMB_OBJ_T obj, /* [in] Pointer to the object to lock */
WMB_TID_T tid, /* [in] Transaction that requests the lock */
WMB_LOCK_MODE_T mode /* [in] Read or Write Lock */
)
{
DB_ENTRY_T * pEntry;
WMB_LOCK_HEAD_T * pHead;
WMB_LOCK_REQ_T * pLock = NULL;
if (NULL == (pEntry = wmbObjectEntryGet(obj)))
return wmError(ERROR_LM_ENTRY_NOT_FOUND, "wmbObjectLock: No Entry Pointer");
if (OK != wmbComponentLevelLock(obj, tid, WMB_MODE_INTENT))
return ERROR;
if (OK != wmbTableLevelLock(obj, tid, WMB_MODE_INTENT))
{
wmbComponentLevelUnlock(obj, tid);
return ERROR;
}
if (NULL == (pHead = wmbEntryLockHeadGet(pEntry)))
{
if (OK != wmbLockHeadNew(&pHead))
{
wmbTableLevelUnlock(obj, tid);
wmbComponentLevelUnlock(obj, tid);
return ERROR;
}
wmbEntryLockHeadSet(pEntry, pHead);
}
if (OK != wmbLockAdd(pHead, tid, mode, &pLock))
{
wmbTableLevelUnlock(obj, tid);
wmbComponentLevelUnlock(obj, tid);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* wmbTableLevelLock - Lock the Table object.
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
LOCAL STATUS wmbTableLevelLock
(
WMB_OBJ_T obj, /* [in] Pointer to the object to lock */
WMB_TID_T tid, /* [in] Transaction that requests the lock */
WMB_LOCK_MODE_T mode /* [in] Read or Write Lock */
)
{
WMB_LOCK_HEAD_T * pHead;
WMB_LOCK_REQ_T * pLock;
DB_TABLE_T * pTable;
pTable = wmbObjectTableGet(obj);
if (NULL == pTable)
{
if (WMB_MODE_INTENT == mode)
return OK;
else
return wmError(ERROR_LM_TABLE_NOT_FOUND, "wmbTableLevelLock: Table not found");
}
if (WMB_MODE_INTENT != mode)
{
if (OK != wmbComponentLevelLock(obj, tid, WMB_MODE_INTENT))
return ERROR;
}
if (NULL == (pHead = wmbTableLockHeadGet(pTable)))
{
if (OK != wmbLockHeadNew(&pHead))
{
wmbComponentLevelUnlock(obj, tid);
return ERROR;
}
wmbTableLockHeadSet(pTable, pHead);
}
if (OK != wmbLockAdd(pHead, tid, mode, &pLock))
{
wmbComponentLevelUnlock(obj, tid);
return ERROR;
}
return OK;
}
/**************************************************************************
*
* wmbComponentLevelLock - Lock the Component object.
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
LOCAL STATUS wmbComponentLevelLock
(
WMB_OBJ_T obj, /* [in] Pointer to the object to lock */
WMB_TID_T tid, /* [in] Transaction that requests the lock */
WMB_LOCK_MODE_T mode /* [in] Read or Write Lock */
)
{
WMB_LOCK_HEAD_T * pHead;
WMB_LOCK_REQ_T * pLock;
WMB_COMPONENT_T * pComponent;
pComponent = wmbObjectComponentGet(obj);
if (NULL == pComponent)
return wmError(ERROR_GENERAL_COMPONENT_NOT_FOUND, "wmbComponentLevelLock: Component not found");
pHead = wmbComponentLockHeadGet(pComponent);
if (NULL == pHead)
{
if (OK != wmbLockHeadNew(&pHead))
return ERROR;
wmbComponentLockHeadSet(pComponent, pHead);
}
return wmbLockAdd(pHead, tid, mode, &pLock);
}
/**************************************************************************
*
* wmbWindMarkLevelUnlock - Unlock the WindMark object.
*
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
LOCAL STATUS wmbWindMarkLevelUnlock
(
WMB_OBJ_T obj, /* [in] Pointer to the object to unlock */
WMB_TID_T tid /* [in] Transaction that requests the unlock */
)
{
DB_ENTRY_T * pEntry;
WMB_LOCK_HEAD_T * pHead;
pEntry = wmbObjectEntryGet(obj);
if (NULL == pEntry)
return wmError(ERROR_LM_ENTRY_NOT_FOUND, "wmbWindMarkLevelUnlock: No Entry Pointer");
if (NULL == (pHead = wmbEntryLockHeadGet(pEntry)))
return wmError(ERROR_LM_ENTRY_NOT_FOUND, "wmbWindMarkLevelUnlock: no lock head");
wmbLockRemove(pHead, tid);
if (0 == pHead->numLocks)
{
wmbEntryLockHeadSet(pEntry, NULL);
wmbLockHeadFree(pHead);
}
wmbTableLevelUnlock(obj, tid);
return OK;
}
/**************************************************************************
*
* wmbTableLevelUnlock - Unlock the Table object.
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
LOCAL STATUS wmbTableLevelUnlock
(
WMB_OBJ_T obj, /* [in] Pointer to the object to unlock */
WMB_TID_T tid /* [in] Transaction that requests the unlock */
)
{
DB_TABLE_T * pTable;
WMB_LOCK_HEAD_T * pHead;
pTable = wmbObjectTableGet(obj);
if (NULL != pTable)
{
if (NULL != (pHead = wmbTableLockHeadGet(pTable)))
{
wmbLockRemove(pHead, tid);
if (0 == pHead->numLocks)
{
wmbTableLockHeadSet(pTable, NULL);
wmbLockHeadFree(pHead);
}
}
}
return wmbComponentLevelUnlock(obj, tid);
}
/**************************************************************************
*
* wmbComponentLevelUnlock - Unlock the Component object.
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
LOCAL STATUS wmbComponentLevelUnlock
(
WMB_OBJ_T obj, /* [in] Pointer to the object to unlock */
WMB_TID_T tid /* [in] Transaction that requests the unlock */
)
{
WMB_LOCK_HEAD_T * pHead;
WMB_COMPONENT_T * pComponent;
pComponent = wmbObjectComponentGet(obj);
if (NULL == pComponent)
return wmError(ERROR_GENERAL_COMPONENT_NOT_FOUND, "wmbComponentLevelUnlock: Component not found");
if (NULL == (pHead = wmbComponentLockHeadGet(pComponent)))
return wmError(ERROR_GENERAL_COMPONENT_NOT_FOUND, "wmbComponentLevelUnlock: no lock");
wmbLockRemove(pHead, tid);
if (0 == pHead->numLocks)
{
wmbComponentLockHeadSet(pComponent, NULL);
wmbLockHeadFree(pHead);
}
return OK;
}
/**************************************************************************
*
* wmbLockIsDeadlock - See if deadlock occurred between two locks.
*
* RETURNS: TRUE if deadlocked.
*
*
* NOMANUAL
*/
LOCAL BOOL wmbLockIsDeadlock
(
WMB_LOCK_REQ_T *pLockAnchor, /* [in] Pointer to the lock to check against */
WMB_LOCK_REQ_T *pLockTr /* [in] Pointer to the lock list of transaction */
)
{
WMB_LOCK_HEAD_T *pHead;
WMB_LOCK_REQ_T *pLock;
while (NULL != pLockTr)
{
if (pLockTr->lockStatus == pLockAnchor->lockStatus)
{
pHead = pLockTr->pHead;
pLock = pHead->pLockReq;
while (NULL != pLock)
{
if ((pLock->tid == pLockAnchor->tid) &&
(pLock != pLockAnchor))
break;
pLock = pLock->pNextLock;
}
if (NULL != pLock)
{
if (((WMB_STATUS_GRANTED == pLockTr->lockStatus) &&
(WMB_STATUS_WAITING == pLock->lockStatus)) ||
((WMB_STATUS_GRANTED == pLock->lockStatus) &&
(WMB_STATUS_WAITING == pLockTr->lockStatus)))
return TRUE;
}
}
pLockTr = pLockTr->pTranNext;
}
return FALSE;
}
/**************************************************************************
*
* wmbLockIsDeadlockPotential - See if deadlock is possible for this Lock.
*
* RETURNS: TRUE if deadlock is possible.
*
*
* NOMANUAL
*/
LOCAL BOOL wmbLockIsDeadlockPotential
(
WMB_LOCK_REQ_T *pLock /* [in] Pointer to the first lock in the list */
)
{
WMB_LOCK_REQ_T *pLock2;
BOOL bGranted = FALSE;
BOOL bWaiting = FALSE;
pLock2 = pLock;
while (NULL != pLock2)
{
if (WMB_STATUS_GRANTED == pLock2->lockStatus)
{
bGranted = TRUE;
if (bWaiting)
break;
}
else if (WMB_STATUS_WAITING == pLock2->lockStatus)
{
bWaiting = TRUE;
if (bGranted)
break;
}
pLock2 = pLock2->pTranNext;
}
return bGranted && bWaiting;
}
/**************************************************************************
*
* wmbLockDeadlockFind - Find a deadlock causing lock in a transaction.
*
* RETURNS: Transaction ID that causes the deadlock.
*
* NOMANUAL
*/
WMB_TID_T wmbLockDeadlockFind
(
WMB_LOCK_REQ_T *pLock, /* [in] Pointer to the first lock in the list */
BOOL bStrict /* [in] TRUE, strict enforcement, FALSE potential */
)
{
WMB_LOCK_REQ_T *pLock2, *pLock3, *pLock4;
WMB_LOCK_HEAD_T *pHead;
WMB_TID_T tid;
WMB_TID_T tid2;
if (wmbLockIsDeadlockPotential(pLock))
{/*
* We now know that there are granted and waiting locks for this transaction.
* Potentially a deadlock situation. Find another transaction like this and
* compare them
*/
tid = pLock->tid;
for (pLock2 = pLock; NULL != pLock2; pLock2 = pLock2->pTranNext)
{
pHead = pLock2->pHead;
pLock3 = pHead->pLockReq;
while (NULL != pLock3)
{
tid2 = pLock3->tid;
if (tid2 != tid)
{
pLock4 = wmbTransactionLockGet(tid2);
if (wmbLockIsDeadlockPotential(pLock4))
{
if (!bStrict)
return tid2;
if (wmbLockIsDeadlock(pLock2, pLock4))
return tid2;
}
}
pLock3 = pLock3->pNextLock;
}
}
}
return NULL;
}
#endif /* __WM_NO_LOCKS__ */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,470 @@
/* wmbPortfolioLib.c - Portfolio Manager API functions */
/* Copyright (c) 2002-2004 2013 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,31jan13,r_w disable portfolio feature
01c,24feb07,msa Correct the apigen comments so they match the actual
routines.
01b,07jul04,vmk Null pcb pointer handling; Corrected Blade string parsing
01a,20jan04,jws event manager ifdef's removed
modification history added
*/
/*
DESCRIPTION
This file implements the portfolio manager
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#if 0 /* disable portfolio feature */
#include "wm.h"
#include "wmb.h"
#include "string.h"
/* defines */
/* typedefs */
/* locals */
LOCAL BOOL wmbIsBladeMatch
(
sbyte *fileName, /* [in] Pointer to the file name string */
sbyte *blade /* [in] Pointer to the blade name string */
);
LOCAL BOOL wmbIsExtensionMatch
(
sbyte *fileName, /* [in] Pointer to the file name string */
sbyte *extension /* [in] Pointer to the extension name string */
);
LOCAL OS_SEM_T portSem;
LOCAL WMB_PCB_ANCHOR_T * pPcbAnchor = NULL;
/* externals - will be moved to header file */
IMPORT void (*pWmbEventSubmit)(WMB_CID_T,WMB_EVENT_TYPE_T,ubyte4,
WMB_EVENT_SEVERITY_T,
ubyte4,ubyte4 *);
/**************************************************************************
*
* wmbPortfolioStart - initialize portfolio manager library
*
* RETURNS: OK
*
*
* NOMANUAL
*/
STATUS wmbPortfolioStart
(
void
)
{
if (NULL != pPcbAnchor)
return wmError(ERROR, "wmbPortfolioStart: corrupt anchor");
if (! wmNew(pPcbAnchor))
return wmError(ERROR, "no memory");
if (OK != wmosSemCreate(&portSem, 1, 0))
return ERROR;
return OK;
}
/**************************************************************************
*
* wmbPortfolioStop - shut down portfolio manager library
*
* RETURNS: OK
*
*
* NOMANUAL
*/
STATUS wmbPortfolioStop
(
void
)
{
WMB_PORTFOLIO_T * pPcb;
WMB_PORTFOLIO_T * pTemp;
if (NULL != pPcbAnchor)
{
pPcb = pPcbAnchor->pPCBList;
while (NULL != pPcb)
{
pTemp = pPcb;
pPcb = pPcb->pNext;
wmFree(pTemp);
}
wmFree (pPcbAnchor);
pPcbAnchor = NULL;
}
if (OK != wmosSemDestroy(portSem))
return ERROR;
return OK;
}
/**************************************************************************
*
* wmbPortfolioNew - Create a new Portfolio control block
*
* RETURNS: STATUS
*
*
* NOMANUAL
*/
STATUS wmbPortfolioNew
(
WMB_PORTFOLIO_T * * ppPcb /* [out] Pointer to the WMB_PORTFOLIO_T returned */
)
{
WMB_PORTFOLIO_T * pPcb;
WMB_PORTFOLIO_T * pPcb2;
if (! wmNew(pPcb))
return wmError(SYS_ERROR_NO_MEMORY, "wmbTMNewPCB: no memory");
wmosSemTake(portSem, WAIT_FOREVER_K);
if (NULL == pPcbAnchor->pPCBList)
pPcbAnchor->pPCBList = pPcb;
else
{
pPcb2 = pPcbAnchor->pPCBList;
while (NULL != pPcb2->pNext)
pPcb2 = pPcb2->pNext;
pPcb2->pNext = pPcb;
}
pPcbAnchor->numPCB++;
wmosSemGive(portSem);
if (NULL != ppPcb)
*ppPcb = pPcb;
return OK;
}
/**************************************************************************
*
* wmbPortfolioFromCIDGet - return Portfolio Control Block, given its CID
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbPortfolioFromCIDGet
(
WMB_CID_T cid, /* [in] Component ID */
WMB_PORTFOLIO_T ** ppPcb /* [out] Pointer to the WMB_PORTFOLIO_T returned */
)
{
WMB_PORTFOLIO_T * pPcb;
WMB_PORTFOLIO_T * pPrior = NULL;
WMB_PORTFOLIO_T * pRoot = NULL;
if (! wmbBackplaneMaster())
return wmbPortfolioFromCIDGetRemote(cid, ppPcb);
pPcb = pPcbAnchor->pPCBList;
while (NULL != pPcb)
{
if (cid == pPcb->cid)
{
if (NULL == pRoot)
pRoot = pPcb;
if (NULL != pPrior)
pPrior->pListNext = pPcb;
pPcb->pListNext = NULL;
pPrior = pPcb;
}
pPcb = pPcb->pNext;
}
*ppPcb = pPcb;
if (NULL == pPcb)
return wmError(ERROR_GENERAL_NOT_FOUND, "wmbPortfolioFromCIDGet: Portfolio not found");
return OK;
}
/**************************************************************************
*
* wmbPortfolioFromFileNameGet - return Portfolio Control Block, given its File Name
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbPortfolioFromFileNameGet
(
sbyte *fileName, /* [in] File Name */
WMB_PORTFOLIO_T **ppPcb /* [out] Pointer to the WMB_PORTFOLIO_T returned */
)
{
STATUS rc = OK;
WMB_PORTFOLIO_T *pPcb;
if (!wmbBackplaneMaster())
{
rc = wmbPortfolioFromFileNameGetRemote(fileName, ppPcb);
return rc;
}
pPcb = pPcbAnchor->pPCBList;
while (NULL != pPcb)
{
if (!STRICMP(fileName, pPcb->fileName))
break;
pPcb = pPcb->pNext;
}
*ppPcb = pPcb;
if (NULL == pPcb)
rc = wmError(ERROR_GENERAL_NOT_FOUND, "wmbPortfolioFromFileNameGet");
return rc;
}
/**************************************************************************
*
* wmbPortfolioRegister - create a new Portfolio Control Block
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
STATUS wmbPortfolioRegister
(
WMB_CID_T component, /* [in] management component pointer */
WMB_PORTFOLIO_TYPE_T type, /* [in] portfolio type */
WMB_FILENAME_T fileName, /* [in] portfolio file name */
ubyte4 flags /* [in] flags associated with this file */
)
{
WMB_PORTFOLIO_T * pPcb;
WMB_CID_T wmb_comp;
if (! wmbBackplaneMaster())
return wmbPortfolioRegisterRemote(component, type, fileName, flags);
if (OK != wmbPortfolioNew(&pPcb))
return ERROR;
pPcb->cid = component;
pPcb->type = type;
pPcb->fileName = fileName;
pPcb->flags = flags;
if (pWmbEventSubmit)
{
wmbBackplaneComponentGet(wmbBackplaneGet(), &wmb_comp);
pWmbEventSubmit(wmb_comp, WMB_EVENT_TYPE_PORTFOLIO,
WMB_PORTFOLIO_CREATED_EVENT,
WMB_EVENT_SEV_INFO, sizeof(WMB_CID_T),
(ubyte4*)&component);
}
return OK;
}
/**************************************************************************
*
* wmbPortfolioDeregister - Deregister a portfolio
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
void wmbPortfolioDeregister
(
WMB_CID_T cid, /* [in] unique id for this component */
WMB_FILENAME_T filename /* [in] filename of Portfolio location */
)
{
WMB_PORTFOLIO_T *pPcb;
WMB_PORTFOLIO_T *pPcb2;
WMB_CID_T wmb_comp;
if (!wmbBackplaneMaster())
{
wmbPortfolioDeregisterRemote(cid, filename);
return;
}
wmosSemTake(portSem, WAIT_FOREVER_K);
wmbPortfolioFromFileNameGet(filename, &pPcb);
if ((NULL != pPcb) && (pPcb->cid == cid))
{
if (pPcb == pPcbAnchor->pPCBList)
pPcbAnchor->pPCBList = pPcb->pNext;
else
{
pPcb2 = pPcbAnchor->pPCBList;
while (pPcb != pPcb2->pNext)
pPcb2 = pPcb2->pNext;
pPcb2->pNext = pPcb->pNext;
}
}
pPcbAnchor->numPCB--;
wmosSemGive(portSem);
wmDelete(pPcb);
if (pWmbEventSubmit)
{
wmbBackplaneComponentGet(wmbBackplaneGet(), &wmb_comp);
pWmbEventSubmit(wmb_comp, WMB_EVENT_TYPE_PORTFOLIO,
WMB_PORTFOLIO_DELETED_EVENT,
WMB_EVENT_SEV_INFO, sizeof(WMB_CID_T), (ubyte4*)cid);
}
}
/**************************************************************************
*
* wmbPortfolioGet - Get a list of portfolio structures
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
STATUS wmbPortfolioGet
(
sbyte *pBlade, /* [in] Search a blade related files */
sbyte *pExtension, /* [in] Search same extension files */
WMB_PORTFOLIO_T **ppPcb /* [out] Contains the linked list of portfolio CBs */
)
{
STATUS rc = OK;
WMB_PORTFOLIO_T *pPcb;
WMB_PORTFOLIO_T *pPcb2;
WMB_PORTFOLIO_T *pPrior = NULL;
BOOL bladeMatch = TRUE;
BOOL extMatch = TRUE;
if (!wmbBackplaneMaster())
{
rc = wmbPortfolioGetRemote(pBlade, pExtension, ppPcb);
return rc;
}
*ppPcb = NULL;
if (NULL == pPcbAnchor)
return wmError(ERROR, "wmbPortfolioGet: Not initialized");
pPcb = pPcbAnchor->pPCBList;
while (pPcb != NULL)
{
if (NULL != pBlade)
bladeMatch = wmbIsBladeMatch(pPcb->fileName, pBlade);
if (NULL != pExtension)
extMatch = wmbIsExtensionMatch(pPcb->fileName, pExtension);
if (bladeMatch && extMatch && ((NULL != pBlade) || (NULL != pExtension)))
{
if (! wmNew(pPcb2))
{
rc = wmError(ERROR_MEMMGR_NO_MEMORY, "wmbPortfolioGet");
break;
}
MEMCPY(pPcb2, pPcb, sizeof(WMB_PORTFOLIO_T));
pPcb2->pNext = NULL;
if (NULL == pPrior)
*ppPcb = pPcb2;
else
pPrior->pListNext = pPcb2;
pPcb2->pListNext = NULL;
pPrior = pPcb2;
}
pPcb = pPcb->pNext;
}
if (NULL == *ppPcb)
rc = wmError(ERROR_GENERAL_NOT_FOUND, "wmbPortfolioGet");
return rc;
}
/**************************************************************************
*
* wmbIsBladeMatch - Match blade string to the filename
*
* RETURNS: TRUE, FALSE
*
*
* NOMANUAL
*/
LOCAL BOOL wmbIsBladeMatch
(
sbyte *fileName, /* [in] Pointer to the file name string */
sbyte *blade /* [in] Pointer to the blade name string */
)
{
sbyte *test;
if (NULL == (test = strstr(fileName, blade)))
return FALSE;
return ((test == fileName) && (*(test + STRLEN(blade)) == '_'));
}
/**************************************************************************
*
* wmbIsExtensionMatch - Match extension string to the filename
*
* RETURNS: TRUE, FALSE
*
*
* NOMANUAL
*/
LOCAL BOOL wmbIsExtensionMatch
(
sbyte *fileName, /* [in] Pointer to the file name string */
sbyte *extension /* [in] Pointer to the extension name string */
)
{
sbyte *test;
if (NULL == (test = strstr(fileName, extension)))
return FALSE;
return ((*(test + STRLEN(test)) == 0) && (*(test - 1) == '.'));
}
#endif
@@ -0,0 +1,814 @@
/* wmbPortfolioRemote.c - Portfolio Manager Remote access functions */
/* Copyright (c) 2002-2010 2013 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,31jan13,r_w disable portfolio feature
01d,09jul10,m_z remove compile warning
01c,01apr10,f_f VxWorks 64bit support (WIND00193649)
01b,24feb07,msa Correct the apigen comments so they match the actual
routines.
01a,23sep03,jws fix compiler warnings, SPR 90282
*/
/*
DESCRIPTION
This file implements the portfolio manager remote access
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#if 0 /* disable portfolio feature */
#include "wrn/wm/common/wm.h"
#include "wrn/wm/backplane/wmb.h"
/* defines */
/* typedefs */
/* locals */
/**************************************************************************
*
* wmbPortfolioHandler - WindMark handler for Portfolio
*
* RETURNS: STATUS
*
*
* NOMANUAL
*/
STATUS wmbPortfolioHandler
(
WMB_TID_T tid, /* [in] Transaction ID */
WMB_OBJ_T obj, /* [in] Object List */
COMMAND_T cmd /* [in] Handler command */
)
{
STATUS rc = OK;
WMB_OBJ_T obj2;
WMB_PORTFOLIO_T *pPcb2;
WMB_PORTFOLIO_T *pPcb;
WMB_PM_REQUEST_T prcb;
sbyte *pXml;
sbyte4 id;
if (cmd != CMD_GET_K)
return wmError(ERROR, "wmbPortfolioHandler: Bad Command");
obj2 = obj;
do
{
id = wmbObjectLocalGet(obj2);
switch (id)
{
case WMB_PORTFOLIO_REG:
case WMB_PORTFOLIO_DEL:
rc = wmbMakePCBfromXML(wmbObjectInstanceGet(obj2)->data, &pPcb);
if (OK == rc)
{
pPcb2 = pPcb;
while ((OK == rc) && (NULL != pPcb2))
{
if (id == WMB_PORTFOLIO_REG)
rc = wmbPortfolioRegister(pPcb2->cid, pPcb2->type, pPcb2->fileName, pPcb2->flags);
else
wmbPortfolioDeregister(pPcb2->cid, pPcb2->fileName);
pPcb = pPcb2;
pPcb2 = pPcb->pNext;
wmDelete(pPcb);
}
}
wmbObjectStatusSet(obj2, rc);
break;
case WMB_PORTFOLIO_GET:
pPcb = NULL;
rc = wmbMakeRequestfromXML(wmbObjectInstanceGet(obj2)->data, &prcb);
if (OK == rc)
{
if (STRLEN(prcb.fileName) >0)
rc = wmbPortfolioFromFileNameGet(prcb.fileName, &pPcb);
else if (0 != prcb.cid)
rc = wmbPortfolioFromCIDGet(prcb.cid, &pPcb);
else
rc = wmbPortfolioGet(prcb.blade, prcb.extension, &pPcb);
}
if (NULL != pPcb)
{
rc = wmbMakeXMLFromPCB(pPcb, &pXml);
if (OK == rc)
{
rc = wmbObjectImport (wmbObject(obj2), pXml, STRLEN(pXml) + 1, DATATYPE_STRING_K);
}
}
wmbObjectStatusSet(obj2, rc);
break;
default:
rc = wmError(ERROR, "wmbPortfolioHandler: Unknown ID");
break;
}
obj2 = wmbObjectGroupNextGet(obj2);
}while ((OK == rc) && !wmbObjectBad(obj2));
return rc;
}
/**************************************************************************
*
* wmbMakePCBfromXML - Convert an XML string into WMB_PORTFOLIO_T structure
*
* RETURNS: STATUS
*
*
* NOMANUAL
*/
STATUS wmbMakePCBfromXML
(
sbyte *pXml, /* [in] Pointer to the XML string */
WMB_PORTFOLIO_T **pPcb /* [out] Pointer to the WMB_PORTFOLIO_T to be initialized */
)
{
STATUS rc;
XML_ENV_T xmlEnv;
xmlEnv.pCookie = NULL;
rc = wmXmlParserStart(&xmlEnv, wmbPortfolioDocPCBHandler, pXml, STRLEN(pXml));
*pPcb = xmlEnv.pCookie;
wmXmlParserStop(&xmlEnv);
return rc;
}
/**************************************************************************
*
* wmbMakeRequestfromXML - Convert an XML string into WMB_PM_REQUEST_T structure
*
* RETURNS: STATUS
*
*
* NOMANUAL
*/
STATUS wmbMakeRequestfromXML
(
sbyte *pXml, /* [in] Pointer to the XML string */
WMB_PM_REQUEST_T *pPrcb /* [in] Pointer to the WMB_PM_REQUEST_T to be initialized */
)
{
STATUS rc = OK;
XML_ENV_T xmlEnv;
xmlEnv.pCookie = pPrcb;
rc = wmXmlParserStart(&xmlEnv, wmbPortfolioDocREQHandler, pXml, STRLEN(pXml));
wmXmlParserStop(&xmlEnv);
return rc;
}
/**************************************************************************
*
* wmbMakeXMLFromPCB - Convert a WMB_PORTFOLIO_T into an XML string
*
* RETURNS: STATUS
*
*
* NOMANUAL
*/
STATUS wmbMakeXMLFromPCB
(
WMB_PORTFOLIO_T *pPcb, /* [in] Pointer to the WMB_PORTFOLIO_T */
sbyte **ppXml /* [out] Pointer to the XML string is returned */
)
{
STATUS rc = OK;
sbyte4 size = 0;
WMB_PORTFOLIO_T *pPcb2;
sbyte *temp;
pPcb2 = pPcb;
do
{
size += (sbyte4)(sizeof(pPcb2->cid) * 2 + sizeof(pPcb2->flags) * 2 + sizeof(pPcb2->type) * 2 + STRLEN(pPcb2->fileName) + 4);
pPcb2 = pPcb2->pListNext;
}while (NULL != pPcb2);
pPcb2 = pPcb;
temp = wmMalloc((size_t)size);
if (NULL == temp)
return wmError(ERROR_MEMMGR_NO_MEMORY, "wmbMakeXMLFromPCB");
STRCPY(temp, XML_HEADER1);
STRCAT(temp, DTD_HEADER1);
STRCAT(temp, "<");
STRCAT(temp, WMB_XML_PORTFOLIO);
STRCAT(temp, ">\n");
do
{
STRCAT(temp, "<");
STRCAT(temp, WMB_XML_PCB);
STRCAT(temp, ">\n<");
STRCAT(temp, WMB_XML_CID);
STRCAT(temp, ">");
rc = wmConvertToStr(&(pPcb2->cid), &temp[STRLEN(temp)], (sbyte4)(256-STRLEN(temp)), DATATYPE_ULONG_K);
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_CID);
STRCAT(temp, ">\n<");
STRCAT(temp, WMB_XML_PTYPE);
STRCAT(temp, ">");
rc = wmConvertToStr(&(pPcb2->type), &temp[STRLEN(temp)], (sbyte4)(256-STRLEN(temp)), DATATYPE_UINTEGER_K);
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_PTYPE);
STRCAT(temp, ">\n<");
STRCAT(temp, WMB_XML_PFILE);
STRCAT(temp, ">");
STRCAT(temp, pPcb2->fileName);
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_PFILE);
STRCAT(temp, ">\n<");
STRCAT(temp, WMB_XML_PFLAGS);
STRCAT(temp, ">");
rc = wmConvertToStr(&(pPcb2->flags), &temp[STRLEN(temp)], (sbyte4)(256-STRLEN(temp)), DATATYPE_UINTEGER_K);
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_PFLAGS);
STRCAT(temp, ">\n");
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_PCB);
STRCAT(temp, ">\n");
pPcb2 = pPcb2->pListNext;
}while ((OK == rc) && (pPcb2 != NULL));
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_PORTFOLIO);
STRCAT(temp, ">\n");
*ppXml = temp;
return rc;
}
/**************************************************************************
*
* wmbMakeXMLFromRequest - Convert a WMB_PM_REQUEST_T into an XML string
*
* RETURNS: STATUS
*
*
* NOMANUAL
*/
STATUS wmbMakeXMLFromRequest
(
WMB_PM_REQUEST_T *pPrcb, /* [in] Pointer to the WMB_PM_REQUEST_T */
sbyte **ppXml /* [out] Pointer to the XML string is returned */
)
{
STATUS rc = OK;
sbyte4 size = 0;
sbyte *temp;
size = (sbyte4)(sizeof(pPrcb->cid) * 2);
if (pPrcb->blade != NULL)
size += (sbyte4)STRLEN(pPrcb->blade) + 1;
if (pPrcb->extension != NULL)
size += (sbyte4)STRLEN(pPrcb->extension) + 1;
if (pPrcb->fileName != NULL)
size += (sbyte4)STRLEN(pPrcb->fileName) + 1;
temp = wmMalloc((size_t)size);
if (NULL == temp)
return wmError(ERROR_MEMMGR_NO_MEMORY, "wmbMakeXMLFromRequest");
STRCPY(temp, XML_HEADER1);
STRCAT(temp, DTD_HEADER1);
STRCAT(temp, "<");
STRCAT(temp, WMB_XML_REQUEST);
STRCAT(temp, ">\n");
if (pPrcb->cid != 0)
{
STRCAT(temp, "<");
STRCAT(temp, WMB_XML_CID);
STRCAT(temp, ">");
rc = wmConvertToStr(&(pPrcb->cid), &temp[STRLEN(temp)], (sbyte4)(256-STRLEN(temp)), DATATYPE_ULONG_K);
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_CID);
STRCAT(temp, ">\n");
}
if (pPrcb->fileName != NULL)
{
STRCAT(temp, "<");
STRCAT(temp, WMB_XML_PFILE);
STRCAT(temp, ">");
STRCAT(temp, pPrcb->fileName);
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_PFILE);
STRCAT(temp, ">\n");
}
if (pPrcb->blade != NULL)
{
STRCAT(temp, "<");
STRCAT(temp, WMB_XML_BLADE);
STRCAT(temp, ">");
STRCAT(temp, pPrcb->blade);
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_BLADE);
STRCAT(temp, ">\n");
}
if (pPrcb->extension != NULL)
{
STRCAT(temp, "<");
STRCAT(temp, WMB_XML_EXTENSION);
STRCAT(temp, ">");
STRCAT(temp, pPrcb->extension);
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_EXTENSION);
STRCAT(temp, ">\n");
}
STRCAT(temp, "</");
STRCAT(temp, WMB_XML_REQUEST);
STRCAT(temp, ">\n");
*ppXml = temp;
return rc;
}
/**************************************************************************
*
* wmbPortfolioDocPCBHandler - Callback function to process PCB list XML doc.
*
* RETURNS: STATUS
*
*
* NOMANUAL
*/
STATUS wmbPortfolioDocPCBHandler
(
XML_ENV_T *pXmlEnv, /* [in] Pointer to the parser environment structure */
SAX_FUNCTION_T functionID, /* [in] Function ID to dispatch. */
XML_DATUM_T *pXmlData /* [in] Received data if any */
)
{
STATUS rc = OK;
BOOL bNewPCB = FALSE;
WMB_PORTFOLIO_T *pPcb;
WMB_PORTFOLIO_T *pPrior;
sbyte *pData = pXmlData->pValue;
pPcb = (WMB_PORTFOLIO_T*)(pXmlEnv->pCookie);
if (NULL == pPcb)
{
if (! wmNew(pPcb))
return wmError(SYS_ERROR_NO_MEMORY, "wmbTMNewPCB: no memory");
bNewPCB = TRUE;
}
switch (functionID)
{
case SAX_START_DOCUMENT_K:
break;
case SAX_END_DOCUMENT_K:
break;
case SAX_START_ELEMENT_K:
if (!STRCMP(pData, WMB_XML_PCB))
{
bNewPCB = FALSE;
if (NULL == pXmlEnv->pCookie)
pXmlEnv->pCookie = pPcb;
else
{
pPrior = (WMB_PORTFOLIO_T*)(pXmlEnv->pCookie);
while (NULL != pPrior->pNext)
pPrior = pPrior->pNext;
pPrior->pNext = pPcb;
}
pPcb->cid = 0;
pPcb->fileName = NULL;
pPcb->flags = 0;
pPcb->type = 0;
pPcb->pListNext = NULL;
pPcb->currentTag = 0;
}
else
{
if (!STRCMP(WMB_XML_CID, pData))
pPcb->currentTag = WMB_XML_CID_TAG;
else
{
if (!STRCMP(WMB_XML_PFLAGS, pData))
pPcb->currentTag = WMB_XML_PFLAGS_TAG;
else
{
if (!STRCMP(WMB_XML_PTYPE, pData))
pPcb->currentTag = WMB_XML_PTYPE_TAG;
else
{
if (!STRCMP(WMB_XML_PFILE, pData))
pPcb->currentTag = WMB_XML_PFILE_TAG;
}
}
}
}
break;
case SAX_END_ELEMENT_K:
if (!STRCMP(pData, WMB_XML_PCB))
{
bNewPCB = FALSE;
}
break;
case SAX_CHARACTERS_K:
switch (pPcb->currentTag)
{
case WMB_XML_CID_TAG:
rc = wmConvertStrTo(pData, &pPcb->cid, DATATYPE_ULONG_K, TRUE);
break;
case WMB_XML_PTYPE_TAG:
rc = wmConvertStrTo(pData, &pPcb->type, DATATYPE_UINTEGER_K, TRUE);
break;
case WMB_XML_PFILE_TAG:
pPcb->fileName = pData;
break;
case WMB_XML_PFLAGS_TAG:
rc = wmConvertStrTo(pData, &pPcb->flags, DATATYPE_UINTEGER_K, TRUE);
break;
default:
break;
}
break;
case SAX_IGNORABLE_WHITESPACE_K:
case SAX_PROCESSING_INSTRUCTION_K:
default:
break;
}
if (TRUE == bNewPCB)
wmDelete(pPcb);
return rc;
}
/**************************************************************************
*
* wmbPortfolioDocREQHandler - Callback function to process REQUEST XML doc.
*
* RETURNS: STATUS
*
*
* NOMANUAL
*/
STATUS wmbPortfolioDocREQHandler
(
XML_ENV_T *pXmlEnv, /* [in] Pointer to the parser environment structure */
SAX_FUNCTION_T functionID, /* [in] Function ID to dispatch. */
XML_DATUM_T *pXmlData /* [in] Received data if any */
)
{
STATUS rc = OK;
WMB_PM_REQUEST_T *pPrcb;
sbyte *pData = pXmlData->pValue;
pPrcb = (WMB_PM_REQUEST_T*)(pXmlEnv->pCookie);
if (NULL == pPrcb)
return wmError(ERROR_GENERAL_OUT_OF_RANGE, "wmbPortfolioDocREQHandler");
switch (functionID)
{
case SAX_START_DOCUMENT_K:
break;
case SAX_END_DOCUMENT_K:
break;
case SAX_START_ELEMENT_K:
if (!STRCMP(WMB_XML_CID, pData))
pPrcb->currentTag = WMB_XML_CID_TAG;
else
{
if (!STRCMP(WMB_XML_BLADE, pData))
pPrcb->currentTag = WMB_XML_BLADE_TAG;
else
{
if (!STRCMP(WMB_XML_EXTENSION, pData))
pPrcb->currentTag = WMB_XML_EXTENSION_TAG;
else
{
if (!STRCMP(WMB_XML_PFILE, pData))
pPrcb->currentTag = WMB_XML_PFILE_TAG;
}
}
}
break;
case SAX_END_ELEMENT_K:
break;
case SAX_CHARACTERS_K:
switch (pPrcb->currentTag)
{
case WMB_XML_CID_TAG:
rc = wmConvertStrTo(pData, &pPrcb->cid, DATATYPE_ULONG_K, TRUE);
break;
case WMB_XML_BLADE_TAG:
pPrcb->blade = pData;
break;
case WMB_XML_PFILE_TAG:
pPrcb->fileName = pData;
break;
case WMB_XML_EXTENSION_TAG:
pPrcb->extension = pData;
break;
default:
break;
}
break;
case SAX_IGNORABLE_WHITESPACE_K:
case SAX_PROCESSING_INSTRUCTION_K:
default:
break;
}
return rc;
}
/**************************************************************************
*
* wmbPortfolioFromCIDGetRemote - return Portfolio Control Block, given its CID
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbPortfolioFromCIDGetRemote
(
WMB_CID_T cid, /* [in] Component ID */
WMB_PORTFOLIO_T **ppPcb /* [out] Pointer to the WMB_PORTFOLIO_T returned */
)
{
STATUS rc;
WMB_PM_REQUEST_T pmReq;
pmReq.blade = NULL;
pmReq.extension = NULL;
pmReq.cid = cid;
pmReq.fileName = NULL;
rc = wmbPortfolioRequestRemote(&pmReq, ppPcb);
return rc;
}
/**************************************************************************
*
* wmbPortfolioFromFileNameGetRemote - return Portfolio Control Block, given its File Name
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
STATUS wmbPortfolioFromFileNameGetRemote
(
sbyte *fileName, /* [in] File Name */
WMB_PORTFOLIO_T **ppPcb /* [out] Pointer to the WMB_PORTFOLIO_T returned */
)
{
STATUS rc;
WMB_PM_REQUEST_T pmReq;
pmReq.blade = NULL;
pmReq.extension = NULL;
pmReq.cid = NULL;
pmReq.fileName = fileName;
rc = wmbPortfolioRequestRemote(&pmReq, ppPcb);
return rc;
}
/**************************************************************************
*
* wmbPortfolioGetRemote - Get a list of portfolio structures using WindMarks
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
STATUS wmbPortfolioGetRemote
(
sbyte *pBlade, /* [in] Search a blade related files */
sbyte *pExtension, /* [in] Search same extension files */
WMB_PORTFOLIO_T **ppPcb /* [out] Contains the linked list of portfolio CBs */
)
{
STATUS rc;
WMB_PM_REQUEST_T pmReq;
pmReq.blade = pBlade;
pmReq.extension = pExtension;
pmReq.cid = NULL;
pmReq.fileName = NULL;
rc = wmbPortfolioRequestRemote(&pmReq, ppPcb);
return rc;
}
/**************************************************************************
*
* wmbPortfolioRequestRemote - Do a remote request
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
STATUS wmbPortfolioRequestRemote
(
WMB_PM_REQUEST_T *pmReq, /* [in] Pointer to the request structure */
WMB_PORTFOLIO_T **ppPcb /* [out] Contains the linked list of portfolio CBs */
)
{
STATUS rc = OK;
sbyte *pXml;
sbyte *pReturnXml = NULL;
WMB_TID_T tid;
WMB_OBJ_T obj;
WMB_CID_T pComponent;
WMB_SESSION_T *pSession;
wmbBackplaneComponentGet(wmbBackplaneGet(), &pComponent);
if (NULL == pComponent)
return wmError(ERROR_GENERAL_NOT_FOUND, "wmbPortfolioGetRemote");
rc = wmbSessionCreate(pComponent, 0, WMB_SESSION_NO_DEF_TRANSACTION, &pSession);
if (OK != rc)
return rc;
rc = wmbMakeXMLFromRequest(pmReq, &pXml);
if (OK == rc)
{
rc = wmbTransactionCreate(pSession, 0, 0, &tid);
if (OK == rc)
{
rc = wmbObjectCreate(tid, WMB_PORTFOLIO_GET_NAME, pXml, (sbyte4)STRLEN(pXml), &obj);
if (OK == rc)
{
rc = wmbTransactionProcess(tid, CMD_GET_K);
if (OK == rc)
{
obj = wmbTransactionHeadGet(tid);
if (!wmbObjectBad(obj))
{
pReturnXml = wmBufferDataGet(wmbObjectValueGet(obj));
}
}
wmbObjectDelete(obj);
}
wmbTransactionEnd(tid);
}
wmDelete(pXml);
}
if ((OK == rc) && (NULL != pReturnXml))
{
rc = wmbMakePCBfromXML(pReturnXml, ppPcb);
wmDelete(pReturnXml);
}
wmbSessionDestroy(pSession);
return rc;
}
/**************************************************************************
*
* wmbPortfolioDeregisterRemote - Deregister a portfolio
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
void wmbPortfolioDeregisterRemote
(
WMB_CID_T cid, /* [in] unique id for this component */
WMB_FILENAME_T filename /* [in] filename of Portfolio location */
)
{
WMB_PORTFOLIO_T pmPort;
pmPort.cid = cid;
pmPort.fileName = filename;
pmPort.pNext = NULL;
pmPort.pListNext = NULL;
wmbPortfolioRegDeregRemote(&pmPort, WMB_PORTFOLIO_DEL_NAME);
return;
}
/**************************************************************************
*
* wmbPortfolioRegisterRemote - create a new Portfolio Control Block
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
STATUS wmbPortfolioRegisterRemote
(
WMB_CID_T component, /* [in] management component pointer */
WMB_PORTFOLIO_TYPE_T type, /* [in] portfolio type */
WMB_FILENAME_T fileName, /* [in] portfolio file name */
ubyte4 flags /* [in] flags associated with this file */
)
{
STATUS rc;
WMB_PORTFOLIO_T pmPort;
pmPort.cid = component;
pmPort.fileName = fileName;
pmPort.flags = flags;
pmPort.type = type;
pmPort.pNext = NULL;
pmPort.pListNext = NULL;
rc = wmbPortfolioRegDeregRemote(&pmPort, WMB_PORTFOLIO_REG_NAME);
return rc;
}
/**************************************************************************
*
* wmbPortfolioRegDeregRemote - create a new Portfolio Control Block
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
STATUS wmbPortfolioRegDeregRemote
(
WMB_PORTFOLIO_T *pmPort, /* [in] Pointer to the Portfolio CB to register */
sbyte *pWindMark /* [in] Register or Deregister WindMark Name */
)
{
STATUS rc = OK;
WMB_SESSION_T *pSession;
WMB_CID_T pComponent;
sbyte *pXml;
WMB_TID_T tid;
WMB_OBJ_T obj;
wmbBackplaneComponentGet(wmbBackplaneGet(), &pComponent);
if (NULL == pComponent)
return wmError(ERROR_GENERAL_NOT_FOUND, "wmbPortfolioGetRemote");
rc = wmbSessionCreate(pComponent, 0, WMB_SESSION_NO_DEF_TRANSACTION, &pSession);
if (OK != rc)
return rc;
rc = wmbMakeXMLFromPCB(pmPort, &pXml);
if (OK == rc)
{
rc = wmbTransactionCreate(pSession, 0, 0, &tid);
if (OK == rc)
{
rc = wmbObjectCreate(tid, pWindMark, pXml, (sbyte4)STRLEN(pXml), &obj);
if (OK == rc)
{
rc = wmbTransactionProcess(tid, CMD_GET_K);
if (OK == rc)
{
obj = wmbTransactionHeadGet(tid);
if (!wmbObjectBad(obj))
{
rc = (STATUS)wmbObjectStatusGet(obj);
}
}
wmbObjectDelete(obj);
}
wmbTransactionEnd(tid);
}
wmDelete(pXml);
}
wmbSessionDestroy(pSession);
return rc;
}
#endif
@@ -0,0 +1,209 @@
/* wmbSNMPLib.c - SNMP interface handler of WMB */
/* Copyright 2002-2007 Wind River Systems, Inc. */
#include "copyright_wrs.h"
/*
DESCRIPTION
This file includes support for registering SNMP objects with the backplane and managing
all aspects of the SNMP related functions, including portfolios
*/
/* includes */
#include "wm.h"
#include "wmb.h"
#include "wmbSNMPLib.h"
#ifdef ENVOY_STACK_K
#include "wmmMethodRoutine.h"
#endif
#if defined __ENABLE_SNMP_RESOURCE_REGISTER__
/* defines */
/* typedefs */
/* locals */
static WMB_SNMP_ENTRY_T wmbEntry[WMB_MAX_SNMP_ENTRIES];
static int numTables = 0;
/**************************************************************************
*
* wmbSNMPEntryLookup - Return the index of WMB_SNMP_ENTRY_T for a component
*
* RETURNS: index
*
*
* NOMANUAL
*/
LOCAL sbyte2 wmbSNMPEntryLookup
(
WMB_CID_T component /* [in] Component ID */
)
{
sbyte4 i;
for (i = 0; i < WMB_MAX_SNMP_ENTRIES; i++)
{
if (wmbEntry[i].component == component)
break;
}
return i;
}
/**************************************************************************
*
* wmbSNMPResourceRegister - Register SNMP object
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
STATUS wmbSNMPResourceRegister
(
WMB_CID_T component, /* [in] Component ID */
sbyte *objName, /* [in] Object name */
ubyte4 *Id, /* [in] OID */
ubyte2 oidLen, /* [in] OID Len */
ubyte2 dataType, /* [in] Data Type */
ubyte2 accessRead, /* [in] Read access value */
ubyte2 accessWrite, /* [in] Write access value */
ubyte2 flags, /* [in] Flags */
WMB_HANDLER_T wmbHandler /* [in] Pointer to the WMB Handler function */
)
{
STATUS rc = OK;
WMB_ENTRY_T *pEntry;
sbyte4 i;
if (accessWrite == -1)
flags |= DB_FLAG_READONLY_K;
i = wmbSNMPEntryLookup(component);
if (i == WMB_MAX_SNMP_ENTRIES)
return ERROR;
if (wmbEntry[i].numEntry == wmbEntry[i].maxEntry)
return ERROR;
pEntry = &(wmbEntry[i].pEntryArray[wmbEntry[i].numEntry]);
pEntry->accessRead = 0;
pEntry->accessWrite = 0;
pEntry->flags = flags | DB_FLAG_INSTANCE;
pEntry->handler = wmbHandler;
pEntry->localId = 0;
pEntry->pData = Id;
pEntry->pName = objName;
pEntry->pValid = NULL;
pEntry->sibling = 0;
pEntry->size = oidLen;
pEntry->table = 0;
pEntry->type = dataType;
#ifdef ENVOY_STACK_K
rc = wmmRegisterSNMPObject(objName, Id, oidLen / sizeof (ubyte4),
dataType, accessRead, accessWrite, Id);
#endif
if ( rc == OK )
wmbEntry[i].numEntry++;
else
bzero( (char *)pEntry, sizeof(WMB_ENTRY_T) );
return rc;
}
/**************************************************************************
*
* wmbSNMPObjectEntryCreate - Allocate space for MIB Object entries
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
STATUS wmbSNMPObjectEntryCreate
(
WMB_CID_T component, /* [in] Component ID */
sbyte2 maxMIBObjects /* [in] Number of Entries to allocate for */
)
{
sbyte4 i;
if (numTables == WMB_MAX_SNMP_ENTRIES)
return wmError(ERROR_MEMMGR_NO_MEMORY, "wmbSNMPObjectEntryCreate: Access beyond wmbEntry array");
for (i = 0; i < WMB_MAX_SNMP_ENTRIES; i++)
{
if (wmbEntry[i].maxEntry == 0)
break;
}
wmbEntry[i].component = component;
wmbEntry[i].numEntry = 0;
wmbEntry[i].maxEntry = maxMIBObjects;
/* Use Calloc to get zero'd memory */
wmbEntry[i].pEntryArray = wmCalloc(maxMIBObjects, sizeof(WMB_ENTRY_T));
if (wmbEntry[i].pEntryArray == NULL)
return wmError(ERROR_MEMMGR_NO_MEMORY, "wmbSNMPObjectEntryCreate");
return OK;
}
/**************************************************************************
*
* wmbSNMPObjectEntryDelete - Delete MIB Object entries for the component
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
void wmbSNMPObjectEntryDelete
(
WMB_CID_T component /* [in] Component ID */
)
{
sbyte4 i;
i = wmbSNMPEntryLookup(component);
if (i == WMB_MAX_SNMP_ENTRIES)
return;
wmbEntry[i].maxEntry = 0;
wmbEntry[i].component = NULL;
wmbEntry[i].numEntry = 0;
wmFree(wmbEntry[i].pEntryArray);
}
/**************************************************************************
*
* wmbSNMPResourceArrayRegister - Registration of objects completed. WMB will be
* updated.
*
* RETURNS: ERROR, OK
*
*
* NOMANUAL
*/
STATUS wmbSNMPResourceArrayRegister
(
WMB_CID_T component, /* [in] Component ID */
sbyte *path, /* [in] Path of the component */
WMB_HANDLER_T wmbHandler /* [in] Pointer to the WMB Handler function */
)
{
sbyte4 i;
i = wmbSNMPEntryLookup(component);
if (i == WMB_MAX_SNMP_ENTRIES)
return ERROR;
return wmbResourceRegister(wmbComponentNameGet(component), path, wmbEntry[i].pEntryArray,
wmbEntry[i].numEntry, NULL, 0, wmbHandler);
}
#endif /* __ENABLE_SNMP_RESOURCE_REGISTER__ */
@@ -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 */
@@ -0,0 +1,219 @@
/* wmbSystem.c - backplane built-in elements */
/* Copyright 2001-2010 Wind River Systems, Inc. */
/*
modification history
--------------------
01e,09jul10,m_z remove compile warning
01d,01apr10,f_f VxWorks 64bit support (WIND00193649)
01c,26dlr04,dlr update to current API
01b,11oct01,rws comments modified
01a,01aug01,pns written
*/
/*
DESCRIPTION
backplane built-in elements.
INCLUDE FILES: wm.h wmb.h
*/
#include "wm.h"
#include "wmb.h"
#define TIME_SIZE_K 18 /* for uptime buffer */
LOCAL char wmbSystemSyslog [32] = "90.0.0.1";
LOCAL char wmbSystemMessage[32] = "System message";
LOCAL char wmbSystemLogfile[32] = "debug.txt";
LOCAL int wmbSystemDebug = 0;
LOCAL BOOL wmbSystemStderr = FALSE;
LOCAL BOOL wmbSystemThread = FALSE;
STATUS wmbSystemHandler
(
WMB_TID_T tid, /* wmb transaction pointer */
WMB_OBJ_T obj, /* wmb object pointer */
COMMAND_T command /* transaction type (e.g. GET,SET) */
);
STATUS wmbSystemLoad
(
sbyte * pName
);
enum WMB_SYSTEM_K
{
WMB_SYSTEM_INVALID_K,
WMB_SYSTEM_NAME_K,
WMB_SYSTEM_UPTIME_K,
WMB_SYSTEM_MEMORY_K,
WMB_SYSTEM_CLIENT_K,
WMB_SYSTEM_MSG_K,
WMB_SYSTEM_SYSLOG_K,
WMB_SYSTEM_LOGFILE_K,
WMB_SYSTEM_STDERR_K,
WMB_SYSTEM_THREAD_K,
WMB_SYSTEM_DEBUG_K
};
/* name id data type validation size read write flags handler */
WMB_ENTRY_T wmbSystem[] =
{
{"client", WMB_SYSTEM_CLIENT_K, NULL, DATATYPE_IPV4_K, NULL, 0, 0, 0, DB_FLAG_CALC, wmbSystemHandler},
{"debug", WMB_SYSTEM_DEBUG_K, &wmbSystemDebug, DATATYPE_INTEGER_K, NULL, sizeof(wmbSystemDebug), 0, 0, DB_FLAG_QUALIFIED, wmbSystemHandler},
{"logfile", WMB_SYSTEM_SYSLOG_K, wmbSystemLogfile, DATATYPE_STRING_K, NULL, sizeof(wmbSystemLogfile),0, 0, DB_FLAG_QUALIFIED, wmbSystemHandler},
{"memory", WMB_SYSTEM_MEMORY_K, NULL, DATATYPE_INTEGER_K, NULL, 0, 0, 0, DB_FLAG_CALC | DB_FLAG_QUALIFIED, wmbSystemHandler},
{"message", WMB_SYSTEM_MSG_K, wmbSystemMessage, DATATYPE_STRING_K, NULL, sizeof(wmbSystemMessage), 0, 0, DB_FLAG_QUALIFIED, wmbSystemHandler},
{"name", WMB_SYSTEM_NAME_K, NULL, DATATYPE_STRING_K, NULL, 0, 0, 0, DB_FLAG_CALC | DB_FLAG_QUALIFIED, wmbSystemHandler},
{"stderr", WMB_SYSTEM_STDERR_K, &wmbSystemStderr, DATATYPE_BOOL_K, NULL, sizeof(wmbSystemStderr), 0, 0, DB_FLAG_QUALIFIED, NULL},
{"syslog", WMB_SYSTEM_SYSLOG_K, wmbSystemSyslog, DATATYPE_STRING_K, NULL, sizeof(wmbSystemSyslog), 0, 0, DB_FLAG_QUALIFIED, wmbSystemHandler},
{"threads", WMB_SYSTEM_THREAD_K, &wmbSystemThread, DATATYPE_BOOL_K, NULL, sizeof(wmbSystemThread), 0, 0, DB_FLAG_QUALIFIED, NULL},
{"uptime", WMB_SYSTEM_UPTIME_K, NULL, DATATYPE_TICKS_K, NULL, 0, 0, 0, DB_FLAG_CALC | DB_FLAG_QUALIFIED, wmbSystemHandler}
};
/**************************************************************************
*
* wmbSystemLoad - load internal system data.
*
* This routine acts on Wind River CLI, Web, MIBway system internals.
*
* RETURNS:\is
*
*\i OK
*
*\ie
*/
STATUS wmbSystemLoad
(
sbyte * pName
)
{
return wmbComponentResourceLoad (wmbComponentLookup(pName), wmbSystem,
ARRAY_SIZE(wmbSystem), pName);
}
/**************************************************************************
*
* wmbSystemHandler - Displays backplane system data.
*
* This routine acts on backplane system internals. These objects can only
* be set by the special usage of the CMD_GET_K command
*
* RETURNS:\is
*\i ERROR_TRANS_NOT_HANDLED
*
*\i OK
*
*\ie
*/
STATUS wmbSystemHandler
(
WMB_TID_T tid, /* wmb transaction pointer */
WMB_OBJ_T obj, /* wmb object pointer */
COMMAND_T command /* transaction type (e.g. GET,SET) */
)
{
WMB_ID_T backplane;
DATATYPE_T type;
DB_ENTRY_T * pEntry;
WMB_SESSION_T * pSession;
ubyte4 temp;
size_t tempSize;
sbyte * pData;
size_t dataSize;
BOOL writable;
sbyte4 test;
size_t written;
backplane = wmbBackplaneGet();
writable = FALSE;
pEntry = wmbObjectEntryGet(obj);
/* get relevant data pointers */
test = wmbObjectLocalGet(obj);
switch (wmbObjectLocalGet(obj))
{
case WMB_SYSTEM_CLIENT_K:
if (CMD_GET_K != command)
return wmError(ERROR_GENERAL_ACCESS_DENIED, "not writable!");
pSession = wmbTransactionSessionGet(tid);
temp = wmbSessionAddressGet(pSession);
return wmbObjectImport(obj, &temp, sizeof(temp), DATATYPE_IPV4_K);
case WMB_SYSTEM_NAME_K:
pData = wmbBackplaneNameGet(backplane);
switch (command)
{
case CMD_GET_K:
return wmbObjectImport (obj, pData, STRLEN(pData),
DATATYPE_STRING_K);
case CMD_SET_K:
return wmbObjectExport (obj, pData,
WMB_BACKPLANE_NAME_MAX_K,
DATATYPE_STRING_K, &written);
}
return wmError(ERROR, "name: not handled");
case WMB_SYSTEM_UPTIME_K:
temp = (ubyte4)wmosTimeGet() - wmbBackplaneStartGet(backplane);
temp *= 100; /* 100 ticks / second */
switch (command)
{
case CMD_GET_K:
return wmbObjectImport (obj, &temp, sizeof(temp), DATATYPE_TICKS_K);
case CMD_SET_K:
return wmError(ERROR, "not writable!");
}
return wmError(ERROR_TM_NOT_HANDLED, "name: not handled");
case WMB_SYSTEM_MEMORY_K:
tempSize = (size_t)wmMemoryUsed();
pData = (sbyte *) &tempSize;
dataSize = sizeof(long);
type = DATATYPE_LONG_K;
break;
case WMB_SYSTEM_MSG_K:
case WMB_SYSTEM_SYSLOG_K:
case WMB_SYSTEM_LOGFILE_K:
case WMB_SYSTEM_DEBUG_K:
pData = wmbEntryDataGet(pEntry);
dataSize = wmbEntrySizeGet(pEntry);
type = wmbEntryTypeGet(pEntry);
writable = TRUE;
break;
default:
return wmError(ERROR_TM_NOT_HANDLED, "wmbSystemHandler: not handled");
}
/* act on our data */
switch (command)
{
case CMD_GET_K:
wmbObjectImport (obj, pData, dataSize, type);
break;
case CMD_SET_K:
if (! writable)
return wmError(ERROR_GENERAL_READ_ONLY, "not writable!");
wmbObjectExport (obj, pData, dataSize, type, &written);
break;
default:
return wmError(ERROR_TM_NOT_HANDLED, "wmbSystemHandler: not handled");
}
return OK;
}
/* wmbSytem.c */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,613 @@
/* wmbTransactionLib.c - Transaction API functions for Transaction Manager */
/* Copyright 2001-2007 Wind River Systems, Inc. */
/*
modification history
--------------------
01d,09jul10,m_z remove compile warning
01c,23oct08,y_z remove Abort step in the wmbTransactionInternal because it is
redundant and will produce a error int Transaction FSM
01b,24feb07,msa Correct the apigen comments so they match the actual
routines. Also fix any apigen errors.
01a,01Oct03,bk written
*/
/*
DESCRIPTION
This file implements transaction API for RCB clients
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#include "wm.h"
#include "wmb.h"
#include "wmbTransactionLibP.h"
/* defines */
/* typedefs */
/* locals */
LOCAL STATUS wmbTransactionInternal
(
WMB_TRANSACTION_T *pTcb /* [in] Pointer to the Transaction Control Block */
);
/**************************************************************************
*
* wmbTransactionCreate - create a new transaction
*
* This function creates a new Transaction Control Block with the parameters
* provided. There are other properties of the transaction, aside from what is
* provided here. Those properties can be set after the transaction is created.
* The transaction will be deleted by a call to wmbTransactionEnd() function.
*
* RETURNS: ERROR, OK
*
*/
STATUS wmbTransactionCreate
(
WMB_SESSION_T * pSession, /* [in] Pointer to the Session that owns this transaction */
ubyte4 timeout, /* [in] Tranaction timeout period */
ubyte4 flags, /* [in] Flags define how transactions are processed */
WMB_TID_T * pTid /* [out] Returned ID for transaction when OK */
)
{
WMB_TRANSACTION_T * pTcb;
WMB_CID_T component;
STATUS rc;
WMB_ID_T backplane;
backplane = wmbBackplaneGet();
if (wmbBackplaneBad(backplane))
return wmError(ERROR, "wmbTransactionCreate: invalid backplane");
if (wmbSessionBad(pSession))
{
if (NULL != pTid)
*pTid = (WMB_TID_T) 0;
return wmError(ERROR_GENERAL_NOT_FOUND, NULL);
}
rc = wmbTMNewTCB(&pTcb);
if (NULL == pTcb)
return wmError(ERROR_MEMMGR_NO_MEMORY, "no memory");
pTcb->state = TR_NULL;
pTcb->flags = flags;
pTcb->timeout = timeout;
pTcb->pSession = pSession;
pTcb->pool = wmbBackplaneMemGet(backplane);
#ifdef __ENABLE_IPC__
pTcb->pMemory = wmbBackplaneSharedGet(backplane);
#endif
component = wmbSessionComponentGet(pSession);
if (! wmbComponentBad(component))
pTcb->qid = wmbComponentQidGet(component);
if (NULL != pTid)
*pTid = wmbTransactionTidGet(pTcb);
wmbSessionTidSet(pSession, wmbTransactionTidGet(pTcb));
return OK;
}
/**************************************************************************
*
* wmbTransactionBegin - start a new transaction.
*
* Starts the previously created transaction. If a timeout was defined, this
* function will start the clock as well. When the transaction is started
* one of CMD_SET_K, CMD_GET_K or CMD_GET_NEXT_K commands must be specified.
*
* RETURNS: STATUS
*
*/
STATUS wmbTransactionBegin
(
WMB_TID_T tid, /* [in] Transaction ID to begin transaction */
COMMAND_T cmd /* [in] Command to process */
)
{
WMB_TRANSACTION_T *pTcb;
pTcb = wmbTMFindTCB(tid);
if (wmbTransactionBad(pTcb))
return wmError(ERROR_TM_TID_NOT_FOUND, "wmbTransactionBegin: bad tid");
pTcb->command = cmd;
return wmbTMProcessInput(TR_FSM_BEGINWORK, pTcb);
}
/**************************************************************************
*
* wmbTransactionTest - Enter the test phase of transaction.
*
* This function can be called after a wmbTransactionBegin() function, and if
* the command was CMD_SET_K.
*
* RETURNS: STATUS
*/
STATUS wmbTransactionTest
(
WMB_TID_T tid /* [in] Transaction ID of the transaction */
)
{
if (wmbTransactionBad(tid))
return wmError(ERROR_TM_TID_NOT_FOUND, NULL);
return wmbTMProcessInput(TR_FSM_TESTWORK, tid);
}
/**************************************************************************
*
* wmbTransactionCommit - Commits the transaction.
*
* This function can be called if the wmbTransactionTest() function was called
* and it was successful. Once the transaction is committed, it must be completed
* for the values to be permanently set.
*
* RETURNS: STATUS
*/
STATUS wmbTransactionCommit
(
WMB_TID_T tid /* [in] Transaction ID of the transaction */
)
{
if (wmbTransactionBad(tid))
return wmError(ERROR_TM_TID_NOT_FOUND, NULL);
return wmbTMProcessInput(TR_FSM_COMMITWORK, tid);
}
/**************************************************************************
*
* wmbTransactionComplete - Transaction is completed, after commit.
*
* This function can be called if the wmbTransactionCommit() function was called
* and it was successful. .
*
* RETURNS: STATUS
*/
STATUS wmbTransactionComplete
(
WMB_TID_T tid /* [in] Transaction ID of the transaction */
)
{
if (wmbTransactionBad(tid))
return wmError(ERROR_TM_TID_NOT_FOUND, NULL);
return wmbTMProcessInput(TR_FSM_COMPLETE, tid);
}
/**************************************************************************
*
* wmbTransactionAbort - Abort the transaction
*
* This function can be called after wmbTransactionTest() for set operations,
* or if a get operation iss to be cancelled. It returns error if the transaction
* was already committed.
*
* RETURNS: STATUS
*/
STATUS wmbTransactionAbort
(
WMB_TID_T tid /* [in] Transaction ID of the transaction */
)
{
if (wmbTransactionBad(tid))
return wmError(ERROR_TM_TID_NOT_FOUND, NULL);
return wmbTMProcessInput(TR_FSM_ABORTWORK, tid);
}
/**************************************************************************
*
* wmbTransactionEnd - End the transaction and cleanup.
*
* This function is called after the transaction is aborted or committed or the
* get operation is completed, and the values of the objects are extracted
* from the transaction records. This function deletes all resources allocated
* for the transaction.
*
* RETURNS: STATUS
*/
STATUS wmbTransactionEnd
(
WMB_TID_T tid /* [in] Transaction ID of the transaction */
)
{
if (wmbTransactionBad(tid))
return wmError(ERROR_TM_TID_NOT_FOUND, NULL);
return wmbTMProcessInput(TR_FSM_ENDWORK, tid);
}
/**************************************************************************
*
* wmbTransactionInternal - process all this transaction's current objects
*
* Both blocking and non-blocking processing of the wmbTransactionProcess function.
*
* RETURNS: ERROR, OK
*
* NOMANUAL
*/
LOCAL STATUS wmbTransactionInternal
(
WMB_TRANSACTION_T *pTcb /* [in] Pointer to the Transaction Control Block */
)
{
STATUS rc;
ubyte4 flags;
STATUS trStatus = OK;
flags = pTcb->flags;
pTcb->flags &= ~WMB_TM_DOASYNC;
switch (pTcb->command)
{
case CMD_SET_K:
rc = wmbTMProcessInput(TR_FSM_TESTWORK, pTcb);
if (OK == rc)
{
rc = wmbTMProcessInput(TR_FSM_COMMITWORK, pTcb);
if (OK == rc)
{
rc = wmbTMProcessInput(TR_FSM_COMPLETE, pTcb);
if (OK != rc)
{
if (!wmbTransactionBad(pTcb))
{
trStatus = pTcb->status;
}
}
}
}
else
trStatus = pTcb->status;
if (OK != trStatus)
{
rc = wmError(trStatus, NULL);
}
break;
default:
rc = wmbTMProcessInput(TR_FSM_GETREQUEST, pTcb);
break;
}
if ((flags & WMB_TM_DOASYNC) && (!wmbTransactionBad(pTcb)) && (NULL != pTcb->pFnComp))
{
pTcb->flags = flags;
(pTcb->pFnComp)(wmbTransactionTidGet(pTcb), WMB_TRANSACTION_COMPLETE_K, pTcb->pAsyncCtl);
}
return rc;
}
/**************************************************************************
*
* wmbTransactionProcess - process all this transaction's current objects
*
* Based on the <cmd>, all of the objects in the transaction <tid> are processed
* to completion. In case of error, transaction is automatically aborted.
*
* RETURNS: ERROR, OK
*/
STATUS wmbTransactionProcess
(
WMB_TID_T tid, /* [in] Transaction ID of the transaction */
COMMAND_T cmd /* [in] Command to process (CMD_SET_K...) */
)
{
WMB_TRANSACTION_T *pTcb;
pTcb = wmbTMFindTCB(tid);
if (wmbTransactionBad(pTcb))
return wmError(ERROR_TM_TID_NOT_FOUND, NULL);
pTcb->command = cmd;
if (OK != wmbTMProcessInput(TR_FSM_BEGINWORK, pTcb))
return ERROR;
if (pTcb->flags & WMB_TM_DOASYNC)
return wmThreadStart((VOIDFUNCPTR) wmbTransactionInternal, pTcb);
return wmbTransactionInternal(pTcb);
}
/**************************************************************************
*
* wmbTransactionObjectAdd - Add an Object to the Transaction
*
* After the transaction is created but before wmbTransactionBegin is called
* a number of objects to be included in the transaction are added by calling this
* function.
*
* RETURNS: STATUS
*
*/
STATUS wmbTransactionObjectAdd
(
WMB_TID_T tid, /* [in] Transaction Identifier */
WMB_OBJ_T obj /* [in] Object to add */
)
{
if (wmbTransactionBad(tid))
return wmError(ERROR_TM_TID_NOT_FOUND, "wmbTransactionObjectAdd");
return wmbTMAddObject(tid, obj);
}
/**************************************************************************
*
* wmbTransactionObjectRemove - Remove an Object from the Transaction
*
* RETURNS: STATUS
*
*
* NOMANUAL
*/
STATUS wmbTransactionObjectRemove
(
WMB_TID_T tid, /* [in] Transaction Identifier */
WMB_OBJ_T obj /* [in] Object to remove */
)
{
if (wmbTransactionBad(tid))
return wmError(ERROR_TM_TID_NOT_FOUND, "wmbTransactionObjectAdd");
return wmbTMRemoveObject(tid, obj);
}
/**************************************************************************
*
* wmbTransactionBad - Test if a Transaction ID is valid
*
* RETURNS: TRUE if TID is valid, FALSE otherwise
*
*/
BOOL wmbTransactionBad
(
WMB_TID_T tid /* [in] Transaction Identifier */
)
{
if ((NULL != makeTrans(tid)) &&
!(wmMagicBad(makeTrans(tid), MAGIC_TID_K)))
return FALSE;
return TRUE;
}
/**************************************************************************
*
* wmbTransactionLockDelete - Delete a Lock from the transaction list
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS wmbTransactionLockDelete
(
WMB_TID_T tid, /* [in] Transaction Identifier */
WMB_LOCK_REQ_T *pLock /* [in] The Lock to delete */
)
{
WMB_TRANSACTION_T * pTcb;
WMB_LOCK_REQ_T * pLock2;
WMB_LOCK_REQ_T * pLock3;
if (NULL == (pTcb = wmbTMFindTCB(tid)))
pTcb = wmbTMFindTCB(tid);
if (wmbTransactionBad(pTcb))
return wmError(ERROR_TM_TID_NOT_FOUND, "wmbTransactionLockDelete : Bad TID");
pLock2 = wmbTransactionLockGet(pTcb);
if (NULL == pLock2)
return OK;
wmosSemTake(pTcb->sem, WAIT_FOREVER_K);
if (pLock == pLock2)
{
wmbTransactionLockSet(pTcb, wmbLockReqTranNextGet(pLock));
if (NULL != (pLock2 = wmbTransactionLockGet(pTcb)))
wmbLockReqTranPrevSet(pLock2, NULL);
}
else
{
while ((NULL != pLock2) && (pLock != wmbLockReqTranNextGet(pLock2)))
{
pLock2 = wmbLockReqTranNextGet(pLock2);
}
if (NULL != pLock2)
wmbLockReqTranNextSet(pLock2, wmbLockReqTranNextGet(pLock));
if (NULL != (pLock3 = wmbLockReqTranNextGet(pLock)))
wmbLockReqTranPrevSet(pLock3, pLock2);
}
wmosSemGive(pTcb->sem);
return OK;
}
/**************************************************************************
*
* wmbTransactionLockAdd - Add a Lock to the transaction list
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
STATUS wmbTransactionLockAdd
(
WMB_TID_T tid, /* [in] Transaction Identifier */
WMB_LOCK_REQ_T *pLock /* [in] The Lock to Add */
)
{
STATUS rc = OK;
WMB_TRANSACTION_T *pTcb;
WMB_LOCK_REQ_T *pLock2;
pTcb = wmbTMFindTCB(tid);
if (wmbTransactionBad(pTcb))
{
return wmError(ERROR_TM_TID_NOT_FOUND, "wmbTransactionLockAdd : Bad TID");
}
wmosSemTake(pTcb->sem, WAIT_FOREVER_K);
if (NULL == (pLock2 = wmbTransactionLockGet(pTcb)))
{
wmbTransactionLockSet(pTcb, pLock);
wmbLockReqTranPrevSet(pLock, NULL);
}
else
{
while (NULL != wmbLockReqTranNextGet(pLock2))
pLock2 = wmbLockReqTranNextGet(pLock2);
wmbLockReqTranNextSet(pLock2, pLock);
wmbLockReqTranPrevSet(pLock, pLock2);
}
wmbLockReqTranNextSet(pLock, NULL);
wmosSemGive(pTcb->sem);
return rc;
}
/**************************************************************************
*
* wmbTransactionSharedGet - Retruen the shared memory pointer
*
* RETURNS: OS_MEM_SHARE_T pointer
*
* NOMANUAL
*/
OS_MEM_SHARE_T * wmbTransactionSharedGet
(
WMB_TID_T tid /* [in] Transaction Identifier */
)
{
WMB_TRANSACTION_T *pTcb = wmbTMFindTCB(tid);
if (NULL != pTcb)
return pTcb->pMemory;
else
return NULL;
}
/**************************************************************************
*
* wmbTransactionReplyGet - Return the transaction Message Q
*
* RETURNS: OS_MSGQ_T
*
* NOMANUAL
*/
OS_MSGQ_T wmbTransactionReplyGet
(
WMB_TID_T tid /* [in] Transaction Identifier */
)
{
WMB_TRANSACTION_T *pTcb = wmbTMFindTCB(tid);
if (NULL != pTcb)
return pTcb->qid;
else
return (OS_MSGQ_T)0;
}
/**************************************************************************
*
* wmbTransactionSessionTidAppend - Append a tid to the session tid list
*
* RETURNS: N/A
*
* NOMANUAL
*/
void wmbTransactionSessionTidAppend
(
WMB_TID_T tid, /* [in] Pointer to the head of TCB to append */
WMB_TID_T head /* [in] Head of the transaction list */
)
{
WMB_TRANSACTION_T *pTcb = wmbTMFindTCB(tid);
WMB_TRANSACTION_T *pTcb2 = wmbTMFindTCB(head);
if (NULL == pTcb2)
return;
while ((NULL != pTcb2) && (pTcb2->pSessionNext != NULL))
pTcb2 = pTcb2->pSessionNext;
if (NULL != pTcb2)
pTcb2->pSessionNext = pTcb;
}
/**************************************************************************
*
* wmbTransactionBackplaneGet - get current backplane
*
* If <pTcb> is valid, use its backplane, otherwise use system default.
*
* RETURNS: WMB_ID_T : Backplane ID
*
* NOMANUAL
*/
WMB_ID_T wmbTransactionBackplaneGet
(
WMB_TID_T tid /* [in] Transaction Identifier */
)
{
if (wmbTransactionBad (tid) || wmbSessionBad (wmbTransactionSessionGet(tid)))
return wmbBackplaneGet();
return wmbSessionBackplaneGet(wmbTransactionSessionGet(tid));
}
/****************************************************************************
*
* wmbTransactionIsBestEffort - Should the transaction be aborted on error or not?
*
* RETURNS: OK or ERROR
*
* NOMANUAL
*/
BOOL wmbTransactionIsBestEffort
(
WMB_TID_T tid /* [in] Transaction Identifier */
)
{
if ((WMB_TM_NOUNDO & wmbTransactionFlagsGet(tid)) == WMB_TM_NOUNDO)
return TRUE; /* Transaction is best effort */
return FALSE;
}
/* eof wmbTransactionLib.c */
@@ -0,0 +1,552 @@
/* cli2krnl.c - command transfering shell context from WebCLI to kernel one */
/*
* Copyright (c) 2009-2012, 2014 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
--------------------
01h,11aug14,f_f cancel the task of reading CLI Escape Sequence (VXW6-83234)
01g,16may12,f_f close the fd before removing ptyDev (WIND00349935)
01f,22dec11,f_f change the flags of tty device
01e,15Jun11,r_w add timeout mechanism in vxshell mode
CQID:Defect WIND00272340.
01d,23dec10,m_z change kernel shell invocation interface
CQID: Fix WIND00248130
01c,13jul10,m_z add simple data filter (WIND00220166)
CQID: Fix WIND00223764
01b,27apr10,m_z VxWorks 64-bit support
(WIND00193649)
01a,01Jun09,m_z Initial code
*/
/*
* DESCRIPTION
* This module provides command for CLI to change to kernel shell context.
*
* INCLUDE FILES:
*/
/* includes */
#include "wm.h"
#include "wmb.h"
#include "rcc.h"
#include <shellLib.h>
#include <private/shellLibP.h>
#include <ioLib.h>
#include <ptyDrv.h>
/* defines */
#define IO_BUFFER_LEN 512
#define PTY_NAME_LEN_MAX 256
#define TASK_NAME_LEN 256
#define SHELL_PTY_BUFFER_SIZE 512
#define SHELL_USERNAME_LEN 256
#define SHELL_PASSWORD_LEN 256
#define WEBCLI_SHELL_TASK_ID_NUM kRCC_MAX_CLI_TASK
#define SHELL_REMOTE_TASK_NAME_BASE "tShellRem"
#define SHELL_DATA_NAME "_webcli_remAcc"
/* globals */
extern TASK_ID webcliTaskIDList[WEBCLI_SHELL_TASK_ID_NUM];
extern SEM_ID webcliTaskIDSem;
extern int webcliCheckTaskID(TASK_ID taskId);
extern int webcliSaveTaskID(TASK_ID taskId);
extern int webcliDeleteTaskID(TASK_ID taskId);
ssize_t dataFilter(ssize_t len, char * buf);
int shellDataTranceiver ( int srcFd, int destFd, char * ioBuf, int io);
int shellCreatePTY ( char* ptyDevName, size_t nameLen, int *masterFd,
int *slaveFd);
void shellLogoutCallback ( void * arg);
void krnlShellProxy ( int ptyFd, char * ptyDevName);
extern int krnlShellStart ( int * shellFd );
extern STATUS wmvxshell ( cli_env * pCliEnv, struct paramList * pParams,
sbyte * pAuxBuf);
extern STATUS wmexit ( cli_env *pCliEnv, paramList *pParams, sbyte *pAuxBuf);
extern void shellLogoutInstall ( SHELL_LOGOUT_RTN logRtn, void * logVar);
extern STATUS shellGenericInit (const char * config, size_t stackSize,
const char * shellName, char **pShellName,
BOOL interactive, BOOL loginAccess,
int fdin, int fdout, int fderr);
/****************************************************************************
*
* shellUserAuth - authenticate user with password
*
* This routine authenticates user before init kernel shell instance
*
* RETURNS: 0(OK), or -1 if authentication fails
*
* ERRNO:
*/
/* int shellUserAuth */
/* ( */
/* int fd */
/* ) */
/* { */
/* int rLen = 0; */
/* int wLen = 0; */
/* int i; */
/* char username[SHELL_USERNAME_LEN] = {0}; */
/* char password[SHELL_PASSWORD_LEN] = {0}; */
/* */
/* if (write(fd, "\nlogin: ", 8) != 8) */
/* return -1; */
/* */
/* for (i = 0; i < SHELL_USERNAME_LEN; i++) */
/* { */
/* if (read(fd, username+i, 1) != 1) */
/* { */
/* return -1; */
/* } */
/* */
/* if (username[i] == '\r' || username [i] == '\n') */
/* { */
/* username[i] = '\0'; */
/* break; */
/* } */
/* } */
/* */
/* ioctl(fd, FIOFLUSH, 0); */
/* */
/* if (write(fd, "\npassword: ", 11) != 11) */
/* return -1; */
/* */
/* for (i = 0; i < SHELL_PASSWORD_LEN; i++) */
/* { */
/* if (read(fd, password+i, 1) != 1) */
/* { */
/* return -1; */
/* } */
/* */
/* if (password[i] == '\r' || password[i] == '\n') */
/* { */
/* password[i] = '\0'; */
/* break; */
/* } */
/* } */
/* */
/* ioctrl(fd, FIOFLUSH, 0); */
/* */
/* if (ipcom_auth_login(username, password, IP_NULL, IP_NULL, IP_NULL) != IPCOM_SUCCESS) */
/* return -1; */
/* */
/* */
/* return 0; */
/* } */
/****************************************************************************
*
* dataFilter - keep data consistent between terminal and vxworks shell
*
* This routine manipulates read data according to filter
the active filter: CR/LF pairs are translated to CR
*
* RETURNS: length of data left after filtering
*
* ERRNO: N/A
*/
ssize_t dataFilter(ssize_t len, char * buf)
{
ssize_t i, j;
ssize_t del = 0;
for (i = 1; i < len; i++)
{
if (
(buf[i-1] == 0x0d && buf[i] == 0x0a) ||
(buf[i-1] == 0x0d && buf[i] == 0x00) ||
(buf[i-1] == 0x0a && buf[i] == 0x00)
)
{
del++;
for (j = i+1; j < len; j++)
{
buf[j-1] = buf[j];
}
}
}
return (len - del);
}
/****************************************************************************
*
* shellDataTranceiver - read data from src file and write them to the dest
*
* This routine transports data between two files
*
* RETURNS: 0(OK), or -1 if error occurred such as socket disconnected
*
* ERRNO: N/A
*/
int shellDataTranceiver
(
int srcFd,
int destFd,
char * ioBuf,
int io
)
{
ssize_t rLen = 0;
ssize_t wLen = 0;
rLen = read(srcFd, ioBuf, IO_BUFFER_LEN);
if(rLen <= 0 || rLen > IO_BUFFER_LEN)
return -1;
if (0 != io)
{
/* now we consider CR/LF pairs transferred together*/
rLen = dataFilter(rLen, ioBuf);
}
wLen = write(destFd, ioBuf, rLen);
if(wLen != rLen)
return -1;
return 0;
}
/****************************************************************************
*
* shellCreatePTY - create PTY device
*
* This routine create PTY devcie working together with kernel shell
*
* RETURNS: 0(OK), or -1 if error during creating pty device
*
* ERRNO: N/A
*/
int shellCreatePTY
(
char* ptyDevName,
size_t nameLen,
int *masterFd,
int *slaveFd
)
{
char ptyDevNameM[PTY_NAME_LEN_MAX] = {0};
char ptyDevNameS[PTY_NAME_LEN_MAX] = {0};
/* Create unique names for the pty device */
snprintf (ptyDevName, nameLen, "%s_%l.", "stdio_pty", taskIdSelf());
snprintf (ptyDevNameM, PTY_NAME_LEN_MAX, "%sM", ptyDevName);
snprintf (ptyDevNameS, PTY_NAME_LEN_MAX, "%sS", ptyDevName);
/* pseudo tty device creation */
if (OK != ptyDevCreate (ptyDevName, SHELL_PTY_BUFFER_SIZE, SHELL_PTY_BUFFER_SIZE))
return -1;
*masterFd = open (ptyDevNameM, O_RDWR, 0);
if (ERROR == *masterFd)
{
ptyDevRemove(ptyDevName);
return -1;
}
*slaveFd = open (ptyDevNameS, O_RDWR, 0);
if (ERROR == *slaveFd)
{
(void)close(*masterFd);
ptyDevRemove(ptyDevName);
return -1;
}
if (ERROR == ioctl(*slaveFd, FIOOPTIONS, OPT_TERMINAL & ~(OPT_ABORT|OPT_MON_TRAP|OPT_ECHO|OPT_LINE)))
{
(void)close(*masterFd);
(void)close(*slaveFd);
ptyDevRemove(ptyDevName);
return -1;
};
return 0;
}
/****************************************************************************
*
* shellLogoutCallback - call when logout kernel shell
*
* This routine provided to kernel shell parent task and called when logout
* from kernel shell, so the parent task can dealing with work such as resource
* relesae
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
void shellLogoutCallback
(
void * arg
)
{
wmosSemGive((*(OS_SEM_T *)arg)); /* let the parent task go on */
}
/****************************************************************************
*
* krnlShellProxy - create a kernel shell instance
*
* This routine create kernel shell task and wait for its ending
*
* RETURNS: N/A
*
* ERRNO: N/A
*/
void krnlShellProxy
(
int ptyFd,
char * ptyDevName
)
{
SHELL_ID shellId;
TASK_ID taskId;
OS_SEM_T shellExitSem;
char * newTaskName;
char taskName[TASK_NAME_LEN + 1] = {'\0'};
if (OK != wmosSemCreate(&shellExitSem, 0, 0))
{
ptyDevRemove(ptyDevName);
wmosFree(ptyDevName);
return;
}
sprintf (taskName, "%s%ld", SHELL_REMOTE_TASK_NAME_BASE, (long)&shellExitSem);
shellLogoutInstall ((SHELL_LOGOUT_RTN) shellLogoutCallback, &shellExitSem);
if (OK == shellGenericInit (NULL, 0, taskName, &newTaskName, TRUE, TRUE, ptyFd, ptyFd, ptyFd))
{
taskId = taskNameToId(newTaskName);
shellId = shellFromNameGet(newTaskName);
webcliSaveTaskID(taskId);
wmosSemTake(shellExitSem, WAIT_FOREVER_K);
shellTerminate (shellId);
webcliDeleteTaskID(taskId);
}
close(ptyFd);
ptyDevRemove(ptyDevName);
wmosFree(ptyDevName);
wmosSemDestroy(shellExitSem);
}
/****************************************************************************
*
* krnlShellStart - create a proxy task to create kernel shell instance
*
* This routine spawn a proxy task to create kernel shell instance, and provide
* PTY devcie working together with kernel shell
*
* RETURNS: 0(OK), or -1 if error
*
* ERRNO: N/A
*/
int krnlShellStart
(
int * shellFd
)
{
int shellFdM = 0;
int shellFdS = 0;
char * ptyDevName = NULL;
char taskName[TASK_NAME_LEN]={0};
ptyDevName = wmosMalloc(PTY_NAME_LEN_MAX);
if (NULL == ptyDevName)
return -1;
if (OK != shellCreatePTY(ptyDevName, PTY_NAME_LEN_MAX, &shellFdM, &shellFdS))
return -1;
*shellFd = shellFdM;
snprintf (taskName, TASK_NAME_LEN, "%s_%l.", "krnlShellProxy", taskIdSelf());
if (TASK_ID_ERROR == taskSpawn(
taskName,
kRCC_SERVER_PRIO,
0,
6000,
(FUNCPTR)krnlShellProxy,
(_Vx_usr_arg_t)shellFdS,
(_Vx_usr_arg_t)ptyDevName, 0, 0, 0, 0, 0, 0, 0, 0))
{
close(shellFdM);
close(shellFdS);
ptyDevRemove(ptyDevName);
wmosFree(ptyDevName);
return -1;
}
return 0;
}
/***************************************************************************
*
* printTimeOutMsg - show timeout message
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*
* NOMANUAL
*/
LOCAL STATUS printTimeOutMsg
(
WMB_SESSION_T * pCliEnv
)
{
sbyte4 length;
sbyte *pBuffer = NULL;
sbyte4 timeOut = MCONN_GetTimeOut(pCliEnv);
if (0 == timeOut)
return OK;
length = (sbyte4)wmMax( sizeof(kRCC_MSG_LOGOUT_IDLE),
sizeof(kRCC_MSG_LOGOUT_LEFT) );
length += 18; /* wiggle room */
if (NULL == (pBuffer = (wmMalloc((ubyte4)length))))
return RCC_ERROR_THROW(ERROR_MEMMGR_NO_MEMORY);
sprintf(pBuffer, kRCC_MSG_LOGOUT_IDLE, timeOut/2);
RCC_EXT_WriteStr(pCliEnv, pBuffer);
sprintf(pBuffer, kRCC_MSG_LOGOUT_LEFT, timeOut/2);
RCC_EXT_WriteStr(pCliEnv, pBuffer);
wmFree(pBuffer);
return OK;
}
/****************************************************************************
*
* vxshell - WebCLI command
*
* This routine provides WebCLI the ability of calling VxWorks kernel shell
* by adding such command routine interface "vxshell"
*
* RETURNS: 0(OK), or error
*
* ERRNO: N/A
*/
STATUS wmvxshell
(
cli_env * pCliEnv,
struct paramList * pParams,
sbyte * pAuxBuf
)
{
RLSTATUS status = OK;
int clientFd = -1;
int shellFd = -1;
int maxSock = -1;
int num = -1;
int ret = -1;
fd_set readSet;
char ioBuf[IO_BUFFER_LEN] = {0};
int flag = 0;
struct timeval tv;
sbyte4 timeOut = MCONN_GetTimeOut(pCliEnv);
tv.tv_sec = timeOut/2;
tv.tv_usec = 0;
#ifndef __DISABLE_CLI_INTERRUPT__
RCC_TASK_CancelRead(pCliEnv);
#endif
if (0 <= webcliCheckTaskID(taskIdSelf()))
{
return OK;
}
if (-1 == krnlShellStart(&shellFd))
{
return ERROR_GENERAL;
}
clientFd = pCliEnv->sock;
FD_ZERO(&readSet);
maxSock = clientFd > shellFd?clientFd:shellFd;
for (;;)
{
FD_SET(clientFd, &readSet);
FD_SET(shellFd, &readSet);
num = select(maxSock + 1, &readSet, NULL, NULL, (timeOut==0) ? NULL : &tv);
if (num < 0)
goto exit;
if (num == 0)
{
flag++;
if(flag == 1)
{
printTimeOutMsg(pCliEnv);
continue;
}
MCONN_SetTimeOut(pCliEnv,2);
goto exit;
}
if (num > 0 && FD_ISSET(shellFd, &readSet))
{
flag = 0;
/* Check for activity from shell */
ret = shellDataTranceiver(shellFd, clientFd, ioBuf, 0);
if (ret != 0)
goto exit;
}
if (num > 0 && FD_ISSET(clientFd, &readSet))
{
flag = 0;
/* Check for activity from terminal */
ret = shellDataTranceiver(clientFd, shellFd, ioBuf, 1);
if (ret != 0)
goto exit;
}
}
exit:
if(shellFd >= 0)
close(shellFd);
MCONN_SetRecvState(pCliEnv, kRCC_TS_DATA);
return (status);
}
/****************************************************************************
*
* wmexit - WebCLI command
*
* This routine provides WebCLI the ability of quit current CLI session
*
* RETURNS: STATUS_RCC_LOGOUT
*
* ERRNO: N/A
*/
STATUS wmexit
(
cli_env *pCliEnv,
paramList *pParams,
sbyte *pAuxBuf
)
{
return STATUS_RCC_LOGOUT;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,183 @@
<?xml version="1.0"?>
<base_rc_project
version_major="4"
version_minor="00"
output_location=".\"
output_locationH=".\"
output_locationP=".\">
<enabled_blades>
<blade type="RCCLI"/>
</enabled_blades>
<workspace
project_name="commands"
component_name=""
parent_name=""
dirC=".\"
dirH=".\"
dirP=".\"
main="false"
inibld="true"
iniunq="true"
eol="false"
warn_prm="false"
warn_var="false"
subproj="false">
<wmbcons_lst>
<wmbcons
name="Cli"
agnt="true"
clnt="false"
dyn="false"
stc="true"
mode=""
alone=""
cgfile=""/>
<wmbcons
name="Mib"
agnt="false"
clnt="false"
dyn="false"
stc="false"
mode=""
alone=""
cgfile=""/>
<wmbcons
name="Web"
agnt="false"
clnt="false"
dyn="false"
stc="false"
mode=""
alone="false"
cgfile=""/>
<wmbcons
name="Nvm"
agnt=""
clnt=""
dyn=""
stc=""
mode="none"
alone=""
cgfile=""/>
</wmbcons_lst>
<subproj_lst>
</subproj_lst>
<proj_lst>
</proj_lst>
</workspace>
<options_h>
<system_specifications>
<os
type="vxworks"
kWmosThreadCreateOptions="0"
prop_os_flag=""/>
<compiler
sbyte="char"
sbyte2="short"
sbyte4="int"
ubyte="unsigned_char"
ubyte2="unsigned_short"
ubyte4="unsigned_int"/>
<hardware
endianness="little"
hw_ticks="sysClkRateGet()"/>
</system_specifications>
<general_configuration
dflt_hnd=""
dflt_lck=""
dflt_udo=""
dflt_tim=""
dflt_pri="">
<rapidmark_options
underlying_struct="hash_table"
rapidmark_buffer_size="1000"
delimiter="default_delim"/>
<server
threading="multi"
enable_thread_pool="false"
max_pool_threads="4"
enable_ssl="false"/>
<memory_management
manager="RLI"
initial_size="125000"/>
<lan_filtering
enabled="false"
callback_filter_enabled_handler="Custom_CheckIpFilterEnabled"
callback_filter_check_handler="Custom_CheckIpFilterAddress"/>
<mibway
enabled="false"
snmp_agent="envoy"/>
<image_size
disable_structures="false"
use_local_libraries="false"
file_sys_enable="true"/>
<backplane_config
enable="true"
name="publicWMB"
componentmax="20"
resourcemax="1000"
parentname=""
pipe="false"
port="false"
portnumber=""
timeout=""
deregcookie="NULL"
dereghdlr="NULL"/>
<component_config
name=""
path=""
reghdlr=""
dereghdlr=""
deregcookie="NULL"
regnaming="single"/>
<producer_config
hide="false"
local="false"
defhnd=""/>
<consumer_config timeout=""/>
<event_config select="none"/>
<code_gen tmplt_file=""/>
<ip_support stack="ipv4"/>
</general_configuration>
<security_preferences
access_level="Access_08_08"
access_options="N=2 D=| T=Guest|Admin|"
javascript_digest="false"
model="access">
<group_list>
</group_list>
<view_list>
</view_list>
</security_preferences>
<file_manager
filemgr_enb="false"
dir_enb="false"
dir_dflt="/tgtsvr/"
dir_len="256"/>
<dbg_list>
</dbg_list>
<future_extensions xml:space="">
#define __ENABLE_WMB_USERS__
#define __ENABLE_SESSION_DIRECTORIES__
#define __ANSI_FILE_MANAGER_ENABLED__
#undef __ENABLE_MEMMGR_DEBUG__
#undef __WM_DEBUG__
/*#define kRCC_DEFAULT_PATH &quot;/tgtsvr/&quot;
*/
</future_extensions>
</options_h>
<function_templates output_location=".\ansi.c"/>
<ignition_c
output_location=".\"
output_locationH=".\"
output_locationP=".\">
<header_list>
</header_list>
<custom_variable_type_list>
</custom_variable_type_list>
<rapidmark_list>
</rapidmark_list>
<windgroup_list>
</windgroup_list>
</ignition_c>
</base_rc_project>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,472 @@
<?xml version="1.0"?>
<!--This Document Type Definition (DTD) describes the layout of the base WindManage
project file. This project was originally generated by the GUI-based
WindManage Integration Tool (WMIT), and can be used by either the WMIT or
by any console tool that requires a project file.
The DTD is included below so that this project file is completely standalone. In
addition, the DTD provides guidance on how to modify the project file, should you
want to modify the file by hand. If you modify the file properly, you should be
able to open it with the WMIT, and you should be able to feed it into any console
tool.
To properly modify the file, be sure that any modifications you make follow
the element and attribute rules specified below. For example,
the element "mibway" has the attribute "enabled", and "enabled" must be either
"true" or "false", as specified by the DTD. Therefore, in the actual project
listing below the DTD, in the "mibway" element, you must either have "true" or
"false" listed for the "enabled" attribute. "TRUE", or "True", or "not true" or
something to that effect, is invalid. Note that XML is case-sensitive.
As a general precaution, you should probably run any modifications you make through
an XML validator, before you try and load the file into one of our tools. The
validators provide you with good line-character information for any errors.
A reasonably good free validator can be found on the Microsoft site, at the url:
"http://msdn.microsoft.com/downloads/samples/internet/xml/xml_validator/default.asp".
NOTE THAT YOU CANNOT MODIFY THE DTD. The WindManage tool suite parsing code is
geared to follow this and only this DTD. So if you modify the DTD, ugly things
might happen.
NOTE ALSO THAT THIS FILE IS GENERATED FROM SCRATCH EACH TIME YOU SAVE IT FROM
THE WMIT. That means you "COMMENT OUT" THINGS AT YOUR OWN RISK. You can put
XML comment delimiters around a given WindMark specification, and the WMIT
and the console tools won't read in a commented out WindMark when they open
the project. However, if you go to save the project file again from the WMIT,
the commented out code will disappear and you will have lost the data.
Lastly, we've tried to make the text below easy to modify for both novice and power
users. The elements and attributes that are seldom modified, such as those in
options_h, typically have long names, to make them easier to identify at first
glance. Elements and attributes that are heavily modified, such as WindMark
characteristics, have shorter names so the attribute doesn't dominate your
text editor.
As a compromise though, the elements and attributes with short, non-intuitive names
have a comment above their DTD specification, so that you could refer back to
that comment if necessary.
-->
<!DOCTYPE base_rc_project [
<!ELEMENT base_rc_project ( enabled_blades, workspace, options_h, function_templates,
ignition_c )>
<!ATTLIST base_rc_project version_major CDATA #REQUIRED>
<!ATTLIST base_rc_project version_minor CDATA #REQUIRED>
<!ATTLIST base_rc_project output_location CDATA #REQUIRED>
<!ATTLIST base_rc_project output_locationH CDATA #REQUIRED>
<!ATTLIST base_rc_project output_locationP CDATA #REQUIRED>
<!ELEMENT enabled_blades ( blade+ )>
<!ELEMENT blade EMPTY >
<!ATTLIST blade type ( RCW | RCA | RCCLI | RCM ) #REQUIRED>
<!ELEMENT workspace (wmbcons_lst, subproj_lst, proj_lst)>
<!ATTLIST workspace project_name CDATA #REQUIRED>
<!ATTLIST workspace component_name CDATA #REQUIRED>
<!ATTLIST workspace parent_name CDATA #REQUIRED>
<!ATTLIST workspace dirC CDATA #REQUIRED>
<!ATTLIST workspace dirH CDATA #REQUIRED>
<!ATTLIST workspace dirP CDATA #REQUIRED>
<!ATTLIST workspace main CDATA #REQUIRED>
<!ATTLIST workspace inibld CDATA #REQUIRED>
<!ATTLIST workspace iniunq CDATA #REQUIRED>
<!ATTLIST workspace eol CDATA #REQUIRED>
<!ATTLIST workspace subproj CDATA #REQUIRED>
<!ELEMENT wmbcons_lst ( wmbcons* )>
<!ATTLIST workspace project_name CDATA #REQUIRED>
<!ELEMENT wmbcons EMPTY>
<!ATTLIST wmbcons name CDATA #REQUIRED>
<!ATTLIST wmbcons agnt CDATA "">
<!ATTLIST wmbcons clnt CDATA "">
<!ATTLIST wmbcons dyn CDATA "">
<!ATTLIST wmbcons stc CDATA "">
<!ATTLIST wmbcons mode CDATA "">
<!ATTLIST wmbcons alone CDATA "">
<!ATTLIST wmbcons cgfile CDATA "">
<!ELEMENT subproj_lst (subproj*) >
<!ELEMENT subproj EMPTY >
<!ATTLIST subproj name CDATA #REQUIRED>
<!ELEMENT proj_lst (proj*) >
<!ELEMENT proj EMPTY>
<!ATTLIST proj name CDATA #REQUIRED>
<!ATTLIST proj view CDATA #REQUIRED>
<!ELEMENT options_h (system_specifications, general_configuration,
security_preferences, file_manager, dbg_list, future_extensions )>
<!ELEMENT system_specifications ( os, compiler, hardware )>
<!ELEMENT os EMPTY>
<!ATTLIST os type ( proprietary | vxworks | vxworks_ae |
bsd_os | win32 | posix ) #REQUIRED>
<!ATTLIST os prop_os_flag CDATA "__CUSTOMER_SPECIFIC_OS__">
<!ELEMENT compiler EMPTY>
<!ATTLIST compiler sbyte ( char | Byte | byte ) #REQUIRED>
<!ATTLIST compiler sbyte2 ( short | int ) #REQUIRED>
<!ATTLIST compiler sbyte4 ( long | int ) #REQUIRED>
<!ATTLIST compiler ubyte ( unsigned_char | Byte | byte ) #REQUIRED>
<!ATTLIST compiler ubyte2 ( unsigned_short | unsigned_int ) #REQUIRED>
<!ATTLIST compiler ubyte4 ( unsigned_int | unsigned_long ) #REQUIRED>
<!ELEMENT hardware EMPTY>
<!ATTLIST hardware endianness ( big | little ) #REQUIRED>
<!ATTLIST hardware hw_ticks CDATA #REQUIRED>
<!ELEMENT general_configuration ( rapidmark_options, server, memory_management,
lan_filtering, mibway, image_size,
backplane_config, component_config, producer_config, consumer_config, event_config, code_gen, ip_support )>
<!ATTLIST general_configuration dflt_hnd CDATA #REQUIRED>
<!ATTLIST general_configuration dflt_lck CDATA #REQUIRED>
<!ATTLIST general_configuration dflt_udo CDATA #REQUIRED>
<!ATTLIST general_configuration dflt_tim CDATA #REQUIRED>
<!ATTLIST general_configuration dflt_pri CDATA #REQUIRED>
<!ELEMENT rapidmark_options EMPTY>
<!ATTLIST rapidmark_options underlying_struct (array | hash_table |
binary_tree) #REQUIRED>
<!ATTLIST rapidmark_options rapidmark_buffer_size CDATA #REQUIRED>
<!ATTLIST rapidmark_options delimiter ( default_delim | bracket_delim) #REQUIRED>
<!ELEMENT server EMPTY>
<!ATTLIST server threading (single | multi) #REQUIRED>
<!ATTLIST server enable_thread_pool (true | false) #REQUIRED>
<!ATTLIST server max_pool_threads CDATA #REQUIRED>
<!ATTLIST server enable_ssl (true | false) #REQUIRED>
<!ELEMENT memory_management EMPTY>
<!ATTLIST memory_management manager (RLI | host) #REQUIRED>
<!ATTLIST memory_management initial_size CDATA #REQUIRED>
<!ELEMENT lan_filtering EMPTY>
<!ATTLIST lan_filtering enabled (true | false) #REQUIRED>
<!ATTLIST lan_filtering callback_filter_enabled_handler CDATA #REQUIRED>
<!ATTLIST lan_filtering callback_filter_check_handler CDATA #REQUIRED>
<!ELEMENT mibway EMPTY>
<!ATTLIST mibway enabled (true | false) #REQUIRED>
<!ATTLIST mibway snmp_agent ( envoy | envoy_m_sa ) #REQUIRED>
<!ELEMENT image_size EMPTY >
<!ATTLIST image_size disable_structures (true | false) #REQUIRED>
<!ATTLIST image_size use_local_libraries (true | false) #REQUIRED>
<!ATTLIST image_size file_sys_enable (true | false) #REQUIRED>
<!ELEMENT backplane_config EMPTY >
<!ATTLIST backplane_config enable CDATA #REQUIRED>
<!ATTLIST backplane_config name CDATA #REQUIRED>
<!ATTLIST backplane_config componentmax CDATA #REQUIRED>
<!ATTLIST backplane_config resourcemax CDATA #REQUIRED>
<!ATTLIST backplane_config parentname CDATA #REQUIRED>
<!ATTLIST backplane_config pipe CDATA #REQUIRED>
<!ATTLIST backplane_config port CDATA #REQUIRED>
<!ATTLIST backplane_config portnumber CDATA #REQUIRED>
<!ATTLIST backplane_config timeout CDATA #REQUIRED>
<!ATTLIST backplane_config deregcookie CDATA #REQUIRED>
<!ATTLIST backplane_config dereghdlr CDATA #REQUIRED>
<!ELEMENT component_config EMPTY >
<!ATTLIST component_config name CDATA #REQUIRED>
<!ATTLIST component_config path CDATA #REQUIRED>
<!ATTLIST component_config reghdlr CDATA #REQUIRED>
<!ATTLIST component_config dereghdlr CDATA #REQUIRED>
<!ATTLIST component_config deregcookie CDATA #REQUIRED>
<!ATTLIST component_config regnaming CDATA #REQUIRED>
<!ELEMENT producer_config EMPTY >
<!ATTLIST producer_config hide CDATA #REQUIRED>
<!ATTLIST producer_config local CDATA #REQUIRED>
<!ATTLIST producer_config defhnd CDATA #REQUIRED>
<!ELEMENT consumer_config EMPTY >
<!ATTLIST consumer_config timeout CDATA #REQUIRED>
<!ELEMENT event_config EMPTY >
<!ATTLIST event_config select CDATA #REQUIRED>
<!ELEMENT code_gen EMPTY >
<!ATTLIST code_gen tmplt_file CDATA #REQUIRED>
<!ELEMENT ip_support EMPTY >
<!ATTLIST ip_support stack (ipv4 | ipv4_6) #REQUIRED>
<!ELEMENT security_preferences (group_list, view_list) >
<!ATTLIST security_preferences model (access | view) #REQUIRED>
<!ATTLIST security_preferences access_level CDATA #REQUIRED>
<!ATTLIST security_preferences access_options CDATA #REQUIRED>
<!ELEMENT group_list (group*) >
<!ELEMENT group EMPTY >
<!ATTLIST group name CDATA #REQUIRED>
<!ELEMENT view_list (view*) >
<!ELEMENT view EMPTY >
<!ATTLIST view name CDATA #REQUIRED>
<!ELEMENT file_manager EMPTY>
<!ATTLIST file_manager filemgr_enb (true | false) #REQUIRED>
<!ATTLIST file_manager dir_enb (true | false) #REQUIRED>
<!ATTLIST file_manager dir_dflt CDATA #REQUIRED>
<!ATTLIST file_manager dir_len CDATA #REQUIRED>
<!ELEMENT dbg_list (dbg*) >
<!ELEMENT dbg EMPTY >
<!ATTLIST dbg def CDATA #REQUIRED>
<!ELEMENT future_extensions (#PCDATA)>
<!ATTLIST future_extensions xml:space (default | preserve) "preserve">
<!ELEMENT function_templates EMPTY>
<!ATTLIST function_templates output_location CDATA #REQUIRED>
<!ELEMENT ignition_c ( header_list, custom_variable_type_list,
rapidmark_list, windgroup_list )>
<!ATTLIST ignition_c output_location CDATA "">
<!ATTLIST ignition_c output_locationH CDATA "">
<!ATTLIST ignition_c output_locationP CDATA "">
<!--This is the list of C header files that should be #included in
any builds of wmb_*.c.
-->
<!ELEMENT header_list ( header* )>
<!ELEMENT header EMPTY>
<!ATTLIST header name CDATA #REQUIRED>
<!--This is the list of custom variable types, should you want to
be able to reuse any glue-code routines.
vt - Variable type
name - The name of the variable type, such as ipaddress
parent - The name of the built-in type from which this is derived
validstr- The descriptor/valiadtion string
notes - Notes about this type
-->
<!ELEMENT custom_variable_type_list ( vt* )>
<!ELEMENT vt (#PCDATA)>
<!ATTLIST vt name CDATA #REQUIRED>
<!ATTLIST vt parent CDATA #REQUIRED>
<!ATTLIST vt validstr CDATA #REQUIRED>
<!ATTLIST vt notes CDATA #REQUIRED>
<!ATTLIST vt xml:space (default | preserve) "preserve">
<!--This is our list of WindMarks.
-->
<!ELEMENT rapidmark_list ( rm* )>
<!ELEMENT rm EMPTY>
<!ATTLIST rm name CDATA #REQUIRED>
<!ATTLIST rm vt CDATA #REQUIRED>
<!ATTLIST rm c_vt CDATA #REQUIRED>
<!ATTLIST rm perm ( readonly | readwrite ) #REQUIRED>
<!ATTLIST rm rl CDATA #REQUIRED>
<!ATTLIST rm wl CDATA #REQUIRED>
<!ATTLIST rm grp CDATA #REQUIRED>
<!ATTLIST rm dc CDATA #REQUIRED>
<!ATTLIST rm dct CDATA #REQUIRED>
<!ATTLIST rm group CDATA #REQUIRED>
<!ATTLIST rm hdlr CDATA #REQUIRED>
<!ATTLIST rm oid CDATA #REQUIRED>
<!ATTLIST rm validstr CDATA #REQUIRED>
<!ATTLIST rm alt CDATA #REQUIRED>
<!ATTLIST rm issub CDATA "" >
<!ATTLIST rm hidden CDATA #REQUIRED>
<!ATTLIST rm imply CDATA #REQUIRED>
<!ATTLIST rm index CDATA #REQUIRED>
<!ATTLIST rm rw CDATA #REQUIRED>
<!ATTLIST rm nvm CDATA #REQUIRED>
<!ATTLIST rm defval CDATA #REQUIRED>
<!ATTLIST rm defidx CDATA #REQUIRED>
<!ATTLIST rm hndtyp CDATA #REQUIRED>
<!ATTLIST rm lock CDATA #REQUIRED>
<!ATTLIST rm undo CDATA #REQUIRED>
<!ATTLIST rm time CDATA #REQUIRED>
<!ATTLIST rm prty CDATA #REQUIRED>
<!ATTLIST rm hndcfg CDATA #REQUIRED>
<!ATTLIST rm notes CDATA #REQUIRED>
<!ELEMENT windgroup_list ( wg* )>
<!ELEMENT wg ( member_list ) >
<!ATTLIST wg name CDATA #REQUIRED>
<!ATTLIST wg type CDATA #REQUIRED>
<!ATTLIST wg struct CDATA #REQUIRED>
<!ATTLIST wg oid CDATA #REQUIRED>
<!ATTLIST wg hdlr CDATA #REQUIRED>
<!ATTLIST wg hndtyp CDATA #REQUIRED>
<!ATTLIST wg lock CDATA #REQUIRED>
<!ATTLIST wg undo CDATA #REQUIRED>
<!ATTLIST wg time CDATA #REQUIRED>
<!ATTLIST wg prty CDATA #REQUIRED>
<!ATTLIST wg hndcfg CDATA #REQUIRED>
<!ELEMENT member_list ( m_wg* )>
<!ELEMENT m_wg EMPTY>
<!ATTLIST m_wg name CDATA #REQUIRED>
<!ATTLIST m_wg idx CDATA #REQUIRED>
<!ATTLIST m_wg field CDATA #REQUIRED>
<!ATTLIST m_wg mode CDATA #REQUIRED>
]>
<base_rc_project
version_major="4"
version_minor="00"
output_location=".\"
output_locationH=".\"
output_locationP=".\">
<enabled_blades>
<blade type="RCCLI" />
</enabled_blades>
<workspace project_name="debug" component_name="" parent_name="publicWMB" dirC=".\" dirH=".\" dirP=".\" main="false" inibld="true" iniunq="true" eol="false" subproj="false">
<wmbcons_lst>
<wmbcons name="Cli" agnt="true" clnt="false" dyn="false" stc="true" />
<wmbcons name="Mib" agnt="false" clnt="false" dyn="false" stc="false" />
<wmbcons name="Web" agnt="false" clnt="false" alone="false" dyn="false" stc="false" />
<wmbcons name="Nvm" mode="none" cgfile="" />
</wmbcons_lst>
<subproj_lst>
</subproj_lst>
<proj_lst>
</proj_lst>
</workspace>
<options_h>
<system_specifications>
<os
type="vxworks"
prop_os_flag="__VXWORKS_OS__" />
<compiler
sbyte="char"
sbyte2="short"
sbyte4="int"
ubyte="unsigned_char"
ubyte2="unsigned_short"
ubyte4="unsigned_int" />
<hardware
endianness="little"
hw_ticks="60" />
</system_specifications>
<general_configuration
dflt_hnd=""
dflt_lck=""
dflt_udo=""
dflt_tim=""
dflt_pri="">
<rapidmark_options
underlying_struct="hash_table"
rapidmark_buffer_size="1000"
delimiter="default_delim" />
<server
threading="multi"
enable_thread_pool="false"
max_pool_threads="4"
enable_ssl="false" />
<memory_management
manager="RLI"
initial_size="125000" />
<lan_filtering
enabled="false"
callback_filter_enabled_handler="Custom_CheckIpFilterEnabled"
callback_filter_check_handler="Custom_CheckIpFilterAddress" />
<mibway
enabled="false"
snmp_agent="envoy" />
<image_size
disable_structures="false"
use_local_libraries="false"
file_sys_enable="true" />
<backplane_config
enable="true"
name="publicWMB"
componentmax="20"
resourcemax="1000"
parentname=""
pipe="false"
port="false"
portnumber=""
timeout=""
deregcookie="NULL"
dereghdlr="NULL" />
<component_config
name=""
path=""
reghdlr=""
dereghdlr=""
deregcookie="NULL"
regnaming="single" />
<producer_config
hide="false"
local="false"
defhnd="" />
<consumer_config
timeout="" />
<event_config
select="none" />
<code_gen
tmplt_file="" />
<ip_support
stack="ipv4" />
</general_configuration>
<security_preferences
access_level="Access_16_16"
access_options="N=0 D=| T=|"
model="access">
<group_list>
</group_list>
<view_list>
</view_list>
</security_preferences>
<file_manager filemgr_enb="false" dir_enb="false" dir_dflt="/tgtsvr/" dir_len="256" />
<dbg_list>
<dbg def="#define __RCC_DEBUG__"/>
</dbg_list>
<future_extensions xml:space=""> #define __ENABLE_MEMMGR_DEBUG__
</future_extensions>
</options_h>
<function_templates output_location=".\ansi.c" />
<ignition_c output_location=".\" output_locationH=".\" output_locationP=".\">
<header_list>
</header_list>
<custom_variable_type_list>
</custom_variable_type_list>
<rapidmark_list>
</rapidmark_list>
<windgroup_list>
</windgroup_list>
</ignition_c>
</base_rc_project>
@@ -0,0 +1,612 @@
<?xml version="1.0"?>
<!--This Document Type Definition (DTD) describes the layout of the WindManage for
CLI project file. This project was originally generated by the GUI-based
WindManage Integration Tool (WMIT), and can be used by either the WMIT or
by any console tool that requires a WindManage for CLI project file.
Please refer to the comment in the corresponding base WindManage project for
more information on the DTD below and on how to modify this file.
-->
<!DOCTYPE rcc_project [
<!ELEMENT rcc_project ( general, options_h, custom_param_list, command_node_list)>
<!ATTLIST rcc_project version_major CDATA #REQUIRED>
<!ATTLIST rcc_project version_minor CDATA #REQUIRED>
<!ELEMENT general (cli_h_preamble, cli_c_preamble, hnd_preamble, custom_flag_list)>
<!ATTLIST general dirH CDATA #REQUIRED>
<!ATTLIST general dirC CDATA #REQUIRED>
<!ATTLIST general dirP CDATA #REQUIRED>
<!ATTLIST general access_options CDATA #REQUIRED>
<!ELEMENT cli_h_preamble (#PCDATA)>
<!ATTLIST cli_h_preamble xml:space (default | preserve) "preserve">
<!ELEMENT cli_c_preamble (#PCDATA)>
<!ATTLIST cli_c_preamble xml:space (default | preserve) "preserve">
<!ELEMENT hnd_preamble (#PCDATA)>
<!ATTLIST hnd_preamble xml:space (default | preserve) "preserve">
<!ELEMENT custom_flag_list ( cfl* )>
<!ELEMENT cfl EMPTY>
<!ATTLIST cfl name CDATA #REQUIRED>
<!ATTLIST cfl flag CDATA #REQUIRED>
<!ELEMENT options_h (telnet, login, shell, command, system, display, help, future_extensions)>
<!ELEMENT telnet EMPTY>
<!ATTLIST telnet port CDATA #REQUIRED>
<!ATTLIST telnet thread_stack_size CDATA #REQUIRED>
<!ATTLIST telnet server_priority CDATA #REQUIRED>
<!ATTLIST telnet timeout CDATA #REQUIRED>
<!ELEMENT login EMPTY>
<!ATTLIST login maximum CDATA #REQUIRED>
<!ATTLIST login length CDATA #REQUIRED>
<!ATTLIST login password_length CDATA #REQUIRED>
<!ATTLIST login prompt CDATA #REQUIRED>
<!ATTLIST login password_prompt CDATA #REQUIRED>
<!ELEMENT shell EMPTY>
<!ATTLIST shell number_history CDATA #REQUIRED>
<!ATTLIST shell default_prompt CDATA #REQUIRED>
<!ATTLIST shell alias_buf_size CDATA #REQUIRED>
<!ATTLIST shell alias_count CDATA #REQUIRED>
<!ATTLIST shell modal_history (true | false) #REQUIRED>
<!ATTLIST shell unlimited_history (true | false) #REQUIRED>
<!ATTLIST shell enable_scripting (true | false) #REQUIRED>
<!ATTLIST shell enable_stdio (true | false) #REQUIRED>
<!ELEMENT command EMPTY>
<!ATTLIST command prompt_length CDATA #REQUIRED>
<!ATTLIST command length CDATA #REQUIRED>
<!ATTLIST command output_buffer_size CDATA #REQUIRED>
<!ATTLIST command enable_console ( true | false ) #REQUIRED>
<!ATTLIST command exec_leaf_only ( true | false ) #REQUIRED>
<!ATTLIST command no_inter_mode ( true | false ) #REQUIRED>
<!ATTLIST command strict_no_hdlr ( true | false ) #REQUIRED>
<!ATTLIST command no_retry ( true | false ) #REQUIRED>
<!ELEMENT system EMPTY>
<!ATTLIST system maximum_task CDATA #REQUIRED>
<!ATTLIST system param_order (None | Unnamed | Full) #REQUIRED>
<!ELEMENT display EMPTY>
<!ATTLIST display hard_wrap ( true | false ) #REQUIRED>
<!ATTLIST display no_pause ( true | false ) #REQUIRED>
<!ATTLIST display scroll_long_line ( true | false ) #REQUIRED>
<!ATTLIST display dash_error_line ( true | false ) #REQUIRED>
<!ATTLIST display no_vt_esc ( true | false ) #REQUIRED>
<!ELEMENT help EMPTY>
<!ATTLIST help show_all_params ( true | false ) #REQUIRED>
<!ATTLIST help no_formatting ( true | false ) #REQUIRED>
<!ATTLIST help show_no ( true | false ) #REQUIRED>
<!ATTLIST help hide_blanks ( true | false ) #REQUIRED>
<!ATTLIST help show_next_only ( true | false ) #REQUIRED>
<!ATTLIST help show_exec ( true | false ) #REQUIRED>
<!ATTLIST help skip_node ( true | false ) #REQUIRED>
<!ATTLIST help self_help ( true | false ) #REQUIRED>
<!ATTLIST help error_help ( true | false ) #REQUIRED>
<!ATTLIST help leaf_param_only ( true | false ) #REQUIRED>
<!ELEMENT future_extensions (#PCDATA)>
<!ATTLIST future_extensions xml:space (default | preserve) "preserve">
<!ELEMENT custom_param_list (cp*)>
<!ELEMENT cp (#PCDATA)>
<!ATTLIST cp typename CDATA #REQUIRED>
<!ATTLIST cp typebase (null |
char | unsigned_char |
short | unsigned_short |
integer | unsigned_integer |
long | unsigned_long |
ip_address | mac_address |
enumerate | list |
string | absolute ) #REQUIRED>
<!ATTLIST cp validstr CDATA #REQUIRED>
<!ATTLIST cp accessstr CDATA #REQUIRED>
<!ATTLIST cp defaultstr CDATA #REQUIRED>
<!ATTLIST cp customvalid CDATA #REQUIRED>
<!ATTLIST cp convert2base CDATA #REQUIRED>
<!ATTLIST cp helpmethod (0 | 1) #REQUIRED>
<!ATTLIST cp helpstr CDATA #REQUIRED>
<!ATTLIST cp helphandler CDATA #REQUIRED>
<!ELEMENT parameter_list ( pd* )>
<!ELEMENT pd (#PCDATA)>
<!ATTLIST pd keyword CDATA #REQUIRED>
<!ATTLIST pd type (null |
char | unsigned_char |
short | unsigned_short |
integer | unsigned_integer |
long | unsigned_long |
ip_address | mac_address |
enumerate | list |
string | absolute ) #REQUIRED>
<!ATTLIST pd set_rapidmark CDATA #REQUIRED>
<!ATTLIST pd paramnum CDATA #REQUIRED>
<!ATTLIST pd nokeyword CDATA #REQUIRED>
<!ATTLIST pd typename CDATA #REQUIRED>
<!ATTLIST pd validstr CDATA #REQUIRED>
<!ATTLIST pd accessstr CDATA #REQUIRED>
<!ATTLIST pd defaultstr CDATA #REQUIRED>
<!ATTLIST pd customvalid CDATA #REQUIRED>
<!ATTLIST pd helpmethod (0 | 1) #REQUIRED>
<!ATTLIST pd helpstr CDATA #REQUIRED>
<!ATTLIST pd helphandler CDATA #REQUIRED>
<!ATTLIST pd convert2base CDATA #REQUIRED>
<!ELEMENT handler_param_order ( ho* )>
<!ELEMENT ho EMPTY>
<!ATTLIST ho paramnam CDATA #REQUIRED>
<!ATTLIST ho paramnum CDATA #REQUIRED>
<!ATTLIST ho type (required | optional) #REQUIRED>
<!ELEMENT inv_hdlr_params ( vp* )>
<!ELEMENT vp EMPTY>
<!ATTLIST vp paramnam CDATA #REQUIRED>
<!ATTLIST vp type (Iterative | Guiding | Value | Other) #REQUIRED>
<!ELEMENT handler_list ( hd* )>
<!ELEMENT hd (#PCDATA | handler_param_order | inv_hdlr_params)*>
<!ATTLIST hd req_param_mask CDATA #REQUIRED>
<!ATTLIST hd opt_param_mask CDATA #REQUIRED>
<!ATTLIST hd type CDATA #REQUIRED>
<!ATTLIST hd func CDATA #REQUIRED>
<!ATTLIST hd enable_cfg_dump ( true | false ) #REQUIRED>
<!ATTLIST hd xml:space (default | preserve) "preserve">
<!ELEMENT command_node_list ( command_node* )>
<!ELEMENT command_node ( parameter_list, handler_list, command_node_list, get_rapidmark_list, custflag_list )>
<!ATTLIST command_node keyword CDATA #REQUIRED>
<!ATTLIST command_node helpmethod (0 | 1) #REQUIRED>
<!ATTLIST command_node help CDATA #REQUIRED>
<!ATTLIST command_node helphandler CDATA #REQUIRED>
<!ATTLIST command_node mode_support ( true | false ) #REQUIRED>
<!ATTLIST command_node prompt_string CDATA #REQUIRED>
<!ATTLIST command_node access_level CDATA #REQUIRED>
<!ATTLIST command_node partition CDATA #REQUIRED>
<!ATTLIST command_node allow_no_form ( true | false ) #REQUIRED>
<!ATTLIST command_node inherit_rapidmarks ( true | false ) #REQUIRED>
<!ATTLIST command_node global_node ( true | false ) #REQUIRED>
<!ATTLIST command_node no_generate ( true | false ) #REQUIRED>
<!ATTLIST command_node meta_node ( true | false ) #REQUIRED>
<!ATTLIST command_node queue_node ( true | false ) #REQUIRED>
<!ATTLIST command_node nolink_node ( true | false ) #REQUIRED>
<!ATTLIST command_node no_exec ( true | false ) #REQUIRED>
<!ATTLIST command_node fallthrough ( true | false ) #REQUIRED>
<!ATTLIST command_node ignore ( true | false ) #REQUIRED>
<!ATTLIST command_node no_to_all ( true | false ) #REQUIRED>
<!ATTLIST command_node show_next ( true | false ) #REQUIRED>
<!ATTLIST command_node exact_node ( true | false ) #REQUIRED>
<!ATTLIST command_node exact_param ( true | false ) #REQUIRED>
<!ATTLIST command_node bind_param ( true | false ) #REQUIRED>
<!ATTLIST command_node leaf_only ( true | false ) #REQUIRED>
<!ATTLIST command_node function ( true | false ) #REQUIRED>
<!ATTLIST command_node operator ( true | false ) #REQUIRED>
<!ATTLIST command_node raw ( true | false ) #REQUIRED>
<!ELEMENT get_rapidmark_list ( rm* )>
<!ELEMENT rm EMPTY>
<!ATTLIST rm name CDATA #REQUIRED>
<!ELEMENT custflag_list ( cf* )>
<!ELEMENT cf EMPTY>
<!ATTLIST cf flag CDATA #REQUIRED>
]>
<rcc_project
version_major="4"
version_minor="00">
<workspace
project_name="files"
component_name=""
parent_name="publicWMB"
dirC=".\"
dirH=".\"
dirP=".\"
main="false"
inibld="true"
iniunq="true"
eol="false"
warn_prm="false"
warn_var="false"
subproj="false">
<wmbcons_lst>
<wmbcons name="Cli" agnt="true" clnt="false" dyn="false" stc="true" />
<wmbcons name="Nvm" mode="none" cgfile="" />
</wmbcons_lst>
<subproj_lst>
</subproj_lst>
<proj_lst>
</proj_lst>
</workspace>
<general project="files" dirH=".\" dirC=".\" dirP=".\" parentWmb="publicWMB" compname="" sec_model="access" access_options="N=0 D=| T=|" def_dir="kDIR_DEFAULT_PATH" auto_exec="">
<cli_h_preamble>
#include &quot;rcc.h&quot; </cli_h_preamble>
<cli_c_preamble>
#include &quot;rcc.h&quot; </cli_c_preamble>
<hnd_preamble>
#include &quot;rcc.h&quot; </hnd_preamble>
<custom_flag_list>
<cfl name="Custom1" flag="kRCC_COMMAND_CUSTOM1" />
<cfl name="Custom2" flag="kRCC_COMMAND_CUSTOM2" />
<cfl name="Custom3" flag="kRCC_COMMAND_CUSTOM3" />
</custom_flag_list>
<code_gen tmplt_file=""/>
</general>
<options_h>
<future_extensions>
</future_extensions>
<telnet
port="23"
thread_stack_size="5000"
server_priority="100"
timeout="1800" />
<login
maximum="5"
length="16"
password_length="5"
prompt="Login:"
password_prompt="Password:"
auth_callback="myRCC_TASK_ValidateLogin"/>
<shell
number_history="30"
default_prompt="CLI"
default_prompt_tail="# "
alias_buf_size="1024"
alias_count="32"
modal_history="false"
unlimited_history="false"
enable_scripting="false"
enable_stdio="false" />
<command
prompt_length="16"
length="256"
output_buffer_size="kMagicMarkupBufferSize"
enable_console="true"
exec_leaf_only="false"
no_inter_mode="false"
strict_no_hdlr="false"
no_retry="false"
hide_priv="false"/>
<system
maximum_task="7"
param_order="Full" />
<display
hard_wrap="false"
no_pause="false"
scroll_long_line="false"
dash_error_line="false"
no_vt_esc="false" />
<help
show_all_params="false"
no_formatting="false"
show_no="false"
hide_blanks="false"
show_more_than_next="false"
show_next_only="false"
show_exec="false"
skip_node="false"
self_help="false"
error_help="false"
leaf_param_only="false" />
</options_h>
<custom_param_list>
</custom_param_list>
<command_node_list>
<command_node keyword="cat" helpmethod="0" help="Display contents of a file" helphandler="" mode_support="false" prompt_string="" access_level="0" grp="" allow_no_form="false" inherit_rapidmarks="false" global_node="true" no_generate="false" meta_node="false" queue_node="false" nolink_node="false" partition="" no_exec="false" fallthrough="false" ignore="false" no_to_all="false" show_next="false" exact_node="false" exact_param="false" bind_param="false" leaf_only="false" function="false" operator="false" raw="false">
<parameter_list>
<pd keyword="filename" type="string" set_rapidmark="" paramnum="0" nokeyword="yes" treepos="0x0100" typename="string" validstr="" accessstr="" grp="" defaultstr="" customvalid="" convert2base="No" helpmethod="0" helpstr="file to display" helphandler="">
</pd>
</parameter_list>
<handler_list>
<hd type="0" enable_cfg_dump="false" req_param_mask="0x00000001" opt_param_mask="0x00000000" func="RCC_EXEC_Cat">
extern RLSTATUS
RCC_EXEC_Cat(cli_env *pCliEnv, paramList *pParams, sbyte *pAuxBuf)
{
RLSTATUS status = OK;
sbyte *pFileName = NULL;
paramDescr *pParamDescr;
BOOL isAnsi = FALSE;
sbyte *pFileBuffer = NULL;
sbyte *pLine;
sbyte *pChar;
sbyte4 fileLen = 0;
sbyte4 lineLen;
sbyte4 remainder;
/* get required parameter */
status = RCC_DB_RetrieveParam(pParams, &quot;filename&quot;, mCat_Filename, &amp;pParamDescr );
if ( OK != status )
{
return(status);
} else pFileName= (sbyte*)(pParamDescr-&gt;pValue);
/* TO DO: Add your handler code here */
#ifdef __ANSI_FILE_MANAGER_ENABLED__
pFileBuffer = wmFileReadFile(wmbSessionDirGet(pCliEnv), &amp;fileLen, pFileName);
if (NULL != pFileBuffer)
isAnsi = TRUE;
#endif /* __ANSI_FILE_MANAGER_ENABLED__ */
#ifdef __FILE_MANAGER_ENABLED__
if (NULL == pFileBuffer)
pFileBuffer = FILEMGR_RetrieveFile(&amp;fileLen, pFileName);
#endif /* __FILE_MANAGER_ENABLED__ */
if (NULL == pFileBuffer)
{
/* empty file? */
if (0 == fileLen)
return OK;
else
return ERROR_GENERAL_FILE_NOT_FOUND;
}
pChar = pFileBuffer;
pLine = pFileBuffer;
remainder = fileLen;
while (0 &lt; remainder)
{
lineLen = 0;
while (&apos;\r&apos; != *pChar)
{
pChar++;
lineLen++;
if (0 &gt; --remainder)
break;
}
RCC_EXT_Write(pCliEnv, pLine, lineLen);
RCC_EXT_WriteStrLine(pCliEnv, &quot;&quot;);
/* skip c/r */
pChar++;
remainder--;
pLine += lineLen + 1;
/* skip l/f */
if ((0 &lt; remainder) &amp;&amp; (&apos;\n&apos; == *pChar))
{
pChar++;
pLine++;
remainder--;
}
}
#ifdef __ANSI_FILE_MANAGER_ENABLED__
if (isAnsi)
wmFileReleaseFile(pFileBuffer);
#endif /* __ANSI_FILE_MANAGER_ENABLED__ */
#ifdef __FILE_MANAGER_ENABLED__
if (! isAnsi)
wmFileReleaseFile(pFileBuffer);
#endif /* __FILE_MANAGER_ENABLED__ */
return status;
} <handler_param_order>
<ho paramnam="filename" paramnum="0" type="required" treepos="0x0100" />
</handler_param_order>
<inv_hdlr_params>
</inv_hdlr_params>
</hd>
</handler_list>
<command_node_list>
</command_node_list>
<get_rapidmark_list>
</get_rapidmark_list>
<custflag_list>
</custflag_list>
</command_node>
<command_node keyword="cd" helpmethod="0" help="Change working directory" helphandler="" mode_support="false" prompt_string="" access_level="0" grp="" allow_no_form="false" inherit_rapidmarks="false" global_node="true" no_generate="false" meta_node="false" queue_node="false" nolink_node="false" partition="" no_exec="false" fallthrough="false" ignore="false" no_to_all="false" show_next="false" exact_node="false" exact_param="false" bind_param="false" leaf_only="false" function="false" operator="false" raw="false">
<parameter_list>
<pd keyword="directory" type="string" set_rapidmark="" paramnum="0" nokeyword="yes" treepos="0x0100" typename="string" validstr="" accessstr="" grp="" defaultstr="" customvalid="" convert2base="No" helpmethod="0" helpstr="New directory" helphandler="">
</pd>
</parameter_list>
<handler_list>
<hd type="0" enable_cfg_dump="false" req_param_mask="0x00000001" opt_param_mask="0x00000000" func="RCC_EXEC_Cd">
extern RLSTATUS
RCC_EXEC_Cd(cli_env *pCliEnv, paramList *pParams, sbyte *pAuxBuf)
{
RLSTATUS status = OK;
sbyte *pVal;
paramDescr *pParamDescr;
/* get required parameter */
status = RCC_DB_RetrieveParam(pParams, &quot;directory&quot;, mCd_Directory, &amp;pParamDescr );
if ( OK != status )
{
return(status);
} else pVal = (sbyte*)(pParamDescr-&gt;pValue);
#ifdef __ANSI_FILE_MANAGER_ENABLED__
status = wmFileChdir(wmbSessionDirGet(pCliEnv), pVal);
#endif /* __ANSI_FILE_MANAGER_ENABLED__ */
return status;
} <handler_param_order>
<ho paramnam="directory" paramnum="0" type="required" treepos="0x0100" />
</handler_param_order>
<inv_hdlr_params>
</inv_hdlr_params>
</hd>
</handler_list>
<command_node_list>
</command_node_list>
<get_rapidmark_list>
</get_rapidmark_list>
<custflag_list>
</custflag_list>
</command_node>
<command_node keyword="ls" helpmethod="0" help="List files" helphandler="" mode_support="false" prompt_string="" access_level="0" grp="" allow_no_form="false" inherit_rapidmarks="false" global_node="true" no_generate="false" meta_node="false" queue_node="false" nolink_node="false" partition="" no_exec="false" fallthrough="false" ignore="false" no_to_all="false" show_next="false" exact_node="false" exact_param="false" bind_param="false" leaf_only="false" function="false" operator="false" raw="false">
<parameter_list>
<pd keyword="filemask" type="string" set_rapidmark="" paramnum="0" nokeyword="yes" treepos="0x0100" typename="string" validstr="" accessstr="" grp="" defaultstr="" customvalid="" convert2base="No" helpmethod="0" helpstr="File template" helphandler="">
</pd>
</parameter_list>
<handler_list>
<hd type="0" enable_cfg_dump="false" req_param_mask="0x00000000" opt_param_mask="0x00000001" func="RCC_EXEC_Ls">
extern RLSTATUS
RCC_EXEC_Ls(cli_env *pCliEnv, paramList *pParams, sbyte *pAuxBuf)
{
RLSTATUS status = OK;
#ifdef __ANSI_FILE_MANAGER_ENABLED__
sbyte *pVal = NULL;
paramDescr *pParamDescr;
sbyte *pFileName;
sbyte dirChar;
sbyte4 length;
sbyte4 size;
ubyte4 flags;
sbyte buffer[32];
ubyte4 valLen;
BOOL isDir = FALSE;
/* get optional parameter */
if (OK == RCC_DB_RetrieveParam(pParams, &quot;filemask&quot;, mLs_Filemask, &amp;pParamDescr ))
{
pVal = (sbyte*)(pParamDescr-&gt;pValue);
}
if (OK != (status = wmFileOpenDir(wmbSessionDirGet(pCliEnv), pVal)))
return status;
valLen = STRLEN(pVal);
if (NULL != pVal &amp;&amp; *(pVal+valLen-1) == PATH_CHAR_K)
isDir = TRUE;
while (1)
{
pFileName = wmFileNextDir(wmbSessionDirGet(pCliEnv), &amp;size, &amp;flags);
if (NULL == pFileName)
break;
if (NULL != pVal &amp;&amp; !isDir)
{
if (0 != STRCMP(pVal, pFileName))
continue;
}
wmConvertToStr(&amp;size, buffer, 4, DATATYPE_INTEGER_K);
length = STRLEN(pFileName) + STRLEN(buffer);
dirChar = (flags &amp; FS_DIRECTORY_K) ? kFileSeparator : &apos; &apos;;
RCC_EXT_WriteStr(pCliEnv, pFileName);
RCC_EXT_Write(pCliEnv, &amp;dirChar, 1);
RCC_EXT_PrintString(pCliEnv, &quot;&quot;, 40 - length, &apos; &apos;);
RCC_EXT_WriteStrLine(pCliEnv, buffer);
}
wmFileCloseDir(wmbSessionDirGet(pCliEnv));
#endif /* __ANSI_FILE_MANAGER_ENABLED__ */
return status;
} <handler_param_order>
<ho paramnam="filemask" paramnum="0" type="optional" treepos="0x0100" />
</handler_param_order>
<inv_hdlr_params>
</inv_hdlr_params>
</hd>
</handler_list>
<command_node_list>
</command_node_list>
<get_rapidmark_list>
</get_rapidmark_list>
<custflag_list>
</custflag_list>
</command_node>
<command_node keyword="pwd" helpmethod="0" help="Print working directory" helphandler="" mode_support="false" prompt_string="" access_level="0" grp="" allow_no_form="false" inherit_rapidmarks="false" global_node="true" no_generate="false" meta_node="false" queue_node="false" nolink_node="false" partition="" no_exec="false" fallthrough="false" ignore="false" no_to_all="false" show_next="false" exact_node="false" exact_param="false" bind_param="false" leaf_only="false" function="false" operator="false" raw="false">
<parameter_list>
</parameter_list>
<handler_list>
<hd type="0" enable_cfg_dump="false" req_param_mask="0x00000000" opt_param_mask="0x00000000" func="RCC_EXEC_Pwd">
extern RLSTATUS
RCC_EXEC_Pwd(cli_env *pCliEnv, paramList *pParams, sbyte *pAuxBuf)
{
#ifdef __ENABLE_SESSION_DIRECTORIES__
RCC_EXT_WriteStrLine(pCliEnv, wmbSessionCwdGet(pCliEnv));
#endif /* __ENABLE_SESSION_DIRECTORIES__ */
return OK;
} <handler_param_order>
</handler_param_order>
<inv_hdlr_params>
</inv_hdlr_params>
</hd>
</handler_list>
<command_node_list>
</command_node_list>
<get_rapidmark_list>
</get_rapidmark_list>
<custflag_list>
</custflag_list>
</command_node>
</command_node_list>
</rcc_project>
@@ -0,0 +1,464 @@
<?xml version="1.0"?>
<!--This Document Type Definition (DTD) describes the layout of the base WindManage
project file. This project was originally generated by the GUI-based
WindManage Integration Tool (WMIT), and can be used by either the WMIT or
by any console tool that requires a project file.
The DTD is included below so that this project file is completely standalone. In
addition, the DTD provides guidance on how to modify the project file, should you
want to modify the file by hand. If you modify the file properly, you should be
able to open it with the WMIT, and you should be able to feed it into any console
tool.
To properly modify the file, be sure that any modifications you make follow
the element and attribute rules specified below. For example,
the element "mibway" has the attribute "enabled", and "enabled" must be either
"true" or "false", as specified by the DTD. Therefore, in the actual project
listing below the DTD, in the "mibway" element, you must either have "true" or
"false" listed for the "enabled" attribute. "TRUE", or "True", or "not true" or
something to that effect, is invalid. Note that XML is case-sensitive.
As a general precaution, you should probably run any modifications you make through
an XML validator, before you try and load the file into one of our tools. The
validators provide you with good line-character information for any errors.
A reasonably good free validator can be found on the Microsoft site, at the url:
"http://msdn.microsoft.com/downloads/samples/internet/xml/xml_validator/default.asp".
NOTE THAT YOU CANNOT MODIFY THE DTD. The WindManage tool suite parsing code is
geared to follow this and only this DTD. So if you modify the DTD, ugly things
might happen.
NOTE ALSO THAT THIS FILE IS GENERATED FROM SCRATCH EACH TIME YOU SAVE IT FROM
THE WMIT. That means you "COMMENT OUT" THINGS AT YOUR OWN RISK. You can put
XML comment delimiters around a given WindMark specification, and the WMIT
and the console tools won't read in a commented out WindMark when they open
the project. However, if you go to save the project file again from the WMIT,
the commented out code will disappear and you will have lost the data.
Lastly, we've tried to make the text below easy to modify for both novice and power
users. The elements and attributes that are seldom modified, such as those in
options_h, typically have long names, to make them easier to identify at first
glance. Elements and attributes that are heavily modified, such as WindMark
characteristics, have shorter names so the attribute doesn't dominate your
text editor.
As a compromise though, the elements and attributes with short, non-intuitive names
have a comment above their DTD specification, so that you could refer back to
that comment if necessary.
-->
<!DOCTYPE base_rc_project [
<!ELEMENT base_rc_project ( enabled_blades, options_h, function_templates,
ignition_c )>
<!ATTLIST base_rc_project version_major CDATA #REQUIRED>
<!ATTLIST base_rc_project version_minor CDATA #REQUIRED>
<!ATTLIST base_rc_project output_location CDATA #REQUIRED>
<!ATTLIST base_rc_project output_locationH CDATA #REQUIRED>
<!ATTLIST base_rc_project output_locationP CDATA #REQUIRED>
<!ELEMENT enabled_blades ( blade+ )>
<!ELEMENT blade EMPTY >
<!ATTLIST blade type ( RCW | RCA | RCCLI | MIBway ) #REQUIRED>
<!ELEMENT workspace (wmbcons_lst, subproj_lst, proj_lst)>
<!ATTLIST workspace project_name CDATA #REQUIRED>
<!ATTLIST workspace component_name CDATA #REQUIRED>
<!ATTLIST workspace parent_name CDATA #REQUIRED>
<!ATTLIST workspace dirC CDATA #REQUIRED>
<!ATTLIST workspace dirH CDATA #REQUIRED>
<!ATTLIST workspace dirP CDATA #REQUIRED>
<!ATTLIST workspace main CDATA #REQUIRED>
<!ATTLIST workspace inibld CDATA #REQUIRED>
<!ATTLIST workspace iniunq CDATA #REQUIRED>
<!ATTLIST workspace eol CDATA #REQUIRED>
<!ELEMENT wmbcons_lst ( wmbcons* )>
<!ATTLIST workspace project_name CDATA #REQUIRED>
<!ELEMENT wmbcons EMPTY>
<!ATTLIST wmbcons name CDATA #REQUIRED>
<!ATTLIST wmbcons agnt CDATA #REQUIRED>
<!ATTLIST wmbcons clnt CDATA #REQUIRED>
<!ATTLIST wmbcons dyn CDATA #REQUIRED>
<!ATTLIST wmbcons stc CDATA #REQUIRED>
<!ATTLIST wmbcons alone CDATA "">
<!ELEMENT subproj_lst EMPTY>
<!ATTLIST subproj_lst name CDATA #REQUIRED>
<!ELEMENT proj_lst EMPTY>
<!ATTLIST proj_lst name CDATA #REQUIRED>
<!ATTLIST proj_lst view CDATA #REQUIRED>
<!ELEMENT options_h (system_specifications, general_configuration,
security_preferences, future_extensions )>
<!ELEMENT system_specifications ( os, compiler, hardware )>
<!ELEMENT os EMPTY>
<!ATTLIST os type ( proprietary | vxworks | vxworks_ae |
bsd_os | win32 | posix ) #REQUIRED>
<!ATTLIST os prop_os_flag CDATA "__CUSTOMER_SPECIFIC_OS__">
<!ELEMENT compiler EMPTY>
<!ATTLIST compiler sbyte ( char | Byte | byte ) #REQUIRED>
<!ATTLIST compiler sbyte2 ( short | int ) #REQUIRED>
<!ATTLIST compiler sbyte4 ( long | int ) #REQUIRED>
<!ATTLIST compiler ubyte ( unsigned_char | Byte | byte ) #REQUIRED>
<!ATTLIST compiler ubyte2 ( unsigned_short | unsigned_int ) #REQUIRED>
<!ATTLIST compiler ubyte4 ( unsigned_int | unsigned_long ) #REQUIRED>
<!ELEMENT hardware EMPTY>
<!ATTLIST hardware endianness ( big | little ) #REQUIRED>
<!ATTLIST hardware hw_ticks CDATA #REQUIRED>
<!ELEMENT general_configuration ( rapidmark_options, server, memory_management,
lan_filtering, mibway, image_size,
backplane_config, component_config, producer_config, consumer_config, event_config )>
<!ELEMENT rapidmark_options EMPTY>
<!ATTLIST rapidmark_options underlying_struct (array | hash_table |
binary_tree) #REQUIRED>
<!ATTLIST rapidmark_options rapidmark_buffer_size CDATA #REQUIRED>
<!ATTLIST rapidmark_options delimiter ( default_delim | bracket_delim) #REQUIRED>
<!ELEMENT server EMPTY>
<!ATTLIST server threading (single | multi) #REQUIRED>
<!ATTLIST server enable_thread_pool (true | false) #REQUIRED>
<!ATTLIST server max_pool_threads CDATA #REQUIRED>
<!ELEMENT memory_management EMPTY>
<!ATTLIST memory_management manager (RLI | host) #REQUIRED>
<!ATTLIST memory_management initial_size CDATA #REQUIRED>
<!ELEMENT lan_filtering EMPTY>
<!ATTLIST lan_filtering enabled (true | false) #REQUIRED>
<!ATTLIST lan_filtering callback_filter_enabled_handler CDATA #REQUIRED>
<!ATTLIST lan_filtering callback_filter_check_handler CDATA #REQUIRED>
<!ELEMENT mibway EMPTY>
<!ATTLIST mibway enabled (true | false) #REQUIRED>
<!ATTLIST mibway snmp_agent ( none | envoy | envoy_m_sa | windnet_snmp_bin |
windnet_snmp_src | snmp_v1 | cmu_snmp | other ) #REQUIRED>
<!ELEMENT image_size EMPTY >
<!ATTLIST image_size disable_structures (true | false) #REQUIRED>
<!ATTLIST image_size use_local_libraries (true | false) #REQUIRED>
<!ELEMENT backplane_config EMPTY >
<!ATTLIST backplane_config enable CDATA #REQUIRED>
<!ATTLIST backplane_config name CDATA #REQUIRED>
<!ATTLIST backplane_config componentmax CDATA #REQUIRED>
<!ATTLIST backplane_config resourcemax CDATA #REQUIRED>
<!ATTLIST backplane_config parentname CDATA #REQUIRED>
<!ATTLIST backplane_config pipe CDATA #REQUIRED>
<!ATTLIST backplane_config port CDATA #REQUIRED>
<!ATTLIST backplane_config portnumber CDATA #REQUIRED>
<!ATTLIST backplane_config timeout CDATA #REQUIRED>
<!ATTLIST backplane_config deregcookie CDATA #REQUIRED>
<!ATTLIST backplane_config dereghdlr CDATA #REQUIRED>
<!ELEMENT component_config EMPTY >
<!ATTLIST component_config name CDATA #REQUIRED>
<!ATTLIST component_config path CDATA #REQUIRED>
<!ATTLIST component_config dereghdlr CDATA #REQUIRED>
<!ATTLIST component_config deregcookie CDATA #REQUIRED>
<!ATTLIST component_config regnaming CDATA #REQUIRED>
<!ELEMENT producer_config EMPTY >
<!ATTLIST producer_config hide CDATA #REQUIRED>
<!ATTLIST producer_config local CDATA #REQUIRED>
<!ATTLIST producer_config defhnd CDATA #REQUIRED>
<!ELEMENT consumer_config EMPTY >
<!ATTLIST consumer_config timeout CDATA #REQUIRED>
<!ELEMENT event_config EMPTY >
<!ATTLIST event_config enable CDATA #REQUIRED>
<!ATTLIST event_config hdlr CDATA #REQUIRED>
<!ATTLIST event_config queue CDATA #REQUIRED>
<!ELEMENT security_preferences (group_list, view_list) >
<!ATTLIST security_preferences model (access | view) #REQUIRED>
<!ATTLIST security_preferences access_level CDATA #REQUIRED>
<!ATTLIST security_preferences access_options CDATA #REQUIRED>
<!ELEMENT group_list EMPTY >
<!ATTLIST group_list name CDATA #REQUIRED>
<!ELEMENT view_list EMPTY >
<!ATTLIST view_list name CDATA #REQUIRED>
<!ELEMENT future_extensions (#PCDATA)>
<!ATTLIST future_extensions xml:space (default | preserve) "preserve">
<!ELEMENT function_templates EMPTY>
<!ATTLIST function_templates output_location CDATA #REQUIRED>
<!ELEMENT ignition_c ( header_list, custom_variable_type_list,
struct_desc_list, rapidmark_list )>
<!ATTLIST ignition_c output_location CDATA "">
<!ATTLIST ignition_c output_locationH CDATA "">
<!ATTLIST ignition_c output_locationP CDATA "">
<!--This is the list of C header files that should be #included in
any builds of wmb_*.c.
-->
<!ELEMENT header_list ( header* )>
<!ELEMENT header EMPTY>
<!ATTLIST header name CDATA #REQUIRED>
<!--This is the list of custom variable types, should you want to
be able to reuse any glue-code routines.
vt - Variable type
name - The name of the variable type, such as ipaddress
parent - The name of the built-in type from which this is derived
validstr- The descriptor/valiadtion string
notes - Notes about this type
-->
<!ELEMENT custom_variable_type_list ( vt* )>
<!ELEMENT vt (#PCDATA)>
<!ATTLIST vt name CDATA #REQUIRED>
<!ATTLIST vt parent CDATA #REQUIRED>
<!ATTLIST vt validstr CDATA #REQUIRED>
<!ATTLIST vt notes CDATA #REQUIRED>
<!ATTLIST vt xml:space (default | preserve) "preserve">
<!--This is our list of "structure descriptions". This provides the
tool with knowledge of a particular structure that a WindMark
might be associated with.
sd - Structure description
si - Structure instance
sdecl - Structure declaration
cache - Cache permissions
safun - Structure address function
swfun - Structure write function (optional - may be "")
snfun - Structure 'next' function (optional - may be "")
slfun - Structure lock function (optional - may be "")
sufun - Structure unlock function (optional - may be "")
-->
<!ELEMENT struct_desc_list ( sd* )>
<!ELEMENT sd EMPTY>
<!ATTLIST sd si CDATA #REQUIRED>
<!ATTLIST sd sdecl CDATA #REQUIRED>
<!ATTLIST sd cache (cacheNone | cacheRead |
cacheWrite | cacheReadWrite ) #REQUIRED>
<!ATTLIST sd safun CDATA #REQUIRED>
<!ATTLIST sd swfun CDATA #REQUIRED>
<!ATTLIST sd snfun CDATA #REQUIRED>
<!ATTLIST sd slfun CDATA #REQUIRED>
<!ATTLIST sd sufun CDATA #REQUIRED>
<!--This is our list of WindMarks.
rm - WindMark
vt - Variable Type (can be one of the standard variable types,
or custom)
c_vt - Custom Variable Type (If vt is custom, then this specifies
which custom variable type it is. This
must match one of the variables in the
custom variable type list.)
perm - Permissions for this WindMark
rl - Read-level permissions (must be greater than or equal to 0)
wl - Write-level permissions (must be greater than or equal to 0)
rfun - Read function associated with this rm (may be "", if the
rm is accessing data
directly, or if the rm is
using a custom variable
type)
wfun - Write function associated with this rm (same options as rfun)
vfun - Validation function associated with this rm (optional - may be "")
addr - Address of the data with this rm (optional. note also that "&'s"
are written as &amp;)
si - Structure instance associated with (optional - may be "")
sf - Structure Field associated with rm (optional - may be "")
-->
<!ELEMENT rapidmark_list ( rm* )>
<!ELEMENT rm EMPTY>
<!ATTLIST rm name CDATA #REQUIRED>
<!ATTLIST rm vt (char | uchar |
short | ushort |
integer | uinteger |
long | ulong |
macro | snmp |
extapi | custom ) #REQUIRED>
<!ATTLIST rm c_vt CDATA #REQUIRED>
<!ATTLIST rm perm ( readonly | readwrite ) #REQUIRED>
<!ATTLIST rm rl CDATA #REQUIRED>
<!ATTLIST rm wl CDATA #REQUIRED>
<!ATTLIST rm rfun CDATA #REQUIRED>
<!ATTLIST rm wfun CDATA #REQUIRED>
<!ATTLIST rm vfun CDATA #REQUIRED>
<!ATTLIST rm addr CDATA #REQUIRED>
<!ATTLIST rm si CDATA #REQUIRED>
<!ATTLIST rm sf CDATA #REQUIRED>
]>
<base_rc_project
version_major="4"
version_minor="00"
output_location=".\"
output_locationH=".\"
output_locationP=".\">
<enabled_blades>
<blade type="RCCLI" />
</enabled_blades>
<workspace project_name="files" component_name="" parent_name="publicWMB" dirC=".\" dirH=".\" dirP=".\" main="false" inibld="true" iniunq="true" eol="false">
<wmbcons_lst>
<wmbcons name="Cli" agnt="true" clnt="false" dyn="false" stc="true" />
<wmbcons name="Mib" agnt="true" clnt="false" dyn="false" stc="true" />
<wmbcons name="Web" agnt="false" clnt="false" alone="false" dyn="false" stc="true" />
<wmbcons name="Nvm" mode="none" cgfile="" />
</wmbcons_lst>
<subproj_lst>
</subproj_lst>
<proj_lst>
</proj_lst>
</workspace>
<options_h>
<system_specifications>
<os
type="vxworks"
prop_os_flag="__VXWORKS_OS__" />
<compiler
sbyte="char"
sbyte2="short"
sbyte4="int"
ubyte="unsigned_char"
ubyte2="unsigned_short"
ubyte4="unsigned_int" />
<hardware
endianness="little"
hw_ticks="60" />
</system_specifications>
<general_configuration>
<rapidmark_options
underlying_struct="hash_table"
rapidmark_buffer_size="1000"
delimiter="default_delim" />
<server
threading="multi"
enable_thread_pool="false"
max_pool_threads="4" />
<memory_management
manager="RLI"
initial_size="125000" />
<lan_filtering
enabled="false"
callback_filter_enabled_handler="Custom_CheckIpFilterEnabled"
callback_filter_check_handler="Custom_CheckIpFilterAddress" />
<mibway
enabled="false"
snmp_agent="cmu_snmp" />
<image_size
disable_structures="false"
use_local_libraries="false" />
<backplane_config
enable="true"
name="publicWMB"
componentmax="20"
resourcemax="1000"
parentname=""
pipe="false"
port="false"
portnumber=""
timeout=""
deregcookie="NULL"
dereghdlr="NULL" />
<component_config
name=""
path=""
reghdlr=""
dereghdlr=""
deregcookie="NULL"
regnaming="single" />
<producer_config
hide="false"
local="false"
defhnd="" />
<consumer_config
timeout="" />
<event_config
select="none" />
<code_gen tmplt_file=""/>
<ip_support stack="ipv4"/>
</general_configuration>
<security_preferences
access_level="Access_16_16"
access_options="N=0 D=| T=|"
model="access">
<group_list>
</group_list>
<view_list>
</view_list>
</security_preferences>
<file_manager
filemgr_enb="false"
dir_enb="false"
dir_dflt="/tgtsvr/"
dir_len="256"/>
<dbg_list>
<dbg def="#define __WM_ERROR_SHOW__"/>
</dbg_list>
<future_extensions>
</future_extensions>
</options_h>
<function_templates output_location=".\ansi.c" />
<ignition_c output_location=".\" output_locationH=".\" output_locationP=".\">
<header_list>
</header_list>
<custom_variable_type_list>
</custom_variable_type_list>
<rapidmark_list>
</rapidmark_list>
<windgroup_list>
</windgroup_list>
</ignition_c>
</base_rc_project>
@@ -0,0 +1,508 @@
/* krnl2cli.c - command transfering shell context from kernel to WebCLI */
/*
* Copyright (c) 2009, 2010, 2014 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
--------------------
01e,15aug14,f_f replace shellInOutGet with shellIOStdGet (VXW6-83229)
01d,28apr10,m_z VxWorks 64-bit support
(WIND00193649)
01c,27sep09,m_z add timeout on receiving data
(WIND00180029)
01b,25sep09,m_z semTake calll error
(WIND00181271)
01a,01Jun09,m_z Initial code
*/
/*
* DESCRIPTION
* This module provides command for kernel to change to WebCIL shell context.
*
* INCLUDE FILES:
*/
/* Includes */
#include <vxWorks.h>
#include <shellInterpCmdLib.h>
#include "wm.h"
#include "wmb.h"
#include "rcc.h"
/* defines */
#define TASK_NAME_LEN 64
#define WEBCLI_SHELL_TASK_ID_NUM kRCC_MAX_CLI_TASK
/* globals */
TASK_ID webcliTaskIDList[WEBCLI_SHELL_TASK_ID_NUM] = {0};
SEM_ID webcliTaskIDSem = NULL;
extern int wmbStarted;
extern STATUS shellIOStdGet (SHELL_ID shellId, int * pInFd, int * pOutFd,
int * pErrFd);
/* local */
static int webcliShellCmd(int argc, char** arcv);
static const SHELL_CMD webcliShellCmdArray[] = {/* List of the commands */
{"webcli",
webcliShellCmd,
NULL,
"Invoke WebCLI shell",
"The '%s' command start one WebCLI shell instance. \"exit\" to quit.",
"%s "},
{NULL, NULL, NULL, NULL, NULL, NULL}};
/* Forward declarations */
int webcliCheckTaskID(TASK_ID taskID);
int webcliSaveTaskID(TASK_ID taskID);
int webcliDeleteTaskID(TASK_ID taskID);
extern STATUS webcliShellCmdInit (void);
extern STATUS webcliShellCmdUninit (void);
STATUS webcliShellRecvHandler ( WMB_SESSION_T * pCliEnv, cliChar * charReceived);
STATUS webcliShellSendHandler ( WMB_SESSION_T * pEnv, sbyte * pBuf, sbyte4 bufLen);
STATUS webcliShellInitHandler ( WMB_SESSION_T * pCliEnv);
void RCC_EXT_StartSession ( /* OS_SOCKET_T sock, */ int inFd, int outFd, int errFd, SEM_ID shellStartSem);
extern STATUS WMB_COMPONENT_Start ( void);
extern STATUS WMB_COMPONENT_Stop (void *) ;
/*******************************************************************************
*
* webcliShellCmdInit - initialize the shell commands for WebCLI
*
* This function is used to initialize the shell commands used for transfering
* from kernel shell context to WebCLI shell context. It adds new commands to
* the list of available commands.
*
* RETURNS: OK, or ERROR if an error occured.
*
* ERRNO: N/A
*/
STATUS webcliShellCmdInit (void)
{
STATUS status;
/* Create a new topic for the tutorial commands */
status = shellCmdTopicAdd ("WebCLI",
"WebCLI shell context.");
if (status != OK)
return ERROR;
/* Register the commands */
status = shellCmdArrayAdd ("WebCLI", webcliShellCmdArray);
if (status != OK)
return ERROR;
/* Add default aliases */
/* shellCmdAliasArrayAdd (webcliShellAliasArray, FALSE); */
webcliTaskIDSem = semCCreate(SEM_Q_FIFO, 1);
if (NULL == webcliTaskIDSem)
return ERROR;
return OK;
}
/*******************************************************************************
*
* webcliShellCmdUninit - Uninitialize the shell commands for WebCLI
*
* This function is used to release resource applied in initialization
*
* RETURNS: OK
*
* ERRNO: N/A
*/
STATUS webcliShellCmdUninit (void)
{
if (NULL != webcliTaskIDSem)
semDelete(webcliTaskIDSem);
webcliTaskIDSem = NULL;
return OK;
}
/*******************************************************************************
*
* webcliShellRecvHandler - function for the 'webclishell' receivng data
*
* This function provides data receive handler for webcli shell
*
* RETURNS: 0 or error if failed
*
* ERRNO: N/A
*
*/
STATUS webcliShellRecvHandler
(
WMB_SESSION_T * pCliEnv,
cliChar * charReceived
)
{
STATUS ret;
struct fd_set readFds;
char temp=0;
int sock = pCliEnv->sock;
int timeout = MCONN_GetTimeOut(pCliEnv);
struct timeval tv;
ssize_t rLen;
tv.tv_sec = timeout;
tv.tv_usec = 0;
do {
FD_ZERO(&readFds);
FD_SET(sock, &readFds);
ret = select(sock+1, &readFds, 0, 0, &tv);
}while (-1 == ret && EINTR == errno);
if (0 > ret)
return SYS_ERROR_SOCKET_GENERAL;
else if (0 == ret)
return ERROR_RCC_TIMEOUT;
rLen = read(sock, &temp, 1);
if (0 > rLen)
return SYS_ERROR_SOCKET_GENERAL;
else if (0 == rLen)
return SYS_ERROR_SOCKET_DISCONNECTED;
RCC_TELNET_Process(pCliEnv, temp);
*charReceived = temp;
return OK;
}
/*******************************************************************************
*
* webcliShellSendHandler - function for the 'webclishell' sending data
*
* This function provides data send handler for webcli shell
*
* RETURNS: 0 or writen chararcter numbers
*
* ERRNO: N/A
*
*/
STATUS webcliShellSendHandler
(
WMB_SESSION_T * pEnv,
sbyte * pBuf,
sbyte4 bufLen
)
{
ssize_t wLen;
wLen = write(pEnv->sock, pBuf, (size_t)bufLen);
if (wLen != (ssize_t)bufLen)
return SYS_ERROR_SOCKET_GENERAL;
return OK;
}
/*******************************************************************************
*
* webcliShellInitHandler - function for the 'webclishell' session initiation
*
* This function provides session initiation handler for webcli shell
*
* RETURNS: 0
*
* ERRNO: N/A
*
*/
STATUS webcliShellInitHandler
(
WMB_SESSION_T * pCliEnv
)
{
sbyte4 optSize = (sbyte4)(sizeof(PairState) * kRCC_MAX_OPT_HANDLED);
MCONN_SetSubOption(pCliEnv, 0);
MCONN_SetConnType(pCliEnv, kRCC_CONN_TELNET);
MCONN_SetWriteHandle(pCliEnv, webcliShellSendHandler);
MCONN_SetReadHandle(pCliEnv, webcliShellRecvHandler);
MCONN_SetRecvState(pCliEnv, kRCC_TS_DATA);
MCONN_SetOptBufferIndex(pCliEnv, -1);
MEMSET(MMISC_GetOptHandled(pCliEnv), 0, (ubyte4)optSize);
return OK;
}
/*******************************************************************************
*
* webcliShellInitHandler - function for the 'webclishell' session initiation
*
* This function provides session initiation handler for webcli shell
*
* RETURNS: N/A
*
* ERRNO: N/A
*
*/
void RCC_EXT_StartSession
(
/* OS_SOCKET_T sock, */
int inFd,
int outFd,
int errFd,
SEM_ID shellStartSem
)
{
/* we can only deal with in/out/err using the same file */
if (inFd == outFd && inFd == errFd)
{
ioTaskStdSet(0, STD_IN, inFd);
ioTaskStdSet(0, STD_OUT, outFd);
ioTaskStdSet(0, STD_ERR, errFd);
RCC_TELNETD_CreateSession(
inFd,
webcliShellInitHandler,
webcliShellRecvHandler,
webcliShellSendHandler,
kRCC_CONN_TELNET,
"ptelnet");
}
semGive((SEM_ID)shellStartSem);
}
/*******************************************************************************
*
* webcliShellCmd - function for the 'webclishell' command
*
* This function starts an instance of WebCLI shell, and changes currrent shell
* context to it.
*
* RETURNS: 0 or -1 if failed
*
* ERRNO: N/A
*
*/
static int webcliShellCmd
(
int argc,
char** arcv
)
{
int inFd = 0;
int outFd = 0;
int errFd = 0;
int inOpt = 0;
TASK_ID taskID = 0;
int ret = 0;
SEM_ID shellStartSem;
char taskName[TASK_NAME_LEN]={0};
if (0 <= webcliCheckTaskID(taskIdSelf()))
{
return -1;
}
shellStartSem = semCCreate(SEM_Q_FIFO, 0);
if (NULL == shellStartSem)
{
return -1;
}
shellIOStdGet (0, &inFd, &outFd, &errFd);
inOpt = ioctl(inFd, FIOGETOPTIONS, 0);
ioctl(inFd, FIOSETOPTIONS, OPT_RAW);
semTake(webcliTaskIDSem, WAIT_FOREVER);
if (0 == wmbStarted)
{
if (OK != WMB_COMPONENT_Start())
{
semGive(webcliTaskIDSem);
ret = -1;
goto exit;
}
}
else
wmbStarted++; /* providing there is no competition */
semGive(webcliTaskIDSem);
snprintf (taskName, TASK_NAME_LEN, "%s_%l.", "webclishell", taskIdSelf());
taskID = taskSpawn(
taskName,
kRCC_SERVER_PRIO,
0,
6000,
(FUNCPTR)RCC_EXT_StartSession,
(_Vx_usr_arg_t)inFd,
(_Vx_usr_arg_t)outFd,
(_Vx_usr_arg_t)errFd,
(_Vx_usr_arg_t)shellStartSem, 0, 0, 0, 0, 0, 0);
if ((TASK_ID)ERROR == taskID)
{
ret = -1;
goto exit;
}
else
{
webcliSaveTaskID(taskID);
}
semTake(shellStartSem, WAIT_FOREVER);
exit:
semTake(webcliTaskIDSem, WAIT_FOREVER);
if (1 < wmbStarted)
wmbStarted--;
else if (0 < wmbStarted)
WMB_COMPONENT_Stop(0);
semGive(webcliTaskIDSem);
ioctl(inFd, FIOSETOPTIONS, inOpt);
semDelete(shellStartSem);
webcliDeleteTaskID(taskID);
return ret;
}
/*******************************************************************************
*
* webcliCheckTaskID - function for taskID check
*
* This function checks registered taskID array if current task is already spawned
* by such shell context changing command
*
* RETURNS: -1 if not registered or index in the array
*
* ERRNO: N/A
*
*/
int webcliCheckTaskID
(
TASK_ID taskID
)
{
int ret = -1;
int i;
if ( taskID == 0)
goto exit;
semTake(webcliTaskIDSem, WAIT_FOREVER);
for (i = 0; i < WEBCLI_SHELL_TASK_ID_NUM; i++)
{
if ( taskID == webcliTaskIDList[i])
{
ret = i;
break;
}
}
semGive(webcliTaskIDSem);
exit:
return ret;
}
/*******************************************************************************
*
* webcliSaveTaskId - function for taskId save
*
* This function saves registered taskid in array
*
* RETURNS: -1 if not register or index in the array
*
* ERRNO: N/A
*
*/
int webcliSaveTaskID
(
TASK_ID taskID
)
{
int ret = -1;
int i;
if ( taskID <= 0)
goto exit;
semTake(webcliTaskIDSem, WAIT_FOREVER);
for (i = 0; i < WEBCLI_SHELL_TASK_ID_NUM; i++)
{
if (0 == webcliTaskIDList[i])
{
webcliTaskIDList[i] = taskID;
ret = i;
break;
}
}
semGive(webcliTaskIDSem);
exit:
return ret;
}
/*******************************************************************************
*
* webcliDelteTaskId - function for taskId delete
*
* This function delete registered taskid in array
*
* RETURNS: -1 if not register or index in the array
*
* ERRNO: N/A
*
*/
int webcliDeleteTaskID
(
TASK_ID taskID
)
{
int ret = -1;
int i;
if ( taskID <= 0)
goto exit;
semTake(webcliTaskIDSem, WAIT_FOREVER);
for (i = 0; i < WEBCLI_SHELL_TASK_ID_NUM; i++)
{
if ( taskID == webcliTaskIDList[i])
{
ret = i;
webcliTaskIDList[i] = 0;
break;
}
}
semGive(webcliTaskIDSem);
exit:
return ret;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,462 @@
<?xml version="1.0"?>
<!--This Document Type Definition (DTD) describes the layout of the base WindManage
project file. This project was originally generated by the GUI-based
WindManage Integration Tool (WMIT), and can be used by either the WMIT or
by any console tool that requires a project file.
The DTD is included below so that this project file is completely standalone. In
addition, the DTD provides guidance on how to modify the project file, should you
want to modify the file by hand. If you modify the file properly, you should be
able to open it with the WMIT, and you should be able to feed it into any console
tool.
To properly modify the file, be sure that any modifications you make follow
the element and attribute rules specified below. For example,
the element "mibway" has the attribute "enabled", and "enabled" must be either
"true" or "false", as specified by the DTD. Therefore, in the actual project
listing below the DTD, in the "mibway" element, you must either have "true" or
"false" listed for the "enabled" attribute. "TRUE", or "True", or "not true" or
something to that effect, is invalid. Note that XML is case-sensitive.
As a general precaution, you should probably run any modifications you make through
an XML validator, before you try and load the file into one of our tools. The
validators provide you with good line-character information for any errors.
A reasonably good free validator can be found on the Microsoft site, at the url:
"http://msdn.microsoft.com/downloads/samples/internet/xml/xml_validator/default.asp".
NOTE THAT YOU CANNOT MODIFY THE DTD. The WindManage tool suite parsing code is
geared to follow this and only this DTD. So if you modify the DTD, ugly things
might happen.
NOTE ALSO THAT THIS FILE IS GENERATED FROM SCRATCH EACH TIME YOU SAVE IT FROM
THE WMIT. That means you "COMMENT OUT" THINGS AT YOUR OWN RISK. You can put
XML comment delimiters around a given WindMark specification, and the WMIT
and the console tools won't read in a commented out WindMark when they open
the project. However, if you go to save the project file again from the WMIT,
the commented out code will disappear and you will have lost the data.
Lastly, we've tried to make the text below easy to modify for both novice and power
users. The elements and attributes that are seldom modified, such as those in
options_h, typically have long names, to make them easier to identify at first
glance. Elements and attributes that are heavily modified, such as WindMark
characteristics, have shorter names so the attribute doesn't dominate your
text editor.
As a compromise though, the elements and attributes with short, non-intuitive names
have a comment above their DTD specification, so that you could refer back to
that comment if necessary.
-->
<!DOCTYPE base_rc_project [
<!ELEMENT base_rc_project ( enabled_blades, options_h, function_templates,
ignition_c )>
<!ATTLIST base_rc_project version_major CDATA #REQUIRED>
<!ATTLIST base_rc_project version_minor CDATA #REQUIRED>
<!ATTLIST base_rc_project output_location CDATA #REQUIRED>
<!ATTLIST base_rc_project output_locationH CDATA #REQUIRED>
<!ATTLIST base_rc_project output_locationP CDATA #REQUIRED>
<!ELEMENT enabled_blades ( blade+ )>
<!ELEMENT blade EMPTY >
<!ATTLIST blade type ( RCW | RCA | RCCLI | MIBway ) #REQUIRED>
<!ELEMENT workspace (wmbcons_lst, subproj_lst, proj_lst)>
<!ATTLIST workspace project_name CDATA #REQUIRED>
<!ATTLIST workspace component_name CDATA #REQUIRED>
<!ATTLIST workspace parent_name CDATA #REQUIRED>
<!ATTLIST workspace dirC CDATA #REQUIRED>
<!ATTLIST workspace dirH CDATA #REQUIRED>
<!ATTLIST workspace dirP CDATA #REQUIRED>
<!ATTLIST workspace main CDATA #REQUIRED>
<!ATTLIST workspace inibld CDATA #REQUIRED>
<!ATTLIST workspace iniunq CDATA #REQUIRED>
<!ATTLIST workspace eol CDATA #REQUIRED>
<!ELEMENT wmbcons_lst ( wmbcons* )>
<!ATTLIST workspace project_name CDATA #REQUIRED>
<!ELEMENT wmbcons EMPTY>
<!ATTLIST wmbcons name CDATA #REQUIRED>
<!ATTLIST wmbcons agnt CDATA #REQUIRED>
<!ATTLIST wmbcons clnt CDATA #REQUIRED>
<!ATTLIST wmbcons dyn CDATA #REQUIRED>
<!ATTLIST wmbcons stc CDATA #REQUIRED>
<!ATTLIST wmbcons alone CDATA "">
<!ELEMENT subproj_lst EMPTY>
<!ATTLIST subproj_lst name CDATA #REQUIRED>
<!ELEMENT proj_lst EMPTY>
<!ATTLIST proj_lst name CDATA #REQUIRED>
<!ATTLIST proj_lst view CDATA #REQUIRED>
<!ELEMENT options_h (system_specifications, general_configuration,
security_preferences, future_extensions )>
<!ELEMENT system_specifications ( os, compiler, hardware )>
<!ELEMENT os EMPTY>
<!ATTLIST os type ( proprietary | vxworks | vxworks_ae |
bsd_os | win32 | posix ) #REQUIRED>
<!ATTLIST os prop_os_flag CDATA "__CUSTOMER_SPECIFIC_OS__">
<!ELEMENT compiler EMPTY>
<!ATTLIST compiler sbyte ( char | Byte | byte ) #REQUIRED>
<!ATTLIST compiler sbyte2 ( short | int ) #REQUIRED>
<!ATTLIST compiler sbyte4 ( long | int ) #REQUIRED>
<!ATTLIST compiler ubyte ( unsigned_char | Byte | byte ) #REQUIRED>
<!ATTLIST compiler ubyte2 ( unsigned_short | unsigned_int ) #REQUIRED>
<!ATTLIST compiler ubyte4 ( unsigned_int | unsigned_long ) #REQUIRED>
<!ELEMENT hardware EMPTY>
<!ATTLIST hardware endianness ( big | little ) #REQUIRED>
<!ATTLIST hardware hw_ticks CDATA #REQUIRED>
<!ELEMENT general_configuration ( rapidmark_options, server, memory_management,
lan_filtering, mibway, image_size,
backplane_config, component_config, producer_config, consumer_config, event_config )>
<!ELEMENT rapidmark_options EMPTY>
<!ATTLIST rapidmark_options underlying_struct (array | hash_table |
binary_tree) #REQUIRED>
<!ATTLIST rapidmark_options rapidmark_buffer_size CDATA #REQUIRED>
<!ATTLIST rapidmark_options delimiter ( default_delim | bracket_delim) #REQUIRED>
<!ELEMENT server EMPTY>
<!ATTLIST server threading (single | multi) #REQUIRED>
<!ATTLIST server enable_thread_pool (true | false) #REQUIRED>
<!ATTLIST server max_pool_threads CDATA #REQUIRED>
<!ELEMENT memory_management EMPTY>
<!ATTLIST memory_management manager (RLI | host) #REQUIRED>
<!ATTLIST memory_management initial_size CDATA #REQUIRED>
<!ELEMENT lan_filtering EMPTY>
<!ATTLIST lan_filtering enabled (true | false) #REQUIRED>
<!ATTLIST lan_filtering callback_filter_enabled_handler CDATA #REQUIRED>
<!ATTLIST lan_filtering callback_filter_check_handler CDATA #REQUIRED>
<!ELEMENT mibway EMPTY>
<!ATTLIST mibway enabled (true | false) #REQUIRED>
<!ATTLIST mibway snmp_agent ( none | envoy | envoy_m_sa | windnet_snmp_bin |
windnet_snmp_src | snmp_v1 | cmu_snmp | other ) #REQUIRED>
<!ELEMENT image_size EMPTY >
<!ATTLIST image_size disable_structures (true | false) #REQUIRED>
<!ATTLIST image_size use_local_libraries (true | false) #REQUIRED>
<!ELEMENT backplane_config EMPTY >
<!ATTLIST backplane_config enable CDATA #REQUIRED>
<!ATTLIST backplane_config name CDATA #REQUIRED>
<!ATTLIST backplane_config componentmax CDATA #REQUIRED>
<!ATTLIST backplane_config resourcemax CDATA #REQUIRED>
<!ATTLIST backplane_config parentname CDATA #REQUIRED>
<!ATTLIST backplane_config pipe CDATA #REQUIRED>
<!ATTLIST backplane_config port CDATA #REQUIRED>
<!ATTLIST backplane_config portnumber CDATA #REQUIRED>
<!ATTLIST backplane_config timeout CDATA #REQUIRED>
<!ATTLIST backplane_config deregcookie CDATA #REQUIRED>
<!ATTLIST backplane_config dereghdlr CDATA #REQUIRED>
<!ELEMENT component_config EMPTY >
<!ATTLIST component_config name CDATA #REQUIRED>
<!ATTLIST component_config path CDATA #REQUIRED>
<!ATTLIST component_config dereghdlr CDATA #REQUIRED>
<!ATTLIST component_config deregcookie CDATA #REQUIRED>
<!ATTLIST component_config regnaming CDATA #REQUIRED>
<!ELEMENT producer_config EMPTY >
<!ATTLIST producer_config hide CDATA #REQUIRED>
<!ATTLIST producer_config local CDATA #REQUIRED>
<!ATTLIST producer_config defhnd CDATA #REQUIRED>
<!ELEMENT consumer_config EMPTY >
<!ATTLIST consumer_config timeout CDATA #REQUIRED>
<!ELEMENT event_config EMPTY >
<!ATTLIST event_config enable CDATA #REQUIRED>
<!ATTLIST event_config hdlr CDATA #REQUIRED>
<!ATTLIST event_config queue CDATA #REQUIRED>
<!ELEMENT security_preferences (group_list, view_list) >
<!ATTLIST security_preferences model (access | view) #REQUIRED>
<!ATTLIST security_preferences access_level CDATA #REQUIRED>
<!ATTLIST security_preferences access_options CDATA #REQUIRED>
<!ELEMENT group_list EMPTY >
<!ATTLIST group_list name CDATA #REQUIRED>
<!ELEMENT view_list EMPTY >
<!ATTLIST view_list name CDATA #REQUIRED>
<!ELEMENT future_extensions (#PCDATA)>
<!ATTLIST future_extensions xml:space (default | preserve) "preserve">
<!ELEMENT function_templates EMPTY>
<!ATTLIST function_templates output_location CDATA #REQUIRED>
<!ELEMENT ignition_c ( header_list, custom_variable_type_list,
struct_desc_list, rapidmark_list )>
<!ATTLIST ignition_c output_location CDATA "">
<!ATTLIST ignition_c output_locationH CDATA "">
<!ATTLIST ignition_c output_locationP CDATA "">
<!--This is the list of C header files that should be #included in
any builds of wmb_*.c.
-->
<!ELEMENT header_list ( header* )>
<!ELEMENT header EMPTY>
<!ATTLIST header name CDATA #REQUIRED>
<!--This is the list of custom variable types, should you want to
be able to reuse any glue-code routines.
vt - Variable type
name - The name of the variable type, such as ipaddress
parent - The name of the built-in type from which this is derived
validstr- The descriptor/valiadtion string
notes - Notes about this type
-->
<!ELEMENT custom_variable_type_list ( vt* )>
<!ELEMENT vt (#PCDATA)>
<!ATTLIST vt name CDATA #REQUIRED>
<!ATTLIST vt parent CDATA #REQUIRED>
<!ATTLIST vt validstr CDATA #REQUIRED>
<!ATTLIST vt notes CDATA #REQUIRED>
<!ATTLIST vt xml:space (default | preserve) "preserve">
<!--This is our list of "structure descriptions". This provides the
tool with knowledge of a particular structure that a WindMark
might be associated with.
sd - Structure description
si - Structure instance
sdecl - Structure declaration
cache - Cache permissions
safun - Structure address function
swfun - Structure write function (optional - may be "")
snfun - Structure 'next' function (optional - may be "")
slfun - Structure lock function (optional - may be "")
sufun - Structure unlock function (optional - may be "")
-->
<!ELEMENT struct_desc_list ( sd* )>
<!ELEMENT sd EMPTY>
<!ATTLIST sd si CDATA #REQUIRED>
<!ATTLIST sd sdecl CDATA #REQUIRED>
<!ATTLIST sd cache (cacheNone | cacheRead |
cacheWrite | cacheReadWrite ) #REQUIRED>
<!ATTLIST sd safun CDATA #REQUIRED>
<!ATTLIST sd swfun CDATA #REQUIRED>
<!ATTLIST sd snfun CDATA #REQUIRED>
<!ATTLIST sd slfun CDATA #REQUIRED>
<!ATTLIST sd sufun CDATA #REQUIRED>
<!--This is our list of WindMarks.
rm - WindMark
vt - Variable Type (can be one of the standard variable types,
or custom)
c_vt - Custom Variable Type (If vt is custom, then this specifies
which custom variable type it is. This
must match one of the variables in the
custom variable type list.)
perm - Permissions for this WindMark
rl - Read-level permissions (must be greater than or equal to 0)
wl - Write-level permissions (must be greater than or equal to 0)
rfun - Read function associated with this rm (may be "", if the
rm is accessing data
directly, or if the rm is
using a custom variable
type)
wfun - Write function associated with this rm (same options as rfun)
vfun - Validation function associated with this rm (optional - may be "")
addr - Address of the data with this rm (optional. note also that "&'s"
are written as &amp;)
si - Structure instance associated with (optional - may be "")
sf - Structure Field associated with rm (optional - may be "")
-->
<!ELEMENT rapidmark_list ( rm* )>
<!ELEMENT rm EMPTY>
<!ATTLIST rm name CDATA #REQUIRED>
<!ATTLIST rm vt (char | uchar |
short | ushort |
integer | uinteger |
long | ulong |
macro | snmp |
extapi | custom ) #REQUIRED>
<!ATTLIST rm c_vt CDATA #REQUIRED>
<!ATTLIST rm perm ( readonly | readwrite ) #REQUIRED>
<!ATTLIST rm rl CDATA #REQUIRED>
<!ATTLIST rm wl CDATA #REQUIRED>
<!ATTLIST rm rfun CDATA #REQUIRED>
<!ATTLIST rm wfun CDATA #REQUIRED>
<!ATTLIST rm vfun CDATA #REQUIRED>
<!ATTLIST rm addr CDATA #REQUIRED>
<!ATTLIST rm si CDATA #REQUIRED>
<!ATTLIST rm sf CDATA #REQUIRED>
]>
<base_rc_project
version_major="4"
version_minor="00"
output_location=".\"
output_locationH=".\"
output_locationP=".\">
<enabled_blades>
<blade type="RCCLI" />
</enabled_blades>
<workspace project_name="scripting" component_name="" parent_name="publicWMB" dirC=".\" dirH=".\" dirP=".\" main="false" inibld="true" iniunq="true" eol="false">
<wmbcons_lst>
<wmbcons name="Cli" agnt="true" clnt="false" dyn="false" stc="true" />
<wmbcons name="Mib" agnt="true" clnt="false" dyn="false" stc="true" />
<wmbcons name="Web" agnt="false" clnt="false" alone="false" dyn="false" stc="true" />
<wmbcons name="Nvm" mode="none" cgfile="" />
</wmbcons_lst>
<subproj_lst>
</subproj_lst>
<proj_lst>
</proj_lst>
</workspace>
<options_h>
<system_specifications>
<os
type="vxworks"
prop_os_flag="__VXWORKS_OS__" />
<compiler
sbyte="char"
sbyte2="short"
sbyte4="int"
ubyte="unsigned_char"
ubyte2="unsigned_short"
ubyte4="unsigned_int" />
<hardware
endianness="little"
hw_ticks="60" />
</system_specifications>
<general_configuration>
<rapidmark_options
underlying_struct="hash_table"
rapidmark_buffer_size="1000"
delimiter="default_delim" />
<server
threading="multi"
enable_thread_pool="false"
max_pool_threads="4" />
<memory_management
manager="RLI"
initial_size="125000" />
<lan_filtering
enabled="false"
callback_filter_enabled_handler="Custom_CheckIpFilterEnabled"
callback_filter_check_handler="Custom_CheckIpFilterAddress" />
<mibway
enabled="false"
snmp_agent="cmu_snmp" />
<image_size
disable_structures="false"
use_local_libraries="false" />
<backplane_config
enable="true"
name="publicWMB"
componentmax="20"
resourcemax="1000"
parentname=""
pipe="false"
port="false"
portnumber=""
timeout=""
deregcookie="NULL"
dereghdlr="NULL" />
<component_config
name=""
path=""
reghdlr=""
dereghdlr=""
deregcookie="NULL"
regnaming="single" />
<producer_config
hide="false"
local="false"
defhnd="" />
<consumer_config
timeout="" />
<event_config
select="none" />
<code_gen tmplt_file=""/>
<ip_support stack="ipv4"/>
</general_configuration>
<security_preferences
access_level="Access_16_16"
access_options="N=0 D=| T=|"
model="access">
<group_list>
</group_list>
<view_list>
</view_list>
</security_preferences>
<file_manager
filemgr_enb="false"
dir_enb="false"
dir_dflt="/tgtsvr/"
dir_len="256"/>
<dbg_list>
<dbg def="#define __WM_ERROR_SHOW__"/>
</dbg_list>
<future_extensions>
</future_extensions>
</options_h>
<function_templates output_location=".\ansi.c" />
<ignition_c output_location=".\" output_locationH=".\" output_locationP=".\">
<header_list>
</header_list>
<custom_variable_type_list>
</custom_variable_type_list>
<rapidmark_list>
</rapidmark_list>
<windgroup_list>
</windgroup_list>
</ignition_c>
</base_rc_project>
@@ -0,0 +1,353 @@
<?xml version="1.0"?>
<!--This Document Type Definition (DTD) describes the layout of the WindManage for
CLI project file. This project was originally generated by the GUI-based
WindManage Integration Tool (WMIT), and can be used by either the WMIT or
by any console tool that requires a WindManage for CLI project file.
Please refer to the comment in the corresponding base WindManage project for
more information on the DTD below and on how to modify this file.
-->
<!DOCTYPE rcc_project [
<!ELEMENT rcc_project ( general, options_h, custom_param_list, command_node_list)>
<!ATTLIST rcc_project version_major CDATA #REQUIRED>
<!ATTLIST rcc_project version_minor CDATA #REQUIRED>
<!ELEMENT general (cli_h_preamble, cli_c_preamble, hnd_preamble, custom_flag_list)>
<!ATTLIST general dirH CDATA #REQUIRED>
<!ATTLIST general dirC CDATA #REQUIRED>
<!ATTLIST general dirP CDATA #REQUIRED>
<!ATTLIST general access_options CDATA #REQUIRED>
<!ELEMENT cli_h_preamble (#PCDATA)>
<!ATTLIST cli_h_preamble xml:space (default | preserve) "preserve">
<!ELEMENT cli_c_preamble (#PCDATA)>
<!ATTLIST cli_c_preamble xml:space (default | preserve) "preserve">
<!ELEMENT hnd_preamble (#PCDATA)>
<!ATTLIST hnd_preamble xml:space (default | preserve) "preserve">
<!ELEMENT custom_flag_list ( cfl* )>
<!ELEMENT cfl EMPTY>
<!ATTLIST cfl name CDATA #REQUIRED>
<!ATTLIST cfl flag CDATA #REQUIRED>
<!ELEMENT options_h (telnet, login, shell, command, system, display, help, future_extensions)>
<!ELEMENT telnet EMPTY>
<!ATTLIST telnet port CDATA #REQUIRED>
<!ATTLIST telnet thread_stack_size CDATA #REQUIRED>
<!ATTLIST telnet server_priority CDATA #REQUIRED>
<!ATTLIST telnet timeout CDATA #REQUIRED>
<!ELEMENT login EMPTY>
<!ATTLIST login maximum CDATA #REQUIRED>
<!ATTLIST login length CDATA #REQUIRED>
<!ATTLIST login password_length CDATA #REQUIRED>
<!ATTLIST login prompt CDATA #REQUIRED>
<!ATTLIST login password_prompt CDATA #REQUIRED>
<!ELEMENT shell EMPTY>
<!ATTLIST shell number_history CDATA #REQUIRED>
<!ATTLIST shell default_prompt CDATA #REQUIRED>
<!ATTLIST shell alias_buf_size CDATA #REQUIRED>
<!ATTLIST shell alias_count CDATA #REQUIRED>
<!ATTLIST shell modal_history (true | false) #REQUIRED>
<!ATTLIST shell unlimited_history (true | false) #REQUIRED>
<!ATTLIST shell enable_scripting (true | false) #REQUIRED>
<!ATTLIST shell enable_stdio (true | false) #REQUIRED>
<!ELEMENT command EMPTY>
<!ATTLIST command prompt_length CDATA #REQUIRED>
<!ATTLIST command length CDATA #REQUIRED>
<!ATTLIST command output_buffer_size CDATA #REQUIRED>
<!ATTLIST command enable_console ( true | false ) #REQUIRED>
<!ATTLIST command exec_leaf_only ( true | false ) #REQUIRED>
<!ATTLIST command no_inter_mode ( true | false ) #REQUIRED>
<!ATTLIST command strict_no_hdlr ( true | false ) #REQUIRED>
<!ATTLIST command no_retry ( true | false ) #REQUIRED>
<!ELEMENT system EMPTY>
<!ATTLIST system maximum_task CDATA #REQUIRED>
<!ATTLIST system param_order (None | Unnamed | Full) #REQUIRED>
<!ELEMENT display EMPTY>
<!ATTLIST display hard_wrap ( true | false ) #REQUIRED>
<!ATTLIST display no_pause ( true | false ) #REQUIRED>
<!ATTLIST display scroll_long_line ( true | false ) #REQUIRED>
<!ATTLIST display dash_error_line ( true | false ) #REQUIRED>
<!ATTLIST display no_vt_esc ( true | false ) #REQUIRED>
<!ELEMENT help EMPTY>
<!ATTLIST help show_all_params ( true | false ) #REQUIRED>
<!ATTLIST help no_formatting ( true | false ) #REQUIRED>
<!ATTLIST help show_no ( true | false ) #REQUIRED>
<!ATTLIST help hide_blanks ( true | false ) #REQUIRED>
<!ATTLIST help show_next_only ( true | false ) #REQUIRED>
<!ATTLIST help show_exec ( true | false ) #REQUIRED>
<!ATTLIST help skip_node ( true | false ) #REQUIRED>
<!ATTLIST help self_help ( true | false ) #REQUIRED>
<!ATTLIST help error_help ( true | false ) #REQUIRED>
<!ATTLIST help leaf_param_only ( true | false ) #REQUIRED>
<!ELEMENT future_extensions (#PCDATA)>
<!ATTLIST future_extensions xml:space (default | preserve) "preserve">
<!ELEMENT custom_param_list (cp*)>
<!ELEMENT cp (#PCDATA)>
<!ATTLIST cp typename CDATA #REQUIRED>
<!ATTLIST cp typebase (null |
char | unsigned_char |
short | unsigned_short |
integer | unsigned_integer |
long | unsigned_long |
ip_address | mac_address |
enumerate | list |
string | absolute ) #REQUIRED>
<!ATTLIST cp validstr CDATA #REQUIRED>
<!ATTLIST cp accessstr CDATA #REQUIRED>
<!ATTLIST cp defaultstr CDATA #REQUIRED>
<!ATTLIST cp customvalid CDATA #REQUIRED>
<!ATTLIST cp convert2base CDATA #REQUIRED>
<!ATTLIST cp helpmethod (0 | 1) #REQUIRED>
<!ATTLIST cp helpstr CDATA #REQUIRED>
<!ATTLIST cp helphandler CDATA #REQUIRED>
<!ELEMENT parameter_list ( pd* )>
<!ELEMENT pd (#PCDATA)>
<!ATTLIST pd keyword CDATA #REQUIRED>
<!ATTLIST pd type (null |
char | unsigned_char |
short | unsigned_short |
integer | unsigned_integer |
long | unsigned_long |
ip_address | mac_address |
enumerate | list |
string | absolute ) #REQUIRED>
<!ATTLIST pd set_rapidmark CDATA #REQUIRED>
<!ATTLIST pd paramnum CDATA #REQUIRED>
<!ATTLIST pd nokeyword CDATA #REQUIRED>
<!ATTLIST pd typename CDATA #REQUIRED>
<!ATTLIST pd validstr CDATA #REQUIRED>
<!ATTLIST pd accessstr CDATA #REQUIRED>
<!ATTLIST pd defaultstr CDATA #REQUIRED>
<!ATTLIST pd customvalid CDATA #REQUIRED>
<!ATTLIST pd helpmethod (0 | 1) #REQUIRED>
<!ATTLIST pd helpstr CDATA #REQUIRED>
<!ATTLIST pd helphandler CDATA #REQUIRED>
<!ATTLIST pd convert2base CDATA #REQUIRED>
<!ELEMENT handler_param_order ( ho* )>
<!ELEMENT ho EMPTY>
<!ATTLIST ho paramnam CDATA #REQUIRED>
<!ATTLIST ho paramnum CDATA #REQUIRED>
<!ATTLIST ho type (required | optional) #REQUIRED>
<!ELEMENT inv_hdlr_params ( vp* )>
<!ELEMENT vp EMPTY>
<!ATTLIST vp paramnam CDATA #REQUIRED>
<!ATTLIST vp type (Iterative | Guiding | Value | Other) #REQUIRED>
<!ELEMENT handler_list ( hd* )>
<!ELEMENT hd (#PCDATA | handler_param_order | inv_hdlr_params)*>
<!ATTLIST hd req_param_mask CDATA #REQUIRED>
<!ATTLIST hd opt_param_mask CDATA #REQUIRED>
<!ATTLIST hd type CDATA #REQUIRED>
<!ATTLIST hd func CDATA #REQUIRED>
<!ATTLIST hd enable_cfg_dump ( true | false ) #REQUIRED>
<!ATTLIST hd xml:space (default | preserve) "preserve">
<!ELEMENT command_node_list ( command_node* )>
<!ELEMENT command_node ( parameter_list, handler_list, command_node_list, get_rapidmark_list, custflag_list )>
<!ATTLIST command_node keyword CDATA #REQUIRED>
<!ATTLIST command_node helpmethod (0 | 1) #REQUIRED>
<!ATTLIST command_node help CDATA #REQUIRED>
<!ATTLIST command_node helphandler CDATA #REQUIRED>
<!ATTLIST command_node mode_support ( true | false ) #REQUIRED>
<!ATTLIST command_node prompt_string CDATA #REQUIRED>
<!ATTLIST command_node access_level CDATA #REQUIRED>
<!ATTLIST command_node partition CDATA #REQUIRED>
<!ATTLIST command_node allow_no_form ( true | false ) #REQUIRED>
<!ATTLIST command_node inherit_rapidmarks ( true | false ) #REQUIRED>
<!ATTLIST command_node global_node ( true | false ) #REQUIRED>
<!ATTLIST command_node no_generate ( true | false ) #REQUIRED>
<!ATTLIST command_node meta_node ( true | false ) #REQUIRED>
<!ATTLIST command_node queue_node ( true | false ) #REQUIRED>
<!ATTLIST command_node nolink_node ( true | false ) #REQUIRED>
<!ATTLIST command_node no_exec ( true | false ) #REQUIRED>
<!ATTLIST command_node fallthrough ( true | false ) #REQUIRED>
<!ATTLIST command_node ignore ( true | false ) #REQUIRED>
<!ATTLIST command_node no_to_all ( true | false ) #REQUIRED>
<!ATTLIST command_node show_next ( true | false ) #REQUIRED>
<!ATTLIST command_node exact_node ( true | false ) #REQUIRED>
<!ATTLIST command_node exact_param ( true | false ) #REQUIRED>
<!ATTLIST command_node bind_param ( true | false ) #REQUIRED>
<!ATTLIST command_node leaf_only ( true | false ) #REQUIRED>
<!ATTLIST command_node function ( true | false ) #REQUIRED>
<!ATTLIST command_node operator ( true | false ) #REQUIRED>
<!ATTLIST command_node raw ( true | false ) #REQUIRED>
<!ELEMENT get_rapidmark_list ( rm* )>
<!ELEMENT rm EMPTY>
<!ATTLIST rm name CDATA #REQUIRED>
<!ELEMENT custflag_list ( cf* )>
<!ELEMENT cf EMPTY>
<!ATTLIST cf flag CDATA #REQUIRED>
]>
<rcc_project
version_major="4"
version_minor="00">
<workspace
project_name="snmp"
component_name=""
parent_name="publicWMB"
dirC=".\"
dirH=".\"
dirP=".\"
main="false"
inibld="true"
iniunq="true"
eol="false"
warn_prm="false"
warn_var="false"
subproj="false">
<wmbcons_lst>
<wmbcons name="Cli" agnt="true" clnt="false" dyn="false" stc="true" />
<wmbcons name="Nvm" mode="none" cgfile="" />
</wmbcons_lst>
<subproj_lst>
</subproj_lst>
<proj_lst>
</proj_lst>
</workspace>
<general project="snmp" dirH=".\" dirC=".\" dirP=".\" parentWmb="publicWMB" compname="" sec_model="access" access_options="N=0 D=| T=|" def_dir="kDIR_DEFAULT_PATH" auto_exec="">
<cli_h_preamble>
</cli_h_preamble>
<cli_c_preamble>
</cli_c_preamble>
<hnd_preamble>
#include &quot;rcm_mibway.h&quot; </hnd_preamble>
<custom_flag_list>
<cfl name="Custom1" flag="kRCC_COMMAND_CUSTOM1" />
<cfl name="Custom2" flag="kRCC_COMMAND_CUSTOM2" />
<cfl name="Custom3" flag="kRCC_COMMAND_CUSTOM3" />
</custom_flag_list>
<code_gen tmplt_file=""/>
</general>
<options_h>
<future_extensions>
</future_extensions>
<telnet
port="23"
thread_stack_size="5000"
server_priority="100"
timeout="1800" />
<login
maximum="5"
length="16"
password_length="16"
prompt="Login:"
password_prompt="Password:"
auth_callback="myRCC_TASK_ValidateLogin"/>
<shell
number_history="30"
default_prompt="CLI"
default_prompt_tail="# "
alias_buf_size="1024"
alias_count="32"
modal_history="false"
unlimited_history="false"
enable_scripting="false"
enable_stdio="false" />
<command
prompt_length="16"
length="256"
output_buffer_size="kMagicMarkupBufferSize"
enable_console="true"
exec_leaf_only="false"
no_inter_mode="false"
strict_no_hdlr="false"
no_retry="false"
hide_priv="false"/>
<system
maximum_task="7"
param_order="Full" />
<display
hard_wrap="false"
no_pause="false"
scroll_long_line="false"
dash_error_line="false"
no_vt_esc="false" />
<help
show_all_params="false"
no_formatting="false"
show_no="false"
hide_blanks="false"
show_more_than_next="false"
show_next_only="false"
show_exec="false"
skip_node="false"
self_help="false"
error_help="false"
leaf_param_only="false" />
</options_h>
<custom_param_list>
</custom_param_list>
<command_node_list>
<command_node keyword="commit" helpmethod="0" help="Commit snmp writes" helphandler="" mode_support="false" prompt_string="" access_level="0" grp="" allow_no_form="false" inherit_rapidmarks="false" global_node="true" no_generate="false" meta_node="false" queue_node="false" nolink_node="false" partition="" no_exec="false" fallthrough="false" ignore="false" no_to_all="false" show_next="false" exact_node="false" exact_param="false" bind_param="false" leaf_only="false" function="false" operator="false" raw="false">
<parameter_list>
</parameter_list>
<handler_list>
<hd type="0" enable_cfg_dump="false" req_param_mask="0x00000000" opt_param_mask="0x00000000" func="RCC_EXEC_Commit">
extern RLSTATUS
RCC_EXEC_Commit(cli_env *pCliEnv, paramList *pParams, sbyte *pAuxBuf)
{
return RCC_CMD_Snmp_Commit(pCliEnv);
} <handler_param_order>
</handler_param_order>
<inv_hdlr_params>
</inv_hdlr_params>
</hd>
</handler_list>
<command_node_list>
</command_node_list>
<get_rapidmark_list>
</get_rapidmark_list>
<custflag_list>
</custflag_list>
</command_node>
</command_node_list>
</rcc_project>
@@ -0,0 +1,464 @@
<?xml version="1.0"?>
<!--This Document Type Definition (DTD) describes the layout of the base WindManage
project file. This project was originally generated by the GUI-based
WindManage Integration Tool (WMIT), and can be used by either the WMIT or
by any console tool that requires a project file.
The DTD is included below so that this project file is completely standalone. In
addition, the DTD provides guidance on how to modify the project file, should you
want to modify the file by hand. If you modify the file properly, you should be
able to open it with the WMIT, and you should be able to feed it into any console
tool.
To properly modify the file, be sure that any modifications you make follow
the element and attribute rules specified below. For example,
the element "mibway" has the attribute "enabled", and "enabled" must be either
"true" or "false", as specified by the DTD. Therefore, in the actual project
listing below the DTD, in the "mibway" element, you must either have "true" or
"false" listed for the "enabled" attribute. "TRUE", or "True", or "not true" or
something to that effect, is invalid. Note that XML is case-sensitive.
As a general precaution, you should probably run any modifications you make through
an XML validator, before you try and load the file into one of our tools. The
validators provide you with good line-character information for any errors.
A reasonably good free validator can be found on the Microsoft site, at the url:
"http://msdn.microsoft.com/downloads/samples/internet/xml/xml_validator/default.asp".
NOTE THAT YOU CANNOT MODIFY THE DTD. The WindManage tool suite parsing code is
geared to follow this and only this DTD. So if you modify the DTD, ugly things
might happen.
NOTE ALSO THAT THIS FILE IS GENERATED FROM SCRATCH EACH TIME YOU SAVE IT FROM
THE WMIT. That means you "COMMENT OUT" THINGS AT YOUR OWN RISK. You can put
XML comment delimiters around a given WindMark specification, and the WMIT
and the console tools won't read in a commented out WindMark when they open
the project. However, if you go to save the project file again from the WMIT,
the commented out code will disappear and you will have lost the data.
Lastly, we've tried to make the text below easy to modify for both novice and power
users. The elements and attributes that are seldom modified, such as those in
options_h, typically have long names, to make them easier to identify at first
glance. Elements and attributes that are heavily modified, such as WindMark
characteristics, have shorter names so the attribute doesn't dominate your
text editor.
As a compromise though, the elements and attributes with short, non-intuitive names
have a comment above their DTD specification, so that you could refer back to
that comment if necessary.
-->
<!DOCTYPE base_rc_project [
<!ELEMENT base_rc_project ( enabled_blades, options_h, function_templates,
ignition_c )>
<!ATTLIST base_rc_project version_major CDATA #REQUIRED>
<!ATTLIST base_rc_project version_minor CDATA #REQUIRED>
<!ATTLIST base_rc_project output_location CDATA #REQUIRED>
<!ATTLIST base_rc_project output_locationH CDATA #REQUIRED>
<!ATTLIST base_rc_project output_locationP CDATA #REQUIRED>
<!ELEMENT enabled_blades ( blade+ )>
<!ELEMENT blade EMPTY >
<!ATTLIST blade type ( RCW | RCA | RCCLI | MIBway ) #REQUIRED>
<!ELEMENT workspace (wmbcons_lst, subproj_lst, proj_lst)>
<!ATTLIST workspace project_name CDATA #REQUIRED>
<!ATTLIST workspace component_name CDATA #REQUIRED>
<!ATTLIST workspace parent_name CDATA #REQUIRED>
<!ATTLIST workspace dirC CDATA #REQUIRED>
<!ATTLIST workspace dirH CDATA #REQUIRED>
<!ATTLIST workspace dirP CDATA #REQUIRED>
<!ATTLIST workspace main CDATA #REQUIRED>
<!ATTLIST workspace inibld CDATA #REQUIRED>
<!ATTLIST workspace iniunq CDATA #REQUIRED>
<!ATTLIST workspace eol CDATA #REQUIRED>
<!ELEMENT wmbcons_lst ( wmbcons* )>
<!ATTLIST workspace project_name CDATA #REQUIRED>
<!ELEMENT wmbcons EMPTY>
<!ATTLIST wmbcons name CDATA #REQUIRED>
<!ATTLIST wmbcons agnt CDATA #REQUIRED>
<!ATTLIST wmbcons clnt CDATA #REQUIRED>
<!ATTLIST wmbcons dyn CDATA #REQUIRED>
<!ATTLIST wmbcons stc CDATA #REQUIRED>
<!ATTLIST wmbcons alone CDATA "">
<!ELEMENT subproj_lst EMPTY>
<!ATTLIST subproj_lst name CDATA #REQUIRED>
<!ELEMENT proj_lst EMPTY>
<!ATTLIST proj_lst name CDATA #REQUIRED>
<!ATTLIST proj_lst view CDATA #REQUIRED>
<!ELEMENT options_h (system_specifications, general_configuration,
security_preferences, future_extensions )>
<!ELEMENT system_specifications ( os, compiler, hardware )>
<!ELEMENT os EMPTY>
<!ATTLIST os type ( proprietary | vxworks | vxworks_ae |
bsd_os | win32 | posix ) #REQUIRED>
<!ATTLIST os prop_os_flag CDATA "__CUSTOMER_SPECIFIC_OS__">
<!ELEMENT compiler EMPTY>
<!ATTLIST compiler sbyte ( char | Byte | byte ) #REQUIRED>
<!ATTLIST compiler sbyte2 ( short | int ) #REQUIRED>
<!ATTLIST compiler sbyte4 ( long | int ) #REQUIRED>
<!ATTLIST compiler ubyte ( unsigned_char | Byte | byte ) #REQUIRED>
<!ATTLIST compiler ubyte2 ( unsigned_short | unsigned_int ) #REQUIRED>
<!ATTLIST compiler ubyte4 ( unsigned_int | unsigned_long ) #REQUIRED>
<!ELEMENT hardware EMPTY>
<!ATTLIST hardware endianness ( big | little ) #REQUIRED>
<!ATTLIST hardware hw_ticks CDATA #REQUIRED>
<!ELEMENT general_configuration ( rapidmark_options, server, memory_management,
lan_filtering, mibway, image_size,
backplane_config, component_config, producer_config, consumer_config, event_config )>
<!ELEMENT rapidmark_options EMPTY>
<!ATTLIST rapidmark_options underlying_struct (array | hash_table |
binary_tree) #REQUIRED>
<!ATTLIST rapidmark_options rapidmark_buffer_size CDATA #REQUIRED>
<!ATTLIST rapidmark_options delimiter ( default_delim | bracket_delim) #REQUIRED>
<!ELEMENT server EMPTY>
<!ATTLIST server threading (single | multi) #REQUIRED>
<!ATTLIST server enable_thread_pool (true | false) #REQUIRED>
<!ATTLIST server max_pool_threads CDATA #REQUIRED>
<!ELEMENT memory_management EMPTY>
<!ATTLIST memory_management manager (RLI | host) #REQUIRED>
<!ATTLIST memory_management initial_size CDATA #REQUIRED>
<!ELEMENT lan_filtering EMPTY>
<!ATTLIST lan_filtering enabled (true | false) #REQUIRED>
<!ATTLIST lan_filtering callback_filter_enabled_handler CDATA #REQUIRED>
<!ATTLIST lan_filtering callback_filter_check_handler CDATA #REQUIRED>
<!ELEMENT mibway EMPTY>
<!ATTLIST mibway enabled (true | false) #REQUIRED>
<!ATTLIST mibway snmp_agent ( none | envoy | envoy_m_sa | windnet_snmp_bin |
windnet_snmp_src | snmp_v1 | cmu_snmp | other ) #REQUIRED>
<!ELEMENT image_size EMPTY >
<!ATTLIST image_size disable_structures (true | false) #REQUIRED>
<!ATTLIST image_size use_local_libraries (true | false) #REQUIRED>
<!ELEMENT backplane_config EMPTY >
<!ATTLIST backplane_config enable CDATA #REQUIRED>
<!ATTLIST backplane_config name CDATA #REQUIRED>
<!ATTLIST backplane_config componentmax CDATA #REQUIRED>
<!ATTLIST backplane_config resourcemax CDATA #REQUIRED>
<!ATTLIST backplane_config parentname CDATA #REQUIRED>
<!ATTLIST backplane_config pipe CDATA #REQUIRED>
<!ATTLIST backplane_config port CDATA #REQUIRED>
<!ATTLIST backplane_config portnumber CDATA #REQUIRED>
<!ATTLIST backplane_config timeout CDATA #REQUIRED>
<!ATTLIST backplane_config deregcookie CDATA #REQUIRED>
<!ATTLIST backplane_config dereghdlr CDATA #REQUIRED>
<!ELEMENT component_config EMPTY >
<!ATTLIST component_config name CDATA #REQUIRED>
<!ATTLIST component_config path CDATA #REQUIRED>
<!ATTLIST component_config dereghdlr CDATA #REQUIRED>
<!ATTLIST component_config deregcookie CDATA #REQUIRED>
<!ATTLIST component_config regnaming CDATA #REQUIRED>
<!ELEMENT producer_config EMPTY >
<!ATTLIST producer_config hide CDATA #REQUIRED>
<!ATTLIST producer_config local CDATA #REQUIRED>
<!ATTLIST producer_config defhnd CDATA #REQUIRED>
<!ELEMENT consumer_config EMPTY >
<!ATTLIST consumer_config timeout CDATA #REQUIRED>
<!ELEMENT event_config EMPTY >
<!ATTLIST event_config enable CDATA #REQUIRED>
<!ATTLIST event_config hdlr CDATA #REQUIRED>
<!ATTLIST event_config queue CDATA #REQUIRED>
<!ELEMENT security_preferences (group_list, view_list) >
<!ATTLIST security_preferences model (access | view) #REQUIRED>
<!ATTLIST security_preferences access_level CDATA #REQUIRED>
<!ATTLIST security_preferences access_options CDATA #REQUIRED>
<!ELEMENT group_list EMPTY >
<!ATTLIST group_list name CDATA #REQUIRED>
<!ELEMENT view_list EMPTY >
<!ATTLIST view_list name CDATA #REQUIRED>
<!ELEMENT future_extensions (#PCDATA)>
<!ATTLIST future_extensions xml:space (default | preserve) "preserve">
<!ELEMENT function_templates EMPTY>
<!ATTLIST function_templates output_location CDATA #REQUIRED>
<!ELEMENT ignition_c ( header_list, custom_variable_type_list,
struct_desc_list, rapidmark_list )>
<!ATTLIST ignition_c output_location CDATA "">
<!ATTLIST ignition_c output_locationH CDATA "">
<!ATTLIST ignition_c output_locationP CDATA "">
<!--This is the list of C header files that should be #included in
any builds of wmb_*.c.
-->
<!ELEMENT header_list ( header* )>
<!ELEMENT header EMPTY>
<!ATTLIST header name CDATA #REQUIRED>
<!--This is the list of custom variable types, should you want to
be able to reuse any glue-code routines.
vt - Variable type
name - The name of the variable type, such as ipaddress
parent - The name of the built-in type from which this is derived
validstr- The descriptor/valiadtion string
notes - Notes about this type
-->
<!ELEMENT custom_variable_type_list ( vt* )>
<!ELEMENT vt (#PCDATA)>
<!ATTLIST vt name CDATA #REQUIRED>
<!ATTLIST vt parent CDATA #REQUIRED>
<!ATTLIST vt validstr CDATA #REQUIRED>
<!ATTLIST vt notes CDATA #REQUIRED>
<!ATTLIST vt xml:space (default | preserve) "preserve">
<!--This is our list of "structure descriptions". This provides the
tool with knowledge of a particular structure that a WindMark
might be associated with.
sd - Structure description
si - Structure instance
sdecl - Structure declaration
cache - Cache permissions
safun - Structure address function
swfun - Structure write function (optional - may be "")
snfun - Structure 'next' function (optional - may be "")
slfun - Structure lock function (optional - may be "")
sufun - Structure unlock function (optional - may be "")
-->
<!ELEMENT struct_desc_list ( sd* )>
<!ELEMENT sd EMPTY>
<!ATTLIST sd si CDATA #REQUIRED>
<!ATTLIST sd sdecl CDATA #REQUIRED>
<!ATTLIST sd cache (cacheNone | cacheRead |
cacheWrite | cacheReadWrite ) #REQUIRED>
<!ATTLIST sd safun CDATA #REQUIRED>
<!ATTLIST sd swfun CDATA #REQUIRED>
<!ATTLIST sd snfun CDATA #REQUIRED>
<!ATTLIST sd slfun CDATA #REQUIRED>
<!ATTLIST sd sufun CDATA #REQUIRED>
<!--This is our list of WindMarks.
rm - WindMark
vt - Variable Type (can be one of the standard variable types,
or custom)
c_vt - Custom Variable Type (If vt is custom, then this specifies
which custom variable type it is. This
must match one of the variables in the
custom variable type list.)
perm - Permissions for this WindMark
rl - Read-level permissions (must be greater than or equal to 0)
wl - Write-level permissions (must be greater than or equal to 0)
rfun - Read function associated with this rm (may be "", if the
rm is accessing data
directly, or if the rm is
using a custom variable
type)
wfun - Write function associated with this rm (same options as rfun)
vfun - Validation function associated with this rm (optional - may be "")
addr - Address of the data with this rm (optional. note also that "&'s"
are written as &amp;)
si - Structure instance associated with (optional - may be "")
sf - Structure Field associated with rm (optional - may be "")
-->
<!ELEMENT rapidmark_list ( rm* )>
<!ELEMENT rm EMPTY>
<!ATTLIST rm name CDATA #REQUIRED>
<!ATTLIST rm vt (char | uchar |
short | ushort |
integer | uinteger |
long | ulong |
macro | snmp |
extapi | custom ) #REQUIRED>
<!ATTLIST rm c_vt CDATA #REQUIRED>
<!ATTLIST rm perm ( readonly | readwrite ) #REQUIRED>
<!ATTLIST rm rl CDATA #REQUIRED>
<!ATTLIST rm wl CDATA #REQUIRED>
<!ATTLIST rm rfun CDATA #REQUIRED>
<!ATTLIST rm wfun CDATA #REQUIRED>
<!ATTLIST rm vfun CDATA #REQUIRED>
<!ATTLIST rm addr CDATA #REQUIRED>
<!ATTLIST rm si CDATA #REQUIRED>
<!ATTLIST rm sf CDATA #REQUIRED>
]>
<base_rc_project
version_major="4"
version_minor="00"
output_location=".\"
output_locationH=".\"
output_locationP=".\">
<enabled_blades>
<blade type="RCCLI" />
</enabled_blades>
<workspace project_name="snmp" component_name="" parent_name="publicWMB" dirC=".\" dirH=".\" dirP=".\" main="false" inibld="true" iniunq="true" eol="false">
<wmbcons_lst>
<wmbcons name="Cli" agnt="true" clnt="false" dyn="false" stc="true" />
<wmbcons name="Mib" agnt="true" clnt="false" dyn="false" stc="true" />
<wmbcons name="Web" agnt="true" clnt="false" alone="false" dyn="false" stc="true" />
<wmbcons name="Nvm" mode="none" cgfile="" />
</wmbcons_lst>
<subproj_lst>
</subproj_lst>
<proj_lst>
</proj_lst>
</workspace>
<options_h>
<system_specifications>
<os
type="vxworks"
prop_os_flag="__VXWORKS_OS__" />
<compiler
sbyte="char"
sbyte2="short"
sbyte4="int"
ubyte="unsigned_char"
ubyte2="unsigned_short"
ubyte4="unsigned_int" />
<hardware
endianness="little"
hw_ticks="1" />
</system_specifications>
<general_configuration>
<rapidmark_options
underlying_struct="hash_table"
rapidmark_buffer_size="1000"
delimiter="default_delim" />
<server
threading="multi"
enable_thread_pool="false"
max_pool_threads="" />
<memory_management
manager="RLI"
initial_size="75000" />
<lan_filtering
enabled="false"
callback_filter_enabled_handler="Custom_CheckIpFilterEnabled"
callback_filter_check_handler="Custom_CheckIpFilterAddress" />
<mibway
enabled="false"
snmp_agent="none" />
<image_size
disable_structures="false"
use_local_libraries="false" />
<backplane_config
enable="false"
name=""
componentmax="12"
resourcemax="1000"
parentname=""
pipe="false"
port="false"
portnumber=""
timeout="100"
deregcookie="NULL"
dereghdlr="NULL" />
<component_config
name=""
path=""
reghdlr=""
dereghdlr=""
deregcookie="NULL"
regnaming="single" />
<producer_config
hide="false"
local="false"
defhnd="NULL" />
<consumer_config
timeout="100" />
<event_config
select="none" />
<code_gen tmplt_file=""/>
<ip_support stack="ipv4"/>
</general_configuration>
<security_preferences
access_level="Access_16_16"
access_options="N=0 D=| T=|"
model="access">
<group_list>
</group_list>
<view_list>
</view_list>
</security_preferences>
<file_manager
filemgr_enb="false"
dir_enb="false"
dir_dflt="/tgtsvr/"
dir_len="256"/>
<dbg_list>
<dbg def="#define __WM_ERROR_SHOW__"/>
</dbg_list>
<future_extensions>
</future_extensions>
</options_h>
<function_templates output_location=".\ansi.c" />
<ignition_c output_location=".\" output_locationH=".\" output_locationP=".\">
<header_list>
</header_list>
<custom_variable_type_list>
</custom_variable_type_list>
<rapidmark_list>
</rapidmark_list>
<windgroup_list>
</windgroup_list>
</ignition_c>
</base_rc_project>
@@ -0,0 +1,495 @@
/* usrGetNextSetCode.c - common support code for artibrary Get, Next, and Set */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01c,21apr10,m_z VxWorks 64-bit support
(WIND00193649)
01b,04may04,dlr Added error codes, use wmbTableLib instead of wmbDataXxx for SNMP data.
01a,24mar04,dlr written.
*/
/*
DESCRIPTION
This sample user code provides uniform access to arbitrary WindMarks with arbitrary
argument/instance information as part of the name.
It can access data in purely string format or as native data.
It updates the instance/argument part of the WindMark name when using getnext.
This sample code will use the wmbTableLib for SNMP WindMark access, to better capture
and report errors. In particular, in WM 4.3 GetNext for SNMP objects must use wmbTableLib
for access through MIBWay.
This code provides support for the sample demonstration CLI commands wmget, wmnext, and wmset.
NOMANUAL
*/
#include "wm.h"
#include "wmb.h"
#include "usrGetNextSetCode.h"
#include "wrn/wm/backplane/wmbTableLib.h"
#include "errnoLib.h"
/*******************************************************************************
*
* usrWindMarkIsWmbTable - Set flag if registered WindMark is controled by wmbTableLib
* - i.e. DB_FLAG_OID_COOKIE_K flag is set
*
* NOMANUAL
*
* RETURNS: OK if successful, or
* ERROR if WindMark could not be found
*/
STATUS usrWindMarkIsWmbTable
(
char * szName, /* WindMark name */
BOOL * bIsWmbTable,/* Pointer to type variable to set */
BOOL * bIsOidTable,/* Pointer to type variable to set */
DATATYPE_T *wmType /* Data type of object */
)
{
DB_ENTRY_T * pDBEntry;
char *pInstance;
char ch = '\0';
*bIsWmbTable = FALSE;
*bIsOidTable = FALSE;
*wmType = DATATYPE_STRING_K;
/* strip off existing instance, if any */
if (NULL == (pInstance = strchr (szName, '(')))
pInstance = strchr (szName, '.');
if (NULL != pInstance)
{
ch = *pInstance;
*pInstance = '\0';
}
/* Get the DB entry for this WindMark, any component */
pDBEntry = wmbDBEntryGet (wmbBackplaneDBGet (wmbBackplaneGet()), szName, NULL, FALSE);
if (NULL == pDBEntry)
{
wmError (ERROR_GENERAL_NOT_FOUND, "usrWindMarkIsWmbTable: no such WindMark");
return ERROR;
}
*bIsWmbTable = (wmbEntry(pDBEntry)->table) != NULL;
*bIsOidTable = (wmbDBEntryFlagGet(pDBEntry,DB_FLAG_OID_COOKIE_K));
*wmType = (wmbEntryTypeGet(pDBEntry));
/* restore instance separater, if any */
if (NULL != pInstance)
*pInstance = ch;
return OK;
}
/*******************************************************************************
*
* usrParseAndRequest - fetch value of a WindMark, GET/GETNEXT/SET, Scalar/Table Object
*
* This routine will fetch a context-less WindMark name. It will determine if it
* member of an SNMP table (and thus require the instance in binary OID form),
* a WindMark table member, or a simple SNMP/WindMark scalar.
*
* It will work for both native and string types and instances/arguments.
*
* Instances are extracted and restored to the string WindMark name.
*
* In addtion to a basic GET request, it can process a GETNEXT updating the
* returned instance information as appropriate. An End-Of-Table is indicated
* by the instance not changing.
*
* NOTE: processing GETNEXT on a SNMP table object requires using the wmbTableLib API
*
* NOMANUAL
*
* RETURNS: OK if the object has been fetched successfully, or
* ERROR if illegal name or instance.
*/
STATUS usrParseAndRequest
(
WMB_SESSION_T * pSession, /* WMB Session used by this request */
char * szName, /* Original WindMark name */
void * szValue, /* WindMark value buffer */
ubyte4 nValueMax, /* WindMark value buffer max size */
ubyte4* pValueSize, /* size of new value */
ubyte4 nCmnd, /* CMD_GET_K | CMD_GET_NEXT_K | CMD_SET_K */
BOOL bIsString /* TRUE=string, FALSE=native: value&inst */
)
{
/* Local value fetch */
sbyte *pInstance,*pTemp;
sbyte4 instanceLength;
sbyte4 instanceMaxLength;
char instanceSep;
char *szNameBf;
BOOL bIsTableObject = FALSE;
BOOL bIsSNMPObject = FALSE;
BOOL bIsRootInstance = FALSE;
BOOL bInstanceInOidForm = FALSE;
char * pStrInstance = NULL;
sbyte4 nStrInstanceLen = 0;
sbyte4 nStrInstanceMax = 0;
DATATYPE_T wmType = DATATYPE_STRING_K;
STATUS status = OK;
#ifdef _WRS_CONFIG_LP64
sbyte8 valueSize64;
#endif
/* Got to have a name to work with */
if ( szName == NULL )
{
return ERROR;
}
/* Create temp and modifiable name buffer */
if (NULL == (szNameBf = wmMalloc(kMagicMarkupBufferSize)))
{
return ERROR;
}
/* Make safe local copy of name */
strcpy(szNameBf,szName);
/* If this is a table WindMark with no instance, attach appropriate */
if (OK != usrWindMarkIsWmbTable(szNameBf, &bIsTableObject, &bIsSNMPObject,&wmType))
{
return ERROR;
}
/* A name without instance may be a root name of a table member */
if (bIsTableObject && (NULL == strchr (szNameBf, '(')) && (NULL == strchr (szNameBf, '.')))
{
bIsRootInstance = TRUE;
strcat(szNameBf,(bIsSNMPObject) ? ".":"()");
}
/* Extract any instance/argument field */
pInstance = NULL;
/* extract any instance/argument from WindMark name */
if (NULL != (pInstance = strchr (szNameBf, '(')))
{
*pInstance++ = '\0';
/* remove closing paren */
if (NULL !=(pTemp = strrchr (pInstance, ')')))
*pTemp = '\0';
instanceLength = (sbyte4)strlen(pInstance) + 1;
instanceSep = '(';
}
else if (NULL != (pInstance = strchr (szNameBf, '.')))
{
*pInstance++ = '\0';
instanceLength = (sbyte4)strlen(pInstance) + 1;
instanceMaxLength = kMagicMarkupBufferSize - (sbyte4)strlen(szNameBf) - 1;
instanceSep = '.';
/* The pInstance is really the string OID buffer. If GetNext transaction, Swap in binary version. */
bInstanceInOidForm = (CMD_GET_NEXT_K == nCmnd);
if (bInstanceInOidForm)
{
pStrInstance = pInstance;
nStrInstanceLen = instanceLength;
nStrInstanceMax = instanceMaxLength;
instanceMaxLength = 128*4;
pInstance = wmMalloc((ubyte4)instanceMaxLength);
if (NULL != pInstance)
{
if ((0 == nStrInstanceLen) ||
(OK != wmConvertStrToOid(pStrInstance, (ubyte4 *) pInstance, instanceMaxLength, &instanceLength)) )
{
instanceLength = 0;
}
}
else
{
instanceMaxLength = 0;
instanceLength = 0;
}
if (OK != wmbTableCreate(pSession, szNameBf, (0 != instanceLength) ? pStrInstance:NULL, szNameBf))
{
DEBUG_MSG_1("usrParseAndRequest: wmbTableCreate(%s) ERROR! =========\n",szNameBf);
}
}
}
else
{
/* the buffer after the name is available for a new instance */
pInstance = &szNameBf[strlen(szNameBf) + 1];
memset(pInstance,0,4);
instanceLength = 0;
instanceSep = '\0';
}
instanceMaxLength = kMagicMarkupBufferSize - (sbyte4)strlen(szNameBf) - 1;
/* Time to do the transaction */
if (!bIsString)
{
if (CMD_SET_K == nCmnd)
{
status = wmbDataNativeSet (pSession, szNameBf,
pInstance, instanceLength,
szValue, nValueMax);
}
else if ((CMD_GET_NEXT_K == nCmnd) && bIsSNMPObject)
{
/* GETNEXT for bIsSNMPObject objects are managed by wmbTableLib */
void *table = wmbSessionTableGet(pSession);
/* If Root Instance, then we have the first row data already */
if (!bIsRootInstance)
status = wmbTableRowNext(table);
if (OK == status)
{
WM_BUFFER_T * oidSfx;
/* Extract the GETNEXT string value !Use second half of value buffer! */
wmbTableGet(pSession,szNameBf, ((char*)szValue)+(nValueMax/2),nValueMax/2);
*pValueSize = (ubyte4)strlen( (char *)(((char*)szValue)+(nValueMax/2)) )+1;
/* Convert to native type */
#ifndef _WRS_CONFIG_LP64
wmConvert( (((char*)szValue)+(nValueMax/2)) ,*pValueSize,DATATYPE_STRING_K,
szValue,nValueMax,wmType,(sbyte4 *) pValueSize);
#else
wmConvert( (((char*)szValue)+(nValueMax/2)) ,*pValueSize,DATATYPE_STRING_K,
szValue,nValueMax,wmType, &valueSize64);
*pValueSize = (ubyte4)valueSize64;
#endif
/* Extract the new GETNEXT instance */
oidSfx = wmbTableInstanceSfxGet (pSession, szNameBf);
instanceLength = (sbyte4)wmBufferUsedGet(oidSfx);
memcpy(pInstance,wmBufferDataGet(oidSfx),(ubyte4)instanceLength);
}
else
{
if (wmErrNo()!=ERROR_TABLE_END_OF_TABLE)
{
errnoSet(ERROR_TABLE_END_OF_TABLE);
}
}
}
else if ((CMD_GET_K == nCmnd) && bIsSNMPObject)
{
/* This GET for bIsSNMPObject objects are managed by wmbTableLib */
/* Extract the GET string value !Use second half of value buffer! */
status = wmbTableGet(pSession,szNameBf,((char*)szValue)+(nValueMax/2),nValueMax/2);
*pValueSize = (ubyte4)strlen( (char *)(((char*)szValue)+(nValueMax/2)) )+1;
/* Convert to native type */
#ifndef _WRS_CONFIG_LP64
wmConvert( (&((char*)szValue)[nValueMax/2]) ,*pValueSize ,DATATYPE_STRING_K,
szValue,nValueMax,wmType, (sbyte4 *) pValueSize);
#else
wmConvert( (&((char*)szValue)[nValueMax/2]) ,*pValueSize ,DATATYPE_STRING_K,
szValue,nValueMax,wmType, &valueSize64);
*pValueSize = (ubyte4)valueSize64;
#endif
}
else if (CMD_GET_NEXT_K == nCmnd)
#ifndef _WRS_CONFIG_LP64
status = wmbDataNativeGetNext (pSession, szNameBf,
pInstance, &instanceLength, instanceMaxLength,DATATYPE_STRING_K,
szValue, nValueMax,
(sbyte4 *) pValueSize);
#else
{
status = wmbDataNativeGetNext (pSession, szNameBf,
pInstance, &instanceLength, instanceMaxLength,DATATYPE_STRING_K,
szValue, nValueMax,
&valueSize64);
*pValueSize = (ubyte4)valueSize64;
}
#endif
else
#ifndef _WRS_CONFIG_LP64
status = wmbDataNativeGet (pSession, szNameBf,
pInstance, instanceLength,
szValue, nValueMax,
(sbyte4 *) pValueSize);
#else
{
status = wmbDataNativeGet (pSession, szNameBf,
pInstance, instanceLength,
szValue, nValueMax,
&valueSize64);
*pValueSize = (ubyte4)valueSize64;
}
#endif
if (OK != status)
{
/* Handler Errors here */
DEBUG_MSG_1("usrParseAndRequest: wmbDataNativeGet(%s) ERROR! =========\n",szNameBf);
memset(szValue,0,4);
*pValueSize = 4;
}
}
else
{
if (CMD_SET_K == nCmnd)
{
status = wmbDataStringSet (pSession, szNameBf,
pInstance, instanceLength,
szValue, (sbyte4)STRLEN(szValue));
}
else if ((CMD_GET_NEXT_K == nCmnd) && bIsSNMPObject)
{
/* GETNEXT for bIsSNMPObject objects are managed by wmbTableLib */
void *table = wmbSessionTableGet(pSession);
/* If Root Instance, then we have the first row data already */
if (!bIsRootInstance)
status = wmbTableRowNext(table);
if (OK == status)
{
WM_BUFFER_T * oidSfx;
/* Extract the GETNEXT string value */
wmbTableGet(pSession,szNameBf,szValue,nValueMax);
*pValueSize = (ubyte4)strlen(szValue)+1;
/* Extract the new GETNEXT instance */
oidSfx = wmbTableInstanceSfxGet (pSession, szNameBf);
instanceLength = (sbyte4)wmBufferUsedGet(oidSfx);
memcpy(pInstance,wmBufferDataGet(oidSfx),(ubyte4)instanceLength);
}
else
{
if (wmErrNo()!=ERROR_TABLE_END_OF_TABLE)
{
errnoSet(ERROR_TABLE_END_OF_TABLE);
}
}
}
else if ((CMD_GET_K == nCmnd) && bIsSNMPObject)
{
/* This GET for bIsSNMPObject objects are managed by wmbTableLib */
/* Extract the GET string value */
status = wmbTableGet(pSession,szNameBf,szValue,nValueMax);
*pValueSize = (ubyte4)strlen(szValue)+1;
}
else if (CMD_GET_NEXT_K == nCmnd)
#ifndef _WRS_CONFIG_LP64
status = wmbDataStringGetNext (pSession, szNameBf,
pInstance, &instanceLength, instanceMaxLength,DATATYPE_STRING_K,
szValue, nValueMax,
(sbyte4 *) pValueSize);
#else
{
status = wmbDataStringGetNext (pSession, szNameBf,
pInstance, &instanceLength, instanceMaxLength,DATATYPE_STRING_K,
szValue, nValueMax,
&valueSize64);
*pValueSize = (ubyte4)valueSize64;
}
#endif
else
#ifndef _WRS_CONFIG_LP64
status = wmbDataStringGet (pSession, (sbyte *) szNameBf,
pInstance, instanceLength,
(sbyte *) szValue, kMagicMarkupBufferSize,
(sbyte4 *) pValueSize);
#else
{
status = wmbDataStringGet (pSession, (sbyte *) szNameBf,
pInstance, instanceLength,
(sbyte *) szValue, kMagicMarkupBufferSize,
&valueSize64);
*pValueSize = (ubyte4)valueSize64;
}
#endif
if (OK != status)
{
/* Handler Errors here */
DEBUG_MSG_1("usrParseAndRequest: wmbDataStringGet(%s) ERROR! =========\n",szNameBf);
strcpy(szValue,(wmErrNo()==ERROR_TABLE_END_OF_TABLE) ? "<EndTable>":"<NoValue>");
*pValueSize = (ubyte4)strlen(szValue);
}
/* insure actual string length from wmbDataStringGet !!! */
if (((ubyte4)strlen(szValue)+1) != *pValueSize)
{
*pValueSize = (ubyte4)strlen(szValue) + 1;
}
}
/* Put any binary OID back to string OID */
if (bInstanceInOidForm)
{
char *temp;
if ((NULL == pInstance) || (0 == instanceLength) ||
(OK != wmConvertOidToString(
(ubyte4 *) pInstance,
instanceLength,
pStrInstance,
nStrInstanceMax,
&nStrInstanceLen))
)
{
*pStrInstance = '\0';
}
/* swap, so that pInstance is string OID ptr, and pStrInstance is temp buffer */
temp = pInstance;
pInstance = pStrInstance;
pStrInstance = temp;
instanceLength = nStrInstanceLen; /* we do not care about nStrInstanceLen after this */
}
/* The new GETNEXT instance needs some propagation */
if (CMD_GET_NEXT_K == nCmnd)
{
/* remember that pInstance is one (delim) character past end of name */
if ('\0' == instanceSep)
{
/* Force an instance delim if this base base instance (i.e. no instance) */
instanceSep = (char)((bIsSNMPObject) ? '.':'(');
}
pInstance--;
*pInstance = instanceSep;
if ('(' == instanceSep)
strcat(pInstance,")");
/* UPDATE INPUT NAME BUFFER WITH NEW NAME*/
strcpy(szName,szNameBf);
}
/* Release any wmbTable structure for this object */
if (bIsSNMPObject && (NULL != wmbSessionTableGet(pSession)) )
{
wmbTableDestroy(pSession);
}
/* if pStrInstance buffer at large, free it */
if (NULL != pStrInstance)
wmFree(pStrInstance);
if (NULL != szNameBf)
wmFree(szNameBf);
return( (OK == status) ? OK:ERROR);
}
@@ -0,0 +1,51 @@
/* usrSupportCode.h - common WIND MANAGE functionality */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,24mar04,dlr written.
*/
/*
DESCRIPTION
This package provides common support libraries for using WindMarks in user code
NOMANUAL
*/
#ifndef __INCusrSupportCodeh
#define __INCusrSupportCodeh
/* prototypes */
#ifdef __cplusplus
extern "C" {
#endif
STATUS usrWindMarkIsWmbTable
(
char * szName, /* WindMark name */
BOOL * bIsWmbTable,/* Pointer to type variable to set */
BOOL * bIsOidTable,/* Pointer to type variable to set */
DATATYPE_T *wmType /* Data type of object */
);
STATUS usrParseAndRequest
(
WMB_SESSION_T * pSession, /* WMB Session used by LC thread */
char * szName, /* Original WindMark name */
void * szValue, /* WindMark value buffer */
ubyte4 nValueMax, /* WindMark value buffer max size */
ubyte4* pValueSize, /* size of new value */
ubyte4 nCmnd, /* CMD_GET_K | CMD_GET_NEXT_K | CMD_SET_K */
BOOL bIsString /* TRUE=string, FALSE=native: value&inst */
);
#ifdef __cplusplus
}
#endif
#endif /* __INCusrSupportCodeh */
@@ -0,0 +1,14 @@
cli/rcc.c
cli/rcc_alias.c
cli/rcc_cmd.c
cli/rcc_db.c
cli/rcc_ext.c
cli/rcc_help.c
cli/rcc_hist.c
cli/rcc_system.c
cli/rcc_task.c
cli/rcc_telnet.c
cli/rcc_telnetd.c
cli/rcc_util.c
cli/wmcPortfolio.c
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,394 @@
/* rcc_alias.c - command alias support */
/* Copyright (c) 1999-2007 2010-2012 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
--------------------
01h,08nov12,shi clean up warning. (WIND00386819)
01g,30mar11,r_w fix defect WIND00257291 make API reference readable
01f,19arp10,m_z VxWorks 64-bit support
(WIND00193649)
01e,22feb07,msa Correct the apigen comments so they match the actual
routines.
01d,13feb07,msa Fix comments to remove APIgen errors.
01c,17jun04,gsr fix for alias initialization during startup SPR 98267
01b,20jan04,gsr alias support SPR 83988
01a,03may20,pns initial WRS layout.
*/
/*
DESCRIPTION
This module provides command parsing support for CLI.
*/
#include "wm.h"
#include "wmb.h"
#include "rcc.h"
#include <string.h>
#ifdef __RCC_ENABLED__
#ifndef __NO_ALIASING__
#define kRCC_END_OF_DUMP -1
#define kRCC_ALIAS_WIDTH 30
/***************************************************************************
*
* RCC_ALIAS_Apply - replace aliased word with it's real value
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*
* NOMANUAL
*/
void RCC_ALIAS_Apply
(
WMB_SESSION_T * pCliEnv,
sbyte * pBuffer
)
{
AliasTable *pAliases = MMISC_AliasPtr(pCliEnv);
CmdAlias *pAlias = pAliases->alias;
sbyte newText[kRCC_MAX_CMD_LEN];
sbyte tempBuf[kRCC_MAX_CMD_LEN];
BOOL aliased = FALSE;
sbyte4 index;
sbyte *pBuf;
sbyte *pSrc;
sbyte *pCmd;
pCmd = MEDIT_GetBufPtr(pCliEnv);
for (index = 0; index < pAliases->numEntries; index++, pAlias++)
{
pSrc = aliased ? tempBuf : pCmd;
if (NULL == (pBuf = strstr(pSrc, pAlias->pName)))
continue;
if (OK == RC_Replace(pSrc, newText, kRCC_MAX_CMD_LEN,
pAlias->pName, pAlias->pText, TRUE))
{
STRCPY(tempBuf, newText);
aliased = TRUE;
}
}
if (aliased)
STRCPY(pBuffer, tempBuf);
else
STRCPY(pBuffer, pCmd);
}
/***************************************************************************
*
* RCC_ALIAS_DisplayAliases - show aliases and their values
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*/
void RCC_ALIAS_DisplayAliases
(
WMB_SESSION_T * pCliEnv
)
{
sbyte4 index;
AliasTable *pAliases = MMISC_AliasPtr(pCliEnv);
CmdAlias *pAlias = pAliases->alias;
for (index = 0; index < pAliases->numEntries; index++, pAlias++)
{
RCC_EXT_PrintString(pCliEnv, pAlias->pName, kRCC_ALIAS_WIDTH, ' ');
RCC_EXT_WriteStrLine(pCliEnv, pAlias->pText);
}
}
/***************************************************************************
*
* RCC_ALIAS_DeleteAlias - delete an alias and its value
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*
* NOMANUAL
*/
STATUS RCC_ALIAS_DeleteAlias
(
WMB_SESSION_T * pCliEnv,
sbyte * aliasName
)
{
AliasTable *pAliases = MMISC_AliasPtr(pCliEnv);
CmdAlias *pAlias = pAliases->alias;
sbyte4 index = 0;
sbyte4 count = 0;
sbyte4 delta = 0;
sbyte4 block = 0;
BOOL deleted = FALSE;
sbyte *pLower;
sbyte *pUpper;
for (index = 0; index < pAliases->numEntries; index++, pAlias++)
{
if (0 != COMPARE(pAlias->pName, aliasName))
continue;
deleted = TRUE;
delta = (sbyte4)STRLEN(pAlias->pName) + (sbyte4)STRLEN(pAlias->pText) + 2;
/* shift all remaining data down */
pLower = pAlias->pName;
pUpper = pLower + delta;
block = pAliases->bufferUsed - (sbyte4)(pUpper - pAliases->data);
for (count = 0; count < block; count++, pLower++, pUpper++)
*pLower = *pUpper;
/* null remainder */
MEMSET(pUpper, 0, (ubyte4)delta);
break;
}
if (! deleted)
return OK;
/* shift all remaining entries down */
for ( ; index < pAliases->numEntries; index++, pAlias++)
{
if (index < pAliases->numEntries - 1)
{
pAlias[0] = pAlias[1];
pAlias->pName -= delta;
pAlias->pText -= delta;
}
}
pAliases->bufferUsed -= delta;
pAliases->numEntries--;
return OK;
}
/***************************************************************************
*
* ALIAS_Init - initialize alias support
*
* Assign each token to a node, parameter keyword or parameter data
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*
* NOMANUAL
*/
LOCAL void ALIAS_Init
(
WMB_SESSION_T * pCliEnv,
cmdNode * pNode
)
{
AliasTable *pAliases = MMISC_AliasPtr(pCliEnv);
if (NULL != pNode)
pAliases->pAliasCmd = pNode->pKeyword;
else
pAliases->pAliasCmd = NULL;
}
/***************************************************************************
*
* RCC_ALIAS_CreateAlias - create a new alias
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*
* NOMANUAL
*/
STATUS RCC_ALIAS_CreateAlias
(
WMB_SESSION_T * pCliEnv,
sbyte * aliasName,
sbyte * aliasText
)
{
AliasTable *pAliases = MMISC_AliasPtr(pCliEnv);
sbyte *buffer = pAliases->data;
cmdNode *pNode = MMISC_GetCmdNode(pCliEnv);
sbyte4 currLen;
sbyte4 nameLen;
sbyte4 textLen;
sbyte4 index;
sbyte slashAlias[kRCC_ALIAS_BUFFER_SIZE];
sbyte *pslashAlias = slashAlias;
if (NULL_STRING(aliasName) || NULL_STRING(aliasText))
return RCC_ERROR_THROW(RCC_ERROR);
/* don't let user change "alias" itself!! */
if ((NULL != pNode) && (0 == COMPARE(pNode->pKeyword, aliasName)))
return RCC_ERROR_THROW(RCC_ERROR);
ALIAS_Init(pCliEnv, pNode);
if (kRCC_ALIAS_COUNT <= pAliases->numEntries)
return RCC_ERROR_THROW(ERROR_RCC_MAX_ALIASES);
/* remove prior definition, if it exists */
RCC_ALIAS_DeleteAlias(pCliEnv, aliasName);
index = pAliases->numEntries;
currLen = pAliases->bufferUsed;
/* convert "xxxx" to \"xxxx\" to preserve quotes through the parser */
if (NULL != (pslashAlias = strrchr(aliasText,kDoubleQuote)))
{
*pslashAlias='\0'; /* terminate at last Double Quote, keep the initial quote */
sprintf(slashAlias,"%c%s%c%c",kBackSlash,aliasText,kBackSlash,kDoubleQuote);
STRCPY(aliasText,slashAlias);
}
nameLen = (sbyte4)STRLEN(aliasName) + 1; /* don't forget null term */
textLen = (sbyte4)STRLEN(aliasText) + 1; /* don't forget null term */
if (kRCC_ALIAS_BUFFER_SIZE < nameLen + textLen + currLen)
return RCC_ERROR_THROW(RCC_ERROR);
buffer += currLen;
STRCPY(buffer, aliasName);
pAliases->alias[index].pName = buffer;
buffer += nameLen;
STRCPY(buffer, aliasText);
pAliases->alias[index].pText = buffer;
pAliases->bufferUsed += (nameLen + textLen);
pAliases->numEntries++;
return OK;
}
/***************************************************************************
*
* RCC_ALIAS_AliasDump - save alias info for a future session
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*/
STATUS RCC_ALIAS_AliasDump
(
WMB_SESSION_T * pCliEnv,
sbyte * pDumpBuffer,
sbyte4 bufferSize
)
{
AliasTable *pAliases = MMISC_AliasPtr(pCliEnv);
CmdAlias *pAlias = pAliases->alias;
sbyte *pWrite = pDumpBuffer;
sbyte4 writeSize = 0;
sbyte4 remaining = bufferSize;
sbyte4 index;
if (NULL == pDumpBuffer)
return RCC_ERROR_THROW(ERROR_GENERAL_NULL_POINTER);
for (index = 0; index < pAliases->numEntries; index++, pAlias++)
{
writeSize = (sbyte4)wmMin(remaining, (sbyte4) STRLEN(pAlias->pName));
STRNCPY(pWrite, pAlias->pName, (ubyte4)remaining);
remaining -= writeSize;
pWrite += writeSize;
if (0 < remaining)
{
*(++pWrite) = 0;
remaining--;
}
writeSize = (sbyte4)wmMin(remaining, (sbyte4) STRLEN(pAlias->pText));
STRNCPY(pWrite, pAlias->pText, (ubyte4)remaining);
remaining -= writeSize;
pWrite += writeSize;
if (0 < remaining)
{
*(++pWrite) = 0;
remaining--;
}
}
*pWrite = (sbyte)kRCC_END_OF_DUMP;
return OK;
}
/***************************************************************************
*
* RCC_ALIAS_AliasRestore - retrieve alias info from prior saved session
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*/
STATUS RCC_ALIAS_AliasRestore
(
WMB_SESSION_T * pCliEnv,
sbyte * pDumpBuffer,
sbyte4 bufferSize
)
{
sbyte *pRead = pDumpBuffer;
sbyte *pName = NULL;
sbyte *pText = NULL;
if (NULL == pDumpBuffer)
return RCC_ERROR_THROW(ERROR_GENERAL_NULL_POINTER);
while (0 < bufferSize)
{
pText = pName = pRead;
while (0 != *(pText++))
bufferSize--;
RCC_ALIAS_CreateAlias(pCliEnv, pName, pText);
pRead = pText;
while (0 != *(pRead++))
bufferSize--;
if ((sbyte) kRCC_END_OF_DUMP != *pRead)
break;
}
return OK;
}
#endif /* ! __NO_ALIASING__ */
#endif /* __RCC_ENABLED__ */
@@ -0,0 +1,487 @@
/* rcc_cmd.c - internal command support */
/*
* Copyright (c) 2002-2008, 2010-2012 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
--------------------
01o,13dec12,shi adjust the display items of who, and format the output.
(WIND00388779)
01n,16feb12,f_f make command "who" can get ipv6 address (WIND00329147)
01m,12aug11,m_z remove history trigger in RCC_CMD_ExecFile
01l,30mar11,r_w fix defect WIND00257291 make API reference readable
01k,25jan11,m_z command who on ssh show real IP address
CQID: Fix WIND00203639
01j,17dec10,m_z part of APIs changed
CQID: Fix WIND00247096
01i,14sep10,m_z adjust display information of command "who"
CQID: Fix WIND00232854
01h,27jul10,m_z eliminate compile warning
01g,19apr10,m_z VxWorks 64-bit support
(WIND00193649)
01f,17dec08,m_z dynamically set cli session max number when initial
(WIND00127186)
01e,22feb07,msa Correct the apigen comments so they match the actual
routines.
01d,13feb07,msa Fix comments to remove APIgen errors.
01c,05may04,gsr add support to display correct SNMP error messages SPR 90299
01b,23sep03,jws fix compiler warnings, SPR 90282
01a,03may02,pns initial WRS layout.
*/
/*
DESCRIPTION
This module provides command parsing support for CLI.
*/
#include "wm.h"
#include "wmb.h"
#ifdef __RCC_ENABLED__
#include "rcc.h"
#ifdef __SNMP_API_ENABLED__
#ifdef ENVOY_STACK_K
#include "rcm_envoy.h"
#include "rcm_ev_cnv.h"
#include "rcm_snmp.h"
#endif
#if (defined(__GENERIC_SNMP_V1__) || defined(__CMU_SNMP_V1__))
#include "rcm_cmu.h"
#include "rcm_cmu_cnv.h"
#include "rcm_snmp.h"
#endif
#include "rcm_mibway.h"
#include "wmmMethodRoutine.h"
#endif /* __SNMP_API_ENABLED__*/
#define envDir(pCliEnv) pCliEnv->pDir
#ifdef __RCC_TASK_MAX_DYN__
extern ubyte4 kRCC_TASK_MAX;
#endif
/***************************************************************************
*
* RCC_CMD_Snmp_Auto - toggle support for automatic snmp writes
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*/
STATUS RCC_CMD_Snmp_Auto
(
WMB_SESSION_T * pCliEnv
)
{
RCC_EXT_WriteStr(pCliEnv, kRCC_MSG_SNMPAUTO);
if (RCC_IsEnabled(pCliEnv, kRCC_FLAG_SNMPAUTO))
{
RCC_DisableFeature(pCliEnv, kRCC_FLAG_SNMPAUTO);
RCC_EXT_WriteStrLine(pCliEnv, kRCC_MSG_DISABLED);
}
else
{
RCC_EnableFeature(pCliEnv, kRCC_FLAG_SNMPAUTO);
RCC_EXT_WriteStrLine(pCliEnv, kRCC_MSG_ENABLED);
}
return OK;
}
/***************************************************************************
*
* RCC_CMD_Snmp_Commit - write pending snmp command
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*
* NOMANUAL
*/
STATUS RCC_CMD_Snmp_Commit
(
WMB_SESSION_T * pCliEnv
)
{
STATUS status = OK;
#ifdef __SNMP_API_ENABLED__
snmpStatus *pSnmpStatus = NULL;
status = OCSNMP_Commit(pCliEnv, 0, &pSnmpStatus);
if (OK != status)
{
if (! NULL_STRING(pSnmpStatus->error_text))
RCC_EXT_WriteStrLine(pCliEnv, pSnmpStatus->error_text);
/* get corresponding WMB error code */
status = wmmErrorSNMPToWMB((ubyte2)pSnmpStatus->error_status);
}
if (NULL != pSnmpStatus)
wmFree(pSnmpStatus);
#endif /* __SNMP_API_ENABLED__ */
return status;
}
/***************************************************************************
*
* RCC_CMD_DosClear - clear DOS screen
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*
* NOMANUAL
*/
#ifdef __WIN32_OS__
void RCC_CMD_DosClear
(
WMB_SESSION_T * pCliEnv
)
{
CONSOLE_SCREEN_BUFFER_INFO lpScreenBufferInfo;
DWORD nLength;
COORD dwWriteCoord;
DWORD NumberOfCharsWritten;
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
if (INVALID_HANDLE_VALUE == console)
return;
if (0 == GetConsoleScreenBufferInfo(console, &lpScreenBufferInfo))
return;
dwWriteCoord.X = 0;
dwWriteCoord.Y = 0;
nLength = lpScreenBufferInfo.dwSize.X * lpScreenBufferInfo.dwSize.Y;
if (! FillConsoleOutputCharacter(
console, // handle to screen buffer
' ', // character
nLength, // number of cells
dwWriteCoord, // first coordinates
&NumberOfCharsWritten // number of cells written
))
return;
SetConsoleCursorPosition(console, dwWriteCoord);
}
#endif /* __WIN32_OS__ */
/***************************************************************************
*
* RCC_CMD_Clear - clear screen
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*/
STATUS RCC_CMD_Clear
(
WMB_SESSION_T * pCliEnv
)
{
#ifdef __WIN32_OS__
if (kRCC_CONN_CONSOLE == MCONN_GetConnType(pCliEnv))
RCC_CMD_DosClear(pCliEnv);
else
#endif /* __WIN32_OS__ */
{
/* assume that non-Windows console is really telnet */
switch MCONN_GetTermType(pCliEnv)
{
case kRCC_TERM_XTERM:
RCC_EXT_PutStr(pCliEnv, kRCC_XTERM_CLEAR); /* ESC Ctrl-L */
break;
case kRCC_TERM_CONSOLE:
case kRCC_TERM_ANSI:
case kRCC_TERM_VT100: /* fall through */
default:
RCC_EXT_PutStr(pCliEnv, kRCC_VT100_CLEAR);
RCC_EXT_PutStr(pCliEnv, kRCC_VT100_HOME);
}
}
return OK;
}
/***************************************************************************
*
* RCC_CMD_ExecFile - execute a script file
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*/
STATUS RCC_CMD_ExecFile
(
WMB_SESSION_T * pCliEnv,
sbyte * pFileName,
BOOL echo
)
{
#if defined(__ANSI_FILE_MANAGER_ENABLED__)
STATUS status = OK;
sbyte *pFileBuffer = NULL;
#ifndef _WRS_CONFIG_LP64
sbyte4 fileLen = 0;
#else
sbyte8 fileLen = 0;
#endif
BOOL isAnsi = FALSE;
pFileBuffer = wmFileReadFile(wmbSessionDirGet(pCliEnv), &fileLen, pFileName);
if (NULL != pFileBuffer)
{
isAnsi = TRUE;
}
else
{
return RCC_ERROR_THROW(ERROR_GENERAL_FILE_NOT_FOUND);
}
RCC_EnableFeature(pCliEnv, kRCC_FLAG_EXEC);
status = RCC_CMD_Exec(pCliEnv, pFileBuffer, (sbyte4)fileLen, echo);
if (isAnsi)
wmFileReleaseFile(pFileBuffer);
RCC_DisableFeature(pCliEnv, kRCC_FLAG_EXEC);
return status;
#else
return RCC_ERROR_THROW(ERROR_GENERAL_FILE_NOT_FOUND);
#endif
}
/***************************************************************************
*
* RCC_CMD_ExecRM - execute windmark value as a script
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*/
STATUS RCC_CMD_ExecRM
(
WMB_SESSION_T * pCliEnv,
sbyte * pRapidMark,
BOOL echo
)
{
STATUS status = OK;
sbyte pRMBuffer[kMagicMarkupBufferSize];
#ifndef _WRS_CONFIG_LP64
sbyte4 rapidLength;
#else
sbyte8 rapidLength;
#endif
status = wmbDataStringGet (pCliEnv, pRapidMark, NULL, 0, pRMBuffer,
kMagicMarkupBufferSize, (ssize_t*)&rapidLength);
if (OK != status)
return status;
return RCC_CMD_Exec(pCliEnv, pRMBuffer, (sbyte4)rapidLength, echo);
}
/***************************************************************************
*
* RCC_CMD_Who - show users logged into system
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*/
STATUS RCC_CMD_Who
(
WMB_SESSION_T * pCliEnv
)
{
sbyte4 index;
WMB_SESSION_T *pOther;
WMNET_IP_ADDR ipAddr;
#ifndef _WRS_CONFIG_LP64
ubyte4 now;
#else
ubyte8 now;
#endif
sbyte4 ptty;
sbyte *pTermName;
sbyte terminal[18];
sbyte connHost[64];
sbyte elapsedTime[18];
sbyte formatStr[128];
now = wmosTimeGet();
sprintf(formatStr," %-10s%-12s%-14s%-s","User","Line","ElapsedTime","Host");
RCC_EXT_WriteStrLine(pCliEnv, formatStr);
for (index = 0; index < kRCC_TASK_MAX; index++)
{
if (NULL == (pOther = RCC_TELNETD_GetSession(index)))
continue;
if (NULL == CLIENV(pOther))
continue;
ptty = MCONN_GetPtty(pOther);
wmConvertSecsToStr ((ubyte4)(now - MCONN_GetStartTime(pOther)), elapsedTime, (sbyte4)sizeof(elapsedTime));
pTermName = MCONN_GetTermName(pOther);
sprintf(terminal, "%s/%d", pTermName, index);
switch (MCONN_GetConnType(pOther))
{
case kRCC_CONN_CONSOLE:
sprintf(connHost,"(%s)",MCONN_GetTermName(pOther));
break;
case kRCC_CONN_TELNET:
wmnetClientIpAddrGet(MCONN_GetSock(pOther), &ipAddr);
#ifdef __WM_INET6__
if (ipAddr.family == AF_INET6)
{
struct in6_addr container;
memcpy((void *)&container, (const void *)ipAddr.ipAddrBytes, sizeof(struct in6_addr));
if (IN6_IS_ADDR_LOOPBACK(&container) && pOther->clientAddr[0])
strcpy(connHost, pOther->clientAddr);
else
wmConvertToStr(ipAddr.ipAddrBytes, connHost, sizeof(connHost), DATATYPE_IPV6_K);
}
#endif
if (ipAddr.family == AF_INET)
{
ubyte4 nAddr;
nAddr = *(ubyte4 *)(ipAddr.ipAddrBytes);
if (nAddr == HTON4(INADDR_LOOPBACK) && pOther->clientAddr[0])
{
strcpy(connHost, pOther->clientAddr);
}
else
{
wmConvertToStr(&ipAddr, connHost, sizeof(connHost), DATATYPE_IPV4_K);
}
}
break;
}
sprintf(formatStr," %-10s%-12s%-14s%-s",strlen(MMISC_GetLogin(pOther))>0? MMISC_GetLogin(pOther):"(None)",terminal,elapsedTime,connHost);
RCC_EXT_WriteStrLine(pCliEnv, formatStr);
}
return OK;
}
/***************************************************************************
*
* RCC_CMD_Write - write a message to another user
*
*
* RETURNS: OK, or ERROR
*
* ERRNO:
*/
STATUS RCC_CMD_Write
(
WMB_SESSION_T * pCliEnv,
sbyte * recipient,
sbyte * message
)
{
sbyte4 index;
WMB_SESSION_T *pOther;
sbyte *pWriter;
BOOL match;
if (NULL_STRING(recipient))
return RCC_ERROR_THROW(ERROR_RCC_INVALID_USER);
if (NULL_STRING(message))
return RCC_ERROR_THROW(ERROR_RCC_NO_PARAM_DATA);
pWriter = MMISC_GetLogin(pCliEnv);
match = FALSE;
for (index = 0; index < kRCC_TASK_MAX; index++)
{
pOther = RCC_TELNETD_GetSession(index);
if ((NULL == pOther) || (NULL == CLIENV(pOther)))
continue;
if (0 != COMPARE(recipient, MMISC_GetLogin(pOther)))
continue;
match = TRUE;
if (pCliEnv != pOther)
{
RCC_EXT_WriteStrLine(pOther, "");
RCC_EXT_WriteStr(pOther, "Message from: ");
RCC_EXT_WriteStrLine(pOther, pWriter);
}
RCC_EXT_WriteStrLine(pOther, message);
if (pCliEnv != pOther)
RCC_DB_ShowInput(pOther, TRUE);
}
if (! match)
return RCC_ERROR_THROW(ERROR_RCC_INVALID_USER);
return OK;
}
#endif /* __RCC_ENABLED__ */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,236 @@
/* rcc_system.c - CLI system defaults */
/*
* Copyright (c) 2003-2004, 2007, 2010-2012 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
--------------------
01k,22nov12,f_f Added the kKEY_BREAK and kKEY_ESCAPE to the gEditKeys
(REQ: WIND00364534)
01j,01feb12,h_l add ERROR_RCC_BAD_COMMAND_RETRY item
01i,15dec11,f_f remove TASK_NOMSG_K flag from all the invalid parameter error type
01h,15nov11,r_w change flags TASK_BOTH_K to TASK_RETRY_K for ERROR_RCC_INVALID_PARAM(defect WIND00316385)
01g,29jun11,r_w change flags TASK_BOTH_K to TASK_RETRY_K for ERROR_GENERAL_ILLEGAL_VALUE
CQID: defect WIND00272292
01f,30mar11,r_w fix defect WIND00257291 make API reference readable
01e,20apr10,m_z VxWorks 64-bit support
(WIND00193649)
01d,22feb07,msa Correct the apigen comments so they match the actual
routines.
01c,25nov04,gsr correct gErrorTable[] for error messages SPR 86753
01b,05may04,gsr add SNMP error codes to gErrorTable SPR 90299
01a,20may03,pns initial WRS layout.
*/
/*
DESCRIPTION
This module provides command parsing support for CLI.
*/
#include "wm.h"
#include "wmb.h"
#ifdef __RCC_ENABLED__
#include "rcc.h"
EditKeys gEditKeys[] =
{
{kKEY_DELETE_CHAR, "Delete current character"},
{kKEY_DELETE_FROM_START, "Delete text up to cursor"},
{kKEY_DELETE_TO_END, "Delete from cursor to end of line"},
{kKEY_LINE_START, "Move to beginning of line"},
{kKEY_LINE_END, "Move to end of line"},
{kKEY_MOVE_UP, "Get prior command from history"},
{kKEY_MOVE_DOWN, "Get next command from history"},
{kKEY_MOVE_LEFT, "Move cursor left"},
{kKEY_MOVE_RIGHT, "Move cursor right"},
{kKEY_WORD_PREV, "Move back one word"},
{kKEY_WORD_NEXT, "Move forward one word"},
{kKEY_BREAK, "Break the execution"},
{kKEY_ESCAPE, "Break the execution"},
{kKEY_UPPERCASE, "Convert rest of word to uppercase"},
{kKEY_LOWERCASE, "Convert rest of word to lowercase"},
{kKEY_DELETE_WORD_END, "Delete remainder of word"},
{kKEY_DELETE_WORD_START, "Delete word up to cursor"},
{kKEY_TRANSPOSE, "Transpose current and previous character"},
{kKEY_END_OF_ENTRY, "Enter command and return to root prompt"},
{kKEY_REFRESH_DISPLAY, "Refresh input line"}
};
#define TASK_BOTH_K TASK_RETRY_K | TASK_NOMSG_K
ErrorTable gErrorTable[] =
{
{TASK_NONE_K, ERROR_GENERAL_INVALID_PATH, kMSG_ERROR_GENERAL_INVALID_PATH},
{TASK_NONE_K, ERROR_RCC_INVALID_HISTORY, kMSG_ERROR_RCC_INVALID_HISTORY},
{TASK_NONE_K, ERROR_GENERAL_NOT_FOUND, kMSG_ERROR_GENERAL_NOT_FOUND},
{TASK_NONE_K, ERROR_RCC_HANDLER_EXEC_FAILED, NULL},
{TASK_NONE_K, ERROR_RCC_NO_ERROR_MSG, NULL},
{TASK_NONE_K, ERROR_GENERAL_ACCESS_DENIED, kMSG_ERROR_GENERAL_ACCESS_DENIED},
{TASK_RETRY_K, ERROR_RCC_BAD_COMMAND_RETRY, kMSG_ERROR_RCC_BAD_COMMAND},
{TASK_NONE_K, ERROR_RCC_BAD_COMMAND, kMSG_ERROR_RCC_BAD_COMMAND},
{TASK_RETRY_K, ERROR_RCC_INVALID_PARAM, kMSG_ERROR_RCC_INVALID_PARAM},
{TASK_RETRY_K, ERROR_GENERAL_ILLEGAL_VALUE, kMSG_ERROR_RCC_INVALID_PARAM},
{TASK_RETRY_K, ERROR_CONVERSION_INCORRECT_TYPE, kMSG_ERROR_RCC_INVALID_PARAM},
{TASK_RETRY_K, ERROR_CONVERSION_OVERFLOW, kMSG_ERROR_RCC_INVALID_PARAM},
{TASK_RETRY_K, ERROR_RCC_INVALID_VALUE, kMSG_ERROR_RCC_INVALID_PARAM},
{TASK_RETRY_K, ERROR_GENERAL_DATA_AMBIG, kMSG_ERROR_GENERAL_DATA_AMBIG},
{TASK_RETRY_K, ERROR_RCC_AMBIGUOUS_PARAM, kMSG_ERROR_RCC_AMBIGUOUS_PARAM},
{TASK_RETRY_K, ERROR_RCC_NO_PARAM_DATA, kMSG_ERROR_RCC_NO_PARAM_DATA},
{TASK_NONE_K, ERROR_GENERAL_INVALID_RAPIDMARK, kMSG_ERROR_INVALID_RAPIDMARK},
{TASK_RETRY_K, ERROR_RCC_MISSING_PARAM, kMSG_ERROR_RCC_MISSING_PARAM},
{TASK_NONE_K, ERROR_RCC_NO_HANDLER, kMSG_ERROR_RCC_NO_HANDLER},
{TASK_NONE_K, ERROR_RCC_INVALID_USER, kMSG_ERROR_RCC_INVALID_USER},
{TASK_NONE_K, ERROR_CONVERSION_TOO_LONG, kMSG_ERROR_CONVERSION_TOO_LONG},
{TASK_NONE_K, ERROR_RCC_NO_HELP, kMSG_ERROR_RCC_NO_HELP},
{TASK_RETRY_K, ERROR_GENERAL_OUT_OF_RANGE, kMSG_ERROR_GENERAL_OUT_OF_RANGE},
{TASK_NONE_K, ERROR_GENERAL_FILE_NOT_FOUND, kMSG_ERROR_GENERAL_FILE_NOT_FOUND},
{TASK_RETRY_K, ERROR_RCC_AMBIGUOUS_COMMAND, kMSG_ERROR_RCC_AMBIGUOUS_COMMAND},
{TASK_RETRY_K, ERROR_RCC_INVALID_NO, kMSG_ERROR_RCC_INVALID_NO},
{TASK_RETRY_K, ERROR_RCC_EXTRA_PARAMS, kMSG_ERROR_RCC_EXTRA_PARAMS},
{TASK_RETRY_K, ERROR_RCC_BAD_PARAM_ORDER, kMSG_ERROR_RCC_BAD_PARAM_ORDER},
{TASK_RETRY_K, ERROR_RCC_KEYWORD_AS_PARAM, kMSG_ERROR_RCC_KEYWORD_AS_PARAM},
{TASK_RETRY_K, ERROR_RCC_CUSTOM_RETRY, kMSG_ERROR_RCC_CUSTOM_RETRY},
{TASK_NONE_K, ERROR_RCC_CUSTOM_NO_RETRY, kMSG_ERROR_RCC_CUSTOM_NO_RETRY},
{TASK_RETRY_K, ERROR_RCC_NO_CHAIN, kMSG_ERROR_RCC_NO_CHAIN},
{TASK_RETRY_K, ERROR_RCC_MISSING_NO, kMSG_ERROR_RCC_MISSING_NO},
{TASK_NONE_K, ERROR_RCC_MAX_ALIASES, kMSG_ERROR_RCC_MAX_ALIASES},
{TASK_NONE_K, ERROR_GENERAL_NO_ACCESS, kMSG_ERROR_GENERAL_NO_ACCESS},
{TASK_RETRY_K, ERROR_GENERAL_INCONSISTENT_VALUE, kMSG_ERROR_GENERAL_INCONSISTENT_VALUE},
{TASK_RETRY_K, ERROR_GENERAL_INCONSISTENT_NAME, kMSG_ERROR_GENERAL_INCONSISTENT_NAME},
{TASK_NONE_K, ERROR_GENERAL_RESOURCE_UNAVAILABLE,kMSG_ERROR_GENERAL_RESOURCE_UNAVAILABLE},
{TASK_NONE_K, ERROR_GENERAL_WRONG_VALUE, kMSG_ERROR_GENERAL_WRONG_VALUE},
{TASK_NONE_K, ERROR_GENERAL_NO_CREATION, kMSG_ERROR_GENERAL_NO_CREATION},
{TASK_NONE_K, ERROR_GENERAL_COMMIT_FAILED, kMSG_ERROR_GENERAL_COMMIT_FAILED},
{TASK_NONE_K, ERROR_GENERAL_UNDO_FAILED, kMSG_ERROR_GENERAL_UNDO_FAILED},
{TASK_NONE_K, ERROR_GENERAL_WRONG_LENGTH, kMSG_ERROR_GENERAL_WRONG_LENGTH},
{TASK_NONE_K, ERROR_GENERAL_TOO_BIG, kMSG_ERROR_GENERAL_TOO_BIG},
{TASK_NONE_K, ERROR_GENERAL_NO_SUCH_NAME, kMSG_ERROR_GENERAL_NO_SUCH_NAME},
{TASK_BOTH_K, ERROR_GENERAL_BAD_VALUE, kMSG_ERROR_GENERAL_BAD_VALUE},
{TASK_NONE_K, ERROR_GENERAL_READ_ONLY, kMSG_ERROR_GENERAL_READ_ONLY},
{TASK_NONE_K, ERROR_GENERAL_WRONG_TYPE, kMSG_ERROR_GENERAL_WRONG_TYPE},
{TASK_NONE_K, ERROR_GENERAL_WRONG_ENCODING, kMSG_ERROR_GENERAL_WRONG_ENCODING},
{TASK_RETRY_K, ERROR_GENERAL_AUTHORIZATION_ERROR, kMSG_ERROR_GENERAL_AUTHORIZATION_ERROR},
{TASK_NONE_K, ERROR_GENERAL_NOT_WRITABLE, kMSG_ERROR_GENERAL_NOT_WRITABLE},
};
/***************************************************************************
*
* RCC_SYSTEM_EvalError - evaluate error
*
* RETURNS: NA
*
* ERRNO:
*/
ubyte4 RCC_SYSTEM_EvalError
(
STATUS status,
sbyte * * ppMsg
)
{
ErrorTable * pError;
sbyte4 index;
pError = gErrorTable;
for (index = 0; index < (sbyte4)(ARRAY_SIZE(gErrorTable)); index++, pError++)
{
if (status != pError->status)
continue;
*ppMsg = pError->pErrorText;
return pError->flags;
}
*ppMsg = NULL;
return 0;
}
/***************************************************************************
*
* HELP_ShowHotKey - show the key text for a given key
*
* RETURNS: NA
*
* ERRNO:
*
* NOMANUAL
*/
LOCAL void HELP_ShowHotKey
(
WMB_SESSION_T * pCliEnv,
ubyte key
)
{
sbyte keyText;
if (key <= 26)
{
keyText = (sbyte)(CONTROL_KEY(key));
RCC_EXT_WriteStr(pCliEnv, "Ctrl-");
RCC_EXT_Write(pCliEnv, &keyText, 1);
}
else
{
keyText = (sbyte)(ESCAPE_KEY(key));
RCC_EXT_WriteStr(pCliEnv, "Esc-");
RCC_EXT_Write(pCliEnv, &keyText, 1);
}
}
/***************************************************************************
*
* RCC_SYSTEM_EditHelp - show editing commands
*
* RETURNS: NA
*
* ERRNO:
*/
STATUS RCC_SYSTEM_EditHelp
(
WMB_SESSION_T * pCliEnv
)
{
EditKeys * pEditKey;
sbyte4 index;
RCC_EXT_WriteStrLine(pCliEnv, kRCC_MSG_KEYSTROKES);
pEditKey = gEditKeys;
for (index = 0; index < (sbyte4)(ARRAY_SIZE(gEditKeys)); index++, pEditKey++)
{
RCC_EXT_PrintString(pCliEnv, pEditKey->helpText, kRCC_HELP_KEYS_WIDTH, '.');
HELP_ShowHotKey(pCliEnv, pEditKey->key);
RCC_EXT_WriteStrLine(pCliEnv, "");
}
RCC_EXT_WriteStrLine(pCliEnv, "");
return OK;
}
#endif /* __RCC_ENABLED__ */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,820 @@
/* memPoolLib.c - memory pool management */
/*
* Copyright (c) 1997-2008, 2010 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
--------------------
02i,28apr10,m_z eliminate compile warning
02h,29jan10,m_z VxWorks 64-bit support
(WIND00193649)
02g,10jan08,ps add semaphore protection to memPoolCheck()
02f,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
02e,28aug02,jc fixed semTake 0 timeout bug
02d,12apr02,pns added support for managing shared memory
02c,15mar02,pns added support for tracking memory used (leak detection)
02b,16jan02,pns ported to windmanage
02a,16may01,jc renamed to memPool and ported to wmos
01f,09jun99,km merge of Wind Web Server 2.0 code drop from 3Soft.
01e,17feb99,ck fixed wrong assertion statement.
01d,04dec98,mb bugfix: httpMemPartAlloc() caused memory corruption, reworked.
01c,13may97,mb osal introduced.
01b,12may97,ics logical simplifications.
01a,03mar97,ck initial creation.
*/
/*
DESCRIPTION
This module provides memory pool management.
NOMANUAL
*/
#include <stdio.h>
#define DEFINED_MEM_POOL_DESC
#define __DEBUG_MESSAGES_OFF__ /* undefine to allow debugging messages */
#include "wrn/wm/common/wm.h"
/* if in shared memory then pointers are stored as offset from pool id */
#ifdef __ENABLE_SHARED_MEMORY__
#define memPtrGet(pool, data) (void *) (pool->shared ? wmPtrGet(pool, data) : data)
#define memPtrSet(pool, data) (void *) (pool->shared ? wmPtrSet(pool, data) : data)
#else
#define memPtrGet(pool, data) data
#define memPtrSet(pool, data) data
#endif
/*******************************************************************************
*
* memPoolNew - create a memory pool (used by macro memPoolCreate)
*
* This routine creates a new memory pool, inside a memory block supplied by
* the caller. It returns a pool ID, which can be passed to other routines to
* manage the pool (that is, to allocate and free memory blocks in the
* partition). Partitions can be created to manage any number of
* separate memory pools.
*
* NOTE: Most of the memory required for administrative data is taken
* from the specified memory block. Therefore, the actual available
* memory will be slightly smaller than <ulPoolSize>.
* There is some additional dynamic memory allocation for some types
* of administrative data (such as semaphores or control blocks) that
* does not come from the block.
*
* RETURNS: The pool ID, or NULL if there is insufficient memory in
* the system memory pool for a new pool descriptor.
*
* NOMANUAL
*/
MEM_POOL_ID memPoolNew
(
char * pPool, /* memory area to create the pool in */
unsigned long ulPoolSize /* size in bytes of pPool */
#ifdef __ENABLE_SHARED_MEMORY__
,
BOOL shared
#endif
)
{
MEM_POOL_ID memDesc = NULL;
if (NULL == pPool)
{
wmError (ERROR_GENERAL, "Input parameter is NULL!");
return (NULL);
}
if (ulPoolSize < sizeof (MEM_POOL_MCB) +
sizeof (MEM_POOL_DESC) +
sizeof (unsigned long) +
MCB_ALIGN )
{
wmError (ERROR_GENERAL, "Partition too small for admin data!");
return (NULL);
}
memset (pPool, 0, ulPoolSize);
memDesc = (MEM_POOL_ID) pPool;
memDesc->ulPoolSize = ulPoolSize - sizeof (MEM_POOL_DESC)
- sizeof(unsigned long);
memDesc->ulWatermarkFree = memDesc->ulPoolSize;
#ifdef __ENABLE_SHARED_MEMORY__
memDesc->shared = shared;
#endif
if (OK != wmosSemCreate (&memDesc->semLockPool, 1, SEM_TYPICAL_K))
{
/* !! log this error !! */
return (NULL);
}
memPoolCleanup (memDesc);
DEBUG_MSG_2 ("memPoolCreate: id: 0x%x size: %d\n", pPool, ulPoolSize);
return (memDesc);
}
/*******************************************************************************
*
* memPoolCleanup - clear a memory pool
*
* This routine clears an existing pool containing a
* specified memory pool. It reinitializes the pool to its
* initial state, from which no memory is allocated. If
* there is a pointer to memory allocated from this pool, that
* memory will be corrupted and subsequently re-allocated.
*
* RETURNS: OK if the pool was cleaned up properly,
* or ERROR if the administrative data was found to be corrupted.
*
* NOMANUAL
*/
STATUS memPoolCleanup
(
MEM_POOL_ID poolId /* Memory pool ID */
)
{
MEM_POOL_MCB * pStart;
MEM_POOL_MCB * pPoolStart;
unsigned long ulSize;
unsigned long * pulDelimit;
#ifdef __ENABLE_SHARED_MEMORY__
DEBUG_MSG_2("memPoolCleanup: pool 0x%x is%s shared\n",
poolId, poolId->shared ? "" : " NOT");
#endif
if (poolId == NULL)
return wmError (ERROR_GENERAL, "memPoolCleanup: NULL poolID");
/*
* Calculate the start address of the allocatable memory. If this
* is our first time through, we'll need to initialize
* poolId->pPoolStart.
*/
pStart = (MEM_POOL_MCB *) ((((unsigned long) poolId + sizeof(MEM_POOL_DESC)
+ MCB_ALIGN - 1) / MCB_ALIGN) * MCB_ALIGN);
if (NULL == poolId->pPoolStart)
{
DEBUG_MSG_2 ("memPoolCleanup: pool: 0x%x start using : 0x%x\n",
poolId, pStart);
poolId->pPoolStart = memPtrSet(poolId, pStart);
pPoolStart = pStart;
DEBUG_MSG_2 ("memPoolCleanup: pool: 0x%x start NATIVE: 0x%x\n",
poolId, poolId->pPoolStart);
}
else
{
if (OK != memPoolCheck (poolId))
return wmError (ERROR_GENERAL, "memPoolCleanup: pool corrupted!");
pPoolStart = memPtrGet(poolId, poolId->pPoolStart);
}
DEBUG_MSG_2 ("memPoolCleanup: pool: 0x%x start: 0x%x\n", poolId, pPoolStart);
ulSize = poolId->ulPoolSize;
/* XXX walk through list to free semaphores, once they are introduced... */
if (OK != wmosSemTake (poolId->semLockPool, WAIT_FOREVER_K))
return ERROR;
memset (pStart, 0, ulSize);
pPoolStart->ulUsage = MCB_FREE;
pPoolStart->pPoolNext = NULL;
pPoolStart->ulBlockSize = poolId->ulPoolSize
- sizeof (MEM_POOL_MCB)
- ((unsigned long) pPoolStart + sizeof(MEM_POOL_DESC)) %
sizeof(MCB_ALIGN);
/* XXX SEM CREATE */
pulDelimit = (unsigned long *) ((char *)pStart + poolId->ulPoolSize );
*pulDelimit= MCB_DELIMITER;
wmosSemGive (poolId->semLockPool);
return OK;
}
#ifdef xx__ENABLE_MEMMGR_DEBUG__
/*******************************************************************************
*
* memPoolExists - see if a memory pool already created for address
*
* This routine checks if the administrative data of the given
* memory pool is still valid. This routine has a good chance of
* detecting corruption (caused, for example, by exceeding the bounds
* of allocated memory), but it cannot be guaranteed that it will
* do so.
*
* RETURNS: OK if the pool is valid, or ERROR if the
* administrative data has been corrupted.
*
* NOMANUAL
*/
BOOL memPoolExists
(
MEM_POOL_ID poolId /* memory pool to check */
)
{
MEM_POOL_MCB * pNextMCB;
if (poolId == NULL)
return wmError (ERROR_GENERAL,"memPoolExists: null id");
pNextMCB = pPoolAnchor;
while (pNextMCB != NULL)
{
if (poolId == pNextMCB)
return TRUE;
pNextMCB = memPtrGet(poolId, pNextMCB->pPoolNext);
}
return (OK);
}
#endif
/*******************************************************************************
*
* memPoolCheck - check the itegrity of a memory pool
*
* This routine checks if the administrative data of the given
* memory pool is still valid. This routine has a good chance of
* detecting corruption (caused, for example, by exceeding the bounds
* of allocated memory), but it cannot be guaranteed that it will
* do so.
*
* RETURNS: OK if the pool is valid, or ERROR if the
* administrative data has been corrupted.
*
* NOMANUAL
*/
STATUS memPoolCheck
(
MEM_POOL_ID poolId /* memory pool to check */
)
{
MEM_POOL_MCB * pStart;
MEM_POOL_MCB * pNextMCB;
#ifdef DEBUG_INFO
MEM_POOL_MCB * pLastMCB = NULL;
unsigned long ulAvailBytes = 0;
#endif
unsigned long * pulDelimit;
if (poolId == NULL)
return wmError (ERROR_GENERAL,"memPoolCheck: null poolID");
wmosSemTake (poolId->semLockPool, WAIT_FOREVER_K);
pStart = (MEM_POOL_MCB *) ((((unsigned long) poolId +
sizeof (MEM_POOL_DESC) + MCB_ALIGN - 1) / MCB_ALIGN) * MCB_ALIGN);
/* do all comparisons in pointer space, since we'll be using pointers */
pNextMCB = memPtrGet(poolId, poolId->pPoolStart);
if ((NULL != poolId->pPoolStart) && (pStart != pNextMCB))
{
DEBUG_MSG_2 ("memPoolCheck: invalid id: 0x%x expected start = 0x%x native = 0x%x\n",
poolId, pStart);
DEBUG_MSG_3 ("memPoolCheck: invalid id: 0x%x adjusted start = 0x%x native = 0x%x\n",
poolId, memPtrGet(poolId, poolId->pPoolStart), poolId->pPoolStart);
wmosSemGive (poolId->semLockPool);
return wmError (ERROR_GENERAL,"memPoolCheck: descriptor table invalid!");
}
/* check for pool overrun */
pulDelimit = (unsigned long *) ((char *) pStart + poolId->ulPoolSize);
if (*pulDelimit != MCB_DELIMITER)
{
wmosSemGive (poolId->semLockPool);
return wmError (ERROR_GENERAL, "memPoolCheck: end-of-pool overrun!");
}
/* walk through all pools */
while (NULL != pNextMCB)
{
MEM_POOL_MCB * pNextPossibleMCB;
pNextPossibleMCB = wmAdjust (pNextMCB, sizeof(MEM_POOL_MCB) + pNextMCB->ulBlockSize);
if (pNextMCB->ulUsage != MCB_FREE && pNextMCB->ulUsage != MCB_OCCUPIED)
{
DEBUG_MSG_3 ("memPoolCheck: 0x%x NextMCB: 0x%x NEXT_Possible: 0x%x\n",
poolId, pNextMCB, pNextPossibleMCB);
DEBUG_MSG_2 ("memPoolCheck: 0x%x type: 0x%x\n", poolId, pNextMCB->ulUsage);
wmosSemGive (poolId->semLockPool);
return wmError (ERROR, "memPoolCheck: bad block type");
}
/* if shared memory we need to make offsets back into pointers */
if ((NULL != pNextMCB->pPoolNext) &&
(memPtrGet(poolId, pNextMCB->pPoolNext) != pNextPossibleMCB))
{
#ifdef DEBUG_INFO
fprintf (stderr, "memPoolCheck: MCB corrupted between block %#x and %#x! "
"(signature set to %#lx, next is %x, should be %x)\n",
(int) pNextMCB, (int) pLastMCB, pNextMCB->ulUsage,
(int) pNextMCB->pPoolNext, (int) pNextPossibleMCB);
#endif
wmosSemGive (poolId->semLockPool);
return (ERROR);
}
#ifdef DEBUG_INFO
pLastMCB = pNextMCB;
ulAvailBytes += pNextMCB->ulBlockSize + sizeof (MEM_POOL_MCB);
#endif
#ifdef __ENABLE_SHARED_MEMORY__
if (poolId->shared)
DEBUG_MSG_3 ("memPoolCheck: id: 0x%x next: 0x%x adjusted 0x%x\n",
poolId, pNextMCB->pPoolNext,
memPtrGet(poolId, pNextMCB->pPoolNext));
#endif
pNextMCB = memPtrGet(poolId, pNextMCB->pPoolNext);
}
#ifdef DEBUG_INFO
ulAvailBytes += ((unsigned long)(poolId->pPoolStart)+sizeof(MEM_POOL_DESC))
% sizeof (MCB_ALIGN);
if (poolId->ulPoolSize != ulAvailBytes)
fprintf (stderr,"memPoolCheck: Memory leak detected! "
"%ld bytes from %ld bytes are missing!\n",
poolId->ulPoolSize - ulAvailBytes, poolId->ulPoolSize);
#endif
wmosSemGive (poolId->semLockPool);
return (OK);
}
/*******************************************************************************
*
* memPoolDelete - destroy a memory pool
*
* This routine destroys an existing memory pool. If there is
* pointer to memory allocated from this pool, that memory will be
* corrupted and subsequently returned to its original owner.
*
* RETURNS: A pointer to the memory block originally used to create this
* pool (as given to memPoolCreate()), or NULL if there is an error.
*
* NOMANUAL
*/
char * memPoolDelete
(
MEM_POOL_ID poolId /* Memory pool ID */
)
{
if (OK != memPoolCleanup (poolId))
{
wmError (ERROR_GENERAL,"memPoolCleanup: error during cleanup");
return (NULL);
}
wmosSemDestroy (poolId->semLockPool);
return ((char *) poolId);
}
/*******************************************************************************
*
* memPoolAvail - get the size of memory available in a pool
*
* This routine returns the total amount of unused memory in a pool if
* <sMode> is 0. It returns the size of the largest contiguous block of
* memory if <sMode> is 1. In the debugging library, 128 gives the minimum
* number of bytes that have up to now been available (the high
* water-mark).
*
* RETURNS: The number of bytes in the largest available block
*
* NOMANUAL
*/
unsigned long memPoolAvail
(
MEM_POOL_ID poolId, /* memory pool to check */
short sMode
)
{
MEM_POOL_MCB * mcbTmp;
unsigned long ulFree;
ulFree = 0;
if (memPoolCheck (poolId) != OK)
{
wmError (ERROR_GENERAL,"memPoolAvail: no valid pool");
return (0);
}
if (OK != wmosSemTake (poolId->semLockPool, WAIT_FOREVER_K))
return (0);
if (sMode == 128)
ulFree = poolId->ulPoolSize - poolId->ulWatermarkFree;
else
{
mcbTmp = memPtrGet(poolId, poolId->pPoolStart);
while (mcbTmp != NULL)
{
if (mcbTmp->ulUsage == MCB_FREE)
{
if ((sMode == 1) && (ulFree <(mcbTmp->ulBlockSize)))
ulFree = (mcbTmp->ulBlockSize);
if (sMode == 0)
ulFree += mcbTmp->ulBlockSize;
}
mcbTmp = memPtrGet(poolId, mcbTmp->pPoolNext);
}
}
wmosSemGive (poolId->semLockPool);
return (ulFree);
}
/*******************************************************************************
*
* memPoolUsed - get the amount of memory used in a pool
*
* RETURNS: The number of bytes in the largest available block
*
* NOMANUAL
*/
long memPoolUsed
(
MEM_POOL_ID poolId /* memory pool to check */
)
{
if (OK != memPoolCheck (poolId))
{
wmError (ERROR_GENERAL,"memPoolAvail: no valid pool");
return -1;
}
return (long)poolId->memUsed;
}
/*******************************************************************************
*
* memPoolAlloc - allocate a memory block from a memory pool
*
* This routine allocates a block of memory from a specified
* pool. The size of the block will be equal to or greater than
* <ulBytes> (the best-fit strategy is employed to choose the
* block of memory). The pool must already have been initialized with
* memPoolCreate().
*
* RETURNS: A pointer to the memory pool as given to memPoolCreate(),
* or NULL if there is an error.
*
* NOMANUAL
*/
void * memPoolAlloc
(
MEM_POOL_ID poolId, /* Memory pool ID */
unsigned long ulBytes /* Number of bytes to allocate */
)
{
MEM_POOL_MCB * mcbBestFit;
MEM_POOL_MCB * mcbTmp;
unsigned long ulFree;
unsigned long ulRoundedBlockSize;
if (memPoolCheck (poolId) != OK)
{
wmError (ERROR_GENERAL,"memPoolAlloc: no valid pool");
return (NULL);
}
if (OK != wmosSemTake (poolId->semLockPool, WAIT_FOREVER_K))
{
wmError (ERROR_GENERAL,"memPoolAlloc: wmosSemTake failed");
return (NULL);
}
mcbTmp = memPtrGet(poolId, poolId->pPoolStart);
/* Try to find a perfect match, (mcbBestFit->ulBlockSize == ulBytes)
or the closest one! */
mcbBestFit = NULL;
while ((mcbBestFit == NULL) || (mcbBestFit->ulBlockSize != ulBytes))
{
if ((mcbTmp->ulUsage == MCB_FREE) &&
(mcbTmp->ulBlockSize >= ulBytes) &&
( (mcbBestFit == NULL) || (mcbBestFit->ulBlockSize > mcbTmp->ulBlockSize)) )
{
mcbBestFit = mcbTmp;
}
if (NULL == (mcbTmp = memPtrGet(poolId, mcbTmp->pPoolNext)))
break;;
}
/* Nothing with at least ulBytes found... give up! */
if (mcbBestFit == NULL)
{
wmosSemGive (poolId->semLockPool);
DEBUG_MSG_2 ("memPoolAlloc: size requested: %d available: %d\n",
ulBytes, poolId->ulPoolSize - poolId->memUsed);
wmError (ERROR_GENERAL, "memPoolAlloc: insufficient memory");
return (NULL);
}
/* ulRoundedBlockSize: size of requested memory including fraction
of aligment boundaries */
ulRoundedBlockSize = ( ( ulBytes + MCB_ALIGN - 1 ) / MCB_ALIGN ) * MCB_ALIGN;
/* take a bigger block and try to split it! */
/* there must be enough memory for at least 1 more MCB, */
/* the current memory block and the new memory block */
/* to be able to split memory blocks ! */
if (mcbBestFit->ulBlockSize > ( ulRoundedBlockSize + sizeof (MEM_POOL_MCB ) ) )
{
/* SPLIT found memory block into two halves, aligned to sizeof (mem_pool_mcb) */
mcbTmp = (MEM_POOL_MCB *) (((char *)mcbBestFit) + ulRoundedBlockSize +
sizeof (MEM_POOL_MCB) );
/* fprintf ( stdout,"memPoolAlloc: splitting block, new block at %lx,
parent at %lx.\n", &mcbTmp[1],&mcbBestFit[1]); */
/* generate new MCB */
mcbTmp->ulUsage = MCB_FREE;
mcbTmp->pPoolNext = memPtrSet(poolId, mcbBestFit->pPoolNext);
mcbTmp->ulBlockSize = mcbBestFit->ulBlockSize - sizeof (MEM_POOL_MCB) - ulRoundedBlockSize;
#if 0 /* figure out how to replace this later */
assert ( mcbTmp->ulBlockSize > 0 );
#endif
/* ALLOCATE semaphore semLockBlock .... XXX */
/* modify existing MCB, ulBlockSize never counts sizeof(MEM_POOL_MCB) */
mcbBestFit->pPoolNext = memPtrSet(poolId, mcbTmp);
mcbBestFit->ulBlockSize = ulRoundedBlockSize;
}
/* Now, we should have found *anything* satisfying out needs */
#if 0
assert (mcbBestFit->ulBlockSize >= ulBytes);
#endif
mcbBestFit->ulUsage = MCB_OCCUPIED;
wmosSemGive (poolId->semLockPool);
ulFree = memPoolAvail (poolId, 0);
if (poolId->ulWatermarkFree > ulFree)
poolId->ulWatermarkFree = ulFree;
#ifdef DEBUG_INFO
printf("Block %p allocated!\n", &(mcbBestFit[1]));
#endif
poolId->memUsed += mcbBestFit->ulBlockSize;
mcbBestFit++;
DEBUG_MSG_2("memPoolAlloc: pool: 0x%x addr: 0x%x\n", poolId, mcbBestFit);
return ((void *) mcbBestFit);
}
/*******************************************************************************
*
* memPoolFree - free a memory block in a memory pool
*
* This routine returns a block of memory to the specified pool.
*
* RETURNS:
* OK, or ERROR if the pool is corrupt or invalid, or if
* the memory pointer is not to a valid block of memory
* previously allocated from this pool.
*
*
* NOMANUAL
*/
STATUS memPoolFree
(
MEM_POOL_ID poolId, /* Memory pool ID */
void * pBlock /* pointer to block of memory to free */
)
{
MEM_POOL_MCB * mcbLast = NULL;
MEM_POOL_MCB * mcbTmp;
MEM_POOL_MCB * mcbCurrent;
MEM_POOL_MCB * mcbNext;
char * pPoolStart;
if (NULL == poolId)
{
wmosFree(pBlock);
return OK;
}
if (memPoolCheck (poolId) != OK)
return wmError (ERROR_GENERAL,"memPoolFree: no valid pool");
/* check if pointer given to free, SEEMS to be correct... */
DEBUG_MSG_2 ("memPoolFree: pool: 0x%x addr: 0x%x\n", poolId, pBlock);
pPoolStart = (char *) memPtrGet(poolId, poolId->pPoolStart);
if ((char *)pBlock < pPoolStart ||
(char *)pBlock > pPoolStart + poolId->ulPoolSize + sizeof (MEM_POOL_DESC))
{
#ifdef __ENABLE_SHARED_MEMORY__
DEBUG_MSG_2 ("memPoolCheck: pool: 0x%x %s\n", poolId,
poolId->shared ? "SHARED" : "NOT SHARED");
#endif
DEBUG_MSG_2 ("memPoolCheck: pool: 0x%x native: 0x%x\n",
poolId, poolId->pPoolStart);
DEBUG_MSG_3 ("memPoolCheck: block: 0x%x start: 0x%x end: 0x%x\n",
pBlock, pPoolStart, pPoolStart + poolId->ulPoolSize);
return wmError (ERROR_GENERAL, "memPoolFree: can't find memory");
}
mcbCurrent = (MEM_POOL_MCB *) ((char *)pBlock - sizeof (MEM_POOL_MCB));
if (mcbCurrent->ulUsage == MCB_FREE || mcbCurrent->ulUsage != MCB_OCCUPIED)
{
DEBUG_MSG_2 ("memPoolCheck: pool: 0x%x block: 0x%x\n", poolId, pBlock);
return wmError (ERROR_GENERAL, "memPoolFree: invalid or already freed!");
}
#ifdef __WM_DIRTY__
/* "dirty" data to force error if used after free */
memset(pBlock, MY_BAD_K, mcbCurrent->ulBlockSize);
#endif
if (OK != wmosSemTake (poolId->semLockPool, WAIT_FOREVER_K))
return ERROR;
mcbTmp = memPtrGet(poolId, poolId->pPoolStart);
while (mcbTmp != NULL && mcbTmp != mcbCurrent)
{
mcbLast = mcbTmp;
mcbTmp = memPtrGet(poolId, mcbTmp->pPoolNext);
}
if (mcbTmp != mcbCurrent)
{
wmosSemGive (poolId->semLockPool);
return wmError (ERROR_GENERAL, "memPoolFree: block not found!");;
}
/* mark current block as free... */
mcbCurrent->ulUsage = MCB_FREE;
poolId->memUsed -= mcbCurrent->ulBlockSize;
/* when next block is free also, concatenate them ... */
mcbNext = memPtrGet(poolId, mcbCurrent->pPoolNext);
if (NULL != mcbNext && mcbNext->ulUsage == MCB_FREE)
{
mcbCurrent->ulBlockSize += mcbNext->ulBlockSize + sizeof (MEM_POOL_MCB);
/* FREE semaphore of now obsolete mcb.... once it is introduced! */
/* semDelete... */
mcbCurrent->pPoolNext = mcbNext->pPoolNext;
}
/* when preceding block is free also, concatenate them ... */
if (mcbLast != NULL && mcbLast->ulUsage == MCB_FREE)
{
mcbLast->ulBlockSize += mcbCurrent->ulBlockSize
+ sizeof (MEM_POOL_MCB);
/* FREE semaphore of now obsolete mcb.... once it is introduced! */
/* semDelete... */
mcbLast->pPoolNext = mcbCurrent->pPoolNext;
}
wmosSemGive (poolId->semLockPool);
#ifdef DEBUG_INFO
printf("Block %p freed!\n", pBlock);
#endif
return (OK);
}
#ifdef __ENABLE_MEMMGR_DEBUG__
/*******************************************************************************
*
* memPoolBlockSize - return size of memory block for debugging
*
* This routine returns the size of a block of memory in the specified pool.
*
* RETURNS:
* OK, or ERROR if the pool is corrupt or invalid, or if
* the memory pointer is not to a valid block of memory
* previously allocated from this pool.
*
* NOMANUAL
*/
sbyte4 memPoolBlockSize
(
MEM_POOL_ID poolId, /* Memory pool ID */
void * pBlock
)
{
MEM_POOL_MCB * mcbCurrent;
char * pPoolStart;
if (memPoolCheck (poolId) != OK)
return -1;
/* check if pointer given to free, SEEMS to be correct... */
pPoolStart = (char *) memPtrGet(poolId, poolId->pPoolStart);
/* should range check be a macro -- used elsewhere? */
if ((char *)pBlock < pPoolStart ||
(char *)pBlock > pPoolStart + poolId->ulPoolSize + sizeof (MEM_POOL_DESC))
return -1;
mcbCurrent = (MEM_POOL_MCB *) ((char *)pBlock - sizeof (MEM_POOL_MCB));
if (mcbCurrent->ulUsage == MCB_FREE || mcbCurrent->ulUsage != MCB_OCCUPIED)
return -1;
return mcbCurrent->ulBlockSize;
} /* memPoolSize */
#endif /* __ENABLE_MEMMGR_DEBUG__ */
#ifdef __ENABLE_SHARED_MEMORY__
BOOL memPoolShared
(
MEM_POOL_ID pool
)
{
return pool->shared;
}
#endif /* __ENABLE_SHARED_MEMORY__ */
/* eof memPoolLib.c */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,89 @@
/* mudUtils.c - Utilities for Multithreaded Universal Daemon (MUD)*/
/* Copyright 1984-2007, 2010 Wind River Systems, Inc. */
/*
modification history
--------------------
01g,28apr10,m_z eliminate compile warning
01f,29jan10,m_z VxWorks 64-bit support
(WIND00193649)
01e,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01d,02jan04,jws add mudlib.h include
01c,18dec03,adb included private/mudLibP.h
01b,02may03,jws remove assert()'s
01a,06sep01,jc written.
*/
/*
DESCRIPTION
Put a Multithreaded Universal Daemon in your life!
*/
/* include C standard library */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* include OSAL */
#include "wm.h"
/* include public interface to mud */
#include "memPoolLib.h"
#include "private/mudLibP.h"
#include "mudLib.h" /* this is needed !! */
#include "mudUtils.h" /* this is needed !! */
/**************************************************************************
*
* readLineFromSocket - Read a line from a socket.
*
* Read a single LF (\n) terminated line from a socket and terminate
* it with a NULL
*
* RETURNS: OK, or ERROR.
*
* NOMANUAL
*/
STATUS readLineFromSocket
(
MUD_SOCKET sock,
char * buffer,
#ifndef _WRS_CONFIG_LP64
ubyte4 sizebuf
#else
ubyte8 sizebuf
#endif
)
{
char oneChar;
#ifndef _WRS_CONFIG_LP64
sbyte4 bytesRead;
ubyte4 bytesMsg;
#else
sbyte8 bytesRead;
ubyte8 bytesMsg;
#endif
STATUS status;
bytesMsg = 0;
/* read as much as we can from the socket, and send an acknowledgement */
wmnetSocketBlocking (sock, TRUE);
do
{
if (OK != (status = wmnetTcpRead (sock, &oneChar, 1, &bytesRead)))
return status;
buffer[bytesMsg] = oneChar;
bytesMsg++;
} while (('\n' != oneChar) && (bytesMsg <= sizebuf));
buffer[bytesMsg] = 0; /* terminate string */
return OK;
}
/* eof mudUtils.c */
@@ -0,0 +1,731 @@
/* wmnetBSD.c - Implementation in BSD of the Rapid Control net AL */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,19feb04,jws Add modification history and copyright, SPR 92723
*/
/*
DESCRIPTION
This module implements all the functions defined in wmnet.h for BSD
*
*/
#include "wm.h"
#ifdef __BSD_OS__
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdarg.h>
#include <arpa/inet.h>
#include <errno.h>
/* constants used ONLY in this module */
#define kTCP_LISTEN_BACKLOG 20
#define kMinimalSocketTimeout 10
LOCAL OS_SOCKET_T tcpSocketCreate
(
void
)
{
OS_SOCKET_T sock;
sock = socket(PF_INET, SOCK_STREAM, 0);
DEBUG_MSG_1("socket 0x%x created\n", sock);
return sock;
}
LOCAL STATUS bindSocketToAddr
(
OS_SOCKET_T sock,
ubyte2 port
)
{
struct sockaddr_in LocalAddr;
/* ask the system to allocate a port and bind to INADDR_ANY */
memset(&LocalAddr, 0x00, sizeof(LocalAddr));
/* get system to allocate a port number by binding a host address */
LocalAddr.sin_family = PF_INET;
LocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
LocalAddr.sin_port = htons(port);
/* bind socket to local address */
if (ERROR == bind(sock, (struct sockaddr *) &LocalAddr, sizeof(LocalAddr)))
{
wmosError(ERROR_GENERAL_ACCESS_DENIED, "bindSocketToAddr: failed");
close(sock);
return ERROR;
}
return OK;
}
STATUS wmnetInitialize
(
void
)
{
return OK;
}
STATUS wmnetUdpBind
(
OS_SOCKET_T * pSock,
ubyte2 port
)
{
/* Create a datagram stream socket */
if (OK != wmnetUdpSocketCreate(pSock))
return ERROR;
if (OK != bindSocketToAddr(*pSock, port))
return ERROR;
return OK;
}
STATUS wmnetTcpServerOpen
(
OS_SOCKET_T * pSock,
ubyte2 port
)
{
STATUS status;
/* Create a stream socket */
if (-1 == (*pSock = tcpSocketCreate()))
return ERROR_GENERAL_ACCESS_DENIED;
if (OK != (status = bindSocketToAddr(*pSock, port)))
return status;
/* Create a incoming Client connect request queue */
if (0 != listen(*pSock, kTCP_LISTEN_BACKLOG))
{
wmosError(ERROR_GENERAL_ACCESS_DENIED, "wmnetTcpServerOpen: failed");
close(*pSock);
return ERROR;
}
return OK;
}
STATUS wmnetUdpSendTo
(
OS_SOCKET_T sock,
ubyte4 addr,
ubyte2 port,
sbyte * pBuffer,
ubyte4 bufSize
)
{
struct sockaddr_in *pAddrTo;
if (NULL == (pAddrTo = (struct sockaddr_in *) wmNew(pAddrTo)))
return ERROR_MEMMGR_NO_MEMORY;
pAddrTo->sin_family = PF_INET;
pAddrTo->sin_addr.s_addr = addr;
pAddrTo->sin_port = HTON2(port);
if (ERROR == sendto(sock, (sbyte *) pBuffer, bufSize, 0,
(struct sockaddr *)pAddrTo, sizeof(struct sockaddr)) )
{
wmFree(pAddrTo);
return wmosError(SYS_ERROR_SOCKET_GENERAL, "send failed");
}
wmFree(pAddrTo);
return OK;
}
STATUS wmnetUdpRcvFrom
(
OS_SOCKET_T sock,
ubyte4 * pAddrSender,
ubyte2 port,
sbyte * pBuffer,
ubyte4 bufSize,
sbyte4 * pBytesRead
)
{
struct sockaddr_in * pAddr;
ubyte4 iAddrLen;
int RecvResult;
iAddrLen = sizeof(*pAddr);
if ( NULL == (pAddr = (struct sockaddr_in *) wmMalloc(iAddrLen)) )
return ERROR_MEMMGR_NO_MEMORY;
RecvResult = recvfrom(sock, pBuffer, kMaxUdpPacketSize,
0, (struct sockaddr *) pAddr, &iAddrLen);
if (-1 == RecvResult)
{
wmFree(pAddr);
return wmosError(ERROR_GENERAL, "recv failed");
}
(*pAddrSender) = (ubyte4) pAddr->sin_addr.s_addr;
(*pBytesRead) = (ubyte4)RecvResult;
wmFree(pAddr);
return OK;
}
STATUS wmnetTcpAccept
(
OS_SOCKET_T * soc,
OS_SOCKET_T * accSoc,
ubyte2 port
)
{
struct sockaddr_in ClientAddr;
ubyte4 iAddrLen;
iAddrLen = sizeof(ClientAddr);
memset(&ClientAddr, 0x00, iAddrLen);
*accSoc = accept(*soc, (struct sockaddr *)&ClientAddr, &iAddrLen);
DEBUG_MSG_1("socket %d accepted++++++++++\n",*accSoc);
if (ERROR == *accSoc)
{
wmosError(ERROR_GENERAL, "wmnetTcpAccept: failed");
close(*accSoc);
close(*soc);
wmnetTcpServerOpen(soc, port);
return SYS_ERROR_SOCKET_ACCEPT;
}
return OK;
}
STATUS wmnetClientAddrGet
(
OS_SOCKET_T ClientSock,
ubyte4 * pAddr
)
{
struct sockaddr_in ClientAddr;
ubyte4 iAddrLen;
*pAddr = 0;
iAddrLen = sizeof(ClientAddr);
memset(&ClientAddr, 0x00, iAddrLen);
if (OK != getpeername(ClientSock, (struct sockaddr *)&ClientAddr, &iAddrLen))
return wmosError(ERROR_GENERAL, "unable to get address from socket");
*pAddr = ntohl(ClientAddr.sin_addr.s_addr);
return OK;
}
STATUS wmnetSocketClose
(
OS_SOCKET_T sock
)
{
DEBUG_MSG_1("wmnetSocketClose: socket = 0x%x\n", sock);
if (-1 == close(sock))
return wmosError (ERROR_GENERAL_ACCESS_DENIED,
"wmnetSocketClose: failed");
return OK;
}
LOCAL STATUS connectToServer
(
OS_SOCKET_T sock,
sbyte * pName,
ubyte2 port
)
{
struct sockaddr_in RemAddr;
ubyte4 ulHostAddress;
struct hostent * pHost;
char * pAddr;
memset(&RemAddr, 0x00, sizeof(RemAddr));
if (NULL == (pHost = gethostbyname(pName)))
return wmosError(ERROR_GENERAL,"remote host unknown");
pAddr = *(pHost->h_addr_list);
ulHostAddress = (ubyte4) ((ubyte4 *) pAddr);
RemAddr.sin_family = PF_INET;
RemAddr.sin_addr.s_addr = ulHostAddress;
RemAddr.sin_port = htons(port);
/* Create a Client connection */
if (-1 == connect( sock, (struct sockaddr *) &RemAddr, sizeof(RemAddr)))
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "connectToServer: failed");
return OK;
}
STATUS wmnetTcpConnect
(
OS_SOCKET_T * pSoc,
sbyte * pName,
ubyte2 port
)
{
STATUS status;
/* Create a stream socket */
*pSoc = tcpSocketCreate();
if (ERROR == *pSoc)
return wmosError(ERROR_GENERAL, "failed socket creation");
if (OK != (status = bindSocketToAddr(*pSoc, ANY_PORT_K)))
return status;
/* Create a Client connection */
return connectToServer( *pSoc, pName, port );
}
STATUS wmnetTcpWrite
(
OS_SOCKET_T sock,
sbyte * pBuf,
ubyte4 BufLen
)
{
if (-1 == send(sock, pBuf, BufLen, 0))
return ERROR_GENERAL_ACCESS_DENIED;
return OK;
}
STATUS wmnetTcpRead
(
OS_SOCKET_T sock,
sbyte * pBuf,
ubyte4 BufSize,
ubyte4 * pBytesRead
)
{
ubyte4 bytes;
DEBUG_MSG_2 ("tcp read start sock: %x size: %d\n", sock, BufSize);
if (-1 == (bytes = recv(sock, pBuf, BufSize, 0)))
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "wmnetTcpRead: failed");
if (NULL != pBytesRead)
*pBytesRead = bytes;
return OK;
}
/*******************************************************************************
*
* wmnetSocketBlocking - enable or disable socket blocking
*
* This function modifies the behavior of other socket functions. If socket
* blocking is enabled, calling wmosSocketRead or wmosSocketPeek will block until
* data is available. If socket blocking is disabled, these functions will return
* immediately.
*
* RETURNS: N/A
*
*/
STATUS wmnetSocketBlocking
(
OS_SOCKET_T sock, /* the socket */
BOOL block /* TRUE to enable socket blocking */
)
{
BOOL iOpt = (TRUE == block) ? FALSE : TRUE;
DEBUG_MSG_1("wmnetSocketBlocking: block = %d\n", block);
if (0 == ioctl (sock, FIONBIO, (int)&iOpt))
{
DEBUG_MSG_0("blocking set\n");
return OK;
}
switch(errno)
{
case EBADF:
DEBUG_MSG_0("d is not a valid descriptor.\n");
break;
case ENOTTY:
DEBUG_MSG_0("d is not associated with a character special device.\n");
break;
case EINVAL:
DEBUG_MSG_0("Request or argp is not valid.\n");
break;
default:
DEBUG_MSG_0("unknown ioctl error\n");
}
return wmosError(SYS_ERROR_SOCKET_GENERAL, "block set failed");
}
/*******************************************************************************
*
* wmnetSocketPeek - peek into a socket
*
* This routine peeks into a socket without modifying the data waiting on it. As
* many as (*pBufSize) characters are read and copied onto pBuf. When no data is
* pending, the routine will block or return immediately depending on wether
* socket blocking is enable or not (see wmnetSocketBlocking()).
*
* RETURNS: The number of characters that have been copied to pBuf or one of
* these errors:
* SYS_ERROR_SOCKET_TIMEOUT
* SYS_ERROR_SOCKET_GENERAL
*
*/
STATUS wmnetTcpPeek
(
OS_SOCKET_T sock, /* the socket */
sbyte * pBuf, /* the buffer where data will be copied */
ubyte4 BufSize, /* buffer size */
ubyte4 * pBytesRead /* return: number of bytes read */
)
{
ubyte4 bytes;
if (-1 == (bytes = recv(sock, pBuf, BufSize, MSG_PEEK)))
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "wmnetTcpPeek: failed");
*pBytesRead = bytes;
return OK;
}
/*******************************************************************************
*
* wmnetSocketGroupWait - wait on a set of sockets and/or pipes
*
* This routine blocks until there is some activity (data available for
* reading or socket/pipe is closed) on the set of monitored sockets.
*
* setOfSockets is the list of sockets/pipes to wait on and it can be modified
* using the functions wmnetSocketGroupAddTo, wmnetSocketGroupAddPipe and
* wmnetSocketGroupClear.
*
* When the function returns, wmnet[Socket/Pipe]WantsAction could be used to
* determine which of the monitored sockets.pipes was active.
*
* timeoutInSecs can be set to 0 to indicate no timeout (i.e. infinite wait)
*
* RETURNS: The number of characters that have been copied to pBuf or one of
* these errors:
* SYS_ERROR_SOCKET_TIMEOUT
* SYS_ERROR_SOCKET_GENERAL
*
*/
STATUS wmnetSocketGroupWait
(
OS_FDSET_T * setOfSockets,
ubyte4 timeoutInSecs
)
{
int r;
struct timeval tv;
DEBUG_MSG_1("wmnetSocketGroupWait: timeout = %d\n", timeoutInSecs);
tv.tv_sec = timeoutInSecs;
tv.tv_usec = 0;
DEBUG_MSG_1("wmnetSocketGroupWait: max sockets = %d\n", setOfSockets->fdMax + 1);
r = select (setOfSockets->fdMax + 1, &setOfSockets->fdSet, NULL, NULL, &tv);
if (-1 == r)
{
switch (errno)
{
case EBADF:
DEBUG_MSG_0("One of the descriptor sets specified an invalid descriptor.\n");
break;
case EINTR:
DEBUG_MSG_0("A signal was delivered before the time limit expired "
"and before any of the selected events occurred.\n");
break;
case EINVAL:
DEBUG_MSG_0("The specified time limit is invalid. One of its "
"components is negative or too large. Or nfds was invalid.\n");
break;
default:
DEBUG_MSG_0("unknown select error\n");
}
return SYS_ERROR_SOCKET_GENERAL;
}
if (0 == r)
return ERROR_GENERAL_TIMEOUT;
return OK;
}
STATUS wmnetSocketGroupAddTo
(
OS_SOCKET_T sock,
OS_FDSET_T * setOfSockets
)
{
if (sock > FD_SETSIZE)
{
DEBUG_MSG_2("wmnetSocketGroupAddTo: ERROR - socket 0x%x greater than 0x%x\n",
sock, FD_SETSIZE);
return ERROR_GENERAL;
}
DEBUG_MSG_1("wmnetSocketGroupAddTo: socket = 0x%x\n", sock);
FD_SET(sock, &setOfSockets->fdSet);
if (sock > setOfSockets->fdMax)
setOfSockets->fdMax = sock;
return OK;
}
STATUS wmnetSocketGroupAddPipe
(
OS_PIPE_T pipe,
OS_FDSET_T * setOfSockets
)
{
DEBUG_MSG_1("wmnetSocketGroupAddPipe: pipe = 0x%x\n", (int) pipe);
return wmnetSocketGroupAddTo ((OS_SOCKET_T) pipe, setOfSockets);
}
STATUS wmnetSocketGroupClear
(
OS_FDSET_T * setOfSockets
)
{
DEBUG_MSG_0("wmnetSocketGroupClear: called\n");
FD_ZERO(setOfSockets);
setOfSockets->fdMax = 0;
return OK;
}
BOOL wmnetSocketWantsAction
(
OS_SOCKET_T sock,
OS_FDSET_T * setOfSockets
)
{
DEBUG_MSG_1("wmnetSocketGroupAddTo: socket = %d\n", sock);
return FD_ISSET(sock, (&setOfSockets->fdSet));
}
BOOL wmnetPipeWantsAction
(
OS_PIPE_T pipe,
OS_FDSET_T * setOfSockets
)
{
DEBUG_MSG_0("wmnetPipeWantsAction: called\n");
return wmnetSocketWantsAction((OS_SOCKET_T) pipe, setOfSockets);
}
/*******************************************************************************
*
* wmnetSocketPrintf - output a formatted string to a socket
*
* This sends a formatted string to the connection socket.
* It is identical to printf() in terms of the
* usage of parameters and format strings.
*
* RETURNS: size of sent string
*/
sbyte4 wmnetSocketPrintf
(
OS_SOCKET_T sock,
sbyte * szFormat,
...
)
{
enum {PRINTF_BUFFER = 1000 };
va_list vaList;
sbyte tmpBuffer[PRINTF_BUFFER];
ubyte4 bytesPrinted = 0;
va_start (vaList, szFormat);
bytesPrinted = vsprintf (tmpBuffer, szFormat, vaList);
wmnetTcpWrite(sock, tmpBuffer, bytesPrinted);
va_end (vaList);
return bytesPrinted;
}
/*******************************************************************************
*
* wmnetSockPrintf - print a formatted string on a socket
*
* All parameters identical to vfprintf, except for the first which identifies
* a socket instead of a file. ANSI requires that call to vfprintf should be
* preceded by a call to va_start, and followed by a call to va_end. The same
* applies to this function.
*
* SPECIFIC TO THIS PORT:
* Formatted output cannot be sent to a socket under Windows (fprintf does
* not work on sockets) and a temporary buffer needs to be allocated. If the
* size of the message is larger than PRINTF_BUFFER some data will be lost.
*
* RETURNS: OK or an error
* The number of characters sent to the socket (by reference)
*
*/
STATUS wmnetSocketVprintf
(
OS_SOCKET_T sock,
sbyte * szFormat,
va_list args,
ubyte4 * pBytesPrinted
)
{
enum {PRINTF_BUFFER = 1000 };
sbyte tmpBuffer[PRINTF_BUFFER];
* pBytesPrinted = 0;
(* pBytesPrinted) = vsprintf (tmpBuffer, szFormat, args);
wmnetTcpWrite(sock, tmpBuffer, strlen(tmpBuffer));
return OK;
}
STATUS wmnetAddressResolve
(
sbyte * pName,
ubyte4 * pAddress
)
{
sbyte * pTmp;
struct hostent * pHostAddr;
struct in_addr * pInAddr;
/* only resolve once */
*pAddress = inet_addr(pName);
if (-1 != *pAddress)
return OK;
pHostAddr = gethostbyname (pName);
if (pHostAddr == NULL)
{
*pAddress = 0;
return wmosError(SYS_ERROR_SOCKET_GENERAL, "wmnetAddressResolve: invalid name");
}
pInAddr = (struct in_addr *) pHostAddr->h_addr_list[0];
pTmp = inet_ntoa(*pInAddr);
*pAddress = inet_addr(pTmp);
return (-1 != *pAddress) ? OK : SYS_ERROR_SOCKET_GENERAL;
}
STATUS wmnetUdpSocketCreate
(
OS_SOCKET_T * pSock
)
{
*pSock = socket(PF_INET, SOCK_DGRAM, 0);
if (-1 == *pSock)
return wmosError(SYS_ERROR_SOCKET_GENERAL,
"wmnetUdpSocketCreate: socket creation failed");
return OK;
}
/*******************************************************************************
*
* wmnetStdoutToSocket - redirect STDIO to a socket
*
* This routine redirects current STDIO to the socket. An OS specific value
* needed to restore the Stdout is returned by reference in the second parameter.
*
*
* RETURNS: 'OK' or an error
*/
STATUS wmnetStdoutToSocket
(
OS_SOCKET_T sock,
sbyte4 * pOldStdout
)
{
return OK;
}
#endif /*__BSD_OS__*/
@@ -0,0 +1,704 @@
/* wmnetPosix.c - Implementation in Posix of the WindManage net AL */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,19feb04,jws Add modification history and copyright, SPR 92723
*/
/*
DESCRIPTION
This module implements all the functions defined in wmnet.h for most
Posix IP stacks
*/
#include "wm.h"
#ifdef __POSIX_OS__
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/termios.h>
#include <netdb.h>
#include <sys/filio.h>
#include <errno.h>
/* constants used ONLY in this module */
#define kTCP_LISTEN_BACKLOG 20
#define kMinimalSocketTimeout 10
LOCAL STATUS wmnetTcpSocketCreate
(
OS_SOCKET_T * pSock
)
{
if (NULL == pSock)
return wmosError(ERROR, "wmnetTcpSocketCreate: null pointer");
*pSock = socket(PF_INET, SOCK_STREAM, 0);
if (-1 == *pSock)
return wmosError(ERROR, "wmnetTcpSocketCreate: creation failed");
return OK;
}
STATUS wmnetUdpSocketCreate
(
OS_SOCKET_T * pSock
)
{
*pSock = socket(PF_INET, SOCK_DGRAM, 0);
if (-1 == *pSock)
return wmosError(ERROR_GENERAL, "wmnetUdpSocketCreate: failed");
return OK;
}
STATUS wmnetAddressResolve
(
sbyte * pName,
ubyte4 * pAddress
)
{
sbyte * pTmp;
struct hostent * pHostAddr;
struct in_addr * pInAddr;
/* only resolve once */
*pAddress = inet_addr(pName);
if (-1 != *pAddress)
return OK;
pHostAddr = gethostbyname (pName);
if (pHostAddr == NULL)
{
*pAddress = 0;
return wmosError(SYS_ERROR_SOCKET_GENERAL, "wmnetAddressResolve: invalid name");
}
pInAddr = (struct in_addr *) pHostAddr->h_addr_list[0];
pTmp = inet_ntoa(*pInAddr);
*pAddress = inet_addr(pTmp);
if (-1 == *pAddress)
return wmosError(SYS_ERROR_SOCKET_GENERAL, "wmnetAddressResolve: bad address");
return OK;
}
/*-----------------------------------------------------------------------*/
LOCAL STATUS wmnetBindSockToAddr
(
OS_SOCKET_T soc,
ubyte2 port
)
{
struct sockaddr_in LocalAddr;
/* ask the system to allocate a port and bind to INADDR_ANY */
memset(&LocalAddr, 0x00, sizeof(LocalAddr));
/* get system to allocate a port number by binding a host address */
LocalAddr.sin_family = PF_INET;
LocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
LocalAddr.sin_port = htons((ubyte2)port);
/* bind socket to local address */
if (ERROR == bind(soc, (struct sockaddr *) &LocalAddr, sizeof(LocalAddr)))
{
close(soc);
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "");
}
return OK;
}
STATUS wmnetInitialize
(
void
)
{
return OK;
}
STATUS wmnetUdpBind
(
OS_SOCKET_T * pSoc,
ubyte2 port
)
{
/* Create a stream socket */
if (OK != wmnetUdpSocketCreate(pSoc))
return ERROR;
if (OK != wmnetBindSockToAddr(*pSoc, port))
return ERROR;
return OK;
}
STATUS wmnetTcpServerOpen
(
OS_SOCKET_T * pSoc,
ubyte2 port
)
{
/* Create a stream socket */
if (OK != wmnetTcpSocketCreate(pSoc))
return ERROR;
if (OK != wmnetBindSockToAddr(*pSoc, port))
return ERROR;
/* Create a incoming Client connect request queue */
if (0 != listen(*pSoc, kTCP_LISTEN_BACKLOG))
{
close(*pSoc);
return wmosError(ERROR_GENERAL, "wmnetTcpServerOpen: listen failed");
}
return OK;
}
STATUS wmnetUdpSendTo
(
OS_SOCKET_T sock,
ubyte4 addr,
ubyte2 port,
sbyte * pBuffer,
ubyte4 bufSize
)
{
struct sockaddr_in *pAddrTo;
if ( NULL == (pAddrTo = (struct sockaddr_in *) wmMalloc(sizeof(struct sockaddr_in))) )
return wmosError(ERROR_MEMMGR_NO_MEMORY, "wmnetUdpSendTo: no memory");
pAddrTo->sin_family = PF_INET;
pAddrTo->sin_addr.s_addr = addr;
pAddrTo->sin_port = HTON2(port);
if (ERROR == sendto(sock, (sbyte *) pBuffer,
bufSize, 0,
(struct sockaddr *)pAddrTo,
sizeof(struct sockaddr)) )
{
wmFree(pAddrTo);
return wmosError(SYS_ERROR_SOCKET_GENERAL, "wmnetUdpSendTo: sendto failed");
}
wmFree(pAddrTo);
return OK;
}
STATUS wmnetUdpRcvFrom
(
OS_SOCKET_T sock,
ubyte4 * pAddrSender,
ubyte2 port,
sbyte * pBuffer,
ubyte4 bufSize,
sbyte4 * pBytesRead
)
{
struct sockaddr_in *pAddr;
int iAddrLen;
int RecvResult;
iAddrLen = sizeof(struct sockaddr_in);
if ( NULL == (pAddr = (struct sockaddr_in *) wmMalloc(iAddrLen)) )
return wmosError(ERROR_MEMMGR_NO_MEMORY, "no memory");
RecvResult = recvfrom(sock, pBuffer, kMaxUdpPacketSize,
0, (struct sockaddr *)pAddr, &iAddrLen );
if (ERROR == RecvResult)
{
wmFree(pAddr);
return wmosError(ERROR_GENERAL, "");
}
*pAddrSender = (ubyte4) pAddr->sin_addr.s_addr;
*pBytesRead = (ubyte4) RecvResult;
wmFree(pAddr);
return OK;
}
/*-----------------------------------------------------------------------*/
STATUS wmnetTcpAccept
(
OS_SOCKET_T * soc,
OS_SOCKET_T * accSoc,
ubyte2 port
)
{
struct sockaddr_in ClientAddr;
int iAddrLen;
iAddrLen = sizeof(ClientAddr);
memset(&ClientAddr, 0x00, iAddrLen);
*accSoc = accept(*soc, (struct sockaddr *)&ClientAddr, &iAddrLen);
#ifdef DEBUG_VERBOSE
posixLog("socket %d accepted++++++++++\n",*accSoc);
#endif
if (ERROR == *accSoc)
{
close(*accSoc);
close(*soc);
wmnetTcpServerOpen(soc, port);
return wmosError(SYS_ERROR_SOCKET_ACCEPT, "wmnetTcpAccept: no server");
}
return OK;
}
/*-----------------------------------------------------------------------*/
STATUS wmnetClientAddrGet
(
OS_SOCKET_T ClientSock,
ubyte4 * pAddr
)
{
struct sockaddr_in ClientAddr;
int iAddrLen;
*pAddr = 0;
iAddrLen = sizeof(ClientAddr);
memset(&ClientAddr, 0x00, iAddrLen);
if (OK != getpeername(ClientSock, (struct sockaddr *)&ClientAddr, &iAddrLen))
return wmosError(ERROR_GENERAL, "unable to get address from socket");
*pAddr = ntohl(ClientAddr.sin_addr.s_addr);
return OK;
}
STATUS wmnetSocketClose
(
OS_SOCKET_T sock
)
{
#ifdef DEBUG_VERBOSE
posixLog("socket %d closed----------\n",sock,0,0,0,0,0);
#endif
if (ERROR == close(sock))
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "wmnetSocketClose");
return OK;
}
LOCAL STATUS connectToServer
(
OS_SOCKET_T sock,
sbyte * pName,
ubyte4 port
)
{
struct sockaddr_in RemAddr;
int err;
struct hostent * pHost;
memset(&RemAddr, 0x00, sizeof(RemAddr));
if (NULL == (pHost = gethostbyname(pName)))
return wmosError(ERROR_GENERAL,"remote host unknown");
RemAddr.sin_family = PF_INET;
RemAddr.sin_addr.s_addr = (unsigned int) pHost->h_addr;
RemAddr.sin_port = htons((ubyte2)port);
/* Create a Client connection */
err = connect( sock, (struct sockaddr *)&RemAddr, sizeof(RemAddr));
if ( ERROR == err )
return wmosError(ERROR_GENERAL_ACCESS_DENIED, NULL);
return OK;
}
STATUS wmnetTcpConnect
(
OS_SOCKET_T * pSoc,
sbyte * pName,
ubyte2 port
)
{
/* Create a stream socket */
if (OK != wmnetTcpSocketCreate(pSoc))
return ERROR;
if (OK != wmnetBindSockToAddr(*pSoc, ANY_PORT_K))
return ERROR;
/* Create a Client connection */
return connectToServer( *pSoc, pName, port );
}
STATUS wmnetTcpWrite
(
OS_SOCKET_T sock,
sbyte * pBuf,
ubyte4 bufLen
)
{
sbyte * pMsg;
if (ERROR != send(sock, pBuf, bufLen, 0))
return OK;
switch (errno)
{
case EBADF:
pMsg = "invalid file descriptor";
break;
case EINTR:
pMsg = "operation was interrupted by signal";
break;
case EINVAL:
pMsg = "tolen not valid size for specified address family";
break;
case EMSGSIZE:
pMsg = "socket requires message be sent atomically, "
"and the message was too long";
break;
case ENOMEM:
pMsg = "insufficient memory available";
break;
case ENOSR:
pMsg = "insufficient STREAMS resources";
break;
case ENOTSOCK:
pMsg = "not a socket";
break;
case EWOULDBLOCK:
pMsg = "socket is marked non-blocking and the "
"requested operation would block";
break;
default:
pMsg = "unknown send error";
break;
}
return wmosError(ERROR_GENERAL_ACCESS_DENIED, pMsg);
}
STATUS wmnetTcpRead
(
OS_SOCKET_T sock,
sbyte * pBuf,
ubyte4 BufSize,
ubyte4 * pBytesRead
)
{
ubyte4 bytes;
if (NULL != pBytesRead)
*pBytesRead = 0;
bytes = recv(sock, pBuf, BufSize, 0);
if (ERROR == bytes)
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "wmnetTcpRead: denied");
if (NULL != pBytesRead)
*pBytesRead = bytes;
return OK;
}
/*******************************************************************************
*
* wmnetSocketBlocking - enable or disable socket blocking
*
* This function modifies the behavior of other socket functions. If socket
* blocking is enabled, calling wmosSocketRead or wmosSocketPeek will block until
* data is available. If socket blocking is disabled, these functions will return
* immediately.
*
* RETURNS: N/A
*
*/
STATUS wmnetSocketBlocking
(
OS_SOCKET_T sock, /* the socket */
BOOL block /* TRUE to enable socket blocking */
)
{
int iOpt;
iOpt = ! block;
if (ERROR == ioctl (sock, FIONBIO, (int) &iOpt))
return wmosError (SYS_ERROR_SOCKET_GENERAL,
"wmnetSocketBlocking: ioctl failed");
return OK;
}
/*******************************************************************************
*
* wmnetSocketPeek - peek into a socket
*
* This routine peeks into a socket without modifying the data waiting on it. As
* many as (*pBufSize) characters are read and copied onto pBuf. When no data is
* pending, the routine will block or return immediately depending on wether
* socket blocking is enable or not (see wmnetSocketBlocking()).
*
* RETURNS: The number of characters that have been copied to pBuf or one of
* these errors:
* SYS_ERROR_SOCKET_TIMEOUT
* SYS_ERROR_SOCKET_GENERAL
*
*/
STATUS wmnetTcpPeek
(
OS_SOCKET_T sock, /* the socket */
sbyte * pBuf, /* the buffer where data will be copied */
ubyte4 BufSize, /* buffer size */
ubyte4 * bytesRead /* return: number of bytes read */
)
{
ubyte4 bytes;
bytes = recv(sock, pBuf, BufSize, MSG_PEEK);
if (ERROR == bytes)
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "wmnetTcpPeek: denied");
if (NULL != bytesRead)
*bytesRead = bytes;
return OK;
}
/*******************************************************************************
*
* wmnetSocketGroupWait - wait on a set of sockets and/or pipes
*
* This routine blocks until there is some activity (data available for
* reading or socket/pipe is closed) on the set of monitored sockets.
*
* setOfSockets is the list of sockets/pipes to wait on and it can be modified
* using the functions wmnetSocketGroupAddTo, wmnetSocketGroupAddPipe and
* wmnetSocketGroupClear.
*
* When the function returns, wmnet[Socket/Pipe]WantsAction could be used to
* determine which of the monitored sockets.pipes was active.
*
* timeoutInSecs can be set to 0 to indicate no timeout (i.e. infinite wait)
*
* RETURNS: The number of characters that have been copied to pBuf or one of
* these errors:
* SYS_ERROR_SOCKET_TIMEOUT
* SYS_ERROR_SOCKET_GENERAL
*
*/
STATUS wmnetSocketGroupWait
(
OS_FDSET_T * setOfSockets,
ubyte4 timeoutInSecs
)
{
int r;
struct timeval tv;
tv.tv_sec = timeoutInSecs;
tv.tv_usec = 0;
assert ((0 < setOfSockets->fdMax) && (64 > setOfSockets->fdMax));
r = select (setOfSockets->fdMax + 1, &setOfSockets->fdSet, NULL, NULL, &tv);
if (0 > r)
return wmosError(SYS_ERROR_SOCKET_GENERAL, "wmnetSocketGroupWait: error");
if (0 == r)
return wmosError(ERROR_GENERAL_TIMEOUT, "wmnetSocketGroupWait: timeout");
return OK;
}
STATUS wmnetSocketGroupAddTo
(
OS_SOCKET_T sock,
OS_FDSET_T * setOfSockets
)
{
FD_SET(sock, &setOfSockets->fdSet);
if (sock > setOfSockets->fdMax)
setOfSockets->fdMax = sock;
return OK;
}
STATUS wmnetSocketGroupAddPipe
(
OS_PIPE_T pipe,
OS_FDSET_T * setOfSockets
)
{
return wmnetSocketGroupAddTo ((OS_SOCKET_T) pipe,setOfSockets);
}
STATUS wmnetSocketGroupClear
(
OS_FDSET_T * setOfSockets
)
{
FD_ZERO(&setOfSockets->fdSet);
setOfSockets->fdMax = 0;
return OK;
}
BOOL wmnetSocketWantsAction
(
OS_SOCKET_T sock,
OS_FDSET_T * setOfSockets
)
{
return FD_ISSET(sock, &setOfSockets->fdSet);
}
BOOL wmnetPipeWantsAction
(
OS_PIPE_T pipe,
OS_FDSET_T * setOfSockets
)
{
return wmnetSocketWantsAction((OS_SOCKET_T) pipe, setOfSockets);
}
/*******************************************************************************
*
* wmnetSocketPrintf - output a formatted string to a socket
*
* This sends a formatted string to the connection socket.
* It is identical to printf() in terms of the
* usage of parameters and format strings.
*
* INTERNAL: Note that vfdprintf is not ANSI, and that the function is not
* portable because it assumes that a socket is a file descriptor, which is not
* true in some OSes.
*
* RETURNS: OK or ERROR.
*/
STATUS wmnetSocketPrintf
(
OS_SOCKET_T sock,
sbyte * szFormat,
...
)
{
#if 0
va_list vaList;
va_start (vaList, szFormat);
if (vfprintf (sock, szFormat, vaList) > 0)
{
#ifdef DEBUG_VERBOSE
/* produce verbose output */
printf ("SOCKET PRINTF: ");
vprintf (szFormat, vaList);
printf ("\n");
#endif
va_end (vaList);
return OK;
}
else
{
va_end (vaList);
return wmosError(ERROR_GENERAL, "wmnetSocketPrintf failed");
}
#endif
return 0;
}
/*******************************************************************************
*
* wmnetStdoutToSocket - redirect STDIO to a socket
*
* This routine redirects current STDIO to the socket. An OS specific value
* needed to restore the Stdout is returned by reference in the second parameter.
*
*
* RETURNS: 'OK' or an error
*/
STATUS wmnetStdoutToSocket
(
OS_SOCKET_T sock,
sbyte4 * pOldStdout
)
{
return OK;
}
#endif /*__POSIX_OS__*/
@@ -0,0 +1,758 @@
/* wmnetPosix.c - Implementation in Posix of the WindManage net AL */
/* Copyright 2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,19feb04,jws Add modification history and copyright, SPR 92723
*/
/*
DESCRIPTION
This module implements all the functions defined in wmnet.h for most
Posix IP stacks
*/
#include "wm.h"
#ifdef __SOLARIS_OS__
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/termios.h>
#include <netdb.h>
#include <sys/filio.h>
#include <errno.h>
/* constants used ONLY in this module */
#define kTCP_LISTEN_BACKLOG 20
#define kMinimalSocketTimeout 10
LOCAL STATUS wmnetTcpSocketCreate
(
OS_SOCKET_T * pSock
)
{
if (NULL == pSock)
return wmosError(ERROR, "wmnetTcpSocketCreate: null pointer");
*pSock = socket(PF_INET, SOCK_STREAM, 0);
if (-1 == *pSock)
return wmosError(ERROR, "wmnetTcpSocketCreate: creation failed");
return OK;
}
STATUS wmnetUdpSocketCreate
(
OS_SOCKET_T * pSock
)
{
*pSock = socket(PF_INET, SOCK_DGRAM, 0);
if (-1 == *pSock)
return wmosError(ERROR_GENERAL, "wmnetUdpSocketCreate: failed");
return OK;
}
STATUS wmnetAddressResolve
(
sbyte * pName,
ubyte4 * pAddress
)
{
sbyte * pTmp;
struct hostent * pHostAddr;
struct in_addr * pInAddr;
/* only resolve once */
*pAddress = inet_addr(pName);
if (-1 != *pAddress)
return OK;
pHostAddr = gethostbyname (pName);
if (pHostAddr == NULL)
{
*pAddress = 0;
return wmosError(SYS_ERROR_SOCKET_GENERAL, "wmnetAddressResolve: invalid name");
}
pInAddr = (struct in_addr *) pHostAddr->h_addr_list[0];
pTmp = inet_ntoa(*pInAddr);
*pAddress = inet_addr(pTmp);
if (-1 == *pAddress)
return wmosError(SYS_ERROR_SOCKET_GENERAL, "wmnetAddressResolve: bad address");
return OK;
}
/*-----------------------------------------------------------------------*/
LOCAL STATUS wmnetBindSockToAddr
(
OS_SOCKET_T soc,
ubyte2 port
)
{
struct sockaddr_in LocalAddr;
/* ask the system to allocate a port and bind to INADDR_ANY */
memset(&LocalAddr, 0x00, sizeof(LocalAddr));
/* get system to allocate a port number by binding a host address */
LocalAddr.sin_family = PF_INET;
LocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
LocalAddr.sin_port = htons((ubyte2)port);
/* bind socket to local address */
if (ERROR == bind(soc, (struct sockaddr *) &LocalAddr, sizeof(LocalAddr)))
{
close(soc);
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "");
}
return OK;
}
STATUS wmnetInitialize
(
void
)
{
return OK;
}
STATUS wmnetUdpBind
(
OS_SOCKET_T * pSoc,
ubyte2 port
)
{
/* Create a stream socket */
if (OK != wmnetUdpSocketCreate(pSoc))
return ERROR;
if (OK != wmnetBindSockToAddr(*pSoc, port))
return ERROR;
return OK;
}
STATUS wmnetTcpServerOpen
(
OS_SOCKET_T * pSoc,
ubyte2 port
)
{
/* Create a stream socket */
if (OK != wmnetTcpSocketCreate(pSoc))
return ERROR;
if (OK != wmnetBindSockToAddr(*pSoc, port))
return ERROR;
/* Create a incoming Client connect request queue */
if (0 != listen(*pSoc, kTCP_LISTEN_BACKLOG))
{
close(*pSoc);
return wmosError(ERROR_GENERAL, "wmnetTcpServerOpen: listen failed");
}
return OK;
}
STATUS wmnetUdpSendTo
(
OS_SOCKET_T sock,
ubyte4 addr,
ubyte2 port,
sbyte * pBuffer,
ubyte4 bufSize
)
{
struct sockaddr_in *pAddrTo;
if ( NULL == (pAddrTo = (struct sockaddr_in *) wmMalloc(sizeof(struct sockaddr_in))) )
return wmosError(ERROR_MEMMGR_NO_MEMORY, "wmnetUdpSendTo: no memory");
pAddrTo->sin_family = PF_INET;
pAddrTo->sin_addr.s_addr = addr;
pAddrTo->sin_port = HTON2(port);
if (ERROR == sendto(sock, (sbyte *) pBuffer,
bufSize, 0,
(struct sockaddr *)pAddrTo,
sizeof(struct sockaddr)) )
{
wmFree(pAddrTo);
return wmosError(SYS_ERROR_SOCKET_GENERAL, "wmnetUdpSendTo: sendto failed");
}
wmFree(pAddrTo);
return OK;
}
STATUS wmnetUdpRcvFrom
(
OS_SOCKET_T sock,
ubyte4 * pAddrSender,
ubyte2 port,
sbyte * pBuffer,
ubyte4 bufSize,
sbyte4 * pBytesRead
)
{
struct sockaddr_in *pAddr;
int iAddrLen;
int RecvResult;
iAddrLen = sizeof(struct sockaddr_in);
if ( NULL == (pAddr = (struct sockaddr_in *) wmMalloc(iAddrLen)) )
return wmosError(ERROR_MEMMGR_NO_MEMORY, "no memory");
RecvResult = recvfrom(sock, pBuffer, kMaxUdpPacketSize,
0, (struct sockaddr *)pAddr, &iAddrLen );
if (ERROR == RecvResult)
{
wmFree(pAddr);
return wmosError(ERROR_GENERAL, "");
}
*pAddrSender = (ubyte4) pAddr->sin_addr.s_addr;
*pBytesRead = (ubyte4) RecvResult;
wmFree(pAddr);
return OK;
}
/*-----------------------------------------------------------------------*/
STATUS wmnetTcpAccept
(
OS_SOCKET_T * soc,
OS_SOCKET_T * accSoc,
ubyte2 port
)
{
struct sockaddr_in ClientAddr;
int iAddrLen;
iAddrLen = sizeof(ClientAddr);
memset(&ClientAddr, 0x00, iAddrLen);
*accSoc = accept(*soc, (struct sockaddr *)&ClientAddr, &iAddrLen);
#ifdef DEBUG_VERBOSE
posixLog("socket %d accepted++++++++++\n",*accSoc);
#endif
if (ERROR == *accSoc)
{
close(*accSoc);
close(*soc);
wmnetTcpServerOpen(soc, port);
return wmosError(SYS_ERROR_SOCKET_ACCEPT, "wmnetTcpAccept: no server");
}
return OK;
}
/*-----------------------------------------------------------------------*/
STATUS wmnetClientAddrGet
(
OS_SOCKET_T ClientSock,
ubyte4 * pAddr
)
{
struct sockaddr_in ClientAddr;
int iAddrLen;
*pAddr = 0;
iAddrLen = sizeof(ClientAddr);
memset(&ClientAddr, 0x00, iAddrLen);
if (OK != getpeername(ClientSock, (struct sockaddr *)&ClientAddr, &iAddrLen))
return wmosError(ERROR_GENERAL, "unable to get address from socket");
*pAddr = ntohl(ClientAddr.sin_addr.s_addr);
return OK;
}
STATUS wmnetSocketClose
(
OS_SOCKET_T sock
)
{
#ifdef DEBUG_VERBOSE
posixLog("socket %d closed----------\n",sock,0,0,0,0,0);
#endif
if (ERROR == close(sock))
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "wmnetSocketClose");
return OK;
}
LOCAL STATUS connectToServer
(
OS_SOCKET_T sock,
sbyte * pName,
ubyte4 port
)
{
struct sockaddr_in RemAddr;
int err;
struct hostent * pHost;
memset(&RemAddr, 0x00, sizeof(RemAddr));
if (NULL == (pHost = gethostbyname(pName)))
return wmosError(ERROR_GENERAL,"remote host unknown");
RemAddr.sin_family = PF_INET;
RemAddr.sin_addr.s_addr = (unsigned int) pHost->h_addr;
RemAddr.sin_port = htons((ubyte2)port);
/* Create a Client connection */
err = connect( sock, (struct sockaddr *)&RemAddr, sizeof(RemAddr));
if ( ERROR == err )
return wmosError(ERROR_GENERAL_ACCESS_DENIED, NULL);
return OK;
}
STATUS wmnetTcpConnect
(
OS_SOCKET_T * pSoc,
sbyte * pName,
ubyte2 port
)
{
/* Create a stream socket */
if (OK != wmnetTcpSocketCreate(pSoc))
return ERROR;
if (OK != wmnetBindSockToAddr(*pSoc, ANY_PORT_K))
return ERROR;
/* Create a Client connection */
return connectToServer( *pSoc, pName, port );
}
STATUS wmnetTcpWrite
(
OS_SOCKET_T sock,
sbyte * pBuf,
ubyte4 bufLen
)
{
sbyte * pMsg;
if (ERROR != send(sock, pBuf, bufLen, 0))
return OK;
switch (errno)
{
case EBADF:
pMsg = "invalid file descriptor";
break;
case EINTR:
pMsg = "operation was interrupted by signal";
break;
case EINVAL:
pMsg = "tolen not valid size for specified address family";
break;
case EMSGSIZE:
pMsg = "socket requires message be sent atomically, "
"and the message was too long";
break;
case ENOMEM:
pMsg = "insufficient memory available";
break;
case ENOSR:
pMsg = "insufficient STREAMS resources";
break;
case ENOTSOCK:
pMsg = "not a socket";
break;
case EWOULDBLOCK:
pMsg = "socket is marked non-blocking and the "
"requested operation would block";
break;
default:
pMsg = "unknown send error";
break;
}
return wmosError(ERROR_GENERAL_ACCESS_DENIED, pMsg);
}
STATUS wmnetTcpRead
(
OS_SOCKET_T sock,
sbyte * pBuf,
ubyte4 BufSize,
ubyte4 * pBytesRead
)
{
ubyte4 bytes;
if (NULL != pBytesRead)
*pBytesRead = 0;
bytes = recv(sock, pBuf, BufSize, 0);
if (ERROR == bytes)
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "wmnetTcpRead: denied");
if (NULL != pBytesRead)
*pBytesRead = bytes;
return OK;
}
/*******************************************************************************
*
* wmnetSocketBlocking - enable or disable socket blocking
*
* This function modifies the behavior of other socket functions. If socket
* blocking is enabled, calling wmosSocketRead or wmosSocketPeek will block until
* data is available. If socket blocking is disabled, these functions will return
* immediately.
*
* RETURNS: N/A
*
*/
STATUS wmnetSocketBlocking
(
OS_SOCKET_T sock, /* the socket */
BOOL block /* TRUE to enable socket blocking */
)
{
int iOpt;
iOpt = ! block;
if (ERROR == ioctl (sock, FIONBIO, (int) &iOpt))
return wmosError (SYS_ERROR_SOCKET_GENERAL,
"wmnetSocketBlocking: ioctl failed");
return OK;
}
/*******************************************************************************
*
* wmnetSocketPeek - peek into a socket
*
* This routine peeks into a socket without modifying the data waiting on it. As
* many as (*pBufSize) characters are read and copied onto pBuf. When no data is
* pending, the routine will block or return immediately depending on wether
* socket blocking is enable or not (see wmnetSocketBlocking()).
*
* RETURNS: The number of characters that have been copied to pBuf or one of
* these errors:
* SYS_ERROR_SOCKET_TIMEOUT
* SYS_ERROR_SOCKET_GENERAL
*
*/
STATUS wmnetTcpPeek
(
OS_SOCKET_T sock, /* the socket */
sbyte * pBuf, /* the buffer where data will be copied */
ubyte4 BufSize, /* buffer size */
ubyte4 * bytesRead /* return: number of bytes read */
)
{
ubyte4 bytes;
bytes = recv(sock, pBuf, BufSize, MSG_PEEK);
if (ERROR == bytes)
return wmosError(ERROR_GENERAL_ACCESS_DENIED, "wmnetTcpPeek: denied");
if (NULL != bytesRead)
*bytesRead = bytes;
return OK;
}
/*******************************************************************************
*
* wmnetSocketGroupWait - wait on a set of sockets and/or pipes
*
* This routine blocks until there is some activity (data available for
* reading or socket/pipe is closed) on the set of monitored sockets.
*
* setOfSockets is the list of sockets/pipes to wait on and it can be modified
* using the functions wmnetSocketGroupAddTo, wmnetSocketGroupAddPipe and
* wmnetSocketGroupClear.
*
* When the function returns, wmnet[Socket/Pipe]WantsAction could be used to
* determine which of the monitored sockets.pipes was active.
*
* timeoutInSecs can be set to 0 to indicate no timeout (i.e. infinite wait)
*
* RETURNS: The number of characters that have been copied to pBuf or one of
* these errors:
* SYS_ERROR_SOCKET_TIMEOUT
* SYS_ERROR_SOCKET_GENERAL
*
*/
STATUS wmnetSocketGroupWait
(
OS_FDSET_T * setOfSockets,
ubyte4 timeoutInSecs
)
{
int r;
struct timeval tv;
tv.tv_sec = timeoutInSecs;
tv.tv_usec = 0;
assert ((0 < setOfSockets->fdMax) && (64 > setOfSockets->fdMax));
r = select (setOfSockets->fdMax + 1, &setOfSockets->fdSet, NULL, NULL, &tv);
if (0 > r)
return wmosError(SYS_ERROR_SOCKET_GENERAL, "wmnetSocketGroupWait: error");
if (0 == r)
return wmosError(ERROR_GENERAL_TIMEOUT, "wmnetSocketGroupWait: timeout");
return OK;
}
STATUS wmnetSocketGroupAddTo
(
OS_SOCKET_T sock,
OS_FDSET_T * setOfSockets
)
{
FD_SET(sock, &setOfSockets->fdSet);
if (sock > setOfSockets->fdMax)
setOfSockets->fdMax = sock;
return OK;
}
STATUS wmnetSocketGroupAddPipe
(
OS_PIPE_T pipe,
OS_FDSET_T * setOfSockets
)
{
return wmnetSocketGroupAddTo ((OS_SOCKET_T) pipe,setOfSockets);
}
STATUS wmnetSocketGroupClear
(
OS_FDSET_T * setOfSockets
)
{
FD_ZERO(&setOfSockets->fdSet);
setOfSockets->fdMax = 0;
return OK;
}
BOOL wmnetSocketWantsAction
(
OS_SOCKET_T sock,
OS_FDSET_T * setOfSockets
)
{
return FD_ISSET(sock, &setOfSockets->fdSet);
}
BOOL wmnetPipeWantsAction
(
OS_PIPE_T pipe,
OS_FDSET_T * setOfSockets
)
{
return wmnetSocketWantsAction((OS_SOCKET_T) pipe, setOfSockets);
}
/*******************************************************************************
*
* wmnetSocketPrintf - output a formatted string to a socket
*
* This sends a formatted string to the connection socket.
* It is identical to printf() in terms of the
* usage of parameters and format strings.
*
* INTERNAL: Note that vfdprintf is not ANSI, and that the function is not
* portable because it assumes that a socket is a file descriptor, which is not
* true in some OSes.
*
* RETURNS: OK or ERROR.
*/
STATUS wmnetSocketPrintf
(
OS_SOCKET_T sock,
sbyte * szFormat,
...
)
{
#if 0
int size;
int copy;
FILE * file;
if (0 > (copy = dup(sock)))
return wmError(ERROR_GENERAL, "wmnetSocketPrintf: can't dupe socket");
if (NULL == (file = fdopen(copy, "w")))
return wmError(ERROR_GENERAL, "wmnetSocketPrintf: can't open socket file");
size = 0;
va_list vaList;
va_start (vaList, szFormat);
if (0 > (size += vfprintf (file, szFormat, vaList)))
{
#ifdef DEBUG_VERBOSE
/* produce verbose output */
printf ("SOCKET PRINTF: ");
vprintf (szFormat, vaList);
printf ("\n");
#endif
va_end (vaList);
}
else
{
va_end (vaList);
wmosError(ERROR_GENERAL, "wmnetSocketPrintf failed");
size = -1;
}
fclose(file);
return size;
#endif
return 0;
}
/*******************************************************************************
*
* wmnetSockPrintf - print a formatted string on a socket
*
* All parameters identical to vfprintf, except for the first which identifies
* a socket instead of a file. ANSI requires that call to vfprintf should be
* preceded by a call to va_start, and followed by a call to va_end. The same
* applies to this function.
*
* SPECIFIC TO THIS PORT:
* Formatted output cannot be sent to a socket under Windows (fprintf does
* not work on sockets) and a temporary buffer needs to be allocated. If the
* size of the message is larger than PRINTF_BUFFER some data will be lost.
*
* RETURNS: OK or an error
* The number of characters sent to the socket (by reference)
*
*/
STATUS wmnetSocketVprintf
(
OS_SOCKET_T sock,
sbyte * szFormat,
va_list args,
ubyte4 * pBytesPrinted
)
{
enum {PRINTF_BUFFER = 1000 };
sbyte tmpBuffer[PRINTF_BUFFER];
* pBytesPrinted = 0;
(* pBytesPrinted) = vsprintf (tmpBuffer, szFormat, args);
wmnetTcpWrite(sock, tmpBuffer, strlen(tmpBuffer));
return OK;
}
/*******************************************************************************
*
* wmnetStdoutToSocket - redirect STDIO to a socket
*
* This routine redirects current STDIO to the socket. An OS specific value
* needed to restore the Stdout is returned by reference in the second parameter.
*
*
* RETURNS: 'OK' or an error
*/
STATUS wmnetStdoutToSocket
(
OS_SOCKET_T sock,
sbyte4 * pOldStdout
)
{
return OK;
}
#endif /*__SOLARIS_OS__*/
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,438 @@
/* wmos.c - os isolation functions */
/*
* Copyright (c) 2003-2008, 2010-2012 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
--------------------
01h,17sep12,r_w correct for thread priority.
Defect: WIND00375444
01g,07jan11,m_z correct compiling error on linux
CQID: Fix WIND00249657
01f,31mar10,m_z correct 32bit error
01e,29jan10,m_z VxWorks 64-bit support
(WIND00193649)
01d,28aug08,q_z fix for mud tasks spawned with option (WIND00130158)
01c,15jan04,gsr added mutex semaphore support
01b,02jan04,jws start componentization (COMMON_IS_COMPONENT)
01a,24sep03,jws modification history added
fix compiler warnings, SPR 90843
*/
/*
DESCRIPTION
This module contains interface routines for the Wind Manage Backplane.
*/
/* includes */
#ifndef COMMON_IS_COMPONENT
#include "wm_options.h"
#else
#define kHwTicksPerSecond sysClkRateGet()
#endif
#include "wrn/wm/common/wm.h"
#ifdef __VXWORKS_OS__
#include "sysLib.h"
#endif
#ifdef __SOLARIS_OS__
#include "semLib.h"
#include "taskLib.h"
#endif
/* defines */
#define DREF(x) (NULL == x) ? 0 : *((int *) x)
#undef __DEBUG_THREADS__
#ifdef __DEBUG_THREADS__
#define DEBUG_THREAD_M(fn, msg, data) \
printf("%20s: tid = 0x%x %-8s ptr = 0x%lx data = 0x%lx\n", \
fn, taskIdSelf(), msg, data, DREF(data));
#else
#define DEBUG_THREAD_M(fn, msg, data)
#endif
/* globals */
/* locals */
/**************************************************************************
*
* wmosInit - constructor of the OSAL layer
*
* RETURNS: none
*/
void wmosInit(void)
{
#if 0
#ifdef __BSD_OS__
osalInit();
#endif
#endif
}
/**************************************************************************
*
* wmosFini - destructor of the OSAL layer
*
* RETURNS: none
*/
void wmosFini(void)
{
#if 0
#ifdef __BSD_OS__
osalFini();
#endif
#endif
}
/**************************************************************************
*
* wmosSemBinaryCreate - create binary semaphore
*
* RETURNS: 'OK', or ERROR
*/
STATUS wmosSemBinaryCreate
(
OS_SEM_T *pSem,
OS_SEM_OPTIONS_T opt
)
{
if (NULL == pSem)
return wmError(ERROR_GENERAL_NULL_POINTER, "null pointer");
*pSem = semBCreate(opt, SEM_EMPTY);
return OK;
}
/**************************************************************************
*
* wmosSemMCreate - create mutex semaphore
*
* RETURNS: 'OK', or ERROR
*/
STATUS wmosSemMCreate
(
OS_SEM_T *pSem,
OS_SEM_OPTIONS_T opt
)
{
if (NULL == pSem)
return wmError(ERROR_GENERAL_NULL_POINTER, "null pointer");
*pSem = semMCreate(opt);
return OK;
}
/**************************************************************************
*
* wmosSemBinaryTake - why does this dupe wmosSemTake
*
* RETURNS: 'OK', or ERROR
*/
STATUS wmosSemBinaryTake
(
OS_SEM_T sem,
ubyte4 timeout
)
{
return semTake (sem, timeout);
}
/**************************************************************************
*
* wmosSemCreate - create a counting semaphore
*
* RETURNS: 'OK', or ERROR_GENERAL if creation failed failed
*/
STATUS wmosSemCreate
(
OS_SEM_T * pSem,
sbyte4 count,
OS_SEM_OPTIONS_T opt
)
{
switch (opt)
{
case SEM_TYPICAL_K:
*pSem = semCCreate (SEM_Q_FIFO, count);
if (NULL == *pSem)
return wmosError (ERROR_GENERAL,"Failed to create semaphr");
break;
case SEM_SHARED_MEM_K:
#ifdef WMOS_INCLUDE_SHARED_MEM_OBJS
*pSem = semCSmCreate (SEM_Q_FIFO, count);
if (NULL == *pSem)
return wmosError(ERROR_GENERAL,"Failed to create semaphore");
#else
return wmosError (ERROR_GENERAL,"Shared mem objs not included");
#endif
break;
default:
return wmosError (ERROR_GENERAL_ILLEGAL_VALUE,"unknown shared mem error");
}
return OK;
}
/**************************************************************************
*
* wmosSemDestroy - destroy an existing semaphore
*
* RETURNS: 'OK', or ERROR_GENERAL_ILLEGAL_VALUE the parameter was not an
* valid semaphore
*/
STATUS wmosSemDestroy
(
OS_SEM_T sem
)
{
if (ERROR == semDelete (sem))
return wmosError(ERROR_GENERAL_ILLEGAL_VALUE,"");
return OK;
}
/**************************************************************************
*
* wmosSemTake - take a semaphore
*
* This function decrements the count of an existing semaphore. When the
* count reaches zero, the function blocks until another thread gives
* the semaphore or it is destroyed.
*
* RETURNS: 'OK'
*/
STATUS wmosSemTake
(
OS_SEM_T sem,
ubyte4 timeout
)
{
return semTake(sem, timeout);
}
/**************************************************************************
*
* wmosSemGive - give a semaphore
*
* This function increments the count of an existing semaphore and unblocks
* any thread that may be waiting on it.
*
* RETURNS: 'OK'
*/
STATUS wmosSemGive
(
OS_SEM_T sem
)
{
return semGive(sem);
}
/**************************************************************************
*
* wmosSemFlush - unblock all tasks waiting for this semaphore
*
* This function unblocks all the tasks that may be waiting on semaphore
* 'sem', but the state (count) of the semaphore remains unmodified.
*
* RETURNS: 'OK'
*/
STATUS wmosSemFlush
(
OS_SEM_T sem
)
{
return semFlush(sem);
}
/**************************************************************************
*
* wmosYield - yield processor time
*
* This function will block only if other threads <with the same priority>
* are ready to run.
*
* RETURNS: N/A
*/
void wmosYield
(
void
)
{
taskDelay(NO_WAIT_K); /* yield the processor */
}
/**************************************************************************
*
* wmosTimeSleep - sleep for x milliseconds
*
* This function will block for 'mSecs' milliseconds.
*
* RETURNS: N/A
*/
void wmosTimeSleep
(
ubyte4 mSecs
)
{
int ticks = (int)((int)mSecs * kHwTicksPerSecond ) / 1000;
taskDelay(ticks);
}
/**************************************************************************
*
* wmosThreadCreate - spawn a new thread
*
* This function spawns a new thread from function 'pHandlerFcn'. A name
* 'pTaskName' may be given to the thread, otherwise this parameter may be NULL.
* 'priority' should be between 0 and 255, with the lower number signifying
* higher priority. The thread 'stackSize' should be given in bytes.
*
*
* RETURNS: 'OK', or ERROR_GENERAL_CREATE_TASK if thread creation failed
* 'pTid', the value of the thread identifier is returned by reference
*/
STATUS wmosThreadCreate
(
VOIDFUNCPTR pHandlerFcn,
sbyte * pTaskName,
void * pArg,
sbyte4 priority,
#ifndef _WRS_CONFIG_LP64
ubyte4 stackSize,
#else
ubyte8 stackSize,
#endif
OS_THREAD_T * pTid
)
{
OS_THREAD_T tid;
if (0 == stackSize)
stackSize = DEFAULT_THREAD_STACK_SIZE_K;
DEBUG_MSG_2("!!!! wmosThreadCreate: %s stacksize: %d\n",
NULL == pTaskName ? "(none)" : pTaskName, stackSize);
if ((0 >= priority) || (255 < priority))
priority = DEFAULT_THREAD_PRIORITY_K;
DEBUG_MSG_2("wmosThreadCreate: priority: %d arg ptr: 0x%x\n", priority, (int) pArg);
tid = taskSpawn (pTaskName, priority, kWmosThreadCreateOptions, stackSize, (FUNCPTR) pHandlerFcn,
(OS_ARG_T) pArg,0,0,0,0,0,0,0,0,0 );
#ifndef _WRS_CONFIG_LP64
if (ERROR == (STATUS) tid)
#else
if (TASK_ID_ERROR == tid)
#endif
{
wmosThreadCreateError();
return wmosError(ERROR_GENERAL_CREATE_TASK,"wmosThreadCreate: creation failed");
}
if (NULL != pTid)
*pTid = tid;
return OK;
}
/**************************************************************************
*
* wmosThreadKill - kill a thread
*
* This function kills an existing thread. The parameter 'tid' should be
* the one returned by wmosThreadCreate when the thread was created.
*
* RETURNS: 'OK', or ERROR_GENERAL if thread creation failed
*/
STATUS wmosThreadKill
(
OS_THREAD_T tid
)
{
if (ERROR == taskDelete(tid))
return wmosError(ERROR_GENERAL,"");
return OK;
}
/**************************************************************************
*
* wmosThreadSuspend - suspend a thread
*
* This function suspends an existing thread. The parameter 'tid' should be
* the one returned by wmosThreadCreate when the thread was created.
*
* RETURNS: 'OK', or ERROR if failed
*/
STATUS wmosThreadSuspend
(
OS_THREAD_T tid
)
{
if (ERROR == taskSuspend(tid))
return wmosError(ERROR_GENERAL,"");
return OK;
}
/**************************************************************************
*
* wmosThreadResume - resume a thread
*
* This function resumes an existing thread. The parameter 'tid' should be
* the one returned by wmosThreadCreate when the thread was created.
*
* RETURNS: 'OK', or ERROR if failed
*/
STATUS wmosThreadResume
(
OS_THREAD_T tid
)
{
if (ERROR == taskResume(tid))
return wmosError(ERROR_GENERAL,"");
return OK;
}
@@ -0,0 +1,783 @@
/* wmosVxWorks.c - Implementation in VxWorks of the Rapid Control OS AL */
/* Copyright 2004-2008, 2010 Wind River Systems, Inc. */
/*
modification history
--------------------
03c,07jan11,m_z correct compiling error on linux
CQID: Fix WIND00249657
03b,28jul10,m_z eliminate compile warning
03a,19jul10,h_y modified for WIND00223629
02l,09jul10,m_z remove compile warning
02k,07may10,m_z eliminate compile warning
02j,31mar10,m_z correct 32bit error
02i,29jan10,m_z VxWorks 64-bit support
(WIND00193649)
02k,28oct08,m_z change value cast to eliminate build warning
(WIND00139452)
01e,11oct07,ten For SMP use thread local storage (fomr tlsLib) rather than
task variables
01d,07mar07,ps fixes for RTP builds. defect WIND00044864
01c,17may06,ps add some vxWorks include files. CQ WIND000044862
01b,13jan04,gsr added pipeDelete routine for SPR 93009
01a,02jan04,jws add modification history
start componentization (COMMON_IS_COMPONENT)
*/
/*
DESCRIPTION
This module implements all the functions defined in wmos.h for the VxWorks OS
*/
#ifndef COMMON_IS_COMPONENT
#include "wm_options.h"
#else
#define kHwTicksPerSecond sysClkRateGet()
#undef RCB_SYSLOG_HOST_K /* appears only in this file !! */
/*
* There is an inclusion order problem with wm.h that forces us
* to define __VXWORKS_OS__ here. This must be looked at.
*/
#define __VXWORKS_OS__
#endif
#if defined(__VXWORKS_OS__) || defined(__VXWORKS_AE_OS__)
#include <vxWorks.h>
#include <tickLib.h>
#include <sysLib.h>
#include <pipeDrv.h>
#include <ioLib.h>
#include <errnoLib.h>
#include <stdlib.h>
#ifdef _WRS_KERNEL
#include <usrConfig.h>
#include <smObjLib.h>
#ifdef _WRS_VX_SMP
#include <tlsLib.h>
#endif
#else
#include <sys/fcntlcom.h>
#endif
#include "wm.h"
#define LONGEST_PIPE_NAME_K 128
#ifdef _WRS_VX_SMP
__thread long taskData;
#else
long taskData;
#endif
#ifdef _WRS_KERNEL
extern int errnoGet (void);
#endif
/**************************************************************************
*
* wmosMalloc - allocate memory
*
* uses native os management to allocate a block of memory.
*
* RETURNS: Pointer to memory allocated, or NULL if it failed.
*/
void * wmosMalloc
(
#ifndef _WRS_CONFIG_LP64
ubyte4 memSize
#else
ubyte8 memSize
#endif
)
{
char * pMem = NULL;
if ( memSize )
pMem = malloc( memSize );
#ifdef __ENABLE_MEMMGR_DEBUG__
printf("Malloc(%ld) %08lx\n", (ulong_t)memSize, (ulong_t)pMem);
#endif
return (void *)pMem;
}
/**************************************************************************
*
* wmosCalloc - allocate memory
*
* uses native os management to allocate a block of memory.
*
* RETURNS: Pointer to memory allocated, or NULL if it failed.
*/
void * wmosCalloc
(
#ifndef _WRS_CONFIG_LP64
ubyte4 elemCount,
ubyte4 elemSize
#else
ubyte8 elemCount,
ubyte8 elemSize
#endif
)
{
char * pMem = NULL;
/* Verify the allocation sizes are not zero */
if ( elemCount && elemSize )
pMem = calloc(elemCount, elemSize);
#ifdef __ENABLE_MEMMGR_DEBUG__
printf("Calloc(%ld) %08lx\n", (ulong_t)(elemCount * elemSize), (ulong_t)pMem);
#endif
return (void *)pMem;
}
/**************************************************************************
*
* wmosFree - free allocated memory
*
* frees memory allocated using native os management.
*
* RETURNS: N/A
*/
void wmosFree
(
void * pBuffer
)
{
if ( pBuffer )
free(pBuffer);
#ifdef __ENABLE_MEMMGR_DEBUG__
printf("Free(%08lx)\n", (ulong_t)pBuffer);
#endif
}
/**************************************************************************
*
* wmosTimeGet - get system time since 12:00 a.m. 1/1/1970
*
* RETURNS: time
*/
#ifndef _WRS_CONFIG_LP64
ubyte4 wmosTimeGet (void)
{
return (ubyte4)(tickGet() / kHwTicksPerSecond);
}
#else
ubyte8 wmosTimeGet (void)
{
return (ubyte8)(tickGet() / kHwTicksPerSecond);
}
#endif
/**************************************************************************
*
* wmosClock - get microseconds since starting
*
* RETURNS: microseconds
*/
OS_CLOCK_T wmosClock
(
void
)
{
return (clock()/CLOCKS_PER_SEC)*1000000;
}
/**************************************************************************
*
* wmosError - report an error
*
* This function should be called everytime an error is to be returned to a
* calling function. Instead of:
* \cs
* return ERROR_GENERAL
* \ce
* the following call should be used:
* \cs
* return wmosError(ERROR_GENERAL, "oops, did you forget to bring the money?");
* \ce
*
* Doing this provides a common execution path to all the errors,
* which allows trapping errors before they propagate up the call tree.
*
* RETURNS: 'OK', or ERROR_GENERAL if initialization failed
*/
STATUS wmosError
(
sbyte4 error,
sbyte * pMsg
)
{
#ifdef RCB_SYSLOG_HOST_K
char buffer[128];
#endif
#ifdef _WRS_KERNEL
logMsg ("Error =%d\t[%s] errno:%d\n", error, (long) pMsg, errnoGet(),0,0,0);
#endif
#ifdef RCB_SYSLOG_HOST_K
sprintf(buffer, "WM Error %d: %s\n", error, pMsg);
rcbLogSyslog(buffer);
#endif
return error;
}
/**************************************************************************
*
* wmosThreadCreateError - handle error returned by create thread
*
*
* RETURNS: none
*/
void wmosThreadCreateError(void)
{
switch (errno)
{
#ifdef _WRS_KERNEL
case S_intLib_NOT_ISR_CALLABLE:
DEBUG_MSG_0("wmosThreadCreateError: not callable\n");
break;
#endif
case S_objLib_OBJ_ID_ERROR:
DEBUG_MSG_0("wmosThreadCreateError: invalid obj id\n");
break;
#ifdef _WRS_KERNEL
case S_smObjLib_NOT_INITIALIZED:
DEBUG_MSG_0("wmosThreadCreateError: not initialized\n");
break;
case S_memLib_NOT_ENOUGH_MEMORY:
DEBUG_MSG_0("wmosThreadCreateError: not enough memory\n");
break;
case S_memLib_BLOCK_ERROR:
DEBUG_MSG_0("wmosThreadCreateError: blocking error\n");
break;
#endif
#ifdef SOMEONE_KNOWS_WHERE_S_pdLib_PRIORITY_NOT_WITHIN_PD_RANGE_IS_DEFINED
case S_pdLib_PRIORITY_NOT_WITHIN_PD_RANGE:
break;
#endif /* !! someone deal with this !! */
}
}
/**************************************************************************
*
* wmosNamedPipeCreate - create a named pipe
*
* 'pName' should be an alphanumeric string, without any special
* characters such as \/ or . (each port will build a valid pipe name based
* on the given 'pName'. The parameters 'maxMsgs' and 'msgSize' will determine
* the memory requirements for the pipe. The latter is expressed in bytes.
*
* RETURNS: 'OK', or ERROR_GENERAL if creation failed
*/
STATUS wmosNamedPipeCreate
(
sbyte * pName,
ubyte4 maxMsgs,
#ifndef _WRS_CONFIG_LP64
ubyte4 msgSize
#else
ubyte8 msgSize
#endif
)
{
sbyte pipeName[LONGEST_PIPE_NAME_K];
ubyte2 bufSize = LONGEST_PIPE_NAME_K;
STATUS errVal;
#ifdef OS_PIPE_PREFIX_K
strncpy(pipeName, OS_PIPE_PREFIX_K, bufSize);
bufSize = (ubyte2)(bufSize - (ubyte2)strlen(pipeName));
#else
#error OS_PIPE_PREFIX_K is not defined !!
#endif
strncat(pipeName, pName, bufSize);
errVal = pipeDevCreate (pipeName, maxMsgs, msgSize);
if (OK != errVal)
return wmosError(ERROR_GENERAL, "Invalid pipe");
return OK;
}
/**************************************************************************
*
* wmosNamedPipeDelete - delete a named pipe
*
* 'pName' should be an alphanumeric string, without any special
* characters such as \/ or . (each port will build a valid pipe name based
* on the given 'pName'.
*
* RETURNS: 'OK', or ERROR_GENERAL if deletion failed
*/
STATUS wmosNamedPipeDelete
(
sbyte * pName
)
{
sbyte pipeName[LONGEST_PIPE_NAME_K];
ubyte2 bufSize = LONGEST_PIPE_NAME_K;
STATUS errVal;
#ifdef OS_PIPE_PREFIX_K
strncpy(pipeName, OS_PIPE_PREFIX_K, bufSize);
bufSize = (ubyte2)(bufSize - (ubyte2)strlen(pipeName));
#else
#error OS_PIPE_PREFIX_K is not defined !!
#endif
strncat(pipeName, pName, bufSize);
errVal = pipeDevDelete (pipeName, FALSE);
if (OK != errVal)
return wmosError(ERROR_GENERAL, "pipe delete failed");
return OK;
}
/**************************************************************************
*
* wmosNamedPipeOpen - connect to an existing named pipe
*
* After a pipe has been created with wmosNamedPipeCreate, it can be opened
* with this command. The supported 'mode's are 'OS_PIPE_IN' (reading),
* 'OS_PIPE_OUT' (writing) and 'OS_PIPE_BOTH' (read/write).
*
* RETURNS: 'OK', ERROR_GENERAL_ILLEGAL_VALUE if an unrecognized 'mode' is
* passed or ERROR_GENERAL for any other error.
* 'pPipe' points to the pipe identifier (by reference)
*
*/
STATUS wmosNamedPipeOpen
(
sbyte * pName,
OS_PIPE_MODE_T mode,
BOOL noBlock,
OS_PIPE_T * pPipe
)
{
sbyte4 flags;
sbyte pipeName[LONGEST_PIPE_NAME_K];
ubyte2 bufSize = LONGEST_PIPE_NAME_K;
#ifdef OS_PIPE_PREFIX_K
strncpy(pipeName, OS_PIPE_PREFIX_K, bufSize);
bufSize = (ubyte2)(bufSize - (ubyte2)strlen(pipeName));
#endif
strncat(pipeName, pName, bufSize);
switch (mode)
{
case OS_PIPE_IN:
flags = O_RDONLY;
break;
case OS_PIPE_OUT:
flags = O_WRONLY;
break;
case OS_PIPE_BOTH:
flags = O_RDWR;
break;
default:
return wmosError(ERROR_GENERAL_ILLEGAL_VALUE, "invalid pipe mode");
}
(*pPipe) = open(pipeName, flags, 0);
if ( -1 == (*pPipe))
return wmosError(ERROR_GENERAL, "failed to open pipe");
return OK;
}
/**************************************************************************
*
* wmosNamedPipeWrite - write to an open pipe
*
*
* RETURNS: 'OK', ERROR_GENERAL if the writing is unsuccesful
*
*/
STATUS wmosNamedPipeWrite
(
OS_PIPE_T pipe,
sbyte * buffer,
#ifndef _WRS_CONFIG_LP64
ubyte4 bufSize,
ubyte4 * bytesWritten
#else
ubyte8 bufSize,
ubyte8* bytesWritten
#endif
)
{
#ifndef _WRS_CONFIG_LP64
sbyte4 errVal;
#else
sbyte8 errVal;
#endif
errVal = write(pipe, buffer, bufSize);
#ifndef _WRS_CONFIG_LP64
if (errVal != bufSize)
#else
if ((ubyte8)errVal != bufSize)
#endif
return wmosError(ERROR_GENERAL, "pipe write failed");
return OK;
}
/**************************************************************************
*
* wmosNamedPipeRead - read from a named pipe
*
*
* RETURNS: 'OK', or ERROR_GENERAL if initialization failed
*/
STATUS wmosNamedPipeRead
(
OS_PIPE_T pipe,
sbyte * pBuffer,
#ifndef _WRS_CONFIG_LP64
ubyte4 bufSize,
ubyte4 * pBytesRead
#else
ubyte8 bufSize,
ubyte8* pBytesRead
#endif
)
{
#ifndef _WRS_CONFIG_LP64
sbyte4 bytesRead;
#else
sbyte8 bytesRead;
#endif
bytesRead = read(pipe, pBuffer, bufSize);
if (ERROR == bytesRead)
return wmosError(ERROR_GENERAL, "pipe read failed");
if (NULL != pBytesRead)
#ifndef _WRS_CONFIG_LP64
*pBytesRead = (ubyte4) bytesRead;
#else
*pBytesRead = (ubyte8) bytesRead;
#endif
return OK;
}
/**************************************************************************
*
* wmosNamedPipeClose - close a named pipe
*
* RETURNS: 'OK', or ERROR_GENERAL if initialization failed
*/
STATUS wmosNamedPipeClose
(
OS_PIPE_T pipe
)
{
sbyte4 errVal;
errVal = close(pipe);
if (-1 == errVal)
return wmosError(ERROR_GENERAL, "pipe close failed");
return OK;
}
#ifdef _WRS_KERNEL /* functions not available in RTP */
/**************************************************************************
*
* wmosThreadDataInit - prepare to save pointers with thread local storage
*
* Each thread must be call for init
*
* RETURNS: 'OK', or ERROR_GENERAL if initialization failed
*
* NOMANUAL
*/
STATUS wmosThreadDataInit
(
void
)
{
#ifndef _WRS_VX_SMP
/* UP version uses task variables */
#ifndef _WRS_CONFIG_LP64
taskVarAdd(taskIdSelf(), (int *)&taskData);
#endif
#else
/* SMP version uses thread local storage */
/*
* Init: Any reference to the variable will cause per-task
* storage to be allocated
*/
taskData = (long)NULL;
#endif
return OK;
}
/**************************************************************************
*
* wmosThreadDataGet - get pointer saved with thread local storage
*
* RETURNS: 'OK', or ERROR_GENERAL if no pointer or not initialized
*
* NOMANUAL
*/
STATUS wmosThreadDataGet
(
void ** ppData
)
{
/* Retrieve a data pointer for the current thread */
*ppData = (void *) taskData;
return OK;
}
/**************************************************************************
*
* wmosThreadDataSet - save pointer with thread local storage
*
* RETURNS: 'OK'
*
* NOMANUAL
*/
STATUS wmosThreadDataSet
(
void ** ppData
)
{
taskData = (long) *ppData;
return OK;
}
/**************************************************************************
*
* wmosThreadDataExit - frees resources used for thread local storage
*
* RETURNS: 'OK'
*
* NOMANUAL
*/
STATUS wmosThreadDataExit
(
void
)
{
return OK;
}
#endif /* #ifdef _WRS_KERNEL */
/**************************************************************************
*
* wmosQueueCreate - create a message queue
*
* RETURNS: 'OK'
*/
STATUS wmosQueueCreate
(
#ifndef _WRS_CONFIG_LP64
ubyte4 maxMsgs,
ubyte4 msgSize,
#else
ubyte8 maxMsgs,
ubyte8 msgSize,
#endif
sbyte4 flags,
OS_MSGQ_T * pQID
)
{
*pQID = msgQCreate (maxMsgs, msgSize, flags);
if (0 == *pQID)
return wmosError (ERROR, "wmosQueueCreate: queue creation failed");
return OK;
}
/**************************************************************************
*
* wmosQueueDelete - delete a message queue
*
* RETURNS: 'OK'
*/
STATUS wmosQueueDelete
(
OS_MSGQ_T qID
)
{
return msgQDelete (qID);
}
/**************************************************************************
*
* wmosQueueReceive - receive data from a message queue
*
* RETURNS: 'OK'
*/
STATUS wmosQueueReceive
(
OS_MSGQ_T qID,
sbyte * pBuffer,
#ifndef _WRS_CONFIG_LP64
ubyte4 buffSize,
ubyte4 timeout,
sbyte4 * pBytesReceived
#else
ubyte8 buffSize,
ubyte4 timeout,
sbyte8 * pBytesReceived
#endif
)
{
*pBytesReceived = msgQReceive (qID, pBuffer, buffSize, timeout);
#ifndef _WRS_CONFIG_LP64
return (ERROR == *pBytesReceived) ? (STATUS)ERROR : OK;
#else
return ((sbyte8)ERROR == *pBytesReceived) ? (STATUS)ERROR : OK;
#endif
}
/**************************************************************************
*
* wmosQueueSend - send data to a message queue
*
* RETURNS: 'OK'
*/
STATUS wmosQueueSend
(
OS_MSGQ_T qID,
sbyte * pMsg,
#ifndef _WRS_CONFIG_LP64
ubyte4 msgSize,
#else
ubyte8 msgSize,
#endif
ubyte4 timeout,
sbyte4 priority
)
{
return msgQSend (qID, pMsg, msgSize, timeout, priority);
}
#ifdef __ENABLE_SHARED_MEMORY__
/**************************************************************************
*
* wmosSharedMemAttach - attach to previously created shared memory
*
* RETURNS: N/A
*/
STATUS wmosSharedMemoryAttach
(
OS_MEM_SHARE_T * pMemory
)
{
sbyte * pMsg;
if (NULL == pMemory)
return wmError(ERROR, "wmosSharedMemConnect: null ID ptr");
pMemory->pData = sdAttach(pdSelf(), pMemory->id, 0);
pMemory->pool = pMemory->pData;
DEBUG_MSG_0("wmosSharedMemoryAttach: done\n");
return OK;
}
/**************************************************************************
*
* wmosSharedMemCreate - allocated shared memory
*
* frees memory allocated using native os management.
*
* RETURNS: N/A
*/
STATUS wmosSharedMemoryCreate
(
sbyte * pName,
#ifndef _WRS_CONFIG_LP64
sbyte4 size,
#else
sbyte8 size,
#endif
OS_MEM_SHARE_T * pMemory
)
{
pMemory->id = sdCreate(pName, size, 0, NULL, NULL, NULL);
pMemory->size = size;
return OK;
}
STATUS wmosSharedMemoryDestroy
(
OS_MEM_SHARE_T * pMemory
)
{
return sdDetach(pdSelf(), pMemory->id, 0);
}
#endif /* __ENABLE_SHARED_MEMORY__ */
#endif /* __VXWORKS_OS__ */
@@ -0,0 +1,42 @@
common/port/wmnet/wmnetVxWorks.c
common/port/wmos/wmos.c
common/port/wmos/wmosVxWorks.c
common/memPoolLib.c
common/mudLib.c
common/mudUtils.c
common/wmAccessLib.c
common/wmAuth.c
common/wmBufferLib.c
common/wmCompareLib.c
common/wmConvertLib.c
common/wmFileLib.c
common/wmHashLib.c
common/wmLib.c
common/wmLinkListLib.c
common/wmLogLib.c
common/wmMD5.c
common/wmMemBlockLib.c
common/wmNonce.c
common/wmOidLib.c
common/wmInstanceLib.c
common/wmStdLib.c
common/wmUserLib.c
common/wmXmlParser.c
backplane/wmbBackplaneLib.c
backplane/wmbComponentLib.c
backplane/wmbDBLib.c
backplane/wmbEventLib.c
backplane/wmbLib.c
backplane/wmbObjectLib.c
backplane/wmbSessionLib.c
backplane/wmbSystem.c
backplane/wmbTableLib.c
backplane/wmbTransactionCore.c
backplane/wmbTransactionLib.c
backplane/wmbLockMgrCore.c
backplane/wmbLockMgrLib.c
backplane/wmbPortfolioLib.c
backplane/wmbPortfolioRemote.c
backplane/wmbSNMPLib.c
backplane/wmbDataLib.c
backplane/wmbCommonHandlers.c
@@ -0,0 +1,536 @@
/* wmAccessLib.c - user access control library */
/*
* Copyright (c) 2001-2010, 2012 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
--------------------
01k,17may12,h_l replace NO_STRING with NULL_STRING (WIND00032212)
01j,18nov10,m_z add option filter for access level convertion
CQID: Fix WIND00242096
01i,28apr10,m_z eliminate compile warning
01h,19jan10,m_z VxWorks 64-bit support
(WIND00193649)
01g,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01f,13sep04,dkg added new API's to set & get user access level to support
JavaScript Authentication feature
01e,12jul04,gsr access level does not print in user show SPR 84874
01d,02jan04,jws start componentization (COMMON_IS_COMPONENT)
01c,24sep03,jws fix compile warnings, SPR 90843
01a,01aug01,pns written
01b,09oct01,rws modified comments
*/
/*
DESCRIPTION
This module implements access control support for WindManage
INCLUDE FILES: wm.h 'wmb.h'
*/
/* includes */
#include "wrn/wm/common/wm.h"
#include <string.h>
#ifdef COMMON_IS_COMPONENT
#define __RLI_ACCESS_LEVEL_SHIFT__ 0
#endif
#undef __RLI_DEBUG_ACCESS__ /* local macro */
LOCAL ubyte4 systemAccessLevel = ACCESS_LEVEL_MASK_K;
LOCAL ubyte4 systemAccessGroups = ACCESS_GROUP_MASK_K;
LOCAL DTTypeInfo * pAccessInfo = NULL;
#ifdef __ENABLE_LAN_IP_FILTER__
/*-----------------------------------------------------------------------*/
extern BOOL RLI_CUSTOM_DYNAMIC_IP_FILTER_ENABLED();
extern BOOL RLI_CUSTOM_DYNAMIC_IP_CHECK(ubyte4 ClientIpAddr, ubyte4 FutureParam1, ubyte4 FutureParam2);
/**************************************************************************
*
* accessIpValid - IP address validation function.
*
* This routine checks the IP address <ClientIPAddr> against the filtering
* scheme defined in 'RLI_CUSTOM_DYNAMIC_IP_CHECK'. If IP filtering is <not>
* enabled, then all IP addresses are allowed (valid).
*
*
* RETURNS:
*\is
*\i TRUE
* If <ClientIPAddr> is a valid IP address, or if filtering is not enabled.
*\i FALSE
* If <ClientIPAddr> is an invalid IP address (one that should be blocked).
*\ie
*
* NOMANUAL
*/
BOOL accessIpValid
(
ubyte4 ClientIpAddr /* client IP address !rws hex? */
)
{
#ifdef __RLI_DEBUG_ACCESS__
BOOL retBool;
printf("ACCESS_ValidIpAddress: Checking client request (address=%d.%d.%d.%d).\n", (int)((ClientIpAddr >> 24) & 0xff), (int)((ClientIpAddr >> 16) & 0xff), (int)((ClientIpAddr >> 8) & 0xff), (int)(ClientIpAddr & 0xff));
#endif
/* is ip filtering enabled? */
if (RLI_CUSTOM_DYNAMIC_IP_FILTER_ENABLED())
{
#ifndef __RLI_DEBUG_ACCESS__
/* check if the ip address is valid */
return RLI_CUSTOM_DYNAMIC_IP_CHECK(ClientIpAddr, 0, 0);
#else
retBool = RLI_CUSTOM_DYNAMIC_IP_CHECK(ClientIpAddr, 0, 0);
if (retBool)
printf("accessIpValid: Valid IP address.\n");
else
printf("accessIpValid: Invalid IP address --- block!\n");
return retBool;
#endif
}
DEBUG_MSG_0("accessIpValid: filtering not enabled.\n");
return TRUE;
}
#endif /* __ENABLE_LAN_IP_FILTER__ */
DTTypeInfo * wmAccessInfoGet
(
void
)
{
return pAccessInfo;
}
void wmAccessInfoSet
(
DTTypeInfo * pInfo
)
{
pAccessInfo = pInfo;
}
ubyte4 wmAccessLevelGet
(
void * what
)
{
return systemAccessLevel;
}
ubyte4 wmAccessGroupsGet
(
void * what
)
{
return systemAccessGroups;
}
#ifndef __WMB_VIEW_ACCESS_MODEL__
/**************************************************************************
*
* wmAccessReadAllowed - Determines if a user has read access for a resource.
*
* This routine checks a user's access level--defined in the session
* environment structure--against the resources' required access level.
*
*
* RETURNS:
*\is
*\i TRUE
* If the user has the required read access level.
*\i FALSE
* If the user does not have the required read access level.
*\ie
*/
BOOL wmAccessReadAllowed
(
Access userAccess, /* user privileges*/
Access resourceAccess /* access level required by resource */
)
{
/* See if user's access level is high enough */
if (wmAccessInvalidLevel (resourceAccess, userAccess))
return FALSE;
/* If user is in resource's group */
#if (ACCESS_GROUP_MASK_K != 0)
if (wmAccessInvalidGroup (resourceAccess, userAccess))
return FALSE;
#endif
return TRUE;
}
/**************************************************************************
*
* wmAccessWriteAllowed - Determines if a user has write access for a resource.
*
* This routine determines if a user has the appripriate accesss level to
* write to a resource.
*
*
* RETURNS:
*\is
*\i TRUE
* If the user has the required write access level.
*\i FALSE
* If the user does not have the required write access level.
*\ie
*/
BOOL wmAccessWriteAllowed
(
Access userAccess, /* user environment struct pointer */
Access resourceAccess /* access level required by resource */
)
{
/* See if user's access level is high enough */
if (wmAccessInvalidLevel (resourceAccess, userAccess))
return FALSE;
/* See if user's options overlap with the resource's (if resource options is not empty) */
#if (ACCESS_GROUP_MASK_K != 0)
if (wmAccessInvalidGroup (resourceAccess, userAccess))
return FALSE;
#endif
return TRUE;
}
/**************************************************************************
*
* wmAccessReadOkay - Determines if a user has read access for a resource.
*
* This routine checks a user's access level--defined in the session
* environment structure--against the resources' required access level.
*
*
* RETURNS:
*\is
*\i TRUE
* If the user has the required read access level.
*\i FALSE
* If the user does not have the required read access level.
*\ie
*
* NOMANUAL
*/
BOOL wmAccessReadOkay
(
Access userAccess, /* user privileges*/
Access resourceAccess /* access level required by resource */
)
{
/* See if user's access level is high enough */
if (wmAccessInvalidLevel (resourceAccess, userAccess))
return FALSE;
/* If user is in resource's group */
#if (ACCESS_GROUP_MASK_K != 0)
if (wmAccessInvalidGroup (resourceAccess, userAccess))
return FALSE;
#endif
return TRUE;
}
#endif
/**************************************************************************
*
* wmAccessToStr - convert value of access to string
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*/
STATUS wmAccessToStr
(
Access nAccess,
sbyte * pString
)
{
DTTypeInfo * pTypeInfo;
sbyte * tptr;
sbyte delim[2];
sbyte numstr[20];
int i;
int hits;
int count;
Access mask;
unsigned int tmp_access;
if (NULL == (pTypeInfo = wmAccessInfoGet()))
return wmError(ERROR_GENERAL_UNINITIALIZED, "no system access info");
if (NULL == pString)
return wmError(ERROR_GENERAL_NO_DATA, "no access data");
pString[0] = '\0';
#ifndef __RLI_ACCESS_LEVEL_MASK__
return wmConvertToStr (&nAccess,pString,4,DATATYPE_INTEGER_K);
#endif
/* get separater */
tptr = strstr(pTypeInfo->pValidateStr,"D=");
if (NULL==tptr)
return ERROR_GENERAL_NOT_FOUND;
delim[0] = tptr[2];
delim[1] = '\0';
count = wmConvertGetEnumCount(pTypeInfo);
mask = 0x01 << __RLI_ACCESS_LEVEL_SHIFT__;
hits = 0;
/* Convert Option Bits */
while (mask & __RLI_ACCESS_OPTION_MASK__)
{
if (nAccess & mask)
{
/* find it in the list */
for (i = 0; i < count; i++)
{
if (mask == (Access) pTypeInfo->pEnumTable[i].EnumValue)
{
if (hits)
strcat(pString, delim);
strcat(pString,pTypeInfo->pEnumTable[i].EnumString);
nAccess &= (Access)~mask;
hits++;
break;
}
}
/* Do not allow undefined option bits */
if (i == count) {
nAccess &= (Access)~mask;
/* return ERROR_GENERAL_NOT_FOUND; */
}
}
mask = (Access)(mask << 1);
}
/* Convert and append access level */
tmp_access = wmAccessLevelGet(NULL);
if (tmp_access > 0)
tmp_access &= nAccess;
wmConvertToStr(&tmp_access, numstr, sizeof(numstr), DATATYPE_UINTEGER_K);
if (strlen(pString))
strcat(pString,delim);
strcat(pString,numstr);
return OK;
}
/**************************************************************************
*
* wmAccessFromString - convert string representation to numeric access
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i ERROR_GENERAL_OUT_OF_RANGE
*\i OK
*\ie
*/
STATUS wmAccessFromString
(
sbyte * pString,
Access * pAccess
)
{
DTTypeInfo * pTypeInfo;
STATUS status;
sbyte * pTemp;
sbyte * pNext;
sbyte delimiter;
int i;
unsigned int enumLen;
unsigned int enumValue;
int count;
char numstr[20];
sbyte4 tmpAccess;
Access tmpAccess1;
BOOL match;
DTEnumInfo * pEnumTable;
*pAccess = 0;
if (NULL == (pTypeInfo = wmAccessInfoGet()))
return wmError(ERROR_GENERAL_UNINITIALIZED, "no system access info");
if (NULL_STRING(pString))
return wmError(ERROR_GENERAL_NO_DATA, "no access data");
#ifndef __RLI_ACCESS_LEVEL_MASK__
return wmConvertStrTo(pString, pAccess, sizeof(Access), DATATYPE_INTEGER_K);
#endif
/* get separater */
if (NULL == (pTemp = strstr(pTypeInfo->pValidateStr,"D=")))
return ERROR_GENERAL_NOT_FOUND;
delimiter = pTemp[2];
count = wmConvertGetEnumCount(pTypeInfo);
pTemp = pString;
while (0 != *pTemp)
{
enumLen = (unsigned int)STRLEN(pTemp);
if (NULL != (pNext = STRCHR(pTemp, delimiter)))
enumLen = (unsigned int) (pNext - pTemp);
if (ISDIGIT((int)*pTemp))
{
strncpy(numstr, pTemp, enumLen);
numstr[enumLen] = '\0';
if (OK != (status = wmConvertStrTo(numstr, &tmpAccess, sizeof(tmpAccess), DATATYPE_INTEGER_K)))
return status;
if ((0 > tmpAccess) || (tmpAccess > ACCESS_LEVEL_MASK_K))
return ERROR_GENERAL_OUT_OF_RANGE;
tmpAccess1 = (Access)tmpAccess;
*pAccess |= tmpAccess1;
}
else
{
/* find it in the list */
pEnumTable = pTypeInfo->pEnumTable;
match = FALSE;
enumValue = 0;
for (i = 0; i < count; i++, pEnumTable++)
{
if (0 != STRNCMP(pTemp, pEnumTable->EnumString, enumLen))
continue;
enumValue = pEnumTable->EnumValue;
if (enumLen == (unsigned int) STRLEN(pEnumTable->EnumString))
{
match = TRUE;
break;
}
if (match)
return ERROR_GENERAL_DATA_AMBIG;
match = TRUE;
}
/* Do not allow undefined option bits */
if (! match)
return ERROR_GENERAL_ILLEGAL_VALUE;
*pAccess |=(Access)enumValue;
}
/* get next entry */
pTemp += enumLen;
if (NULL != pNext)
pTemp++;
}
return OK;
} /* wmAccessFromString */
/*New APIs */
Access wmAccessReadGet ( WM_ACCESS_T pAccess )
{
return pAccess.read;
}
Access wmAccessWriteGet ( WM_ACCESS_T pAccess )
{
return pAccess.write;
}
STATUS wmAccessReadSet ( WM_ACCESS_T *pAccess, Access readAccess )
{
if (NULL == pAccess)
return ERROR;
else
{
pAccess->read = readAccess ;
return OK;
}
}
STATUS wmAccessWriteSet ( WM_ACCESS_T *pAccess, Access writeAccess )
{
if (NULL == pAccess)
return ERROR;
else
{
pAccess->write = writeAccess ;
return OK;
}
}
/* eof wmAccessLib.c */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,208 @@
/* wmCompareLib.c - comparison tests library */
/* Copyright 2001, 2010 Wind River Systems, Inc. */
/*
modification history
--------------------
01c,29jan10,m_z VxWorks 64-bit support
(WIND00193649)
01a,01aug01,pns written
01b,09oct01,rws modified comments
*/
/*
DESCRIPTION
This module implements data comparisons for RCB data
INCLUDE FILES: wm.h wmb.h
*/
/* includes */
#include "wm.h"
#include "wmb.h"
/*-----------------------------------------------------------------------*/
BOOL compareUchars
(
void * pUchar,
void * pUchar1
)
{
if ( (NULL == pUchar) || (NULL == pUchar1) )
return FALSE;
else
return (*((unsigned char *)pUchar) == *((unsigned char *)pUchar1));
}
/*-----------------------------------------------------------------------*/
BOOL compareIP
(
void * pIPaddr,
void * pIPaddr1
)
{
if ( (NULL == pIPaddr) || (NULL == pIPaddr1) )
return FALSE;
else
return (*((ubyte4 *)pIPaddr) == *((ubyte4 *)pIPaddr1));
}
/*-----------------------------------------------------------------------*/
BOOL compareInts
(
void * pInt,
void * pInt1
)
{
if ( (NULL == pInt) || (NULL == pInt1) )
return FALSE;
else
return (*((int *)pInt) == *((int *)pInt1)) ? TRUE : FALSE;
}
/*-----------------------------------------------------------------------*/
BOOL compareUnsignedInts
(
void * pUnsigned,
void * pUnsigned1
)
{
if ( (NULL == pUnsigned) || (NULL == pUnsigned1) )
return FALSE;
else
return (*((unsigned int *)pUnsigned) == *((unsigned int *)pUnsigned1));
}
/*-----------------------------------------------------------------------*/
BOOL compareShorts
(
void * pShort,
void * pShort1
)
{
if ( (NULL == pShort) || (NULL == pShort1) )
return FALSE;
else
return (*((short *)pShort) == *((short *)pShort1));
}
/*-----------------------------------------------------------------------*/
BOOL compareUshorts
(
void * pUshort,
void * pUshort1
)
{
if ( (NULL == pUshort) || (NULL == pUshort1) )
return FALSE;
else
return (*((unsigned short *)pUshort) == *((unsigned short *)pUshort1));
}
/*-----------------------------------------------------------------------*/
BOOL compareLongs
(
void * pLong,
void * pLong1
)
{
if ( (NULL == pLong) || (NULL == pLong1) )
return FALSE;
else
return (*((long *)pLong) == *((long *)pLong1));
}
/*-----------------------------------------------------------------------*/
BOOL compareUlongs
(
void * pUlong,
void * pUlong1
)
{
if ( (NULL == pUlong) || (NULL == pUlong1) )
return FALSE;
else
return (*((unsigned long *)pUlong) == *((unsigned long *)pUlong1));
}
/*-----------------------------------------------------------------------*/
BOOL compareStrings
(
void * pStr,
void * pStr1
)
{
if ((NULL == pStr) || (NULL == pStr1))
return FALSE;
return (0 == STRCMP(pStr, pStr1));
}
/**************************************************************************
*
* compareValues - Compare objects of same datatype.
*
* This routine is a wrapper for comparison functions for each of the
* following datatypes: 'int', 'uint','short', 'ushort', 'long', 'ulong',
* 'IpAddr', and 'string'.
*
* RETURNS:
*\is
*\i TRUE
*
*\i FALSE
*
*\ie
*/
BOOL compareValues
(
void * pDataObject,
void * pDataObject1,
DATATYPE_T DType
)
{
switch (DType)
{
case DATATYPE_INTEGER_K:
return compareInts(pDataObject, pDataObject1);
case DATATYPE_UINTEGER_K:
return compareUnsignedInts(pDataObject, pDataObject1);
case DATATYPE_SHORT_K:
return compareShorts(pDataObject, pDataObject1);
case DATATYPE_USHORT_K:
return compareUshorts(pDataObject, pDataObject1);
case DATATYPE_LONG_K:
return compareLongs(pDataObject, pDataObject1);
case DATATYPE_ULONG_K:
return compareUlongs(pDataObject, pDataObject1);
case DATATYPE_IPV4_K:
return compareIP(pDataObject, pDataObject1);
case DATATYPE_STRING_K:
return compareStrings(pDataObject, pDataObject1);
default:
break;
}
return FALSE;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,871 @@
/* wmFileLib.c - ansi file support */
/* adapted from rc_ansifs.c */
/*
* Copyright (c) 2002-2010, 2012 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
--------------------
01h,12nov12,f_f don't attach fileDir if it's invalid (WIND00387021)
01g,02aug12,f_f correct the wrong file dir from the full path (WIND00367073)
01f,17may12,h_l replace NO_STRING with NULL_STRING (WIND00032212)
01e,07may10,m_z eliminate compile warning
01d,29jan10,m_z VxWorks 64-bit support
(WIND00193649)
01c,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01b,10aug06,ps fix missing arguments to wmosSemTake
01a,17may02,rs updated refgen comments
01 , ,ps imported from rc 3.3 vob
*/
/*
DESCRIPTION:
WindManage ANSI file support library.
INCLUDE FILES:
wm.h
*/
#include "wm.h"
#ifdef __ANSI_FILE_MANAGER_ENABLED__
#ifndef kDIRECTORY_BUFFER_SIZE
#define kDIRECTORY_BUFFER_SIZE 256
#endif
static sbyte * mDefaultPath = NULL;
static OS_SEM_T mFileMutex;
/*-----------------------------------------------------------------------*/
#ifdef __DECOMPRESSION_ENABLED__
LOCAL void wmFileLock
(
void
)
{
wmosSemTake( mFileMutex, WAIT_FOREVER_K );
}
/*-----------------------------------------------------------------------*/
LOCAL void wmFileUnlock
(
void
)
{
wmosSemGive( mFileMutex );
}
#endif /* __DECOMPRESSION_ENABLED__ */
/*-----------------------------------------------------------------------*/
LOCAL void wmFileDetermineFileLength
(
FILE * pFile,
Length * pLength
)
{
long start, end;
/* Is there an easier way of doing this? */
fseek(pFile, 0, SEEK_SET);
start = ftell(pFile);
fseek(pFile, 0, SEEK_END);
end = ftell(pFile);
fseek(pFile, 0, SEEK_SET);
*pLength = (Length)end - (Length)start;
}
/**************************************************************************
*
* wmFileCreateDirDOS - WMB file open.
*
* This routine will.
*
* RETURNS: OK, or ERROR if the file is not found or if there is insufficient
* memory to open the file.
*
*
* NOMANUAL
*/
#if 0
LOCAL WM_DIR_T * wmFileCreateDirDOS
(
sbyte * pFileName
)
{
WM_DIR_T * pDir;
if (! wmNew(pDir))
{
wmError(ERROR_MEMMGR_NO_MEMORY, "wmFileCreateDirDOS: no memory");
return NULL;
}
if (NULL == (pDir->pDirHandle = (DIR_HANDLE *) wmMalloc(sizeof(DIR_HANDLE))))
{
wmFree(pDir)
wmError(ERROR_MEMMGR_NO_MEMORY, "wmFileCreateDirDOS: no memory");
return NULL;
}
return pDir;
}
#endif
/*-----------------------------------------------------------------------*/
LOCAL void * wmFileOpenFile
(
sbyte * pFileName,
sbyte * pPathName,
#ifndef _WRS_CONFIG_LP64
sbyte4 * pLength,
#else
sbyte8 * pLength,
#endif
BOOL compression
)
{
sbyte *pFullPath = NULL;
sbyte *pData = NULL;
sbyte *pReturn = NULL;
FILE *pFile = NULL;
Length pathLen = 0;
Length fullPathLen = 0;
Length bytesRead = 0;
Length fileLen = 0;
#ifdef __DECOMPRESSION_ENABLED__
BOOL isCompressed = FALSE;
sbyte *pDecompressedData;
sbyte4 decompressedLen;
#endif /* __DECOMPRESSION_ENABLED__ */
*pLength = -1; /* to differentiate a null for empty file */
pathLen = STRLEN(pPathName);
fullPathLen = pathLen + STRLEN(pFileName) + 3;
pFullPath = (sbyte*) wmosMalloc(fullPathLen);
if (NULL == pFullPath)
{
DEBUG_MSG_2("error malloc -- %d bytes, for %s\n", fullPathLen, pFileName);
return NULL;
}
STRCPY(pFullPath, pPathName);
/* does the base path have proper path separator? */
if (0 < pathLen)
{
--pathLen;
#ifdef __WIN32_OS__
if ('\\' != pPathName[pathLen])
STRCAT(pFullPath, "\\");
#else
if ('/' != pPathName[pathLen])
STRCAT(pFullPath, "/");
#endif
}
STRCAT(pFullPath, pFileName);
pFile = fopen(pFullPath, "rb");
if (NULL == pFile)
{
DEBUG_MSG_1("error fopen -- %s", pFullPath);
wmosFree(pFullPath);
return NULL;
}
wmFileDetermineFileLength( pFile, &fileLen );
if (0 >= fileLen)
{
*pLength = 0;
wmosFree(pFullPath);
return NULL;
}
pData = (sbyte*) wmosMalloc(fileLen + 1); /* +1 for EOL */
if (NULL == pData)
{
DEBUG_MSG_1("error malloc -- %d bytes, for buffer\n", fileLen);
wmosFree(pFullPath);
return NULL;
}
bytesRead = fread(pData, sizeof(sbyte), fileLen, pFile);
*pLength = fileLen;
pReturn = pData;
pData[fileLen] = 0; /* null terminate string */
#ifdef __DECOMPRESSION_ENABLED__
if (compression)
{
/* If the file is compressed, then use the decompression code.
Otherwise, just return the data as is. */
DECOMP_IsCompressed(pData, &isCompressed);
if ( isCompressed )
{
wmFileLock();
DECOMP_DecompressData(pData, bytesRead,
&pDecompressedData, &decompressedLen);
wmFileUnlock();
wmosFree(pData);
*pLength = decompressedLen;
pReturn = pDecompressedData;
}
}
#endif /* __DECOMPRESSION_ENABLED__ */
wmosFree(pFullPath);
fclose(pFile);
return pReturn;
}
/**************************************************************************
*
* wmFileReadFile - .
*
* This routine will .
*
* RETURNS: N/A.
*
*
* NOMANUAL
*/
void * wmFileReadFile
(
WM_DIR_T * pDir,
#ifndef _WRS_CONFIG_LP64
sbyte4 * pLen,
#else
sbyte8 * pLen,
#endif
sbyte * pId
)
{
sbyte * pBasePath;
if (NULL == pDir)
pBasePath = mDefaultPath;
else
pBasePath = pDir->cwd;
return wmFileOpenFile(pId, pBasePath, pLen, TRUE);
}
/**************************************************************************
*
* wmFileRetrieveFile - File retrieve.
*
* This routine will .
*
* RETURNS: Pointer to .
*
*
* NOMANUAL
*/
void * wmFileRetrieveFile
(
#ifndef _WRS_CONFIG_LP64
sbyte4 * pLen,
#else
sbyte8 * pLen,
#endif
sbyte * pId
)
{
return wmFileOpenFile(pId, mDefaultPath, pLen, TRUE);
}
/**************************************************************************
*
* wmFileReleaseFile - WMB file release.
*
* This routine will .
*
* RETURNS: N/A.
*
*
* NOMANUAL
*/
void wmFileReleaseFile
(
void *pObject
)
{
if (NULL != pObject)
wmosFree(pObject);
}
/**************************************************************************
*
* wmFileRetreiveResource - WMB resource retreive.
*
* This routine will .
*
* RETURNS: N/A.
*
*
* NOMANUAL
*/
void* wmFileRetrieveResource
(
#ifndef _WRS_CONFIG_LP64
sbyte4 * pLen,
#else
sbyte8 * pLen,
#endif
sbyte *pId
)
{
return wmFileOpenFile(pId, mDefaultPath, pLen, FALSE);
}
/**************************************************************************
*
* wmFileReleaseResource - WMB resource release.
*
* This routine will .
*
* RETURNS: N/A.
*
*
* NOMANUAL
*/
void wmFileReleaseResource
(
void *pObject
)
{
wmosFree(pObject);
}
/**************************************************************************
*
* wmFileInit - WMB file Lib init.
*
* This routine will .
*
* RETURNS: N/A.
*
*
* NOMANUAL
*/
STATUS wmFileInit
(
sbyte *pPath
)
{
/* already initialized? */
if (NULL != mDefaultPath)
return ERROR_GENERAL;
mDefaultPath = wmosMalloc (STRLEN(pPath) + 1 );
if ( NULL == mDefaultPath )
return ERROR_MEMMGR_NO_MEMORY;
STRCPY( mDefaultPath, pPath );
return wmosSemCreate(&mFileMutex, 1, 0);
}
#ifdef __ENABLE_SESSION_DIRECTORIES__
LOCAL BOOL wmFileChangePath
(
sbyte * pOldPath,
sbyte * pNewPath
)
{
sbyte *pParent;
/* relative change */
while (('.' == *pNewPath) && ('.' == *(pNewPath + 1)))
{
/* move up old path */
pParent = STRRCHR(pOldPath, PATH_CHAR_K);
pNewPath = STRCHR(pNewPath, PATH_CHAR_K);
/*
if (NULL == pNewPath)
return FALSE;
*/
if (NULL == pParent)
break;
*(++pParent) = 0;
if (NULL == pNewPath)
break;
}
return TRUE;
}
/**************************************************************************
*
* wmFileChdir - WMB chdir.
*
* This routine will .
*
* RETURNS: OK, or ERROR if <pPath> is invlaid. <pPath> can be relative or
* absolute.
*
*
* NOMANUAL
*/
STATUS wmFileChdir
(
WM_DIR_T * pDir,
sbyte * pPath
)
{
STATUS status = OK;
sbyte tempPath[kDIRECTORY_BUFFER_SIZE];
#ifndef _WRS_CONFIG_LP64
ubyte4 length;
#else
ubyte8 length;
#endif
#ifdef __WIN32_OS__
DWORD attributes;
#else
DIR *handle;
#endif
if (NULL == pDir)
return wmError(ERROR_GENERAL_NULL_POINTER, "no dir info");
if (NULL_STRING(pPath))
return wmError(ERROR_GENERAL_INVALID_PATH, "invalid path");
if (kDIRECTORY_BUFFER_SIZE < STRLEN(pPath))
return wmError(ERROR_GENERAL_BUFFER_OVERRUN, "buffer overflow");
STRNCPY(tempPath, pDir->cwd, kDIRECTORY_BUFFER_SIZE);
switch (*pPath)
{
case '.':
/* relative path */
wmFileChangePath(tempPath, pPath);
break;
case PATH_CHAR_K:
/* absolute path */
STRNCPY(tempPath, pPath, kDIRECTORY_BUFFER_SIZE);
break;
default:
#ifdef __WIN32_OS__
/* grrrr... stupid DOS */
if (':' == *(pPath + 1))
STRNCPY(tempPath, pPath, kDIRECTORY_BUFFER_SIZE);
else
#endif
{
length = STRLEN(tempPath);
if (PATH_CHAR_K != tempPath[length - 1])
{
tempPath[length++] = PATH_CHAR_K;
tempPath[length ] = 0;
}
STRNCAT(tempPath, pPath, kDIRECTORY_BUFFER_SIZE - length);
}
break;
}
/* make sure path is valid and have access */
#ifdef __WIN32_OS__
if ( -1 == (attributes = GetFileAttributes(tempPath)))
return ERROR_GENERAL_INVALID_PATH;
if ( 0 == (FILE_ATTRIBUTE_DIRECTORY & attributes))
return ERROR_GENERAL_INVALID_PATH;
#else
if (NULL == (handle = opendir(tempPath)))
return ERROR_GENERAL_INVALID_PATH;
closedir(handle);
#endif
STRNCPY(pDir->cwd, tempPath, kDIRECTORY_BUFFER_SIZE);
return status;
}
/**************************************************************************
*
* wmFileOpenDir - WMB file open. Win32 specific!
*
* This routine will.
*
* RETURNS: OK, or ERROR if the file is not found or if there is insufficient
* memory to open the file.
*
*
* NOMANUAL
*/
#ifdef __WIN32_OS__
STATUS wmFileOpenDir
(
WM_DIR_T * pDir,
sbyte * pFileName
)
{
sbyte * pFullPath;
sbyte4 length;
if (wmDirBad(pDir))
return wmError(ERROR_GENERAL_NULL_POINTER, "wmFileOpenDir: invalid dir struct");
if (NULL == pFileName)
pFileName = "*";
if (NULL == (pFullPath = wmMalloc(kDIRECTORY_BUFFER_SIZE)))
return wmError(ERROR_MEMMGR_NO_MEMORY, "wmFileOpenDir: no memory");
length = STRLEN(pDir->cwd);
STRCPY(pFullPath, pDir->cwd);
if (PATH_CHAR_K != pFullPath[length - 1])
{
pFullPath[length++] = PATH_CHAR_K;
pFullPath[length] = 0;
}
STRNCAT(pFullPath, pFileName, kDIRECTORY_BUFFER_SIZE - length);
/* Find first file in current directory */
if (-1L == (pDir->handle = _findfirst(pFullPath, &pDir->fileInfo)))
{
pDir->found = FALSE;
wmFree(pFullPath);
return wmError(ERROR_GENERAL_FILE_NOT_FOUND, "file not found");
}
wmFree(pFullPath);
return OK;
}
#else /* ! __WIN32_OS__ */
/**************************************************************************
*
* wmFileOpenDir - WMB file open.
*
* This routine will.
*
* RETURNS: OK, or ERROR if the file is not found or if there is insufficient
* memory to open the file.
*
*
* NOMANUAL
*/
STATUS wmFileOpenDir
(
WM_DIR_T * pDir,
sbyte * pFileName
)
{
#ifndef _WRS_CONFIG_LP64
ubyte4 length;
#else
ubyte8 length;
#endif
sbyte * pFullPath = NULL;
sbyte * pTruncate = NULL;
if (wmDirBad(pDir))
return wmError(ERROR_MEMMGR_NO_MEMORY, "wmFileOpenDir: invalid dir struct");
DEBUG_MSG_1("Open directory for filename: %s\n", pFileName);
if (NULL == (pFullPath = wmMalloc(kDIRECTORY_BUFFER_SIZE)))
return wmError(ERROR_MEMMGR_NO_MEMORY, "wmFileOpenDir: no memory");
length = STRLEN(pDir->cwd);
STRCPY(pFullPath, pDir->cwd);
if (PATH_CHAR_K != pFullPath[length - 1])
{
pFullPath[length++] = PATH_CHAR_K;
pFullPath[length] = 0;
}
DEBUG_MSG_1("Current working directory: %s\n", pFullPath);
if (! NULL_STRING(pFileName))
{
DEBUG_MSG_1("Appending filename: %s\n", pFileName);
STRNCAT(pFullPath, pFileName, kDIRECTORY_BUFFER_SIZE - length);
pTruncate = STRRCHR(pFullPath, PATH_CHAR_K);
if (NULL == pTruncate)
pTruncate = STRRCHR(pFullPath, '.');
}
DEBUG_MSG_0("Appended filename\n");
if (NULL != pTruncate)
{
pTruncate++;
DEBUG_MSG_1("Filemask: %s\n", pTruncate);
STRNCPY(pDir->fileMask, pTruncate, sizeof(pDir->fileMask));
*pTruncate = 0;
STRNCPY(pDir->fileDir, pFileName, sizeof(pDir->fileDir));
}
else
{
DEBUG_MSG_0("No filename given\n");
if (NULL_STRING(pFileName))
pDir->fileMask[0] = 0;
else
STRNCPY(pDir->fileMask, pFileName, sizeof(pDir->fileMask));
pDir->fileDir[0] = 0;
}
pDir->nameLen = (sbyte4)STRLEN(pDir->fileMask);
DEBUG_MSG_1("Adjusted directory: %s\n", pFullPath);
DEBUG_MSG_1("Filemask: %s\n", pDir->fileMask);
if (NULL == (pDir->handle = opendir (pFullPath)))
{
wmFree(pFullPath);
return wmError(ERROR_GENERAL_FILE_NOT_FOUND, "file not found");
}
wmFree(pFullPath);
return OK;
}
#endif /* ! __WIN32_OS__ */
/**************************************************************************
*
* wmFileNextDir - Get next file in dir. Win32 specific!
*
* This routine will .
*
* RETURNS: Poitner to next filename, or NULL if ?
*
*
* NOMANUAL
*/
#ifdef __WIN32_OS__
sbyte * wmFileNextDir
(
WM_DIR_T * pDir,
sbyte4 * size,
ubyte4 * flags
)
{
*size = 0;
*flags = 0;
if (NULL == pDir)
return NULL;
/* First file in current directory? */
if (FALSE == pDir->found)
pDir->found = TRUE;
else
{
if (0 > _findnext(pDir->handle, &pDir->fileInfo))
return NULL;
}
if (pDir->fileInfo.attrib & _A_SUBDIR)
*flags |= FS_DIRECTORY_K;
if (pDir->fileInfo.attrib & _A_RDONLY)
*flags |= FS_READ_ONLY_K;
*size = pDir->fileInfo.size;
return pDir->fileInfo.name;
}
#else /* ! __WIN32_OS__ */
/**************************************************************************
*
* wmFileNextDir - Get next file in dir.
*
* This routine will .
*
* RETURNS: Poitner to next filename, or NULL if .
*
*
* NOMANUAL
*/
sbyte * wmFileNextDir
(
WM_DIR_T * pDir,
#ifndef _WRS_CONFIG_LP64
sbyte4 *size,
#else
sbyte8 *size,
#endif
ubyte4 *flags
)
{
sbyte fileSeparator = PATH_CHAR_K;
sbyte * pFullName;
struct dirent * pDirInfo;
sbyte * pName;
struct stat fileStats;
ubyte4 dirlen;
*size = 0;
*flags = 0;
if (wmDirBad(pDir))
return NULL;
if (NULL == (pFullName = wmMalloc(kDIRECTORY_BUFFER_SIZE)))
return NULL;
*pFullName = 0;
if (NULL == (pDirInfo = readdir(pDir->handle)))
{
DEBUG_MSG_0("Readdir failed\n");
wmFree(pFullName);
return NULL;
}
pName = pDirInfo->d_name;
if (0 == STRCMP(pName, ".") || (0 == STRCMP(pName, "..")))
return pName;
/*
if ( (!NULL_STRING(pName)) && (0 != STRNCMP(pName, pDir->fileMask, pDir->nameLen)))
return NULL;
*/
if (!NULL_STRING(pDir->cwd))
STRCPY(pFullName, pDir->cwd);
dirlen = STRLEN(pDir->fileDir);
if (dirlen > 1 && PATH_CHAR_K == pDir->fileDir[dirlen-1])
{
if (!NULL_STRING(pFullName))
STRNCAT(pFullName, &fileSeparator, 1);
if (!NULL_STRING(pDir->fileDir))
STRCAT(pFullName, pDir->fileDir);
}
if (!NULL_STRING(pFullName))
STRNCAT(pFullName, &fileSeparator, 1);
if (!NULL_STRING(pDirInfo->d_name))
STRCAT(pFullName, pDirInfo->d_name);
DEBUG_MSG_1("Stat for: %s\n", pFullName);
/* expand error handling -- get err info */
if (0 != stat(pFullName, &fileStats))
{
DEBUG_MSG_0("Stat failed\n");
wmFree(pFullName);
return NULL;
}
*size = fileStats.st_size;
DEBUG_MSG_1("File size: %d\n", *size);
if (S_ISDIR(fileStats.st_mode))
*flags |= FS_DIRECTORY_K;
wmFree(pFullName);
return pDirInfo->d_name;
}
#endif /* __WIN32_OS__ */
/**************************************************************************
*
* wmFileCloseDir - WMB file close.
*
* This routine will .
*
* RETURNS: N/A.
*
*
* NOMANUAL
*/
void wmFileCloseDir
(
WM_DIR_T * pDir
)
{
CLOSEDIR(pDir->handle);
}
#else /* __ENABLE_SESSION_DIRECTORIES__ */
STATUS wmFileChdir(WM_DIR_T * pDir, sbyte *pPath) {return OK;}
void wmFileCloseDir(WM_DIR_T * pDir){}
STATUS wmFileOpenDir(WM_DIR_T * pDir, sbyte *pFileName) {return OK;}
sbyte* wmFileNextDir(
WM_DIR_T * pDir,
#ifndef _WRS_CONFIG_LP64
sbyte4 *size,
#else
sbyte8 *size,
#endif
ubyte4 *flags
)
{
*size = 0;
*flags = 0;
return NULL;
}
#endif /* __ENABLE_SESSION_DIRECTORIES__ */
#endif /* __ANSI_FILE_MANAGER_ENABLED__ */
@@ -0,0 +1,473 @@
/* wmHashLib.c - hash function library */
/* Copyright 2001-2007,2010 Wind River Systems, Inc. */
/*
modification history
--------------------
01d.28apr10,m_z eliminate compile warning
01c,29jan10,m_z VxWorks 64-bit support
(WIND00193649)
01b,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01a,01aug01,pns written
*/
/*
DESCRIPTION
This module implements hash functions for the internal database
INCLUDE FILES: wm.h
*/
/* includes */
#include "wm.h"
/* average number of hash collisions per bucket */
#ifndef AVERAGE_COLLISIONS_K
#define AVERAGE_COLLISIONS_K 3
#endif
sbyte4 wmHashPrime ( sbyte4 start);
LOCAL sbyte4 prime_numbers[] = /* array of prime numbers */
{
7, 13, 23, 31, 47, 53, 71, 89, 101, 199, 223, 293, 311, 397, 409, 499,
509, 599, 607, 691, 709, 797, 811, 887, 907, 997, 1013, 1097, 1109,
1193, 1201, 1297, 1301
};
sbyte4 wmHashPrime
(
sbyte4 start /* number of objects to find prime number */
)
{
unsigned int i;
/* Find the Prime number just larger than start */
for (i = 0; i < ARRAY_SIZE(prime_numbers); i++)
{
/* scan the list of primes looking for the entry larger */
if ( prime_numbers[i] >= start)
return prime_numbers[i];
}
/* The largest prime used for object counts over 5000 */
return prime_numbers[ARRAY_SIZE(prime_numbers) - 1];
}
/**************************************************************************
*
* wmHashKeyGenerate - generate hash value from string
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
ubyte4 wmHashKeyGenerate
(
sbyte * pStr
)
{
sbyte4 count = 0;
sbyte4 hash = 0;
while (NAME_OK(pStr))
{
count++;
hash *= 32;
hash += *(pStr++);
}
return (ubyte4)hash;
}
/**************************************************************************
*
* wmHashEntryGet - get hash node to table entry offset
*
* Entry is first found -- may be wrong item because of hash collision
* This is ok, the caller must verify
*
* RETURNS: Found hash or NULL
*
*
* NOMANUAL
*/
LOCAL STATUS wmHashEntryGet
(
WMB_HASH_TABLE_T * pTable,
sbyte * pName,
ubyte4 * pKey,
HASH_T * * ppHash
)
{
ubyte4 key;
ubyte4 index;
HASH_T * pNode;
if (NULL == pTable || NULL == pName || NULL == pKey || NULL == ppHash)
return wmError(ERROR_GENERAL_NULL_POINTER, "null pointers");
pNode = pTable->pNodes;
key = wmHashKeyGenerate (pName);
/* key has to be trimmed to within table range */
index = key % pTable->tableSize;
pNode += index;
*ppHash = pNode;
*pKey = key;
return OK;
}
/**************************************************************************
*
* wmHashConstruct - make a new hash table
*
* RETURNS: ERROR or OK
*
*
* NOMANUAL
*/
STATUS wmHashConstruct
(
MEM_POOL_ID memID,
sbyte4 rows,
fnHashKeyExtract pFuncExtractKey,
fnHashCompare pFuncCompare,
fnHashNodeName pFuncName,
WMB_HASH_TABLE_T ** ppTable
)
{
WMB_HASH_TABLE_T * pTable;
sbyte4 size;
HASH_T * pNodes;
if (1 > rows)
return wmError (ERROR, "wmHashConstruct: invalid row count");
rows = wmHashPrime (rows / AVERAGE_COLLISIONS_K);
size = (sbyte4)sizeof(HASH_T) * rows;
if (NULL == memID)
{
pTable = (WMB_HASH_TABLE_T *) wmMalloc (sizeof(WMB_HASH_TABLE_T));
pNodes = (HASH_T *) wmMalloc ((ubyte4)size);
}
else
{
pTable = (WMB_HASH_TABLE_T *) wmPoolAlloc (memID, sizeof(WMB_HASH_TABLE_T));
pNodes = (HASH_T *) wmPoolAlloc (memID, (ubyte4)size);
}
if (NULL == pTable || NULL == pNodes)
{
if (NULL == memID)
{
if (NULL != pTable)
wmFree (pTable);
if (NULL != pNodes)
wmFree (pNodes);
}
else
{
if (NULL != pTable)
wmPoolFree (memID, pTable);
if (NULL != pNodes)
wmPoolFree (memID, pNodes);
}
return wmError (ERROR, "no memory");
}
memset(pNodes, 0, (ubyte4)size);
pTable->tableSize = rows;
pTable->pFuncCompare = pFuncCompare;
pTable->pFuncExtractKey = pFuncExtractKey;
pTable->pNodes = pNodes;
pTable->mem = memID;
pTable->pBlock = NULL;
*ppTable = pTable;
return OK;
}
/**************************************************************************
*
* wmHashDestruct - free a hash table
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
void wmHashDestruct
(
WMB_HASH_TABLE_T * pTable /* pointer to hash table */
)
{
MEM_POOL_ID pool;
if (NULL != pTable->pBlock)
wmMemBlockDestroy (pTable->pBlock);
if (NULL != (pool = pTable->mem))
{
wmPoolFree (pool, pTable->pNodes);
wmPoolFree (pool, pTable);
}
else
{
wmFree (pTable->pNodes);
wmFree (pTable);
}
}
/**************************************************************************
*
* wmHashNodeNew - create a new hash node
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
LOCAL HASH_T * wmHashNodeNew
(
WMB_HASH_TABLE_T * pTable /* hash table */
)
{
WM_BLOCK_T * pBlock;
HASH_T * pHash;
if (NULL == (pBlock = pTable->pBlock))
{
pBlock = wmMemBlockCreate(pTable->mem, NULL, pTable->tableSize, sizeof(HASH_T));
if (NULL == pBlock)
return NULL;
pTable->pBlock = pBlock;
}
if (NULL != (pHash = wmMemBlockEntryCreate(pBlock)))
wmZero(pHash);
return pHash;
}
/**************************************************************************
*
* wmHashEntryAdd - add a new element to hash table
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
STATUS wmHashEntryAdd
(
WMB_HASH_TABLE_T * pHashTable, /* hash table */
sbyte * pName, /* name to register */
void * pId, /* identifier (component or session) */
void * pEntry /* database entry */
)
{
HASH_T * pNode;
HASH_T * pPrevNode;
fnHashCompare compare;
ubyte4 key;
if ((NULL == pHashTable) || (NULL == pEntry))
return wmError (ERROR_GENERAL_NOT_FOUND,
"wmHashEntryAdd: invalid table or entry");
/* Find the relevant bucket entry */
if (OK != wmHashEntryGet(pHashTable, pName, &key, &pNode))
return ERROR;
/* if we got a hit it's either a duplication or hash collision */
compare = pHashTable->pFuncCompare;
if (NULL != pNode->pEntry)
{
pPrevNode = pNode;
/* Check to make sure there aren't any duplicates */
while (NULL != pNode)
{
if (NULL == pNode->pEntry)
break;
/* don't bother w/ strings unless keys are same */
if ((key == pNode->key) &&
(NULL != pId && pId == pNode->owner) &&
compare (pName, pNode->pEntry))
{
DEBUG_MSG_1("Duplicate entry: %s\n", pName);
return wmError(ERROR_GENERAL_ACCESS_DENIED, "duplicate entry");
}
pPrevNode = pNode;
pNode = pNode->pNext;
}
if (NULL == pNode)
{
if (NULL == (pNode = wmHashNodeNew(pHashTable)))
return wmError(ERROR_GENERAL, "no memory");
}
/* don't link to ourselves */
if (pNode != pPrevNode)
pPrevNode->pNext = pNode;
}
pNode->pEntry = pEntry;
pNode->key = key;
pNode->owner = pId;
pHashTable->count++;
#ifdef __WM_DEBUG__
pNode->rid = pHashTable->count;
#endif
return OK;
} /* wmHashEntryAdd */
/**************************************************************************
*
* wmHashEntryFind - find a name in hash table
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
void * wmHashEntryFind
(
WMB_HASH_TABLE_T * pTable,
sbyte * pName,
void * pID
)
{
ubyte4 key;
HASH_T * pNode;
if ((NULL == pTable) || (NULL == pName))
return NULL;
if (OK != wmHashEntryGet(pTable, pName, &key, &pNode))
return NULL;
if (NULL == pNode->pEntry)
return NULL;
/*
if (wmbEntryFlagGet(pEntry, DB_FLAG_ALIASED))
{
pName = wmbEntryNameGet(pEntry);
while (NAME_OK(pName))
pName++;
if (OK != wmHashEntryGet(pTable, ++pName, &key, &pNode))
return NULL;
}
*/
for ( ; NULL != pNode; pNode = pNode->pNext)
{
if (NULL == pNode->pEntry)
return NULL;
if (NULL != pID && pID != pNode->owner)
continue;
if (key != pNode->key)
continue;
if (pTable->pFuncCompare (pName, pNode->pEntry))
return pNode->pEntry;
}
return NULL;
} /* wmHashEntryFind */
#ifdef __WM_DEBUG__
/**************************************************************************
*
* wmHashDump - dump hash table
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
void wmHashDump
(
WMB_HASH_TABLE_T * pTable
)
{
sbyte4 index;
HASH_T * pNode;
HASH_T * pTemp;
fnHashNodeName pFuncName;
pFuncName = pTable->pFuncName;
pNode = pTable->pNodes;
for (index = 0; index < pTable->tableSize; index++, pNode++)
{
for (pTemp = pNode; NULL != pTemp; pTemp = pTemp->pNext)
{
if (NULL == pTemp->pEntry)
continue;
printf("%3d 0x%x %s\n", index, pTemp->key, pFuncName(pTemp->pEntry));
}
}
}
#endif
/* eof wmHashLib.c */
@@ -0,0 +1,749 @@
/* wmInstanceLib.c - WindManage Instance library */
/*
* Copyright (c) 2004-2007, 2010-2013 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
--------------------
01g,08apr13,r_w fix coverity issues for defect WIND00411995
01f,17may12,h_l replace NO_STRING with NULL_STRING (WIND00032212)
01e,03mar11,r_w prevent from accessing illegal address.defect WIND00255070
01d,29apr10,m_z eliminate compile warning
01c,29jan10,m_z VxWorks 64-bit support
(WIND00193649)
01b,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01a,04may04,dlr derived from wmOidLib.c, adapted to string Instances
*/
/*
DESCRIPTION
This module contains support routines string-based instance manipulation.
All string instance sizes include the termination character.
This library does support base instances for the tables. They
are not yet used, but are reserved for heirarchical WindMarks
in the future. NOTE that termination character of the base
Instance must be accounted for when merging or comparing
Instances.
INCLUDE FILES: wm.h
*/
/* includes */
#include "wm.h"
#ifndef _WRS_CONFIG_LP64
int wmInstanceMax
#else
long wmInstanceMax
#endif
(
WM_INSTANCE_T inst
);
#ifdef __WM_DEBUG__
LOCAL BOOL debugEnabled = FALSE;
void wmInstanceDebug
(
WM_INSTANCE_T inst,
sbyte * pMsg
)
{
if (! debugEnabled)
return;
wmInstancePrint(inst, pMsg);
}
void wmInstanceDebugEnable
(
BOOL enable
)
{
debugEnabled = enable;
}
#endif /* __WM_DEBUG__ */
/**************************************************************************
*
* wmInstanceMax - max possible of Instance in bytes
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
#ifndef _WRS_CONFIG_LP64
int wmInstanceMax
#else
long wmInstanceMax
#endif
(
WM_INSTANCE_T inst
)
{
return (long)wmBufferMaxGet(inst);
}
/**************************************************************************
*
* wmInstanceLen - length of Instance in bytes (the terminator is counted)
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
#ifndef _WRS_CONFIG_LP64
int wmInstanceLen
#else
long wmInstanceLen
#endif
(
WM_INSTANCE_T inst
)
{
return (long)wmBufferUsedGet(inst);
}
/**************************************************************************
*
* wmInstancePrint - print ascii Instance w/ message
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
void wmInstancePrint
(
WM_INSTANCE_T pInstance,
sbyte * pMsg
)
{
sbyte temp[256];
if (OK != wmInstanceStringGet(pInstance, temp, sizeof(temp)))
strcpy(temp, "(empty)");
if (NULL == pMsg)
printf("%s\n", temp);
else
printf("%s %s\n", pMsg, temp);
}
/**************************************************************************
*
* wmInstanceFromString - create inst from an ascii string
*
* This routine copys the string-based instance into the provided buffer,
*
* If <msize> is greater than the storage required, the buffer size is
* increased to <msize>.
*
*
* RETURNS:\is
*\i inst buffer pointer
*\i NULL
*\ie
*
* NOMANUAL
*/
WM_BUFFER_T * wmInstanceFromString
(
sbyte * pString, /* ascii version of inst */
#ifndef _WRS_CONFIG_LP64
int msize /* optional max buffer size in bytes */
#else
long msize /* optional max buffer size in bytes */
#endif
)
{
WM_BUFFER_T * pInst;
#ifndef _WRS_CONFIG_LP64
int len = 1;
#else
long len = 1;
#endif
if (NULL_STRING(pString)) return NULL;
#ifndef _WRS_CONFIG_LP64
len = (int)strlen(pString) + 1; /* Count the terminator */
#else
len = (long)strlen(pString) + 1; /* Count the terminator */
#endif
if (msize < len) msize = len; /* set size of buffer to ask for */
/* create an Instance buffer */
#ifndef _WRS_CONFIG_LP64
pInst = wmBufferCreate (NULL, (unsigned int)msize, pString, DATATYPE_STRING_K, TRUE);
#else
pInst = wmBufferCreate (NULL, (unsigned long)msize, pString, DATATYPE_STRING_K, TRUE);
#endif
if (NULL == pInst) return NULL;
#ifndef _WRS_CONFIG_LP64
pInst->Used = (ubyte4)len;
#else
pInst->Used = (ubyte8)len;
#endif
return (pInst);
}
/**************************************************************************
*
* wmInstanceStringSet - update inst with an ascii string inst
*
* This routine simply copies/appends a string-based instance
*
* RETURNS:\is
*\i OK or ERROR
*\ie
*
* NOMANUAL
*/
STATUS wmInstanceStringSet
(
WM_INSTANCE_T pInstance,
sbyte * pString,
BOOL append
)
{
char * pInst;
#ifndef _WRS_CONFIG_LP64
int max;
int used;
unsigned int len;
#else
long max;
long used;
unsigned long len;
#endif
if ((NULL == pString) || (NULL == pInstance))
return wmError(ERROR_GENERAL_NO_DATA, "no data");
#ifndef _WRS_CONFIG_LP64
max = (int)wmBufferMaxGet(pInstance);
used = (int)wmBufferUsedGet(pInstance);
#else
max = (long)wmBufferMaxGet(pInstance);
used = (long)wmBufferUsedGet(pInstance);
#endif
pInst = wmBufferDataGet(pInstance);
if (NULL == pInst)
{
wmBufferUpdate(pInstance, NULL, 256, 0, FALSE);
#ifndef _WRS_CONFIG_LP64
max = (int)wmBufferMaxGet(pInstance);
#else
max = (long)wmBufferMaxGet(pInstance);
#endif
pInst = wmBufferDataGet(pInstance);
}
else
{
if (append)
pInst += used;
else
used = 0;
}
strcpy(pInst, pString); /* max !!! */
len = strlen(pString) + 1; /* count the terminator */
#ifndef _WRS_CONFIG_LP64
wmBufferUsedSet(pInstance, ((ubyte4)used + len));
#else
wmBufferUsedSet(pInstance, ((ubyte8)used + len));
#endif
return OK;
}
/**************************************************************************
*
* wmInstanceAppend - append one buffer onto another
*
*
* RETURNS: ERROR or OK
*
* NOMANUAL
*/
STATUS wmInstanceAppend
(
WM_INSTANCE_T pDestInst,
WM_INSTANCE_T pAddInst
)
{
#ifndef _WRS_CONFIG_LP64
/* ubyte4 destLen;*/
ubyte4 addLen;
/* ubyte4 total;*/
#else
/* ubyte8 destLen;*/
ubyte8 addLen;
/* ubyte8 total;*/
#endif
/*sbyte * pDest;*/
sbyte * pAdd;
if (NULL == pDestInst || NULL == pAddInst)
return wmError(ERROR_GENERAL_NO_DATA, "wmInstanceAppend: null arg(s)");
/*pDest = wmBufferDataGet(pDestInst);*/
pAdd = wmBufferDataGet(pAddInst);
/* total = wmBufferMaxGet(pDestInst);
destLen = wmBufferUsedGet(pDestInst);*/
addLen = wmBufferUsedGet(pAddInst);
/* wmBufferAppend will skip terminator in the Dest string instance buffer */
return wmBufferAppend(pDestInst, pAdd, addLen);
}
/**************************************************************************
*
* wmInstanceEqual - compare 2 insts
*
* RETURNS: TRUE if same
*
* NOMANUAL
*/
BOOL wmInstanceEqual
(
WM_INSTANCE_T orig,
WM_INSTANCE_T test
)
{
#ifndef _WRS_CONFIG_LP64
ubyte4 destLen;
ubyte4 addLen;
#else
ubyte8 destLen;
ubyte8 addLen;
#endif
sbyte * pDest;
sbyte * pAdd;
pDest = wmBufferDataGet(orig);
pAdd = wmBufferDataGet(test);
if (NULL == pDest || NULL == pAdd)
return FALSE;
destLen = wmBufferUsedGet(orig);
addLen = wmBufferUsedGet(test);
/* make sure there's enough space (fix later: just resize) */
if (addLen != destLen)
return FALSE;
return (0 == memcmp(pDest, pAdd, addLen));
}
/**************************************************************************
*
* wmInstanceCmp - compare 2 insts
*
* RETURNS:
*
* NOMANUAL
*/
int wmInstanceCmp
(
WM_INSTANCE_T orig,
WM_INSTANCE_T test
)
{
#ifndef _WRS_CONFIG_LP64
ubyte4 i;
ubyte4 origLen;
ubyte4 testLen;
#else
ubyte8 i;
ubyte8 origLen;
ubyte8 testLen;
#endif
ubyte * pOrig;
ubyte * pTest;
pOrig = wmBufferDataGet(orig);
pTest = wmBufferDataGet(test);
if (NULL == pTest || NULL == pOrig)
return 0;
origLen = wmBufferUsedGet(orig) - 1; /* skip terminators */
testLen = wmBufferUsedGet(test) - 1;
for (i = 0; (i < origLen) && (i < testLen); i++, pOrig++, pTest++)
{
if (*pOrig < *pTest)
return -1;
if (*pOrig > *pTest)
return 1;
}
/* so far they are the same */
if (origLen < testLen)
return -1;
if (origLen > testLen)
return 1;
return 0;
}
/**************************************************************************
*
* wmInstanceTruncate - truncate inst
*
*
* RETURNS: ERROR or OK
*
* NOMANUAL
*/
STATUS wmInstanceTruncate
(
WM_INSTANCE_T inst,
#ifndef _WRS_CONFIG_LP64
sbyte4 length /* in bytes */
#else
sbyte8 length /* in bytes */
#endif
)
{
sbyte * pData;
#ifndef _WRS_CONFIG_LP64
ubyte4 used;
ubyte4 max;
#else
ubyte8 used;
ubyte8 max;
#endif
pData = wmBufferDataGet (inst);
max = wmBufferMaxGet (inst);
used = wmBufferUsedGet (inst);
pData += length;
#ifndef _WRS_CONFIG_LP64
if (length > (sbyte4)used)
#else
if (length > (sbyte8)used)
#endif
return wmError(ERROR_GENERAL_ILLEGAL_VALUE, "wmInstanceTruncate: length too long");
/* nothing to do */
#ifndef _WRS_CONFIG_LP64
if (length == (sbyte4)used)
#else
if (length == (sbyte8)used)
#endif
return OK;
#ifndef _WRS_CONFIG_LP64
memset(pData, 0, (max - (ubyte4)length)); /* the zero's double as the string terminator */
wmBufferUsedSet(inst, (ubyte4)length);
#else
memset(pData, 0, (max - (ubyte8)length)); /* the zero's double as the string terminator */
wmBufferUsedSet(inst, (ubyte8)length);
#endif
return OK;
}
/**************************************************************************
*
* wmInstanceSuffix - create new buffer containing unique instance suffix
*
*
* RETURNS: buffer with suffix only
*
* NOMANUAL
*/
WM_INSTANCE_T wmInstanceSuffix
(
WM_INSTANCE_T pBaseInst,
WM_INSTANCE_T pFullInst
)
{
WM_INSTANCE_T pSuffix;
#ifndef _WRS_CONFIG_LP64
ubyte4 baseLen;
ubyte4 fullLen;
ubyte4 index;
#else
ubyte8 baseLen;
ubyte8 fullLen;
ubyte8 index;
#endif
sbyte * pBase;
sbyte * pFull;
if (NULL == pBaseInst || NULL == pFullInst)
return NULL;
pBase = wmBufferDataGet (pBaseInst);
pFull = wmBufferDataGet (pFullInst);
baseLen = wmBufferUsedGet (pBaseInst);
fullLen = wmBufferUsedGet (pFullInst);
if (baseLen >= fullLen)
return NULL;
/* Skip the zero terminator */
if (0 < baseLen)
baseLen--;
/* base should match beginning of full */
if (0 != baseLen) for (index = baseLen; index > 0; index --, pBase++, pFull++)
{
if (*pBase != *pFull)
return NULL;
}
/* only create suffix if it doesn't already exist */
fullLen -= baseLen;
pSuffix = wmBufferCreate(NULL, fullLen, pFull, wmBufferTypeGet(pFullInst), TRUE);
return pSuffix;
}
/**************************************************************************
*
* wmInstanceScalerSet - there is currently no definition for non-OID scalars
*
* RETURNS: OK
*
*
* NOMANUAL
*/
#if 0
void wmInstanceScalerSet
(
WM_INSTANCE_T inst
)
{
int zero = 0;
wmBufferAppend(inst, &zero, sizeof(zero));
}
/* return if scaler */
BOOL wmInstanceScaler
(
WM_INSTANCE_T inst
)
{
int * pData;
int size;
if (0 >= (size = wmBufferUsedGet(inst)))
return FALSE;
pData = wmBufferDataGet(inst);
pData += size;
return (*pData == 0);
}
#endif /* 0 */
/**************************************************************************
*
* wmInstanceStringGet - create ascii version of inst
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
STATUS wmInstanceStringGet
(
WM_INSTANCE_T inst,
sbyte * pString,
#ifndef _WRS_CONFIG_LP64
sbyte4 strLen
#else
sbyte8 strLen
#endif
)
{
int * pData;
#ifndef _WRS_CONFIG_LP64
sbyte4 instLen;
#else
sbyte8 instLen;
#endif
if (wmInstanceBad(inst))
return wmError(ERROR_GENERAL_INVALID, "wmInstanceStringGet: bad inst");
pData = wmBufferDataGet (inst);
#ifndef _WRS_CONFIG_LP64
instLen = (sbyte4)wmBufferUsedGet (inst);
#else
instLen = (sbyte8)wmBufferUsedGet (inst);
#endif
if (NULL == pData || 1 > instLen)
return wmError(ERROR_GENERAL_NO_DATA, "wmInstanceStringGet: no data");
if (strLen < instLen) /* string terminators are already included in these sizes */
return wmError(ERROR_GENERAL_NO_DATA, "wmInstanceStringGet: dest buffer too small");
strcpy(pString, (char *) pData);
return OK;
}
/**************************************************************************
*
* wmInstanceValid - does Instance contain valid data
*
*
* RETURNS:\is
*\i ERROR
*\i OK
*\ie
*
* NOMANUAL
*/
STATUS wmInstanceValid
(
WM_INSTANCE_T inst
)
{
if (wmInvalid(inst))
return wmError(ERROR_GENERAL_INVALID, "wmInstanceInvalid: bad Instance");
if (wmInvalid(wmBufferDataGet(inst)))
return wmError(ERROR_GENERAL_INVALID, "wmInstanceInvalid: bad data");
return OK;
}
/**************************************************************************
*
* wmBufferSuffix - copy unique portion of buffer
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
STATUS wmBufferInstSuffix
(
WM_BUFFER_T * pRoot, /* [in] root buffer */
WM_BUFFER_T * pFull, /* [in] complete buffer */
WM_BUFFER_T * pSuffix /* [in/out] portion complete root lacks */
)
{
sbyte * pRootData = NULL;
sbyte * pFullData = NULL;
#ifndef _WRS_CONFIG_LP64
ubyte4 rootLen;
ubyte4 fullLen;
#else
ubyte8 rootLen;
ubyte8 fullLen;
#endif
pRootData = wmBufferDataGet(pRoot);
pFullData = wmBufferDataGet(pFull);
if((NULL == pRootData)||(NULL == pFullData))
{
wmInstancePrint(pRoot, "root");
wmInstancePrint(pFull, "full");
return ERROR;
}
rootLen = wmBufferUsedGet(pRoot) - 1; /* don't count the zero terminator here */
fullLen = wmBufferUsedGet(pFull);
if (memcmp(pRootData, pFullData, rootLen) != 0)
{
wmInstancePrint(pRoot, "root");
wmInstancePrint(pFull, "full");
return ERROR;
}
return wmBufferUpdate (pSuffix, &pFullData[rootLen], fullLen - rootLen,
wmBufferTypeGet(pFull), TRUE);
}
/* eof wmInstanceLib.c */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,523 @@
/* wmLinkListLib.c - RCB linklist library */
/* Copyright 2001-2007 Wind River Systems, Inc. */
/*
modification history
--------------------
01d,15mar10,m_z VxWorks 64bit support (WIND00193649)
01c,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01b,11oct01,rws comments modified
01a,01aug01,pns written
*/
/*
DESCRIPTION
LinkListLib.c
INCLUDE FILES: rc2.h
*/
/* includes */
#include "wm.h"
/**************************************************************************
*
* wmLinkListMoveToEnd - move to end of linklist.
*
* RETURNS: Pointer to end of linklist.
*
*
* NOMANUAL
*/
static WM_LIST_T * wmLinkListMoveToEnd
(
WM_LIST_T * pFindEnd
)
{
if (NULL == pFindEnd)
return NULL;
while (NULL != pFindEnd->pNext)
pFindEnd = pFindEnd->pNext;
return pFindEnd;
}
/**************************************************************************
*
* wmLinkListAddObject - Add an object to a linklist.
*
* RETURNS:\is
*\i OK
*\i ERROR_GENERAL_NOT_FOUND
*\i SYS_ERROR_NO_MEMORY
*\ie
*
* NOMANUAL
*/
STATUS wmLinkListAddObject
(
WM_LIST_T * p_lstHead,
void * pData
)
{
WM_LIST_T *p_lstNewElement, *pFindEnd = p_lstHead;
if (NULL == p_lstHead)
return ERROR_GENERAL_NOT_FOUND;
if ((NULL == p_lstHead->pNext) && (NULL == p_lstHead->pObject))
{
p_lstHead->pObject = pData;
return OK;
}
p_lstNewElement = (WM_LIST_T *) wmMalloc (sizeof(WM_LIST_T));
if (NULL == p_lstNewElement)
return SYS_ERROR_NO_MEMORY;
p_lstNewElement->pObject = pData;
p_lstNewElement->pNext = NULL;
pFindEnd = wmLinkListMoveToEnd(pFindEnd);
pFindEnd->pNext = p_lstNewElement;
return OK;
} /* wmLinkListAddObject */
/**************************************************************************
*
* wmLinkListGetNextObject - Get the next object from a linklist.
*
* RETURNS: A pointer to the next object.
*
*
* NOMANUAL
*/
void * wmLinkListGetNextObject
(
WM_LIST_T ** p_lstSpot
)
{
void * pTemp;
if (NULL == p_lstSpot)
return NULL;
if (NULL == (*p_lstSpot))
return NULL;
pTemp = (*p_lstSpot)->pObject;
*p_lstSpot = (*p_lstSpot)->pNext;
return pTemp;
}
/**************************************************************************
*
* wmLinkListGetFirstObject - Get the first object from a linklist.
*
* RETURNS: A pointer to the first object.
*
*
* NOMANUAL
*/
void * wmLinkListGetFirstObject
(
WM_LIST_T * plstHead
)
{
if (NULL == plstHead)
return NULL;
return plstHead->pObject;
}
/**************************************************************************
*
* wmLinkListFindObject - Find an object with value <pValue> in a linklist.
*
* RETURNS: A pointer to the object.
*
*
* NOMANUAL
*/
void * wmLinkListFindObject
(
WM_LIST_T * p_lstHead,
void * pValue,
BOOL (*fComparisonHandler)(void *, void *)
)
{
void *pObject;
if ((NULL == p_lstHead) || (NULL == fComparisonHandler))
return NULL;
while (NULL != (pObject = wmLinkListGetNextObject(&p_lstHead)))
{
if (TRUE == fComparisonHandler(pValue, pObject))
return pObject;
}
return NULL;
}
/**************************************************************************
*
* wmLinkListSize - Get the length of a linklist.
*
* RETURNS: The length <ListLen> of the linklist.
*
*
* NOMANUAL
*/
Length wmLinkListSize
(
WM_LIST_T * p_lstHead
)
{
Length ListLen = 0;
if (NULL == p_lstHead)
return ListLen;
if (NULL != p_lstHead->pObject)
ListLen++;
while (NULL != p_lstHead->pNext)
{
p_lstHead = p_lstHead->pNext;
ListLen++;
}
return ListLen;
}
/**************************************************************************
*
* wmLinkListRemoveObject - Remove an object from a linklist.
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
STATUS wmLinkListRemoveObject
(
WM_LIST_T * p_lstHead,
BOOL (*funcComparisonHandler)(void *)
)
{
WM_LIST_T *p_lstPrevious, *p_lstCurrent;
if ((NULL == p_lstHead) || (NULL == p_lstHead->pObject) ||
(NULL == funcComparisonHandler))
{
return ERROR_GENERAL_NOT_FOUND;
}
if (funcComparisonHandler(p_lstHead->pObject))
{
WM_LIST_T *p_lstTemp;
wmFree(p_lstHead->pObject);
if (NULL == p_lstHead->pNext)
{
p_lstHead->pObject = NULL;
return OK;
}
p_lstHead->pObject = p_lstHead->pNext->pObject;
p_lstTemp = p_lstHead->pNext;
p_lstHead->pNext = p_lstHead->pNext->pNext;
wmFree(p_lstTemp);
return OK;
}
p_lstPrevious = p_lstHead;
p_lstCurrent = p_lstPrevious->pNext;
while (NULL != p_lstCurrent)
{
if (funcComparisonHandler(p_lstCurrent->pObject))
{
wmFree(p_lstCurrent->pObject);
p_lstPrevious->pNext = p_lstCurrent->pNext;
wmFree(p_lstCurrent);
return OK;
}
p_lstPrevious = p_lstCurrent;
p_lstCurrent = p_lstCurrent->pNext;
}
return ERROR_GENERAL_NOT_FOUND;
} /* wmLinkListRemoveObject */
/**************************************************************************
*
* wmLinkListSelectiveRemoveObject - Remove an object from a linklist.
*
* Remove an object with parameter <pRemoveParam> from a linklist.
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
STATUS wmLinkListSelectiveRemoveObject
(
WM_LIST_T * p_lstHead,
void * pRemoveParam,
BOOL (*funcComparisonHandler)(void *, void *))
{
WM_LIST_T * p_lstPrevious;
WM_LIST_T * p_lstCurrent;
if ((NULL == p_lstHead) || (NULL == p_lstHead->pObject) ||
(NULL == funcComparisonHandler))
{
return ERROR_GENERAL_NOT_FOUND;
}
if (funcComparisonHandler(pRemoveParam, p_lstHead->pObject))
{
WM_LIST_T *p_lstTemp;
wmFree(p_lstHead->pObject);
if (NULL == p_lstHead->pNext)
{
p_lstHead->pObject = NULL;
return OK;
}
p_lstHead->pObject = p_lstHead->pNext->pObject;
p_lstTemp = p_lstHead->pNext;
p_lstHead->pNext = p_lstHead->pNext->pNext;
wmFree(p_lstTemp);
return OK;
}
p_lstPrevious = p_lstHead;
p_lstCurrent = p_lstPrevious->pNext;
while (NULL != p_lstCurrent)
{
if (funcComparisonHandler(pRemoveParam, p_lstCurrent->pObject))
{
wmFree(p_lstCurrent->pObject);
p_lstPrevious->pNext = p_lstCurrent->pNext;
wmFree(p_lstCurrent);
return OK;
}
p_lstPrevious = p_lstCurrent;
p_lstCurrent = p_lstCurrent->pNext;
}
return ERROR_GENERAL_NOT_FOUND;
} /* wmLinkListSelectiveRemoveObject */
/**************************************************************************
*
* wmLinkListTraverse - Traverse a linklist.
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
STATUS wmLinkListTraverse
(
WM_LIST_T * p_lstHead,
void (*funcProcessObject)(void *)
)
{
WM_LIST_T * p_lstSpot = p_lstHead;
void * pObject;
if ((NULL == p_lstHead) || (NULL == funcProcessObject))
return ERROR_GENERAL_NOT_FOUND;
while (NULL != (pObject = wmLinkListGetNextObject(&p_lstSpot)))
funcProcessObject(pObject);
return OK;
}
/**************************************************************************
*
* wmLinkListConstruct - Create a linklist.
*
*
* RETURNS: A pointer to the new linklist.
*
*
* NOMANUAL
*/
WM_LIST_T * wmLinkListConstruct
(
void
)
{
WM_LIST_T * pList;
pList = (WM_LIST_T *) wmMalloc (sizeof(WM_LIST_T));
if (NULL == pList)
return NULL;
pList->pObject = NULL;
pList->pNext = NULL;
return pList;
}
/**************************************************************************
*
* wmLinkListParamDestruct - wmLinkListParamDestruct
*
*
* RETURNS: n/a
*
*
* NOMANUAL
*/
void wmLinkListParamDestruct
(
WM_LIST_T ** p_lstToDelete,
void (*funcObject_Destruct)(void *, void *),
void * second_param
)
{
WM_LIST_T * p_lstCurrent, *p_lstNext;
if ((NULL == p_lstToDelete) || (NULL == funcObject_Destruct))
return;
p_lstCurrent = *(p_lstToDelete);
while (NULL != p_lstCurrent)
{
if (NULL != p_lstCurrent->pObject)
funcObject_Destruct(p_lstCurrent->pObject, second_param);
p_lstNext = p_lstCurrent->pNext;
wmFree(p_lstCurrent);
p_lstCurrent = p_lstNext;
}
*p_lstToDelete = NULL;
}
/**************************************************************************
*
* wmLinkListDestruct - Destroy a linklist.
*
*
* RETURNS: n/a
*
*
* NOMANUAL
*/
void wmLinkListDestruct
(
WM_LIST_T ** p_lstToDelete,
void (*funcObject_Destruct)(void *)
)
{
WM_LIST_T *p_lstCurrent, *p_lstNext;
if ((NULL == p_lstToDelete) || (NULL == *p_lstToDelete) || (NULL == funcObject_Destruct))
return;
p_lstCurrent = *(p_lstToDelete);
while (NULL != p_lstCurrent)
{
if (NULL != p_lstCurrent->pObject)
funcObject_Destruct(p_lstCurrent->pObject);
p_lstNext = p_lstCurrent->pNext;
wmFree(p_lstCurrent);
p_lstCurrent = p_lstNext;
}
*p_lstToDelete = NULL;
}
@@ -0,0 +1,343 @@
/* wmLogLib.c - WindManage logging library */
/* Copyright (c) 2001-2007 2010 2012 Wind River Systems, Inc. */
/*
modification history
--------------------
01g,31jan12,r_w fix defect WIND00326056 to eliminate compile warning
01f,28jul10,m_z eliminate compile warning
01e,27jul10,m_z eliminate compile warning
01d,29apr10,m_z eliminate compile warining
01c,15mar10,m_z VxWorks 64bit support (WIND00193649)
01b,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01a,01aug01,pns written
02a,07dec01,pns renamed, updated
*/
/*
DESCRIPTION
This module implements logging to file or syslog servers
INCLUDE FILES: wm2.h 'wmb.h'
*/
/* includes */
#include "wm.h"
#include <string.h>
typedef struct LOG_INFO_S
{
ubyte4 flags;
ubyte4 syslog_host;
OS_SOCKET_T sock;
FILE * pFile;
} LOG_INFO_T, * LOG_PTR_T;
LOCAL LOG_INFO_T systemLog;
LOCAL LOG_ID_T log = &systemLog;
#define wmLogBad(x) (NULL == x)
#define wmLogGet(x) x = &mLog
#define wmLogTypeGet(x) ((LOG_PTR_T) x)->type
#define wmLogFileGet(x) ((LOG_PTR_T) x)->pFile
#define wmLogSockGet(x) ((LOG_PTR_T) x)->sock
#define wmLogHostGet(x) ((LOG_PTR_T) x)->syslog_host
#define wmLogTypeSet(x,y) ((LOG_PTR_T) x)->type = y
#define wmLogFileSet(x,y) ((LOG_PTR_T) x)->pFile = y
#define wmLogSockSet(x,y) ((LOG_PTR_T) x)->sock = y
#define wmLogHostSet(x,y) ((LOG_PTR_T) x)->syslog_host = y
#define wmLogEnabled(x,y) FLAG_SET(((LOG_PTR_T) x), y)
#define wmLogEnable(x,y) SET_FLAG(((LOG_PTR_T) x), y)
#define wmLogDisable(x,y) CLEAR_FLAG(((LOG_PTR_T) x), y)
#define LOG_FLAG_THREAD 0x01
#define LOG_FLAG_STDERR 0x02
#define LOG_FLAG_SYSLOG 0x04
#define LOG_FLAG_FILE 0x08
void wmLogThreads
(
BOOL enabled
)
{
if (enabled)
wmLogEnable (log, LOG_FLAG_THREAD);
else
wmLogDisable (log, LOG_FLAG_THREAD);
}
BOOL wmLogThreadsGet
(
void
)
{
return wmLogEnabled(log, LOG_FLAG_THREAD);
}
void wmLogStderr
(
BOOL enabled
)
{
if (enabled)
wmLogEnable (log, LOG_FLAG_STDERR);
else
wmLogDisable (log, LOG_FLAG_STDERR);
}
BOOL wmLogStderrGet
(
void
)
{
return wmLogEnabled(log, LOG_FLAG_STDERR);
}
void wmLogReset
(
void
)
{
memset(log, 0, sizeof(LOG_INFO_T));
}
/**************************************************************************
*
* wmLogSyslogInit - initalize syslog to go to <pHost>
*
* RETURNS:
*
* NOMANUAL
*/
LOCAL STATUS wmLogSyslogInit
(
LOG_ID_T slog,
char * pHost
)
{
wmnetUdpSocketCreate(&wmLogSockGet(slog));
wmnetAddressResolve(pHost, (ubyte4 *)&wmLogHostGet(slog));
return OK;
}
/**************************************************************************
*
* wmLogInit - initalize logging to use file <pFileName>
*
* RETURNS:
* \is
*
* \i NULL
* file doesn't exist
* \ie
*
* NOMANUAL
*/
STATUS wmLogOpen
(
LOG_TYPE_T type,
char * pName
)
{
FILE * pFile;
wmLogReset();
switch(type)
{
case LOG_TYPE_FILE:
if (NULL == pName)
return wmError (ERROR, "wmLogInit: name is null");
if (NULL == (pFile = fopen(pName, "w")))
return wmError (ERROR, "wmLogInit: unable to open file");
wmLogEnable (log, LOG_FLAG_FILE);
wmLogFileSet (log, pFile);
break;
case LOG_TYPE_SYSLOG:
if (NULL == pName)
return wmError (ERROR, "wmLogInit: name is null");
wmLogEnable (log, LOG_FLAG_SYSLOG);
wmLogSyslogInit (log, pName);
break;
case LOG_TYPE_STDERR:
wmLogEnable (log, LOG_FLAG_STDERR);
break;
default:
return wmError (ERROR, "wmLogInit");
}
return OK;
}
/**************************************************************************
*
* wmLogSyslog - send <pMsg> to a remote syslog server
*
* RETURNS: N/A
*
* NOMANUAL
*/
void wmLogSyslog
(
char * pMsg
)
{
if (NULL == pMsg)
pMsg = "(no message)";
wmnetUdpSendTo(wmLogSockGet(log), wmLogHostGet(log), 514, pMsg, strlen(pMsg));
}
/**************************************************************************
*
* wmLogWrite - write <pText> to log
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
void wmLogWrite
(
char * pText
)
{
if (NULL == pText)
return;
if (wmLogEnabled(log, LOG_FLAG_FILE))
{
fprintf (wmLogFileGet (log), "%s\r\n", pText);
fflush (wmLogFileGet (log));
}
if (wmLogEnabled(log, LOG_FLAG_SYSLOG))
wmLogSyslog (pText);
}
/**************************************************************************
*
* wmLogClose - release resouwmes used for logging
*
* RETURNS: N/A
*
*
* NOMANUAL
*/
void wmLogClose
(
void
)
{
if (wmLogEnabled(log, LOG_FLAG_FILE))
fclose (wmLogFileGet (log));
if (wmLogEnabled(log, LOG_FLAG_SYSLOG))
wmnetSocketClose (wmLogSockGet (log));
}
/**************************************************************************
*
* wmLogPrintf - send formatted string <pMsg> to log
*
* RETURNS: N/A
*
* NOMANUAL
*/
void wmLogPrintf
(
char * pMsg,
...
)
{
char buffer[256];
char * pBuf;
va_list vaList;
if (NULL == pMsg)
return;
if (wmLogEnabled(log, LOG_FLAG_STDERR) && wmLogEnabled(log, LOG_FLAG_THREAD))
#ifndef _WRS_CONFIG_LP64
fprintf(stderr, "Thread (0x%x) : ", (int)taskIdSelf());
#else
fprintf(stderr, "Thread (0x%p) : ", (void*)taskIdSelf());
#endif
va_start (vaList, pMsg);
if (wmLogEnabled(log, LOG_FLAG_SYSLOG))
{
pBuf = buffer;
if (wmLogEnabled(log, LOG_FLAG_THREAD))
{
#ifndef _WRS_CONFIG_LP64
sprintf(pBuf, "TID: %-5x ", (int)taskIdSelf());
#else
sprintf(pBuf, "TID: %-5p ", (void *) (taskIdSelf()));
#endif
wmLogSyslog(buffer);
pBuf += strlen(buffer);
}
vsprintf(pBuf, pMsg, vaList);
wmLogSyslog(pBuf);
}
if (wmLogEnabled(log, LOG_FLAG_STDERR))
vfprintf(stderr, pMsg, vaList);
if (wmLogEnabled(log, LOG_FLAG_FILE))
vfprintf (wmLogFileGet (log), pMsg, vaList);
va_end (vaList);
}
/**************************************************************************
*
* wmLogSyslogSend - send <pMsg> to a syslog server <pHost>
*
* RETURNS: N/A
*
* NOMANUAL
*/
void wmLogSyslogSend
(
char * pHost,
char * pMsg
)
{
wmLogReset();
wmLogOpen (LOG_TYPE_SYSLOG, pHost);
wmLogSyslog (pMsg);
wmLogClose ();
}
@@ -0,0 +1,416 @@
/* wmMD5.c - MD5 Interface Routines */
/* Copyright(c) 2005-2007, 2010, 2012 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
--------------------
01e,18apr12,r_w remove dependence of retrofit.h
Requirement: WIND00299859
01d,15mar10,m_z VxWorks 64bit support (WIND00193649)
01c,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01b,25apr05,??? Update JS Auth #define ordering
01a,17sep04,dkg ported from RC3.3 to WM4.4 for JavaScript Authentication
*/
/*-----------------------------------------------------------------------*/
/*
**********************************************************************
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
** **
** License to copy and use this software is granted provided that **
** it is identified as the "RSA Data Security, Inc. MD5 Message **
** Digest Algorithm" in all material mentioning or referencing this **
** software or this function. **
** **
** License is also granted to make and use derivative works **
** provided that such works are identified as "derived from the RSA **
** Data Security, Inc. MD5 Message Digest Algorithm" in all **
** material mentioning or referencing the derived work. **
** **
** RSA Data Security, Inc. makes no representations concerning **
** either the merchantability of this software or the suitability **
** of this software for any particular purpose. It is provided "as **
** is" without express or implied warranty of any kind. **
** **
** These notices must be retained in any copies of any part of this **
** documentation and/or software. **
**********************************************************************
*/
/* See if Digest is enabled globally */
#include "wm_options.h"
#ifdef __JAVASCRIPT_DIGEST_ENABLED__
#include "httpLib.h"
#include "wmMD5.h"
/* forward references */
extern void wmMD5Init (MD5_CTX *mdContext);
extern void wmMD5Update(MD5_CTX *mdContext, ubyte *inBuf, ubyte4 inLen);
extern void wmMD5Final (MD5_CTX *mdContext);
static void wmTransform (ubyte4 *buf, ubyte4 *in);
static ubyte PADDING[64] =
{
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/*-----------------------------------------------------------------------*/
/* F, G and H are basic MD5 functions: selection, majority, parity */
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits */
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
/* Rotation is separate from addition to prevent recomputation */
#define FF(a, b, c, d, x, s, ac) \
{ (a) += F ((b), (c), (d)) + (x) + (ubyte4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) \
{ (a) += G ((b), (c), (d)) + (x) + (ubyte4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) \
{ (a) += H ((b), (c), (d)) + (x) + (ubyte4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) \
{ (a) += I ((b), (c), (d)) + (x) + (ubyte4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
static OS_SEM_T MD5_MUTEX;
/*-----------------------------------------------------------------------*/
extern STATUS wmMD5INIT(void)
{
return wmosSemCreate(&MD5_MUTEX, 1, 0);
}
/*-----------------------------------------------------------------------*/
static STATUS wmMD5MutexWait()
{
return wmosSemTake(MD5_MUTEX, WAIT_FOREVER_K);
}
/*-----------------------------------------------------------------------*/
static STATUS wmMD5MutexRelease()
{
return wmosSemGive(MD5_MUTEX);
}
/*-----------------------------------------------------------------------*/
extern void wmMD5Init(MD5_CTX *mdContext)
{
mdContext->i[0] = mdContext->i[1] = (ubyte4)0;
/* Load magic initialization constants. */
mdContext->buf[0] = (ubyte4)0x67452301;
mdContext->buf[1] = (ubyte4)0xefcdab89;
mdContext->buf[2] = (ubyte4)0x98badcfe;
mdContext->buf[3] = (ubyte4)0x10325476;
}
/*-----------------------------------------------------------------------*/
extern void wmMD5Update(MD5_CTX *mdContext, ubyte *inBuf, ubyte4 inLen)
{
ubyte4 in[16];
sbyte4 mdi;
ubyte4 i, ii;
/* compute number of bytes mod 64 */
mdi = (sbyte4)((mdContext->i[0] >> 3) & 0x3F);
/* update number of bits */
if ((mdContext->i[0] + ((ubyte4)inLen << 3)) < mdContext->i[0])
mdContext->i[1]++;
mdContext->i[0] += ((ubyte4)inLen << 3);
mdContext->i[1] += ((ubyte4)inLen >> 29);
while (inLen--)
{
/* add new character to buffer, increment mdi */
mdContext->in[mdi++] = *inBuf++;
/* transform if necessary */
if (mdi == 0x40)
{
for (i = 0, ii = 0; i < 16; i++, ii += 4)
in[i] = (((ubyte4)mdContext->in[ii+3]) << 24) | (((ubyte4)mdContext->in[ii+2]) << 16) |
(((ubyte4)mdContext->in[ii+1]) << 8) | ((ubyte4)mdContext->in[ii]);
wmTransform (mdContext->buf, in);
mdi = 0;
}
}
} /* wmMD5Update */
/*-----------------------------------------------------------------------*/
extern void wmMD5Final(MD5_CTX *mdContext)
{
ubyte4 in[16];
sbyte4 mdi;
ubyte4 i, ii;
ubyte4 padLen;
/* save number of bits */
in[14] = mdContext->i[0];
in[15] = mdContext->i[1];
/* compute number of bytes mod 64 */
mdi = (sbyte4)((mdContext->i[0] >> 3) & 0x3F);
/* pad out to 56 mod 64 */
padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
wmMD5Update(mdContext, PADDING, padLen);
/* append length in bits and transform */
for (i = 0, ii = 0; i < 14; i++, ii += 4)
in[i] = (((ubyte4)mdContext->in[ii+3]) << 24) | (((ubyte4)mdContext->in[ii+2]) << 16) |
(((ubyte4)mdContext->in[ii+1]) << 8) | ((ubyte4)mdContext->in[ii]);
wmTransform (mdContext->buf, in);
/* store buffer in digest */
for (i = 0, ii = 0; i < 4; i++, ii += 4)
{
mdContext->digest[ii] = (ubyte) (mdContext->buf[i] & 0xFF);
mdContext->digest[ii+1] = (ubyte)((mdContext->buf[i] >> 8) & 0xFF);
mdContext->digest[ii+2] = (ubyte)((mdContext->buf[i] >> 16) & 0xFF);
mdContext->digest[ii+3] = (ubyte)((mdContext->buf[i] >> 24) & 0xFF);
}
} /* wmMD5Final */
/*-----------------------------------------------------------------------*/
extern STATUS wmMD5MessageCompare(sbyte *pFirstMesg, sbyte *pSecondMesg)
{
if ((NULL == pFirstMesg) || (NULL == pSecondMesg))
return kMD5_NoMatch;
return (0 == MEMCMP(pFirstMesg, pSecondMesg, kDigestMesgBufSize)) ? kMD5_Match : kMD5_NoMatch;
}
/*-----------------------------------------------------------------------*/
extern STATUS wmMD5MessageDigest(sbyte *pInputMessage, Length MesgLen, sbyte *pRetDigestMesg)
{
MD5_CTX* pMdContext;
/* JavaScript digest style. JAB */
if (NULL == pRetDigestMesg)
return ERROR_GENERAL_NO_DATA;
MEMSET(pRetDigestMesg, 0x00, kDigestMesgBufSize);
if (NULL == pInputMessage)
return ERROR_GENERAL_NO_DATA;
if (OK != wmMD5MutexWait())
return SYS_ERROR_MUTEX_WAIT;
if (NULL != (pMdContext = wmMalloc(sizeof(MD5_CTX))))
{
Length k;
/* Computes the message digest for the input string pInputMessage. */
wmMD5Init(pMdContext);
for (k = 0; k < MesgLen; k++)
{
wmMD5Update(pMdContext, (ubyte *) pInputMessage, 1);
pInputMessage++;
}
wmMD5Final(pMdContext);
}
else
{
wmMD5MutexRelease();
return ERROR_MEMMGR_NO_MEMORY;
}
if (OK != wmMD5MutexRelease())
{
wmFree(pMdContext);
return SYS_ERROR_MUTEX_RELEASE;
}
MEMCPY(pRetDigestMesg, pMdContext->digest, kDigestMesgBufSize);
wmFree(pMdContext);
return OK;
} /* wmMD5MessageDigest */
/*-----------------------------------------------------------------------*/
static void wmTransform(ubyte4 *buf, ubyte4 *in)
{
ubyte4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
/* Basic MD5 step. Transform buf based on in. */
/* Round 1 */
#define S11 7
#define S12 12
#define S13 17
#define S14 22
FF ( a, b, c, d, in[ 0], S11, 3614090360U); /* 1 */
FF ( d, a, b, c, in[ 1], S12, 3905402710U); /* 2 */
FF ( c, d, a, b, in[ 2], S13, 606105819U); /* 3 */
FF ( b, c, d, a, in[ 3], S14, 3250441966U); /* 4 */
FF ( a, b, c, d, in[ 4], S11, 4118548399U); /* 5 */
FF ( d, a, b, c, in[ 5], S12, 1200080426U); /* 6 */
FF ( c, d, a, b, in[ 6], S13, 2821735955U); /* 7 */
FF ( b, c, d, a, in[ 7], S14, 4249261313U); /* 8 */
FF ( a, b, c, d, in[ 8], S11, 1770035416U); /* 9 */
FF ( d, a, b, c, in[ 9], S12, 2336552879U); /* 10 */
FF ( c, d, a, b, in[10], S13, 4294925233U); /* 11 */
FF ( b, c, d, a, in[11], S14, 2304563134U); /* 12 */
FF ( a, b, c, d, in[12], S11, 1804603682U); /* 13 */
FF ( d, a, b, c, in[13], S12, 4254626195U); /* 14 */
FF ( c, d, a, b, in[14], S13, 2792965006U); /* 15 */
FF ( b, c, d, a, in[15], S14, 1236535329U); /* 16 */
/* Round 2 */
#define S21 5
#define S22 9
#define S23 14
#define S24 20
GG ( a, b, c, d, in[ 1], S21, 4129170786U); /* 17 */
GG ( d, a, b, c, in[ 6], S22, 3225465664U); /* 18 */
GG ( c, d, a, b, in[11], S23, 643717713U); /* 19 */
GG ( b, c, d, a, in[ 0], S24, 3921069994U); /* 20 */
GG ( a, b, c, d, in[ 5], S21, 3593408605U); /* 21 */
GG ( d, a, b, c, in[10], S22, 38016083U); /* 22 */
GG ( c, d, a, b, in[15], S23, 3634488961U); /* 23 */
GG ( b, c, d, a, in[ 4], S24, 3889429448U); /* 24 */
GG ( a, b, c, d, in[ 9], S21, 568446438U); /* 25 */
GG ( d, a, b, c, in[14], S22, 3275163606U); /* 26 */
GG ( c, d, a, b, in[ 3], S23, 4107603335U); /* 27 */
GG ( b, c, d, a, in[ 8], S24, 1163531501U); /* 28 */
GG ( a, b, c, d, in[13], S21, 2850285829U); /* 29 */
GG ( d, a, b, c, in[ 2], S22, 4243563512U); /* 30 */
GG ( c, d, a, b, in[ 7], S23, 1735328473U); /* 31 */
GG ( b, c, d, a, in[12], S24, 2368359562U); /* 32 */
/* Round 3 */
#define S31 4
#define S32 11
#define S33 16
#define S34 23
HH ( a, b, c, d, in[ 5], S31, 4294588738U); /* 33 */
HH ( d, a, b, c, in[ 8], S32, 2272392833U); /* 34 */
HH ( c, d, a, b, in[11], S33, 1839030562U); /* 35 */
HH ( b, c, d, a, in[14], S34, 4259657740U); /* 36 */
HH ( a, b, c, d, in[ 1], S31, 2763975236U); /* 37 */
HH ( d, a, b, c, in[ 4], S32, 1272893353U); /* 38 */
HH ( c, d, a, b, in[ 7], S33, 4139469664U); /* 39 */
HH ( b, c, d, a, in[10], S34, 3200236656U); /* 40 */
HH ( a, b, c, d, in[13], S31, 681279174U); /* 41 */
HH ( d, a, b, c, in[ 0], S32, 3936430074U); /* 42 */
HH ( c, d, a, b, in[ 3], S33, 3572445317U); /* 43 */
HH ( b, c, d, a, in[ 6], S34, 76029189U); /* 44 */
HH ( a, b, c, d, in[ 9], S31, 3654602809U); /* 45 */
HH ( d, a, b, c, in[12], S32, 3873151461U); /* 46 */
HH ( c, d, a, b, in[15], S33, 530742520U); /* 47 */
HH ( b, c, d, a, in[ 2], S34, 3299628645U); /* 48 */
/* Round 4 */
#define S41 6
#define S42 10
#define S43 15
#define S44 21
II ( a, b, c, d, in[ 0], S41, 4096336452U); /* 49 */
II ( d, a, b, c, in[ 7], S42, 1126891415U); /* 50 */
II ( c, d, a, b, in[14], S43, 2878612391U); /* 51 */
II ( b, c, d, a, in[ 5], S44, 4237533241U); /* 52 */
II ( a, b, c, d, in[12], S41, 1700485571U); /* 53 */
II ( d, a, b, c, in[ 3], S42, 2399980690U); /* 54 */
II ( c, d, a, b, in[10], S43, 4293915773U); /* 55 */
II ( b, c, d, a, in[ 1], S44, 2240044497U); /* 56 */
II ( a, b, c, d, in[ 8], S41, 1873313359U); /* 57 */
II ( d, a, b, c, in[15], S42, 4264355552U); /* 58 */
II ( c, d, a, b, in[ 6], S43, 2734768916U); /* 59 */
II ( b, c, d, a, in[13], S44, 1309151649U); /* 60 */
II ( a, b, c, d, in[ 4], S41, 4149444226U); /* 61 */
II ( d, a, b, c, in[11], S42, 3174756917U); /* 62 */
II ( c, d, a, b, in[ 2], S43, 718787259U); /* 63 */
II ( b, c, d, a, in[ 9], S44, 3951481745U); /* 64 */
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
} /* wmTransform */
#endif /*__JAVASCRIPT_DIGEST_ENABLED__*/
@@ -0,0 +1,611 @@
/* wmMemBlockLib.c - WindManage backplane data pool management. */
/* Copyright 2001-2007 Wind River Systems, Inc. */
/*
modification history
--------------------
01g,28apr10,m-z eliminate compile warning
01f,15mar10,m_z VxWorks 64bit support (WIND00193649)
01d,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01c,17sep03,jws Fix compiler warnings, SPR 90282
01a,01aug01,pns written
01b,11oct01,rws comments modified
*/
/*
DESCRIPTION
WindManage Backplane data pool management.
*/
/*
INCLUDE FILES: wm.h wmb.h
*/
#include "wrn/wm/common/wm.h"
#include "wrn/wm/backplane/wmb.h"
#undef MEM_ALLOC
#undef MEM_FREE
#define MEM_ALLOC(pool, size) (NULL == pool ? wmMalloc(size) : wmPoolAlloc(pool, size))
#define MEM_FREE(pool, data) if (NULL == pool) wmFree(data); else wmPoolFree(pool, data)
#ifndef __NO_MAGIC__
#define MEM_HEAD 0xbbbbbbbb
#define MEM_TAIL 0xcccccccc
#endif
BOOL wmMemBlockOkay
(
WM_BLOCK_T * pBlock,
void * pData
);
/**************************************************************************
*
* setBit - set state of bit in bitfield.
*
* RETURNS: NA
*
*/
LOCAL void setBit
(
ubyte4 * pBits, /* bit flags in words */
#ifndef _WRS_CONFIG_LP64
ubyte4 offset, /* offset into data */
#else
ubyte8 offset, /* offset into data */
#endif
BOOL on
)
{
#ifndef _WRS_CONFIG_LP64
ubyte4 major;
ubyte4 minor;
#else
ubyte8 major;
ubyte8 minor;
#endif
ubyte4 mask;
major = offset / WORD_BITS_K;
minor = offset % WORD_BITS_K;
mask = (ubyte4)(1 << minor);
if (on)
pBits[major] |= mask;
else
pBits[major] &= ~mask;
}
/**************************************************************************
*
* firstBit - find free bit in bitfield.
*
* Destructive get - sets bit found
*
* RETURNS: integer count of bits until encountering first enabled bit
*
*
* NOMANUAL
*/
#ifndef _WRS_CONFIG_LP64
LOCAL sbyte4 firstBit
#else
LOCAL sbyte8 firstBit
#endif
(
ubyte4 * pBits, /* bitfield */
#ifndef _WRS_CONFIG_LP64
ubyte4 max /* bitfield bit count */
#else
ubyte8 max /* bitfield bit count */
#endif
)
{
ubyte4 mask;
#ifndef _WRS_CONFIG_LP64
ubyte4 index;
ubyte4 loop;
#else
ubyte8 index;
ubyte8 loop;
#endif
/* counting by words */
max /= WORD_BITS_K;
for (index = 0; index < max; index++, pBits++)
{
if (0xffffffff == *pBits)
continue;
mask = 1;
for (loop = 0; loop < WORD_BITS_K; loop++ )
{
if (0 == (mask & *pBits))
{
/* set bit to indicate use */
*pBits |= mask;
#ifndef _WRS_CONFIG_LP64
return (sbyte4)((index * WORD_BITS_K) + loop);
#else
return (sbyte8)((index * WORD_BITS_K) + loop);
#endif
}
mask = mask << 1;
}
}
return -1;
}
/**************************************************************************
*
* wmMemBlockCreate - Create a new data pool.
*
* This routine creates a new data pool.
*
* RETURNS: A pointer to the new data pool <pBlock>.
*
*
* NOMANUAL
*/
WM_BLOCK_T * wmMemBlockCreate
(
void * memID,
WM_BLOCK_T * pPrior, /* link to prior block */
#ifndef _WRS_CONFIG_LP64
int elements, /* number of elements in block */
int size /* size of each element */
#else
long elements, /* number of elements in block */
long size /* size of each element */
#endif
)
{
WM_BLOCK_T * pBlock;
int * pBits;
void * pData;
unsigned long adjust;
unsigned long bytes;
unsigned long total;
pBlock = (WM_BLOCK_T *) MEM_ALLOC(memID, sizeof(WM_BLOCK_T));
if (NULL == pBlock)
return NULL;
/* adjust size to multiple of sizeof int */
adjust = elements % WORD_BITS_K;
if (0 < adjust)
elements += (long)(WORD_BITS_K - adjust);
/* how many bits to keep track of elements */
bytes = (unsigned long)(elements / 8);
/* now actual size of all data needed */
#ifndef __NO_MAGIC__
/*
* only head needs adjusting for head and tail,
* all other blocks will inherit adjusted size
*/
if (NULL == pPrior)
size += (long)(2 * sizeof(ubyte4));
#endif
total = (unsigned long)(elements * size);
if (NULL == (pData = MEM_ALLOC(memID, total)))
{
MEM_FREE(memID, pBlock);
return NULL;
}
if (NULL == (pBits = MEM_ALLOC(memID, bytes + 1)))
{
MEM_FREE(memID, pData);
MEM_FREE(memID, pBlock);
return NULL;
}
memset(pBits, 0, bytes);
while (NULL != pPrior)
{
if (NULL == pPrior->pNext)
break;
pPrior = pPrior->pNext;
}
if (NULL != pPrior)
pPrior->pNext = pBlock;
wmMemBlockBless(pBlock);
pBlock->memID = memID;
pBlock->pData = pData;
pBlock->free = pBits;
pBlock->max = elements;
pBlock->size = size;
pBlock->used = 0;
pBlock->pNext = NULL;
return pBlock;
}
/**************************************************************************
*
* wmMemBlockExtend - append a similar memory block.
*
* This routine creates a new data pool.
*
* RETURNS: A pointer to the new data pool <pBlock>.
*
*
* NOMANUAL
*/
LOCAL WM_BLOCK_T * wmMemBlockExtend
(
WM_BLOCK_T * pBlock /* prior block */
)
{
return wmMemBlockCreate(pBlock->memID, pBlock, pBlock->max, pBlock->size);
}
/**************************************************************************
*
* wmMemBlockDestroy - free a data pool.
*
* RETURNS: N/A.
*
*
* NOMANUAL
*/
void wmMemBlockDestroy
(
WM_BLOCK_T * pBlock /* block(s) to free */
)
{
WM_BLOCK_T * pNext;
while (NULL != pBlock)
{
pNext = pBlock->pNext;
MEM_FREE(pBlock->memID, pBlock->free);
MEM_FREE(pBlock->memID, pBlock->pData);
MEM_FREE(pBlock->memID, pBlock);
pBlock = pNext;
}
}
#if 0
struct WM_BLOCK_T * pNext;
void * memID; /* mem pool id */
int used; /* elements in use */
int top; /* highest used element */
int max; /* size of pool */
int size; /* element size */
void * free; /* bitflags if free */
void * pData; /* data */
#endif
/**************************************************************************
*
* wmMemBlockEntryCreate - Create an entry in data pool <pBlock>.
*
* Create an entry in data pool <pBlock>.
*
*
* RETURNS: A pointer to the new entry.
*
* NOMANUAL
*/
void * wmMemBlockEntryCreate
(
WM_BLOCK_T * pBlock /* data pool pointer */
)
{
WM_BLOCK_T * pPrior = NULL;
void * pData = NULL;
#ifndef _WRS_CONFIG_LP64
sbyte4 offset;
#else
sbyte8 offset;
#endif
#ifndef __NO_MAGIC__
ubyte4 * pMagic;
#ifndef _WRS_CONFIG_LP64
ubyte4 bytes;
#else
ubyte8 bytes;
#endif
#endif
for ( ; NULL != pBlock; pBlock = pBlock->pNext)
{
pPrior = pBlock;
/* all filled up? */
if (pBlock->used == pBlock->max)
continue;
/* find first free spot */
#ifndef _WRS_CONFIG_LP64
offset = firstBit(pBlock->free, (ubyte4)pBlock->max);
#else
offset = firstBit(pBlock->free, (ubyte8)pBlock->max);
#endif
if (0 > offset)
{
wmError(ERROR, "no high bit found!");
return NULL;
}
pData = wmMemBlockEntryGet(pBlock, offset);
break;
}
/* no hits means add another block and try again */
if (NULL == pBlock)
{
if (NULL == (pBlock = wmMemBlockExtend(pPrior)))
{
wmError(ERROR_MEMMGR_NO_MEMORY, "no memory");
return NULL;
}
#ifndef _WRS_CONFIG_LP64
offset = firstBit(pBlock->free, (ubyte4)pBlock->max);
#else
offset = firstBit(pBlock->free, (ubyte8)pBlock->max);
#endif
pData = wmMemBlockEntryGet(pBlock, offset);
}
/* if we have no data here then something is seriously wrong! */
if (NULL == pData)
{
wmError(ERROR, "why no data?");
return NULL;
}
pBlock->used++;
#ifndef __NO_MAGIC__
pMagic = (ubyte4 *) pData;
*pMagic = MEM_HEAD;
bytes = (pBlock->size / sizeof(ubyte4)) - 1;
pMagic[bytes] = MEM_TAIL;
/* we return data just past magic header */
pData = ++pMagic;
#endif
return pData;
}
/**************************************************************************
*
* wmMemBlockEntryGet - Gets an entry in data pool <pBlock>.
*
* Gets an entry in data pool <pBlock>.
*
*
* RETURNS: A pointer to the pool entry <pData> in pool <pBlock>.
*
* NOMANUAL
*/
void * wmMemBlockEntryGet
(
WM_BLOCK_T * pBlock, /* data pool pointer */
#ifndef _WRS_CONFIG_LP64
int index /* offset into pool */
#else
long index /* offset into pool */
#endif
)
{
char * pData;
if (wmMemBlockBad(pBlock))
return NULL;
while (index > pBlock->max)
{
pBlock = pBlock->pNext;
index -= pBlock->max;
if (wmMemBlockBad(pBlock))
return NULL;
}
pData = pBlock->pData;
pData += pBlock->size * index;
return pData;
}
/**************************************************************************
*
* wmMemBlockOkay - validate <pData> in block <pBlock>.
*
* RETURNS: OK or ERROR if <pData> or <pBlock> are invalid
*
* NOMANUAL
*/
BOOL wmMemBlockOkay
(
WM_BLOCK_T * pBlock,
void * pData
)
{
#ifndef __NO_MAGIC__
return TRUE;
#else
pMagic = (ubyte4 *) pData;
pMagic--;
if (MEM_HEAD != *pMagic)
return FALSE;
/* ensure we didn't overwrite end of block */
bytes = pBlock->size / sizeof(ubyte4) - 1;
return (MEM_TAIL == pMagic[bytes]))
#endif
}
/**************************************************************************
*
* wmMemBlockFree - Free the allocated entry <pData> in block <pBlock>.
*
* RETURNS: OK or ERROR if <pData> or <pBlock> are invalid
*
* NOMANUAL
*/
STATUS wmMemBlockFree
(
WM_BLOCK_T * pBlock,
void * pData
)
{
char * pStart = NULL;
char * pTest;
#ifndef _WRS_CONFIG_LP64
int blockSize;
int offset;
int bCount;
#else
long blockSize;
long offset;
long bCount;
#endif
#ifndef __NO_MAGIC__
ubyte4 * pMagic;
#ifndef _WRS_CONFIG_LP64
ubyte4 bytes;
#else
ubyte8 bytes;
#endif
#endif
if (wmMemBlockBad(pBlock))
return wmError(ERROR_GENERAL_INVALID, "wmMemBlockFree: bad block");
if (NULL == pData)
return wmError(ERROR_GENERAL_NULL_POINTER, "wmMemBlockFree: NULL pointer");
#ifndef __NO_MAGIC__
pMagic = (ubyte4 *) pData;
pMagic--;
if (MEM_HEAD != *pMagic)
return wmError(ERROR, "block header corrupted");
/* ensure we didn't overwrite end of block */
bytes = pBlock->size / sizeof(ubyte4) - 1;
if (MEM_TAIL != pMagic[bytes])
return wmError(ERROR, "corrupted tail");
/* adjust to actual assigned data */
pData = pMagic;
#endif
pTest = (char *) pData;
blockSize = (pBlock->max - 1) * pBlock->size;
/* is data in this block? */
for ( ; NULL != pBlock; pBlock = pBlock->pNext)
{
pStart = pBlock->pData;
if (pStart <= pTest && pTest <= pStart + blockSize)
break;
}
if (NULL == pBlock)
return wmError(ERROR_GENERAL_NULL_POINTER, "wmMemBlockFree: invalid data ptr");
/* which block is it? */
offset = (pTest - pStart) / pBlock->size;
/* mark as unused */
if (pBlock->used == pBlock->max)
bCount = 0;
#ifndef _WRS_CONFIG_LP64
setBit(pBlock->free, (unsigned int)offset, FALSE);
#else
setBit(pBlock->free, (unsigned long)offset, FALSE);
#endif
/* adjust count */
pBlock->used--;
#ifdef __WM_INVALIDATE__
memset(pData, MY_BAD_K, pBlock->size);
#endif
return OK;
}
/* eof wmMemBlockLib.c */
@@ -0,0 +1,51 @@
/* wmNonce.c - JS support routines */
/* Copyright(c) 2005-2007, 2010, 2012 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
--------------------
01e,18apr12,r_w remove dependence of retrofit.h
Requirement: WIND00299859
01d,15mar10,m_z VxWorks 64bit support (WIND00193649)
01c,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01b,25apr05,??? Update JS Auth #define ordering
01a,17sep04,dkg ported from RC3.3 to WM4.4 for JavaScript Authentication
*/
/* See if Digest is enabled globally */
#include "wm_options.h"
#ifdef __JAVASCRIPT_DIGEST_ENABLED__
#include "httpLib.h"
#include "wmAuth.h"
#include "wmNonce.h"
STATUS wmbGetNonceHandler
(
WMB_TID_T tid, /* transaction id */
WMB_OBJ_T obj, /* the WindMark object */
COMMAND_T cmd /* handler command */
)
{
sbyte *pHtmlOutputBuf;
STATUS status;
WMB_SESSION_T * pSession = wmbTransactionSessionGet(tid);
pHtmlOutputBuf = wmAUTHGetSentNonce(pSession->clientIndex);
status = wmbObjectImport(obj,pHtmlOutputBuf,32,DATATYPE_STRING_K);
return status;
}
#endif
@@ -0,0 +1,656 @@
/* wmOidLib.c - WindManage OID library */
/*
* Copyright (c) 2001-2007, 2010, 2012-2013 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
--------------------
01h,08apr13,r_w fix coverity issues for defect WIND00411995
01g,17may12,h_l replace NO_STRING with NULL_STRING (WIND00032212)
01f,01apr10,m_z correct 32bit error
01e,15mar10,m_z VxWorks 64bit support (WIND00193649)
01d,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01c,07apr03,jws fix SPR 87133 (wmOidFromString())
01b,07feb03,jws fix compiler warning SPR 84193
01a,13mar01,pns written
*/
/*
DESCRIPTION
This module contains support routines OID manipulation.
INCLUDE FILES: wm.h
*/
/* includes */
#include "wm.h"
#ifdef __WM_DEBUG__
LOCAL BOOL debugEnabled = FALSE;
void wmOidDebug
(
WM_OID_T oid,
sbyte * pMsg
)
{
if (! debugEnabled)
return;
wmOidPrint(oid, pMsg);
}
void wmOidDebugEnable
(
BOOL enable
)
{
debugEnabled = enable;
}
#endif /* __WM_DEBUG__ */
/**************************************************************************
*
* wmOidMax - max possible of OID in bytes
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
int wmOidMax
(
WM_OID_T oid
)
{
return (wmBufferMaxGet(oid) < 0x0fffffff)?((int)wmBufferMaxGet(oid)):0x0fffffff;
}
/**************************************************************************
*
* wmOidLen - length of OID in bytes
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
int wmOidLen
(
WM_OID_T oid
)
{
return (int)wmBufferUsedGet(oid);
}
#if 0
/**************************************************************************
*
* wmOidLenSet - set length of OID in 4 byte words
*
*
* RETURNS: NA
*
* NOMANUAL
*/
LOCAL void wmOidLenSet
(
WM_OID_T oid,
sbyte4 len
)
{
wmBufferUsedSet(oid, len);
}
#endif
/**************************************************************************
*
* wmOidPrint - print ascii OID w/ message
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
void wmOidPrint
(
WM_OID_T pInstance,
sbyte * pMsg
)
{
sbyte temp[256];
if (OK != wmOidStringGet(pInstance, temp, sizeof(temp)))
strcpy(temp, "(empty)");
if (NULL == pMsg)
printf("%s\n", temp);
else
printf("%s %s\n", pMsg, temp);
}
/**************************************************************************
*
* wmOidFromString - create oid from an ascii string
*
* This routine counts the number of elements in an ascii OID string,
* and creates a buffer holding an array of these elements as binary
* 32 bit integers.
*
* If <msize> is greater than the storage required, the buffer size is
* increased to <msize>.
*
*
* RETURNS:\is
*\i oid buffer pointer
*\i NULL
*\ie
*
* NOMANUAL
*/
WM_BUFFER_T * wmOidFromString
(
sbyte * pString, /* ascii version of oid, e.g. "1.1.2" */
int msize /* optional max buffer size in bytes */
)
{
WM_BUFFER_T * pOid;
sbyte * pAsciiOid;
int len = 1;
if (NULL_STRING(pString)) return NULL;
/* compute number of elements in oid string */
for (pAsciiOid = pString; '\0' != *pAsciiOid; pAsciiOid++)
{
if ('.' == *pAsciiOid) len++;
}
len *= 4; /* convert to number of bytes needed for binary oid */
if (msize < len) msize = len; /* set size of buffer to ask for */
/* create an OID buffer */
#ifndef _WRS_CONFIG_LP64
pOid = wmBufferCreate (NULL, msize, NULL, DATATYPE_OID_K, TRUE);
#else
pOid = wmBufferCreate (NULL, (ubyte8)msize, NULL, DATATYPE_OID_K, TRUE);
#endif
if (NULL == pOid) return NULL;
/* update data with binary version of oid */
if (wmConvertStrToOid(pString, wmBufferDataGet(pOid), msize, &len) != OK)
{
wmBufferDelete(pOid);
return NULL;
}
#ifndef _WRS_CONFIG_LP64
pOid->Used = len;
#else
pOid->Used = (ubyte8)len;
#endif
return (pOid);
}
/**************************************************************************
*
* wmOidStringSet - update oid with an ascii string oid
*
*
* RETURNS:\is
*\i OK or ERROR
*\ie
*
* NOMANUAL
*/
STATUS wmOidStringSet
(
WM_OID_T pInstance,
sbyte * pString,
BOOL append
)
{
int * pInt;
int max;
int used;
int len;
if ((NULL == pString) || (NULL == pInstance))
return wmError(ERROR_GENERAL_NO_DATA, "no data");
max = (int)wmBufferMaxGet(pInstance);
used = (int)wmBufferUsedGet(pInstance);
pInt = wmBufferDataGet(pInstance);
if (NULL == pInt)
{
wmBufferUpdate(pInstance, NULL, 256, 0, FALSE);
max = (int)wmBufferMaxGet(pInstance);
pInt = wmBufferDataGet(pInstance);
}
else
{
if (append)
pInt += used;
else
used = 0;
}
#ifndef _WRS_CONFIG_LP64
wmConvertStrToOid(pString, pInt, (max * (int)sizeof(int)), &len);
#else
wmConvertStrToOid(pString, pInt, (ubyte8)(max * (int)sizeof(int)), &len);
#endif
/*
len /= sizeof(int);
wmOidLenSet(pInstance, used + len);
*/
#ifndef _WRS_CONFIG_LP64
wmBufferUsedSet(pInstance, used + len);
#else
wmBufferUsedSet(pInstance, (ubyte8)(used + len));
#endif
return OK;
}
/**************************************************************************
*
* wmOidAppend - append one buffer onto another
*
*
* RETURNS: ERROR or OK
*
* NOMANUAL
*/
STATUS wmOidAppend
(
WM_OID_T pDestOid,
WM_OID_T pAddOid
)
{
/*sbyte4 destLen;*/
sbyte4 addLen;
/* sbyte * pDest;*/
sbyte * pAdd;
/* sbyte4 total;*/
if (NULL == pDestOid || NULL == pAddOid)
return wmError(ERROR_GENERAL_NO_DATA, "wmOidAppend: null arg(s)");
/* pDest = wmBufferDataGet(pDestOid);*/
pAdd = wmBufferDataGet(pAddOid);
/* total = (sbyte4)wmBufferMaxGet(pDestOid);*/
/* destLen = (sbyte4)wmBufferUsedGet(pDestOid);*/
addLen = (sbyte4)wmBufferUsedGet(pAddOid);
#ifndef _WRS_CONFIG_LP64
return wmBufferAppend(pDestOid, pAdd, addLen);
#else
return wmBufferAppend(pDestOid, pAdd, (ubyte8)addLen);
#endif
#if 0
/* make sure there's enough space (fix later: just resize) */
if (addLen > total - destLen)
return wmError(ERROR_GENERAL_BUFFER_OVERRUN, "wmOidAppend: not enough space");
/* add suffix! */
pDest += destLen;
destLen += addLen;
memcpy(pDest, pAdd, addLen);
wmBufferUsedSet(pDestOid, destLen);
return OK;
#endif
}
/**************************************************************************
*
* wmOidEqual - compare 2 oids
*
* RETURNS: TRUE if same
*
* NOMANUAL
*/
BOOL wmOidEqual
(
WM_OID_T orig,
WM_OID_T test
)
{
sbyte4 destLen;
sbyte4 addLen;
sbyte * pDest;
sbyte * pAdd;
pDest = wmBufferDataGet(orig);
pAdd = wmBufferDataGet(test);
if (NULL == pDest || NULL == pAdd)
return FALSE;
destLen = (sbyte4)wmBufferUsedGet(orig);
addLen = (sbyte4)wmBufferUsedGet(test);
/* make sure there's enough space (fix later: just resize) */
if (addLen != destLen)
return FALSE;
#ifndef _WRS_CONFIG_LP64
return (0 == memcmp(pDest, pAdd, addLen));
#else
return (0 == memcmp(pDest, pAdd, (ubyte8)addLen));
#endif
}
/**************************************************************************
*
* wmOidCmp - compare 2 oids
*
* RETURNS:
*
* NOMANUAL
*/
int wmOidCmp
(
WM_OID_T orig,
WM_OID_T test
)
{
sbyte4 i;
sbyte4 origLen;
sbyte4 testLen;
ubyte4 * pOrig;
ubyte4 * pTest;
pOrig = wmBufferDataGet(orig);
pTest = wmBufferDataGet(test);
if (NULL == pTest || NULL == pOrig)
return 0;
origLen = (sbyte4)wmBufferUsedGet(orig) / 4;
testLen = (sbyte4)wmBufferUsedGet(test) / 4;
for (i = 0; (i < origLen) && (i < testLen); i++, pOrig++, pTest++)
{
if (*pOrig < *pTest)
return -1;
if (*pOrig > *pTest)
return 1;
}
/* so far they are the same */
if (origLen < testLen)
return -1;
if (origLen > testLen)
return 1;
return 0;
}
/**************************************************************************
*
* wmOidTruncate - truncate oid
*
*
* RETURNS: ERROR or OK
*
* NOMANUAL
*/
STATUS wmOidTruncate
(
WM_OID_T oid,
sbyte4 length /* in bytes */
)
{
sbyte * pData;
sbyte4 used;
sbyte4 max;
pData = wmBufferDataGet (oid);
max = (sbyte4)wmBufferMaxGet (oid);
used = (sbyte4)wmBufferUsedGet (oid);
pData += length;
if (length > used)
return wmError(ERROR_GENERAL_ILLEGAL_VALUE, "wmOidTruncate: length too long");
/* nothing to do */
if (length == used)
return OK;
#ifndef _WRS_CONFIG_LP64
memset(pData, 0, max - length);
wmBufferUsedSet(oid, length);
#else
memset(pData, 0, (ubyte8)(max - length));
wmBufferUsedSet(oid, (ubyte8)length);
#endif
return OK;
}
/**************************************************************************
*
* wmOidSuffix - create new buffer containing unique instance suffix
*
*
* RETURNS: buffer with suffix only
*
* NOMANUAL
*/
WM_OID_T wmOidSuffix
(
WM_OID_T pBaseOid,
WM_OID_T pFullOid
)
{
WM_OID_T pSuffix;
sbyte4 baseLen;
sbyte4 fullLen;
sbyte4 * pBase;
sbyte4 * pFull;
sbyte4 index;
if (NULL == pBaseOid || NULL == pFullOid)
return NULL;
pBase = wmBufferDataGet (pBaseOid);
pFull = wmBufferDataGet (pFullOid);
baseLen = (sbyte4)wmBufferUsedGet (pBaseOid);
fullLen = (sbyte4)wmBufferUsedGet (pFullOid);
if (baseLen >= fullLen)
return NULL;
/* base should match beginning of full */
for (index = baseLen; index > 0; index -= 4, pBase++, pFull++)
{
if (*pBase != *pFull)
return NULL;
}
/* only create suffix if it doesn't already exist */
fullLen -= baseLen;
#ifndef _WRS_CONFIG_LP64
pSuffix = wmBufferCreate(NULL, fullLen, pFull, wmBufferTypeGet(pFullOid), TRUE);
#else
pSuffix = wmBufferCreate(NULL, (ubyte8)fullLen, pFull, wmBufferTypeGet(pFullOid), TRUE);
#endif
/*
wmBufferMakeOid(pSuffix, TRUE);
*/
return pSuffix;
}
/**************************************************************************
*
* wmOidScalerSet - set OID to be scalar object, i.e., .0 at end
*
* RETURNS: OK
*
*
* NOMANUAL
*/
void wmOidScalerSet
(
WM_OID_T oid
)
{
int zero = 0;
wmBufferAppend(oid, &zero, sizeof(zero));
}
/* return if scaler */
BOOL wmOidScaler
(
WM_OID_T oid
)
{
int * pData;
int size;
if (0 >= (size = (int)wmBufferUsedGet(oid)))
return FALSE;
pData = wmBufferDataGet(oid);
pData += size;
return (*pData == 0);
}
/**************************************************************************
*
* wmOidStringGet - create ascii version of oid
*
*
* RETURNS:\is
*\i ERROR_GENERAL_NOT_FOUND
*\i OK
*\ie
*
* NOMANUAL
*/
STATUS wmOidStringGet
(
WM_OID_T oid,
sbyte * pString,
sbyte4 strLen
)
{
int * pData;
sbyte4 oidLen;
if (wmOidBad(oid))
return wmError(ERROR_GENERAL_INVALID, "wmOidStringGet: bad oid");
pData = wmBufferDataGet (oid);
oidLen = (sbyte4)wmBufferUsedGet (oid);
if (NULL == pData || 4 > oidLen)
return wmError(ERROR_GENERAL_NO_DATA, "wmOidStringGet: no data");
wmConvertOidToString ((ubyte4 *)pData, oidLen, pString, strLen, NULL);
return OK;
}
/**************************************************************************
*
* wmOidValid - does OID contain valid data
*
*
* RETURNS:\is
*\i ERROR
*\i OK
*\ie
*
* NOMANUAL
*/
STATUS wmOidValid
(
WM_OID_T oid
)
{
if (wmInvalid(oid))
return wmError(ERROR_GENERAL_INVALID, "wmOidInvalid: bad OID");
if (wmInvalid(wmBufferDataGet(oid)))
return wmError(ERROR_GENERAL_INVALID, "wmOidInvalid: bad data");
return OK;
}
/* eof wmOidLib.c */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,381 @@
/* wmUserLib.c - WindManage user access library */
/*
* Copyright (c) 2002, 2007, 2009, 2010, 2012 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
--------------------
02e,22nov12,f_f move the userInfo defination to the header file
(REQ: WIND00364534)
01f,17may12,h_l replace NO_STRING with NULL_STRING (WIND00032212)
01e,07may10,m_z eliminate compile warning
01d,15mar10,m_z VxWorks 64bit support (WIND00193649)
01c,09mar09,m_z Eliminate compile warning
02b,09mar09,m_z Eliminate compile warning
(WIND00157339)
02,24feb07,msa Correct the apigen comments so they match the actual routines
and correct any apigen errors that may occur.
01,17may02,rs updated refgen comments
*/
/*
DESCRIPTION:
This module implements multi user access routines.
INCLUDE FILES:
wm.h
wmb.h
*/
#include "wm.h"
#include "wmb.h"
#ifdef __ENABLE_WMB_USERS__
/* passwords should be stored in encrypted form */
#ifndef RCC_ENCRYPT_FUNC
# define RCC_ENCRYPT_FUNC(password, salt) password
#endif
userInfo userBase[MAX_USERS_K] =
{
{DEFAULT_LOGIN_K, DEFAULT_PASSWORD_K, 10},
{"guest", "guest", 0}
};
LOCAL void USER_GetSalt
(
sbyte salt[2]
)
{
sbyte buffer[32];
#ifndef _WRS_CONFIG_LP64
ubyte4 timeNow;
#else
ubyte8 timeNow;
#endif
sbyte4 len;
sbyte4 offset;
sbyte4 seed = 0;
timeNow = wmosTimeGet();
ASCTIME((ubyte4)timeNow, buffer);
len = (sbyte4)STRLEN(buffer) - 1;
offset = (int)(timeNow % len);
while (1)
{
seed = buffer[offset];
if (ISALNUM(seed))
break;
++offset;
offset = offset % len;
}
salt[0] = (sbyte) seed;
offset = seed % len;
while (1)
{
seed = buffer[offset];
if (ISALNUM(seed))
break;
++offset;
offset = offset % len;
}
salt[1] = (sbyte) seed;
}
LOCAL userInfo * USER_GetUser
(
sbyte * pLogin
)
{
sbyte2 index;
userInfo *pUser = userBase;
for (index = 0; index < MAX_USERS_K; index++, pUser++)
{
if (0 == STRCMP(pUser->login, pLogin))
return pUser;
}
return NULL;
}
#if 0
LOCAL userInfo * USER_GetPasswordOwner
(
sbyte * pPassword
)
{
sbyte2 index;
sbyte salt[2];
sbyte * pEncrypted = NULL;
userInfo * pUser = userBase;
USER_GetSalt(salt);
pEncrypted = RCC_ENCRYPT_FUNC(pPassword, salt);
for (index = 0; index < MAX_USERS_K; index++, pUser++)
{
if (NULL_STRING(pUser->password))
continue;
if (0 == STRCMP(pUser->password, pEncrypted))
return pUser;
}
return NULL;
}
#endif
/*-----------------------------------------------------------------------*/
LOCAL userInfo * USER_NewUser
(
void
)
{
sbyte2 index;
userInfo *pUser = userBase;
for (index = 0; index < MAX_USERS_K; index++, pUser++)
{
if (NULL_STRING(pUser->login))
return pUser;
}
return NULL;
}
/**************************************************************************
*
* wmUserValidate - Validate (authenticate?) a WMB user.
*
* This routine validates a user <pLogin>:<pPassword> .
*
* RETURNS: TRUE is <pUser> is a valid WMB user. FALSE if not.
*
*/
BOOL wmUserValidate
(
OS_SOCKET_T sock,
sbyte * pLogin,
sbyte * pPassword,
Access * pAccess
)
{
sbyte * pEncrypted = NULL;
sbyte salt[2];
userInfo * pUser;
#ifdef __USE_PASSWORD_ONLY__
if (NULL != (pUser = USER_GetPasswordOwner(pPassword)))
{
*pAccess = pUser->accessLevel;
return TRUE;
}
else
{
*pAccess = 0;
return FALSE;
}
#endif
if (NULL == (pUser = USER_GetUser(pLogin)))
return FALSE;
*pAccess = pUser->accessLevel;
USER_GetSalt(salt);
pEncrypted = RCC_ENCRYPT_FUNC(pPassword, salt);
return (0 == STRCMP(pUser->password, pEncrypted));
}
/**************************************************************************
*
* wmUserAdd - Add a WMB user.
*
* This routine adds a user <pLogin>:<pPassword>, with <pAccess> level.
*
* RETURNS: OK, or ERROR if the username already exists, the specified
* access level is invalid, or if the user database is full.
*
*/
STATUS wmUserAdd
(
sbyte * pLogin,
sbyte * pAccess
)
{
Access accessLevel;
userInfo * pUser;
/* check for pre-existing account */
if (NULL != (pUser = USER_GetUser(pLogin)))
{
printf("User: %s already exists.", pLogin);
return wmError(ERROR_GENERAL, "User already exists");
}
if (NULL == pAccess)
pAccess = DEFAULT_ACCESS_K;
if (OK != wmConvertStrTypeTo(pAccess, &accessLevel, wmAccessInfoGet()))
return wmError(ERROR_GENERAL_ILLEGAL_VALUE, "invalid access");
if (NULL == (pUser = USER_NewUser()))
return wmError(ERROR_GENERAL_MAXED, "user database is full");
STRCPY(pUser->login, pLogin);
pUser->accessLevel = accessLevel;
return OK;
}
/**************************************************************************
*
* wmUserDelete - Delete a WMB user.
*
* This routine deletes user <pLogin> from the WMB user database.
*
* RETURNS: OK, or ERROR if the username does not exist.
*
*/
STATUS wmUserDelete
(
sbyte * pLogin
)
{
userInfo * pUser;
if (NULL == (pUser = USER_GetUser(pLogin)))
return wmError(ERROR_GENERAL, "invalid user");
MEMSET(pUser->login, 0, sizeof(pUser->login));
MEMSET(pUser->password, 0, sizeof(pUser->password));
pUser->accessLevel = 0;
return OK;
}
/**************************************************************************
*
* wmUserChangePassword - Change a WMB user's password.
*
* This routine changes the password for user <pLogin>.
*
* RETURNS: OK, or ERROR if the username does not exist.
*
*/
STATUS wmUserChangePassword
(
sbyte * pLogin,
sbyte * pPassword
)
{
sbyte seed[2];
userInfo * pUser;
if (NULL == (pUser = USER_GetUser(pLogin)))
return wmError(ERROR_GENERAL, "invalid user");
USER_GetSalt(seed);
STRCPY(pUser->password,RCC_ENCRYPT_FUNC(pPassword, seed));
return OK;
}
/**************************************************************************
*
* wmUserChangeAccess - Change a WMB user's access level.
*
* This routine changes the access level for user <pLogin> to <pAccess>.
*
* RETURNS: OK, or ERROR if the username does not exist.
*
*/
STATUS wmUserChangeAccess
(
sbyte * pLogin,
sbyte * pAccess
)
{
userInfo * pUser = USER_GetUser(pLogin);
Access accessLevel;
STATUS status;
if (NULL == pUser)
return wmError(ERROR_GENERAL_INVALID_USER, "invalid user");
status = wmConvertStrTypeTo(pAccess, &accessLevel, wmAccessInfoGet());
if (OK != status)
return status;
pUser->accessLevel = accessLevel;
return OK;
}
/*-----------------------------------------------------------------------*/
/**************************************************************************
*
* wmUserShowUsers - Shows all WMB users.
*
* This routine lists all WMB users and WMB access level. This is intended for
* use ONLY as a debugging feature.
*
* RETURNS: N/A.
*
*/
void wmUserShowUsers
(
void
)
{
sbyte4 index;
sbyte access[30];
userInfo * pUser;
pUser = userBase;
for (index = 0; index < MAX_USERS_K; index++, pUser++)
{
if (NULL_STRING(pUser->login))
continue;
wmAccessToStr(pUser->accessLevel, access);
printf ("User: %20s Access: %s", pUser->login, access);
printf ("\n");
}
}
#endif /* __ENABLE_WMB_USERS__ */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,54 @@
# Makefile - makefile for src/wrn/wm/common/zlib
#
# Copyright (c) 2002-2003, 2013 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,22apr13,r_w modified for coverity tool prevent.pl
# 01b,13mar03,jws merged from TMS branch
# 01a,01nov02,kw created
#
# DESCRIPTION
# This file contains the makefile rules for building part of
# the wm library
#
#
LIB_BASE_NAME = wmzlib
TGT_DIR = $(WIND_BASE)/target
# Using WM_BASE works whether or not we are under WIND_BASE.
WM_BASE = ../../../../..
DOC_FILES =
SRC_FILES= zlib_adler32.c zlib_compress.c zlib_crc32.c zlib_deflate.c \
zlib_gzio.c zlib_infblock.c zlib_infcodes.c zlib_inffast.c \
zlib_inflate.c zlib_inftrees.c zlib_infutil.c zlib_trees.c \
zlib_uncompr.c zlib_zutil.c
OBJS= $(SRC_FILES:%c=%o)
# PRE_INCLUDE= -I$(WM_BASE)/h -I$(WM_BASE)/h/wrn/wm \
# -I$(WM_BASE)/h/wrn/wm/common \
# -I$(WM_BASE)/h/wrn/wm/backplane \
# -I$(WM_BASE)/h/wrn/wm/wmm \
# -I$(WM_BASE)/h/wrn/wm/http \
# -I$(WM_BASE)/h/wrn/wm/cli \
# -I$(WM_BASE)/h/wrn/wm/common/zlib/vxWorks \
# -I$(WM_BASE)/h/wrn/em \
# -I$(WM_BASE)/h/wrn/wm/snmp/engine
PRE_INCLUDE= -I$(WM_BASE)/h/wrn/wm/common/zlib/vxWorks
# EXTRA_DEFINE = -DCOMMON_IS_COMPONENT
include $(TGT_DIR)/h/make/rules.library
@@ -0,0 +1,48 @@
/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2002 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zlib.h"
#define BASE 65521L /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
/* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
const Bytef *buf;
uInt len;
{
unsigned long s1 = adler & 0xffff;
unsigned long s2 = (adler >> 16) & 0xffff;
int k;
if (buf == Z_NULL) return 1L;
while (len > 0) {
k = len < NMAX ? len : NMAX;
len -= k;
while (k >= 16) {
DO16(buf);
buf += 16;
k -= 16;
}
if (k != 0) do {
s1 += *buf++;
s2 += s1;
} while (--k);
s1 %= BASE;
s2 %= BASE;
}
return (s2 << 16) | s1;
}
@@ -0,0 +1,68 @@
/* compress.c -- compress a memory buffer
* Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zlib.h"
/* ===========================================================================
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream;
int err;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = deflateInit(&stream, level);
if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
err = deflateEnd(&stream);
return err;
}
/* ===========================================================================
*/
int ZEXPORT compress (dest, destLen, source, sourceLen)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}
@@ -0,0 +1,162 @@
/* crc32.c -- compute the CRC-32 of a data stream
* Copyright (C) 1995-2002 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zlib.h"
#define local static
#ifdef DYNAMIC_CRC_TABLE
local int crc_table_empty = 1;
local uLongf crc_table[256];
local void make_crc_table OF((void));
/*
Generate a table for a byte-wise 32-bit CRC calculation on the polynomial:
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
Polynomials over GF(2) are represented in binary, one bit per coefficient,
with the lowest powers in the most significant bit. Then adding polynomials
is just exclusive-or, and multiplying a polynomial by x is a right shift by
one. If we call the above polynomial p, and represent a byte as the
polynomial q, also with the lowest power in the most significant bit (so the
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and
taking the remainder. The register is initialized to zero, and for each
incoming bit, x^32 is added mod p to the register if the bit is a one (where
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
x (which is shifting right by one and adding x^32 mod p if the bit shifted
out is a one). We start with the highest power (least significant bit) of
q and repeat for all eight bits of q.
The table is simply the CRC of all possible eight bit values. This is all
the information needed to generate CRC's on data a byte at a time for all
combinations of CRC register values and incoming bytes.
*/
local void make_crc_table()
{
uLong c;
int n, k;
uLong poly; /* polynomial exclusive-or pattern */
/* terms of polynomial defining this crc (except x^32): */
static const Byte p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* make exclusive-or pattern from polynomial (0xedb88320L) */
poly = 0L;
for (n = 0; n < sizeof(p)/sizeof(Byte); n++)
poly |= 1L << (31 - p[n]);
for (n = 0; n < 256; n++)
{
c = (uLong)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc_table[n] = c;
}
crc_table_empty = 0;
}
#else
/* ========================================================================
* Table of CRC-32's of all single-byte values (made by make_crc_table)
*/
local const uLongf crc_table[256] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
0x2d02ef8dL
};
#endif
/* =========================================================================
* This function can be used by asm versions of crc32()
*/
const uLongf * ZEXPORT get_crc_table()
{
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty) make_crc_table();
#endif
return (const uLongf *)crc_table;
}
/* ========================================================================= */
#define DO1(buf) crc = crc_table[((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8);
#define DO2(buf) DO1(buf); DO1(buf);
#define DO4(buf) DO2(buf); DO2(buf);
#define DO8(buf) DO4(buf); DO4(buf);
/* ========================================================================= */
uLong ZEXPORT crc32(crc, buf, len)
uLong crc;
const Bytef *buf;
uInt len;
{
if (buf == Z_NULL) return 0L;
#ifdef DYNAMIC_CRC_TABLE
if (crc_table_empty)
make_crc_table();
#endif
crc = crc ^ 0xffffffffL;
while (len >= 8)
{
DO8(buf);
len -= 8;
}
if (len) do {
DO1(buf);
} while (--len);
return crc ^ 0xffffffffL;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,874 @@
/* gzio.c -- IO on .gz files
* Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*
* Compile this file with -DNO_DEFLATE to avoid the compression code.
*/
/* @(#) $Id$ */
#include <stdio.h>
#include "zutil.h"
struct internal_state {int dummy;}; /* for buggy compilers */
#ifndef Z_BUFSIZE
# ifdef MAXSEG_64K
# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
# else
# define Z_BUFSIZE 16384
# endif
#endif
#ifndef Z_PRINTF_BUFSIZE
# define Z_PRINTF_BUFSIZE 4096
#endif
#define ALLOC(size) malloc(size)
#define TRYFREE(p) {if (p) free(p);}
int ZEXPORT gzeof (gzFile file);
static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
/* gzip flag byte */
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
#define COMMENT 0x10 /* bit 4 set: file comment present */
#define RESERVED 0xE0 /* bits 5..7: reserved */
typedef struct gz_stream {
z_stream stream;
int z_err; /* error code for last stream operation */
int z_eof; /* set if end of input file */
FILE *file; /* .gz file */
Byte *inbuf; /* input buffer */
Byte *outbuf; /* output buffer */
uLong crc; /* crc32 of uncompressed data */
char *msg; /* error message */
char *path; /* path name for debugging only */
int transparent; /* 1 if input file is not a .gz file */
char mode; /* 'w' or 'r' */
long startpos; /* start of compressed data in file (header skipped) */
} gz_stream;
local gzFile gz_open OF((const char *path, const char *mode, int fd));
local int do_flush OF((gzFile file, int flush));
local int get_byte OF((gz_stream *s));
local void check_header OF((gz_stream *s));
local int destroy OF((gz_stream *s));
local void putLong OF((FILE *file, uLong x));
local uLong getLong OF((gz_stream *s));
/* ===========================================================================
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb"). The file is given either by file descriptor
or path name (if fd == -1).
gz_open return NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR).
*/
local gzFile gz_open (path, mode, fd)
const char *path;
const char *mode;
int fd;
{
int err;
int level = Z_DEFAULT_COMPRESSION; /* compression level */
int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
char *p = (char*)mode;
gz_stream *s;
char fmode[80]; /* copy of mode, without the compression level */
char *m = fmode;
if (!path || !mode) return Z_NULL;
s = (gz_stream *)ALLOC(sizeof(gz_stream));
if (!s) return Z_NULL;
s->stream.zalloc = (alloc_func)0;
s->stream.zfree = (free_func)0;
s->stream.opaque = (voidpf)0;
s->stream.next_in = s->inbuf = Z_NULL;
s->stream.next_out = s->outbuf = Z_NULL;
s->stream.avail_in = s->stream.avail_out = 0;
s->file = NULL;
s->z_err = Z_OK;
s->z_eof = 0;
s->crc = crc32(0L, Z_NULL, 0);
s->msg = NULL;
s->transparent = 0;
s->path = (char*)ALLOC(strlen(path)+1);
if (s->path == NULL) {
return destroy(s), (gzFile)Z_NULL;
}
strcpy(s->path, path); /* do this early for debugging */
s->mode = '\0';
do {
if (*p == 'r') s->mode = 'r';
if (*p == 'w' || *p == 'a') s->mode = 'w';
if (*p >= '0' && *p <= '9') {
level = *p - '0';
} else if (*p == 'f') {
strategy = Z_FILTERED;
} else if (*p == 'h') {
strategy = Z_HUFFMAN_ONLY;
} else {
*m++ = *p; /* copy the mode */
}
} while (*p++ && m != fmode + sizeof(fmode));
if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
if (s->mode == 'w') {
#ifdef NO_DEFLATE
err = Z_STREAM_ERROR;
#else
err = deflateInit2(&(s->stream), level,
Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
/* windowBits is passed < 0 to suppress zlib header */
s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
#endif
if (err != Z_OK || s->outbuf == Z_NULL) {
return destroy(s), (gzFile)Z_NULL;
}
} else {
s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
err = inflateInit2(&(s->stream), -MAX_WBITS);
/* windowBits is passed < 0 to tell that there is no zlib header.
* Note that in this case inflate *requires* an extra "dummy" byte
* after the compressed stream in order to complete decompression and
* return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
* present after the compressed stream.
*/
if (err != Z_OK || s->inbuf == Z_NULL) {
return destroy(s), (gzFile)Z_NULL;
}
}
s->stream.avail_out = Z_BUFSIZE;
errno = 0;
s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
if (s->file == NULL) {
return destroy(s), (gzFile)Z_NULL;
}
if (s->mode == 'w') {
/* Write a very simple .gz header:
*/
fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
s->startpos = 10L;
/* We use 10L instead of ftell(s->file) to because ftell causes an
* fflush on some systems. This version of the library doesn't use
* startpos anyway in write mode, so this initialization is not
* necessary.
*/
} else {
check_header(s); /* skip the .gz header */
s->startpos = (ftell(s->file) - s->stream.avail_in);
}
return (gzFile)s;
}
/* ===========================================================================
Opens a gzip (.gz) file for reading or writing.
*/
gzFile ZEXPORT gzopen (path, mode)
const char *path;
const char *mode;
{
return gz_open (path, mode, -1);
}
/* ===========================================================================
Associate a gzFile with the file descriptor fd. fd is not dup'ed here
to mimic the behavio(u)r of fdopen.
*/
gzFile ZEXPORT gzdopen (fd, mode)
int fd;
const char *mode;
{
char name[20];
if (fd < 0) return (gzFile)Z_NULL;
sprintf(name, "<fd:%d>", fd); /* for debugging */
return gz_open (name, mode, fd);
}
/* ===========================================================================
* Update the compression level and strategy
*/
int ZEXPORT gzsetparams (file, level, strategy)
gzFile file;
int level;
int strategy;
{
gz_stream *s = (gz_stream*)file;
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
/* Make room to allow flushing */
if (s->stream.avail_out == 0) {
s->stream.next_out = s->outbuf;
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
s->z_err = Z_ERRNO;
}
s->stream.avail_out = Z_BUFSIZE;
}
return deflateParams (&(s->stream), level, strategy);
}
/* ===========================================================================
Read a byte from a gz_stream; update next_in and avail_in. Return EOF
for end of file.
IN assertion: the stream s has been sucessfully opened for reading.
*/
local int get_byte(s)
gz_stream *s;
{
if (s->z_eof) return EOF;
if (s->stream.avail_in == 0) {
errno = 0;
s->stream.avail_in = (unsigned)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
if (s->stream.avail_in == 0) {
s->z_eof = 1;
if (ferror(s->file)) s->z_err = Z_ERRNO;
return EOF;
}
s->stream.next_in = s->inbuf;
}
s->stream.avail_in--;
return *(s->stream.next_in)++;
}
/* ===========================================================================
Check the gzip header of a gz_stream opened for reading. Set the stream
mode to transparent if the gzip magic header is not present; set s->err
to Z_DATA_ERROR if the magic header is present but the rest of the header
is incorrect.
IN assertion: the stream s has already been created sucessfully;
s->stream.avail_in is zero for the first time, but may be non-zero
for concatenated .gz files.
*/
local void check_header(s)
gz_stream *s;
{
int method; /* method byte */
int flags; /* flags byte */
uInt len;
int c;
/* Check the gzip magic header */
for (len = 0; len < 2; len++) {
c = get_byte(s);
if (c != gz_magic[len]) {
if (len != 0) s->stream.avail_in++, s->stream.next_in--;
if (c != EOF) {
s->stream.avail_in++, s->stream.next_in--;
s->transparent = 1;
}
s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
return;
}
}
method = get_byte(s);
flags = get_byte(s);
if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
s->z_err = Z_DATA_ERROR;
return;
}
/* Discard time, xflags and OS code: */
for (len = 0; len < 6; len++) (void)get_byte(s);
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
len = (uInt)get_byte(s);
len += ((uInt)get_byte(s))<<8;
/* len is garbage if EOF but the loop below will quit anyway */
while (len-- != 0 && get_byte(s) != EOF) ;
}
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
while ((c = get_byte(s)) != 0 && c != EOF) ;
}
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
while ((c = get_byte(s)) != 0 && c != EOF) ;
}
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
for (len = 0; len < 2; len++) (void)get_byte(s);
}
s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
}
/* ===========================================================================
* Cleanup then free the given gz_stream. Return a zlib error code.
Try freeing in the reverse order of allocations.
*/
local int destroy (s)
gz_stream *s;
{
int err = Z_OK;
if (!s) return Z_STREAM_ERROR;
TRYFREE(s->msg);
if (s->stream.state != NULL) {
if (s->mode == 'w') {
#ifdef NO_DEFLATE
err = Z_STREAM_ERROR;
#else
err = deflateEnd(&(s->stream));
#endif
} else if (s->mode == 'r') {
err = inflateEnd(&(s->stream));
}
}
if (s->file != NULL && fclose(s->file)) {
#ifdef ESPIPE
if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
#endif
err = Z_ERRNO;
}
if (s->z_err < 0) err = s->z_err;
TRYFREE(s->inbuf);
TRYFREE(s->outbuf);
TRYFREE(s->path);
TRYFREE(s);
return err;
}
/* ===========================================================================
Reads the given number of uncompressed bytes from the compressed file.
gzread returns the number of bytes actually read (0 for end of file).
*/
int ZEXPORT gzread (file, buf, len)
gzFile file;
voidp buf;
unsigned len;
{
gz_stream *s = (gz_stream*)file;
Bytef *start = (Bytef*)buf; /* starting point for crc computation */
Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */
if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
if (s->z_err == Z_STREAM_END) return 0; /* EOF */
next_out = (Byte*)buf;
s->stream.next_out = (Bytef*)buf;
s->stream.avail_out = len;
while (s->stream.avail_out != 0) {
if (s->transparent) {
/* Copy first the lookahead bytes: */
uInt n = s->stream.avail_in;
if (n > s->stream.avail_out) n = s->stream.avail_out;
if (n > 0) {
zmemcpy(s->stream.next_out, s->stream.next_in, n);
next_out += n;
s->stream.next_out = next_out;
s->stream.next_in += n;
s->stream.avail_out -= n;
s->stream.avail_in -= n;
}
if (s->stream.avail_out > 0) {
s->stream.avail_out -= (unsigned)fread(next_out, 1, s->stream.avail_out,
s->file);
}
len -= s->stream.avail_out;
s->stream.total_in += (uLong)len;
s->stream.total_out += (uLong)len;
if (len == 0) s->z_eof = 1;
return (int)len;
}
if (s->stream.avail_in == 0 && !s->z_eof) {
errno = 0;
s->stream.avail_in = (unsigned)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
if (s->stream.avail_in == 0) {
s->z_eof = 1;
if (ferror(s->file)) {
s->z_err = Z_ERRNO;
break;
}
}
s->stream.next_in = s->inbuf;
}
s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
if (s->z_err == Z_STREAM_END) {
/* Check CRC and original size */
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
start = s->stream.next_out;
if (getLong(s) != s->crc) {
s->z_err = Z_DATA_ERROR;
} else {
(void)getLong(s);
/* The uncompressed length returned by above getlong() may
* be different from s->stream.total_out) in case of
* concatenated .gz files. Check for such files:
*/
check_header(s);
if (s->z_err == Z_OK) {
uLong total_in = s->stream.total_in;
uLong total_out = s->stream.total_out;
inflateReset(&(s->stream));
s->stream.total_in = total_in;
s->stream.total_out = total_out;
s->crc = crc32(0L, Z_NULL, 0);
}
}
}
if (s->z_err != Z_OK || s->z_eof) break;
}
s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
return (int)(len - s->stream.avail_out);
}
/* ===========================================================================
Reads one byte from the compressed file. gzgetc returns this byte
or -1 in case of end of file or error.
*/
int ZEXPORT gzgetc(file)
gzFile file;
{
unsigned char c;
return gzread(file, &c, 1) == 1 ? c : -1;
}
/* ===========================================================================
Reads bytes from the compressed file until len-1 characters are
read, or a newline character is read and transferred to buf, or an
end-of-file condition is encountered. The string is then terminated
with a null character.
gzgets returns buf, or Z_NULL in case of error.
The current implementation is not optimized at all.
*/
char * ZEXPORT gzgets(file, buf, len)
gzFile file;
char *buf;
int len;
{
char *b = buf;
if (buf == Z_NULL || len <= 0) return Z_NULL;
while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
*buf = '\0';
return b == buf && len > 0 ? Z_NULL : b;
}
#ifndef NO_DEFLATE
/* ===========================================================================
Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of bytes actually written (0 in case of error).
*/
int ZEXPORT gzwrite (file, buf, len)
gzFile file;
const voidp buf;
unsigned len;
{
gz_stream *s = (gz_stream*)file;
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
s->stream.next_in = (Bytef*)buf;
s->stream.avail_in = len;
while (s->stream.avail_in != 0) {
if (s->stream.avail_out == 0) {
s->stream.next_out = s->outbuf;
if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
s->z_err = Z_ERRNO;
break;
}
s->stream.avail_out = Z_BUFSIZE;
}
s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
if (s->z_err != Z_OK) break;
}
s->crc = crc32(s->crc, (const Bytef *)buf, len);
return (int)(len - s->stream.avail_in);
}
/* ===========================================================================
Converts, formats, and writes the args to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
uncompressed bytes actually written (0 in case of error).
*/
#ifdef STDC
#include <stdarg.h>
int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
{
char buf[Z_PRINTF_BUFSIZE];
va_list va;
int len;
va_start(va, format);
#ifdef HAS_vsnprintf
len = vsnprintf(buf, sizeof(buf), format, va);
#else
len = vsprintf(buf, format, va);
#endif
va_end(va);
if ((len <= 0) || (len >= Z_PRINTF_BUFSIZE))
return 0;
return gzwrite(file, buf, (unsigned)len);
}
#else /* not ANSI C */
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
gzFile file;
const char *format;
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
{
char buf[Z_PRINTF_BUFSIZE];
int len;
#ifdef HAS_snprintf
len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
#else
len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
#endif
if ((len <= 0) || (len >= Z_PRINTF_BUFSIZE)) return 0;
return gzwrite(file, buf, len);
}
#endif
/* ===========================================================================
Writes c, converted to an unsigned char, into the compressed file.
gzputc returns the value that was written, or -1 in case of error.
*/
int ZEXPORT gzputc(file, c)
gzFile file;
int c;
{
unsigned char cc = (unsigned char) c; /* required for big endian systems */
return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1;
}
/* ===========================================================================
Writes the given null-terminated string to the compressed file, excluding
the terminating null character.
gzputs returns the number of characters written, or -1 in case of error.
*/
int ZEXPORT gzputs(file, s)
gzFile file;
const char *s;
{
return gzwrite(file, (char*)s, (unsigned)strlen(s));
}
/* ===========================================================================
Flushes all pending output into the compressed file. The parameter
flush is as in the deflate() function.
*/
local int do_flush (file, flush)
gzFile file;
int flush;
{
uInt len;
int done = 0;
gz_stream *s = (gz_stream*)file;
if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
s->stream.avail_in = 0; /* should be zero already anyway */
for (;;) {
len = Z_BUFSIZE - s->stream.avail_out;
if (len != 0) {
if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
s->z_err = Z_ERRNO;
return Z_ERRNO;
}
s->stream.next_out = s->outbuf;
s->stream.avail_out = Z_BUFSIZE;
}
if (done) break;
s->z_err = deflate(&(s->stream), flush);
/* Ignore the second of two consecutive flushes: */
if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
/* deflate has finished flushing only when it hasn't used up
* all the available space in the output buffer:
*/
done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
}
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
}
int ZEXPORT gzflush (file, flush)
gzFile file;
int flush;
{
gz_stream *s = (gz_stream*)file;
int err = do_flush (file, flush);
if (err) return err;
fflush(s->file);
return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
}
#endif /* NO_DEFLATE */
/* ===========================================================================
Sets the starting position for the next gzread or gzwrite on the given
compressed file. The offset represents a number of bytes in the
gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error.
SEEK_END is not implemented, returns error.
In this version of the library, gzseek can be extremely slow.
*/
z_off_t ZEXPORT gzseek (file, offset, whence)
gzFile file;
z_off_t offset;
int whence;
{
gz_stream *s = (gz_stream*)file;
if (s == NULL || whence == SEEK_END ||
s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
return -1L;
}
if (s->mode == 'w') {
#ifdef NO_DEFLATE
return -1L;
#else
if (whence == SEEK_SET) {
offset -= (unsigned)s->stream.total_in;
}
if (offset < 0) return -1L;
/* At this point, offset is the number of zero bytes to write. */
if (s->inbuf == Z_NULL) {
s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
zmemzero(s->inbuf, Z_BUFSIZE);
}
while (offset > 0) {
uInt size = Z_BUFSIZE;
if (offset < Z_BUFSIZE) size = (uInt)offset;
size = (uInt)gzwrite(file, s->inbuf, size);
if (size == 0) return -1L;
offset -= size;
}
return (z_off_t)s->stream.total_in;
#endif
}
/* Rest of function is for reading only */
/* compute absolute position */
if (whence == SEEK_CUR) {
offset += (unsigned)s->stream.total_out;
}
if (offset < 0) return -1L;
if (s->transparent) {
/* map to fseek */
s->stream.avail_in = 0;
s->stream.next_in = s->inbuf;
if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
s->stream.total_in = s->stream.total_out = (uLong)offset;
return offset;
}
/* For a negative seek, rewind and use positive seek */
if ((uLong)offset >= s->stream.total_out) {
offset -= (unsigned)s->stream.total_out;
} else if (gzrewind(file) < 0) {
return -1L;
}
/* offset is now the number of bytes to skip. */
if (offset != 0 && s->outbuf == Z_NULL) {
s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
}
while (offset > 0) {
int size = Z_BUFSIZE;
if (offset < Z_BUFSIZE) size = (int)offset;
size = gzread(file, s->outbuf, (uInt)size);
if (size <= 0) return -1L;
offset -= size;
}
return (z_off_t)s->stream.total_out;
}
/* ===========================================================================
Rewinds input file.
*/
int ZEXPORT gzrewind (file)
gzFile file;
{
gz_stream *s = (gz_stream*)file;
if (s == NULL || s->mode != 'r') return -1;
s->z_err = Z_OK;
s->z_eof = 0;
s->stream.avail_in = 0;
s->stream.next_in = s->inbuf;
s->crc = crc32(0L, Z_NULL, 0);
if (s->startpos == 0) { /* not a compressed file */
rewind(s->file);
return 0;
}
(void) inflateReset(&s->stream);
return fseek(s->file, s->startpos, SEEK_SET);
}
/* ===========================================================================
Returns the starting position for the next gzread or gzwrite on the
given compressed file. This position represents a number of bytes in the
uncompressed data stream.
*/
z_off_t ZEXPORT gztell (file)
gzFile file;
{
return gzseek(file, 0L, SEEK_CUR);
}
/* ===========================================================================
Returns 1 when EOF has previously been detected reading the given
input stream, otherwise zero.
*/
int ZEXPORT gzeof (file)
gzFile file;
{
gz_stream *s = (gz_stream*)file;
return (s == NULL || s->mode != 'r') ? 0 : s->z_eof;
}
/* ===========================================================================
Outputs a long in LSB order to the given file
*/
local void putLong (file, x)
FILE *file;
uLong x;
{
int n;
for (n = 0; n < 4; n++) {
fputc((int)(x & 0xff), file);
x >>= 8;
}
}
/* ===========================================================================
Reads a long in LSB order from the given gz_stream. Sets z_err in case
of error.
*/
local uLong getLong (s)
gz_stream *s;
{
uLong x = (uLong)get_byte(s);
int c;
x += ((uLong)get_byte(s))<<8;
x += ((uLong)get_byte(s))<<16;
c = get_byte(s);
if (c == EOF) s->z_err = Z_DATA_ERROR;
x += ((uLong)c)<<24;
return x;
}
/* ===========================================================================
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression state.
*/
int ZEXPORT gzclose (file)
gzFile file;
{
int err;
gz_stream *s = (gz_stream*)file;
if (s == NULL) return Z_STREAM_ERROR;
if (s->mode == 'w') {
#ifdef NO_DEFLATE
return Z_STREAM_ERROR;
#else
err = do_flush (file, Z_FINISH);
if (err != Z_OK) return destroy((gz_stream*)file);
putLong (s->file, s->crc);
putLong (s->file, s->stream.total_in);
#endif
}
return destroy((gz_stream*)file);
}
/* ===========================================================================
Returns the error message for the last error which occured on the
given compressed file. errnum is set to zlib error number. If an
error occured in the file system and not in the compression library,
errnum is set to Z_ERRNO and the application may consult errno
to get the exact error code.
*/
const char* ZEXPORT gzerror (file, errnum)
gzFile file;
int *errnum;
{
char *m;
gz_stream *s = (gz_stream*)file;
if (s == NULL) {
*errnum = Z_STREAM_ERROR;
return (const char*)ERR_MSG(Z_STREAM_ERROR);
}
*errnum = s->z_err;
if (*errnum == Z_OK) return (const char*)"";
m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
TRYFREE(s->msg);
s->msg = (char*)ALLOC(strlen(s->path) + strlen(m) + 3);
strcpy(s->msg, s->path);
strcat(s->msg, ": ");
strcat(s->msg, m);
return (const char*)s->msg;
}
@@ -0,0 +1,403 @@
/* infblock.c -- interpret and process block types to last block
* Copyright (C) 1995-2002 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "infblock.h"
#include "inftrees.h"
#include "infcodes.h"
#include "infutil.h"
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
/* Table for deflate from PKZIP's appnote.txt. */
local const uInt border[] = { /* Order of the bit length code lengths */
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
/*
Notes beyond the 1.93a appnote.txt:
1. Distance pointers never point before the beginning of the output
stream.
2. Distance pointers can point back across blocks, up to 32k away.
3. There is an implied maximum of 7 bits for the bit length table and
15 bits for the actual data.
4. If only one code exists, then it is encoded using one bit. (Zero
would be more efficient, but perhaps a little confusing.) If two
codes exist, they are coded using one bit each (0 and 1).
5. There is no way of sending zero distance codes--a dummy must be
sent if there are none. (History: a pre 2.0 version of PKZIP would
store blocks with no distance codes, but this was discovered to be
too harsh a criterion.) Valid only for 1.93a. 2.04c does allow
zero distance codes, which is sent as one code of zero bits in
length.
6. There are up to 286 literal/length codes. Code 256 represents the
end-of-block. Note however that the static length tree defines
288 codes just to fill out the Huffman codes. Codes 286 and 287
cannot be used though, since there is no length base or extra bits
defined for them. Similarily, there are up to 30 distance codes.
However, static trees define 32 codes (all 5 bits) to fill out the
Huffman codes, but the last two had better not show up in the data.
7. Unzip can check dynamic Huffman blocks for complete code sets.
The exception is that a single code would not be complete (see #4).
8. The five bits following the block type is really the number of
literal codes sent minus 257.
9. Length codes 8,16,16 are interpreted as 13 length codes of 8 bits
(1+6+6). Therefore, to output three times the length, you output
three codes (1+1+1), whereas to output four times the same length,
you only need two codes (1+3). Hmm.
10. In the tree reconstruction algorithm, Code = Code + Increment
only if BitLength(i) is not zero. (Pretty obvious.)
11. Correction: 4 Bits: # of Bit Length codes - 4 (4 - 19)
12. Note: length code 284 can represent 227-258, but length code 285
really is 258. The last length deserves its own, short code
since it gets used a lot in very redundant files. The length
258 is special since 258 - 3 (the min match length) is 255.
13. The literal/length and distance code bit lengths are read as a
single stream of lengths. It is possible (and advantageous) for
a repeat code (16, 17, or 18) to go across the boundary between
the two sets of lengths.
*/
void inflate_blocks_reset(s, z, c)
inflate_blocks_statef *s;
z_streamp z;
uLongf *c;
{
if (c != Z_NULL)
*c = s->check;
if (s->mode == BTREE || s->mode == DTREE)
ZFREE(z, s->sub.trees.blens);
if (s->mode == CODES)
inflate_codes_free(s->sub.decode.codes, z);
s->mode = TYPE;
s->bitk = 0;
s->bitb = 0;
s->read = s->write = s->window;
if (s->checkfn != Z_NULL)
z->adler = s->check = (*s->checkfn)(0L, (const Bytef *)Z_NULL, 0);
Tracev((stderr, "inflate: blocks reset\n"));
}
inflate_blocks_statef *inflate_blocks_new(z, c, w)
z_streamp z;
check_func c;
uInt w;
{
inflate_blocks_statef *s;
if ((s = (inflate_blocks_statef *)ZALLOC
(z,1,sizeof(struct inflate_blocks_state))) == Z_NULL)
return s;
if ((s->hufts =
(inflate_huft *)ZALLOC(z, sizeof(inflate_huft), MANY)) == Z_NULL)
{
ZFREE(z, s);
return Z_NULL;
}
if ((s->window = (Bytef *)ZALLOC(z, 1, w)) == Z_NULL)
{
ZFREE(z, s->hufts);
ZFREE(z, s);
return Z_NULL;
}
s->end = s->window + w;
s->checkfn = c;
s->mode = TYPE;
Tracev((stderr, "inflate: blocks allocated\n"));
inflate_blocks_reset(s, z, Z_NULL);
return s;
}
int inflate_blocks(s, z, r)
inflate_blocks_statef *s;
z_streamp z;
int r;
{
uInt t; /* temporary storage */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
/* copy input/output information to locals (UPDATE macro restores) */
LOAD
/* process input based on current state */
while (1) switch (s->mode)
{
case TYPE:
NEEDBITS(3)
t = (uInt)b & 7;
s->last = t & 1;
switch (t >> 1)
{
case 0: /* stored */
Tracev((stderr, "inflate: stored block%s\n",
s->last ? " (last)" : ""));
DUMPBITS(3)
t = k & 7; /* go to byte boundary */
DUMPBITS(t)
s->mode = LENS; /* get length of stored block */
break;
case 1: /* fixed */
Tracev((stderr, "inflate: fixed codes block%s\n",
s->last ? " (last)" : ""));
{
uInt bl, bd;
inflate_huft *tl, *td;
inflate_trees_fixed(&bl, &bd, &tl, &td, z);
s->sub.decode.codes = inflate_codes_new(bl, bd, tl, td, z);
if (s->sub.decode.codes == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
}
DUMPBITS(3)
s->mode = CODES;
break;
case 2: /* dynamic */
Tracev((stderr, "inflate: dynamic codes block%s\n",
s->last ? " (last)" : ""));
DUMPBITS(3)
s->mode = TABLE;
break;
case 3: /* illegal */
DUMPBITS(3)
s->mode = BAD;
z->msg = (char*)"invalid block type";
r = Z_DATA_ERROR;
LEAVE
}
break;
case LENS:
NEEDBITS(32)
if ((((~b) >> 16) & 0xffff) != (b & 0xffff))
{
s->mode = BAD;
z->msg = (char*)"invalid stored block lengths";
r = Z_DATA_ERROR;
LEAVE
}
s->sub.left = (uInt)b & 0xffff;
b = k = 0; /* dump bits */
Tracev((stderr, "inflate: stored length %u\n", s->sub.left));
s->mode = s->sub.left ? STORED : (s->last ? DRY : TYPE);
break;
case STORED:
if (n == 0)
LEAVE
NEEDOUT
t = s->sub.left;
if (t > n) t = n;
if (t > m) t = m;
zmemcpy(q, p, t);
p += t; n -= t;
q += t; m -= t;
if ((s->sub.left -= t) != 0)
break;
Tracev((stderr, "inflate: stored end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read :
(s->end - s->read) + (q - s->window))));
s->mode = s->last ? DRY : TYPE;
break;
case TABLE:
NEEDBITS(14)
s->sub.trees.table = t = (uInt)b & 0x3fff;
#ifndef PKZIP_BUG_WORKAROUND
if ((t & 0x1f) > 29 || ((t >> 5) & 0x1f) > 29)
{
s->mode = BAD;
z->msg = (char*)"too many length or distance symbols";
r = Z_DATA_ERROR;
LEAVE
}
#endif
t = 258 + (t & 0x1f) + ((t >> 5) & 0x1f);
if ((s->sub.trees.blens = (uIntf*)ZALLOC(z, t, sizeof(uInt))) == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
DUMPBITS(14)
s->sub.trees.index = 0;
Tracev((stderr, "inflate: table sizes ok\n"));
s->mode = BTREE;
case BTREE:
while (s->sub.trees.index < 4 + (s->sub.trees.table >> 10))
{
NEEDBITS(3)
s->sub.trees.blens[border[s->sub.trees.index++]] = (uInt)b & 7;
DUMPBITS(3)
}
while (s->sub.trees.index < 19)
s->sub.trees.blens[border[s->sub.trees.index++]] = 0;
s->sub.trees.bb = 7;
t = inflate_trees_bits(s->sub.trees.blens, &s->sub.trees.bb,
&s->sub.trees.tb, s->hufts, z);
if (t != Z_OK)
{
r = t;
if (r == Z_DATA_ERROR)
{
ZFREE(z, s->sub.trees.blens);
s->mode = BAD;
}
LEAVE
}
s->sub.trees.index = 0;
Tracev((stderr, "inflate: bits tree ok\n"));
s->mode = DTREE;
case DTREE:
while (t = s->sub.trees.table,
s->sub.trees.index < 258 + (t & 0x1f) + ((t >> 5) & 0x1f))
{
inflate_huft *h;
uInt i, j, c;
t = s->sub.trees.bb;
NEEDBITS(t)
h = s->sub.trees.tb + ((uInt)b & inflate_mask[t]);
t = h->bits;
c = h->base;
if (c < 16)
{
DUMPBITS(t)
s->sub.trees.blens[s->sub.trees.index++] = c;
}
else /* c == 16..18 */
{
i = c == 18 ? 7 : c - 14;
j = c == 18 ? 11 : 3;
NEEDBITS(t + i)
DUMPBITS(t)
j += (uInt)b & inflate_mask[i];
DUMPBITS(i)
i = s->sub.trees.index;
t = s->sub.trees.table;
if (i + j > 258 + (t & 0x1f) + ((t >> 5) & 0x1f) ||
(c == 16 && i < 1))
{
ZFREE(z, s->sub.trees.blens);
s->mode = BAD;
z->msg = (char*)"invalid bit length repeat";
r = Z_DATA_ERROR;
LEAVE
}
c = c == 16 ? s->sub.trees.blens[i - 1] : 0;
do {
s->sub.trees.blens[i++] = c;
} while (--j);
s->sub.trees.index = i;
}
}
s->sub.trees.tb = Z_NULL;
{
uInt bl, bd;
inflate_huft *tl, *td;
inflate_codes_statef *c;
bl = 9; /* must be <= 9 for lookahead assumptions */
bd = 6; /* must be <= 9 for lookahead assumptions */
t = s->sub.trees.table;
t = inflate_trees_dynamic(257 + (t & 0x1f), 1 + ((t >> 5) & 0x1f),
s->sub.trees.blens, &bl, &bd, &tl, &td,
s->hufts, z);
if (t != Z_OK)
{
if (t == (uInt)Z_DATA_ERROR)
{
ZFREE(z, s->sub.trees.blens);
s->mode = BAD;
}
r = t;
LEAVE
}
Tracev((stderr, "inflate: trees ok\n"));
if ((c = inflate_codes_new(bl, bd, tl, td, z)) == Z_NULL)
{
r = Z_MEM_ERROR;
LEAVE
}
s->sub.decode.codes = c;
}
ZFREE(z, s->sub.trees.blens);
s->mode = CODES;
case CODES:
UPDATE
if ((r = inflate_codes(s, z, r)) != Z_STREAM_END)
return inflate_flush(s, z, r);
r = Z_OK;
inflate_codes_free(s->sub.decode.codes, z);
LOAD
Tracev((stderr, "inflate: codes end, %lu total out\n",
z->total_out + (q >= s->read ? q - s->read :
(s->end - s->read) + (q - s->window))));
if (!s->last)
{
s->mode = TYPE;
break;
}
s->mode = DRY;
case DRY:
FLUSH
if (s->read != s->write)
LEAVE
s->mode = DONE;
case DONE:
r = Z_STREAM_END;
LEAVE
case BAD:
r = Z_DATA_ERROR;
LEAVE
default:
r = Z_STREAM_ERROR;
LEAVE
}
}
int inflate_blocks_free(s, z)
inflate_blocks_statef *s;
z_streamp z;
{
inflate_blocks_reset(s, z, Z_NULL);
ZFREE(z, s->window);
ZFREE(z, s->hufts);
ZFREE(z, s);
Tracev((stderr, "inflate: blocks freed\n"));
return Z_OK;
}
void inflate_set_dictionary(s, d, n)
inflate_blocks_statef *s;
const Bytef *d;
uInt n;
{
zmemcpy(s->window, d, n);
s->read = s->write = s->window + n;
}
/* Returns true if inflate is currently at the end of a block generated
* by Z_SYNC_FLUSH or Z_FULL_FLUSH.
* IN assertion: s != Z_NULL
*/
int inflate_blocks_sync_point(s)
inflate_blocks_statef *s;
{
return s->mode == LENS;
}
@@ -0,0 +1,251 @@
/* infcodes.c -- process literals and length/distance pairs
* Copyright (C) 1995-2002 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "inftrees.h"
#include "infblock.h"
#include "infcodes.h"
#include "infutil.h"
#include "inffast.h"
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
typedef enum { /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
START, /* x: set up for LEN */
LEN, /* i: get length/literal/eob next */
LENEXT, /* i: getting length extra (have base) */
DIST, /* i: get distance next */
DISTEXT, /* i: getting distance extra */
COPY, /* o: copying bytes in window, waiting for space */
LIT, /* o: got literal, waiting for output space */
WASH, /* o: got eob, possibly still output waiting */
END, /* x: got eob and all data flushed */
BADCODE} /* x: got error */
inflate_codes_mode;
/* inflate codes private state */
struct inflate_codes_state {
/* mode */
inflate_codes_mode mode; /* current inflate_codes mode */
/* mode dependent information */
uInt len;
union {
struct {
inflate_huft *tree; /* pointer into tree */
uInt need; /* bits needed */
} code; /* if LEN or DIST, where in tree */
uInt lit; /* if LIT, literal */
struct {
uInt get; /* bits to get for extra */
uInt dist; /* distance back to copy from */
} copy; /* if EXT or COPY, where and how much */
} sub; /* submode */
/* mode independent information */
Byte lbits; /* ltree bits decoded per branch */
Byte dbits; /* dtree bits decoder per branch */
inflate_huft *ltree; /* literal/length/eob tree */
inflate_huft *dtree; /* distance tree */
};
inflate_codes_statef *inflate_codes_new(bl, bd, tl, td, z)
uInt bl, bd;
inflate_huft *tl;
inflate_huft *td; /* need separate declaration for Borland C++ */
z_streamp z;
{
inflate_codes_statef *c;
if ((c = (inflate_codes_statef *)
ZALLOC(z,1,sizeof(struct inflate_codes_state))) != Z_NULL)
{
c->mode = START;
c->lbits = (Byte)bl;
c->dbits = (Byte)bd;
c->ltree = tl;
c->dtree = td;
Tracev((stderr, "inflate: codes new\n"));
}
return c;
}
int inflate_codes(s, z, r)
inflate_blocks_statef *s;
z_streamp z;
int r;
{
uInt j; /* temporary storage */
inflate_huft *t; /* temporary pointer */
uInt e; /* extra bits or operation */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
Bytef *f; /* pointer to copy strings from */
inflate_codes_statef *c = s->sub.decode.codes; /* codes state */
/* copy input/output information to locals (UPDATE macro restores) */
LOAD
/* process input and output based on current state */
while (1) switch (c->mode)
{ /* waiting for "i:"=input, "o:"=output, "x:"=nothing */
case START: /* x: set up for LEN */
#ifndef SLOW
if (m >= 258 && n >= 10)
{
UPDATE
r = inflate_fast(c->lbits, c->dbits, c->ltree, c->dtree, s, z);
LOAD
if (r != Z_OK)
{
c->mode = r == Z_STREAM_END ? WASH : BADCODE;
break;
}
}
#endif /* !SLOW */
c->sub.code.need = c->lbits;
c->sub.code.tree = c->ltree;
c->mode = LEN;
case LEN: /* i: get length/literal/eob next */
j = c->sub.code.need;
NEEDBITS(j)
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
DUMPBITS(t->bits)
e = (uInt)(t->exop);
if (e == 0) /* literal */
{
c->sub.lit = t->base;
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
"inflate: literal '%c'\n" :
"inflate: literal 0x%02x\n", t->base));
c->mode = LIT;
break;
}
if (e & 16) /* length */
{
c->sub.copy.get = e & 15;
c->len = t->base;
c->mode = LENEXT;
break;
}
if ((e & 64) == 0) /* next table */
{
c->sub.code.need = e;
c->sub.code.tree = t + t->base;
break;
}
if (e & 32) /* end of block */
{
Tracevv((stderr, "inflate: end of block\n"));
c->mode = WASH;
break;
}
c->mode = BADCODE; /* invalid code */
z->msg = (char*)"invalid literal/length code";
r = Z_DATA_ERROR;
LEAVE
case LENEXT: /* i: getting length extra (have base) */
j = c->sub.copy.get;
NEEDBITS(j)
c->len += (uInt)b & inflate_mask[j];
DUMPBITS(j)
c->sub.code.need = c->dbits;
c->sub.code.tree = c->dtree;
Tracevv((stderr, "inflate: length %u\n", c->len));
c->mode = DIST;
case DIST: /* i: get distance next */
j = c->sub.code.need;
NEEDBITS(j)
t = c->sub.code.tree + ((uInt)b & inflate_mask[j]);
DUMPBITS(t->bits)
e = (uInt)(t->exop);
if (e & 16) /* distance */
{
c->sub.copy.get = e & 15;
c->sub.copy.dist = t->base;
c->mode = DISTEXT;
break;
}
if ((e & 64) == 0) /* next table */
{
c->sub.code.need = e;
c->sub.code.tree = t + t->base;
break;
}
c->mode = BADCODE; /* invalid code */
z->msg = (char*)"invalid distance code";
r = Z_DATA_ERROR;
LEAVE
case DISTEXT: /* i: getting distance extra */
j = c->sub.copy.get;
NEEDBITS(j)
c->sub.copy.dist += (uInt)b & inflate_mask[j];
DUMPBITS(j)
Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist));
c->mode = COPY;
case COPY: /* o: copying bytes in window, waiting for space */
f = q - c->sub.copy.dist;
while (f < s->window) /* modulo window size-"while" instead */
f += s->end - s->window; /* of "if" handles invalid distances */
while (c->len)
{
NEEDOUT
OUTBYTE(*f++)
if (f == s->end)
f = s->window;
c->len--;
}
c->mode = START;
break;
case LIT: /* o: got literal, waiting for output space */
NEEDOUT
OUTBYTE(c->sub.lit)
c->mode = START;
break;
case WASH: /* o: got eob, possibly more output */
if (k > 7) /* return unused byte, if any */
{
Assert(k < 16, "inflate_codes grabbed too many bytes")
k -= 8;
n++;
p--; /* can always return one */
}
FLUSH
if (s->read != s->write)
LEAVE
c->mode = END;
case END:
r = Z_STREAM_END;
LEAVE
case BADCODE: /* x: got error */
r = Z_DATA_ERROR;
LEAVE
default:
r = Z_STREAM_ERROR;
LEAVE
}
#ifdef NEED_DUMMY_RETURN
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
#endif
}
void inflate_codes_free(c, z)
inflate_codes_statef *c;
z_streamp z;
{
ZFREE(z, c);
Tracev((stderr, "inflate: codes free\n"));
}
@@ -0,0 +1,183 @@
/* inffast.c -- process literals and length/distance pairs fast
* Copyright (C) 1995-2002 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "inftrees.h"
#include "infblock.h"
#include "infcodes.h"
#include "infutil.h"
#include "inffast.h"
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
/* macros for bit input with no checking and for returning unused bytes */
#define GRABBITS(j) {while(k<(j)){b|=((uLong)NEXTBYTE)<<k;k+=8;}}
#define UNGRAB {c=z->avail_in-n;c=(k>>3)<c?k>>3:c;n+=c;p-=c;k-=c<<3;}
/* Called with number of bytes left to write in window at least 258
(the maximum string length) and number of input bytes available
at least ten. The ten bytes are six bytes for the longest length/
distance pair plus four bytes for overloading the bit buffer. */
int inflate_fast(bl, bd, tl, td, s, z)
uInt bl, bd;
inflate_huft *tl;
inflate_huft *td; /* need separate declaration for Borland C++ */
inflate_blocks_statef *s;
z_streamp z;
{
inflate_huft *t; /* temporary pointer */
uInt e; /* extra bits or operation */
uLong b; /* bit buffer */
uInt k; /* bits in bit buffer */
Bytef *p; /* input data pointer */
uInt n; /* bytes available there */
Bytef *q; /* output window write pointer */
uInt m; /* bytes to end of window or read pointer */
uInt ml; /* mask for literal/length tree */
uInt md; /* mask for distance tree */
uInt c; /* bytes to copy */
uInt d; /* distance back to copy from */
Bytef *r; /* copy source pointer */
/* load input, output, bit values */
LOAD
/* initialize masks */
ml = inflate_mask[bl];
md = inflate_mask[bd];
/* do until not enough input or output space for fast loop */
do { /* assume called with m >= 258 && n >= 10 */
/* get literal/length code */
GRABBITS(20) /* max bits for literal/length code */
if ((e = (t = tl + ((uInt)b & ml))->exop) == 0)
{
DUMPBITS(t->bits)
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
"inflate: * literal '%c'\n" :
"inflate: * literal 0x%02x\n", t->base));
*q++ = (Byte)t->base;
m--;
continue;
}
do {
DUMPBITS(t->bits)
if (e & 16)
{
/* get extra bits for length */
e &= 15;
c = t->base + ((uInt)b & inflate_mask[e]);
DUMPBITS(e)
Tracevv((stderr, "inflate: * length %u\n", c));
/* decode distance base of block to copy */
GRABBITS(15); /* max bits for distance code */
e = (t = td + ((uInt)b & md))->exop;
do {
DUMPBITS(t->bits)
if (e & 16)
{
/* get extra bits to add to distance base */
e &= 15;
GRABBITS(e) /* get extra bits (up to 13) */
d = t->base + ((uInt)b & inflate_mask[e]);
DUMPBITS(e)
Tracevv((stderr, "inflate: * distance %u\n", d));
/* do the copy */
m -= c;
r = q - d;
if (r < s->window) /* wrap if needed */
{
do {
r += s->end - s->window; /* force pointer in window */
} while (r < s->window); /* covers invalid distances */
e = (uInt)(s->end - r);
if (c > e)
{
c -= e; /* wrapped copy */
do {
*q++ = *r++;
} while (--e);
r = s->window;
do {
*q++ = *r++;
} while (--c);
}
else /* normal copy */
{
*q++ = *r++; c--;
*q++ = *r++; c--;
do {
*q++ = *r++;
} while (--c);
}
}
else /* normal copy */
{
*q++ = *r++; c--;
*q++ = *r++; c--;
do {
*q++ = *r++;
} while (--c);
}
break;
}
else if ((e & 64) == 0)
{
t += t->base;
e = (t += ((uInt)b & inflate_mask[e]))->exop;
}
else
{
z->msg = (char*)"invalid distance code";
UNGRAB
UPDATE
return Z_DATA_ERROR;
}
} while (1);
break;
}
if ((e & 64) == 0)
{
t += t->base;
if ((e = (t += ((uInt)b & inflate_mask[e]))->exop) == 0)
{
DUMPBITS(t->bits)
Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ?
"inflate: * literal '%c'\n" :
"inflate: * literal 0x%02x\n", t->base));
*q++ = (Byte)t->base;
m--;
break;
}
}
else if (e & 32)
{
Tracevv((stderr, "inflate: * end of block\n"));
UNGRAB
UPDATE
return Z_STREAM_END;
}
else
{
z->msg = (char*)"invalid literal/length code";
UNGRAB
UPDATE
return Z_DATA_ERROR;
}
} while (1);
} while (m >= 258 && n >= 10);
/* not enough input or output--restore pointers and return */
UNGRAB
UPDATE
return Z_OK;
}
@@ -0,0 +1,366 @@
/* inflate.c -- zlib interface to inflate modules
* Copyright (C) 1995-2002 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "infblock.h"
struct inflate_blocks_state {int dummy;}; /* for buggy compilers */
typedef enum {
METHOD, /* waiting for method byte */
FLAG, /* waiting for flag byte */
DICT4, /* four dictionary check bytes to go */
DICT3, /* three dictionary check bytes to go */
DICT2, /* two dictionary check bytes to go */
DICT1, /* one dictionary check byte to go */
DICT0, /* waiting for inflateSetDictionary */
BLOCKS, /* decompressing blocks */
CHECK4, /* four check bytes to go */
CHECK3, /* three check bytes to go */
CHECK2, /* two check bytes to go */
CHECK1, /* one check byte to go */
DONE, /* finished check, done */
BAD} /* got an error--stay here */
inflate_mode;
/* inflate private state */
struct internal_state {
/* mode */
inflate_mode mode; /* current inflate mode */
/* mode dependent information */
union {
uInt method; /* if FLAGS, method byte */
struct {
uLong was; /* computed check value */
uLong need; /* stream check value */
} check; /* if CHECK, check values to compare */
uInt marker; /* if BAD, inflateSync's marker bytes count */
} sub; /* submode */
/* mode independent information */
int nowrap; /* flag for no wrapper */
uInt wbits; /* log2(window size) (8..15, defaults to 15) */
inflate_blocks_statef
*blocks; /* current inflate_blocks state */
};
int ZEXPORT inflateReset(z)
z_streamp z;
{
if (z == Z_NULL || z->state == Z_NULL)
return Z_STREAM_ERROR;
z->total_in = z->total_out = 0;
z->msg = Z_NULL;
z->state->mode = z->state->nowrap ? BLOCKS : METHOD;
inflate_blocks_reset(z->state->blocks, z, Z_NULL);
Tracev((stderr, "inflate: reset\n"));
return Z_OK;
}
int ZEXPORT inflateEnd(z)
z_streamp z;
{
if (z == Z_NULL || z->state == Z_NULL || z->zfree == Z_NULL)
return Z_STREAM_ERROR;
if (z->state->blocks != Z_NULL)
inflate_blocks_free(z->state->blocks, z);
ZFREE(z, z->state);
z->state = Z_NULL;
Tracev((stderr, "inflate: end\n"));
return Z_OK;
}
int ZEXPORT inflateInit2_(z, w, version, stream_size)
z_streamp z;
int w;
const char *version;
int stream_size;
{
if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
stream_size != sizeof(z_stream))
return Z_VERSION_ERROR;
/* initialize state */
if (z == Z_NULL)
return Z_STREAM_ERROR;
z->msg = Z_NULL;
if (z->zalloc == Z_NULL)
{
z->zalloc = zcalloc;
z->opaque = (voidpf)0;
}
if (z->zfree == Z_NULL) z->zfree = zcfree;
if ((z->state = (struct internal_state FAR *)
ZALLOC(z,1,sizeof(struct internal_state))) == Z_NULL)
return Z_MEM_ERROR;
z->state->blocks = Z_NULL;
/* handle undocumented nowrap option (no zlib header or check) */
z->state->nowrap = 0;
if (w < 0)
{
w = - w;
z->state->nowrap = 1;
}
/* set window size */
if (w < 8 || w > 15)
{
inflateEnd(z);
return Z_STREAM_ERROR;
}
z->state->wbits = (uInt)w;
/* create inflate_blocks state */
if ((z->state->blocks =
inflate_blocks_new(z, z->state->nowrap ? Z_NULL : adler32, (uInt)1 << w))
== Z_NULL)
{
inflateEnd(z);
return Z_MEM_ERROR;
}
Tracev((stderr, "inflate: allocated\n"));
/* reset state */
inflateReset(z);
return Z_OK;
}
int ZEXPORT inflateInit_(z, version, stream_size)
z_streamp z;
const char *version;
int stream_size;
{
return inflateInit2_(z, DEF_WBITS, version, stream_size);
}
#define NEEDBYTE {if(z->avail_in==0)return r;r=f;}
#define NEXTBYTE (z->avail_in--,z->total_in++,*z->next_in++)
int ZEXPORT inflate(z, f)
z_streamp z;
int f;
{
int r;
uInt b;
if (z == Z_NULL || z->state == Z_NULL || z->next_in == Z_NULL)
return Z_STREAM_ERROR;
f = f == Z_FINISH ? Z_BUF_ERROR : Z_OK;
r = Z_BUF_ERROR;
while (1) switch (z->state->mode)
{
case METHOD:
NEEDBYTE
if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
{
z->state->mode = BAD;
z->msg = (char*)"unknown compression method";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
if ((z->state->sub.method >> 4) + 8 > z->state->wbits)
{
z->state->mode = BAD;
z->msg = (char*)"invalid window size";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
z->state->mode = FLAG;
case FLAG:
NEEDBYTE
b = NEXTBYTE;
if (((z->state->sub.method << 8) + b) % 31)
{
z->state->mode = BAD;
z->msg = (char*)"incorrect header check";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
Tracev((stderr, "inflate: zlib header ok\n"));
if (!(b & PRESET_DICT))
{
z->state->mode = BLOCKS;
break;
}
z->state->mode = DICT4;
case DICT4:
NEEDBYTE
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
z->state->mode = DICT3;
case DICT3:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
z->state->mode = DICT2;
case DICT2:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
z->state->mode = DICT1;
case DICT1:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE;
z->adler = z->state->sub.check.need;
z->state->mode = DICT0;
return Z_NEED_DICT;
case DICT0:
z->state->mode = BAD;
z->msg = (char*)"need dictionary";
z->state->sub.marker = 0; /* can try inflateSync */
return Z_STREAM_ERROR;
case BLOCKS:
r = inflate_blocks(z->state->blocks, z, r);
if (r == Z_DATA_ERROR)
{
z->state->mode = BAD;
z->state->sub.marker = 0; /* can try inflateSync */
break;
}
if (r == Z_OK)
r = f;
if (r != Z_STREAM_END)
return r;
r = f;
inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
if (z->state->nowrap)
{
z->state->mode = DONE;
break;
}
z->state->mode = CHECK4;
case CHECK4:
NEEDBYTE
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
z->state->mode = CHECK3;
case CHECK3:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
z->state->mode = CHECK2;
case CHECK2:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
z->state->mode = CHECK1;
case CHECK1:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE;
if (z->state->sub.check.was != z->state->sub.check.need)
{
z->state->mode = BAD;
z->msg = (char*)"incorrect data check";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
Tracev((stderr, "inflate: zlib check ok\n"));
z->state->mode = DONE;
case DONE:
return Z_STREAM_END;
case BAD:
return Z_DATA_ERROR;
default:
return Z_STREAM_ERROR;
}
#ifdef NEED_DUMMY_RETURN
return Z_STREAM_ERROR; /* Some dumb compilers complain without this */
#endif
}
int ZEXPORT inflateSetDictionary(z, dictionary, dictLength)
z_streamp z;
const Bytef *dictionary;
uInt dictLength;
{
uInt length = dictLength;
if (z == Z_NULL || z->state == Z_NULL || z->state->mode != DICT0)
return Z_STREAM_ERROR;
if (adler32(1L, dictionary, dictLength) != z->adler) return Z_DATA_ERROR;
z->adler = 1L;
if (length >= ((uInt)1<<z->state->wbits))
{
length = (1<<z->state->wbits)-1;
dictionary += dictLength - length;
}
inflate_set_dictionary(z->state->blocks, dictionary, length);
z->state->mode = BLOCKS;
return Z_OK;
}
int ZEXPORT inflateSync(z)
z_streamp z;
{
uInt n; /* number of bytes to look at */
Bytef *p; /* pointer to bytes */
uInt m; /* number of marker bytes found in a row */
uLong r, w; /* temporaries to save total_in and total_out */
/* set up */
if (z == Z_NULL || z->state == Z_NULL)
return Z_STREAM_ERROR;
if (z->state->mode != BAD)
{
z->state->mode = BAD;
z->state->sub.marker = 0;
}
if ((n = z->avail_in) == 0)
return Z_BUF_ERROR;
p = z->next_in;
m = z->state->sub.marker;
/* search */
while (n && m < 4)
{
static const Byte mark[4] = {0, 0, 0xff, 0xff};
if (*p == mark[m])
m++;
else if (*p)
m = 0;
else
m = 4 - m;
p++, n--;
}
/* restore */
z->total_in += p - z->next_in;
z->next_in = p;
z->avail_in = n;
z->state->sub.marker = m;
/* return no joy or set up to restart on a new block */
if (m != 4)
return Z_DATA_ERROR;
r = z->total_in; w = z->total_out;
inflateReset(z);
z->total_in = r; z->total_out = w;
z->state->mode = BLOCKS;
return Z_OK;
}
/* Returns true if inflate is currently at the end of a block generated
* by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
* implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
* but removes the length bytes of the resulting empty stored block. When
* decompressing, PPP checks that at the end of input packet, inflate is
* waiting for these length bytes.
*/
int ZEXPORT inflateSyncPoint(z)
z_streamp z;
{
if (z == Z_NULL || z->state == Z_NULL || z->state->blocks == Z_NULL)
return Z_STREAM_ERROR;
return inflate_blocks_sync_point(z->state->blocks);
}
@@ -0,0 +1,454 @@
/* inftrees.c -- generate Huffman trees for efficient decoding
* Copyright (C) 1995-2002 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "inftrees.h"
#if !defined(BUILDFIXED) && !defined(STDC)
# define BUILDFIXED /* non ANSI compilers may not accept inffixed.h */
#endif
const char inflate_copyright[] =
" inflate 1.1.4 Copyright 1995-2002 Mark Adler ";
/*
If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot
include such an acknowledgment, I would appreciate that you keep this
copyright string in the executable of your product.
*/
struct internal_state {int dummy;}; /* for buggy compilers */
/* simplify the use of the inflate_huft type with some defines */
#define exop word.what.Exop
#define bits word.what.Bits
local int huft_build OF((
uIntf *, /* code lengths in bits */
uInt, /* number of codes */
uInt, /* number of "simple" codes */
const uIntf *, /* list of base values for non-simple codes */
const uIntf *, /* list of extra bits for non-simple codes */
inflate_huft * FAR*,/* result: starting table */
uIntf *, /* maximum lookup bits (returns actual) */
inflate_huft *, /* space for trees */
uInt *, /* hufts used in space */
uIntf * )); /* space for values */
/* Tables for deflate from PKZIP's appnote.txt. */
local const uInt cplens[31] = { /* Copy lengths for literal codes 257..285 */
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
/* see note #13 above about 258 */
local const uInt cplext[31] = { /* Extra bits for literal codes 257..285 */
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 112, 112}; /* 112==invalid */
local const uInt cpdist[30] = { /* Copy offsets for distance codes 0..29 */
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
8193, 12289, 16385, 24577};
local const uInt cpdext[30] = { /* Extra bits for distance codes */
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10, 11, 11,
12, 12, 13, 13};
/*
Huffman code decoding is performed using a multi-level table lookup.
The fastest way to decode is to simply build a lookup table whose
size is determined by the longest code. However, the time it takes
to build this table can also be a factor if the data being decoded
is not very long. The most common codes are necessarily the
shortest codes, so those codes dominate the decoding time, and hence
the speed. The idea is you can have a shorter table that decodes the
shorter, more probable codes, and then point to subsidiary tables for
the longer codes. The time it costs to decode the longer codes is
then traded against the time it takes to make longer tables.
This results of this trade are in the variables lbits and dbits
below. lbits is the number of bits the first level table for literal/
length codes can decode in one step, and dbits is the same thing for
the distance codes. Subsequent tables are also less than or equal to
those sizes. These values may be adjusted either when all of the
codes are shorter than that, in which case the longest code length in
bits is used, or when the shortest code is *longer* than the requested
table size, in which case the length of the shortest code in bits is
used.
There are two different values for the two tables, since they code a
different number of possibilities each. The literal/length table
codes 286 possible values, or in a flat code, a little over eight
bits. The distance table codes 30 possible values, or a little less
than five bits, flat. The optimum values for speed end up being
about one bit more than those, so lbits is 8+1 and dbits is 5+1.
The optimum values may differ though from machine to machine, and
possibly even between compilers. Your mileage may vary.
*/
/* If BMAX needs to be larger than 16, then h and x[] should be uLong. */
#define BMAX 15 /* maximum bit length of any code */
local int huft_build(b, n, s, d, e, t, m, hp, hn, v)
uIntf *b; /* code lengths in bits (all assumed <= BMAX) */
uInt n; /* number of codes (assumed <= 288) */
uInt s; /* number of simple-valued codes (0..s-1) */
const uIntf *d; /* list of base values for non-simple codes */
const uIntf *e; /* list of extra bits for non-simple codes */
inflate_huft * FAR *t; /* result: starting table */
uIntf *m; /* maximum lookup bits, returns actual */
inflate_huft *hp; /* space for trees */
uInt *hn; /* hufts used in space */
uIntf *v; /* working area: values in order of bit length */
/* Given a list of code lengths and a maximum table size, make a set of
tables to decode that set of codes. Return Z_OK on success, Z_BUF_ERROR
if the given code set is incomplete (the tables are still built in this
case), or Z_DATA_ERROR if the input is invalid. */
{
uInt a; /* counter for codes of length k */
uInt c[BMAX+1]; /* bit length count table */
uInt f; /* i repeats in table every f entries */
int g; /* maximum code length */
int h; /* table level */
register uInt i; /* counter, current code */
register uInt j; /* counter */
register int k; /* number of bits in current code */
int l; /* bits per table (returned in m) */
uInt mask; /* (1 << w) - 1, to avoid cc -O bug on HP */
register uIntf *p; /* pointer into c[], b[], or v[] */
inflate_huft *q; /* points to current table */
struct inflate_huft_s r; /* table entry for structure assignment */
inflate_huft *u[BMAX]; /* table stack */
register int w; /* bits before this table == (l * h) */
uInt x[BMAX+1]; /* bit offsets, then code stack */
uIntf *xp; /* pointer into x */
int y; /* number of dummy codes added */
uInt z; /* number of entries in current table */
/* Generate counts for each bit length */
p = c;
#define C0 *p++ = 0;
#define C2 C0 C0 C0 C0
#define C4 C2 C2 C2 C2
C4 /* clear c[]--assume BMAX+1 is 16 */
p = b; i = n;
do {
c[*p++]++; /* assume all entries <= BMAX */
} while (--i);
if (c[0] == n) /* null input--all zero length codes */
{
*t = (inflate_huft *)Z_NULL;
*m = 0;
return Z_OK;
}
/* Find minimum and maximum length, bound *m by those */
l = (int)*m;
for (j = 1; j <= BMAX; j++)
if (c[j])
break;
k = (int)j; /* minimum code length */
if ((uInt)l < j)
l = (int)j;
for (i = BMAX; i; i--)
if (c[i])
break;
g = (int)i; /* maximum code length */
if ((uInt)l > i)
l = (int)i;
*m = (uInt)l;
/* Adjust last length count to fill out codes, if needed */
for (y = 1 << j; j < i; j++, y <<= 1)
if ((y -= (int)c[j]) < 0)
return Z_DATA_ERROR;
if ((y -= (int)c[i]) < 0)
return Z_DATA_ERROR;
c[i] += (uInt)y;
/* Generate starting offsets into the value table for each length */
x[1] = j = 0;
p = c + 1; xp = x + 2;
while (--i) { /* note that i == g from above */
*xp++ = (j += *p++);
}
/* Make a table of values in order of bit lengths */
p = b; i = 0;
do {
if ((j = *p++) != 0)
v[x[j]++] = i;
} while (++i < n);
n = x[g]; /* set n to length of v */
/* Generate the Huffman codes and for each, make the table entries */
x[0] = i = 0; /* first Huffman code is zero */
p = v; /* grab values in bit order */
h = -1; /* no tables yet--level -1 */
w = -l; /* bits decoded == (l * h) */
u[0] = (inflate_huft *)Z_NULL; /* just to keep compilers happy */
q = (inflate_huft *)Z_NULL; /* ditto */
z = 0; /* ditto */
/* go through the bit lengths (k already is bits in shortest code) */
for (; k <= g; k++)
{
a = c[k];
while (a--)
{
/* here i is the Huffman code of length k bits for value *p */
/* make tables up to required level */
while (k > w + l)
{
h++;
w += l; /* previous table always l bits */
/* compute minimum size table less than or equal to l bits */
z = (uInt)(g - w);
z = z > (uInt)l ? (uInt)l : z; /* table size upper limit */
if ((f = (uInt)(1 << (j = (uInt)(k - w)))) > a + 1) /* try a k-w bit table */
{ /* too few codes for k-w bit table */
f -= a + 1; /* deduct codes from patterns left */
xp = c + k;
if (j < z)
while (++j < z) /* try smaller tables up to z bits */
{
if ((f <<= 1) <= *++xp)
break; /* enough codes to use up j bits */
f -= *xp; /* else deduct codes from patterns */
}
}
z = (uInt)(1 << j); /* table entries for j-bit table */
/* allocate new table */
if (*hn + z > MANY) /* (note: doesn't matter for fixed) */
return Z_DATA_ERROR; /* overflow of MANY */
u[h] = q = hp + *hn;
*hn += z;
/* connect to last table, if there is one */
if (h)
{
x[h] = i; /* save pattern for backing up */
r.bits = (Byte)l; /* bits to dump before this table */
r.exop = (Byte)j; /* bits in this table */
j = i >> (w - l);
r.base = (uInt)(q - u[h-1] - j); /* offset to this table */
u[h-1][j] = r; /* connect to last table */
}
else
*t = q; /* first table is returned result */
}
/* set up table entry in r */
r.bits = (Byte)(k - w);
if (p >= v + n)
r.exop = 128 + 64; /* out of values--invalid code */
else if (*p < s)
{
r.exop = (Byte)(*p < 256 ? 0 : 32 + 64); /* 256 is end-of-block */
r.base = *p++; /* simple code is just the value */
}
else
{
r.exop = (Byte)(e[*p - s] + 16 + 64);/* non-simple--look up in lists */
r.base = d[*p++ - s];
}
/* fill code-like entries with r */
f = (uInt)(1 << (k - w));
for (j = (uInt)(i >> w); j < z; j += f)
q[j] = r;
/* backwards increment the k-bit code i */
for (j = (uInt)(1 << (k - 1)); i & j; j >>= 1)
i ^= j;
i ^= j;
/* backup over finished tables */
mask = (uInt)((1 << w) - 1); /* needed on HP, cc -O bug */
while ((i & mask) != x[h])
{
h--; /* don't need to update q */
w -= l;
mask = (uInt)((1 << w) - 1);
}
}
}
/* Return Z_BUF_ERROR if we were given an incomplete table */
return y != 0 && g != 1 ? Z_BUF_ERROR : Z_OK;
}
int inflate_trees_bits(c, bb, tb, hp, z)
uIntf *c; /* 19 code lengths */
uIntf *bb; /* bits tree desired/actual depth */
inflate_huft * FAR *tb; /* bits tree result */
inflate_huft *hp; /* space for trees */
z_streamp z; /* for messages */
{
int r;
uInt hn = 0; /* hufts used in space */
uIntf *v; /* work area for huft_build */
if ((v = (uIntf*)ZALLOC(z, 19, sizeof(uInt))) == Z_NULL)
return Z_MEM_ERROR;
r = huft_build(c, 19, 19, (uIntf*)Z_NULL, (uIntf*)Z_NULL,
tb, bb, hp, &hn, v);
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed dynamic bit lengths tree";
else if (r == Z_BUF_ERROR || *bb == 0)
{
z->msg = (char*)"incomplete dynamic bit lengths tree";
r = Z_DATA_ERROR;
}
ZFREE(z, v);
return r;
}
int inflate_trees_dynamic(nl, nd, c, bl, bd, tl, td, hp, z)
uInt nl; /* number of literal/length codes */
uInt nd; /* number of distance codes */
uIntf *c; /* that many (total) code lengths */
uIntf *bl; /* literal desired/actual bit depth */
uIntf *bd; /* distance desired/actual bit depth */
inflate_huft * FAR *tl; /* literal/length tree result */
inflate_huft * FAR *td; /* distance tree result */
inflate_huft *hp; /* space for trees */
z_streamp z; /* for messages */
{
int r;
uInt hn = 0; /* hufts used in space */
uIntf *v; /* work area for huft_build */
/* allocate work area */
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
return Z_MEM_ERROR;
/* build literal/length tree */
r = huft_build(c, nl, 257, cplens, cplext, tl, bl, hp, &hn, v);
if (r != Z_OK || *bl == 0)
{
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed literal/length tree";
else if (r != Z_MEM_ERROR)
{
z->msg = (char*)"incomplete literal/length tree";
r = Z_DATA_ERROR;
}
ZFREE(z, v);
return r;
}
/* build distance tree */
r = huft_build(c + nl, nd, 0, cpdist, cpdext, td, bd, hp, &hn, v);
if (r != Z_OK || (*bd == 0 && nl > 257))
{
if (r == Z_DATA_ERROR)
z->msg = (char*)"oversubscribed distance tree";
else if (r == Z_BUF_ERROR) {
#ifdef PKZIP_BUG_WORKAROUND
r = Z_OK;
}
#else
z->msg = (char*)"incomplete distance tree";
r = Z_DATA_ERROR;
}
else if (r != Z_MEM_ERROR)
{
z->msg = (char*)"empty distance tree with lengths";
r = Z_DATA_ERROR;
}
ZFREE(z, v);
return r;
#endif
}
/* done */
ZFREE(z, v);
return Z_OK;
}
/* build fixed tables only once--keep them here */
#ifdef BUILDFIXED
local int fixed_built = 0;
#define FIXEDH 544 /* number of hufts used by fixed tables */
local inflate_huft fixed_mem[FIXEDH];
local uInt fixed_bl;
local uInt fixed_bd;
local inflate_huft *fixed_tl;
local inflate_huft *fixed_td;
#else
#include "inffixed.h"
#endif
int inflate_trees_fixed(bl, bd, tl, td, z)
uIntf *bl; /* literal desired/actual bit depth */
uIntf *bd; /* distance desired/actual bit depth */
inflate_huft * FAR *tl; /* literal/length tree result */
inflate_huft * FAR *td; /* distance tree result */
z_streamp z; /* for memory allocation */
{
#ifdef BUILDFIXED
/* build fixed tables if not already */
if (!fixed_built)
{
int k; /* temporary variable */
uInt f = 0; /* number of hufts used in fixed_mem */
uIntf *c; /* length list for huft_build */
uIntf *v; /* work area for huft_build */
/* allocate memory */
if ((c = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
return Z_MEM_ERROR;
if ((v = (uIntf*)ZALLOC(z, 288, sizeof(uInt))) == Z_NULL)
{
ZFREE(z, c);
return Z_MEM_ERROR;
}
/* literal table */
for (k = 0; k < 144; k++)
c[k] = 8;
for (; k < 256; k++)
c[k] = 9;
for (; k < 280; k++)
c[k] = 7;
for (; k < 288; k++)
c[k] = 8;
fixed_bl = 9;
huft_build(c, 288, 257, cplens, cplext, &fixed_tl, &fixed_bl,
fixed_mem, &f, v);
/* distance table */
for (k = 0; k < 30; k++)
c[k] = 5;
fixed_bd = 5;
huft_build(c, 30, 0, cpdist, cpdext, &fixed_td, &fixed_bd,
fixed_mem, &f, v);
/* done */
ZFREE(z, v);
ZFREE(z, c);
fixed_built = 1;
}
#endif
*bl = fixed_bl;
*bd = fixed_bd;
*tl = fixed_tl;
*td = fixed_td;
return Z_OK;
}
@@ -0,0 +1,87 @@
/* inflate_util.c -- data and routines common to blocks and codes
* Copyright (C) 1995-2002 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include "zutil.h"
#include "infblock.h"
#include "inftrees.h"
#include "infcodes.h"
#include "infutil.h"
struct inflate_codes_state {int dummy;}; /* for buggy compilers */
/* And'ing with mask[n] masks the lower n bits */
uInt inflate_mask[17] = {
0x0000,
0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
};
/* copy as much as possible from the sliding window to the output area */
int inflate_flush(s, z, r)
inflate_blocks_statef *s;
z_streamp z;
int r;
{
uInt n;
Bytef *p;
Bytef *q;
/* local copies of source and destination pointers */
p = z->next_out;
q = s->read;
/* compute number of bytes to copy as far as end of window */
n = (uInt)((q <= s->write ? s->write : s->end) - q);
if (n > z->avail_out) n = z->avail_out;
if (n && r == Z_BUF_ERROR) r = Z_OK;
/* update counters */
z->avail_out -= n;
z->total_out += n;
/* update check information */
if (s->checkfn != Z_NULL)
z->adler = s->check = (*s->checkfn)(s->check, q, n);
/* copy as far as end of window */
zmemcpy(p, q, n);
p += n;
q += n;
/* see if more to copy at beginning of window */
if (q == s->end)
{
/* wrap pointers */
q = s->window;
if (s->write == s->end)
s->write = s->window;
/* compute bytes to copy */
n = (uInt)(s->write - q);
if (n > z->avail_out) n = z->avail_out;
if (n && r == Z_BUF_ERROR) r = Z_OK;
/* update counters */
z->avail_out -= n;
z->total_out += n;
/* update check information */
if (s->checkfn != Z_NULL)
z->adler = s->check = (*s->checkfn)(s->check, q, n);
/* copy */
zmemcpy(p, q, n);
p += n;
q += n;
}
/* update pointers */
z->next_out = p;
s->read = q;
/* done */
return r;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,58 @@
/* uncompr.c -- decompress a memory buffer
* Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zlib.h"
/* ===========================================================================
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
int ZEXPORT uncompress (dest, destLen, source, sourceLen)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
z_stream stream;
int err;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
err = inflateInit(&stream);
if (err != Z_OK) return err;
err = inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
inflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
err = inflateEnd(&stream);
return err;
}
@@ -0,0 +1,225 @@
/* zutil.c -- target dependent utility functions for the compression library
* Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zutil.h"
struct internal_state {int dummy;}; /* for buggy compilers */
#ifndef STDC
extern void exit OF((int));
#endif
const char *z_errmsg[10] = {
"need dictionary", /* Z_NEED_DICT 2 */
"stream end", /* Z_STREAM_END 1 */
"", /* Z_OK 0 */
"file error", /* Z_ERRNO (-1) */
"stream error", /* Z_STREAM_ERROR (-2) */
"data error", /* Z_DATA_ERROR (-3) */
"insufficient memory", /* Z_MEM_ERROR (-4) */
"buffer error", /* Z_BUF_ERROR (-5) */
"incompatible version",/* Z_VERSION_ERROR (-6) */
""};
const char * ZEXPORT zlibVersion()
{
return ZLIB_VERSION;
}
#ifdef DEBUG
# ifndef verbose
# define verbose 0
# endif
int z_verbose = verbose;
void z_error (m)
char *m;
{
fprintf(stderr, "%s\n", m);
exit(1);
}
#endif
/* exported to allow conversion of error code to string for compress() and
* uncompress()
*/
const char * ZEXPORT zError(err)
int err;
{
return ERR_MSG(err);
}
#ifndef HAVE_MEMCPY
void zmemcpy(dest, source, len)
Bytef* dest;
const Bytef* source;
uInt len;
{
if (len == 0) return;
do {
*dest++ = *source++; /* ??? to be unrolled */
} while (--len != 0);
}
int zmemcmp(s1, s2, len)
const Bytef* s1;
const Bytef* s2;
uInt len;
{
uInt j;
for (j = 0; j < len; j++) {
if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
}
return 0;
}
void zmemzero(dest, len)
Bytef* dest;
uInt len;
{
if (len == 0) return;
do {
*dest++ = 0; /* ??? to be unrolled */
} while (--len != 0);
}
#endif
#ifdef __TURBOC__
#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
/* Small and medium model in Turbo C are for now limited to near allocation
* with reduced MAX_WBITS and MAX_MEM_LEVEL
*/
# define MY_ZCALLOC
/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
* and farmalloc(64K) returns a pointer with an offset of 8, so we
* must fix the pointer. Warning: the pointer must be put back to its
* original form in order to free it, use zcfree().
*/
#define MAX_PTR 10
/* 10*64K = 640K */
local int next_ptr = 0;
typedef struct ptr_table_s {
voidpf org_ptr;
voidpf new_ptr;
} ptr_table;
local ptr_table table[MAX_PTR];
/* This table is used to remember the original form of pointers
* to large buffers (64K). Such pointers are normalized with a zero offset.
* Since MSDOS is not a preemptive multitasking OS, this table is not
* protected from concurrent access. This hack doesn't work anyway on
* a protected system like OS/2. Use Microsoft C instead.
*/
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{
voidpf buf = opaque; /* just to make some compilers happy */
ulg bsize = (ulg)items*size;
/* If we allocate less than 65520 bytes, we assume that farmalloc
* will return a usable pointer which doesn't have to be normalized.
*/
if (bsize < 65520L) {
buf = farmalloc(bsize);
if (*(ush*)&buf != 0) return buf;
} else {
buf = farmalloc(bsize + 16L);
}
if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
table[next_ptr].org_ptr = buf;
/* Normalize the pointer to seg:0 */
*((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
*(ush*)&buf = 0;
table[next_ptr++].new_ptr = buf;
return buf;
}
void zcfree (voidpf opaque, voidpf ptr)
{
int n;
if (*(ush*)&ptr != 0) { /* object < 64K */
farfree(ptr);
return;
}
/* Find the original pointer */
for (n = 0; n < next_ptr; n++) {
if (ptr != table[n].new_ptr) continue;
farfree(table[n].org_ptr);
while (++n < next_ptr) {
table[n-1] = table[n];
}
next_ptr--;
return;
}
ptr = opaque; /* just to make some compilers happy */
Assert(0, "zcfree: ptr not found");
}
#endif
#endif /* __TURBOC__ */
#if defined(M_I86) && !defined(__32BIT__)
/* Microsoft C in 16-bit mode */
# define MY_ZCALLOC
#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
# define _halloc halloc
# define _hfree hfree
#endif
voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
{
if (opaque) opaque = 0; /* to make compiler happy */
return _halloc((long)items, size);
}
void zcfree (voidpf opaque, voidpf ptr)
{
if (opaque) opaque = 0; /* to make compiler happy */
_hfree(ptr);
}
#endif /* MSC */
#ifndef MY_ZCALLOC /* Any system without a special alloc function */
#ifndef STDC
extern voidp calloc OF((uInt items, uInt size));
extern void free OF((voidpf ptr));
#endif
voidpf zcalloc (opaque, items, size)
voidpf opaque;
unsigned items;
unsigned size;
{
if (opaque) items += size - size; /* make compiler happy */
return (voidpf)calloc(items, size);
}
void zcfree (opaque, ptr)
voidpf opaque;
voidpf ptr;
{
free(ptr);
if (opaque) return; /* make compiler happy */
}
#endif /* MY_ZCALLOC */
@@ -0,0 +1,114 @@
/*****************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* This example shows usage of simple cookie interface.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <curl/curl.h> /* the standard opensource way of including the curl library */
/* this routine is in place to print the curl cookie that was downloaded from google */
static void
print_cookies(CURL *curl)
{
CURLcode res; /* this is jsut the return code we check to see whether our curl state machine was successful, if it wasn't this would be assigned one of the many relatively useful return codes documented in the curl man page */
struct curl_slist *cookies; /* a linked list of cookies */
struct curl_slist *nc; /* just another linked list */
int i;
printf("Cookies, curl knows:\n");
res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies); /* here we load up the linked list with the curl cookie repository */
if (res != CURLE_OK) { /* something wen't horribly wrong */
fprintf(stderr, "Curl curl_easy_getinfo failed: %s\n", curl_easy_strerror(res));
exit(1);
}
nc = cookies, i = 1;
while (nc) { /* now we iterate through the cookie list */
printf("[%d]: %s\n", i, nc->data); /* here we print out the cookie data */
nc = nc->next; /* go to the next cookie */
i++;
}
if (i == 1) { /* there were no cookies... how boring */
printf("(none)\n");
}
curl_slist_free_all(cookies); /* gotta cleanup the memory allocated to that linked list */
}
int
curlCookieExample(void)
{
CURL *curl; /* this is the basic curl state machine */
CURLcode res; /* this is jsut the return code we check to see whether our curl state machine was successful, if it wasn't this would be assigned one of the many relatively useful return codes documented in the curl man page */
curl_global_init(CURL_GLOBAL_ALL); /* this is the global init, I'm not really sure why this example does this here because the following easy init is suppose to do this for you */
curl = curl_easy_init(); /* easy init is typically the fastest and best way to get a basic curl state machine initialized */
if (curl) {/* here we're just checking to make sure the state machine initialization was successful */
char nline[256];
printf("\n========================http://www.google.com========================\n");
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com"); /* we're going to connect to google and download the infomous immortal cookie */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); /* this just enable verbose output so you can see more info as the curl state machine progresses through communicating with sourceforge */
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* just to start the cookie engine */
res = curl_easy_perform(curl); /* now that the state machine has been configured we tell it to act on our configuration parameters */
if (res != CURLE_OK) { /* here we are checkin that state machine's return code to make sure everything went alright */
fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); /* this curl_easy_stderror() function is a pretty slick idea */
return 1;
}
print_cookies(curl); /* ok so everything went well so let eat...I mean print those cookies */
printf("Erasing curl's knowledge of cookies!\n");
curl_easy_setopt(curl, CURLOPT_COOKIELIST, "ALL"); /* and this is how we flush the cooke repository */
print_cookies(curl); /* print the repository again just to see if we really did clean it out */
printf("-----------------------------------------------\n"
"Setting a cookie \"PREF\" via cookie interface:\n");
#ifdef WIN32
#define snprintf _snprintf
#endif
/* Netscape format cookie */
snprintf(nline, 256, "%s\t%s\t%s\t%s\t%u\t%s\t%s",
".google.com", "TRUE", "/", "FALSE", time(NULL) + 31337, "PREF", "hello google, i like you very much!");/* here we're creating a cookie request message */
res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); /* and we're loading that message */
if (res != CURLE_OK) {
fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res));
return 1;
}
/* HTTP-header style cookie */
snprintf(nline, 256,
"Set-Cookie: OLD_PREF=3d141414bf4209321; "
"expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com"); /* now we've setup a second cookie in the HTTP header format */
res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); /* and we're also adding it to the cookie repository */
if (res != CURLE_OK) {
fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res));
return 1;
}
print_cookies(curl); /* now we should see the two cookies we added */
res = curl_easy_perform(curl); /* now we should see google renew our cookie base on the two we added ourselves */
if (res != CURLE_OK) {
fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res));
return 1;
}
print_cookies(curl); /* and now we should see that one of the cookies has been updated with information from google */
}
else {
fprintf(stderr, "Curl init failed!\n");
return 1;
}
curl_global_cleanup(); /* and of course after we play we have to cleanup */
return 0;
}
@@ -0,0 +1,112 @@
/*****************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* $Id: https.c,v 1.2 2004/11/24 16:11:35 bagder Exp $
*/
#include <stdio.h>
#include <curl/curl.h> /* the standard opensource way of including the curl library */
#define SKIP_PEER_VERIFICATION
#define SKIP_HOSTNAME_VERFICATION
int curlHttpsExample1(void)
{
CURL *curl; /* this is the basic curl state machine */
CURLcode res; /* this is jsut the return code we check to see whether our curl state machine was successful, if it wasn't this would be assigned one of the many relatively useful return codes documented in the curl man page */
curl = curl_easy_init(); /* easy init is typically the fastest and best way to get a basic curl state machine initialized */
if(curl) { /* here we're just checking to make sure the state machine initialization was successful */
printf("\n========================https://sourceforge.net========================\n");
curl_easy_setopt(curl, CURLOPT_URL, "https://sourceforge.net"); /* we're going to connect to sourceforge's https sight since it a stable good example */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); /* this just enable verbose output so you can see more info as the curl state machine progresses through communicating with sourceforge */
#ifdef SKIP_PEER_VERIFICATION /* I never got a chance to figure out how to get certificate verification working, this would propably be a good thing to do */
/*
* If you want to connect to a site who isn't using a certificate that is
* signed by one of the certs in the CA bundle you have, you can skip the
* verification of the server's certificate. This makes the connection
* A LOT LESS SECURE.
*
* If you have a CA cert for the server stored someplace else than in the
* default bundle, then the CURLOPT_CAPATH option might come handy for
* you.
*/
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE); /* this is done to skip certificate verification */
#endif
#ifdef SKIP_HOSTNAME_VERFICATION /* didn't get hostname verification going either */
/*
* If the site you're connecting to uses a different host name that what
* they have mentioned in their server certificate's commonName (or
* subjectAltName) fields, libcurl will refuse to connect. You can skip
* this check, but this will make the connection less secure.
*/
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); /* this is done to skip hostname verification */
#endif
res = curl_easy_perform(curl); /* now that the state machine has been configured we tell it to act on our configuration parameters */
/* always cleanup */
curl_easy_cleanup(curl); /* because we used easy init we can also use easy cleanup, which does a bunch o the more tedious cleanup tasks */
}
else
{
return -1;
}
return res;
}
int curlHttpsExample2(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
printf("\n========================https://www.wiredsafety.org========================\n");
curl_easy_setopt(curl, CURLOPT_URL, "https://www.wiredsafety.org");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
#ifdef SKIP_PEER_VERIFICATION
/*
* If you want to connect to a site who isn't using a certificate that is
* signed by one of the certs in the CA bundle you have, you can skip the
* verification of the server's certificate. This makes the connection
* A LOT LESS SECURE.
*
* If you have a CA cert for the server stored someplace else than in the
* default bundle, then the CURLOPT_CAPATH option might come handy for
* you.
*/
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
#endif
#ifdef SKIP_HOSTNAME_VERFICATION
/*
* If the site you're connecting to uses a different host name that what
* they have mentioned in their server certificate's commonName (or
* subjectAltName) fields, libcurl will refuse to connect. You can skip
* this check, but this will make the connection less secure.
*/
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
#endif
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
else
{
return -1;
}
return res;
}
@@ -0,0 +1,200 @@
# Makefile - makefile for src/wrn/wmw
#
# Copyright (c) 2002-2007, 2009, 2011-2013, 2016, 2018 Wind River Systems, Inc.
#
# modification history
# --------------------
# 01j,15nov18,lan support openssl-1_0_2 for fixing VXW6-86992
# 01i,29nov16,r_w Support openssl-1_0_1 for fixing VXW6-85987
# 01h,18apr13,r_w eliminate warning, defect WIND00413440
# 01g,24jul12,r_w fix undefined SSL symbols issue on RTP space(defect WIND00365069)
# 01f,15dec11,r_w fix icc build error(defect WIND00251394)
# 01e,02nov09,mdk fix comment
# 01d,30oct09,m_z use VSB lib path for default
# (WIND00188837)
# 01c,17oct07,pee using ipcom rules.
# 01b,05sep07,msa Update with new C filenames.
# 01a,26sep06,msa Update this so it is the primary build point.
#
# DESCRIPTION
# This file contains the makefile rules for building the wmw library
#
#*/
WIND_HOME := $(subst \,/,$(WIND_HOME))
WIND_BASE := $(subst \,/,$(WIND_BASE))
WIND_USR := $(subst \,/,$(WIND_USR))
ifeq ($(SPACE),)
SPACE = kernel
endif
ifeq ($(SPACE),kernel)
TGT_DIR = $(WIND_BASE)/target
endif
ifeq ($(SPACE),user)
TGT_DIR = $(WIND_BASE)/target/usr
endif
LIB_BASE_NAME = curl
include $(VSB_DIR)/h/config/auto.conf
# Using CURL_BASE works whether or not we are under WIND_BASE.
CURL_BASE = ../../../../../..
ifeq ($(SPACE),kernel)
CURL_INCLUDE_DIRS= -I$(WIND_BASE)/target/h \
-I$(WIND_BASE)/target/h/wrn \
-I$(WIND_BASE)/target/h/wrn/coreip
endif
ifeq ($(SPACE),user)
CURL_INCLUDE_DIRS= -I$(WIND_BASE)/target/usr/h \
-I$(WIND_BASE)/target/usr/h/wrn \
-I$(WIND_BASE)/target/usr/h/wrn/coreip
endif
ifeq ($(findstring diab,$(TOOL)),diab)
CURL_INCLUDE_DIRS += -I$(CURL_BASE)/target/h/wrn/wm/curl
else
CURL_INCLUDE_DIRS += -idirafter $(CURL_BASE)/target/h/wrn/wm/curl
endif
CURL_INCLUDE_DIRS += -I$(CURL_BASE)/target/h/wrn/wm \
-I$(CURL_BASE)/target/src/wrn/wm/curl/lib \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/include \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/config \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/include \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/config \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/port/vxworks/include \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/port/vxworks/config
ifeq ($(_WRS_CONFIG_COMPONENT_IPCRYPTO_OPENSSL_1_0_2),y)
CURL_INCLUDE_DIRS += -I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/openssl-1_0_2/include \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-1_0_2/ssl \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-1_0_2/include
else
CURL_INCLUDE_DIRS += -I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/openssl-0_9_8/include \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-0_9_8/ssl \
-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-0_9_8/include
endif
WRN_DEFINITIONS= -D__VxWORKS__ -D__BIG_ENUMS__ -DWRN_PD_CODE
CURL_DEFINITIONS=
# Curl definitions for turning components on and off ...
# Curl definitions for supoorted features in vxWorks...
#CURL_DEFINITIONS+= -DCURL_DISABLE_COOKIES
#CURL_DEFINITIONS+= -DCURL_DISABLE_HTTP
#CURL_DEFINITIONS+= -DCURL_DISABLE_HTTPS
#CURL_DEFINITIONS+= -DCURL_DISABLE_VERBOSE_STRINGS
# Curl definitions for unsupported feaures which are disabled by default...
CURL_DEFINITIONS+= -DCURL_DISABLE_CRYPTO_AUTH
CURL_DEFINITIONS+= -DCURL_DISABLE_DICT
CURL_DEFINITIONS+= -DCURL_DISABLE_FILE
CURL_DEFINITIONS+= -DCURL_DISABLE_FTP
CURL_DEFINITIONS+= -DCURL_DISABLE_LDAP
CURL_DEFINITIONS+= -DCURL_DISABLE_TELNET
CURL_DEFINITIONS+= -DCURL_DISABLE_TFTP
#Curl definitions for defining the capabilities of the OS
CURL_DEFINITIONS+= -DHAVE_CONFIG_H
ifeq ($(SPACE),user)
CURL_DEFINITIONS+= -DCURL_DISABLE_HTTPS
else
CURL_DEFINITIONS+= -UCURL_DISABLE_HTTPS
endif
#SDA defaults to disabled on some architectures and breaks perfectly functioning builds
SDA_DISABLE=TRUE
ifeq ($(DEBUG),YES)
override EXTRA_DEFINE += -g -O0 -D__VxDEBUG__ -D__WRN_DEF_DEBUG__ $(WRN_DEFINITIONS) $(CURL_DEFINITIONS) $(CURL_INCLUDE_DIRS)
else
override EXTRA_DEFINE += $(WRN_DEFINITIONS) $(CURL_DEFINITIONS) $(CURL_INCLUDE_DIRS)
endif
SRC_FILES = libcurl_base64.c \
libcurl_connect.c \
libcurl_content_encoding.c \
libcurl_cookie.c \
libcurl_dict.c \
libcurl_easy.c \
libcurl_escape.c \
libcurl_file.c \
libcurl_formdata.c \
libcurl_ftp.c \
libcurl_getenv.c \
libcurl_getinfo.c \
libcurl_gtls.c \
libcurl_hash.c \
libcurl_hostares.c \
libcurl_hostasyn.c \
libcurl_hostip4.c \
libcurl_hostip6.c \
libcurl_hostip.c \
libcurl_hostsyn.c \
libcurl_hostthre.c \
libcurl_http.c \
libcurl_http_chunks.c \
libcurl_http_digest.c \
libcurl_http_negotiate.c \
libcurl_http_ntlm.c \
libcurl_if2ip.c \
libcurl_inet_ntop.c \
libcurl_inet_pton.c \
libcurl_krb4.c \
libcurl_ldap.c \
libcurl_llist.c \
libcurl_md5.c \
libcurl_mprintf.c \
libcurl_multi.c \
libcurl_netrc.c \
libcurl_parsedate.c \
libcurl_progress.c \
libcurl_security.c \
libcurl_select.c \
libcurl_sendf.c \
libcurl_share.c \
libcurl_speedcheck.c \
libcurl_sslgen.c \
libcurl_ssluse.c \
libcurl_strequal.c \
libcurl_strerror.c \
libcurl_strtok.c \
libcurl_strtoofft.c \
libcurl_telnet.c \
libcurl_tftp.c \
libcurl_timeval.c \
libcurl_transfer.c \
libcurl_url.c \
libcurl_version.c
# libcurl_memorydebug.c
OBJS= $(SRC_FILES:%c=%o)
DOC_FILES= $(SRC_FILES)
ifeq ($(SPACE),user)
include $(TGT_DIR)/make/defs.default
include $(WRVX_COMPBASE)/$(COMP_IPNET2)/osconfig/vxworks/make/defs.ipcom
include $(TGT_DIR)/make/rules.library
include $(WRVX_COMPBASE)/$(COMP_IPNET2)/osconfig/vxworks/make/rules.ipcom
else
include $(TGT_DIR)/h/make/defs.library
include $(WRVX_COMPBASE)/$(COMP_IPNET2)/osconfig/vxworks/make/defs.ipcom
include $(TGT_DIR)/h/make/rules.library
include $(WRVX_COMPBASE)/$(COMP_IPNET2)/osconfig/vxworks/make/rules.ipcom
endif
#ifeq ($(SPACE),user)
#rclean:
# rm -rf $(LIB_ROOT)/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/objcurl
# rm -rf $(LIB_ROOT)/$(VX_CPU_FAMILY)/$(CPU)/$(TOOL_COMMON_DIR)/libcurl.a
#endif
@@ -0,0 +1,58 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* $Id: amigaos.h,v 1.6 2006/01/09 13:17:14 bagder Exp $
***************************************************************************/
#ifndef LIBCURL_AMIGAOS_H
#define LIBCURL_AMIGAOS_H
#ifndef __ixemul__
#include <exec/types.h>
#include <exec/execbase.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <sys/socket.h>
#include "config-amigaos.h"
#ifndef select
# define select(args...) WaitSelect( args, NULL)
#endif
#ifndef inet_ntoa
# define inet_ntoa(x) Inet_NtoA( x ## .s_addr)
#endif
#ifndef ioctl
# define ioctl(a,b,c,d) IoctlSocket( (LONG)a, (ULONG)b, (char*)c)
#endif
#define _AMIGASF 1
extern void amiga_cleanup();
extern BOOL amiga_init();
#else /* __ixemul__ */
#warning compiling with ixemul...
#endif /* __ixemul__ */
#endif /* LIBCURL_AMIGAOS_H */
@@ -0,0 +1,101 @@
#ifndef __ARPA_TELNET_H
#define __ARPA_TELNET_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* $Id: arpa_telnet.h,v 1.12 2004/12/20 18:23:43 danf Exp $
***************************************************************************/
#ifndef CURL_DISABLE_TELNET
/*
* Telnet option defines. Add more here if in need.
*/
#define CURL_TELOPT_BINARY 0 /* binary 8bit data */
#define CURL_TELOPT_SGA 3 /* Supress Go Ahead */
#define CURL_TELOPT_EXOPL 255 /* EXtended OPtions List */
#define CURL_TELOPT_TTYPE 24 /* Terminal TYPE */
#define CURL_TELOPT_XDISPLOC 35 /* X DISPlay LOCation */
#define CURL_TELOPT_NEW_ENVIRON 39 /* NEW ENVIRONment variables */
#define CURL_NEW_ENV_VAR 0
#define CURL_NEW_ENV_VALUE 1
/*
* The telnet options represented as strings
*/
static const char * const telnetoptions[]=
{
"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD",
"NAME", "STATUS", "TIMING MARK", "RCTE",
"NAOL", "NAOP", "NAOCRD", "NAOHTS",
"NAOHTD", "NAOFFD", "NAOVTS", "NAOVTD",
"NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
"DE TERMINAL", "SUPDUP", "SUPDUP OUTPUT", "SEND LOCATION",
"TERM TYPE", "END OF RECORD", "TACACS UID", "OUTPUT MARKING",
"TTYLOC", "3270 REGIME", "X3 PAD", "NAWS",
"TERM SPEED", "LFLOW", "LINEMODE", "XDISPLOC",
"OLD-ENVIRON", "AUTHENTICATION", "ENCRYPT", "NEW-ENVIRON"
};
#define CURL_TELOPT_MAXIMUM CURL_TELOPT_NEW_ENVIRON
#define CURL_TELOPT_OK(x) ((x) <= CURL_TELOPT_MAXIMUM)
#define CURL_TELOPT(x) telnetoptions[x]
#define CURL_NTELOPTS 40
/*
* First some defines
*/
#define CURL_xEOF 236 /* End Of File */
#define CURL_SE 240 /* Sub negotiation End */
#define CURL_NOP 241 /* No OPeration */
#define CURL_DM 242 /* Data Mark */
#define CURL_GA 249 /* Go Ahead, reverse the line */
#define CURL_SB 250 /* SuBnegotiation */
#define CURL_WILL 251 /* Our side WILL use this option */
#define CURL_WONT 252 /* Our side WON'T use this option */
#define CURL_DO 253 /* DO use this option! */
#define CURL_DONT 254 /* DON'T use this option! */
#define CURL_IAC 255 /* Interpret As Command */
/*
* Then those numbers represented as strings:
*/
static const char * const telnetcmds[]=
{
"EOF", "SUSP", "ABORT", "EOR", "SE",
"NOP", "DMARK", "BRK", "IP", "AO",
"AYT", "EC", "EL", "GA", "SB",
"WILL", "WONT", "DO", "DONT", "IAC"
};
#define CURL_TELCMD_MINIMUM CURL_xEOF /* the first one */
#define CURL_TELCMD_MAXIMUM CURL_IAC /* surprise, 255 is the last one! ;-) */
#define CURL_TELQUAL_IS 0
#define CURL_TELQUAL_SEND 1
#define CURL_TELQUAL_INFO 2
#define CURL_TELQUAL_NAME 3
#define CURL_TELCMD_OK(x) ( ((unsigned int)(x) >= CURL_TELCMD_MINIMUM) && \
((unsigned int)(x) <= CURL_TELCMD_MAXIMUM) )
#define CURL_TELCMD(x) telnetcmds[(x)-CURL_TELCMD_MINIMUM]
#endif
#endif
@@ -0,0 +1,27 @@
#ifndef __BASE64_H
#define __BASE64_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* $Id: base64.h,v 1.17 2005/03/31 07:02:03 bagder Exp $
***************************************************************************/
size_t Curl_base64_encode(const char *input, size_t size, char **str);
size_t Curl_base64_decode(const char *source, unsigned char **outptr);
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1 @@
/* ca bundle path set in here*/
@@ -0,0 +1,124 @@
#ifndef CONFIG_H
#define CONFIG_H
#define OS "vxWorks"
#include <inetLib.h>
#include <sockLib.h>
#include <hostLib.h>
#include <time.h>
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/ossl_typ.h>
#ifdef BUFSIZE
#undef BUFSIZE
#endif
#define STDC_HEADERS
#define HAVE_SYS_SOCKET_H
#define HAVE_SYS_SELECT_H
#define HAVE_NETINET_IN_H
#define HAVE_NETDB_H
#define HAVE_SYS_IOCTL_H
#define IOCTL_3_ARGS
#define HAVE_FIONBIO
#define HAVE_SYS_STAT_H
#define HAVE_STDLIB_H
#define HAVE_UNISTD_H
#define HAVE_NET_IF_H
#define HAVE_SYS_TIME_H
#define HAVE_SELECT
#define HAVE_SOCKET
#define HAVE_GETTIMEOFDAY
/*#define HAVE_NETINET_IN_H 1*/
/*#define HAVE_SYS_SOCKET_H 1*/
/*#define HAVE_SYS_SELECT_H 1*/
/*#define HAVE_NETDB_H 1*/
/*#define HAVE_ARPA_INET_H 1*/
/*#define HAVE_UNISTD_H 1*/
/*#define HAVE_NET_IF_H 1*/
/*#define HAVE_SYS_TYPES_H 1*/
/*#define HAVE_GETTIMEOFDAY 1*/
/*#define HAVE_FCNTL_H 1*/
/*#define HAVE_SYS_STAT_H 1*/
/*#define HAVE_ALLOCA_H 1*/
/*#define HAVE_TIME_H 1*/
/*#define HAVE_STDLIB_H 1*/
/*#define HAVE_UTIME_H 1*/
/*#define TIME_WITH_SYS_TIME 1*/
/*#define HAVE_STRDUP 1*/
/*#define HAVE_UTIME 1*/
/*#define HAVE_INET_NTOA 1*/
/*#define HAVE_SETVBUF 1*/
/*#define HAVE_STRFTIME 1*/
/*#define HAVE_INET_ADDR 1*/
/*#define HAVE_MEMCPY 1*/
/*#define HAVE_SELECT 1*/
/*#define HAVE_SOCKET 1*/
/*#define HAVE_SIGACTION 1*/
/*#define HAVE_RAND_STATUS 1*/
/*#define HAVE_RAND_EGD 1*/
/*#define HAVE_FIONBIO 1*/
/*#define HAVE_SYS_IOCTL_H 1*/
/*Curl definitions for using OpenSSL... */
#ifndef CURL_DISABLE_HTTPS
#define HAVE_LIBSSL 1
#define HAVE_OPENSSL_CRYPTO_H 1
#define HAVE_OPENSSL_ERR_H 1
#define HAVE_OPENSSL_PEM_H 1
#define HAVE_OPENSSL_RSA_H 1
#define HAVE_OPENSSL_SSL_H 1
#define HAVE_OPENSSL_X509_H 1
#define USE_SSLEAY 1
#define USE_OPENSSL 1
#endif /*CURL_DISABLE_HTTPS*/
/*
* Floating point support is mainly used for extended precision counters
* and timers with sub-second resolution. The vxWorks implementation of
* libcurl defaults to not using floating point as the loss of information
* is unacceptible in the embedded world.
*
* If the developer dearly wishes to use doubles and the libcurl API as it
* was originally released and documented, uncomment the HAVE_FP_SUPPORT
* #define and make sure to start all libcurl tasks with the VX_FP_TASK
* flag set.
*
* I realize this changes the public API, but I'm claiming the Nuremberg
* defense.
*/
/*#define HAVE_FP_SUPPORT 1*/
/* ---------------------------------------------------------------- */
/* TYPEDEF REPLACEMENTS */
/* ---------------------------------------------------------------- */
/* Define this if in_addr_t is not an available 'typedefed' type */
#define in_addr_t unsigned long
#define ioctl(x, y, z) ioctl((int)x, (int)y, (int)z)
#define getsockname(x, y, z) getsockname((int)x, (struct sockaddr *)y, (int *)z)
#define getsockopt(v, w, x, y, z) getsockopt((int)v, (int)w, (int)x, (char *)y, (int *)z)
#define open(x, y) open((const char *)x, (int)y, S_IRWXU)
/* ---------------------------------------------------------------- */
/* FUNCTION REPLACEMENTS */
/* ---------------------------------------------------------------- */
#if 0
static int gettimeofday(struct timeval *tp, void *nothing)
{
(void)nothing; /* we don't support specific time-zones */
tp->tv_sec = (long)time(NULL);
tp->tv_usec = 0;
return 0;
}
#endif
#endif /*#ifndef CONFIG_H*/
@@ -0,0 +1,46 @@
#ifndef __CONNECT_H
#define __CONNECT_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* $Id: connect.h,v 1.20 2005/01/29 13:07:17 bagder Exp $
***************************************************************************/
int Curl_nonblock(curl_socket_t sockfd, /* operate on this */
int nonblock /* TRUE or FALSE */);
CURLcode Curl_is_connected(struct connectdata *conn,
int sockindex,
bool *connected);
CURLcode Curl_connecthost(struct connectdata *conn,
struct Curl_dns_entry *host, /* connect to this */
curl_socket_t *sockconn, /* not set if error */
Curl_addrinfo **addr, /* the one we used */
bool *connected /* truly connected? */
);
int Curl_ourerrno(void);
CURLcode Curl_store_ip_addr(struct connectdata *conn);
#define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */
#endif

Some files were not shown because too many files have changed in this diff Show More