Oolite
Loading...
Searching...
No Matches
OODebugTCPConsoleProtocol.h
Go to the documentation of this file.
1/*
2
3OODebugTCPConsoleProtocol.h
4
5Definitions used in Oolite remote debug console protocol.
6
7
8Oolite Debug Support
9
10Copyright (C) 2007-2013 Jens Ayton
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files (the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions:
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29
30*/
31
32#ifndef OOALSTR
33#ifdef __OBJC__
34#import <Foundation/Foundation.h>
35#define OOALSTR(x) @"" x
36#else // C
37#include <CoreFoundation/CoreFoundation.h>
38#define OOALSTR(x) CFSTR(x)
39#endif
40#endif
41
42enum {
43 kOOTCPConsolePort = 0x002173 /* = 8563 */
44};
45
46/* PROTOCOL OVERVIEW
47
48 The basic unit of the protocol is property lists. Property lists originate
49 with OpenStep and are thus defined in Cocoa and GNUstep, but they're also
50 implemented in CoreFoundation (Mac OS X) and CFLite (cross-platform), with
51 a C interface.
52
53 The protocol uses a TCP stream in each direction. Each stream consists of
54 a series of property lists in the Apple XML encoding. Each property list
55 is framed in the simplest possible way: it is preceeded by an unsigned
56 32-bit length, in network-endian order. Each length + property list
57 combination is referred to as a packet.
58
59 Every packet's property list must have a dictionary as its root element.
60 The dictionary must contain a kOOTCPConsolePacketType key, whose value
61 determines the meaning of the rest of the dictionary.
62*/
63
64/* *** Packet types *** */
65/* kOOTCPPacket_RequestConnection
66 client --> server
67 Message sent from client (Oolite) to server (console) to request a cosole
68 connection.
69
70 Required values:
71 kOOTCPProtocolVersion
72 kOOTCPOoliteVersion
73 Expected responses:
74 kOOTCPPacket_ApproveConnection
75 OR
76 kOOTCPPacket_RejectConnection
77*/
78#define kOOTCPPacket_RequestConnection OOALSTR("Request Connection")
79
80/* kOOTCPPacket_ApproveConnection
81 client <-- server
82 Message sent in response to kOOTCPPacket_RequestConnection if connection is
83 established successfully.
84
85 Optional values:
86 kOOTCPConsoleIdentity
87*/
88#define kOOTCPPacket_ApproveConnection OOALSTR("Approve Connection")
89
90/* kOOTCPPacket_RejectConnection
91 client <-- server
92 Message sent in response to kOOTCPPacket_RequestConnection if connection is
93 not established successfully. After this message is sent, the connection
94 is closed with no further traffic.
95
96 Optional values:
97 kOOTCPMessage
98 Expected responses:
99 None permitted.
100*/
101#define kOOTCPPacket_RejectConnection OOALSTR("Reject Connection")
102
103/* kOOTCPPacket_CloseConnection
104 client <-> server
105 Message sent by either party to cleanly close connection.
106
107 Optional values:
108 kOOTCPMessage
109 Expected responses:
110 None permitted.
111*/
112#define kOOTCPPacket_CloseConnection OOALSTR("Close Connection")
113
114/* kOOTCPPacket_ConsoleOutput
115 client --> server
116 Message sent by Oolite to print text to console.
117
118 Required values:
119 kOOTCPMessage
120 kOOTCPColorKey
121 Optional values:
122 kOOTCPEmphasisRanges
123*/
124#define kOOTCPPacket_ConsoleOutput OOALSTR("Console Output")
125
126/* kOOTCPPacket_ClearConsole
127 client --> server
128 Message sent by Oolite to clear console output.
129*/
130#define kOOTCPPacket_ClearConsole OOALSTR("Clear Console")
131
132/* kOOTCPPacket_ShowConsole
133 client --> server
134 Message sent by Oolite to request that the cosole makes itself visible and
135 active.
136*/
137#define kOOTCPPacket_ShowConsole OOALSTR("Show Console")
138
139/* kOOTCPPacket_NoteConfiguration
140 client --> server
141 Message sent by Oolite to appraise the console of the contents of the
142 configuration dictionary. Sent once after the initial handshake.
143
144 Required values:
145 kOOTCPConfiguration
146*/
147#define kOOTCPPacket_NoteConfiguration OOALSTR("Note Configuration")
148
149/* kOOTCPPacket_NoteConfigurationChange
150 client <-> server
151 Message sent by Oolite when the contents of the configuration dictionary
152 change, or by console to change the configuration dictionary (in which
153 case a confirmation will be returned in form of one or more
154 kOOTCPPacket_NoteConfigurationChange messages). For this message,
155 kOOTCPConfiguration is a delta -- keys not contained in it are not to be
156 removed, they are simply unchanged. Deletions are handled with
157 kOOTCPRemovedConfigurationKeys.
158
159 This key is also sent in response to a kOOTCPPacket_RequestConfigurationValue
160 message, even if no configuration value has changed.
161
162 Required values (at least one of):
163 kOOTCPConfiguration
164 kOOTCPRemovedConfigurationKeys
165*/
166#define kOOTCPPacket_NoteConfigurationChange OOALSTR("Note Configuration Change")
167
168/* kOOTCPPacket_PerformCommand
169 client <-- server
170 Message sent by console to issue a command.
171
172 Required values:
173 kOOTCPMessage
174*/
175#define kOOTCPPacket_PerformCommand OOALSTR("Perform Command")
176
177/* kOOTCPPacket_RequestConfigurationValue
178 client <-- server
179 Message sent by console to request a configuration value. This will result
180 in a kOOTCPPacket_NoteConfigurationChange message being sent. If the value
181 is nil, the response will contain a kOOTCPRemovedConfigurationKeys value.
182
183 Required values:
184 kOOTCPConfigurationKey
185 Expected response:
186 kOOTCPPacket_NoteConfigurationChange
187*/
188#define kOOTCPPacket_RequestConfigurationValue OOALSTR("Request Configuration Value")
189
190/* kOOTCPPacket_Ping
191 client <-> server
192 Must be responded to with a kOOTCPPacket_Pong message containing the same
193 kOOTCPMessage, if any.
194
195 Optional values:
196 kOOTCPMessage
197 Expected response:
198 kOOTCPPacket_Pong
199*/
200#define kOOTCPPacket_Ping OOALSTR("Ping")
201
202/* kOOTCPPacket_Pong
203 client <-> server
204 Must be sent in response to kOOTCPPacket_Ping. If the kOOTCPPacket_Ping
205 packet had a kOOTCPMessage, the same kOOTCPMessage value must be attached
206 to the kOOTCPPacket_Pong.
207
208 Optional values:
209 kOOTCPMessage (required if included in ping)
210*/
211#define kOOTCPPacket_Pong OOALSTR("Pong")
212
213/* *** Value keys *** */
214/* kOOTCPPacketType
215 String indicating packet type. See above under
216
217 See constants below under *** Packet types ***.
218*/
219#define kOOTCPPacketType OOALSTR("packet type")
220
221/* kOOTCPProtocolVersion
222 Number indicating version of debug console TCP protocol. Sent with
223 kOOTCPPacket_RequestConnection.
224
225 See constants below under *** Version constants ***.
226*/
227#define kOOTCPProtocolVersion OOALSTR("protocol version")
228
229/* kOOTCPOoliteVersion
230 String indicating the version of Oolite, for example "1.70" or "1.71.1 b2".
231 Consists of two or more integers separated by .s, optionally followed by
232 a space and additional information in unspecified format. Sent with
233 kOOTCPPacket_RequestConnection.
234*/
235#define kOOTCPOoliteVersion OOALSTR("Oolite version")
236
237/* kOOTCPMessage
238 Textual message sent with various packet types. No specified format.
239*/
240#define kOOTCPMessage OOALSTR("message")
241
242/* kOOTCPConsoleIdentity
243 String identifying console software. No specified format.
244*/
245#define kOOTCPConsoleIdentity OOALSTR("console identity")
246
247/* kOOTCPColorKey
248 String identifying colour/formatting to be used. The configuration
249 dictionary contains keys of the form foo-foreground-color and
250 foo-background-color to be used. If no colour is specified for the
251 specified key, the key "general" should be tried. The colour values are
252 specified as arrays of three numbers in the range 0-1, specifying RGB
253 colours.
254
255 For example, if the configuration key contains:
256 {
257 general-background-color = (1,1,1);
258 general-foreground-color = (0,0,0);
259 foo-background-color = (1,0,0);
260 }
261 the colour key "foo" maps to the background colour (1,0,0) and the
262 foreground color (0,0,0). Sent with kOOTCPPacket_ConsoleOutput.
263*/
264#define kOOTCPColorKey OOALSTR("color key")
265
266/* kOOTCPEmphasisRanges
267 An array containing an even number of integers. Each pair of integers
268 specifies a range (in the form offset, length) which should be emphasized.
269 Sent with kOOTCPPacket_ConsoleOutput.
270*/
271#define kOOTCPEmphasisRanges OOALSTR("emphasis ranges")
272
273/* kOOTCPConfiguration
274 A dictionary of key/value pairs to add/set in the configuration
275 dictionary. Sent with kOOTCPPacket_NoteConfiguration and
276 kOOTCPPacket_NoteConfiguration.
277*/
278#define kOOTCPConfiguration OOALSTR("configuration")
279
280/* kOOTCPConfiguration
281 An array of keys to remove from the configuration dictionary. Sent with
282 kOOTCPPacket_NoteConfiguration.
283*/
284#define kOOTCPRemovedConfigurationKeys OOALSTR("removed configuration keys")
285
286/* kOOTCPConfigurationKey
287 A string specifying the configuration key for which a value is requested.
288 Sent with kOOTCPPacket_RequestConfigurationValue.
289*/
290#define kOOTCPConfigurationKey OOALSTR("configuration key")
291
292/* *** Version constants *** */
293/* Version constants have three components: format, major and minor. The
294 format version will change if the framing mechanism is changed, that is,
295 if we switch from the property-list basted protocol in use. The major
296 version will be changed to indicate compatibility-breaking changes. The
297 minor version will be changed when new non-critical packets are added.
298*/
299
300#define OOTCP_ENCODE_VERSION(f, mj, mi) \
301 ((((f) << 16) & kOOTCPProtocolVersionFormatMask) | (((f) << 8) & kOOTCPProtocolVersionMajorMask) | ((mi) & kOOTCPProtocolVersionMinorMask))
302
303#define OOTCP_VERSION_FORMAT(v) (((v) & kOOTCPProtocolVersionFormatMask) >> 16)
304#define OOTCP_VERSION_MAJOR(v) (((v) & kOOTCPProtocolVersionMajorMask) >> 8)
305#define OOTCP_VERSION_MINOR(v) ((v) & kOOTCPProtocolVersionMinorMask)
306
307enum {
311
313
314 // 1:1.0, first version.
316};
@ kOOTCPProtocolVersionMajorMask
@ kOOTCPProtocolVersionMinorMask
@ kOOTCPProtocolVersionPListFormat
@ kOOTCPProtocolVersionFormatMask
@ kOOTCPProtocolVersion_1_1_0
#define OOTCP_ENCODE_VERSION(f, mj, mi)