Back to index

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

List of all members.

Public Member Functions

 Handle ($commandCode)
 Handles creates, updates or deletes of a folder issued by the commands FolderCreate, FolderUpdate and FolderDelete.

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 folderchange.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:

FolderChange::Handle ( commandCode)

Handles creates, updates or deletes of a folder issued by the commands FolderCreate, FolderUpdate and FolderDelete.

Parameters:
int$commandCodepublic
Returns:
boolean

Reimplemented from RequestProcessor.

Definition at line 55 of file folderchange.php.

                                          {
        $el = self::$decoder->getElement();

        if($el[EN_TYPE] != EN_TYPE_STARTTAG)
            return false;

        $create = $update = $delete = false;
        if($el[EN_TAG] == SYNC_FOLDERHIERARCHY_FOLDERCREATE)
            $create = true;
        else if($el[EN_TAG] == SYNC_FOLDERHIERARCHY_FOLDERUPDATE)
            $update = true;
        else if($el[EN_TAG] == SYNC_FOLDERHIERARCHY_FOLDERDELETE)
            $delete = true;

        if(!$create && !$update && !$delete)
            return false;

        // SyncKey
        if(!self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_SYNCKEY))
            return false;
        $synckey = self::$decoder->getElementContent();
        if(!self::$decoder->getElementEndTag())
            return false;

        // ServerID
        $serverid = false;
        if(self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_SERVERENTRYID)) {
            $serverid = self::$decoder->getElementContent();
            if(!self::$decoder->getElementEndTag())
                return false;
        }

        // Parent
        $parentid = false;

        // when creating or updating more information is necessary
        if (!$delete) {
            if(self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_PARENTID)) {
                $parentid = self::$decoder->getElementContent();
                if(!self::$decoder->getElementEndTag())
                    return false;
            }

            // Displayname
            if(!self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_DISPLAYNAME))
                return false;
            $displayname = self::$decoder->getElementContent();
            if(!self::$decoder->getElementEndTag())
                return false;

            // Type
            $type = false;
            if(self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_TYPE)) {
                $type = self::$decoder->getElementContent();
                if(!self::$decoder->getElementEndTag())
                    return false;
            }
        }

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

        $status = SYNC_FSSTATUS_SUCCESS;
        // Get state of hierarchy
        try {
            $syncstate = self::$deviceManager->GetStateManager()->GetSyncState($synckey);
            $newsynckey = self::$deviceManager->GetStateManager()->GetNewSyncKey($synckey);

            // Over the ChangesWrapper the HierarchyCache is notified about all changes
            $changesMem = self::$deviceManager->GetHierarchyChangesWrapper();

            // the hierarchyCache should now fully be initialized - check for changes in the additional folders
            $changesMem->Config(ZPush::GetAdditionalSyncFolders());

            // there are unprocessed changes in the hierarchy, trigger resync
            if ($changesMem->GetChangeCount() > 0)
                throw new StatusException("HandleFolderChange() can not proceed as there are unprocessed hierarchy changes", SYNC_FSSTATUS_SERVERERROR);

            // any additional folders can not be modified!
            if ($serverid !== false && ZPush::GetAdditionalSyncFolderStore($serverid))
                throw new StatusException("HandleFolderChange() can not change additional folders which are configured", SYNC_FSSTATUS_UNKNOWNERROR);

            // switch user store if this this happens inside an additional folder
            // if this is an additional folder the backend has to be setup correctly
            if (!self::$backend->Setup(ZPush::GetAdditionalSyncFolderStore((($parentid != false)?$parentid:$serverid))))
                throw new StatusException(sprintf("HandleFolderChange() could not Setup() the backend for folder id '%s'", (($parentid != false)?$parentid:$serverid)), SYNC_FSSTATUS_SERVERERROR);
        }
        catch (StateNotFoundException $snfex) {
            $status = SYNC_FSSTATUS_SYNCKEYERROR;
        }
        catch (StatusException $stex) {
           $status = $stex->getCode();
        }

        // set $newsynckey in case of an error
        if (!isset($newsynckey))
            $newsynckey = $synckey;

        if ($status == SYNC_FSSTATUS_SUCCESS) {
            try {
                // Configure importer with last state
                $importer = self::$backend->GetImporter();
                $importer->Config($syncstate);

                // the messages from the PIM will be forwarded to the real importer
                $changesMem->SetDestinationImporter($importer);

                // process incoming change
                if (!$delete) {
                    // Send change
                    $folder = new SyncFolder();
                    $folder->serverid = $serverid;
                    $folder->parentid = $parentid;
                    $folder->displayname = $displayname;
                    $folder->type = $type;

                    $serverid = $changesMem->ImportFolderChange($folder);
                }
                else {
                    // delete folder
                    $changesMem->ImportFolderDeletion($serverid, 0);
                }
            }
            catch (StatusException $stex) {
                $status = $stex->getCode();
            }
        }

        self::$encoder->startWBXML();
        if ($create) {

            self::$encoder->startTag(SYNC_FOLDERHIERARCHY_FOLDERCREATE);
            {
                {
                    self::$encoder->startTag(SYNC_FOLDERHIERARCHY_STATUS);
                    self::$encoder->content($status);
                    self::$encoder->endTag();

                    self::$encoder->startTag(SYNC_FOLDERHIERARCHY_SYNCKEY);
                    self::$encoder->content($newsynckey);
                    self::$encoder->endTag();

                    self::$encoder->startTag(SYNC_FOLDERHIERARCHY_SERVERENTRYID);
                    self::$encoder->content($serverid);
                    self::$encoder->endTag();
                }
                self::$encoder->endTag();
            }
            self::$encoder->endTag();
        }

        elseif ($update) {
            self::$encoder->startTag(SYNC_FOLDERHIERARCHY_FOLDERUPDATE);
            {
                {
                    self::$encoder->startTag(SYNC_FOLDERHIERARCHY_STATUS);
                    self::$encoder->content($status);
                    self::$encoder->endTag();

                    self::$encoder->startTag(SYNC_FOLDERHIERARCHY_SYNCKEY);
                    self::$encoder->content($newsynckey);
                    self::$encoder->endTag();
                }
                self::$encoder->endTag();
            }
        }

        elseif ($delete) {
            self::$encoder->startTag(SYNC_FOLDERHIERARCHY_FOLDERDELETE);
            {
                {
                    self::$encoder->startTag(SYNC_FOLDERHIERARCHY_STATUS);
                    self::$encoder->content($status);
                    self::$encoder->endTag();

                    self::$encoder->startTag(SYNC_FOLDERHIERARCHY_SYNCKEY);
                    self::$encoder->content($newsynckey);
                    self::$encoder->endTag();
                }
                self::$encoder->endTag();
            }
        }

        self::$encoder->endTag();

        self::$topCollector->AnnounceInformation(sprintf("Operation status %d", $status), true);

        // Save the sync state for the next time
        self::$deviceManager->GetStateManager()->SetSyncState($newsynckey, $importer->GetState());

        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: