aboutsummaryrefslogtreecommitdiff
path: root/doc/nx-X11_vs_XOrg69_patches/ConnDis.c.NX.patch
blob: 17f05497017aef4e221e2f38eac21b75db41f44d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
--- ./nx-X11/lib/X11/ConnDis.c.X.original	2015-02-13 14:03:44.620443950 +0100
+++ ./nx-X11/lib/X11/ConnDis.c	2015-02-10 19:13:13.008715687 +0100
@@ -25,6 +25,24 @@
 in this Software without prior written authorization from The Open Group.
 
 */
+
+/**************************************************************************/
+/*                                                                        */
+/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/.         */
+/*                                                                        */
+/* NX-X11, NX protocol compression and NX extensions to this software     */
+/* are copyright of NoMachine. Redistribution and use of the present      */
+/* software is allowed according to terms specified in the file LICENSE   */
+/* which comes in the source distribution.                                */
+/*                                                                        */
+/* Check http://www.nomachine.com/licensing.html for applicability.       */
+/*                                                                        */
+/* NX and NoMachine are trademarks of Medialogic S.p.A.                   */
+/*                                                                        */
+/* All rights reserved.                                                   */
+/*                                                                        */
+/**************************************************************************/
+
 /* $XFree86: xc/lib/X11/ConnDis.c,v 3.28 2003/12/02 23:33:17 herrb Exp $ */
 
 /* 
@@ -162,6 +180,39 @@
     saddrlen = 0;			/* set so that we can clear later */
     saddr = NULL;
 
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+        fprintf(stderr, "_X11TransConnectDisplay: Called with display_name [%s].\n", display_name);
+#endif
+
+#ifdef NX_TRANS_SOCKET
+
+    /*
+     * Check if user selected the "nx"
+     * protocol or an "nx" hostname.
+     */
+
+    if (!strncasecmp(p, "nx/", 3) || !strcasecmp(p, "nx") ||
+            !strncasecmp(p, "nx:", 3) || !strncasecmp(p, "nx,", 3))
+    {
+        if (*(display_name + 2) == '/')
+        {
+          p += 3;
+        }
+
+        pprotocol = copystring ("nx", 2);
+
+        if (!pprotocol) goto bad;
+
+#ifdef NX_TRANS_TEST
+        fprintf(stderr, "_X11TransConnectDisplay: Forced protocol to [%s].\n", pprotocol);
+#endif
+
+    }
+    else
+    {
+
+#endif
+
     /*
      * Step 0, find the protocol.  This is delimited by the optional 
      * slash ('/').
@@ -176,6 +227,60 @@
     } else
 	p = display_name;		/* reset the pointer in
 					   case no protocol was given */
+#ifdef NX_TRANS_SOCKET
+
+    } /* End of step 0. */
+
+    /*
+     * Check if user specified the "nx" protocol or
+     * hostname is "nx" or in the form "nx,...".
+     */
+
+    if (pprotocol && !strcasecmp(pprotocol, "nx"))
+    {
+
+#ifdef NX_TRANS_TEST
+        fprintf(stderr, "_X11TransConnectDisplay: Checking hostname [%s].\n", p);
+#endif
+
+        /*
+         * Options can include a "display=" tuple so
+         * need to scan right to left.
+         */
+
+        lastp = p;
+        lastc = NULL;
+
+        for (; *p; p++)
+            if (*p == ':')
+                lastc = p;
+
+        /*
+         * Don't complain if no screen was provided.
+         */
+
+        if (lastc)
+        {
+            phostname = copystring (lastp, lastc - lastp);
+
+            p = lastc;
+        }
+        else
+        {
+            phostname = copystring (lastp, strlen(lastp));
+        }
+
+        if (!phostname) goto bad;
+
+#ifdef NX_TRANS_TEST
+        fprintf(stderr, "_X11TransConnectDisplay: Forced hostname [%s].\n", phostname);
+#endif
+
+    }
+    else
+    {
+
+#endif
 
     /*
      * Step 1, find the hostname.  This is delimited by either one colon,
@@ -240,6 +345,20 @@
     }
 #endif
 
+#ifdef NX_TRANS_SOCKET
+
+    } /* End of step 1. */
+
+    /*
+     * Check if no display was specified. In this case
+     * search the "port=n" option in NX host string.
+     */
+
+    if (*p)
+    {
+
+#endif
+
 
     /*
      * Step 2, find the display number.  This field is required and is 
@@ -254,6 +373,66 @@
       goto bad;
     idisplay = atoi (pdpynum);
 
+#ifdef NX_TRANS_SOCKET
+
+    }
+    else
+    {
+        char *host  = NULL;
+        char *name  = NULL;
+        char *value = NULL;
+
+#ifdef NX_TRANS_TEST
+        fprintf(stderr, "_X11TransConnectDisplay: Searching port in port [%s].\n", phostname);
+#endif
+
+        if (!strncasecmp(phostname, "nx,", 3))
+        {
+            host = copystring(phostname + 3, strlen(phostname) - 3);
+        }
+
+        if (!host) goto bad;
+
+        idisplay = -1;
+
+        name = strtok(host, "=");
+
+        while (name)
+        {
+            value = strtok(NULL, ",");
+
+            if (value == NULL || strstr(value, "=") != NULL ||
+                    strstr(name, ",") != NULL || strlen(value) >= 128)
+            {
+                Xfree(host);
+
+                goto bad;
+            }
+            else if (strcasecmp(name, "port") == 0)
+            {
+                idisplay = atoi(value);
+
+                pdpynum = copystring(value, strlen(value));
+
+                if (!pdpynum) goto bad;
+
+                break;
+            }
+
+            name = strtok(NULL, "=");
+        }
+
+        Xfree(host);
+
+        if (idisplay == -1)
+        {
+            goto bad;
+        }
+
+    } /* End of step 2. */
+
+#endif
+
 
     /*
      * Step 3, find the screen number.  This field is optional.  It is 
@@ -286,6 +465,27 @@
      * is "unix", then choose BSD UNIX domain sockets (if configured).
      */
 
+#ifdef NX_TRANS_SOCKET
+
+    /*
+     * If user selected the "nx" protocol
+     * force "local" transport.
+     */
+
+    if (pprotocol && !strcasecmp(pprotocol, "nx"))
+    {
+        pprotocol = copystring ("local", 5);
+
+        if (!pprotocol) goto bad;
+
+#ifdef NX_TRANS_TEST
+        fprintf(stderr, "_X11TransConnectDisplay: Converted protocol to [%s].\n", pprotocol);
+#endif
+
+    }
+
+#endif
+
 #if defined(TCPCONN) || defined(UNIXCONN) || defined(LOCALCONN) || defined(MNX_TCPCONN) || defined(OS2PIPECONN)
     if (!pprotocol) {
 	if (!phostname) {
@@ -358,14 +558,26 @@
      * being a server listening at all, which is why we have to not retry
      * too many times).
      */
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+        fprintf(stderr, "_X11TransConnectDisplay: Entering connection loop.\n");
+#endif
     for(retry=X_CONNECTION_RETRIES; retry>=0; retry-- )
 	{
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+        fprintf(stderr, "_X11TransConnectDisplay: Going to call _X11TransOpenCOTSClient(address) with address [%s].\n", address);
+#endif
 	if ( (trans_conn = _X11TransOpenCOTSClient(address)) == NULL )
 	    {
 	    break;
 	    }
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+        fprintf(stderr, "_X11TransConnectDisplay: Going to call _X11TransConnect(trans_conn,address).\n");
+#endif
 	if ((connect_stat = _X11TransConnect(trans_conn,address)) < 0 )
 	    {
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+            fprintf(stderr, "_X11TransConnectDisplay: Going to call _X11TransClose(trans_conn).\n");
+#endif
 	    _X11TransClose(trans_conn);
 	    trans_conn = NULL;
 
@@ -378,6 +590,9 @@
 		break;
 	    }
 
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+        fprintf(stderr, "_X11TransConnectDisplay: Going to call _X11TransGetPeerAddr(trans_conn, &family, &saddrlen, &saddr).\n");
+#endif
 	_X11TransGetPeerAddr(trans_conn, &family, &saddrlen, &saddr);
 
 	/*
@@ -386,6 +601,9 @@
 	 * X protocol (ie FamilyInternet).
 	 */
 
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+        fprintf(stderr, "_X11TransConnectDisplay: Going to call _X11TransConvertAddress(&family, &saddrlen, &saddr).\n");
+#endif
 	if( _X11TransConvertAddress(&family, &saddrlen, &saddr) < 0 )
 	    {
 	    _X11TransClose(trans_conn);
@@ -402,6 +620,9 @@
 	break;
 	}
 
+#if defined(NX_TRANS_SOCKET) && defined(NX_TRANS_TEST)
+        fprintf(stderr, "_X11TransConnectDisplay: Out of connection loop.\n");
+#endif
     if (address != addrbuf) Xfree (address);
     address = addrbuf;
 
@@ -570,6 +791,17 @@
 
     if (len != 0)
 	return -1;
+#ifdef NX_TRANS_SOCKET
+    if (_NXDisplayWriteFunction != NULL) {
+        (*_NXDisplayWriteFunction)(dpy, len);
+    }
+#ifdef NX_TRANS_CHANGE
+    if (_NXDisplayCongestionFunction != NULL &&
+            _X11TransSocketCongestionChange(dpy->trans_conn, &congestion) == 1) {
+        (*_NXDisplayCongestionFunction)(dpy, congestion);
+    }
+#endif
+#endif
 
 #ifdef K5AUTH
     if (auth_length == 14 &&