1/*
2 * Copyright 1990 Network Computing Devices;
3 * Portions Copyright 1987 by Digital Equipment Corporation
4 *
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without fee,
7 * provided that the above copyright notice appear in all copies and
8 * that both that copyright notice and this permission notice appear
9 * in supporting documentation, and that the names of Network Computing
10 * Devices or Digital not be used in advertising or publicity pertaining
11 * to distribution of the software without specific, written prior
12 * permission. Network Computing Devices or Digital make no representations
13 * about the suitability of this software for any purpose.  It is provided
14 * "as is" without express or implied warranty.
15 *
16 * NETWORK COMPUTING DEVICES AND  DIGITAL DISCLAIM ALL WARRANTIES WITH
17 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES
19 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
20 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23 * SOFTWARE.
24 */
25
26/*
27
28Copyright 1987, 1994, 1998  The Open Group
29
30Permission to use, copy, modify, distribute, and sell this software and its
31documentation for any purpose is hereby granted without fee, provided that
32the above copyright notice appear in all copies and that both that
33copyright notice and this permission notice appear in supporting
34documentation.
35
36The above copyright notice and this permission notice shall be included in
37all copies or substantial portions of the Software.
38
39THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
42OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
43AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
44CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
45
46Except as contained in this notice, the name of The Open Group shall not be
47used in advertising or otherwise to promote the sale, use or other dealings
48in this Software without prior written authorization from The Open Group.
49
50*/
51
52#ifdef HAVE_CONFIG_H
53#include <config.h>
54#endif
55#include <stdio.h>
56#include "FSlibint.h"
57#include <X11/Xos.h>
58
59static const char *FSErrorList[] = {
60     /* FSBadRequest	 */ "BadRequest, invalid request code or no such operation",
61     /* FSBadFormat	 */ "BadFormat, bad font format mask",
62     /* FSBadFont	 */ "BadFont, invalid Font parameter",
63     /* FSBadRange	 */ "BadRange, invalid character range attributes",
64     /* FSBadEventMask	 */ "BadEventMask, illegal event mask",
65     /* FSBadAccessContext */ "BadAccessContext, insufficient permissions for operation",
66     /* FSBadIDChoice  */ "BadIDChoice, invalid resource ID chosen for this connection",
67     /* FSBadName	 */ "BadName, named font does not exist",
68     /* FSBadResolution	 */ "BadResolution, improperly formatted resolution",
69     /* FSBadAlloc	 */ "BadAlloc, insufficient resources for operation",
70     /* FSBadLength	 */ "BadLength, request too large or internal FSlib length error",
71     /* FSBadImplementation */ "BadImplementation, request unsupported",
72};
73#define FSErrorListSize sizeof(FSErrorList)
74
75
76/* ARGSUSED */
77int FSGetErrorDatabaseText(
78    FSServer		*svr,
79    const char		*name,
80    const char		*type,
81    const char		*defaultp,
82    char		*buffer,
83    int			 nbytes)
84{
85    if (nbytes == 0)
86	return 0;
87#ifdef HAVE_STRLCPY
88    if (strlcpy(buffer, defaultp, nbytes) >= nbytes)
89	return 0;
90#else
91    (void) strncpy(buffer, defaultp, nbytes);
92    if ((strlen(defaultp) + 1) > nbytes)
93	buffer[nbytes - 1] = '\0';
94#endif
95    return 1;
96}
97
98int FSGetErrorText(
99    register FSServer	*svr,
100    register int	 code,
101    char		*buffer,
102    int			 nbytes)
103{
104    char        buf[32];
105    register _FSExtension *ext;
106
107    if (nbytes == 0)
108	return 0;
109    snprintf(buf, sizeof(buf), "%d", code);
110    if (code < (FSErrorListSize / sizeof(char *)) && code >= 0) {
111	const char *defaultp = FSErrorList[code];
112	FSGetErrorDatabaseText(svr, "FSProtoError", buf, defaultp, buffer, nbytes);
113    }
114    ext = svr->ext_procs;
115    while (ext) {		/* call out to any extensions interested */
116	if (ext->error_string != NULL)
117	    (*ext->error_string) (svr, code, &ext->codes, buffer, nbytes);
118	ext = ext->next;
119    }
120    return 1;
121}
122
123