GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - InterLinked1/patternmatchgen: Asterisk dialplan pattern match generator

BranchesTags
Open more actions menu

Latest commit

 

History

8 Commits
8 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
LICENSE
LICENSE
 
 
PatternMatchGen.php
PatternMatchGen.php
 
 
PatternMatchGenTest.php
PatternMatchGenTest.php
 
 
README.md
README.md
 
 

Repository files navigation

PatternMatchGen

Asterisk dialplan pattern match generator

This is a simple program that can be used to automatically generate dialplan pattern matches for use in the Asterisk dialplan. It does the opposite of what Asterisk does: instead of using a pattern match to represent a collection of extensions, it converts a collection of extensions into the corresponding pattern match representation(s).

The basic premise of this program is actually very simple. Given a starting number and an ending number, generate dialplan pattern matches for this number range, ideally using the fewest possible number of pattern matches, without encompassing any numbers that do not fall in the provided range. It's not really that difficult, it just involves a lot of math.

e.g. given 234, 742:

exten => _23[4-9]
exten => _2[4-9]XX
exten => _[3-6]XX
exten => _7[0-3]X
exten => _74[0-2]

This is what we will call the minimally encompassing set of pattern matches. The goal of this program is to generate this information.

For multiple ranges (disjoint number ranges), call the function multiple times. Typically, what you'll want to do is retrieve a window range using SQL and then for each range that you get, call this function.

Usage

Parameters

$ptr = pointer to array to store result.
$min = starting number
$max = ending number

Return Value

The constructor function does not explicitly return anything, but it fills an array containing key value pairs corresponding to the starting number and the quantity of additional numbers in that range (e.g. 0 for just that number, 1 for two consecutive numbers, etc.). This is sufficient to then generate pattern matches using some trivial logic.

Example

$min = 234;
$max = 742;
$numberGroups = array();
$ptr = &$numberGroups;
new \PatternMatchGen($ptr, $min, $max);
foreach ($numberGroups as $start => $qty) {
	$ext = \PatternMatchGen::matchCallback($start, $qty);
	$ext .= ",1,Return(somethingcool)\n";
	echo $ext; # print the full extenpattern,priority,app that we just generated.
}

Result

exten => _23[4-9],1,Return(somethingcool)
exten => _2[4-9]XX,1,Return(somethingcool)
exten => _[3-6]XX,1,Return(somethingcool)
exten => _7[0-3]X,1,Return(somethingcool)
exten => _74[0-2],1,Return(somethingcool)

Demo Usage from the command line:

php PatternMatchGen.php <min> <max>

About

Asterisk dialplan pattern match generator

Topics

asteriskasterisk-dialplandialplan

Resources

Readme
Apache-2.0 license
Activity

Stars

1 star

Watchers

1 watching

Forks

1 fork
Report repository

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.