Back to index

d-push  2.0
Public Member Functions | Static Public Member Functions | Static Protected Attributes
Ping Class Reference
Inheritance diagram for Ping:
Inheritance graph
[legend]
Collaboration diagram for Ping:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Handle ($commandCode)
 Handles the Ping command.

Static Public Member Functions

static Authenticate ()
 Authenticates the remote user The sent HTTP authentication information is used to on Backend->Logon().
static isUserAuthenticated ()
 Indicates if the user was "authenticated".
static Initialize ()
 Initialize the RequestProcessor.
static HandleRequest ()
 Loads the command handler and processes a command sent from the mobile.

Static Protected Attributes

static $backend
static $deviceManager
static $topCollector
static $decoder
static $encoder
static $userIsAuthenticated

Detailed Description

Definition at line 44 of file ping.php.


Member Function Documentation

static RequestProcessor::Authenticate ( ) [static, inherited]

Authenticates the remote user The sent HTTP authentication information is used to on Backend->Logon().

As second step the GET-User verified by Backend->Setup() for permission check Request::GetGETUser() is usually the same as the Request::GetAuthUser(). If the GETUser is different from the AuthUser, the AuthUser MUST HAVE admin permissions on GETUsers data store. Only then the Setup() will be sucessfull. This allows the user 'john' to do operations as user 'joe' if he has sufficient privileges.

public

Returns:
Exceptions:
AuthenticationRequiredException

Definition at line 72 of file requestprocessor.php.

                                          {
        self::$userIsAuthenticated = false;

        $backend = ZPush::GetBackend();
        if($backend->Logon(Request::GetAuthUser(), Request::GetAuthDomain(), Request::GetAuthPassword()) == false)
            throw new AuthenticationRequiredException("Access denied. Username or password incorrect");

        // mark this request as "authenticated"
        self::$userIsAuthenticated = true;

        // check Auth-User's permissions on GETUser's store
        if($backend->Setup(Request::GetGETUser(), true) == false)
            throw new AuthenticationRequiredException(sprintf("Not enough privileges of '%s' to setup for user '%s': Permission denied", Request::GetAuthUser(), Request::GetGETUser()));
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Ping::Handle ( commandCode)

Handles the Ping command.

Parameters:
int$commandCodepublic
Returns:
boolean

Reimplemented from RequestProcessor.

Definition at line 54 of file ping.php.

                                         {
        $interval = (defined('PING_INTERVAL') && PING_INTERVAL > 0) ? PING_INTERVAL : 30;
        $pingstatus = false;
        $fakechanges = array();
        $foundchanges = false;

        // Contains all requested folders (containers)
        $sc = new SyncCollections();

        // Load all collections - do load states and check permissions
        try {
            $sc->LoadAllCollections(true, true, true);
        }
        catch (StateNotFoundException $snfex) {
            $pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED;
            self::$topCollector->AnnounceInformation("StateNotFoundException: require HierarchySync", true);
        }
        catch (StateInvalidException $snfex) {
            // we do not have a ping status for this, but SyncCollections should have generated fake changes for the folders which are broken
            $fakechanges = $sc->GetChangedFolderIds();
            $foundchanges = true;

            self::$topCollector->AnnounceInformation("StateInvalidException: force sync", true);
        }
        catch (StatusException $stex) {
            $pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED;
            self::$topCollector->AnnounceInformation("StatusException: require HierarchySync", true);
        }

        ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandlePing(): reference PolicyKey for PING: %s", $sc->GetReferencePolicyKey()));

        // receive PING initialization data
        if(self::$decoder->getElementStartTag(SYNC_PING_PING)) {
            self::$topCollector->AnnounceInformation("Processing PING data");
            ZLog::Write(LOGLEVEL_DEBUG, "HandlePing(): initialization data received");

            if(self::$decoder->getElementStartTag(SYNC_PING_LIFETIME)) {
                $sc->SetLifetime(self::$decoder->getElementContent());
                self::$decoder->getElementEndTag();
            }

            if(($el = self::$decoder->getElementStartTag(SYNC_PING_FOLDERS)) && $el[EN_FLAGS] & EN_FLAGS_CONTENT) {
                // remove PingableFlag from all collections
                foreach ($sc as $folderid => $spa)
                    $spa->DelPingableFlag();

                while(self::$decoder->getElementStartTag(SYNC_PING_FOLDER)) {
                    while(1) {
                        if(self::$decoder->getElementStartTag(SYNC_PING_SERVERENTRYID)) {
                            $folderid = self::$decoder->getElementContent();
                            self::$decoder->getElementEndTag();
                        }
                        if(self::$decoder->getElementStartTag(SYNC_PING_FOLDERTYPE)) {
                            $class = self::$decoder->getElementContent();
                            self::$decoder->getElementEndTag();
                        }

                        $e = self::$decoder->peek();
                        if($e[EN_TYPE] == EN_TYPE_ENDTAG) {
                            self::$decoder->getElementEndTag();
                            break;
                        }
                    }

                    $spa = $sc->GetCollection($folderid);
                    if (! $spa) {
                        // The requested collection is not synchronized.
                        // check if the HierarchyCache is available, if not, trigger a HierarchySync
                        try {
                            self::$deviceManager->GetFolderClassFromCacheByID($folderid);
                        }
                        catch (NoHierarchyCacheAvailableException $nhca) {
                            ZLog::Write(LOGLEVEL_INFO, sprintf("HandlePing(): unknown collection '%s', triggering HierarchySync", $folderid));
                            $pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED;
                        }

                        // Trigger a Sync request because then the device will be forced to resync this folder.
                        $fakechanges[$folderid] = 1;
                        $foundchanges = true;
                    }
                    else if ($class == $spa->GetContentClass()) {
                        $spa->SetPingableFlag(true);
                        ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandlePing(): using saved sync state for '%s' id '%s'", $spa->GetContentClass(), $folderid));
                    }

                }
                if(!self::$decoder->getElementEndTag())
                    return false;
            }
            if(!self::$decoder->getElementEndTag())
                return false;

            // save changed data
            foreach ($sc as $folderid => $spa)
                $sc->SaveCollection($spa);
        } // END SYNC_PING_PING

        // Check for changes on the default LifeTime, set interval and ONLY on pingable collections
        try {
            if (empty($fakechanges)) {
                $foundchanges = $sc->CheckForChanges($sc->GetLifetime(), $interval, true);
            }
        }
        catch (StatusException $ste) {
            switch($ste->getCode()) {
                case SyncCollections::ERROR_NO_COLLECTIONS:
                    $pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS;
                    break;
                case SyncCollections::ERROR_WRONG_HIERARCHY:
                    $pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED;
                    self::$deviceManager->AnnounceProcessStatus(false, $pingstatus);
                    break;

            }
        }

        self::$encoder->StartWBXML();
        self::$encoder->startTag(SYNC_PING_PING);
        {
            self::$encoder->startTag(SYNC_PING_STATUS);
            if (isset($pingstatus) && $pingstatus)
                self::$encoder->content($pingstatus);
            else
                self::$encoder->content($foundchanges ? SYNC_PINGSTATUS_CHANGES : SYNC_PINGSTATUS_HBEXPIRED);
            self::$encoder->endTag();

            if (! $pingstatus) {
                self::$encoder->startTag(SYNC_PING_FOLDERS);

                if (empty($fakechanges))
                    $changes = $sc->GetChangedFolderIds();
                else
                    $changes = $fakechanges;

                foreach ($changes as $folderid => $changecount) {
                    if ($changecount > 0) {
                        self::$encoder->startTag(SYNC_PING_FOLDER);
                        self::$encoder->content($folderid);
                        self::$encoder->endTag();
                        if (empty($fakechanges))
                            self::$topCollector->AnnounceInformation(sprintf("Found change in %s", $sc->GetCollection($folderid)->GetContentClass()), true);
                    }
                }
                self::$encoder->endTag();
            }
        }
        self::$encoder->endTag();

        return true;
    }

Here is the call graph for this function:

static RequestProcessor::HandleRequest ( ) [static, inherited]

Loads the command handler and processes a command sent from the mobile.

public

Returns:
boolean

Definition at line 122 of file requestprocessor.php.

                                           {
        $handler = ZPush::GetRequestHandlerForCommand(Request::GetCommandCode());

        // TODO handle WBXML exceptions here and print stack
        return $handler->Handle(Request::GetCommandCode());
    }

Here is the call graph for this function:

static RequestProcessor::Initialize ( ) [static, inherited]

Initialize the RequestProcessor.

public

Returns:

Definition at line 105 of file requestprocessor.php.

                                        {
        self::$backend = ZPush::GetBackend();
        self::$deviceManager = ZPush::GetDeviceManager();
        self::$topCollector = ZPush::GetTopCollector();

        if (!ZPush::CommandNeedsPlainInput(Request::GetCommandCode()))
            self::$decoder = new WBXMLDecoder(Request::GetInputStream());

        self::$encoder = new WBXMLEncoder(Request::GetOutputStream());
    }

Here is the call graph for this function:

static RequestProcessor::isUserAuthenticated ( ) [static, inherited]

Indicates if the user was "authenticated".

public

Returns:
boolean

Definition at line 93 of file requestprocessor.php.

                                                 {
        if (!isset(self::$userIsAuthenticated))
            return false;
        return self::$userIsAuthenticated;
    }

Here is the caller graph for this function:


Member Data Documentation

RequestProcessor::$backend [static, protected, inherited]

Definition at line 52 of file requestprocessor.php.

RequestProcessor::$decoder [static, protected, inherited]

Definition at line 55 of file requestprocessor.php.

RequestProcessor::$deviceManager [static, protected, inherited]

Definition at line 53 of file requestprocessor.php.

RequestProcessor::$encoder [static, protected, inherited]

Definition at line 56 of file requestprocessor.php.

RequestProcessor::$topCollector [static, protected, inherited]

Definition at line 54 of file requestprocessor.php.

RequestProcessor::$userIsAuthenticated [static, protected, inherited]

Definition at line 57 of file requestprocessor.php.


The documentation for this class was generated from the following file: