Group preferences added.
This commit is contained in:
parent
997d80d406
commit
771a443d1f
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.3 $
|
||||
Version : $Revision: 1.4 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/Prefs.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -52,6 +52,7 @@ class Prefs{
|
|||
}
|
||||
|
||||
/* ======================================================= public methods */
|
||||
/* ----------------------------------------------------- user preferences */
|
||||
/**
|
||||
* Read preference record by session id
|
||||
*
|
||||
|
@ -125,11 +126,75 @@ class Prefs{
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------- group preferences */
|
||||
/**
|
||||
* Read group preference record
|
||||
*
|
||||
* @param sessid string, session id
|
||||
* @param grname string, group name
|
||||
* @param key string, preference key
|
||||
* @return string, preference value
|
||||
*/
|
||||
function loadGroupPref($sessid, $grname, $key)
|
||||
{
|
||||
$subjid = $this->gb->getSubjId($grname);
|
||||
if(PEAR::isError($subjid)) return $subjid;
|
||||
if(is_null($subjid)){
|
||||
return PEAR::raiseError(
|
||||
"Prefs::loadGroupPref: invalid group name", ALIBERR_NOTGR);
|
||||
}
|
||||
$val = $this->readVal($subjid, $key);
|
||||
if(PEAR::isError($val)) return $val;
|
||||
if($val === FALSE){
|
||||
return PEAR::raiseError(
|
||||
"Prefs::loadGroupPref: invalid preference key", GBERR_PREF);
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save group preference record
|
||||
*
|
||||
* @param sessid string, session id
|
||||
* @param grname string, group name
|
||||
* @param key string, preference key
|
||||
* @param value string, preference value
|
||||
* @return boolean
|
||||
*/
|
||||
function saveGroupPref($sessid, $grname, $key, $value)
|
||||
{
|
||||
$uid = $this->gb->getSessUserId($sessid);
|
||||
if(PEAR::isError($uid)) return $uid;
|
||||
if(is_null($uid)){
|
||||
return PEAR::raiseError(
|
||||
"Prefs::loadGroupPref: invalid session id", GBERR_SESS);
|
||||
}
|
||||
$gid = $this->gb->getSubjId($grname);
|
||||
if(PEAR::isError($gid)) return $gid;
|
||||
if(is_null($gid)){
|
||||
return PEAR::raiseError(
|
||||
"Prefs::saveGroupPref: invalid group name", GBERR_SESS);
|
||||
}
|
||||
$memb = $this->gb->isMemberOf($uid, $gid);
|
||||
if(PEAR::isError($memb)) return $memb;
|
||||
if(!$memb){
|
||||
return PEAR::raiseError(
|
||||
"Prefs::saveGroupPref: access denied", GBERR_DENY);
|
||||
}
|
||||
$r = $this->update($gid, $key, $value);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
if($r === FALSE){
|
||||
$r = $this->insert($gid, $key, $value);
|
||||
if(PEAR::isError($r)) return $r;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ===================================================== gb level methods */
|
||||
/**
|
||||
* Insert of new preference record
|
||||
*
|
||||
* @param subjid int, local user id
|
||||
* @param subjid int, local user/group id
|
||||
* @param keystr string, preference key
|
||||
* @param valstr string, preference value
|
||||
* @return int, local user id
|
||||
|
@ -151,7 +216,7 @@ class Prefs{
|
|||
/**
|
||||
* Read value of preference record
|
||||
*
|
||||
* @param subjid int, local user id
|
||||
* @param subjid int, local user/group id
|
||||
* @param keystr string, preference key
|
||||
* @return string, preference value
|
||||
*/
|
||||
|
@ -169,7 +234,7 @@ class Prefs{
|
|||
/**
|
||||
* Update value of preference record
|
||||
*
|
||||
* @param subjid int, local user id
|
||||
* @param subjid int, local user/group id
|
||||
* @param keystr string, preference key
|
||||
* @param newvalstr string, new preference value
|
||||
* @return boolean
|
||||
|
@ -189,7 +254,7 @@ class Prefs{
|
|||
/**
|
||||
* Delete preference record
|
||||
*
|
||||
* @param subjid int, local user id
|
||||
* @param subjid int, local user/group id
|
||||
* @param keystr string, preference key
|
||||
* @return boolean
|
||||
*/
|
||||
|
@ -252,6 +317,9 @@ class Prefs{
|
|||
ON {$this->prefTable} (subjid, keystr)");
|
||||
$this->dbc->query("CREATE INDEX {$this->prefTable}_subjid_idx
|
||||
ON {$this->prefTable} (subjid)");
|
||||
$stPrefGr = $this->gb->getSubjId('StationPrefs');
|
||||
$r = $this->insert($stPrefGr, 'stationName', "Radio Station 1");
|
||||
if(PEAR::isError($r)) echo $r->getMessage()."\n";
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.7 $
|
||||
Version : $Revision: 1.8 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/conf.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -63,6 +63,7 @@ $config = array(
|
|||
),
|
||||
'tblNamePrefix' => 'ls_',
|
||||
'authCookieName'=> 'lssid',
|
||||
'StationPrefsGr'=> 'StationPrefs',
|
||||
'storageDir' => dirname(getcwd()).'/stor',
|
||||
'bufferDir' => dirname(getcwd()).'/stor/buffer',
|
||||
'transDir' => dirname(getcwd()).'/trans',
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.9 $
|
||||
Version : $Revision: 1.10 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/XR_LocStor.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -1166,9 +1166,14 @@ class XR_LocStor extends LocStor{
|
|||
* <ul>
|
||||
* <li>audioClipResults : array with gunid strings
|
||||
* of audioClips have been found</li>
|
||||
* <li>audioClipCnt : int - number of audioClips matching
|
||||
* the criteria</li>
|
||||
* <li>playlistResults : array with gunid strings
|
||||
* of playlists have been found</li>
|
||||
* <li>playlistCnt : int - number of playlists matching
|
||||
* the criteria</li>
|
||||
* </ul>
|
||||
* (cnt values may be greater than size of arrays - see limit param)
|
||||
*
|
||||
* On errors, returns an XML-RPC error response.
|
||||
* The possible error codes and error message are:
|
||||
|
@ -1196,7 +1201,23 @@ class XR_LocStor extends LocStor{
|
|||
" ".$res->getUserInfo()
|
||||
);
|
||||
}
|
||||
return new XML_RPC_Response(XML_RPC_encode($res));
|
||||
# return new XML_RPC_Response(XML_RPC_encode($res));
|
||||
$xv = new XML_RPC_Value;
|
||||
$xv->addStruct(array(
|
||||
'audioClipCnt' => XML_RPC_encode($res['audioClipCnt']),
|
||||
'playlistCnt' => XML_RPC_encode($res['playlistCnt']),
|
||||
'audioClipResults' =>
|
||||
(count($res['audioClipResults'])==0
|
||||
? new XML_RPC_Value(array(), 'array')
|
||||
: XML_RPC_encode($res['audioClipResults'])
|
||||
),
|
||||
'playlistResults' =>
|
||||
(count($res['playlistResults'])==0
|
||||
? new XML_RPC_Value(array(), 'array')
|
||||
: XML_RPC_encode($res['playlistResults'])
|
||||
),
|
||||
));
|
||||
return $xv;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------- methods for preferences */
|
||||
|
@ -1351,6 +1372,114 @@ class XR_LocStor extends LocStor{
|
|||
return new XML_RPC_Response(XML_RPC_encode(array('status'=>$res)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read group preference record
|
||||
*
|
||||
* The XML-RPC name of this method is "locstor.loadGroupPref".
|
||||
*
|
||||
* The input parameters are an XML-RPC struct with the following
|
||||
* fields:
|
||||
* <ul>
|
||||
* <li> sessid : string - session id </li>
|
||||
* <li> group : string - group name </li>
|
||||
* <li> key : string - preference key </li>
|
||||
* </ul>
|
||||
*
|
||||
* On success, returns a XML-RPC struct with single field:
|
||||
* <ul>
|
||||
* <li> value : string - preference value </li>
|
||||
* </ul>
|
||||
*
|
||||
* On errors, returns an XML-RPC error response.
|
||||
* The possible error codes and error message are:
|
||||
* <ul>
|
||||
* <li> 3 - Incorrect parameters passed to method:
|
||||
* Wanted ... , got ... at param </li>
|
||||
* <li> 801 - wrong 1st parameter, struct expected.</li>
|
||||
* <li> 805 - xr_loadGroupPref:
|
||||
* <message from lower layer> </li>
|
||||
* <li> 820 - invalid group name.</li>
|
||||
* <li> 848 - invalid session id.</li>
|
||||
* <li> 849 - invalid preference key.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param input XMLRPC struct
|
||||
* @return XMLRPC struct
|
||||
* @see Pref::loadGroupPref
|
||||
*/
|
||||
function xr_loadGroupPref($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
require_once '../../../storageServer/var/Prefs.php';
|
||||
$pr =& new Prefs(&$this);
|
||||
$res = $pr->loadGroupPref($r['sessid'], $r['group'], $r['key']);
|
||||
if(PEAR::isError($res)){
|
||||
$ec0 = intval($res->getCode());
|
||||
$ec = (
|
||||
$ec0 == GBERR_SESS || $ec0 == GBERR_PREF || $ec0==ALIBERR_NOTGR
|
||||
? 800+$ec0 : 805
|
||||
);
|
||||
return new XML_RPC_Response(0, $ec,
|
||||
"xr_getAudioClip: ".$res->getMessage()." ".$res->getUserInfo()
|
||||
|
||||
);
|
||||
}
|
||||
return new XML_RPC_Response(XML_RPC_encode(array('value'=>$res)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save group preference record
|
||||
*
|
||||
* The XML-RPC name of this method is "locstor.saveGroupPref".
|
||||
*
|
||||
* The input parameters are an XML-RPC struct with the following
|
||||
* fields:
|
||||
* <ul>
|
||||
* <li> sessid : string - session id </li>
|
||||
* <li> group : string - group name </li>
|
||||
* <li> key : string - preference key </li>
|
||||
* <li> value : string - preference value </li>
|
||||
* </ul>
|
||||
*
|
||||
* On success, returns a XML-RPC struct with single field:
|
||||
* <ul>
|
||||
* <li> status : boolean</li>
|
||||
* </ul>
|
||||
*
|
||||
* On errors, returns an XML-RPC error response.
|
||||
* The possible error codes and error message are:
|
||||
* <ul>
|
||||
* <li> 3 - Incorrect parameters passed to method:
|
||||
* Wanted ... , got ... at param </li>
|
||||
* <li> 801 - wrong 1st parameter, struct expected.</li>
|
||||
* <li> 805 - xr_saveGroupPref:
|
||||
* <message from lower layer> </li>
|
||||
* <li> 820 - invalid group name.</li>
|
||||
* <li> 848 - invalid session id.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param input XMLRPC struct
|
||||
* @return XMLRPC struct
|
||||
* @see Pref::saveGroupPref
|
||||
*/
|
||||
function xr_saveGroupPref($input)
|
||||
{
|
||||
list($ok, $r) = $this->_xr_getPars($input);
|
||||
if(!$ok) return $r;
|
||||
require_once '../../../storageServer/var/Prefs.php';
|
||||
$pr =& new Prefs(&$this);
|
||||
$res = $pr->saveGroupPref($r['sessid'], $r['group'], $r['key'], $r['value']);
|
||||
if(PEAR::isError($res)){
|
||||
$ec0 = intval($res->getCode());
|
||||
$ec = ($ec0==GBERR_SESS || $ec0==ALIBERR_NOTGR ? 800+$ec0 : 805 );
|
||||
return new XML_RPC_Response(0, $ec,
|
||||
"xr_getAudioClip: ".$res->getMessage()." ".$res->getUserInfo()
|
||||
);
|
||||
}
|
||||
return new XML_RPC_Response(XML_RPC_encode(array('status'=>$res)));
|
||||
}
|
||||
|
||||
/* -------------------------------------------- remote repository methods */
|
||||
/**
|
||||
* Starts upload audioclip to remote archive
|
||||
|
@ -1466,7 +1595,8 @@ class XR_LocStor extends LocStor{
|
|||
* <ul>
|
||||
* <li>trtype: string - audioclip | playlist</li>
|
||||
* <li>direction: string - up | down</li>
|
||||
* <li>status: boolean</li>
|
||||
* <li>status: boolean - true if file have been
|
||||
* succesfully transported</li>
|
||||
* <li>expectedsize: int - expected size</li>
|
||||
* <li>realsize: int - size of transported file</li>
|
||||
* <li>expectedsum: string - expected checksum</li>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#
|
||||
#
|
||||
# Author : $Author: tomas $
|
||||
# Version : $Revision: 1.17 $
|
||||
# Version : $Revision: 1.18 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/testRunner.sh,v $
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
|
@ -231,9 +231,9 @@ deletePlaylist() {
|
|||
prefTest() {
|
||||
PREFKEY="testKey"
|
||||
PREFVAL="test preference value"
|
||||
echo -n "# savePref: "
|
||||
echo -n "# savePref ($PREFKEY): "
|
||||
$XR_CLI savePref $SESSID "$PREFKEY" "$PREFVAL"|| exit $?
|
||||
echo -n "# loadPref: "
|
||||
echo -n "# loadPref ($PREFKEY): "
|
||||
VAL=`$XR_CLI loadPref $SESSID "$PREFKEY"` || \
|
||||
{ ERN=$?; echo $VAL; exit $ERN; }
|
||||
echo "$VAL "
|
||||
|
@ -255,6 +255,28 @@ prefTest() {
|
|||
fi
|
||||
}
|
||||
|
||||
groupPrefTest() {
|
||||
PREFKEY="Station frequency"
|
||||
PREFVAL="89.5 FM"
|
||||
GR="StationPrefs"
|
||||
echo -n "# saveGroupPref ($PREFKEY): "
|
||||
$XR_CLI saveGroupPref $SESSID "$GR" "$PREFKEY" "$PREFVAL"|| exit $?
|
||||
echo -n "# loadGroupPref ($PREFKEY): "
|
||||
VAL=`$XR_CLI loadGroupPref $SESSID "$GR" "$PREFKEY"` || \
|
||||
{ ERN=$?; echo $VAL; exit $ERN; }
|
||||
echo "$VAL "
|
||||
if [ "x$VAL" != "x$PREFVAL" ] ; then
|
||||
echo " NOT MATCH"
|
||||
echo " Expected:"; echo $PREFVAL
|
||||
echo " Returned:"; echo $VAL
|
||||
exit 1
|
||||
else
|
||||
echo "# pref value check: OK"
|
||||
fi
|
||||
echo -n "# saveGroupPref (clear it): "
|
||||
$XR_CLI saveGroupPref $SESSID "$GR" "$PREFKEY" ""|| exit $?
|
||||
}
|
||||
|
||||
logout() {
|
||||
echo -n "# logout: "
|
||||
$XR_CLI logout $SESSID || exit $?
|
||||
|
@ -264,6 +286,7 @@ preferenceTest(){
|
|||
echo "#XMLRPC preference test"
|
||||
login
|
||||
prefTest
|
||||
groupPrefTest
|
||||
logout
|
||||
echo "#XMLRPC: preference: OK."
|
||||
echo ""
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.18 $
|
||||
Version : $Revision: 1.19 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/xrLocStor.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -117,6 +117,8 @@ $methods = array(
|
|||
'loadPref' => 'Load user preference value.',
|
||||
'savePref' => 'Save user preference value.',
|
||||
'delPref' => 'Delete user preference record.',
|
||||
'loadGroupPref' => 'Read group preference record.',
|
||||
'saveGroupPref' => 'Delete user preference record.',
|
||||
|
||||
'uploadToArchive' => 'Starts upload audioclip to remote archive.',
|
||||
'downloadFromArchive' => 'Starts download audioclip from remote archive.',
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
|
||||
Author : $Author: tomas $
|
||||
Version : $Revision: 1.2 $
|
||||
Version : $Revision: 1.3 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageServer/var/xmlrpc/xr_cli_test.php,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -37,7 +37,9 @@ if($pars[0] == '-v'){ $verbose = TRUE; array_shift($pars); }
|
|||
if($pars[0] == '-s'){
|
||||
array_shift($pars);
|
||||
$serverPath = array_shift($pars);
|
||||
}else $serverPath = 'http://localhost:80/livesupportStorageServer/xmlrpc/xrLocStor.php';
|
||||
}else{
|
||||
$serverPath = 'http://localhost:80/livesupportStorageServer/xmlrpc/xrLocStor.php';
|
||||
}
|
||||
|
||||
#$serverPath = "http://localhost:80/livesupportStorageServerCVS/xmlrpc/xrLocStor.php";
|
||||
|
||||
|
@ -122,6 +124,10 @@ $infos = array(
|
|||
'p'=>array('sessid', 'key', 'value'), 'r'=>'status'),
|
||||
"delPref" => array('m'=>"locstor.delPref",
|
||||
'p'=>array('sessid', 'key'), 'r'=>'status'),
|
||||
"loadGroupPref" => array('m'=>"locstor.loadGroupPref",
|
||||
'p'=>array('sessid', 'group', 'key'), 'r'=>'value'),
|
||||
"saveGroupPref" => array('m'=>"locstor.saveGroupPref",
|
||||
'p'=>array('sessid', 'group', 'key', 'value'), 'r'=>'status'),
|
||||
|
||||
"uploadToArchive" => array('m'=>"locstor.uploadToArchive",
|
||||
'p'=>array('sessid', 'gunid'), 'r'=>'trtok'),
|
||||
|
|
Loading…
Reference in New Issue