~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/lib/Xext/XShape.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Xorg: XShape.c,v 1.4 2001/02/09 02:03:49 xorgcvs Exp $
 
3
 *
 
4
Copyright 1989, 1998  The Open Group
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software and its
 
7
documentation for any purpose is hereby granted without fee, provided that
 
8
the above copyright notice appear in all copies and that both that
 
9
copyright notice and this permission notice appear in supporting
 
10
documentation.
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
Except as contained in this notice, the name of The Open Group shall not be
 
23
used in advertising or otherwise to promote the sale, use or other dealings
 
24
in this Software without prior written authorization from The Open Group.
 
25
 *
 
26
 * Author:  Keith Packard, MIT X Consortium
 
27
 */
 
28
/* $XFree86: xc/lib/Xext/XShape.c,v 1.4 2002/10/16 02:19:22 dawes Exp $ */
 
29
#define NEED_EVENTS
 
30
#define NEED_REPLIES
 
31
#include <X11/Xlibint.h>
 
32
#include <X11/Xutil.h>
 
33
#include "region.h"                     /* in Xlib sources */
 
34
#include <X11/extensions/Xext.h>
 
35
#include <X11/extensions/extutil.h>
 
36
#include <X11/extensions/shapestr.h>
 
37
 
 
38
static XExtensionInfo _shape_info_data;
 
39
static XExtensionInfo *shape_info = &_shape_info_data;
 
40
static /* const */ char *shape_extension_name = SHAPENAME;
 
41
 
 
42
#define ShapeCheckExtension(dpy,i,val) \
 
43
  XextCheckExtension (dpy, i, shape_extension_name, val)
 
44
#define ShapeSimpleCheckExtension(dpy,i) \
 
45
  XextSimpleCheckExtension (dpy, i, shape_extension_name)
 
46
 
 
47
 
 
48
/*****************************************************************************
 
49
 *                                                                           *
 
50
 *                         private utility routines                          *
 
51
 *                                                                           *
 
52
 *****************************************************************************/
 
53
 
 
54
static int close_display(Display *dpy, XExtCodes *codes);
 
55
static Bool wire_to_event (Display *dpy, XEvent *re, xEvent *event);
 
56
static Status event_to_wire (Display *dpy, XEvent *re, xEvent *event);
 
57
static /* const */ XExtensionHooks shape_extension_hooks = {
 
58
    NULL,                               /* create_gc */
 
59
    NULL,                               /* copy_gc */
 
60
    NULL,                               /* flush_gc */
 
61
    NULL,                               /* free_gc */
 
62
    NULL,                               /* create_font */
 
63
    NULL,                               /* free_font */
 
64
    close_display,                      /* close_display */
 
65
    wire_to_event,                      /* wire_to_event */
 
66
    event_to_wire,                      /* event_to_wire */
 
67
    NULL,                               /* error */
 
68
    NULL,                               /* error_string */
 
69
};
 
70
 
 
71
static XEXT_GENERATE_FIND_DISPLAY (find_display, shape_info,
 
72
                                   shape_extension_name, 
 
73
                                   &shape_extension_hooks,
 
74
                                   ShapeNumberEvents, NULL)
 
75
 
 
76
static XEXT_GENERATE_CLOSE_DISPLAY (close_display, shape_info)
 
77
 
 
78
 
 
79
static Bool
 
80
wire_to_event (Display *dpy, XEvent *re, xEvent *event)
 
81
{
 
82
    XExtDisplayInfo *info = find_display (dpy);
 
83
    XShapeEvent         *se;
 
84
    xShapeNotifyEvent   *sevent;
 
85
 
 
86
    ShapeCheckExtension (dpy, info, False);
 
87
 
 
88
    switch ((event->u.u.type & 0x7f) - info->codes->first_event) {
 
89
    case ShapeNotify:
 
90
        se = (XShapeEvent *) re;
 
91
        sevent = (xShapeNotifyEvent *) event;
 
92
        se->type = sevent->type & 0x7f;
 
93
        se->serial = _XSetLastRequestRead(dpy,(xGenericReply *) event);
 
94
        se->send_event = (sevent->type & 0x80) != 0;
 
95
        se->display = dpy;
 
96
        se->window = sevent->window;
 
97
        se->kind = sevent->kind;
 
98
        se->x = cvtINT16toInt (sevent->x);
 
99
        se->y = cvtINT16toInt (sevent->y);
 
100
        se->width = sevent->width;
 
101
        se->height = sevent->height;
 
102
        se->time = sevent->time;
 
103
        se->shaped = True;
 
104
        if (sevent->shaped == xFalse)
 
105
            se->shaped = False;
 
106
        return True;
 
107
    }
 
108
    return False;
 
109
}
 
110
 
 
111
static Status
 
112
event_to_wire (Display *dpy, XEvent *re, xEvent *event)
 
113
{
 
114
    XExtDisplayInfo *info = find_display (dpy);
 
115
    XShapeEvent         *se;
 
116
    xShapeNotifyEvent   *sevent;
 
117
 
 
118
    ShapeCheckExtension (dpy, info, 0);
 
119
 
 
120
    switch ((re->type & 0x7f) - info->codes->first_event) {
 
121
    case ShapeNotify:
 
122
        se = (XShapeEvent *) re;
 
123
        sevent = (xShapeNotifyEvent *) event;
 
124
        sevent->type = se->type | (se->send_event ? 0x80 : 0);
 
125
        sevent->sequenceNumber = se->serial & 0xffff;
 
126
        sevent->window = se->window;
 
127
        sevent->kind = se->kind;
 
128
        sevent->x = se->x;
 
129
        sevent->y = se->y;
 
130
        sevent->width = se->width;
 
131
        sevent->height = se->height;
 
132
        sevent->time = se->time;
 
133
        return 1;
 
134
    }
 
135
    return 0;
 
136
}
 
137
 
 
138
 
 
139
/****************************************************************************
 
140
 *                                                                          *
 
141
 *                          Shape public interfaces                         *
 
142
 *                                                                          *
 
143
 ****************************************************************************/
 
144
 
 
145
Bool XShapeQueryExtension (dpy, event_basep, error_basep)
 
146
    Display *dpy;
 
147
    int *event_basep, *error_basep;
 
148
{
 
149
    XExtDisplayInfo *info = find_display (dpy);
 
150
 
 
151
    if (XextHasExtension(info)) {
 
152
        *event_basep = info->codes->first_event;
 
153
        *error_basep = info->codes->first_error;
 
154
        return True;
 
155
    } else {
 
156
        return False;
 
157
    }
 
158
}
 
159
 
 
160
 
 
161
Status XShapeQueryVersion(dpy, major_versionp, minor_versionp)
 
162
    Display *dpy;
 
163
    int     *major_versionp, *minor_versionp;
 
164
{
 
165
    XExtDisplayInfo *info = find_display (dpy);
 
166
    xShapeQueryVersionReply         rep;
 
167
    register xShapeQueryVersionReq  *req;
 
168
 
 
169
    ShapeCheckExtension (dpy, info, 0);
 
170
 
 
171
    LockDisplay (dpy);
 
172
    GetReq (ShapeQueryVersion, req);
 
173
    req->reqType = info->codes->major_opcode;
 
174
    req->shapeReqType = X_ShapeQueryVersion;
 
175
    if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
 
176
        UnlockDisplay (dpy);
 
177
        SyncHandle ();
 
178
        return 0;
 
179
    }
 
180
    *major_versionp = rep.majorVersion;
 
181
    *minor_versionp = rep.minorVersion;
 
182
    UnlockDisplay (dpy);
 
183
    SyncHandle ();
 
184
    return 1;
 
185
}
 
186
 
 
187
void XShapeCombineRegion(dpy, dest, destKind, xOff, yOff, r, op)
 
188
register Display    *dpy;
 
189
Window              dest;
 
190
int                 destKind, op, xOff, yOff;
 
191
register REGION     *r;
 
192
{
 
193
    XExtDisplayInfo *info = find_display (dpy);
 
194
    register xShapeRectanglesReq *req;
 
195
    register long nbytes;
 
196
    register int i;
 
197
    register XRectangle *xr, *pr;
 
198
    register BOX *pb;
 
199
 
 
200
    ShapeSimpleCheckExtension (dpy, info);
 
201
 
 
202
    LockDisplay(dpy);
 
203
    GetReq(ShapeRectangles, req);
 
204
    xr = (XRectangle *) 
 
205
        _XAllocScratch(dpy, (unsigned long)(r->numRects * sizeof (XRectangle)));
 
206
    for (pr = xr, pb = r->rects, i = r->numRects; --i >= 0; pr++, pb++) {
 
207
        pr->x = pb->x1;
 
208
        pr->y = pb->y1;
 
209
        pr->width = pb->x2 - pb->x1;
 
210
        pr->height = pb->y2 - pb->y1;
 
211
     }
 
212
    req->reqType = info->codes->major_opcode;
 
213
    req->shapeReqType = X_ShapeRectangles;
 
214
    req->op = op;
 
215
    req->ordering = YXBanded;
 
216
    req->destKind = destKind;
 
217
    req->dest = dest;
 
218
    req->xOff = xOff;
 
219
    req->yOff = yOff;
 
220
 
 
221
    /* SIZEOF(xRectangle) will be a multiple of 4 */
 
222
    req->length += r->numRects * (SIZEOF(xRectangle) / 4);
 
223
 
 
224
    nbytes = r->numRects * sizeof(xRectangle);
 
225
 
 
226
    Data16 (dpy, (short *) xr, nbytes);
 
227
    UnlockDisplay(dpy);
 
228
    SyncHandle();
 
229
}
 
230
 
 
231
 
 
232
void XShapeCombineRectangles (dpy, dest, destKind, xOff, yOff,
 
233
                              rects, n_rects, op, ordering)
 
234
register Display *dpy;
 
235
XID dest;
 
236
int destKind, op, xOff, yOff, ordering;
 
237
XRectangle  *rects;
 
238
int n_rects;
 
239
{
 
240
    XExtDisplayInfo *info = find_display (dpy);
 
241
    register xShapeRectanglesReq *req;
 
242
    register long nbytes;
 
243
 
 
244
    ShapeSimpleCheckExtension (dpy, info);
 
245
 
 
246
    LockDisplay(dpy);
 
247
    GetReq(ShapeRectangles, req);
 
248
    req->reqType = info->codes->major_opcode;
 
249
    req->shapeReqType = X_ShapeRectangles;
 
250
    req->op = op;
 
251
    req->ordering = ordering;
 
252
    req->destKind = destKind;
 
253
    req->dest = dest;
 
254
    req->xOff = xOff;
 
255
    req->yOff = yOff;
 
256
 
 
257
    /* SIZEOF(xRectangle) will be a multiple of 4 */
 
258
    req->length += n_rects * (SIZEOF(xRectangle) / 4);
 
259
 
 
260
    nbytes = n_rects * sizeof(xRectangle);
 
261
 
 
262
    Data16 (dpy, (short *) rects, nbytes);
 
263
    UnlockDisplay(dpy);
 
264
    SyncHandle();
 
265
}
 
266
 
 
267
 
 
268
void XShapeCombineMask (dpy, dest, destKind, xOff, yOff, src, op)
 
269
register Display *dpy;
 
270
int destKind;
 
271
XID dest;
 
272
Pixmap  src;
 
273
int op, xOff, yOff;
 
274
{
 
275
    XExtDisplayInfo *info = find_display (dpy);
 
276
    register xShapeMaskReq *req;
 
277
 
 
278
    ShapeSimpleCheckExtension (dpy, info);
 
279
 
 
280
    LockDisplay(dpy);
 
281
    GetReq(ShapeMask, req);
 
282
    req->reqType = info->codes->major_opcode;
 
283
    req->shapeReqType = X_ShapeMask;
 
284
    req->op = op;
 
285
    req->destKind = destKind;
 
286
    req->dest = dest;
 
287
    req->xOff = xOff;
 
288
    req->yOff = yOff;
 
289
    req->src = src;
 
290
    UnlockDisplay(dpy);
 
291
    SyncHandle();
 
292
}
 
293
 
 
294
void XShapeCombineShape (dpy, dest, destKind, xOff, yOff, src, srcKind, op)
 
295
register Display *dpy;
 
296
int destKind;
 
297
XID dest;
 
298
int srcKind;
 
299
XID src;
 
300
int op, xOff, yOff;
 
301
{
 
302
    XExtDisplayInfo *info = find_display (dpy);
 
303
    register xShapeCombineReq *req;
 
304
 
 
305
    ShapeSimpleCheckExtension (dpy, info);
 
306
 
 
307
    LockDisplay(dpy);
 
308
    GetReq(ShapeCombine, req);
 
309
    req->reqType = info->codes->major_opcode;
 
310
    req->shapeReqType = X_ShapeCombine;
 
311
    req->op = op;
 
312
    req->destKind = destKind;
 
313
    req->srcKind = srcKind;
 
314
    req->dest = dest;
 
315
    req->xOff = xOff;
 
316
    req->yOff = yOff;
 
317
    req->src = src;
 
318
    UnlockDisplay(dpy);
 
319
    SyncHandle();
 
320
}
 
321
 
 
322
void XShapeOffsetShape (dpy, dest, destKind, xOff, yOff)
 
323
register Display *dpy;
 
324
int destKind;
 
325
XID dest;
 
326
int xOff, yOff;
 
327
{
 
328
    XExtDisplayInfo *info = find_display (dpy);
 
329
    register xShapeOffsetReq *req;
 
330
 
 
331
    ShapeSimpleCheckExtension (dpy, info);
 
332
 
 
333
    LockDisplay(dpy);
 
334
    GetReq(ShapeOffset, req);
 
335
    req->reqType = info->codes->major_opcode;
 
336
    req->shapeReqType = X_ShapeOffset;
 
337
    req->destKind = destKind;
 
338
    req->dest = dest;
 
339
    req->xOff = xOff;
 
340
    req->yOff = yOff;
 
341
    UnlockDisplay(dpy);
 
342
    SyncHandle();
 
343
}
 
344
 
 
345
Status XShapeQueryExtents (dpy, window,
 
346
                           bShaped, xbs, ybs, wbs, hbs,
 
347
                           cShaped, xcs, ycs, wcs, hcs)    
 
348
    register Display    *dpy;
 
349
    Window                  window;
 
350
    int                     *bShaped, *cShaped;     /* RETURN */
 
351
    int                     *xbs, *ybs, *xcs, *ycs; /* RETURN */
 
352
    unsigned int            *wbs, *hbs, *wcs, *hcs; /* RETURN */
 
353
{
 
354
    XExtDisplayInfo *info = find_display (dpy);
 
355
    xShapeQueryExtentsReply         rep;
 
356
    register xShapeQueryExtentsReq *req;
 
357
    
 
358
    ShapeCheckExtension (dpy, info, 0);
 
359
 
 
360
    LockDisplay (dpy);
 
361
    GetReq (ShapeQueryExtents, req);
 
362
    req->reqType = info->codes->major_opcode;
 
363
    req->shapeReqType = X_ShapeQueryExtents;
 
364
    req->window = window;
 
365
    if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
 
366
        UnlockDisplay (dpy);
 
367
        SyncHandle ();
 
368
        return 0;
 
369
    }
 
370
    *bShaped = rep.boundingShaped;
 
371
    *cShaped = rep.clipShaped;
 
372
    *xbs = cvtINT16toInt (rep.xBoundingShape);
 
373
    *ybs = cvtINT16toInt (rep.yBoundingShape);
 
374
    *wbs = rep.widthBoundingShape;
 
375
    *hbs = rep.heightBoundingShape;
 
376
    *xcs = cvtINT16toInt (rep.xClipShape);
 
377
    *ycs = cvtINT16toInt (rep.yClipShape);
 
378
    *wcs = rep.widthClipShape;
 
379
    *hcs = rep.heightClipShape;
 
380
    UnlockDisplay (dpy);
 
381
    SyncHandle ();
 
382
    return 1;
 
383
}
 
384
 
 
385
 
 
386
void XShapeSelectInput (dpy, window, mask)
 
387
    register Display    *dpy;
 
388
    Window              window;
 
389
    unsigned long       mask;
 
390
{
 
391
    XExtDisplayInfo *info = find_display (dpy);
 
392
    register xShapeSelectInputReq   *req;
 
393
 
 
394
    ShapeSimpleCheckExtension (dpy, info);
 
395
 
 
396
    LockDisplay (dpy);
 
397
    GetReq (ShapeSelectInput, req);
 
398
    req->reqType = info->codes->major_opcode;
 
399
    req->shapeReqType = X_ShapeSelectInput;
 
400
    req->window = window;
 
401
    if (mask & ShapeNotifyMask)
 
402
        req->enable = xTrue;
 
403
    else
 
404
        req->enable = xFalse;
 
405
    UnlockDisplay (dpy);
 
406
    SyncHandle ();
 
407
}
 
408
 
 
409
unsigned long XShapeInputSelected (dpy, window)
 
410
    register Display    *dpy;
 
411
    Window              window;
 
412
{
 
413
    XExtDisplayInfo *info = find_display (dpy);
 
414
    register xShapeInputSelectedReq *req;
 
415
    xShapeInputSelectedReply        rep;
 
416
 
 
417
    ShapeCheckExtension (dpy, info, False);
 
418
 
 
419
    LockDisplay (dpy);
 
420
    GetReq (ShapeInputSelected, req);
 
421
    req->reqType = info->codes->major_opcode;
 
422
    req->shapeReqType = X_ShapeInputSelected;
 
423
    req->window = window;
 
424
    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
 
425
        UnlockDisplay (dpy);
 
426
        SyncHandle ();
 
427
        return False;
 
428
    }
 
429
    UnlockDisplay (dpy);
 
430
    SyncHandle ();
 
431
    return rep.enabled ? ShapeNotifyMask : 0L;
 
432
}
 
433
 
 
434
 
 
435
XRectangle *XShapeGetRectangles (dpy, window, kind, count, ordering)
 
436
    register Display    *dpy;
 
437
    Window              window;
 
438
    int                 kind;
 
439
    int                 *count; /* RETURN */
 
440
    int                 *ordering; /* RETURN */
 
441
{
 
442
    XExtDisplayInfo *info = find_display (dpy);
 
443
    register xShapeGetRectanglesReq   *req;
 
444
    xShapeGetRectanglesReply        rep;
 
445
    XRectangle                      *rects;
 
446
    xRectangle                      *xrects;
 
447
    int                             i;
 
448
 
 
449
    ShapeCheckExtension (dpy, info, (XRectangle *)NULL);
 
450
 
 
451
    LockDisplay (dpy);
 
452
    GetReq (ShapeGetRectangles, req);
 
453
    req->reqType = info->codes->major_opcode;
 
454
    req->shapeReqType = X_ShapeGetRectangles;
 
455
    req->window = window;
 
456
    req->kind = kind;
 
457
    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
 
458
        UnlockDisplay (dpy);
 
459
        SyncHandle ();
 
460
        return (XRectangle *)NULL;
 
461
    }
 
462
    *count = rep.nrects;
 
463
    *ordering = rep.ordering;
 
464
    rects = 0;
 
465
    if (*count) {
 
466
        xrects = (xRectangle *) Xmalloc (*count * sizeof (xRectangle));
 
467
        rects = (XRectangle *) Xmalloc (*count * sizeof (XRectangle));
 
468
        if (!xrects || !rects) {
 
469
            if (xrects)
 
470
                Xfree (xrects);
 
471
            if (rects)
 
472
                Xfree (rects);
 
473
            _XEatData (dpy, *count * sizeof (xRectangle));
 
474
            rects = 0;
 
475
            *count = 0;
 
476
        } else {
 
477
            _XRead (dpy, (char *) xrects, *count * sizeof (xRectangle));
 
478
            for (i = 0; i < *count; i++) {
 
479
                rects[i].x = (short) cvtINT16toInt (xrects[i].x);
 
480
                rects[i].y = (short) cvtINT16toInt (xrects[i].y);
 
481
                rects[i].width = xrects[i].width;
 
482
                rects[i].height = xrects[i].height;
 
483
            }
 
484
            Xfree (xrects);
 
485
        }
 
486
    }
 
487
    UnlockDisplay (dpy);
 
488
    SyncHandle ();
 
489
    return rects;
 
490
}