Debian Codegraph @

src/modules/app_perl/lib/perl/Kamailio/VDB/Adapter/Alias.pm

raw
1 #
2 # $Id: Alias.pm 757 2007-01-05 10:56:28Z bastian $
3 #
4 # Perl module for Kamailio
5 #
6 # Copyright (C) 2007 Collax GmbH
7 # (Bastian Friedrich <[email protected]>)
8 #
9 # This file is part of Kamailio, a free SIP server.
10 #
11 # Kamailio is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version
15 #
16 # Kamailio is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #
25
26 =head1 Kamailio::VDB::Adapter::Alias
27
28 This package is intended for usage with the alias_db module. The query VTab
29 has to take two arguments and return an array of two arguments (user name/domain).
30
31 =cut
32
33 package Kamailio::VDB::Adapter::Alias;
34
35 use Kamailio::Constants;
36 use Kamailio qw ( log );
37
38 use Kamailio::VDB;
39 use Kamailio::VDB::Column;
40 use Kamailio::VDB::Result;
41
42 use Data::Dumper;
43
44 our @ISA = qw ( Kamailio::VDB );
45
46 =head2 query(conds,retkeys,order)
47
48 Queries the vtab with the given arguments for
49 request conditions, keys to return and sort order column name.
50
51 =cut
52
53 sub query {
54 my $self = shift;
55
56 my $conds = shift;
57 my $retkeys = shift; # Unused value here.
58 my $order = shift; # Unused value here.
59
60 my @cols;
61
62 my $alias_username = undef;
63 my $alias_domain = undef;
64 my $username;
65 my $domain;
66
67 for my $c (@$conds) {
68 if (($c->key() eq "alias_username") && ($c->op() eq "=")) {
69 $alias_username = $c->data();
70 }
71 if (($c->key() eq "alias_domain") && ($c->op() eq "=")) {
72 $alias_domain = $c->data();
73 }
74 }
75
76 my $vtab = $self->{vtabs}->{$self->{tablename}};
77 $newaddr = $vtab->call("query", $alias_username, $alias_domain);
78
79 my $result;
80
81 push @cols, new Kamailio::VDB::Column(DB_STRING, "username");
82 push @cols, new Kamailio::VDB::Column(DB_STRING, "domain");
83
84 if ($newaddr) {
85 my @row;
86 my $resval1 = new Kamailio::VDB::Value(DB_STRING, $newaddr->{username} );
87 push @row, $resval1;
88 my $resval2 = new Kamailio::VDB::Value(DB_STRING, $newaddr->{domain} );
89 push @row, $resval2;
90 $result = new Kamailio::VDB::Result(\@cols, (bless \@row, "Kamailio::Utils::Debug"));
91 } else {
92 $result = new Kamailio::VDB::Result(\@cols);
93 }
94
95 return $result;
96 }
97
98 1;