Initial revision
This commit is contained in:
parent
37f30a7efd
commit
f62c1fab5d
40 changed files with 7381 additions and 0 deletions
153
livesupport/modules/storageServer/Makefile
Normal file
153
livesupport/modules/storageServer/Makefile
Normal file
|
@ -0,0 +1,153 @@
|
|||
#-------------------------------------------------------------------------------
|
||||
# Storage - file storage component
|
||||
# Copyright (c) 2004 Media Development Loan Fund
|
||||
#
|
||||
# This file is part of the LiveSupport project.
|
||||
#
|
||||
# LiveSupport is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# LiveSupport is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LiveSupport; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# Author : $Author: tomas $
|
||||
# Version : $Revision: 1.1 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/Attic/Makefile,v $
|
||||
#
|
||||
# @configure_input@
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# General command definitions
|
||||
#-------------------------------------------------------------------------------
|
||||
MKDIR = mkdir -p
|
||||
RM = rm -f
|
||||
RMDIR = rm -rf
|
||||
DOXYGEN = doxygen
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Misc
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
MODULE_NAME = storageServer
|
||||
TAR_C = tar -cj --exclude CVS --exclude '*~' -C ${BASE_DIR} -f
|
||||
DIST_EXT = .tgz
|
||||
DATE = `date +%y%m%d`
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Basic directory and file definitions
|
||||
#-------------------------------------------------------------------------------
|
||||
#BASE_DIR = @builddir@
|
||||
BASE_DIR = .
|
||||
DOC_DIR = ${BASE_DIR}/doc
|
||||
DOXYGEN_DIR = ${DOC_DIR}/doxygen
|
||||
ETC_DIR = ${BASE_DIR}/etc
|
||||
INCLUDE_DIR = ${BASE_DIR}/include
|
||||
LIB_DIR = ${BASE_DIR}/lib
|
||||
SRC_DIR = ${BASE_DIR}/src
|
||||
TMP_DIR = ${BASE_DIR}/tmp
|
||||
|
||||
USR_DIR = ${BASE_DIR}/../../usr
|
||||
USR_INCLUDE_DIR = ${USR_DIR}/include
|
||||
USR_LIB_DIR = ${USR_DIR}/lib
|
||||
|
||||
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
||||
|
||||
HTTP_GROUP = nobody
|
||||
|
||||
PHP_DIR = ${BASE_DIR}/var
|
||||
INSTALL_DIR = ${PHP_DIR}/install
|
||||
STOR_DIR = ${PHP_DIR}/stor
|
||||
ACCESS_DIR = ${PHP_DIR}/access
|
||||
BUFF_DIR = ${STOR_DIR}/buffer
|
||||
TEST_RUNNER = ${PHP_DIR}/xmlrpc/testRunner.sh
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Configuration parameters
|
||||
#-------------------------------------------------------------------------------
|
||||
#CPPFLAGS = @CPPFLAGS@
|
||||
#CXXFLAGS = @CXXFLAGS@ @DEFS@ -I${USR_INCLUDE_DIR} -I${INCLUDE_DIR} -I${TMP_DIR}\
|
||||
# -pedantic -Wall
|
||||
#LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${LIB_DIR}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Dependencies
|
||||
#-------------------------------------------------------------------------------
|
||||
#HELLO_LIB_OBJS = ${TMP_DIR}/Hello.o
|
||||
#TEST_RUNNER_OBJS = ${TMP_DIR}/HelloTest.o ${TMP_DIR}/TestRunner.o
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Targets
|
||||
#-------------------------------------------------------------------------------
|
||||
.PHONY: all dir_setup doc clean docclean depclean distclean dist db_init db_clean
|
||||
|
||||
all: dir_setup db_init
|
||||
|
||||
dir_setup: ${DOXYGEN_DIR} ${STOR_DIR} ${ACCESS_DIR}
|
||||
|
||||
doc:
|
||||
${DOXYGEN} ${DOXYGEN_CONFIG}
|
||||
|
||||
clean: db_clean
|
||||
|
||||
docclean:
|
||||
${RMDIR} ${DOXYGEN_DIR}/html
|
||||
|
||||
depclean: clean
|
||||
|
||||
dist:
|
||||
${TAR_C} ${MODULE_NAME}${DATE}${DIST_EXT} *
|
||||
|
||||
distclean: clean docclean
|
||||
|
||||
check: all ${TEST_RUNNER}
|
||||
${TEST_RUNNER}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Specific targets
|
||||
#-------------------------------------------------------------------------------
|
||||
db_init:
|
||||
cd var/install; php -q install.php
|
||||
|
||||
db_clean:
|
||||
cd var/install; php -q uninstall.php
|
||||
|
||||
${TMP_DIR}:
|
||||
${MKDIR} ${TMP_DIR}
|
||||
|
||||
${DOXYGEN_DIR}:
|
||||
${MKDIR} ${DOXYGEN_DIR}
|
||||
|
||||
${STOR_DIR}:
|
||||
${MKDIR} ${STOR_DIR}
|
||||
chown .${HTTP_GROUP} ${STOR_DIR}
|
||||
chmod g+ws ${STOR_DIR}
|
||||
|
||||
${ACCESS_DIR}:
|
||||
${MKDIR} ${ACCESS_DIR}
|
||||
chown .${HTTP_GROUP} ${ACCESS_DIR}
|
||||
chmod g+ws ${ACCESS_DIR}
|
||||
|
||||
${BUFF_DIR}:
|
||||
${MKDIR} ${BUFF_DIR}
|
||||
chmod g+w ${BUFF_DIR}
|
||||
|
||||
${TEST_RUNNER}:
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pattern rules
|
||||
#-------------------------------------------------------------------------------
|
||||
#${TMP_DIR}/%.o : ${SRC_DIR}/%.cxx
|
||||
# ${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $<
|
||||
|
1144
livesupport/modules/storageServer/etc/doxygen.config
Normal file
1144
livesupport/modules/storageServer/etc/doxygen.config
Normal file
File diff suppressed because it is too large
Load diff
993
livesupport/modules/storageServer/var/GreenBox.php
Normal file
993
livesupport/modules/storageServer/var/GreenBox.php
Normal file
|
@ -0,0 +1,993 @@
|
|||
<?
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/GreenBox.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
define('GBERR_DENY', 40);
|
||||
define('GBERR_FILEIO', 41);
|
||||
define('GBERR_FILENEX', 42);
|
||||
define('GBERR_FOBJNEX', 43);
|
||||
define('GBERR_WRTYPE', 44);
|
||||
define('GBERR_NONE', 45);
|
||||
define('GBERR_AOBJNEX', 46);
|
||||
define('GBERR_NOTF', 47);
|
||||
|
||||
define('GBERR_NOTIMPL', 50);
|
||||
|
||||
require_once '../../../alib/var/alib.php';
|
||||
require_once '../StoredFile.php';
|
||||
|
||||
/**
|
||||
* GreenBox class
|
||||
*
|
||||
* LiveSupport file storage module
|
||||
*
|
||||
* @author $Author: tomas $
|
||||
* @version $Revision: 1.1 $
|
||||
* @see Alib
|
||||
*/
|
||||
class GreenBox extends Alib{
|
||||
var $filesTable;
|
||||
var $mdataTable;
|
||||
var $accessTable;
|
||||
var $storageDir;
|
||||
var $accessDir;
|
||||
var $rootId;
|
||||
var $storId;
|
||||
var $doDebug = true;
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param dbc PEAR::db abstract class reference
|
||||
* @param config config array from conf.php
|
||||
* @return class instance
|
||||
*/
|
||||
function GreenBox(&$dbc, $config)
|
||||
{
|
||||
parent::Alib(&$dbc, $config);
|
||||
$this->filesTable = $config['tblNamePrefix'].'files';
|
||||
$this->mdataTable = $config['tblNamePrefix'].'mdata';
|
||||
$this->accessTable= $config['tblNamePrefix'].'access';
|
||||
$this->storageDir = $config['storageDir'];
|
||||
$this->accessDir = $config['accessDir'];
|
||||
$this->dbc->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
$this->rootId = $this->getRootNode();
|
||||
$this->storId = $this->wd =
|
||||
$this->getObjId('StorageRoot', $this->rootId);
|
||||
$this->dbc->setErrorHandling();
|
||||
}
|
||||
|
||||
|
||||
/* ======================================================= public methods */
|
||||
|
||||
/**
|
||||
* Create new folder
|
||||
*
|
||||
* @param parid int, parent id
|
||||
* @param folderName string, name for new folder
|
||||
* @param sessid string, session id
|
||||
* @return id of new folder
|
||||
* @exception PEAR::error
|
||||
*/
|
||||
function createFolder($parid, $folderName, $sessid='')
|
||||
{
|
||||
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
return $this->addObj($folderName , 'Folder', $parid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new file in the storage
|
||||
*
|
||||
* @param parid int, parent id
|
||||
* @param fileName string, name for new file
|
||||
* @param mediaFileLP string, local path of media file
|
||||
* @param mdataFileLP string, local path of metadata file
|
||||
* @param sessid string, session id
|
||||
* @return int
|
||||
* @exception PEAR::error
|
||||
*/
|
||||
function putFile($parid, $fileName,
|
||||
$mediaFileLP, $mdataFileLP, $sessid='')
|
||||
{
|
||||
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$name = "$fileName";
|
||||
$id = $this->addObj($name , 'File', $parid);
|
||||
$ac =& StoredFile::insert(
|
||||
&$this, $id, $name, $mediaFileLP, $mdataFileLP
|
||||
);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return raw media file.<br>
|
||||
* <b>will be probably removed from API</b><br>
|
||||
* see access() method
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param sessid string, session id
|
||||
* @return file
|
||||
*/
|
||||
function getFile($id, $sessid='')
|
||||
{
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::getFile: probably obsolete API function');
|
||||
if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
else{
|
||||
$fname = $ac->accessRawMediaData();
|
||||
# readfile($fname);
|
||||
return join('', file($fname));
|
||||
$fname = $ac->releaseRawMediaData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze media file for internal metadata information
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param sessid string, session id
|
||||
* @return array
|
||||
*/
|
||||
function analyzeFile($id, $sessid='')
|
||||
{
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
else{
|
||||
# echo"<pre>\n"; print_r($ac); exit;
|
||||
$ia = $ac->analyzeMediaFile();
|
||||
return $ia;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return access link to media file
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param sessid string, session id
|
||||
* @return filename as string or PEAR::error
|
||||
*/
|
||||
function access($id, $sessid='')
|
||||
{
|
||||
if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
else{
|
||||
$fname = $ac->accessRawMediaData($sessid);
|
||||
return $fname;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Release access link to media file
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param sessid string, session id
|
||||
* @return boolean or PEAR::error
|
||||
*/
|
||||
function release($id, $sessid='')
|
||||
{
|
||||
if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
else{
|
||||
$res = $ac->releaseRawMediaData($sessid);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename file
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param newName string
|
||||
* @param sessid string, session id
|
||||
* @return boolean or PEAR::error
|
||||
*/
|
||||
function renameFile($id, $newName, $sessid='')
|
||||
{
|
||||
$parid = $this->getParent($id);
|
||||
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
else{
|
||||
$res = $ac->rename($newName);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return $this->renameObj($id, $newName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move file
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param did int, destination folder local id
|
||||
* @param sessid string, session id
|
||||
* @return boolean or PEAR::error
|
||||
*/
|
||||
function moveFile($id, $did, $sessid='')
|
||||
{
|
||||
if($this->getObjType($did) !== 'Folder')
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::moveFile: destination is not folder', GBERR_WRTYPE
|
||||
);
|
||||
if(($res = $this->_authorize(
|
||||
array('read', 'write'), array($id, $did), $sessid
|
||||
)) !== TRUE) return $res;
|
||||
$this->_relocateSubtree($id, $did);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy file
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param did int, destination folder local id
|
||||
* @param sessid string, session id
|
||||
* @return boolean or PEAR::error
|
||||
*/
|
||||
function copyFile($id, $did, $sessid='')
|
||||
{
|
||||
if($this->getObjType($did)!=='Folder')
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::copyFile: destination is not folder', GBERR_WRTYPE
|
||||
);
|
||||
if(($res = $this->_authorize(
|
||||
array('read', 'write'), array($id, $did), $sessid
|
||||
)) !== TRUE) return $res;
|
||||
return $this->_copySubtree($id, $did);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete file
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param sessid int
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function deleteFile($id, $sessid='')
|
||||
{
|
||||
$parid = $this->getParent($id);
|
||||
if(($res = $this->_authorize('write', $parid, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$res = $this->removeObj($id);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- replicas, versions etc. */
|
||||
|
||||
/**
|
||||
* Create replica.<br>
|
||||
* <b>TODO: NOT FINISHED</b>
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param did int, destination folder local id
|
||||
* @param replicaName string, name of new replica
|
||||
* @param sessid string, session id
|
||||
* @return int, local id of new object
|
||||
*/
|
||||
function createReplica($id, $did, $replicaName='', $sessid='')
|
||||
{
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::createVersion: not implemented', GBERR_NOTIMPL
|
||||
);
|
||||
// ---
|
||||
if($this->getObjType($did)!=='Folder')
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::createReplica: dest is not folder', GBERR_WRTYPE
|
||||
);
|
||||
if(($res = $this->_authorize(
|
||||
array('read', 'write'), array($id, $did), $sessid
|
||||
)) !== TRUE) return $res;
|
||||
if($replicaName=='') $replicaName = $this->getObjName($id);
|
||||
while(($exid = $this->getObjId($replicaName, $did))<>'')
|
||||
{ $replicaName.='_R'; }
|
||||
$rid = $this->addObj($replicaName , 'Replica', $did, 0, $id);
|
||||
if(PEAR::isError($rid)) return $rid;
|
||||
# $this->addMdata($this->_pathFromId($rid), 'isReplOf', $id, $sessid);
|
||||
return $rid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create version.<br>
|
||||
* <b>TODO: NOT FINISHED</b>
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param did int, destination folder local id
|
||||
* @param versionLabel string, name of new version
|
||||
* @param sessid string, session id
|
||||
* @return int, local id of new object
|
||||
*/
|
||||
function createVersion($id, $did, $versionLabel, $sessid='')
|
||||
{
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::createVersion: not implemented', GBERR_NOTIMPL
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------- metadata */
|
||||
|
||||
/**
|
||||
* Update metadata tree
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param mdataFile string, local path of metadata XML file
|
||||
* @param sessid string, session id
|
||||
* @return boolean or PEAR::error
|
||||
*/
|
||||
function updateMetadata($id, $mdataFile, $sessid='')
|
||||
{
|
||||
if(($res = $this->_authorize('write', $id, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
else{
|
||||
return $ac->updateMetaData($mdataFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
else{
|
||||
return $ac->updateMetaDataRecord($mdid, $object, $objns);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add single metadata record.<br>
|
||||
* <b>TODO: NOT FINISHED</b><br>
|
||||
* 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 PEAR::raiseError(
|
||||
'GreenBox::addMetaDataRecord: not implemented', GBERR_NOTIMPL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get metadata XML tree as string
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param sessid string, session id
|
||||
* @return string or PEAR::error
|
||||
*/
|
||||
function getMdata($id, $sessid='')
|
||||
{
|
||||
if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
else{
|
||||
return $ac->getMetaData();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search in local metadata database.<br>
|
||||
* <b>TODO: NOT FINISHED</b><br>
|
||||
* Should support structured queries, e.g.:<br>
|
||||
* XML file with the structure as metadata, but
|
||||
* with SQL LIKE terms instead of metadata values.<br>
|
||||
* Some standard query format would be better,
|
||||
* but I've not found it yet.
|
||||
*
|
||||
* @param searchData string, search query -
|
||||
* only one SQL LIKE term supported now.
|
||||
* It will be searched in all literal object values
|
||||
* in metadata database
|
||||
* @param sessid string, session id
|
||||
* @return array of gunid strings
|
||||
*/
|
||||
function localSearch($searchData, $sessid='')
|
||||
{
|
||||
$ftsrch = $searchData;
|
||||
$res = $this->dbc->getAll("SELECT md.gunid as gunid
|
||||
FROM {$this->filesTable} f, {$this->mdataTable} md
|
||||
WHERE f.gunid=md.gunid AND md.objns='_L' AND
|
||||
md.object like '$ftsrch'
|
||||
GROUP BY md.gunid
|
||||
");
|
||||
if(!is_array($res)) $res = array();
|
||||
/*
|
||||
if(!(count($res)>0))
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::localSearch: no items found', GBERR_NONE
|
||||
);
|
||||
*/
|
||||
return $res;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- remote repository methods */
|
||||
|
||||
/**
|
||||
* Upload file to remote repository
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param sessid string, session id
|
||||
* @return string - transfer id or PEAR::error
|
||||
*/
|
||||
function uploadFile($id, $sessid='')
|
||||
{
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::uploadFile: not implemented', GBERR_NOTIMPL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file from remote repository
|
||||
*
|
||||
* @param id int, virt.file's local id
|
||||
* @param parid int, destination folder local id
|
||||
* @param sessid string, session id
|
||||
* @return string - transfer id or PEAR::error
|
||||
*/
|
||||
function downloadFile($id, $parid, $sessid='')
|
||||
{
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::downloadFile: not implemented', GBERR_NOTIMPL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search in central metadata database
|
||||
*
|
||||
* @param searchData string, search query - see localSearch method
|
||||
* @param sessid string, session id
|
||||
* @return string - job id or PEAR::error
|
||||
*/
|
||||
function globalSearch($searchData, $sessid='')
|
||||
{
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::globalSearch: not implemented', GBERR_NOTIMPL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/* --------------------------------------------------------- info methods */
|
||||
|
||||
/**
|
||||
* List files in folder
|
||||
*
|
||||
* @param id int, local id of folder
|
||||
* @param sessid string, session id
|
||||
* @return array
|
||||
*/
|
||||
function listFolder($id, $sessid='')
|
||||
{
|
||||
if(($res = $this->_authorize('read', $id, $sessid)) !== TRUE)
|
||||
return $res;
|
||||
if($this->getObjType($id)!=='Folder')
|
||||
return PEAR::raiseError(
|
||||
'GreenBox::listFolder: not a folder', GBERR_NOTF
|
||||
);
|
||||
$a = $this->getDir($id, 'id, name, type, param as target', 'name');
|
||||
return $a;
|
||||
}
|
||||
|
||||
/**
|
||||
* List files in folder
|
||||
*
|
||||
* @param id int, local id of object
|
||||
* @param relPath string, relative path
|
||||
* @return array
|
||||
*/
|
||||
function getObjIdFromRelPath($id, $relPath='.')
|
||||
{
|
||||
# $a = $this->getDir($id, 'id, name, type, param as target', 'name');
|
||||
$a = split('/', $relPath);
|
||||
if($this->getObjType($id)!=='Folder') $nid = $this->getparent($id);
|
||||
else $nid = $id;
|
||||
foreach($a as $i=>$item){
|
||||
switch($item){
|
||||
case".":
|
||||
break;
|
||||
case"..":
|
||||
$nid = $this->getparent($nid);
|
||||
break;
|
||||
case"":
|
||||
break;
|
||||
default:
|
||||
$nid = $this->getObjId($item, $nid);
|
||||
}
|
||||
# $a[$i] = array('o'=>$item, 'n'=>($nid==null ? 'NULL' : $nid));
|
||||
}
|
||||
# return $a;
|
||||
return $nid;
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------- redefined methods */
|
||||
|
||||
/**
|
||||
* Logout and destroy session
|
||||
*
|
||||
* @param sessid string
|
||||
* @return true/err
|
||||
*/
|
||||
function logout($sessid)
|
||||
{
|
||||
$acfa = $this->dbc->getAll("SELECT * FROM {$this->accessTable}
|
||||
WHERE sessid='$sessid'");
|
||||
if(PEAR::isError($acfa)) return $acfa;
|
||||
foreach($acfa as $i=>$acf){
|
||||
$ac =& StoredFile::recallFromLink(&$this, $acf['tmplink'], $sessid);
|
||||
$ac->releaseRawMediaData($sessid);
|
||||
}
|
||||
parent::logout($sessid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new user with home folder
|
||||
*
|
||||
* @param login string
|
||||
* @param pass string OPT
|
||||
* @return int/err
|
||||
*/
|
||||
function addSubj($login, $pass=NULL)
|
||||
{
|
||||
$uid = parent::addSubj($login, $pass);
|
||||
if(PEAR::isError($uid)) return $uid;
|
||||
$fid = $this->addObj($login , 'Folder', $this->storId);
|
||||
if(PEAR::isError($fid)) return $fid;
|
||||
$res = $this->addPerm($uid, '_all', $fid, 'A');
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return $uid;
|
||||
}
|
||||
/**
|
||||
* Remove user and his home folder
|
||||
*
|
||||
* @param login string
|
||||
* @param uid int OPT
|
||||
* @return boolean/err
|
||||
*/
|
||||
function removeSubj($login, $uid=NULL)
|
||||
{
|
||||
$res = parent::removeSubj($login, $pass);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$id = $this->getObjId($login, $this->storId);
|
||||
if(PEAR::isError($id)) return $id;
|
||||
$res = $this->removeObj($id);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file's path in virtual filesystem
|
||||
*
|
||||
* @param id int
|
||||
* @return array
|
||||
*/
|
||||
function getPath($id)
|
||||
{
|
||||
$pa = parent::getPath($id, 'id, name, type'); array_shift($pa);
|
||||
return $pa;
|
||||
}
|
||||
|
||||
/* ==================================================== "private" methods */
|
||||
|
||||
/**
|
||||
* Copy virtual file.<br>
|
||||
* Redefined from parent class.
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
function copyObj($id, $newParid, $after='')
|
||||
{
|
||||
$nid = parent::copyObj($id, $newParid, $after='');
|
||||
if($this->getObjType($id)==='File'){
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(PEAR::isError($ac)){ return $ac; }
|
||||
$ac2 =& StoredFile::copyOf(&$ac, $nid);
|
||||
}
|
||||
return $nid;
|
||||
}
|
||||
/**
|
||||
* Optionaly remove virtual file with the same name and add new one.<br>
|
||||
* Redefined from parent class.
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
function addObj($name, $type, $parid=1, $aftid=NULL, $param='')
|
||||
{
|
||||
if(!is_null($exid = $this->getObjId($name, $parid)))
|
||||
{ $this->removeObj($exid); }
|
||||
return parent::addObj($name, $type, $parid, $aftid, $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove virtual file.<br>
|
||||
* Redefined from parent class.
|
||||
*
|
||||
* @param id int, local id of removed object
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function removeObj($id)
|
||||
{
|
||||
switch($this->getObjType($id)){
|
||||
case"File":
|
||||
$ac =& StoredFile::recall(&$this, $id);
|
||||
if(!PEAR::isError($ac)){
|
||||
$ac->delete();
|
||||
}
|
||||
parent::removeObj($id);
|
||||
break;
|
||||
case"Folder":
|
||||
parent::removeObj($id);
|
||||
break;
|
||||
case"Replica":
|
||||
parent::removeObj($id);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check authorization - auxiliary method
|
||||
*
|
||||
* @param acts array of actions
|
||||
* @param pars array of parameters - e.g. ids
|
||||
* @param sessid string, session id
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function _authorize($acts, $pars, $sessid='')
|
||||
{
|
||||
$userid = $this->getSessUserId($sessid);
|
||||
if(!is_array($pars)) $pars = array($pars);
|
||||
if(!is_array($acts)) $acts = array($acts);
|
||||
$perm = true;
|
||||
foreach($acts as $i=>$action){
|
||||
$res = $this->checkPerm($userid, $action, $pars[$i]);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$perm = $perm && $res;
|
||||
}
|
||||
if($perm) return TRUE;
|
||||
return PEAR::raiseError("GreenBox::$method: access denied", GBERR_DENY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local id from global id
|
||||
*
|
||||
* @param gunid string global id
|
||||
* @return int local id
|
||||
*/
|
||||
function _idFromGunid($gunid)
|
||||
{
|
||||
return $this->dbc->getOne(
|
||||
"SELECT id FROM {$this->filesTable} WHERE gunid='$gunid'"
|
||||
);
|
||||
}
|
||||
|
||||
/* =============================================== test and debug methods */
|
||||
/**
|
||||
* dump
|
||||
*
|
||||
*/
|
||||
function dump($id='', $indch=' ', $ind='', $format='{name}')
|
||||
{
|
||||
if($id=='') $id = $this->storId;
|
||||
return parent::dump($id, $indch, $ind, $format);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
function dumpDir($id='', $format='$o["name"]')
|
||||
{
|
||||
if($id=='') $id = $this->storId;
|
||||
$arr = $this->getDir($id, 'id,name');
|
||||
// if($this->doDebug){ $this->debug($arr); exit; }
|
||||
$arr = array_map(create_function('$o', 'return "'.$format.'";'), $arr);
|
||||
return join('', $arr);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
function debug($va)
|
||||
{
|
||||
echo"<pre>\n"; print_r($va); #exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* deleteData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function deleteData()
|
||||
{
|
||||
// $this->dbc->query("DELETE FROM {$this->filesTable}");
|
||||
$ids = $this->dbc->getAll("SELECT id FROM {$this->filesTable}");
|
||||
if(is_array($ids)) foreach($ids as $i=>$item){
|
||||
$this->removeObj($item['id']);
|
||||
}
|
||||
parent::deleteData();
|
||||
$this->initData();
|
||||
}
|
||||
/**
|
||||
* testData
|
||||
*
|
||||
*/
|
||||
function testData($d='')
|
||||
{
|
||||
$exdir = dirname(getcwd()).'/tests';
|
||||
$s = $this->sessid;
|
||||
$o[] = $this->addSubj('test1', 'a');
|
||||
$o[] = $this->addSubj('test2', 'a');
|
||||
$o[] = $this->addSubj('test3', 'a');
|
||||
$o[] = $this->addSubj('test4', 'a');
|
||||
|
||||
$o[] = $t1hd = $this->getObjId('test1', $this->storId);
|
||||
$o[] = $t1d1 = $this->createFolder($t1hd, 'test1_folder1', $s);
|
||||
$o[] = $this->createFolder($t1hd, 'test1_folder2', $s);
|
||||
$o[] = $this->createFolder($t1d1, 'test1_folder1_1', $s);
|
||||
$o[] = $t1d12 = $this->createFolder($t1d1, 'test1_folder1_2', $s);
|
||||
|
||||
$o[] = $t2hd = $this->getObjId('test2', $this->storId);
|
||||
$o[] = $this->createFolder($t2hd, 'test2_folder1', $s);
|
||||
|
||||
$o[] = $this->putFile($t1hd, 'file1.mp3', "$exdir/ex1.mp3", '', $s);
|
||||
$o[] = $this->putFile($t1d12 , 'file2.wav', "$exdir/ex2.wav", '', $s);
|
||||
/*
|
||||
*/
|
||||
$this->tdata['storage'] = $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* test
|
||||
*
|
||||
*/
|
||||
function test()
|
||||
{
|
||||
// if(PEAR::isError($p = parent::test())) return $p;
|
||||
$this->deleteData();
|
||||
$this->login('root', $this->config['tmpRootPass']);
|
||||
$this->testData();
|
||||
$this->logout($this->sessid);
|
||||
$this->test_correct = " StorageRoot
|
||||
root
|
||||
test1
|
||||
test1_folder1
|
||||
test1_folder1_1
|
||||
test1_folder1_2
|
||||
file2.wav
|
||||
test1_folder2
|
||||
file1.mp3
|
||||
test2
|
||||
test2_folder1
|
||||
test3
|
||||
test4
|
||||
";
|
||||
$this->test_dump = $this->dumpTree($this->storId);
|
||||
if($this->test_dump==$this->test_correct)
|
||||
{ $this->test_log.="Storage: OK\n"; return true; }
|
||||
else PEAR::raiseError('GreenBox::test:', 1, PEAR_ERROR_DIE, '%s'.
|
||||
"<pre>\ncorrect:\n.{$this->test_correct}.\n".
|
||||
"dump:\n.{$this->test_dump}.\n</pre>\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* initData - initialize
|
||||
*
|
||||
*/
|
||||
function initData()
|
||||
{
|
||||
$this->rootId = $this->getRootNode();
|
||||
$this->storId = $this->wd =
|
||||
$this->addObj('StorageRoot', 'Folder', $this->rootId);
|
||||
$rootUid = parent::addSubj('root', $this->config['tmpRootPass']);
|
||||
$this->login('root', $this->config['tmpRootPass']);
|
||||
$res = $this->addPerm($rootUid, '_all', $this->rootId, 'A');
|
||||
$fid = $this->createFolder($this->storId, 'root', $this->sessid);
|
||||
# $id = $this->dbc->nextId("{$this->mdataTable}_id_seq");
|
||||
$this->logout($this->sessid);
|
||||
}
|
||||
/**
|
||||
* install - create tables
|
||||
*
|
||||
*/
|
||||
function install()
|
||||
{
|
||||
parent::install();
|
||||
$this->dbc->query("CREATE TABLE {$this->filesTable} (
|
||||
id int not null,
|
||||
gunid char(32) not null,
|
||||
name varchar(255) not null default'',
|
||||
type varchar(255) not null default'',
|
||||
currentlyAccessing int not null default 0
|
||||
)");
|
||||
$this->dbc->query("CREATE UNIQUE INDEX {$this->filesTable}_id_idx
|
||||
ON {$this->filesTable} (id)");
|
||||
$this->dbc->query("CREATE UNIQUE INDEX {$this->filesTable}_gunid_idx
|
||||
ON {$this->filesTable} (gunid)");
|
||||
$this->dbc->query("CREATE INDEX {$this->filesTable}_name_idx
|
||||
ON {$this->filesTable} (name)");
|
||||
|
||||
$this->dbc->createSequence("{$this->mdataTable}_id_seq");
|
||||
$this->dbc->query("CREATE TABLE {$this->mdataTable} (
|
||||
id int not null,
|
||||
gunid char(32),
|
||||
subjns varchar(255), -- subject namespace shortcut/uri
|
||||
subject varchar(255) not null default '',
|
||||
predns varchar(255), -- predicate namespace shortcut/uri
|
||||
predicate varchar(255) not null,
|
||||
predxml char(1) not null default 'T', -- Tag or Attribute
|
||||
objns varchar(255), -- object namespace shortcut/uri
|
||||
object text
|
||||
)");
|
||||
$this->dbc->query("CREATE UNIQUE INDEX {$this->mdataTable}_id_idx
|
||||
ON {$this->mdataTable} (id)");
|
||||
$this->dbc->query("CREATE INDEX {$this->mdataTable}_gunid_idx
|
||||
ON {$this->mdataTable} (gunid)");
|
||||
$this->dbc->query("CREATE INDEX {$this->mdataTable}_subj_idx
|
||||
ON {$this->mdataTable} (subjns, subject)");
|
||||
$this->dbc->query("CREATE INDEX {$this->mdataTable}_pred_idx
|
||||
ON {$this->mdataTable} (predns, predicate)");
|
||||
|
||||
$this->dbc->query("CREATE TABLE {$this->accessTable} (
|
||||
gunid char(32) not null,
|
||||
sessid char(32) not null,
|
||||
tmpLink varchar(255) not null default'',
|
||||
ts timestamp
|
||||
)");
|
||||
$this->dbc->query("CREATE INDEX {$this->accessTable}_acc_idx
|
||||
ON {$this->accessTable} (tmpLink, sessid)");
|
||||
if(!file_exists("{$this->storageDir}/buffer")){
|
||||
mkdir("{$this->storageDir}/buffer", 0775);
|
||||
}
|
||||
$this->initData();
|
||||
}
|
||||
/**
|
||||
* id subjns subject predns predicate objns object
|
||||
* y1 literal xmbf NULL namespace literal http://www.sotf.org/xbmf
|
||||
* x1 gunid <gunid> xbmf contributor NULL NULL
|
||||
* x2 mdid x1 xbmf role literal Editor
|
||||
*
|
||||
* predefined shortcuts:
|
||||
* _L = literal
|
||||
* _G = gunid (global id of media file)
|
||||
* _I = mdid (local id of metadata record)
|
||||
* _nssshortcut = namespace shortcut definition
|
||||
* _blank = blank node
|
||||
*/
|
||||
|
||||
/**
|
||||
* uninstall
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function uninstall()
|
||||
{
|
||||
$this->dbc->query("DROP TABLE {$this->mdataTable}");
|
||||
$this->dbc->dropSequence("{$this->mdataTable}_id_seq");
|
||||
$this->dbc->query("DROP TABLE {$this->filesTable}");
|
||||
$this->dbc->query("DROP TABLE {$this->accessTable}");
|
||||
$d = dir($this->storageDir);
|
||||
while (is_object($d) && (false !== ($entry = $d->read()))){
|
||||
if(filetype("{$this->storageDir}/$entry")=='dir' &&
|
||||
$entry!='CVS' && strlen($entry)==3)
|
||||
{
|
||||
$dd = dir("{$this->storageDir}/$entry");
|
||||
while (false !== ($ee = $dd->read())){
|
||||
//if(substr($ee, -4)=='.mp3' || substr($ee, -4)=='.xml')
|
||||
if(substr($ee, 0, 1)!=='.')
|
||||
unlink("{$this->storageDir}/$entry/$ee");
|
||||
}
|
||||
$dd->close();
|
||||
rmdir("{$this->storageDir}/$entry");
|
||||
}
|
||||
}
|
||||
if(is_object($d)) $d->close();
|
||||
if(file_exists("{$this->storageDir}/buffer")){
|
||||
$d = dir("{$this->storageDir}/buffer");
|
||||
while (false !== ($entry = $d->read())) if(substr($entry,0,1)!='.')
|
||||
{ unlink("{$this->storageDir}/buffer/$entry"); }
|
||||
$d->close();
|
||||
rmdir("{$this->storageDir}/buffer");
|
||||
}
|
||||
parent::uninstall();
|
||||
}
|
||||
|
||||
/**
|
||||
* Aux logging for debug
|
||||
*
|
||||
* @param msg string - log message
|
||||
*/
|
||||
function debugLog($msg)
|
||||
{
|
||||
$fp=fopen("{$this->storageDir}/log", "a") or die("Can't write to log\n");
|
||||
fputs($fp, date("H:i:s").">$msg<\n");
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
?>
|
124
livesupport/modules/storageServer/var/LocStor.php
Normal file
124
livesupport/modules/storageServer/var/LocStor.php
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?
|
||||
/**
|
||||
* LocStor class
|
||||
*
|
||||
* Livesupport local storage interface
|
||||
*/
|
||||
require_once '../GreenBox.php';
|
||||
|
||||
class LocStor extends GreenBox{
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @param gunid string
|
||||
* @param sessid string
|
||||
* @return boolean
|
||||
*/
|
||||
function existsAudioClip($sessid, $gunid)
|
||||
{
|
||||
$ac =& StoredFile::recall(&$this, '', $gunid);
|
||||
if(PEAR::isError($ac)){
|
||||
// catch some exceptions
|
||||
switch($ac->getCode()){
|
||||
case GBERR_FILENEX:
|
||||
case GBERR_FOBJNEX:
|
||||
return FALSE;
|
||||
break;
|
||||
default: return $ac;
|
||||
}
|
||||
}
|
||||
if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
return $ac->exists();
|
||||
}
|
||||
function storeAudioClip($sessid, $gunid, $mediaFileLP, $mdataFileLP)
|
||||
{
|
||||
// test if specified gunid exists:
|
||||
$ac =& StoredFile::recall(&$this, '', $gunid);
|
||||
if(!PEAR::isError($ac)){
|
||||
// gunid exists - do replace
|
||||
if(($res = $this->_authorize(
|
||||
'write', $ac->getId(), $sessid
|
||||
)) !== TRUE) return $res;
|
||||
if($ac->isAccessed()){
|
||||
return PEAR::raiseError(
|
||||
'LocStor.php: storeAudioClip: is accessed'
|
||||
);
|
||||
}
|
||||
$res = $ac->replace(
|
||||
$ac->getId(), $ac->name,$mediaFileLP, $mdataFileLP
|
||||
);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
}else{
|
||||
// gunid doesn't exists - do insert
|
||||
$tmpid = uniqid('');
|
||||
$parid = $this->getObjId(
|
||||
$this->getSessLogin($sessid), $this->storId
|
||||
);
|
||||
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, '', $mediaFileLP, $mdataFileLP
|
||||
);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
// $this->debugLog("parid=$parid, gunid={$ac->gunid},
|
||||
// mediaFileLP=$mediaFileLP");
|
||||
$res = $this->renameFile($oid, $ac->gunid, $sessid);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
}
|
||||
return $ac->gunid;
|
||||
}
|
||||
function deleteAudioClip($sessid, $gunid)
|
||||
{
|
||||
$ac =& StoredFile::recall(&$this, '', $gunid);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$res = $this->deleteFile($ac->getId(), $sessid);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
function updateAudioClipMetadata($sessid, $gunid, $mdataFileLP)
|
||||
{
|
||||
$ac =& StoredFile::recall(&$this, '', $gunid);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('write', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
return $ac->replaceMetaData($mdataFileLP);
|
||||
}
|
||||
function accessRawAudioData($sessid, $gunid)
|
||||
{
|
||||
$ac =& StoredFile::recall(&$this, '', $gunid);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
return $ac->accessRawMediaData($sessid);
|
||||
}
|
||||
function releaseRawAudioData($sessid, $tmpLink)
|
||||
{
|
||||
$ac =& StoredFile::recallFromLink(&$this, $tmpLink, $sessid);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
return $ac->releaseRawMediaData($sessid);
|
||||
}
|
||||
function searchMetadata($sessid, $criteria)
|
||||
{
|
||||
$res = $this->localSearch($criteria, $sessid);
|
||||
return $res;
|
||||
}
|
||||
function getAudioClip($sessid, $gunid)
|
||||
{
|
||||
$ac =& StoredFile::recall(&$this, '', $gunid);
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
if(($res = $this->_authorize('read', $ac->getId(), $sessid)) !== TRUE)
|
||||
return $res;
|
||||
$md = $this->getMdata($ac->getId(), $sessid);
|
||||
if(PEAR::isError($md)) return $md;
|
||||
return $md;
|
||||
}
|
||||
}
|
||||
?>
|
454
livesupport/modules/storageServer/var/MetaData.php
Normal file
454
livesupport/modules/storageServer/var/MetaData.php
Normal file
|
@ -0,0 +1,454 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/MetaData.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* MetaData class
|
||||
*
|
||||
* LiveSupport file storage support class.<br>
|
||||
* Store metadata tree in relational database.<br>
|
||||
* <b>requires DOMXML support in PHP!</b>
|
||||
*
|
||||
* @see StoredFile
|
||||
*/
|
||||
class MetaData{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param gb reference to GreenBox object
|
||||
* @param gunid string, global unique id
|
||||
* @return this
|
||||
*/
|
||||
function MetaData(&$gb, $gunid)
|
||||
{
|
||||
$this->dbc =& $gb->dbc;
|
||||
$this->mdataTable = $gb->mdataTable;
|
||||
$this->gunid = $gunid;
|
||||
$this->exists = $this->dbCheck($gunid);
|
||||
}
|
||||
/**
|
||||
* Parse and store metadata from XML file or XML string
|
||||
*
|
||||
* @param mdata string, local path to metadata XML file or XML string
|
||||
* @param loc string 'file'|'string'
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function insert($mdata, $loc='file')
|
||||
{
|
||||
if($this->exists) return FALSE;
|
||||
$res = $this->storeXMLDoc($mdata, $loc);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$this->exists = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
/**
|
||||
* Parse and update metadata
|
||||
*
|
||||
* @param mdata string, local path to metadata XML file or XML string
|
||||
* @param loc string 'file'|'string'
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function update($mdata, $loc='file')
|
||||
{
|
||||
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
|
||||
*
|
||||
* @param mdata string, local path to metadata XML file or XML string
|
||||
* @param loc string 'file'|'string'
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function replace($mdata, $loc='file')
|
||||
{
|
||||
if($this->exists) $res = $this->delete();
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return $this->insert($mdata, $loc);
|
||||
}
|
||||
/**
|
||||
* Return true if metadata exists
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function exists()
|
||||
{
|
||||
return $this->exists;
|
||||
}
|
||||
/**
|
||||
* Delete all file's metadata
|
||||
*
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function delete()
|
||||
{
|
||||
$res = $this->dbc->query("DELETE FROM {$this->mdataTable}
|
||||
WHERE gunid='{$this->gunid}'");
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$this->exists = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
/**
|
||||
* Return metadata XML string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getMetaData()
|
||||
{
|
||||
return $this->genXMLDoc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there are any file's metadata in database
|
||||
*
|
||||
* @param gunid string, global unique id
|
||||
* @return boolean
|
||||
*/
|
||||
function dbCheck($gunid)
|
||||
{
|
||||
$cnt = $this->dbc->getOne("SELECT count(*)as cnt
|
||||
FROM {$this->mdataTable} WHERE gunid='$gunid'");
|
||||
if(PEAR::isError($cnt)) return $cnt;
|
||||
return (intval($cnt) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse and insert or update metadata XML to database
|
||||
*
|
||||
* @param mdata string, local path to metadata XML file or XML string
|
||||
* @param loc string 'file'|'string'
|
||||
* @param mode string 'insert'|'update'
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function storeXMLDoc($mdata='', $loc='file', $mode='insert')
|
||||
{
|
||||
if($loc=='file' && file_exists($mdata)){
|
||||
$xml = domxml_open_file($mdata);
|
||||
}else{
|
||||
$xml = domxml_open_mem($mdata);
|
||||
}
|
||||
$root = $xml->document_element();
|
||||
// $res = $this->dbTransaction($root, NULL, $mode);
|
||||
// $root, $parid=NULL, $mode='insert'
|
||||
// if(PEAR::isError($res)) return $res;
|
||||
$this->dbc->query("BEGIN");
|
||||
if($mode == 'update') $this->nameSpaces = $this->readNamespaces();
|
||||
$res = $this->storeXMLNode($root, NULL, $mode);
|
||||
if(PEAR::isError($res)){
|
||||
$this->dbc->query("ROLLBACK"); return $res;
|
||||
}
|
||||
foreach($this->nameSpaces as $prefix=>$uri){
|
||||
$res = $this->storeRecord(
|
||||
'_L', $prefix, NULL, '_namespace', 'T', '_L', $uri, $mode
|
||||
);
|
||||
if(PEAR::isError($res)){
|
||||
$this->dbc->query("ROLLBACK"); return $res;
|
||||
}
|
||||
}
|
||||
$res = $this->dbc->query("COMMIT");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
return TRUE;
|
||||
|
||||
|
||||
return $root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read namespace definitions from database and return it as array
|
||||
*
|
||||
* @return array or PEAR::error
|
||||
*/
|
||||
function readNamespaces()
|
||||
{
|
||||
$nameSpaces = array();
|
||||
$arr = $this->dbc->getAll("SELECT subject, object
|
||||
FROM {$this->mdataTable}
|
||||
WHERE gunid='{$this->gunid}'
|
||||
AND subjns='_L'
|
||||
AND predns is null AND predicate='_namespace'
|
||||
AND objns='_L'
|
||||
");
|
||||
if(PEAR::isError($arr)) return $arr;
|
||||
if(is_array($arr)){
|
||||
foreach($arr as $i=>$v){
|
||||
$nameSpaces[$v['subject']] = $v['object'];
|
||||
}
|
||||
}
|
||||
return $nameSpaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process one node of metadata XML for insert or update.<br>
|
||||
* <b>TODO: add support for other usable node types</b>
|
||||
*
|
||||
* @param node DOM node object
|
||||
* @param parid int, parent id
|
||||
* @param mode 'insert'|'update'
|
||||
* @return
|
||||
*/
|
||||
function storeXMLNode($node, $parid=NULL, $mode='insert')
|
||||
{
|
||||
switch($node->node_type()){
|
||||
case 1: // element
|
||||
case 2: // attribute
|
||||
$subjns = (is_null($parid)? '_G' : '_I');
|
||||
$subject = (is_null($parid)? $this->gunid : $parid);
|
||||
if(!isset($this->nameSpaces[$node->prefix()]))
|
||||
$this->nameSpaces[$node->prefix()] = $node->namespace_uri();
|
||||
$prefix = $node->prefix();
|
||||
break;
|
||||
}
|
||||
switch($node->node_type()){
|
||||
case 9: // document
|
||||
$this->storeXMLNode($node->document_element(), $parid, $mode);
|
||||
break;
|
||||
case 1: // element
|
||||
if($node->is_blank_node()) break;
|
||||
$id = $this->storeRecord(
|
||||
$subjns, $subject, $prefix, $node->node_name(), 'T',
|
||||
'_blank', NULL, $mode
|
||||
);
|
||||
if(PEAR::isError($id)) return $id;
|
||||
if($node->has_attributes()){
|
||||
foreach($node->attributes() as $attr){
|
||||
$res = $this->storeXMLNode($attr, $id, $mode);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
}
|
||||
}
|
||||
if($node->has_child_nodes()){
|
||||
foreach($node->child_nodes() as $child){
|
||||
$res = $this->storeXMLNode($child, $id, $mode);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2: // attribute
|
||||
$res = $this->storeRecord(
|
||||
$subjns, $subject, $prefix, $node->node_name(),
|
||||
'A', '_L', $node->value(), $mode
|
||||
);
|
||||
if(PEAR::isError($res)) return $res;
|
||||
break;
|
||||
case 3: // text
|
||||
case 4: // cdata
|
||||
# echo"T\n";
|
||||
if($node->is_blank_node()) break;
|
||||
$objns_sql = "'_L'";
|
||||
$object_sql = "coalesce(object,'')||'".$node->node_value()."'";
|
||||
$res = $this->dbc->query("
|
||||
UPDATE {$this->mdataTable}
|
||||
SET objns=$objns_sql, object=$object_sql
|
||||
WHERE id='$parid'
|
||||
");
|
||||
if(PEAR::isError($res)) return $res;
|
||||
break;
|
||||
case"5": case"6": case"7": case"8":
|
||||
break;
|
||||
default:
|
||||
return PEAR::raiseError(
|
||||
"MetaData::storeXMLNode: unsupported node type (".
|
||||
$node->node_type().")"
|
||||
);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update object namespace and value of one metadata record
|
||||
* identified by metadata record 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
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function updateRecord($mdid, $object, $objns='_L')
|
||||
{
|
||||
$res = $this->dbc->query("UPDATE {$this->mdataTable}
|
||||
SET objns = '$objns', object = '$object'
|
||||
WHERE gunid = '{$this->gunid}' AND id='$mdid'
|
||||
");
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert or update of one metadata record completely
|
||||
*
|
||||
* @param subjns string, subject namespace prefix, have to be defined
|
||||
* in file's metadata (or reserved prefix)
|
||||
* @param subject string, subject value, e.g. gunid
|
||||
* @param predns string, predicate namespace prefix, have to be defined
|
||||
* in file's metadata (or reserved prefix)
|
||||
* @param predicate string, predicate value, e.g. name of DC element
|
||||
* @param predxml string 'T'|'A' - XML tag or attribute
|
||||
* @param objns string, object namespace prefix, have to be defined
|
||||
* in file's metadata (or reserved prefix)
|
||||
* @param object string, object value, e.g. title of song
|
||||
* @param mode 'insert'|'update'
|
||||
* @return int, new metadata record id
|
||||
*/
|
||||
function storeRecord($subjns, $subject, $predns, $predicate, $predxml='T',
|
||||
$objns=NULL, $object=NULL, $mode='insert')
|
||||
{
|
||||
$predns_sql = (is_null($predns) ? "NULL":"'$predns'" );
|
||||
$objns_sql = (is_null($objns) ? "NULL":"'$objns'" );
|
||||
$object_sql = (is_null($object)? "NULL":"'$object'");
|
||||
if($mode == 'insert'){
|
||||
$id = $this->dbc->nextId("{$this->mdataTable}_id_seq");
|
||||
}else{
|
||||
$cond = "gunid = '{$this->gunid}' AND predns=$predns_sql
|
||||
AND predicate='$predicate'";
|
||||
$id = $this->dbc->getOne("SELECT id FROM {$this->mdataTable}
|
||||
WHERE $cond");
|
||||
}
|
||||
if(PEAR::isError($id)) return $id;
|
||||
if($mode == 'insert'){
|
||||
$res = $this->dbc->query("
|
||||
INSERT INTO {$this->mdataTable}
|
||||
(id , gunid , subjns , subject ,
|
||||
predns , predicate , predxml ,
|
||||
objns , object
|
||||
)
|
||||
VALUES
|
||||
($id, '{$this->gunid}', '$subjns', '$subject',
|
||||
$predns_sql, '$predicate', '$predxml',
|
||||
$objns_sql, $object_sql
|
||||
)
|
||||
");
|
||||
}else{
|
||||
$res = $this->dbc->query("
|
||||
UPDATE {$this->mdataTable}
|
||||
SET subjns = '$subjns', subject = '$subject',
|
||||
objns = $objns_sql, object = $object_sql
|
||||
WHERE id='$id'
|
||||
");
|
||||
// WHERE $cond
|
||||
}
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return $id;
|
||||
}
|
||||
/**
|
||||
* Generate XML document from metadata database
|
||||
*
|
||||
* @return string with XML document
|
||||
*/
|
||||
function genXMLDoc()
|
||||
{
|
||||
$domd =& domxml_new_xmldoc('1.0');
|
||||
$row = $this->dbc->getRow("
|
||||
SELECT * FROM {$this->mdataTable}
|
||||
WHERE gunid='{$this->gunid}'
|
||||
AND subjns='_G' AND subject='{$this->gunid}'
|
||||
");
|
||||
if(PEAR::isError($row)) return $row;
|
||||
if(is_null($row)) return PEAR::raiseError(
|
||||
"MetaData::genXMLDoc: not exists ({$this->gunid})"
|
||||
);
|
||||
$rr = $this->genXMLNode(&$domd, &$domd, $row);
|
||||
if(PEAR::isError($rr)) return $rr;
|
||||
return preg_replace("|</([^>]*)>|", "</\\1>\n", $domd->dump_mem())."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate XML element from database
|
||||
*
|
||||
* @param domd DOM document object
|
||||
* @param xn DOM element object
|
||||
* @param row array, database row with values for created element
|
||||
* @return void
|
||||
*/
|
||||
function genXMLNode(&$domd, &$xn, $row)
|
||||
{
|
||||
if($row['predxml']=='T'){
|
||||
$nxn =& $domd->create_element($row['predicate']);
|
||||
}else{
|
||||
$nxn =& $domd->create_attribute($row['predicate'], '');
|
||||
}
|
||||
$xn->append_child(&$nxn);
|
||||
$uri = $this->dbc->getOne("
|
||||
SELECT object FROM {$this->mdataTable}
|
||||
WHERE gunid='{$this->gunid}' AND predicate='_namespace'
|
||||
AND subjns='_L' AND subject='{$row['predns']}'
|
||||
");
|
||||
if(!is_null($uri) && $uri !== ''){
|
||||
$root =& $domd->document_element();
|
||||
$root->add_namespace($uri, $row['predns']);
|
||||
if($row['predns'] !== ''){
|
||||
$nxn->set_namespace($uri, $row['predns']);
|
||||
}
|
||||
}
|
||||
if($row['object'] != 'NULL'){
|
||||
$tn =& $domd->create_text_node($row['object']);
|
||||
$nxn->append_child(&$tn);
|
||||
}
|
||||
$this->genXMLTree(&$domd, &$nxn, $row['id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate XML subtree from database
|
||||
*
|
||||
* @param domd DOM document object
|
||||
* @param xn DOM element object
|
||||
* @param parid parent id
|
||||
* @return void
|
||||
*/
|
||||
function genXMLTree(&$domd, &$xn, $parid)
|
||||
{
|
||||
$qh = $this->dbc->query("
|
||||
SELECT * FROM {$this->mdataTable}
|
||||
WHERE gunid='{$this->gunid}' AND subjns='_I' AND subject='$parid'
|
||||
ORDER BY id
|
||||
");
|
||||
if(PEAR::isError($qh)) return $qh;
|
||||
while($row = $qh->fetchRow()){
|
||||
$this->genXMLNode(&$domd, &$xn, $row);
|
||||
}
|
||||
$qh->free();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method
|
||||
*
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function test()
|
||||
{
|
||||
$res = $this->replace(getcwd().'/mdata2.xml');
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$res = $this->getMetaData();
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
?>
|
236
livesupport/modules/storageServer/var/RawMediaData.php
Normal file
236
livesupport/modules/storageServer/var/RawMediaData.php
Normal file
|
@ -0,0 +1,236 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/RawMediaData.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* RawMediaData class
|
||||
*
|
||||
* LiveSupport file storage support class
|
||||
* Store media files in real filesystem and handle access to them.<br>
|
||||
*
|
||||
* @see StoredFile
|
||||
*/
|
||||
|
||||
/* ================== RawMediaData ================== */
|
||||
class RawMediaData{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param gunid string, global unique id
|
||||
* @param resDir string, directory
|
||||
* @return this
|
||||
*/
|
||||
function RawMediaData($gunid, $resDir)
|
||||
{
|
||||
$this->gunid = $gunid;
|
||||
$this->resDir = $resDir;
|
||||
$this->fname = $this->makeFname();
|
||||
$this->exists = file_exists($this->fname);
|
||||
}
|
||||
/**
|
||||
* Insert media file to filesystem
|
||||
*
|
||||
* @param mediaFileLP string, local path
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function insert($mediaFileLP)
|
||||
{
|
||||
if($this->exists) return FALSE;
|
||||
@umask(0002);
|
||||
if(@copy($mediaFileLP, $this->fname)){
|
||||
// @chmod($this->fname, 0775);
|
||||
$this->exists = TRUE;
|
||||
return TRUE;
|
||||
}else{
|
||||
@unlink($this->fname);
|
||||
$this->exists = FALSE;
|
||||
return PEAR::raiseError(
|
||||
"RawMediaData::insert: file save failed", GBERR_FILEIO
|
||||
);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Delete and insert media file
|
||||
*
|
||||
* @param mediaFileLP string, local path
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function replace($mediaFileLP)
|
||||
{
|
||||
if($this->exists) $r = $this->delete();
|
||||
if(PEAR::isError($r)) return $r;
|
||||
return $this->insert($mediaFileLP);
|
||||
}
|
||||
/**
|
||||
* Return true if file corresponding to the object exists
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function exists()
|
||||
{
|
||||
return $this->exists;
|
||||
}
|
||||
/**
|
||||
* Return filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getFname()
|
||||
{
|
||||
return $this->fname;
|
||||
}
|
||||
/**
|
||||
* Make access symlink to the media file
|
||||
*
|
||||
* @param accLinkName string, access symlink name
|
||||
* @return string, access symlink name
|
||||
*/
|
||||
function access($accLinkName)
|
||||
{
|
||||
if(!$this->exists) return FALSE;
|
||||
if(file_exists($accLinkName)) return $accLinkName;
|
||||
if(@symlink($this->fname, $accLinkName)){
|
||||
// @chmod($accLinkName, 0775);
|
||||
return $accLinkName;
|
||||
}else return PEAR::raiseError(
|
||||
"RawMediaData::access: symlink create failed ($accLinkName)",
|
||||
GBERR_FILEIO
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Delete access symlink
|
||||
*
|
||||
* @param accLinkName string, access symlink name
|
||||
* @return boolean or PEAR::error
|
||||
*/
|
||||
function release($accLinkName)
|
||||
{
|
||||
if(!$this->exists) return FALSE;
|
||||
if(@unlink($accLinkName)) return TRUE;
|
||||
else return PEAR::raiseError(
|
||||
"RawMediaData::release: symlink unlink failed", GBERR_FILEIO
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Delete media file from filesystem
|
||||
*
|
||||
* @return boolean or PEAR::error
|
||||
*/
|
||||
function delete()
|
||||
{
|
||||
if(!$this->exists) return FALSE;
|
||||
if(@unlink($this->fname)){
|
||||
$this->exists = FALSE;
|
||||
return TRUE;
|
||||
}else{
|
||||
return PEAR::raiseError(
|
||||
"RawMediaData::delete: unlink failed ({$this->fname})",
|
||||
GBERR_FILEIO
|
||||
);
|
||||
}
|
||||
return $this->exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze media file with getid3 module
|
||||
*
|
||||
* @return hierarchical hasharray with information about media file
|
||||
*/
|
||||
function analyze()
|
||||
{
|
||||
if(!$this->exists) return FALSE;
|
||||
$ia = GetAllFileinfo($this->fname);
|
||||
return $ia;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mime-type returned by getid3 module
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getMime()
|
||||
{
|
||||
$a = $this->analyze();
|
||||
if($a === FALSE) return $a;
|
||||
return $a['mime_type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Contruct filepath of media file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function makeFname()
|
||||
{
|
||||
return "{$this->resDir}/{$this->gunid}";
|
||||
}
|
||||
/**
|
||||
* Test method
|
||||
*
|
||||
* @param testFname1 string
|
||||
* @param testFname2 string
|
||||
* @param accLinkFname string
|
||||
* @return string
|
||||
*/
|
||||
function test($testFname1, $testFname2, $accLinkFname)
|
||||
{
|
||||
$log = '';
|
||||
if($this->exists())
|
||||
$log .= "---: exists: YES\n";
|
||||
else
|
||||
$log .= "---: exists: NO\n";
|
||||
if(!($r = $this->delete()))
|
||||
$log .= "---: delete: nothing to delete\n";
|
||||
if(PEAR::isError($r))
|
||||
$log .= "ERR: ".$r->getMessage()."\n";
|
||||
if($r = $this->insert($testFname1))
|
||||
$log .= "---: insert: already exists\n";
|
||||
if(PEAR::isError($r))
|
||||
$log .= "ERR: ".$r->getMessage()."\n";
|
||||
if($r = $this->replace($testFname2))
|
||||
$log .= "---: replace: already exists\n";
|
||||
if(PEAR::isError($r))
|
||||
$log .= "ERR: ".$r->getMessage()."\n";
|
||||
if($this->exists())
|
||||
$log .= "---: exists: YES\n";
|
||||
else
|
||||
$log .= "---: exists: NO\n";
|
||||
if(!$this->access($accLinkFname))
|
||||
$log .= "---: access: not exists\n";
|
||||
if(($ft = filetype($accLinkFname)) == 'link'){
|
||||
if(($rl = readlink($accLinkFname)) != $this->fname)
|
||||
$log .= "ERR: wrong target ($rl)\n";
|
||||
}else
|
||||
$log .= "ERR: wrong file type ($ft)\n";
|
||||
if(!$this->release($accLinkFname))
|
||||
$log .= "---: access: not exists\n";
|
||||
return $log;
|
||||
}
|
||||
}
|
||||
?>
|
504
livesupport/modules/storageServer/var/StoredFile.php
Normal file
504
livesupport/modules/storageServer/var/StoredFile.php
Normal file
|
@ -0,0 +1,504 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/StoredFile.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
require_once '../RawMediaData.php';
|
||||
require_once '../MetaData.php';
|
||||
require_once '../../../getid3/var/getid3.php';
|
||||
|
||||
/**
|
||||
* StoredFile class
|
||||
*
|
||||
* LiveSupport file storage support class.<br>
|
||||
* Represents one virtual file in storage. Virtual file has up to two parts:
|
||||
* <ul>
|
||||
* <li>metada in database - represeted by MetaData class</li>
|
||||
* <li>binary media data in real file
|
||||
* - represented by RawMediaData class</li>
|
||||
* </ul>
|
||||
* @see GreenBox
|
||||
* @see MetaData
|
||||
* @see RawMediaData
|
||||
*/
|
||||
class StoredFile{
|
||||
/* ========================================================== constructor */
|
||||
/**
|
||||
* Constructor, but shouldn't be externally called
|
||||
*
|
||||
* @param gb reference to GreenBox object
|
||||
* @param gunid string, optional, globally unique id of file
|
||||
* @return this
|
||||
*/
|
||||
function StoredFile(&$gb, $gunid=NULL)
|
||||
{
|
||||
$this->gb =& $gb;
|
||||
$this->dbc =& $gb->dbc;
|
||||
$this->filesTable = $gb->filesTable;
|
||||
$this->accessTable= $gb->accessTable;
|
||||
$this->gunid = $gunid;
|
||||
if(is_null($this->gunid)) $this->gunid = $this->_createGunid();
|
||||
$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);
|
||||
return $this->gunid;
|
||||
}
|
||||
/* ========= 'factory' methods - should be called to construct StoredFile */
|
||||
/**
|
||||
* Create instace of StoreFile object and insert new file
|
||||
*
|
||||
* @param gb reference to GreenBox object
|
||||
* @param oid int, local object id in the tree
|
||||
* @param name string, name of new file
|
||||
* @param mediaFileLP string, local path to media file
|
||||
* @param mdataFileLP string, local path to metadata XML file
|
||||
* @return instace of StoredFile object
|
||||
*/
|
||||
function insert(&$gb, $oid, $name, $mediaFileLP='', $mdataFileLP='')
|
||||
{
|
||||
$ac =& new StoredFile(&$gb);
|
||||
$ac->name = $name;
|
||||
$ac->id = $oid;
|
||||
$ac->type = "unKnown";
|
||||
if($ac->name=='') $ac->name=$ac->gunid;
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $ac->dbc->query("INSERT INTO {$ac->filesTable}
|
||||
(id, name, gunid, type)
|
||||
VALUES
|
||||
('$oid', '{$ac->name}', '{$ac->gunid}', '{$ac->type}')"
|
||||
);
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
if($mdataFileLP != ''){
|
||||
$res = $ac->md->insert($mdataFileLP);
|
||||
if(PEAR::isError($res)){
|
||||
$this->dbc->query("ROLLBACK"); return $res;
|
||||
}
|
||||
}
|
||||
if($mediaFileLP != ''){
|
||||
$res = $ac->rmd->insert($mediaFileLP);
|
||||
if(PEAR::isError($res)){
|
||||
$this->dbc->query("ROLLBACK"); return $res;
|
||||
}
|
||||
$mime = $ac->rmd->getMime();
|
||||
// return PEAR::raiseError("X1");
|
||||
// $gb->debugLog("gunid={$ac->gunid}, mime=$mime");
|
||||
if($mime !== FALSE){
|
||||
$res = $ac->dbc->query("UPDATE {$ac->filesTable}
|
||||
SET type='$mime' WHERE id='$oid'");
|
||||
if(PEAR::isError($res)){
|
||||
$ac->dbc->query("ROLLBACK"); return $res;
|
||||
}
|
||||
}
|
||||
}
|
||||
$res = $this->dbc->query("COMMIT");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
return $ac;
|
||||
}
|
||||
/**
|
||||
* Create instace of StoreFile object and recall existing file.<br>
|
||||
* Should be supplied oid XOR gunid - not both ;)
|
||||
*
|
||||
* @param gb reference to GreenBox object
|
||||
* @param oid int, optional, local object id in the tree
|
||||
* @param gunid string, optional, global unique id of file
|
||||
* @return instace of StoredFile object
|
||||
*/
|
||||
function recall(&$gb, $oid='', $gunid='')
|
||||
{
|
||||
$cond = ($gunid=='' ? "id='$oid'" : "gunid='$gunid'" );
|
||||
$row = $gb->dbc->getRow("SELECT id, gunid, type, name
|
||||
FROM {$gb->filesTable} WHERE $cond");
|
||||
if(PEAR::isError($row)) return $row;
|
||||
if(is_null($row)){
|
||||
return PEAR::raiseError(
|
||||
"StoredFile::recall: fileobj not exist", GBERR_FOBJNEX);
|
||||
}
|
||||
$ac =& new StoredFile(&$gb, $row['gunid']);
|
||||
$ac->type = $row['type'];
|
||||
$ac->name = $row['name'];
|
||||
$ac->id = $row['id'];
|
||||
return $ac;
|
||||
}
|
||||
/**
|
||||
* Create instace of StoreFile object and recall existing file from tmpLink
|
||||
*
|
||||
* @param gb reference to GreenBox object
|
||||
* @param tmpLink string
|
||||
* @param sessid string
|
||||
*/
|
||||
function recallFromLink(&$gb, $tmpLink, $sessid)
|
||||
{
|
||||
$gunid = $gb->dbc->getOne("SELECT gunid FROM {$gb->accessTable}
|
||||
WHERE tmpLink='$tmpLink' AND sessid='$sessid'");
|
||||
if(PEAR::isError($gunid)) return $gunid;
|
||||
if(is_null($gunid)) return PEAR::raiseError(
|
||||
"StoredFile::recallFromLink: accessobj not exist", GBERR_AOBJNEX);
|
||||
return StoredFile::recall(&$gb, '', $gunid);
|
||||
}
|
||||
/**
|
||||
* Create instace of StoreFile object and make copy of existing file
|
||||
*
|
||||
* @param src reference to source object
|
||||
* @param nid int, new local id
|
||||
*/
|
||||
function copyOf(&$src, $nid)
|
||||
{
|
||||
$ac =& StoredFile::insert(&$src->gb, $nid, $src->name, $src->_getRealRADFname(), '');
|
||||
if(PEAR::isError($ac)) return $ac;
|
||||
$ac->md->replace($src->md->getMetaData(), 'xml');
|
||||
return $ac;
|
||||
}
|
||||
|
||||
/* ======================================================= public methods */
|
||||
/**
|
||||
* Replace existing file with new data
|
||||
*
|
||||
* @param oid int, local id
|
||||
* @param name string, name of file
|
||||
* @param mediaFileLP string, local path to media file
|
||||
* @param mdataFileLP string, local path to metadata XML file or XML string
|
||||
* @param mdataLoc string 'file'|'string'
|
||||
*/
|
||||
function replace($oid, $name, $mediaFileLP='', $mdataFileLP='',
|
||||
$mdataLoc='file')
|
||||
{
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $this->dbc->query("UPDATE {$this->filesTable}
|
||||
SET name='$name', type='{$this->type}' WHERE id='$oid'");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
if($mediaFileLP != ''){
|
||||
$res = $this->rmd->replace($mediaFileLP, $this->type);
|
||||
if(PEAR::isError($res)){
|
||||
$this->dbc->query("ROLLBACK"); return $res;
|
||||
}
|
||||
$mime = $this->rmd->getMime();
|
||||
if($mime !== FALSE){
|
||||
$res = $this->dbc->query("UPDATE {$this->filesTable}
|
||||
SET type='$mime' WHERE id='$oid'");
|
||||
if(PEAR::isError($res)){
|
||||
$this->dbc->query("ROLLBACK"); return $res;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($mdataFileLP != ''){
|
||||
$res = $this->md->replace($mdataFileLP, $mdataLoc);
|
||||
if(PEAR::isError($res)){
|
||||
$this->dbc->query("ROLLBACK"); return $res;
|
||||
}
|
||||
}
|
||||
$res = $this->dbc->query("COMMIT");
|
||||
if(PEAR::isError($res)){
|
||||
$this->dbc->query("ROLLBACK"); return $res;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
/**
|
||||
* Increase access counter, create access record,
|
||||
* call access method of RawMediaData
|
||||
*
|
||||
* @param sessid string
|
||||
*/
|
||||
function accessRawMediaData($sessid)
|
||||
{
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $this->dbc->query("UPDATE {$this->filesTable}
|
||||
SET currentlyaccessing=currentlyaccessing+1
|
||||
WHERE gunid='{$this->gunid}'");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$accLinkName = $this->_getAccessFname($sessid, $this->_getExt());
|
||||
$res = $this->dbc->query("INSERT INTO {$this->accessTable}
|
||||
(gunid, sessid, tmplink, ts)
|
||||
VALUES
|
||||
('{$this->gunid}', '$sessid', '$accLinkName', now())");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$acc = $this->rmd->access($accLinkName);
|
||||
if(PEAR::isError($acc)){ $this->dbc->query("ROLLBACK"); return $acc; }
|
||||
if($acc === FALSE){
|
||||
$this->dbc->query("ROLLBACK");
|
||||
return PEAR::raiseError(
|
||||
'StoredFile::accessRawMediaData: not exists'
|
||||
);
|
||||
}
|
||||
$res = $this->dbc->query("COMMIT");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
return $acc;
|
||||
}
|
||||
/**
|
||||
* Decrease access couter, delete access record,
|
||||
* call release method of RawMediaData
|
||||
*
|
||||
* @param sessid string
|
||||
*/
|
||||
function releaseRawMediaData($sessid)
|
||||
{
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $this->dbc->query("UPDATE {$this->filesTable}
|
||||
SET currentlyaccessing=currentlyaccessing-1
|
||||
WHERE gunid='{$this->gunid}' AND currentlyaccessing>0"
|
||||
);
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$ca = $this->dbc->getOne("SELECT currentlyaccessing
|
||||
FROM {$this->filesTable}
|
||||
WHERE gunid='{$this->gunid}'"
|
||||
);
|
||||
if(PEAR::isError($ca)){ $this->dbc->query("ROLLBACK"); return $ca; }
|
||||
$accLinkName = $this->_getAccessFname($sessid, $this->_getExt());
|
||||
$res = $this->dbc->query("DELETE FROM {$this->accessTable}
|
||||
WHERE gunid='{$this->gunid}' AND sessid='$sessid'
|
||||
AND tmplink='$accLinkName'");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
$res = $this->dbc->query("COMMIT");
|
||||
if(PEAR::isError($res)){ $this->dbc->query("ROLLBACK"); return $res; }
|
||||
if(intval($ca)==0) return $this->rmd->release($accLinkName);
|
||||
return TRUE;
|
||||
}
|
||||
/**
|
||||
* Replace metadata with new XML file
|
||||
*
|
||||
* @param mdataFileLP string, local path to metadata XML file or XML string
|
||||
* @param mdataLoc string 'file'|'string'
|
||||
*/
|
||||
function replaceMetaData($mdataFileLP, $mdataLoc='file')
|
||||
{
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $this->md->replace($mdataFileLP, $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 metadata with new XML file
|
||||
*
|
||||
* @param mdataFileLP string, local path to metadata XML file or XML string
|
||||
* @param mdataLoc string 'file'|'string'
|
||||
* @return boolean or PEAR::error
|
||||
*/
|
||||
function updateMetaData($mdataFileLP, $mdataLoc='file')
|
||||
{
|
||||
$this->dbc->query("BEGIN");
|
||||
$res = $this->md->update($mdataFileLP, $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
|
||||
*
|
||||
* @return XML string
|
||||
* @see MetaData
|
||||
*/
|
||||
function getMetaData()
|
||||
{
|
||||
return $this->md->getMetaData();
|
||||
}
|
||||
/**
|
||||
* Analyze file with getid3 module.<br>
|
||||
* Obtain some metadata stored in media file.<br>
|
||||
* This method should be used for prefilling metadata input form.
|
||||
*
|
||||
* @return array
|
||||
* @see MetaData
|
||||
*/
|
||||
function analyzeMediaFile()
|
||||
{
|
||||
$ia = $this->rmd->analyze();
|
||||
return $ia;
|
||||
}
|
||||
/**
|
||||
* Rename stored virtual file
|
||||
*
|
||||
* @param newname string
|
||||
* @return true or PEAR::error
|
||||
*/
|
||||
function rename($newname)
|
||||
{
|
||||
$res = $this->dbc->query("UPDATE {$this->filesTable} SET name='$newname'
|
||||
WHERE gunid='{$this->gunid}'");
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
/**
|
||||
* Delete stored virtual file
|
||||
*
|
||||
* @see RawMediaData
|
||||
* @see MetaData
|
||||
*/
|
||||
function delete()
|
||||
{
|
||||
$res = $this->rmd->delete();
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$res = $this->md->delete();
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$links = $this->dbc->getAll("SELECT tmplink FROM {$this->accessTable}
|
||||
WHERE gunid='{$this->gunid}'");
|
||||
if(is_array($links)) foreach($links as $i=>$item){
|
||||
@unlink($item['tmplink']);
|
||||
}
|
||||
$res = $this->dbc->query("DELETE FROM {$this->accessTable}
|
||||
WHERE gunid='{$this->gunid}'");
|
||||
if(PEAR::isError($res)) return $res;
|
||||
$res = $this->dbc->query("DELETE FROM {$this->filesTable}
|
||||
WHERE gunid='{$this->gunid}'");
|
||||
if(PEAR::isError($res)) return $res;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if virtual file is accessed.<br>
|
||||
* Static or dynamic call is possible.
|
||||
*
|
||||
* @param gunid string, optional (for static call), global unique id
|
||||
*/
|
||||
function isAccessed($gunid=NULL)
|
||||
{
|
||||
if(is_null($gunid)) $gunid = $this->gunid;
|
||||
return (0 < $this->dbc->getOne("
|
||||
SELECT currentlyAccessing FROM {$this->filesTable}
|
||||
WHERE gunid='$gunid'
|
||||
"));
|
||||
}
|
||||
/**
|
||||
* Returns local id of virtual file
|
||||
*
|
||||
*/
|
||||
function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
/**
|
||||
* Returns true if raw media file exists
|
||||
*
|
||||
*/
|
||||
function exists()
|
||||
{
|
||||
$indb = $this->dbc->getRow("SELECT gunid FROM {$this->filesTable}
|
||||
WHERE gunid='{$this->gunid}'");
|
||||
return (!is_null($indb) && $this->rmd->exists());
|
||||
}
|
||||
|
||||
/* ==================================================== "private" methods */
|
||||
/**
|
||||
* Create new global unique id
|
||||
*
|
||||
*/
|
||||
function _createGunid()
|
||||
{
|
||||
return md5(microtime().$_SERVER['SERVER_ADDR'].rand().
|
||||
"org.mdlf.livesupport");
|
||||
}
|
||||
/**
|
||||
* Get local id from global id.
|
||||
* Static or dynamic call is possible.
|
||||
*
|
||||
* @param gunid string, optional (for static call),
|
||||
* global unique id of file
|
||||
*/
|
||||
function _idFromGunid($gunid=NULL)
|
||||
{
|
||||
if(is_null($gunid)) $gunid = $this->$gunid;
|
||||
$id = $this->dbc->getOne("SELECT id FROM {$this->filesTable}
|
||||
WHERE gunid='$gunid'");
|
||||
if(is_null($id)) return PEAR::raiseError(
|
||||
"StoredFile::_idFromGunid: no such global unique id ($gunid)"
|
||||
);
|
||||
return $id;
|
||||
}
|
||||
/**
|
||||
* Return suitable extension.<br>
|
||||
* <b>TODO: make it general - is any tool for it?</b>
|
||||
*
|
||||
* @return string file extension without a dot
|
||||
*/
|
||||
function _getExt()
|
||||
{
|
||||
switch($this->type){
|
||||
case"audio/mpeg": $ext="mp3"; break;
|
||||
case"audio/x-wave": $ext="wav"; break;
|
||||
case"application/x-ogg": $ext="ogg"; break;
|
||||
default: $ext="bin"; break;
|
||||
}
|
||||
return $ext;
|
||||
}
|
||||
/**
|
||||
* Get filetype from global id
|
||||
*
|
||||
* @param gunid string, optional, global unique id of file
|
||||
*/
|
||||
function _getType($gunid)
|
||||
{
|
||||
return $this->dbc->getOne("SELECT type FROM {$this->filesTable}
|
||||
WHERE gunid='$gunid'");
|
||||
}
|
||||
/**
|
||||
* Get and optionaly create subdirectory in real filesystem for storing
|
||||
* raw media data
|
||||
*
|
||||
*/
|
||||
function _getResDir()
|
||||
{
|
||||
$resDir="{$this->gb->storageDir}/".substr($this->gunid, 0, 3);
|
||||
if(!file_exists($resDir)){ mkdir($resDir, 02775); }
|
||||
return $resDir;
|
||||
}
|
||||
/**
|
||||
* Get real filename of raw media data
|
||||
*
|
||||
* @see RawMediaData
|
||||
*/
|
||||
function _getRealRADFname()
|
||||
{
|
||||
return $this->rmd->getFname();
|
||||
}
|
||||
/**
|
||||
* Create and return name for temporary symlink.<br>
|
||||
* <b>TODO: Should be more unique</b>
|
||||
*
|
||||
*/
|
||||
function _getAccessFname($sessid, $ext='EXT')
|
||||
{
|
||||
$spart = md5("{$sessid}_{$this->gunid}");
|
||||
return "{$this->accessDir}/$spart.$ext";
|
||||
}
|
||||
}
|
||||
?>
|
63
livesupport/modules/storageServer/var/conf.php
Normal file
63
livesupport/modules/storageServer/var/conf.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/conf.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
$config = array(
|
||||
'dsn' => array(
|
||||
'username' => 'test',
|
||||
'password' => 'test',
|
||||
'hostspec' => 'localhost',
|
||||
# 'hostspec' => '127.0.0.1', // for bad resolver
|
||||
'phptype' => 'pgsql',
|
||||
'database' => 'LiveSupport-test',
|
||||
),
|
||||
'tblNamePrefix' => 'gb_',
|
||||
'authCookieName'=> 'gbsid',
|
||||
'RootNode' => 'RootNode',
|
||||
'tmpRootPass' => 'q',
|
||||
'objtypes' => array(
|
||||
'RootNode' => array('Folder'),
|
||||
'Storage' => array('Folder', 'File', 'Replica'),
|
||||
'Folder' => array('Folder', 'File', 'Replica'),
|
||||
'File' => array(),
|
||||
'Replica' => array(),
|
||||
),
|
||||
'allowedActions'=> array(
|
||||
'RootNode' => array('classes', 'subjects'),
|
||||
'Folder' => array('editPrivs', 'write', 'read'),
|
||||
'File' => array('editPrivs', 'write', 'read'),
|
||||
'Replica' => array('editPrivs', 'write', 'read'),
|
||||
'_class' => array('editPrivs', 'write', 'read'),
|
||||
),
|
||||
'allActions' => array(
|
||||
'editPrivs', 'write', 'read', 'classes', 'subjects'
|
||||
),
|
||||
'storageDir' => dirname(getcwd()).'/stor',
|
||||
'accessDir' => dirname(getcwd()).'/access',
|
||||
);
|
||||
?>
|
19
livesupport/modules/storageServer/var/html/default.css
Normal file
19
livesupport/modules/storageServer/var/html/default.css
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!--
|
||||
/*body { font-family:'Arial CE', 'Helvetica CE', Arial, helvetica, sans-serif; background-color:#eee; }*/
|
||||
body { font-family:sans-serif; background-color:#eee; }
|
||||
h1 { border:0px solid black; margin-bottom:2px; font-size:x-large; }
|
||||
h2 { border:0px solid black; margin-bottom:2px; margin-top:2px; font-size:large; }
|
||||
h3 { border:0px solid black; margin-bottom:1ex; margin-top:2px; font-size:medium; font-weight:bold; }
|
||||
table { border-collapse:collapse; margin:1ex 0px; }
|
||||
tr.odd { background-color:#ccc; }
|
||||
tr.ev { background-color:#aaa; }
|
||||
td { border:0px solid black; padding:2px 1em; }
|
||||
pre { border:solid black; border-width:1px 0px; padding:1em 1px;}
|
||||
.b { font-weight:bold; }
|
||||
.slash { padding:0px 0px; }
|
||||
.lnkbutt { padding:0px 4px; font-weigt:bolder; }
|
||||
.hidden { display:none; }
|
||||
.button { border:1px outset; background-color:#eee; padding:0px 4px; }
|
||||
.button:hover { background-color:#fff; }
|
||||
.button:active { border:1px inset; }
|
||||
-->
|
245
livesupport/modules/storageServer/var/html/gbHtmlBrowse.php
Normal file
245
livesupport/modules/storageServer/var/html/gbHtmlBrowse.php
Normal file
|
@ -0,0 +1,245 @@
|
|||
<?
|
||||
#echo"<pre>\n"; print_r($_FILES); print_r($_REQUEST); print_r($_SERVER); exit;
|
||||
require_once"gbHtml_h.php";
|
||||
require_once"gbHtmlTestAuth.php";
|
||||
|
||||
$fldsname=array('author'=>'Author', 'title'=>'Title', 'creator'=>'Creator',
|
||||
'description'=>'Description', 'subject'=>'Subject', 'genre'=>'Genre');
|
||||
|
||||
$sessid = $_REQUEST[$config['authCookieName']];
|
||||
$userid = $gb->getSessUserId($sessid);
|
||||
$login = $gb->getSessLogin($sessid);
|
||||
|
||||
#$path = ($_REQUEST['path']=='' ? '/' : $_REQUEST['path']);
|
||||
$id = (!$_REQUEST['id'] ? $gb->storId : $_REQUEST['id']);
|
||||
|
||||
#echo"<pre>\nsessid=$sessid\nuserid=$userid\nlogin=$login\n"; exit;
|
||||
|
||||
$tpldata = array(
|
||||
'msg' => $_SESSION['alertMsg'],
|
||||
'loggedAs' => $login,
|
||||
'id' => $id,
|
||||
); unset($_SESSION['alertMsg']);
|
||||
|
||||
switch($_REQUEST['act']){
|
||||
case"getHomeDir":
|
||||
$id = $gb->getObjId($login, $gb->storId);
|
||||
$tpldata['id'] = $id;
|
||||
default:
|
||||
# echo"<pre>\n$path\n$upath<hr>\n"; print_r($_FILES); print_r($_REQUEST); exit;
|
||||
$tpldata=array_merge($tpldata, array(
|
||||
'pathdata' => $gb->getPath($id, $sessid),
|
||||
'listdata' => ($gb->getObjType($id)=='Folder'?
|
||||
$gb->listFolder($id, $sessid):array()
|
||||
),
|
||||
'tree' => ($_REQUEST['tree']=='Y'),
|
||||
'showPath' => true,
|
||||
'showTree' => true,
|
||||
));
|
||||
if($_REQUEST['tree']=='Y'){
|
||||
$tpldata['treedata'] = $gb->getSubTree($id, $sessid);
|
||||
}
|
||||
break;
|
||||
case"newfile":
|
||||
$tpldata=array(
|
||||
'pathdata' => $gb->getPath($id, $sessid),
|
||||
'showEdit' => true,
|
||||
'id' => $id,
|
||||
);
|
||||
break;
|
||||
case"sform":
|
||||
$tpldata=array(
|
||||
# 'pathdata' => $gb->getPath($path, $sessid),
|
||||
'showSForm' => true,
|
||||
'id' => $id,
|
||||
);
|
||||
break;
|
||||
case"search":
|
||||
$tpldata=array(
|
||||
# 'pathdata' => $gb->getPath($path, $sessid),
|
||||
'search' => $gb->localSearch($_REQUEST['srch'], $sessid),
|
||||
'showSRes' => true,
|
||||
'id' => $id,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
if(PEAR::isError($tpldata['listdata'])){
|
||||
$tpldata['msg'] = $tpldata['listdata']->getMessage();
|
||||
$tpldata['listdata'] = array();
|
||||
}
|
||||
#echo"<pre>\n$path<hr>\n"; print_r($tpldata['pathdata']); print_r($tpldata); exit;
|
||||
|
||||
$tpldata['showMenu']=true;
|
||||
|
||||
|
||||
// =================== template: ===================
|
||||
|
||||
?>
|
||||
<html><head>
|
||||
<title>Browser</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="default.css">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
#rmenu { float:right; margin-right:1em; border:1px solid black; background-color:#ddd; padding:2px 1ex; }
|
||||
#parent, #parent a { background-color:#888; font-weight:bold; color:white; }
|
||||
#tree { width:50%; }
|
||||
-->
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
function frename(name, id){
|
||||
var s=document.getElementById('ID'+id);
|
||||
s.innerHTML='<form action="gbHttp.php" method="post" style="display:inline">'+
|
||||
'<input type="text" name="newname" value="'+name+'" size="12">'+
|
||||
'<input type="hidden" name="id" value="'+id+'">'+
|
||||
'<input type="hidden" name="act" value="rename">'+
|
||||
'</form>';
|
||||
}
|
||||
function fmove(id, relPath){
|
||||
var newPath=prompt('Destination folder:', relPath);
|
||||
if(newPath==null) return;
|
||||
location.href='gbHttp.php?id='+id+'&act=move&newPath='+newPath;
|
||||
}
|
||||
function fcopy(id, relPath){
|
||||
var newPath=prompt('Destination folder:', relPath);
|
||||
if(newPath==null) return;
|
||||
location.href='gbHttp.php?id='+id+'&act=copy&newPath='+newPath;
|
||||
}
|
||||
function freplicate(name, id){
|
||||
var np=prompt('Destination folder:', id);
|
||||
if(np==null) return;
|
||||
location.href='gbHttp.php?id='+id+'&act=repl&newparid='+np;
|
||||
}
|
||||
function newFolder(){
|
||||
var nn=prompt('New folder name:');
|
||||
if(nn==null) return;
|
||||
location.href='gbHttp.php?id=<?=$tpldata['id']?>&act=newFolder&newname='+nn;
|
||||
}
|
||||
-->
|
||||
</script>
|
||||
</head><body>
|
||||
<div id="rmenu">
|
||||
Logged as: <span class="b"><?php echo$tpldata['loggedAs']?></span><br>
|
||||
<a href="gbHttp.php?act=logout">logout</a><br>
|
||||
<a href="gbHtmlPerms.php?id=<?=$tpldata['id']?>">Permission editor</a><br>
|
||||
<a href="gbHtmlSubj.php">User/Group editor</a><br>
|
||||
</div>
|
||||
|
||||
<?if($tpldata['showMenu']){?>
|
||||
<h3>
|
||||
<a href="gbHtmlBrowse.php?act=getHomeDir" class="button">Home directory</a>
|
||||
<a href="gbHtmlBrowse.php?id=<?=$tpldata['id']?>&act=newfile" class="button"><span class="hidden">[</span>Upload new file<span class="hidden">]</span></a>
|
||||
<a href="javascript:newFolder()" class="button"><span class="hidden">[</span>Create new folder<span class="hidden">]</span></a>
|
||||
<a href="gbHtmlBrowse.php?id=<?=$tpldata['id']?>&act=sform" class="button"><span class="hidden">[</span>Search<span class="hidden">]</span></a>
|
||||
</h3>
|
||||
<?}?>
|
||||
|
||||
<?if($tpldata['showPath']){?>
|
||||
<h3>
|
||||
<a href="gbHtmlBrowse.php?id=<?=$tpldata['id']?>&tree=Y" class="button">Tree</a>
|
||||
<?foreach($tpldata['pathdata'] as $o){?>
|
||||
<a href="gbHtmlBrowse.php?id=<?=urlencode($o['id'])?>"><?=$o['name']?></a>
|
||||
<?if($o['type']=='Folder'){?><span class="slash b">/</span><?}?>
|
||||
<?}?>:
|
||||
<span style="padding-left:6em">
|
||||
<a href="gbHtmlPerms.php?id=<?=$id?>" class="button">permissions</a>
|
||||
</span>
|
||||
</h3>
|
||||
<?}?>
|
||||
|
||||
<?if($tpldata['showTree']) if($tpldata['tree']){?>
|
||||
<?foreach($tpldata['treedata'] as $o){?>
|
||||
<?=str_repeat(' ', ($tpldata['tree']?intval($o['level']):3)*2)?>
|
||||
<a href="gbHtmlBrowse.php?id=<?=$o['id']?>"><?=$o['name']?></a>
|
||||
<br>
|
||||
<?}?>
|
||||
<?}else{?>
|
||||
<table border="0">
|
||||
<?foreach($tpldata['listdata'] as $o){?>
|
||||
<tr><td valign="top">
|
||||
<?=str_repeat(' ', ($tpldata['tree']?intval($o['level']):3)*2)?><span id="ID<?=$o['id']?>"
|
||||
><a <?if($o['type']=='Folder'){?>href="gbHtmlBrowse.php?id=<?=$o['id']?>"<?}?>><?=$o['name']?></a
|
||||
></span>
|
||||
</td><td>
|
||||
<?$a=array('Folder'=>'D', 'File'=>'F', 'Replica'=>'R'); echo$a[$o['type']]?>
|
||||
<a href="javascript:frename('<?=$o['name']?>', '<?=$o['id']?>')" class="button">rename</a>
|
||||
<?/**/?>
|
||||
<a href="javascript:fmove('<?=$o['id']?>', '.')" class="button">move</a>
|
||||
<a href="javascript:fcopy('<?=$o['id']?>', '.')" class="button">copy</a>
|
||||
<a href="javascript:freplicate('<?=$o['name']?>', '<?=$o['id']?>')" class="button">replicate</a>
|
||||
<?/**/?>
|
||||
<a href="gbHtmlPerms.php?id=<?=$o['id']?>" class="button">permissions</a>
|
||||
<a href="gbHttp.php?act=delete&id=<?=$o['id']?>" class="button"
|
||||
onClick="return confirm('Delete object "<?=$o['name']?>"?')">DEL</a>
|
||||
<?if($o['type']=='File'){?>
|
||||
<a href="gbHttp.php?act=getFile&id=<?=$o['id']?>" class="button">Access</a>
|
||||
<a href="gbHttp.php?act=getInfo&id=<?=$o['id']?>" class="button">Analyze</a>
|
||||
<a href="gbHttp.php?act=getMdata&id=<?=$o['id']?>" class="button">MetaData</a>
|
||||
<?}?>
|
||||
<?if($o['type']=='Replica'){?>
|
||||
(-><?=$o['target']?>)
|
||||
<?}?>
|
||||
</td>
|
||||
</tr>
|
||||
<?} if(count($tpldata['listdata'])==0){?>
|
||||
<tr><td>No objects</td></tr>
|
||||
<?}?>
|
||||
</table>
|
||||
<?}?>
|
||||
|
||||
<?if($tpldata['showEdit']){?>
|
||||
<form method="post" enctype="multipart/form-data" action="gbHttp.php">
|
||||
<?#<form method="post" enctype="multipart/form-data" action="http://localhost:8000">?>
|
||||
<table>
|
||||
<tr><td>File name:</td><td><input type="text" name="filename" value=""></td></tr>
|
||||
<tr><td>Media file:</td><td><input type="file" name="mediafile"></td></tr>
|
||||
<tr><td>Metadata file:</td><td><input type="file" name="mdatafile"></td></tr>
|
||||
<?for($i=0; $i<0; $i++){?>
|
||||
<tr><td>
|
||||
<select name="elnames[<?=$i?>]">
|
||||
<?$ii=0?>
|
||||
<?foreach($fldsname as $fld=>$descr){?>
|
||||
<option value="<?=$fld?>"<?=($i==$ii++ ? ' selected' : '')?>><?=$descr?></option>
|
||||
<?}?>
|
||||
</select>
|
||||
</td><td><input type="text" name="elvals[<?=$i?>]" value=""></td></tr>
|
||||
<?}?>
|
||||
<tr><td colspan="2"><input type="submit" value="Send!"></td></tr>
|
||||
</table>
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="1048576">
|
||||
<input type="hidden" name="act" value="upload">
|
||||
<input type="hidden" name="id" value="<?=$tpldata['id']?>">
|
||||
</form>
|
||||
<?}?>
|
||||
|
||||
<?if($tpldata['showSForm']){?>
|
||||
<form method="post" action="gbHtmlBrowse.php">
|
||||
<table>
|
||||
<tr><td>Search string:</td><td><input type="text" name="srch" value=""></td></tr>
|
||||
<tr><td colspan="2"><input type="submit" value="Send!"></td></tr>
|
||||
</table>
|
||||
<input type="hidden" name="act" value="search">
|
||||
<input type="hidden" name="id" value="<?=$tpldata['id']?>">
|
||||
</form>
|
||||
<?}?>
|
||||
|
||||
<?if($tpldata['showSRes']){?>
|
||||
<ul>
|
||||
<? if(is_array($tpldata['search'])) foreach($tpldata['search'] as $k=>$v){?>
|
||||
<li><a href="gbHttp.php?act=getMdata&id=<?=$gb->_idFromGunid($v['gunid'])?>"><?=$v['gunid']?></a>
|
||||
<? }else{?>
|
||||
No items found
|
||||
<? }?>
|
||||
</ul>
|
||||
<?}?>
|
||||
|
||||
<?php if($tpldata['msg']){?>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
alert('<?php echo$tpldata['msg']?>');
|
||||
-->
|
||||
</script><noscript><?php echo$tpldata['msg']?></noscript>
|
||||
<?php }?>
|
||||
</body></html>
|
73
livesupport/modules/storageServer/var/html/gbHtmlLogin.php
Normal file
73
livesupport/modules/storageServer/var/html/gbHtmlLogin.php
Normal file
|
@ -0,0 +1,73 @@
|
|||
<?
|
||||
// $Id: gbHtmlLogin.php,v 1.1 2004/09/12 21:59:08 tomas Exp $
|
||||
require_once"gbHtml_h.php";
|
||||
|
||||
// prefill data structure for template
|
||||
$d = array(
|
||||
'users' => $gb->getSubjects(),
|
||||
'actions' => $gb->getAllActions(),
|
||||
'objects' => $gb->getAllObjects(),
|
||||
'msg' => $_SESSION['alertMsg']
|
||||
);
|
||||
unset($_SESSION['alertMsg']);
|
||||
|
||||
// forms prefill:
|
||||
if(is_array($_SESSION['lastPost'])) $d = array_merge($d, array(
|
||||
'lastSubj' => $_SESSION['lastPost']['subj'],
|
||||
'lastAction'=> $_SESSION['lastPost']['permAction'],
|
||||
'lastObj' => $_SESSION['lastPost']['obj']
|
||||
));
|
||||
unset($_SESSION['lastPost']);
|
||||
|
||||
#header("Content-type: text/plain"); print_r($d); exit;
|
||||
#require_once"gbHtml_f.php";
|
||||
// template follows:
|
||||
?>
|
||||
<html><head>
|
||||
<title>Storage - login</title>
|
||||
<link rel="stylesheet" type="text/css" href="default.css">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
#help { float:right; margin-right:1em; border:1px solid black; background-color:#ddd; padding:2px 1ex; }
|
||||
-->
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
function preloadLogin(u, p)
|
||||
{
|
||||
var f=document.getElementById('loginform');
|
||||
f.login.value=u;
|
||||
f.pass.value=p;
|
||||
f.submit();
|
||||
}
|
||||
-->
|
||||
</script>
|
||||
</head><body>
|
||||
|
||||
<div id="help">
|
||||
Test accounts/pass:
|
||||
<ul style="margin:1px 0px">
|
||||
<li><a href="javascript:preloadLogin('root', 'q')">root/q</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<h1>Storage - login</h1>
|
||||
|
||||
<form action="gbHttp.php" method="post" id="loginform">
|
||||
<table>
|
||||
<tr><td>Login:</td><td><input type="text" name="login"></td></tr>
|
||||
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
|
||||
<tr><td colspan="2"><input type="hidden" name="act" value="login">
|
||||
<input type="submit" value="Go!">
|
||||
</td></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
<?php if($d['msg']){ //error message printing: ?>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
alert('<?php echo$d['msg']?>');
|
||||
-->
|
||||
</script>
|
||||
<?php }?>
|
||||
<body></html>
|
111
livesupport/modules/storageServer/var/html/gbHtmlPerms.php
Normal file
111
livesupport/modules/storageServer/var/html/gbHtmlPerms.php
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
// $Id: gbHtmlPerms.php,v 1.1 2004/09/12 21:59:09 tomas Exp $
|
||||
require_once"gbHtml_h.php";
|
||||
require_once"gbHtmlTestAuth.php";
|
||||
|
||||
$userid = $gb->getSessUserId($_REQUEST[$config['authCookieName']]);
|
||||
$login = $gb->getSessLogin($_REQUEST[$config['authCookieName']]);
|
||||
|
||||
$id = (!$_REQUEST['id'] ? $gb->storId : $_REQUEST['id']);
|
||||
|
||||
#header("Content-type: text/plain"); print_r($_REQUEST); exit;
|
||||
#header("Content-type: text/plain"); echo $gb->dumpTree($id, ' ')."\n"; exit;
|
||||
|
||||
// prefill data structure for template
|
||||
$tpldata = array(
|
||||
'pathdata' => $gb->getPath($id),
|
||||
'perms' => $gb->getObjPerms($id),
|
||||
'actions' => $gb->getAllowedActions($gb->getObjType($id)),
|
||||
'subjects' => $gb->getSubjects(),
|
||||
'id' => $id,
|
||||
'loggedAs' => $login,
|
||||
);
|
||||
$tpldata['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']);
|
||||
|
||||
#header("Content-type: text/plain"); print_r($tpldata); exit;
|
||||
|
||||
|
||||
#require_once"gbHtml_f.php";
|
||||
// template follows:
|
||||
?>
|
||||
<html><head>
|
||||
<title>Storage - permission editor</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="default.css">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
#menu { float:right; margin-right:1em; border:1px solid black; background-color:#ddd; padding:2px 1ex; }
|
||||
#tbl { width:60%; }
|
||||
-->
|
||||
</style>
|
||||
</head><body>
|
||||
<div id="menu">
|
||||
Logged as: <span class="b"><?php echo$tpldata['loggedAs']?></span><br>
|
||||
<a href="gbHttp.php?act=logout">Logout</a><br>
|
||||
<?php if(is_array($tpldata['pathdata'])){?>
|
||||
<a href="gbHtmlBrowse.php?id=<?php echo$id?>">Browser</a><br>
|
||||
<?php }else{?>
|
||||
<a href="gbHtmlBrowse.php">Tree editor</a><br>
|
||||
<?php }?>
|
||||
<a href="gbHtmlSubj.php">User/Group editor</a><br>
|
||||
</div>
|
||||
|
||||
<h1>Permission editor</h1>
|
||||
<?php if(is_array($tpldata['pathdata'])){?>
|
||||
<h2><a href="gbHtmlBrowse.php?id=<?=$id?>" title="Tree editor">Path</a>:
|
||||
<?php foreach($tpldata['pathdata'] as $k=>$it) {?>
|
||||
<?php echo$it["name"]?></a><span class="slash">/</span>
|
||||
<?php }?>
|
||||
<?php }?>
|
||||
</h2>
|
||||
|
||||
<table id="tbl" border="0" cellpadding="5">
|
||||
<tr><td>subject name</td><td>action</td><td>permission</td><td></td></tr>
|
||||
<?php if(is_array($tpldata['perms'])&&count($tpldata['perms'])>0) foreach($tpldata['perms'] as $k=>$row) {
|
||||
$da=($row['type']=='A' ? 'allow' : ($row['type']=='D' ? '<b>deny</b>' : $row['type']));?>
|
||||
<tr class="<?php echo(($o=1-$o) ? 'odd' : 'ev')?>">
|
||||
<td class="b"><a <?#href="alibExPList.php?id=<?php echo$row['subj']? >"?>><?php echo$row['login']?></a></td>
|
||||
<td class="b"><?php echo$row['action']?></td>
|
||||
<td><?php echo$da?></td>
|
||||
<td>
|
||||
<a href="gbHttp.php?act=removePerm&permid=<?php echo$row['permid']?>&oid=<?php echo$tpldata['id']?>&id=<?php echo$id?>"
|
||||
class="lnkbutt" onClick="return confirm('Delete permission "<?=$da?> <?=$row['action']?>" for user <?php echo$row['login']?>?')">remove</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php }else{?>
|
||||
<tr class="odd"><td colspan="4">none</td></tr>
|
||||
<?php }?>
|
||||
</table>
|
||||
|
||||
<form action="gbHttp.php" method="post">
|
||||
Add permission
|
||||
<select name="allowDeny">
|
||||
<option value="A">Allow</option>
|
||||
<option value="D">Deny</option>
|
||||
</select>
|
||||
for action
|
||||
<select name="permAction">
|
||||
<option value="_all">all</option>
|
||||
<?php if(is_array($tpldata['actions'])) foreach($tpldata['actions'] as $k=>$it) {?>
|
||||
<option value="<?php echo$it?>"><?php echo$it?></option>
|
||||
<?}?>
|
||||
</select>
|
||||
to subject
|
||||
<select name="subj">
|
||||
<?php if(is_array($tpldata['subjects'])) foreach($tpldata['subjects'] as $k=>$it) {?>
|
||||
<option value="<?php echo$it['id']?>"><?php echo$it['login']?></option>
|
||||
<?}?>
|
||||
</select>
|
||||
<input type="hidden" name="act" value="addPerm">
|
||||
<input type="hidden" name="id" value="<?php echo$tpldata['id']?>">
|
||||
<input type="submit" value="Do it!">
|
||||
</form>
|
||||
|
||||
<?php if($tpldata['msg']){?>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
alert('<?php echo$tpldata['msg']?>');
|
||||
-->
|
||||
</script><noscript><hr><b><?php echo$tpldata['msg']?></b></hr></noscript>
|
||||
<?php }?>
|
||||
</body></html>
|
162
livesupport/modules/storageServer/var/html/gbHtmlSubj.php
Normal file
162
livesupport/modules/storageServer/var/html/gbHtmlSubj.php
Normal file
|
@ -0,0 +1,162 @@
|
|||
<?php
|
||||
// $Id: gbHtmlSubj.php,v 1.1 2004/09/12 21:59:11 tomas Exp $
|
||||
require_once"gbHtml_h.php";
|
||||
require_once"gbHtmlTestAuth.php";
|
||||
|
||||
switch($_REQUEST['act']){
|
||||
case "passwd":
|
||||
$type='passwd';
|
||||
break;
|
||||
default:
|
||||
if(isset($_GET['id']) && is_numeric($_GET['id'])){
|
||||
$id = $_GET['id']; $type='group';
|
||||
}else $type='list';
|
||||
}
|
||||
|
||||
#header("Content-type: text/plain"); print_r($gb->listGroup($id)); exit;
|
||||
|
||||
// prefill data structure for template
|
||||
switch($type){
|
||||
case "list":
|
||||
$d = array(
|
||||
'subj' => $gb->getSubjectsWCnt(),
|
||||
'loggedAs' => $login
|
||||
);
|
||||
break;
|
||||
case "group":
|
||||
$d = array(
|
||||
'rows' => $gb->listGroup($id),
|
||||
'id' => $id,
|
||||
'loggedAs' => $login,
|
||||
'gname' => $gb->getSubjName($id),
|
||||
'subj' => $gb->getSubjects()
|
||||
);
|
||||
break;
|
||||
case "passwd":
|
||||
break;
|
||||
default:
|
||||
}
|
||||
$d['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']);
|
||||
|
||||
#header("Content-type: text/plain"); print_r($d); echo($list ? 'Y' : 'N')."\n"; exit;
|
||||
#require_once"gbHtml_f.php";
|
||||
// template follows:
|
||||
?>
|
||||
<html><head>
|
||||
<title>Storage - user and roles editor</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<link rel="stylesheet" type="text/css" href="default.css">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
#menu { float:right; margin-right:1em; border:1px solid black; background-color:#ddd; padding:2px 1ex; }
|
||||
#parent, #parent a { background-color:#888; font-weight:bold; color:white; }
|
||||
#tree { width:60%; }
|
||||
-->
|
||||
</style>
|
||||
</head><body>
|
||||
<div id="menu">
|
||||
Logged as: <span class="b"><?php echo$d['loggedAs']?></span><br>
|
||||
<a href="gbHttp.php?act=logout">logout</a><br>
|
||||
<a href="gbHtmlBrowse.php?act=getHomeDir">Browser</a><br>
|
||||
</div>
|
||||
|
||||
<h1>User/Group editor</h1>
|
||||
|
||||
<?php switch($type){ case "list":?>
|
||||
<h3>Subjects:</h3>
|
||||
<table id="tree" border="0" cellpadding="5">
|
||||
<tr><td>id</td><td>login</td><td>user/group</td><td></td></tr>
|
||||
<?php if(is_array($d['subj'])&&count($d['subj'])>0) foreach($d['subj'] as $k=>$c) {?>
|
||||
<tr class="<?php echo(($o=1-$o) ? 'odd' : 'ev')?>">
|
||||
<td><?php echo$c['id']?></td>
|
||||
<td class="b">
|
||||
<?if($c['type']=='G'){?>
|
||||
<a href="gbHtmlSubj.php?id=<?php echo$c['id']?>"><?php echo$c['login']?></a>
|
||||
<?}else{?><?php echo$c['login']?>
|
||||
<?}?>
|
||||
</td
|
||||
<td><?if($c['type']=='G'){?>(G:<?php echo$c['cnt']?>)<?}else{?> (U)<?}?></td>
|
||||
<td>
|
||||
<a class="lnkbutt" href="gbHttp.php?act=removeSubj&login=<?php echo urlencode($c['login'])?>">remove</a>
|
||||
<a class="lnkbutt" href="gbHtmlSubj.php?act=passwd&uid=<?php echo urlencode($c['id'])?>">change password</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php }else{?>
|
||||
<tr class="odd"><td colspan="4">none</td></tr>
|
||||
<?php }?>
|
||||
</table>
|
||||
|
||||
<form action="gbHttp.php" method="post">
|
||||
Add subject with name: <input type="text" name="login" value="" size="10">
|
||||
[and password: <input type="password" name="pass" value="" size="10">]
|
||||
<input type="hidden" name="act" value="addSubj">
|
||||
<input type="submit" value="Do it!">
|
||||
</form>
|
||||
|
||||
<?php break; case "group":?>
|
||||
|
||||
<h2>Subjects in group <?php echo$d['gname']?>:</h2>
|
||||
|
||||
<table id="tree" border="0" cellpadding="5">
|
||||
<tr id="parent">
|
||||
<td colspan="5">
|
||||
<a href="gbHtmlSubj.php">All subjects</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php if(is_array($d['rows'])&&count($d['rows'])>0) foreach($d['rows'] as $k=>$row) {?>
|
||||
<tr class="<?php echo(($o=1-$o) ? 'odd' : 'ev')?>">
|
||||
<td><?php echo$row['id']?></td>
|
||||
<td class="b">
|
||||
<?if($row['type']=='G'){?>
|
||||
<a href="gbHtmlSubj.php?id=<?php echo$row['id']?>"><?php echo$row['login']?></a>
|
||||
<?}else{?><?php echo$row['login']?>
|
||||
<?}?>
|
||||
</td
|
||||
<td><?if($row['type']=='G'){?> (G)<?}else{?> (U)<?}?></td>
|
||||
<td>
|
||||
<a class="lnkbutt"
|
||||
href="gbHttp.php?act=removeSubjFromGr&login=<?php echo urlencode($row['login'])?>&gname=<?php echo urlencode($d['gname'])?>&reid=<?php echo$d['id']?>">
|
||||
removeFromGroup
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php }else{?>
|
||||
<tr class="odd"><td colspan="3">none</td></tr>
|
||||
<?php }?>
|
||||
</table>
|
||||
|
||||
<form action="gbHttp.php" method="post">
|
||||
Add subject
|
||||
<select name="login">
|
||||
<?php if(is_array($d['subj'])) foreach($d['subj'] as $k=>$row) {?>
|
||||
<option value="<?php echo$row['login']?>"><?php echo$row['login']?></option>
|
||||
<?}?>
|
||||
</select>
|
||||
to group <?php echo$d['gname']?>
|
||||
<input type="hidden" name="act" value="addSubj2Gr">
|
||||
<input type="hidden" name="reid" value="<?php echo$d['id']?>">
|
||||
<input type="hidden" name="gname" value="<?php echo$d['gname']?>">
|
||||
<input type="submit" value="Do it!">
|
||||
</form>
|
||||
|
||||
<?php break; case "passwd":?>
|
||||
<form action="gbHttp.php" method="post">
|
||||
<table>
|
||||
<tr><td>Old password:</td><td><input type="password" name="oldpass" value=""></td></tr>
|
||||
<tr><td>New password:</td><td><input type="password" name="pass" value=""></td></tr>
|
||||
<tr><td>Retype:</td><td><input type="password" name="pass2" value=""></td></tr>
|
||||
<tr><td colspan="2"><input type="submit" value="Submit"></td></tr>
|
||||
</table>
|
||||
<input type="hidden" name="uid" value="<?php echo $_REQUEST['uid']?>">
|
||||
<input type="hidden" name="act" value="passwd">
|
||||
</form>
|
||||
<?php default: }?>
|
||||
|
||||
<?php if($d['msg']){?>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
alert('<?php echo$d['msg']?>');
|
||||
-->
|
||||
</script>
|
||||
<?php }?>
|
||||
</body></html>
|
|
@ -0,0 +1,9 @@
|
|||
<?
|
||||
// $Id: gbHtmlTestAuth.php,v 1.1 2004/09/12 21:59:11 tomas Exp $
|
||||
$login = $gb->getSessLogin($_REQUEST[$config['authCookieName']]);
|
||||
if(!isset($login)||$login==''){
|
||||
$_SESSION['alertMsg'] = "Login required";
|
||||
header("Location: gbHtmlLogin.php");
|
||||
exit;
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,13 @@
|
|||
<?
|
||||
$gb->initDb();
|
||||
$gb->init();
|
||||
#system("rm -f {$config['storageDir']}/*.bin {$config['storageDir']}/*.xml");
|
||||
$d = $gb->testData();
|
||||
$gb->putFile('/folder1/folder1_2/folder1_2_1', 'fileA', "123\n345\n", "<xml/>", 'at');
|
||||
$gb->createReplica('/folder1/folder1_2/folder1_2_1/fileA', '/folder1/folder1_2/folder1_2_1', 'replFA', 'at');
|
||||
$gb->putFile('/folder1/folder1_2/folder1_2_1', 'fileB', "123\n345\n789\n", "<xml/>", 'at');
|
||||
$gb->ovewriteMetadata('/folder1/folder1_2/folder1_2_1/fileA', "<xml>\n</xml>", 'at');
|
||||
|
||||
$gb->deleteFile('/folder1/folder1_2/folder1_2_1/fileB', 'at');
|
||||
|
||||
?>
|
25
livesupport/modules/storageServer/var/html/gbHtml_h.php
Normal file
25
livesupport/modules/storageServer/var/html/gbHtml_h.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?
|
||||
session_start();
|
||||
require_once '../conf.php';
|
||||
require_once 'DB.php';
|
||||
require_once '../GreenBox.php';
|
||||
|
||||
#PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_WARNING);
|
||||
#PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errCallBack');
|
||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||
#PEAR::setErrorHandling(PEAR_ERROR_PRINT);
|
||||
|
||||
function errCallBack($err)
|
||||
{
|
||||
echo "<pre>gm:\n".$err->getMessage()."\ndi:\n".$err->getDebugInfo()."\nui:\n".$err->getUserInfo()."\n";
|
||||
echo "<hr>BackTrace:\n";
|
||||
print_r($err->backtrace);
|
||||
echo "</pre>\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$dbc = DB::connect($config['dsn'], TRUE);
|
||||
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
$gb = &new GreenBox(&$dbc, $config);
|
||||
|
||||
?>
|
197
livesupport/modules/storageServer/var/html/gbHttp.php
Normal file
197
livesupport/modules/storageServer/var/html/gbHttp.php
Normal file
|
@ -0,0 +1,197 @@
|
|||
<?
|
||||
require_once"gbHtml_h.php";
|
||||
#header("Content-type: text/plain"); echo"GET:\n"; print_r($_GET); echo"POST:\n"; print_r($_POST); echo"REQUEST:\n"; print_r($_REQUEST); echo"FILES:\n"; print_r($_FILES); exit;
|
||||
#echo"<pre>\n"; print_r($_SERVER); exit;
|
||||
|
||||
define('BROWSER', "gbHtmlBrowse.php");
|
||||
|
||||
|
||||
$sessid = $_REQUEST[$config['authCookieName']];
|
||||
$userid = $gb->getSessUserId($sessid);
|
||||
$login = $gb->getSessLogin($sessid);
|
||||
|
||||
#$path = ($_REQUEST['path']=='' ? '/' : $_REQUEST['path']);
|
||||
#$upath = urlencode($path);
|
||||
#$id = $gb->_idFromPath($path);
|
||||
$id = (!$_REQUEST['id'] ? $gb->storId : $_REQUEST['id']);
|
||||
|
||||
|
||||
#if(PEAR::isError($id)){ $_SESSION['msg'] = $id->getMessage(); header("Location: ".BROWSER."?id=$id"); exit; }
|
||||
$redirUrl="gbHtmlBrowse.php?id=$id";
|
||||
|
||||
switch($_REQUEST['act']){
|
||||
// --- authentication ---
|
||||
case"login";
|
||||
# echo"<pre>\n"; print_r($_REQUEST); exit;
|
||||
$sessid = $gb->login($_REQUEST['login'], $_REQUEST['pass']);
|
||||
if($sessid && !PEAR::isError($sessid)){
|
||||
# echo"<pre>$sessid\n"; print_r($_REQUEST); exit;
|
||||
setcookie($config['authCookieName'], $sessid);
|
||||
$redirUrl="gbHtmlBrowse.php";
|
||||
$fid = $gb->getObjId($_REQUEST['login'], $gb->storId);
|
||||
if(!PEAR::isError($fid)) $redirUrl.="?id=$fid";
|
||||
}else{ $redirUrl="gbHtmlLogin.php"; $_SESSION['alertMsg']='Login failed.'; }
|
||||
# echo"<pre>$redirUrl\n"; print_r($_REQUEST); exit;
|
||||
break;
|
||||
case"logout";
|
||||
$gb->logout($sessid);
|
||||
setcookie($config['authCookieName'], '');
|
||||
$redirUrl="gbHtmlLogin.php";
|
||||
break;
|
||||
|
||||
// --- files ---
|
||||
case"upload":
|
||||
$tmpgunid = md5(microtime().$_SERVER['SERVER_ADDR'].rand()."org.mdlf.livesupport");
|
||||
$ntmp = "{$gb->storageDir}/buffer/$tmpgunid";
|
||||
# $ntmp = tempnam(""{$gb->storageDir}/buffer", 'gbTmp_');
|
||||
$mdtmp = "";
|
||||
move_uploaded_file($_FILES['mediafile']['tmp_name'], $ntmp); chmod($ntmp, 0664);
|
||||
if($_FILES['mdatafile']['tmp_name']){
|
||||
$mdtmp = "$ntmp.xml";
|
||||
if(move_uploaded_file($_FILES['mdatafile']['tmp_name'], $mdtmp)){
|
||||
chmod($mdtmp, 0664);
|
||||
}
|
||||
}
|
||||
$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);
|
||||
}
|
||||
$redirUrl = BROWSER."?id=$id";
|
||||
break;
|
||||
case"newFolder":
|
||||
$r = $gb->createFolder($id, $_REQUEST['newname'], $sessid);
|
||||
if(PEAR::isError($r)) $_SESSION['alertMsg'] = $r->getMessage();
|
||||
$redirUrl = BROWSER."?id=$id";
|
||||
break;
|
||||
case"rename":
|
||||
$parid = $gb->getparent($id);
|
||||
$r = $gb->renameFile($id, $_REQUEST['newname'], $sessid);
|
||||
if(PEAR::isError($r)) $_SESSION['alertMsg'] = $r->getMessage();
|
||||
$redirUrl = BROWSER."?id=$parid";
|
||||
break;
|
||||
/* NOT WORKING - sorry */
|
||||
case"move":
|
||||
$newPath = urlencode($_REQUEST['newPath']);
|
||||
$did = $gb->getObjIdFromRelPath($id, $newPath);
|
||||
$parid = $gb->getparent($id);
|
||||
$r = $gb->moveFile($id, $did, $sessid);
|
||||
if(PEAR::isError($r)){
|
||||
$_SESSION['alertMsg'] = $r->getMessage();
|
||||
$redirUrl = BROWSER."?id=$parid";
|
||||
}
|
||||
else $redirUrl = BROWSER."?id=$did";
|
||||
break;
|
||||
case"copy":
|
||||
$newPath = urldecode($_REQUEST['newPath']);
|
||||
$did = $gb->getObjIdFromRelPath($id, $newPath);
|
||||
$parid = $gb->getparent($id);
|
||||
# echo"<pre>\n$id\t$newPath\t$did\n"; print_r($did); exit;
|
||||
$r = $gb->copyFile($id, $did, $sessid);
|
||||
if(PEAR::isError($r)){
|
||||
$_SESSION['alertMsg'] = $r->getMessage();
|
||||
$redirUrl = BROWSER."?id=$parid";
|
||||
}
|
||||
else $redirUrl = BROWSER."?id=$did";
|
||||
break;
|
||||
case"repl":
|
||||
$unewpath = urlencode($_REQUEST['newpath']);
|
||||
$r = $gb->createReplica($id, $_REQUEST['newpath'], '', $sessid);
|
||||
if(PEAR::isError($r)) $_SESSION['alertMsg'] = $r->getMessage();
|
||||
$redirUrl = BROWSER."?id=$newparid";
|
||||
break;
|
||||
/* */
|
||||
case"delete":
|
||||
$parid = $gb->getparent($id);
|
||||
$r = $gb->deleteFile($id, $sessid);
|
||||
if(PEAR::isError($r)) $_SESSION['alertMsg'] = $r->getMessage();
|
||||
$redirUrl = BROWSER."?id=$parid";
|
||||
break;
|
||||
case"getFile":
|
||||
# echo"<pre>$t, $ctype\n"; exit;
|
||||
# $r = $gb->getFile($id, $sessid);
|
||||
$r = $gb->access($id, $sessid);
|
||||
if(PEAR::isError($r)) $_SESSION['alertMsg'] = $r->getMessage();
|
||||
else echo $r;
|
||||
exit;
|
||||
break;
|
||||
case"getMdata":
|
||||
header("Content-type: text/xml");
|
||||
$r = $gb->getMdata($id, $sessid);
|
||||
print_r($r);
|
||||
exit;
|
||||
break;
|
||||
case"getInfo":
|
||||
header("Content-type: text/plain");
|
||||
$ia = $gb->analyzeFile($id, $sessid);
|
||||
echo"fileformat: {$ia['fileformat']}\n";
|
||||
echo"channels: {$ia['audio']['channels']}\n";
|
||||
echo"sample_rate: {$ia['audio']['sample_rate']}\n";
|
||||
echo"bits_per_sample: {$ia['audio']['bits_per_sample']}\n";
|
||||
echo"channelmode: {$ia['audio']['channelmode']}\n";
|
||||
echo"title: {$ia['id3v1']['title']}\n";
|
||||
echo"artist: {$ia['id3v1']['artist']}\n";
|
||||
echo"comment: {$ia['id3v1']['comment']}\n";
|
||||
# echo": {$ia['id3v1']['']}\n";
|
||||
# print_r($ia);
|
||||
exit;
|
||||
break;
|
||||
|
||||
// --- subjs ----
|
||||
case"addSubj";
|
||||
$redirUrl="gbHtmlSubj.php";
|
||||
if($gb->checkPerm($userid, 'subjects'))
|
||||
$res = $gb->addSubj($_REQUEST['login'], ($_REQUEST['pass']=='' ? NULL:$_REQUEST['pass'] ));
|
||||
else{ $_SESSION['alertMsg']='Access denied.'; break; }
|
||||
if(PEAR::isError($res)) $_SESSION['alertMsg'] = $res->getMessage();
|
||||
break;
|
||||
case"removeSubj";
|
||||
$redirUrl="gbHtmlSubj.php";
|
||||
if($gb->checkPerm($userid, 'subjects'))
|
||||
$res = $gb->removeSubj($_REQUEST['login']);
|
||||
else{ $_SESSION['alertMsg']='Access denied.'; break; }
|
||||
if(PEAR::isError($res)) $_SESSION['alertMsg'] = $res->getMessage();
|
||||
break;
|
||||
case"passwd";
|
||||
$redirUrl="gbHtmlSubj.php";
|
||||
$ulogin = $gb->getSubjName($_REQUEST['uid']);
|
||||
if($userid != $_REQUEST['uid'] &&
|
||||
! $gb->checkPerm($userid, 'subjects')){
|
||||
$_SESSION['alertMsg']='Access denied..';
|
||||
break;
|
||||
}
|
||||
if(FALSE === $gb->authenticate($ulogin, $_REQUEST['oldpass'])){
|
||||
$_SESSION['alertMsg']='Wrong old pasword.';
|
||||
break;
|
||||
}
|
||||
if($_REQUEST['pass'] !== $_REQUEST['pass2']){
|
||||
$_SESSION['alertMsg']="Passwords do not match. ({$_REQUEST['pass']}/{$_REQUEST['pass2']})";
|
||||
break;
|
||||
}
|
||||
$gb->passwd($ulogin, $_REQUEST['oldpass'], $_REQUEST['pass']);
|
||||
break;
|
||||
|
||||
// --- perms ---
|
||||
case"addPerm";
|
||||
if($gb->checkPerm($userid, 'editPerms', $_REQUEST['id']))
|
||||
$gb->addPerm($_REQUEST['subj'], $_REQUEST['permAction'], $_REQUEST['id'], $_REQUEST['allowDeny']);
|
||||
else $_SESSION['alertMsg']='Access denied.';
|
||||
$redirUrl="gbHtmlPerms.php?id=$id";
|
||||
break;
|
||||
case"removePerm";
|
||||
if($gb->checkPerm($userid, 'editPerms', $_REQUEST['oid']))
|
||||
$gb->removePerm($_GET['permid']);
|
||||
else $_SESSION['alertMsg']='Access denied.';
|
||||
$redirUrl="gbHtmlPerms.php?id=$id";
|
||||
break;
|
||||
|
||||
default:
|
||||
$_SESSION['alertMsg']="Unknown method: {$_REQUEST['act']}";
|
||||
$redirUrl="gbHtmlLogin.php";
|
||||
}
|
||||
|
||||
#echo"<pre>$redirUrl\n"; print_r($_REQUEST); exit;
|
||||
header("Location: $redirUrl");
|
||||
?>
|
34
livesupport/modules/storageServer/var/html/index.php
Normal file
34
livesupport/modules/storageServer/var/html/index.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/html/Attic/index.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
header ("location: gbHtmlLogin.php");
|
||||
die;
|
||||
|
||||
?>
|
45
livesupport/modules/storageServer/var/index.php
Normal file
45
livesupport/modules/storageServer/var/index.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/index.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
header ("location: html/gbHtmlLogin.php");
|
||||
exit;
|
||||
/*
|
||||
?>
|
||||
<html><head>
|
||||
<title>Storage module</title>
|
||||
</head><body>
|
||||
<h3>Storage module</h3>
|
||||
<br>
|
||||
<a href="../html/gbHtmlLogin.php" accesskey="H"><b>H</b>TML client</a><br>
|
||||
<a href="../xmlrpc/" accesskey="X"><b>X</b>mlRpc test</a><br>
|
||||
<a href="../tests/" accesskey="T"><b>T</b>est</a><br>
|
||||
</body></html>
|
||||
<?
|
||||
*/
|
||||
?>
|
34
livesupport/modules/storageServer/var/install/index.php
Normal file
34
livesupport/modules/storageServer/var/install/index.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/install/index.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
header ("location: ../index.php");
|
||||
die;
|
||||
|
||||
?>
|
87
livesupport/modules/storageServer/var/install/install.php
Normal file
87
livesupport/modules/storageServer/var/install/install.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/install/install.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
require_once '../conf.php';
|
||||
require_once 'DB.php';
|
||||
require_once '../GreenBox.php';
|
||||
|
||||
function errCallback($err)
|
||||
{
|
||||
if(assert_options(ASSERT_ACTIVE)==1) return;
|
||||
echo "ERROR:\n";
|
||||
echo "request: "; print_r($_REQUEST);
|
||||
echo "gm:\n".$err->getMessage()."\ndi:\n".$err->getDebugInfo()."\nui:\n".$err->getUserInfo()."\n</pre>\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
|
||||
$dbc = DB::connect($config['dsn'], TRUE);
|
||||
if(PEAR::isError($dbc)){
|
||||
echo "Database connection problem.\n";
|
||||
echo "Check if database '{$config['dsn']['database']}' exists with corresponding permissions.\n";
|
||||
echo "Database access is defined by 'dsn' values in conf.php.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
$gb = &new GreenBox(&$dbc, $config);
|
||||
|
||||
echo "Storage: Install ...\n";
|
||||
$dbc->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
$gb->uninstall();
|
||||
PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
|
||||
$gb->install();
|
||||
|
||||
echo " Testing ...\n";
|
||||
$gb->test();
|
||||
$log = $gb->test_log;
|
||||
echo " TESTS:\n$log\n---\n";
|
||||
|
||||
#echo " Reinstall + testdata insert ...\n";
|
||||
#$gb->reinstall();
|
||||
#$gb->sessid = $gb->login('root', $gb->config['tmpRootPass']);
|
||||
#$gb->testData();
|
||||
#$gb->logout($gb->sessid); unset($gb->sessid);
|
||||
|
||||
echo " TREE DUMP:\n";
|
||||
echo $gb->dumpTree();
|
||||
|
||||
echo " Delete test data ...\n";
|
||||
$gb->deleteData();
|
||||
|
||||
if(!($fp = @fopen($config['storageDir']."/_writeTest", 'w')))
|
||||
echo "\n<b>!!! make {$config['storageDir']} dir webdaemon-writeable !!!</b>\nand run install again\n\n";
|
||||
else{
|
||||
fclose($fp); unlink($config['storageDir']."/_writeTest");
|
||||
echo "\nStorage is probably installed OK\n";
|
||||
}
|
||||
|
||||
$dbc->disconnect();
|
||||
?>
|
61
livesupport/modules/storageServer/var/install/uninstall.php
Normal file
61
livesupport/modules/storageServer/var/install/uninstall.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/install/uninstall.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
require_once '../conf.php';
|
||||
require_once 'DB.php';
|
||||
require_once '../GreenBox.php';
|
||||
|
||||
function errCallback($err)
|
||||
{
|
||||
if(assert_options(ASSERT_ACTIVE)==1) return;
|
||||
echo "ERROR:\n";
|
||||
echo "request: "; print_r($_REQUEST);
|
||||
echo "gm:\n".$err->getMessage()."\ndi:\n".$err->getDebugInfo()."\nui:\n".$err->getUserInfo()."\n</pre>\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
PEAR::setErrorHandling(PEAR_ERROR_PRINT, "%s<hr>\n");
|
||||
$dbc = DB::connect($config['dsn'], TRUE);
|
||||
if(PEAR::isError($dbc)){
|
||||
echo "Database connection problem.\n";
|
||||
echo "Check if database '{$config['dsn']['database']}' exists with corresponding permissions.\n";
|
||||
echo "Database access is defined by 'dsn' values in conf.php.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
$gb = &new GreenBox(&$dbc, $config);
|
||||
|
||||
# $dbc->setErrorHandling(PEAR_ERROR_RETURN);
|
||||
echo "Trying to uninstall all ...\n";
|
||||
$gb->uninstall();
|
||||
|
||||
$dbc->disconnect();
|
||||
?>
|
25
livesupport/modules/storageServer/var/tests/analyze.php
Executable file
25
livesupport/modules/storageServer/var/tests/analyze.php
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/php -q
|
||||
<?
|
||||
header("Content-type: text/plain");
|
||||
echo "TEST\n";
|
||||
|
||||
#$gunid = "5716b53127c3761f92fddde3412c7773";
|
||||
$gunid = $argv[1];
|
||||
echo "GUNID: $gunid\n";
|
||||
|
||||
require_once '../conf.php';
|
||||
require_once 'DB.php';
|
||||
require_once '../GreenBox.php';
|
||||
|
||||
#$rmd =& new RawMediaData('qwerty', '../stor');
|
||||
#$r = $rmd->insert('./ex1.mp3', 'mp3');
|
||||
#$r = $rmd->test('./ex1.mp3', './ex2.wav', '../access/xyz.ext');
|
||||
|
||||
$rmd =& new RawMediaData($gunid, '../stor/'.substr($gunid, 0, 3));
|
||||
$r = $rmd->analyze();
|
||||
|
||||
echo "r=$r (".gettype($r).")\n";
|
||||
if(PEAR::isError($r)) echo"ERR: ".$r->getMessage()."\n".$r->getUserInfo()."\n";
|
||||
if(is_array($r)) print_r($r);
|
||||
echo"\n";
|
||||
?>
|
BIN
livesupport/modules/storageServer/var/tests/ex1.mp3
Normal file
BIN
livesupport/modules/storageServer/var/tests/ex1.mp3
Normal file
Binary file not shown.
BIN
livesupport/modules/storageServer/var/tests/ex2.ogg
Normal file
BIN
livesupport/modules/storageServer/var/tests/ex2.ogg
Normal file
Binary file not shown.
BIN
livesupport/modules/storageServer/var/tests/ex2.wav
Normal file
BIN
livesupport/modules/storageServer/var/tests/ex2.wav
Normal file
Binary file not shown.
34
livesupport/modules/storageServer/var/tests/index.php
Normal file
34
livesupport/modules/storageServer/var/tests/index.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/tests/index.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
header ("location: ../index.php");
|
||||
die;
|
||||
|
||||
?>
|
33
livesupport/modules/storageServer/var/tests/mdata1.xml
Normal file
33
livesupport/modules/storageServer/var/tests/mdata1.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<metadata
|
||||
xmlns="http://www.streamonthefly.org/"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:dcterms="http://purl.org/dc/terms/"
|
||||
xmlns:xbmf="http://www.streamonthefly.org/xbmf"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
>
|
||||
<dc:title >File Title txt</dc:title>
|
||||
<dcterms:alternative >Alternative File Title txt</dcterms:alternative>
|
||||
<dc:subject >Keywords: qwe, asd, zcx</dc:subject>
|
||||
<dc:description >Abstract txt</dc:description>
|
||||
<dc:date >2004-05-21</dc:date>
|
||||
<dcterms:available >2004-05-22</dcterms:available>
|
||||
<dcterms:issued >2004-05-23</dcterms:issued>
|
||||
<dcterms:modified >2004-05-24</dcterms:modified>
|
||||
<dcterms:valid >2004-05-25</dcterms:valid>
|
||||
<dc:type xsi:type="dcterms:DCMIType" >Sound</dc:type>
|
||||
<dc:format xsi:type="dcterms:IMT" >audio/mpeg</dc:format>
|
||||
<dcterms:extent >123</dcterms:extent>
|
||||
<dcterms:medium >online</dcterms:medium>
|
||||
<dc:identifier >streamonthefly:</dc:identifier>
|
||||
<dc:identifier >http://some.url.mdlf.org/</dc:identifier>
|
||||
<dcterms:spatial >Spatial Coverage</dcterms:spatial>
|
||||
<dcterms:temporal >Temporal Covarage</dcterms:temporal>
|
||||
<xbmf:episodetitle >Episode Title txt</xbmf:episodetitle>
|
||||
<xbmf:episodesequence >Episode sequence</xbmf:episodesequence>
|
||||
<xbmf:contributor>
|
||||
<xbmf:role>Editor</xbmf:role>
|
||||
<xbmf:name>John X</xbmf:name>
|
||||
<xbmf:phone>123456789</xbmf:phone>
|
||||
</xbmf:contributor>
|
||||
</metadata>
|
33
livesupport/modules/storageServer/var/tests/mdata2.xml
Normal file
33
livesupport/modules/storageServer/var/tests/mdata2.xml
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<metadata
|
||||
xmlns="http://www.streamonthefly.org/"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:dcterms="http://purl.org/dc/terms/"
|
||||
xmlns:xbmf="http://www.streamonthefly.org/xbmf"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
>
|
||||
<dc:title >File2 Title txt</dc:title>
|
||||
<dcterms:alternative >Alternative File2 Title txt</dcterms:alternative>
|
||||
<dc:subject >Keywords: qwe, asd, zcx</dc:subject>
|
||||
<dc:description >Abstract txt</dc:description>
|
||||
<dc:date >2004-05-21</dc:date>
|
||||
<dcterms:available >2004-05-22</dcterms:available>
|
||||
<dcterms:issued >2004-05-23</dcterms:issued>
|
||||
<dcterms:modified >2004-05-24</dcterms:modified>
|
||||
<dcterms:valid >2004-05-25</dcterms:valid>
|
||||
<dc:type xsi:type="dcterms:DCMIType" >Sound</dc:type>
|
||||
<dc:format xsi:type="dcterms:IMT" >audio/mpeg</dc:format>
|
||||
<dcterms:extent >123</dcterms:extent>
|
||||
<dcterms:medium >online</dcterms:medium>
|
||||
<dc:identifier >streamonthefly:</dc:identifier>
|
||||
<dc:identifier >http://some.url.mdlf.org/</dc:identifier>
|
||||
<dcterms:spatial >Spatial Coverage</dcterms:spatial>
|
||||
<dcterms:temporal >Temporal Covarage</dcterms:temporal>
|
||||
<xbmf:episodetitle >Episode Title txt</xbmf:episodetitle>
|
||||
<xbmf:episodesequence >Episode sequence</xbmf:episodesequence>
|
||||
<xbmf:contributor>
|
||||
<xbmf:role>Editor</xbmf:role>
|
||||
<xbmf:name>John X</xbmf:name>
|
||||
<xbmf:phone>123456789</xbmf:phone>
|
||||
</xbmf:contributor>
|
||||
</metadata>
|
16
livesupport/modules/storageServer/var/tests/mdata3.xml
Normal file
16
livesupport/modules/storageServer/var/tests/mdata3.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<metadata
|
||||
xmlns="http://www.streamonthefly.org/"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:dcterms="http://purl.org/dc/terms/"
|
||||
xmlns:xbmf="http://www.streamonthefly.org/xbmf"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
>
|
||||
<dc:title >File Title3 txt</dc:title>
|
||||
<dcterms:alternative >Alternative File Title txt</dcterms:alternative>
|
||||
<xbmf:contributor>
|
||||
<xbmf:role>Author</xbmf:role>
|
||||
<xbmf:name>John Y</xbmf:name>
|
||||
<xbmf:phone>234</xbmf:phone>
|
||||
</xbmf:contributor>
|
||||
</metadata>
|
BIN
livesupport/modules/storageServer/var/tests/question.wav
Normal file
BIN
livesupport/modules/storageServer/var/tests/question.wav
Normal file
Binary file not shown.
14
livesupport/modules/storageServer/var/tests/srch_cri1.xml
Normal file
14
livesupport/modules/storageServer/var/tests/srch_cri1.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<metadata
|
||||
xmlns="http://www.streamonthefly.org/"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:dcterms="http://purl.org/dc/terms/"
|
||||
xmlns:xbmf="http://www.streamonthefly.org/xbmf"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
>
|
||||
<dc:title >File%</dc:title>
|
||||
<xbmf:contributor>
|
||||
<xbmf:role>Author</xbmf:role>
|
||||
<xbmf:name>John Y</xbmf:name>
|
||||
</xbmf:contributor>
|
||||
</metadata>
|
12
livesupport/modules/storageServer/var/tests/testStorage.xml
Normal file
12
livesupport/modules/storageServer/var/tests/testStorage.xml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE testStorage [
|
||||
|
||||
<!ELEMENT testStorage (playlist*) >
|
||||
|
||||
<!ELEMENT playlist EMPTY >
|
||||
<!ATTLIST playlist id NMTOKEN #REQUIRED >
|
||||
<!ATTLIST playlist playlength NMTOKEN #REQUIRED >
|
||||
]>
|
||||
<testStorage>
|
||||
<playlist id="1" playlength="01:30:00.00"/>
|
||||
</testStorage>
|
34
livesupport/modules/storageServer/var/xmlrpc/index.php
Normal file
34
livesupport/modules/storageServer/var/xmlrpc/index.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/index.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
header ("location: ../index.php");
|
||||
die;
|
||||
|
||||
?>
|
155
livesupport/modules/storageServer/var/xmlrpc/testRunner.sh
Executable file
155
livesupport/modules/storageServer/var/xmlrpc/testRunner.sh
Executable file
|
@ -0,0 +1,155 @@
|
|||
#!/bin/sh
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copyright (c) 2004 Media Development Loan Fund
|
||||
#
|
||||
# This file is part of the LiveSupport project.
|
||||
# http://livesupport.campware.org/
|
||||
# To report bugs, send an e-mail to bugs@campware.org
|
||||
#
|
||||
# LiveSupport is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# LiveSupport is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LiveSupport; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# Author : $Author: tomas $
|
||||
# Version : $Revision: 1.1 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh,v $
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
COMM=$1
|
||||
shift
|
||||
GUNID=$1
|
||||
|
||||
#XMLRPC=http://localhost:80/tom/work/mdlf/livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php
|
||||
XMLRPC=http://localhost:80/livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php
|
||||
echo "XMLRPC server URL (check it in troubles):"
|
||||
echo $XMLRPC
|
||||
|
||||
TESTDIR=`dirname $0`
|
||||
XR_CLI="$TESTDIR/xr_cli_test.py -s $XMLRPC"
|
||||
|
||||
login() {
|
||||
echo "login:"
|
||||
SESSID=`$XR_CLI login root q`
|
||||
echo "sessid: $SESSID"
|
||||
}
|
||||
|
||||
test() {
|
||||
echo "test:"
|
||||
$XR_CLI test $SESSID stringForUppercase
|
||||
}
|
||||
|
||||
existsAudioClip() {
|
||||
echo "existsAudioClip:"
|
||||
$XR_CLI existsAudioClip $SESSID $GUNID
|
||||
}
|
||||
|
||||
accessRawAudioData() {
|
||||
echo "accessRawAudioData:"
|
||||
FPATH=`$XR_CLI accessRawAudioData $SESSID $GUNID`
|
||||
FPATH="<?echo urldecode(\"$FPATH\")?>"
|
||||
FPATH=`echo "$FPATH" | php -q`
|
||||
echo $FPATH
|
||||
ls -l $FPATH
|
||||
echo "releaseRawAudioData:"
|
||||
$XR_CLI releaseRawAudioData $SESSID $FPATH
|
||||
#$XR_CLI getAudioClip $SESSID $GUNID
|
||||
}
|
||||
|
||||
storeAudioClip() {
|
||||
echo "storeAudioClip:"
|
||||
MEDIA=../tests/ex1.mp3
|
||||
METADATA=../tests/testStorage.xml
|
||||
RGUNID=`$XR_CLI storeAudioClip "$SESSID" 'X' "$MEDIA" "$METADATA"`
|
||||
echo $RGUNID
|
||||
}
|
||||
|
||||
deleteAudioClip() {
|
||||
echo "deleteAudioClip:"
|
||||
$XR_CLI deleteAudioClip $SESSID $GUNID
|
||||
}
|
||||
|
||||
updateAudioClipMetadata() {
|
||||
echo "updateAudioClipMetadata:"
|
||||
$XR_CLI updateAudioClipMetadata $SESSID $GUNID '../tests/mdata3.xml'
|
||||
}
|
||||
|
||||
getAudioClip() {
|
||||
echo "getAudioClip:"
|
||||
$XR_CLI getAudioClip $SESSID $GUNID | ./urldecode
|
||||
}
|
||||
|
||||
searchMetadata() {
|
||||
echo "searchMetadata:"
|
||||
# $XR_CLI searchMetadata $SESSID '../tests/srch_cri1.xml'
|
||||
$XR_CLI searchMetadata $SESSID 'John %'
|
||||
}
|
||||
|
||||
logout() {
|
||||
echo "logout:"
|
||||
$XR_CLI logout $SESSID
|
||||
}
|
||||
|
||||
usage(){
|
||||
echo "Usage: $0 <command> [args]"
|
||||
echo -e "commands:\n test\n existsAudioClip\n accessRawAudioData"
|
||||
echo -e " storeAudioClip\n deleteAudioClip\n updateAudioClipMetadata"
|
||||
echo -e " getAudioClip\n searchMetadata\n"
|
||||
}
|
||||
|
||||
if [ "$COMM" == "test" ]; then
|
||||
login
|
||||
test
|
||||
logout
|
||||
elif [ "$COMM" == "existsAudioClip" ]; then
|
||||
login
|
||||
existsAudioClip
|
||||
logout
|
||||
elif [ "$COMM" == "accessRawAudioData" ]; then
|
||||
login
|
||||
accessRawAudioData
|
||||
logout
|
||||
elif [ "$COMM" == "storeAudioClip" ]; then
|
||||
login
|
||||
storeAudioClip
|
||||
logout
|
||||
elif [ "$COMM" == "deleteAudioClip" ]; then
|
||||
login
|
||||
deleteAudioClip
|
||||
logout
|
||||
elif [ "$COMM" == "updateAudioClipMetadata" ]; then
|
||||
login
|
||||
updateAudioClipMetadata
|
||||
logout
|
||||
elif [ "$COMM" == "getAudioClip" ]; then
|
||||
login
|
||||
getAudioClip
|
||||
logout
|
||||
elif [ "$COMM" == "searchMetadata" ]; then
|
||||
login
|
||||
searchMetadata
|
||||
logout
|
||||
elif [ "x$COMM" == "x" ]; then
|
||||
login
|
||||
storeAudioClip
|
||||
GUNID=$RGUNID
|
||||
accessRawAudioData
|
||||
deleteAudioClip
|
||||
logout
|
||||
elif [ "$COMM" == "help" ]; then
|
||||
usage
|
||||
else
|
||||
echo "Unknown command"
|
||||
usage
|
||||
fi
|
7
livesupport/modules/storageServer/var/xmlrpc/urldecode
Executable file
7
livesupport/modules/storageServer/var/xmlrpc/urldecode
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/php -q
|
||||
<?
|
||||
$fp = fopen("/dev/stdin", "r");
|
||||
$data = '';
|
||||
while($part = fgets($fp, 1024)) $data .= $part;
|
||||
echo urldecode($data);
|
||||
?>
|
1489
livesupport/modules/storageServer/var/xmlrpc/xmlrpc.inc
Normal file
1489
livesupport/modules/storageServer/var/xmlrpc/xmlrpc.inc
Normal file
File diff suppressed because it is too large
Load diff
450
livesupport/modules/storageServer/var/xmlrpc/xmlrpcs.inc
Normal file
450
livesupport/modules/storageServer/var/xmlrpc/xmlrpcs.inc
Normal file
|
@ -0,0 +1,450 @@
|
|||
<?php
|
||||
// by Edd Dumbill (C) 1999-2002
|
||||
// <edd@usefulinc.com>
|
||||
// $Id: xmlrpcs.inc,v 1.1 2004/09/12 21:59:34 tomas Exp $
|
||||
|
||||
// Copyright (c) 1999,2000,2002 Edd Dumbill.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
//
|
||||
// * Neither the name of the "XML-RPC for PHP" nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// XML RPC Server class
|
||||
// requires: xmlrpc.inc
|
||||
|
||||
// listMethods: either a string, or nothing
|
||||
$_xmlrpcs_listMethods_sig=array(array($xmlrpcArray, $xmlrpcString), array($xmlrpcArray));
|
||||
$_xmlrpcs_listMethods_doc='This method lists all the methods that the XML-RPC server knows how to dispatch';
|
||||
function _xmlrpcs_listMethods($server, $m)
|
||||
{
|
||||
global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
|
||||
$v=new xmlrpcval();
|
||||
$dmap=$server->dmap;
|
||||
$outAr=array();
|
||||
for(reset($dmap); list($key, $val)=each($dmap); )
|
||||
{
|
||||
$outAr[]=new xmlrpcval($key, 'string');
|
||||
}
|
||||
$dmap=$_xmlrpcs_dmap;
|
||||
for(reset($dmap); list($key, $val)=each($dmap); )
|
||||
{
|
||||
$outAr[]=new xmlrpcval($key, 'string');
|
||||
}
|
||||
$v->addArray($outAr);
|
||||
return new xmlrpcresp($v);
|
||||
}
|
||||
|
||||
$_xmlrpcs_methodSignature_sig=array(array($xmlrpcArray, $xmlrpcString));
|
||||
$_xmlrpcs_methodSignature_doc='Returns an array of known signatures (an array of arrays) for the method name passed. If no signatures are known, returns a none-array (test for type != array to detect missing signature)';
|
||||
function _xmlrpcs_methodSignature($server, $m)
|
||||
{
|
||||
global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
|
||||
|
||||
$methName=$m->getParam(0);
|
||||
$methName=$methName->scalarval();
|
||||
if (ereg("^system\.", $methName))
|
||||
{
|
||||
$dmap=$_xmlrpcs_dmap; $sysCall=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$dmap=$server->dmap; $sysCall=0;
|
||||
}
|
||||
// print "<!-- ${methName} -->\n";
|
||||
if (isset($dmap[$methName]))
|
||||
{
|
||||
if ($dmap[$methName]['signature'])
|
||||
{
|
||||
$sigs=array();
|
||||
$thesigs=$dmap[$methName]['signature'];
|
||||
for($i=0; $i<sizeof($thesigs); $i++)
|
||||
{
|
||||
$cursig=array();
|
||||
$inSig=$thesigs[$i];
|
||||
for($j=0; $j<sizeof($inSig); $j++)
|
||||
{
|
||||
$cursig[]=new xmlrpcval($inSig[$j], 'string');
|
||||
}
|
||||
$sigs[]=new xmlrpcval($cursig, 'array');
|
||||
}
|
||||
$r=new xmlrpcresp(new xmlrpcval($sigs, 'array'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$r=new xmlrpcresp(new xmlrpcval('undef', 'string'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$r=new xmlrpcresp(0,$xmlrpcerr['introspect_unknown'], $xmlrpcstr['introspect_unknown']);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
$_xmlrpcs_methodHelp_sig=array(array($xmlrpcString, $xmlrpcString));
|
||||
$_xmlrpcs_methodHelp_doc='Returns help text if defined for the method passed, otherwise returns an empty string';
|
||||
function _xmlrpcs_methodHelp($server, $m)
|
||||
{
|
||||
global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
|
||||
|
||||
$methName=$m->getParam(0);
|
||||
$methName=$methName->scalarval();
|
||||
if (ereg("^system\.", $methName))
|
||||
{
|
||||
$dmap=$_xmlrpcs_dmap; $sysCall=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$dmap=$server->dmap; $sysCall=0;
|
||||
}
|
||||
// print "<!-- ${methName} -->\n";
|
||||
if (isset($dmap[$methName]))
|
||||
{
|
||||
if ($dmap[$methName]['docstring'])
|
||||
{
|
||||
$r=new xmlrpcresp(new xmlrpcval($dmap[$methName]["docstring"]), 'string');
|
||||
}
|
||||
else
|
||||
{
|
||||
$r=new xmlrpcresp(new xmlrpcval('', 'string'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$r=new xmlrpcresp(0, $xmlrpcerr['introspect_unknown'], $xmlrpcstr['introspect_unknown']);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
$_xmlrpcs_multicall_sig = array(array($xmlrpcArray, $xmlrpcArray));
|
||||
$_xmlrpcs_multicall_doc = 'Boxcar multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details';
|
||||
|
||||
function _xmlrpcs_multicall_error($err)
|
||||
{
|
||||
if (is_string($err))
|
||||
{
|
||||
global $xmlrpcerr, $xmlrpcstr;
|
||||
$str = $xmlrpcstr["multicall_${err}"];
|
||||
$code = $xmlrpcerr["multicall_${err}"];
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = $err->faultCode();
|
||||
$str = $err->faultString();
|
||||
}
|
||||
$struct['faultCode'] = new xmlrpcval($code, 'int');
|
||||
$struct['faultString'] = new xmlrpcval($str, 'string');
|
||||
return new xmlrpcval($struct, 'struct');
|
||||
}
|
||||
|
||||
function _xmlrpcs_multicall_do_call($server, $call)
|
||||
{
|
||||
if ($call->kindOf() != 'struct')
|
||||
return _xmlrpcs_multicall_error('notstruct');
|
||||
$methName = $call->structmem('methodName');
|
||||
if (!$methName)
|
||||
return _xmlrpcs_multicall_error('nomethod');
|
||||
if ($methName->kindOf() != 'scalar' || $methName->scalartyp() != 'string')
|
||||
return _xmlrpcs_multicall_error('notstring');
|
||||
if ($methName->scalarval() == 'system.multicall')
|
||||
return _xmlrpcs_multicall_error('recursion');
|
||||
|
||||
$params = $call->structmem('params');
|
||||
if (!$params)
|
||||
return _xmlrpcs_multicall_error('noparams');
|
||||
if ($params->kindOf() != 'array')
|
||||
return _xmlrpcs_multicall_error('notarray');
|
||||
$numParams = $params->arraysize();
|
||||
|
||||
$msg = new xmlrpcmsg($methName->scalarval());
|
||||
for ($i = 0; $i < $numParams; $i++)
|
||||
$msg->addParam($params->arraymem($i));
|
||||
|
||||
$result = $server->execute($msg);
|
||||
|
||||
if ($result->faultCode() != 0)
|
||||
return _xmlrpcs_multicall_error($result); // Method returned fault.
|
||||
|
||||
return new xmlrpcval(array($result->value()), "array");
|
||||
}
|
||||
|
||||
function _xmlrpcs_multicall($server, $m)
|
||||
{
|
||||
$calls = $m->getParam(0);
|
||||
$numCalls = $calls->arraysize();
|
||||
$result = array();
|
||||
|
||||
for ($i = 0; $i < $numCalls; $i++)
|
||||
{
|
||||
$call = $calls->arraymem($i);
|
||||
$result[$i] = _xmlrpcs_multicall_do_call($server, $call);
|
||||
}
|
||||
|
||||
return new xmlrpcresp(new xmlrpcval($result, 'array'));
|
||||
}
|
||||
|
||||
$_xmlrpcs_dmap=array(
|
||||
'system.listMethods' => array(
|
||||
'function' => '_xmlrpcs_listMethods',
|
||||
'signature' => $_xmlrpcs_listMethods_sig,
|
||||
'docstring' => $_xmlrpcs_listMethods_doc),
|
||||
'system.methodHelp' => array(
|
||||
'function' => '_xmlrpcs_methodHelp',
|
||||
'signature' => $_xmlrpcs_methodHelp_sig,
|
||||
'docstring' => $_xmlrpcs_methodHelp_doc),
|
||||
'system.methodSignature' => array(
|
||||
'function' => '_xmlrpcs_methodSignature',
|
||||
'signature' => $_xmlrpcs_methodSignature_sig,
|
||||
'docstring' => $_xmlrpcs_methodSignature_doc),
|
||||
'system.multicall' => array(
|
||||
'function' => '_xmlrpcs_multicall',
|
||||
'signature' => $_xmlrpcs_multicall_sig,
|
||||
'docstring' => $_xmlrpcs_multicall_doc
|
||||
)
|
||||
);
|
||||
|
||||
$_xmlrpc_debuginfo='';
|
||||
function xmlrpc_debugmsg($m)
|
||||
{
|
||||
global $_xmlrpc_debuginfo;
|
||||
$_xmlrpc_debuginfo=$_xmlrpc_debuginfo . $m . "\n";
|
||||
}
|
||||
|
||||
class xmlrpc_server
|
||||
{
|
||||
var $dmap=array();
|
||||
|
||||
function xmlrpc_server($dispMap='', $serviceNow=1)
|
||||
{
|
||||
global $HTTP_RAW_POST_DATA;
|
||||
// dispMap is a dispatch array of methods
|
||||
// mapped to function names and signatures
|
||||
// if a method
|
||||
// doesn't appear in the map then an unknown
|
||||
// method error is generated
|
||||
/* milosch - changed to make passing dispMap optional.
|
||||
* instead, you can use the class add_to_map() function
|
||||
* to add functions manually (borrowed from SOAPX4)
|
||||
*/
|
||||
if($dispMap)
|
||||
{
|
||||
$this->dmap = $dispMap;
|
||||
if($serviceNow)
|
||||
{
|
||||
$this->service();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function serializeDebug()
|
||||
{
|
||||
global $_xmlrpc_debuginfo;
|
||||
if ($_xmlrpc_debuginfo!='')
|
||||
{
|
||||
return "<!-- DEBUG INFO:\n\n" . $_xmlrpc_debuginfo . "\n-->\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
function service()
|
||||
{
|
||||
global $xmlrpc_defencoding;
|
||||
|
||||
$r=$this->parseRequest();
|
||||
$payload='<?xml version="1.0" encoding="' . $xmlrpc_defencoding . '"?>' . "\n"
|
||||
. $this->serializeDebug()
|
||||
. $r->serialize();
|
||||
Header("Content-type: text/xml\r\nContent-length: " .
|
||||
strlen($payload));
|
||||
print $payload;
|
||||
}
|
||||
|
||||
/*
|
||||
add a method to the dispatch map
|
||||
*/
|
||||
function add_to_map($methodname,$function,$sig,$doc)
|
||||
{
|
||||
$this->dmap[$methodname] = array(
|
||||
'function' => $function,
|
||||
'signature' => $sig,
|
||||
'docstring' => $doc
|
||||
);
|
||||
}
|
||||
|
||||
function verifySignature($in, $sig)
|
||||
{
|
||||
for($i=0; $i<sizeof($sig); $i++)
|
||||
{
|
||||
// check each possible signature in turn
|
||||
$cursig=$sig[$i];
|
||||
if (sizeof($cursig)==$in->getNumParams()+1)
|
||||
{
|
||||
$itsOK=1;
|
||||
for($n=0; $n<$in->getNumParams(); $n++)
|
||||
{
|
||||
$p=$in->getParam($n);
|
||||
// print "<!-- $p -->\n";
|
||||
if ($p->kindOf() == 'scalar')
|
||||
{
|
||||
$pt=$p->scalartyp();
|
||||
}
|
||||
else
|
||||
{
|
||||
$pt=$p->kindOf();
|
||||
}
|
||||
// $n+1 as first type of sig is return type
|
||||
if ($pt != $cursig[$n+1])
|
||||
{
|
||||
$itsOK=0;
|
||||
$pno=$n+1; $wanted=$cursig[$n+1]; $got=$pt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($itsOK)
|
||||
{
|
||||
return array(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return array(0, "Wanted ${wanted}, got ${got} at param ${pno})");
|
||||
}
|
||||
|
||||
function parseRequest($data='')
|
||||
{
|
||||
global $_xh,$HTTP_RAW_POST_DATA;
|
||||
global $xmlrpcerr, $xmlrpcstr, $xmlrpcerrxml, $xmlrpc_defencoding,
|
||||
$_xmlrpcs_dmap;
|
||||
|
||||
if ($data=="")
|
||||
{
|
||||
$data=$HTTP_RAW_POST_DATA;
|
||||
}
|
||||
$parser = xml_parser_create($xmlrpc_defencoding);
|
||||
|
||||
$_xh[$parser]=array();
|
||||
$_xh[$parser]['st']='';
|
||||
$_xh[$parser]['cm']=0;
|
||||
$_xh[$parser]['isf']=0;
|
||||
$_xh[$parser]['params']=array();
|
||||
$_xh[$parser]['method']='';
|
||||
|
||||
// decompose incoming XML into request structure
|
||||
|
||||
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
|
||||
xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee');
|
||||
xml_set_character_data_handler($parser, 'xmlrpc_cd');
|
||||
xml_set_default_handler($parser, 'xmlrpc_dh');
|
||||
if (!xml_parse($parser, $data, 1))
|
||||
{
|
||||
// return XML error as a faultCode
|
||||
$r=new xmlrpcresp(0,
|
||||
$xmlrpcerrxml+xml_get_error_code($parser),
|
||||
sprintf("XML error: %s at line %d",
|
||||
xml_error_string(xml_get_error_code($parser)),
|
||||
xml_get_current_line_number($parser)));
|
||||
xml_parser_free($parser);
|
||||
}
|
||||
else
|
||||
{
|
||||
xml_parser_free($parser);
|
||||
$m=new xmlrpcmsg($_xh[$parser]['method']);
|
||||
// now add parameters in
|
||||
$plist="";
|
||||
for($i=0; $i<sizeof($_xh[$parser]['params']); $i++)
|
||||
{
|
||||
//print "<!-- " . $_xh[$parser]['params'][$i]. "-->\n";
|
||||
$plist.="$i - " . $_xh[$parser]['params'][$i]. " \n";
|
||||
eval('$m->addParam(' . $_xh[$parser]['params'][$i]. ");");
|
||||
}
|
||||
// uncomment this to really see what the server's getting!
|
||||
// xmlrpc_debugmsg($plist);
|
||||
|
||||
$r = $this->execute($m);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
function execute ($m)
|
||||
{
|
||||
global $xmlrpcerr, $xmlrpcstr, $_xmlrpcs_dmap;
|
||||
// now to deal with the method
|
||||
$methName = $m->method();
|
||||
$sysCall = ereg("^system\.", $methName);
|
||||
$dmap = $sysCall ? $_xmlrpcs_dmap : $this->dmap;
|
||||
|
||||
if (!isset($dmap[$methName]['function']))
|
||||
{
|
||||
// No such method
|
||||
return new xmlrpcresp(0,
|
||||
$xmlrpcerr['unknown_method'],
|
||||
$xmlrpcstr['unknown_method']);
|
||||
}
|
||||
|
||||
// Check signature.
|
||||
if (isset($dmap[$methName]['signature']))
|
||||
{
|
||||
$sig = $dmap[$methName]['signature'];
|
||||
list ($ok, $errstr) = $this->verifySignature($m, $sig);
|
||||
if (!$ok)
|
||||
{
|
||||
// Didn't match.
|
||||
return new xmlrpcresp(0,
|
||||
$xmlrpcerr['incorrect_params'],
|
||||
$xmlrpcstr['incorrect_params'] . ": ${errstr}");
|
||||
}
|
||||
}
|
||||
|
||||
$func = $dmap[$methName]['function'];
|
||||
|
||||
if ($sysCall)
|
||||
{
|
||||
return call_user_func($func, $this, $m);
|
||||
}
|
||||
else
|
||||
{
|
||||
return call_user_func($func, $m);
|
||||
}
|
||||
}
|
||||
|
||||
function echoInput()
|
||||
{
|
||||
global $HTTP_RAW_POST_DATA;
|
||||
|
||||
// a debugging routine: just echos back the input
|
||||
// packet as a string value
|
||||
|
||||
$r=new xmlrpcresp;
|
||||
$r->xv=new xmlrpcval( "'Aha said I: '" . $HTTP_RAW_POST_DATA, 'string');
|
||||
print $r->serialize();
|
||||
}
|
||||
}
|
||||
?>
|
181
livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php
Normal file
181
livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php
Normal file
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
// $Id: xrLocStor.php,v 1.1 2004/09/12 21:59:27 tomas Exp $
|
||||
include_once "xmlrpc.inc";
|
||||
include_once "xmlrpcs.inc";
|
||||
require_once '../conf.php';
|
||||
require_once 'DB.php';
|
||||
require_once '../GreenBox.php';
|
||||
require_once '../LocStor.php';
|
||||
|
||||
#PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_WARNING);
|
||||
#PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errCallBack');
|
||||
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||
#PEAR::setErrorHandling(PEAR_ERROR_PRINT);
|
||||
|
||||
function errCallBack($err)
|
||||
{
|
||||
echo "<pre>gm:\n".$err->getMessage()."\ndi:\n".$err->getDebugInfo()."\nui:\n".$err->getUserInfo()."\n";
|
||||
echo "<hr>BackTrace:\n";
|
||||
print_r($err->backtrace);
|
||||
echo "</pre>\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
$dbc = DB::connect($config['dsn'], TRUE);
|
||||
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
|
||||
function v2xr($var, $struct=true){
|
||||
if(is_array($var)){
|
||||
$r = array();
|
||||
foreach($var as $k=>$v) if($struct) $r[$k]=v2xr($v); else $r[]=v2xr($v);
|
||||
return new xmlrpcval($r, ($struct ? "struct" : "array"));
|
||||
}else if(is_int($var)){
|
||||
return new xmlrpcval($var, "int");
|
||||
}else if(is_bool($var)){
|
||||
return new xmlrpcval($var, "boolean");
|
||||
}else{
|
||||
return new xmlrpcval($var, "string");
|
||||
}
|
||||
}
|
||||
|
||||
class XR_LocStor extends LocStor{
|
||||
function _xr_getPars($input)
|
||||
{
|
||||
$p = $input->getParam(0);
|
||||
if(isset($p) && $p->scalartyp()=="struct"){
|
||||
$p->structreset(); $r = array();
|
||||
while(list($k,$v) = $p->structeach()){ $r[$k] = $v->scalarval(); }
|
||||
return array(TRUE, $r);
|
||||
}
|
||||
else return array(FALSE, new xmlrpcresp(0, 801, "xr_login: wrong 1st parameter, struct expected."));
|
||||
}
|
||||
function xr_test($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
return new xmlrpcresp(v2xr(array(
|
||||
'str'=>strtoupper($r['teststring']),
|
||||
'login'=>$this->getSessLogin($r['sessid']),
|
||||
'sessid'=>$r['sessid']
|
||||
), true));
|
||||
}
|
||||
function xr_authenticate($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
$res = $this->authenticate($r['login'], $r['pass']);
|
||||
return new xmlrpcresp(new xmlrpcval($res, "boolean"));
|
||||
}
|
||||
function xr_login($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
if(!($res = $this->login($r['login'], $r['pass'])))
|
||||
return new xmlrpcresp(0, 802, "xr_login: login failed - incorrect username or password.");
|
||||
else
|
||||
return new xmlrpcresp(v2xr($res, false));
|
||||
}
|
||||
function xr_logout($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
$res = $this->logout($r['sessid']);
|
||||
if(!PEAR::isError($res)) return new xmlrpcresp(v2xr('Bye', false));
|
||||
else return new xmlrpcresp(0, 803, "xr_logout: logout failed - not logged.");
|
||||
}
|
||||
function xr_existsAudioClip($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
# $this->debugLog(join(', ', $r));
|
||||
$res = $this->existsAudioClip($r['sessid'], $r['gunid']);
|
||||
# $this->debugLog($res);
|
||||
if(PEAR::isError($res))
|
||||
return new xmlrpcresp(0, 803, "xr_existsAudioClip: ".$res->getMessage()." ".$res->getUserInfo());
|
||||
return new xmlrpcresp(new xmlrpcval($res, "boolean"));
|
||||
}
|
||||
function xr_storeAudioClip($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
$res = $this->storeAudioClip($r['sessid'], $r['gunid'], $r['mediaFileLP'], $r['mdataFileLP']);
|
||||
if(!PEAR::isError($res)) return new xmlrpcresp(new xmlrpcval($res, "string"));
|
||||
else return new xmlrpcresp(0, 803, "xr_storeAudioClip: ".$res->getMessage()." ".$res->getUserInfo());
|
||||
}
|
||||
function xr_deleteAudioClip($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
$res = $this->deleteAudioClip($r['sessid'], $r['gunid']);
|
||||
if(!PEAR::isError($res)) return new xmlrpcresp(new xmlrpcval($res, "boolean"));
|
||||
else return new xmlrpcresp(0, 803, "xr_deleteAudioClip: ".$res->getMessage()." ".$res->getUserInfo());
|
||||
}
|
||||
function xr_updateAudioClipMetadata($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
$res = $this->updateAudioClipMetadata($r['sessid'], $r['gunid'], $r['mdataFileLP']);
|
||||
if(!PEAR::isError($res)) return new xmlrpcresp(new xmlrpcval($res, "boolean"));
|
||||
else return new xmlrpcresp(0, 803, "xr_updateAudioClip: ".$res->getMessage()." ".$res->getUserInfo());
|
||||
}
|
||||
function xr_searchMetadata($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
$res = $this->searchMetadata($r['sessid'], $r['criteria']);
|
||||
if(!PEAR::isError($res)) return new xmlrpcresp(new xmlrpcval($res, "boolean"));
|
||||
else return new xmlrpcresp(0, 803, "xr_searchAudioClip: ".$res->getMessage()." ".$res->getUserInfo());
|
||||
}
|
||||
function xr_accessRawAudioData($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
$res = $this->accessRawAudioData($r['sessid'], $r['gunid']);
|
||||
if(!PEAR::isError($res)) return new xmlrpcresp(new xmlrpcval($res, "string"));
|
||||
else return new xmlrpcresp(0, 803, "xr_accessRawAudioData: ".$res->getMessage()." ".$res->getUserInfo());
|
||||
}
|
||||
function xr_releaseRawAudioData($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
$res = $this->releaseRawAudioData($r['sessid'], $r['tmpLink']);
|
||||
if(!PEAR::isError($res)) return new xmlrpcresp(new xmlrpcval($res, "boolean"));
|
||||
else return new xmlrpcresp(0, 803, "xr_releaseRawAudioData: ".$res->getMessage()." ".$res->getUserInfo());
|
||||
}
|
||||
function xr_getAudioClip($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
$res = $this->getAudioClip($r['sessid'], $r['gunid'], $r['metaData']);
|
||||
if(!PEAR::isError($res)) return new xmlrpcresp(new xmlrpcval($res, "string"));
|
||||
else return new xmlrpcresp(0, 803, "xr_getAudioClip: ".$res->getMessage()." ".$res->getUserInfo());
|
||||
}
|
||||
}
|
||||
|
||||
$locStor = &new XR_LocStor(&$dbc, $config);
|
||||
|
||||
$methods = array(
|
||||
'test' => 'Tests toupper and checks sessid, params: teststring, sessid.',
|
||||
'authenticate' => 'Checks authentication.',
|
||||
'login' => 'Login to storage.',
|
||||
'logout' => 'Logout from storage.',
|
||||
'existsAudioClip' => 'Checks if an Audio clip with the specified id is stored in local storage.',
|
||||
'storeAudioClip' => 'Store a new audio clip or replace an existing one.',
|
||||
'deleteAudioClip' => 'Delete an existing Audio clip.',
|
||||
'updateAudioClipMetadata' => 'Update the metadata of an Audio clip stored in Local storage.',
|
||||
'searchMetadata' => 'Search through the metadata of stored AudioClips, and return all matching clip ids.',
|
||||
'accessRawAudioData' => 'Get access to raw audio data of an AudioClip.',
|
||||
'releaseRawAudioData' => 'Release access for raw audio data.',
|
||||
'getAudioClip' => 'Return the contents of an Audio clip.'
|
||||
);
|
||||
|
||||
$defs = array();
|
||||
foreach($methods as $method=>$description){
|
||||
$defs["locstor.$method"] = array(
|
||||
"function" => array(&$locStor, "xr_$method"),
|
||||
"signature" => array(array($xmlrpcStruct, $xmlrpcStruct)),
|
||||
"docstring" => $description
|
||||
);
|
||||
}
|
||||
$s=new xmlrpc_server( $defs );
|
||||
?>
|
112
livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py
Executable file
112
livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.py
Executable file
|
@ -0,0 +1,112 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (c) 2004 Media Development Loan Fund
|
||||
#
|
||||
# This file is part of the LiveSupport project.
|
||||
# http://livesupport.campware.org/
|
||||
# To report bugs, send an e-mail to bugs@campware.org
|
||||
#
|
||||
# LiveSupport is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# LiveSupport is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with LiveSupport; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# Author : $Author: tomas $
|
||||
# Version : $Revision: 1.1 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/Attic/xr_cli_test.py,v $
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
from xmlrpclib import *
|
||||
import sys
|
||||
|
||||
if len(sys.argv)<3:
|
||||
print """
|
||||
Usage: xr_cli_pok.py [-v] [-s http://<server>/<path>/xmlrpc/xrGreenBox.php] <command> <args>
|
||||
commands and args:
|
||||
listMethods
|
||||
methodHelp <method>
|
||||
methodSignature <method>
|
||||
test <session_id> <teststring>
|
||||
login <username> <password>
|
||||
authenticate <username> <password>
|
||||
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>
|
||||
"""
|
||||
sys.exit(1)
|
||||
|
||||
pars = sys.argv
|
||||
verbose=0
|
||||
if pars[1]=="-v":
|
||||
pars.pop(1)
|
||||
verbose=1
|
||||
if pars[1]=="-s":
|
||||
pars.pop(1)
|
||||
serverPath = pars.pop(1)
|
||||
else:
|
||||
serverPath = 'http://localhost:80/storage/xmlrpc/xrLocStor.php'
|
||||
server = Server(serverPath)
|
||||
method = pars.pop(1)
|
||||
pars.pop(0)
|
||||
if verbose:
|
||||
print "method: "+method
|
||||
print "pars: "
|
||||
print pars
|
||||
print "result:"
|
||||
#sys.exit(0)
|
||||
|
||||
try:
|
||||
if method=="listMethods":
|
||||
print server.system.listMethods()
|
||||
elif method=="methodHelp":
|
||||
print server.system.methodHelp(pars[0])
|
||||
elif method=="methodSignature":
|
||||
print server.system.methodSignature(pars[0])
|
||||
elif method=="test":
|
||||
print server.locstor.test({'sessid':pars[0], 'teststring':pars[1]})
|
||||
elif method=="authenticate":
|
||||
print server.locstor.authenticate({'login':pars[0], 'pass':pars[1]})
|
||||
elif method=="login":
|
||||
print server.locstor.login({'login':pars[0], 'pass':pars[1]})
|
||||
elif method=="logout":
|
||||
print server.locstor.logout({'sessid':pars[0]})
|
||||
elif method=="existsAudioClip":
|
||||
print server.locstor.existsAudioClip({'sessid':pars[0], 'gunid':pars[1]} )
|
||||
elif method=="storeAudioClip":
|
||||
print server.locstor.storeAudioClip({'sessid':pars[0], 'gunid':pars[1], 'mediaFileLP':pars[2], 'mdataFileLP':pars[3]})
|
||||
elif method=="deleteAudioClip":
|
||||
print server.locstor.deleteAudioClip({'sessid':pars[0], 'gunid':pars[1]})
|
||||
elif method=="updateAudioClipMetadata":
|
||||
print server.locstor.updateAudioClipMetadata({'sessid':pars[0], 'gunid':pars[1], 'mdataFileLP':pars[2]})
|
||||
elif method=="searchMetadata":
|
||||
print server.locstor.searchMetadata({'sessid':pars[0], 'criteria':pars[1]})
|
||||
elif method=="accessRawAudioData":
|
||||
print server.locstor.accessRawAudioData({'sessid':pars[0], 'gunid':pars[1]})
|
||||
elif method=="releaseRawAudioData":
|
||||
print server.locstor.releaseRawAudioData({'sessid':pars[0], 'tmpLink':pars[1]})
|
||||
elif method=="getAudioClip":
|
||||
print server.locstor.getAudioClip({'sessid':pars[0], 'gunid':pars[1]})
|
||||
else:
|
||||
print "Unknown command: "+method
|
||||
sys.exit(1)
|
||||
except Error, v:
|
||||
print "XML-RPC Error:",v
|
Loading…
Add table
Add a link
Reference in a new issue