⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m2ppplib.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************** m2pppInterfaceStackObjGet - dereference ifIndex to PFW_STACK_OBJ pointer** It will return OK if a non-NULL pointer is paired to the input * <ifIndex> * - in which case it places its value in the position pointed by pStackObj -* or if a node with the input ifIndex key does not exist on the tree* - in which case it places NULL in the position pointed by pStackObj -* and ERROR if a NULL pointer it paired to the input <ifIndex>.** NOTE: The validity of the output should be checked by the caller.** RETURNS: OK or ERROR** INTERNAL: note that m2pppInterfaceStackObjGet does not check validity of* output. Hence, even though we do verify here that stackObj != NULL it still* may be the case that the the returned *pStackObj value is invalid.*/STATUS m2pppInterfaceStackObjGet    (    UINT32              ifIndex,    /* retrieval key */    PFW_STACK_OBJ **    pStackObj   /* placeholder of corresponding pointer */    )    {    M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY  keyEntry;    M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY *    retrievedEntryPtr;    GENERIC_ARGUMENT auxGenericArgument;        /* This routine is a wrapper of avlSearch.      * In our design compareMain considers as key of a node the whole node and     * accepts as arguments two M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY pointers.      * This design simplifies the handling of trees with multiple keys.     * After initializing keyEntry we pass its address to avlSearch.     */    if  ((ifIndex > MAX_IF_INDEX)  ||         (NULL == pStackObj))         {        return ERROR;        }    M2_PPP_LIB_SEM_TAKE(m2pppLibSem);    POPULATE_M2_PPP_KEY_ENTRY;    auxGenericArgument.p = (void *)(&keyEntry);        if  (NULL == (retrievedEntryPtr = avlSearch(m2pppIfIndexToStackObjTree,                                       auxGenericArgument,                                      compareMain)))        {        *pStackObj = NULL;        M2_PPP_LIB_SEM_GIVE(m2pppLibSem);        return OK;        }    else        {        if  ((*pStackObj = retrievedEntryPtr->stackObj) != NULL)            {            M2_PPP_LIB_SEM_GIVE(m2pppLibSem);            return OK;            }        else            {            logMsg("a null stackObj is paired to input ifIndex = %u\n",                    retrievedEntryPtr->ifIndex, 0,0,0,0,0);            M2_PPP_LIB_SEM_GIVE(m2pppLibSem);            return ERROR;            }        }    }/******************************************************************************** m2pppNextInterfaceStackObjGet - implementation support of GetNext SNMP PDU** It will return OK if a non-NULL pointer is paired to * a key that is * immediate successor to the the input <ifIndex> -in which case it places * its value in the position pointed by pStackObj and the value of the * corresponding key in the position pointed by nextIfIndex- * or if a node with such a key* does not exist on the tree - in which case it places NULL in the position * pointed by pStackObj - and ERROR if a NULL pointer is paired to the * immediate successor to the input key.** NOTE: The validity of the output should be checked by the caller.** RETURNS: OK or ERROR** INTERNAL: note that m2pppNextInterfaceStackObjGet does not check validity of* output. Hence, even though we do verify here that stackObj != NULL it still* may be the case that the the returned *pStackObj value is invalid.*/STATUS m2pppNextInterfaceStackObjGet    (    UINT32              ifIndex,        /* key ifIndex */    UINT32 *            nextIfIndex,    /* placeholder of successor ifIndex */    PFW_STACK_OBJ **    pStackObj       /* placeholder of retrieved pointer */    )    {    M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY  keyEntry;    M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY *    retrievedEntryPtr;    GENERIC_ARGUMENT auxGenericArgument;        /* This routine is a wrapper of avlSuccessorGet.     * In our design compareMain considers as key of a node the whole node and     * accepts as arguments two M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY pointers.      * This design simplifies the handling of trees with multiple keys.     * After initializing keyEntry we pass its address to avlSuccessorGet.     */    if  ((ifIndex > MAX_IF_INDEX)  ||         (NULL == nextIfIndex) ||         (NULL == pStackObj))         {        return ERROR;        }    M2_PPP_LIB_SEM_TAKE(m2pppLibSem);    POPULATE_M2_PPP_KEY_ENTRY;    auxGenericArgument.p = (void *)(&keyEntry);            if  (NULL == (retrievedEntryPtr =                   avlSuccessorGet(m2pppIfIndexToStackObjTree,                                   auxGenericArgument,                                  compareMain)))        {        *pStackObj = NULL;        *nextIfIndex = INVALID_IF_INDEX;        M2_PPP_LIB_SEM_GIVE(m2pppLibSem);        return OK;        }    else        {        if  ((*pStackObj = retrievedEntryPtr->stackObj) != NULL)            {            *nextIfIndex = retrievedEntryPtr->ifIndex;            M2_PPP_LIB_SEM_GIVE(m2pppLibSem);            return OK;            }        else            {            logMsg("ifIndex = %u; next node's key = %u, stackObj = NULL\n",                     ifIndex, retrievedEntryPtr->ifIndex, 0,0,0,0);            M2_PPP_LIB_SEM_GIVE(m2pppLibSem);            return ERROR;            }        }    }/******************************************************************************** m2pppPreviousInterfaceStackObjGet - analog of m2pppNextInterfaceStackObjGet** It will return OK if a non-NULL pointer is paired to a key that is * immediate predecessor to the the input <ifIndex> - in which case it places * its value in the position pointed by pStackObj - or if a node with such a key* does not exist on the tree - in which case it places NULL in the position * pointed by pStackObj - and ERROR otherwise.** NOTE: The validity of the output should be checked by the caller.** RETURNS: OK or ERROR** INTERNAL: note that m2pppPreviousInterfaceStackObjGet does not check validity* of output. Hence, even though we do verify here that stackObj != NULL it still* may be the case that the the returned *pStackObj value is invalid.*/STATUS m2pppPreviousInterfaceStackObjGet    (    UINT32              ifIndex,         /* key ifIndex */    UINT32 *            previousIfIndex, /* placeholder of predecessor index */    PFW_STACK_OBJ **    pStackObj        /* placeholder of retrieved pointer */    )    {    M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY  keyEntry;    M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY *    retrievedEntryPtr;    GENERIC_ARGUMENT auxGenericArgument;        /* This routine is a wrapper of avlPredecessorGet.     * In our design compareMain considers as key of a node the whole node and     * accepts as arguments two M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY pointers.      * This design simplifies the handling of trees with multiple keys.     * After initializing keyEntry we pass its address to avlPredecessorGet.     */    if  ((ifIndex > MAX_IF_INDEX)  ||         (NULL == previousIfIndex) ||         (NULL == pStackObj))         {        return ERROR;        }    M2_PPP_LIB_SEM_TAKE(m2pppLibSem);    POPULATE_M2_PPP_KEY_ENTRY;    auxGenericArgument.p = (void *)(&keyEntry);            if  (NULL == (retrievedEntryPtr =                  avlPredecessorGet(m2pppIfIndexToStackObjTree,                                     auxGenericArgument,                                    compareMain)))        {        *pStackObj = NULL;        *previousIfIndex = INVALID_IF_INDEX;        M2_PPP_LIB_SEM_GIVE(m2pppLibSem);        return OK;        }    else        {        if  ((*pStackObj = retrievedEntryPtr->stackObj) != NULL)            {            *previousIfIndex = retrievedEntryPtr->ifIndex;            M2_PPP_LIB_SEM_GIVE(m2pppLibSem);            return OK;            }        else            {            logMsg("ifIndex = %u; previous node's key = %u, stackObj = NULL\n",                    ifIndex, retrievedEntryPtr->ifIndex, 0,0,0,0);            M2_PPP_LIB_SEM_GIVE(m2pppLibSem);            return ERROR;            }        }    }/******************************************************************************** m2pppLibClear - deinstall the ifIndex to PFW_STACK_OBJ pointer database** It releases all resources reserved by the m2pppLib.** RETURNS: OK or ERROR.** INTERNAL: the implicit arguments of this routine are m2pppLibSem and * m2pppIfIndexToStackObjTreePtr, the protecting the library semaphore and * the pointer to the root of the database tree.*/STATUS m2pppLibClear(void)    {    M2_PPP_LIB_SEM_TAKE(m2pppLibSem);    if  (avlTreeErase(m2pppIfIndexToStackObjTreePtr) != OK)        {        logMsg("Tree memory deallocation failed\n",0,0,0,0,0,0);        M2_PPP_LIB_SEM_GIVE(m2pppLibSem);                return ERROR;        }    else        {        if  (semDelete(m2pppLibSem) != OK)            {            logMsg("semDelete failed; m2pppLibSem is likely invalid\n",                   0,0,0,0,0,0);            return ERROR;            }        else            {            m2pppLibSem = NULL;			return OK;            }        }    }/******************************************************************************** compareMain - it compares the relative order of two nodes. * * In order to accommodate multiple key ordering it receives as input * pointers to the nodes themselves and not just their keys.** nodePtr and keyPtr should address M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY nodes.** Note that the caller holds the mutual exclusion semaphore m2pppLibSem.* * RETURNS: +1 if the nodes are in correct order, -1 if they are in reverse* order, and 0 otherwise.* * NOMANUAL*/LOCAL int compareMain    (    void *              nodePtr,     GENERIC_ARGUMENT    keyPtr    )    {    UINT32  nodeKey, key;    nodeKey =   ((M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY *)nodePtr)->ifIndex;    key =       ((M2_PPP_IF_INDEX_TO_STACK_OBJ_ENTRY *)keyPtr.p)->ifIndex;     if  (nodeKey == key) return 0;    return ((nodeKey>key) ? -1 : 1);    }/* #include "m2pppLibTest.c" */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -