Added md5 checksum to FILES table in the database. The XML-RPC function call storeAudioClipOpen now returns error code 888 if the file uploaded is a duplicate of an existing file. Started an upgrade script, but still needs a little bit of work. Removed unused className argument to StoredFile::recall functions. Fixed xr_cli_test.php to use Console_GetOpt PEAR class and fixed code formatting. Fixed code documentation. Fixed some function names to conform to coding standards.

This commit is contained in:
paul 2007-01-09 21:11:45 +00:00
parent 1a8610b37b
commit 997814e78a
16 changed files with 524 additions and 600 deletions

View File

@ -313,16 +313,16 @@ class Backup
// if the file is a playlist then it have only meta file // if the file is a playlist then it have only meta file
if (strtolower($sf->md->format)!='playlist') { if (strtolower($sf->md->format)!='playlist') {
$this->filenames[] = array( $this->filenames[] = array(
'filename' => $sf->_getRealRADFname(), // get real filename of raw media data 'filename' => $sf->getRealFileName(),
'format' => $sf->md->format 'format' => $sf->md->format
); );
} }
$this->filenames[] = array( $this->filenames[] = array(
'filename' => $sf->_getRealMDFname(), # get real filename of metadata file 'filename' => $sf->getRealMetadataFileName(),
'format' => $sf->md->format 'format' => $sf->md->format
); );
if ($this->loglevel=='debug') { if ($this->loglevel=='debug') {
$this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames - add file: {$sf->md->format}|".$sf->_getRealMDFname()."\n"); $this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames - add file: {$sf->md->format}|".$sf->getRealMetadataFileName()."\n");
} }
} }
return $this->filenames; return $this->filenames;

View File

@ -239,7 +239,7 @@ class BasicStor {
} }
if (!empty($mdataFileLP) && if (!empty($mdataFileLP) &&
($mdataLoc!='file' || file_exists($mdataFileLP))) { ($mdataLoc!='file' || file_exists($mdataFileLP))) {
$r = $ac->replaceMetaData($mdataFileLP, $mdataLoc); $r = $ac->replaceMetadata($mdataFileLP, $mdataLoc);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -521,14 +521,14 @@ class BasicStor {
$gunid = $ac->gunid; $gunid = $ac->gunid;
switch ($part) { switch ($part) {
case "media": case "media":
$realfile = $ac->_getRealRADFname(); $realfile = $ac->getRealFileName();
$ext = $ac->_getExt(); $ext = $ac->getFileExtension();
$filename = $ac->_getFileName(); $filename = $ac->getFileName();
break; break;
case "metadata": case "metadata":
$realfile = $ac->_getRealMDFname(); $realfile = $ac->getRealMetadataFileName();
$ext = "xml"; $ext = "xml";
$filename = $ac->_getFileName(); $filename = $ac->getFileName();
break; break;
default: default:
return PEAR::raiseError( return PEAR::raiseError(
@ -599,9 +599,8 @@ class BasicStor {
} }
$escapedChsum = pg_escape_string($chsum); $escapedChsum = pg_escape_string($chsum);
$token = StoredFile::CreateGunid(); $token = StoredFile::CreateGunid();
$res = $CC_DBC->query(" $res = $CC_DBC->query("DELETE FROM ".$CC_CONFIG['accessTable']
DELETE FROM ".$CC_CONFIG['accessTable']." WHERE token=x'$token'::bigint ." WHERE token=x'$token'::bigint");
");
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -612,8 +611,7 @@ class BasicStor {
(gunid, token, ext, chsum, type, owner, ts) (gunid, token, ext, chsum, type, owner, ts)
VALUES VALUES
($gunidSql, x'$token'::bigint, ($gunidSql, x'$token'::bigint,
'', '$escapedChsum', 'put', $ownerSql, now()) '', '$escapedChsum', 'put', $ownerSql, now())");
");
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -639,39 +637,52 @@ class BasicStor {
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$token = StoredFile::NormalizeGunid($token); $token = StoredFile::NormalizeGunid($token);
if (!BasicStor::bsCheckToken($token, 'put')) { if (!BasicStor::bsCheckToken($token, 'put')) {
return PEAR::raiseError( return PEAR::raiseError(
"BasicStor::bsClosePut: invalid token ($token)", "BasicStor::bsClosePut: invalid token ($token)",
GBERR_TOKEN GBERR_TOKEN);
);
} }
$row = $CC_DBC->getRow(" $row = $CC_DBC->getRow(
SELECT chsum, owner FROM ".$CC_CONFIG['accessTable']." "SELECT chsum, owner FROM ".$CC_CONFIG['accessTable']
WHERE token=x'{$token}'::bigint ." WHERE token=x'{$token}'::bigint");
");
if (PEAR::isError($row)) { if (PEAR::isError($row)) {
return $row; return $row;
} }
$chsum = $row['chsum'];
$owner = $row['owner'];
$res = $CC_DBC->query("
DELETE FROM ".$CC_CONFIG['accessTable']." WHERE token=x'$token'::bigint
");
if (PEAR::isError($res)) {
return $res;
}
$fname = $CC_CONFIG['accessDir']."/$token"; $fname = $CC_CONFIG['accessDir']."/$token";
$md5sum = md5_file($fname); $md5sum = md5_file($fname);
if (trim($chsum) !='' && $chsum != $md5sum) {
$chsum = $row['chsum'];
$owner = $row['owner'];
$error = null;
if ( (trim($chsum) != '') && ($chsum != $md5sum) ) {
// Delete the file if the checksums do not match.
if (file_exists($fname)) { if (file_exists($fname)) {
@unlink($fname); @unlink($fname);
} }
return PEAR::raiseError( $error = new PEAR_Error(
"BasicStor::bsClosePut: md5sum does not match (token=$token)". "BasicStor::bsClosePut: md5sum does not match (token=$token)".
" [$chsum/$md5sum]", " [$chsum/$md5sum]",
GBERR_PUT GBERR_PUT);
); } else {
// Remember the MD5 sum
$storedFile = StoredFile::recallByToken($token);
if (!PEAR::isError($storedFile)) {
$storedFile->setMd5($md5sum);
} else {
$error = $storedFile;
} }
}
// Delete entry from access table.
$res = $CC_DBC->query("DELETE FROM ".$CC_CONFIG['accessTable']
." WHERE token=x'$token'::bigint");
if (PEAR::isError($error)) {
return $error;
} elseif (PEAR::isError($res)) {
return $res;
}
return array('fname'=>$fname, 'owner'=>$owner); return array('fname'=>$fname, 'owner'=>$owner);
} }
@ -793,7 +804,7 @@ class BasicStor {
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
return $ac->replaceMetaData($mdata, $mdataLoc); return $ac->replaceMetadata($mdata, $mdataLoc);
} }
@ -1157,7 +1168,7 @@ class BasicStor {
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
$MDfname = $ac->md->getFname(); $MDfname = $ac->md->getFileName();
if (PEAR::isError($MDfname)) { if (PEAR::isError($MDfname)) {
return $MDfname; return $MDfname;
} }
@ -1188,11 +1199,11 @@ class BasicStor {
copy($MDfname, "$tmpdc/{$it['gunid']}.xml"); break; copy($MDfname, "$tmpdc/{$it['gunid']}.xml"); break;
} // switch } // switch
} // if file_exists() } // if file_exists()
$RADfname = $ac->_getRealRADFname(); $RADfname = $ac->getRealFileName();
if (PEAR::isError($RADfname)) { if (PEAR::isError($RADfname)) {
return $RADfname; return $RADfname;
} }
$RADext = $ac->_getExt(); $RADext = $ac->getFileExtension();
if (PEAR::isError($RADext)) { if (PEAR::isError($RADext)) {
return $RADext; return $RADext;
} }
@ -1278,9 +1289,7 @@ class BasicStor {
case "xml": case "xml":
case "lspl": case "lspl":
$fname = $plid; $fname = $plid;
$res = $this->bsPutFile($parid, $fname, $res = $this->bsPutFile($parid, $fname, NULL, $path, $plid, 'playlist');
NULL, $path, $plid, 'playlist'
);
break; break;
case "smil": case "smil":
require_once("SmilPlaylist.php"); require_once("SmilPlaylist.php");
@ -1375,8 +1384,7 @@ class BasicStor {
} }
if (!PEAR::isError($res) ) { if (!PEAR::isError($res) ) {
$res = $this->bsPutFile($parid, $gunid, $rawMedia, $metadata, $res = $this->bsPutFile($parid, $gunid, $rawMedia, $metadata,
$gunid, 'audioclip' $gunid, 'audioclip');
);
} }
@unlink("$tmpdc/{$it['rawMedia']}"); @unlink("$tmpdc/{$it['rawMedia']}");
@unlink("$tmpdc/{$it['metadata']}"); @unlink("$tmpdc/{$it['metadata']}");
@ -1449,8 +1457,8 @@ class BasicStor {
} }
$listArr[$i]['gunid'] = $gunid; $listArr[$i]['gunid'] = $gunid;
// THE BUG IS HERE - "_getState()" IS NOT A STATIC FUNCTION! // THE BUG IS HERE - "getState()" IS NOT A STATIC FUNCTION!
if (StoredFile::_getState($gunid) == 'incomplete') { if (StoredFile::getState($gunid) == 'incomplete') {
unset($listArr[$i]); unset($listArr[$i]);
} }
} }
@ -1708,15 +1716,11 @@ class BasicStor {
* @param string $pass * @param string $pass
* @return boolean|sessionId|PEAR_Error * @return boolean|sessionId|PEAR_Error
*/ */
// function login($login, $pass) function login($login, $pass)
// { {
// $r = $this->upgradeDbStructure(); $r = Alib::Login($login, $pass);
// if (PEAR::isError($r)) { return $r;
// return $r; }
// }
// $r = parent::login($login, $pass);
// return $r;
// }
/* ================================================== "protected" methods */ /* ================================================== "protected" methods */
@ -1932,7 +1936,7 @@ class BasicStor {
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
$state = $ac->_getState(); $state = $ac->getState();
if ($p_val) { if ($p_val) {
$r = $ac->setState('edited', $p_subjid); $r = $ac->setState('edited', $p_subjid);
} else { } else {
@ -2135,53 +2139,6 @@ class BasicStor {
} }
/**
* Check and optionally upgrade LS db structure.
* (add column suported only now)
*
* items in array with db changes:
* <ul>
* <li>tbl - table name</li>
* <li>fld - field name</li>
* <li>type - type of field</li>
* </ul>
*
* @return TRUE/error
*/
// function upgradeDbStructure()
// {
// $chDb = array(
// '1.1 Leon' => array(
// array('tbl'=>$this->accessTable, 'fld'=>'owner',
// 'type'=>"int REFERENCES {$this->subjTable}"
// ),
// ),
// '1.1 Freetown' => array(
// array('tbl'=>$this->filesTable, 'fld'=>'mtime',
// 'type'=>'timestamp(6) with time zone'
// ),
// ),
// );
// foreach ($chDb as $version => $chArr) {
// foreach ($chArr as $change) {
// extract($change); // tbl, op, fld, type
// $r = $CC_DBC->tableInfo($tbl, DB_TABLEINFO_ORDERTABLE);
// if (PEAR::isError($r)) {
// return $r;
// }
// if (!isset($r['ordertable'][$tbl][$fld])) {
// $q = "ALTER table $tbl ADD $fld $type";
// $r = $CC_DBC->query($q);
// if (PEAR::isError($r)) {
// return $r;
// }
// }
// }
// }
// return TRUE;
// }
/* =============================================== test and debug methods */ /* =============================================== test and debug methods */
/** /**
* Reset storageServer for debugging. * Reset storageServer for debugging.
@ -2244,10 +2201,7 @@ class BasicStor {
$fname = basename($xml); $fname = basename($xml);
break; break;
} }
$r = $this->bsPutFile( $r = $this->bsPutFile($rootHD, $fname, $media, $xml, $gunid, $type);
$rootHD, $fname,
$media, $xml, $gunid, $type
);
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
@ -2563,164 +2517,6 @@ class BasicStor {
} }
/**
* install - create tables
*
* file states:
* <ul>
* <li>empty</li>
* <li>incomplete</li>
* <li>ready</li>
* <li>edited</li>
* <li>deleted</li>
* </ul>
* file types:
* <ul>
* <li>audioclip</li>
* <li>playlist</li>
* <li>webstream</li>
* </ul>
* access types:
* <ul>
* <li>access</li>
* <li>download</li>
* </ul>
*/
// public function install()
// {
// parent::install();
// $r = $CC_DBC->query("CREATE TABLE {$this->filesTable} (
// id int not null,
// gunid bigint not null, -- global unique ID
// name varchar(255) not null default'', -- human file id ;)
// mime varchar(255) not null default'', -- mime type
// ftype varchar(128) not null default'', -- file type
// state varchar(128) not null default'empty', -- file state
// currentlyaccessing int not null default 0, -- access counter
// editedby int REFERENCES {$this->subjTable}, -- who edits it
// mtime timestamp(6) with time zone -- lst modif.time
// )");
// if (PEAR::isError($r)) {
// return $r;
// }
// $CC_DBC->query("CREATE UNIQUE INDEX {$this->filesTable}_id_idx
// ON {$this->filesTable} (id)");
// $CC_DBC->query("CREATE UNIQUE INDEX {$this->filesTable}_gunid_idx
// ON {$this->filesTable} (gunid)");
// $CC_DBC->query("CREATE INDEX {$this->filesTable}_name_idx
// ON {$this->filesTable} (name)");
//
// $CC_DBC->createSequence("{$this->mdataTable}_id_seq");
// $r = $CC_DBC->query("CREATE TABLE {$this->mdataTable} (
// id int not null,
// gunid bigint,
// 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
// )");
// if (PEAR::isError($r)) {
// return $r;
// }
// $CC_DBC->query("CREATE UNIQUE INDEX {$this->mdataTable}_id_idx
// ON {$this->mdataTable} (id)");
// $CC_DBC->query("CREATE INDEX {$this->mdataTable}_gunid_idx
// ON {$this->mdataTable} (gunid)");
// $CC_DBC->query("CREATE INDEX {$this->mdataTable}_subj_idx
// ON {$this->mdataTable} (subjns, subject)");
// $CC_DBC->query("CREATE INDEX {$this->mdataTable}_pred_idx
// ON {$this->mdataTable} (predns, predicate)");
//
// $r = $CC_DBC->query("CREATE TABLE {$this->accessTable} (
// gunid bigint, -- global unique id
// token bigint, -- access token
// chsum char(32) not null default'', -- md5 checksum
// ext varchar(128) not null default'', -- extension
// type varchar(20) not null default'', -- access type
// parent bigint, -- parent token
// owner int REFERENCES {$this->subjTable}, -- subject have started it
// ts timestamp
// )");
// if (PEAR::isError($r)) {
// return $r;
// }
// $CC_DBC->query("CREATE INDEX {$this->accessTable}_token_idx
// ON {$this->accessTable} (token)");
// $CC_DBC->query("CREATE INDEX {$this->accessTable}_gunid_idx
// ON {$this->accessTable} (gunid)");
// $CC_DBC->query("CREATE INDEX {$this->accessTable}_parent_idx
// ON {$this->accessTable} (parent)");
// if (!file_exists($this->storageDir)) {
// mkdir($this->storageDir, 02775);
// }
// if (!file_exists($this->bufferDir)) {
// mkdir($this->bufferDir, 02775);
// }
// $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
*/
// public function uninstall()
// {
// global $CC_CONFIG, $CC_DBC;
// $CC_DBC->query("DROP TABLE ".$CC_CONFIG['mdataTable']);
// $CC_DBC->dropSequence($CC_CONFIG['mdataTable']."_id_seq");
// $CC_DBC->query("DROP TABLE ".$CC_CONFIG['filesTable']);
// $CC_DBC->query("DROP TABLE ".$CC_CONFIG['accessTable']);
// $d = @dir($CC_CONFIG['storageDir']);
// while (is_object($d) && (false !== ($entry = $d->read()))){
// if (filetype($CC_CONFIG['storageDir']."/$entry")=='dir') {
// if ($entry!='CVS' && $entry!='tmp' && strlen($entry)==3) {
// $dd = dir($CC_CONFIG['storageDir']."/$entry");
// while (false !== ($ee = $dd->read())) {
// if (substr($ee, 0, 1)!=='.') {
// unlink($CC_CONFIG['storageDir']."/$entry/$ee");
// }
// }
// $dd->close();
// rmdir($CC_CONFIG['storageDir']."/$entry");
// }
// }
// }
// if (is_object($d)) {
// $d->close();
// }
// if (file_exists($this->bufferDir)) {
// $d = dir($this->bufferDir);
// while (false !== ($entry = $d->read())) {
// if(substr($entry,0,1)!='.') {
// unlink("{$this->bufferDir}/$entry");
// }
// }
// $d->close();
// @rmdir($this->bufferDir);
// }
// parent::uninstall();
// }
/** /**
* Aux logging for debug * Aux logging for debug
* *

View File

@ -60,18 +60,15 @@ class GreenBox extends BasicStor {
* @param string $ftype * @param string $ftype
* Internal file type * Internal file type
* @return int * @return int
* @exception PEAR::error
*/ */
public function putFile($parid, $fileName, public function putFile($parid, $fileName, $mediaFileLP, $mdataFileLP,
$mediaFileLP, $mdataFileLP, $sessid='', $sessid='', $gunid=NULL, $ftype='audioclip')
$gunid=NULL, $ftype='audioclip')
{ {
if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) {
return $res; return $res;
} }
return $this->bsPutFile( return $this->bsPutFile($parid, $fileName, $mediaFileLP,
$parid, $fileName, $mediaFileLP, $mdataFileLP, $gunid, $ftype $mdataFileLP, $gunid, $ftype);
);
} // fn putFile } // fn putFile

View File

@ -38,17 +38,25 @@ class LocStor extends BasicStor {
* @return array * @return array
* {url:writable URL for HTTP PUT, token:access token} * {url:writable URL for HTTP PUT, token:access token}
*/ */
protected function storeAudioClipOpen( protected function storeAudioClipOpen($sessid, $gunid, $metadata,
$sessid, $gunid, $metadata, $fname, $chsum, $ftype='audioclip' $fname, $chsum, $ftype='audioclip')
)
{ {
// test of gunid format: // Check the gunid format
if (!BasicStor::CheckGunid($gunid)) { if (!BasicStor::CheckGunid($gunid)) {
return PEAR::raiseError( return PEAR::raiseError(
"LocStor::storeAudioClipOpen: Wrong gunid ($gunid)" "LocStor::storeAudioClipOpen: Wrong gunid ($gunid)"
); );
} }
// test if specified gunid exists:
// Check if we already have this file.
if ($duplicate = StoredFile::RecallByMd5($chsum)) {
return PEAR::raiseError(
"LocStor::storeAudioClipOpen: Duplicate file"
." - Matched MD5 against '".$duplicate->getFileName()."'",
888);
}
// Check if specified gunid exists.
$ac =& StoredFile::recallByGunid($gunid); $ac =& StoredFile::recallByGunid($gunid);
if (!PEAR::isError($ac)) { if (!PEAR::isError($ac)) {
// gunid exists - do replace // gunid exists - do replace
@ -61,15 +69,13 @@ class LocStor extends BasicStor {
'LocStor::storeAudioClipOpen: is accessed' 'LocStor::storeAudioClipOpen: is accessed'
); );
} }
$res = $ac->replace( $res = $ac->replace($oid, $ac->name, '', $metadata, 'string');
$oid, $ac->name, '', $metadata, 'string'
);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
} else { } else {
// gunid doesn't exists - do insert: // gunid doesn't exist - do insert:
$tmpFname = uniqid(''); $tmpFname = uniqid();
$parid = $this->_getHomeDirIdFromSess($sessid); $parid = $this->_getHomeDirIdFromSess($sessid);
if (PEAR::isError($parid)) { if (PEAR::isError($parid)) {
return $parid; return $parid;
@ -555,7 +561,7 @@ class LocStor extends BasicStor {
if (($res = BasicStor::Authorize('write', $ac->getId(), $sessid)) !== TRUE) { if (($res = BasicStor::Authorize('write', $ac->getId(), $sessid)) !== TRUE) {
return $res; return $res;
} }
return $ac->replaceMetaData($metadata, 'string'); return $ac->replaceMetadata($metadata, 'string');
} }
@ -692,7 +698,7 @@ class LocStor extends BasicStor {
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
$res = $ac->replaceMetaData($newPlaylist, 'string', 'playlist'); $res = $ac->replaceMetadata($newPlaylist, 'string', 'playlist');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }
@ -729,7 +735,7 @@ class LocStor extends BasicStor {
if (PEAR::isError($mdata)) { if (PEAR::isError($mdata)) {
return $mdata; return $mdata;
} }
$res = $ac->replaceMetaData($mdata, 'string'); $res = $ac->replaceMetadata($mdata, 'string');
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
} }

View File

@ -473,7 +473,7 @@ class LsPlaylistAudioClip
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
$RADext = $ac->_getExt(); $RADext = $ac->getFileExtension();
if (PEAR::isError($RADext)) { if (PEAR::isError($RADext)) {
return $RADext; return $RADext;
} }
@ -493,7 +493,7 @@ class LsPlaylistAudioClip
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
$RADext = $ac->_getExt(); $RADext = $ac->getFileExtension();
if (PEAR::isError($RADext)) { if (PEAR::isError($RADext)) {
return $RADext; return $RADext;
} }
@ -512,7 +512,7 @@ class LsPlaylistAudioClip
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
$RADext = $ac->_getExt(); $RADext = $ac->getFileExtension();
if (PEAR::isError($RADext)) { if (PEAR::isError($RADext)) {
return $RADext; return $RADext;
} }

View File

@ -29,8 +29,6 @@ class MetaData {
public $exists; public $exists;
/** /**
* @param Greenbox $gb
* A reference to GreenBox object
* @param string $gunid * @param string $gunid
* global unique id * global unique id
* @param string $resDir * @param string $resDir
@ -40,7 +38,7 @@ class MetaData {
{ {
$this->gunid = $gunid; $this->gunid = $gunid;
$this->resDir = $resDir; $this->resDir = $resDir;
$this->fname = $this->makeFname(); $this->fname = $this->makeFileName();
$this->exists = null; $this->exists = null;
} }
@ -554,7 +552,7 @@ class MetaData {
* *
* @return string * @return string
*/ */
private function makeFname() private function makeFileName()
{ {
return "{$this->resDir}/{$this->gunid}.xml"; return "{$this->resDir}/{$this->gunid}.xml";
} }
@ -565,7 +563,7 @@ class MetaData {
* *
* @return string * @return string
*/ */
public function getFname() public function getFileName()
{ {
return $this->fname; return $this->fname;
} }

View File

@ -17,7 +17,6 @@
*/ */
function camp_add_metadata(&$p_mdata, $p_key, $p_val, $p_inputEncoding='iso-8859-1') function camp_add_metadata(&$p_mdata, $p_key, $p_val, $p_inputEncoding='iso-8859-1')
{ {
#echo "$key($iEnc): $val\n";
if (!is_null($p_val)) { if (!is_null($p_val)) {
$data = $p_val; $data = $p_val;
$outputEncoding = 'UTF-8'; $outputEncoding = 'UTF-8';
@ -69,7 +68,6 @@ function camp_get_audio_metadata($p_filename, $p_testonly = false)
if (isset($infoFromFile['error'])) { if (isset($infoFromFile['error'])) {
return new PEAR_Error(array_pop($infoFromFile['error'])); return new PEAR_Error(array_pop($infoFromFile['error']));
} }
#if(!$infoFromFile['fileformat']){ echo "???\n"; continue; }
if (!$infoFromFile['bitrate']) { if (!$infoFromFile['bitrate']) {
return new PEAR_Error("File given is not an audio file."); return new PEAR_Error("File given is not an audio file.");
} }
@ -241,11 +239,8 @@ class RawMediaData {
{ {
$this->gunid = $gunid; $this->gunid = $gunid;
$this->resDir = $resDir; $this->resDir = $resDir;
$this->fname = $this->makeFname(); $this->fname = $this->makeFileName();
$this->exists = $this->exists = is_file($this->fname) && is_readable($this->fname);
is_file($this->fname) &&
is_readable($this->fname)
;
} }
@ -256,8 +251,7 @@ class RawMediaData {
* local path * local path
* @param boolean $copyMedia * @param boolean $copyMedia
* copy the media file if true, make symlink if false * copy the media file if true, make symlink if false
* @return mixed * @return TRUE|PEAR_Error
* true or PEAR::error
*/ */
function insert($mediaFileLP, $copyMedia=TRUE) function insert($mediaFileLP, $copyMedia=TRUE)
{ {
@ -292,9 +286,9 @@ class RawMediaData {
/** /**
* Delete and insert media file * Delete and insert media file
* *
* @param string $mediaFileLP, local path * @param string $mediaFileLP
* @return mixed * local path
* true or PEAR::error * @return TRUE|PEAR_Error
*/ */
function replace($mediaFileLP) function replace($mediaFileLP)
{ {
@ -326,7 +320,7 @@ class RawMediaData {
* *
* @return string * @return string
*/ */
function getFname() function getFileName()
{ {
return $this->fname; return $this->fname;
} }
@ -335,8 +329,7 @@ class RawMediaData {
/** /**
* Delete media file from filesystem * Delete media file from filesystem
* *
* @return mixed * @return boolean|PEAR_Error
* boolean or PEAR::error
*/ */
function delete() function delete()
{ {
@ -399,7 +392,7 @@ class RawMediaData {
* *
* @return string * @return string
*/ */
function makeFname() function makeFileName()
{ {
return "{$this->resDir}/{$this->gunid}"; return "{$this->resDir}/{$this->gunid}";
} }

View File

@ -75,7 +75,7 @@ class SmilPlaylist {
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }
$r = $pl->replaceMetaData($lspl, 'string', 'playlist'); $r = $pl->replaceMetadata($lspl, 'string', 'playlist');
if (PEAR::isError($r)) { if (PEAR::isError($r)) {
return $r; return $r;
} }

View File

@ -21,16 +21,10 @@ require_once(dirname(__FILE__)."/../../getid3/var/getid3.php");
* @copyright 2006 MDLF, Inc. * @copyright 2006 MDLF, Inc.
* @license http://www.gnu.org/licenses/gpl.txt * @license http://www.gnu.org/licenses/gpl.txt
* @link http://www.campware.org * @link http://www.campware.org
* @see GreenBox
* @see MetaData * @see MetaData
* @see RawMediaData * @see RawMediaData
*/ */
class StoredFile { class StoredFile {
/**
* @var DB
*/
public $dbc;
/** /**
* Unique ID for the file. * Unique ID for the file.
* *
@ -82,9 +76,9 @@ class StoredFile {
* *
* @param int $oid * @param int $oid
* local object id in the tree * local object id in the tree
* @param string $name * @param string $filename
* name of new file * name of new file
* @param string $mediaFileLP * @param string $localFilePath
* local path to media file * local path to media file
* @param string $metadata * @param string $metadata
* local path to metadata XML file or XML string * local path to metadata XML file or XML string
@ -94,38 +88,35 @@ class StoredFile {
* unique id - for insert file with gunid * unique id - for insert file with gunid
* @param string $ftype * @param string $ftype
* internal file type * internal file type
* @param string $className
* class to be constructed
* @param boolean $copyMedia * @param boolean $copyMedia
* copy the media file if true, make symlink if false * copy the media file if true, make symlink if false
* @return StoredFile * @return StoredFile
*/ */
public static function &insert($oid, $name, public static function &insert($oid, $filename, $localFilePath='',
$mediaFileLP='', $metadata='', $mdataLoc='file', $metadata='', $mdataLoc='file', $gunid=NULL, $ftype=NULL, $copyMedia=TRUE)
$gunid=NULL, $ftype=NULL, $className='StoredFile', $copyMedia=TRUE)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$ac = new $className(($gunid ? $gunid : NULL)); $ac = new StoredFile(($gunid ? $gunid : NULL));
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
} }
$ac->name = $name; $ac->name = $filename;
$ac->id = $oid; $ac->id = $oid;
$ac->mime = "unknown"; $ac->mime = "unknown";
$emptyState = TRUE; $emptyState = TRUE;
if ($ac->name == '') { if ($ac->name == '') {
$ac->name = $ac->gunid; $ac->name = $ac->gunid;
} }
$escapedName = pg_escape_string($name); $md5 = md5_file($localFilePath);
$escapedName = pg_escape_string($filename);
$escapedFtype = pg_escape_string($ftype); $escapedFtype = pg_escape_string($ftype);
$CC_DBC->query("BEGIN"); $CC_DBC->query("BEGIN");
$res = $CC_DBC->query(" $sql = "INSERT INTO ".$CC_CONFIG['filesTable']
INSERT INTO ".$CC_CONFIG['filesTable']." ."(id, name, gunid, mime, state, ftype, mtime, md5)"
(id, name, gunid, mime, state, ftype, mtime) ."VALUES ('$oid', '{$escapedName}', x'{$ac->gunid}'::bigint,
VALUES '{$ac->mime}', 'incomplete', '$escapedFtype', now(), '$md5')";
('$oid', '{$escapedName}', x'{$ac->gunid}'::bigint, echo $sql;
'{$ac->mime}', 'incomplete', '$escapedFtype', now()) $res = $CC_DBC->query($sql);
");
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK"); $CC_DBC->query("ROLLBACK");
return $res; return $res;
@ -147,12 +138,12 @@ class StoredFile {
return $res; return $res;
} }
// --- media file insert: // --- media file insert:
if ($mediaFileLP != '') { if ($localFilePath != '') {
if (!file_exists($mediaFileLP)) { if (!file_exists($localFilePath)) {
return PEAR::raiseError("StoredFile::insert: ". return PEAR::raiseError("StoredFile::insert: ".
"media file not found ($mediaFileLP)"); "media file not found ($localFilePath)");
} }
$res = $ac->rmd->insert($mediaFileLP, $copyMedia); $res = $ac->rmd->insert($localFilePath, $copyMedia);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
$CC_DBC->query("ROLLBACK"); $CC_DBC->query("ROLLBACK");
return $res; return $res;
@ -191,11 +182,9 @@ class StoredFile {
* local object id in the tree * local object id in the tree
* @param string $gunid * @param string $gunid
* global unique id of file * global unique id of file
* @param string $className
* classname to recall
* @return StoredFile * @return StoredFile
*/ */
public static function &recall($oid='', $gunid='', $className='StoredFile') public static function &recall($oid='', $gunid='')
{ {
global $CC_DBC; global $CC_DBC;
global $CC_CONFIG; global $CC_CONFIG;
@ -218,7 +207,7 @@ class StoredFile {
return $r; return $r;
} }
$gunid = StoredFile::NormalizeGunid($row['gunid']); $gunid = StoredFile::NormalizeGunid($row['gunid']);
$ac = new $className($gunid); $ac = new StoredFile($gunid);
$ac->mime = $row['mime']; $ac->mime = $row['mime'];
$ac->name = $row['name']; $ac->name = $row['name'];
$ac->id = $row['id']; $ac->id = $row['id'];
@ -232,14 +221,12 @@ class StoredFile {
* by gunid. * by gunid.
* *
* @param string $gunid * @param string $gunid
* optional, global unique id of file * global unique id of file
* @param string $className
* optional classname to recall
* @return StoredFile * @return StoredFile
*/ */
public static function &recallByGunid($gunid='', $className='StoredFile') public static function &recallByGunid($gunid='')
{ {
return StoredFile::recall('', $gunid, $className); return StoredFile::recall('', $gunid);
} }
@ -249,18 +236,15 @@ class StoredFile {
* *
* @param string $token * @param string $token
* access token * access token
* @param string $className
* optional classname to recall
* @return StoredFile * @return StoredFile
*/ */
public static function recallByToken($token, $className='StoredFile') public static function recallByToken($token)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$gunid = $CC_DBC->getOne(" $gunid = $CC_DBC->getOne("
SELECT to_hex(gunid) as gunid SELECT to_hex(gunid) as gunid
FROM ".$CC_CONFIG['accessTable']." FROM ".$CC_CONFIG['accessTable']."
WHERE token=x'$token'::bigint WHERE token=x'$token'::bigint");
");
if (PEAR::isError($gunid)) { if (PEAR::isError($gunid)) {
return $gunid; return $gunid;
} }
@ -269,7 +253,32 @@ class StoredFile {
"StoredFile::recallByToken: invalid token ($token)", GBERR_AOBJNEX); "StoredFile::recallByToken: invalid token ($token)", GBERR_AOBJNEX);
} }
$gunid = StoredFile::NormalizeGunid($gunid); $gunid = StoredFile::NormalizeGunid($gunid);
return StoredFile::recall('', $gunid, $className); return StoredFile::recall('', $gunid);
}
/**
* Check if the MD5 value already exists.
*
* @param string $p_md5sum
* @return StoredFile|FALSE|PEAR_Error
*/
public static function RecallByMd5($p_md5sum)
{
global $CC_CONFIG, $CC_DBC;
$gunid = $CC_DBC->getOne(
"SELECT to_hex(gunid) as gunid
FROM ".$CC_CONFIG['filesTable']."
WHERE md5='$p_md5sum'");
if (PEAR::isError($gunid)) {
return $gunid;
}
if ($gunid) {
$gunid = StoredFile::NormalizeGunid($gunid);
return StoredFile::recall('', $gunid);
} else {
return FALSE;
}
} }
@ -284,7 +293,7 @@ class StoredFile {
*/ */
public static function &CopyOf(&$src, $nid) public static function &CopyOf(&$src, $nid)
{ {
$ac = StoredFile::insert($nid, $src->name, $src->_getRealRADFname(), $ac = StoredFile::insert($nid, $src->name, $src->getRealFileName(),
'', '', NULL, BasicStor::GetType($src->gunid)); '', '', NULL, BasicStor::GetType($src->gunid));
if (PEAR::isError($ac)) { if (PEAR::isError($ac)) {
return $ac; return $ac;
@ -294,9 +303,8 @@ class StoredFile {
} }
/* ======================================================= public methods */
/** /**
* Replace existing file with new data * Replace existing file with new data.
* *
* @param int $oid * @param int $oid
* local id * local id
@ -308,6 +316,7 @@ class StoredFile {
* local path to metadata XML file or XML string * local path to metadata XML file or XML string
* @param string $mdataLoc * @param string $mdataLoc
* 'file'|'string' * 'file'|'string'
* @return TRUE|PEAR_Error
*/ */
public function replace($oid, $name, $mediaFileLP='', $metadata='', public function replace($oid, $name, $mediaFileLP='', $metadata='',
$mdataLoc='file') $mdataLoc='file')
@ -319,7 +328,7 @@ class StoredFile {
$CC_DBC->query("ROLLBACK"); $CC_DBC->query("ROLLBACK");
return $res; return $res;
} }
if ($mediaFileLP != '') { // media if ($mediaFileLP != '') {
$res = $this->replaceRawMediaData($mediaFileLP); $res = $this->replaceRawMediaData($mediaFileLP);
} else { } else {
$res = $this->rmd->delete(); $res = $this->rmd->delete();
@ -328,8 +337,8 @@ class StoredFile {
$CC_DBC->query("ROLLBACK"); $CC_DBC->query("ROLLBACK");
return $res; return $res;
} }
if ($metadata != '') { // metadata if ($metadata != '') {
$res = $this->replaceMetaData($metadata, $mdataLoc); $res = $this->replaceMetadata($metadata, $mdataLoc);
} else { } else {
$res = $this->md->delete(); $res = $this->md->delete();
} }
@ -357,8 +366,8 @@ class StoredFile {
*/ */
public function accessRawMediaData($parent='0') public function accessRawMediaData($parent='0')
{ {
$realFname = $this->_getRealRADFname(); $realFname = $this->getRealFileName();
$ext = $this->_getExt(); $ext = $this->getFileExtension();
$res = BasicStor::bsAccess($realFname, $ext, $this->gunid, 'access', $parent); $res = BasicStor::bsAccess($realFname, $ext, $this->gunid, 'access', $parent);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return $res; return $res;
@ -392,6 +401,7 @@ class StoredFile {
* *
* @param string $mediaFileLP * @param string $mediaFileLP
* local path to media file * local path to media file
* @return void|PEAR_Error
*/ */
public function replaceRawMediaData($mediaFileLP) public function replaceRawMediaData($mediaFileLP)
{ {
@ -426,7 +436,7 @@ class StoredFile {
* (NULL = no validation) * (NULL = no validation)
* @return boolean * @return boolean
*/ */
public function replaceMetaData($metadata, $mdataLoc='file', $format=NULL) public function replaceMetadata($metadata, $mdataLoc='file', $format=NULL)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$CC_DBC->query("BEGIN"); $CC_DBC->query("BEGIN");
@ -479,7 +489,7 @@ class StoredFile {
* Rename stored virtual file * Rename stored virtual file
* *
* @param string $newname * @param string $newname
* @return TRUE/PEAR_Error * @return TRUE|PEAR_Error
*/ */
public function rename($newname) public function rename($newname)
{ {
@ -503,8 +513,7 @@ class StoredFile {
* 'empty'|'incomplete'|'ready'|'edited' * 'empty'|'incomplete'|'ready'|'edited'
* @param int $editedby * @param int $editedby
* user id | 'NULL' for clear editedBy field * user id | 'NULL' for clear editedBy field
* (optional) * @return TRUE|PEAR_Error
* @return TRUE/PEAR_Error
*/ */
public function setState($state, $editedby=NULL) public function setState($state, $editedby=NULL)
{ {
@ -528,7 +537,7 @@ class StoredFile {
* *
* @param string $mime * @param string $mime
* mime-type * mime-type
* @return boolean or error * @return boolean|PEAR_Error
*/ */
public function setMime($mime) public function setMime($mime)
{ {
@ -548,11 +557,33 @@ class StoredFile {
} }
/**
* Set md5 of virtual file
*
* @param string $p_md5sum
* @return boolean|PEAR_Error
*/
public function setMd5($p_md5sum)
{
global $CC_CONFIG, $CC_DBC;
$escapedMd5 = pg_escape_string($p_md5sum);
$res = $CC_DBC->query("
UPDATE ".$CC_CONFIG['filesTable']." SET md5='$escapedMd5', mtime=now()
WHERE gunid=x'{$this->gunid}'::bigint
");
if (PEAR::isError($res)) {
return $res;
}
return TRUE;
}
/** /**
* Delete stored virtual file * Delete stored virtual file
* *
* @see RawMediaData * @see RawMediaData
* @see MetaData * @see MetaData
* @return TRUE|PEAR_Error
*/ */
public function delete() public function delete()
{ {
@ -571,7 +602,7 @@ class StoredFile {
"); ");
if (is_array($tokens)) { if (is_array($tokens)) {
foreach($tokens as $i=>$item){ foreach($tokens as $i=>$item){
$file = $this->_getAccessFname($item['token'], $item['ext']); $file = $this->_getAccessFileName($item['token'], $item['ext']);
if (file_exists($file)) { if (file_exists($file)) {
@unlink($file); @unlink($file);
} }
@ -601,6 +632,7 @@ class StoredFile {
* *
* @param string $gunid * @param string $gunid
* optional (for static call), global unique id * optional (for static call), global unique id
* @return boolean|PEAR_Error
*/ */
public function isAccessed($gunid=NULL) public function isAccessed($gunid=NULL)
{ {
@ -634,7 +666,7 @@ class StoredFile {
if (is_null($playlistId)) { if (is_null($playlistId)) {
$playlistId = $this->gunid; $playlistId = $this->gunid;
} }
$state = $this->_getState($playlistId); $state = $this->getState($playlistId);
if ($state != 'edited') { if ($state != 'edited') {
return FALSE; return FALSE;
} }
@ -647,7 +679,7 @@ class StoredFile {
* *
* @param string $playlistId * @param string $playlistId
* playlist global unique ID * playlist global unique ID
* @return null or int * @return int|null|PEAR_Error
* id of user editing it * id of user editing it
*/ */
public function isEditedBy($playlistId=NULL) public function isEditedBy($playlistId=NULL)
@ -672,7 +704,7 @@ class StoredFile {
/** /**
* Returns local id of virtual file * Returns local id of virtual file
* * @return int
*/ */
public function getId() public function getId()
{ {
@ -682,15 +714,14 @@ class StoredFile {
/** /**
* Returns true if raw media file exists * Returns true if raw media file exists
* * @return boolean|PEAR_Error
*/ */
public function exists() public function exists()
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
$indb = $CC_DBC->getRow(" $indb = $CC_DBC->getRow(
SELECT to_hex(gunid) FROM ".$CC_CONFIG['filesTable']." "SELECT to_hex(gunid) FROM ".$CC_CONFIG['filesTable']
WHERE gunid=x'{$this->gunid}'::bigint ." WHERE gunid=x'{$this->gunid}'::bigint");
");
if (PEAR::isError($indb)) { if (PEAR::isError($indb)) {
return $indb; return $indb;
} }
@ -704,16 +735,14 @@ class StoredFile {
} }
/* ==================================================== "private" methods */
/** /**
* Create new global unique id * Create new global unique id
* * @return string
*/ */
public static function CreateGunid() public static function CreateGunid()
{ {
$ip = (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : ''); $ip = (isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '');
$initString = $initString = microtime().$ip.rand()."org.mdlf.campcaster";
microtime().$ip.rand()."org.mdlf.campcaster";
$hash = md5($initString); $hash = md5($initString);
// non-negative int8 // non-negative int8
$hsd = substr($hash, 0, 1); $hsd = substr($hash, 0, 1);
@ -727,9 +756,9 @@ class StoredFile {
* *
* @return string * @return string
*/ */
public static function NormalizeGunid($gunid0) public static function NormalizeGunid($gunid)
{ {
return str_pad($gunid0, 16, "0", STR_PAD_LEFT); return str_pad($gunid, 16, "0", STR_PAD_LEFT);
} }
@ -767,9 +796,9 @@ class StoredFile {
* @return string * @return string
* file extension without a dot * file extension without a dot
*/ */
public function _getExt() public function getFileExtension()
{ {
$fname = $this->_getFileName(); $fname = $this->getFileName();
$pos = strrpos($fname, '.'); $pos = strrpos($fname, '.');
if ($pos !== FALSE) { if ($pos !== FALSE) {
$ext = substr($fname, $pos+1); $ext = substr($fname, $pos+1);
@ -801,7 +830,7 @@ class StoredFile {
* Get mime-type from global id * Get mime-type from global id
* *
* @param string $gunid * @param string $gunid
* optional, global unique id of file * global unique id of file
* @return string * @return string
* mime-type * mime-type
*/ */
@ -821,11 +850,11 @@ class StoredFile {
* Get storage-internal file state * Get storage-internal file state
* *
* @param string $gunid * @param string $gunid
* optional, global unique id of file * global unique id of file
* @return string * @return string
* see install() * see install()
*/ */
public function _getState($gunid=NULL) public function getState($gunid=NULL)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
if (is_null($gunid)) { if (is_null($gunid)) {
@ -842,11 +871,10 @@ class StoredFile {
* Get mnemonic file name * Get mnemonic file name
* *
* @param string $gunid * @param string $gunid
* optional, global unique id of file * global unique id of file
* @return string * @return string
* see install()
*/ */
public function _getFileName($gunid=NULL) public function getFileName($gunid=NULL)
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
if (is_null($gunid)) { if (is_null($gunid)) {
@ -860,9 +888,10 @@ class StoredFile {
/** /**
* Get and optionaly create subdirectory in real filesystem for storing * Get and optionally create subdirectory in real filesystem for storing
* raw media data * raw media data.
* *
* @return string
*/ */
private function _getResDir() private function _getResDir()
{ {
@ -881,22 +910,24 @@ class StoredFile {
/** /**
* Get real filename of raw media data * Get real filename of raw media data
* *
* @return string
* @see RawMediaData * @see RawMediaData
*/ */
public function _getRealRADFname() public function getRealFileName()
{ {
return $this->rmd->getFname(); return $this->rmd->getFileName();
} }
/** /**
* Get real filename of metadata file * Get real filename of metadata file
* *
* @return string
* @see MetaData * @see MetaData
*/ */
public function _getRealMDFname() public function getRealMetadataFileName()
{ {
return $this->md->getFname(); return $this->md->getFileName();
} }
@ -904,8 +935,9 @@ class StoredFile {
* Create and return name for temporary symlink. * Create and return name for temporary symlink.
* *
* @todo Should be more unique * @todo Should be more unique
* @return string
*/ */
private function _getAccessFname($token, $ext='EXT') private function _getAccessFileName($token, $ext='EXT')
{ {
global $CC_CONFIG; global $CC_CONFIG;
$token = StoredFile::NormalizeGunid($token); $token = StoredFile::NormalizeGunid($token);

View File

@ -292,7 +292,7 @@ class Transport
return $ac; return $ac;
} }
// handle metadata: // handle metadata:
$mdfpath = $ac->_getRealMDFname(); $mdfpath = $ac->getRealMetadataFileName();
if (PEAR::isError($mdfpath)) { if (PEAR::isError($mdfpath)) {
return $mdfpath; return $mdfpath;
} }
@ -303,11 +303,11 @@ class Transport
return $mdtrec; return $mdtrec;
} }
// handle raw media file: // handle raw media file:
$fpath = $ac->_getRealRADFname(); $fpath = $ac->getRealFileName();
if (PEAR::isError($fpath)) { if (PEAR::isError($fpath)) {
return $fpath; return $fpath;
} }
$fname = $ac->_getFileName(); $fname = $ac->getFileName();
if (PEAR::isError($fname)) { if (PEAR::isError($fname)) {
return $fname; return $fname;
} }
@ -329,7 +329,7 @@ class Transport
if (PEAR::isError($pl)) { if (PEAR::isError($pl)) {
return $pl; return $pl;
} }
$fname = $pl->_getFileName(); $fname = $pl->getFileName();
if (PEAR::isError($fname)) { if (PEAR::isError($fname)) {
return $fname; return $fname;
} }
@ -352,7 +352,7 @@ class Transport
$fname = $fname.".lspl"; $fname = $fname.".lspl";
$trtype = 'playlistPkg'; $trtype = 'playlistPkg';
} else { } else {
$plfpath = $pl->_getRealMDFname(); $plfpath = $pl->getRealMetadataFileName();
if (PEAR::isError($plfpath)) { if (PEAR::isError($plfpath)) {
return $plfpath; return $plfpath;
} }

View File

@ -0,0 +1,71 @@
<?php
/**
* @author Paul Baranowski <paul@paulbaranowski.org>
* @version $Revision: 2834 $
* @package Campcaster
* @subpackage StorageServer
* @copyright 2006 MDLF, Inc.
* @license http://www.gnu.org/licenses/gpl.txt
* @link http://www.campware.org
*
* Note: This file was broken into two parts: install.php and
* installMain.php so that the archive server could use the same
* installation script, but with just a different config file.
*/
// Do not allow remote execution
$arr = array_diff_assoc($_SERVER, $_ENV);
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
header("HTTP/1.1 400");
header("Content-type: text/plain; charset=UTF-8");
echo "400 Not executable\r\n";
exit(1);
}
echo "**********************************\n";
echo "* StorageServer Upgrade to 1.2.0 *\n";
echo "**********************************\n";
require_once('../../conf.php');
require_once("../installInit.php");
require_once("../../StoredFile.php");
// Check to see if upgrade has already been applied
//$sql = "SELECT md5 FROM ".$CC_CONFIG['filesTable']." LIMIT 1";
//$result = $CC_DBC->query($sql);
//if (!PEAR::isError($result)) {
// echo "THIS UPGRADE HAS ALREADY BEEN APPLIED.\n";
// exit(0);
//}
//
//echo " * Modifying '".$CC_CONFIG['filesTable']." table...";
//$sql = "ALTER TABLE ".$CC_CONFIG['filesTable']." ADD COLUMN md5 char(32)";
//camp_install_query($sql);
//
//$sql = "ALTER TABLE ".$CC_CONFIG['filesTable']." ALTER COLUMN md5 SET STORAGE EXTENDED";
//camp_install_query($sql);
//
//$sql = "CREATE INDEX ".$CC_CONFIG['filesTable']."_md5_idx ON ".$CC_CONFIG['filesTable']." (md5)";
//camp_install_query($sql);
// Get MD5 values for all files
$sql = "SELECT gunid FROM ".$CC_CONFIG['filesTable'] ." WHERE ftype='audioclip'";
$rows = $CC_DBC->GetAll($sql);
foreach ($rows as $row) {
echo $row['gunid']."\n";
$gunid = StoredFile::NormalizeGunid($gunid);
$storedFile = new StoredFile($row['gunid']);
$fileName = $storedFile->getRealFileName();
echo $fileName."\n";
if (file_exists($fileName)) {
$md5 = md5_file($fileName);
$storedFile->setMd5($md5);
}
}
echo "**********************************\n";
echo "* StorageServer Install Complete *\n";
echo "**********************************\n";
?>

View File

@ -252,6 +252,8 @@ class XR_LocStor extends LocStor {
* <li> 801 - wrong 1st parameter, struct expected.</li> * <li> 801 - wrong 1st parameter, struct expected.</li>
* <li> 805 - xr_storeAudioClipOpen: * <li> 805 - xr_storeAudioClipOpen:
* &lt;message from lower layer&gt; </li> * &lt;message from lower layer&gt; </li>
* <li> 888 - If the file being uploaded is a duplicate of
* a file already in the system.</li>
* </ul> * </ul>
* *
* @param XML_RPC_Message $input * @param XML_RPC_Message $input
@ -264,11 +266,14 @@ class XR_LocStor extends LocStor {
if (!$ok) { if (!$ok) {
return $r; return $r;
} }
$res = $this->storeAudioClipOpen( $res = $this->storeAudioClipOpen($r['sessid'], $r['gunid'],
$r['sessid'], $r['gunid'], $r['metadata'], $r['fname'], $r['chsum'] $r['metadata'], $r['fname'], $r['chsum']);
);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
return new XML_RPC_Response(0, 805, $code = 805;
if ($res->getCode() == 888) {
$code = 888;
}
return new XML_RPC_Response(0, $code,
"xr_storeAudioClipOpen: ".$res->getMessage(). "xr_storeAudioClipOpen: ".$res->getMessage().
" ".$res->getUserInfo() " ".$res->getUserInfo()
); );

View File

@ -32,16 +32,17 @@
define('USE_FLOCK', TRUE); define('USE_FLOCK', TRUE);
require_once dirname(__FILE__).'/../conf.php'; require_once(dirname(__FILE__).'/../conf.php');
require_once 'DB.php'; require_once('DB.php');
require_once dirname(__FILE__).'/../LocStor.php'; require_once(dirname(__FILE__).'/../LocStor.php');
PEAR::setErrorHandling(PEAR_ERROR_RETURN); PEAR::setErrorHandling(PEAR_ERROR_RETURN);
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); $CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
$gb = new LocStor(); $gb = new LocStor();
function http_error($code, $err) { function http_error($code, $err)
{
header("HTTP/1.1 $code"); header("HTTP/1.1 $code");
header("Content-type: text/plain; charset=UTF-8"); header("Content-type: text/plain; charset=UTF-8");
echo "$err\r\n"; echo "$err\r\n";

View File

@ -83,7 +83,7 @@ if (PEAR::isError($ftype)) {
} }
switch ($ftype) { switch ($ftype) {
case "audioclip": case "audioclip":
$realFname = $ac->_getRealRADFname(); $realFname = $ac->getRealFileName();
$mime = $ac->rmd->getMime(); $mime = $ac->rmd->getMime();
header("Content-type: $mime"); header("Content-type: $mime");
header("Content-length: ".filesize($realFname)); header("Content-length: ".filesize($realFname));

View File

@ -72,9 +72,9 @@ $methods = array(
'logout' => 'Logout from storage.', 'logout' => 'Logout from storage.',
'existsAudioClip' => 'Checks if an Audio clip with the specified '. 'existsAudioClip' => 'Checks if an Audio clip with the specified '.
'id is stored in local storage.', 'id is stored in local storage.',
'storeAudioClipOpen' => 'Open channel for store a new audio clip '. 'storeAudioClipOpen' => 'Open channel to store a new audio clip '.
'or replace an existing one.', 'or replace an existing one.',
'storeAudioClipClose' => 'Close channel for store a new audio clip'. 'storeAudioClipClose' => 'Close channel to store a new audio clip'.
' or replace an existing one.', ' or replace an existing one.',
'downloadRawAudioDataOpen'=> 'Create and return downloadable URL'. 'downloadRawAudioDataOpen'=> 'Create and return downloadable URL'.
'for audio file', 'for audio file',

View File

@ -1,44 +1,69 @@
<?php <?php
require_once dirname(__FILE__).'/../conf.php'; require_once(dirname(__FILE__).'/../conf.php');
include_once "XML/RPC.php"; include_once("XML/RPC.php");
include_once dirname(__FILE__)."/../conf.php"; include_once("Console/Getopt.php");
$pars = $argv; function printUsage()
array_shift($pars); {
$verbose = FALSE; echo "Usage:\n";
#$verbose = TRUE; echo " -v Verbose output\n";
if($pars[0] == '-v'){ $verbose = TRUE; array_shift($pars); } echo " -s arg Server Path\n";
if($pars[0] == '-s'){ echo " -o arg1:value1,arg2:value2 Function Arguments\n";
array_shift($pars); echo " -h Help\n";
$serverPath = array_shift($pars); echo "\n";
}else{
$serverPath =
"http://{$CC_CONFIG['storageUrlHost']}:{$CC_CONFIG['storageUrlPort']}".
"{$CC_CONFIG['storageUrlPath']}/{$CC_CONFIG['storageXMLRPC']}";
} }
$options = array();
if($pars[0] == '-o'){ $verbose = TRUE;
array_shift($pars); $parsedCommandLine = Console_Getopt::getopt($argv, "vs:o:h");
$optStr = array_shift($pars);
$cmdLineOptions = $parsedCommandLine[0];
if (count($parsedCommandLine[1]) == 0) {
printUsage();
exit;
}
$method = array_pop($parsedCommandLine[1]);
foreach ($cmdLineOptions as $tmpValue) {
$optionName = $tmpValue[0];
$optionValue = $tmpValue[1];
switch ($optionName) {
case "h":
printUsage();
exit;
case "v":
$verbose = TRUE;
break;
case "s":
$serverPath = $optionValue;
break;
case "o":
$optStr = $optionValue;
$optArr = split(",", $optStr); $optArr = split(",", $optStr);
foreach ($optArr as $opt) { foreach ($optArr as $opt) {
list($k, $v) = split(':', $opt); list($k, $v) = split(':', $opt);
$options[$k] = $v; $options[$k] = $v;
} }
}
} }
#$serverPath = "http://localhost:80/campcasterStorageServerCVS/xmlrpc/xrLocStor.php"; if (!isset($serverPath)) {
$serverPath =
"http://{$CC_CONFIG['storageUrlHost']}:{$CC_CONFIG['storageUrlPort']}".
"{$CC_CONFIG['storageUrlPath']}/{$CC_CONFIG['storageXMLRPC']}";
}
$url = parse_url($serverPath); $url = parse_url($serverPath);
$client = new XML_RPC_Client($url['path'], $url['host']); $client = new XML_RPC_Client($url['path'], $url['host']);
$method = array_shift($pars);
if ($verbose) { if ($verbose) {
$client->debug = 1; $client->debug = 1;
echo "serverPath: $serverPath\n"; echo "ServerPath: $serverPath\n";
echo "host: {$url['host']}, path: {$url['path']}\n"; echo "Host: {$url['host']}, path: {$url['path']}\n";
echo "method: $method\n"; echo "Method: $method\n";
echo "pars:\n"; echo "Parameters:\n";
var_dump($pars); var_dump($pars);
} }
@ -46,17 +71,11 @@ $infos = array(
"listMethods" => array('m'=>"system.listMethods", 'p'=>NULL), "listMethods" => array('m'=>"system.listMethods", 'p'=>NULL),
"methodHelp" => array('m'=>"system.methodHelp", 'p'=>0), "methodHelp" => array('m'=>"system.methodHelp", 'p'=>0),
"methodSignature" => array('m'=>"system.methodSignature", 'p'=>0), "methodSignature" => array('m'=>"system.methodSignature", 'p'=>0),
"test" => "test" => array('m'=>"locstor.test", 'p'=>array('sessid', 'teststring')),
array('m'=>"locstor.test", 'p'=>array('sessid', 'teststring')), "getVersion" => array('m'=>"locstor.getVersion", 'p'=>array(), 'r'=>'version'),
"getVersion" => array('m'=>"locstor.getVersion", "authenticate" => array('m'=>"locstor.authenticate", 'p'=>array('login', 'pass'), 'r'=>'authenticate'),
'p'=>array(), 'r'=>'version'), "login" => array('m'=>"locstor.login", 'p'=>array('login', 'pass'), 'r'=>'sessid'),
"authenticate" => array('m'=>"locstor.authenticate", "logout" => array('m'=>"locstor.logout", 'p'=>array('sessid'), 'r'=>'status'),
'p'=>array('login', 'pass'), 'r'=>'authenticate'),
"login" => array('m'=>"locstor.login",
'p'=>array('login', 'pass'), 'r'=>'sessid'),
"logout" => array('m'=>"locstor.logout",
'p'=>array('sessid'), 'r'=>'status'),
"storeAudioClipOpen" => array('m'=>"locstor.storeAudioClipOpen", "storeAudioClipOpen" => array('m'=>"locstor.storeAudioClipOpen",
'p'=>array('sessid', 'gunid', 'metadata', 'fname', 'chsum'), 'p'=>array('sessid', 'gunid', 'metadata', 'fname', 'chsum'),
'r'=>array('url', 'token') 'r'=>array('url', 'token')
@ -290,9 +309,12 @@ $resp = XML_RPC_decode($res->value());
if (isset($infos[$method]['r'])) { if (isset($infos[$method]['r'])) {
$pom = $infos[$method]['r']; $pom = $infos[$method]['r'];
if (is_array($pom)) { if (is_array($pom)) {
foreach($pom as $k=>$it) $pom[$k] = $resp[$it]; foreach ($pom as $k => $it) {
$pom[$k] = $resp[$it];
}
echo join(' ', $pom)."\n"; echo join(' ', $pom)."\n";
}else switch($pom){ } else {
switch ($pom) {
case "status": case "status":
case "exists": case "exists":
echo ($resp[$pom]=='1' ? "TRUE" : "FALSE" )."\n"; echo ($resp[$pom]=='1' ? "TRUE" : "FALSE" )."\n";
@ -300,31 +322,34 @@ if(isset($infos[$method]['r'])){
default: default:
echo "{$resp[$pom]}\n"; echo "{$resp[$pom]}\n";
} }
}
} else { } else {
switch ($method) { switch ($method) {
case "searchMetadata": case "searchMetadata":
case "getSearchResults": case "getSearchResults":
$acCnt = 0; $acGunids = array(); $acCnt = 0;
$plCnt = 0; $plGunids = array(); $acGunids = array();
$plCnt = 0;
$plGunids = array();
$fld = (isset($options['category']) ? $options['category'] : 'gunid' ); $fld = (isset($options['category']) ? $options['category'] : 'gunid' );
foreach ($resp['results'] as $k => $v) { foreach ($resp['results'] as $k => $v) {
if($v['type']=='audioclip'){ $acCnt++; if ($v['type']=='audioclip') {
$acCnt++;
$acGunids[] = $v[$fld]; $acGunids[] = $v[$fld];
} }
if($v['type']=='playlist'){ $plCnt++; if ($v['type']=='playlist') {
$plCnt++;
$plGunids[] = $v[$fld]; $plGunids[] = $v[$fld];
} }
} }
echo echo "AC({$acCnt}): ".
"AC({$acCnt}): ".
join(", ", $acGunids). join(", ", $acGunids).
" | PL({$plCnt}): ". " | PL({$plCnt}): ".
join(", ", $plGunids). join(", ", $plGunids).
"\n"; "\n";
break; break;
case "browseCategory": case "browseCategory":
echo echo "RES({$resp['cnt']}): ".
"RES({$resp['cnt']}): ".
join(", ", $resp['results']). join(", ", $resp['results']).
"\n"; "\n";
break; break;