Back to index

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

List of all members.

Public Member Functions

 Handle ($commandCode)
 Handles the ItemOperations command Provides batched online handling for Fetch, EmptyFolderContents and Move.

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

ItemOperations::Handle ( commandCode)

Handles the ItemOperations command Provides batched online handling for Fetch, EmptyFolderContents and Move.

Parameters:
int$commandCodepublic
Returns:
boolean

Reimplemented from RequestProcessor.

Definition at line 55 of file itemoperations.php.

                                         {
        // Parse input
        if(!self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_ITEMOPERATIONS))
            return false;

        //TODO check if multiple item operations are possible in one request
        $el = self::$decoder->getElement();

        if($el[EN_TYPE] != EN_TYPE_STARTTAG)
            return false;
        //ItemOperations can either be Fetch, EmptyFolderContents or Move
        $fetch = $efc = $move = false;
        if($el[EN_TAG] == SYNC_ITEMOPERATIONS_FETCH)
            $fetch = true;
        else if($el[EN_TAG] == SYNC_ITEMOPERATIONS_EMPTYFOLDERCONTENTS)
            $efc = true;
        else if($el[EN_TAG] == SYNC_ITEMOPERATIONS_MOVE)
            $move = true;

        if(!$fetch && !$efc && !$move) {
            ZLog::Write(LOGLEVEL_DEBUG, "Unknown item operation:".print_r($el, 1));
            return false;
        }

        if ($fetch) {
            if(!self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_STORE))
                return false;
            $store = self::$decoder->getElementContent();
            if(!self::$decoder->getElementEndTag())
                return false;//SYNC_ITEMOPERATIONS_STORE

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

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

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

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

            if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_OPTIONS)) {
                //TODO other options
                //schema
                //range
                //username
                //password
                //bodypartpreference
                //rm:RightsManagementSupport

                // Save all OPTIONS into a ContentParameters object
                $collection["cpo"] = new ContentParameters();
                while(1) {
                    while (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODYPREFERENCE)) {
                        if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TYPE)) {
                            $bptype = self::$decoder->getElementContent();
                            $collection["cpo"]->BodyPreference($bptype);
                            if(!self::$decoder->getElementEndTag()) {
                                return false;
                            }
                        }

                        if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TRUNCATIONSIZE)) {
                            $collection["cpo"]->BodyPreference($bptype)->SetTruncationSize(self::$decoder->getElementContent());
                            if(!self::$decoder->getElementEndTag())
                                return false;
                        }

                        if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_ALLORNONE)) {
                            $collection["cpo"]->BodyPreference($bptype)->SetAllOrNone(self::$decoder->getElementContent());
                            if(!self::$decoder->getElementEndTag())
                                return false;
                        }

                        if(self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_PREVIEW)) {
                            $collection["cpo"]->BodyPreference($bptype)->SetPreview(self::$decoder->getElementContent());
                            if(!self::$decoder->getElementEndTag())
                                return false;
                        }

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

                    if(self::$decoder->getElementStartTag(SYNC_MIMESUPPORT)) {
                        $collection["cpo"]->SetMimeSupport(self::$decoder->getElementContent());
                        if(!self::$decoder->getElementEndTag())
                        return false;
                    }

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

        if ($efc) {
            if(self::$decoder->getElementStartTag(SYNC_FOLDERID)) {
                $folderid = self::$decoder->getElementContent();
                if(!self::$decoder->getElementEndTag())
                    return false;//SYNC_FOLDERID
            }
            if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_OPTIONS)) {
                if(self::$decoder->getElementStartTag(SYNC_ITEMOPERATIONS_DELETESUBFOLDERS)) {
                    $deletesubfolders = true;
                    if (($dsf = self::$decoder->getElementContent()) !== false) {
                        $deletesubfolders = (boolean)$dsf;
                        if(!self::$decoder->getElementEndTag())
                            return false;
                    }
                }
                self::$decoder->getElementEndTag();
            }
        }

        //TODO EmptyFolderContents
        //TODO move

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

        $status = SYNC_ITEMOPERATIONSSTATUS_SUCCESS;
        //TODO status handling

        self::$encoder->startWBXML();

        self::$encoder->startTag(SYNC_ITEMOPERATIONS_ITEMOPERATIONS);

        self::$encoder->startTag(SYNC_ITEMOPERATIONS_STATUS);
        self::$encoder->content($status);
        self::$encoder->endTag();//SYNC_ITEMOPERATIONS_STATUS

        self::$encoder->startTag(SYNC_ITEMOPERATIONS_RESPONSE);

        // fetch response
        if ($fetch) {
            self::$encoder->startTag(SYNC_ITEMOPERATIONS_FETCH);

                self::$encoder->startTag(SYNC_ITEMOPERATIONS_STATUS);
                self::$encoder->content($status);
                self::$encoder->endTag();//SYNC_ITEMOPERATIONS_STATUS

                if (isset($folderid) && isset($serverid)) {
                    self::$encoder->startTag(SYNC_FOLDERID);
                    self::$encoder->content($folderid);
                    self::$encoder->endTag(); // end SYNC_FOLDERID

                    self::$encoder->startTag(SYNC_SERVERENTRYID);
                    self::$encoder->content($serverid);
                    self::$encoder->endTag(); // end SYNC_SERVERENTRYID

                    self::$encoder->startTag(SYNC_FOLDERTYPE);
                    self::$encoder->content("Email");
                    self::$encoder->endTag();

                    $data = self::$backend->Fetch($folderid, $serverid, $collection["cpo"]);
                }

                if (isset($longid)) {
                    self::$encoder->startTag(SYNC_SEARCH_LONGID);
                    self::$encoder->content($longid);
                    self::$encoder->endTag(); // end SYNC_FOLDERID

                    self::$encoder->startTag(SYNC_FOLDERTYPE);
                    self::$encoder->content("Email");
                    self::$encoder->endTag();

                    $tmp = explode(":", $longid);
                    $data = self::$backend->Fetch($tmp[0], $tmp[1], $collection["cpo"]);
                }

                if (isset($filereference)) {
                    self::$encoder->startTag(SYNC_AIRSYNCBASE_FILEREFERENCE);
                    self::$encoder->content($filereference);
                    self::$encoder->endTag(); // end SYNC_AIRSYNCBASE_FILEREFERENCE

                    $data = self::$backend->GetAttachmentData($filereference);
                }

                //TODO put it in try catch block

                if (isset($data)) {
                    self::$encoder->startTag(SYNC_ITEMOPERATIONS_PROPERTIES);
                    $data->Encode(self::$encoder);
                    self::$encoder->endTag(); //SYNC_ITEMOPERATIONS_PROPERTIES
                }

            self::$encoder->endTag();//SYNC_ITEMOPERATIONS_FETCH
        }
        // empty folder contents operation
        else if ($efc) {
            try {
                // send request to backend
                self::$backend-> EmptyFolder($folderid, $deletesubfolders);
            }
            catch (StatusException $stex) {
               $status = $stex->getCode();
            }

            self::$encoder->startTag(SYNC_ITEMOPERATIONS_EMPTYFOLDERCONTENTS);

                self::$encoder->startTag(SYNC_ITEMOPERATIONS_STATUS);
                self::$encoder->content($status);
                self::$encoder->endTag();//SYNC_ITEMOPERATIONS_STATUS

                if (isset($folderid)) {
                    self::$encoder->startTag(SYNC_FOLDERID);
                    self::$encoder->content($folderid);
                    self::$encoder->endTag(); // end SYNC_FOLDERID
                }
            self::$encoder->endTag();//SYNC_ITEMOPERATIONS_EMPTYFOLDERCONTENTS
        }
        // TODO implement ItemOperations Move
        // move operation
        else {
            self::$encoder->startTag(SYNC_ITEMOPERATIONS_MOVE);
                self::$encoder->startTag(SYNC_ITEMOPERATIONS_STATUS);
                self::$encoder->content($status);
                self::$encoder->endTag();//SYNC_ITEMOPERATIONS_STATUS
            self::$encoder->endTag();//SYNC_ITEMOPERATIONS_MOVE
        }

        self::$encoder->endTag();//SYNC_ITEMOPERATIONS_RESPONSE
        self::$encoder->endTag();//SYNC_ITEMOPERATIONS_ITEMOPERATIONS

        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: