[Netpass-devel] NetPass/lib/NetPass DB.pm,1.44,1.45
Brought to you by:
jeffmurphy
|
From: Matt <mt...@us...> - 2005-06-02 20:34:58
|
Update of /cvsroot/netpass/NetPass/lib/NetPass In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4403 Modified Files: DB.pm Log Message: Index: DB.pm =================================================================== RCS file: /cvsroot/netpass/NetPass/lib/NetPass/DB.pm,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- DB.pm 2 Jun 2005 19:59:08 -0000 1.44 +++ DB.pm 2 Jun 2005 20:34:49 -0000 1.45 @@ -2668,25 +2668,54 @@ return $self->{'dbh'}->commit; } - - - =head2 updateRegister(-mac => '', -status => [QUAR|PQUAR|UNQUAR|PUNQUAR]) Update the register table for the given MAC address. RETURNS - 0 on success + 1 on success "invalid parameters" routine called improperly - "mac not exist" given mac doesnt exist (use registerHost first) + "mac doesnt exist" given mac doesnt exist (use registerHost first) "..." db error =cut sub updateRegister { - my $self = shift; - # params... + my $self = shift; + + $self->reconnect() || return undef; + my $parms = parse_parms({ + -parms => \@_, + -legal => [ qw(-mac -status) ], + -defaults => { -mac => '', + -status => '', + } + } + ); + + return "invalid params\n".Carp::longmess(Class::ParmList->error) if (!defined($parms)); + my ($mac, $status) = $parms->get('-mac', '-status'); + + if ($mac !~ /^[0-9a-fA-F]+$/ || $status !~ /^(QUAR|PQUAR|UNQUAR|PUNQUAR)$/) { + return "invalid parameters"; + } + + $mac = NetPass::padMac($mac); + + my $sql = "UPDATE register SET status=? WHERE macAddress = ?"; + my $sth = $self->{'dbh'}->prepare($sql); + my $rv = $sth->execute($status, $mac); + + if ($rv == 0) { + return "mac doesnt exist"; + } + + if ($rv < 0) { + _log("ERROR", "db failure ".$self->{'dbh'}->errstr); + return "db failure ".$self->{'dbh'}->errstr; + } + return 1; } |