From d086760277a3d2c7c687485692b6f3a6520c2eab Mon Sep 17 00:00:00 2001 From: tomas Date: Wed, 29 Sep 2004 01:37:40 +0000 Subject: [PATCH] Major changes in transport layer and xmlrpc interface. Transport prepared for search jobs. --- livesupport/modules/archiveServer/Makefile | 18 +- livesupport/modules/archiveServer/doc/INSTALL | 2 +- .../modules/archiveServer/var/Archive.php | 211 ++- .../modules/archiveServer/var/conf.php | 18 +- .../archiveServer/var/html/gbHtmlBrowse.php | 2 +- .../archiveServer/var/html/gbHtmlLogin.php | 6 +- .../archiveServer/var/html/gbHtmlPerms.php | 4 +- .../archiveServer/var/html/gbHtmlSubj.php | 4 +- .../archiveServer/var/install/install.php | 6 +- livesupport/modules/archiveServer/var/put.cgi | 83 + .../archiveServer/var/xmlrpc/xmlrpc.inc | 1489 ----------------- .../archiveServer/var/xmlrpc/xmlrpcs.inc | 450 ----- .../archiveServer/var/xmlrpc/xrArchive.php | 148 +- 13 files changed, 363 insertions(+), 2078 deletions(-) create mode 100755 livesupport/modules/archiveServer/var/put.cgi delete mode 100644 livesupport/modules/archiveServer/var/xmlrpc/xmlrpc.inc delete mode 100644 livesupport/modules/archiveServer/var/xmlrpc/xmlrpcs.inc diff --git a/livesupport/modules/archiveServer/Makefile b/livesupport/modules/archiveServer/Makefile index 453fbf020..7224744ae 100644 --- a/livesupport/modules/archiveServer/Makefile +++ b/livesupport/modules/archiveServer/Makefile @@ -20,7 +20,7 @@ # # # Author : $Author: tomas $ -# Version : $Revision: 1.1 $ +# Version : $Revision: 1.2 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/archiveServer/Attic/Makefile,v $ # # @configure_input@ @@ -62,13 +62,15 @@ USR_LIB_DIR = ${USR_DIR}/lib DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config -HTTP_GROUP = apache -#HTTP_GROUP = nobody +GET_GNAME = install/getGname.php +WWW_ROOT := $(shell cd ../storageServer/var/install; php -q getWwwRoot.php) +HTTP_GROUP := $(shell curl -s ${WWW_ROOT}/${GET_GNAME}) PHP_DIR = ${BASE_DIR}/var INSTALL_DIR = ${PHP_DIR}/install STOR_DIR = ${PHP_DIR}/stor ACCESS_DIR = ${PHP_DIR}/access +TRANS_DIR = ${PHP_DIR}/trans BUFF_DIR = ${STOR_DIR}/buffer TEST_RUNNER = ${PHP_DIR}/xmlrpc/testRunner.sh @@ -95,12 +97,15 @@ TEST_RUNNER = ${PHP_DIR}/xmlrpc/testRunner.sh all: dir_setup db_init -dir_setup: ${DOXYGEN_DIR} ${STOR_DIR} ${ACCESS_DIR} +dir_setup: ${DOXYGEN_DIR} ${STOR_DIR} ${ACCESS_DIR} ${TRANS_DIR} doc: ${DOXYGEN} ${DOXYGEN_CONFIG} clean: db_clean + ${RMDIR} ${STOR_DIR} + ${RMDIR} ${ACCESS_DIR} + ${RMDIR} ${TRANS_DIR} docclean: ${RMDIR} ${DOXYGEN_DIR}/html @@ -141,6 +146,11 @@ ${ACCESS_DIR}: chown .${HTTP_GROUP} ${ACCESS_DIR} chmod g+ws ${ACCESS_DIR} +${TRANS_DIR}: + ${MKDIR} ${TRANS_DIR} + chown .${HTTP_GROUP} ${TRANS_DIR} + chmod g+ws ${TRANS_DIR} + ${BUFF_DIR}: ${MKDIR} ${BUFF_DIR} chmod g+w ${BUFF_DIR} diff --git a/livesupport/modules/archiveServer/doc/INSTALL b/livesupport/modules/archiveServer/doc/INSTALL index 14f4f44b1..71082d31d 100644 --- a/livesupport/modules/archiveServer/doc/INSTALL +++ b/livesupport/modules/archiveServer/doc/INSTALL @@ -8,7 +8,7 @@ Install steps for file uploading (do it with appropriate changes): 2) move put.cgi there from var subdir 3) add to apache2 config (i.g. commonapache2.conf): - + Script PUT /cgi-bin-put/put.cgi ScriptAlias /cgi-bin-put/ "/usr/local/apache2/cgi-bin-put/" diff --git a/livesupport/modules/archiveServer/var/Archive.php b/livesupport/modules/archiveServer/var/Archive.php index a36dee141..6a26aaddf 100644 --- a/livesupport/modules/archiveServer/var/Archive.php +++ b/livesupport/modules/archiveServer/var/Archive.php @@ -23,130 +23,195 @@ Author : $Author: tomas $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/archiveServer/var/Archive.php,v $ ------------------------------------------------------------------------------*/ require_once "../../../storageServer/var/LocStor.php"; -$config['archiveUrlPath'] = '/livesupport/modules/archiveServer/var'; -$config['archiveXMLRPC'] = 'xmlrpc/xrArchive.php'; -$config['archiveUrlHost'] = 'localhost'; -$config['archiveUrlPort'] = 80; -$config['archiveAccountLogin'] = 'root'; -$config['archiveAccountPass'] = 'q'; - /** * Extension to StorageServer to act as ArchiveServer */ class Archive extends LocStor{ /** - * Open download + * Constructor */ - function downloadOpen($sessid, $gunid) + function Archive(&$dbc, $config) { - // access - $lnk = $this->accessRawAudioData($sessid, $gunid); - if(PEAR::isError($lnk)) return $lnk; - // return tmpurl, fname, md5h - $url = $this->_lnk2url($lnk); - $md5h = $this->_md5sum($lnk); - return array('url'=>$url, 'md5h'=>$md5h, 'fname'=>basename($lnk)); + parent::LocStor(&$dbc, $config); + $this->transDir = $config['transDir']; } - - + + /* ======================================================= upload methods */ + /** - * Close download + * Open file upload + * + * @param sessid string - session id + * @param trid string - transport id + * @param type string - media|metadata|search + * @return array(url string) or error */ - function downloadClose($sessid, $url) + function uploadOpen($sessid, $trid, $type) { - // release - $lnk = $this->_url2lnk($url); - $res = $this->releaseRawAudioData($sessid, $lnk); - return $res; - } - - - /** - * Open upload - */ - function uploadOpen($sessid, $gunid) - { - $fname = "{$this->storageDir}/buffer/$gunid"; - if(!$fp = fopen($fname, 'w')) return PEAR::raiseError( + $file = "{$this->transDir}/$trid"; + if(!$fp = fopen($file, 'w')) return PEAR::raiseError( "Archive::uploadOpen: unable to create blank file" ); fclose($fp); - $res = $this->storeAudioClip($sessid, $gunid, $fname, ''); - if(PEAR::isError($res)) return $res; - $lnk = $this->accessRawAudioData($sessid, $gunid); - if(PEAR::isError($lnk)) return $lnk; - $url = $this->_lnk2url($lnk); + $host = $this->config['archiveUrlHost']; + $port = $this->config['archiveUrlPort']; + $path = $this->config['archiveUrlPath']; + $url = "http://$host:$port$path/trans/".basename($file); return array('url'=>$url); } - /** - * Abort upload - */ - function uploadAbort($sessid, $url) - { - $lnk = $this->_url2lnk($url); - $res = $this->releaseRawAudioData($sessid, $lnk); - return $res; - } - - - /** - * Check upload + * Check uploaded file + * + * @param sessid string - session id + * @param url string + * @return array(md5h string, size int, url string) */ function uploadCheck($sessid, $url) { - $lnk = $this->_url2lnk($url); - $md5h = $this->_md5sum($lnk); - $size = filesize($lnk); + $file = "{$this->transDir}/".basename($url); + $md5h = $this->_md5sum($file); + $size = filesize($file); return array('md5h'=>$md5h, 'size'=>$size, 'url'=>$url); } /** - * Close upload + * Close file upload + * + * @param sessid string - session id + * @param url string + * @param type string - media|metadata|search + * @param gunid string - global unique id + * @return boolean or error */ - function uploadClose($sessid, $url, $type='file') + function uploadClose($sessid, $url, $type, $gunid) + { + $file = "{$this->transDir}/".basename($url); + $res = $this->processUploaded($sessid, $file, $type, $gunid); + return $res; + } + + /** + * Process uploaded file - insert to the storage + * + * @param sessid string - session id + * @param file string - absolute local pathname + * @param type string - media|metadata|search + * @param gunid string - global unique id + * @return boolean or error + */ + function processUploaded($sessid, $file, $type, $gunid='X') { switch($type){ - default: // case"file": - // release - $lnk = $this->_url2lnk($url); - $res = $this->releaseRawAudioData($sessid, $lnk); - return $res; + case 'media': + if(!file_exists($file)) break; + $res = $this->storeAudioClip($sessid, $gunid, + $file, ''); + if(PEAR::isError($res)) return $res; + @unlink($file); break; - case"search": - // localSearch - // return results + case 'metadata': + case 'mdata': + if(!file_exists($file)) break; + $res = $this->updateAudioClipMetadata($sessid, $gunid, + $file); + if(PEAR::isError($res)){ + // catch valid exception + if($res->getCode() == GBERR_FOBJNEX){ + $res2 = $this->storeAudioClip($sessid, $gunid, + '', $file); + if(PEAR::isError($res2)) return $res2; + }else return $res; + } + @unlink($file); + break; + case 'search': + return PEAR::raiseError("Archive::processUploaded: search not implemented"); + /* + rename($file, $file."_"); + $criteria = unserialize(file_get_contents($file_)); + $res = $this->searchMetadata($sessid, $criteria); + $fh = fopen($file, "w"); + fwrite($fh, serialize($res)); + fclose($fh); + @unlink($file."_"); + */ + break; + default: + return PEAR::raiseError("Archive::processUploaded: unknown type ($type)"); break; } + return TRUE; } + /* ===================================================== download methods */ /** - * Translate local symlink to URL + * Open file download * + * @param sessid string - session id + * @param type string media|metadata|search + * @param par string - depends on type */ - function _lnk2url($lnk) + function downloadOpen($sessid, $type, $par) { - return "http://{$this->config['archiveUrlHost']}:{$this->config['archiveUrlPort']}". - "{$this->config['archiveUrlPath']}/access/".basename($lnk); + switch($type){ + case 'media': + case 'metadata': + $gunid = $par; + $res = $this->prepareForTransport('', $gunid, $sessid); + if(PEAR::isError($res)) return $res; + list($mediaFile, $mdataFile, $gunid) = $res; + default: + } + switch($type){ + case 'media': + $fname = $mediaFile; + break; + case 'metadata': + $fname = $mdataFile; + break; + default: + } + $file = "{$this->transDir}/$fname"; + $host = $this->config['archiveUrlHost']; + $port = $this->config['archiveUrlPort']; + $path = $this->config['archiveUrlPath']; + $url = "http://$host:$port$path/trans/$fname"; + $md5h = $this->_md5sum($file); + return array('url'=>$url, 'md5h'=>$md5h, 'fname'=>$fname); } + /** - * Traslate URL to local symlink + * Close file download * + * @param sessid string - session id + * @param url string + * @return boolean */ - function _url2lnk($url) + function downloadClose($sessid, $url) { - return $this->accessDir."/".basename($url); + $file = "{$this->transDir}/".basename($url); + @unlink($file); + return TRUE; } + + /* ==================================================== auxiliary methods */ + + /** + * Returns md5 hash of external file + * + * @param fpath string - local path to file + * @return string + */ function _md5sum($fpath) { $md5h = `md5sum $fpath`; diff --git a/livesupport/modules/archiveServer/var/conf.php b/livesupport/modules/archiveServer/var/conf.php index af580d0be..5d4d27a40 100644 --- a/livesupport/modules/archiveServer/var/conf.php +++ b/livesupport/modules/archiveServer/var/conf.php @@ -23,7 +23,7 @@ Author : $Author: tomas $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/archiveServer/var/conf.php,v $ ------------------------------------------------------------------------------*/ @@ -38,7 +38,7 @@ $config = array( ), 'tblNamePrefix' => 'as_', 'authCookieName'=> 'assid', - 'RootNode' => 'RootNode', + 'RootNode' => 'RootNode', 'tmpRootPass' => 'q', 'objtypes' => array( 'RootNode' => array('Folder'), @@ -58,6 +58,20 @@ $config = array( 'editPrivs', 'write', 'read', 'classes', 'subjects' ), 'storageDir' => dirname(getcwd()).'/stor', + 'bufferDir' => dirname(getcwd()).'/stor/buffer', + 'transDir' => dirname(getcwd()).'/trans', 'accessDir' => dirname(getcwd()).'/access', + +// on central archive side storage=archive + 'storageUrlPath' => '/livesupport/modules/archiveServer/var', + 'storageXMLRPC' => 'xmlrpc/xrArchive.php', + 'storageUrlHost' => 'localhost', + 'storageUrlPort' => 80, +// only for returning right URLs: + 'archiveUrlPath' => '/livesupport/modules/archiveServer/var', + 'archiveXMLRPC' => 'xmlrpc/xrArchive.php', + 'archiveUrlHost' => 'localhost', + 'archiveUrlPort' => 80, + ); ?> \ No newline at end of file diff --git a/livesupport/modules/archiveServer/var/html/gbHtmlBrowse.php b/livesupport/modules/archiveServer/var/html/gbHtmlBrowse.php index d0c40e0f0..321f48233 100644 --- a/livesupport/modules/archiveServer/var/html/gbHtmlBrowse.php +++ b/livesupport/modules/archiveServer/var/html/gbHtmlBrowse.php @@ -77,7 +77,7 @@ $tpldata['showMenu']=true; ?> -Browser +Archive - browser