Skip to content

Commit

Permalink
Merge branch 'master' into horde_5_2
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Oct 22, 2013
2 parents 7666a12 + ec7a55d commit 30b5776
Show file tree
Hide file tree
Showing 30 changed files with 2,893 additions and 732 deletions.
92 changes: 56 additions & 36 deletions framework/ActiveSync/lib/Horde/ActiveSync.php
Expand Up @@ -392,6 +392,13 @@ class Horde_ActiveSync
*/
protected $_globalError = false;

/**
* Process id (used in logging).
*
* @var integer
*/
protected $_procid;

/**
* Supported EAS versions.
*
Expand Down Expand Up @@ -454,6 +461,8 @@ public function __construct(
// Wbxml handlers
$this->_encoder = $encoder;
$this->_decoder = $decoder;

$this->_procid = $this->_procid;
}

/**
Expand Down Expand Up @@ -530,7 +539,10 @@ public function authenticate($username = '')
$user = $username;
} else {
// No provided username or Authorization header.
self::$_logger->debug('Client did not provide authentication data.');
self::$_logger->notice(sprintf(
'[%s] Client did not provide authentication data.',
$this->_procid)
);
return false;
}
$user = $this->_driver->getUsernameFromEmail($user);
Expand Down Expand Up @@ -714,9 +726,9 @@ public function handleRequest($cmd, $devId)
// Set provisioning support now that we are authenticated.
$this->setProvisioning($this->_driver->getProvisioning());

self::$_logger->debug(sprintf(
self::$_logger->info(sprintf(
'[%s] %s request received for user %s',
getmypid(),
$this->_procid,
strtoupper($cmd),
$this->_driver->getUser())
);
Expand Down Expand Up @@ -744,56 +756,59 @@ public function handleRequest($cmd, $devId)
if (!$this->_state->deviceExists($devId, $this->_driver->getUser())) {
// Device might exist, but with a new (additional) user account
if ($this->_state->deviceExists($devId)) {
$device = $this->_state->loadDeviceInfo($devId);
$this->_device = $this->_state->loadDeviceInfo($devId);
} else {
$device = new Horde_ActiveSync_Device($this->_state);
$this->_device = new Horde_ActiveSync_Device($this->_state);
}
$device->policykey = 0;
$device->userAgent = $this->_request->getHeader('User-Agent');
$device->deviceType = !empty($get['DeviceType']) ? $get['DeviceType'] : '';
$device->rwstatus = self::RWSTATUS_NA;
$device->user = $this->_driver->getUser();
$device->id = $devId;
$device->properties['version'] = $version;
// Call this to be sure we add the announced versions.
$device->needsVersionUpdate($this->getSupportedVersions());
$this->_device->policykey = 0;
$this->_device->userAgent = $this->_request->getHeader('User-Agent');
$this->_device->deviceType = !empty($get['DeviceType']) ? $get['DeviceType'] : '';
$this->_device->rwstatus = self::RWSTATUS_NA;
$this->_device->user = $this->_driver->getUser();
$this->_device->id = $devId;
$this->_device->version = $version;
$this->_device->needsVersionUpdate($this->getSupportedVersions());

// @TODO: Remove is_callable check (and extra else clause) for H6.
if (is_callable(array($this->_driver, 'createDeviceCallback'))) {
$callback_ret = $this->_driver->createDeviceCallback($device);
$callback_ret = $this->_driver->createDeviceCallback($this->_device);
if ($callback_ret !== true) {
$msg = sprintf(
'The device %s was disallowed for user %s per policy settings.',
$device->id,
$device->user);
$this->_logger->err($msg);
$this->_device->id,
$this->_device->user);
self::$_logger->err($msg);
if ($version > self::VERSION_TWELVEONE) {
$this->_globalError = $callback_ret;
} else {
throw new Horde_ActiveSync_Exception($msg);
}
} else {
$device->save();
$this->_device->save();
}
} else {
$device->save();
$this->_device->save();
}
} else {
$device = $this->_state->loadDeviceInfo($devId, $this->_driver->getUser());
$device->properties['version'] = $version;
$this->_device = $this->_state->loadDeviceInfo($devId, $this->_driver->getUser());
$this->_device->version = $version;
// Check this here so we only need to save the device object once.
if ($device->properties['version'] < $this->_maxVersion && $device->needsVersionUpdate($this->getSupportedVersions())) {
if ($this->_device->properties['version'] < $this->_maxVersion &&
$this->_device->needsVersionUpdate($this->getSupportedVersions())) {

$needMsRp = true;
}
$device->save();

$this->_device->save();

if (is_callable(array($this->_driver, 'deviceCallback'))) {
$callback_ret = $this->_driver->deviceCallback($device);
$callback_ret = $this->_driver->deviceCallback($this->_device);
if ($callback_ret !== true) {
$msg = sprintf(
'The device %s was disallowed for user %s per policy settings.',
$device->id,
$device->user);
$this->_logger->err($msg);
$this->_device->id,
$this->_device->user);
self::$_logger->err($msg);
if ($version > self::VERSION_TWELVEONE) {
$this->_globalError = $callback_ret;
} else {
Expand All @@ -803,11 +818,6 @@ public function handleRequest($cmd, $devId)
}
}

// Always set the version information instead of caching it, some
// clients may allow changing the protocol version.
$device->version = $version;
$this->_device = $device;

// Don't bother with everything else if all we want are Options
if ($cmd == 'Options') {
$this->_doOptionsRequest();
Expand All @@ -823,7 +833,10 @@ public function handleRequest($cmd, $devId)
if ((!empty($headers['ms-asacceptmultipart']) && $headers['ms-asacceptmultipart'] == 'T') ||
!empty($get['AcceptMultiPart'])) {
$this->_multipart = true;
self::$_logger->debug('MULTIPART REQUEST');
self::$_logger->info(sprintf(
'[%s] Requesting multipart data.',
$this->_procid)
);
}

// Load the request handler to handle the request
Expand All @@ -837,7 +850,10 @@ public function handleRequest($cmd, $devId)

// Should we announce a new version is available to the client?
if (!empty($needMsRp)) {
self::$_logger->info('Announcing X-MS-RP to client.');
self::$_logger->info(sprintf(
'[%s] Announcing X-MS-RP to client.',
$this->_procid)
);
header("X-MS-RP: ". $this->getSupportedVersions());
}

Expand All @@ -846,7 +862,11 @@ public function handleRequest($cmd, $devId)
$request = new $class($this);
$request->setLogger(self::$_logger);
$result = $request->handle();
self::$_logger->debug('Maximum memory usage for ActiveSync request: ' . memory_get_peak_usage());
self::$_logger->info(sprintf(
'[%s] Maximum memory usage for ActiveSync request: %d bytes.',
$this->_procid,
memory_get_peak_usage())
);

return $result;
}
Expand Down
19 changes: 12 additions & 7 deletions framework/ActiveSync/lib/Horde/ActiveSync/Collections.php
Expand Up @@ -268,7 +268,7 @@ public function addCollection(array $collection, $requireSyncKey = false)
? $cached_collections[$collection['id']]['lastsynckey']
: 0;

if ($collection['synckey'] == 0) {
if ($collection['synckey'] === 0) {
$this->_logger->err(sprintf('[%s] Attempting to add a collection
to the sync cache while requiring a synckey, but no
synckey could be found. Most likely a client error in
Expand Down Expand Up @@ -316,10 +316,14 @@ public function getBackendIdForFolderUid($folderid)
*
* @return string The EAS uid.
*/

public function getFolderUidForBackendId($id)
public function getFolderUidForBackendId($folderid)
{
return $this->_as->state->getFolderUidForBackendId($id);
$map = $this->_as->state->getFolderUidToBankendIdMap();
if (empty($map[$folderid])) {
return false;
}

return $map[$folderid];
}

/**
Expand Down Expand Up @@ -745,8 +749,9 @@ public function initPartialSync()
$csk = $this->_cache->confirmed_synckeys;
if ($csk) {
$this->_logger->info(sprintf(
'Confirmed Synckeys contains %s',
print_r($csk, true))
'[%s] Confirmed Synckeys contains %s',
$this->_procid,
serialize($csk))
);
$this->_logger->err('Some synckeys were not confirmed. Requesting full SYNC');
$this->save();
Expand Down Expand Up @@ -1193,4 +1198,4 @@ public function getIterator()
return new ArrayIterator($this->_collections);
}

}
}
21 changes: 17 additions & 4 deletions framework/ActiveSync/lib/Horde/ActiveSync/Connector/Exporter.php
Expand Up @@ -101,6 +101,13 @@ class Horde_ActiveSync_Connector_Exporter
*/
protected $_as;

/**
* Process id for logging.
*
* @var integer
*/
protected $_procid;

/**
* Const'r
*
Expand All @@ -116,6 +123,7 @@ public function __construct(
$this->_as = $as;
$this->_encoder = $encoder;
$this->_logger = $as->logger;
$this->_procid = getmypid();
}

/**
Expand Down Expand Up @@ -163,7 +171,7 @@ public function sendNextChange()
} else {
$this->_logger->err(sprintf(
'[%s] Error stating %s: ignoring.',
getmypid(), $change['id']));
$this->_procid, $change['id']));
$stat = array('id' => $change['id'], 'mod' => $change['id'], 0);
}
// Update the state.
Expand Down Expand Up @@ -207,12 +215,17 @@ public function sendNextChange()
$message->flags = (isset($change['flags'])) ? $change['flags'] : 0;
$this->messageChange($change['id'], $message);
} catch (Horde_Exception_NotFound $e) {
$this->_logger->err('Message gone or error reading message from server: ' . $e->getMessage());
$this->_logger->err(sprintf(
'[%s] Message gone or error reading message from server: %s',
$this->_procid, $e->getMessage()));
$this->_as->state->updateState($change['type'], $change);
$this->_step++;
return $e;
} catch (Horde_ActiveSync_Exception $e) {
$this->_logger->err('Unknown backend error skipping message: ' . $e->getMessage());
$this->_logger->err(sprintf(
'[%s] Unknown backend error skipping message: %s',
$this->_procid,
$e->getMessage()));
}
break;

Expand Down Expand Up @@ -287,7 +300,7 @@ public function messageChange($id, Horde_ActiveSync_Message_Base $message)
in_array($id, $this->_seenObjects)) {
$this->_logger->err(sprintf(
'[%s] IGNORING message %s since it looks like it was already sent or does not belong to this collection.',
getmypid(),
$this->_procid,
$id));
return;
}
Expand Down
14 changes: 11 additions & 3 deletions framework/ActiveSync/lib/Horde/ActiveSync/Connector/Importer.php
Expand Up @@ -78,6 +78,13 @@ class Horde_ActiveSync_Connector_Importer
*/
protected $_logger;

/**
* Process id for logging.
*
* @var integer
*/
protected $_procid;

/**
* Const'r
*
Expand All @@ -86,6 +93,7 @@ class Horde_ActiveSync_Connector_Importer
public function __construct(Horde_ActiveSync $as)
{
$this->_as = $as;
$this->_procid = getmypid();
}

/**
Expand Down Expand Up @@ -152,7 +160,7 @@ public function importMessageChange(
if ($conflict && $this->_flags == Horde_ActiveSync::CONFLICT_OVERWRITE_PIM) {
$this->_logger->notice(sprintf(
'[%s] Conflict when updating %s, will overwrite client version on next sync.',
getmypid(), $id)
$this->_procid, $id)
);
return array($id, Horde_ActiveSync_Request_Sync::STATUS_CONFLICT);
}
Expand All @@ -161,7 +169,7 @@ public function importMessageChange(
// Already saw this addition, but PIM never received UID
$this->_logger->notice(sprintf(
'[%s] Duplicate addition for %s',
getmypid(), $uid)
$this->_procid, $uid)
);
return $uid;
}
Expand All @@ -171,7 +179,7 @@ public function importMessageChange(
if (!$stat = $this->_as->driver->changeMessage($this->_folderId, $id, $message, $device)) {
$this->_logger->err(sprintf(
'[%s] Change message failed when updating %s',
getmypid(), $id)
$this->_procid, $id)
);
return false;
}
Expand Down

0 comments on commit 30b5776

Please sign in to comment.