[asterisk-users] generating a GUID

James FitzGibbon james.fitzgibbon at gmail.com
Thu Aug 9 08:47:46 CDT 2007


On 8/9/07, Julian Lyndon-Smith <asterisk at dotr.com> wrote:
>
> I have a need to have a GUID (for example,
> bcd47ccc-d7c9-ddb6-dc11-6746a770d77d [36 characters long including the
> "-"]) generated in the dialplan. Is there any asterisk function that
> would do this ? I would prefer not to have to shell out every time a
> call comes in.


There's nothing built in that I know of.  I had mused with the idea of
wrapping the available UUID generator code out there into a function and
offering it as a patch, but it's a low priority thing for me.

In the meantime, you could achieve what you want without the cost of
spinning up a shell process by writing a FastAGI app in Perl.  Using the
modules Asterisk::FastAGI and Data::UUID, you could get a UUID back for the
cost of the socket connection.

This is a quick example that I coded up to do that - it was actually more
painful to install the modules from CPAN than code up the server itself:

--START--
#!/usr/bin/perl
#

use strict;
use warnings;

MyAGI->run( port => 4574 );

package MyAGI;
use base 'Asterisk::FastAGI';

use strict;

use Data::UUID;

my $uuid;

sub child_init_hook
{

  $uuid = Data::UUID->new;

}

sub fastagi_handler
{

  my $self = shift;
  $self->agi->set_variable( UUID => $uuid->create_str() );

}
---END---

When run, this creates a pre-forking server with 5 children, which makes the
individual UUID generation about as cheap as you're going to get going
outside of the Asterisk process.  When I execute that with agi debugging
turned on from this diaplan snippet:

exten   => 7993,1,Answer
exten   => 7993,n,AGI(agi://127.0.0.1:4574/fastagi_handler)
exten   => 7993,n,SayAlpha(${UUID})
exten   => 7993,n,Hangup

I get this:

    -- Executing [7993 at from-internal-admin:1] Answer("SIP/427-9df490e0", "")
in new stack
    -- Executing [7993 at from-internal-admin:2] AGI("SIP/427-9df490e0",
"agi://127.0.0.1:4574/fastagi_handler") in new stack
AGI Tx >> agi_network: yes
AGI Tx >> agi_network_script: fastagi_handler
AGI Tx >> agi_request: agi://127.0.0.1:4574/fastagi_handler
AGI Tx >> agi_channel: SIP/427-9df490e0
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1186667018.723
AGI Tx >> agi_callerid: 427
AGI Tx >> agi_calleridname: James FitzGibbon
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 7993
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: from-internal-admin
AGI Tx >> agi_extension: 7993
AGI Tx >> agi_priority: 2
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >> CLI>
AGI Rx << SET VARIABLE UUID "88AEDB9A-467E-11DC-9F13-8E31D47CEF85"
AGI Tx >> 200 result=1
    -- AGI Script agi://127.0.0.1:4574/fastagi_handler completed, returning
0
    -- Executing [7993 at from-internal-admin:3] SayAlpha("SIP/427-9df490e0",
"88AEDB9A-467E-11DC-9F13-8E31D47CEF85") in new stack

And then Allison starts chattering out the digits of the UUID.

Hope that gives you something to work with.

-- 
j.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20070809/dc17c759/attachment-0001.htm 


More information about the asterisk-users mailing list