From 29e06caa578d1671c215340f358e7fcbd4b43f40 Mon Sep 17 00:00:00 2001 From: Richard Basch Date: Thu, 6 Feb 1997 02:13:14 +0000 Subject: [PATCH] New V2 API + Win16/Win32 support git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@9782 dc483132-0cff-0310-8789-dd5450dbe970 --- src/util/et/ChangeLog | 32 +++ src/util/et/Makefile.in | 46 ++++- src/util/et/com_err.c | 378 +++++++++++++++++++++--------------- src/util/et/com_err.h | 140 +++++++------ src/util/et/error_message.c | 173 ++++++++++------- src/util/et/error_table.h | 86 ++------ src/util/et/error_table.y | 1 + src/util/et/et_c.awk | 34 ++-- src/util/et/et_name.c | 64 +++--- src/util/et/init_et.c | 85 ++++++-- src/util/et/test_et.c | 1 + 11 files changed, 627 insertions(+), 413 deletions(-) diff --git a/src/util/et/ChangeLog b/src/util/et/ChangeLog index 227dc7caf..51441554b 100644 --- a/src/util/et/ChangeLog +++ b/src/util/et/ChangeLog @@ -1,3 +1,35 @@ +Tue Feb 4 15:59:01 1997 Richard Basch + + * Makefile.in com_err.h error_table.h et_c.awk error_message.c + Corrected various declarations for Windows build + +Wed Jan 29 17:32:23 1997 Theodore Ts'o + + * Makefile.in: Add rules to build test_et (for testing!) + + * com_err.h, error_table.h: Fixed up varargs/stdargs declarations + Move definition of struct error_table into com_err.h, and + define first draft of the V2 API. Removed the Windows + specific declarations from error_table.h, since it's now + safe to + + * com_err.c, error_message.c, init_et.c, et_name.c: Added new + V2 API's. Cleaned up C code. + + * test_et.c: Added new test case for error code 0 + + * et_c.awk: Added __far for Windows 16 pointer. + + * internal.h: File removed, no longer used. + + * error_table.y: Add #include the header file "com_err.h" + +Thu Nov 21 11:55:16 EST 1996 Richard Basch + + * Makefile.in: win32 build + * com_err.h error_table.h init_et.c internal.h + Win32 support + Mon Nov 18 20:37:19 1996 Ezra Peisach * configure.in: Set shared library version to 1.0. [krb5-libs/201] diff --git a/src/util/et/Makefile.in b/src/util/et/Makefile.in index 773fe66e2..2f3b1567a 100644 --- a/src/util/et/Makefile.in +++ b/src/util/et/Makefile.in @@ -3,6 +3,8 @@ SED = sed ##DOSBUILDTOP = ..\.. ##DOSLIBNAME=comerr.lib +##DOSXTRA= +##DOSOBJFILE=comerr.lst .c.o: $(CC) $(CFLAGS) -c $(srcdir)/$*.c @@ -14,7 +16,10 @@ INSTALLFILE = cp LINTFLAGS=-uhvb LINTFILES= error_message.c et_name.c init_et.c com_err.c -LIBOBJS= error_message.o et_name.o init_et.o com_err.o +LIBOBJS=com_err.$(OBJEXT) \ + error_message.$(OBJEXT) \ + et_name.$(OBJEXT) \ + init_et.$(OBJEXT) # for et_lex.lex.c include in error_table.y LOCALINCLUDE=-I. -I$(srcdir) @@ -29,6 +34,17 @@ FILES= Makefile et_name.c error_message.c compile_et.c \ # init_et.c com_err.c SRCS= error_message.c et_name.c init_et.c com_err.c +# +# Warning flags +# +# Uncomment WFLAGS if you want really anal GCC warning messages +# +# +WFLAGS= -ansi -D_POSIX_SOURCE -pedantic \ + -Wall -Wwrite-strings -Wpointer-arith \ + -Wcast-qual -Wcast-align -Wtraditional \ + -Wstrict-prototypes -Wmissing-prototypes \ + -Wnested-externs -Winline -DNO_INLINE_FUNCS -Wshadow DEPLIBS= SHLIB_LIBS= @@ -36,9 +52,14 @@ SHLIB_LDFLAGS= $(LDFLAGS) @SHLIB_RPATH_DIRS@ SHLIB_LIBDIRS= @SHLIB_LIBDIRS@ STEXT=@STEXT@ -all-windows: com_err.obj error_message.obj et_name.obj +all-windows:: $(OBJFILE) copy com_err.h $(BUILDTOP)\include +##DOS$(OBJFILE): $(LIBOBJS) +##DOS $(RM) $(OBJFILE) +##WIN16## $(CP) nul: $(OBJFILE) +##WIN32## $(LIBECHO) *.obj > $(OBJFILE) + # # what to build... # @@ -46,7 +67,26 @@ all-windows: com_err.obj error_message.obj et_name.obj # # rules # -error_table.o: et_lex.lex.c +error_table.c: et_lex.lex.c + +error_table.c: $(srcdir)/error_table.y + +error_table.o: error_table.c et_lex.lex.c + $(CC) $(CFLAGS) -c error_table.c + +et_lex.lex.o: et_lex.lex.c + $(CC) $(CFLAGS) -c et_lex.lex.c + +test1.o: test1.c + $(CC) $(CFLAGS) -c test1.c + +test2.o: test2.c + $(CC) $(CFLAGS) -c test2.c + +test_et.o: test1.h test2.h + +test_et: test_et.o test1.o test2.o $(LIBOBJS) + $(CC) -o test_et test_et.o test1.o test2.o $(LIBOBJS) # solaris make loses on com_err.c but not on init_et.c, but this helps com_err.o: com_err.c diff --git a/src/util/et/com_err.c b/src/util/et/com_err.c index e0e5baf89..c24e073df 100644 --- a/src/util/et/com_err.c +++ b/src/util/et/com_err.c @@ -1,108 +1,256 @@ /* - * Copyright 1987, 1988 by MIT Student Information Processing Board. + * Copyright 1997 by Massachusetts Institute of Technology + * + * Copyright 1987, 1988 by MIT Student Information Processing Board * - * For copyright info, see mit-sipb-copyright.h. + * Permission to use, copy, modify, and distribute this software + * and its documentation for any purpose and without fee is + * hereby granted, provided that the above copyright notice + * appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, + * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be + * used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * M.I.T. and the M.I.T. S.I.P.B. make no representations about + * the suitability of this software for any purpose. It is + * provided "as is" without express or implied warranty. */ #include #include -#include "mit-sipb-copyright.h" -#if defined(HAVE_STDARG_H) || defined(_MSDOS) || defined(_WIN32) || defined (_MACINTOSH) -#include -#else -#include -#define VARARGS -#endif +#include "com_err.h" +#include "error_table.h" #ifdef _MACINTOSH #include "icons.h" +static void MacMessageBox(errbuf); #endif -#include "error_table.h" -#include "internal.h" +#if !(defined(_MSDOS) || defined(_WIN32) || defined(_MACINTOSH)) + +static void default_com_err_proc +ET_P((et_ctx ectx, void FAR *priv, + const char FAR *whoami, errcode_t code, + const char FAR *fmt, va_list ap)); + +/* The version for Unix */ +static void default_com_err_proc(ectx, priv, whoami, code, fmt, ap) + et_ctx ectx; + void FAR *priv; + const char FAR *whoami; + errcode_t code; + const char FAR *fmt; + va_list ap; +{ + if (whoami) { + fputs(whoami, stderr); + fputs(": ", stderr); + } + if (code) { + fputs(error_message(code), stderr); + fputs(" ", stderr); + } + if (fmt) { + vfprintf(stderr, fmt, ap); + } + /* should do this only on a tty in raw mode */ + putc('\r', stderr); + putc('\n', stderr); + fflush(stderr); +} + +#else -#ifdef notdef /* - * Protect us from header version (externally visible) of com_err, so - * we can survive in a environment. I think. + * For Macintosh and Windows */ -#define com_err com_err_external -#include "com_err.h" -#undef com_err +void KRB5_CALLCONV default_com_err_proc +ET_P((et_ctx ectx, void FAR *priv, + const char FAR *whoami, errcode_t code, + const char FAR *fmt, va_list ap)); + +void KRB5_CALLCONV default_com_err_proc(ectx, priv, whoami, code, fmt, ap) + et_ctx ectx; + void FAR *priv; + const char FAR *whoami; + errcode_t code; + const char FAR *fmt; + va_list ap; +{ + static char errbuf[1024]; /* For those w/o stdio */ + + *errbuf = '\0'; + if (whoami) { + strcat (errbuf, whoami); + strcat (errbuf, ": "); + } + if (code) { + strcat (errbuf, error_message(code)); + strcat (errbuf, " "); + } + if (fmt) { + vsprintf (errbuf + strlen (errbuf), fmt, ap); + } +#ifdef _MACINTOSH + MacMessageBox(errbuf); +#else + /* For Windows */ + MessageBox ((HWND)NULL, errbuf, "Kerberos", MB_ICONEXCLAMATION); +#endif +} +#endif + +et_old_error_hook_func com_err_hook = 0; + +void et_com_err_va(ectx, priv, whoami, code, fmt, ap) + et_ctx ectx; + void FAR *priv; + const char FAR *whoami; + errcode_t code; + const char FAR *fmt; + va_list ap; +{ + if (ectx) { + if (ectx->hook_func == 0) + ectx->hook_func = default_com_err_proc; + (*ectx->hook_func)(ectx, priv, whoami, code, fmt, ap); + } else { + if (!com_err_hook) + default_com_err_proc(0, 0, whoami, + code, fmt, ap); + else + (*com_err_hook)(whoami, code, fmt, ap); + } +} + +#ifndef ET_VARARGS +KRB5_DLLIMP void KRB5_CALLCONV_C et_com_err(et_ctx ectx, + void FAR *priv, + const char FAR *whoami, + errcode_t code, + const char FAR *fmt, ...) +#else +KRB5_DLLIMP void KRB5_CALLCONV_C et_com_err(ectx, priv, whoami, + code, fmt, va_alist) + et_ctx ectx; + void FAR *priv; + const char FAR *whoami; + errcode_t code; + const char FAR *fmt; + va_dcl +#endif +{ + va_list ap; + +#ifdef ET_VARARGS + va_start(ap); +#else + va_start(ap, fmt); #endif + et_com_err_va(ectx, priv, whoami, code, fmt, ap); + va_end(ap); +} -/* We have problems with varargs definitions if we include com_err.h */ /* - * XXX for now, we define error_message by hand. Ultimately, we - * should fix up com_err.h so that it's safe to #include here - * directly. + * The following are the old-style com_err interfaces.... */ -#if defined(__STDC__) || defined(_MSDOS) || defined(_WIN32) -KRB5_DLLIMP extern char const FAR * KRB5_CALLCONV error_message (long); +#ifndef ET_VARARGS +KRB5_DLLIMP void KRB5_CALLCONV_C com_err(const char FAR *whoami, + errcode_t code, + const char FAR *fmt, ...) #else -extern char * error_message (); +KRB5_DLLIMP void KRB5_CALLCONV_C et_com_err(whoami, code, fmt, va_alist) + const char FAR *whoami; + errcode_t code; + const char FAR *fmt; + va_dcl #endif +{ + va_list ap; -static void -#if defined(__STDC__) || defined(_MSDOS) || defined(_WIN32) - default_com_err_proc (const char *whoami, long code, const char *fmt, va_list args) +#ifdef ET_VARARGS + va_start(ap); #else - default_com_err_proc (whoami, code, fmt, args) - const char *whoami; - long code; - const char *fmt; - va_list args; + va_start(ap, fmt); #endif + et_com_err_va(0, 0, whoami, code, fmt, ap); + va_end(ap); +} + +KRB5_DLLIMP et_old_error_hook_func KRB5_CALLCONV set_com_err_hook (new_proc) + et_old_error_hook_func new_proc; { - static char errbuf[1024]; /* For those w/o stdio */ - - *errbuf = '\0'; - if (whoami) { - strcat (errbuf, whoami); - strcat (errbuf, ": "); - } - if (code) { - strcat (errbuf, error_message(code)); - strcat (errbuf, " "); - } - if (fmt) { - vsprintf (errbuf + strlen (errbuf), fmt, args); - } -#if defined(_MSDOS) || defined(_WIN32) - MessageBox (NULL, errbuf, "Kerboros", MB_ICONEXCLAMATION); -#else + et_old_error_hook_func x = com_err_hook; + + com_err_hook = new_proc; + return x; +} + +KRB5_DLLIMP et_old_error_hook_func KRB5_CALLCONV reset_com_err_hook () +{ + et_old_error_hook_func x = com_err_hook; + + com_err_hook = 0; + return x; +} + +KRB5_DLLIMP errcode_t KRB5_CALLCONV et_set_hook(ectx, new, old) + et_ctx ectx; + struct et_hook FAR *new; + struct et_hook FAR *old; +{ + if (old) { + old->func = ectx->hook_func; + old->data = ectx->hook_func_data; + } + if (new) { + ectx->hook_func = new->func; + ectx->hook_func_data = new->data; + } else { + ectx->hook_func = 0; + ectx->hook_func_data = 0; + } + return 0; +} + #ifdef _MACINTOSH +static void MacMessageBox(errbuf) + char *errbuf; { -WindowPtr errWindow; -ControlHandle errOkButton; -Rect errOkButtonRect = { 120, 220, 140, 280 }; -Rect errRect = { 0, 0, 150, 300 }; -GDHandle mainDevice = GetMainDevice(); -Rect mainRect = (**mainDevice).gdRect; -Rect tmpRect; -Rect errTextRect = { 10, 70, 110, 290 }; -Rect errIconRect = { 10, 10, 10 + 32, 10 + 32 }; -EventRecord theEvent; -Point localPt; -Boolean done; + WindowPtr errWindow; + ControlHandle errOkButton; + Rect errOkButtonRect = { 120, 220, 140, 280 }; + Rect errRect = { 0, 0, 150, 300 }; + GDHandle mainDevice = GetMainDevice(); + Rect mainRect = (**mainDevice).gdRect; + Rect tmpRect; + Rect errTextRect = { 10, 70, 110, 290 }; + Rect errIconRect = { 10, 10, 10 + 32, 10 + 32 }; + EventRecord theEvent; + Point localPt; + Boolean done; /* Find Centered rect for window */ - tmpRect.top = (mainRect.bottom + mainRect.top)/2 - (errRect.bottom + errRect.top)/2; + tmpRect.top = ((mainRect.bottom + mainRect.top)/2 - + (errRect.bottom + errRect.top)/2); tmpRect.bottom = tmpRect.top + (errRect.bottom - errRect.top); - tmpRect.left = (mainRect.right + mainRect.left)/2 - (errRect.right + errRect.left)/2; + tmpRect.left = ((mainRect.right + mainRect.left)/2 - + (errRect.right + errRect.left)/2); tmpRect.right = tmpRect.left + (errRect.right - errRect.left); /* Create the error window - as a dialog window */ - errWindow = NewWindow(NULL, &tmpRect, "\p", TRUE, dBoxProc, (WindowPtr) -1, FALSE, 0L); + errWindow = NewWindow(NULL, &tmpRect, "\p", TRUE, + dBoxProc, (WindowPtr) -1, FALSE, 0L); SetPort(errWindow); TextFont(systemFont); TextSize(12); - errOkButton = NewControl(errWindow,&errOkButtonRect,"\pOk",TRUE,0,0,1,pushButProc,0L); - DrawControls(errWindow); + errOkButton = NewControl(errWindow, &errOkButtonRect, + "\pOk", TRUE, 0, 0, 1, pushButProc, 0L); + DrawControls(errWindow); InsetRect(&errOkButtonRect, -4, -4); PenSize(3,3); FrameRoundRect(&errOkButtonRect, 15,15); @@ -117,27 +265,25 @@ Boolean done; /* mini event loop here */ done = FALSE; - while(!done) - { + while(!done) { GetNextEvent(mDownMask | mUpMask | keyDownMask, &theEvent); - if (theEvent.what == mouseDown) - { + if (theEvent.what == mouseDown) { localPt = theEvent.where; GlobalToLocal(&localPt); - if (TestControl(errOkButton, localPt) && TrackControl(errOkButton, localPt, NULL)) - { + if (TestControl(errOkButton, localPt) && + TrackControl(errOkButton, localPt, NULL)) { done = TRUE; } } else if (theEvent.what == keyDown && - (theEvent.message & 0xff) == 0x0d || /* CR */ - (theEvent.message & 0xff) == 0x03 || /* Enter */ - (theEvent.message & 0xff) == 0x1b /* Escape */ - ) - { - long t; - HiliteControl(errOkButton, 1); // Hilite the button for a bit + (theEvent.message & 0xff) == 0x0d || /* CR */ + (theEvent.message & 0xff) == 0x03 || /* Enter */ + (theEvent.message & 0xff) == 0x1b) { /* Escape */ + long t; + /* Hilite the button for a bit */ + HiliteControl(errOkButton, 1); Delay(5, &t); - HiliteControl(errOkButton, 0); // Dehilite the button + /* Dehilite the button */ + HiliteControl(errOkButton, 0); done = TRUE; } } @@ -145,76 +291,4 @@ Boolean done; /* Dispose of the Window, disposes of controls */ DisposeWindow(errWindow); } -#else - fputs (errbuf, stderr); - /* should do this only on a tty in raw mode */ - putc('\r', stderr); - putc('\n', stderr); - fflush(stderr); -#endif -#endif -} - -#if defined(__STDC__) || defined(_MSDOS) || defined(_WIN32) -typedef void (*errf) (const char *, long, const char *, va_list); -#else -typedef void (*errf) (); -#endif - -errf com_err_hook = default_com_err_proc; - -void com_err_va (whoami, code, fmt, args) - const char *whoami; - long code; - const char *fmt; - va_list args; -{ - (*com_err_hook) (whoami, code, fmt, args); -} - -#ifndef VARARGS -KRB5_DLLIMP void KRB5_CALLCONV_C com_err (const char *whoami, - long code, - const char *fmt, ...) -{ -#else -KRB5_DLLIMP void KRB5_CALLCONV_C com_err (va_alist) - va_dcl -{ - const char *whoami, *fmt; - long code; -#endif - va_list pvar; - - if (!com_err_hook) - com_err_hook = default_com_err_proc; -#ifdef VARARGS - va_start (pvar); - whoami = va_arg (pvar, const char *); - code = va_arg (pvar, long); - fmt = va_arg (pvar, const char *); -#else - va_start(pvar, fmt); #endif - com_err_va (whoami, code, fmt, pvar); - va_end(pvar); -} - -errf set_com_err_hook (new_proc) - errf new_proc; -{ - errf x = com_err_hook; - - if (new_proc) - com_err_hook = new_proc; - else - com_err_hook = default_com_err_proc; - - return x; -} - -errf reset_com_err_hook () { - errf x = com_err_hook; - com_err_hook = default_com_err_proc; - return x; -} diff --git a/src/util/et/com_err.h b/src/util/et/com_err.h index 5d6db0725..225d1c2fb 100644 --- a/src/util/et/com_err.h +++ b/src/util/et/com_err.h @@ -12,87 +12,103 @@ #ifndef __COM_ERR_H -#ifndef HAVE_STDARG_H -/* End-user programs may need this -- oh well */ -#if defined(__STDC__) || defined(_WINDOWS) || defined(_MACINTOSH) -#define HAVE_STDARG_H 1 -#endif -#endif - -#ifdef HAVE_STDARG_H -#include -#else -#include -#endif - /* This should be part of k5-config.h but many application * programs are not including that file. We probably want to * come up with a better way of handling this problem. */ #if defined(_MSDOS) || defined (_WIN32) -#ifdef _MSDOS - /* Windows 16 specific */ -#ifndef KRB5_CALLCONV -#define KRB5_CALLCONV __far __export __pascal -#define KRB5_CALLCONV_C __far __export __cdecl -#define KRB5_DLLIMP -#define INTERFACE KRB5_CALLCONV -#define INTERFACE_C KRB5_CALLCONV_C -#endif /* !KRB5_CALLCONV */ -#ifndef FAR -#define FAR __far -#define NEAR __near -#endif -#else - /* Windows 32 specific */ -#ifndef KRB5_CALLCONV -#ifdef KRB5_DLL_FILE -#define KRB5_DECLSPEC dllexport -#else -#define KRB5_DECLSPEC dllimport +#include #endif -#define KRB5_DLLIMP __declspec(KRB5_DECLSPEC) -#define KRB5_CALLCONV __stdcall -#define KRB5_CALLCONV_C __cdecl -#define INTERFACE KRB5_DLLIMP KRB5_CALLCONV -#define INTERFACE_C KRB5_DLLIMP KRB5_CALLCONV_C -#endif /* !KRB5_CALLCONV */ - -#include - -#endif /* Win 16 vs Win 32 */ -#else /* Windows stuff */ + #ifndef KRB5_CALLCONV #define KRB5_CALLCONV #define KRB5_CALLCONV_C #define KRB5_DLLIMP -#define INTERFACE -#define INTERFACE_C +#define KRB5_EXPORTVAR #endif -#endif /* Windows stuff */ #ifndef FAR #define FAR #define NEAR #endif -#if defined(__STDC__) || defined(_MSDOS) || defined(_WIN32) -/* ANSI C -- use prototypes etc */ -KRB5_DLLIMP extern void KRB5_CALLCONV_C com_err - (const char FAR *, long, const char FAR *, ...); -KRB5_DLLIMP extern const char FAR * KRB5_CALLCONV error_message (long); -extern void (*com_err_hook) (const char *, long, const char *, va_list); -extern void (*set_com_err_hook (void (*) (const char *, long, const char *, va_list))) - (const char *, long, const char *, va_list); -extern void (*reset_com_err_hook ()) (const char *, long, const char *, va_list); +#if defined(__STDC__) || defined(_MSDOS) || defined(_WIN32) || defined(_MACINTOSH) + +/* End-user programs may need this -- oh well */ +#ifndef HAVE_STDARG_H +#define HAVE_STDARG_H 1 +#endif + +#define ET_P(x) x + #else -/* no prototypes */ -extern void com_err (); -extern const char * error_message (); -extern void (*com_err_hook) (); -extern void (*set_com_err_hook ()) (); -extern void (*reset_com_err_hook ()) (); +#define ET_P(x) () +#endif /* __STDC__ */ + +#ifdef HAVE_STDARG_H +#include +#define ET_STDARG_P(x) x +#else +#include +#define ET_STDARG_P(x) () +#define ET_VARARGS #endif +typedef long errcode_t; + +typedef void (*et_old_error_hook_func) ET_P((const char FAR *, errcode_t, + const char FAR *, va_list ap)); + +KRB5_DLLIMP extern void KRB5_CALLCONV_C com_err + ET_STDARG_P((const char FAR *, errcode_t, const char FAR *, ...)); + +KRB5_DLLIMP extern const char FAR * KRB5_CALLCONV error_message + ET_P((errcode_t)); + +KRB5_DLLIMP extern et_old_error_hook_func KRB5_EXPORTVAR com_err_hook; +KRB5_DLLIMP extern et_old_error_hook_func KRB5_CALLCONV set_com_err_hook + ET_P((et_old_error_hook_func)); +KRB5_DLLIMP extern et_old_error_hook_func KRB5_CALLCONV reset_com_err_hook + ET_P((void)); + +/* + * The the new com_err API... + */ +typedef struct et_context FAR *et_ctx; +typedef void (KRB5_CALLCONV *et_error_hook_func) + ET_P((et_ctx, void FAR *, const char FAR *, errcode_t, + const char FAR *, va_list ap)); + +struct error_table { + char const FAR * const FAR * msgs; + long base; + int n_msgs; +}; + +struct et_hook { + et_error_hook_func func; + void FAR *data; +}; + +KRB5_DLLIMP extern errcode_t KRB5_CALLCONV et_init ET_P((et_ctx FAR *)); +KRB5_DLLIMP extern void KRB5_CALLCONV et_shutdown ET_P((et_ctx)); + +KRB5_DLLIMP extern errcode_t KRB5_CALLCONV et_add_error_table + ET_P((et_ctx, struct error_table FAR *)); + +KRB5_DLLIMP extern const char FAR * KRB5_CALLCONV et_error_message + ET_P((et_ctx, errcode_t)); + +KRB5_DLLIMP extern void KRB5_CALLCONV_C et_com_err + ET_STDARG_P((et_ctx, void FAR *, const char FAR *, errcode_t, + const char FAR *, ...)); + +KRB5_DLLIMP extern void KRB5_CALLCONV_C et_com_err_va + ET_STDARG_P((et_ctx, void FAR *, const char FAR *, errcode_t, + const char FAR *, va_list ap)); + +KRB5_DLLIMP errcode_t KRB5_CALLCONV et_set_hook + ET_P((et_ctx, struct et_hook FAR *, struct et_hook FAR *)); + #define __COM_ERR_H #endif /* ! defined(__COM_ERR_H) */ diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c index b14254827..30424a8b6 100644 --- a/src/util/et/error_message.c +++ b/src/util/et/error_message.c @@ -1,10 +1,19 @@ /* - * util/et/error_message.c + * Copyright 1997 by Massachusetts Institute of Technology + * + * Copyright 1987, 1988 by MIT Student Information Processing Board * - * Copyright 1987 by the Student Information Processing Board - * of the Massachusetts Institute of Technology - * - * For copyright info, see "mit-sipb-copyright.h". + * Permission to use, copy, modify, and distribute this software + * and its documentation for any purpose and without fee is + * hereby granted, provided that the above copyright notice + * appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, + * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be + * used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * M.I.T. and the M.I.T. S.I.P.B. make no representations about + * the suitability of this software for any purpose. It is + * provided "as is" without express or implied warranty. */ #include @@ -14,94 +23,112 @@ #include #include "com_err.h" #include "error_table.h" -#include "mit-sipb-copyright.h" -#include "internal.h" + +#if defined(_MSDOS) || defined(_WIN32) +#define HAVE_STRERROR +#endif #ifdef _MACINTOSH #define sys_nerr 100 #endif -static const char copyright[] = - "Copyright 1986, 1987, 1988 by the Student Information Processing Board\nand the department of Information Systems\nof the Massachusetts Institute of Technology"; +#if !defined(HAVE_STRERROR) && !defined(SYS_ERRLIST_DECLARED) +extern char const * const sys_errlist[]; +extern const int sys_nerr; +#endif -static char buffer[25]; +static char buffer[ET_EBUFSIZ]; -struct et_list * _et_list = (struct et_list *) NULL; +KRB5_DLLIMP struct et_list KRB5_EXPORTVAR * _et_list = (struct et_list *) NULL; -KRB5_DLLIMP const char * KRB5_CALLCONV error_message (code) -long code; +KRB5_DLLIMP const char FAR * KRB5_CALLCONV et_error_message(ectx, code) + et_ctx ectx; + long code; { - int offset; - long l_offset; - struct et_list *et; - long table_num; - int started = 0; - char *cp; + int offset; + long l_offset; + struct et_list *et; + long table_num; + int started = 0; + char *cp; #if defined(_MSDOS) || defined(_WIN32) -#define HAVE_STRERROR 1 -/* -** Winsock defines errors in the range 10000-10100. These are equivalent -** to 10000 plus the Berkeley error numbers. -* -* (Does windows strerror() work right here?) -* -* XXX NO. We need to do our own table lookup for Winsock error -* messages!!! --- TYT -* -*/ - if (code >= 10000 && code <= 10100) /* Is it Winsock error? */ - code -= 10000; /* Turn into Berkeley errno */ + /* + * Winsock defines errors in the range 10000-10100. These are + * equivalent to 10000 plus the Berkeley error numbers. + * + * (Does windows strerror() work right here?) + * + * XXX NO. We need to do our own table lookup for Winsock error + * messages!!! --- TYT + * + */ + if (code >= 10000 && code <= 10100) /* Is it Winsock error? */ + code -= 10000; /* Turn into Berkeley errno */ #endif - l_offset = code & ((1<next) { - /* This is to work around a bug in the compiler on the Alpha - comparing longs */ - if (((int) (et->table->base - table_num)) == 0) { - /* This is the right table */ - if (et->table->n_msgs <= offset) - goto oops; - return(et->table->msgs[offset]); } - } + et = ectx ? ectx->tables : _et_list; + while (et) { + /* This is to work around a bug in the compiler on the Alpha + comparing longs */ + if (((int) (et->table->base - table_num)) == 0) { + /* This is the right table */ + if (et->table->n_msgs <= offset) + break; + return(et->table->msgs[offset]); + } + et = et->next; + } oops: - strcpy (buffer, "Unknown code "); - if (table_num) { - strcat (buffer, error_table_name (table_num)); - strcat (buffer, " "); - } - for (cp = buffer; *cp; cp++) - ; - if (offset >= 100) { - *cp++ = '0' + offset / 100; - offset %= 100; - started++; - } - if (started || offset >= 10) { - *cp++ = '0' + offset / 10; - offset %= 10; - } - *cp++ = '0' + offset; - *cp = '\0'; - return(buffer); + cp = ectx ? ectx->error_buf : buffer; + strcpy(cp, "Unknown code "); + cp += sizeof("Unknown code ") - 1; + if (table_num) { + error_table_name_r(table_num, cp); + while (*cp) + cp++; + *cp++ = ' '; + } + if (offset >= 100) { + *cp++ = '0' + offset / 100; + offset %= 100; + started++; + } + if (started || offset >= 10) { + *cp++ = '0' + offset / 10; + offset %= 10; + } + *cp++ = '0' + offset; + *cp = '\0'; + return(buffer); } + +KRB5_DLLIMP const char FAR * KRB5_CALLCONV error_message(code) + errcode_t code; +{ + return et_error_message(0, code); +} + diff --git a/src/util/et/error_table.h b/src/util/et/error_table.h index 1f107463d..179fe5727 100644 --- a/src/util/et/error_table.h +++ b/src/util/et/error_table.h @@ -7,87 +7,29 @@ #ifndef _ET_H -/* This directory doesn't really know about the krb5 world. The following - windows defines are usually hidden in k5-config.h. For now I'll just - place here what is needed from that file. Later we may decide to do - it differently. -*/ -#if defined(_MSDOS) || defined(_WIN32) -#ifdef _MSDOS - /* Windows 16 specific */ -#ifndef KRB5_CALLCONV -#define KRB5_CALLCONV __far __export __pascal -#define KRB5_CALLCONV_C __far __export __cdecl -#define KRB5_DLLIMP -#define INTERFACE KRB5_CALLCONV -#define INTERFACE_C KRB5_CALLCONV_C -#endif - -#ifndef FAR -#define FAR __far -#define NEAR __near -#endif -#else - /* Windows 32 specific */ -#ifdef KRB5_DLL_FILE -#define KRB5_DECLSPEC dllexport -#else -#define KRB5_DECLSPEC dllimport -#endif - -#define KRB5_DLLIMP __declspec(KRB5_DECLSPEC) -#define KRB5_CALLCONV __stdcall -#define KRB5_CALLCONV_C __cdecl -#define INTERFACE KRB5_DLLIMP KRB5_CALLCONV -#define INTERFACE_C KRB5_DLLIMP KRB5_CALLCONV_C - -#ifndef FAR -#define FAR -#define NEAR -#endif - -#endif /* Win16 vs Win32 */ - -#define sys_nerr _sys_nerr -#define sys_errlist _sys_errlist -int FAR KRB5_CALLCONV MessageBox (void FAR *, const char FAR*, const char FAR*, unsigned int); -#define MB_ICONEXCLAMATION 0x0030 -#else -#ifndef KRB5_CALLCONV -#define KRB5_CALLCONV -#define KRB5_CALLCONV_C -#define KRB5_DLLIMP -#define INTERFACE -#define INTERFACE_C -#endif /* KRB5_CALLCONV */ -#endif - -#ifndef FAR -#define FAR -#define NEAR -#endif - #include -struct error_table { - char const * const * msgs; - long base; - int n_msgs; +#define ET_EBUFSIZ 32 + +struct et_context { + struct et_list FAR *tables; + et_error_hook_func hook_func; + void FAR *hook_func_data; + char error_buf[ET_EBUFSIZ]; }; + struct et_list { - struct et_list *next; - const struct error_table *table; + struct et_list FAR *next; + const struct error_table FAR *table; }; -extern struct et_list * _et_list; + +extern KRB5_DLLIMP struct et_list KRB5_EXPORTVAR * _et_list; #define ERRCODE_RANGE 8 /* # of bits to shift table number */ #define BITS_PER_CHAR 6 /* # bits to shift per character in name */ -#if (defined(__STDC__) || defined(_WINDOWS)) && !defined(KRB5_NO_PROTOTYPES) -extern const char *error_table_name (long); -#else -extern const char *error_table_name (); -#endif +extern const char FAR *error_table_name ET_P((long)); +extern const char FAR *error_table_name_r ET_P((long, char FAR *)); #define _ET_H #endif diff --git a/src/util/et/error_table.y b/src/util/et/error_table.y index ad4ffb1ec..f6b082fd4 100644 --- a/src/util/et/error_table.y +++ b/src/util/et/error_table.y @@ -70,6 +70,7 @@ description : QUOTED_STRING #include #include #include +#include "com_err.h" #include "internal.h" #include "error_table.h" #include "mit-sipb-copyright.h" diff --git a/src/util/et/et_c.awk b/src/util/et/et_c.awk index ed8c45a26..3d5472736 100644 --- a/src/util/et/et_c.awk +++ b/src/util/et/et_c.awk @@ -109,6 +109,20 @@ c2n["_"]=63 print " * This file is automatically generated; please do not edit it." > outfile print " */" > outfile + print "#if defined(_MSDOS) || defined(_WIN32)" > outfile + print "#include \"win-mac.h\"" > outfile + print "#else" > outfile + print "# ifndef KRB5_CALLCONV" > outfile + print "# define KRB5_CALLCONV" > outfile + print "# define KRB5_CALLCONV_C" > outfile + print "# define KRB5_DLLIMP" > outfile + print "# define KRB5_EXPORTVAR" > outfile + print "# define FAR" > outfile + print "# define NEAR" > outfile + print "# endif" > outfile + print "#endif" > outfile + print "" > outfile + print "#if defined(__STDC__) || defined(_MSDOS) || defined(_WIN32)" > outfile print "#define NOARGS void" > outfile print "#else" > outfile @@ -116,7 +130,7 @@ c2n["_"]=63 print "#define const" > outfile print "#endif" > outfile print "" > outfile - print "static const char * const text[] = {" > outfile + print "static const char FAR * const text[] = {" > outfile table_item_count = 0 } @@ -176,28 +190,26 @@ c2n["_"]=63 skipone=0 } END { - - print " 0" > outfile print "};" > outfile print "" > outfile print "struct error_table {" > outfile - print " char const * const * msgs;" > outfile + print " char const FAR * const FAR * msgs;" > outfile print " long base;" > outfile print " int n_msgs;" > outfile print "};" > outfile print "struct et_list {" > outfile - print " struct et_list *next;" > outfile - print " const struct error_table * table;" > outfile + print " struct et_list FAR *next;" > outfile + print " const struct error_table FAR *table;" > outfile print "};" > outfile - print "extern struct et_list *_et_list;" > outfile + print "extern KRB5_DLLIMP struct et_list KRB5_EXPORTVAR *_et_list;" > outfile print "" > outfile if (tab_base_high == 0) { - print "static const struct error_table et = { text, " \ + print "const struct error_table et_" table_name "_error_table = { text, " \ sprintf("%dL, %d };", tab_base_sign*tab_base_low, \ table_item_count) > outfile } else { - print "static const struct error_table et = { text, " \ + print "const struct error_table et_" table_name "_error_table = { text, " \ sprintf("%d%06dL, %d };", tab_base_sign*tab_base_high, \ tab_base_low, table_item_count) > outfile } @@ -207,10 +219,8 @@ END { print "void initialize_" table_name "_error_table (NOARGS) {" > outfile print " if (!link.table) {" > outfile print " link.next = _et_list;" > outfile - print " link.table = &et;" > outfile + print " link.table = &et_" table_name "_error_table ;" > outfile print " _et_list = &link;" > outfile print " }" > outfile print "}" > outfile - - } diff --git a/src/util/et/et_name.c b/src/util/et/et_name.c index a46267643..6b1c869f8 100644 --- a/src/util/et/et_name.c +++ b/src/util/et/et_name.c @@ -1,41 +1,51 @@ /* + * Copyright 1997 by Massachusetts Institute of Technology + * * Copyright 1987 by MIT Student Information Processing Board * - * For copyright info, see mit-sipb-copyright.h. + * Permission to use, copy, modify, and distribute this software + * and its documentation for any purpose and without fee is + * hereby granted, provided that the above copyright notice + * appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, + * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be + * used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * M.I.T. and the M.I.T. S.I.P.B. make no representations about + * the suitability of this software for any purpose. It is + * provided "as is" without express or implied warranty. */ +#include "com_err.h" #include "error_table.h" -#include "mit-sipb-copyright.h" -#include "internal.h" - -#ifndef lint -static const char copyright[] = - "Copyright 1987,1988 by Student Information Processing Board, Massachusetts Institute of Technology"; -#endif static const char char_set[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"; -static char buf[6]; +const char * error_table_name_r(num, out) + long num; + char FAR *out; +{ + long ch; + int i; + char *p; + + p = out; + num >>= ERRCODE_RANGE; + + for (i = 3; i >= 0; i--) { + ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1); + if (ch != 0) + *p++ = char_set[ch-1]; + } + *p = '\0'; + return(out); +} -const char * error_table_name (num) - long num; +const char FAR * error_table_name(num) + long num; { - long ch; - int i; - char *p; + static char buf[6]; - /* num = aa aaa abb bbb bcc ccc cdd ddd d?? ??? ??? */ - p = buf; - num >>= ERRCODE_RANGE; - /* num = ?? ??? ??? aaa aaa bbb bbb ccc ccc ddd ddd */ - num &= 077777777; - /* num = 00 000 000 aaa aaa bbb bbb ccc ccc ddd ddd */ - for (i = 4; i >= 0; i--) { - ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1); - if (ch != 0) - *p++ = char_set[ch-1]; - } - *p = '\0'; - return(buf); + return error_table_name_r(num, buf); } diff --git a/src/util/et/init_et.c b/src/util/et/init_et.c index f52facade..0e5d89a54 100644 --- a/src/util/et/init_et.c +++ b/src/util/et/init_et.c @@ -1,31 +1,43 @@ /* - * util/et/init_et.c + * Copyright 1997 by Massachusetts Institute of Technology + * + * Copyright 1986, 1987, 1988 by MIT Student Information Processing Board * - * Copyright 1986, 1987, 1988 by MIT Information Systems and - * the MIT Student Information Processing Board. - * - * For copyright info, see mit-sipb-copyright.h. + * Permission to use, copy, modify, and distribute this software + * and its documentation for any purpose and without fee is + * hereby granted, provided that the above copyright notice + * appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, + * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be + * used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. + * M.I.T. and the M.I.T. S.I.P.B. make no representations about + * the suitability of this software for any purpose. It is + * provided "as is" without express or implied warranty. */ #include +#include +#include "com_err.h" #include "error_table.h" -#include "mit-sipb-copyright.h" - -extern char *malloc(), *realloc(); +#if 0 +/* + * XXX This function is provided without any prototypes in the public + * interface, and isn't used internally. It's probably safe to make + * it go away. + */ struct foobar { struct et_list etl; struct error_table et; }; -extern struct et_list * _et_list; - int init_error_table(msgs, base, count) - const char * const * msgs; + const char FAR * const FAR * msgs; int base; int count; { - struct foobar * new_et; + struct foobar FAR * new_et; if (!base || !count || !msgs) return 0; @@ -42,3 +54,52 @@ int init_error_table(msgs, base, count) _et_list = &new_et->etl; return 0; } +#endif + +KRB5_DLLIMP extern errcode_t KRB5_CALLCONV et_init(ectx) + et_ctx FAR *ectx; +{ + struct et_context FAR *ctx; + + ctx = malloc(sizeof(struct et_context)); + if (!ctx) + return ENOMEM; + ctx->tables = 0; + ctx->hook_func = 0; + ctx->hook_func_data = 0; + + *ectx = ctx; + return 0; +} + +KRB5_DLLIMP extern void KRB5_CALLCONV et_shutdown(ectx) + et_ctx ectx; +{ + struct et_list FAR *p, FAR *n; + + p = ectx->tables; + while (p) { + n = p->next; + free(p); + p = n; + } + free(ectx); +} + +KRB5_DLLIMP extern errcode_t KRB5_CALLCONV et_add_error_table(ectx, tbl) + et_ctx ectx; + struct error_table FAR *tbl; +{ + struct et_list FAR *link; + + link = malloc(sizeof(struct et_list)); + if (!link) + return ENOMEM; + + link->table = tbl; + link->next = ectx->tables; + ectx->tables = link; + + return 0; +} + diff --git a/src/util/et/test_et.c b/src/util/et/test_et.c index 955cb964a..ff638a24c 100644 --- a/src/util/et/test_et.c +++ b/src/util/et/test_et.c @@ -16,6 +16,7 @@ main() printf("Msg FOO_ERR is '%s'\n", error_message(FOO_ERR)); printf("Msg {sys_nerr-1} is '%s'\n", error_message(sys_nerr-1)); printf("Msg {sys_nerr} is '%s'\n", error_message(sys_nerr)); + printf("Msg 0 is '%s'\n", error_message(0)); printf("With 0: tgt-expired -> %s\n", error_message(KRB_MK_AP_TGTEXP)); -- 2.26.2