[asterisk-dev] Dialplan -- Which version of Asterisk is running me?

Steve Murphy murf at digium.com
Thu Oct 19 20:14:28 MST 2006


Today, I committed a VERSION() function into trunk.

That will help you with trunk, 1.6 versions, and above, but
it won't help with 1.4 and previous Asterisks. 

Even if we call the fact that the dialplan had no way of finding the
current asterisk version a "bug", and slide this function into 1.4, 
and mayhaps into 1.2, the generic dialplan designer will still be 
left with a problem: the new function wouldn't be immediately present
in all the 1.2/1.4 asterisks running out there. Not until they update.
And, it's possible, some die-hards may never update.

So, you have to resort to the "sure thing", and that is, you have to
differentiate
between Asterisk versions without having the VERSION() function to help
you.
But how can that be done? Well, one way is to probe the functions you do
have
available. For instance, RAND() is a function that was introduced in
1.4. 1.2 does
not have it. If you try to call RAND() in your dialplan in 1.2, you'll
get a message
in the logs, and a null string will be returned. (I've verified this in
1.4 with VERSION();
I haven't done the 1.2 test yet, tho, but I think it will work!)
The same situation happens in 1.4 with VERSION().

So, extension 86 below demonstrates how to tell the difference...

(this is AEL, by the way... surprise!)

context test {
        86 => {
                Verbose(The version is: ${VERSION()} );
                Verbose(The versionnum is:
${VERSION(ASTERISK_VERSION_NUM)} );
                Verbose(The user is: ${VERSION(BUILD_USER)} );
                Verbose(The hostname is: ${VERSION(BUILD_HOSTNAME)} );
                Verbose(The machine is: ${VERSION(BUILD_MACHINE)} );
                Verbose(The OS is: ${VERSION(BUILD_OS)} );
                Verbose(The date is: ${VERSION(BUILD_DATE)} );
                Verbose(The kernel is: ${VERSION(BUILD_KERNEL)} );

                /* above this, a demo of the different values VERSION
can return...
                   below this, a demo of some code to find out what
version of Asterisk
                   is running this code */

                Set(vinf=${VERSION()});
                Set(vrand=${RAND()});
                if( ${ISNULL(${vinf})} )
                {
                        if( ${ISNULL(${vrand})} )
                                Verbose(Version 1.2 or earlier);
                        else
                                Verbose(Version 1.4!!!);
                }
                else
                        Verbose(${vinf} indicates version pre-1.6 or
higher);
        }
}

Hmmm. Is this the beginning of something like autoconf in a dialplan?

murf

-- 
Steve Murphy
Software Developer
Digium
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3227 bytes
Desc: not available
Url : http://lists.digium.com/pipermail/asterisk-dev/attachments/20061019/16f636cc/smime.bin


More information about the asterisk-dev mailing list