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