1 /*
2  * Copyright 1992 Network Computing Devices
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of NCD. not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  NCD. makes no representations about the
11  * suitability of this software for any purpose.  It is provided "as is"
12  * without express or implied warranty.
13  *
14  * NCD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NCD.
16  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  *
21  * Author:  Keith Packard, Network Computing Devices
22  */
23 
24 #include <stdio.h>
25 #include <X11/X.h>
26 #include <X11/Xproto.h>
27 #define _XLBX_SERVER_
28 #include "scope.h"
29 #include "x11.h"
30 #include "lbxscope.h"
31 #include "extensions.h"
32 
33 static unsigned char LBXRequest, LBXError;
34 unsigned char LBXEvent;         /* exported for DecodeEvent in decode11.c */
35 
36 static void
lbx_decode_req(FD fd,const unsigned char * buf)37 lbx_decode_req(FD fd, const unsigned char *buf)
38 {
39     short Major = IByte(&buf[0]);
40     short Minor = IByte(&buf[1]);
41 
42     switch (Minor) {
43     case 0:
44         LbxQueryVersion(fd, buf);
45         ExtendedReplyExpected(fd, Major, Minor);
46         break;
47     case 1:
48         LbxStartProxy(fd, buf);
49         break;
50     case 2:
51         LbxStopProxy(fd, buf);
52         break;
53     case 3:
54         LbxSwitch(fd, buf);
55         break;
56     case 4:
57         LbxNewClient(fd, buf);
58         break;
59     case 5:
60         LbxCloseClient(fd, buf);
61         break;
62     case 6:
63         LbxModifySequence(fd, buf);
64         break;
65     default:
66         break;
67     }
68 }
69 
70 static void
lbx_decode_reply(FD fd,const unsigned char * buf,short RequestMinor)71 lbx_decode_reply(FD fd, const unsigned char *buf, short RequestMinor)
72 {
73     switch (RequestMinor) {
74     case 0:
75         LbxQueryVersionReply(fd, buf);
76         break;
77     default:
78         break;
79     }
80 }
81 
82 static void
lbx_decode_error(FD fd,const unsigned char * buf)83 lbx_decode_error(FD fd, const unsigned char *buf)
84 {
85     short error = IByte(&buf[1]) - LBXError;
86 
87     switch (error) {
88     case 0:
89         break;
90     default:
91         break;
92     }
93 }
94 
95 static void
lbx_decode_event(FD fd,const unsigned char * buf)96 lbx_decode_event(FD fd, const unsigned char *buf)
97 {
98     short event = IByte(&buf[0]) - LBXEvent;
99 
100     switch (event) {
101     case 0:
102         LbxSwitchEvent(fd, buf);
103         break;
104     case 1:
105         LbxCloseEvent(fd, buf);
106         break;
107     default:
108         break;
109     }
110 }
111 
112 void
InitializeLBX(const unsigned char * buf)113 InitializeLBX(const unsigned char *buf)
114 {
115     TYPE p;
116 
117     LBXRequest = (unsigned char) (buf[9]);
118     LBXEvent = (unsigned char) (buf[10]);
119     LBXError = (unsigned char) (buf[11]);
120 
121     DefineEValue(&TD[REQUEST], (unsigned long) LBXRequest, "LbxRequest");
122     DefineEValue(&TD[REPLY], (unsigned long) LBXRequest, "LbxReply");
123     DefineEValue(&TD[EVENT], (unsigned long) LBXEvent, "LbxEvent");
124     DefineEValue(&TD[ERROR], (unsigned long) LBXError, "LbxError");
125 
126     p = DefineType(LBXREQUEST, ENUMERATED, "LBXREQUEST",
127                    (PrintProcType) PrintENUMERATED);
128     DefineEValue(p, 0L, "QueryVersion");
129     DefineEValue(p, 1L, "StartProxy");
130     DefineEValue(p, 2L, "StopProxy");
131     DefineEValue(p, 3L, "Switch");
132     DefineEValue(p, 4L, "NewClient");
133     DefineEValue(p, 5L, "CloseClient");
134     DefineEValue(p, 6L, "ModifySequence");
135 
136     p = DefineType(LBXREPLY, ENUMERATED, "LBXREPLY",
137                    (PrintProcType) PrintENUMERATED);
138     DefineEValue(p, 0L, "QueryVersion");
139 
140     p = DefineType(LBXEVENT, ENUMERATED, "LBXEVENT",
141                    (PrintProcType) PrintENUMERATED);
142     DefineEValue(p, 0L, "SwitchEvent");
143     DefineEValue(p, 1L, "CloseEvent");
144 
145     InitializeExtensionDecoder(LBXRequest, lbx_decode_req, lbx_decode_reply);
146     InitializeExtensionErrorDecoder(LBXError, lbx_decode_error);
147     InitializeExtensionEventDecoder(LBXEvent, lbx_decode_event);
148 }
149