1 /******************************************************************************
4 Copyright 1993, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
26 Author: Ralph Mor, X Consortium
27 ******************************************************************************/
32 #include <X11/ICE/ICElib.h>
33 #include "ICElibint.h"
47 IceErrorHeader (iceConn,
48 majorOpcode, offendingMinor,
49 iceConn->receive_sequence,
66 IceErrorHeader (iceConn,
67 majorOpcode, offendingMinor,
68 iceConn->receive_sequence,
85 IceErrorHeader (iceConn,
86 majorOpcode, offendingMinor,
87 iceConn->receive_sequence,
102 int length, /* in bytes */
106 IceErrorHeader (iceConn,
107 majorOpcode, offendingMinor,
108 iceConn->receive_sequence,
111 WORD64COUNT (8 + length));
113 IceWriteData32 (iceConn, 4, &offset);
114 IceWriteData32 (iceConn, 4, &length);
115 IceWriteData (iceConn, length, (char *) value);
118 IceWritePad (iceConn, PAD64 (length));
125 _IceErrorNoAuthentication (
130 int severity = (offendingMinor == ICE_ConnectionSetup) ?
131 IceFatalToConnection : IceFatalToProtocol;
133 IceErrorHeader (iceConn,
135 iceConn->receive_sequence,
150 int severity = (offendingMinor == ICE_ConnectionSetup) ?
151 IceFatalToConnection : IceFatalToProtocol;
153 IceErrorHeader (iceConn,
155 iceConn->receive_sequence,
165 _IceErrorSetupFailed (
173 int severity = (offendingMinor == ICE_ConnectionSetup) ?
174 IceFatalToConnection : IceFatalToProtocol;
178 bytes = STRING_BYTES (reason);
180 IceErrorHeader (iceConn,
182 iceConn->receive_sequence,
185 WORD64COUNT (bytes));
187 pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes));
188 STORE_STRING (pBuf, reason);
190 IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart);
196 _IceErrorAuthenticationRejected (
207 bytes = STRING_BYTES (reason);
209 IceErrorHeader (iceConn,
211 iceConn->receive_sequence,
214 WORD64COUNT (bytes));
216 pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes));
217 STORE_STRING (pBuf, reason);
219 IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart);
225 _IceErrorAuthenticationFailed (
236 bytes = STRING_BYTES (reason);
238 IceErrorHeader (iceConn,
240 iceConn->receive_sequence,
243 WORD64COUNT (bytes));
245 pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes));
246 STORE_STRING (pBuf, reason);
248 IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart);
254 _IceErrorProtocolDuplicate (
256 const char *protocolName
264 bytes = STRING_BYTES (protocolName);
266 IceErrorHeader (iceConn,
267 0, ICE_ProtocolSetup,
268 iceConn->receive_sequence,
270 IceProtocolDuplicate,
271 WORD64COUNT (bytes));
273 pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes));
274 STORE_STRING (pBuf, protocolName);
276 IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart);
282 _IceErrorMajorOpcodeDuplicate (
287 char mOp[8] = { (char) majorOpcode };
289 IceErrorHeader (iceConn,
290 0, ICE_ProtocolSetup,
291 iceConn->receive_sequence,
293 IceMajorOpcodeDuplicate,
296 IceWriteData (iceConn, 8, mOp);
302 _IceErrorUnknownProtocol (
304 const char *protocolName
312 bytes = STRING_BYTES (protocolName);
314 IceErrorHeader (iceConn,
315 0, ICE_ProtocolSetup,
316 iceConn->receive_sequence,
319 WORD64COUNT (bytes));
321 pBuf = pStart = IceAllocScratch (iceConn, PADDED_BYTES64 (bytes));
322 STORE_STRING (pBuf, protocolName);
324 IceWriteData (iceConn, PADDED_BYTES64 (bytes), pStart);
337 char maj[8] = { (char) offendingMajor };
339 IceErrorHeader (iceConn,
341 iceConn->receive_sequence,
346 IceWriteData (iceConn, 8, maj);
353 * Default error handler.
357 _IceDefaultErrorHandler (
360 int offendingMinorOpcode,
361 unsigned long offendingSequence,
369 char *pData = (char *) values;
371 switch (offendingMinorOpcode)
373 case ICE_ConnectionSetup:
374 str = "ConnectionSetup";
376 case ICE_AuthRequired:
377 str = "AuthRequired";
382 case ICE_AuthNextPhase:
383 str = "AuthNextPhase";
385 case ICE_ConnectionReply:
386 str = "ConnectionReply";
388 case ICE_ProtocolSetup:
389 str = "ProtocolSetup";
391 case ICE_ProtocolReply:
392 str = "ProtocolReply";
400 case ICE_WantToClose:
410 fprintf (stderr, "\n");
412 fprintf (stderr, "ICE error: Offending minor opcode = %d (%s)\n",
413 offendingMinorOpcode, str);
415 fprintf (stderr, " Offending sequence number = %lu\n",
436 str = "NoAuthentication";
444 case IceAuthRejected:
445 str = "AuthenticationRejected";
448 str = "AuthenticationFailed";
450 case IceProtocolDuplicate:
451 str = "ProtocolDuplicate";
453 case IceMajorOpcodeDuplicate:
454 str = "MajorOpcodeDuplicate";
456 case IceUnknownProtocol:
457 str = "UnknownProtocol";
463 fprintf (stderr, " Error class = %s\n", str);
465 if (severity == IceCanContinue)
467 else if (severity == IceFatalToProtocol)
468 str = "FatalToProtocol";
469 else if (severity == IceFatalToConnection)
470 str = "FatalToConnection";
474 fprintf (stderr, " Severity = %s\n", str);
480 int offset, length, val;
482 EXTRACT_CARD32 (pData, swap, offset);
483 EXTRACT_CARD32 (pData, swap, length);
486 " BadValue Offset = %d\n", offset);
488 " BadValue Length = %d\n", length);
494 else if (length == 2)
496 EXTRACT_CARD16 (pData, swap, val);
500 EXTRACT_CARD32 (pData, swap, val);
504 " BadValue = %d\n", val);
511 fprintf (stderr, "Major opcode : %d\n", (int) *pData);
516 EXTRACT_STRING (pData, swap, estr);
517 fprintf (stderr, "Reason : %s\n", estr);
521 case IceAuthRejected:
523 EXTRACT_STRING (pData, swap, estr);
524 fprintf (stderr, "Reason : %s\n", estr);
530 EXTRACT_STRING (pData, swap, estr);
531 fprintf (stderr, "Reason : %s\n", estr);
535 case IceProtocolDuplicate:
537 EXTRACT_STRING (pData, swap, estr);
538 fprintf (stderr, "Protocol name : %s\n", estr);
542 case IceMajorOpcodeDuplicate:
544 fprintf (stderr, "Major opcode : %d\n", (int) *pData);
547 case IceUnknownProtocol:
549 EXTRACT_STRING (pData, swap, estr);
550 fprintf (stderr, "Protocol name : %s\n", estr);
558 fprintf (stderr, "\n");
560 if (severity != IceCanContinue)
564 IceErrorHandler _IceErrorHandler = _IceDefaultErrorHandler;
568 * This procedure sets the ICE error handler to be the specified
569 * routine. If NULL is passed in the default error handler is restored.
570 * The function's return value is the previous error handler.
575 IceErrorHandler handler
578 IceErrorHandler oldHandler = _IceErrorHandler;
581 _IceErrorHandler = handler;
583 _IceErrorHandler = _IceDefaultErrorHandler;
591 * Default IO error handler.
595 _IceDefaultIOErrorHandler (
600 "ICE default IO error handler doing an exit(), pid = %ld, errno = %d\n",
601 (long)getpid(), errno);
606 IceIOErrorHandler _IceIOErrorHandler = _IceDefaultIOErrorHandler;
610 * This procedure sets the ICE fatal I/O error handler to be the
611 * specified routine. If NULL is passed in the default error
612 * handler is restored. The function's return value is the
613 * previous error handler.
617 IceSetIOErrorHandler (
618 IceIOErrorHandler handler
621 IceIOErrorHandler oldHandler = _IceIOErrorHandler;
624 _IceIOErrorHandler = handler;
626 _IceIOErrorHandler = _IceDefaultIOErrorHandler;