1/************************************************************
2Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
3
4Permission to use, copy, modify, and distribute this
5software and its documentation for any purpose and without
6fee is hereby granted, provided that the above copyright
7notice appear in all copies and that both that copyright
8notice and this permission notice appear in supporting
9documentation, and that the name of Silicon Graphics not be
10used in advertising or publicity pertaining to distribution
11of the software without specific prior written permission.
12Silicon Graphics makes no representation about the suitability
13of this software for any purpose. It is provided "as is"
14without any express or implied warranty.
15
16SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
23THE USE OR PERFORMANCE OF THIS SOFTWARE.
24
25********************************************************/
26
27#ifdef HAVE_DIX_CONFIG_H
28#include <dix-config.h>
29#endif
30
31#include "stdio.h"
32#include <X11/X.h>
33#include <X11/Xproto.h>
34#include "misc.h"
35#include "inputstr.h"
36#include <xkbsrv.h>
37#include "xkbstr.h"
38#include "extnsionst.h"
39#include "xkb.h"
40
41	/*
42	 * REQUEST SWAPPING
43	 */
44static int
45SProcXkbUseExtension(ClientPtr client)
46{
47register int n;
48
49    REQUEST(xkbUseExtensionReq);
50
51    swaps(&stuff->length,n);
52    REQUEST_SIZE_MATCH(xkbUseExtensionReq);
53    swaps(&stuff->wantedMajor,n);
54    swaps(&stuff->wantedMinor,n);
55    return ProcXkbUseExtension(client);
56}
57
58static int
59SProcXkbSelectEvents(ClientPtr client)
60{
61register int n;
62
63    REQUEST(xkbSelectEventsReq);
64
65    swaps(&stuff->length,n);
66    REQUEST_AT_LEAST_SIZE(xkbSelectEventsReq);
67    swaps(&stuff->deviceSpec,n);
68    swaps(&stuff->affectWhich,n);
69    swaps(&stuff->clear,n);
70    swaps(&stuff->selectAll,n);
71    swaps(&stuff->affectMap,n);
72    swaps(&stuff->map,n);
73    if ((stuff->affectWhich&(~XkbMapNotifyMask))!=0)  {
74	union {
75	    BOOL	*b;
76	    CARD8	*c8;
77	    CARD16	*c16;
78	    CARD32	*c32;
79	} from;
80	register unsigned bit,ndx,maskLeft,dataLeft,size;
81
82	from.c8= (CARD8 *)&stuff[1];
83	dataLeft= (stuff->length*4)-SIZEOF(xkbSelectEventsReq);
84	maskLeft= (stuff->affectWhich&(~XkbMapNotifyMask));
85	for (ndx=0,bit=1; (maskLeft!=0); ndx++, bit<<=1) {
86	    if (((bit&maskLeft)==0)||(ndx==XkbMapNotify))
87		continue;
88	    maskLeft&= ~bit;
89	    if ((stuff->selectAll&bit)||(stuff->clear&bit))
90		continue;
91	    switch (ndx) {
92		case XkbNewKeyboardNotify:
93		case XkbStateNotify:
94		case XkbNamesNotify:
95		case XkbAccessXNotify:
96		case XkbExtensionDeviceNotify:
97		    size= 2;
98		    break;
99		case XkbControlsNotify:
100		case XkbIndicatorStateNotify:
101		case XkbIndicatorMapNotify:
102		    size= 4;
103		    break;
104		case XkbBellNotify:
105		case XkbActionMessage:
106		case XkbCompatMapNotify:
107		    size= 1;
108		    break;
109		default:
110		    client->errorValue = _XkbErrCode2(0x1,bit);
111		    return BadValue;
112	    }
113	    if (dataLeft<(size*2))
114		return BadLength;
115	    if (size==2) {
116		swaps(&from.c16[0],n);
117		swaps(&from.c16[1],n);
118	    }
119	    else if (size==4) {
120		swapl(&from.c32[0],n);
121		swapl(&from.c32[1],n);
122	    }
123	    else {
124		size= 2;
125	    }
126	    from.c8+= (size*2);
127	    dataLeft-= (size*2);
128	}
129	if (dataLeft>2) {
130	    ErrorF("[xkb] Extra data (%d bytes) after SelectEvents\n",dataLeft);
131	    return BadLength;
132	}
133    }
134    return ProcXkbSelectEvents(client);
135}
136
137static int
138SProcXkbBell(ClientPtr client)
139{
140register int	n;
141
142    REQUEST(xkbBellReq);
143
144    swaps(&stuff->length,n);
145    REQUEST_SIZE_MATCH(xkbBellReq);
146    swaps(&stuff->deviceSpec,n);
147    swaps(&stuff->bellClass,n);
148    swaps(&stuff->bellID,n);
149    swapl(&stuff->name,n);
150    swapl(&stuff->window,n);
151    swaps(&stuff->pitch,n);
152    swaps(&stuff->duration,n);
153    return ProcXkbBell(client);
154}
155
156static int
157SProcXkbGetState(ClientPtr client)
158{
159register int	n;
160
161    REQUEST(xkbGetStateReq);
162
163    swaps(&stuff->length,n);
164    REQUEST_SIZE_MATCH(xkbGetStateReq);
165    swaps(&stuff->deviceSpec,n);
166    return ProcXkbGetState(client);
167}
168
169static int
170SProcXkbLatchLockState(ClientPtr client)
171{
172register int 	n;
173
174    REQUEST(xkbLatchLockStateReq);
175
176    swaps(&stuff->length,n);
177    REQUEST_SIZE_MATCH(xkbLatchLockStateReq);
178    swaps(&stuff->deviceSpec,n);
179    swaps(&stuff->groupLatch,n);
180    return ProcXkbLatchLockState(client);
181}
182
183static int
184SProcXkbGetControls(ClientPtr client)
185{
186register int	n;
187
188    REQUEST(xkbGetControlsReq);
189
190    swaps(&stuff->length,n);
191    REQUEST_SIZE_MATCH(xkbGetControlsReq);
192    swaps(&stuff->deviceSpec,n);
193    return ProcXkbGetControls(client);
194}
195
196static int
197SProcXkbSetControls(ClientPtr client)
198{
199register int	n;
200
201    REQUEST(xkbSetControlsReq);
202
203    swaps(&stuff->length,n);
204    REQUEST_SIZE_MATCH(xkbSetControlsReq);
205    swaps(&stuff->deviceSpec,n);
206    swaps(&stuff->affectInternalVMods,n);
207    swaps(&stuff->internalVMods,n);
208    swaps(&stuff->affectIgnoreLockVMods,n);
209    swaps(&stuff->ignoreLockVMods,n);
210    swaps(&stuff->axOptions,n);
211    swapl(&stuff->affectEnabledCtrls,n);
212    swapl(&stuff->enabledCtrls,n);
213    swapl(&stuff->changeCtrls,n);
214    swaps(&stuff->repeatDelay,n);
215    swaps(&stuff->repeatInterval,n);
216    swaps(&stuff->slowKeysDelay,n);
217    swaps(&stuff->debounceDelay,n);
218    swaps(&stuff->mkDelay,n);
219    swaps(&stuff->mkInterval,n);
220    swaps(&stuff->mkTimeToMax,n);
221    swaps(&stuff->mkMaxSpeed,n);
222    swaps(&stuff->mkCurve,n);
223    swaps(&stuff->axTimeout,n);
224    swapl(&stuff->axtCtrlsMask,n);
225    swapl(&stuff->axtCtrlsValues,n);
226    swaps(&stuff->axtOptsMask,n);
227    swaps(&stuff->axtOptsValues,n);
228    return ProcXkbSetControls(client);
229}
230
231static int
232SProcXkbGetMap(ClientPtr client)
233{
234register int	n;
235
236    REQUEST(xkbGetMapReq);
237
238    swaps(&stuff->length,n);
239    REQUEST_SIZE_MATCH(xkbGetMapReq);
240    swaps(&stuff->deviceSpec,n);
241    swaps(&stuff->full,n);
242    swaps(&stuff->partial,n);
243    swaps(&stuff->virtualMods,n);
244    return ProcXkbGetMap(client);
245}
246
247static int
248SProcXkbSetMap(ClientPtr client)
249{
250register int	n;
251
252    REQUEST(xkbSetMapReq);
253
254    swaps(&stuff->length,n);
255    REQUEST_AT_LEAST_SIZE(xkbSetMapReq);
256    swaps(&stuff->deviceSpec,n);
257    swaps(&stuff->present,n);
258    swaps(&stuff->flags,n);
259    swaps(&stuff->totalSyms,n);
260    swaps(&stuff->totalActs,n);
261    swaps(&stuff->virtualMods,n);
262    return ProcXkbSetMap(client);
263}
264
265
266static int
267SProcXkbGetCompatMap(ClientPtr client)
268{
269register int	n;
270
271    REQUEST(xkbGetCompatMapReq);
272
273    swaps(&stuff->length,n);
274    REQUEST_SIZE_MATCH(xkbGetCompatMapReq);
275    swaps(&stuff->deviceSpec,n);
276    swaps(&stuff->firstSI,n);
277    swaps(&stuff->nSI,n);
278    return ProcXkbGetCompatMap(client);
279}
280
281static int
282SProcXkbSetCompatMap(ClientPtr client)
283{
284register int	n;
285
286    REQUEST(xkbSetCompatMapReq);
287
288    swaps(&stuff->length,n);
289    REQUEST_AT_LEAST_SIZE(xkbSetCompatMapReq);
290    swaps(&stuff->deviceSpec,n);
291    swaps(&stuff->firstSI,n);
292    swaps(&stuff->nSI,n);
293    return ProcXkbSetCompatMap(client);
294}
295
296static int
297SProcXkbGetIndicatorState(ClientPtr client)
298{
299register int	n;
300
301    REQUEST(xkbGetIndicatorStateReq);
302
303    swaps(&stuff->length,n);
304    REQUEST_SIZE_MATCH(xkbGetIndicatorStateReq);
305    swaps(&stuff->deviceSpec,n);
306    return ProcXkbGetIndicatorState(client);
307}
308
309static int
310SProcXkbGetIndicatorMap(ClientPtr client)
311{
312register int	n;
313
314    REQUEST(xkbGetIndicatorMapReq);
315
316    swaps(&stuff->length,n);
317    REQUEST_SIZE_MATCH(xkbGetIndicatorMapReq);
318    swaps(&stuff->deviceSpec,n);
319    swapl(&stuff->which,n);
320    return ProcXkbGetIndicatorMap(client);
321}
322
323static int
324SProcXkbSetIndicatorMap(ClientPtr client)
325{
326register int	n;
327
328    REQUEST(xkbSetIndicatorMapReq);
329
330    swaps(&stuff->length,n);
331    REQUEST_AT_LEAST_SIZE(xkbSetIndicatorMapReq);
332    swaps(&stuff->deviceSpec,n);
333    swapl(&stuff->which,n);
334    return ProcXkbSetIndicatorMap(client);
335}
336
337static int
338SProcXkbGetNamedIndicator(ClientPtr client)
339{
340register int	n;
341
342    REQUEST(xkbGetNamedIndicatorReq);
343
344    swaps(&stuff->length,n);
345    REQUEST_SIZE_MATCH(xkbGetNamedIndicatorReq);
346    swaps(&stuff->deviceSpec,n);
347    swaps(&stuff->ledClass,n);
348    swaps(&stuff->ledID,n);
349    swapl(&stuff->indicator,n);
350    return ProcXkbGetNamedIndicator(client);
351}
352
353static int
354SProcXkbSetNamedIndicator(ClientPtr client)
355{
356register int	n;
357
358    REQUEST(xkbSetNamedIndicatorReq);
359
360    swaps(&stuff->length,n);
361    REQUEST_SIZE_MATCH(xkbSetNamedIndicatorReq);
362    swaps(&stuff->deviceSpec,n);
363    swaps(&stuff->ledClass,n);
364    swaps(&stuff->ledID,n);
365    swapl(&stuff->indicator,n);
366    swaps(&stuff->virtualMods,n);
367    swapl(&stuff->ctrls,n);
368    return ProcXkbSetNamedIndicator(client);
369}
370
371
372static int
373SProcXkbGetNames(ClientPtr client)
374{
375register int	n;
376
377    REQUEST(xkbGetNamesReq);
378
379    swaps(&stuff->length,n);
380    REQUEST_SIZE_MATCH(xkbGetNamesReq);
381    swaps(&stuff->deviceSpec,n);
382    swapl(&stuff->which,n);
383    return ProcXkbGetNames(client);
384}
385
386static int
387SProcXkbSetNames(ClientPtr client)
388{
389register int	n;
390
391    REQUEST(xkbSetNamesReq);
392
393    swaps(&stuff->length,n);
394    REQUEST_AT_LEAST_SIZE(xkbSetNamesReq);
395    swaps(&stuff->deviceSpec,n);
396    swaps(&stuff->virtualMods,n);
397    swapl(&stuff->which,n);
398    swapl(&stuff->indicators,n);
399    swaps(&stuff->totalKTLevelNames,n);
400    return ProcXkbSetNames(client);
401}
402
403static int
404SProcXkbGetGeometry(ClientPtr client)
405{
406register int	n;
407
408    REQUEST(xkbGetGeometryReq);
409
410    swaps(&stuff->length,n);
411    REQUEST_SIZE_MATCH(xkbGetGeometryReq);
412    swaps(&stuff->deviceSpec,n);
413    swapl(&stuff->name,n);
414    return ProcXkbGetGeometry(client);
415}
416
417static int
418SProcXkbSetGeometry(ClientPtr client)
419{
420register int	n;
421
422    REQUEST(xkbSetGeometryReq);
423
424    swaps(&stuff->length,n);
425    REQUEST_AT_LEAST_SIZE(xkbSetGeometryReq);
426    swaps(&stuff->deviceSpec,n);
427    swapl(&stuff->name,n);
428    swaps(&stuff->widthMM,n);
429    swaps(&stuff->heightMM,n);
430    swaps(&stuff->nProperties,n);
431    swaps(&stuff->nColors,n);
432    swaps(&stuff->nDoodads,n);
433    swaps(&stuff->nKeyAliases,n);
434    return ProcXkbSetGeometry(client);
435}
436
437static int
438SProcXkbPerClientFlags(ClientPtr client)
439{
440register int	n;
441
442    REQUEST(xkbPerClientFlagsReq);
443
444    swaps(&stuff->length,n);
445    REQUEST_SIZE_MATCH(xkbPerClientFlagsReq);
446    swaps(&stuff->deviceSpec,n);
447    swapl(&stuff->change,n);
448    swapl(&stuff->value,n);
449    swapl(&stuff->ctrlsToChange,n);
450    swapl(&stuff->autoCtrls,n);
451    swapl(&stuff->autoCtrlValues,n);
452    return ProcXkbPerClientFlags(client);
453}
454
455static int
456SProcXkbListComponents(ClientPtr client)
457{
458register int	n;
459
460    REQUEST(xkbListComponentsReq);
461
462    swaps(&stuff->length,n);
463    REQUEST_AT_LEAST_SIZE(xkbListComponentsReq);
464    swaps(&stuff->deviceSpec,n);
465    swaps(&stuff->maxNames,n);
466    return ProcXkbListComponents(client);
467}
468
469static int
470SProcXkbGetKbdByName(ClientPtr client)
471{
472register int	n;
473
474    REQUEST(xkbGetKbdByNameReq);
475
476    swaps(&stuff->length,n);
477    REQUEST_AT_LEAST_SIZE(xkbGetKbdByNameReq);
478    swaps(&stuff->deviceSpec,n);
479    swaps(&stuff->want,n);
480    swaps(&stuff->need,n);
481    return ProcXkbGetKbdByName(client);
482}
483
484static int
485SProcXkbGetDeviceInfo(ClientPtr client)
486{
487register int	n;
488
489    REQUEST(xkbGetDeviceInfoReq);
490
491    swaps(&stuff->length,n);
492    REQUEST_SIZE_MATCH(xkbGetDeviceInfoReq);
493    swaps(&stuff->deviceSpec,n);
494    swaps(&stuff->wanted,n);
495    swaps(&stuff->ledClass,n);
496    swaps(&stuff->ledID,n);
497    return ProcXkbGetDeviceInfo(client);
498}
499
500static int
501SProcXkbSetDeviceInfo(ClientPtr client)
502{
503register int	n;
504
505    REQUEST(xkbSetDeviceInfoReq);
506
507    swaps(&stuff->length,n);
508    REQUEST_AT_LEAST_SIZE(xkbSetDeviceInfoReq);
509    swaps(&stuff->deviceSpec,n);
510    swaps(&stuff->change,n);
511    swaps(&stuff->nDeviceLedFBs,n);
512    return ProcXkbSetDeviceInfo(client);
513}
514
515static int
516SProcXkbSetDebuggingFlags(ClientPtr client)
517{
518register int	n;
519
520    REQUEST(xkbSetDebuggingFlagsReq);
521
522    swaps(&stuff->length,n);
523    REQUEST_AT_LEAST_SIZE(xkbSetDebuggingFlagsReq);
524    swapl(&stuff->affectFlags,n);
525    swapl(&stuff->flags,n);
526    swapl(&stuff->affectCtrls,n);
527    swapl(&stuff->ctrls,n);
528    swaps(&stuff->msgLength,n);
529    return ProcXkbSetDebuggingFlags(client);
530}
531
532int
533SProcXkbDispatch (ClientPtr client)
534{
535    REQUEST(xReq);
536    switch (stuff->data)
537    {
538    case X_kbUseExtension:
539	return SProcXkbUseExtension(client);
540    case X_kbSelectEvents:
541	return SProcXkbSelectEvents(client);
542    case X_kbBell:
543	return SProcXkbBell(client);
544    case X_kbGetState:
545	return SProcXkbGetState(client);
546    case X_kbLatchLockState:
547	return SProcXkbLatchLockState(client);
548    case X_kbGetControls:
549	return SProcXkbGetControls(client);
550    case X_kbSetControls:
551	return SProcXkbSetControls(client);
552    case X_kbGetMap:
553	return SProcXkbGetMap(client);
554    case X_kbSetMap:
555	return SProcXkbSetMap(client);
556    case X_kbGetCompatMap:
557	return SProcXkbGetCompatMap(client);
558    case X_kbSetCompatMap:
559	return SProcXkbSetCompatMap(client);
560    case X_kbGetIndicatorState:
561	return SProcXkbGetIndicatorState(client);
562    case X_kbGetIndicatorMap:
563	return SProcXkbGetIndicatorMap(client);
564    case X_kbSetIndicatorMap:
565	return SProcXkbSetIndicatorMap(client);
566    case X_kbGetNamedIndicator:
567	return SProcXkbGetNamedIndicator(client);
568    case X_kbSetNamedIndicator:
569	return SProcXkbSetNamedIndicator(client);
570    case X_kbGetNames:
571	return SProcXkbGetNames(client);
572    case X_kbSetNames:
573	return SProcXkbSetNames(client);
574    case X_kbGetGeometry:
575	return SProcXkbGetGeometry(client);
576    case X_kbSetGeometry:
577	return SProcXkbSetGeometry(client);
578    case X_kbPerClientFlags:
579	return SProcXkbPerClientFlags(client);
580    case X_kbListComponents:
581	return SProcXkbListComponents(client);
582    case X_kbGetKbdByName:
583	return SProcXkbGetKbdByName(client);
584    case X_kbGetDeviceInfo:
585	return SProcXkbGetDeviceInfo(client);
586    case X_kbSetDeviceInfo:
587	return SProcXkbSetDeviceInfo(client);
588    case X_kbSetDebuggingFlags:
589	return SProcXkbSetDebuggingFlags(client);
590    default:
591	return BadRequest;
592    }
593}
594