Major changes - some code tranfers between layers:

StoredFile, BasicStor, GreenBox and LocStor
+Resolved: http://bugs.campware.org/view.php?id=545
This commit is contained in:
tomas 2005-01-17 00:15:51 +00:00
parent 958c1b4952
commit 8e783bea66
4 changed files with 291 additions and 352 deletions

View File

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.18 $ Version : $Revision: 1.19 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -50,7 +50,7 @@ require_once "StoredFile.php";
* Core of LiveSupport file storage module * Core of LiveSupport file storage module
* *
* @author $Author: tomas $ * @author $Author: tomas $
* @version $Revision: 1.18 $ * @version $Revision: 1.19 $
* @see Alib * @see Alib
*/ */
class BasicStor extends Alib{ class BasicStor extends Alib{
@ -127,23 +127,10 @@ class BasicStor extends Alib{
$res = $this->removeObj($id); $res = $this->removeObj($id);
return $ac; return $ac;
} }
if($ftype == 'playlist') $ac->setMime('application/smil');
return $id; return $id;
} }
/**
* Analyze media file for internal metadata information
*
* @param id int, virt.file's local id
* @return array
*/
function bsAnalyzeFile($id)
{
$ac =& StoredFile::recall(&$this, $id);
if(PEAR::isError($ac)) return $ac;
$ia = $ac->analyzeMediaFile();
return $ia;
}
/** /**
* Rename file * Rename file
* *
@ -157,15 +144,16 @@ class BasicStor extends Alib{
switch($this->getObjType($id)){ switch($this->getObjType($id)){
case"audioclip": case"audioclip":
case"playlist": case"playlist":
case"File":
$ac =& StoredFile::recall(&$this, $id); $ac =& StoredFile::recall(&$this, $id);
if(PEAR::isError($ac)){ if(PEAR::isError($ac)){
#// catch nonerror exception: // catch nonerror exception:
#if($ac->getCode() != GBERR_FOBJNEX) //if($ac->getCode() != GBERR_FOBJNEX)
return $ac; return $ac;
} }
$res = $ac->rename($newName); $res = $ac->rename($newName);
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
break;
case"File":
default: default:
} }
return $this->renameObj($id, $newName); return $this->renameObj($id, $newName);
@ -198,7 +186,7 @@ class BasicStor extends Alib{
case"playlist": case"playlist":
case"File": case"File":
return $this->_relocateSubtree($id, $did); return $this->_relocateSubtree($id, $did);
break; break;
default: default:
return PEAR::raiseError( return PEAR::raiseError(
"BasicStor::moveFile: only file move supported now, sorry.", "BasicStor::moveFile: only file move supported now, sorry.",
@ -235,7 +223,7 @@ class BasicStor extends Alib{
case"playlist": case"playlist":
case"File": case"File":
return $this->_copySubtree($id, $did); return $this->_copySubtree($id, $did);
break; break;
default: default:
return PEAR::raiseError( return PEAR::raiseError(
"BasicStor::moveFile: only file sopy supported now, sorry.", "BasicStor::moveFile: only file sopy supported now, sorry.",
@ -253,8 +241,7 @@ class BasicStor extends Alib{
function bsDeleteFile($id) function bsDeleteFile($id)
{ {
$res = $this->removeObj($id); $res = $this->removeObj($id);
if(PEAR::isError($res)) return $res; return $res;
return TRUE;
} }
/* ----------------------------------------------------- put, access etc. */ /* ----------------------------------------------------- put, access etc. */
@ -281,27 +268,16 @@ class BasicStor extends Alib{
* @param realFname string, local filepath to accessed file * @param realFname string, local filepath to accessed file
* @param ext string, useful filename extension for accessed file * @param ext string, useful filename extension for accessed file
* @param gunid int, global unique id * @param gunid int, global unique id
* @param sessid string, session id
* @param type string 'access'|'download' * @param type string 'access'|'download'
* @return array with: seekable filehandle, access token * @return array with: seekable filehandle, access token
*/ */
function bsAccess($realFname, $ext, $gunid, $sessid='', $type='access') function bsAccess($realFname, $ext, $gunid, $type='access')
{ {
$token = StoredFile::_createGunid(); $token = StoredFile::_createGunid();
$res = $this->dbc->query("
INSERT INTO {$this->accessTable}
(gunid, sessid, token,
ext, type, ts)
VALUES
(x'{$gunid}'::bigint, '$sessid', x'$token'::bigint,
'$ext', '$type', now())
");
if(PEAR::isError($res)){ return $res; }
$linkFname = "{$this->accessDir}/$token.$ext"; $linkFname = "{$this->accessDir}/$token.$ext";
if(!file_exists($realFname)){ if(!file_exists($realFname)){
return PEAR::raiseError( return PEAR::raiseError(
"BasicStor::bsAccess: symlink create failed ($accLinkName)", "BasicStor::bsAccess: real file not found ($realFname)",
GBERR_FILEIO); GBERR_FILEIO);
} }
if(! @symlink($realFname, $linkFname)){ if(! @symlink($realFname, $linkFname)){
@ -309,6 +285,23 @@ class BasicStor extends Alib{
"BasicStor::bsAccess: symlink create failed ($linkFname)", "BasicStor::bsAccess: symlink create failed ($linkFname)",
GBERR_FILEIO); GBERR_FILEIO);
} }
$this->dbc->query("BEGIN");
$res = $this->dbc->query("
INSERT INTO {$this->accessTable}
(gunid, token, ext, type, ts)
VALUES
(x'{$gunid}'::bigint, x'$token'::bigint,
'$ext', '$type', now())
");
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
$res = $this->dbc->query("
UPDATE {$this->filesTable}
SET currentlyAccessing=currentlyAccessing+1
WHERE gunid=x'{$gunid}'::bigint
");
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
$res = $this->dbc->query("COMMIT");
if(PEAR::isError($res)){ return $res; }
return array('fname'=>$linkFname, 'token'=>$token); return array('fname'=>$linkFname, 'token'=>$token);
} }
@ -330,19 +323,28 @@ class BasicStor extends Alib{
SELECT to_hex(gunid)as gunid, ext FROM {$this->accessTable} SELECT to_hex(gunid)as gunid, ext FROM {$this->accessTable}
WHERE token=x'{$token}'::bigint AND type='$type' WHERE token=x'{$token}'::bigint AND type='$type'
"); ");
if(PEAR::isError($acc)){ return $acc; }
$ext = $acc['ext']; $ext = $acc['ext'];
$gunid = StoredFile::_normalizeGunid($acc['gunid']); $gunid = StoredFile::_normalizeGunid($acc['gunid']);
if(PEAR::isError($acc)){ return $acc; }
$linkFname = "{$this->accessDir}/$token.$ext"; $linkFname = "{$this->accessDir}/$token.$ext";
$res = $this->dbc->query("
DELETE FROM {$this->accessTable} WHERE token=x'$token'::bigint
");
if(PEAR::isError($res)){ return $res; }
if(! @unlink($linkFname)){ if(! @unlink($linkFname)){
return PEAR::raiseError( return PEAR::raiseError(
"BasicStor::bsRelease: unlink failed ($linkFname)", "BasicStor::bsRelease: unlink failed ($linkFname)",
GBERR_FILEIO); GBERR_FILEIO);
} }
$this->dbc->query("BEGIN");
$res = $this->dbc->query("
UPDATE {$this->filesTable}
SET currentlyAccessing=currentlyAccessing-1
WHERE gunid=x'{$gunid}'::bigint AND currentlyAccessing>0
");
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
$res = $this->dbc->query("
DELETE FROM {$this->accessTable} WHERE token=x'$token'::bigint
");
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
$res = $this->dbc->query("COMMIT");
if(PEAR::isError($res)){ return $res; }
return $gunid; return $gunid;
} }
@ -368,8 +370,7 @@ class BasicStor extends Alib{
$ext = "xml"; $ext = "xml";
break; break;
} }
$sessid = ''; $acc = $this->bsAccess($fname, $ext, $gunid, 'download');
$acc = $this->bsAccess($fname, $ext, $gunid, $sessid, 'download');
$url = $this->getUrlPart()."access/".basename($acc['fname']); $url = $this->getUrlPart()."access/".basename($acc['fname']);
return array('url'=>$url, 'token'=>$acc['token']); return array('url'=>$url, 'token'=>$acc['token']);
} }
@ -400,14 +401,13 @@ class BasicStor extends Alib{
*/ */
function bsOpenPut($chsum, $gunid) function bsOpenPut($chsum, $gunid)
{ {
$sessid = '';
$ext = ''; $ext = '';
$token = StoredFile::_createGunid(); $token = StoredFile::_createGunid();
$res = $this->dbc->query(" $res = $this->dbc->query("
INSERT INTO {$this->accessTable} INSERT INTO {$this->accessTable}
(gunid, sessid, token, ext, chsum, type, ts) (gunid, token, ext, chsum, type, ts)
VALUES VALUES
(x'{$gunid}'::bigint, '$sessid', x'$token'::bigint, (x'{$gunid}'::bigint, x'$token'::bigint,
'$ext', '$chsum', 'put', now()) '$ext', '$chsum', 'put', now())
"); ");
if(PEAR::isError($res)){ return $res; } if(PEAR::isError($res)){ return $res; }
@ -488,7 +488,7 @@ class BasicStor extends Alib{
{ $replicaName.='_R'; } { $replicaName.='_R'; }
$rid = $this->addObj($replicaName , 'Replica', $did, 0, $id); $rid = $this->addObj($replicaName , 'Replica', $did, 0, $id);
if(PEAR::isError($rid)) return $rid; if(PEAR::isError($rid)) return $rid;
# $this->addMdata($this->_pathFromId($rid), 'isReplOf', $id, $sessid); # $this->addMdata($this->_pathFromId($rid), 'isReplOf', $id);
return $rid; return $rid;
} }
@ -637,10 +637,34 @@ class BasicStor extends Alib{
return PEAR::raiseError( return PEAR::raiseError(
'BasicStor::bsListFolder: not a folder', GBERR_NOTF 'BasicStor::bsListFolder: not a folder', GBERR_NOTF
); );
$a = $this->getDir($id, 'id, name, type, param as target', 'name'); $listArr = $this->getDir($id, 'id, name, type, param as target', 'name');
return $a; foreach($listArr as $i=>$v){
if($v['type'] == 'File'){
$gunid = $this->_gunidFromId($v['id']);
$listArr[$i]['type'] =
StoredFile::_getType($gunid);
$listArr[$i]['gunid'] = $gunid;
if(StoredFIle::_getState($gunid) == 'incomplete')
unset($listArr[$i]);
}
}
return $listArr;
} }
/**
* Analyze media file for internal metadata information
*
* @param id int, virt.file's local id
* @return array
*/
function bsAnalyzeFile($id)
{
$ac =& StoredFile::recall(&$this, $id);
if(PEAR::isError($ac)) return $ac;
$ia = $ac->analyzeMediaFile();
return $ia;
}
/** /**
* List files in folder * List files in folder
* *
@ -651,11 +675,11 @@ class BasicStor extends Alib{
function getObjIdFromRelPath($id, $relPath='.') function getObjIdFromRelPath($id, $relPath='.')
{ {
$relPath = trim($relPath); $relPath = trim($relPath);
#if($this->getObjType($id) !== 'Folder') //if($this->getObjType($id) !== 'Folder')
$nid = $this->getParent($id); $nid = $this->getParent($id);
if(PEAR::isError($nid)) return $nid; if(PEAR::isError($nid)) return $nid;
if(is_null($nid)){ return PEAR::raiseError("null parent for $nid"); } if(is_null($nid)){ return PEAR::raiseError("null parent for $nid"); }
#else $nid = $id; //else $nid = $id;
if(substr($relPath, 0, 1)=='/'){ $nid=$this->storId; } if(substr($relPath, 0, 1)=='/'){ $nid=$this->storId; }
$a = split('/', $relPath); $a = split('/', $relPath);
foreach($a as $i=>$pathItem){ foreach($a as $i=>$pathItem){
@ -686,6 +710,174 @@ class BasicStor extends Alib{
return $nid; return $nid;
} }
/* ---------------------------------------------------- redefined methods */
/**
* Get object type by id.
* (RootNode, Folder, File, )
*
* @param oid int, local object id
* @return string/err
*/
function getObjType($oid)
{
$type = $this->getObjName($oid, 'type');
if($type == 'File'){
$ftype =
StoredFile::_getType($this->_gunidFromId($oid));
if(!is_null($ftype)) $type=$ftype;
}
return $type;
}
/* ==================================================== "private" methods */
/**
* Check authorization - auxiliary method
*
* @param acts array of actions
* @param pars array of parameters - e.g. ids
* @param sessid string, session id
* @return true or PEAR::error
*/
function _authorize($acts, $pars, $sessid='')
{
$userid = $this->getSessUserId($sessid);
if(!is_array($pars)) $pars = array($pars);
if(!is_array($acts)) $acts = array($acts);
$perm = true;
foreach($acts as $i=>$action){
$res = $this->checkPerm($userid, $action, $pars[$i]);
if(PEAR::isError($res)) return $res;
$perm = $perm && $res;
}
if($perm) return TRUE;
$adesc = "[".join(',',$acts)."]";
return PEAR::raiseError("GreenBox::$adesc: access denied", GBERR_DENY);
}
/**
* Return users's home folder local ID
*
* @param sessid string, session ID
* @return local folder id
*/
function _getHomeDirId($sessid)
{
$parid = $this->getObjId(
$this->getSessLogin($sessid), $this->storId
);
return $parid;
}
/**
* Get local id from global id
*
* @param gunid string global id
* @return int local id
*/
function _idFromGunid($gunid)
{
return $this->dbc->getOne(
"SELECT id FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint"
);
}
/**
* Get global id from local id
*
* @param id int local id
* @return string global id
*/
function _gunidFromId($id)
{
if(!is_numeric($id)) return NULL;
$gunid = $this->dbc->getOne("
SELECT to_hex(gunid)as gunid FROM {$this->filesTable}
WHERE id='$id'
");
if(PEAR::isError($gunid)) return $gunid;
if(is_null($gunid)) return NULL;
return StoredFile::_normalizeGunid($gunid);
}
/* ------------------------------------------ redefined "private" methods */
/**
* Copy virtual file.<br>
* Redefined from parent class.
*
* @return id
*/
function copyObj($id, $newParid, $after=NULL)
{
$parid = $this->getParent($id);
$nid = parent::copyObj($id, $newParid, $after);
if(PEAR::isError($nid)) return $nid;
switch($this->getObjType($id)){
case"audioclip":
case"playlist":
$ac =& StoredFile::recall(&$this, $id);
if(PEAR::isError($ac)){ return $ac; }
$ac2 =& StoredFile::copyOf(&$ac, $nid);
$ac2->rename($this->getObjName($nid));
break;
case"File":
default:
}
return $nid;
}
/**
* Optionaly remove virtual file with the same name and add new one.<br>
* Redefined from parent class.
*
* @return id
*/
function addObj($name, $type, $parid=1, $aftid=NULL, $param='')
{
if(!is_null($exid = $this->getObjId($name, $parid)))
{ $this->removeObj($exid); }
return parent::addObj($name, $type, $parid, $aftid, $param);
}
/**
* Remove virtual file.<br>
* Redefined from parent class.
*
* @param id int, local id of removed object
* @return true or PEAR::error
*/
function removeObj($id)
{
switch($ot = $this->getObjType($id)){
case"audioclip":
case"playlist":
$ac =& StoredFile::recall(&$this, $id);
if(PEAR::isError($ac)) return $ac;
if($ac->isEdited()){
return PEAR::raiseError(
'BasicStor.php: removeObj: is edited'
);
}
if($ac->isAccessed()){
return PEAR::raiseError(
'BasicStor.php: removeObj: is accessed'
);
}
$ac->delete();
break;
case"File":
case"Folder":
case"Replica":
break;
default:
return PEAR::raiseError(
"GreenBox::bsDeleteFile: unknown obj type ($ot)"
);
}
$res = parent::removeObj($id);
if(PEAR::isError($res)) return $res;
return TRUE;
}
/* =============================================== test and debug methods */ /* =============================================== test and debug methods */
/** /**
* dump * dump
@ -729,7 +921,7 @@ class BasicStor extends Alib{
// $this->dbc->query("DELETE FROM {$this->filesTable}"); // $this->dbc->query("DELETE FROM {$this->filesTable}");
$ids = $this->dbc->getAll("SELECT id FROM {$this->filesTable}"); $ids = $this->dbc->getAll("SELECT id FROM {$this->filesTable}");
if(is_array($ids)) foreach($ids as $i=>$item){ if(is_array($ids)) foreach($ids as $i=>$item){
$this->removeObj($item['id']); $this->bsDeleteFile($item['id']);
} }
parent::deleteData(); parent::deleteData();
$this->initData(); $this->initData();
@ -871,7 +1063,6 @@ class BasicStor extends Alib{
#echo "{$this->accessTable}\n"; #echo "{$this->accessTable}\n";
$r = $this->dbc->query("CREATE TABLE {$this->accessTable} ( $r = $this->dbc->query("CREATE TABLE {$this->accessTable} (
gunid bigint, gunid bigint,
sessid char(32) not null default'',
token bigint, token bigint,
chsum char(32) not null default'', chsum char(32) not null default'',
ext varchar(128) not null default'', ext varchar(128) not null default'',

View File

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.22 $ Version : $Revision: 1.23 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -35,7 +35,7 @@ require_once "BasicStor.php";
* LiveSupport file storage module * LiveSupport file storage module
* *
* @author $Author: tomas $ * @author $Author: tomas $
* @version $Revision: 1.22 $ * @version $Revision: 1.23 $
* @see BasicStor * @see BasicStor
*/ */
class GreenBox extends BasicStor{ class GreenBox extends BasicStor{
@ -55,7 +55,7 @@ class GreenBox extends BasicStor{
{ {
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
return $res; return $res;
return $this->bsCreateFolder($parid, $folderName , 'Folder', $parid); return $this->bsCreateFolder($parid, $folderName);
} }
/** /**
@ -159,37 +159,6 @@ class GreenBox extends BasicStor{
return $this->bsDeleteFile($id); return $this->bsDeleteFile($id);
} }
/* ----------------------------------------------------- put, access etc. */
/**
* Create and return access link to media file
*
* @param id int, virt.file's local id
* @param sessid string, session id
* @return array with: seekable filehandle, access token
*/
function access($id, $sessid='')
{
$ac =& StoredFile::recall(&$this, $id);
if(PEAR::isError($ac)) return $ac;
if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
return $res;
return $ac->accessRawMediaData($sessid);
}
/**
* Release access link to media file
*
* @param sessid string, session id
* @param token string, access token
* @return boolean or PEAR::error
*/
function release($token, $sessid='')
{
$ac =& StoredFile::recallByToken(&$this, $token);
if(PEAR::isError($ac)) return $ac;
return $ac->releaseRawMediaData($sessid, $token);
}
/* ---------------------------------------------- replicas, versions etc. */ /* ---------------------------------------------- replicas, versions etc. */
/** /**
* Create replica.<br> * Create replica.<br>
@ -304,39 +273,11 @@ class GreenBox extends BasicStor{
if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
return $res; return $res;
$listArr = $this->bsListFolder($id); $listArr = $this->bsListFolder($id);
foreach($listArr as $i=>$v){
if($v['type'] == 'File'){
$gunid = $this->_gunidFromId($v['id']);
$listArr[$i]['type'] =
StoredFile::_getType($gunid);
$listArr[$i]['gunid'] = $gunid;
}
}
return $listArr; return $listArr;
} }
/* ---------------------------------------------------- redefined methods */ /* ---------------------------------------------------- redefined methods */
/**
* Logout and destroy session
*
* @param sessid string
* @return true/err
*/
function logout($sessid)
{
/* release all accessed files on logout - probably not useful
$acfa = $this->dbc->getAll("SELECT * FROM {$this->accessTable}
WHERE sessid='$sessid'");
if(PEAR::isError($acfa)) return $acfa;
foreach($acfa as $i=>$acf){
$ac =& StoredFile::recallByToken(&$this, $acf['token']);
$ac->releaseRawMediaData($sessid, $acf['token']);
}
*/
return parent::logout($sessid);
}
/** /**
* Add new user with home folder * Add new user with home folder
* *
@ -348,7 +289,7 @@ class GreenBox extends BasicStor{
{ {
$uid = parent::addSubj($login, $pass); $uid = parent::addSubj($login, $pass);
if(PEAR::isError($uid)) return $uid; if(PEAR::isError($uid)) return $uid;
$fid = $this->addObj($login , 'Folder', $this->storId); $fid = $this->bsCreateFolder($this->storId, $login);
if(PEAR::isError($fid)) return $fid; if(PEAR::isError($fid)) return $fid;
$res = $this->addPerm($uid, '_all', $fid, 'A'); $res = $this->addPerm($uid, '_all', $fid, 'A');
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
@ -367,7 +308,7 @@ class GreenBox extends BasicStor{
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
$id = $this->getObjId($login, $this->storId); $id = $this->getObjId($login, $this->storId);
if(PEAR::isError($id)) return $id; if(PEAR::isError($id)) return $id;
$res = $this->removeObj($id); $res = $this->bsDeleteFile($id);
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
return TRUE; return TRUE;
} }
@ -380,191 +321,11 @@ class GreenBox extends BasicStor{
*/ */
function getPath($id) function getPath($id)
{ {
$pa = parent::getPath($id, 'id, name, type'); array_shift($pa); $pa = parent::getPath($id, 'id, name, type');
array_shift($pa);
return $pa; return $pa;
} }
/**
* Get object type by id.
* (RootNode, Folder, File, )
*
* @param oid int, local object id
* @return string/err
*/
function getObjType($oid)
{
$type = $this->getObjName($oid, 'type');
if($type == 'File'){
$ftype =
StoredFile::_getType($this->_gunidFromId($oid));
if(!is_null($ftype)) $type=$ftype;
}
return $type;
}
/* ========================================== redefined "private" methods */
/**
* Copy virtual file.<br>
* Redefined from parent class.
*
* @return id
*/
function copyObj($id, $newParid, $after=NULL)
{
$parid = $this->getParent($id);
$nid = parent::copyObj($id, $newParid, $after);
if(PEAR::isError($nid)) return $nid;
switch($this->getObjType($id)){
case"audioclip":
case"playlist":
case"File":
$ac =& StoredFile::recall(&$this, $id);
if(PEAR::isError($ac)){ return $ac; }
$ac2 =& StoredFile::copyOf(&$ac, $nid);
$ac2->rename($this->getObjName($nid));
break;
default:
}
return $nid;
}
/**
* Optionaly remove virtual file with the same name and add new one.<br>
* Redefined from parent class.
*
* @return id
*/
function addObj($name, $type, $parid=1, $aftid=NULL, $param='')
{
if(!is_null($exid = $this->getObjId($name, $parid)))
{ $this->removeObj($exid); }
return parent::addObj($name, $type, $parid, $aftid, $param);
}
/**
* Remove virtual file.<br>
* Redefined from parent class.
*
* @param id int, local id of removed object
* @return true or PEAR::error
*/
function removeObj($id)
{
switch($ot = $this->getObjType($id)){
case"audioclip":
case"playlist":
case"File":
$ac =& StoredFile::recall(&$this, $id);
if(!PEAR::isError($ac)){
$ac->delete();
}
$r = parent::removeObj($id);
if(PEAR::isError($r)) return $r;
break;
case"Folder":
$r = parent::removeObj($id);
if(PEAR::isError($r)) return $r;
break;
case"Replica":
$r = parent::removeObj($id);
if(PEAR::isError($r)) return $r;
break;
default:
return PEAR::raiseError(
"GreenBox::removeObj: unknown obj type ($ot)"
);
}
return TRUE;
}
/* ==================================================== "private" methods */ /* ==================================================== "private" methods */
/**
* Return users's home folder local ID
*
* @param sessid string, session ID
* @return local folder id
*/
function _getHomeDirId($sessid)
{
$parid = $this->getObjId(
$this->getSessLogin($sessid), $this->storId
);
return $parid;
}
/**
* Check authorization - auxiliary method
*
* @param acts array of actions
* @param pars array of parameters - e.g. ids
* @param sessid string, session id
* @return true or PEAR::error
*/
function _authorize($acts, $pars, $sessid='')
{
$userid = $this->getSessUserId($sessid);
if(!is_array($pars)) $pars = array($pars);
if(!is_array($acts)) $acts = array($acts);
$perm = true;
foreach($acts as $i=>$action){
$res = $this->checkPerm($userid, $action, $pars[$i]);
if(PEAR::isError($res)) return $res;
$perm = $perm && $res;
}
if($perm) return TRUE;
$adesc = "[".join(',',$acts)."]";
return PEAR::raiseError("GreenBox::$adesc: access denied", GBERR_DENY);
}
/**
* Create fake session for downloaded files
*
* @param userid user id
* @return string sessid
*/
function _fakeSession($userid)
{
$sessid = $this->_createSessid();
if(PEAR::isError($sessid)) return $sessid;
$login = $this->getSubjName($userid);
$r = $this->dbc->query("INSERT INTO {$this->sessTable}
(sessid, userid, login, ts)
VALUES
('$sessid', '$userid', '$login', now())");
if(PEAR::isError($r)) return $r;
return $sessid;
}
/**
* Get local id from global id
*
* @param gunid string global id
* @return int local id
*/
function _idFromGunid($gunid)
{
return $this->dbc->getOne(
"SELECT id FROM {$this->filesTable} WHERE gunid=x'$gunid'::bigint"
);
}
/**
* Get global id from local id
*
* @param id int local id
* @return string global id
*/
function _gunidFromId($id)
{
if(!is_numeric($id)) return NULL;
$gunid = $this->dbc->getOne("
SELECT to_hex(gunid)as gunid FROM {$this->filesTable}
WHERE id='$id'
");
if(PEAR::isError($gunid)) return $gunid;
if(is_null($gunid)) return NULL;
return StoredFile::_normalizeGunid($gunid);
}
} }
?> ?>

View File

@ -23,19 +23,19 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.18 $ Version : $Revision: 1.19 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
require_once "GreenBox.php"; require_once "BasicStor.php";
/** /**
* LocStor class * LocStor class
* *
* Livesupport local storage interface * Livesupport local storage interface
*/ */
class LocStor extends GreenBox{ class LocStor extends BasicStor{
/* ---------------------------------------------------------------- store */ /* ---------------------------------------------------------------- store */
/** /**
* Store or replace existing audio clip * Store or replace existing audio clip
@ -95,7 +95,7 @@ class LocStor extends GreenBox{
if($fname == ''){ if($fname == ''){
$fname = "newFile"; $fname = "newFile";
} }
$res = $this->renameFile($oid, $fname, $sessid); $res = $this->bsRenameFile($oid, $fname);
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
return $this->bsOpenPut($chsum, $ac->gunid); return $this->bsOpenPut($chsum, $ac->gunid);
} }
@ -135,7 +135,7 @@ class LocStor extends GreenBox{
if(PEAR::isError($ac)) return $ac; if(PEAR::isError($ac)) return $ac;
if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE) if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
return $res; return $res;
return $ac->accessRawMediaData($sessid); return $ac->accessRawMediaData();
} }
/** /**
@ -232,7 +232,7 @@ class LocStor extends GreenBox{
if(PEAR::isError($ac)) return $ac; if(PEAR::isError($ac)) return $ac;
if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE) if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
return $res; return $res;
$md = $this->getMdata($ac->getId(), $sessid); $md = $this->bsGetMetadata($ac->getId());
if(PEAR::isError($md)) return $md; if(PEAR::isError($md)) return $md;
return $md; return $md;
} }
@ -284,7 +284,7 @@ class LocStor extends GreenBox{
'playlistResults' => $resPL['results'] 'playlistResults' => $resPL['results']
); );
} }
$srchRes = $this->localSearch($criteria, $sessid); $srchRes = $this->bsLocalSearch($criteria);
$res = array('audioClipResults'=>NULL, 'playlistResults'=>NULL); $res = array('audioClipResults'=>NULL, 'playlistResults'=>NULL);
switch($filetype){ switch($filetype){
case"audioclip": case"audioclip":
@ -356,12 +356,7 @@ class LocStor extends GreenBox{
if(PEAR::isError($ac)) return $ac; if(PEAR::isError($ac)) return $ac;
if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE) if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE)
return $res; return $res;
if($ac->isAccessed()){ $res = $this->bsDeleteFile($ac->getId());
return PEAR::raiseError(
'LocStor.php: deleteAudioClip: is accessed'
);
}
$res = $this->deleteFile($ac->getId(), $sessid);
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
return TRUE; return TRUE;
} }
@ -392,8 +387,6 @@ class LocStor extends GreenBox{
{ {
$this->deleteData(); $this->deleteData();
$rootHD = $this->getObjId('root', $this->storId); $rootHD = $this->getObjId('root', $this->storId);
# $this->login('root', $this->config['tmpRootPass']);
# $s = $this->sessid;
include"../tests/sampleData.php"; include"../tests/sampleData.php";
$res = array(); $res = array();
foreach($sampleData as $k=>$it){ foreach($sampleData as $k=>$it){
@ -420,7 +413,6 @@ class LocStor extends GreenBox{
if(PEAR::isError($r)){ return $r; } if(PEAR::isError($r)){ return $r; }
$res[] = $this->_gunidFromId($r); $res[] = $this->_gunidFromId($r);
} }
# $this->logout($this->sessid);
return $res; return $res;
} }
@ -461,7 +453,7 @@ class LocStor extends GreenBox{
if($fname == ''){ if($fname == ''){
$fname = "newFile.xml"; $fname = "newFile.xml";
} }
$res = $this->renameFile($oid, $fname, $sessid); $res = $this->bsRenameFile($oid, $fname);
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
$res = $ac->setState('ready'); $res = $ac->setState('ready');
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
@ -540,12 +532,7 @@ class LocStor extends GreenBox{
if(PEAR::isError($ac)) return $ac; if(PEAR::isError($ac)) return $ac;
if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE) if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE)
return $res; return $res;
if($this->_isEdited($playlistId)){ $res = $this->bsDeleteFile($ac->getId());
return PEAR::raiseError(
'LocStor.php: deletePlaylist: playlist is edited'
);
}
$res = $this->deleteFile($ac->getId(), $sessid);
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
return TRUE; return TRUE;
} }
@ -626,9 +613,8 @@ class LocStor extends GreenBox{
*/ */
function _isEdited($playlistId) function _isEdited($playlistId)
{ {
$state = StoredFile::_getState($playlistId); $ac =& StoredFile::recallByGunid(&$this, $playlistId);
if($state == 'edited'){ return TRUE; } return $ac->isEdited($playlistId);
return FALSE;
} }
/** /**

View File

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.14 $ Version : $Revision: 1.15 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/StoredFile.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/StoredFile.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -274,28 +274,16 @@ class StoredFile{
* Increase access counter, create access token, insert access record, * Increase access counter, create access token, insert access record,
* call access method of RawMediaData * call access method of RawMediaData
* *
* @param sessid string
* @return array with: access URL, access token * @return array with: access URL, access token
*/ */
function accessRawMediaData($sessid) function accessRawMediaData()
{ {
$this->dbc->query("BEGIN");
$res = $this->dbc->query("
UPDATE {$this->filesTable}
SET currentlyAccessing=currentlyAccessing+1
WHERE gunid=x'{$this->gunid}'::bigint
");
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
# $token = $this->_createGunid();
$realFname = $this->_getRealRADFname(); $realFname = $this->_getRealRADFname();
$ext = $this->_getExt(); $ext = $this->_getExt();
$res = $this->gb->bsAccess($realFname, $ext, $this->gunid);
$res = $this->gb->bsAccess($realFname, $ext, $this->gunid, $sessid); if(PEAR::isError($res)){ return $res; }
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
$resultArray = $resultArray =
array('url'=>"file://{$res['fname']}", 'token'=>$res['token']); array('url'=>"file://{$res['fname']}", 'token'=>$res['token']);
$res = $this->dbc->query("COMMIT");
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
return $resultArray; return $resultArray;
} }
@ -308,16 +296,8 @@ class StoredFile{
*/ */
function releaseRawMediaData($token) function releaseRawMediaData($token)
{ {
$this->dbc->query("BEGIN");
$res = $this->dbc->query("UPDATE {$this->filesTable}
SET currentlyAccessing=currentlyAccessing-1
WHERE gunid=x'{$this->gunid}'::bigint AND currentlyAccessing>0
");
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
$res = $this->gb->bsRelease($token); $res = $this->gb->bsRelease($token);
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; } if(PEAR::isError($res)){ return $res; }
$res = $this->dbc->query("COMMIT");
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
return TRUE; return TRUE;
} }
@ -469,12 +449,33 @@ class StoredFile{
function isAccessed($gunid=NULL) function isAccessed($gunid=NULL)
{ {
if(is_null($gunid)) $gunid = $this->gunid; if(is_null($gunid)) $gunid = $this->gunid;
return (0 < $this->dbc->getOne(" $ca = $this->dbc->getOne("
SELECT currentlyAccessing FROM {$this->filesTable} SELECT currentlyAccessing FROM {$this->filesTable}
WHERE gunid=x'$gunid'::bigint WHERE gunid=x'$gunid'::bigint
")); ");
if(is_null($ca)){
return PEAR::raiseError(
"StoredFile::isAccessed: invalid gunid ($gunid)",
GBERR_FOBJNEX
);
}
return ($ca > 0);
} }
/**
* Returns true if virtual file is edited
*
* @param playlistId string, playlist global unique ID
* @return boolean
*/
function isEdited($gunid=NULL)
{
if(is_null($gunid)) $gunid = $this->gunid;
$state = $this->_getState($gunid);
if($state == 'edited'){ return TRUE; }
return FALSE;
}
/** /**
* Returns local id of virtual file * Returns local id of virtual file
* *