On 8/9/07, <b class="gmail_sendername">Julian Lyndon-Smith</b> <<a href="mailto:asterisk@dotr.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">asterisk@dotr.com</a>> wrote:<div><span class="gmail_quote">
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have a need to have a GUID (for example,<br>bcd47ccc-d7c9-ddb6-dc11-6746a770d77d [36 characters long including the<br>"-"]) generated in the dialplan. Is there any asterisk function that<br>would do this ? I would prefer not to have to shell out every time a
<br>call comes in.</blockquote><div><br>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.
<br><br>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.
<br><br> 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:<br><br>--START--<br>#!/usr/bin/perl<br>#<br><br>use strict;<br>use warnings;
<br><br>MyAGI->run( port => 4574 );<br><br>package MyAGI;<br>use base 'Asterisk::FastAGI';<br><br>use strict;<br><br>use Data::UUID;<br><br>my $uuid;<br><br>sub child_init_hook<br>{<br><br> $uuid = Data::UUID->new;
<br><br>}<br><br>sub fastagi_handler<br>{<br><br> my $self = shift;<br> $self->agi->set_variable( UUID => $uuid->create_str() );<br><br>}<br>---END---<br><br>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:
<br><br>exten => 7993,1,Answer<br>exten => 7993,n,AGI(agi://127.0.0.1:4574/fastagi_handler)<br>exten => 7993,n,SayAlpha(${UUID})<br>exten => 7993,n,Hangup<br><br>I get this:<br><br> -- Executing [7993@from-internal-admin
:1] Answer("SIP/427-9df490e0", "") in new stack<br> -- Executing [7993@from-internal-admin:2] AGI("SIP/427-9df490e0", "agi://127.0.0.1:4574/fastagi_handler") in new stack<br>AGI Tx >> agi_network: yes
<br>AGI Tx >> agi_network_script: fastagi_handler<br>AGI Tx >> agi_request: agi://127.0.0.1:4574/fastagi_handler<br>AGI Tx >> agi_channel: SIP/427-9df490e0<br>AGI Tx >> agi_language: en<br>AGI Tx >> agi_type: SIP
<br>AGI Tx >> agi_uniqueid: 1186667018.723<br>AGI Tx >> agi_callerid: 427<br>AGI Tx >> agi_calleridname: James FitzGibbon<br>AGI Tx >> agi_callingpres: 0<br>AGI Tx >> agi_callingani2: 0<br>AGI Tx >> agi_callington: 0
<br>AGI Tx >> agi_callingtns: 0<br>AGI Tx >> agi_dnid: 7993<br>AGI Tx >> agi_rdnis: unknown<br>AGI Tx >> agi_context: from-internal-admin<br>AGI Tx >> agi_extension: 7993<br>AGI Tx >> agi_priority: 2
<br>AGI Tx >> agi_enhanced: 0.0<br>AGI Tx >> agi_accountcode:<br>AGI Tx >> CLI><br>AGI Rx << SET VARIABLE UUID "88AEDB9A-467E-11DC-9F13-8E31D47CEF85"<br>AGI Tx >> 200 result=1<br>
-- AGI Script agi://127.0.0.1:4574/fastagi_handler completed, returning 0<br> -- Executing [7993@from-internal-admin:3] SayAlpha("SIP/427-9df490e0", "88AEDB9A-467E-11DC-9F13-8E31D47CEF85") in new stack
<br><br>And then Allison starts chattering out the digits of the UUID.<br><br>Hope that gives you something to work with.<br><br></div></div>-- <br>j.