예제 #1
0
 //Flat Tree
 private void CreateBlocks(Dictionary<string, Block> blocks, Node node)
 {
     Block block = new Block(node);
     if (node.Children.Count > 0)
     {
         if (node.Name != "Start")
         {
             blocks.Add(block.InstanceGUID, block);
         }
         foreach (Node child in node.Children)
         {
             CreateBlocks(blocks, child);
         }
     }
 }
예제 #2
0
 private bool DetectExistingConditionStartPoint(IEnumerable<ServiceFlow> serviceFlows, Block newStartblock)
 {
     bool conflictFound = false;
     foreach (ServiceFlow currentserviceFlow in serviceFlows)
     {
         Block startblock = currentserviceFlow.Blocks[currentserviceFlow.FirstBlockGUID];
         if (startblock.BlockType == Block.BlockTypes.Condition)
         {
             if (newStartblock.GlobalGUID == startblock.GlobalGUID)
             {
                 foreach (String key in newStartblock.NextBlocks.Keys)
                 {
                     if (startblock.NextBlocks.ContainsKey(key))
                     {
                         conflictFound = true;
                     }
                 }
             }
         }
     }
     return conflictFound;
 }
예제 #3
0
 //Pruned section of tree starting at node
 private void FillBlocks(Node node, Block block)
 {
     if (node == null) return;
     if (node.Children.Count > 0)
     {
         foreach (Node child in node.Children)
         {
             switch (node.GetType().Name)
             {
                 case "ServiceNode":
                 case "ConditionNode":
                     block.AddChild(child.Name, new Block(child));
                     break;
                 case "ConditionValueNode":
                 case "SIPResponseNode":
                     block.AddChild(child.InstanceGUID, new Block(child));
                     break;
                 default:
                     Console.WriteLine("Unkown node type" + child.GetType().Name);
                     break;
             }
             //FillBlocks(child, block);
         }
     }
 }
예제 #4
0
 public void AddChild(string key, Block block)
 {
     NextBlocks.Add(key, block);
 }
예제 #5
0
 private static Address RouteService(Message request, Block Block, string toId, string fromId)
 {
     string callID = request.First("Call-ID").ToString();
     if (_activeFlows.ContainsKey(callID))
     {
         ActiveFlow af = _activeFlows[callID];
         af.LastRequest = request;
         af.LastBlock = Block;
     }
     else
     {
         ActiveFlow af = new ActiveFlow();
         af.OriginalRequest = request;
         af.LastRequest = request;
         af.LastBlock = Block;
        _activeFlows.Add(callID,af);
     }
     Address dest = new Address(Block.DestURI);
     return dest;
 }
예제 #6
0
 private static Address MatchCondition(Message request, Block firstBlock, string toId, string fromId)
 {
     Dictionary<string, Block> conditionValues = firstBlock.NextBlocks;
     // Look up what condition it is (pull out of condition manager)
     if (_context.ContainsKey(toId))
     {
         if (_context[toId].ContainsKey(firstBlock.ConditionType.ToLower()))
         {
             string conditionOption = _context[toId][firstBlock.ConditionType.ToLower()];
             if (conditionValues.ContainsKey(conditionOption))
             {
                 return CheckServiceBlock(request, conditionValues[conditionOption], toId, fromId);
             }
         }
     }
     // Hard coded contact matching for now
     if (firstBlock.ConditionType.ToLower() == "contact")
     {
         if (firstBlock.Name.ToLower() == "calling party")
         {
             foreach (string key in conditionValues.Keys)
             {
                 if (fromId.ToLower().Contains(key.ToLower()))
                 {
                     return CheckServiceBlock(request, conditionValues[key], toId, fromId);
                 }
             }
         }
     }
     return new Address(request.Uri.ToString());
 }
예제 #7
0
        private static void ContinueRoutingMessage(Message request, Proxy pua, Block block)
        {
            SIPURI to = request.Uri;
            string toID = to.User + "@" + to.Host;

            Address from = (Address)(request.First("From").Value);
            string fromID = from.Uri.User + "@" + from.Uri.Host;

            Address dest = new Address(to.ToString());
            Address temp_dest = CheckServiceBlock(request, block, toID, fromID);
            if (temp_dest != null)
            {
                dest = temp_dest;
            }
            if (dest.ToString().Contains("anonymous.invalid"))
            {
                Message proxiedMessage = pua.CreateResponse(403, "Forbidden");
                pua.SendResponse(proxiedMessage);
            }
            else
            {
                Message proxiedMessage = pua.CreateRequest(request.Method, dest, true, true);
                proxiedMessage.First("To").Value = dest;
                pua.SendRequest(proxiedMessage);
            }
        }
예제 #8
0
 private static Address CheckServiceBlock(Message request, Block firstBlock, string toId, string fromId)
 {
     Address dest = null;
     bool matched = false;
     switch (firstBlock.BlockType)
     {
         case Block.BlockTypes.Condition:
             dest = MatchCondition(request, firstBlock, toId, fromId);
             break;
         case Block.BlockTypes.Service:
             dest = RouteService(request, firstBlock, toId, fromId);
             break;
         case Block.BlockTypes.ConditionOption:
             dest = CheckServiceBlock(request, firstBlock.NextBlocks.Values.First(), toId, fromId);
             break;
         case Block.BlockTypes.SIPResponse:
             if (firstBlock.NextBlocks.Count > 0)
             {
                 dest = CheckServiceBlock(request, firstBlock.NextBlocks.Values.First(), toId, fromId);
             }
             else
             {
                 dest = null;
             }
             break;
         default:
             break;
     }
     return dest;
 }