Asterisk Dial Plan Compiler

Welcome to the Asterisk Dial Plan Compiler Home Page. Here you can find any information related to this program.

What is the Dial Plan Compiler?

This program lets you use a different syntax to program Asterisk dial plans without having to number each line, using references instead. This way, if you insert or delete or move lines around inside an extension, you don't need to double check every reference you had in every Goto or GotoIf in other extensions. You just "compile" your code with the DPC and it will transform it into something Asterisk understands. This saves a lot of time when you have complex dial plans, for example if you're programming an IVR.

You don't have to learn yet another language or anything. There are only minor differences between the Asterisk dial plan code and the Dial Plan Compiler code; mainly, that you only type the extension number once, including its context, and below it you put all your dial plan code, without line numbers and without repeating the extension in every line. Any reference to another line in the same extension or in a different one, is made with a simple syntax that points to a label instead of a line number. You have to mark the destination line with the same label, and when you compile your code, all that will be replced with the correct line numbers.

Here's an example of a simple source file for DPC:

X:example:501 ; some comment for the extension
SetVariable(value=10)
Answer
L:enter-pin:Read(pin,enter-pin,4)
GotoIf($["${pin}" = "1234"]?(L:ok)) ; goto label "ok"
playback(incorrect-pin)
Goto((L:enter-pin))
L:ok:playback(ok)
Goto((L:number:599))
Hangup

X:example:599
NoOp(The password was correct)
L:number:Read(number,enter-number,7)
Dial(${number})

OK, so what do I need to run it?

The compiler is written in Java 1.4.2, but it only uses very basic classes so it might run on Java 1.3.1 although I haven't tested it there (and we're already on version 1.5 so maybe it's time to upgrade your runtime anyway).

Of course you only need the JRE in the machine where you run the compiler, you don't need the JRE in the machine that runs Asterisk for this. Remember, this is only a compiler for complex dial plan files.

I decided to write it in Java for two reasons:

  1. Lately I have become mainly a Java developer, so I figured it would be fastest for me to write this in Java. I know that maybe a perl script can do the same thing in a half-line but I don't know perl and don't have time to learn right now.
  2. Scalability. Adding a GUI to this shouldn't be hard. I'm also planning to write some utility to reverse-compile Asterisk dial plan files, so that if you already have a complex dial plan, you can transform it to the DPC source format in case you have to modify the code in some extension and don't want to check all the references.
  3. Portability. I suppose most Asterisk developers work on Linux, but for example I'm working on a Mac, and now that Asterisk runs on windows (at least for SIP) I guess there might be someone editing dial plans on windows.

Usage

For the moment, the compiler is just a command-line program. I am thinking how to add an optional GUI, in case it's necessary, but being a compiler, a command line should be enough...

Suppose you have downloaded the jar file into /my/jars. You're in the directory with your source file. You can just type:

java -jar /my/jars/ast-dpc.jar myfile.txt /etc/asterisk/myfile.conf

That's it. The compiler reads myfile.txt and writes the result to myfile.conf in /etc/asterisk, overwriting it if it already exists.

If the compiler finds any references that cannot be resolved it will warn you.

Future plans

  • Give more structure to the documentation (not the javadocs but this)
  • Translate the whole thing to English (messages are in Spanish right now)
  • Translate all javadocs to English
  • Add a reverse-compiler that can take a regular Asterisk file and output a source file, so that you can edit it and recompile it later. Should be very useful for people with existing complex dial plans.
Dial Plan Compiler
Home
Project Page
Syntax
Download
Asterisk
Digium
Asterisk Wiki
Other projects
JAGI Server
ezContent
iPod xTract
Cemanahuatl
SourceForge.net Logo