//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); } } }
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; }
//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); } } }
public void AddChild(string key, Block block) { NextBlocks.Add(key, block); }
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; }
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()); }
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); } }
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; }