public function handleHeader(&$hdr)
{
if (is_object($this->_wbxmlparser)) {
/* The WBXML parser only knows about the charset once parsing is
* started. So setup charset now. */
$this->_xmlWriter->output->setVersion($this->_wbxmlparser->getVersion());
$this->_xmlWriter->output->setCharset($this->_wbxmlparser->getCharsetStr());
$GLOBALS['backend']->setCharset($this->_wbxmlparser->getCharsetStr());
}
/* Start the session. */
$hdr->setupState();
$state = $GLOBALS['backend']->state;
$state->wbxml = $this->_xmlWriter->isWBXML();
/* Check auth. */
if (!$state->authenticated) {
$auth = $GLOBALS['backend']->checkAuthentication($hdr->user, $hdr->credData, $hdr->credFormat, $hdr->credType);
if ($auth !== false) {
$state->authenticated = true;
$statuscode = Horde_SyncMl::RESPONSE_AUTHENTICATION_ACCEPTED;
$state->user = $auth;
$GLOBALS['backend']->setUser($auth);
} else {
if (!$hdr->credData) {
$statuscode = Horde_SyncMl::RESPONSE_CREDENTIALS_MISSING;
} else {
$statuscode = Horde_SyncMl::RESPONSE_INVALID_CREDENTIALS;
}
$GLOBALS['backend']->logMessage('Invalid authentication', 'DEBUG');
}
} else {
$statuscode = Horde_SyncMl::RESPONSE_OK;
$GLOBALS['backend']->setUser($state->user);
}
/* Create <SyncML>. */
$this->_xmlWriter->outputInit();
/* Got the state; now write our SyncHdr header. */
$this->_xmlWriter->outputHeader($this->_respURI);
/* Creates <SyncBody>. */
$this->_xmlWriter->outputBodyStart();
/* Output status for SyncHdr. */
$this->_xmlWriter->outputStatus('0', 'SyncHdr', $statuscode, $state->targetURI, $state->sourceURI);
/* Debug logging string. */
$str = 'Authenticated: ' . ($state->authenticated ? 'yes' : 'no') . '; version: ' . $state->getVerDTD() . '; message ID: ' . $state->messageID . '; source URI: ' . $state->sourceURI . '; target URI: ' . $state->targetURI . '; user: ' . $state->user . '; charset: ' . $GLOBALS['backend']->getCharset() . '; wbxml: ' . ($state->wbxml ? 'yes' : 'no');
$GLOBALS['backend']->logMessage($str, 'DEBUG');
}