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 (
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 = (char) majorOpcode;
289 IceErrorHeader (iceConn,
290 0, ICE_ProtocolSetup,
291 iceConn->receive_sequence,
293 IceMajorOpcodeDuplicate,
296 IceWriteData (iceConn, 8, &mOp);
302 _IceErrorUnknownProtocol (
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 = (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,
368 char *pData = (char *) values;
370 switch (offendingMinorOpcode)
372 case ICE_ConnectionSetup:
373 str = "ConnectionSetup";
375 case ICE_AuthRequired:
376 str = "AuthRequired";
381 case ICE_AuthNextPhase:
382 str = "AuthNextPhase";
384 case ICE_ConnectionReply:
385 str = "ConnectionReply";
387 case ICE_ProtocolSetup:
388 str = "ProtocolSetup";
390 case ICE_ProtocolReply:
391 str = "ProtocolReply";
399 case ICE_WantToClose:
409 fprintf (stderr, "\n");
411 fprintf (stderr, "ICE error: Offending minor opcode = %d (%s)\n",
412 offendingMinorOpcode, str);
414 fprintf (stderr, " Offending sequence number = %lu\n",
435 str = "NoAuthentication";
443 case IceAuthRejected:
444 str = "AuthenticationRejected";
447 str = "AuthenticationFailed";
449 case IceProtocolDuplicate:
450 str = "ProtocolDuplicate";
452 case IceMajorOpcodeDuplicate:
453 str = "MajorOpcodeDuplicate";
455 case IceUnknownProtocol:
456 str = "UnknownProtocol";
462 fprintf (stderr, " Error class = %s\n", str);
464 if (severity == IceCanContinue)
466 else if (severity == IceFatalToProtocol)
467 str = "FatalToProtocol";
468 else if (severity == IceFatalToConnection)
469 str = "FatalToConnection";
473 fprintf (stderr, " Severity = %s\n", str);
479 int offset, length, val;
481 EXTRACT_CARD32 (pData, swap, offset);
482 EXTRACT_CARD32 (pData, swap, length);
485 " BadValue Offset = %d\n", offset);
487 " BadValue Length = %d\n", length);
493 else if (length == 2)
495 EXTRACT_CARD16 (pData, swap, val);
499 EXTRACT_CARD32 (pData, swap, val);
503 " BadValue = %d\n", val);
510 fprintf (stderr, "Major opcode : %d\n", (int) *pData);
515 EXTRACT_STRING (pData, swap, str);
516 fprintf (stderr, "Reason : %s\n", str);
520 case IceAuthRejected:
522 EXTRACT_STRING (pData, swap, str);
523 fprintf (stderr, "Reason : %s\n", str);
529 EXTRACT_STRING (pData, swap, str);
530 fprintf (stderr, "Reason : %s\n", str);
534 case IceProtocolDuplicate:
536 EXTRACT_STRING (pData, swap, str);
537 fprintf (stderr, "Protocol name : %s\n", str);
541 case IceMajorOpcodeDuplicate:
543 fprintf (stderr, "Major opcode : %d\n", (int) *pData);
546 case IceUnknownProtocol:
548 EXTRACT_STRING (pData, swap, str);
549 fprintf (stderr, "Protocol name : %s\n", str);
557 fprintf (stderr, "\n");
559 if (severity != IceCanContinue)
563 IceErrorHandler _IceErrorHandler = _IceDefaultErrorHandler;
567 * This procedure sets the ICE error handler to be the specified
568 * routine. If NULL is passed in the default error handler is restored.
569 * The function's return value is the previous error handler.
574 IceErrorHandler handler
577 IceErrorHandler oldHandler = _IceErrorHandler;
580 _IceErrorHandler = handler;
582 _IceErrorHandler = _IceDefaultErrorHandler;
590 * Default IO error handler.
594 _IceDefaultIOErrorHandler (
599 "ICE default IO error handler doing an exit(), pid = %ld, errno = %d\n",
600 (long)getpid(), errno);
605 IceIOErrorHandler _IceIOErrorHandler = _IceDefaultIOErrorHandler;
609 * This procedure sets the ICE fatal I/O error handler to be the
610 * specified routine. If NULL is passed in the default error
611 * handler is restored. The function's return value is the
612 * previous error handler.
616 IceSetIOErrorHandler (
617 IceIOErrorHandler handler
620 IceIOErrorHandler oldHandler = _IceIOErrorHandler;
623 _IceIOErrorHandler = handler;
625 _IceIOErrorHandler = _IceDefaultIOErrorHandler;