steffen: server/kolab-horde-framework/kolab-horde-framework/SyncML/SyncML/Command Alert.php, NONE, 1.1 Final.php, NONE, 1.1 Get.php, NONE, 1.1 Put.php, NONE, 1.1 Replace.php, NONE, 1.1 Results.php, NONE, 1.1 Status.php, NONE, 1.1 Sync.php, NONE, 1.1

cvs at intevation.de cvs at intevation.de
Fri Oct 14 16:33:14 CEST 2005


Author: steffen

Update of /kolabrepository/server/kolab-horde-framework/kolab-horde-framework/SyncML/SyncML/Command
In directory doto:/tmp/cvs-serv28903/kolab-horde-framework/kolab-horde-framework/SyncML/SyncML/Command

Added Files:
	Alert.php Final.php Get.php Put.php Replace.php Results.php 
	Status.php Sync.php 
Log Message:
Separated Horde Framework from kolab-resource-handlers

--- NEW FILE: Alert.php ---
<?php

include_once 'Horde/SyncML/State.php';
include_once 'Horde/SyncML/Command.php';

/**
 * The Horde_SyncML_Alert class provides a SyncML implementation of
 * the Alert command as defined in SyncML Representation Protocol,
 * version 1.1 5.5.2.
 *
 * $Horde: framework/SyncML/SyncML/Command/Alert.php,v 1.16 2004/05/26 17:41:30 chuck Exp $
 *
 * Copyright 2003-2004 Anthony Mills <amills at pyramid6.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Anthony Mills <amills at pyramid6.com>
 * @version $Revision: 1.1 $
 * @since   Horde 3.0
 * @package Horde_SyncML
 */
class Horde_SyncML_Command_Alert extends Horde_SyncML_Command {

    /**
     * @var integer $_alert
     */
    var $_alert;

    /**
     * @var string $_sourceURI
     */
    var $_sourceLocURI;

    /**
     * @var string $_targetURI
     */
    var $_targetLocURI;

    /**
     * @var string $_metaAnchorNext
     */
    var $_metaAnchorNext;

    /**
     * @var integer $_metaAnchorLast
     */
    var $_metaAnchorLast;

    /**
     * @var integer $_alert
     */
    var $_outputMetaAnchorNext;

    /**
     * @var integer $_alert
     */
    var $_outputMetaAnchorLast;

    /**
     * Use in xml tag.
     */
    var $_isInSource;

    /**
     * Creates a new instance of Alert.
     */
    function Horde_SyncML_Command_Alert($alert = null)
    {
        if ($alert != null) {
            $this->_alert = $alert;
        }
    }

    function output($currentCmdID, &$output)
    {
        $attrs = array();

        $state = $_SESSION['SyncML.state'];

        $status = &new Horde_SyncML_Command_Status($state->isAuthorized() ? RESPONSE_OK : RESPONSE_INVALID_CREDENTIALS, 'Alert');
        $status->setCmdRef($this->_cmdID);

        if ($state->isAuthorized() && isset($this->_metaAnchorNext)) {
            $status->setItemDataAnchorNext($this->_metaAnchorNext);
        }

        $currentCmdID = $status->output($currentCmdID, $output);

        if ($state->isAuthorized()) {
            $output->startElement($state->getURI(), 'Alert', $attrs);

            $output->startElement($state->getURI(), 'CmdID', $attrs);
            $chars = $currentCmdID;
            $output->characters($chars);
            $output->endElement($state->getURI(), 'CmdID');

            $output->startElement($state->getURI(), 'Data', $attrs);
            $chars = $this->_alert;
            $output->characters($chars);
            $output->endElement($state->getURI(), 'Data');

            $output->startElement($state->getURI(), 'Item', $attrs);

            if ($this->_sourceLocURI != null) {
                $output->startElement($state->getURI(), 'Target', $attrs);
                $output->startElement($state->getURI(), 'LocURI', $attrs);
                $chars = $this->_sourceLocURI;
                $output->characters($chars);
                $output->endElement($state->getURI(), 'LocURI');
                $output->endElement($state->getURI(), 'Target');
            }

            if ($this->_targetLocURI != null) {
                $output->startElement($state->getURI(), 'Source', $attrs);
                $output->startElement($state->getURI(), 'LocURI', $attrs);
                $chars = $this->_targetLocURI;
                $output->characters($chars);
                $output->endElement($state->getURI(), 'LocURI');
                $output->endElement($state->getURI(), 'Source');
            }

            $output->startElement($state->getURI(), 'Meta', $attrs);

            $output->startElement($state->getURIMeta(), 'Anchor', $attrs);

            if (isset($this->_outputMetaAnchorLast)) {
                $output->startElement($state->getURIMeta(), 'Last', $attrs);
                $chars = $this->_outputMetaAnchorLast;
                $output->characters($chars);
                $output->endElement($state->getURIMeta(), 'Last');
            }

            if (isset($this->_outputMetaAnchorNext)) {
                $output->startElement($state->getURIMeta(), 'Next', $attrs);
                $chars = $this->_outputMetaAnchorNext;
                $output->characters($chars);
                $output->endElement($state->getURIMeta(), 'Next');
            }

            $output->endElement($state->getURIMeta(), 'Anchor');
            $output->endElement($state->getURI(), 'Meta');
            $output->endElement($state->getURI(), 'Item');
            $output->endElement($state->getURI(), 'Alert');

            $currentCmdID++;
        }

        return $currentCmdID;
    }

    /**
     * Setter for property sourceURI.
     *
     * @param string $sourceURI  New value of property sourceURI.
     */
    function setSourceLocURI($sourceURI)
    {
        $this->_sourceURI = $sourceURI;
    }

    function getTargetLocURI()
    {
        return $this->_targetURI;
    }

    /**
     * Setter for property targetURI.
     *
     * @param string $targetURI  New value of property targetURI.
     */
    function setTargetURI($targetURI)
    {
        $this->_targetURI = $targetURI;
    }

    function startElement($uri, $element, $attrs)
    {
        parent::startElement($uri, $element, $attrs);

        switch ($this->_xmlStack) {
        case 3:
            if ($element == 'Target') {
                $this->_isInSource = false;
            } else {
                $this->_isInSource = true;
            }
            break;
        }
    }

    function endElement($uri, $element)
    {
        switch ($this->_xmlStack) {
        case 1:
            $state = $_SESSION['SyncML.state'];
            Horde::logMessage('looking for sync for: ' . $this->_targetLocURI, __FILE__, __LINE__,  PEAR_LOG_DEBUG);
            $sync = $state->getSync($this->_targetLocURI);

            if (!$sync) {
                Horde::logMessage('create new sync for: ' . $this->_targetLocURI . ' ' . $this->_alert, __FILE__, __LINE__,  PEAR_LOG_DEBUG);
                $sync = &Horde_SyncML_Sync::factory($this->_alert);
                $state->setSync($this->_targetLocURI, $sync);
            }

            $_SESSION['SyncML.state'] = $state;
            break;

        case 2:
            if ($element == 'Data') {
                $this->_alert = intval(trim($this->_chars));
            }
            break;

        case 4:
            if ($element == 'LocURI') {
                Horde::logMessage('<'. $element . ' stack ' . $this->_xmlStack . ' source ' . $this->_isInSource, __FILE__, __LINE__, PEAR_LOG_DEBUG);
                if ($this->_isInSource) {
                    $this->_sourceLocURI = trim($this->_chars);
                } else {
                    $this->_targetLocURI = trim($this->_chars);
                }
            }
            break;

        case 5:
            if ($element == 'Next') {
                $this->_metaAnchorNext = trim($this->_chars);
                $this->_outputMetaAnchorNext = $this->_metaAnchorNext;
            }
            break;
        }

        parent::endElement($uri, $element);
    }

    function getAlert()
    {
        return $this->_alert;
    }

    function setAlet($alert)
    {
        $this->_alert = $alert;
    }

}

--- NEW FILE: Final.php ---
<?php

include_once 'Horde/SyncML/Command.php';

/**
 * The Horde_SyncML_Command_Final class.
 *
 * $Horde: framework/SyncML/SyncML/Command/Final.php,v 1.10 2004/05/26 17:41:30 chuck Exp $
 *
 * Copyright 2003-2004 Anthony Mills <amills at pyramid6.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Anthony Mills <amills at pyramid6.com>
 * @version $Revision: 1.1 $
 * @since   Horde 3.0
 * @package Horde_SyncML
 */
class Horde_SyncML_Command_Final extends Horde_SyncML_Command {

    function output($currentCmdID, &$output)
    {
        $state = $_SESSION['SyncML.state'];

        $attrs = array();
        $output->startElement($state->getURI(), 'Final', $attrs);

        $output->endElement($state->getURI(), 'Final');

        return $currentCmdID;
    }

}

--- NEW FILE: Get.php ---
<?php

include_once 'Horde/SyncML/State.php';
include_once 'Horde/SyncML/Command.php';
include_once 'Horde/SyncML/Command/Results.php';

/**
 * The Horde_SyncML_Command_Get class.
 *
 * $Horde: framework/SyncML/SyncML/Command/Get.php,v 1.13 2004/05/26 17:41:30 chuck Exp $
 *
 * Copyright 2003-2004 Anthony Mills <amills at pyramid6.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Anthony Mills <amills at pyramid6.com>
 * @version $Revision: 1.1 $
 * @since   Horde 3.0
 * @package Horde_SyncML
 */
class Horde_SyncML_Command_Get extends Horde_SyncML_Command {

    function output($currentCmdID, &$output)
    {
        $state = $_SESSION['SyncML.state'];

        $status = &new Horde_SyncML_Command_Status((($state->isAuthorized()) ? RESPONSE_OK : RESPONSE_INVALID_CREDENTIALS), 'Get');
        $status->setCmdRef($this->_cmdID);

        $status->setTargetRef('./devinf11');

        $currentCmdID = $status->output($currentCmdID, $output);

        if ($state->isAuthorized()) {
            // Synthesis does not like this one.

            // $results = &new Horde_SyncML_Command_Results();
            // $results->setCmdRef($this->_cmdID);

            // DevInf returnDevInf = new DevInf((version == 0) ? "./devinf" : "./devinf11");

            // result.setData(devinf);
            // $currentCmdID = $results->output($currentCmdID, $output);
        }

        return $currentCmdID;
    }

}

// DevInf info to return. May need to send something like this back:
//
//   <Meta>
//    <Type xmlns='syncml:metinf'>
//     application/vnd.syncml-devinf+xml
//    </Type>
//   </Meta>
//   <Item>
//    <Source>
//     <LocURI>
//      ./devinf11
//     </LocURI>
//    </Source>
//    <Data>
//     <DevInf xmlns='syncml:devinf'>
//      <VerDTD>
//       1.1
//      </VerDTD>
//      <Man>
//       Synthesis AG
//      </Man>
//      <Mod>
//       Synthesis Sync Server 1.0 Demo
//      </Mod>
//      <OEM>
//       Synthesis AG
//      </OEM>
//      <SwV>
//       2.0.1.5
//      </SwV>
//      <DevId>
//       SySync Server (textdb,standalone)
//      </DevId>
//      <DevTyp>
//       server
//      </DevTyp>
//      <UTC>
//      </UTC>
//      <SupportNumberOfChanges>
//      </SupportNumberOfChanges>
//      <SupportLargeObjs>
//      </SupportLargeObjs>
//      <DataStore>
//       <SourceRef>
//        ./contacts
//       </SourceRef>
//       <DisplayName>
//        contacts
//       </DisplayName>
//       <Rx-Pref>
//        <CTType>
//         text/x-vcard
//        </CTType>
//        <VerCT>
//         2.1
//        </VerCT>
//       </Rx-Pref>
//       <Rx>
//        <CTType>
//         text/vcard
//        </CTType>
//        <VerCT>
//         3.0
//        </VerCT>
//       </Rx>
//       <Tx-Pref>
//        <CTType>
//         text/x-vcard
//        </CTType>
//        <VerCT>
//         2.1
//        </VerCT>
//       </Tx-Pref>
//       <Tx>
//        <CTType>
//         text/vcard
//        </CTType>
//        <VerCT>
//         3.0
//        </VerCT>
//       </Tx>
//       <SyncCap>
//        <SyncType>
//         1
//        </SyncType>
//        <SyncType>
//         2
//        </SyncType>
//        <SyncType>
//         4
//        </SyncType>
//        <SyncType>
//         5
//        </SyncType>
//        <SyncType>
//         6
//        </SyncType>
//       </SyncCap>
//      </DataStore>
//      <DataStore>
//       <SourceRef>
//        ./events
//       </SourceRef>
//       <DisplayName>
//        events
//       </DisplayName>
//       <Rx-Pref>
//        <CTType>
//         text/x-vcalendar
//        </CTType>
//        <VerCT>
//         1.0
//        </VerCT>
//       </Rx-Pref>
//       <Tx-Pref>
//        <CTType>
//         text/x-vcalendar
//        </CTType>
//        <VerCT>
//         1.0
//        </VerCT>
//       </Tx-Pref>
//       <SyncCap>
//        <SyncType>
//         1
//        </SyncType>
//        <SyncType>
//         2
//        </SyncType>
//        <SyncType>
//         4
//        </SyncType>
//        <SyncType>
//         5
//        </SyncType>
//        <SyncType>
//         6
//        </SyncType>
//       </SyncCap>
//      </DataStore>
//      <DataStore>
//       <SourceRef>
//        ./tasks
//       </SourceRef>
//       <DisplayName>
//        tasks
//       </DisplayName>
//       <Rx-Pref>
//        <CTType>
//         text/x-vcalendar
//        </CTType>
//        <VerCT>
//         1.0
//        </VerCT>
//       </Rx-Pref>
//       <Tx-Pref>
//        <CTType>
//         text/x-vcalendar
//        </CTType>
//        <VerCT>
//         1.0
//        </VerCT>
//       </Tx-Pref>
//       <SyncCap>
//        <SyncType>
//         1
//        </SyncType>
//        <SyncType>
//         2
//        </SyncType>
//        <SyncType>
//         4
//        </SyncType>
//        <SyncType>
//         5
//        </SyncType>
//        <SyncType>
//         6
//        </SyncType>
//       </SyncCap>
//      </DataStore>
//      <DataStore>
//       <SourceRef>
//        ./calendar
//       </SourceRef>
//       <DisplayName>
//        calendar
//       </DisplayName>
//       <Rx-Pref>
//        <CTType>
//         text/x-vcalendar
//        </CTType>
//        <VerCT>
//         1.0
//        </VerCT>
//       </Rx-Pref>
//       <Tx-Pref>
//        <CTType>
//         text/x-vcalendar
//        </CTType>
//        <VerCT>
//         1.0
//        </VerCT>
//       </Tx-Pref>
//       <SyncCap>
//        <SyncType>
//         1
//        </SyncType>
//        <SyncType>
//         2
//        </SyncType>
//        <SyncType>
//         3
//        </SyncType>
//        <SyncType>
//         4
//        </SyncType>
//        <SyncType>
//         5
//        </SyncType>
//        <SyncType>
//         6
//        </SyncType>
//       </SyncCap>
//      </DataStore>
//      <DataStore>
//       <SourceRef>
//        ./notes
//       </SourceRef>
//       <DisplayName>
//        notes
//       </DisplayName>
//       <Rx-Pref>
//        <CTType>
//         text/plain
//        </CTType>
//        <VerCT>
//         1.0
//        </VerCT>
//       </Rx-Pref>
//       <Tx-Pref>
//        <CTType>
//         text/plain
//        </CTType>
//        <VerCT>
//         1.0
//        </VerCT>
//       </Tx-Pref>
//       <SyncCap>
//        <SyncType>
//         1
//        </SyncType>
//        <SyncType>
//         2
//        </SyncType>
//        <SyncType>
//         4
//        </SyncType>
//        <SyncType>
//         5
//        </SyncType>
//        <SyncType>
//         6
//        </SyncType>
//       </SyncCap>
//      </DataStore>
//      <CTCap>
//       <CTType>
//        text/x-vcard
//       </CTType>
//       <PropName>
//        BEGIN
//       </PropName>
//       <ValEnum>
//        VCARD
//       </ValEnum>
//       <PropName>
//        END
//       </PropName>
//       <ValEnum>
//        VCARD
//       </ValEnum>
//       <PropName>
//        VERSION
//       </PropName>
//       <ValEnum>
//        2.1
//       </ValEnum>
//       <PropName>
//        REV
//       </PropName>
//       <PropName>
//        N
//       </PropName>
//       <PropName>
//        TITLE
//       </PropName>
//       <PropName>
//        ORG
//       </PropName>
//       <PropName>
//        EMAIL
//       </PropName>
//       <PropName>
//        URL
//       </PropName>
//       <PropName>
//        TEL
//       </PropName>
//       <PropName>
//        ADR
//       </PropName>
//       <PropName>
//        BDAY
//       </PropName>
//       <PropName>
//        NOTE
//       </PropName>
//       <CTType>
//        text/vcard
//       </CTType>
//       <PropName>
//        BEGIN
//       </PropName>
//       <ValEnum>
//        VCARD
//       </ValEnum>
//       <PropName>
//        END
//       </PropName>
//       <ValEnum>
//        VCARD
//       </ValEnum>
//       <PropName>
//        VERSION
//       </PropName>
//       <ValEnum>
//        3.0
//       </ValEnum>
//       <PropName>
//        REV
//       </PropName>
//       <PropName>
//        N
//       </PropName>
//       <PropName>
//        TITLE
//       </PropName>
//       <PropName>
//        ORG
//       </PropName>
//       <PropName>
//        EMAIL
//       </PropName>
//       <PropName>
//        URL
//       </PropName>
//       <PropName>
//        TEL
//       </PropName>
//       <PropName>
//        ADR
//       </PropName>
//       <PropName>
//        BDAY
//       </PropName>
//       <PropName>
//        NOTE
//       </PropName>
//       <CTType>
//        text/x-vcalendar
//       </CTType>
//       <PropName>
//        BEGIN
//       </PropName>
//       <ValEnum>
//        VCALENDAR
//       </ValEnum>
//       <ValEnum>
//        VEVENT
//       </ValEnum>
//       <ValEnum>
//        VTODO
//       </ValEnum>
//       <PropName>
//        END
//       </PropName>
//       <ValEnum>
//        VCALENDAR
//       </ValEnum>
//       <ValEnum>
//        VEVENT
//       </ValEnum>
//       <ValEnum>
//        VTODO
//       </ValEnum>
//       <PropName>
//        VERSION
//       </PropName>
//       <ValEnum>
//        1.0
//       </ValEnum>
//       <PropName>
//        TZ
//       </PropName>
//       <PropName>
//        LAST-MODIFIED
//       </PropName>
//       <PropName>
//        DCREATED
//       </PropName>
//       <PropName>
//        SUMMARY
//       </PropName>
//       <PropName>
//        DESCRIPTION
//       </PropName>
//       <PropName>
//        LOCATION
//       </PropName>
//       <PropName>
//        CATEGORIES
//       </PropName>
//       <PropName>
//        DTSTART
//       </PropName>
//       <PropName>
//        DTEND
//       </PropName>
//       <PropName>
//        ATTENDEE
//       </PropName>
//       <PropName>
//        RRULE
//       </PropName>
//       <PropName>
//        EXDATE
//       </PropName>
//       <PropName>
//        AALARM
//       </PropName>
//       <PropName>
//        DALARM
//       </PropName>
//       <PropName>
//        LOCATION
//       </PropName>
//       <PropName>
//        CATEGORIES
//       </PropName>
//       <PropName>
//        DUE
//       </PropName>
//       <PropName>
//        PRIORITY
//       </PropName>
//       <PropName>
//        STATUS
//       </PropName>
//       <PropName>
//        AALARM
//       </PropName>
//       <PropName>
//        DALARM
//       </PropName>
//      </CTCap>
//     </DevInf>
//    </Data>
//   </Item>

--- NEW FILE: Put.php ---
<?php

include_once 'Horde/SyncML/State.php';
include_once 'Horde/SyncML/Command.php';

/**
 * $Horde: framework/SyncML/SyncML/Command/Put.php,v 1.11 2004/05/26 17:43:29 chuck Exp $
 *
 * Copyright 2003-2004 Anthony Mills <amills at pyramid6.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Anthony Mills <amills at pyramid6.com>
 * @version $Revision: 1.1 $
 * @since   Horde 3.0
 * @package Horde_SyncML
 */
class Horde_SyncML_Command_Put extends Horde_SyncML_Command {

    function output($currentCmdID, &$output )
    {
        $state = $_SESSION['SyncML.state'];

        $status = &new Horde_SyncML_Command_Status((($state->isAuthorized()) ? RESPONSE_OK : RESPONSE_INVALID_CREDENTIALS), 'Put');
        $status->setCmdRef($this->_cmdID);

        $status->setSourceRef('./devinf11');

        return $status->output($currentCmdID, $output);
    }

}

--- NEW FILE: Replace.php ---
<?php

include_once 'Horde/SyncML/Command.php';

/**
 * $Horde: framework/SyncML/SyncML/Command/Replace.php,v 1.7 2004/05/26 17:41:30 chuck Exp $
 *
 * Copyright 2003-2004 Anthony Mills <amills at pyramid6.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Anthony Mills <amills at pyramid6.com>
 * @version $Revision: 1.1 $
 * @since   Horde 3.0
 * @package Horde_SyncML
 */
class Horde_SyncML_Command_Final extends Horde_SyncML_Command {

    function output($currentCmdID, &$output)
    {
        return $currentCmdID;
    }

}

--- NEW FILE: Results.php ---
<?php

include_once 'Horde/SyncML/State.php';
include_once 'Horde/SyncML/Command.php';

/**
 * $Horde: framework/SyncML/SyncML/Command/Results.php,v 1.10 2004/05/26 17:41:30 chuck Exp $
 *
 * Copyright 2003-2004 Anthony Mills <amills at pyramid6.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Anthony Mills <amills at pyramid6.com>
 * @version $Revision: 1.1 $
 * @since   Horde 3.0
 * @package Horde_SyncML
 */
class Horde_SyncML_Command_Results extends Horde_SyncML_Command {

    var $_cmdRef;

    function output($currentCmdID, &$output)
    {
        $state = $_SESSION['SyncML.state'];

        $attrs = array();
        $output->startElement($state->getURI(), 'Results', $attrs);

        $output->startElement($state->getURI(), 'CmdID', $attrs);
        $chars = $currentCmdID;
        $output->characters($chars);
        $output->endElement($state->getURI(), 'CmdID');

        $output->startElement($state->getURI(), 'MsgRef', $attrs);
        $chars = $state->getMsgID();
        $output->characters($chars);
        $output->endElement($state->getURI(), 'MsgRef');

        $output->startElement($state->getURI(), 'CmdRef', $attrs);
        $chars = $this->_cmdRef;
        $output->characters($chars);
        $output->endElement($state->getURI(), 'CmdRef');

        /*
        $output->startElement($state->getURI(), 'Meta', $attrs);
        $output->startElement($state->getURIMeta(), 'Type', $attrs);
        $chars = $this->_cmdRef;
        $output->characters($chars);
        $output->endElement($state->getURIMeta(), 'Type');
        $output->endElement($state->getURI(), 'Meta');

        $output->startElement($state->getURI(), 'Item', $attrs);
        $output->startElement($state->getURI(), 'Source', $attrs);
        $output->startElement($state->getURI(), 'LocURI', $attrs);
        $chars = $this->_locSourceURI;
        $output->characters($chars);
        $output->endElement($state->getURI(), 'LocURI');
        $output->endElement($state->getURI(), 'Source');

        $output->startElement($state->getURI(), 'Data', $attrs);

        // Need to send this information as opaque data so the WBXML
        // will understand it.
        $output->opaque($this->_data);

        // $chars = $this->_data;
        // $output->characters($chars);
        $output->endElement($state->getURI(), 'Data');
        $output->endElement($state->getURI(), 'Item');
        */

        $output->endElement($state->getURI(), 'Results');

        $currentCmdID++;

        return $currentCmdID;
    }

    /**
     * Setter for property cmdRef.
     *
     * @param string $cmdRef  New value of property cmdRef.
     */
    function setCmdRef($cmdRef)
    {
        $this->_cmdRef = $cmdRef;
    }

}

--- NEW FILE: Status.php ---
<?php

include_once 'Horde/SyncML/State.php';
include_once 'Horde/SyncML/Command.php';

/**
 * $Horde: framework/SyncML/SyncML/Command/Status.php,v 1.14 2004/05/26 17:41:30 chuck Exp $
 *
 * Copyright 2003-2004 Anthony Mills <amills at pyramid6.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Anthony Mills <amills at pyramid6.com>
 * @version $Revision: 1.1 $
 * @since   Horde 3.0
 * @package Horde_SyncML
 */
class Horde_SyncML_Command_Status extends Horde_SyncML_Command {

    var $_response;

    var $_cmdRef;

    /**
     * Must be present.
     */
    var $_cmd;

    /**
     * Must if not null (what does this mean?).
     */
    var $_sourceRef;

    var $_targetRef;

    var $_chalMetaFormat;

    var $_chalMetaType;

    var $_chalMetaNextNonce;

    var $_itemDataAnchorNext;

    function Horde_SyncML_Command_Status($response = null, $cmd = null)
    {
        if ($response != null) {
            $this->_response = $response;
        }

        if ($cmd != null) {
            $this->_cmd = $cmd;
        }
    }

    function output($currentCmdID, &$output)
    {
        $attrs = array();

        $state = $_SESSION['SyncML.state'];

        if ($this->_cmd != null) {
            $attrs = array();
            $output->startElement($state->getURI(), 'Status', $attrs);

            $output->startElement($state->getURI(), 'CmdID', $attrs);
            $chars = $currentCmdID;
            $output->characters($chars);
            $output->endElement($state->getURI(), 'CmdID');

            $output->startElement($state->getURI(), 'MsgRef', $attrs);
            $chars = $state->getMsgID();
            $output->characters($chars);
            $output->endElement($state->getURI(), 'MsgRef');

            $output->startElement($state->getURI(), 'CmdRef', $attrs);
            $chars = $this->_cmdRef;
            $output->characters($chars);
            $output->endElement($state->getURI(), 'CmdRef');

            $output->startElement($state->getURI(), 'Cmd', $attrs);
            $chars = $this->_cmd;
            $output->characters($chars);
            $output->endElement($state->getURI(), 'Cmd');

            if (isset($this->_sourceRef)) {
                $output->startElement($state->getURI(), 'SourceRef', $attrs);
                $chars = $this->_sourceRef;
                $output->characters($chars);
                $output->endElement($state->getURI(), 'SourceRef');
            }

            if (isset($this->_targetRef)) {
                $output->startElement($state->getURI(), 'TargetRef', $attrs);
                $chars = $this->_targetRef;
                $output->characters($chars);
                $output->endElement($state->getURI(), 'TargetRef');
            }

            // If we are responding to the SyncHdr and we are not
            // authorized then request basic authorization.
            //
            // FIXME: Right now we always send this, ignoring the
            // isAuthorized() test. Is that correct?
            if ($this->_cmd == 'SyncHdr') { // && !$state->isAuthorized()) {
                $this->_chalMetaFormat = 'b64';
                $this->_chalMetaType = 'syncml:auth-basic';
            }

            if (isset($this->_chalMetaFormat) && isset($this->_chalMetaType)) {
                $output->startElement($state->getURI(), 'Chal', $attrs);
                $output->startElement($state->getURI(), 'Meta', $attrs);

                $metainfuri = $state->getURIMeta();

                $output->startElement($metainfuri, 'Format', $attrs);
                $chars = $this->_chalMetaFormat;
                $output->characters($chars);
                $output->endElement($metainfuri, 'Format');

                $output->startElement($metainfuri, 'Type', $attrs);
                $chars = $this->_chalMetaType;
                $output->characters($chars);
                $output->endElement($metainfuri, 'Type');

                //$output->startElement($metainfuri, 'NextNonce', $attrs);
                //$chars = $this->_chalMetaNextNonce;
                //$output->characters($chars);
                //$output->endElement($metainfuri, 'NextNonce');

                $output->endElement($state->getURI(), 'Meta');
                $output->endElement($state->getURI(), 'Chal');
            }

            $output->startElement($state->getURI(), 'Data', $attrs);
            $chars = $this->_response;
            $output->characters($chars);
            $output->endElement($state->getURI(), 'Data');

            if (isset($this->_itemDataAnchorNext)) {
                $output->startElement($state->getURI(), 'Item', $attrs);
                $output->startElement($state->getURI(), 'Data', $attrs);

                $metainfuri = $state->getURIMeta();

                $output->startElement($metainfuri, 'Anchor', $attrs);
                $output->startElement($metainfuri, 'Next', $attrs);
                $chars = $this->_itemDataAnchorNext;
                $output->characters($chars);
                $output->endElement($metainfuri, 'Next');

                $output->endElement($metainfuri, 'Anchor');

                $output->endElement($state->getURI(), 'Data');
                $output->endElement($state->getURI(), 'Item');
            }

            $output->endElement($state->getURI(), 'Status');

            $currentCmdID++;
        }

        return $currentCmdID;
    }

    /**
     * Setter for property response.
     *
     * @param string $response  New value of property response.
     */
    function setResponse($response)
    {
        $this->_response = $response;
    }

    /**
     * Setter for property cmd.
     *
     * @param string $cmd  New value of property cmd.
     */
    function setCmd($cmd)
    {
        $this->_cmd = $cmd;
    }

    /**
     * Setter for property cmdRef.
     *
     * @param string $cmdRef  New value of property cmdRef.
     */
    function setCmdRef($cmdRef)
    {
        $this->_cmdRef = $cmdRef;
    }

    /**
     * Setter for property sourceRef.
     *
     * @param string $sourceRef  New value of property sourceRef.
     */
    function setSourceRef($sourceRef)
    {
        $this->_sourceRef = $sourceRef;
    }

    /**
     * Setter for property targetRef.
     *
     * @param string $targetRef  New value of property targetRef.
     */
    function setTargetRef($targetRef)
    {
        $this->_targetRef = $targetRef;
    }

    /**
     * Setter for property itemDataAnchorNext.
     *
     * @param string $itemDataAnchorNext  New value of property itemDataAnchorNext.
     */
    function setItemDataAnchorNext($itemDataAnchorNext)
    {
        $this->_itemDataAnchorNext = $itemDataAnchorNext;
    }

}

--- NEW FILE: Sync.php ---
<?php

include_once 'Horde/SyncML/State.php';
include_once 'Horde/SyncML/Command.php';
include_once 'Horde/SyncML/Command/Sync/SyncElement.php';

/**
 * $Horde: framework/SyncML/SyncML/Command/Sync.php,v 1.14 2004/05/26 17:46:15 chuck Exp $
 *
 * Copyright 2003-2004 Anthony Mills <amills at pyramid6.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * @author  Anthony Mills <amills at pyramid6.com>
 * @version $Revision: 1.1 $
 * @since   Horde 3.0
 * @package Horde_SyncML
 */
class Horde_SyncML_Command_Sync extends Horde_Syncml_Command {

    var $_isInSource;
    var $_currentSyncElement;
    var $_syncElements = array();

    function output($currentCmdID, &$output)
    {
        $state = $_SESSION['SyncML.state'];

        $attrs = array();

        $output->startElement($state->getURI(), 'Sync', $attrs);

        $output->startElement($state->getURI(), 'CmdID', $attrs);
        $chars = $currentCmdID;
        $output->characters($chars);
        $output->endElement($state->getURI(), 'CmdID');

        $output->startElement($state->getURI(), 'Target', $attrs);
        $output->startElement($state->getURI(), 'LocURI', $attrs);
        $chars = $this->_sourceURI;
        $output->characters($chars);
        $output->endElement($state->getURI(), 'LocURI');
        $output->endElement($state->getURI(), 'Target');

        $output->startElement($state->getURI(), 'Source', $attrs);
        $output->startElement($state->getURI(), 'LocURI', $attrs);
        $chars = $this->_targetURI;
        $output->characters($chars);
        $output->endElement($state->getURI(), 'LocURI');
        $output->endElement($state->getURI(), 'Source');

        $output->startElement($state->getURI(), 'NumberOfChanged', $attrs);
        // $chars = count($this->_syncElements);
        $chars = 0;
        $output->characters($chars);
        $output->endElement($state->getURI(), 'NumberOfChanged');

        $output->endElement($state->getURI(), 'Sync');

        $currentCmdID++;

        // Not sure where the status commands need to fall, but this
        // is a start.
        Horde::logMessage('SyncML: $this->_targetURI = ' . $this->_targetURI, __FILE__, __LINE__,  PEAR_LOG_DEBUG);
        $sync = $state->getSync($this->_targetURI);

        $currentCmdID = $sync->startSync($currentCmdID, $output);

        foreach ($this->_syncElements as $element       ) {
            $currentCmdID = $sync->nextSyncCommand($currentCmdID, $element, $output);
        }

        $currentCmdID = $sync->endSync($currentCmdID, $output);

        $status = &new Horde_SyncML_Command_Status(RESPONSE_OK, 'Sync');
        $status->setState($state);
        $status->setCmdRef($this->_cmdID);

        if ($this->_targetURI != null) {
            $status->setTargetRef($this->_targetURI);
        }

        if ($this->_sourceURI != null) {
            $status->setSourceRef($this->_sourceURI);
        }

        return $status->output($currentCmdID, $output);
    }

    function getTargetURI()
    {
        return $this->_targetURI;
    }

    function startElement($uri, $element, $attrs)
    {
        parent::startElement($uri, $element, $attrs);

        switch ($this->_xmlStack) {
        case 2:
            if ($element == 'Replace' || $element == 'Add' || $element == 'Delete') {
                $this->_currentSyncElement = &Horde_SyncML_Command_Sync_SyncElement::factory($element);
                $this->_currentSyncElement->setVersion($this->_version);
                $this->_currentSyncElement->setCmdRef($this->_cmdID);
                $this->_currentSyncElement->setMsgID($this->_msgID);
            } elseif ($element == 'Target') {
                $this->_isInSource = false;
            } else {
                $this->_isInSource = true;
            }
            break;
        }

        if (isset($this->_currentSyncElement)) {
            $this->_currentSyncElement->startElement($uri, $element, $attrs);
        }
    }

    function endElement($uri, $element)
    {
        if (isset($this->_currentSyncElement)) {
            $this->_currentSyncElement->endElement($uri, $element);
        }

        switch ($this->_xmlStack) {
        case 2:
            if ($element == 'Replace' || $element == 'Add' || $element == 'Delete') {
                $this->_syncElements[] = $this->_currentSyncElement;
                unset($this->_currentSyncElement);
            }
            break;

        case 3:
            if ($element = 'LocURI') {
                if ($this->_isInSource) {
                    $this->_sourceURI = trim($this->_chars);
                } else {
                    $this->_targetURI = trim($this->_chars);
                }
            }
            break;
        }

        parent::endElement($uri, $element);
    }

    function characters($str)
    {
        if (isset($this->_currentSyncElement)) {
            $this->_currentSyncElement->characters($str);
        } else {
            if (isset($this->_chars)) {
                $this->_chars = $this->_chars . $str;
            } else {
                $this->_chars = $str;
            }
        }
    }

}





More information about the commits mailing list