joergs lehrke commit 28945 and 29844 improving syncml session handling

This commit is contained in:
Klaus Leithoff 2010-01-14 08:19:45 +00:00
parent cc873a1a80
commit 88be03483d
2 changed files with 46 additions and 51 deletions

View File

@ -146,7 +146,7 @@ class Horde_SyncML_SyncMLHdr extends Horde_SyncML_ContentHandler {
var $_maxMsgSize;
function getStateFromSession($sourceURI, $locName, $sessionID)
function &getStateFromSession($sourceURI, $locName, $sessionID)
{
// Remove any existing session since we'll be contructing a
// custom session id.
@ -214,23 +214,16 @@ class Horde_SyncML_SyncMLHdr extends Horde_SyncML_ContentHandler {
{
switch ($this->_xmlStack) {
case 2:
/*
$str = 'localname=' . $this->_locName;
$str .= ' version=' . $this->_version;
$str .= ' msgid=' . $this->_msgID;
$str .= ' source=' . $this->_sourceURI;
$str .= ' target=' . $this->_targetURI;
$str .= ' sessionID=' . $this->_sessionID;
*/
// </SyncHdr></SyncML>
// Find the state.
#Horde::logMessage('SymcML: SyncHdr done. Try to load state from session.', __FILE__, __LINE__, PEAR_LOG_DEBUG);
$state = $this->getStateFromSession($this->_sourceURI, $this->_locName, $this->_sessionID);
Horde::logMessage('SyncML['. session_id() .']: package '
. $this->_msgID.' +++++++++++++++++++++ started',
__FILE__, __LINE__, PEAR_LOG_DEBUG);
// Find the state.
//Horde::logMessage('SymcML: SyncHdr done. Try to load state from session.',
// __FILE__, __LINE__, PEAR_LOG_DEBUG);
$state =& $this->getStateFromSession($this->_sourceURI, $this->_locName, $this->_sessionID);
$state->setVersion($this->_version);
$state->setMsgID($this->_msgID);
$state->setTargetURI($this->_targetURI);
@ -247,14 +240,7 @@ class Horde_SyncML_SyncMLHdr extends Horde_SyncML_ContentHandler {
$state->setMaxMsgSize($this->_maxMsgSize);
}
#$str = 'authorized=' . $state->isAuthorized();
#$str .= ' version=' . $state->getVersion();
#$str .= ' msgid=' . $state->getMsgID();
#$str .= ' source=' . $state->getSourceURI();
#$str .= ' target=' . $state->getTargetURI();
#$str .= ' locName=' . $state->getLocName();
$_SESSION['SyncML.state'] = $state;
// $_SESSION['SyncML.state'] = $state;
#Horde::logMessage('SymcML: session id 2 =' . session_id(), __FILE__, __LINE__, PEAR_LOG_DEBUG);
@ -289,7 +275,7 @@ class Horde_SyncML_SyncMLHdr extends Horde_SyncML_ContentHandler {
// </Cred></SyncHdr></SyncML>
$this->_isCred = false;
//multisync does not specify the cred format
// We only support b64 for now
//if ($this->_credFormat == 'b64') {
$this->_credData = base64_decode($this->_credData);
//}
@ -609,7 +595,8 @@ class Horde_SyncML_SyncMLBody extends Horde_SyncML_ContentHandler {
// this packet did not contain any real actions, just status and map.
// This means, we're through! The session can be closed and
// the Anchors saved for the next Sync
Horde::logMessage('SyncML['. session_id() .']: sync' . session_id() . ' completed successfully!', __FILE__, __LINE__, PEAR_LOG_INFO);
Horde::logMessage('SyncML['. session_id() .']: sync' . session_id() . ' completed successfully!',
__FILE__, __LINE__, PEAR_LOG_INFO);
$state->writeSyncSummary();
$log = $state->getLog();
$s="";
@ -630,7 +617,8 @@ class Horde_SyncML_SyncMLBody extends Horde_SyncML_ContentHandler {
// this packet did not contain any real actions, just status and map.
// This means, we're through! The session can be closed and
// the Anchors saved for the next Sync
Horde::logMessage('SyncML['. session_id() .']: sync' . session_id() . ' completed successfully!', __FILE__, __LINE__, PEAR_LOG_INFO);
Horde::logMessage('SyncML['. session_id() .']: sync' . session_id() . ' completed successfully!',
__FILE__, __LINE__, PEAR_LOG_INFO);
$state->writeSyncSummary();
$log = $state->getLog();
$s="";

View File

@ -13,6 +13,7 @@
* @author Joerg Lehrke <jlehrke@noc.de>
* @version $Id$
*/
require_once(EGW_API_INC.'/class.egw_db.inc.php');
include_once dirname(__FILE__).'/State.php';
/**
@ -297,12 +298,12 @@ class EGW_SyncML_State extends Horde_SyncML_State
if (!$this->_isAuthorized) {
if(!isset($this->_locName) && !isset($this->_password)) {
Horde::logMessage('SyncML: Authentication not yet possible currently. Username and password not available' , __FILE__, __LINE__, PEAR_LOG_DEBUG);
return FALSE;
return false;
}
if (!isset($this->_password)) {
Horde::logMessage('SyncML: Authentication not yet possible currently. Password not available' , __FILE__, __LINE__, PEAR_LOG_DEBUG);
return FALSE;
return false;
}
if (strpos($this->_locName,'@') === False) {
@ -325,31 +326,37 @@ class EGW_SyncML_State extends Horde_SyncML_State
$GLOBALS['egw_info']['server']['db_type'] = $GLOBALS['egw_domain'][$this->_account_domain]['db_type'];
// It works -- don't ask me why.
$this->db = new egw_db($GLOBALS['egw_info']['server']);
$this->db->connect();
if (!$this->db->connect()) {
Horde::logMessage('SyncML_EGW: Can not connect to database for user ' . $this->_locName,
__FILE__, __LINE__, PEAR_LOG_ERROR);
return false;
}
#Horde::logMessage('SyncML: authenticate with username: ' . $this->_locName . ' and password: ' . $this->_password, __FILE__, __LINE__, PEAR_LOG_DEBUG);
if (($GLOBALS['sessionid'] = $GLOBALS['egw']->session->create($this->_locName,$this->_password,'text')))
{
if (($GLOBALS['sessionid'] = $GLOBALS['egw']->session->create($this->_locName,$this->_password,'text'))) {
if ($GLOBALS['egw_info']['user']['apps']['syncml']) {
$this->_isAuthorized = true;
Horde::logMessage('SyncML_EGW: Authentication of ' . $this->_locName . '/' . $GLOBALS['sessionid'] . ' succeded' , __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage('SyncML_EGW: Authentication of ' . $this->_locName . '/' . $GLOBALS['sessionid'] . ' succeded',
__FILE__, __LINE__, PEAR_LOG_DEBUG);
} else {
$this->_isAuthorized = false;
Horde::logMessage('SyncML is not enabled for user ' . $this->_locName , __FILE__, __LINE__, PEAR_LOG_ERROR);
Horde::logMessage('SyncML is not enabled for user ' . $this->_locName,
__FILE__, __LINE__, PEAR_LOG_ERROR);
}
return $this->_isAuthorized;
}
}
$this->_isAuthorized = false;
Horde::logMessage('SyncML: Authentication of ' . $this->_locName . ' failed' , __FILE__, __LINE__, PEAR_LOG_INFO);
Horde::logMessage('SyncML: Authentication of ' . $this->_locName . ' failed' ,
__FILE__, __LINE__, PEAR_LOG_INFO);
} else {
if ($this->log) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."()\n".var_export($GLOBALS['egw_info'], true)."\n",3,$this->logfile);
// store sessionID in a variable, because ->verify maybe resets that value
// store sessionID in a variable, because verify() may reset this value
$sessionID = session_id();
$GLOBALS['egw_info']['user']['domain'] = $this->_account_domain;
if (!$GLOBALS['egw']->session->verify($sessionID, 'staticsyncmlkp3')) {
Horde::logMessage('SyncML_EGW: egw session(' .$sessionID. ') not verified ' , __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage('SyncML_EGW: egw session(' .$sessionID. ') not verified' ,
__FILE__, __LINE__, PEAR_LOG_WARNING);
}
}
return $this->_isAuthorized;