[RADIATOR] DB connections in hook code?

Jared Watkins JWatkins at acninc.com
Wed Dec 21 15:01:50 CST 2011

On Dec 21, 2011, at 3:30 PM, Heikki Vatiainen wrote:

On 12/21/2011 09:41 PM, Jared Watkins wrote:

I'm new to Radiator and am working on my first set of hook code to
evaluate it for a project.  I'm taking in call detail records via
radius.. enriching them in the PostProcessingHook through a Handler
and then storing some of them in a sql database.

Usually you have something like this:

<AuthBy SQL>
 Identifier sql-authby

The hook then starts with something like this:

sub {
   my $p = ${$_[0]};      # Request packet
   my $rp = ${$_[1]};     # Response packet

   my $authby_handle = Radius::AuthGeneric::find('sql-authby');
   # Build a $query with possibly @bind_values
   my $sth = $authby_handle->prepareAndExecute($query, @bind_values);

See goodies/hooks.txt for more hook examples. You could look for
PostAuthHook which runs earlier in the processing than PostProcessingHook.

Also, as the example shows, it's easier to use e.g. AuthBy objects and
run queries using them. Since there are no threads, you do not have to
worry about using mutexes and such. The calls, such as
prepareAndExecute, open and reopen the DB connection when needed and do
failover according to handle objects configuration.

I didn't see anything in the pdf doc that speaks to these sorts of

See goodies/README and search for 'hook'. File hooks.txt has plenty of
examples but there are also other files that use hooks.

Thanks for the quick feedback.  That was my mistake about it being multi threaded... I think I was confusing it with some stuff I'd read about the perl POE radius server.

In regard to Radius::AuthGeneric::find... is there somewhere these routines are documented?  I saw references in the pdf doc to AuthGeneric.. but not anything that told me it could be used in this way or that it could return a db connection handle.. or what the subsequent calls to use that handle should be.  I did see a few things in the example code about these but that's hardly a complete reference.

For instance.. I see an example of someone calling fetchrow in one of the goodies.. but that is not a standard DBI call.  In this case it looks like it's returning the data in an array.. but that's only one of many choices the DBI interface gives you.

Am I just missing something here?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.open.com.au/pipermail/radiator/attachments/20111221/7c83390c/attachment.html 

More information about the radiator mailing list