FSQXInfo.c revision ba6a1819
1/* $Xorg: FSQXInfo.c,v 1.4 2001/02/09 02:03:25 xorgcvs Exp $ */
2/*
3 * Copyright 1990 Network Computing Devices;
4 * Portions Copyright 1987 by Digital Equipment Corporation
5 *
6 * Permission to use, copy, modify, distribute, and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation, and that the names of Network Computing
11 * Devices or Digital not be used in advertising or publicity pertaining
12 * to distribution of the software without specific, written prior
13 * permission. Network Computing Devices or Digital make no representations
14 * about the suitability of this software for any purpose.  It is provided
15 * "as is" without express or implied warranty.
16 *
17 * NETWORK COMPUTING DEVICES AND  DIGITAL DISCLAIM ALL WARRANTIES WITH
18 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES
20 * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24 * SOFTWARE.
25 */
26/* $XFree86: xc/lib/FS/FSQXInfo.c,v 1.5tsi Exp $ */
27
28/*
29
30Copyright 1987, 1998  The Open Group
31
32Permission to use, copy, modify, distribute, and sell this software and its
33documentation for any purpose is hereby granted without fee, provided that
34the above copyright notice appear in all copies and that both that
35copyright notice and this permission notice appear in supporting
36documentation.
37
38The above copyright notice and this permission notice shall be included in
39all copies or substantial portions of the Software.
40
41THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
44OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
45AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
46CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47
48Except as contained in this notice, the name of The Open Group shall not be
49used in advertising or otherwise to promote the sale, use or other dealings
50in this Software without prior written authorization from The Open Group.
51
52*/
53
54#ifdef HAVE_CONFIG_H
55#include <config.h>
56#endif
57#include	"FSlibint.h"
58
59/*
60 * Note:  only the range in the first FSQuery is sent to the server.
61 * the others exist as return values only.
62 */
63
64int
65FSQueryXInfo(
66    FSServer		 *svr,
67    Font		  fid,
68    FSXFontInfoHeader	 *info,
69    FSPropInfo		 *props,
70    FSPropOffset	**offsets,
71    unsigned char	**prop_data)
72{
73    fsQueryXInfoReq *req;
74    fsQueryXInfoReply reply;
75    FSPropOffset *offset_data;
76    unsigned char *pdata;
77    fsPropInfo local_pi;
78    fsPropOffset local_po;
79    int j;
80
81    GetReq(QueryXInfo, req);
82    req->id = fid;
83
84    /* get back the info */
85    if (!_FSReply(svr, (fsReply *) & reply, ((SIZEOF(fsQueryXInfoReply) -
86			    SIZEOF(fsGenericReply)) >> 2), fsFalse)) {
87	return FSBadAlloc;
88    }
89
90    FSUnpack_XFontInfoHeader(&reply, info, FSProtocolVersion(svr));
91
92    /* get the prop header */
93    _FSReadPad(svr, (char *) &local_pi, SIZEOF(fsPropInfo));
94    props->num_offsets = local_pi.num_offsets;
95    props->data_len = local_pi.data_len;
96
97#if SIZE_MAX <= UINT_MAX
98    if (props->num_offsets > SIZE_MAX / sizeof(FSPropOffset))
99	return FSBadAlloc;
100#endif
101
102    /* prepare for prop data */
103    offset_data = (FSPropOffset *)
104	FSmalloc(props->num_offsets * sizeof(FSPropOffset));
105    if (!offset_data)
106	return FSBadAlloc;
107    pdata = (unsigned char *) FSmalloc(props->data_len);
108    if (!pdata) {
109	FSfree((char *) offset_data);
110	return FSBadAlloc;
111    }
112    /* get offsets */
113    for (j=0; j<props->num_offsets; j++)
114    {
115	_FSReadPad(svr, (char *) &local_po, SIZEOF(fsPropOffset));
116	offset_data[j].name.position = local_po.name.position;
117	offset_data[j].name.length = local_po.name.length;
118	offset_data[j].value.position = local_po.value.position;
119	offset_data[j].value.length = local_po.value.length;
120	offset_data[j].type = local_po.type;
121    }
122
123    /* get data */
124    _FSReadPad(svr, (char *) pdata, props->data_len);
125    *offsets = offset_data;
126    *prop_data = pdata;
127
128    SyncHandle();
129    return FSSuccess;
130}
131