252 lines
7.7 KiB
PHP
252 lines
7.7 KiB
PHP
<?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/archiveServer/var/xmlrpc/xrArchive.php,v $
|
|
|
|
------------------------------------------------------------------------------*/
|
|
include_once "xmlrpc.inc";
|
|
include_once "xmlrpcs.inc";
|
|
require_once '../conf.php';
|
|
require_once 'DB.php';
|
|
require_once "../Archive.php";
|
|
|
|
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
|
$dbc = DB::connect($config['dsn'], TRUE);
|
|
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
|
|
|
/**
|
|
* XMLRPC layer for Archive module
|
|
*/
|
|
class XR_Archive extends Archive{
|
|
/**
|
|
* Simple ping method - return strtouppered string
|
|
*/
|
|
function xr_ping($input)
|
|
{
|
|
list($ok, $r) = $this->_xr_getPars($input);
|
|
if(!$ok) return $r;
|
|
return new xmlrpcresp(new xmlrpcval(strtoupper($r['par']), "string"));
|
|
}
|
|
|
|
/**
|
|
* Open download
|
|
*/
|
|
function xr_downloadOpen($input)
|
|
{
|
|
list($ok, $r) = $this->_xr_getPars($input);
|
|
if(!$ok) return $r;
|
|
$res = $this->downloadOpen($r['sessid'], $r['gunid']);
|
|
if(PEAR::isError($res))
|
|
return new xmlrpcresp(0, 803,
|
|
"xr_downloadOpen: ".$res->getMessage().
|
|
" ".$res->getUserInfo()
|
|
);
|
|
return new xmlrpcresp(xmlrpc_encoder($res));
|
|
}
|
|
|
|
/**
|
|
* Close download
|
|
*/
|
|
function xr_downloadClose($input)
|
|
{
|
|
list($ok, $r) = $this->_xr_getPars($input);
|
|
if(!$ok) return $r;
|
|
$res = $this->downloadClose($r['sessid'], $r['url']);
|
|
if(PEAR::isError($res))
|
|
return new xmlrpcresp(0, 803,
|
|
"xr_downloadOpen: ".$res->getMessage().
|
|
" ".$res->getUserInfo()
|
|
);
|
|
return new xmlrpcresp(xmlrpc_encoder($res));
|
|
}
|
|
|
|
/**
|
|
* Open upload
|
|
*/
|
|
function xr_uploadOpen($input)
|
|
{
|
|
list($ok, $r) = $this->_xr_getPars($input);
|
|
if(!$ok) return $r;
|
|
$res = $this->uploadOpen($r['sessid'], $r['gunid']);
|
|
if(PEAR::isError($res))
|
|
return new xmlrpcresp(0, 803,
|
|
"xr_downloadOpen: ".$res->getMessage().
|
|
" ".$res->getUserInfo()
|
|
);
|
|
return new xmlrpcresp(xmlrpc_encoder($res));
|
|
}
|
|
|
|
/**
|
|
* Abort upload
|
|
*/
|
|
function xr_uploadAbort($input)
|
|
{
|
|
list($ok, $r) = $this->_xr_getPars($input);
|
|
if(!$ok) return $r;
|
|
$res = $this->uploadAbort($r['sessid'], $r['url']);
|
|
if(PEAR::isError($res))
|
|
return new xmlrpcresp(0, 803,
|
|
"xr_downloadOpen: ".$res->getMessage().
|
|
" ".$res->getUserInfo()
|
|
);
|
|
return new xmlrpcresp(xmlrpc_encoder($res));
|
|
}
|
|
|
|
/**
|
|
* Check upload
|
|
*/
|
|
function xr_uploadCheck($input)
|
|
{
|
|
list($ok, $r) = $this->_xr_getPars($input);
|
|
if(!$ok) return $r;
|
|
$res = $this->uploadCheck($r['sessid'], $r['url']);
|
|
if(PEAR::isError($res))
|
|
return new xmlrpcresp(0, 803,
|
|
"xr_downloadOpen: ".$res->getMessage().
|
|
" ".$res->getUserInfo()
|
|
);
|
|
return new xmlrpcresp(xmlrpc_encoder($res));
|
|
}
|
|
|
|
/**
|
|
* Close upload
|
|
*/
|
|
function xr_uploadClose($input)
|
|
{
|
|
list($ok, $r) = $this->_xr_getPars($input);
|
|
if(!$ok) return $r;
|
|
$res = $this->uploadClose($r['sessid'], $r['url']);
|
|
if(PEAR::isError($res))
|
|
return new xmlrpcresp(0, 803,
|
|
"xr_downloadOpen: ".$res->getMessage().
|
|
" ".$res->getUserInfo()
|
|
);
|
|
return new xmlrpcresp(xmlrpc_encoder($res));
|
|
}
|
|
|
|
|
|
/**
|
|
* Call Archive::login
|
|
*
|
|
* @param input XMLRPC struct
|
|
*/
|
|
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 ({$r['login']}/{$r['pass']})."
|
|
);
|
|
else
|
|
return new xmlrpcresp($this->_v2xr($res, false));
|
|
}
|
|
|
|
/**
|
|
* Call Archive::logout
|
|
*
|
|
* @param input XMLRPC struct
|
|
*/
|
|
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."
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
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."
|
|
));
|
|
}
|
|
}
|
|
|
|
$archive = &new XR_Archive(&$dbc, $config);
|
|
|
|
$methods = array(
|
|
'login' => 'Login to storage.',
|
|
'logout' => 'Logout from storage.',
|
|
'ping' =>'Echo request',
|
|
'downloadOpen' =>'Open download channel',
|
|
'downloadClose' =>'Close download channel',
|
|
'uploadOpen' =>'Open upload channel',
|
|
'uploadAbort' =>'Close upload channel',
|
|
'uploadCheck' =>'Check size and checksum of uploaded file',
|
|
'uploadClose' =>'Close upload channel'
|
|
);
|
|
|
|
$defs = array();
|
|
foreach($methods as $method=>$description){
|
|
$defs["archive.$method"] = array(
|
|
"function" => array(&$archive, "xr_$method"),
|
|
"signature" => array(array($xmlrpcStruct, $xmlrpcStruct)),
|
|
"docstring" => $description
|
|
);
|
|
}
|
|
$s=new xmlrpc_server( $defs );
|
|
?>
|