1 # Copyright (C) 2002 Stanislav Sinyagin
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 # $Id: ServiceID.pm,v 1.1 2010-12-27 00:03:39 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
20 # Manage the properties assigned to Service IDs
22 package Torrus::ServiceID;
37 my $writing = $options{'-WriteAccess'};
39 $self->{'db_params'} =
40 new Torrus::DB( 'serviceid_params',
42 -WriteAccess => $writing );
43 defined( $self->{'db_params'} ) or return( undef );
45 $self->{'is_writing'} = $writing;
54 Debug('Destroyed ServiceID object');
55 undef $self->{'db_params'};
63 my $serviceid = shift;
68 return $self->{'db_params'}->searchList( 't:'.$tree, $serviceid );
71 return $self->{'db_params'}->searchList( 'a:', $serviceid );
78 my $serviceid = shift;
79 my $parameters = shift;
81 $self->{'db_params'}->addToList( 'a:', $serviceid );
83 my $trees = $parameters->{'trees'};
85 foreach my $tree ( split(/\s*,\s*/o, $trees) )
87 $self->{'db_params'}->addToList( 't:'.$tree, $serviceid );
90 foreach my $param ( keys %{$parameters} )
92 my $val = $parameters->{$param};
94 if( defined( $val ) and length( $val ) > 0 )
96 $self->{'db_params'}->put( 'p:'.$serviceid.':'.$param, $val );
97 $self->{'db_params'}->addToList( 'P:'.$serviceid, $param );
106 my $serviceid = shift;
109 my $plist = $self->{'db_params'}->get( 'P:'.$serviceid );
110 foreach my $param ( split(',', $plist ) )
113 $self->{'db_params'}->get( 'p:'.$serviceid.':'.$param );
126 my $idlist = $self->{'db_params'}->get('t:'.$tree);
127 if( defined( $idlist ) )
129 push( @{$ret}, split( ',', $idlist ) );
140 my $idlist = $self->{'db_params'}->get('t:'.$tree);
141 if( defined( $idlist ) )
143 foreach my $serviceid ( split( ',', $idlist ) )
145 # A ServiceID may belong to several trees.
146 # delete it from all other trees.
149 $self->{'db_params'}->get( 'p:'.$serviceid.':trees' );
151 foreach my $srvTree ( split(/\s*,\s*/o, $srvTrees) )
153 if( $srvTree ne $tree )
155 $self->{'db_params'}->delFromList( 't:'.$srvTree,
160 $self->{'db_params'}->delFromList( 'a:', $serviceid );
162 my $plist = $self->{'db_params'}->get( 'P:'.$serviceid );
164 foreach my $param ( split(',', $plist ) )
166 $self->{'db_params'}->del( 'p:'.$serviceid.':'.$param );
169 $self->{'db_params'}->del( 'P:'.$serviceid );
172 $self->{'db_params'}->deleteList('t:'.$tree);
186 # indent-tabs-mode: nil
187 # perl-indent-level: 4