FSQGlyphs.c revision da1f2d5d
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, 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 "FSlibint.h"
56
57int
58FSQueryXBitmaps8(
59    FSServer		 *svr,
60    Font		  fid,
61    FSBitmapFormat	  format,
62    Bool		  range_type,
63    const unsigned char	 *str,
64    unsigned long	  str_len,
65    FSOffset		**offsets,
66    unsigned char	**glyphdata)
67{
68    fsQueryXBitmaps8Req *req;
69    fsQueryXBitmaps8Reply reply;
70    FSOffset   *offs;
71    fsOffset32 local_offs;
72    unsigned char *gd;
73    int         left;
74
75    if (str_len > (FSMaxRequestBytes(svr) - SIZEOF(fsQueryXBitmaps8Req)))
76        return FSBadLength;
77
78    GetReq(QueryXBitmaps8, req);
79    req->fid = fid;
80    req->range = (BOOL) range_type;
81    req->format = format;
82    req->num_ranges = (CARD32) str_len;
83    req->length += (CARD16) ((str_len + 3) >> 2);
84    _FSSend(svr, (char *) str, str_len);
85
86    /* get back the info */
87    if (!_FSReply(svr, (fsReply *) & reply,
88     (SIZEOF(fsQueryXBitmaps8Reply) - SIZEOF(fsGenericReply)) >> 2, fsFalse))
89	return FSBadAlloc;
90
91#if SIZE_MAX <= UINT_MAX
92    if (reply.num_chars > SIZE_MAX / sizeof(FSOffset))
93	return FSBadAlloc;
94#endif
95
96    offs = FSmallocarray(reply.num_chars, sizeof(FSOffset));
97    *offsets = offs;
98    if (!offs)
99	return FSBadAlloc;
100#if (SIZE_MAX >> 2) <= UINT_MAX
101    /* XXX This test is incomplete */
102    if (reply.length > (SIZE_MAX >> 2)) {
103	FSfree(offs);
104	return FSBadAlloc;
105    }
106#endif
107    left = (reply.length << 2) - SIZEOF(fsQueryXBitmaps8Reply)
108	- (SIZEOF(fsOffset32) * reply.num_chars);
109    gd = FSmalloc(left);
110    *glyphdata = gd;
111    if (!gd) {
112	FSfree(offs);
113	return FSBadAlloc;
114    }
115    for (CARD32 i = 0; i < reply.num_chars; i++)
116    {
117	_FSReadPad(svr, (char *) &local_offs, (SIZEOF(fsOffset32)));
118	offs->position = local_offs.position;
119	offs->length = local_offs.length;
120	offs++;
121    }
122    _FSReadPad(svr, (char *) gd, left);
123
124    SyncHandle();
125    return FSSuccess;
126}
127
128int
129FSQueryXBitmaps16(
130    FSServer		 *svr,
131    Font		  fid,
132    FSBitmapFormat	  format,
133    Bool		  range_type,
134    const FSChar2b	 *str,
135    unsigned long	  str_len,
136    FSOffset		**offsets,
137    unsigned char	**glyphdata)
138{
139    fsQueryXBitmaps16Req *req;
140    fsQueryXBitmaps16Reply reply;
141    FSOffset   *offs;
142    fsOffset32 local_offs;
143    unsigned char *gd;
144    int         left;
145
146    /* Relies on fsChar2b & fsChar2b_version1 being the same size */
147    if (str_len > ((FSMaxRequestBytes(svr) - SIZEOF(fsQueryXBitmaps16Req))
148                    / SIZEOF(fsChar2b)))
149        return FSBadLength;
150
151    GetReq(QueryXBitmaps16, req);
152    req->fid = fid;
153    req->range = (BOOL) range_type;
154    req->format = format;
155    req->num_ranges = (CARD32) str_len;
156    req->length += (CARD16) (((str_len * SIZEOF(fsChar2b)) + 3) >> 2);
157    if (FSProtocolVersion(svr) == 1)
158    {
159	fsChar2b_version1 *swapped_str;
160
161	if (str_len > SIZE_MAX/SIZEOF(fsChar2b_version1))
162	    return FSBadAlloc;
163	swapped_str = FSmallocarray(str_len, SIZEOF(fsChar2b_version1));
164	if (!swapped_str)
165	    return FSBadAlloc;
166	for (unsigned long i = 0; i < str_len; i++) {
167	    swapped_str[i].low = str[i].low;
168	    swapped_str[i].high = str[i].high;
169	}
170	_FSSend(svr, (char *)swapped_str, (str_len*SIZEOF(fsChar2b_version1)));
171	FSfree(swapped_str);
172    } else
173	_FSSend(svr, (char *) str, (str_len * SIZEOF(fsChar2b)));
174
175    /* get back the info */
176    if (!_FSReply(svr, (fsReply *) & reply,
177	      (SIZEOF(fsQueryXBitmaps16Reply) - SIZEOF(fsGenericReply)) >> 2,
178		  fsFalse))
179	return FSBadAlloc;
180
181#if SIZE_MAX <= UINT_MAX
182    if(reply.num_chars > SIZE_MAX/sizeof(FSOffset))
183       return FSBadAlloc;
184#endif
185    offs = FSmallocarray(reply.num_chars, sizeof(FSOffset));
186    *offsets = offs;
187    if (!offs)
188	return FSBadAlloc;
189#if (SIZE_MAX >> 2) <= UINT_MAX
190    /* XXX - this test is incomplete */
191    if (reply.length > (SIZE_MAX>>2)) {
192	FSfree(offs);
193	return FSBadAlloc;
194    }
195#endif
196    left = (reply.length << 2) - SIZEOF(fsQueryXBitmaps16Reply)
197	- (SIZEOF(fsOffset32) * reply.num_chars);
198    gd = FSmalloc(left);
199    *glyphdata = gd;
200    if (!gd) {
201	FSfree(offs);
202	return FSBadAlloc;
203    }
204    for (CARD32 i = 0; i < reply.num_chars; i++)
205    {
206	_FSReadPad(svr, (char *) &local_offs, (SIZEOF(fsOffset32)));
207	offs->position = local_offs.position;
208	offs->length = local_offs.length;
209	offs++;
210    }
211    _FSReadPad(svr, (char *) gd, left);
212
213    SyncHandle();
214    return FSSuccess;
215}
216