faultCode 804 faultString "); ini_set("error_append_string", " "); header("Content-type: text/xml"); include_once "xmlrpc.inc"; include_once "xmlrpcs.inc"; require_once '../conf.php'; require_once 'DB.php'; require_once '../LocStor.php'; function errHndl($errno, $errmsg, $filename, $linenum, $vars){ if($errno == 8 /*E_NOTICE*/) return; $xr =& new xmlrpcresp(0, 805, "ERROR:xrLoctor: $errno $errmsg ($filename:$linenum)"); header("Content-type: text/xml"); echo $xr->serialize(); exit($errno); } $old_error_handler = set_error_handler("errHndl"); PEAR::setErrorHandling(PEAR_ERROR_RETURN); $dbc = DB::connect($config['dsn'], TRUE); $dbc->setFetchMode(DB_FETCHMODE_ASSOC); class XR_LocStor extends LocStor{ /** * Convert PHP variables to XMLRPC objects * * @param var mixed - PHP variable * @param struct boolean - flag for using XMLRPC struct instead of array * @return XMLRPC object */ function _v2xr($var, $struct=true){ if(is_array($var)){ $r = array(); foreach($var as $k=>$v){ if($struct) $r[$k]=$this->_v2xr($v); else $r[]=$this->_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"); } } /** * Convert XMLRPC struct to PHP array * * @param input XMLRPC struct * @return array */ 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, "wrong 1st parameter, struct expected." )); } /** * Test XMLRPC - strupper and return given string, * also return loginname of logged user * * @param input XMLRPC struct * @return XMLRPC struct */ function xr_test($input) { list($ok, $r) = $this->_xr_getPars($input); if(!$ok) return $r; return new xmlrpcresp($this->_v2xr(array( 'str'=>strtoupper($r['teststring']), 'login'=>$this->getSessLogin($r['sessid']), 'sessid'=>$r['sessid'] ), true)); } /** * Checks the login name and password of the user and return * true if login data are correct, othervise return false. * * The XML-RPC name of this method is "locstor.authenticate". * * Input parameters: XML-RPC struct with the following fields: * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return boolean * @see Subjects::authenticate */ function xr_authenticate($input) { list($ok, $r) = $this->_xr_getPars($input); if(!$ok) return $r; $res = $this->authenticate($r['login'], $r['pass']); if(PEAR::isError($res)){ return new xmlrpcresp(0, 804,"xr_authenticate: database error"); } $retval = ($res !== FALSE); return new xmlrpcresp(new xmlrpcval($retval, "boolean")); } /** * Checks the login name and password of the user. If the login is * correct, a new session ID string is generated, to be used in all * subsequent XML-RPC calls as the "sessid" field of the * parameters. * * The XML-RPC name of this method is "locstor.login". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return string * @see Alib::login */ function xr_login($input) { list($ok, $r) = $this->_xr_getPars($input); if(!$ok) return $r; $res = $this->login($r['login'], $r['pass']); if(PEAR::isError($res)){ return new xmlrpcresp(0, 804,"xr_login: database error"); } if($res === FALSE) return new xmlrpcresp(0, 802, "xr_login: login failed - incorrect username or password." ); else return new xmlrpcresp($this->_v2xr($res, false)); } /** * Logout, destroy session and return 'Bye'. * If session is not valid error message is returned. * * The XML-RPC name of this method is "locstor.logout". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return string * @see GreenBox::logout */ 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($this->_v2xr('Bye', false)); else return new xmlrpcresp(0, 803, "xr_logout: logout failed - not logged." ); } /** * Check if audio clip exists and return TRUE/FALSE * * The XML-RPC name of this method is "locstor.existsAudioClip". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return boolean * @see LocStor::existsAudioClip */ 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, 805, "xr_existsAudioClip: ".$res->getMessage(). " ".$res->getUserInfo() ); return new xmlrpcresp(new xmlrpcval($res, "boolean")); } /** * Store new AudioClip or replace existing one. * * The XML-RPC name of this method is "locstor.storeAudioClip". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return string * @see LocStor::storeAudioClip */ 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, 805, "xr_storeAudioClip: ".$res->getMessage(). " ".$res->getUserInfo() ); } /** * Delete existing audio clip * * The XML-RPC name of this method is "locstor.deleteAudioClip". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return boolean * @see LocStor::deleteAudioClip */ 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, 805, "xr_deleteAudioClip: ".$res->getMessage(). " ".$res->getUserInfo() ); } /** * Update existing audio clip metadata * * The XML-RPC name of this method is "locstor.updateAudioClipMetadata". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return boolean * @see LocStor::updateAudioClipMetadata */ 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, 805, "xr_updateAudioClip: ".$res->getMessage(). " ".$res->getUserInfo() ); } /** * Search in local metadata database * * The XML-RPC name of this method is "locstor.searchMetadata". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return boolean * @see LocStor::searchMetadata * @see GreenBox::localSearch */ 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() ); } /** * Make access to audio clip. * * The XML-RPC name of this method is "locstor.accessRawAudioData". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return string * @see LocStor::accessRawAudioData */ 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, 805, "xr_accessRawAudioData: ".$res->getMessage(). " ".$res->getUserInfo() ); } /** * Release access to audio clip * * The XML-RPC name of this method is "locstor.releaseRawAudioData". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return boolean * @see LocStor::releaseRawAudioData */ 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, 805, "xr_releaseRawAudioData: ".$res->getMessage(). " ".$res->getUserInfo() ); } /** * Return all file's metadata as XML string * * The XML-RPC name of this method is "locstor.getAudioClip". * * The input parameters are an XML-RPC struct with the following * fields: * * * On success, returns a single XML-RPC value: * * * On errors, returns an XML-RPC error response. * The possible error codes and error message are: * * * @param input XMLRPC struct * @return string * @see LocStor::getAudioClip */ function xr_getAudioClip($input) { list($ok, $r) = $this->_xr_getPars($input); if(!$ok) return $r; $res = $this->getAudioClip($r['sessid'], $r['gunid']); if(!PEAR::isError($res)) return new xmlrpcresp(new xmlrpcval($res, "string")); else return new xmlrpcresp(0, 805, "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, return all matching clip ids.', 'accessRawAudioData' => 'Get access to raw audio data.', 'releaseRawAudioData' => 'Release access to 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 ); ?>