Esempio n. 1
0
        public DialPlanCommand(DialPlanOpsEnum opType, string dst, int priority, string command, List <SIPProvider> sipProviders)
        {
            Operation    = opType;
            Destination  = dst;
            Priority     = priority;
            SIPProviders = sipProviders;

            int startBracketIndex = command.IndexOf("(");
            int endBracketIndex   = command.IndexOf(")");
            int dataLength        = endBracketIndex - startBracketIndex - 1;

            Command = command.Substring(0, startBracketIndex);
            Data    = command.Substring(startBracketIndex + 1, dataLength);
        }
        public DialPlanCommand(DialPlanOpsEnum opType, string dst, int priority, string command, List<SIPProvider> sipProviders)
        {
            Operation = opType;
            Destination = dst;
            Priority = priority;
            SIPProviders = sipProviders;

            int startBracketIndex = command.IndexOf("(");
            int endBracketIndex = command.IndexOf(")");
            int dataLength = endBracketIndex - startBracketIndex - 1;

            Command = command.Substring(0, startBracketIndex);
            Data = command.Substring(startBracketIndex + 1, dataLength);
        }
Esempio n. 3
0
        private void ParseDialPlan(string[] dialPlanEntries)
        {
            try
            {
                if (dialPlanEntries != null)
                {
                    foreach (string line in dialPlanEntries)
                    {
                        if (line == null || line.Trim().Length == 0 || line.Trim().StartsWith(";"))
                        {
                            // Do nothing, blank or comment line.
                        }
                        else
                        {
                            if (line.Trim().StartsWith(DIALPLAN_LINESTART_KEY))
                            {
                                // Split the line on the exten => data to get the data now that the line is recognised as a valid extension line.
                                string          op         = Regex.Match(line, @"exten\s*(?<op>[=~>]+).+").Result("${op}");
                                DialPlanOpsEnum opType     = DialPlanOpTypes.GetDialPlanOp(op);
                                string[]        lineFields = Regex.Split(line, op);

                                if (lineFields == null || lineFields.Length <= 1)
                                {
                                    logger.Warn("Dial plan line was invalid ignored: " + line);
                                }
                                else
                                {
                                    string dstPattern = null;
                                    int    priority   = 1;
                                    string app        = null;

                                    if (opType == DialPlanOpsEnum.Regex)
                                    {
                                        // Check for regex delimiter characters before splitting up the command line. If the regex contains commas it needs to be extracted first.
                                        if (lineFields[1].Trim().StartsWith(REGEX_DELIMITER_CHAR.ToString()))
                                        {
                                            int endDelimIndex = lineFields[1].Trim().Substring(1).IndexOf(REGEX_DELIMITER_CHAR);
                                            dstPattern = lineFields[1].Trim().Substring(1, endDelimIndex);
                                            string[] dataFields = lineFields[1].Trim().Substring(endDelimIndex + 3).Split(new char[] { ',' }, 2);
                                            priority = Convert.ToInt32(dataFields[0]);
                                            app      = dataFields[1];
                                        }
                                    }

                                    if (dstPattern == null)
                                    {
                                        string[] dataFields = lineFields[1].Trim().Split(new char[] { ',' }, 3);
                                        if (dataFields == null || dataFields.Length <= 2)
                                        {
                                            logger.Warn("Dial plan line was invalid ignored: " + line);
                                        }
                                        else
                                        {
                                            dstPattern = dataFields[0];
                                            priority   = Convert.ToInt32(dataFields[1]);
                                            app        = dataFields[2];
                                        }
                                    }

                                    if (dstPattern != null && app != null)
                                    {
                                        DialPlanCommand command = new DialPlanCommand(opType, dstPattern, priority, app, m_sipProviders);
                                        m_commands.Add(command);
                                    }
                                }
                            }
                            else
                            {
                                logger.Warn("Unknown dial plan command ignored: " + line);
                            }
                        }
                    }
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception ParseDialPlan. " + excp.Message);
                throw excp;
            }
        }