Got rid of =& when constructing objects. Improved documentation in many places. Got rid of double-copy operations when checking for errors (e.g. $foo = $r = myMethod()). Tweaked code here and there to fit coding conventions.

This commit is contained in:
paul 2006-11-14 19:13:49 +00:00
parent ea288cb362
commit 5b012f8817
6 changed files with 109 additions and 112 deletions

View file

@ -1,16 +1,20 @@
<?php <?php
require_once dirname(__FILE__)."/../../storageServer/var/xmlrpc/XR_LocStor.php"; require_once(dirname(__FILE__)."/../../storageServer/var/xmlrpc/XR_LocStor.php");
require_once dirname(__FILE__)."/../../storageServer/var/Transport.php"; require_once(dirname(__FILE__)."/../../storageServer/var/Transport.php");
/** /**
* Extension to StorageServer to act as ArchiveServer. * Extension to StorageServer to act as ArchiveServer.
* *
* @author $Author$ * @author Tomas Hlava <th@red2head.com>
* @author Paul Baranowski <paul@paulbaranowski.org>
* @version $Revision$ * @version $Revision$
* @package Campcaster * @package Campcaster
* @subpackage ArchiveServer * @subpackage ArchiveServer
* @copyright 2006 MDLF, Inc.
* @license http://www.gnu.org/licenses/gpl.txt
* @link http://www.campware.org
*/ */
class Archive extends XR_LocStor{ class Archive extends XR_LocStor {
/** /**
* Open upload transport (from station to hub) * Open upload transport (from station to hub)
@ -26,13 +30,13 @@ class Archive extends XR_LocStor{
*/ */
function uploadOpen($sessid, $chsum) function uploadOpen($sessid, $chsum)
{ {
$owner = $r = $this->getSessUserId($sessid); $owner = $this->getSessUserId($sessid);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($owner)) {
return $r; return $owner;
} }
$res = $r = $this->bsOpenPut($chsum, NULL, $owner); $res = $this->bsOpenPut($chsum, NULL, $owner);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
return array('url'=>$res['url'], 'token'=>$res['token']); return array('url'=>$res['url'], 'token'=>$res['token']);
} }
@ -65,31 +69,31 @@ class Archive extends XR_LocStor{
*/ */
function uploadClose($token, $trtype, $pars=array()) function uploadClose($token, $trtype, $pars=array())
{ {
$res = $r = $this->bsClosePut($token); $res = $this->bsClosePut($token);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
extract($res); // fname, owner extract($res); // fname, owner
switch ($trtype) { switch ($trtype) {
case "audioclip": case "audioclip":
$mdtoken = $pars['mdpdtoken']; $mdtoken = $pars['mdpdtoken'];
$res = $r = $this->bsClosePut($mdtoken); $res = $this->bsClosePut($mdtoken);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
$mdfname = $res['fname']; $mdfname = $res['fname'];
if ($gunid == '') { if ($gunid == '') {
$gunid=NULL; $gunid = NULL;
} }
$parid = $r = $this->_getHomeDirId($owner); $parid = $this->_getHomeDirId($owner);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($parid)) {
return $r; return $parid;
} }
$res = $r = $this->bsPutFile($parid, $pars['name'], $res = $this->bsPutFile($parid, $pars['name'],
$fname, $mdfname, $fname, $mdfname,
$pars['gunid'], 'audioclip', 'file'); $pars['gunid'], 'audioclip', 'file');
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
@unlink($fname); @unlink($fname);
@unlink($mdfname); @unlink($mdfname);
@ -98,24 +102,24 @@ class Archive extends XR_LocStor{
if ($gunid == '') { if ($gunid == '') {
$gunid = NULL; $gunid = NULL;
} }
$parid = $r = $this->_getHomeDirId($owner); $parid = $this->_getHomeDirId($owner);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($parid)) {
return $r; return $parid;
} }
$res = $r = $this->bsPutFile($parid, $pars['name'], $res = $this->bsPutFile($parid, $pars['name'],
'', $fname, '', $fname,
$pars['gunid'], 'playlist', 'file'); $pars['gunid'], 'playlist', 'file');
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
@unlink($fname); @unlink($fname);
break; break;
case "playlistPkg": case "playlistPkg":
$chsum = md5_file($fname); $chsum = md5_file($fname);
// importPlaylistOpen: // importPlaylistOpen:
$res = $r = $this->bsOpenPut($chsum, NULL, $owner); $res = $this->bsOpenPut($chsum, NULL, $owner);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
$dest = $res['fname']; $dest = $res['fname'];
$token = $res['token']; $token = $res['token'];
@ -131,16 +135,16 @@ class Archive extends XR_LocStor{
$crits = file_get_contents($fname); $crits = file_get_contents($fname);
$criteria = unserialize($crits); $criteria = unserialize($crits);
@unlink($fname); @unlink($fname);
$results = $r =$this->localSearch($criteria); $results = $this->localSearch($criteria);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($results)) {
return $r; return $results;
} }
$realfile = tempnam($this->accessDir, 'searchjob_'); $realfile = tempnam($this->accessDir, 'searchjob_');
@chmod($realfile, 0660); @chmod($realfile, 0660);
$len = $r = file_put_contents($realfile, serialize($results)); $len = file_put_contents($realfile, serialize($results));
$acc = $r = $this->bsAccess($realfile, '', NULL, 'download'); $acc = $this->bsAccess($realfile, '', NULL, 'download');
if ($this->dbc->isError($r)) { if ($this->dbc->isError($acc)) {
return $r; return $acc;
} }
$url = $this->getUrlPart()."access/".basename($acc['fname']); $url = $this->getUrlPart()."access/".basename($acc['fname']);
$chsum = md5_file($realfile); $chsum = md5_file($realfile);
@ -163,9 +167,12 @@ class Archive extends XR_LocStor{
/** /**
* Open download transport * Open download transport
* *
* @param string $sessid - session id * @param string $sessid
* @param string $trtype - transport type * session id
* @param array $pars - transport parameters * @param string $trtype
* transport type
* @param array $pars
* transport parameters
* @return hasharray with: * @return hasharray with:
* url string: writable URL * url string: writable URL
* token string: PUT token * token string: PUT token
@ -186,36 +193,36 @@ class Archive extends XR_LocStor{
$gunid = $pars['gunid']; $gunid = $pars['gunid'];
// resolve trtype by object type: // resolve trtype by object type:
if ( ($trtype == 'unknown') || ($trtype == 'playlistPkg') ) { if ( ($trtype == 'unknown') || ($trtype == 'playlistPkg') ) {
$trtype2 = $r = $this->_getType($gunid); $trtype2 = $this->_getType($gunid);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($trtype2)) {
return $r; return $trtype2;
} }
// required with content: // required with content:
$trtype = ($trtype2 == 'playlist' && $trtype == 'playlistPkg'? $trtype = ( ($trtype2 == 'playlist') && ($trtype == 'playlistPkg') ?
'playlistPkg' : $trtype2); 'playlistPkg' : $trtype2);
# return PEAR::raiseError("Archive::downloadOpen: TT=$trtype TT2=$trtype2 G=$gunid"); //return PEAR::raiseError("Archive::downloadOpen: TT=$trtype TT2=$trtype2 G=$gunid");
} }
switch ($trtype) { switch ($trtype) {
case "audioclip": case "audioclip":
$res = $r = $this->downloadRawAudioDataOpen($sessid, $gunid); $res = $this->downloadRawAudioDataOpen($sessid, $gunid);
break; break;
case "metadata": case "metadata":
$res = $r = $this->downloadMetadataOpen($sessid, $gunid); $res = $this->downloadMetadataOpen($sessid, $gunid);
break; break;
case "playlist": case "playlist":
$res = $r = $this->accessPlaylist($sessid, $gunid); $res = $this->accessPlaylist($sessid, $gunid);
break; break;
case "playlistPkg": case "playlistPkg":
$res = $r = $this->bsExportPlaylistOpen($gunid); $res = $this->bsExportPlaylistOpen($gunid);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
$tmpn = tempnam($this->transDir, 'plExport_'); $tmpn = tempnam($this->transDir, 'plExport_');
$plfpath = "$tmpn.lspl"; $plfpath = "$tmpn.lspl";
copy($res['fname'], $plfpath); copy($res['fname'], $plfpath);
$res = $r = $this->bsExportPlaylistClose($res['token']); $res = $this->bsExportPlaylistClose($res['token']);
if (PEAR::isError($r)) { if (PEAR::isError($res)) {
return $r; return $res;
} }
$fname = "transported_playlist.lspl"; $fname = "transported_playlist.lspl";
$id = $this->_idFromGunid($gunid); $id = $this->_idFromGunid($gunid);
@ -236,23 +243,27 @@ class Archive extends XR_LocStor{
$res = $pars; $res = $pars;
break; break;
case "file": case "file":
$res = $r = array(); $res = array();
break; break;
default: default:
return PEAR::raiseError("Archive::downloadOpen: NotImpl ($trtype)"); return PEAR::raiseError("Archive::downloadOpen: NotImpl ($trtype)");
} }
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
switch ($trtype) { switch ($trtype) {
case "audioclip": case "audioclip":
case "metadata": case "metadata":
case "playlist": case "playlist":
case "playlistPkg": case "playlistPkg":
$title = $r = $this->bsGetTitle(NULL, $gunid); $title = $this->bsGetTitle(NULL, $gunid);
break;
case "searchjob":
$title = 'searchjob';
break;
case "file":
$title = 'regular file';
break; break;
case "searchjob": $title = 'searchjob'; break;
case "file": $title = 'regular file'; break;
default: default:
} }
$res['title'] = $title; $res['title'] = $title;
@ -277,30 +288,21 @@ class Archive extends XR_LocStor{
{ {
switch ($trtype) { switch ($trtype) {
case "audioclip": case "audioclip":
$res = $r = $this->downloadRawAudioDataClose($token); $res = $this->downloadRawAudioDataClose($token);
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
return $res; return $res;
break;
case "metadata": case "metadata":
$res = $r = $this->downloadMetadataClose($token); $res = $this->downloadMetadataClose($token);
if ($this->dbc->isError($r)) {
return $r;
}
return $res; return $res;
break;
case "playlist": case "playlist":
$res = $r = $this->releasePlaylist(NULL/*$sessid*/, $token); $res = $this->releasePlaylist(NULL/*$sessid*/, $token);
if ($this->dbc->isError($r)) {
return $r;
}
return $res; return $res;
break;
case "playlistPkg": case "playlistPkg":
$res = $r = $this->bsRelease($token, 'download'); $res = $this->bsRelease($token, 'download');
if ($this->dbc->isError($r)) { if ($this->dbc->isError($res)) {
return $r; return $res;
} }
$realFname = $r['realFname']; $realFname = $r['realFname'];
@unlink($realFname); @unlink($realFname);
@ -312,17 +314,11 @@ class Archive extends XR_LocStor{
} }
} }
return $res; return $res;
break;
case "searchjob": case "searchjob":
$res = $r = $this->bsRelease($token, 'download'); $res = $this->bsRelease($token, 'download');
if ($this->dbc->isError($r)) {
return $r;
}
return $res; return $res;
break;
case "file": case "file":
return array(); return array();
break;
default: default:
return PEAR::raiseError("Archive::downloadClose: NotImpl ($trtype)"); return PEAR::raiseError("Archive::downloadClose: NotImpl ($trtype)");
} }
@ -345,12 +341,11 @@ class Archive extends XR_LocStor{
function prepareHubInitiatedTransfer( function prepareHubInitiatedTransfer(
$target, $trtype='file', $direction='up',$pars=array()) $target, $trtype='file', $direction='up',$pars=array())
{ {
$tr =& new Transport($this); $tr = new Transport($this);
$trec = $r = TransportRecord::create($tr, $trtype, $direction, $trec = TransportRecord::create($tr, $trtype, $direction,
array_merge($pars, array('target'=>$target)) array_merge($pars, array('target'=>$target)));
); if (PEAR::isError($trec)) {
if (PEAR::isError($r)) { return $trec;
return $r;
} }
return TRUE; return TRUE;
} }
@ -370,11 +365,8 @@ class Archive extends XR_LocStor{
function listHubInitiatedTransfers( function listHubInitiatedTransfers(
$target=NULL, $direction=NULL, $trtok=NULL) $target=NULL, $direction=NULL, $trtok=NULL)
{ {
$tr =& new Transport($this); $tr = new Transport($this);
$res = $r = $tr->getTransports($direction, $target, $trtok); $res = $tr->getTransports($direction, $target, $trtok);
if (PEAR::isError($r)) {
return $r;
}
return $res; return $res;
} }
@ -388,20 +380,20 @@ class Archive extends XR_LocStor{
* transport token * transport token
* @param string $state * @param string $state
* transport state * transport state
* @return * @return TransportRecord|PEAR_Error
*/ */
function setHubInitiatedTransfer($target, $trtok, $state) function setHubInitiatedTransfer($target, $trtok, $state)
{ {
$tr =& new Transport($this); $tr = new Transport($this);
$trec = $r = TransportRecord::recall($tr, $trtok); $trec = TransportRecord::recall($tr, $trtok);
if (PEAR::isError($r)) { if (PEAR::isError($trec)) {
return $r; return $trec;
} }
$r = $trec->setState($state); $r = $trec->setState($state);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
return $res; return $trec;
} }
/* ==================================================== auxiliary methods */ /* ==================================================== auxiliary methods */

View file

@ -45,8 +45,8 @@ if (PEAR::isError($dbc)) {
} }
$dbc->setFetchMode(DB_FETCHMODE_ASSOC); $dbc->setFetchMode(DB_FETCHMODE_ASSOC);
$gb =& new Archive($dbc, $config, TRUE); $gb = new Archive($dbc, $config, TRUE);
$tr =& new Transport($gb); $tr = new Transport($gb);
echo "# archiveServer step 2:\n# trying uninstall ...\n"; echo "# archiveServer step 2:\n# trying uninstall ...\n";
$dbc->setErrorHandling(PEAR_ERROR_RETURN); $dbc->setErrorHandling(PEAR_ERROR_RETURN);

View file

@ -32,8 +32,8 @@ if (PEAR::isError($dbc)) {
echo "#ArchiveServer uninstall:\n"; echo "#ArchiveServer uninstall:\n";
$dbc->setFetchMode(DB_FETCHMODE_ASSOC); $dbc->setFetchMode(DB_FETCHMODE_ASSOC);
$gb = &new Archive($dbc, $config, TRUE); $gb = new Archive($dbc, $config, TRUE);
$tr = &new Transport($gb); $tr = new Transport($gb);
echo "# Uninstall Transport submodule ..."; echo "# Uninstall Transport submodule ...";

View file

@ -4,6 +4,9 @@
* @version $Revision$ * @version $Revision$
* @package Campcaster * @package Campcaster
* @subpackage ArchiveServer * @subpackage ArchiveServer
* @copyright 2006 MDLF, Inc.
* @license http://www.gnu.org/licenses/gpl.txt
* @link http://www.campware.org
*/ */
require_once "../Archive.php"; require_once "../Archive.php";
@ -15,7 +18,9 @@ require_once "../Archive.php";
* @version $Revision$ * @version $Revision$
* @package Campcaster * @package Campcaster
* @subpackage ArchiveServer * @subpackage ArchiveServer
* * @copyright 2006 MDLF, Inc.
* @license http://www.gnu.org/licenses/gpl.txt
* @link http://www.campware.org
*/ */
class XR_Archive extends Archive { class XR_Archive extends Archive {

View file

@ -36,7 +36,7 @@ require_once dirname(__FILE__).'/../Archive.php';
PEAR::setErrorHandling(PEAR_ERROR_RETURN); PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$dbc = DB::connect($config['dsn'], TRUE); $dbc = DB::connect($config['dsn'], TRUE);
$dbc->setFetchMode(DB_FETCHMODE_ASSOC); $dbc->setFetchMode(DB_FETCHMODE_ASSOC);
$gb = &new Archive($dbc, $config); $gb = new Archive($dbc, $config);
function http_error($code, $err){ function http_error($code, $err){
header("HTTP/1.1 $code"); header("HTTP/1.1 $code");

View file

@ -45,7 +45,7 @@ function errHndl($errno, $errmsg, $filename, $linenum, $vars){
return; return;
break; break;
default: default:
$xr =& new XML_RPC_Response(0, 805, $xr = new XML_RPC_Response(0, 805,
htmlspecialchars("ERROR:xrLocStor: $errno $errmsg ($filename:$linenum)")); htmlspecialchars("ERROR:xrLocStor: $errno $errmsg ($filename:$linenum)"));
header("Content-type: text/xml"); header("Content-type: text/xml");
echo $xr->serialize(); echo $xr->serialize();
@ -64,7 +64,7 @@ PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$dbc = DB::connect($config['dsn'], TRUE); $dbc = DB::connect($config['dsn'], TRUE);
$dbc->setFetchMode(DB_FETCHMODE_ASSOC); $dbc->setFetchMode(DB_FETCHMODE_ASSOC);
$archive = &new XR_Archive($dbc, $config); $archive = new XR_Archive($dbc, $config);
$methods = array( $methods = array(
'test' => 'Tests toupper and checks sessid, params: '. 'test' => 'Tests toupper and checks sessid, params: '.
@ -129,6 +129,6 @@ foreach($methods as $method=>$description){
"docstring" => $description "docstring" => $description
); );
} }
$s = &new XML_RPC_Server( $defs ); $s = new XML_RPC_Server( $defs );
?> ?>