1: <?php
2: /**
3: * The Horde_SyncMl_Command_Status class provides a SyncML implementation of
4: * the Status response as defined in SyncML Representation Protocol, version
5: * 1.1, section 5.4.
6: *
7: * This is not strictly a command but specifies the request status code for a
8: * corresponding SyncML command.
9: *
10: * Copyright 2003-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 <fourmont@gmx.de>
16: * @author Jan Schneider <jan@horde.org>
17: * @package SyncMl
18: */
19: class Horde_SyncMl_Command_Status extends Horde_SyncMl_Command
20: {
21: /**
22: * Name of the command.
23: *
24: * @var string
25: */
26: protected $_cmdName = 'Status';
27:
28: /**
29: * The command ID (CmdID) of the command sent to the client, that this
30: * Status response refers to.
31: *
32: * @var integer
33: */
34: protected $_CmdRef;
35:
36: /**
37: * The message ID (Msg) of the message sent to the client, that this Status
38: * response refers to.
39: *
40: * @var integer
41: */
42: protected $_MsgRef;
43:
44: /**
45: * The status response code, one of the Horde_SyncMl::RESPONSE_* constants.
46: *
47: * @var integer
48: */
49: protected $_Status;
50:
51: /**
52: * The command (Add, Replace, etc) sent to the client, that this Status
53: * response refers to.
54: *
55: * @var string
56: */
57: protected $_Cmd;
58:
59: /**
60: * The client ID of the sent object, that this Status response refers to.
61: *
62: * This element is optional. If specified, Status response refers to a
63: * single Item in the command sent to the client. It refers to all Items in
64: * the sent command otherwise.
65: *
66: * @var string
67: */
68: protected $_TargetRef;
69:
70: /**
71: * The server ID of the sent object, that this Status response refers to.
72: *
73: * This element is optional. If specified, Status response refers to a
74: * single Item in the command sent to the client. It refers to all Items in
75: * the sent command otherwise.
76: *
77: * @var string
78: */
79: protected $_SourceRef;
80:
81: /**
82: * End element handler for the XML parser, delegated from
83: * Horde_SyncMl_ContentHandler::endElement().
84: *
85: * @param string $uri The namespace URI of the element.
86: * @param string $element The element tag name.
87: */
88: public function endElement($uri, $element)
89: {
90: switch (count($this->_stack)) {
91: case 2:
92: switch($element) {
93: case 'CmdRef':
94: case 'MsgRef':
95: case 'Status':
96: $this->{'_' . $element} = intval(trim($this->_chars));
97: break;
98:
99: case 'Cmd':
100: case 'TargetRef':
101: case 'SourceRef':
102: $this->{'_' . $element} = trim($this->_chars);
103: break;
104: }
105: break;
106:
107: case 1:
108: $state = $GLOBALS['backend']->state;
109: switch ($this->_Cmd) {
110: case 'Replace':
111: case 'Add':
112: case 'Delete':
113: $changes = $state->serverChanges[$this->_MsgRef];
114: /* Run through all stored changes and check if we find one
115: * that matches this Status' message and command IDs. */
116: foreach ($changes as $db => $commands) {
117: foreach ($commands as $cmdId => $ids) {
118: if ($cmdId != $this->_CmdRef) {
119: continue;
120: }
121: foreach ($ids as $key => $id) {
122: /* If the Status has a SourceRef and/or TargetRef,
123: * it's a response to a single Item only. */
124: if ((isset($this->_SourceRef) &&
125: $this->_SourceRef != $id[0]) ||
126: (isset($this->_TargetRef) &&
127: $this->_TargetRef != $id[1])) {
128: continue;
129: }
130: /* Match found, remove from stored changes. */
131: unset($state->serverChanges[$this->_MsgRef][$db][$this->_CmdRef][$key]);
132: $sync = &$state->getSync($db);
133: /* This was a Replace originally, but the object
134: * wasn't found on the client. Try an Add
135: * instead. */
136: if ($this->_Cmd == 'Replace' &&
137: $this->_Status == Horde_SyncMl::RESPONSE_NOT_FOUND) {
138: $sync->setServerChange('add', $id[0], $id[1]);
139: }
140: if (isset($this->_SourceRef) || isset($this->_TargetRef)) {
141: break 3;
142: }
143: }
144: }
145: }
146: break;
147: }
148: break;
149: }
150:
151: parent::endElement($uri, $element);
152: }
153: }
154: