Overview

Packages

  • None
  • SyncMl

Classes

  • Horde_SyncMl
  • Horde_SyncMl_Backend
  • Horde_SyncMl_Backend_Horde
  • Horde_SyncMl_Command
  • Horde_SyncMl_Command_Alert
  • Horde_SyncMl_Command_Final
  • Horde_SyncMl_Command_Get
  • Horde_SyncMl_Command_Map
  • Horde_SyncMl_Command_Put
  • Horde_SyncMl_Command_Replace
  • Horde_SyncMl_Command_Results
  • Horde_SyncMl_Command_Status
  • Horde_SyncMl_Command_Sync
  • Horde_SyncMl_Command_SyncHdr
  • Horde_SyncMl_ContentHandler
  • Horde_SyncMl_DataStore
  • Horde_SyncMl_Device
  • Horde_SyncMl_Device_Nokia
  • Horde_SyncMl_Device_P800
  • Horde_SyncMl_Device_sync4j
  • Horde_SyncMl_Device_Sync4JMozilla
  • Horde_SyncMl_Device_Synthesis
  • Horde_SyncMl_DeviceInfo
  • Horde_SyncMl_Property
  • Horde_SyncMl_PropertyParameter
  • Horde_SyncMl_State
  • Horde_SyncMl_Sync
  • Horde_SyncMl_SyncElement
  • Horde_SyncMl_Translation
  • Horde_SyncMl_XmlOutput
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_SyncMl_Command_SyncHdr class provides a SyncML implementation of
  4:  * the SyncHdr as defined in SyncML Representation Protocol, version 1.1,
  5:  * section 5.2.2.
  6:  *
  7:  * SyncHdr is not really a sync command, but this class takes advantage of the
  8:  * XML parser in Horde_SyncMl_Command.
  9:  *
 10:  * Copyright 2006-2012 Horde LLC (http://www.horde.org/)
 11:  *
 12:  * See the enclosed file COPYING for license information (LGPL). If you
 13:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 14:  *
 15:  * @author  Karsten Fourmont <karsten@horde.org>
 16:  * @author  Jan Schneider <jan@horde.org>
 17:  * @package SyncMl
 18:  */
 19: class Horde_SyncMl_Command_SyncHdr extends Horde_SyncMl_Command
 20: {
 21:     /**
 22:      * Name of the command.
 23:      *
 24:      * @var string
 25:      */
 26:     protected $_cmdName = 'SyncHdr';
 27: 
 28:     /**
 29:      * Username as specified in the <LocName> element.
 30:      *
 31:      * @var string
 32:      */
 33:     public $user;
 34: 
 35:     /**
 36:      * Id of this SyncML session as specified in the <SessionID> element.
 37:      *
 38:      * This is not to confuse with the PHP session id, though it is part of
 39:      * the generated PHP session id.
 40:      *
 41:      * @var string
 42:      */
 43:     protected $_sessionID;
 44: 
 45:     /**
 46:      * SyncML protocol version as specified in the <VerProto> element.
 47:      *
 48:      * 0 for SyncML 1.0, 1 for SyncML 1.1, etc.
 49:      *
 50:      * @var integer
 51:      */
 52:     protected $_version;
 53: 
 54:     /**
 55:      * Id of the current message as specified in the <MsgID> element.
 56:      *
 57:      * @var integer
 58:      */
 59:     protected $_message;
 60: 
 61:     /**
 62:      * The target URI as specified by the <Target><LocURI> element.
 63:      *
 64:      * This is normally the URL of the Horde RPC server. However the client is
 65:      * free to send anything.
 66:      *
 67:      * @var string
 68:      */
 69:     protected $_targetURI;
 70: 
 71:     /**
 72:      * The source URI as specified by the <Source><LocURI> element.
 73:      *
 74:      * @var string
 75:      */
 76:     protected $_sourceURI;
 77: 
 78:     /**
 79:      * Authentication credential as specified by the <Cred><Data> element.
 80:      *
 81:      * @var string
 82:      */
 83:     public $credData;
 84: 
 85:     /**
 86:      * Encoding format of $credData as specified in the <Cred><Meta><Format>
 87:      * element like 'b64'.
 88:      *
 89:      * @var string
 90:      */
 91:     public $credFormat;
 92: 
 93:     /**
 94:      * Media type of $credData as specified in the <Cred><Meta><Type> element
 95:      * like 'auth-basic'.
 96:      *
 97:      * @var string
 98:      */
 99:     public $credType;
100: 
101:     /**
102:      * Maximum size of a SyncML message in bytes as specified by the
103:      * <Meta><MaxMsgSize> element.
104:      *
105:      * @var integer
106:      */
107:     protected $_maxMsgSize;
108: 
109:     /**
110:      * End element handler for the XML parser, delegated from
111:      * Horde_SyncMl_ContentHandler::endElement().
112:      *
113:      * @param string $uri      The namespace URI of the element.
114:      * @param string $element  The element tag name.
115:      */
116:     public function endElement($uri, $element)
117:     {
118:         switch (count($this->_stack)) {
119:         case 2:
120:             if ($element == 'VerProto') {
121:                 // </VerProto></SyncHdr></SyncML>
122:                 if (trim($this->_chars) == 'SyncML/1.1') {
123:                     $this->_version = 1;
124:                 } elseif (trim($this->_chars) == 'SyncML/1.2') {
125:                     $this->_version = 2;
126:                 } else {
127:                     $this->_version = 0;
128:                 }
129:             } elseif ($element == 'SessionID') {
130:                 // </SessionID></SyncHdr></SyncML>
131:                 $this->_sessionID = trim($this->_chars);
132:             } elseif ($element == 'MsgID') {
133:                 // </MsgID></SyncHdr></SyncML>
134:                 $this->_message = intval(trim($this->_chars));
135:             }
136:             break;
137: 
138:         case 3:
139:             if ($element == 'LocURI') {
140:                 if ($this->_stack[1] == 'Source') {
141:                     // </LocURI></Source></SyncHdr></SyncML>
142:                     $this->_sourceURI = trim($this->_chars);
143:                 } elseif ($this->_stack[1] == 'Target') {
144:                     // </LocURI></Target></SyncHdr></SyncML>
145:                     $this->_targetURI = trim($this->_chars);
146:                 }
147:             } elseif ($element == 'LocName') {
148:                 if ($this->_stack[1] == 'Source') {
149:                     // </LocName></Source></SyncHdr></SyncML>
150:                     $this->user = trim($this->_chars);
151:                 }
152:             } elseif ($element == 'Data') {
153:                     // </Data></Cred></SyncHdr></SyncML>
154:                 if ($this->_stack[1] == 'Cred') {
155:                     $this->credData = trim($this->_chars);
156:                 }
157:             } elseif ($element == 'MaxMsgSize') {
158:                 // </MaxMsgSize></Meta></SyncHdr></SyncML>
159:                 $this->_maxMsgSize = intval($this->_chars);
160:             }
161:             break;
162: 
163:         case 4:
164:             if ($this->_stack[1] == 'Cred') {
165:                 if ($element == 'Format') {
166:                     // </Format></Meta></Cred></SyncHdr></SyncML>
167:                     $this->credFormat = trim($this->_chars);
168:                 } elseif ($element == 'Type') {
169:                     // </Type></Meta></Cred></SyncHdr></SyncML>
170:                     $this->credType = trim($this->_chars);
171:                 }
172:             }
173:             break;
174:         }
175: 
176:         parent::endElement($uri, $element);
177:     }
178: 
179:     /**
180:      * Starts the PHP session and instantiates the global Horde_SyncMl_State object
181:      * if doesn't exist yet.
182:      */
183:     public function setupState()
184:     {
185:         global $backend;
186: 
187:         $backend->sessionStart($this->_sourceURI, $this->_sessionID);
188: 
189:         if (!$backend->state) {
190:             $backend->logMessage(
191:                 'New session created: ' . session_id(), 'DEBUG');
192:             $backend->state = new Horde_SyncMl_State($this->_sourceURI,
193:                                                $this->user,
194:                                                $this->_sessionID);
195:         } else {
196:             $backend->logMessage('Existing session continued: ' . session_id(), 'DEBUG');
197:         }
198: 
199:         $backend->state->setVersion($this->_version);
200:         $backend->state->messageID = $this->_message;
201:         $backend->state->targetURI = $this->_targetURI;
202:         $backend->state->sourceURI = $this->_sourceURI;
203:         $backend->state->sessionID = $this->_sessionID;
204:         if (!empty($this->_maxMsgSize)) {
205:             $backend->state->maxMsgSize = $this->_maxMsgSize;
206:         }
207: 
208:         $backend->setupState();
209:     }
210: }
211: 
API documentation generated by ApiGen