📄 endpointctrl.c
字号:
* FAIL.
*
* Comments :
*
* History :
* 2005/09/12 : Creation
*
* Date : Sep 12 2005, Frank Zhang
******************************************************************************/
LONG CheckValidityOfEndpointName(ENDPOINT_LOCAL_NAME *pName)
{
int i = 0;
BOOL bFoundAsterisk = FALSE;
BOOL bFoundDollar = FALSE;
Assert(pName);
for (i = 0; i < pName->wHierarchicalNum; i++)
{
if (strchr(pName->SubNames[i], '*') != NULL)
{
/* Found "*" in curretn name path, check if it is ALL wildcard, according
to RFC3435, the "$" should only be used from the right of "*" */
if ((strlen(pName->SubNames[i]) != 1) /* Only "*" in curretn name term ? */
|| bFoundDollar) /* "$" in the left of "*" ? */
{
return FAIL;
}
else
{
bFoundAsterisk = TRUE;
}
}
else if (strchr(pName->SubNames[i], '$') != NULL)
{
/* Found "$" in curretn name path, check if it is ALL wildcard */
if (strlen(pName->SubNames[i]) != 1) /* Only "$" in curretn name term ? */
return FAIL;
else
bFoundDollar = TRUE;
}
else if (bFoundAsterisk || bFoundDollar)
{
/* No wildcard in current name path, check whether has wildcard in the left,
according to RFC3435, Wild-carding should only be done from the right*/
return FAIL;
}
}
return OK;
}
/******************************************************************************
* Function : ParseEndpointName
*
* Description : Parse the endpoint name into hierarchical format
*
* Input parameters : pcSrcName - Pointer to endpoint name
*
* Output parameters : pLocalName - Store the parsed hierarchical format
* endpoint name
*
* Return value : OK - Endpoint name is valid and succeed to be parsed.
* FAIL - Endpoint name is invalid or hierarchical level
* exceed the level limit.
*
* Comments :
*
* History :
* 2005/09/13 : Creation
*
* Date : Sep 13 2005, Frank Zhang
******************************************************************************/
LONG ParseEndpointName(char *pcSrcName, ENDPOINT_LOCAL_NAME *pLocalName)
{
char *tmp;
Assert(pcSrcName);
Assert(pLocalName);
while (*pcSrcName != '\0')
{
if ((tmp = strchr(pcSrcName, '/')) != NULL)
{
/* If endpoint name reach hierarchical level limit ?
leave one space for the name path after the last '/' */
if ((pLocalName->wHierarchicalNum) >= MAX_HIERARCHICAL_LEVEL-1)
return FAIL;
else
{
Assert(tmp-pcSrcName >= 0);
pLocalName->SubNames[pLocalName->wHierarchicalNum]
= (char*)calloc((WORD)(tmp-pcSrcName)+1, sizeof(char));
if (pLocalName->SubNames[pLocalName->wHierarchicalNum] == NULL)
{
return FAIL;
}
strncpy(pLocalName->SubNames[pLocalName->wHierarchicalNum], pcSrcName,
(WORD)(tmp-pcSrcName));
pLocalName->wHierarchicalNum++;
pcSrcName = tmp+1;
}
}
else /* Reach terminal hierarchical level */
{
StrClone(&pLocalName->SubNames[pLocalName->wHierarchicalNum], pcSrcName);
pLocalName->wHierarchicalNum++;
break;
}
}
return CheckValidityOfEndpointName(pLocalName);
}
/******************************************************************************
* Function : FindEndpointNodeByHierarchicalName
*
* Description : Comparison function used to locate the target endpoint
* tree node by hierarchical name
*
* Input parameters : EndpointTreeNode - Pointer to endpoint tree node.
* pcPathName - Hierarchical name
*
* Output parameters :
*
* Return value : Return 0 if the endpoint tree node name is same with the
* target hierarchical name; otherwise return None 0.
*
*
* Comments :
*
* History :
* 2005/09/14 : Creation
*
* Date : Sep 14 2005, Frank Zhang
******************************************************************************/
int FindEndpointNodeByHierarchicalName(void *EndpointTreeNode, void *pcPathName)
{
MGCP_ENDPOINT_TREE_NODE *pNode = (MGCP_ENDPOINT_TREE_NODE*)EndpointTreeNode;
Assert(EndpointTreeNode);
Assert(pcPathName);
return StrCaseCmp((char*)pcPathName, pNode->TreeNodeName);
}
// 将 pNodeList 的所有叶子结点都链到 pFoundEndpointList 中
BOOL GetAllEpidFromTree(SLIST *pNodeList, SLIST *pFoundEndpointList, BOOL bInService)
{
MGCP_ENDPOINT_TREE_NODE *pNode = NULL;
if (pNodeList == NULL || pFoundEndpointList == NULL)
{
return FALSE;
}
SListReset(pNodeList);
if (pNodeList->head == NULL) // 下一层没有任何结点
{
return FALSE;
}
if ((pNode = SListGetCurData(pNodeList)) == NULL) // 第一个结点没有数据 ------> 这种情况不应当出现
{
return FALSE;
}
while (1)
{
if (pNode->SubNodeList.head != NULL) // 有子链表
{
if (GetAllEpidFromTree(&pNode->SubNodeList, pFoundEndpointList, bInService) == FALSE)
{
return FALSE;
}
}
else if (pNode->pEndpoint != NULL) // 当前结点有数据
{
if (bInService == TRUE)
{
if (pNode->pEndpoint->bInService == TRUE)
{
SListAppend(pFoundEndpointList, pNode);
}
}
else
{
SListAppend(pFoundEndpointList, pNode);
}
}
else // 没有子链表并且当前结点没有数据
{
return FALSE;
}
// 处理下一个结点
SListNextNode(pNodeList);
if ((pNode = SListGetCurData(pNodeList)) == NULL) // 当前链表扫描完毕
{
return TRUE;
}
}
}
/******************************************************************************
* Function : FindEndpointNodeByName
*
* Description : Find the endpoint tree node whose name is match the
* requested name
*
* Input parameters : pName - Pointet to the target endpoint name to be found.
* wNameLevel - Hierarchical level of the name in the
endpoint name to be checked.
* pNodeList - Endpoint node list store the endpoint handle
* to be checked.
*
* Output parameters : pFoundEndpointList - Store the endpoint tree node pointer
* whose name is match the target name.
*
* Return value : TRUE if at least one endpoint tree node is found;
* otherwise return FALSE.
*
* Comments :
*
* History :
* 2005/09/15 : Creation
*
* Date : Sep 15 2005, Frank Zhang
******************************************************************************/
BOOL FindEndpointNodeByName(ENDPOINT_LOCAL_NAME *pName, WORD wHierarchicalLevel,
SLIST *pNodeList, SLIST *pFoundEndpointList)
{
MGCP_ENDPOINT_TREE_NODE *pNode = NULL;
char *pcPathName = NULL;
if (pName == NULL || pNodeList == NULL || pFoundEndpointList == NULL)
{
return FALSE;
}
pcPathName = pName->SubNames[wHierarchicalLevel]; // wHierarchicalLevel == 0
// *@[192.168.7.40]
// pName->wHierarchicalNum == 1
// wHierarchicalLevel == 0
// 原程序此时就出错了
/* If current name term is the last in the name path ? */
if (wHierarchicalLevel == pName->wHierarchicalNum - 1)
{
if (strcmp(pcPathName, "*") == 0) /* Current name term is wildcard ? */
{
return (GetAllEpidFromTree(pNodeList, pFoundEndpointList, FALSE));
}
else if (strcmp(pcPathName, "$") ==0) /* Current name term is wildcard ? */
{
/* Append all the endpoint handles whose state is in service in this tree
node into the target list */
return (GetAllEpidFromTree(pNodeList, pFoundEndpointList, TRUE));
}
else /* No wildcard in name terms, only one endpoint should be found */
{
SListReset(pNodeList);
while((pNode = SListGetCurData(pNodeList)) != NULL)
{
/* Check whether the current path name is same as the tree node name */
if (StrCaseCmp(pcPathName, pNode->TreeNodeName) == 0)
{
SListAppend(pFoundEndpointList, pNode);
break;
}
SListNextNode(pNodeList);
}
}
}
else /* The current name term is not the last in the name path */
{
if (strcmp(pcPathName, "*") == 0 || strcmp(pcPathName, "$") == 0)
{
/* Current name term is wildcard, check all the tree nodes in this level */
SListReset(pNodeList);
while((pNode = SListGetCurData(pNodeList)) != NULL)
{
printf("\r\n %s : %d \r\n", __FILE__, __LINE__);
printf(" FindEndpointNodeByName( ... ) \r\n");
FindEndpointNodeByName(pName, wHierarchicalLevel+1, &pNode->SubNodeList,
pFoundEndpointList);
SListNextNode(pNodeList);
}
}
else
{
/* Current name term is specific, find the exect tree node */
SListReset(pNodeList);
while((pNode = SListGetCurData(pNodeList)) != NULL)
{
if (StrCaseCmp(pcPathName, pNode->TreeNodeName) == 0)
{
FindEndpointNodeByName(pName, wHierarchicalLevel+1, &pNode->SubNodeList,
pFoundEndpointList);
break;
}
else
{
SListNextNode(pNodeList);
}
}
}
}
if (pFoundEndpointList->count > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
/******************************************************************************
* Function : AddEndpointIntoEndpointTree
*
* Description : Add the endpoint into the endpoint tree.
*
* Input parameters : pEndpnt - Endpoint handle to be added.
* pEndpntTree - Pointer to the endpoint tree.
*
* Output parameters :
*
* Return value : OK - If the endpoint is added into the endpoint tree
* successfully.
* FAIL - If the endpoint name is invalid or the endpoint
* has already in the endpoint tree.
*
* Comments :
*
* History :
* 2005/09/16 : Creation
*
* Date : Sep 16 2005, Frank Zhang
******************************************************************************/
LONG AddEndpointIntoEndpointTree(H_MGCP_ENDPOINT pEndpnt,
MGCP_ENDPOINT_TREE *pEndpntTree)
{
ENDPOINT_LOCAL_NAME LocalName;
MGCP_ENDPOINT_TREE_NODE *pCurTreeNode = NULL;
SLIST *pCurNodeList = NULL;
WORD i = 0;
if (pEndpnt == NULL || pEndpntTree == NULL)
{
return FAIL;
}
memset(&LocalName, 0, sizeof(LocalName));
pCurNodeList = &pEndpntTree->Root;
/* Check endpoint name validity, no wildcard is permitted */
if (strchr(pEndpnt->pcEndpointName, '*') != NULL
|| strchr(pEndpnt->pcEndpointName, '&') != NULL)
{
return FAIL;
}
/* Parse local name into hierarchical fomrat */
if (ParseEndpointName(pEndpnt->pcEndpointName, &LocalName) != OK)
{
ClearEndpointLocalName(&LocalName);
return FAIL;
}
while (SListFind(pCurNodeList, LocalName.SubNames[i],
FindEndpointNodeByHierarchicalName) != NULL)
{
pCurTreeNode = SListGetCurData(pCurNodeList);
if (pCurTreeNode == NULL)
{
return FAIL;
}
pCurNodeList = &pCurTreeNode->SubNodeList;
i++;
/* If Reach the terminal tree node ? */
if (i >= LocalName.wHierarchicalNum)
{
LONG lRet;
/* The endpoint to be added has already in the endpoint tree ? */
if (pCurTreeNode->pEndpoint != NULL)
{
lRet = FAIL;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -