Subject: | splitresult() fails to return keys with empty values |
Date: | Fri, 07 Mar 2014 01:02:39 -0500 |
To: | bug-asterisk-perl [...] rt.cpan.org |
From: | Dave Miller <justdave [...] mozilla.com> |
When trying to use the "DBGet" action in Asterisk::Manager, the
DBGetResult packet returned does not contain a "Val" key if the Val
value was actually an empty string.
my %resp = $AMI->sendcommand(Action => "DBGet", ActionID => "5", Family
=> "TL/CONF/237", Key => "userpin", 0);
the event that eventually comes back with the response looks like this
in the raw Manager connection capture:
Event: DBGetResponse
Family: TL/CONF/237
Key: userpin
Val:
ActionID: 5
But the hash returned from $AMI->handleevent() looks like this:
$VAR1 = {
'237' => '',
'Event' => 'DBGetResponse',
'Family' => 'TL/CONF/237',
'ActionID' => '5',
'Key' => 'userpin'
};
Note the lack of a "Val" hash key, even though it was present in the
real response, and the mysterious presence of a "237" hash key.
It appears that the problem is that splitresult() is assuming that there
must be at least one non-space character in any value, and doesn't think
there should be such a thing as an empty value, which is obviously not true.
The following patch fixes this:
--- Manager.pm.orig 2011-12-06 19:04:54.000000000 -0800
+++ Manager.pm 2014-03-06 21:44:19.000000000 -0800
@@ -386,7 +386,7 @@
my ($res) = @_;
my ($key, $val) = ('', '');
- $res =~ /^([^:]+):\ {0,1}([^\ ].*)$/;
+ $res =~ /^([^:]+):\ {0,1}(.*?)$/;
$key = $1 if defined($1);
$val = $2 if defined($2);
After applying the above patch, the result hash looks like this:
$VAR1 = {
'Event' => 'DBGetResponse',
'Val' => '',
'Family' => 'TL/CONF/237',
'ActionID' => '5',
'Key' => 'userpin'
};
Which is a true representation of what was in the response packet.
--
Dave Miller http://www.justdave.net/
IT Infrastructure Engineer, Mozilla http://www.mozilla.org/
Project Leader, Bugzilla Bug Tracking System http://www.bugzilla.org/