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

📄 endpointctrl.c

📁 内容正如其名
💻 C
📖 第 1 页 / 共 5 页
字号:
          || 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));                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);}/****************************************************************************** * 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;  char *pcPathName = pName->SubNames[wHierarchicalLevel];  /* 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 ? */    {      /* Append all the endpoint handles in this tree node into the target list */      SListReset(pNodeList);      while ((pNode = SListGetCurData(pNodeList)) != NULL)      {        if (pNode->pEndpoint != NULL)          SListAppend(pFoundEndpointList, pNode);                SListNextNode(pNodeList);      }    }    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 */      SListReset(pNodeList);      while ((pNode = SListGetCurData(pNodeList)) != NULL)      {        /* Only add the enpoint in service state */        if (pNode->pEndpoint != NULL            && pNode->pEndpoint->bInService)          SListAppend(pFoundEndpointList, pNode);                SListNextNode(pNodeList);      }    }    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)      {              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;  SLIST *pCurNodeList = &pEndpntTree->Root;  WORD i = 0;  memset(&LocalName, 0, sizeof(LocalName));  /* 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);        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      {        /* New endpoint, but the tree node is already existed, add into the tree */        pCurTreeNode->pEndpoint = pEndpnt;        lRet = OK;      }      /* Clear the local name */      ClearEndpointLocalName(&LocalName);      return lRet;    }  }  /* New endpoint whose local name has new hierarchical format, add into the     endpoint tree */  while (i < LocalName.wHierarchicalNum)  {    MGCP_ENDPOINT_TREE_NODE *pNewNode      = (MGCP_ENDPOINT_TREE_NODE*)calloc(1, sizeof(MGCP_ENDPOINT_TREE_NODE));    Assert(pNewNode);    /* Terminal node ? */    if (i == LocalName.wHierarchicalNum-1)      pNewNode->pEndpoint = pEndpnt;        StrClone(&pNewNode->TreeNodeName, LocalName.SubNames[i]);    SListAppend(pCurNodeList, pNewNode);    pCurNodeList = &pNewNode->SubNodeList;    i++;  }    ClearEndpointLocalName(&LocalName);  return OK;}/****************************************************************************** * Function          : FindEndpointByName * * Description       : Find the endpoints whose name are match the requested *                     name. If the requested name use wildcard, the found *                     endpoint number maybe more than one. *                      * Input parameters  : pcName - Target endpoint name.  *                     pEndpntTree - Pointer to the endpoint tree in which the *                                   endpoints are checked. * * Output parameters : pFoundEndpointList - Store the endpoint handle whose *                                          name match the requested name. * * Return value      : Return TRUE if endpoint is found; otherwise return FALSE. * * Comments          :  * * History           : *  2005/09/16       : Creation * * Date              : Sep 16 2005, Frank ZHANG ******************************************************************************/BOOL FindEndpointByName(char *pcName, MGCP_ENDPOINT_TREE *pEndpntTree,                        SLIST *pFoundEndpointList){  ENDPOINT_LOCAL_NAME LocalName;  BOOL bRet = FALSE;    Assert(pcName);  Assert(pEndpntTree);  Assert(pFoundEndpointList);  memset(&LocalName, 0, sizeof(LocalName));  if (pcName != NULL )  {    /* Parse local name */    if (ParseEndpointName(pcName, &LocalName) == OK)    {          if (FindEndpointNodeByName(&LocalName, 0, &pEndpntTree->Root,                                 pFoundEndpointList))      {        /* Endpoint node data is pointing to MGCP_ENDPOINT_TREE_NODE,           change it to pointer to H_MGCP_ENDPOING */        MGCP_ENDPOINT_TREE_NODE *pNode;        SListReset(pFoundEndpointList);        while((pNode = SListGetCurData(pFoundEndpointList)) != NULL)        {          /* If current Endpoint tree node contain no endpoint handle, remove it,             such as find "MG01" in endpoint tree "MG01/S1", endpoint tree             node is found, but no endpoint under this node */          if (pNode->pEndpoint != NULL)          {            bRet = TRUE;            pFoundEndpointList->cur->data = pNode->pEndpoint;            SListNextNode(pFoundEndpointList);          }          else          {            /* No endpoint handle under this found tree node, remove it */            SListDelCurNode(pFoundEndpointList);          }        }      }    }    ClearEndpointLocalName(&LocalName);  }  return bRet;}/****************************************************************************** * Function          : RemoveEndpointFromEnpointTree

⌨️ 快捷键说明

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