• News
  • Idefisk
  • Tools
  • Tutorials
  • Forum
  • Reviews
  • VoIP Providers
  • Archives
  • Gallery
ZOIPER SIP softphone
Back to Tutorials

6.1.1.1. CUT (dialplan function) - NEW

1. CUT - this function allows you to split the content of a variable by using a specified delimiter.

NOTE:Information about the Asterisk functions could be obtained by typing the show functions command.

Information about a particular function could be obtained by typing the show function <function name> on the Asterisk CLI command.

NOTE: In Asterisk versions 1.2 and up there are several applications which are mark as deprecated and which are no longer supported.

These applications will now become functions and these functions will be used in combination with the Set application.

You have to know that their functionality will be the same, but with a different syntax.

The CUT function is one of those functions which will replace the old applications. In this tutorial we will show you its syntax and possible usage.

Check out the old syntax of the Cut application here
 


Syntax:

Set(variable1=${CUT(variable2|delimiter|fieldspec)})

 


List of the possible options

variable1 - The new variable where you want to put the already cut part.
variable2 - this is the variable which content you would like to split.
delimiter - the delimiter is set by default to "-"
fieldspec - number of the field you want (1-based offset). It may also be specified as a range (with -) or group of ranges and fields (with &)

 


Purpose and usage

This function allows you to cut a certain number of characters from the value of a variable.

Below, we will give you an example.

 


Prerequisites

To use this application you need a working Asterisk PBX with registered users in iax.conf, sip.conf or mgcp.conf(It depends on which protocol you would like to use) and made extensions. We are using Asterisk version1.2.1.

To see how the application works we recommend you to use our IAX softphone Idefisk. You could download it from here. Please also read our tutorial to learn how to configure it to work with Asterisk PBX.

 


Asterisk PBX configurations

iax.conf Configurations

We need to create one user in the iax.conf file. This is because we are going to use the IAX2 protocol. If you want to use other protocol, such as SIP or MGCP, you have to do the configurations below respectively in sip.conf or mgcp.conf.

iaxoneuser.jpg

So, we have registered the user user1

Type=friend means that this user can make and receive calls. Host=dynamic means that the IP is not static but dynamic through a DHCP server. Allow=all means that the line which this user will use, could support all audio codecs. Context=test - this shows that this user is working with the extensions in this context of the configuration file extensions.conf.


extensions.conf Configurations

Now lets take a look at the extensions.conf file.

extcutnew.jpg

On the picture above you could see our extensions.conf file.

In this example, when somebody dials 100, the call will be answered by the Answer application. The next executed extension will be the one which contains the ChanIsAvail application. As arguments in its brackets we have set IAX2/10.3.3.43. This will check whether this channel is available or not. If the channel is available then it will be set in the ${CHANISAVAIL} variable. We have one extension with the NoOp application, which we will use to check the content of the AVAILCHAN variable.


Because we are going to use only the first four signs before the first "/" character, we have to Cut the unnecessary part.

We want only the IAX2 abbreviation and we will use the CUT function to take only these characters.

We have to use the Set application. As argument in the brackets write the following - NEWVAR=${CUT(AVAILCHAN|/|1)}. So, this actually will cause the cut of the all characters before the first slash character and then these characters will be stored in the NEWVAR variable.

In the brackets of the CUT function we have AVAILCHAN|/|1. AVAILCHAN is the variable from which we would like to cut something. The next argument is the delimiter. By default it is set to "-". In our case we will change it to the /character. The last argument is the fieldspec one. We have set this parameter to 1, which means that the application will Cut all characters before the first "/" character. In other words, the application will start from the first sign and it will cut all the following characters until it reaches the first "/" character. The cut characters will be saved in the variable NewVar. In our case these characters are IAX2.

NOTE: Please, pay attention, that the both variables NEWVAR and AVAILCHAN are without the "${}" characters.

We use another NoOp application to check whether the result is the desired one. In our case this application returns IAX2, which is exactly what we have wanted.

So, lets use this variable for something. Lets call an user through the available channel. For that purpose we will use the Dial application. As argument in its brackets we will set the following: ${NewVar}/user1. Actually, ${NewVar} contains the IAX2 string, so the user user1 will be called through the channel IAX2.

Please pay attention that here, the variable NewVar is used with the ${} characters.

NOTE: The function CUT is case sensitive. You always have to write it in your dialplans with capital letters.

In order to be sure that the Asterisk PBX will hang up the line, when the conversation is over, it is a good idea to use the Hangup application.

 


2. Screenshots of what you could see on the CLI of the Asterisk PBX

clicutnew.jpg

 


3. Additional information

For more information about extensions.conf you can check here.
For more information about iax.conf you can check here.

This application is tested with our IAX softphone Idefisk. You can download it from here. For more information about this softphone please read our tutorial.

If you would like to test this application with the SIP channel you can read our tutorials about the SIP Softphones to learn how to configure them to work with Asterisk PBX

More information about the Set application could be found here

 


4. Uploaded files

CUT.tar - configuration files
 

 
User Comments
Manoj Kumar (man2man_oj at yahoo dot com)
10 March 2006 09:53:31
it is very nice to asterisk beginners.

Thanks
 
Add Comment
Name:
Email:
Comment:
In order to prevent automatic posting on our website, we kindly request you to type in the number you see in the picture below.
Image Verification:
 

Latest Headlines:

  • T.38 faxing with Zoiper 2.15 is now easier than ever
    section: voip software
  • Asterisk 1.4.21 Released
    section: Asterisk
  • Asterisk 1.4.20 Released
    section: Asterisk
  • Asterisk 1.4.20-rc2 Released
    section: Asterisk
  • Asterisk 1.4.20-rc1 Now Available
    section: Asterisk
  • News Archives (older news)

Latest Tutorials:

  • VMAuthenticate (dialplan application)
    added 01/Mar/2008 15:57
  • Siptronic ST-530
    added 06/Nov/2007 17:57
  • Siemens C455 IP hardphone
    added 05/Nov/2007 10:24
  • Zoiper
    added 22/Oct/2007 17:53
  • Grandstream GXP-2020
    added 15/Oct/2007 18:17

Latest Comments:

  • It happened that a Dog <a href="http://w...
    section: voip hardware
  • It happened that a Dog <a href="http://w...
    section: voip hardware
  • thinks i installation <A href=\"http:...
    tutorial: Installation on CentOS
  • uh, why not just use the asterisk packag...
    tutorial: Installation on Debian
  • <br /> <p><a href="http://www.7be.com">...
    section: voip software
 
contact us at: support@asteriskguru.com - asterisKGuru.com © all rights reserved   |   *asterisk is registered trademark of © Digium™