From f57fa14fbd864d7a0541feaf5ee067dff28166b8 Mon Sep 17 00:00:00 2001 From: tomas Date: Wed, 29 Dec 2004 01:51:00 +0000 Subject: [PATCH] Playlist methods added in PHP and XMLRPC layers. +solved bug: http://bugs.campware.org/view.php?id=520 +minor change in _createGunid - for only non-negative bigint. --- livesupport/modules/storageServer/Makefile | 3 +- .../modules/storageServer/var/BasicStor.php | 281 +------------ .../modules/storageServer/var/GreenBox.php | 53 +-- .../modules/storageServer/var/LocStor.php | 233 ++++++++++- .../modules/storageServer/var/MetaData.php | 90 ++++- .../storageServer/var/RawMediaData.php | 4 +- .../modules/storageServer/var/StoredFile.php | 64 +-- .../modules/storageServer/var/html/gbHttp.php | 5 +- .../storageServer/var/tests/mdata4.xml | 16 + .../storageServer/var/tests/mdata5.xml | 2 + .../storageServer/var/tests/sampleData.php | 2 +- .../storageServer/var/xmlrpc/simpleGet.php | 36 +- .../storageServer/var/xmlrpc/testRunner.sh | 94 ++++- .../storageServer/var/xmlrpc/xrLocStor.php | 381 +++++++++++++++++- .../storageServer/var/xmlrpc/xr_cli_test.py | 23 +- 15 files changed, 896 insertions(+), 391 deletions(-) create mode 100644 livesupport/modules/storageServer/var/tests/mdata4.xml create mode 100644 livesupport/modules/storageServer/var/tests/mdata5.xml diff --git a/livesupport/modules/storageServer/Makefile b/livesupport/modules/storageServer/Makefile index 06162d8f5..98582cc81 100644 --- a/livesupport/modules/storageServer/Makefile +++ b/livesupport/modules/storageServer/Makefile @@ -20,7 +20,7 @@ # # # Author : $Author: tomas $ -# Version : $Revision: 1.6 $ +# Version : $Revision: 1.7 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/Attic/Makefile,v $ # # @configure_input@ @@ -119,6 +119,7 @@ distclean: clean docclean testonly: ${TEST_RUNNER} ${TEST_RUNNER} + ${TEST_RUNNER} playlists # $(MAKE) transtest check: all testonly diff --git a/livesupport/modules/storageServer/var/BasicStor.php b/livesupport/modules/storageServer/var/BasicStor.php index 3da7a0ad6..ebcc7832f 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.6 $ + Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/BasicStor.php,v $ ------------------------------------------------------------------------------*/ @@ -48,7 +48,7 @@ require_once "Transport.php"; * Core of LiveSupport file storage module * * @author $Author: tomas $ - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * @see Alib */ class BasicStor extends Alib{ @@ -224,7 +224,7 @@ class BasicStor extends Alib{ } /** - * Create and return access link to media file + * Create and return access link to real file * * @param realFname string, local filepath to accessed file * @param ext string, useful filename extension for accessed file @@ -261,7 +261,7 @@ class BasicStor extends Alib{ } /** - * Release access link to media file + * Release access link to real file * * @param token string, access token * @param type string 'access'|'download' @@ -312,17 +312,7 @@ class BasicStor extends Alib{ $ext = $ac->_getExt(); break; case"metadata": - $md = $this->bsGetMdata($id); - $fname = "{$this->bufferDir}/$gunid"; - $e = FALSE; - if(!$fh = fopen($fname, "w")){ $e = TRUE; } - elseif(fwrite($fh, $md) === FALSE){ $e = TRUE; } - if($e){ - return PEAR::raiseError( - "BasicStor::bsOpenDownload: can't write ($fname)", - GBERR_FILEIO); - } - fclose($fh); + $fname = $ac->_getRealMDFname(); $ext = "xml"; break; } @@ -341,15 +331,10 @@ class BasicStor extends Alib{ */ function bsCloseDownload($token, $part='media') { - if($part == 'metadata'){ - $gunid = $this->dbc->getOne(" - SELECT to_hex(gunid)as gunid FROM {$this->accessTable} - WHERE token=x'{$token}'::bigint AND type='download' - "); - if(PEAR::isError($gunid)){ return $gunid; } - $gunid = StoredFile::_normalizeGunid($gunid); - $fname = "{$this->bufferDir}/$gunid"; - @unlink($fname); + if(!$this->bsCheckToken($token, 'download')){ + return PEAR::raiseError( + "BasicStor::bsCloseDownload: invalid token ($token)" + ); } return $this->bsRelease($token, 'download'); } @@ -381,7 +366,8 @@ class BasicStor extends Alib{ } /** - * Get file from writable URL and insert it to the storage + * Get file from writable URL and return local filename. + * Caller should move or unlink this file. * * @param token string, PUT token * @return string, local path of the file having been put @@ -473,62 +459,27 @@ class BasicStor extends Alib{ /* ------------------------------------------------------------- metadata */ /** - * Update metadata tree + * Replace metadata with new XML file or string * * @param id int, virt.file's local id - * @param mdataFile string, local path of metadata XML file + * @param mdata string, local path of metadata XML file + * @param mdataLoc string 'file'|'string' * @return boolean or PEAR::error */ - function bsUpdateMetadata($id, $mdataFile) + function bsReplaceMetadata($id, $mdata, $mdataLoc='file') { $ac =& StoredFile::recall(&$this, $id); if(PEAR::isError($ac)) return $ac; - return $ac->updateMetaData($mdataFile); + return $ac->replaceMetaData($mdata, $mdataLoc); } /** - * Update object namespace and value of one metadata record - * - * @param id int, virt.file's local id - * @param mdid int, metadata record id - * @param object string, object value, e.g. title string - * @param objns string, object namespace prefix, have to be defined - * in file's metadata (or reserved prefix) - * @return boolean or PEAR::error - * @see MetaData - */ - function bsUpdateMetadataRecord($id, $mdid, $object, $objns='_L') - { - $ac =& StoredFile::recall(&$this, $id); - if(PEAR::isError($ac)) return $ac; - return $ac->updateMetaDataRecord($mdid, $object, $objns); - } - - /** - * Add single metadata record.
- * TODO: NOT FINISHED
- * Params could be changed! - * - * @param id int, virt.file's local id - * @param propertyName string - * @param propertyValue string - * @return boolean or PEAR::error - * @see MetaData - */ - function bsAddMetaDataRecord($id, $propertyName, $propertyValue) - { - return PEAR::raiseError( - 'GreenBox::addMetaDataRecord: not implemented', GBERR_NOTIMPL - ); - } - - /** - * Get metadata XML tree as string + * Get metadata as XML string * * @param id int, virt.file's local id * @return string or PEAR::error */ - function bsGetMdata($id) + function bsGetMetadata($id) { $ac =& StoredFile::recall(&$this, $id); if(PEAR::isError($ac)) return $ac; @@ -647,202 +598,6 @@ class BasicStor extends Alib{ return $nid; } - - - - /* -------------------------------------------- remote repository methods */ - - /** - * Upload file to remote repository - * - * @param id int, virt.file's local id - * @param gunid string, global id - * @param sessid string, session id - * @return string - transfer id or PEAR::error - */ - function uploadFile($id, $gunid, $sessid='') - { - $res = $this->prepareForTransport($id, $gunid, $sessid); - if(PEAR::isError($res)) return $res; - list($mediaFile, $mdataFile, $gunid) = $res; - $tr =& new Transport(&$this->dbc, $this->config); - $res = $tr->uploadOpen($mediaFile, 'media', $sessid, $gunid); - if(PEAR::isError($res)) return $res; - $res2 = $tr->uploadOpen($mdataFile, 'metadata', $sessid, $gunid); - if(PEAR::isError($res2)) return $res2; - $res3 = $tr->getTransportStatus($res); - $res4 = $tr->getTransportStatus($res2); -# return $res; - return array($res, $res2, $res3, $res4); - } - - /** - * Download file from remote repository - * - * @param gunid int, global unique id - * @param sessid string, session id - * @return string - transfer id or PEAR::error - */ - function downloadFile($gunid, $sessid='') - { - $tr =& new Transport(&$this->dbc, $this->config); - // get home dir if needed - $res = $tr->downloadOpen($sessid, 'media', $gunid, - $this->getSessUserId($sessid) - ); - if(PEAR::isError($res)) return $res; - $res2 = $tr->downloadOpen($sessid, 'metadata', $gunid, - $this->getSessUserId($sessid) - ); - if(PEAR::isError($res)) return $res; - $res3 = $tr->getTransportStatus($res); - $res4 = $tr->getTransportStatus($res2); -# return $res; - return array($res, $res2, $res3, $res4); - } - - - - /** - * Method for handling interupted transports via cron - * - */ - function cronJob() - { - $tr =& new Transport(&$this->dbc, $this->config); - $ru = $tr->uploadCron(); - $rd = $tr->downloadCron(&$this); - return array($ru, $rd); - } - - /** - * Get status of asynchronous transfer - * - * @param transferId int, id of asynchronous transfer - * returned by uploadFile or downloadFile methods - * @param sessid string, session id - * @return string or PEAR::error - */ - function getTransferStatus($transferId, $sessid='') - { - return PEAR::raiseError( - 'GreenBox::getTransferStatus: not implemented', GBERR_NOTIMPL - ); - } - - /** - * Prepare symlink to media file and create metadata file for transport - * - * @param id - * @param gunid - * @param sessid - * @return array - */ - function prepareForTransport($id, $gunid, $sessid='') - { - if(!$gunid) $gunid = $this->_gunidFromId($id); - else $id = $this->_idFromGunid($gunid); - $ac =& StoredFile::recallByGunid(&$this, $gunid); - if(PEAR::isError($ac)) return $ac; - $mediaTarget = $ac->_getRealRADFname(); - $mediaFile = "$gunid"; - $mdataFile = "$gunid.xml"; - @symlink($mediaTarget, $this->transDir."/$mediaFile"); - $mdata = $this->getMdata($id, $sessid); - if(PEAR::isError($mdata)) return $mdata; - if(!($fh = fopen($this->transDir."/$mdataFile", 'w'))) $res=FALSE; - else{ - $res = fwrite($fh, $mdata); - fclose($fh); - } - if($res === FALSE) return PEAR::raiseError( - "GreenBox::prepareForTransport:". - " can't write metadata tmp file ($mdataFile)" - ); - return array($mediaFile, $mdataFile, $gunid); - } - - /** - * Insert transported file and metadata into storage.
- * TODO: cals methods from LocStor - it's not good - * - * @param sessid string - session id - * @param file string - local path to filr - * @param type string - media|metadata|search - * @param gunid string - global unique id - */ - function processTransported($sessid, $file, $type, $gunid='X') - { - switch($type){ - case 'media': - if(!file_exists($file)) break; - $res = $this->storeAudioClip($sessid, $gunid, - $file, ''); - if(PEAR::isError($res)) return $res; - @unlink($file); - break; - case 'metadata': - case 'mdata': - if(!file_exists($file)) break; - $res = $this->updateAudioClipMetadata($sessid, $gunid, - $file); - if(PEAR::isError($res)){ - // catch valid exception - if($res->getCode() == GBERR_FOBJNEX){ - $res2 = $this->storeAudioClip($sessid, $gunid, - '', $file); - if(PEAR::isError($res2)) return $res2; - }else return $res; - } - @unlink($file); - break; - case 'search': - //$this->localSearch($criteria); - return PEAR::raiseError("processTranferred: search not implemented"); - break; - default: - return PEAR::raiseError("processTranferred: unknown type ($type)"); - break; - } - } - - /** - * Search in central metadata database - * - * @param criteria string, search query - see localSearch method - * @param sessid string, session id - * @return string - job id or PEAR::error - */ - function globalSearch($criteria, $sessid='') - { - return PEAR::raiseError( - 'GreenBox::globalSearch: not implemented', GBERR_NOTIMPL - ); - /* - $srchid = md5($sessid.mtime()); - $fh = fopen($this->transDir."/$srchid", "w"); - fwrite($fh, serialize($criteria)); - fclose($fh); - $res = $tr->uploadOpen($srchid, 'search', $sessid, $gunid); - if(PEAR::isError($res)) return $res; - return $res; - */ - } - - /** - * Get results from asynchronous search - * - * @param transferId int, transfer id returned by - * @param sessid string, session id - * @return array with results or PEAR::error - */ - function getSearchResults($transferId, $sessid='') - { - return PEAR::raiseError( - 'GreenBox::getSearchResults: not implemented', GBERR_NOTIMPL - ); - } - /* =============================================== test and debug methods */ /** * dump diff --git a/livesupport/modules/storageServer/var/GreenBox.php b/livesupport/modules/storageServer/var/GreenBox.php index d1f9df93e..0c37d008c 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.14 $ + Version : $Revision: 1.15 $ 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.14 $ + * @version $Revision: 1.15 $ * @see BasicStor */ class GreenBox extends BasicStor{ @@ -228,58 +228,21 @@ class GreenBox extends BasicStor{ /* ------------------------------------------------------------- metadata */ /** - * Update metadata tree + * Replace metadata with new XML file or string * * @param id int, virt.file's local id - * @param mdataFile string, local path of metadata XML file + * @param mdata string, local path of metadata XML file + * @param mdataLoc string 'file'|'string' * @param sessid string, session id * @return boolean or PEAR::error */ - function updateMetadata($id, $mdataFile, $sessid='') + function replaceMetadata($id, $mdata, $mdataLoc='file', $sessid='') { if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE) return $res; - return $this->bsUpdateMetadata($id, $mdataFile); + return $this->bsReplaceMetadata($id, $mdata, $mdataLoc); } - /** - * Update object namespace and value of one metadata record - * - * @param id int, virt.file's local id - * @param mdid int, metadata record id - * @param object string, object value, e.g. title string - * @param objns string, object namespace prefix, have to be defined - * in file's metadata (or reserved prefix) - * @param sessid string, session id - * @return boolean or PEAR::error - * @see MetaData - */ - function updateMetadataRecord($id, $mdid, $object, $objns='_L', $sessid='') - { - if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE) - return $res; - return $this->bsUpdateMetadataRecord($id, $mdid, $object, $objns); - } - - /** - * Add single metadata record.
- * TODO: NOT FINISHED
- * Params could be changed! - * - * @param id int, virt.file's local id - * @param propertyName string - * @param propertyValue string - * @param sessid string, session id - * @return boolean or PEAR::error - * @see MetaData - */ - function addMetaDataRecord($id, $propertyName, $propertyValue, $sessid='') - { - if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE) - return $res; - return $this->bsAddMetaDataRecord($id, $propertyName, $propertyValue); - } - /** * Get metadata XML tree as string * @@ -291,7 +254,7 @@ class GreenBox extends BasicStor{ { if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) return $res; - return $this->bsGetMdata($id); + return $this->bsGetMetadata($id); } /** diff --git a/livesupport/modules/storageServer/var/LocStor.php b/livesupport/modules/storageServer/var/LocStor.php index be16b17c9..fd9220f2e 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.13 $ + Version : $Revision: 1.14 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/LocStor.php,v $ ------------------------------------------------------------------------------*/ @@ -109,7 +109,7 @@ class LocStor extends GreenBox{ if(PEAR::isError($fname)){ return $fname; } $res = $ac->replaceRawMediaData($fname); if(PEAR::isError($res)){ return $res; } - @unlink($fname); + if(file_exists($fname)) @unlink($fname); $res = $ac->setState('ready'); if(PEAR::isError($res)) return $res; return $ac->gunid; @@ -257,7 +257,11 @@ class LocStor extends GreenBox{ */ function existsAudioClip($sessid, $gunid) { - return LocStor::existsFile($sessid, $gunid, 'audioclip'); + $ex = $this->existsFile($sessid, $gunid, 'audioclip'); + if(!$ex) return FALSE; + $ac =& StoredFile::recallByGunid(&$this, $gunid); + if(PEAR::isError($ac)){ return $ac; } + return $ac->exists(); } /** @@ -282,10 +286,10 @@ class LocStor extends GreenBox{ default: return $ac; } } - if(!is_null($ftype) && $ac->_getType() != $ftype) return FALSE; + if(!is_null($ftype) && ($ac->_getType() != $ftype)) return FALSE; if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE) return $res; - return $ac->exists(); + return TRUE; } /** @@ -350,5 +354,224 @@ class LocStor extends GreenBox{ $this->logout($this->sessid); return $res; } + + /*====================================================== playlist methods */ + + /** + * Create a new Playlist metafile. + * + * @param sessid string, session ID + * @param playlistId string, playlist global unique ID + * @return string, playlist global unique ID + */ + function createPlaylist($sessid, $playlistId) + { + $ex = $this->existsPlaylist($sessid, $playlistId); + if(PEAR::isError($ex)){ return $ex; } + if($ex){ + return PEAR::raiseError( + 'LocStor.php: createPlaylist: already exists' + ); + } + $tmpid = uniqid(''); + $parid = $this->_getHomeDirId($sessid); + if(PEAR::isError($parid)) return $parid; + if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE) + return $res; + $oid = $this->addObj($tmpid , 'File', $parid); + if(PEAR::isError($oid)) return $oid; + $ac =& StoredFile::insert(&$this, $oid, '', '', + '', + 'string', $playlistId, 'playlist' + ); + if(PEAR::isError($ac)){ + $res = $this->removeObj($oid); + return $ac; + } + $res = $this->renameFile($oid, $ac->gunid, $sessid); + if(PEAR::isError($res)) return $res; + $res = $ac->setState('ready'); + if(PEAR::isError($res)) return $res; + $res = $ac->setMime('application/smil'); + if(PEAR::isError($res)) return $res; + return $playlistId; + } + + /** + * Open a Playlist metafile for editing. + * Open readable URL and mark file as beeing edited. + * + * @param sessid string, session ID + * @param playlistId string, playlist global unique ID + * @return struct {url:readable URL for HTTP GET, token:access token} + */ + function editPlaylist($sessid, $playlistId) + { + $ex = $this->existsPlaylist($sessid, $playlistId); + if(PEAR::isError($ex)){ return $ex; } + if(!$ex){ + return PEAR::raiseError( + 'LocStor.php: editPlaylist: playlist not exists' + ); + } + if($this->_isEdited($playlistId)){ + return PEAR::raiseError( + 'LocStor.php: editPlaylist: playlist already edited' + ); + } + $ac =& StoredFile::recallByGunid(&$this, $playlistId); + if(PEAR::isError($ac)){ return $ac; } + $id = $ac->getId(); + $res = $this->bsOpenDownload($id, 'metadata'); + if(PEAR::isError($res)){ return $res; } + $this->_setEditFlag($playlistId, TRUE); + return $res; + } + + /** + * Store a new Playlist metafile in place of the old one. + * + * @param sessid string, session ID + * @param playlistToken string, playlist access token + * @param newPlaylist string, new playlist as XML string + * @return boolean + */ + function savePlaylist($sessid, $playlistToken, $newPlaylist) + { + $playlistId = $this->bsCloseDownload($playlistToken, $part='metadata'); + $ac =& StoredFile::recallByGunid(&$this, $playlistId); + if(PEAR::isError($ac)){ return $ac; } + $res = $ac->replaceMetaData($newPlaylist, $mdataLoc='string'); + if(PEAR::isError($res)){ return $res; } + $this->_setEditFlag($playlistId, FALSE); + return TRUE; + } + + /** + * Delete a Playlist metafile. + * + * @param sessid string, session ID + * @param playlistId string, playlist global unique ID + * @return boolean + */ + function deletePlaylist($sessid, $playlistId) + { + $ex = $this->existsPlaylist($sessid, $playlistId); + if(PEAR::isError($ex)){ return $ex; } + if(!$ex){ + return PEAR::raiseError( + 'LocStor.php: deletePlaylist: playlist not exists' + ); + } + $ac =& StoredFile::recallByGunid(&$this, $playlistId); + if(PEAR::isError($ac)) return $ac; + if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE) + return $res; + if($this->_isEdited($playlistId)){ + return PEAR::raiseError( + 'LocStor.php: deletePlaylist: playlist is edited' + ); + } + $res = $this->deleteFile($ac->getId(), $sessid); + if(PEAR::isError($res)) return $res; + return TRUE; + } + + /** + * Access (read) a Playlist metafile. + * + * @param sessid string, session ID + * @param playlistId string, playlist global unique ID + * @return struct {url:readable URL for HTTP GET, token:access token + */ + function accessPlaylist($sessid, $playlistId) + { + $ex = $this->existsPlaylist($sessid, $playlistId); + if(PEAR::isError($ex)){ return $ex; } + if(!$ex){ + return PEAR::raiseError( + 'LocStor.php: accessPlaylist: playlist not found' + ); + } + $id = $this->_idFromGunid($playlistId); + if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE) + return $res; + return $this->bsOpenDownload($id, 'metadata'); + } + + /** + * Release the resources obtained earlier by accessPlaylist(). + * + * @param sessid string, session ID + * @param playlistToken string, playlist access token + * @return string, playlist ID + */ + function releasePlaylist($sessid, $playlistToken) + { + return $this->bsCloseDownload($playlistToken, 'metadata'); + } + + /** + * Check whether a Playlist metafile with the given playlist ID exists. + * + * @param sessid string, session ID + * @param playlistId string, playlist global unique ID + * @return boolean + */ + function existsPlaylist($sessid, $playlistId) + { + return $this->existsFile($sessid, $playlistId, 'playlist'); + } + + /** + * Check whether a Playlist metafile with the given playlist ID + * is available for editing, i.e., exists and is not marked as + * beeing edited. + * + * @param sessid string, session ID + * @param playlistId string, playlist global unique ID + * @return boolean + */ + function playlistIsAvailable($sessid, $playlistId) + { + $ex = $this->existsPlaylist($sessid, $playlistId); + if(PEAR::isError($ex)){ return $ex; } + if(!$ex){ + return PEAR::raiseError( + 'LocStor.php: playlistIsAvailable: playlist not exists' + ); + } + return !$this->_isEdited($playlistId); + } + + /* ---------------------------------------------------- "private" methods */ + /** + * Check if playlist is marked as edited + * + * @param playlistId string, playlist global unique ID + * @return boolean + */ + function _isEdited($playlistId) + { + $state = StoredFile::_getState($playlistId); + if($state == 'edited'){ return TRUE; } + return FALSE; + } + + /** + * Set edit flag + * + * @param playlistId string, playlist global unique ID + * @param val boolean, set/clear of edit flag + * @return boolean, previous state + */ + function _setEditFlag($playlistId, $val=TRUE) + { + $ac =& StoredFile::recallByGunid(&$this, $playlistId); + $state = $ac->_getState(); + if($val){ $ac->setState('edited'); } + else{ $ac->setState('ready'); } + return ($state == 'edited'); + } } ?> \ No newline at end of file diff --git a/livesupport/modules/storageServer/var/MetaData.php b/livesupport/modules/storageServer/var/MetaData.php index 1b1a2d6c4..38835ed5f 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.7 $ + Version : $Revision: 1.8 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/MetaData.php,v $ ------------------------------------------------------------------------------*/ @@ -43,14 +43,17 @@ class MetaData{ * * @param gb reference to GreenBox object * @param gunid string, global unique id + * @param resDir string, resource directory * @return this */ - function MetaData(&$gb, $gunid) + function MetaData(&$gb, $gunid, $resDir) { $this->dbc =& $gb->dbc; - $this->mdataTable = $gb->mdataTable; - $this->gunid = $gunid; - $this->exists = $this->dbCheck($gunid); + $this->mdataTable = $gb->mdataTable; + $this->gunid = $gunid; + $this->resDir = $resDir; + $this->fname = $this->makeFname(); + $this->exists = $this->dbCheck($gunid) && file_exists($this->fname); } /** * Parse and store metadata from XML file or XML string @@ -64,6 +67,32 @@ class MetaData{ if($this->exists) return FALSE; $res = $this->storeXMLDoc($mdata, $loc); if(PEAR::isError($res)) return $res; + switch($loc){ + case"file": + if(! @copy($mdata, $this->fname)){ + return PEAR::raiseError( + "MetaData::insert: file save failed". + " ($mdata, {$this->fname})",GBERR_FILEIO + ); + } + break; + case"string": + $fname = $this->fname; + $e = FALSE; + if(!$fh = fopen($fname, "w")){ $e = TRUE; } + elseif(fwrite($fh, $mdata) === FALSE){ $e = TRUE; } + if($e){ + return PEAR::raiseError( + "BasicStor::bsOpenDownload: can't write ($fname)", + GBERR_FILEIO); + } + fclose($fh); + break; + default: + return PEAR::raiseError( + "MetaData::insert: unsupported metadata location ($loc)" + ); + } $this->exists = TRUE; return TRUE; } @@ -76,11 +105,14 @@ class MetaData{ */ function update($mdata, $loc='file') { + return $this->replace($mdata, $loc); + /* if(!$this->exists) return FALSE; $res = $this->storeXMLDoc($mdata, $loc, 'update'); if(PEAR::isError($res)) return $res; $this->exists = TRUE; return TRUE; + */ } /** * Call delete and insert @@ -111,6 +143,7 @@ class MetaData{ */ function delete() { + if(file_exists($fname)) @unlink($this->fname); $res = $this->dbc->query(" DELETE FROM {$this->mdataTable} WHERE gunid=x'{$this->gunid}'::bigint @@ -126,9 +159,30 @@ class MetaData{ */ function getMetaData() { - return $this->genXMLDoc(); + // return $this->genXMLDoc(); // obsolete + return file_get_contents($this->fname); } + /** + * Contruct filepath of metadata file + * + * @return string + */ + function makeFname() + { + return "{$this->resDir}/{$this->gunid}.xml"; + } + + /** + * Return filename + * + * @return string + */ + function getFname() + { + return $this->fname; + } + /** * Check if there are any file's metadata in database * @@ -146,6 +200,7 @@ class MetaData{ return (intval($cnt) > 0); } + /* ============================================= parse and store metadata */ /** * Parse and insert or update metadata XML to database * @@ -156,10 +211,22 @@ class MetaData{ */ function storeXMLDoc($mdata='', $loc='file', $mode='insert') { - if($loc=='file' && file_exists($mdata)){ - $xml = domxml_open_file($mdata); - }else{ - $xml = domxml_open_mem($mdata); + switch($loc){ + case"file": + if(!file_exists($mdata)){ + return PEAR::raiseError( + "MetaData::storeXMLDoc: metadata file not found ($mdata)" + ); + } + $xml = domxml_open_file($mdata); + break; + case"string": + $xml = domxml_open_mem($mdata); + break; + default: + return PEAR::raiseError( + "MetaData::storeXMLDoc: unsupported metadata location ($loc)" + ); } $root = $xml->document_element(); if(!is_object($root)) return PEAR::raiseError( @@ -375,6 +442,8 @@ class MetaData{ if(PEAR::isError($res)) return $res; return $id; } + + /* =========================================== XML reconstruction from db */ /** * Generate XML document from metadata database * @@ -460,6 +529,7 @@ class MetaData{ $qh->free(); } + /* ========================================================= test methods */ /** * Test method * diff --git a/livesupport/modules/storageServer/var/RawMediaData.php b/livesupport/modules/storageServer/var/RawMediaData.php index a5e08bf3d..ae0ab1e40 100644 --- a/livesupport/modules/storageServer/var/RawMediaData.php +++ b/livesupport/modules/storageServer/var/RawMediaData.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.4 $ + Version : $Revision: 1.5 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/RawMediaData.php,v $ ------------------------------------------------------------------------------*/ @@ -44,7 +44,7 @@ class RawMediaData{ * Constructor * * @param gunid string, global unique id - * @param resDir string, directory + * @param resDir string, resource directory * @return this */ function RawMediaData($gunid, $resDir) diff --git a/livesupport/modules/storageServer/var/StoredFile.php b/livesupport/modules/storageServer/var/StoredFile.php index 31287033c..a4d66981c 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.10 $ + Version : $Revision: 1.11 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/StoredFile.php,v $ ------------------------------------------------------------------------------*/ @@ -65,7 +65,7 @@ class StoredFile{ $this->resDir = $this->_getResDir($this->gunid); $this->accessDir = $this->gb->accessDir; $this->rmd =& new RawMediaData($this->gunid, $this->resDir); - $this->md =& new MetaData(&$gb, $this->gunid); + $this->md =& new MetaData(&$gb, $this->gunid, $this->resDir); return $this->gunid; } @@ -80,11 +80,12 @@ class StoredFile{ * @param metadata string, local path to metadata XML file or XML string * @param mdataLoc string 'file'|'string' (optional) * @param gunid global unique id (optional) - for insert file with gunid + * @param ftype string, internal file type * @return instace of StoredFile object */ function insert(&$gb, $oid, $name, $mediaFileLP='', $metadata='', $mdataLoc='file', - $gunid=NULL, $type=NULL) + $gunid=NULL, $ftype=NULL) { $ac =& new StoredFile(&$gb, ($gunid ? $gunid : NULL)); $ac->name = $name; @@ -98,7 +99,7 @@ class StoredFile{ (id, name, gunid, mime, state, ftype) VALUES ('$oid', '{$ac->name}', x'{$ac->gunid}'::bigint, - '{$ac->mime}', 'incomplete', '$type') + '{$ac->mime}', 'incomplete', '$ftype') "); if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; } // --- metadata insert: @@ -128,7 +129,7 @@ class StoredFile{ $mime = $ac->rmd->getMime(); //$gb->debugLog("gunid={$ac->gunid}, mime=$mime"); if($mime !== FALSE){ - $res = $ac->setType($mime); + $res = $ac->setMime($mime); if(PEAR::isError($res)){ $ac->dbc->query("ROLLBACK"); return $res; } @@ -226,7 +227,7 @@ class StoredFile{ '', '', NULL, $src->_getType() ); if(PEAR::isError($ac)) return $ac; - $ac->md->replace($src->md->getMetaData(), 'xml'); + $ac->md->replace($src->md->getMetaData()); return $ac; } @@ -331,7 +332,7 @@ class StoredFile{ if(PEAR::isError($res)){ return $res; } $mime = $this->rmd->getMime(); if($mime !== FALSE){ - $res = $this->setType($mime); + $res = $this->setMime($mime); if(PEAR::isError($res)){ return $res; } } } @@ -353,38 +354,6 @@ class StoredFile{ return TRUE; } - /** - * Update metadata with new XML file - * - * @param metadata string, local path to metadata XML file or XML string - * @param mdataLoc string 'file'|'string' - * @return boolean or PEAR::error - */ - function updateMetaData($metadata, $mdataLoc='file') - { - $this->dbc->query("BEGIN"); - $res = $this->md->update($metadata, $mdataLoc); - if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; } - $res = $this->dbc->query("COMMIT"); - if(PEAR::isError($res)) return $res; - return TRUE; - } - - /** - * Update object namespace and value of one metadata record - * - * @param mdid int, metadata record id - * @param object string, object value, e.g. title string - * @param objns string, object namespace prefix, have to be defined - * in file's metadata (or reserved prefix) - * @see MetaData - * @return boolean or PEAR::error - */ - function updateMetaDataRecord($mdid, $object, $objns='_L') - { - return $this->md->updateRecord($mdid, $object, $objns='_L'); - } - /** * Get metadata as XML string * @@ -448,7 +417,7 @@ class StoredFile{ * @param mime string, mime-type * @return boolean or error */ - function setType($mime) + function setMime($mime) { $res = $this->dbc->query(" UPDATE {$this->filesTable} SET mime='$mime' @@ -538,8 +507,9 @@ class StoredFile{ $initString = microtime().$_SERVER['SERVER_ADDR'].rand()."org.mdlf.livesupport"; $hash = md5($initString); - // int8 - $res = substr($hash, 0, 16); + // non-negative int8 + $hsd = substr($hash, 0, 1); + $res = dechex(hexdec($hsd)>>1).substr($hash, 1, 15); return StoredFile::_normalizeGunid($res); } @@ -657,6 +627,16 @@ class StoredFile{ return $this->rmd->getFname(); } + /** + * Get real filename of metadata file + * + * @see MetaData + */ + function _getRealMDFname() + { + return $this->md->getFname(); + } + /** * Create and return name for temporary symlink.
* TODO: Should be more unique diff --git a/livesupport/modules/storageServer/var/html/gbHttp.php b/livesupport/modules/storageServer/var/html/gbHttp.php index 69678f030..9fe27e961 100644 --- a/livesupport/modules/storageServer/var/html/gbHttp.php +++ b/livesupport/modules/storageServer/var/html/gbHttp.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.8 $ + Version : $Revision: 1.9 $ Location : $ $ ------------------------------------------------------------------------------*/ @@ -33,7 +33,7 @@ require_once"gbHtml_h.php"; * storageServer WWW-form interface * * @author $Author: tomas $ - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * @see Alib * @see GreenBox */ @@ -119,7 +119,6 @@ switch($_REQUEST['act']){ $r = $gb->putFile($id, $_REQUEST['filename'], $ntmp, $mdtmp, $sessid); if(PEAR::isError($r)) $_SESSION['alertMsg'] = $r->getMessage(); else{ -# $gb->updateMetadataDB($gb->_pathFromId($r), $mdata, $sessid); @unlink($ntmp); @unlink($mdtmp); } diff --git a/livesupport/modules/storageServer/var/tests/mdata4.xml b/livesupport/modules/storageServer/var/tests/mdata4.xml new file mode 100644 index 000000000..b8e1ff15c --- /dev/null +++ b/livesupport/modules/storageServer/var/tests/mdata4.xml @@ -0,0 +1,16 @@ + + +File Title4 utf-8 +ěščřžýáíé ĚŠČŘŽÝÁÍÉ úůÚŮ ďťňĎŤŇ é + + Author + John Y + 234 + + \ No newline at end of file diff --git a/livesupport/modules/storageServer/var/tests/mdata5.xml b/livesupport/modules/storageServer/var/tests/mdata5.xml new file mode 100644 index 000000000..e046e23f0 --- /dev/null +++ b/livesupport/modules/storageServer/var/tests/mdata5.xml @@ -0,0 +1,2 @@ + +00:00:11 diff --git a/livesupport/modules/storageServer/var/tests/sampleData.php b/livesupport/modules/storageServer/var/tests/sampleData.php index 5b10e56f0..d512301cd 100644 --- a/livesupport/modules/storageServer/var/tests/sampleData.php +++ b/livesupport/modules/storageServer/var/tests/sampleData.php @@ -1,7 +1,7 @@ \ No newline at end of file diff --git a/livesupport/modules/storageServer/var/xmlrpc/simpleGet.php b/livesupport/modules/storageServer/var/xmlrpc/simpleGet.php index bab7e25a8..201a27c71 100644 --- a/livesupport/modules/storageServer/var/xmlrpc/simpleGet.php +++ b/livesupport/modules/storageServer/var/xmlrpc/simpleGet.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.6 $ + Version : $Revision: 1.7 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/simpleGet.php,v $ ------------------------------------------------------------------------------*/ @@ -82,16 +82,32 @@ if(preg_match("|^[0-9a-fA-F]{16}$|", $_REQUEST['id'])){ http_error(400, "Error on id parameter. ({$_REQUEST['id']})"); } -$ex = $locStor->existsAudioClip($sessid, $gunid); -if(PEAR::isError($ex)){ - if($ex->getCode() == GBERR_DENY){ http_error(403, $ex->getMessage()); } - else{ http_error(500, $ex->getMessage()); } +$ex_ac = $locStor->existsAudioClip($sessid, $gunid); +if(PEAR::isError($ex_ac)){ + if($ex_ac->getCode() == GBERR_DENY){ + http_error(403, $ex_ac->getMessage()); + }else{ http_error(500, $ex_ac->getMessage()); } } -if(!$ex){ http_error(404, "File not found"); } +$ex_pl = $locStor->existsPlaylist($sessid, $gunid); +if(PEAR::isError($ex_pl)){ + if($ex_pl->getCode() == GBERR_DENY){ + http_error(403, $ex_pl->getMessage()); + }else{ http_error(500, $ex_pl->getMessage()); } +} +if(!$ex_ac && !$ex_pl){ http_error(404, "404 File not found"); } $ac =& StoredFile::recallByGunid(&$locStor, $gunid); if(PEAR::isError($ac)){ http_error(500, $ac->getMessage()); } -$realFname = $ac->_getRealRADFname(); -$mime = $ac->rmd->getMime(); -header("Content-type: $mime"); -readfile($realFname); +if($ex_ac){ + $realFname = $ac->_getRealRADFname(); + $mime = $ac->rmd->getMime(); + header("Content-type: $mime"); + readfile($realFname); + exit; +} +if($ex_pl){ + $md = $locStor->getMdata($ac->getId(), $sessid); + header("Content-type: application/smil"); + echo $md; + exit; +} ?> diff --git a/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh b/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh index abf9dbd57..326986f95 100755 --- a/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh +++ b/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh @@ -23,7 +23,7 @@ # # # Author : $Author: tomas $ -# Version : $Revision: 1.9 $ +# Version : $Revision: 1.10 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh,v $ #------------------------------------------------------------------------------- @@ -33,8 +33,13 @@ COMM=$1 shift GUNID=$1 -METADATA=" -ěščřžé" +#METADATA=" +#ěščřžé" +METADATA=" + +00:00:11" echo "" XMLRPC=`cd var/install; php -q getXrUrl.php` || exit $? @@ -146,12 +151,12 @@ deleteAudioClip() { updateAudioClipMetadata() { echo -n "#updateAudioClipMetadata: " - $XR_CLI updateAudioClipMetadata $SESSID $GUNID '../tests/mdata3.xml' || exit $? + $XR_CLI updateAudioClipMetadata $SESSID $GUNID "$METADATA" || exit $? } getAudioClip() { echo -n "#getAudioClip: " - $XR_CLI getAudioClip $SESSID $GUNID | $TESTDIR/urldecode || exit $? + $XR_CLI getAudioClip $SESSID $GUNID || exit $? } searchMetadata() { @@ -160,6 +165,67 @@ searchMetadata() { $XR_CLI searchMetadata $SESSID 'John %' || exit $? } +PLID="123456789abcdef2" + +createPlaylist() { + echo -n "# createPlaylist: " + $XR_CLI createPlaylist $SESSID $PLID || exit $? +} + +accessPlaylist() { + echo "# accessPlaylist: " + RES=`$XR_CLI accessPlaylist $SESSID $PLID` || \ + { ERN=$?; echo $RES; exit $ERN; } + unset URL + for i in $RES; do if [ -z $URL ] ; then URL=$i; else TOKEN=$i; fi; done + echo $TOKEN + echo $URL + echo "# curl: " + curl -fs $URL || { ERN=$?; echo $RES; exit $ERN; } + echo "" + echo "# status: $?" + if [ $DEBUG ]; then echo -n "Press enter ..."; read KEY; fi + echo -n "# releasePlaylist: " + $XR_CLI releasePlaylist $SESSID $TOKEN || exit $? +} + +editPlaylist() { + DATE=`date '+%H:%M:%S'` + PLAYLIST=" + + + XY $DATE + + + " + echo "# editPlaylist: " + RES=`$XR_CLI editPlaylist $SESSID $PLID` || \ + { ERN=$?; echo $RES; exit $ERN; } + unset URL + for i in $RES; do if [ -z $URL ] ; then URL=$i; else TOKEN=$i; fi; done + echo $TOKEN + echo $URL + if [ $DEBUG ]; then echo -n "Press enter ..."; read KEY; fi + echo " Playlist:" + echo $PLAYLIST + echo -n "# savePlaylist: " + $XR_CLI savePlaylist $SESSID $TOKEN "$PLAYLIST" || exit $? +} + +existsPlaylist() { + echo -n "# existsPlaylist (${PLID}): " + $XR_CLI existsPlaylist $SESSID $PLID || exit $? +} + +deletePlaylist() { + echo -n "# deletePlaylist: " + $XR_CLI deletePlaylist $SESSID $PLID + # || exit $? + echo "# status: $?" +} + logout() { echo -n "# logout: " $XR_CLI logout $SESSID || exit $? @@ -204,7 +270,23 @@ elif [ "$COMM" == "searchMetadata" ]; then login searchMetadata logout +elif [ "$COMM" == "playlists" ]; then + echo "#XMLRPC playlists test" + login + existsPlaylist + deletePlaylist + createPlaylist + existsPlaylist + accessPlaylist + editPlaylist + accessPlaylist +# deletePlaylist + existsPlaylist + logout + echo "#XMLRPC: playlists: OK." + echo "" elif [ "x$COMM" == "x" ]; then + echo "#XMLRPC: storage test" login storeAudioClip GUNID=$RGUNID @@ -215,7 +297,7 @@ elif [ "x$COMM" == "x" ]; then deleteAudioClip existsAudioClip logout - echo "#XMLRPC tests: OK." + echo "#XMLRPC: storage: OK." echo "" elif [ "$COMM" == "help" ]; then usage diff --git a/livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php b/livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php index f6aa921f0..de75d6e1d 100644 --- a/livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php +++ b/livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.10 $ + Version : $Revision: 1.11 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php,v $ ------------------------------------------------------------------------------*/ @@ -635,6 +635,376 @@ class XR_LocStor extends LocStor{ return new XML_RPC_Response(XML_RPC_encode(array('status'=>$res))); } + /*====================================================== playlist methods */ + /** + * Create a new Playlist metafile. + * + * The XML-RPC name of this method is "locstor.createPlaylist". + * + * The input parameters are an XML-RPC struct with the following + * fields: + * + * + * On success, returns a XML-RPC struct with single field: + * + * + * On errors, returns an XML-RPC error response. + * The possible error codes and error message are: + * + * + * @param input XMLRPC struct + * @return XMLRPC struct + * @see LocStor::createPlaylist + */ + function xr_createPlaylist($input) + { + list($ok, $r) = $this->_xr_getPars($input); + if(!$ok) return $r; + $res = $this->createPlaylist($r['sessid'], $r['plid']); + if(PEAR::isError($res)){ + return new XML_RPC_Response(0, 805, + "xr_createPlaylist: ".$res->getMessage(). + " ".$res->getUserInfo() + ); + } + return new XML_RPC_Response(XML_RPC_encode(array('plid'=>$res))); + } + + /** + * Open a Playlist metafile for editing. + * Open readable URL and mark file as beeing edited. + * + * The XML-RPC name of this method is "locstor.editPlaylist". + * + * The input parameters are an XML-RPC struct with the following + * fields: + * + * + * On success, returns a XML-RPC struct with single field: + * + * + * On errors, returns an XML-RPC error response. + * The possible error codes and error message are: + * + * + * @param input XMLRPC struct + * @return XMLRPC struct + * @see LocStor::editPlaylist + */ + function xr_editPlaylist($input) + { + list($ok, $r) = $this->_xr_getPars($input); + if(!$ok) return $r; + $res = $this->editPlaylist($r['sessid'], $r['plid']); + if(PEAR::isError($res)){ + return new XML_RPC_Response(0, 805, + "xr_editPlaylist: ".$res->getMessage(). + " ".$res->getUserInfo() + ); + } + return new XML_RPC_Response(XML_RPC_encode($res)); + } + + /** + * Store a new Playlist metafile in place of the old one. + * + * The XML-RPC name of this method is "locstor.savePlaylist". + * + * The input parameters are an XML-RPC struct with the following + * fields: + * + * + * On success, returns a XML-RPC struct with single field: + * + * + * On errors, returns an XML-RPC error response. + * The possible error codes and error message are: + * + * + * @param input XMLRPC struct + * @return XMLRPC struct + * @see LocStor::savePlaylist + */ + function xr_savePlaylist($input) + { + list($ok, $r) = $this->_xr_getPars($input); + if(!$ok) return $r; + $res = $this->savePlaylist( + $r['sessid'], $r['token'], $r['newPlaylist']); + if(PEAR::isError($res)){ + return new XML_RPC_Response(0, 805, + "xr_savePlaylist: ".$res->getMessage(). + " ".$res->getUserInfo() + ); + } + return new XML_RPC_Response(XML_RPC_encode(array('status'=>$res))); + } + + /** + * Delete a Playlist metafile. + * + * The XML-RPC name of this method is "locstor.deletePlaylist". + * + * The input parameters are an XML-RPC struct with the following + * fields: + * + * + * On success, returns a XML-RPC struct with single field: + * + * + * On errors, returns an XML-RPC error response. + * The possible error codes and error message are: + * + * + * @param input XMLRPC struct + * @return XMLRPC struct + * @see LocStor::deletePlaylist + */ + function xr_deletePlaylist($input) + { + list($ok, $r) = $this->_xr_getPars($input); + if(!$ok) return $r; + $res = $this->deletePlaylist($r['sessid'], $r['plid']); + if(PEAR::isError($res)){ + return new XML_RPC_Response(0, 805, + "xr_deletePlaylist: ".$res->getMessage(). + " ".$res->getUserInfo() + ); + } + return new XML_RPC_Response(XML_RPC_encode(array('status'=>$res))); + } + + /** + * Access (read) a Playlist metafile. + * + * The XML-RPC name of this method is "locstor.accessPlaylist". + * + * The input parameters are an XML-RPC struct with the following + * fields: + * + * + * On success, returns a XML-RPC struct with single field: + * + * + * On errors, returns an XML-RPC error response. + * The possible error codes and error message are: + * + * + * @param input XMLRPC struct + * @return XMLRPC struct + * @see LocStor::accessPlaylist + */ + function xr_accessPlaylist($input) + { + list($ok, $r) = $this->_xr_getPars($input); + if(!$ok) return $r; + $res = $this->accessPlaylist($r['sessid'], $r['plid']); + if(PEAR::isError($res)){ + return new XML_RPC_Response(0, 805, + "xr_accessPlaylist: ".$res->getMessage(). + " ".$res->getUserInfo() + ); + } + return new XML_RPC_Response(XML_RPC_encode($res)); + } + + /** + * Release the resources obtained earlier by accessPlaylist(). + * + * The XML-RPC name of this method is "locstor.releasePlaylist". + * + * The input parameters are an XML-RPC struct with the following + * fields: + * + * + * On success, returns a XML-RPC struct with single field: + * + * + * On errors, returns an XML-RPC error response. + * The possible error codes and error message are: + * + * + * @param input XMLRPC struct + * @return XMLRPC struct + * @see LocStor::releasePlaylist + */ + function xr_releasePlaylist($input) + { + list($ok, $r) = $this->_xr_getPars($input); + if(!$ok) return $r; + $res = $this->releasePlaylist($r['sessid'], $r['token']); + if(PEAR::isError($res)){ + return new XML_RPC_Response(0, 805, + "xr_releasePlaylist: ".$res->getMessage(). + " ".$res->getUserInfo() + ); + } + return new XML_RPC_Response(XML_RPC_encode(array('plid'=>$res))); + } + + /** + * Check whether a Playlist metafile with the given playlist ID exists. + * + * The XML-RPC name of this method is "locstor.existsPlaylist". + * + * The input parameters are an XML-RPC struct with the following + * fields: + * + * + * On success, returns a XML-RPC struct with single field: + * + * + * On errors, returns an XML-RPC error response. + * The possible error codes and error message are: + * + * + * @param input XMLRPC struct + * @return XMLRPC struct + * @see LocStor::existsPlaylist + */ + function xr_existsPlaylist($input) + { + list($ok, $r) = $this->_xr_getPars($input); + if(!$ok) return $r; + $res = $this->existsPlaylist($r['sessid'], $r['plid']); + if(PEAR::isError($res)){ + return new XML_RPC_Response(0, 805, + "xr_existsPlaylist: ".$res->getMessage(). + " ".$res->getUserInfo() + ); + } + return new XML_RPC_Response(XML_RPC_encode(array('exists'=>$res))); + } + + /** + * Check whether a Playlist metafile with the given playlist ID + * is available for editing, i.e., exists and is not marked as + * beeing edited. + * + * The XML-RPC name of this method is "locstor.playlistIsAvailable". + * + * The input parameters are an XML-RPC struct with the following + * fields: + * + * + * On success, returns a XML-RPC struct with single field: + * + * + * On errors, returns an XML-RPC error response. + * The possible error codes and error message are: + * + * + * @param input XMLRPC struct + * @return XMLRPC struct + * @see LocStor::playlistIsAvailable + */ + function xr_playlistIsAvailable($input) + { + list($ok, $r) = $this->_xr_getPars($input); + if(!$ok) return $r; + $res = $this->playlistIsAvailable($r['sessid'], $r['plid']); + if(PEAR::isError($res)){ + return new XML_RPC_Response(0, 805, + "xr_playlistIsAvailable: ".$res->getMessage(). + " ".$res->getUserInfo() + ); + } + return new XML_RPC_Response(XML_RPC_encode(array('available'=>$res))); + } + /* ----------------------------------------------------------------- etc. */ /** * Check if audio clip exists and return TRUE/FALSE @@ -978,6 +1348,15 @@ $methods = array( 'releaseRawAudioData' => 'Release access to raw audio data.', 'getAudioClip' => 'Return the contents of an Audio clip.', 'resetStorage' => 'Reset storageServer for debugging.', + 'createPlaylist' => 'Create a new Playlist metafile.', + 'editPlaylist' => 'Open a Playlist metafile for editing.', + 'savePlaylist' => 'Save a Playlist metafile.', + 'deletePlaylist' => 'Delete a Playlist metafile.', + 'accessPlaylist' => 'Open readable URL to a Playlist metafile.', + 'releasePlaylist' => 'Release readable URL from accessPlaylist.', + 'existsPlaylist' => 'Check whether a Playlist exists.', + 'playlistIsAvailable' => 'Check whether a Playlist is available '. + 'for editing.', ); $defs = array(); diff --git a/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py b/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py index 490671f58..b8c5e7f84 100755 --- a/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py +++ b/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py @@ -24,7 +24,7 @@ # # # Author : $Author: tomas $ -# Version : $Revision: 1.8 $ +# Version : $Revision: 1.9 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/Attic/xr_cli_test.py,v $ # #------------------------------------------------------------------------------ @@ -115,10 +115,29 @@ try: elif method=="existsAudioClip": print server.locstor.existsAudioClip({'sessid':pars[0], 'gunid':pars[1]}) elif method=="updateAudioClipMetadata": - print server.locstor.updateAudioClipMetadata({'sessid':pars[0], 'gunid':pars[1], 'mdataFileLP':pars[2]}) + print server.locstor.updateAudioClipMetadata({'sessid':pars[0], 'gunid':pars[1], 'metadata':pars[2]}) elif method=="searchMetadata": # print server.locstor.searchMetadata({'sessid':pars[0], 'criteria':pars[1]}) print server.locstor.searchMetadata({'sessid':pars[0], 'criteria':{'type':'and', 'conds':['a', 'b']}}) + elif method=="existsPlaylist": + print server.locstor.existsPlaylist({'sessid':pars[0], 'plid':pars[1]}) + elif method=="playlistIsAvailable": + print server.locstor.playlistIsAvailable({'sessid':pars[0], 'plid':pars[1]}) + elif method=="createPlaylist": + print server.locstor.createPlaylist({'sessid':pars[0], 'plid':pars[1]}) + elif method=="editPlaylist": + r = server.locstor.editPlaylist({'sessid':pars[0], 'plid':pars[1]}) + print r['url']+'\n'+r['token'] + elif method=="savePlaylist": + print server.locstor.savePlaylist({'sessid':pars[0], 'token':pars[1], 'newPlaylist':pars[2]}) + elif method=="deletePlaylist": + print server.locstor.deletePlaylist({'sessid':pars[0], 'plid':pars[1]}) + elif method=="accessPlaylist": + r = server.locstor.accessPlaylist({'sessid':pars[0], 'plid':pars[1]}) + print r['url']+'\n'+r['token'] + elif method=="releasePlaylist": + print server.locstor.releasePlaylist({'sessid':pars[0], 'token':pars[1]}) + elif method=="getAudioClip": r = server.locstor.getAudioClip({'sessid':pars[0], 'gunid':pars[1]}) print r['metadata']