Webstream support added +minor changes.

This commit is contained in:
tomas 2005-02-09 22:43:38 +00:00
parent 1291e232d6
commit e7e6569e01
5 changed files with 124 additions and 33 deletions

View File

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.26 $ Version : $Revision: 1.27 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -52,7 +52,7 @@ require_once "Transport.php";
* Core of LiveSupport file storage module * Core of LiveSupport file storage module
* *
* @author $Author: tomas $ * @author $Author: tomas $
* @version $Revision: 1.26 $ * @version $Revision: 1.27 $
* @see Alib * @see Alib
*/ */
class BasicStor extends Alib{ class BasicStor extends Alib{
@ -147,6 +147,7 @@ class BasicStor extends Alib{
switch($this->getObjType($id)){ switch($this->getObjType($id)){
case"audioclip": case"audioclip":
case"playlist": case"playlist":
case"webstream":
$ac =& StoredFile::recall($this, $id); $ac =& StoredFile::recall($this, $id);
if(PEAR::isError($ac)){ if(PEAR::isError($ac)){
// catch nonerror exception: // catch nonerror exception:
@ -187,6 +188,7 @@ class BasicStor extends Alib{
switch($this->getObjType($id)){ switch($this->getObjType($id)){
case"audioclip": case"audioclip":
case"playlist": case"playlist":
case"webstream":
case"File": case"File":
return $this->_relocateSubtree($id, $did); return $this->_relocateSubtree($id, $did);
break; break;
@ -224,6 +226,7 @@ class BasicStor extends Alib{
switch($this->getObjType($id)){ switch($this->getObjType($id)){
case"audioclip": case"audioclip":
case"playlist": case"playlist":
case"webstream":
case"File": case"File":
return $this->_copySubtree($id, $did); return $this->_copySubtree($id, $did);
break; break;
@ -620,12 +623,15 @@ class BasicStor extends Alib{
* @param value string/NULL value to store, if NULL then delete record * @param value string/NULL value to store, if NULL then delete record
* @param lang string, optional xml:lang value for select language version * @param lang string, optional xml:lang value for select language version
* @param mid int, metadata record id (OPTIONAL on unique elements) * @param mid int, metadata record id (OPTIONAL on unique elements)
* @param container string, container element name for insert
* @return boolean * @return boolean
*/ */
function bsSetMetadataValue($id, $category, $value, $lang=NULL, $mid=NULL) function bsSetMetadataValue(
$id, $category, $value, $lang=NULL, $mid=NULL, $container='metadata')
{ {
$ac =& StoredFile::recall($this, $id); $ac =& StoredFile::recall($this, $id);
$res = $ac->md->setMetadataValue($category, $value, $lang, $mid); $res = $ac->md->setMetadataValue(
$category, $value, $lang, $mid, $container);
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
$r = $ac->md->regenerateXmlFile(); $r = $ac->md->regenerateXmlFile();
if(PEAR::isError($r)) return $r; if(PEAR::isError($r)) return $r;
@ -855,7 +861,7 @@ class BasicStor extends Alib{
} }
if($perm) return TRUE; if($perm) return TRUE;
$adesc = "[".join(',',$acts)."]"; $adesc = "[".join(',',$acts)."]";
return PEAR::raiseError("GreenBox::$adesc: access denied", GBERR_DENY); return PEAR::raiseError("BasicStor::$adesc: access denied", GBERR_DENY);
} }
/** /**
@ -922,6 +928,22 @@ class BasicStor extends Alib{
return $ftype; return $ftype;
} }
/**
* Check gunid format
*
* @param gunid string, global unique ID
* @return boolean
*/
function _checkGunid($gunid)
{
if(!preg_match("|^([0-9a-fA-F]{16})?$|", $gunid)){
return PEAR::raiseError(
"BasicStor.php: Wrong gunid ($gunid)"
);
}
return TRUE;
}
/* ------------------------------------------ redefined "private" methods */ /* ------------------------------------------ redefined "private" methods */
/** /**
* Copy virtual file.<br> * Copy virtual file.<br>
@ -937,6 +959,7 @@ class BasicStor extends Alib{
switch($this->getObjType($id)){ switch($this->getObjType($id)){
case"audioclip": case"audioclip":
case"playlist": case"playlist":
case"webstream":
$ac =& StoredFile::recall($this, $id); $ac =& StoredFile::recall($this, $id);
if(PEAR::isError($ac)){ return $ac; } if(PEAR::isError($ac)){ return $ac; }
$ac2 =& StoredFile::copyOf($ac, $nid); $ac2 =& StoredFile::copyOf($ac, $nid);
@ -974,6 +997,7 @@ class BasicStor extends Alib{
switch($ot = $this->getObjType($id)){ switch($ot = $this->getObjType($id)){
case"audioclip": case"audioclip":
case"playlist": case"playlist":
case"webstream":
$ac =& StoredFile::recall($this, $id); $ac =& StoredFile::recall($this, $id);
if(PEAR::isError($ac)) return $ac; if(PEAR::isError($ac)) return $ac;
if($ac->isEdited() && !$forced){ if($ac->isEdited() && !$forced){
@ -994,7 +1018,7 @@ class BasicStor extends Alib{
break; break;
default: default:
return PEAR::raiseError( return PEAR::raiseError(
"GreenBox::bsDeleteFile: unknown obj type ($ot)" "BasicStor::bsDeleteFile: unknown obj type ($ot)"
); );
} }
$res = parent::removeObj($id); $res = parent::removeObj($id);

View File

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.29 $ Version : $Revision: 1.30 $
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.29 $ * @version $Revision: 1.30 $
* @see BasicStor * @see BasicStor
*/ */
class GreenBox extends BasicStor{ class GreenBox extends BasicStor{
@ -82,6 +82,33 @@ class GreenBox extends BasicStor{
); );
} }
/**
* Store new webstream
*
* @param parid int, parent id
* @param fileName string, name for new file
* @param mdataFileLP string, local path of metadata file
* @param sessid string, session id
* @param gunid string, global unique id OPTIONAL
* @param url string, wewbstream url
* @return int
* @exception PEAR::error
*/
function storeWebstream($parid, $fileName, $mdataFileLP, $sessid='',
$gunid=NULL, $url)
{
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
return $res;
$oid = $this->bsPutFile(
$parid, $fileName, '', $mdataFileLP, $gunid, 'webstream'
);
if(PEAR::isError($oid)) return $oid;
$r = $this-> bsSetMetadataValue(
$oid, 'ls:url', $url, NULL, NULL, 'audioClip');
if(PEAR::isError($r)) return $r;
return $oid;
}
/** /**
* Analyze media file for internal metadata information * Analyze media file for internal metadata information
* *
@ -259,7 +286,7 @@ class GreenBox extends BasicStor{
* @param mid int, metadata record id (OPTIONAL on unique elements) * @param mid int, metadata record id (OPTIONAL on unique elements)
* @return boolean * @return boolean
*/ */
function setMdataValue($id, $category, $sessid='', $value, $lang=NULL, $mid=NULL) function setMdataValue($id, $category, $sessid, $value, $lang=NULL, $mid=NULL)
{ {
if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE) if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE)
return $res; return $res;

View File

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.26 $ Version : $Revision: 1.27 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -40,32 +40,32 @@ class LocStor extends BasicStor{
/** /**
* Store or replace existing audio clip * Store or replace existing audio clip
* *
* @param sessid string * @param sessid string, session id
* @param gunid string * @param gunid string, global unique id
* @param metadata string, metadata XML string * @param metadata string, metadata XML string
* @param fname string, human readable menmonic file name * @param fname string, human readable menmonic file name
* with extension corresponding to filetype * with extension corresponding to filetype
* @param chsum string, md5 checksum of media file * @param chsum string, md5 checksum of media file
* @param ftype string audioclip | playlist * @param ftype string audioclip | playlist | webstream
* @return struct {url:writable URL for HTTP PUT, token:access token * @return struct {url:writable URL for HTTP PUT, token:access token
*/ */
function storeAudioClipOpen( function storeAudioClipOpen(
$sessid, $gunid, $metadata, $fname, $chsum, $ftype='audioclip' $sessid, $gunid, $metadata, $fname, $chsum, $ftype='audioclip'
) )
{ {
// test if specified gunid exists: // test of gunid format:
if(!preg_match("|^([0-9a-fA-F]{16})?$|", $gunid)){ if(!$this->_checkGunid($gunid)){
return PEAR::raiseError( return PEAR::raiseError(
"LocStor.php: storeAudioClipOpen: Wrong gunid ($gunid)" "LocStor.php: storeAudioClipOpen: Wrong gunid ($gunid)"
); );
} }
// test if specified gunid exists:
$ac =& StoredFile::recallByGunid($this, $gunid); $ac =& StoredFile::recallByGunid($this, $gunid);
if(!PEAR::isError($ac)){ if(!PEAR::isError($ac)){
// gunid exists - do replace // gunid exists - do replace
$oid = $ac->getId(); $oid = $ac->getId();
if(($res = $this->_authorize( if(($res = $this->_authorize('write', $oid, $sessid)) !== TRUE)
'write', $oid, $sessid { return $res; }
)) !== TRUE) return $res;
if($ac->isAccessed()){ if($ac->isAccessed()){
return PEAR::raiseError( return PEAR::raiseError(
'LocStor.php: storeAudioClipOpen: is accessed' 'LocStor.php: storeAudioClipOpen: is accessed'
@ -76,12 +76,12 @@ class LocStor extends BasicStor{
); );
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
}else{ }else{
// gunid doesn't exists - do insert // gunid doesn't exists - do insert:
$tmpFname = uniqid(''); $tmpFname = uniqid('');
$parid = $this->_getHomeDirId($sessid); $parid = $this->_getHomeDirId($sessid);
if(PEAR::isError($parid)) return $parid; if(PEAR::isError($parid)) return $parid;
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
return $res; { return $res; }
$oid = $this->addObj($tmpFname , 'File', $parid); $oid = $this->addObj($tmpFname , 'File', $parid);
if(PEAR::isError($oid)) return $oid; if(PEAR::isError($oid)) return $oid;
$ac =& StoredFile::insert( $ac =& StoredFile::insert(
@ -136,6 +136,33 @@ class LocStor extends BasicStor{
return $this->bsCheckPut($token); return $this->bsCheckPut($token);
} }
/**
* Store webstream
*
* @param sessid string, session id
* @param gunid string, global unique id
* @param metadata string, metadata XML string
* @param fname string, human readable menmonic file name
* with extension corresponding to filetype
* @param url string, wewbstream url
* @return
*/
function storeWebstream($sessid, $gunid, $metadata, $fname, $url)
{
$a = $this->storeAudioClipOpen(
$sessid, $gunid, $metadata, $fname, md5(''), 'webstream');
if(PEAR::isError($a)) return $a;
$gunid = $this->storeAudioClipClose($sessid, $a['token']);
if(PEAR::isError($gunid)) return $gunid;
$ac =& StoredFile::recallByGunid($this, $gunid);
if(PEAR::isError($ac)) return $ac;
$oid = $ac->getId();
$r = $this-> bsSetMetadataValue(
$oid, 'ls:url', $url, NULL, NULL, 'audioClip');
if(PEAR::isError($r)) return $r;
return $gunid;
}
/* --------------------------------------------------------------- access */ /* --------------------------------------------------------------- access */
/** /**
* Make access to audio clip * Make access to audio clip
@ -368,7 +395,11 @@ class LocStor extends BasicStor{
function existsAudioClip($sessid, $gunid) function existsAudioClip($sessid, $gunid)
{ {
$ex = $this->existsFile($sessid, $gunid, 'audioclip'); $ex = $this->existsFile($sessid, $gunid, 'audioclip');
if(!$ex) return FALSE; if($ex === FALSE ){
$ex = $this->existsFile($sessid, $gunid, 'webstream');
}
if($ex === FALSE ) return FALSE;
if(PEAR::isError($ex)){ return $ex; }
$ac =& StoredFile::recallByGunid($this, $gunid); $ac =& StoredFile::recallByGunid($this, $gunid);
if(PEAR::isError($ac)){ return $ac; } if(PEAR::isError($ac)){ return $ac; }
return $ac->exists(); return $ac->exists();

View File

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.16 $ Version : $Revision: 1.17 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/MetaData.php,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/MetaData.php,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -174,9 +174,9 @@ class MetaData{
// return $this->genXMLDoc(); // obsolete // return $this->genXMLDoc(); // obsolete
if(file_exists($this->fname)){ if(file_exists($this->fname)){
$res = file_get_contents($this->fname); $res = file_get_contents($this->fname);
# require_once "XML/Beautifier.php"; //require_once "XML/Beautifier.php";
# $fmt = new XML_Beautifier(); //$fmt = new XML_Beautifier();
# $res = $fmt->formatString($res); //$res = $fmt->formatString($res);
return $res; return $res;
}else }else
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<metadata/>\n"; return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<metadata/>\n";
@ -243,9 +243,11 @@ class MetaData{
* @param value string/NULL value to store, if NULL then delete record * @param value string/NULL value to store, if NULL then delete record
* @param lang string, optional xml:lang value for select language version * @param lang string, optional xml:lang value for select language version
* @param mid int, metadata record id (OPTIONAL on unique elements) * @param mid int, metadata record id (OPTIONAL on unique elements)
* @param container string, container element name for insert
* @return boolean * @return boolean
*/ */
function setMetadataValue($category, $value, $lang=NULL, $mid=NULL) function setMetadataValue($category, $value, $lang=NULL, $mid=NULL,
$container='metadata')
{ {
$rows = $this->getMetadataValue($category, $lang); $rows = $this->getMetadataValue($category, $lang);
$aktual = NULL; $aktual = NULL;
@ -277,12 +279,12 @@ class MetaData{
} }
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
}else{ }else{
$container = $this->getMetadataValue('metadata', NULL, '_blank'); $contArr = $this->getMetadataValue($container, NULL, '_blank');
if(PEAR::isError($container)) return $container; if(PEAR::isError($contArr)) return $contArr;
$id = $container[0]['mid']; $id = $contArr[0]['mid'];
if(is_null($id)){ if(is_null($id)){
return PEAR::raiseError( return PEAR::raiseError(
"MetaData::setMdataValue: metadata container not found" "MetaData::setMdataValue: container ($container) not found"
); );
} }
$a = XML_Util::splitQualifiedName(strtolower($category)); $a = XML_Util::splitQualifiedName(strtolower($category));
@ -302,7 +304,7 @@ class MetaData{
} }
/** /**
* Regenerate XML metadata file after category value change * Regenerate XML metadata file after metadata value change
* *
* @return boolean * @return boolean
*/ */
@ -490,6 +492,8 @@ class MetaData{
$objns=NULL, $object=NULL) $objns=NULL, $object=NULL)
{ {
//echo "$subjns, $subject, $predns, $predicate, $predxml, $objns, $object\n"; //echo "$subjns, $subject, $predns, $predicate, $predxml, $objns, $object\n";
$predns = strtolower($predns);
$predicate = strtolower($predicate);
$predns_sql = (is_null($predns) ? "NULL" : "'$predns'" ); $predns_sql = (is_null($predns) ? "NULL" : "'$predns'" );
$objns_sql = (is_null($objns) ? "NULL" : "'$objns'" ); $objns_sql = (is_null($objns) ? "NULL" : "'$objns'" );
$object_sql = (is_null($object)? "NULL" : "'$object'"); $object_sql = (is_null($object)? "NULL" : "'$object'");
@ -514,6 +518,7 @@ class MetaData{
/** /**
* Delete metadata record recursively * Delete metadata record recursively
* *
* @param mid int local metadata record id
* @return boolean * @return boolean
*/ */
function deleteRecord($mid) function deleteRecord($mid)

View File

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.19 $ Version : $Revision: 1.20 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -496,7 +496,11 @@ class StoredFile{
WHERE gunid=x'{$this->gunid}'::bigint WHERE gunid=x'{$this->gunid}'::bigint
"); ");
if(PEAR::isError($indb)) return $indb; if(PEAR::isError($indb)) return $indb;
return (!is_null($indb) && $this->rmd->exists()); if(is_null($indb)) return FALSE;
if($this->gb->_getType($this->gunid) == 'audioclip'){
return $this->rmd->exists();
}
return TRUE;
} }
/* ==================================================== "private" methods */ /* ==================================================== "private" methods */