Features/Dial Plan/Regular Expressions

From Snom User Wiki

(Difference between revisions)
Jump to: navigation, search
Line 145: Line 145:
It is not necessarily the last word in this topic, as the user name part of the URI also may contain passwords.
It is not necessarily the last word in this topic, as the user name part of the URI also may contain passwords.
-
[[Category:Dial Plan]][[Category:Firmware V6]]
+
[[Category:Dial Plan]][[Category:Firmware V6]][[Category:Firmware V7]]

Revision as of 17:40, 24 April 2008

Author: Martin Kunkel Date: Mar-27-2004

Contents

Introduction

Identity/Line page - SIP Tab

On the phone, a dial plan may have the following functions:

  • Determine when a number is complete (e.g. ten-digit number in USA)
  • Automatically convert local numbers into global numbers (e.g. dialing 398330 in Berlin, Germany gets converted into +4930398330)
  • Automatically append the local domain (e.g. dialing 398330 gets converted into sip:398330@company.com;user=phone)

The phone is able to generate predefined dial plans from the user interface.

The dial plan depends on the outgoing line identity; therefore the snom phone supports 4 (snom300) - 7 (snom190) -12 (snom320/snom360) dial plan entries. Those entries are available in the SIP/Stack settings.

From a requirement point of view, dial plans are similar to the replacements known from ENUM or NAPTR. Therefore, snom built upon these mechanisms and added some more features that make them suitable for the above scenarios.

The first additional feature is that there can be more than one pattern. The patterns are separated by spaces. The first pattern which yields a match is taken.

Dial Plan Entries

Dial plan entries have three parts. The parts may be seperated by any character; typically the characters “!” or “|” are used for seperation.

The first part contains a pattern which is used for matching the dialled number. The second part contains the result or the dial plan step and the third (optional) part contains flags that set additional processing attributes.

The following flags are available:

  • The “d” flag means that the number is complete and can be dialed. Example:“|([0-9]{5})|sip:\1@test.com|d” means

that a number with five digits will be dialed automatically.

  • The “i” flag means that the comparisons should be done case-insensitive.

Substitutions

Substitutions are found in the second part of the dial plan entry. The following substitutions are available:

  • The “d” replacement inserts the name of the registrar. For example, „!*!sip:\1@\d!“

inserts the domain name behind the „@“ symbol.

  • The 1-9 replacements insert matches 1- 9 according to RFC2915. For example, “!(.+)!sip:\1!” inserts a “sip:” before the string (which is the first match).

Triggering ENUM

The phone supports ENUM lookup. In order to trigger the steps described in the ENUM RFC2916, the SIP URI must contain the parameter phone set to yes (“;phone=yes”).

The ENUM handling of the phone is described in a separate document.

Summary of extended regular expressions

See also the Internet for detail description of extended regular expressions.

  • To match a character, just use that character. If a character has a special meaning, it has to be escaped by the backslash character.
  • ^ matches the beginning of a string, $ matches the end of a string
  • dot („.“) matches every character.
  • To match a range of characters, use [ and ] and list the characters between the brackets. Ranges can be defined by the dash symbol. Ranges can be negated by the ^ symbol (for example [^0-9] matches all characters but numbers).
  • „+“, „*“, „?“ are multipliers which match at least once („+“), a unlimited number of times („*“) and at most once („?“). Multipliers can also be explicitly stated in curly brackets, for example {5,9} means at least 5 times, at most 9 times. {5,} means at least five times, {5} means exactly five times. Without multiplier, exactly one match is expected.
  • Brackets can be used to group matches (like in „(abc)?“ which matches „abc“ or the empty string).
  • The „|“ can be used to indicate alternate matches (like in „a|b“ which matches a or b).

Examples:

  • “(sip:)?(+?[0-9]+)@.+” matches SIP URI that contain a telephone number (like sip:+4930432343@isp.de or 30432343@isp.de).
  • “^sip:([^@]*)@(.*)” matches SIP URI that contain a user name
  • “http://([^/:]+)” matches typical http URL (like “http://bla.test.com/test.htm”)
  • “(A(B(C)DE)(F)G)” matches “ABCDEFG”
  • “(http://([^/:]+))|(SIP:([^@]+)@.*)” matches a http URL or a SIP URI.
  • “urn:cid:.+@([^\\.]+\\.)(.*)$” matches for example “urn:cid:39CB83F7.A8450130@fake.gatech.edu”.

Examples for Dial Plans

One common usage is to convert an emergency number into a SIP URL. This pattern could look like this:

!^911$!sip:emergency@local!d

Separated by the exclamation mark, it contains the pattern for the 911 and the resulting SIP URI. The d flag indicates that there is no need to press the Ok key after dialing this number.


Another common problem is to make the phone dial a number when the pound key is pressed. The pattern could look like this:

!([^#]+)#!sip:\1@\d!d

This dial plan entry will look for a pattern ending in a pound symbol and use this as the user name in a SIP URI (not including the pound symbol).


Matching an international number is easy. Just put the 011 pattern at the front of the pattern, like in

|^011([0-9]*)$|sip:+\1@\d;phone=yes|

This pattern requires that the user presses the Ok key in order to start the call.


To make the phone dial a number when a certain number of digits have been reached, the following dial plan entry could be used:

|^1([0-9]{10})$|sip:+1\1@\d;phone=yes|d

This pattern will look for a number starting with 1 and followed by ten digits. It will replace it with a URI that contain the hint to try an ENUM lookup first before sending it to the proxy.


Calling a complete URI is a little bit more difficult because of the number of allowed characters in the user name. The following character can be base for such a dial plan entry

|^([a-zA-Z0-9&=+\$,;?\-_.!~*‘()%]+@.+)|sip:\1|

Separating * codes from normal numbers is sometimes desired e.g. a plan is needed to add a leading 0 to an outgoing number not starting with 0 e.g. 3039833104 should be dialed as 03039833104 but not 03039833104 be converted to 003039833104. One could use the following for this purpose:

|^([1-9]{2})([0-9]{6,})$|sip:0\1\2@\d

But if a start code is followed by a destination e.g. *7939833452, it is not desired to convert it to 07939833452, because the pbx is expected to get the whole string and use it accordingly. Hence we can concatenate a plan to the one above to look after such exceptions:

"|^\*([0-9]*)$|sip:*\1@\d""|^([1-9]{2})([0-9]{6,})$|sip:0\1\2@\d"

It is not necessarily the last word in this topic, as the user name part of the URI also may contain passwords.

Personal tools
Interoperability