File: SyncHdr.php

package info (click to toggle)
horde3 3.3.8%2Bdebian0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 34,220 kB
  • ctags: 28,224
  • sloc: php: 115,191; xml: 4,247; sql: 2,417; sh: 147; makefile: 140
file content (220 lines) | stat: -rw-r--r-- 6,671 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php

require_once 'SyncML/Command.php';

/**
 * The SyncML_Command_SyncHdr class provides a SyncML implementation of the
 * SyncHdr as defined in SyncML Representation Protocol, version 1.1, section
 * 5.2.2.
 *
 * SyncHdr is not really a sync command, but this class takes advantage of the
 * XML parser in SyncML_Command.
 *
 * $Horde: framework/SyncML/SyncML/Command/SyncHdr.php,v 1.4.2.5 2009/04/05 21:38:48 jan Exp $
 *
 * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
 *
 * 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  Karsten Fourmont <karsten@horde.org>
 * @author  Jan Schneider <jan@horde.org>
 * @since   Horde 3.2
 * @package SyncML
 */
class SyncML_Command_SyncHdr extends SyncML_Command {

    /**
     * Name of the command.
     *
     * @var string
     */
    var $_cmdName = 'SyncHdr';

    /**
     * Username as specified in the <LocName> element.
     *
     * @var string
     */
    var $user;

    /**
     * Id of this SyncML session as specified in the <SessionID> element.
     *
     * This is not to confuse with the PHP session id, though it is part of
     * the generated PHP session id.
     *
     * @var string
     */
    var $_sessionID;

    /**
     * SyncML protocol version as specified in the <VerProto> element.
     *
     * 0 for SyncML 1.0, 1 for SyncML 1.1, etc.
     *
     * @var integer
     */
    var $_version;

    /**
     * Id of the current message as specified in the <MsgID> element.
     *
     * @var integer
     */
    var $_message;

    /**
     * The target URI as specified by the <Target><LocURI> element.
     *
     * This is normally the URL of the Horde RPC server. However the client is
     * free to send anything.
     *
     * @var string
     */
    var $_targetURI;

    /**
     * The source URI as specified by the <Source><LocURI> element.
     *
     * @var string
     */
    var $_sourceURI;

    /**
     * Authentication credential as specified by the <Cred><Data> element.
     *
     * @var string
     */
    var $credData;

    /**
     * Encoding format of $credData as specified in the <Cred><Meta><Format>
     * element like 'b64'.
     *
     * @var string
     */
    var $credFormat;

    /**
     * Media type of $credData as specified in the <Cred><Meta><Type> element
     * like 'auth-basic'.
     *
     * @var string
     */
    var $credType;

    /**
     * Maximum size of a SyncML message in bytes as specified by the
     * <Meta><MaxMsgSize> element.
     *
     * @var integer
     */
    var $_maxMsgSize;

    /**
     * End element handler for the XML parser, delegated from
     * SyncML_ContentHandler::endElement().
     *
     * @param string $uri      The namespace URI of the element.
     * @param string $element  The element tag name.
     */
    function endElement($uri, $element)
    {
        switch (count($this->_stack)) {
        case 2:
            if ($element == 'VerProto') {
                // </VerProto></SyncHdr></SyncML>
                if (trim($this->_chars) == 'SyncML/1.1') {
                    $this->_version = 1;
                } elseif (trim($this->_chars) == 'SyncML/1.2') {
                    $this->_version = 2;
                } else {
                    $this->_version = 0;
                }
            } elseif ($element == 'SessionID') {
                // </SessionID></SyncHdr></SyncML>
                $this->_sessionID = trim($this->_chars);
            } elseif ($element == 'MsgID') {
                // </MsgID></SyncHdr></SyncML>
                $this->_message = intval(trim($this->_chars));
            }
            break;

        case 3:
            if ($element == 'LocURI') {
                if ($this->_stack[1] == 'Source') {
                    // </LocURI></Source></SyncHdr></SyncML>
                    $this->_sourceURI = trim($this->_chars);
                } elseif ($this->_stack[1] == 'Target') {
                    // </LocURI></Target></SyncHdr></SyncML>
                    $this->_targetURI = trim($this->_chars);
                }
            } elseif ($element == 'LocName') {
                if ($this->_stack[1] == 'Source') {
                    // </LocName></Source></SyncHdr></SyncML>
                    $this->user = trim($this->_chars);
                }
            } elseif ($element == 'Data') {
                    // </Data></Cred></SyncHdr></SyncML>
                if ($this->_stack[1] == 'Cred') {
                    $this->credData = trim($this->_chars);
                }
            } elseif ($element == 'MaxMsgSize') {
                // </MaxMsgSize></Meta></SyncHdr></SyncML>
                $this->_maxMsgSize = intval($this->_chars);
            }
            break;

        case 4:
            if ($this->_stack[1] == 'Cred') {
                if ($element == 'Format') {
                    // </Format></Meta></Cred></SyncHdr></SyncML>
                    $this->credFormat = trim($this->_chars);
                } elseif ($element == 'Type') {
                    // </Type></Meta></Cred></SyncHdr></SyncML>
                    $this->credType = trim($this->_chars);
                }
            }
            break;
        }

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

    /**
     * Starts the PHP session and instantiates the global SyncML_State object
     * if doesn't exist yet.
     */
    function setupState()
    {
        $GLOBALS['backend']->sessionStart($this->_sourceURI,
                                          $this->_sessionID);

        if (!isset($_SESSION['SyncML.state'])) {
            $GLOBALS['backend']->logMessage(
                'New session created: ' . session_id(),
                __FILE__, __LINE__, PEAR_LOG_DEBUG);
            $_SESSION['SyncML.state'] = new SyncML_State($this->_sourceURI,
                                                         $this->user,
                                                         $this->_sessionID);
        } else {
            $GLOBALS['backend']->logMessage(
                'Existing session continued: ' . session_id(),
                __FILE__, __LINE__, PEAR_LOG_DEBUG);
        }

        $state = &$_SESSION['SyncML.state'];
        $state->setVersion($this->_version);
        $state->messageID = $this->_message;
        $state->targetURI = $this->_targetURI;
        $state->sourceURI = $this->_sourceURI;
        $state->sessionID = $this->_sessionID;
        if (!empty($this->_maxMsgSize)) {
            $state->maxMsgSize = $this->_maxMsgSize;
        }

        $GLOBALS['backend']->setupState($state);
    }

}