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 "scope.h"
25 #include "x11.h"
26 #include "lbxscope.h"
27 
28 static unsigned long sequences[256];
29 static unsigned char starting_server[256];
30 static unsigned char starting_client[256];
31 static int client_client;
32 
33 void
LbxQueryVersion(FD fd,const unsigned char * buf)34 LbxQueryVersion(FD fd, const unsigned char *buf)
35 {
36     PrintField(buf, 0, 1, REQUEST, REQUESTHEADER); /* LbxRequest */
37     PrintField(buf, 1, 1, LBXREQUEST, LBXREQUESTHEADER); /* LbxSwitch */
38     if (Verbose < 1)
39         return;
40     if (Verbose > 1)
41         PrintField(SBf, 0, 4, CARD32, "sequence number");
42 
43     printreqlen(buf, fd, CONST2(2));
44 }
45 
46 void
LbxQueryVersionReply(FD fd,const unsigned char * buf)47 LbxQueryVersionReply(FD fd, const unsigned char *buf)
48 {
49     PrintField(RBf, 0, 1, REPLY, REPLYHEADER); /* LbxRequest reply */
50     PrintField(RBf, 1, 1, LBXREPLY,
51                LBXREPLYHEADER); /* LbxQueryVersion reply */
52     if (Verbose < 1)
53         return;
54     printfield(buf, 2, 2, CARD16, "sequence number");
55     printfield(buf, 4, 4, DVALUE4(0), "reply length");
56     PrintField(buf, 8, 2, CARD16, "major-version");
57     PrintField(buf, 10, 2, CARD16, "minor-version");
58 }
59 
60 void
LbxStartProxy(FD fd,const unsigned char * buf)61 LbxStartProxy(FD fd, const unsigned char *buf)
62 {
63     PrintField(buf, 0, 1, REQUEST, REQUESTHEADER); /* LbxRequest */
64     PrintField(buf, 1, 1, LBXREQUEST, LBXREQUESTHEADER); /* LbxSwitch */
65     if (Verbose < 1)
66         return;
67     if (Verbose > 1)
68         PrintField(SBf, 0, 4, CARD32, "sequence number");
69 
70     printreqlen(buf, fd, CONST2(2));
71 }
72 
73 void
LbxStopProxy(FD fd,const unsigned char * buf)74 LbxStopProxy(FD fd, const unsigned char *buf)
75 {
76     PrintField(buf, 0, 1, REQUEST, REQUESTHEADER); /* LbxRequest */
77     PrintField(buf, 1, 1, LBXREQUEST, LBXREQUESTHEADER); /* LbxSwitch */
78     if (Verbose < 1)
79         return;
80     if (Verbose > 1)
81         PrintField(SBf, 0, 4, CARD32, "sequence number");
82 
83     printreqlen(buf, fd, CONST2(2));
84 }
85 
86 void
LbxNewClient(FD fd,const unsigned char * buf)87 LbxNewClient(FD fd, const unsigned char *buf)
88 {
89     unsigned long c;
90 
91     c = ILong(&buf[4]);
92     starting_client[c] = 1;
93     starting_server[c] = 1;
94     sequences[c] = 0;
95 
96     PrintField(buf, 0, 1, REQUEST, REQUESTHEADER); /* LbxRequest */
97     PrintField(buf, 1, 1, LBXREQUEST, LBXREQUESTHEADER); /* LbxSwitch */
98     if (Verbose < 1)
99         return;
100     if (Verbose > 1)
101         PrintField(SBf, 0, 4, CARD32, "sequence number");
102 
103     printreqlen(buf, fd, CONST2(2));
104     PrintField(buf, 4, 4, CARD32, "new-client-id");
105 }
106 
107 void
LbxCloseClient(FD fd,const unsigned char * buf)108 LbxCloseClient(FD fd, const unsigned char *buf)
109 {
110 }
111 
112 void
LbxSwitch(FD fd,const unsigned char * buf)113 LbxSwitch(FD fd, const unsigned char *buf)
114 {
115     unsigned long c;
116 
117     c = ILong(&buf[4]);
118     CS[fd].SequenceNumber--;
119     sequences[client_client] = CS[fd].SequenceNumber;
120     if (starting_client[c]) {
121         CS[fd].ByteProcessing = StartSetUpMessage;
122         CS[fd].NumberofBytesNeeded = 12;
123         starting_client[c] = 0;
124     }
125     CS[fd].SequenceNumber = sequences[c];
126     client_client = c;
127 
128     PrintField(buf, 0, 1, REQUEST, REQUESTHEADER); /* LbxRequest */
129     PrintField(buf, 1, 1, LBXREQUEST, LBXREQUESTHEADER); /* LbxSwitch */
130     if (Verbose < 1)
131         return;
132     if (Verbose > 1)
133         PrintField(SBf, 0, 4, CARD32, "sequence number");
134 
135     printreqlen(buf, fd, CONST2(2));
136     PrintField(buf, 4, 4, CARD32, "client number");
137 }
138 
139 void
LbxModifySequence(FD fd,const unsigned char * buf)140 LbxModifySequence(FD fd, const unsigned char *buf)
141 {
142     int mod;
143 
144     mod = ILong(&buf[4]);
145     CS[fd].SequenceNumber += mod;
146 
147     PrintField(buf, 0, 1, REQUEST, REQUESTHEADER); /* LbxRequest */
148     PrintField(buf, 1, 1, LBXREQUEST,
149                LBXREQUESTHEADER); /* LbxModifySequence */
150     if (Verbose < 1)
151         return;
152     if (Verbose > 1)
153         PrintField(SBf, 0, 4, CARD32, "sequence number");
154 
155     printreqlen(buf, fd, CONST2(2));
156     printfield(buf, 4, 4, INT32, "adjustment");
157 }
158 
159 void
LbxSwitchEvent(FD fd,const unsigned char * buf)160 LbxSwitchEvent(FD fd, const unsigned char *buf)
161 {
162     unsigned long c;
163 
164     c = ILong(&buf[4]);
165     if (starting_server[c]) {
166         CS[fd].ByteProcessing = StartSetUpReply;
167         CS[fd].NumberofBytesNeeded = 8;
168         starting_server[c] = 0;
169     }
170 
171     PrintField(buf, 0, 1, EVENT, EVENTHEADER); /* LbxEvent */
172     PrintField(buf, 1, 1, LBXEVENT, LBXEVENTHEADER); /* LbxSwitchEvent */
173     if (Verbose < 1)
174         return;
175     printfield(buf, 2, 2, CARD16, "sequence number");
176     PrintField(buf, 4, 4, CARD32, "client");
177 }
178 
179 void
LbxCloseEvent(FD fd,const unsigned char * buf)180 LbxCloseEvent(FD fd, const unsigned char *buf)
181 {
182     PrintField(buf, 0, 1, EVENT, EVENTHEADER); /* LbxEvent */
183     PrintField(buf, 1, 1, LBXEVENT, LBXEVENTHEADER); /* LbxSwitchEvent */
184     if (Verbose < 1)
185         return;
186     printfield(buf, 2, 2, CARD16, "sequence number");
187     PrintField(buf, 4, 4, CARD32, "client");
188 }
189