3 Copyright 1993, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
28 * Author: Ralph Mor, X Consortium
35 #include <X11/Xfuncs.h>
37 #include <X11/ICE/ICEmsg.h>
38 #include <X11/ICE/ICEproto.h>
39 #include <X11/SM/SMproto.h>
52 #define SmVendorString "MIT"
53 #define SmReleaseString "1.0"
57 * Pad to a 64 bit boundary
60 #define PAD64(_bytes) ((8 - ((unsigned int) (_bytes) % 8)) % 8)
62 #define PADDED_BYTES64(_bytes) (_bytes + PAD64 (_bytes))
66 * Pad to 32 bit boundary
69 #define PAD32(_bytes) ((4 - ((unsigned int) (_bytes) % 4)) % 4)
71 #define PADDED_BYTES32(_bytes) (_bytes + PAD32 (_bytes))
75 * Number of 8 byte units in _bytes.
78 #define WORD64COUNT(_bytes) (((unsigned int) ((_bytes) + 7)) >> 3)
82 * Compute the number of bytes for an ARRAY8 representation
85 #define ARRAY8_BYTES(_len) (4 + _len + PAD64 (4 + _len))
93 /* byte swap a long literal */
94 #define lswapl(_val) ((((_val) & 0xff) << 24) |\
95 (((_val) & 0xff00) << 8) |\
96 (((_val) & 0xff0000) >> 8) |\
97 (((_val) >> 24) & 0xff))
99 /* byte swap a short literal */
100 #define lswaps(_val) ((((_val) & 0xff) << 8) | (((_val) >> 8) & 0xff))
107 #define STORE_CARD32(_pBuf, _val) \
109 *((CARD32 *) _pBuf) = _val; \
118 #define EXTRACT_CARD16(_pBuf, _swap, _val) \
120 _val = *((CARD16 *) _pBuf); \
123 _val = lswaps (_val); \
126 #define EXTRACT_CARD32(_pBuf, _swap, _val) \
128 _val = *((CARD32 *) _pBuf); \
131 _val = lswapl (_val); \
136 * Compute the number of bytes for a LISTofPROPERTY representation
139 #define LISTOF_PROP_BYTES(_numProps, _props, _bytes) \
143 for (_i = 0; _i < _numProps; _i++) \
145 _bytes += (8 + ARRAY8_BYTES (strlen (_props[_i]->name)) + \
146 ARRAY8_BYTES (strlen (_props[_i]->type))); \
148 for (_j = 0; _j < _props[_i]->num_vals; _j++) \
149 _bytes += ARRAY8_BYTES (_props[_i]->vals[_j].length); \
158 #define STORE_ARRAY8(_pBuf, _len, _array8) \
160 STORE_CARD32 (_pBuf, (CARD32) _len); \
162 memcpy (_pBuf, _array8, _len); \
163 _pBuf += _len + PAD64 (4 + _len); \
166 #define STORE_LISTOF_PROPERTY(_pBuf, _count, _props) \
169 STORE_CARD32 (_pBuf, _count); \
171 for (_i = 0; _i < _count; _i++) \
173 STORE_ARRAY8 (_pBuf, strlen (_props[_i]->name), _props[_i]->name); \
174 STORE_ARRAY8 (_pBuf, strlen (_props[_i]->type), _props[_i]->type); \
175 STORE_CARD32 (_pBuf, _props[_i]->num_vals); \
177 for (_j = 0; _j < _props[_i]->num_vals; _j++) \
179 STORE_ARRAY8 (_pBuf, _props[_i]->vals[_j].length, \
180 (char *) _props[_i]->vals[_j].value); \
190 #define EXTRACT_ARRAY8(_pBuf, _swap, _len, _array8) \
192 EXTRACT_CARD32 (_pBuf, _swap, _len); \
193 _array8 = malloc (_len + 1); \
194 memcpy (_array8, _pBuf, _len); \
195 _array8[_len] = '\0'; \
196 _pBuf += _len + PAD64 (4 + _len); \
199 #define EXTRACT_ARRAY8_AS_STRING(_pBuf, _swap, _string) \
202 EXTRACT_CARD32 (_pBuf, _swap, _len); \
203 _string = malloc (_len + 1); \
204 memcpy (_string, _pBuf, _len); \
205 _string[_len] = '\0'; \
206 _pBuf += _len + PAD64 (4 + _len); \
209 #define EXTRACT_LISTOF_PROPERTY(_pBuf, _swap, _count, _props) \
212 EXTRACT_CARD32 (_pBuf, _swap, _count); \
214 _props = malloc (_count * sizeof (SmProp *)); \
215 for (_i = 0; _i < _count; _i++) \
217 _props[_i] = malloc (sizeof (SmProp)); \
218 EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->name); \
219 EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->type); \
220 EXTRACT_CARD32 (_pBuf, _swap, _props[_i]->num_vals); \
222 _props[_i]->vals = malloc ( \
223 _props[_i]->num_vals * sizeof (SmPropValue)); \
224 for (_j = 0; _j < _props[_i]->num_vals; _j++) \
227 EXTRACT_ARRAY8 (_pBuf, _swap, _props[_i]->vals[_j].length, _temp);\
228 _props[_i]->vals[_j].value = (SmPointer) _temp; \
234 #define SKIP_ARRAY8(_pBuf, _swap) \
237 EXTRACT_CARD32 (_pBuf, _swap, _len); \
238 _pBuf += _len + PAD64 (4 + _len); \
241 #define SKIP_LISTOF_PROPERTY(_pBuf, _swap) \
245 EXTRACT_CARD32 (_pBuf, _swap, _count); \
247 for (_i = 0; _i < _count; _i++) \
250 SKIP_ARRAY8 (_pBuf, _swap); \
251 SKIP_ARRAY8 (_pBuf, _swap); \
252 EXTRACT_CARD32 (_pBuf, _swap, _numvals); \
254 for (_j = 0; _j < _numvals; _j++) \
255 SKIP_ARRAY8 (_pBuf, _swap);\
261 * Client replies not processed by callbacks (we block for them).
265 Status status; /* if 1, client successfully registered */
267 } _SmcRegisterClientReply;
271 * Waiting for Interact
274 typedef struct _SmcInteractWait {
275 SmcInteractProc interact_proc;
276 SmPointer client_data;
277 struct _SmcInteractWait *next;
282 * Waiting for SaveYourselfPhase2
285 typedef struct _SmcPhase2Wait {
286 SmcSaveYourselfPhase2Proc phase2_proc;
287 SmPointer client_data;
292 * Waiting for Properties Reply
295 typedef struct _SmcPropReplyWait {
296 SmcPropReplyProc prop_reply_proc;
297 SmPointer client_data;
298 struct _SmcPropReplyWait *next;
304 * Client connection object
313 unsigned int save_yourself_in_progress : 1;
314 unsigned int shutdown_in_progress : 1;
315 unsigned int unused1 : 6; /* future use */
316 unsigned int unused2 : 8; /* future use */
320 * We use ICE to esablish a connection with the SM.
327 * Major and minor versions of the XSMP.
330 int proto_major_version;
331 int proto_minor_version;
335 * The session manager vendor and release number.
343 * The Client Id uniquely identifies this client to the session manager.
350 * Callbacks to be invoked when messages arrive from the session manager.
351 * These callbacks are specified at SmcOpenConnection time.
354 SmcCallbacks callbacks;
358 * We keep track of all Interact Requests sent by the client. When the
359 * Interact message arrives, we remove it from the list (a FIFO list
363 _SmcInteractWait *interact_waits;
367 * If we send a SaveYourselfPhase2Request, we wait for SaveYourselfPhase2.
370 _SmcPhase2Wait *phase2_wait;
374 * We keep track of all Get Properties sent by the client. When the
375 * Properties Reply arrives, we remove it from the list (a FIFO list
379 _SmcPropReplyWait *prop_reply_waits;
385 * Session manager connection object
394 unsigned int save_yourself_in_progress : 1;
395 unsigned int can_cancel_shutdown : 1;
396 unsigned int interact_in_progress : 1;
397 unsigned int unused1 : 5; /* future use */
398 unsigned int unused2 : 8; /* future use */
402 * We use ICE to esablish a connection with the client.
409 * Major and minor versions of the XSMP.
412 int proto_major_version;
413 int proto_minor_version;
417 * The Client Id uniquely identifies this client to the session manager.
424 * Callbacks to be invoked when messages arrive from the client.
427 SmsCallbacks callbacks;
431 * What type of interaction is allowed - SmInteractStyle{None,Errors,Any}
434 char interaction_allowed;
440 * Extern declarations
443 _SmcProcessMessage(IceConn iceConn, IcePointer clientData, int opcode,
444 unsigned long length, Bool swap,
445 IceReplyWaitInfo *replyWait, Bool *replyReadyRet);
448 _SmsProcessMessage(IceConn iceConn, IcePointer clientData, int opcode,
449 unsigned long length, Bool swap);
452 _SmcDefaultErrorHandler(SmcConn smcConn, Bool swap, int offendingMinorOpcode,
453 unsigned long offendingSequence, int errorClass,
454 int severity, SmPointer values);
457 _SmsDefaultErrorHandler(SmsConn smsConn, Bool swap, int offendingMinorOpcode,
458 unsigned long offendingSequence, int errorClass,
459 int severity, SmPointer values);
461 extern int _SmcOpcode;
462 extern int _SmsOpcode;
464 extern SmsNewClientProc _SmsNewClientProc;
465 extern SmPointer _SmsNewClientData;
467 extern SmcErrorHandler _SmcErrorHandler;
468 extern SmsErrorHandler _SmsErrorHandler;
470 #endif /* _SMLIBINT_H_ */