minor changes

This commit is contained in:
tomas 2004-12-22 02:19:56 +00:00
parent bc954ea07b
commit c0ccb18a82
6 changed files with 75 additions and 44 deletions

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.1 $ Version : $Revision: 1.2 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -48,7 +48,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.1 $ * @version $Revision: 1.2 $
* @see Alib * @see Alib
*/ */
class BasicStor extends Alib{ class BasicStor extends Alib{
@ -261,7 +261,7 @@ class BasicStor extends Alib{
* *
* @param token string, access token * @param token string, access token
* @param type string 'access'|'download' * @param type string 'access'|'download'
* @return boolean * @return string, global unique ID
*/ */
function bsRelease($token, $type='access') function bsRelease($token, $type='access')
{ {
@ -270,11 +270,13 @@ class BasicStor extends Alib{
"BasicStor::bsRelease: invalid token ($token)" "BasicStor::bsRelease: invalid token ($token)"
); );
} }
$ext = $this->dbc->getOne(" $acc = $this->dbc->getRow("
SELECT ext FROM {$this->accessTable} SELECT gunid, ext FROM {$this->accessTable}
WHERE token='{$token}' AND type='$type' WHERE token='{$token}' AND type='$type'
"); ");
if(PEAR::isError($ext)){ return $ext; } $ext = $acc['ext'];
$gunid = $acc['gunid'];
if(PEAR::isError($acc)){ return $acc; }
$linkFname = "{$this->accessDir}/$token.$ext"; $linkFname = "{$this->accessDir}/$token.$ext";
$res = $this->dbc->query(" $res = $this->dbc->query("
DELETE FROM {$this->accessTable} WHERE token='$token' DELETE FROM {$this->accessTable} WHERE token='$token'
@ -285,7 +287,7 @@ class BasicStor extends Alib{
"BasicStor::bsRelease: unlink failed ($linkFname)", "BasicStor::bsRelease: unlink failed ($linkFname)",
GBERR_FILEIO); GBERR_FILEIO);
} }
return TRUE; return $gunid;
} }
/** /**
@ -331,7 +333,7 @@ class BasicStor extends Alib{
* *
* @param token string, download token * @param token string, download token
* @param part string, 'media'|'metadata' * @param part string, 'media'|'metadata'
* @return boolean * @return string, gunid
*/ */
function bsCloseDownload($token, $part='media') function bsCloseDownload($token, $part='media')
{ {
@ -534,15 +536,27 @@ class BasicStor extends Alib{
* Mode is "match all" or "match any". * Mode is "match all" or "match any".
* Query parts is array of [fieldname, operator, value] entities. * Query parts is array of [fieldname, operator, value] entities.
* *
* @param searchData string, search query - * @param criteria string, search query -
* only one SQL LIKE term supported now. * only one SQL LIKE term supported now.
* It will be searched in all literal object values * It will be searched in all literal object values
* in metadata database * in metadata database
* @return array of gunid strings * @return array of gunid strings
*/ */
function bsLocalSearch($searchData) function bsLocalSearch($criteria)
{ {
$ftsrch = $searchData; $ops = array('full'=>"like '%s'", 'partial'=>"like '%%%s%%'", 'prefix'=>"like '%s%%'",
'<'=>"< '%s'", '='=>"= '%s'", '>'=>"> '%s'", '<='=>"<= '%s'", '>='=>">= '%s'"
);
# var_dump($criteria);
$type = $criteria['type'];
$conds = $criteria['conds'];
foreach($conds as $cond){
$cat = $cond['cat'];
$opVal = sprintf($ops[$cond['op']], $cond['val']);
$sqlCond = "$cat $opVal";
echo "$sqlCond\n";
}
$ftsrch = $criteria;
$res = $this->dbc->getCol("SELECT md.gunid as gunid $res = $this->dbc->getCol("SELECT md.gunid as gunid
FROM {$this->filesTable} f, {$this->mdataTable} md FROM {$this->filesTable} f, {$this->mdataTable} md
WHERE f.gunid=md.gunid AND md.objns='_L' AND WHERE f.gunid=md.gunid AND md.objns='_L' AND
@ -761,11 +775,11 @@ class BasicStor extends Alib{
/** /**
* Search in central metadata database * Search in central metadata database
* *
* @param searchData string, search query - see localSearch method * @param criteria string, search query - see localSearch method
* @param sessid string, session id * @param sessid string, session id
* @return string - job id or PEAR::error * @return string - job id or PEAR::error
*/ */
function globalSearch($searchData, $sessid='') function globalSearch($criteria, $sessid='')
{ {
return PEAR::raiseError( return PEAR::raiseError(
'GreenBox::globalSearch: not implemented', GBERR_NOTIMPL 'GreenBox::globalSearch: not implemented', GBERR_NOTIMPL
@ -773,7 +787,7 @@ class BasicStor extends Alib{
/* /*
$srchid = md5($sessid.mtime()); $srchid = md5($sessid.mtime());
$fh = fopen($this->transDir."/$srchid", "w"); $fh = fopen($this->transDir."/$srchid", "w");
fwrite($fh, serialize($searchData)); fwrite($fh, serialize($criteria));
fclose($fh); fclose($fh);
$res = $tr->uploadOpen($srchid, 'search', $sessid, $gunid); $res = $tr->uploadOpen($srchid, 'search', $sessid, $gunid);
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.11 $ Version : $Revision: 1.12 $
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.11 $ * @version $Revision: 1.12 $
* @see BasicStor * @see BasicStor
*/ */
class GreenBox extends BasicStor{ class GreenBox extends BasicStor{
@ -300,16 +300,16 @@ class GreenBox extends BasicStor{
* Query parts is array of [fieldname, operator, value] entities. * Query parts is array of [fieldname, operator, value] entities.
* *
* *
* @param searchData string, search query - * @param criteria string, search query -
* only one SQL LIKE term supported now. * only one SQL LIKE term supported now.
* It will be searched in all literal object values * It will be searched in all literal object values
* in metadata database * in metadata database
* @param sessid string, session id * @param sessid string, session id
* @return array of gunid strings * @return array of gunid strings
*/ */
function localSearch($searchData, $sessid='') function localSearch($criteria, $sessid='')
{ {
return $this->bsLocalSearch($searchData); return $this->bsLocalSearch($criteria);
} }
/* --------------------------------------------------------- info methods */ /* --------------------------------------------------------- info methods */
@ -456,6 +456,20 @@ class GreenBox extends BasicStor{
return TRUE; return TRUE;
} }
/**
* 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 * Check authorization - auxiliary method
* *

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.9 $ Version : $Revision: 1.10 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -67,9 +67,7 @@ class LocStor extends GreenBox{
}else{ }else{
// gunid doesn't exists - do insert // gunid doesn't exists - do insert
$tmpid = uniqid(''); $tmpid = uniqid('');
$parid = $this->getObjId( $parid = $this->_getHomeDirId($sessid);
$this->getSessLogin($sessid), $this->storId
);
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;
@ -168,7 +166,7 @@ class LocStor extends GreenBox{
* Discard downloadable URL for audio file * Discard downloadable URL for audio file
* *
* @param token string, download token * @param token string, download token
* @return boolean * @return string, gunid
*/ */
function downloadRawAudioDataClose($token) function downloadRawAudioDataClose($token)
{ {
@ -201,7 +199,7 @@ class LocStor extends GreenBox{
* Discard downloadable URL for metadata * Discard downloadable URL for metadata
* *
* @param token string, download token * @param token string, download token
* @return boolean * @return string, gunid
*/ */
function downloadMetadataClose($token) function downloadMetadataClose($token)
{ {

View file

@ -23,7 +23,7 @@
Author : $Author: tomas $ Author : $Author: tomas $
Version : $Revision: 1.7 $ Version : $Revision: 1.8 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -329,6 +329,7 @@ class StoredFile{
* *
* @param metadata string, local path to metadata XML file or XML string * @param metadata string, local path to metadata XML file or XML string
* @param mdataLoc string 'file'|'string' * @param mdataLoc string 'file'|'string'
* @return boolean
*/ */
function replaceMetaData($metadata, $mdataLoc='file') function replaceMetaData($metadata, $mdataLoc='file')
{ {
@ -457,11 +458,11 @@ class StoredFile{
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
$res = $this->md->delete(); $res = $this->md->delete();
if(PEAR::isError($res)) return $res; if(PEAR::isError($res)) return $res;
$tokens = $this->dbc->getAll("SELECT token FROM {$this->accessTable} $tokens = $this->dbc->getAll("SELECT token, ext FROM {$this->accessTable}
WHERE gunid='{$this->gunid}'"); WHERE gunid='{$this->gunid}'");
if(is_array($tokens)) foreach($tokens as $i=>$item){ if(is_array($tokens)) foreach($tokens as $i=>$item){
$file = _getAccessFname($item['token'], $item['ext']); $file = $this->_getAccessFname($item['token'], $item['ext']);
@unlink($file); if(file_exists($file)){ @unlink($file); }
} }
$res = $this->dbc->query("DELETE FROM {$this->accessTable} $res = $this->dbc->query("DELETE FROM {$this->accessTable}
WHERE gunid='{$this->gunid}'"); WHERE gunid='{$this->gunid}'");

View file

@ -23,7 +23,7 @@
# #
# #
# Author : $Author: tomas $ # Author : $Author: tomas $
# Version : $Revision: 1.7 $ # Version : $Revision: 1.8 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh,v $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh,v $
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
@ -60,12 +60,13 @@ storeAudioClip() {
# echo -n "# storeAudioClip: " # echo -n "# storeAudioClip: "
# MEDIA=../tests/ex1.mp3 # MEDIA=../tests/ex1.mp3
MEDIA=var/tests/ex1.mp3 MEDIA=var/tests/ex1.mp3
METADATA=../tests/testStorage.xml # METADATA=var/tests/mdata4.xml
# RGUNID=`$XR_CLI storeAudioClip "$SESSID" '' "$MEDIA" "$METADATA"` || \ # RGUNID=`$XR_CLI storeAudioClip "$SESSID" '' "$MEDIA" "$METADATA"` || \
# { ERN=$?; echo $RGUNID; exit $ERN; } # { ERN=$?; echo $RGUNID; exit $ERN; }
MD5=`md5sum $MEDIA`; for i in $MD5; do MD5=$i; break; done MD5=`md5sum $MEDIA`; for i in $MD5; do MD5=$i; break; done
echo "md5=$MD5"
echo -n "# storeAudioClipOpen: " echo -n "# storeAudioClipOpen: "
RES=`$XR_CLI storeAudioClipOpen "$SESSID" '' '<metadata><title>Title XY</title></metadata>' "$MD5"` || \ RES=`$XR_CLI storeAudioClipOpen "$SESSID" '' '<metadata><title>ěščřžé</title></metadata>' "$MD5"` || \
{ ERN=$?; echo $RES; exit $ERN; } { ERN=$?; echo $RES; exit $ERN; }
unset URL unset URL
for i in $RES; do if [ -z $URL ] ; then URL=$i; else TOKEN=$i; fi; done for i in $RES; do if [ -z $URL ] ; then URL=$i; else TOKEN=$i; fi; done

View file

@ -24,7 +24,7 @@
# #
# #
# Author : $Author: tomas $ # Author : $Author: tomas $
# Version : $Revision: 1.4 $ # Version : $Revision: 1.5 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/Attic/xr_cli_test.py,v $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/Attic/xr_cli_test.py,v $
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -43,15 +43,16 @@ if len(sys.argv)<3:
login <username> <password> login <username> <password>
authenticate <username> <password> authenticate <username> <password>
logout <session_id> logout <session_id>
existsAudioClip <session_id> <global_unique_id> ...
storeAudioClip <session_id> <global_unique_id> <media_file_path> <metadata_file_path>
deleteAudioClip <session_id> <global_unique_id>
updateAudioClipMetadata <session_id> <global_unique_id> <metadata_file_path>
searchMetadata <session_id> <criteria>
accessRawAudioData <session_id> <global_unique_id>
releaseRawAudioData <session_id> <tmp_link_path>
getAudioClip <session_id> <global_unique_id>
""" """
# existsAudioClip <session_id> <global_unique_id>
# storeAudioClip <session_id> <global_unique_id> <media_file_path> <metadata_file_path>
# deleteAudioClip <session_id> <global_unique_id>
# updateAudioClipMetadata <session_id> <global_unique_id> <metadata_file_path>
# searchMetadata <session_id> <criteria>
# accessRawAudioData <session_id> <global_unique_id>
# releaseRawAudioData <session_id> <tmp_link_path>
# getAudioClip <session_id> <global_unique_id>
sys.exit(1) sys.exit(1)
pars = sys.argv pars = sys.argv
@ -63,7 +64,7 @@ if pars[1]=="-s":
pars.pop(1) pars.pop(1)
serverPath = pars.pop(1) serverPath = pars.pop(1)
else: else:
serverPath = 'http://localhost:80/storage/xmlrpc/xrLocStor.php' serverPath = 'http://localhost:80/livesupportStorageServer/xmlrpc/xrLocStor.php'
server = Server(serverPath) server = Server(serverPath)
method = pars.pop(1) method = pars.pop(1)
pars.pop(0) pars.pop(0)
@ -116,9 +117,11 @@ try:
elif method=="updateAudioClipMetadata": 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], 'mdataFileLP':pars[2]})
elif method=="searchMetadata": elif method=="searchMetadata":
print server.locstor.searchMetadata({'sessid':pars[0], 'criteria':pars[1]}) # 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=="getAudioClip": elif method=="getAudioClip":
print server.locstor.getAudioClip({'sessid':pars[0], 'gunid':pars[1]}) r = server.locstor.getAudioClip({'sessid':pars[0], 'gunid':pars[1]})
print r['metadata']
elif method=="resetStorage": elif method=="resetStorage":
print server.locstor.resetStorage({}) print server.locstor.resetStorage({})
elif method=="openPut": elif method=="openPut":