1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#
# $Id: VDB.pm 757 2007-01-05 10:56:28Z bastian $
#
# Perl module for Kamailio
#
# Copyright (C) 2006 Collax GmbH
# (Bastian Friedrich <bastian.friedrich@collax.com>)
#
# This file is part of Kamailio, a free SIP server.
#
# Kamailio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version
#
# Kamailio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
=head1 Kamailio::VDB
This package is an (abstract) base class for all virtual databases. Derived
packages can be configured to be used by Kamailio as a database.
The base class itself should NOT be used in this context, as it does not
provide any functionality.
=cut
package Kamailio::VDB;
use Kamailio;
use Kamailio::Constants;
use Kamailio::VDB::Column;
use Kamailio::VDB::Pair;
use Kamailio::VDB::ReqCond;
use Kamailio::VDB::Result;
use Kamailio::VDB::Value;
use Kamailio::VDB::VTab;
use UNIVERSAL qw ( can );
our @ISA = qw ( Kamailio::Utils::Debug );
sub new {
my $class = shift;
my $self = {
tablename => undef,
vtabs => {}
};
bless $self, $class;
return $self;
}
sub use_table {
my $self = shift;
my $v = shift;
$self->{tablename} = $v;
if ($v eq "version") {
# "version" table is handled individually. Don't initialize VTabs.
return 0;
}
if ($self->{vtabs}->{$v}) {
return 0;
}
if ($v =~ m/^((.*)::)?([\w_][\d\w_]*)$/) {
my $pkg;
if (!$2) {
$pkg = "main";
} else {
$pkg = $2;
}
Kamailio::log(L_DBG, "perlvdb:VDB: Setting VTab: v is $v (pkg is $pkg, func/method is $3)\n");
if (can($pkg, $3)) {
$self->{vtabs}->{$v} = new Kamailio::VDB::VTab( func => $pkg . "::" . $3);
} elsif (can($v, "init")) {
$v->init();
$self->{vtabs}->{$v} = new Kamailio::VDB::VTab( obj => $v );
} elsif (can($v, "new")) {
my $obj = $v->new();
$self->{vtabs}->{$v} = new Kamailio::VDB::VTab( obj => $obj );
} else {
Kamailio::log(L_ERR, "perlvdb:VDB: Invalid virtual table.\n");
return -1;
}
} else {
Kamailio::log(L_ERR, "perlvdb:VDB: Invalid virtual table.\n");
return -1;
}
}
sub _insert {
my $self = shift;
return $self->insert(@_);
}
sub _replace {
my $self = shift;
return $self->replace(@_);
}
sub _delete {
my $self = shift;
return $self->delete(@_);
}
sub _update {
my $self = shift;
return $self->update(@_);
}
sub _query {
my $self = shift;
return $self->query(@_);
}
sub insert {
Kamailio::log(L_INFO, "perlvdb:Insert not implemented in base class.\n");
return -1;
}
sub replace {
Kamailio::log(L_INFO, "perlvdb:Replace not implemented in base class.\n");
return -1;
}
sub delete {
Kamailio::log(L_INFO, "perlvdb:Delete not implemented in base class.\n");
return -1;
}
sub update {
Kamailio::log(L_INFO, "perlvdb:Update not implemented in base class.\n");
return -1;
}
sub query {
Kamailio::log(L_INFO, "perlvdb:Query not implemented in base class.\n");
return -1;
}
1;
|