1
/* $Xorg: SMlibint.h,v 1.4 2001/02/09 02:03:30 xorgcvs Exp $ */
5
Copyright 1993, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
28
/* $XFree86: xc/lib/SM/SMlibint.h,v 1.4 2001/12/14 19:53:55 dawes Exp $ */
31
* Author: Ralph Mor, X Consortium
38
#include <X11/Xfuncs.h>
40
#include <X11/ICE/ICEmsg.h>
41
#include <X11/ICE/ICEproto.h>
42
#include <X11/SM/SMproto.h>
55
#define SmVendorString "MIT"
56
#define SmReleaseString "1.0"
60
* Pad to a 64 bit boundary
63
#define PAD64(_bytes) ((8 - ((unsigned int) (_bytes) % 8)) % 8)
65
#define PADDED_BYTES64(_bytes) (_bytes + PAD64 (_bytes))
69
* Pad to 32 bit boundary
72
#define PAD32(_bytes) ((4 - ((unsigned int) (_bytes) % 4)) % 4)
74
#define PADDED_BYTES32(_bytes) (_bytes + PAD32 (_bytes))
78
* Number of 8 byte units in _bytes.
81
#define WORD64COUNT(_bytes) (((unsigned int) ((_bytes) + 7)) >> 3)
85
* Compute the number of bytes for an ARRAY8 representation
88
#define ARRAY8_BYTES(_len) (4 + _len + PAD64 (4 + _len))
96
/* byte swap a long literal */
97
#define lswapl(_val) ((((_val) & 0xff) << 24) |\
98
(((_val) & 0xff00) << 8) |\
99
(((_val) & 0xff0000) >> 8) |\
100
(((_val) >> 24) & 0xff))
102
/* byte swap a short literal */
103
#define lswaps(_val) ((((_val) & 0xff) << 8) | (((_val) >> 8) & 0xff))
112
#define STORE_CARD32(_pBuf, _val) \
114
*((CARD32 *) _pBuf) = _val; \
120
#define STORE_CARD32(_pBuf, _val) \
126
memcpy (_pBuf, &_d, 4); \
139
#define EXTRACT_CARD16(_pBuf, _swap, _val) \
141
_val = *((CARD16 *) _pBuf); \
144
_val = lswaps (_val); \
147
#define EXTRACT_CARD32(_pBuf, _swap, _val) \
149
_val = *((CARD32 *) _pBuf); \
152
_val = lswapl (_val); \
157
#define EXTRACT_CARD16(_pBuf, _swap, _val) \
159
_val = *(_pBuf + 0) & 0xff; /* 0xff incase _pBuf is signed */ \
161
_val |= *(_pBuf + 1) & 0xff;\
164
_val = lswaps (_val); \
167
#define EXTRACT_CARD32(_pBuf, _swap, _val) \
169
_val = *(_pBuf + 0) & 0xff; /* 0xff incase _pBuf is signed */ \
171
_val |= *(_pBuf + 1) & 0xff;\
173
_val |= *(_pBuf + 2) & 0xff;\
175
_val |= *(_pBuf + 3) & 0xff;\
178
_val = lswapl (_val); \
185
* Compute the number of bytes for a LISTofPROPERTY representation
188
#define LISTOF_PROP_BYTES(_numProps, _props, _bytes) \
192
for (_i = 0; _i < _numProps; _i++) \
194
_bytes += (8 + ARRAY8_BYTES (strlen (_props[_i]->name)) + \
195
ARRAY8_BYTES (strlen (_props[_i]->type))); \
197
for (_j = 0; _j < _props[_i]->num_vals; _j++) \
198
_bytes += ARRAY8_BYTES (_props[_i]->vals[_j].length); \
207
#define STORE_ARRAY8(_pBuf, _len, _array8) \
209
STORE_CARD32 (_pBuf, _len); \
210
memcpy (_pBuf, _array8, _len); \
212
if (PAD64 (4 + _len)) \
213
_pBuf += PAD64 (4 + _len); \
216
#define STORE_LISTOF_PROPERTY(_pBuf, _count, _props) \
219
STORE_CARD32 (_pBuf, _count); \
221
for (_i = 0; _i < _count; _i++) \
223
STORE_ARRAY8 (_pBuf, strlen (_props[_i]->name), _props[_i]->name); \
224
STORE_ARRAY8 (_pBuf, strlen (_props[_i]->type), _props[_i]->type); \
225
STORE_CARD32 (_pBuf, _props[_i]->num_vals); \
227
for (_j = 0; _j < _props[_i]->num_vals; _j++) \
229
STORE_ARRAY8 (_pBuf, _props[_i]->vals[_j].length, \
230
(char *) _props[_i]->vals[_j].value); \
240
#define EXTRACT_ARRAY8(_pBuf, _swap, _len, _array8) \
242
EXTRACT_CARD32 (_pBuf, _swap, _len); \
243
_array8 = (char *) malloc (_len + 1); \
244
memcpy (_array8, _pBuf, _len); \
245
_array8[_len] = '\0'; \
247
if (PAD64 (4 + _len)) \
248
_pBuf += PAD64 (4 + _len); \
251
#define EXTRACT_ARRAY8_AS_STRING(_pBuf, _swap, _string) \
254
EXTRACT_CARD32 (_pBuf, _swap, _len); \
255
_string = (char *) malloc (_len + 1); \
256
memcpy (_string, _pBuf, _len); \
257
_string[_len] = '\0'; \
259
if (PAD64 (4 + _len)) \
260
_pBuf += PAD64 (4 + _len); \
263
#define EXTRACT_LISTOF_PROPERTY(_pBuf, _swap, _count, _props) \
266
EXTRACT_CARD32 (_pBuf, _swap, _count); \
268
_props = (SmProp **) malloc (_count * sizeof (SmProp *)); \
269
for (_i = 0; _i < _count; _i++) \
271
_props[_i] = (SmProp *) malloc (sizeof (SmProp)); \
272
EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->name); \
273
EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->type); \
274
EXTRACT_CARD32 (_pBuf, _swap, _props[_i]->num_vals); \
276
_props[_i]->vals = (SmPropValue *) malloc ( \
277
_props[_i]->num_vals * sizeof (SmPropValue)); \
278
for (_j = 0; _j < _props[_i]->num_vals; _j++) \
281
EXTRACT_ARRAY8 (_pBuf, _swap, _props[_i]->vals[_j].length, _temp);\
282
_props[_i]->vals[_j].value = (SmPointer) _temp; \
288
#define SKIP_ARRAY8(_pBuf, _swap) \
291
EXTRACT_CARD32 (_pBuf, _swap, _len); \
293
if (PAD64 (4 + _len)) \
294
_pBuf += PAD64 (4 + _len); \
297
#define SKIP_LISTOF_PROPERTY(_pBuf, _swap) \
301
EXTRACT_CARD32 (_pBuf, _swap, _count); \
303
for (_i = 0; _i < _count; _i++) \
306
SKIP_ARRAY8 (_pBuf, _swap); \
307
SKIP_ARRAY8 (_pBuf, _swap); \
308
EXTRACT_CARD32 (_pBuf, _swap, _numvals); \
310
for (_j = 0; _j < _numvals; _j++) \
311
SKIP_ARRAY8 (_pBuf, _swap);\
317
* Client replies not processed by callbacks (we block for them).
321
Status status; /* if 1, client successfully registered */
323
} _SmcRegisterClientReply;
327
* Waiting for Interact
330
typedef struct _SmcInteractWait {
331
SmcInteractProc interact_proc;
332
SmPointer client_data;
333
struct _SmcInteractWait *next;
338
* Waiting for SaveYourselfPhase2
341
typedef struct _SmcPhase2Wait {
342
SmcSaveYourselfPhase2Proc phase2_proc;
343
SmPointer client_data;
348
* Waiting for Properties Reply
351
typedef struct _SmcPropReplyWait {
352
SmcPropReplyProc prop_reply_proc;
353
SmPointer client_data;
354
struct _SmcPropReplyWait *next;
360
* Client connection object
369
unsigned int save_yourself_in_progress : 1;
370
unsigned int shutdown_in_progress : 1;
371
unsigned int unused1 : 6; /* future use */
372
unsigned int unused2 : 8; /* future use */
376
* We use ICE to esablish a connection with the SM.
383
* Major and minor versions of the XSMP.
386
int proto_major_version;
387
int proto_minor_version;
391
* The session manager vendor and release number.
399
* The Client Id uniquely identifies this client to the session manager.
406
* Callbacks to be invoked when messages arrive from the session manager.
407
* These callbacks are specified at SmcOpenConnection time.
410
SmcCallbacks callbacks;
414
* We keep track of all Interact Requests sent by the client. When the
415
* Interact message arrives, we remove it from the list (a FIFO list
419
_SmcInteractWait *interact_waits;
423
* If we send a SaveYourselfPhase2Request, we wait for SaveYourselfPhase2.
426
_SmcPhase2Wait *phase2_wait;
430
* We keep track of all Get Properties sent by the client. When the
431
* Properties Reply arrives, we remove it from the list (a FIFO list
435
_SmcPropReplyWait *prop_reply_waits;
441
* Session manager connection object
450
unsigned int save_yourself_in_progress : 1;
451
unsigned int can_cancel_shutdown : 1;
452
unsigned int interact_in_progress : 1;
453
unsigned int unused1 : 5; /* future use */
454
unsigned int unused2 : 8; /* future use */
458
* We use ICE to esablish a connection with the client.
465
* Major and minor versions of the XSMP.
468
int proto_major_version;
469
int proto_minor_version;
473
* The Client Id uniquely identifies this client to the session manager.
480
* Callbacks to be invoked when messages arrive from the client.
483
SmsCallbacks callbacks;
487
* What type of interaction is allowed - SmInteractStyle{None,Errors,Any}
490
char interaction_allowed;
496
* Extern declarations
499
extern int _SmcOpcode;
500
extern int _SmsOpcode;
502
extern int _SmVersionCount;
503
extern IcePoVersionRec _SmcVersions[];
504
extern IcePaVersionRec _SmsVersions[];
506
extern int _SmAuthCount;
507
extern char *_SmAuthNames[];
508
extern IcePoAuthProc _SmcAuthProcs[];
509
extern IcePaAuthProc _SmsAuthProcs[];
511
extern SmsNewClientProc _SmsNewClientProc;
512
extern SmPointer _SmsNewClientData;
514
extern SmcErrorHandler _SmcErrorHandler;
515
extern SmsErrorHandler _SmsErrorHandler;
517
#endif /* _SMLIBINT_H_ */