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))
109 #define STORE_CARD32(_pBuf, _val) \
111 *((CARD32 *) _pBuf) = _val; \
117 #define STORE_CARD32(_pBuf, _val) \
123 memcpy (_pBuf, &_d, 4); \
136 #define EXTRACT_CARD16(_pBuf, _swap, _val) \
138 _val = *((CARD16 *) _pBuf); \
141 _val = lswaps (_val); \
144 #define EXTRACT_CARD32(_pBuf, _swap, _val) \
146 _val = *((CARD32 *) _pBuf); \
149 _val = lswapl (_val); \
154 #define EXTRACT_CARD16(_pBuf, _swap, _val) \
156 _val = *(_pBuf + 0) & 0xff; /* 0xff incase _pBuf is signed */ \
158 _val |= *(_pBuf + 1) & 0xff;\
161 _val = lswaps (_val); \
164 #define EXTRACT_CARD32(_pBuf, _swap, _val) \
166 _val = *(_pBuf + 0) & 0xff; /* 0xff incase _pBuf is signed */ \
168 _val |= *(_pBuf + 1) & 0xff;\
170 _val |= *(_pBuf + 2) & 0xff;\
172 _val |= *(_pBuf + 3) & 0xff;\
175 _val = lswapl (_val); \
182 * Compute the number of bytes for a LISTofPROPERTY representation
185 #define LISTOF_PROP_BYTES(_numProps, _props, _bytes) \
189 for (_i = 0; _i < _numProps; _i++) \
191 _bytes += (8 + ARRAY8_BYTES (strlen (_props[_i]->name)) + \
192 ARRAY8_BYTES (strlen (_props[_i]->type))); \
194 for (_j = 0; _j < _props[_i]->num_vals; _j++) \
195 _bytes += ARRAY8_BYTES (_props[_i]->vals[_j].length); \
204 #define STORE_ARRAY8(_pBuf, _len, _array8) \
206 STORE_CARD32 (_pBuf, _len); \
208 memcpy (_pBuf, _array8, _len); \
209 _pBuf += _len + PAD64 (4 + _len); \
212 #define STORE_LISTOF_PROPERTY(_pBuf, _count, _props) \
215 STORE_CARD32 (_pBuf, _count); \
217 for (_i = 0; _i < _count; _i++) \
219 STORE_ARRAY8 (_pBuf, strlen (_props[_i]->name), _props[_i]->name); \
220 STORE_ARRAY8 (_pBuf, strlen (_props[_i]->type), _props[_i]->type); \
221 STORE_CARD32 (_pBuf, _props[_i]->num_vals); \
223 for (_j = 0; _j < _props[_i]->num_vals; _j++) \
225 STORE_ARRAY8 (_pBuf, _props[_i]->vals[_j].length, \
226 (char *) _props[_i]->vals[_j].value); \
236 #define EXTRACT_ARRAY8(_pBuf, _swap, _len, _array8) \
238 EXTRACT_CARD32 (_pBuf, _swap, _len); \
239 _array8 = (char *) malloc (_len + 1); \
240 memcpy (_array8, _pBuf, _len); \
241 _array8[_len] = '\0'; \
242 _pBuf += _len + PAD64 (4 + _len); \
245 #define EXTRACT_ARRAY8_AS_STRING(_pBuf, _swap, _string) \
248 EXTRACT_CARD32 (_pBuf, _swap, _len); \
249 _string = (char *) malloc (_len + 1); \
250 memcpy (_string, _pBuf, _len); \
251 _string[_len] = '\0'; \
252 _pBuf += _len + PAD64 (4 + _len); \
255 #define EXTRACT_LISTOF_PROPERTY(_pBuf, _swap, _count, _props) \
258 EXTRACT_CARD32 (_pBuf, _swap, _count); \
260 _props = (SmProp **) malloc (_count * sizeof (SmProp *)); \
261 for (_i = 0; _i < _count; _i++) \
263 _props[_i] = (SmProp *) malloc (sizeof (SmProp)); \
264 EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->name); \
265 EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->type); \
266 EXTRACT_CARD32 (_pBuf, _swap, _props[_i]->num_vals); \
268 _props[_i]->vals = (SmPropValue *) malloc ( \
269 _props[_i]->num_vals * sizeof (SmPropValue)); \
270 for (_j = 0; _j < _props[_i]->num_vals; _j++) \
273 EXTRACT_ARRAY8 (_pBuf, _swap, _props[_i]->vals[_j].length, _temp);\
274 _props[_i]->vals[_j].value = (SmPointer) _temp; \
280 #define SKIP_ARRAY8(_pBuf, _swap) \
283 EXTRACT_CARD32 (_pBuf, _swap, _len); \
284 _pBuf += _len + PAD64 (4 + _len); \
287 #define SKIP_LISTOF_PROPERTY(_pBuf, _swap) \
291 EXTRACT_CARD32 (_pBuf, _swap, _count); \
293 for (_i = 0; _i < _count; _i++) \
296 SKIP_ARRAY8 (_pBuf, _swap); \
297 SKIP_ARRAY8 (_pBuf, _swap); \
298 EXTRACT_CARD32 (_pBuf, _swap, _numvals); \
300 for (_j = 0; _j < _numvals; _j++) \
301 SKIP_ARRAY8 (_pBuf, _swap);\
307 * Client replies not processed by callbacks (we block for them).
311 Status status; /* if 1, client successfully registered */
313 } _SmcRegisterClientReply;
317 * Waiting for Interact
320 typedef struct _SmcInteractWait {
321 SmcInteractProc interact_proc;
322 SmPointer client_data;
323 struct _SmcInteractWait *next;
328 * Waiting for SaveYourselfPhase2
331 typedef struct _SmcPhase2Wait {
332 SmcSaveYourselfPhase2Proc phase2_proc;
333 SmPointer client_data;
338 * Waiting for Properties Reply
341 typedef struct _SmcPropReplyWait {
342 SmcPropReplyProc prop_reply_proc;
343 SmPointer client_data;
344 struct _SmcPropReplyWait *next;
350 * Client connection object
359 unsigned int save_yourself_in_progress : 1;
360 unsigned int shutdown_in_progress : 1;
361 unsigned int unused1 : 6; /* future use */
362 unsigned int unused2 : 8; /* future use */
366 * We use ICE to esablish a connection with the SM.
373 * Major and minor versions of the XSMP.
376 int proto_major_version;
377 int proto_minor_version;
381 * The session manager vendor and release number.
389 * The Client Id uniquely identifies this client to the session manager.
396 * Callbacks to be invoked when messages arrive from the session manager.
397 * These callbacks are specified at SmcOpenConnection time.
400 SmcCallbacks callbacks;
404 * We keep track of all Interact Requests sent by the client. When the
405 * Interact message arrives, we remove it from the list (a FIFO list
409 _SmcInteractWait *interact_waits;
413 * If we send a SaveYourselfPhase2Request, we wait for SaveYourselfPhase2.
416 _SmcPhase2Wait *phase2_wait;
420 * We keep track of all Get Properties sent by the client. When the
421 * Properties Reply arrives, we remove it from the list (a FIFO list
425 _SmcPropReplyWait *prop_reply_waits;
431 * Session manager connection object
440 unsigned int save_yourself_in_progress : 1;
441 unsigned int can_cancel_shutdown : 1;
442 unsigned int interact_in_progress : 1;
443 unsigned int unused1 : 5; /* future use */
444 unsigned int unused2 : 8; /* future use */
448 * We use ICE to esablish a connection with the client.
455 * Major and minor versions of the XSMP.
458 int proto_major_version;
459 int proto_minor_version;
463 * The Client Id uniquely identifies this client to the session manager.
470 * Callbacks to be invoked when messages arrive from the client.
473 SmsCallbacks callbacks;
477 * What type of interaction is allowed - SmInteractStyle{None,Errors,Any}
480 char interaction_allowed;
486 * Extern declarations
489 _SmcProcessMessage(IceConn iceConn, IcePointer clientData, int opcode,
490 unsigned long length, Bool swap,
491 IceReplyWaitInfo *replyWait, Bool *replyReadyRet);
494 _SmsProcessMessage(IceConn iceConn, IcePointer clientData, int opcode,
495 unsigned long length, Bool swap);
498 _SmcDefaultErrorHandler(SmcConn smcConn, Bool swap, int offendingMinorOpcode,
499 unsigned long offendingSequence, int errorClass,
500 int severity, SmPointer values);
503 _SmsDefaultErrorHandler(SmsConn smsConn, Bool swap, int offendingMinorOpcode,
504 unsigned long offendingSequence, int errorClass,
505 int severity, SmPointer values);
507 extern int _SmcOpcode;
508 extern int _SmsOpcode;
510 extern SmsNewClientProc _SmsNewClientProc;
511 extern SmPointer _SmsNewClientData;
513 extern SmcErrorHandler _SmcErrorHandler;
514 extern SmsErrorHandler _SmsErrorHandler;
516 #endif /* _SMLIBINT_H_ */