diff --git a/livesupport/modules/storageServer/var/BasicStor.php b/livesupport/modules/storageServer/var/BasicStor.php index 3173fe762..c01c223f7 100644 --- a/livesupport/modules/storageServer/var/BasicStor.php +++ b/livesupport/modules/storageServer/var/BasicStor.php @@ -23,7 +23,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -52,7 +52,7 @@ require_once "Transport.php"; * Core of LiveSupport file storage module * * @author $Author: tomas $ - * @version $Revision: 1.26 $ + * @version $Revision: 1.27 $ * @see Alib */ class BasicStor extends Alib{ @@ -147,6 +147,7 @@ class BasicStor extends Alib{ switch($this->getObjType($id)){ case"audioclip": case"playlist": + case"webstream": $ac =& StoredFile::recall($this, $id); if(PEAR::isError($ac)){ // catch nonerror exception: @@ -187,6 +188,7 @@ class BasicStor extends Alib{ switch($this->getObjType($id)){ case"audioclip": case"playlist": + case"webstream": case"File": return $this->_relocateSubtree($id, $did); break; @@ -224,6 +226,7 @@ class BasicStor extends Alib{ switch($this->getObjType($id)){ case"audioclip": case"playlist": + case"webstream": case"File": return $this->_copySubtree($id, $did); break; @@ -620,12 +623,15 @@ class BasicStor extends Alib{ * @param value string/NULL value to store, if NULL then delete record * @param lang string, optional xml:lang value for select language version * @param mid int, metadata record id (OPTIONAL on unique elements) + * @param container string, container element name for insert * @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); - $res = $ac->md->setMetadataValue($category, $value, $lang, $mid); + $res = $ac->md->setMetadataValue( + $category, $value, $lang, $mid, $container); if(PEAR::isError($res)) return $res; $r = $ac->md->regenerateXmlFile(); if(PEAR::isError($r)) return $r; @@ -855,7 +861,7 @@ class BasicStor extends Alib{ } if($perm) return TRUE; $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; } + /** + * 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 */ /** * Copy virtual file.
@@ -937,6 +959,7 @@ class BasicStor extends Alib{ switch($this->getObjType($id)){ case"audioclip": case"playlist": + case"webstream": $ac =& StoredFile::recall($this, $id); if(PEAR::isError($ac)){ return $ac; } $ac2 =& StoredFile::copyOf($ac, $nid); @@ -974,6 +997,7 @@ class BasicStor extends Alib{ switch($ot = $this->getObjType($id)){ case"audioclip": case"playlist": + case"webstream": $ac =& StoredFile::recall($this, $id); if(PEAR::isError($ac)) return $ac; if($ac->isEdited() && !$forced){ @@ -994,7 +1018,7 @@ class BasicStor extends Alib{ break; default: return PEAR::raiseError( - "GreenBox::bsDeleteFile: unknown obj type ($ot)" + "BasicStor::bsDeleteFile: unknown obj type ($ot)" ); } $res = parent::removeObj($id); diff --git a/livesupport/modules/storageServer/var/GreenBox.php b/livesupport/modules/storageServer/var/GreenBox.php index 332bd4444..aa7b420aa 100644 --- a/livesupport/modules/storageServer/var/GreenBox.php +++ b/livesupport/modules/storageServer/var/GreenBox.php @@ -23,7 +23,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -35,7 +35,7 @@ require_once "BasicStor.php"; * LiveSupport file storage module * * @author $Author: tomas $ - * @version $Revision: 1.29 $ + * @version $Revision: 1.30 $ * @see 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 * @@ -259,7 +286,7 @@ class GreenBox extends BasicStor{ * @param mid int, metadata record id (OPTIONAL on unique elements) * @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) return $res; diff --git a/livesupport/modules/storageServer/var/LocStor.php b/livesupport/modules/storageServer/var/LocStor.php index 9c2bebe4e..d28cb72f1 100644 --- a/livesupport/modules/storageServer/var/LocStor.php +++ b/livesupport/modules/storageServer/var/LocStor.php @@ -23,7 +23,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -40,32 +40,32 @@ class LocStor extends BasicStor{ /** * Store or replace existing audio clip * - * @param sessid string - * @param gunid string + * @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 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 */ function storeAudioClipOpen( $sessid, $gunid, $metadata, $fname, $chsum, $ftype='audioclip' ) { - // test if specified gunid exists: - if(!preg_match("|^([0-9a-fA-F]{16})?$|", $gunid)){ + // test of gunid format: + if(!$this->_checkGunid($gunid)){ return PEAR::raiseError( "LocStor.php: storeAudioClipOpen: Wrong gunid ($gunid)" ); } + // test if specified gunid exists: $ac =& StoredFile::recallByGunid($this, $gunid); if(!PEAR::isError($ac)){ // gunid exists - do replace $oid = $ac->getId(); - if(($res = $this->_authorize( - 'write', $oid, $sessid - )) !== TRUE) return $res; + if(($res = $this->_authorize('write', $oid, $sessid)) !== TRUE) + { return $res; } if($ac->isAccessed()){ return PEAR::raiseError( 'LocStor.php: storeAudioClipOpen: is accessed' @@ -76,12 +76,12 @@ class LocStor extends BasicStor{ ); if(PEAR::isError($res)) return $res; }else{ - // gunid doesn't exists - do insert + // gunid doesn't exists - do insert: $tmpFname = uniqid(''); $parid = $this->_getHomeDirId($sessid); if(PEAR::isError($parid)) return $parid; if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) - return $res; + { return $res; } $oid = $this->addObj($tmpFname , 'File', $parid); if(PEAR::isError($oid)) return $oid; $ac =& StoredFile::insert( @@ -136,6 +136,33 @@ class LocStor extends BasicStor{ 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 */ /** * Make access to audio clip @@ -368,7 +395,11 @@ class LocStor extends BasicStor{ function existsAudioClip($sessid, $gunid) { $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); if(PEAR::isError($ac)){ return $ac; } return $ac->exists(); diff --git a/livesupport/modules/storageServer/var/MetaData.php b/livesupport/modules/storageServer/var/MetaData.php index 39698b0b9..23650e238 100644 --- a/livesupport/modules/storageServer/var/MetaData.php +++ b/livesupport/modules/storageServer/var/MetaData.php @@ -23,7 +23,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -174,9 +174,9 @@ class MetaData{ // return $this->genXMLDoc(); // obsolete if(file_exists($this->fname)){ $res = file_get_contents($this->fname); -# require_once "XML/Beautifier.php"; -# $fmt = new XML_Beautifier(); -# $res = $fmt->formatString($res); + //require_once "XML/Beautifier.php"; + //$fmt = new XML_Beautifier(); + //$res = $fmt->formatString($res); return $res; }else return "\n\n"; @@ -243,9 +243,11 @@ class MetaData{ * @param value string/NULL value to store, if NULL then delete record * @param lang string, optional xml:lang value for select language version * @param mid int, metadata record id (OPTIONAL on unique elements) + * @param container string, container element name for insert * @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); $aktual = NULL; @@ -277,12 +279,12 @@ class MetaData{ } if(PEAR::isError($res)) return $res; }else{ - $container = $this->getMetadataValue('metadata', NULL, '_blank'); - if(PEAR::isError($container)) return $container; - $id = $container[0]['mid']; + $contArr = $this->getMetadataValue($container, NULL, '_blank'); + if(PEAR::isError($contArr)) return $contArr; + $id = $contArr[0]['mid']; if(is_null($id)){ return PEAR::raiseError( - "MetaData::setMdataValue: metadata container not found" + "MetaData::setMdataValue: container ($container) not found" ); } $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 */ @@ -490,6 +492,8 @@ class MetaData{ $objns=NULL, $object=NULL) { //echo "$subjns, $subject, $predns, $predicate, $predxml, $objns, $object\n"; + $predns = strtolower($predns); + $predicate = strtolower($predicate); $predns_sql = (is_null($predns) ? "NULL" : "'$predns'" ); $objns_sql = (is_null($objns) ? "NULL" : "'$objns'" ); $object_sql = (is_null($object)? "NULL" : "'$object'"); @@ -514,6 +518,7 @@ class MetaData{ /** * Delete metadata record recursively * + * @param mid int local metadata record id * @return boolean */ function deleteRecord($mid) diff --git a/livesupport/modules/storageServer/var/StoredFile.php b/livesupport/modules/storageServer/var/StoredFile.php index d1941ca8b..dc74ec864 100644 --- a/livesupport/modules/storageServer/var/StoredFile.php +++ b/livesupport/modules/storageServer/var/StoredFile.php @@ -23,7 +23,7 @@ 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 $ ------------------------------------------------------------------------------*/ @@ -496,7 +496,11 @@ class StoredFile{ WHERE gunid=x'{$this->gunid}'::bigint "); 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 */