1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 05_x11vnc.patch by Stéphane Graber <stgraber@ubuntu.com>
4
## All lines beginning with `## DP:' are a description of the patch.
5
## DP: Update X11VNC to fix tight encoding crash
8
Index: ../ica/src/ivs.cpp
9
===================================================================
10
--- ../ica/src/ivs.cpp (Revision 401)
11
+++ ../ica/src/ivs.cpp (Arbeitskopie)
17
cmdline << "-dbg";// << "-o" << "/tmp/italc_client_x11vnc.log";
20
char * old_av = m_argv[0];
21
m_argv = new char *[cmdline.size()+1];
22
Index: ../ica/x11/x11vnc/userinput.c
23
===================================================================
24
--- ../ica/x11/x11vnc/userinput.c (Revision 401)
25
+++ ../ica/x11/x11vnc/userinput.c (Arbeitskopie)
27
if (cmap8to24 && cmap8to24_fb) {
28
use_fb = cmap8to24_fb;
33
+ } else if (depth <= 16) {
38
@@ -1882,9 +1884,14 @@
41
if (0) fprintf(stderr, "copyrect: cmap8to24_fb: mode=%d\n", mode);
42
- if (cmap8to24 && depth == 8) {
44
- stride = 4 * stride0;
48
+ stride = 4 * stride0;
49
+ } else if (depth <= 16) {
51
+ stride = 2 * stride0;
54
dst = cmap8to24_fb + y1*stride + x1*Bpp;
55
src = cmap8to24_fb + (y1-dy)*stride + (x1-dx)*Bpp;
56
@@ -3566,6 +3573,17 @@
60
+ if (advertise_truecolor && advertise_truecolor_reset && indexed_color) {
61
+ /* this will reset framebuffer to correct colors, if needed */
64
+ if (now > last_client + 1.0 && now < last_client + 3.0 && now > dlast + 5.0) {
65
+ rfbLog("advertise truecolor reset framebuffer\n");
73
static int wireframe_mod_state() {
74
@@ -8083,8 +8101,12 @@
76
if (cmap8to24 && cmap8to24_fb) {
77
src_fb = cmap8to24_fb;
78
- if (scaling && depth == 8) {
83
+ } else if (depth <= 16) {
89
Index: ../ica/x11/x11vnc/options.h
90
===================================================================
91
--- ../ica/x11/x11vnc/options.h (Revision 401)
92
+++ ../ica/x11/x11vnc/options.h (Arbeitskopie)
94
extern int flash_cmap;
95
extern int shift_cmap;
96
extern int force_indexed_color;
97
+extern int advertise_truecolor;
98
+extern int advertise_truecolor_reset;
100
extern char *cmap8to24_str;
101
extern int xform24to32;
103
extern int using_shm;
104
extern int flip_byte_order;
106
+extern int got_waitms;
107
extern double wait_ui;
108
extern double slow_fb;
109
extern double xrefresh;
110
Index: ../ica/x11/x11vnc/xinerama.c
111
===================================================================
112
--- ../ica/x11/x11vnc/xinerama.c (Revision 401)
113
+++ ../ica/x11/x11vnc/xinerama.c (Arbeitskopie)
118
+static int did_xinerama_clip = 0;
120
+void check_xinerama_clip(void) {
121
+#if LIBVNCSERVER_HAVE_LIBXINERAMA
122
+ int n, k, i, ev, er, juse = -1;
123
+ int score[32], is = 0;
124
+ XineramaScreenInfo *x;
126
+ if (!clip_str || !dpy) {
129
+ if (sscanf(clip_str, "xinerama%d", &k) == 1) {
131
+ } else if (sscanf(clip_str, "screen%d", &k) == 1) {
140
+ if (! XineramaQueryExtension(dpy, &ev, &er)) {
143
+ if (! XineramaIsActive(dpy)) {
146
+ x = XineramaQueryScreens(dpy, &n);
147
+ if (k < 0 || k >= n) {
151
+ for (i=0; i < n; i++) {
152
+ score[is++] = nabs(x[i].x_org) + nabs(x[i].y_org);
157
+ for (i=0; i <= k; i++) {
158
+ int j, jmon, mon = -1, mox = -1;
159
+ for (j=0; j < is; j++) {
160
+ if (mon < 0 || score[j] < mon) {
164
+ if (mox < 0 || score[j] > mox) {
169
+ score[juse] = mox+1+i;
172
+ if (juse >= 0 && juse < n) {
174
+ sprintf(str, "%dx%d+%d+%d", x[juse].width, x[juse].height,
175
+ x[juse].x_org, x[juse].y_org);
176
+ clip_str = strdup(str);
177
+ did_xinerama_clip = 1;
179
+ clip_str = strdup("");
183
+ rfbLog("set -clip to '%s' for xinerama%d\n", clip_str, k);
188
static void initialize_xinerama (void) {
189
#if !LIBVNCSERVER_HAVE_LIBXINERAMA
190
rfbLog("Xinerama: Library libXinerama is not available to determine\n");
191
@@ -263,19 +333,19 @@
193
rfbLog("Xinerama is present and active (e.g. multi-head).\n");
195
- if (! use_xwarppointer && ! got_noxwarppointer) {
196
+ /* n.b. change to XineramaGetData() someday */
197
+ xineramas = XineramaQueryScreens(dpy, &n);
199
+ rfbLog("Xinerama: number of sub-screens: %d\n", n);
202
+ if (! use_xwarppointer && ! got_noxwarppointer && n > 1) {
203
rfbLog("Xinerama: enabling -xwarppointer mode to try to correct\n");
204
rfbLog("Xinerama: mouse pointer motion. XTEST+XINERAMA bug.\n");
205
rfbLog("Xinerama: Use -noxwarppointer to force XTEST.\n");
206
use_xwarppointer = 1;
209
- /* n.b. change to XineramaGetData() someday */
210
- xineramas = XineramaQueryScreens(dpy, &n);
212
- rfbLog("Xinerama: number of sub-screens: %d\n", n);
217
rfbLog("Xinerama: no blackouts needed (only one"
223
if (sraRgnEmpty(black_region)) {
224
rfbLog("Xinerama: no blackouts needed (screen fills"
227
sraRgnDestroy(black_region);
230
+ if (did_xinerama_clip) {
231
+ rfbLog("Xinerama: no blackouts due to -clip xinerama.\n");
235
/* max len is 10000x10000+10000+10000 (23 chars) per geometry */
236
rcnt = (int) sraRgnCountRects(black_region);
237
Index: ../ica/x11/x11vnc/user.c
238
===================================================================
239
--- ../ica/x11/x11vnc/user.c (Revision 401)
240
+++ ../ica/x11/x11vnc/user.c (Arbeitskopie)
241
@@ -1094,7 +1094,6 @@
244
static void handle_one_http_request(void) {
246
rfbLog("handle_one_http_request: begin.\n");
247
if (inetd || screen->httpPort == 0) {
248
int port = find_free_port(5800, 5860);
249
@@ -1111,7 +1110,7 @@
251
rfbInitServer(screen);
257
if (0) fprintf(stderr, "%d %d %d %d\n", conn, screen->listenSock, screen->httpSock, screen->httpListenSock);
258
@@ -1136,6 +1135,7 @@
259
rfbLog("handle_one_http_request: finished.\n");
263
#if LIBVNCSERVER_HAVE_FORK
265
int s_in = screen->inetdSock;
266
@@ -1147,7 +1147,6 @@
268
rfbLog("handle_one_http_request: could not fork.\n");
271
} else if (pid > 0) {
274
@@ -1162,7 +1161,6 @@
276
rfbLog("handle_one_http_request: finished.\n");
280
int sock = rfbConnectToTcpAddr("127.0.0.1",
282
@@ -1322,149 +1320,20 @@
286
-extern char find_display[];
287
-extern char create_display[];
288
-static XImage ximage_struct;
289
+static void do_chvt(int vt) {
291
+ sprintf(chvt, "chvt %d >/dev/null 2>/dev/null &", vt);
292
+ rfbLog("running: %s\n", chvt);
297
-int wait_for_client(int *argc, char** argv, int http) {
299
- int w = 640, h = 480, b = 32;
300
- int w0, h0, i, chg_raw_fb = 0;
301
- char *str, *q, *cmd = NULL;
303
- char tmp[] = "/tmp/x11vnc-find_display.XXXXXX";
304
- int tmp_fd = -1, dt = 0;
305
- char *create_cmd = NULL;
306
- char *users_list_save = NULL;
307
- int created_disp = 0;
309
- int did_client_connect = 0;
312
- char *vnc_redirect_host = "localhost";
313
- int vnc_redirect_port = -1;
314
- int vnc_redirect_cnt = 0;
315
- char vnc_redirect_test[10];
319
- if (! use_dpy || strstr(use_dpy, "WAIT:") != use_dpy) {
323
- if (getenv("WAIT_FOR_CLIENT_DB")) {
327
- for (i=0; i < *argc; i++) {
328
- if (!strcmp(argv[i], "-desktop")) {
331
- if (db) fprintf(stderr, "args %d %s\n", i, argv[i]);
333
- if (!quiet && !strstr(use_dpy, "FINDDISPLAY-run")) {
334
- rfbLog("wait_for_client: %s\n", use_dpy);
337
- str = strdup(use_dpy);
338
- str += strlen("WAIT");
340
- xdmcp_insert = NULL;
342
- /* get any leading geometry: */
343
- q = strchr(str+1, ':');
346
- if (sscanf(str+1, "%dx%d", &w0, &h0) == 2) {
349
- rfbLog("wait_for_client set: w=%d h=%d\n", w, h);
355
- /* str currently begins with a ':' */
356
- if (strstr(str, ":cmd=") == str) {
357
- /* cmd=/path/to/mycommand */
359
- } else if (strpbrk(str, "0123456789") == str+1) {
367
- if (db) fprintf(stderr, "str: %s\n", str);
369
- if (strstr(str, "cmd=") == str) {
370
- if (no_external_cmds || !cmd_ok("WAIT")) {
371
- rfbLog("wait_for_client external cmds not allowed:"
376
- cmd = str + strlen("cmd=");
377
- if (!strcmp(cmd, "FINDDISPLAY-print")) {
378
- fprintf(stdout, "%s", find_display);
381
- if (!strcmp(cmd, "FINDDISPLAY-run")) {
382
- char tmp[] = "/tmp/fd.XXXXXX";
384
- int fd = mkstemp(tmp);
386
- write(fd, find_display, strlen(find_display));
388
- set_env("FINDDISPLAY_run", "1");
389
- sprintf(com, "/bin/sh %s -n; rm -f %s", tmp, tmp);
395
- if (!strcmp(str, "FINDCREATEDISPLAY-print")) {
396
- fprintf(stdout, "%s", create_display);
399
- if (db) fprintf(stderr, "cmd: %s\n", cmd);
400
- if (strstr(str, "FINDCREATEDISPLAY") || strstr(str, "FINDDISPLAY")) {
401
- if (strstr(str, "Xvnc.redirect") || strstr(str, "X.redirect")) {
405
- if (strstr(cmd, "FINDDISPLAY-vnc_redirect") == cmd) {
408
- if (strlen(cmd) >= 256) {
409
- rfbLog("wait_for_client string too long: %s\n", str);
413
- if (sscanf(cmd, "FINDDISPLAY-vnc_redirect=%d", &p) == 1) {
415
- } else if (sscanf(cmd, "FINDDISPLAY-vnc_redirect=%s %d", h, &p) == 2) {
418
- rfbLog("wait_for_client bad string: %s\n", cmd);
421
- vnc_redirect_port = p;
422
- if (strcmp(h, "")) {
423
- vnc_redirect_host = strdup(h);
426
- rfbLog("wait_for_client: vnc_redirect: %s:%d\n", vnc_redirect_host, vnc_redirect_port);
430
+static void setup_fake_fb(XImage* fb_image, int w, int h, int b) {
434
fake_fb = (char *) calloc(w*h*b/8, 1);
436
- fb_image = &ximage_struct;
437
fb_image->data = fake_fb;
438
fb_image->format = ZPixmap;
440
@@ -1483,64 +1352,9 @@
448
- argv[*argc] = strdup("-desktop");
449
- *argc = (*argc) + 1;
453
- s = choose_title(":0");
454
- q = strstr(s, ":0");
459
- s = choose_title(str);
461
- rfb_desktop_name = strdup(s);
463
- *argc = (*argc) + 1;
466
- ncache_save = ncache;
469
- initialize_allowed_input();
471
- if (! multiple_cursors_mode) {
472
- multiple_cursors_mode = strdup("default");
474
- initialize_cursors_mode();
476
- initialize_screen(argc, argv, fb_image);
478
- initialize_signals();
480
- if (ssh_str != NULL) {
481
- ssh_remote_tunnel(ssh_str, screen->port);
486
- /* kludge to get RAWFB_RET with dpy == NULL guards */
487
- raw_fb = (char *) 0x1;
490
- if (cmd && !strcmp(cmd, "HTTPONCE")) {
491
- handle_one_http_request();
495
- if (http && check_httpdir()) {
496
- http_connections(1);
499
- if (cmd && unixpw) {
503
+static void setup_service(void) {
506
announce(screen->port, use_openssl, NULL);
507
@@ -1562,7 +1376,9 @@
509
avahi_advertise(name, this_host(), screen->port);
513
+static void check_waitbg(void) {
514
if (getenv("WAITBG")) {
515
#if LIBVNCSERVER_HAVE_FORK && LIBVNCSERVER_HAVE_SETSID
517
@@ -1594,91 +1410,9 @@
523
- if (vnc_redirect) {
525
- rfbLog("wait_for_client: -unixpw and Xvnc.redirect not allowed\n");
528
- if (client_connect) {
529
- rfbLog("wait_for_client: -connect and Xvnc.redirect not allowed\n");
534
- accept_openssl(OPENSSL_INETD, -1);
537
- if (first_conn_timeout) {
538
- if (first_conn_timeout < 0) {
539
- first_conn_timeout = -first_conn_timeout;
541
- signal(SIGALRM, vnc_redirect_timeout);
542
- alarm(first_conn_timeout);
545
- accept_openssl(OPENSSL_VNC, -1);
547
- struct sockaddr_in addr;
549
- int addrlen = sizeof(addr);
551
- socklen_t addrlen = sizeof(addr);
553
- if (screen->listenSock < 0) {
554
- rfbLog("wait_for_client: Xvnc.redirect not listening... sock=%d port=%d\n", screen->listenSock, screen->port);
557
- vnc_redirect_sock = accept(screen->listenSock, (struct sockaddr *)&addr, &addrlen);
559
- if (first_conn_timeout) {
563
- if (vnc_redirect_sock < 0) {
564
- rfbLog("wait_for_client: vnc_redirect failed.\n");
567
- if (!inetd && use_openssl) {
568
- /* check for Fetch Cert closing */
576
- FD_SET(vnc_redirect_sock, &rfds);
579
- tv.tv_usec = 200000;
580
- nfds = select(vnc_redirect_sock+1, &rfds, NULL, NULL, &tv);
582
- rfbLog("wait_for_client: vnc_redirect nfds: %d\n", nfds);
585
- n = read(vnc_redirect_sock, vnc_redirect_test, 1);
587
- close(vnc_redirect_sock);
588
- vnc_redirect_sock = -1;
589
- rfbLog("wait_for_client: waiting for 2nd connection (Fetch Cert?)\n");
590
- accept_openssl(OPENSSL_VNC, -1);
591
- if (vnc_redirect_sock < 0) {
592
- rfbLog("wait_for_client: vnc_redirect failed.\n");
596
- vnc_redirect_cnt = n;
600
- goto vnc_redirect_place;
603
- if (inetd && use_openssl) {
604
- accept_openssl(OPENSSL_INETD, -1);
607
+static void setup_client_connect(int *did_client_connect) {
608
if (client_connect != NULL) {
609
char *remainder = NULL;
611
@@ -1701,7 +1435,7 @@
612
rfbLog("wait_for_client: reverse_connect(%s)\n",
614
reverse_connect(client_connect);
615
- did_client_connect = 1;
616
+ *did_client_connect = 1;
618
free(client_connect);
619
if (remainder != NULL) {
620
@@ -1711,11 +1445,14 @@
621
client_connect = NULL;
626
+static void loop_for_connect(int did_client_connect) {
628
+ time_t start = time(NULL);
629
if (first_conn_timeout < 0) {
630
first_conn_timeout = -first_conn_timeout;
632
- start = time(NULL);
636
@@ -1789,16 +1526,19 @@
642
if (! screen || ! screen->clientHead) {
647
rfbLog("wait_for_client: got client\n");
653
+static void do_unixpw_loop(void) {
655
if (! unixpw_in_progress) {
656
rfbLog("unixpw but no unixpw_in_progress\n");
657
@@ -1808,12 +1548,6 @@
658
rfbLog("taking unixpw_client off hold.\n");
659
unixpw_client->onHold = FALSE;
661
- if (cmd && strstr(cmd, "FINDCREATEDISPLAY") == cmd) {
662
- if (users_list && strstr(users_list, "unixpw=") == users_list) {
663
- users_list_save = users_list;
670
@@ -1831,482 +1565,803 @@
678
- vnc_redirect_place:
680
- if (vnc_redirect == 2) {
689
- char *usslpeer = NULL;
691
- memset(line1, 0, 1024);
692
- memset(line2, 0, 16384);
694
- if (users_list && strstr(users_list, "sslpeer=") == users_list) {
696
- char *u = NULL, *upeer = NULL;
699
- char *q, *p, *str = strdup(certret_str);
700
- q = strstr(str, "Subject: ");
702
- p = strstr(q, "\n");
704
- q = strstr(q, "CN=");
706
- if (! getenv("X11VNC_SSLPEER_CN")) {
708
- q = strstr(q, "/emailAddress=");
709
- if (! q) q = strstr(p, "/Email=");
711
+static void vnc_redirect_loop(char *vnc_redirect_test, int *vnc_redirect_cnt) {
713
+ rfbLog("wait_for_client: -unixpw and Xvnc.redirect not allowed\n");
716
+ if (client_connect) {
717
+ rfbLog("wait_for_client: -connect and Xvnc.redirect not allowed\n");
722
+ accept_openssl(OPENSSL_INETD, -1);
726
+ if (screen->httpListenSock >= 0) {
727
+#if LIBVNCSERVER_HAVE_FORK
728
+ if ((pid = fork()) > 0) {
729
+ close(screen->httpListenSock);
730
+ screen->httpListenSock = -2;
731
+ usleep(500 * 1000);
733
+ close(screen->listenSock);
734
+ screen->listenSock = -1;
737
+ rfbHttpCheckFds(screen);
739
- q = strstr(q, "=");
742
- p = strstr(q, " ");
744
- p = strstr(q, "@");
746
- p = strstr(q, "/");
749
- if (strcmp(upeer, "")) {
751
- while (*p != '\0') {
753
- if (!isalnum((int) c)) {
759
- if (strcmp(upeer, "")) {
765
- if (! ok || !upeer) {
771
+ if (first_conn_timeout) {
772
+ if (first_conn_timeout < 0) {
773
+ first_conn_timeout = -first_conn_timeout;
775
- rfbLog("sslpeer unix username extracted from x509 cert: %s\n", upeer);
776
- u = (char *) malloc(strlen(upeer+2));
778
- if (!strcmp(users_list, "sslpeer=")) {
779
- sprintf(u, "+%s", upeer);
780
+ signal(SIGALRM, vnc_redirect_timeout);
781
+ alarm(first_conn_timeout);
786
+ accept_openssl(OPENSSL_VNC, -1);
788
- char *p, *str = strdup(users_list);
789
- p = strtok(str + strlen("sslpeer="), ",");
791
- if (!strcmp(p, upeer)) {
792
- sprintf(u, "+%s", upeer);
793
+ for (i=0; i < 16; i++) {
794
+ accept_openssl(OPENSSL_VNC, -1);
795
+ rfbLog("iter %d: vnc_redirect_sock: %d\n", i, vnc_redirect_sock);
796
+ if (vnc_redirect_sock >= 0) {
799
- p = strtok(NULL, ",");
803
- if (u[0] == '\0') {
804
- rfbLog("sslpeer cannot determine user: %s\n", upeer);
808
+ struct sockaddr_in addr;
810
+ int addrlen = sizeof(addr);
812
+ socklen_t addrlen = sizeof(addr);
814
+ if (screen->listenSock < 0) {
815
+ rfbLog("wait_for_client: Xvnc.redirect not listening... sock=%d port=%d\n", screen->listenSock, screen->port);
820
+ vnc_redirect_sock = accept(screen->listenSock, (struct sockaddr *)&addr, &addrlen);
822
+ if (first_conn_timeout) {
826
+#if LIBVNCSERVER_HAVE_FORK
829
+ rfbLog("wait_for_client: kill TERM: %d\n", (int) pid);
830
+ kill(pid, SIGTERM);
831
+ usleep(1000 * 1000); /* 1.0 sec */
832
+ pidw = waitpid(pid, &rc, WNOHANG);
834
+ usleep(1000 * 1000); /* 1.0 sec */
835
+ pidw = waitpid(pid, &rc, WNOHANG);
842
+ if (vnc_redirect_sock < 0) {
843
+ rfbLog("wait_for_client: vnc_redirect failed.\n");
846
+ if (!inetd && use_openssl) {
847
+ /* check for Fetch Cert closing */
852
- /* only sets environment variables: */
853
- run_user_command("", latest_client, "env", NULL, 0, NULL);
856
- if (program_name) {
857
- set_env("X11VNC_PROG", program_name);
859
- set_env("X11VNC_PROG", "x11vnc");
862
+ FD_SET(vnc_redirect_sock, &rfds);
864
- if (!strcmp(cmd, "FINDDISPLAY") ||
865
- strstr(cmd, "FINDCREATEDISPLAY") == cmd) {
867
- tmp_fd = mkstemp(tmp);
869
- rfbLog("wait_for_client: open failed: %s\n", tmp);
870
- rfbLogPerror("mkstemp");
874
- if (getenv("X11VNC_FINDDISPLAY_ALWAYS_FAILS")) {
875
- char *s = "#!/bin/sh\necho _FAIL_\nexit 1\n";
876
- write(tmp_fd, s, strlen(s));
878
+ tv.tv_usec = 200000;
879
+ nfds = select(vnc_redirect_sock+1, &rfds, NULL, NULL, &tv);
881
+ rfbLog("wait_for_client: vnc_redirect nfds: %d\n", nfds);
884
+ n = read(vnc_redirect_sock, vnc_redirect_test, 1);
886
+ close(vnc_redirect_sock);
887
+ vnc_redirect_sock = -1;
888
+ rfbLog("wait_for_client: waiting for 2nd connection (Fetch Cert?)\n");
889
+ accept_openssl(OPENSSL_VNC, -1);
890
+ if (vnc_redirect_sock < 0) {
891
+ rfbLog("wait_for_client: vnc_redirect failed.\n");
895
- write(tmp_fd, find_display, strlen(find_display));
896
+ *vnc_redirect_cnt = n;
904
- if (strstr(cmd, "FINDCREATEDISPLAY") == cmd) {
905
- char *opts = strchr(cmd, '-');
907
- char fdgeom[128], fdsess[128], fdopts[128], fdprog[128];
908
- char fdxsrv[128], fdxdum[128], fdcups[128], fdesd[128];
909
- char fdnas[128], fdsmb[128], fdtag[128];
912
- if (strstr(opts, "xdmcp")) {
918
- sprintf(fdgeom, "NONE");
930
+static void do_vnc_redirect(int created_disp, char *vnc_redirect_host, int vnc_redirect_port,
931
+ int vnc_redirect_cnt, char *vnc_redirect_test) {
932
+ char *q = strchr(use_dpy, ':');
933
+ int vdpy = -1, sock = -1;
934
+ int s_in, s_out, i;
935
+ if (vnc_redirect == 2) {
937
+ sprintf(num, ":%d", vnc_redirect_port);
941
+ rfbLog("wait_for_client: can't find number in X display: %s\n", use_dpy);
944
+ if (sscanf(q+1, "%d", &vdpy) != 1) {
945
+ rfbLog("wait_for_client: can't find number in X display: %s\n", q);
948
+ if (vdpy == -1 && vnc_redirect != 2) {
949
+ rfbLog("wait_for_client: can't find number in X display: %s\n", q);
952
+ if (vnc_redirect == 2) {
955
+ } else if (vdpy < 200) {
961
+ if (created_disp) {
964
+ for (i=0; i < 20; i++) {
965
+ sock = rfbConnectToTcpAddr(vnc_redirect_host, vdpy);
969
+ rfbLog("wait_for_client: ...\n");
973
+ rfbLog("wait_for_client: could not connect to a VNC Server at %s:%d\n", vnc_redirect_host, vdpy);
977
+ s_in = fileno(stdin);
978
+ s_out = fileno(stdout);
980
+ s_in = s_out = vnc_redirect_sock;
982
+ if (vnc_redirect_cnt > 0) {
983
+ write(vnc_redirect_sock, vnc_redirect_test, vnc_redirect_cnt);
985
+ rfbLog("wait_for_client: switching control to VNC Server at %s:%d\n", vnc_redirect_host, vdpy);
986
+ raw_xfer(sock, s_in, s_out);
989
- if (unixpw && keep_unixpw_opts && keep_unixpw_opts[0] != '\0') {
990
- char *q, *p, *t = strdup(keep_unixpw_opts);
991
- if (strstr(t, "gnome")) {
992
- sprintf(fdsess, "gnome");
993
- } else if (strstr(t, "kde")) {
994
- sprintf(fdsess, "kde");
995
- } else if (strstr(t, "twm")) {
996
- sprintf(fdsess, "twm");
997
- } else if (strstr(t, "fvwm")) {
998
- sprintf(fdsess, "fvwm");
999
- } else if (strstr(t, "mwm")) {
1000
- sprintf(fdsess, "mwm");
1001
- } else if (strstr(t, "cde")) {
1002
- sprintf(fdsess, "cde");
1003
- } else if (strstr(t, "dtwm")) {
1004
- sprintf(fdsess, "dtwm");
1005
- } else if (strstr(t, "xterm")) {
1006
- sprintf(fdsess, "xterm");
1007
- } else if (strstr(t, "wmaker")) {
1008
- sprintf(fdsess, "wmaker");
1009
- } else if (strstr(t, "xfce")) {
1010
- sprintf(fdsess, "xfce");
1011
- } else if (strstr(t, "enlightenment")) {
1012
- sprintf(fdsess, "enlightenment");
1013
- } else if (strstr(t, "Xsession")) {
1014
- sprintf(fdsess, "Xsession");
1015
- } else if (strstr(t, "failsafe")) {
1016
- sprintf(fdsess, "failsafe");
1018
+extern char find_display[];
1019
+extern char create_display[];
1021
- q = strstr(t, "ge=");
1022
- if (! q) q = strstr(t, "geom=");
1023
- if (! q) q = strstr(t, "geometry=");
1026
- q = strstr(q, "=");
1028
- p = strstr(q, ",");
1034
- } else if (isdigit((int) *p)) {
1042
- if (ok && strlen(q) < 32) {
1043
- sprintf(fdgeom, q);
1045
- rfbLog("set create display geom: %s\n", fdgeom);
1049
- q = strstr(t, "cups=");
1052
- if (sscanf(q, "cups=%d", &p) == 1) {
1053
- sprintf(fdcups, "%d", p);
1056
- q = strstr(t, "esd=");
1059
- if (sscanf(q, "esd=%d", &p) == 1) {
1060
- sprintf(fdesd, "%d", p);
1065
- if (fdgeom[0] == '\0' && getenv("FD_GEOM")) {
1066
- snprintf(fdgeom, 120, "%s", getenv("FD_GEOM"));
1068
- if (fdsess[0] == '\0' && getenv("FD_SESS")) {
1069
- snprintf(fdsess, 120, "%s", getenv("FD_SESS"));
1071
- if (fdopts[0] == '\0' && getenv("FD_OPTS")) {
1072
- snprintf(fdopts, 120, "%s", getenv("FD_OPTS"));
1074
- if (fdprog[0] == '\0' && getenv("FD_PROG")) {
1075
- snprintf(fdprog, 120, "%s", getenv("FD_PROG"));
1077
- if (fdxsrv[0] == '\0' && getenv("FD_XSRV")) {
1078
- snprintf(fdxsrv, 120, "%s", getenv("FD_XSRV"));
1080
- if (fdcups[0] == '\0' && getenv("FD_CUPS")) {
1081
- snprintf(fdcups, 120, "%s", getenv("FD_CUPS"));
1083
- if (fdesd[0] == '\0' && getenv("FD_ESD")) {
1084
- snprintf(fdesd, 120, "%s", getenv("FD_ESD"));
1086
- if (fdnas[0] == '\0' && getenv("FD_NAS")) {
1087
- snprintf(fdnas, 120, "%s", getenv("FD_NAS"));
1089
- if (fdsmb[0] == '\0' && getenv("FD_SMB")) {
1090
- snprintf(fdsmb, 120, "%s", getenv("FD_SMB"));
1092
- if (fdtag[0] == '\0' && getenv("FD_TAG")) {
1093
- snprintf(fdtag, 120, "%s", getenv("FD_TAG"));
1095
- if (fdxdum[0] == '\0' && getenv("FD_XDUMMY_NOROOT")) {
1096
- snprintf(fdxdum, 120, "%s", getenv("FD_XDUMMY_NOROOT"));
1098
+char *setup_cmd(char *str, int *vnc_redirect, char **vnc_redirect_host, int *vnc_redirect_port, int db) {
1101
+ if (no_external_cmds || !cmd_ok("WAIT")) {
1102
+ rfbLog("wait_for_client external cmds not allowed:"
1103
+ " %s\n", use_dpy);
1107
- set_env("FD_GEOM", fdgeom);
1108
- set_env("FD_OPTS", fdopts);
1109
- set_env("FD_PROG", fdprog);
1110
- set_env("FD_XSRV", fdxsrv);
1111
- set_env("FD_CUPS", fdcups);
1112
- set_env("FD_ESD", fdesd);
1113
- set_env("FD_NAS", fdnas);
1114
- set_env("FD_SMB", fdsmb);
1115
- set_env("FD_TAG", fdtag);
1116
- set_env("FD_XDUMMY_NOROOT", fdxdum);
1117
- set_env("FD_SESS", fdsess);
1118
+ cmd = str + strlen("cmd=");
1119
+ if (!strcmp(cmd, "FINDDISPLAY-print")) {
1120
+ fprintf(stdout, "%s", find_display);
1123
+ if (!strcmp(cmd, "FINDDISPLAY-run")) {
1124
+ char tmp[] = "/tmp/fd.XXXXXX";
1126
+ int fd = mkstemp(tmp);
1128
+ write(fd, find_display, strlen(find_display));
1130
+ set_env("FINDDISPLAY_run", "1");
1131
+ sprintf(com, "/bin/sh %s -n; rm -f %s", tmp, tmp);
1137
+ if (!strcmp(str, "FINDCREATEDISPLAY-print")) {
1138
+ fprintf(stdout, "%s", create_display);
1141
+ if (db) fprintf(stderr, "cmd: %s\n", cmd);
1142
+ if (strstr(str, "FINDCREATEDISPLAY") || strstr(str, "FINDDISPLAY")) {
1143
+ if (strstr(str, "Xvnc.redirect") || strstr(str, "X.redirect")) {
1144
+ *vnc_redirect = 1;
1147
+ if (strstr(cmd, "FINDDISPLAY-vnc_redirect") == cmd) {
1150
+ if (strlen(cmd) >= 256) {
1151
+ rfbLog("wait_for_client string too long: %s\n", str);
1155
+ if (sscanf(cmd, "FINDDISPLAY-vnc_redirect=%d", &p) == 1) {
1157
+ } else if (sscanf(cmd, "FINDDISPLAY-vnc_redirect=%s %d", h, &p) == 2) {
1160
+ rfbLog("wait_for_client bad string: %s\n", cmd);
1163
+ *vnc_redirect_port = p;
1164
+ if (strcmp(h, "")) {
1165
+ *vnc_redirect_host = strdup(h);
1167
+ *vnc_redirect = 2;
1168
+ rfbLog("wait_for_client: vnc_redirect: %s:%d\n", *vnc_redirect_host, *vnc_redirect_port);
1173
- if (usslpeer || (unixpw && keep_unixpw_user)) {
1174
- char *uu = usslpeer;
1176
- uu = keep_unixpw_user;
1178
- create_cmd = (char *) malloc(strlen(tmp)+1
1179
- + strlen("env USER='' ")
1180
- + strlen("FD_GEOM='' ")
1181
- + strlen("FD_OPTS='' ")
1182
- + strlen("FD_PROG='' ")
1183
- + strlen("FD_XSRV='' ")
1184
- + strlen("FD_CUPS='' ")
1185
- + strlen("FD_ESD='' ")
1186
- + strlen("FD_NAS='' ")
1187
- + strlen("FD_SMB='' ")
1188
- + strlen("FD_TAG='' ")
1189
- + strlen("FD_XDUMMY_NOROOT='' ")
1190
- + strlen("FD_SESS='' /bin/sh ")
1192
- + strlen(fdgeom) + 1
1193
- + strlen(fdopts) + 1
1194
- + strlen(fdprog) + 1
1195
- + strlen(fdxsrv) + 1
1196
- + strlen(fdcups) + 1
1197
- + strlen(fdesd) + 1
1198
- + strlen(fdnas) + 1
1199
- + strlen(fdsmb) + 1
1200
- + strlen(fdtag) + 1
1201
- + strlen(fdxdum) + 1
1202
- + strlen(fdsess) + 1
1203
- + strlen(opts) + 1);
1204
- sprintf(create_cmd, "env USER='%s' FD_GEOM='%s' FD_SESS='%s' "
1205
- "FD_OPTS='%s' FD_PROG='%s' FD_XSRV='%s' FD_CUPS='%s' "
1206
- "FD_ESD='%s' FD_NAS='%s' FD_SMB='%s' FD_TAG='%s' "
1207
- "FD_XDUMMY_NOROOT='%s' /bin/sh %s %s",
1208
- uu, fdgeom, fdsess, fdopts, fdprog, fdxsrv,
1209
- fdcups, fdesd, fdnas, fdsmb, fdtag, fdxdum, tmp, opts);
1210
+static char *build_create_cmd(char *cmd, int *saw_xdmcp, char *usslpeer, char *tmp) {
1211
+ char *create_cmd = NULL;
1212
+ char *opts = strchr(cmd, '-');
1214
+ char fdgeom[128], fdsess[128], fdopts[128], fdprog[128];
1215
+ char fdxsrv[128], fdxdum[128], fdcups[128], fdesd[128];
1216
+ char fdnas[128], fdsmb[128], fdtag[128];
1220
+ if (strstr(opts, "xdmcp")) {
1226
+ sprintf(fdgeom, "NONE");
1239
+ if (unixpw && keep_unixpw_opts && keep_unixpw_opts[0] != '\0') {
1240
+ char *q, *p, *t = strdup(keep_unixpw_opts);
1241
+ if (strstr(t, "gnome")) {
1242
+ sprintf(fdsess, "gnome");
1243
+ } else if (strstr(t, "kde")) {
1244
+ sprintf(fdsess, "kde");
1245
+ } else if (strstr(t, "twm")) {
1246
+ sprintf(fdsess, "twm");
1247
+ } else if (strstr(t, "fvwm")) {
1248
+ sprintf(fdsess, "fvwm");
1249
+ } else if (strstr(t, "mwm")) {
1250
+ sprintf(fdsess, "mwm");
1251
+ } else if (strstr(t, "cde")) {
1252
+ sprintf(fdsess, "cde");
1253
+ } else if (strstr(t, "dtwm")) {
1254
+ sprintf(fdsess, "dtwm");
1255
+ } else if (strstr(t, "xterm")) {
1256
+ sprintf(fdsess, "xterm");
1257
+ } else if (strstr(t, "wmaker")) {
1258
+ sprintf(fdsess, "wmaker");
1259
+ } else if (strstr(t, "xfce")) {
1260
+ sprintf(fdsess, "xfce");
1261
+ } else if (strstr(t, "enlightenment")) {
1262
+ sprintf(fdsess, "enlightenment");
1263
+ } else if (strstr(t, "Xsession")) {
1264
+ sprintf(fdsess, "Xsession");
1265
+ } else if (strstr(t, "failsafe")) {
1266
+ sprintf(fdsess, "failsafe");
1269
+ q = strstr(t, "ge=");
1270
+ if (! q) q = strstr(t, "geom=");
1271
+ if (! q) q = strstr(t, "geometry=");
1274
+ q = strstr(q, "=");
1276
+ p = strstr(q, ",");
1282
+ } else if (isdigit((int) *p)) {
1285
- create_cmd = (char *) malloc(strlen(tmp)
1286
- + strlen("/bin/sh ") + 1 + strlen(opts) + 1);
1287
- sprintf(create_cmd, "/bin/sh %s %s", tmp, opts);
1292
-if (db) fprintf(stderr, "create_cmd: %s\n", create_cmd);
1295
- if (getenv("X11VNC_SKIP_DISPLAY")) {
1296
- nd = strdup(getenv("X11VNC_SKIP_DISPLAY"));
1298
- if (unixpw && keep_unixpw_opts && keep_unixpw_opts[0] != '\0') {
1299
- char *q, *t = keep_unixpw_opts;
1300
- q = strstr(t, "nd=");
1301
- if (! q) q = strstr(t, "nodisplay=");
1304
- q = strchr(q, '=') + 1;
1307
- t2 = strchr(t, ',');
1308
- if (t2) *t2 = '\0';
1309
- while (*t != '\0') {
1315
- if (!strchr(q, '\'')) {
1316
- if (! quiet) rfbLog("set X11VNC_SKIP_DISPLAY: %s\n", q);
1319
+ if (ok && strlen(q) < 32) {
1320
+ sprintf(fdgeom, q);
1322
+ rfbLog("set create display geom: %s\n", fdgeom);
1326
+ q = strstr(t, "cups=");
1329
+ if (sscanf(q, "cups=%d", &p) == 1) {
1330
+ sprintf(fdcups, "%d", p);
1333
+ q = strstr(t, "esd=");
1336
+ if (sscanf(q, "esd=%d", &p) == 1) {
1337
+ sprintf(fdesd, "%d", p);
1342
+ if (fdgeom[0] == '\0' && getenv("FD_GEOM")) {
1343
+ snprintf(fdgeom, 120, "%s", getenv("FD_GEOM"));
1345
+ if (fdsess[0] == '\0' && getenv("FD_SESS")) {
1346
+ snprintf(fdsess, 120, "%s", getenv("FD_SESS"));
1348
+ if (fdopts[0] == '\0' && getenv("FD_OPTS")) {
1349
+ snprintf(fdopts, 120, "%s", getenv("FD_OPTS"));
1351
+ if (fdprog[0] == '\0' && getenv("FD_PROG")) {
1352
+ snprintf(fdprog, 120, "%s", getenv("FD_PROG"));
1354
+ if (fdxsrv[0] == '\0' && getenv("FD_XSRV")) {
1355
+ snprintf(fdxsrv, 120, "%s", getenv("FD_XSRV"));
1357
+ if (fdcups[0] == '\0' && getenv("FD_CUPS")) {
1358
+ snprintf(fdcups, 120, "%s", getenv("FD_CUPS"));
1360
+ if (fdesd[0] == '\0' && getenv("FD_ESD")) {
1361
+ snprintf(fdesd, 120, "%s", getenv("FD_ESD"));
1363
+ if (fdnas[0] == '\0' && getenv("FD_NAS")) {
1364
+ snprintf(fdnas, 120, "%s", getenv("FD_NAS"));
1366
+ if (fdsmb[0] == '\0' && getenv("FD_SMB")) {
1367
+ snprintf(fdsmb, 120, "%s", getenv("FD_SMB"));
1369
+ if (fdtag[0] == '\0' && getenv("FD_TAG")) {
1370
+ snprintf(fdtag, 120, "%s", getenv("FD_TAG"));
1372
+ if (fdxdum[0] == '\0' && getenv("FD_XDUMMY_NOROOT")) {
1373
+ snprintf(fdxdum, 120, "%s", getenv("FD_XDUMMY_NOROOT"));
1376
- cmd = (char *) malloc(strlen("env X11VNC_SKIP_DISPLAY='' ")
1377
- + strlen(nd) + strlen(tmp) + strlen("/bin/sh ") + 1);
1378
- sprintf(cmd, "env X11VNC_SKIP_DISPLAY='%s' /bin/sh %s", nd, tmp);
1379
+ set_env("FD_GEOM", fdgeom);
1380
+ set_env("FD_OPTS", fdopts);
1381
+ set_env("FD_PROG", fdprog);
1382
+ set_env("FD_XSRV", fdxsrv);
1383
+ set_env("FD_CUPS", fdcups);
1384
+ set_env("FD_ESD", fdesd);
1385
+ set_env("FD_NAS", fdnas);
1386
+ set_env("FD_SMB", fdsmb);
1387
+ set_env("FD_TAG", fdtag);
1388
+ set_env("FD_XDUMMY_NOROOT", fdxdum);
1389
+ set_env("FD_SESS", fdsess);
1391
+ if (usslpeer || (unixpw && keep_unixpw_user)) {
1392
+ char *uu = usslpeer;
1394
+ uu = keep_unixpw_user;
1396
+ create_cmd = (char *) malloc(strlen(tmp)+1
1397
+ + strlen("env USER='' ")
1398
+ + strlen("FD_GEOM='' ")
1399
+ + strlen("FD_OPTS='' ")
1400
+ + strlen("FD_PROG='' ")
1401
+ + strlen("FD_XSRV='' ")
1402
+ + strlen("FD_CUPS='' ")
1403
+ + strlen("FD_ESD='' ")
1404
+ + strlen("FD_NAS='' ")
1405
+ + strlen("FD_SMB='' ")
1406
+ + strlen("FD_TAG='' ")
1407
+ + strlen("FD_XDUMMY_NOROOT='' ")
1408
+ + strlen("FD_SESS='' /bin/sh ")
1410
+ + strlen(fdgeom) + 1
1411
+ + strlen(fdopts) + 1
1412
+ + strlen(fdprog) + 1
1413
+ + strlen(fdxsrv) + 1
1414
+ + strlen(fdcups) + 1
1415
+ + strlen(fdesd) + 1
1416
+ + strlen(fdnas) + 1
1417
+ + strlen(fdsmb) + 1
1418
+ + strlen(fdtag) + 1
1419
+ + strlen(fdxdum) + 1
1420
+ + strlen(fdsess) + 1
1421
+ + strlen(opts) + 1);
1422
+ sprintf(create_cmd, "env USER='%s' FD_GEOM='%s' FD_SESS='%s' "
1423
+ "FD_OPTS='%s' FD_PROG='%s' FD_XSRV='%s' FD_CUPS='%s' "
1424
+ "FD_ESD='%s' FD_NAS='%s' FD_SMB='%s' FD_TAG='%s' "
1425
+ "FD_XDUMMY_NOROOT='%s' /bin/sh %s %s",
1426
+ uu, fdgeom, fdsess, fdopts, fdprog, fdxsrv,
1427
+ fdcups, fdesd, fdnas, fdsmb, fdtag, fdxdum, tmp, opts);
1429
+ create_cmd = (char *) malloc(strlen(tmp)
1430
+ + strlen("/bin/sh ") + 1 + strlen(opts) + 1);
1431
+ sprintf(create_cmd, "/bin/sh %s %s", tmp, opts);
1433
+ return create_cmd;
1436
- rfbLog("wait_for_client: running: %s\n", cmd);
1437
+static char *certret_extract() {
1438
+ char *q, *p, *str = strdup(certret_str);
1439
+ char *upeer = NULL;
1443
- int res = 0, k, j, i;
1445
+ q = strstr(str, "Subject: ");
1446
+ if (! q) return NULL;
1448
- memset(line, 0, 18000);
1449
+ p = strstr(q, "\n");
1452
- if (keep_unixpw_user && keep_unixpw_pass) {
1454
- res = su_verify(keep_unixpw_user,
1455
- keep_unixpw_pass, cmd, line, &n, nodisp);
1456
+ q = strstr(q, "CN=");
1457
+ if (! q) return NULL;
1459
+ if (! getenv("X11VNC_SSLPEER_CN")) {
1461
+ q = strstr(q, "/emailAddress=");
1462
+ if (! q) q = strstr(p, "/Email=");
1463
+ if (! q) return NULL;
1466
+ q = strstr(q, "=");
1467
+ if (! q) return NULL;
1470
+ p = strstr(q, " ");
1472
+ p = strstr(q, "@");
1474
+ p = strstr(q, "/");
1477
+ upeer = strdup(q);
1479
+ if (strcmp(upeer, "")) {
1481
+ while (*p != '\0') {
1483
+ if (!isalnum((int) c)) {
1489
+ if (strcmp(upeer, "")) {
1499
+static void check_nodisplay(char **nd) {
1500
+ if (unixpw && keep_unixpw_opts && keep_unixpw_opts[0] != '\0') {
1501
+ char *q, *t = keep_unixpw_opts;
1502
+ q = strstr(t, "nd=");
1503
+ if (! q) q = strstr(t, "nodisplay=");
1506
+ q = strchr(q, '=') + 1;
1509
+ t2 = strchr(t, ',');
1510
+ if (t2) *t2 = '\0';
1511
+ while (*t != '\0') {
1517
+ if (!strchr(q, '\'')) {
1518
+ if (! quiet) rfbLog("set X11VNC_SKIP_DISPLAY: %s\n", q);
1525
+static char *get_usslpeer() {
1526
+ char *u = NULL, *upeer = NULL;
1528
+ if (certret_str) {
1529
+ upeer = certret_extract();
1534
+ rfbLog("sslpeer unix username extracted from x509 cert: %s\n", upeer);
1536
+ u = (char *) malloc(strlen(upeer+2));
1538
+ if (!strcmp(users_list, "sslpeer=")) {
1539
+ sprintf(u, "+%s", upeer);
1541
+ char *p, *str = strdup(users_list);
1542
+ p = strtok(str + strlen("sslpeer="), ",");
1544
+ if (!strcmp(p, upeer)) {
1545
+ sprintf(u, "+%s", upeer);
1548
+ p = strtok(NULL, ",");
1552
+ if (u[0] == '\0') {
1553
+ rfbLog("sslpeer cannot determine user: %s\n", upeer);
1561
+static int do_run_cmd(char *cmd, char *create_cmd, char *users_list_save, int created_disp, int db) {
1562
+ char tmp[] = "/tmp/x11vnc-find_display.XXXXXX";
1563
+ char line1[1024], line2[16384];
1564
+ char *q, *usslpeer = NULL;
1565
+ int n, nodisp = 0, saw_xdmcp = 0;
1568
+ memset(line1, 0, 1024);
1569
+ memset(line2, 0, 16384);
1571
+ if (users_list && strstr(users_list, "sslpeer=") == users_list) {
1572
+ usslpeer = get_usslpeer();
1578
+ /* only sets environment variables: */
1579
+ run_user_command("", latest_client, "env", NULL, 0, NULL);
1581
+ if (program_name) {
1582
+ set_env("X11VNC_PROG", program_name);
1584
+ set_env("X11VNC_PROG", "x11vnc");
1587
+ if (!strcmp(cmd, "FINDDISPLAY") ||
1588
+ strstr(cmd, "FINDCREATEDISPLAY") == cmd) {
1590
+ tmp_fd = mkstemp(tmp);
1592
+ rfbLog("wait_for_client: open failed: %s\n", tmp);
1593
+ rfbLogPerror("mkstemp");
1597
+ if (getenv("X11VNC_FINDDISPLAY_ALWAYS_FAILS")) {
1598
+ char *s = "#!/bin/sh\necho _FAIL_\nexit 1\n";
1599
+ write(tmp_fd, s, strlen(s));
1601
+ write(tmp_fd, find_display, strlen(find_display));
1606
+ if (strstr(cmd, "FINDCREATEDISPLAY") == cmd) {
1607
+ create_cmd = build_create_cmd(cmd, &saw_xdmcp, usslpeer, tmp);
1608
+ if (db) fprintf(stderr, "create_cmd: %s\n", create_cmd);
1610
+ if (getenv("X11VNC_SKIP_DISPLAY")) {
1611
+ nd = strdup(getenv("X11VNC_SKIP_DISPLAY"));
1613
+ check_nodisplay(&nd);
1615
+ cmd = (char *) malloc(strlen("env X11VNC_SKIP_DISPLAY='' ")
1616
+ + strlen(nd) + strlen(tmp) + strlen("/bin/sh ") + 1);
1617
+ sprintf(cmd, "env X11VNC_SKIP_DISPLAY='%s' /bin/sh %s", nd, tmp);
1620
+ rfbLog("wait_for_client: running: %s\n", cmd);
1623
+ int res = 0, k, j, i;
1626
+ memset(line, 0, 18000);
1628
+ if (keep_unixpw_user && keep_unixpw_pass) {
1630
+ res = su_verify(keep_unixpw_user,
1631
+ keep_unixpw_pass, cmd, line, &n, nodisp);
1634
if (db) {fprintf(stderr, "line: "); write(2, line, n); write(2, "\n", 1); fprintf(stderr, "res=%d n=%d\n", res, n);}
1636
- rfbLog("wait_for_client: find display cmd failed\n");
1638
+ rfbLog("wait_for_client: find display cmd failed\n");
1641
+ if (! res && create_cmd) {
1642
+ FILE *mt = fopen(tmp, "w");
1644
+ rfbLog("wait_for_client: open failed: %s\n", tmp);
1645
+ rfbLogPerror("fopen");
1648
+ fprintf(mt, "%s", create_display);
1651
- if (! res && create_cmd) {
1652
- FILE *mt = fopen(tmp, "w");
1654
- rfbLog("wait_for_client: open failed: %s\n", tmp);
1655
- rfbLogPerror("fopen");
1658
- fprintf(mt, "%s", create_display);
1660
+ findcreatedisplay = 1;
1662
- findcreatedisplay = 1;
1664
- if (getuid() != 0) {
1665
- /* if not root, run as the other user... */
1668
- res = su_verify(keep_unixpw_user,
1669
- keep_unixpw_pass, create_cmd, line, &n, nodisp);
1670
+ if (getuid() != 0) {
1671
+ /* if not root, run as the other user... */
1674
+ res = su_verify(keep_unixpw_user,
1675
+ keep_unixpw_pass, create_cmd, line, &n, nodisp);
1676
if (db) fprintf(stderr, "c-res=%d n=%d line: '%s'\n", res, n, line);
1681
+ rfbLog("wait_for_client: running: %s\n", create_cmd);
1682
+ p = popen(create_cmd, "r");
1684
+ rfbLog("wait_for_client: popen failed: %s\n", create_cmd);
1686
+ } else if (fgets(line1, 1024, p) == NULL) {
1687
+ rfbLog("wait_for_client: read failed: %s\n", create_cmd);
1692
- rfbLog("wait_for_client: running: %s\n", create_cmd);
1693
- p = popen(create_cmd, "r");
1695
- rfbLog("wait_for_client: popen failed: %s\n", create_cmd);
1696
+ n = fread(line2, 1, 16384, p);
1697
+ if (pclose(p) != 0) {
1699
- } else if (fgets(line1, 1024, p) == NULL) {
1700
- rfbLog("wait_for_client: read failed: %s\n", create_cmd);
1703
- n = fread(line2, 1, 16384, p);
1704
- if (pclose(p) != 0) {
1707
- strncpy(line, line1, 100);
1708
- memcpy(line + strlen(line1), line2, n);
1709
+ strncpy(line, line1, 100);
1710
+ memcpy(line + strlen(line1), line2, n);
1711
if (db) fprintf(stderr, "line1: '%s'\n", line1);
1712
- n += strlen(line1);
1716
+ n += strlen(line1);
1721
- if (res && saw_xdmcp) {
1722
- xdmcp_insert = strdup(keep_unixpw_user);
1726
- if (tmp_fd >= 0) {
1728
+ if (res && saw_xdmcp) {
1729
+ xdmcp_insert = strdup(keep_unixpw_user);
1734
- rfbLog("wait_for_client: cmd failed: %s\n", cmd);
1735
- unixpw_msg("No DISPLAY found.", 3);
1738
+ if (tmp_fd >= 0) {
1743
- * we need to hunt for DISPLAY= since there may be
1744
- * a login banner or something at the beginning.
1746
- q = strstr(line, "DISPLAY=");
1752
+ rfbLog("wait_for_client: cmd failed: %s\n", cmd);
1753
+ unixpw_msg("No DISPLAY found.", 3);
1757
- for (k = 0; k < 1024; k++) {
1759
- if (q[k] == '\n') {
1764
+ * we need to hunt for DISPLAY= since there may be
1765
+ * a login banner or something at the beginning.
1767
+ q = strstr(line, "DISPLAY=");
1773
+ for (k = 0; k < 1024; k++) {
1775
+ if (q[k] == '\n') {
1781
- for (j = 0; j < 16384; j++) {
1782
- if (j < 16384 - 1) {
1783
- /* xauth data, assume pty added CR */
1784
- if (q[k+j] == '\r' && q[k+j+1] == '\n') {
1790
+ for (j = 0; j < 16384; j++) {
1791
+ if (j < 16384 - 1) {
1792
+ /* xauth data, assume pty added CR */
1793
+ if (q[k+j] == '\r' && q[k+j+1] == '\n') {
1797
- line2[i] = q[k+j];
1801
+ line2[i] = q[k+j];
1804
if (db) write(2, line, 100);
1805
if (db) fprintf(stderr, "\n");
1813
+ if (getuid() == 0) {
1814
+ c = (char *) malloc(strlen("su - '' -c \"")
1815
+ + strlen(usslpeer) + strlen(cmd) + 1 + 1);
1816
+ sprintf(c, "su - '%s' -c \"%s\"", usslpeer, cmd);
1820
+ p = popen(c, "r");
1827
+ p = popen(cmd, "r");
1830
+ rfbLog("wait_for_client: cmd failed: %s\n", cmd);
1831
+ rfbLogPerror("popen");
1832
+ if (tmp_fd >= 0) {
1837
+ if (fgets(line1, 1024, p) == NULL) {
1838
+ rfbLog("wait_for_client: read failed: %s\n", cmd);
1839
+ rfbLogPerror("fgets");
1840
+ if (tmp_fd >= 0) {
1845
+ n = fread(line2, 1, 16384, p);
1850
- if (getuid() == 0) {
1851
- c = (char *) malloc(strlen("su - '' -c \"")
1852
- + strlen(usslpeer) + strlen(cmd) + 1 + 1);
1853
- sprintf(c, "su - '%s' -c \"%s\"", usslpeer, cmd);
1857
+ rfbLog("wait_for_client: find display cmd failed\n");
1860
+ if (create_cmd && rc != 0) {
1861
+ FILE *mt = fopen(tmp, "w");
1863
+ rfbLog("wait_for_client: open failed: %s\n", tmp);
1864
+ rfbLogPerror("fopen");
1865
+ if (tmp_fd >= 0) {
1868
- p = popen(c, "r");
1872
- p = popen(cmd, "r");
1875
+ fprintf(mt, "%s", create_display);
1878
+ findcreatedisplay = 1;
1880
+ rfbLog("wait_for_client: FINDCREATEDISPLAY cmd: %s\n", create_cmd);
1882
+ p = popen(create_cmd, "r");
1884
- rfbLog("wait_for_client: cmd failed: %s\n", cmd);
1885
+ rfbLog("wait_for_client: cmd failed: %s\n", create_cmd);
1886
rfbLogPerror("popen");
1889
@@ -2314,7 +2369,7 @@
1892
if (fgets(line1, 1024, p) == NULL) {
1893
- rfbLog("wait_for_client: read failed: %s\n", cmd);
1894
+ rfbLog("wait_for_client: read failed: %s\n", create_cmd);
1895
rfbLogPerror("fgets");
1898
@@ -2322,199 +2377,318 @@
1901
n = fread(line2, 1, 16384, p);
1905
- rfbLog("wait_for_client: find display cmd failed\n");
1908
- if (create_cmd && rc != 0) {
1909
- FILE *mt = fopen(tmp, "w");
1911
- rfbLog("wait_for_client: open failed: %s\n", tmp);
1912
- rfbLogPerror("fopen");
1913
- if (tmp_fd >= 0) {
1918
- fprintf(mt, "%s", create_display);
1921
- findcreatedisplay = 1;
1923
- rfbLog("wait_for_client: FINDCREATEDISPLAY cmd: %s\n", create_cmd);
1925
- p = popen(create_cmd, "r");
1927
- rfbLog("wait_for_client: cmd failed: %s\n", create_cmd);
1928
- rfbLogPerror("popen");
1929
- if (tmp_fd >= 0) {
1934
- if (fgets(line1, 1024, p) == NULL) {
1935
- rfbLog("wait_for_client: read failed: %s\n", create_cmd);
1936
- rfbLogPerror("fgets");
1937
- if (tmp_fd >= 0) {
1942
- n = fread(line2, 1, 16384, p);
1944
- if (tmp_fd >= 0) {
1948
+ if (tmp_fd >= 0) {
1953
if (db) fprintf(stderr, "line1=%s\n", line1);
1955
- if (strstr(line1, "DISPLAY=") != line1) {
1956
- rfbLog("wait_for_client: bad reply '%s'\n", line1);
1958
- unixpw_msg("No DISPLAY found.", 3);
1961
+ if (strstr(line1, "DISPLAY=") != line1) {
1962
+ rfbLog("wait_for_client: bad reply '%s'\n", line1);
1964
+ unixpw_msg("No DISPLAY found.", 3);
1970
- if (strstr(line1, ",VT=")) {
1972
- char *t = strstr(line1, ",VT=");
1973
- vt = atoi(t + strlen(",VT="));
1975
- if (7 <= vt && vt <= 15) {
1977
- sprintf(chvt, "chvt %d >/dev/null 2>/dev/null &", vt);
1978
- rfbLog("running: %s\n", chvt);
1982
- } else if (strstr(line1, ",XPID=")) {
1983
- int i, pvt, vt = -1;
1984
- char *t = strstr(line1, ",XPID=");
1985
- pvt = atoi(t + strlen(",XPID="));
1988
- for (i=3; i <= 10; i++) {
1992
- sprintf(proc, "/proc/%d/fd/%d", pvt, i);
1993
+ if (strstr(line1, ",VT=")) {
1995
+ char *t = strstr(line1, ",VT=");
1996
+ vt = atoi(t + strlen(",VT="));
1998
+ if (7 <= vt && vt <= 15) {
2001
+ } else if (strstr(line1, ",XPID=")) {
2002
+ int i, pvt, vt = -1;
2003
+ char *t = strstr(line1, ",XPID=");
2004
+ pvt = atoi(t + strlen(",XPID="));
2007
+ for (i=3; i <= 10; i++) {
2011
+ sprintf(proc, "/proc/%d/fd/%d", pvt, i);
2012
if (db) fprintf(stderr, "%d -- %s\n", i, proc);
2013
- for (k=0; k < 100; k++) {
2017
- if (readlink(proc, buf, 100) != -1) {
2018
- buf[100-1] = '\0';
2019
+ for (k=0; k < 100; k++) {
2023
+ if (readlink(proc, buf, 100) != -1) {
2024
+ buf[100-1] = '\0';
2025
if (db) fprintf(stderr, "%d -- %s -- %s\n", i, proc, buf);
2026
- if (strstr(buf, "/dev/tty") == buf) {
2027
- vt = atoi(buf + strlen("/dev/tty"));
2031
+ if (strstr(buf, "/dev/tty") == buf) {
2032
+ vt = atoi(buf + strlen("/dev/tty"));
2039
- if (7 <= vt && vt <= 12) {
2041
- sprintf(chvt, "chvt %d >/dev/null 2>/dev/null &", vt);
2042
- rfbLog("running: %s\n", chvt);
2048
- use_dpy = strdup(line1 + strlen("DISPLAY="));
2050
- while (*q != '\0') {
2051
- if (*q == '\n' || *q == '\r') *q = '\0';
2053
+ if (7 <= vt && vt <= 12) {
2056
- if (line2[0] != '\0') {
2057
- if (strstr(line2, "XAUTHORITY=") == line2) {
2059
- while (*q != '\0') {
2060
- if (*q == '\n' || *q == '\r') *q = '\0';
2066
- auth_file = strdup(line2 + strlen("XAUTHORITY="));
2070
- xauth_raw_data = (char *)malloc(n);
2071
- xauth_raw_len = n;
2072
- memcpy(xauth_raw_data, line2, n);
2073
+ use_dpy = strdup(line1 + strlen("DISPLAY="));
2075
+ while (*q != '\0') {
2076
+ if (*q == '\n' || *q == '\r') *q = '\0';
2079
+ if (line2[0] != '\0') {
2080
+ if (strstr(line2, "XAUTHORITY=") == line2) {
2082
+ while (*q != '\0') {
2083
+ if (*q == '\n' || *q == '\r') *q = '\0';
2089
+ auth_file = strdup(line2 + strlen("XAUTHORITY="));
2092
+ xauth_raw_data = (char *)malloc(n);
2093
+ xauth_raw_len = n;
2094
+ memcpy(xauth_raw_data, line2, n);
2095
if (db) {fprintf(stderr, "xauth_raw_len: %d\n", n);
2096
write(2, xauth_raw_data, n);
2097
fprintf(stderr, "\n");}
2103
- char *u = (char *) malloc(strlen(usslpeer+2));
2104
- sprintf(u, "+%s", usslpeer);
2105
- if (switch_user(u, 0)) {
2106
- rfbLog("sslpeer switched to user: %s\n", usslpeer);
2108
- rfbLog("sslpeer failed to switch to user: %s\n", usslpeer);
2112
- } else if (users_list_save && keep_unixpw_user) {
2113
- char *user = keep_unixpw_user;
2114
- char *u = (char *)malloc(strlen(user)+1);
2116
+ char *u = (char *) malloc(strlen(usslpeer+2));
2117
+ sprintf(u, "+%s", usslpeer);
2118
+ if (switch_user(u, 0)) {
2119
+ rfbLog("sslpeer switched to user: %s\n", usslpeer);
2121
+ rfbLog("sslpeer failed to switch to user: %s\n", usslpeer);
2125
+ } else if (users_list_save && keep_unixpw_user) {
2126
+ char *user = keep_unixpw_user;
2127
+ char *u = (char *)malloc(strlen(user)+1);
2129
- users_list = users_list_save;
2130
+ users_list = users_list_save;
2133
- if (!strcmp(users_list, "unixpw=")) {
2134
- sprintf(u, "+%s", user);
2136
- char *p, *str = strdup(users_list);
2137
- p = strtok(str + strlen("unixpw="), ",");
2139
- if (!strcmp(p, user)) {
2140
- sprintf(u, "+%s", user);
2143
- p = strtok(NULL, ",");
2145
+ if (!strcmp(users_list, "unixpw=")) {
2146
+ sprintf(u, "+%s", user);
2148
+ char *p, *str = strdup(users_list);
2149
+ p = strtok(str + strlen("unixpw="), ",");
2151
+ if (!strcmp(p, user)) {
2152
+ sprintf(u, "+%s", user);
2156
+ p = strtok(NULL, ",");
2159
- if (u[0] == '\0') {
2160
- rfbLog("unixpw_accept skipping switch to user: %s\n", user);
2161
- } else if (switch_user(u, 0)) {
2162
- rfbLog("unixpw_accept switched to user: %s\n", user);
2164
- rfbLog("unixpw_accept failed to switch to user: %s\n", user);
2170
+ if (u[0] == '\0') {
2171
+ rfbLog("unixpw_accept skipping switch to user: %s\n", user);
2172
+ } else if (switch_user(u, 0)) {
2173
+ rfbLog("unixpw_accept switched to user: %s\n", user);
2175
+ rfbLog("unixpw_accept failed to switch to user: %s\n", user);
2185
- if (keep_unixpw_user && keep_unixpw_pass) {
2186
- strzero(keep_unixpw_user);
2187
- strzero(keep_unixpw_pass);
2189
+ if (keep_unixpw_user && keep_unixpw_pass) {
2190
+ strzero(keep_unixpw_user);
2191
+ strzero(keep_unixpw_pass);
2195
+ if (created_disp) {
2196
+ snprintf(str, 30, "Created DISPLAY %s", use_dpy);
2198
+ snprintf(str, 30, "Using DISPLAY %s", use_dpy);
2200
+ unixpw_msg(str, 2);
2205
+static XImage ximage_struct;
2207
+int wait_for_client(int *argc, char** argv, int http) {
2208
+ /* ugh, here we go... */
2210
+ int w = 640, h = 480, b = 32;
2211
+ int w0, h0, i, chg_raw_fb = 0;
2212
+ char *str, *q, *cmd = NULL;
2213
+ int db = 0, dt = 0;
2214
+ char *create_cmd = NULL;
2215
+ char *users_list_save = NULL;
2216
+ int created_disp = 0, ncache_save;
2217
+ int did_client_connect = 0;
2218
+ char *vnc_redirect_host = "localhost";
2219
+ int vnc_redirect_port = -1, vnc_redirect_cnt = 0;
2220
+ char vnc_redirect_test[10];
2222
+ if (getenv("WAIT_FOR_CLIENT_DB")) {
2228
+ if (! use_dpy || strstr(use_dpy, "WAIT:") != use_dpy) {
2232
+ for (i=0; i < *argc; i++) {
2233
+ if (!strcmp(argv[i], "-desktop")) {
2236
+ if (db) fprintf(stderr, "args %d %s\n", i, argv[i]);
2238
+ if (!quiet && !strstr(use_dpy, "FINDDISPLAY-run")) {
2239
+ rfbLog("wait_for_client: %s\n", use_dpy);
2242
+ str = strdup(use_dpy);
2243
+ str += strlen("WAIT");
2245
+ xdmcp_insert = NULL;
2247
+ /* get any leading geometry: */
2248
+ q = strchr(str+1, ':');
2251
+ if (sscanf(str+1, "%dx%d", &w0, &h0) == 2) {
2254
+ rfbLog("wait_for_client set: w=%d h=%d\n", w, h);
2260
+ /* str currently begins with a ':' */
2261
+ if (strstr(str, ":cmd=") == str) {
2262
+ /* cmd=/path/to/mycommand */
2264
+ } else if (strpbrk(str, "0123456789") == str+1) {
2268
+ /* hostname:0.0 */
2272
+ if (db) fprintf(stderr, "str: %s\n", str);
2274
+ if (strstr(str, "cmd=") == str) {
2275
+ cmd = setup_cmd(str, &vnc_redirect, &vnc_redirect_host, &vnc_redirect_port, db);
2278
+ fb_image = &ximage_struct;
2279
+ setup_fake_fb(fb_image, w, h, b);
2283
+ argv[*argc] = strdup("-desktop");
2284
+ *argc = (*argc) + 1;
2288
+ s = choose_title(":0");
2289
+ q = strstr(s, ":0");
2294
+ s = choose_title(str);
2296
+ rfb_desktop_name = strdup(s);
2298
+ *argc = (*argc) + 1;
2301
- if (created_disp) {
2302
- snprintf(str, 30, "Created DISPLAY %s", use_dpy);
2304
- snprintf(str, 30, "Using DISPLAY %s", use_dpy);
2305
+ ncache_save = ncache;
2308
+ initialize_allowed_input();
2310
+ if (! multiple_cursors_mode) {
2311
+ multiple_cursors_mode = strdup("default");
2313
+ initialize_cursors_mode();
2315
+ initialize_screen(argc, argv, fb_image);
2317
+ initialize_signals();
2319
+ if (ssh_str != NULL) {
2320
+ ssh_remote_tunnel(ssh_str, screen->port);
2325
+ /* kludge to get RAWFB_RET with dpy == NULL guards */
2326
+ raw_fb = (char *) 0x1;
2329
+ if (cmd && !strcmp(cmd, "HTTPONCE")) {
2330
+ handle_one_http_request();
2334
+ if (http && check_httpdir()) {
2335
+ http_connections(1);
2338
+ if (cmd && unixpw) {
2346
+ if (vnc_redirect) {
2347
+ vnc_redirect_loop(vnc_redirect_test, &vnc_redirect_cnt);
2349
+ if (inetd && use_openssl) {
2350
+ accept_openssl(OPENSSL_INETD, -1);
2353
+ setup_client_connect(&did_client_connect);
2355
+ loop_for_connect(did_client_connect);
2358
+ if (cmd && strstr(cmd, "FINDCREATEDISPLAY") == cmd) {
2359
+ if (users_list && strstr(users_list, "unixpw=") == users_list) {
2360
+ users_list_save = users_list;
2361
+ users_list = NULL;
2364
- unixpw_msg(str, 2);
2369
+ if (vnc_redirect == 2) {
2372
+ if (!do_run_cmd(cmd, create_cmd, users_list_save, created_disp, db)) {
2376
use_dpy = strdup(str);
2378
@@ -2532,61 +2706,8 @@
2382
- char *q = strchr(use_dpy, ':');
2383
- int vdpy = -1, sock = -1;
2384
- int s_in, s_out, i;
2385
- if (vnc_redirect == 2) {
2387
- sprintf(num, ":%d", vnc_redirect_port);
2391
- rfbLog("wait_for_client: can't find number in X display: %s\n", use_dpy);
2394
- if (sscanf(q+1, "%d", &vdpy) != 1) {
2395
- rfbLog("wait_for_client: can't find number in X display: %s\n", q);
2398
- if (vdpy == -1 && vnc_redirect != 2) {
2399
- rfbLog("wait_for_client: can't find number in X display: %s\n", q);
2402
- if (vnc_redirect == 2) {
2405
- } else if (vdpy < 200) {
2411
- if (created_disp) {
2412
- usleep(1000*1000);
2414
- for (i=0; i < 20; i++) {
2415
- sock = rfbConnectToTcpAddr(vnc_redirect_host, vdpy);
2419
- rfbLog("wait_for_client: ...\n");
2423
- rfbLog("wait_for_client: could not connect to a VNC Server at %s:%d\n", vnc_redirect_host, vdpy);
2427
- s_in = fileno(stdin);
2428
- s_out = fileno(stdout);
2430
- s_in = s_out = vnc_redirect_sock;
2432
- if (vnc_redirect_cnt > 0) {
2433
- write(vnc_redirect_sock, vnc_redirect_test, vnc_redirect_cnt);
2435
- rfbLog("wait_for_client: switching control to VNC Server at %s:%d\n", vnc_redirect_host, vdpy);
2436
- raw_xfer(sock, s_in, s_out);
2437
+ do_vnc_redirect(created_disp, vnc_redirect_host, vnc_redirect_port,
2438
+ vnc_redirect_cnt, vnc_redirect_test);
2442
Index: ../ica/x11/x11vnc/8to24.c
2443
===================================================================
2444
--- ../ica/x11/x11vnc/8to24.c (Revision 401)
2445
+++ ../ica/x11/x11vnc/8to24.c (Arbeitskopie)
2453
static Colormap root_cmap = 0;
2454
-static unsigned int root_rgb[NCOLOR];
2455
+static unsigned int *root_rgb = NULL;
2457
static void set_root_cmap(void) {
2460
static time_t last_set = 0;
2461
time_t now = time(NULL);
2462
XWindowAttributes attr;
2463
- static XColor color[NCOLOR];
2464
+ static XColor *color = NULL;
2471
+ ncolor = 1 << depth;
2477
+ root_rgb = (unsigned int *) malloc(ncolor * sizeof(unsigned int));
2480
+ color = (XColor *) malloc(ncolor * sizeof(XColor));
2483
if (now > last_set + 10) {
2489
if (attr.colormap) {
2490
- int i, ncells = NCOLOR;
2491
+ int i, ncells = ncolor;
2494
+ ncells = CellsOfScreen(ScreenOfDisplay(dpy, scr));
2496
for (i=0; i < ncells; i++) {
2499
@@ -236,7 +255,11 @@
2500
return; /* this saves a bit of RAM */
2502
pfb(4, &poll24_fb, &poll24_fb_w, &poll24_fb_h);
2503
- pfb(1, &poll8_fb, &poll8_fb_w, &poll8_fb_h);
2505
+ pfb(2, &poll8_fb, &poll8_fb_w, &poll8_fb_h); /* 2X for rare 16bpp colormap case */
2507
+ pfb(1, &poll8_fb, &poll8_fb_w, &poll8_fb_h);
2513
if (check_depth(win, win, doall)) {
2515
* returns 1 if no need to recurse down e.g. It
2516
- * is 8bpp and we assume all lower one are too.
2517
+ * is 8bpp and we assume all lower ones are too.
2522
mark_8bpp(MARK_8BPP_ALL);
2525
- } else if (depth == 8 && multivis_24count) {
2526
+ } else if (depth <= 16 && multivis_24count) {
2527
static double last_check = 0.0;
2528
if (now > last_check + 0.4) {
2531
if (attr->depth > 0) {
2532
if (depth == 24 && attr->depth != 24) {
2534
- } else if (depth == 8 && root_cmap && attr->colormap !=
2536
+ } else if (depth <= 16 && root_cmap && attr->colormap != root_cmap) {
2544
+/* polling line XImage */
2545
static XImage *p_xi(XImage *xi, Visual *visual, int win_depth, int *w) {
2548
@@ -771,8 +794,12 @@
2552
- if (win_depth == 8) {
2553
- d = (char *) malloc(dpy_x * 1);
2554
+ if (win_depth != 24) {
2555
+ if (win_depth > 8) {
2556
+ d = (char *) malloc(dpy_x * 2);
2558
+ d = (char *) malloc(dpy_x * 1);
2561
d = (char *) malloc(dpy_x * 4);
2563
@@ -837,14 +864,18 @@
2567
- if (attr.depth != 8 && attr.depth != 24) {
2568
+ if (attr.depth > 16 && attr.depth != 24) {
2571
- } else if (attr.depth == 8) {
2572
- xi = xi8 = p_xi(xi8, attr.visual, 8, &xi8_w);
2573
+ } else if (attr.depth <= 16) {
2574
+ xi = xi8 = p_xi(xi8, attr.visual, attr.depth, &xi8_w);
2578
+ if (attr.depth > 8) {
2583
n_off = poll8_fb_w * y1 + x1;
2585
xi = xi24 = p_xi(xi24, attr.visual, 24, &xi24_w);
2586
@@ -1280,7 +1311,7 @@
2590
- if (! seen && attr.depth == 8) {
2591
+ if (!seen && attr.depth <= 16) {
2592
/* store only new ones: */
2593
cmaps[ncmaps++] = attr.colormap;
2595
@@ -1292,10 +1323,11 @@
2599
-static XColor color[CMAPMAX][NCOLOR];
2600
-static unsigned int rgb[CMAPMAX][NCOLOR];
2601
+static XColor *color[CMAPMAX];
2602
+static unsigned int *rgb[CMAPMAX];
2603
static int cmap_failed[CMAPMAX];
2605
+static int color_init = 0;
2608
static int get_cmap(int j, Colormap cmap) {
2610
@@ -1303,27 +1335,38 @@
2615
+ int i, ncells, ncolor;
2616
XErrorHandler old_handler = NULL;
2622
+ ncolor = 1 << depth;
2626
+ if (!color_init) {
2628
+ for (cm = 0; cm < CMAPMAX; cm++) {
2629
+ color[cm] = (XColor *) malloc(ncolor * sizeof(XColor));
2630
+ rgb[cm] = (unsigned int *) malloc(ncolor * sizeof(unsigned int));
2635
+ if (depth <= 16) {
2636
/* not working properly for depth 24... */
2638
ncells = CellsOfScreen(ScreenOfDisplay(dpy, scr));
2643
if (db24 > 1) fprintf(stderr, "get_cmap: %d 0x%x\n", j, (unsigned int) cmap);
2645
- /* ncells should "always" be 256. */
2646
- if (ncells > NCOLOR) {
2648
- } else if (ncells == 8) {
2649
- /* hmmm. see set_colormap() */
2651
+ if (ncells > ncolor) {
2653
+ } else if (ncells == 8 && depth != 3) {
2654
+ /* XXX. see set_colormap() */
2655
+ ncells = 1 << depth;
2658
/* initialize XColor array: */
2659
@@ -1404,7 +1447,7 @@
2663
- if (windows_8bpp[n].depth == 8) { /* 24 won't have a cmap */
2664
+ if (windows_8bpp[n].depth != 24) { /* 24 won't have a cmap */
2665
if (failed || cm == -1) {
2668
@@ -1448,17 +1491,18 @@
2669
if (! dpy || ! valid_window(win, &attr, 1)) {
2670
return (XImage *) NULL;
2672
- if (attr.depth != win_depth) {
2673
- return (XImage *) NULL;
2674
- } else if (win_depth == 8) {
2675
- d = (char *) malloc(dpy_x * dpy_y * 1);
2676
- } else if (win_depth == 24) {
2677
+ if (win_depth == 24) {
2678
d = (char *) malloc(dpy_x * dpy_y * 4);
2679
+ } else if (win_depth <= 16) {
2680
+ if (win_depth > 8) {
2681
+ d = (char *) malloc(dpy_x * dpy_y * 2);
2683
+ d = (char *) malloc(dpy_x * dpy_y * 1);
2686
return (XImage *) NULL;
2688
- return XCreateImage(dpy, attr.visual, win_depth, ZPixmap, 0, d, dpy_x,
2690
+ return XCreateImage(dpy, attr.visual, win_depth, ZPixmap, 0, d, dpy_x, dpy_y, 8, 0);
2694
@@ -1472,6 +1516,7 @@
2696
char *src, *dst, *poll;
2698
+ unsigned short *us;
2700
int ps, pixelsize = bpp/8;
2702
@@ -1495,7 +1540,7 @@
2703
h = rect.y2 - rect.y1;
2704
w = rect.x2 - rect.x1;
2707
+ if (depth != 24) {
2708
/* need to fetch depth 24 data. */
2711
@@ -1524,21 +1569,32 @@
2715
- if (win_depth == 8) {
2716
- if (xi_8 == NULL || xi_8->width != dpy_x ||
2717
- xi_8->height != dpy_y) {
2718
- xi_8 = cmap_xi(xi_8, win, 8);
2721
- } else if (win_depth == 24) {
2722
+ if (win_depth == 24) {
2723
if (xi_24 == NULL || xi_24->width != dpy_x ||
2724
xi_24->height != dpy_y) {
2725
xi_24 = cmap_xi(xi_24, win, 24);
2728
+ } else if (win_depth <= 16) {
2729
+ if (xi_8 == NULL || xi_8->width != dpy_x ||
2730
+ xi_8->height != dpy_y) {
2731
+ if (win_depth > 8) {
2733
+ xi_8 = cmap_xi(xi_8, win, 16);
2735
+ xi_8 = cmap_xi(xi_8, win, 8);
2743
+ rfbLog("transform_rect: xi is NULL\n");
2748
old_handler = XSetErrorHandler(trap_xerror);
2751
@@ -1578,7 +1634,7 @@
2755
- if (xi->depth != 8 && xi->depth != 24) {
2756
+ if (xi->depth > 16 && xi->depth != 24) {
2760
@@ -1590,64 +1646,76 @@
2764
- if (xi->depth == 8) {
2765
- int ps1, ps2, fac;
2770
+ if (xi->depth == 24) {
2771
+ /* line by line ... */
2775
+ } else if (depth <= 16) {
2781
+ fac = 1; /* will not happen 24 on 24 */
2785
dst = cmap8to24_fb + fac * n_off;
2787
- poll = poll8_fb + poll8_fb_w * rect.y1 + rect.x1;
2788
- poll_Bpl = poll8_fb_w * 1;
2789
+ poll = poll24_fb + (poll24_fb_w * rect.y1 + rect.x1) * 4;
2790
+ poll_Bpl = poll24_fb_w * 4;
2792
- /* line by line ... */
2793
for (line = 0; line < h; line++) {
2794
- /* pixel by pixel... */
2795
- for (j = 0; j < w; j++) {
2796
+ memcpy(dst, src, w * ps1);
2797
+ memcpy(poll, src, w * ps1);
2799
- uc = (unsigned char *) (src + ps1 * j);
2800
- ui = (unsigned int *) (dst + ps2 * j);
2802
- idx = (int) (*uc);
2804
- *ui = rgb[cm][idx];
2806
- *(poll + ps1 * j) = *uc;
2808
src += xi->bytes_per_line;
2809
dst += main_bytes_per_line * fac;
2812
- } else if (xi->depth == 24) {
2813
- /* line by line ... */
2816
+ } else if (xi->depth <= 16) {
2817
+ int ps1, ps2, fac;
2823
+ } else if (depth <= 16) {
2828
- fac = 1; /* will not happen */
2829
+ /* should be 24 case */
2836
- dst = cmap8to24_fb + fac * n_off;
2837
+ dst = cmap8to24_fb + (fac/ps1) * n_off;
2839
- poll = poll24_fb + (poll24_fb_w * rect.y1 + rect.x1)*4;
2840
- poll_Bpl = poll24_fb_w * 4;
2841
+ poll = poll8_fb + poll8_fb_w * rect.y1 * ps1 + rect.x1 * ps1;
2842
+ poll_Bpl = poll8_fb_w * ps1;
2844
+ /* line by line ... */
2845
for (line = 0; line < h; line++) {
2846
- memcpy(dst, src, w * ps1);
2847
- memcpy(poll, src, w * ps1);
2848
+ /* pixel by pixel... */
2849
+ for (j = 0; j < w; j++) {
2851
+ unsigned short *ptmp;
2852
+ us = (unsigned short *) (src + ps1 * j);
2853
+ idx = (int) (*us);
2854
+ ptmp = (unsigned short *) (poll + ps1 * j);
2857
+ uc = (unsigned char *) (src + ps1 * j);
2858
+ idx = (int) (*uc);
2859
+ *(poll + ps1 * j) = *uc;
2861
+ ui = (unsigned int *) (dst + ps2 * j);
2862
+ *ui = rgb[cm][idx];
2865
src += xi->bytes_per_line;
2866
- dst += main_bytes_per_line * fac;
2867
+ dst += main_bytes_per_line * (fac/ps1);
2871
@@ -1661,11 +1729,12 @@
2872
} else if (! do_getimage) {
2876
+ if (depth <= 16) {
2877
/* cooked up depth 24 TrueColor */
2878
/* but currently disabled (high bits no useful?) */
2881
+ /* XXX not correct for depth > 8, but do we ever come here in that case? */
2882
src = cmap8to24_fb + 4 * n_off;
2885
@@ -1697,6 +1766,7 @@
2886
void bpp8to24(int x1, int y1, int x2, int y2) {
2889
+ unsigned short *us;
2891
int idx, pixelsize = bpp/8;
2892
int line, k, i, j, h, w;
2893
@@ -1741,18 +1811,34 @@
2898
+ if (depth == 24) {
2899
+ /* pixelsize = 4 */
2900
+ n_off = main_bytes_per_line * y1 + pixelsize * x1;
2902
+ src = main_fb + n_off;
2903
+ dst = cmap8to24_fb + n_off;
2905
+ /* otherwise, the pixel data as is */
2906
+ for (line = 0; line < h; line++) {
2907
+ memcpy(dst, src, w * pixelsize);
2908
+ src += main_bytes_per_line;
2909
+ dst += main_bytes_per_line;
2911
+ } else if (depth <= 16) {
2912
/* need to cook up to depth 24 TrueColor */
2913
- /* pixelsize = 1 */
2914
+ int ps1 = 1, ps2 = 4;
2919
+ /* pixelsize = 1, 2 */
2920
n_off = main_bytes_per_line * y1 + pixelsize * x1;
2922
src = main_fb + n_off;
2923
- dst = cmap8to24_fb + 4 * n_off;
2924
+ dst = cmap8to24_fb + (4/ps1) * n_off;
2928
- int ps1 = 1, ps2 = 4;
2932
@@ -1761,12 +1847,15 @@
2933
for (line = 0; line < h; line++) {
2934
/* pixel by pixel... */
2935
for (j = 0; j < w; j++) {
2937
- uc = (unsigned char *) (src + ps1 * j);
2939
+ us = (unsigned short *) (src + ps1 * j);
2940
+ idx = (int) (*us);
2942
+ uc = (unsigned char *) (src + ps1 * j);
2943
+ idx = (int) (*uc);
2945
ui = (unsigned int *) (dst + ps2 * j);
2947
- idx = (int) (*uc);
2949
if (0 && line % 100 == 0 && j % 32 == 0) fprintf(stderr, "%d %d %u x1=%d y1=%d\n", line, j, root_rgb[idx], x1, y1);
2952
@@ -1779,23 +1868,10 @@
2953
if (db24 > 2) histo[idx]++;
2955
src += main_bytes_per_line;
2956
- dst += main_bytes_per_line * 4;
2957
+ dst += main_bytes_per_line * (4/ps1);
2961
- } else if (depth == 24) {
2962
- /* pixelsize = 4 */
2963
- n_off = main_bytes_per_line * y1 + pixelsize * x1;
2965
- src = main_fb + n_off;
2966
- dst = cmap8to24_fb + n_off;
2968
- /* otherwise, the pixel data as is */
2969
- for (line = 0; line < h; line++) {
2970
- memcpy(dst, src, w * pixelsize);
2971
- src += main_bytes_per_line;
2972
- dst += main_bytes_per_line;
2976
if (last_map_count > MAX_8BPP_WINDOWS/4) {
2977
@@ -1871,7 +1947,7 @@
2978
* now go back and transform and 8bpp regions to TrueColor in
2981
- if (last_map_count && (ncmaps || depth == 8)) {
2982
+ if (last_map_count && (ncmaps || depth <= 16)) {
2984
int win[MAX_8BPP_WINDOWS];
2985
int did[MAX_8BPP_WINDOWS];
2986
Index: ../ica/x11/x11vnc/connections.c
2987
===================================================================
2988
--- ../ica/x11/x11vnc/connections.c (Revision 401)
2989
+++ ../ica/x11/x11vnc/connections.c (Arbeitskopie)
2990
@@ -2149,15 +2149,95 @@
2994
+char *get_repeater_string(char *str, int *len) {
2995
+ int pren, which = 0;
2996
+ int prestring_len = 0;
2997
+ char *prestring = NULL, *ptmp = NULL;
2998
+ char *equals = strchr(str, '=');
2999
+ char *plus = strrchr(str, '+');
3002
+ if (!plus || !equals) {
3007
+ if (strstr(str, "repeater=") == str) {
3008
+ /* ultravnc repeater http://www.uvnc.com/addons/repeater.html */
3009
+ prestring_len = 250;
3010
+ ptmp = (char *) calloc(prestring_len+1, 1);
3011
+ snprintf(ptmp, 250, "%s", str + strlen("repeater="));
3013
+ } else if (strstr(str, "pre=") == str) {
3014
+ prestring_len = strlen(str + strlen("pre="));
3015
+ ptmp = (char *) calloc(prestring_len+1, 1);
3016
+ snprintf(ptmp, prestring_len+1, "%s", str + strlen("pre="));
3018
+ } else if (sscanf(str, "pre%d=", &pren) == 1) {
3019
+ if (pren > 0 && pren <= 16384) {
3020
+ prestring_len = pren;
3021
+ ptmp = (char *) calloc(prestring_len+1, 1);
3022
+ snprintf(prestring, prestring_len, "%s", equals+1);
3026
+ if (ptmp != NULL) {
3029
+ prestring = (char *)calloc(prestring_len+1, 1);
3030
+ /* translate \n to newline, etc. */
3031
+ for (i=0; i < prestring_len; i++) {
3032
+ if (i < prestring_len-1 && *(p+i) == '\\') {
3033
+ if (*(p+i+1) == 'r') {
3034
+ prestring[k++] = '\r'; i++;
3035
+ } else if (*(p+i+1) == 'n') {
3036
+ prestring[k++] = '\n'; i++;
3037
+ } else if (*(p+i+1) == 't') {
3038
+ prestring[k++] = '\t'; i++;
3039
+ } else if (*(p+i+1) == 'a') {
3040
+ prestring[k++] = '\a'; i++;
3041
+ } else if (*(p+i+1) == 'b') {
3042
+ prestring[k++] = '\b'; i++;
3043
+ } else if (*(p+i+1) == 'v') {
3044
+ prestring[k++] = '\v'; i++;
3045
+ } else if (*(p+i+1) == 'f') {
3046
+ prestring[k++] = '\f'; i++;
3047
+ } else if (*(p+i+1) == '\\') {
3048
+ prestring[k++] = '\\'; i++;
3049
+ } else if (*(p+i+1) == 'c') {
3050
+ prestring[k++] = ','; i++;
3052
+ prestring[k++] = *(p+i);
3055
+ prestring[k++] = *(p+i);
3059
+ prestring_len = k;
3062
+ rfbLog("-connect prestring: '%s'\n", prestring);
3068
+ *len = prestring_len;
3073
* Do a reverse connect for a single "host" or "host:port"
3076
extern int ssl_client_mode;
3078
-static int do_reverse_connect(char *str) {
3079
+static int do_reverse_connect(char *str_in) {
3082
+ char *host, *p, *str = str_in, *s = NULL;
3083
+ char *prestring = NULL;
3084
+ int prestring_len = 0;
3085
int rport = 5500, len = strlen(str);
3088
@@ -2173,6 +2253,24 @@
3090
if (unixpw_in_progress) return 0;
3092
+ /* look for repeater pre-string */
3093
+ if (strchr(str, '=') && strrchr(str, '+')
3094
+ && (strstr(str, "pre") == str || strstr(str, "repeater=") == str)) {
3095
+ prestring = get_repeater_string(str, &prestring_len);
3096
+ str = strrchr(str, '+') + 1;
3097
+ } else if (strrchr(str, '+') && strstr(str, "repeater://") == str) {
3098
+ /* repeater://host:port+string */
3099
+ /* repeater=string+host:port */
3100
+ char *plus = strrchr(str, '+');
3101
+ str = (char *) malloc(strlen(str_in)+1);
3104
+ sprintf(str, "repeater=%s+%s", plus+1, str_in + strlen("repeater://"));
3105
+ prestring = get_repeater_string(str, &prestring_len);
3106
+ str = strrchr(str, '+') + 1;
3110
/* copy in to host */
3111
host = (char *) malloc(len+1);
3113
@@ -2204,10 +2302,15 @@
3114
rfbLog("reverse_connect: failed to connect to: %s\n", str);
3117
+ if (prestring != NULL) {
3118
+ write(vncsock, prestring, prestring_len);
3121
#define OPENSSL_REVERSE 4
3123
accept_openssl(OPENSSL_REVERSE, vncsock);
3129
@@ -2220,17 +2323,17 @@
3133
- int is_localhost = 0, user_disabled = 0;
3134
+ int is_localhost = 0, user_disabled_it = 0;
3136
if(!strcmp(host, "localhost") || !strcmp(host, "127.0.0.1")) {
3139
if (getenv("UNIXPW_DISABLE_LOCALHOST")) {
3140
- user_disabled = 1;
3141
+ user_disabled_it = 1;
3144
if (! is_localhost) {
3145
- if (user_disabled ) {
3146
+ if (user_disabled_it) {
3147
rfbLog("reverse_connect: warning disabling localhost constraint in -unixpw\n");
3149
rfbLog("reverse_connect: error not localhost in -unixpw\n");
3150
@@ -2242,10 +2345,23 @@
3151
if (connect_proxy != NULL) {
3152
int sock = proxy_connect(host, rport);
3154
+ if (prestring != NULL) {
3155
+ write(sock, prestring, prestring_len);
3158
cl = rfbNewClient(screen, sock);
3162
+ } else if (prestring != NULL) {
3163
+ int sock = rfbConnectToTcpAddr(host, rport);
3165
+ write(sock, prestring, prestring_len);
3167
+ cl = rfbNewClient(screen, sock);
3172
cl = rfbReverseConnection(screen, host, rport);
3174
@@ -2618,6 +2734,23 @@
3178
+static int turn_off_truecolor = 0;
3180
+static void turn_off_truecolor_ad(rfbClientPtr client) {
3181
+ if (turn_off_truecolor) {
3182
+ rfbLog("turning off truecolor advertising.\n");
3183
+ screen->serverFormat.trueColour = FALSE;
3184
+ screen->displayHook = NULL;
3185
+ screen->serverFormat.redShift = 0;
3186
+ screen->serverFormat.greenShift = 0;
3187
+ screen->serverFormat.blueShift = 0;
3188
+ screen->serverFormat.redMax = 0;
3189
+ screen->serverFormat.greenMax = 0;
3190
+ screen->serverFormat.blueMax = 0;
3191
+ turn_off_truecolor = 0;
3196
* libvncserver callback for when a new client connects
3198
@@ -2761,6 +2894,43 @@
3202
+ if (advertise_truecolor && indexed_color) {
3203
+ int rs = 0, gs = 2, bs = 4;
3204
+ int rm = 3, gm = 3, bm = 3;
3206
+ rs = 0, gs = 8, bs = 16;
3207
+ rm = 255, gm = 255, bm = 255;
3208
+ } else if (bpp >= 16) {
3209
+ rs = 0, gs = 5, bs = 10;
3210
+ rm = 31, gm = 31, bm = 31;
3212
+ rfbLog("advertising truecolor.\n");
3213
+ if (getenv("ADVERT_BMSHIFT")) {
3217
+ client->format.trueColour = TRUE;
3218
+ client->format.redShift = rs;
3219
+ client->format.greenShift = gs;
3220
+ client->format.blueShift = bs;
3221
+ client->format.redMax = rm;
3222
+ client->format.greenMax = gm;
3223
+ client->format.blueMax = bm;
3225
+ rfbSetTranslateFunction(client);
3227
+ screen->serverFormat.trueColour = TRUE;
3228
+ screen->serverFormat.redShift = rs;
3229
+ screen->serverFormat.greenShift = gs;
3230
+ screen->serverFormat.blueShift = bs;
3231
+ screen->serverFormat.redMax = rm;
3232
+ screen->serverFormat.greenMax = gm;
3233
+ screen->serverFormat.blueMax = bm;
3234
+ screen->displayHook = turn_off_truecolor_ad;
3236
+ turn_off_truecolor = 1;
3240
unixpw_in_progress = 1;
3241
unixpw_client = client;
3242
Index: ../ica/x11/x11vnc/cursor.c
3243
===================================================================
3244
--- ../ica/x11/x11vnc/cursor.c (Revision 401)
3245
+++ ../ica/x11/x11vnc/cursor.c (Arbeitskopie)
3250
- if (cmap8to24 && cmap8to24_fb && depth == 8) {
3252
+ if (cmap8to24 && cmap8to24_fb && depth <= 16) {
3257
Index: ../ica/x11/x11vnc/x11vnc_defs.c
3258
===================================================================
3259
--- ../ica/x11/x11vnc/x11vnc_defs.c (Revision 401)
3260
+++ ../ica/x11/x11vnc/x11vnc_defs.c (Arbeitskopie)
3262
int xdamage_base_event_type = 0;
3264
/* date +'lastmod: %Y-%m-%d' */
3265
-char lastmod[] = "0.9.4 lastmod: 2008-01-24";
3266
+char lastmod[] = "0.9.4 lastmod: 2008-06-24";
3268
/* X display info */
3270
Index: ../ica/x11/x11vnc/tkx11vnc.h
3271
===================================================================
3272
--- ../ica/x11/x11vnc/tkx11vnc.h (Revision 401)
3273
+++ ../ica/x11/x11vnc/tkx11vnc.h (Arbeitskopie)
3276
" Properties - Brings up the Properties dialog to set some basic\n"
3277
" parameters. The full tkx11vnc GUI may be accessed\n"
3278
-" via the \\\"Advanced ...\\\" button. Press \\\"Help ...\\\"\n"
3279
+" via the \\\"Advanced ...\\\" button. Press \\\"Help\\\"\n"
3280
" in the Properties dialog for more info.\n"
3282
" Help - Displays this help text.\n"
3284
"If you set \\\"ViewOnly Password\\\" to the empty string that just removes\n"
3285
"the ViewOnly log in aspect: \\\"Password\\\" is still required to log in.\n"
3287
-" - The \\\"Help ...\\\" button shows this help text.\n"
3288
+" - The \\\"Help\\\" button shows this help text.\n"
3290
" - The \\\"Advanced ...\\\" button replaces the Properties dialog with the full\n"
3291
" tkx11vnc GUI. All dynamic settings can be modified in the full GUI.\n"
3292
@@ -4283,7 +4283,7 @@
3294
" bind $w <KeyPress-Escape> \"destroy $w\"\n"
3296
-" pack $b1.apply $b1.cancel $b1.ok -side right -expand 1\n"
3297
+" pack $b1.ok $b1.cancel $b1.apply -side left -expand 0\n"
3298
" lappend props_buttons $b1.apply $b1.cancel $b1.ok\n"
3300
" set b2 \"$w.buttons2\"\n"
3301
@@ -4293,12 +4293,12 @@
3302
" -command \"destroy $w; props_advanced\" -font $bfont\n"
3303
" if {! $icon_noadvanced} {\n"
3304
" lappend props_buttons $b2.advanced\n"
3305
-" pack $b2.advanced -side right -expand 1\n"
3306
+" pack $b2.advanced -side left -expand 0\n"
3309
-" button $b2.help -text \"Help ...\" -command \"menu_help Properties\" -font $bfont\n"
3310
+" button $b2.help -text \"Help\" -command \"menu_help Properties\" -font $bfont\n"
3311
" lappend props_buttons $b2.help\n"
3312
-" pack $b2.help -side right -expand 1\n"
3313
+" pack $b2.help -side left -expand 0\n"
3315
" set vp \"$w.viewpw\"\n"
3316
" if {$have_labelframes} {\n"
3317
@@ -6637,14 +6637,8 @@
3321
-"if {$icon_mode} {\n"
3322
-" if {$tray_embed} {\n"
3323
-" make_gui \"tray\"\n"
3325
-" make_gui \"icon\"\n"
3329
+"proc check_setpasswd {} {\n"
3330
+" global icon_setpasswd\n"
3331
" if {$icon_setpasswd} {\n"
3332
" set m \"You must specify a Session Password\\n\" \n"
3333
" set m \"${m}before VNC clients can connect.\\n\" \n"
3334
@@ -6654,9 +6648,33 @@
3336
" #push_new_value \"unlock\" \"unlock\" 1 0\n"
3341
+" if {[info exists env(X11VNC_ICON_SETPASS)]} {\n"
3342
+" if {$env(X11VNC_ICON_SETPASS) == \"2\"} {\n"
3343
+" global icon_mode_at_startup icon_mode\n"
3344
+" set icon_mode_at_startup 1\n"
3345
+" set icon_mode 2\n"
3350
+"if {$icon_mode} {\n"
3351
+" if {$icon_mode == 2} {\n"
3352
+" make_gui \"full\"\n"
3353
+" } elseif {$tray_embed} {\n"
3354
+" make_gui \"tray\"\n"
3356
+" make_gui \"icon\"\n"
3360
+" check_setpasswd\n"
3362
" make_gui \"full\"\n"
3364
+" check_setpasswd\n"
3368
Index: ../ica/x11/x11vnc/scan.c
3369
===================================================================
3370
--- ../ica/x11/x11vnc/scan.c (Revision 401)
3371
+++ ../ica/x11/x11vnc/scan.c (Arbeitskopie)
3372
@@ -881,7 +881,10 @@
3374
j2 = nfix(j2, ny) + 1;
3376
- /* special case integer magnification with no blending */
3378
+ * special case integer magnification with no blending.
3379
+ * vision impaired magnification usage is interested in this case.
3381
if (mark && ! blend && mag_int && Bpp != 3) {
3382
int jmin, jmax, imin, imax;
3384
@@ -1122,14 +1125,10 @@
3387
/* unroll the loops, can give 20% */
3389
- ((unsigned char) *(src ));
3391
- ((unsigned char) *(src+1));
3393
- ((unsigned char) *(src+2));
3395
- ((unsigned char) *(src+3));
3396
+ pixave[0] += w * ((unsigned char) *(src ));
3397
+ pixave[1] += w * ((unsigned char) *(src+1));
3398
+ pixave[2] += w * ((unsigned char) *(src+2));
3399
+ pixave[3] += w * ((unsigned char) *(src+3));
3400
} else if (Bpp == 2) {
3402
* 16bpp: trickier with green
3403
@@ -1286,8 +1285,12 @@
3405
if (cmap8to24 && cmap8to24_fb) {
3406
src_fb = cmap8to24_fb;
3407
- if (scaling && depth == 8) {
3412
+ } else if (depth <= 16) {
3418
Index: ../ica/x11/x11vnc/gui.c
3419
===================================================================
3420
--- ../ica/x11/x11vnc/gui.c (Revision 401)
3421
+++ ../ica/x11/x11vnc/gui.c (Arbeitskopie)
3422
@@ -558,8 +558,11 @@
3423
if ((q = strchr(p, '=')) != NULL) {
3424
icon_mode_font = strdup(q+1);
3426
- } else if (!strcmp(p, "full")) {
3428
+ } else if (strstr(p, "full") == p) {
3429
+ if (strstr(p, "setp") && 0) {
3430
+ set_env("X11VNC_ICON_MODE", "2");
3431
+ set_env("X11VNC_ICON_SETPASS", "2");
3433
} else if (strstr(p, "tray") == p || strstr(p, "icon") == p) {
3436
Index: ../ica/x11/x11vnc/selection.c
3437
===================================================================
3438
--- ../ica/x11/x11vnc/selection.c (Revision 401)
3439
+++ ../ica/x11/x11vnc/selection.c (Arbeitskopie)
3441
targets[0] = (Atom) xa_targets;
3442
targets[1] = (Atom) XA_STRING;
3444
- data = (unsigned char *)str;
3446
ret = XChangeProperty(ev->xselectionrequest.display,
3447
ev->xselectionrequest.requestor,
3448
ev->xselectionrequest.property,
3449
Index: ../ica/x11/x11vnc/unixpw.c
3450
===================================================================
3451
--- ../ica/x11/x11vnc/unixpw.c (Revision 401)
3452
+++ ../ica/x11/x11vnc/unixpw.c (Arbeitskopie)
3457
+#ifdef IGNORE_GETSPNAM
3458
+#undef LIBVNCSERVER_HAVE_GETSPNAM
3459
+#define LIBVNCSERVER_HAVE_GETSPNAM 0
3462
#if LIBVNCSERVER_HAVE_PWD_H && LIBVNCSERVER_HAVE_GETPWNAM
3463
#if LIBVNCSERVER_HAVE_CRYPT || LIBVNCSERVER_HAVE_LIBCRYPT
3464
#define UNIXPW_CRYPT
3465
Index: ../ica/x11/x11vnc/screen.c
3466
===================================================================
3467
--- ../ica/x11/x11vnc/screen.c (Revision 401)
3468
+++ ../ica/x11/x11vnc/screen.c (Arbeitskopie)
3473
+/* this is only for rawfb */
3474
void set_greyscale_colormap(void) {
3479
rfbSetClientColourMaps(screen, 0, 256);
3482
+/* this is only for rawfb */
3483
void unset_colormap(void) {
3486
@@ -153,35 +156,55 @@
3487
if (0) fprintf(stderr, "unset_colormap: %s\n", raw_fb_pixfmt);
3490
+/* this is X11 case */
3491
void set_colormap(int reset) {
3497
static int init = 1;
3498
- static XColor color[NCOLOR], prev[NCOLOR];
3499
+ static XColor *color = NULL, *prev = NULL;
3500
+ static int ncolor = 0;
3503
int i, ncells, diffs = 0;
3508
if (screen->colourMap.data.shorts) {
3509
free(screen->colourMap.data.shorts);
3510
screen->colourMap.data.shorts = NULL;
3521
-if (0) fprintf(stderr, "unset_colormap: %d\n", reset);
3524
- screen->colourMap.count = NCOLOR;
3526
+ ncolor = 1 << depth;
3530
+ screen->colourMap.count = ncolor;
3531
screen->serverFormat.trueColour = FALSE;
3532
screen->colourMap.is16 = TRUE;
3533
screen->colourMap.data.shorts = (unsigned short *)
3534
- malloc(3*sizeof(unsigned short) * NCOLOR);
3535
+ malloc(3*sizeof(unsigned short) * ncolor);
3537
+ if (color == NULL) {
3538
+ color = (XColor *) calloc(ncolor * sizeof(XColor), 1);
3539
+ prev = (XColor *) calloc(ncolor * sizeof(XColor), 1);
3542
- for (i=0; i < NCOLOR; i++) {
3543
+ for (i=0; i < ncolor; i++) {
3544
prev[i].red = color[i].red;
3545
prev[i].green = color[i].green;
3546
prev[i].blue = color[i].blue;
3547
@@ -205,15 +228,15 @@
3551
- if (ncells != NCOLOR) {
3552
- if (init && ! quiet) {
3553
- rfbLog("set_colormap: number of cells is %d "
3554
- "instead of %d.\n", ncells, NCOLOR);
3556
+ if (ncells != ncolor) {
3558
screen->colourMap.count = ncells;
3561
+ if (init && ! quiet) {
3562
+ rfbLog("set_colormap: number of cells: %d, "
3563
+ "ncolor(%d) is %d.\n", ncells, depth, ncolor);
3566
if (flash_cmap && ! init) {
3567
XWindowAttributes attr;
3572
- if (ncells > NCOLOR && ! quiet) {
3573
+ if (ncells > ncolor && ! quiet) {
3574
rfbLog("set_colormap: big problem: ncells=%d > %d\n",
3579
if (vis->class == TrueColor || vis->class == DirectColor) {
3581
* mentioned in xdpyinfo. Looks OK... perhaps fortuitously.
3583
if (ncells == 8 && ! shift_cmap) {
3593
- if (shift_cmap && k >= 0 && k < NCOLOR) {
3594
+ if (shift_cmap && k >= 0 && k < ncolor) {
3595
/* kludge to copy the colors to higher pixel values */
3596
screen->colourMap.data.shorts[k*3+0] = color[i].red;
3597
screen->colourMap.data.shorts[k*3+1] = color[i].green;
3599
"with uninitialized clients.\n");
3602
- rfbSetClientColourMaps(screen, 0, NCOLOR);
3603
+ rfbSetClientColourMaps(screen, 0, ncolor);
3605
rfbSetClientColourMaps(screen, 0, ncells);
3609
static void debug_colormap(XImage *fb) {
3610
static int debug_cmap = -1;
3611
- int i, k, histo[NCOLOR];
3615
if (debug_cmap < 0) {
3616
if (getenv("DEBUG_CMAP") != NULL) {
3617
@@ -314,11 +338,13 @@
3621
- if (fb->bits_per_pixel > 8) {
3622
+ if (fb->bits_per_pixel > 16) {
3625
+ ncolor = screen->colourMap.count;
3626
+ histo = (int *) calloc(ncolor * sizeof(int), 1);
3628
- for (i=0; i < NCOLOR; i++) {
3629
+ for (i=0; i < ncolor; i++) {
3632
for (k = 0; k < fb->width * fb->height; k++) {
3636
fprintf(stderr, "\nColormap histogram for current screen contents:\n");
3637
- for (i=0; i < NCOLOR; i++) {
3638
+ for (i=0; i < ncolor; i++) {
3639
unsigned short r = screen->colourMap.data.shorts[i*3+0];
3640
unsigned short g = screen->colourMap.data.shorts[i*3+1];
3641
unsigned short b = screen->colourMap.data.shorts[i*3+2];
3643
fprintf(stderr, "\n");
3647
fprintf(stderr, "\n");
3650
@@ -1355,7 +1382,7 @@
3653
raw_fb_bytes_per_line = 0;
3654
-/* rawfb_vnc_reflect = 0;*/
3655
+ rawfb_vnc_reflect = 0;
3659
@@ -1406,6 +1433,7 @@
3660
initialize_pipeinput();
3664
if (closedpy && !view_only && got_noviewonly) {
3665
rfbLog("not closing X DISPLAY under -noviewonly option.\n");
3667
@@ -1936,12 +1964,38 @@
3669
if (DefaultDepth(dpy, scr) == 24) {
3670
vis_str = strdup("TrueColor:32");
3671
- rfbLog("initialize_xdisplay_fb: vis_str set to: %s ",
3672
+ rfbLog("initialize_xdisplay_fb: vis_str set to: %s\n",
3674
visual_id = (VisualID) 0;
3676
set_visual_str_to_something = 1;
3678
+ } else if (DefaultDepth(dpy, scr) < 8) {
3679
+ /* check very low bpp case, e.g. mono or vga16 */
3680
+ Screen *s = DefaultScreenOfDisplay(dpy);
3681
+ XImage *xi = XGetImage_wr(dpy, DefaultRootWindow(dpy), 0, 0, 2, 2, AllPlanes,
3683
+ if (xi && xi->bits_per_pixel < 8) {
3684
+ int lowbpp = xi->bits_per_pixel;
3687
+ sprintf(tmp, "0x%x:8", (int) s->root_visual->visualid);
3688
+ vis_str = strdup(tmp);
3689
+ rfbLog("initialize_xdisplay_fb: low bpp[%d], vis_str "
3690
+ "set to: %s\n", lowbpp, vis_str);
3694
+ rfbLog("initialize_xdisplay_fb: low bpp[%d], "
3695
+ "disabling shm\n", lowbpp);
3697
+ visual_id = (VisualID) 0;
3699
+ set_visual_str_to_something = 1;
3702
+ XDestroyImage(xi);
3706
if (vis_str != NULL) {
3707
@@ -2425,13 +2479,13 @@
3708
" bpp != 32 with depth == 24\n");
3711
- } else if (depth == 8) {
3712
+ } else if (depth <= 16) {
3713
/* need to cook up the screen fb to be depth 24 */
3717
if (!quiet) rfbLog("disabling -8to24 mode:"
3718
- " default depth not 24 or 8\n");
3719
+ " default depth not 16 or less\n");
3723
@@ -2494,9 +2548,14 @@
3727
- if (cmap8to24 && depth == 8) {
3728
- rfb_bytes_per_line *= 4;
3729
- rot_bytes_per_line *= 4;
3732
+ rfb_bytes_per_line *= 4;
3733
+ rot_bytes_per_line *= 4;
3734
+ } else if (depth <= 16) {
3735
+ rfb_bytes_per_line *= 2;
3736
+ rot_bytes_per_line *= 2;
3741
@@ -2601,7 +2660,7 @@
3745
- if (cmap8to24 && depth == 8 && dpy) {
3746
+ if (cmap8to24 && depth <= 16 && dpy) {
3749
vinfo.green_mask = 0;
3750
@@ -2643,13 +2702,14 @@
3754
- if (! have_masks && screen->serverFormat.bitsPerPixel == 8
3755
+ if (! have_masks && screen->serverFormat.bitsPerPixel <= 16
3756
&& dpy && CellsOfScreen(ScreenOfDisplay(dpy, scr))) {
3757
- /* indexed color */
3758
+ /* indexed color. we let 1 <= bpp <= 16, but it is normally 8 */
3761
- rfbLog("X display %s is 8bpp indexed color\n",
3762
- DisplayString(dpy));
3763
+ rfbLog("X display %s is %dbpp indexed color, depth=%d\n",
3764
+ DisplayString(dpy), screen->serverFormat.bitsPerPixel,
3765
+ screen->serverFormat.depth);
3766
if (! flash_cmap && ! overlay) {
3768
rfbLog("In 8bpp PseudoColor mode if you "
3769
@@ -2661,6 +2721,18 @@
3773
+ if (screen->serverFormat.depth < 8) {
3774
+ rfbLog("resetting serverFormat.depth %d -> 8.\n",
3775
+ screen->serverFormat.depth);
3776
+ rfbLog("resetting serverFormat.bpp %d -> 8.\n",
3777
+ screen->serverFormat.bitsPerPixel);
3778
+ screen->serverFormat.depth = 8;
3779
+ screen->serverFormat.bitsPerPixel = 8;
3781
+ if (screen->serverFormat.depth > 8) {
3782
+ rfbLog("WARNING: indexed color depth > 8, Tight encoding will crash.\n");
3785
screen->serverFormat.trueColour = FALSE;
3788
@@ -2693,6 +2765,29 @@
3792
+ if (!have_masks) {
3793
+ int M, B = bits_per_color;
3795
+ if (3*B > fb_bpp) B--;
3799
+ rfbLog("WARNING: all TrueColor RGB masks are zero!\n");
3800
+ rfbLog("WARNING: cooking something up for VNC fb... B=%d M=%d\n", B, M);
3801
+ main_red_mask = M;
3802
+ main_green_mask = M;
3803
+ main_blue_mask = M;
3804
+ main_red_mask = main_red_mask << (2*B);
3805
+ main_green_mask = main_green_mask << (1*B);
3806
+ main_blue_mask = main_blue_mask << (0*B);
3807
+ fprintf(stderr, " red_mask: 0x%08lx %s\n", main_red_mask,
3808
+ bitprint(main_red_mask, 32));
3809
+ fprintf(stderr, " green_mask: 0x%08lx %s\n", main_green_mask,
3810
+ bitprint(main_green_mask, 32));
3811
+ fprintf(stderr, " blue_mask: 0x%08lx %s\n", main_blue_mask,
3812
+ bitprint(main_blue_mask, 32));
3815
/* convert masks to bit shifts and max # colors */
3816
if (main_red_mask) {
3817
while (! (main_red_mask
3818
@@ -2826,8 +2921,10 @@
3821
int n = main_bytes_per_line * fb->height;
3825
+ } else if (depth <= 16) {
3828
cmap8to24_fb = (char *) malloc(n);
3829
memset(cmap8to24_fb, 0, n);
3830
Index: ../ica/x11/x11vnc/x11vnc.c
3831
===================================================================
3832
--- ../ica/x11/x11vnc/x11vnc.c (Revision 401)
3833
+++ ../ica/x11/x11vnc/x11vnc.c (Arbeitskopie)
3836
* x11vnc: a VNC server for X displays.
3838
- * Copyright (c) 2002-2007 Karl J. Runge <runge@karlrunge.com>
3839
+ * Copyright (c) 2002-2008 Karl J. Runge <runge@karlrunge.com>
3840
* All rights reserved.
3842
* This is free software; you can redistribute it and/or modify
3843
@@ -2514,6 +2514,17 @@
3844
shift_cmap = atoi(argv[++i]);
3845
} else if (!strcmp(arg, "-notruecolor")) {
3846
force_indexed_color = 1;
3847
+ } else if (!strcmp(arg, "-advertise_truecolor")) {
3848
+ advertise_truecolor = 1;
3850
+ char *s = argv[i+1];
3851
+ if (s[0] != '-') {
3852
+ if (strstr(s, "reset")) {
3853
+ advertise_truecolor_reset = 1;
3858
} else if (!strcmp(arg, "-overlay")) {
3860
} else if (!strcmp(arg, "-overlay_nocursor")) {
3861
@@ -2589,7 +2600,7 @@
3862
} else if (!strcmp(arg, "-connect") ||
3863
!strcmp(arg, "-connect_or_exit")) {
3865
- if (strchr(argv[++i], '/')) {
3866
+ if (strchr(argv[++i], '/' && !strstr(argv[i], "repeater://"))) {
3867
client_connect_file = strdup(argv[i]);
3869
client_connect = strdup(argv[i]);
3870
@@ -3211,6 +3222,7 @@
3871
} else if (!strcmp(arg, "-wait")) {
3873
waitms = atoi(argv[++i]);
3875
} else if (!strcmp(arg, "-wait_ui")) {
3877
wait_ui = atof(argv[++i]);
3878
@@ -3280,7 +3292,22 @@
3880
#if LIBVNCSERVER_HAVE_LIBPTHREAD
3881
} else if (!strcmp(arg, "-threads")) {
3882
+#if defined(X11VNC_THREADED)
3885
+ if (getenv("X11VNC_THREADED")) {
3889
+ rfbLog("The -threads mode is unstable and not tested or maintained.\n");
3890
+ rfbLog("It is disabled in the source code. If you really need\n");
3891
+ rfbLog("the feature you can reenable it at build time by setting\n");
3892
+ rfbLog("-DX11VNC_THREADED in CPPFLAGS. Or set X11VNC_THREADED=1\n");
3893
+ rfbLog("in your runtime environment.\n");
3898
} else if (!strcmp(arg, "-nothreads")) {
3901
@@ -3830,11 +3857,14 @@
3902
if (! s) s = "SSH_CONNECTION";
3903
fprintf(stderr, "\n");
3904
rfbLog("Skipping -ssl/-stunnel constraint in"
3906
- rfbLog("mode, assuming your SSH encryption"
3908
+ " -unixpw mode,\n");
3909
+ rfbLog("assuming your SSH encryption"
3911
+ rfbLog(" %s\n", s);
3912
rfbLog("Setting -localhost in SSH + -unixpw"
3914
+ rfbLog("If you *actually* want SSL, restart"
3915
+ " with -ssl on the cmdline\n");
3916
fprintf(stderr, "\n");
3917
allow_list = strdup("127.0.0.1");
3919
@@ -4202,6 +4232,9 @@
3920
if (! quiet) rfbLog("Using default X display.\n");
3923
+ if (clip_str != NULL && dpy != NULL) {
3924
+ check_xinerama_clip();
3927
scr = DefaultScreen(dpy);
3928
rootwin = RootWindow(dpy, scr);
3929
@@ -4756,6 +4789,28 @@
3931
initialize_speeds();
3933
+ if (speeds_read_rate_measured > 100) {
3934
+ /* framebuffer read is fast at > 100 MB/sec */
3935
+ if (! got_waitms) {
3937
+ if (waitms < 10) {
3941
+ rfbLog("fast read: reset wait ms to: %d\n", waitms);
3944
+ if (! got_deferupdate && ! got_defer) {
3945
+ if (defer_update > 15) {
3946
+ defer_update = 15;
3948
+ screen->deferUpdateTime = defer_update;
3950
+ rfbLog("fast read: reset defer ms to: %d\n", defer_update);
3955
initialize_keyboard_and_pointer();
3957
if (inetd && use_openssl) {
3958
Index: ../ica/x11/x11vnc/ssltools.h
3959
===================================================================
3960
--- ../ica/x11/x11vnc/ssltools.h (Revision 401)
3961
+++ ../ica/x11/x11vnc/ssltools.h (Arbeitskopie)
3963
"name_opt = ca_default # Subject Name options\n"
3964
"cert_opt = ca_default # Certificate field options\n"
3966
-"default_days = 365 # how long to certify for\n"
3967
+"default_days = 730 # how long to certify for\n"
3968
"default_crl_days= 30 # how long before next CRL\n"
3969
"default_md = md5 # which md to use.\n"
3970
"preserve = no # keep passed DN ordering\n"
3971
@@ -333,6 +333,13 @@
3972
" echo \"Creating new x11vnc certificate and key for name: $type $name0\"\n"
3975
+" req_args=$REQ_ARGS\n"
3976
+" if echo \"$req_args\" | grep 'days' > /dev/null; then\n"
3979
+" req_args=\"$req_args -days 730\"\n"
3982
" cnf=\"$DIR/tmp/cnf.$$\"\n"
3983
" trap \"rm -f \\\"$cnf\\\"\" 0 1 2 15\n"
3986
" direrror \"$DIR/CA/self.cnf.$type\"\n"
3988
" cat \"$DIR/CA/self.cnf.$type\" | sed -e \"s/%NAME/$name0/\" > \"$cnf\" || exit 1\n"
3989
-" \"$OPENSSL\" req -config \"$cnf\" -nodes -new -newkey rsa:2048 -x509 $REQ_ARGS \\\n"
3990
+" \"$OPENSSL\" req -config \"$cnf\" -nodes -new -newkey rsa:2048 -x509 $req_args \\\n"
3991
" -keyout \"$DIR/$dest.key\" \\\n"
3992
" -out \"$DIR/$dest.crt\"\n"
3995
" direrror \"$DIR/CA/ssl.cnf.$type\"\n"
3997
" cat \"$DIR/CA/ssl.cnf.$type\" | sed -e \"s/%NAME/$name0/\" > \"$cnf\" || exit 1\n"
3998
-" \"$OPENSSL\" req -config \"$cnf\" -nodes -new -newkey rsa:2048 $REQ_ARGS \\\n"
3999
+" \"$OPENSSL\" req -config \"$cnf\" -nodes -new -newkey rsa:2048 $req_args \\\n"
4000
" -keyout \"$DIR/$dest.key\" \\\n"
4001
" -out \"$DIR/$dest.req\"\n"
4003
@@ -1400,32 +1407,32 @@
4005
" sxcmd=$have_xinit\n"
4007
-" echo \"$sxcmd $sess -- $* -nolisten tcp -auth $authfile $FD_OPTS\" 1>&2\n"
4008
+" echo \"$sxcmd $sess -- $* $nolisten -auth $authfile $FD_OPTS\" 1>&2\n"
4009
" if [ \"X$have_root\" != \"X\" ]; then\n"
4010
-" $sxcmd $sess -- $* -nolisten tcp -auth $authfile $FD_OPTS 1>&2 &\n"
4011
+" $sxcmd $sess -- $* $nolisten -auth $authfile $FD_OPTS 1>&2 &\n"
4013
" if [ \"X$ns\" = \"X0\" ]; then\n"
4014
-" $have_nohup sh -c \"$sxcmd $sess -- $* -nolisten tcp -auth $authfile $FD_OPTS\" 1>&2 &\n"
4015
+" $have_nohup sh -c \"$sxcmd $sess -- $* $nolisten -auth $authfile $FD_OPTS\" 1>&2 &\n"
4017
" # Why did we ever sleep before starting the server??\n"
4018
-" $have_nohup sh -c \"(sleep $ns; $sxcmd $sess -- $* -nolisten tcp -auth $authfile $FD_OPTS)\" 1>&2 &\n"
4019
+" $have_nohup sh -c \"(sleep $ns; $sxcmd $sess -- $* $nolisten -auth $authfile $FD_OPTS)\" 1>&2 &\n"
4025
" # need to emulate startx/xinit ourselves...\n"
4026
-" echo \"$* -nolisten tcp -auth $authfile $FD_OPTS\" 1>&2\n"
4027
+" echo \"$* $nolisten -auth $authfile $FD_OPTS\" 1>&2\n"
4028
" if [ \"X$have_root\" != \"X\" ]; then\n"
4029
-" $have_nohup $* -nolisten tcp -auth $authfile $FD_OPTS 1>&2 &\n"
4030
+" $have_nohup $* $nolisten -auth $authfile $FD_OPTS 1>&2 &\n"
4033
" $have_nohup $sess 1>&2 &\n"
4035
" if [ \"X$ns\" = \"X0\" ]; then\n"
4036
-" $have_nohup sh -c \"$* -nolisten tcp -auth $authfile $FD_OPTS\" 1>&2 &\n"
4037
+" $have_nohup sh -c \"$* $nolisten -auth $authfile $FD_OPTS\" 1>&2 &\n"
4039
-" $have_nohup sh -c \"(sleep $ns; $* -nolisten tcp -auth $authfile $FD_OPTS)\" 1>&2 &\n"
4040
+" $have_nohup sh -c \"(sleep $ns; $* $nolisten -auth $authfile $FD_OPTS)\" 1>&2 &\n"
4044
@@ -1719,6 +1726,8 @@
4045
"depth=${depth:-16}\n"
4046
"geom=${geom:-1280x1024}\n"
4048
+"nolisten=${FD_NOLISTEN:-\"-nolisten tcp\"}\n"
4050
"if [ \"X$X11VNC_CREATE_GEOM\" != \"X\" -a \"X$FD_GEOM\" = \"X\" ]; then\n"
4051
" FD_GEOM=$X11VNC_CREATE_GEOM\n"
4053
Index: ../ica/x11/x11vnc/sslhelper.c
4054
===================================================================
4055
--- ../ica/x11/x11vnc/sslhelper.c (Revision 401)
4056
+++ ../ica/x11/x11vnc/sslhelper.c (Arbeitskopie)
4057
@@ -1567,6 +1567,9 @@
4058
if (screen->httpListenSock >= 0 && screen->httpPort > 0) {
4061
+ if (screen->httpListenSock == -2) {
4064
if (mode == OPENSSL_HTTPS && ! have_httpd) {
4065
rfbLog("SSL: accept_openssl[%d]: no httpd socket for "
4066
"-https mode\n", getpid());
4067
@@ -1695,10 +1698,11 @@
4068
/* send the failure tag: */
4071
- if (https_port_redir < 0) {
4072
+ if (https_port_redir < 0 || (strstr(buf, "PORT=") || strstr(buf, "port="))) {
4073
char *q = strstr(buf, "Host:");
4075
+ int fport = 443, match = 0;
4078
if (q && strstr(q, "\n")) {
4079
q += strlen("Host:") + 1;
4080
while (*q != '\n') {
4081
@@ -1706,12 +1710,25 @@
4082
if (*q == ':' && sscanf(q, ":%d", &p) == 1) {
4083
if (p > 0 && p < 65536) {
4092
+ if (!match || !https_port_redir) {
4094
+ if (sscanf(buf, "PORT=%d,", &p) == 1) {
4095
+ if (p > 0 && p < 65536) {
4098
+ } else if (sscanf(buf, "port=%d,", &p) == 1) {
4099
+ if (p > 0 && p < 65536) {
4104
sprintf(num, "HP=%d,", fport);
4107
@@ -2113,8 +2130,16 @@
4110
} else if (rc < 0) {
4111
+ unsigned long err;
4114
- rfbLog("SSL: ssl_helper[%d]: SSL_accept() *FATAL: %d\n", getpid(), rc);
4115
+ rfbLog("SSL: ssl_helper[%d]: SSL_accept() *FATAL: %d SSL FAILED\n", getpid(), rc);
4116
+ while ((err = ERR_get_error()) != 0) {
4117
+ rfbLog("SSL: %s\n", ERR_error_string(err, NULL));
4118
+ if (cnt++ > 100) {
4124
} else if (dnow() > start + 3.0) {
4125
@@ -2157,9 +2182,18 @@
4128
rfbLog("SSL: ssl_helper[%d]: accepted client %s x509 cert is:\n", getpid(), name);
4129
+#if LIBVNCSERVER_HAVE_X509_PRINT_EX_FP
4130
X509_print_ex_fp(stderr, x, 0, XN_FLAG_MULTILINE);
4133
+#if LIBVNCSERVER_HAVE_X509_PRINT_EX_FP
4134
X509_print_ex_fp(cr, x, 0, XN_FLAG_MULTILINE);
4136
+ rfbLog("** not compiled with libssl X509_print_ex_fp() function **\n");
4137
+ if (users_list && strstr(users_list, "sslpeer=")) {
4138
+ rfbLog("** -users sslpeer= will not work! **\n");
4144
Index: ../ica/x11/x11vnc/help.c
4145
===================================================================
4146
--- ../ica/x11/x11vnc/help.c (Revision 401)
4147
+++ ../ica/x11/x11vnc/help.c (Arbeitskopie)
4148
@@ -128,6 +128,13 @@
4149
" into two parts to be accessed via separate viewers by\n"
4150
" running a separate x11vnc on each part.\n"
4152
+" Use '-clip xinerama0' to clip to the first xinerama\n"
4153
+" sub-screen (if xinerama is active). xinerama1 for the\n"
4154
+" 2nd sub-screen, etc. This way you don't need to figure\n"
4155
+" out the WxH+X+Y of the desired xinerama sub-screen.\n"
4156
+" screens are sorted in increasing distance from the\n"
4157
+" (0,0) origin (I.e. not the Xserver's order).\n"
4159
"-flashcmap In 8bpp indexed color, let the installed colormap flash\n"
4160
" as the pointer moves from window to window (slow).\n"
4161
" Also try the -8to24 option to avoid flash altogether.\n"
4162
@@ -140,6 +147,11 @@
4163
" a colormap histogram. Example: -shiftcmap 240\n"
4164
"-notruecolor For 8bpp displays, force indexed color (i.e. a colormap)\n"
4165
" even if it looks like 8bpp TrueColor (rare problem).\n"
4166
+"-advertise_truecolor If the X11 display is indexed color, lie to clients\n"
4167
+" when they first connect by telling them it is truecolor.\n"
4168
+" To workaround RealVNC: inPF has colourMap but not 8bpp\n"
4169
+" Use '-advertise_truecolor reset' to reset client fb too.\n"
4171
"-visual n This option probably does not do what you think.\n"
4172
" It simply *forces* the visual used for the framebuffer;\n"
4173
" this may be a bad thing... (e.g. messes up colors or\n"
4174
@@ -147,8 +159,10 @@
4175
" workarounds. n may be a decimal number, or 0x hex.\n"
4176
" Run xdpyinfo(1) for the values. One may also use\n"
4177
" \"TrueColor\", etc. see <X11/X.h> for a list. If the\n"
4178
-" string ends in \":m\" then for better or for worse the\n"
4179
-" visual depth is forced to be m.\n"
4180
+" string ends in \":m\" then for better or for worse\n"
4181
+" the visual depth is forced to be m. You may want to\n"
4182
+" use -noshm when using this option (so XGetImage may\n"
4183
+" automatically translate the pixel data).\n"
4185
"-overlay Handle multiple depth visuals on one screen, e.g. 8+24\n"
4186
" and 24+8 overlay visuals (the 32 bits per pixel are\n"
4187
@@ -429,6 +443,46 @@
4188
" Be careful about the location of this file if x11vnc\n"
4189
" is running as root (e.g. via gdm(1), etc).\n"
4192
+" Repeater mode: Some services provide an intermediate\n"
4193
+" \"vnc repeater\": http://www.uvnc.com/addons/repeater.html\n"
4194
+" (and also http://koti.mbnet.fi/jtko/ for linux port)\n"
4195
+" that acts as a proxy / gateway. Modes like these require\n"
4196
+" an initial string to be sent for the reverse connection\n"
4197
+" before the VNC protocol is started. Here are the ways\n"
4200
+" -connect pre=some_string+host:port\n"
4201
+" -connect pre128=some_string+host:port\n"
4202
+" -connect repeater=ID:1234+host:port\n"
4203
+" -connect repeater=23.45.67.89::5501+host:port\n"
4205
+" SSVNC notation is also supported:\n"
4207
+" -connect repeater://host:port+ID:1234\n"
4209
+" As with normal -connect usage, if the repeater port is\n"
4210
+" not supplied 5500 is assumed.\n"
4212
+" The basic idea is between the special tag, e.g. \"pre=\"\n"
4213
+" and \"+\" is the pre-string to be sent. Note that in\n"
4214
+" this case host:port is the repeater server, NOT the\n"
4215
+" vnc viewer. Somehow the pre-string tells the repeater\n"
4216
+" server how to find the vnc viewer and connect you to it.\n"
4218
+" In the case pre=some_string+host:port, \"some_string\"\n"
4219
+" is simply sent. In the case preNNN=some_string+host:port\n"
4220
+" \"some_string\" is sent in a null padded buffer of\n"
4221
+" length NNN. repeater= is the same as pre250=, this is\n"
4222
+" the ultravnc repeater buffer size.\n"
4224
+" Strings like \"\\n\" and \"\\r\", etc. are expanded to\n"
4225
+" newline and carriage return. \"\\c\" is expanded to\n"
4226
+" \",\" since the connect string is comma separated.\n"
4228
+" See also the -proxy option below for additional ways\n"
4229
+" to plumb reverse connections.\n"
4231
"-connect_or_exit str As with -connect, except if none of the reverse\n"
4232
" connections succeed, then x11vnc shutdowns immediately.\n"
4234
@@ -896,6 +950,10 @@
4235
" and so \"-ssl SAVE -redirect host:port\" can act as a\n"
4236
" replacement for stunnel(1).\n"
4238
+" This mode only allows one redirected connection.\n"
4239
+" The -forever option does not apply. Use -inetd or\n"
4240
+" -loop for persistant service.\n"
4242
"-display WAIT:... A special usage mode for the normal -display option.\n"
4243
" Useful with -unixpw, but can be used independently\n"
4244
" of it. If the display string begins with WAIT: then\n"
4245
@@ -1531,8 +1589,8 @@
4247
" If you set the env. var REQ_ARGS='...' it will be\n"
4248
" passed to openssl req(1). A common use would be\n"
4249
-" REQ_ARGS='-days 730' to bump up the expiration date\n"
4250
-" (2 years in this case).\n"
4251
+" REQ_ARGS='-days 1095' to bump up the expiration date\n"
4252
+" (3 years in this case).\n"
4254
"-sslEncKey [pem] Utility to encrypt an existing PEM file with a\n"
4255
" passphrase you supply when prompted. For that key to be\n"
4256
@@ -3075,8 +3133,8 @@
4257
"-forcedpms If the system supports the DPMS (Display Power\n"
4258
" Management Signaling) extension, then try to keep the\n"
4259
" monitor in a powered off state. This is to prevent\n"
4260
-" nosey people at the physical display from viewing\n"
4261
-" what is on the screen. Be sure lock the screen before\n"
4262
+" nosey people at the physical display from viewing what\n"
4263
+" is on the screen. Be sure to lock the screen before\n"
4266
" This method is far from bullet proof, e.g. suppose\n"
4267
@@ -3151,7 +3209,11 @@
4269
"-threads Whether or not to use the threaded libvncserver\n"
4270
"-nothreads algorithm [rfbRunEventLoop] if libpthread is available\n"
4272
+" Default: %s. NOTE: The -threads mode is now\n"
4273
+" disabled due to its unstable behavior. Not recommended,\n"
4274
+" but you can recompile with -DX11VNC_THREADED in\n"
4275
+" CPPFLAGS if you need to use it. You can also set the\n"
4276
+" env. variable X11VNC_THREADED=1\n"
4278
"-fs f If the fraction of changed tiles in a poll is greater\n"
4279
" than f, the whole screen is updated. Default: %.2f\n"
4280
Index: ../ica/x11/x11vnc/options.c
4281
===================================================================
4282
--- ../ica/x11/x11vnc/options.c (Revision 401)
4283
+++ ../ica/x11/x11vnc/options.c (Arbeitskopie)
4285
int flash_cmap = 0; /* follow installed colormaps */
4286
int shift_cmap = 0; /* ncells < 256 and needs shift of pixel values */
4287
int force_indexed_color = 0; /* whether to force indexed color for 8bpp */
4288
+int advertise_truecolor = 0;
4289
+int advertise_truecolor_reset = 0;
4290
int cmap8to24 = 0; /* -8to24 */
4291
int xform24to32 = 0; /* -24to32 */
4292
char *cmap8to24_str = NULL;
4294
* poll times of 10-35ms, so maybe this value cuts the idle load by 2 or so.
4297
+int got_waitms = 0;
4298
double wait_ui = 2.0;
4299
double slow_fb = 0.0;
4300
double xrefresh = 0.0;
4303
/* threaded vs. non-threaded (default) */
4304
#if LIBVNCSERVER_HAVE_LIBPTHREAD && defined(X11VNC_THREADED)
4305
-int use_threads = 1;
4306
+int use_threads = 0; /* not 1. now X11VNC_THREADED means enable it at all. */
4308
int use_threads = 0;
4310
Index: ../ica/x11/libvncserver/stats.c
4311
===================================================================
4312
--- ../ica/x11/libvncserver/stats.c (Revision 401)
4313
+++ ../ica/x11/libvncserver/stats.c (Arbeitskopie)
4315
case rfbEncodingZlibHex: snprintf(buf, len, "zlibhex"); break;
4316
case rfbEncodingUltra: snprintf(buf, len, "ultra"); break;
4317
case rfbEncodingZRLE: snprintf(buf, len, "ZRLE"); break;
4318
+ case rfbEncodingZYWRLE: snprintf(buf, len, "ZYWRLE"); break;
4319
case rfbEncodingCache: snprintf(buf, len, "cache"); break;
4320
case rfbEncodingCacheEnable: snprintf(buf, len, "cacheEnable"); break;
4321
case rfbEncodingXOR_Zlib: snprintf(buf, len, "xorZlib"); break;
4322
Index: ../ica/x11/libvncserver/rfbregion.c
4323
===================================================================
4324
--- ../ica/x11/libvncserver/rfbregion.c (Revision 401)
4325
+++ ../ica/x11/libvncserver/rfbregion.c (Arbeitskopie)
4327
sraRgnPopRect(sraRegion *rgn, sraRect *rect, unsigned long flags) {
4328
sraSpan *vcurr, *hcurr;
4329
sraSpan *vend, *hend;
4330
- rfbBool right2left = flags & 2;
4331
- rfbBool bottom2top = flags & 1;
4332
+ rfbBool right2left = (flags & 2) == 2;
4333
+ rfbBool bottom2top = (flags & 1) == 1;
4335
/* - Pick correct order */
4337
Index: ../ica/x11/libvncserver/zywrletemplate.c
4338
===================================================================
4339
--- ../ica/x11/libvncserver/zywrletemplate.c (Revision 401)
4340
+++ ../ica/x11/libvncserver/zywrletemplate.c (Arbeitskopie)
4342
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4343
********************************************************************/
4346
+ V0.02 : 2008/02/04 : Fix mis encode/decode when width != scanline
4347
+ (Thanks Johannes Schindelin, author of LibVNC
4349
+ V0.01 : 2007/02/06 : Initial release
4352
/* #define ZYWRLE_ENCODE */
4353
/* #define ZYWRLE_DECODE */
4354
#define ZYWRLE_QUANTIZE
4359
- Senecal, J. G., P. Lindstrom, M. A. Duchaineau, and K. I. Joy, "An Improved N-Bit to N-Bit Reversible Haar-Like Transform," Pacific Graphics 2004, October 2004, pp. 371-380.
4361
- Shapiro, JM: Embedded Image Coding Using Zerotrees of Wavelet Coefficients, IEEE Trans. Signal. Process., Vol.41, pp.3445-3462 (1993).
4364
+ Senecal, J. G., P. Lindstrom, M. A. Duchaineau, and K. I. Joy, "An Improved N-Bit to N-Bit Reversible Haar-Like Transform," Pacific Graphics 2004, October 2004, pp. 371-380.
4366
+ Shapiro, JM: Embedded Image Coding Using Zerotrees of Wavelet Coefficients, IEEE Trans. Signal. Process., Vol.41, pp.3445-3462 (1993).
4371
#define ZYWRLE_LOAD_PIXEL __RFB_CONCAT2E(ZYWRLE_LOAD_PIXEL,BPP)
4372
#define ZYWRLE_SAVE_PIXEL __RFB_CONCAT2E(ZYWRLE_SAVE_PIXEL,BPP)
4374
-/* Packing/Unpacking pixel stuffs. */
4375
-/* Endian conversion stuffs. */
4376
+/* Packing/Unpacking pixel stuffs.
4377
+ Endian conversion stuffs. */
4381
@@ -147,11 +154,9 @@
4382
{0x0000F000,0x00000000,0x00000000},
4383
{0x0000C000,0x00F0F0F0,0x00000000},
4384
{0x0000C000,0x00C0C0C0,0x00F0F0F0},
4386
- {0x0000FF00,0x00000000,0x00000000},
4387
+/* {0x0000FF00,0x00000000,0x00000000},
4388
{0x0000FF00,0x00FFFFFF,0x00000000},
4389
- {0x0000FF00,0x00FFFFFF,0x00FFFFFF},
4391
+ {0x0000FF00,0x00FFFFFF,0x00FFFFFF}, */
4394
/* Type B:Non liner quantization filter. */
4397
/* Piecewise-Linear Harr(PLHarr) */
4398
int X0 = (int)*pX0, X1 = (int)*pX1;
4399
- int orgX0=X0, orgX1=X1;
4400
- if ((X0^X1) & 0x80) {
4401
+ int orgX0 = X0, orgX1 = X1;
4402
+ if ((X0 ^ X1) & 0x80) {
4405
if (((X1^orgX1)&0x80)==0) {
4410
- if (((X0^orgX0) & 0x80) == 0) {
4411
+ if (((X0 ^ orgX0) & 0x80) == 0) {
4413
X1 += X0; /* L = A */
4415
@@ -325,27 +330,26 @@
4416
*pX1 = (signed char)X0;
4419
- 1D-Wavelet transform.
4420
+ 1D-Wavelet transform.
4422
- In coefficients array, the famous 'pyramid' decomposition is well used.
4423
+ In coefficients array, the famous 'pyramid' decomposition is well used.
4426
- |L0L0L0L0|L0L0L0L0|H0H0H0H0|H0H0H0H0| : level 0
4427
- |L1L1L1L1|H1H1H1H1|H0H0H0H0|H0H0H0H0| : level 1
4429
+ |L0L0L0L0|L0L0L0L0|H0H0H0H0|H0H0H0H0| : level 0
4430
+ |L1L1L1L1|H1H1H1H1|H0H0H0H0|H0H0H0H0| : level 1
4432
- But this method needs line buffer because H/L is different position from X0/X1.
4433
- So, I used 'interleave' decomposition instead of it.
4434
+ But this method needs line buffer because H/L is different position from X0/X1.
4435
+ So, I used 'interleave' decomposition instead of it.
4438
- |L0H0L0H0|L0H0L0H0|L0H0L0H0|L0H0L0H0| : level 0
4439
- |L1H0H1H0|L1H0H1H0|L1H0H1H0|L1H0H1H0| : level 1
4441
+ |L0H0L0H0|L0H0L0H0|L0H0L0H0|L0H0L0H0| : level 0
4442
+ |L1H0H1H0|L1H0H1H0|L1H0H1H0|L1H0H1H0| : level 1
4444
- In this method, H/L and X0/X1 is always same position.
4445
- This lead us to more speed and less memory.
4446
- Of cause, the result of both method is quite same
4447
- because it's only difference that coefficient position.
4448
+ In this method, H/L and X0/X1 is always same position.
4449
+ This lead us to more speed and less memory.
4450
+ Of cause, the result of both method is quite same
4451
+ because it's only difference that coefficient position.
4454
static InlineX void WaveletLevel(int* data, int size, int l, int SkipPixel)
4457
@@ -389,11 +393,11 @@
4458
for (y = 0; y < height / s; y++) {
4459
for (x = 0; x < width / s; x++) {
4461
- these are same following code.
4462
- pH[x] = pH[x] / (~pM[x]+1) * (~pM[x]+1);
4463
- ( round pH[x] with pM[x] bit )
4464
- '&' operator isn't 'round' but is 'floor'.
4465
- So, we must offset when pH[x] is negative.
4466
+ these are same following code.
4467
+ pH[x] = pH[x] / (~pM[x]+1) * (~pM[x]+1);
4468
+ ( round pH[x] with pM[x] bit )
4469
+ '&' operator isn't 'round' but is 'floor'.
4470
+ So, we must offset when pH[x] is negative.
4472
if (((signed char*)pH)[0] & 0x80)
4473
((signed char*)pH)[0] += ~((signed char*)pM)[0];
4474
@@ -410,36 +414,35 @@
4478
- Type B:Non liner quantization filter.
4479
+ Type B:Non liner quantization filter.
4481
- Coefficients have Gaussian curve and smaller value which is
4482
- large part of coefficients isn't more important than larger value.
4483
- So, I use filter of Non liner quantize/dequantize table.
4484
- In general, Non liner quantize formula is explained as following.
4485
+ Coefficients have Gaussian curve and smaller value which is
4486
+ large part of coefficients isn't more important than larger value.
4487
+ So, I use filter of Non liner quantize/dequantize table.
4488
+ In general, Non liner quantize formula is explained as following.
4490
- y=f(x) = sign(x)*round( ((abs(x)/(2^7))^ r )* 2^(bo-1) )*2^(8-bo)
4491
- x=f-1(y) = sign(y)*round( ((abs(y)/(2^7))^(1/r))* 2^(bi-1) )*2^(8-bi)
4492
- ( r:power coefficient bi:effective MSB in input bo:effective MSB in output )
4493
+ y=f(x) = sign(x)*round( ((abs(x)/(2^7))^ r )* 2^(bo-1) )*2^(8-bo)
4494
+ x=f-1(y) = sign(y)*round( ((abs(y)/(2^7))^(1/r))* 2^(bi-1) )*2^(8-bi)
4495
+ ( r:power coefficient bi:effective MSB in input bo:effective MSB in output )
4497
- r < 1.0 : Smaller value is more important than larger value.
4498
- r > 1.0 : Larger value is more important than smaller value.
4499
- r = 1.0 : Liner quantization which is same with EZW style.
4500
+ r < 1.0 : Smaller value is more important than larger value.
4501
+ r > 1.0 : Larger value is more important than smaller value.
4502
+ r = 1.0 : Liner quantization which is same with EZW style.
4504
- r = 0.75 is famous non liner quantization used in MP3 audio codec.
4505
- In contrast to audio data, larger value is important in wavelet coefficients.
4506
- So, I select r = 2.0 table( quantize is x^2, dequantize sqrt(x) ).
4507
+ r = 0.75 is famous non liner quantization used in MP3 audio codec.
4508
+ In contrast to audio data, larger value is important in wavelet coefficients.
4509
+ So, I select r = 2.0 table( quantize is x^2, dequantize sqrt(x) ).
4511
- As compared with EZW style liner quantization, this filter tended to be
4512
- more sharp edge and be more compression rate but be more blocking noise and be less quality.
4513
- Especially, the surface of graphic objects has distinguishable noise in middle quality mode.
4514
+ As compared with EZW style liner quantization, this filter tended to be
4515
+ more sharp edge and be more compression rate but be more blocking noise and be less quality.
4516
+ Especially, the surface of graphic objects has distinguishable noise in middle quality mode.
4518
- We need only quantized-dequantized(filtered) value rather than quantized value itself
4519
- because all values are packed or palette-lized in later ZRLE section.
4520
- This lead us not to need to modify client decoder when we change
4521
- the filtering procedure in future.
4522
- Client only decodes coefficients given by encoder.
4523
+ We need only quantized-dequantized(filtered) value rather than quantized value itself
4524
+ because all values are packed or palette-lized in later ZRLE section.
4525
+ This lead us not to need to modify client decoder when we change
4526
+ the filtering procedure in future.
4527
+ Client only decodes coefficients given by encoder.
4530
static InlineX void FilterWaveletSquare(int* pBuf, int width, int height, int level, int l)
4537
- while(pTop < pEnd) {
4538
+ while (pTop < pEnd) {
4539
WaveletLevel(pTop, height,l, width);
4542
@@ -494,12 +497,13 @@
4545
#ifdef ZYWRLE_DECODE
4546
-static InlineX void InvWavelet(int* pBuf, int width, int height, int level) {
4547
+static InlineX void InvWavelet(int* pBuf, int width, int height, int level)
4553
- for (l = level-1; l >= 0; l--) {
4554
+ for (l = level - 1; l >= 0; l--) {
4562
-/* Load/Save coefficients stuffs. */
4563
-/* Coefficients manages as 24 bits little-endian pixel. */
4564
+/* Load/Save coefficients stuffs.
4565
+ Coefficients manages as 24 bits little-endian pixel. */
4566
#define ZYWRLE_LOAD_COEFF(pSrc,R,G,B) { \
4567
R = ((signed char*)pSrc)[2]; \
4568
G = ((signed char*)pSrc)[1]; \
4569
@@ -532,25 +536,22 @@
4573
- RGB <=> YUV conversion stuffs.
4574
- YUV coversion is explained as following formula in strict meaning:
4575
- Y = 0.299R + 0.587G + 0.114B ( 0<=Y<=255)
4576
- U = -0.169R - 0.331G + 0.500B (-128<=U<=127)
4577
- V = 0.500R - 0.419G - 0.081B (-128<=V<=127)
4578
+ RGB <=> YUV conversion stuffs.
4579
+ YUV coversion is explained as following formula in strict meaning:
4580
+ Y = 0.299R + 0.587G + 0.114B ( 0<=Y<=255)
4581
+ U = -0.169R - 0.331G + 0.500B (-128<=U<=127)
4582
+ V = 0.500R - 0.419G - 0.081B (-128<=V<=127)
4584
- I use simple conversion RCT(reversible color transform) which is described
4585
- in JPEG-2000 specification.
4586
- Y = (R + 2G + B)/4 ( 0<=Y<=255)
4587
- U = B-G (-256<=U<=255)
4588
- V = R-G (-256<=V<=255)
4589
+ I use simple conversion RCT(reversible color transform) which is described
4590
+ in JPEG-2000 specification.
4591
+ Y = (R + 2G + B)/4 ( 0<=Y<=255)
4592
+ U = B-G (-256<=U<=255)
4593
+ V = R-G (-256<=V<=255)
4596
#define ROUND(x) (((x)<0)?0:(((x)>255)?255:(x)))
4598
- RCT is N-bit RGB to N-bit Y and N+1-bit UV.
4599
- For make Same N-bit, UV is lossy.
4600
- More exact PLHarr, we reduce to odd range(-127<=x<=127).
4602
+ /* RCT is N-bit RGB to N-bit Y and N+1-bit UV.
4603
+ For make Same N-bit, UV is lossy.
4604
+ More exact PLHarr, we reduce to odd range(-127<=x<=127). */
4605
#define ZYWRLE_RGBYUV1(R,G,B,Y,U,V,ymask,uvmask) { \
4606
Y = (R+(G<<1)+B)>>2; \
4608
@@ -581,71 +582,77 @@
4612
- coefficient packing/unpacking stuffs.
4613
- Wavelet transform makes 4 sub coefficient image from 1 original image.
4614
+ coefficient packing/unpacking stuffs.
4615
+ Wavelet transform makes 4 sub coefficient image from 1 original image.
4617
- model with pyramid decomposition:
4627
+ model with pyramid decomposition:
4638
- So, we must transfer each sub images individually in strict meaning.
4639
- But at least ZRLE meaning, following one decompositon image is same as
4640
- avobe individual sub image. I use this format.
4641
- (Strictly saying, transfer order is reverse(Hxy->Hy->Hx->L)
4642
- for simplified procedure for any wavelet level.)
4643
+ So, we must transfer each sub images individually in strict meaning.
4644
+ But at least ZRLE meaning, following one decompositon image is same as
4645
+ avobe individual sub image. I use this format.
4646
+ (Strictly saying, transfer order is reverse(Hxy->Hy->Hx->L)
4647
+ for simplified procedure for any wavelet level.)
4668
+#define INC_PTR(data) \
4670
+ if( data-pData >= (w+uw) ){ \
4671
+ data += scanline-(w+uw); \
4675
-#define ZYWRLE_TRANSFER_COEFF(pBuf,data,r,width,height,level,TRANS) \
4676
+#define ZYWRLE_TRANSFER_COEFF(pBuf,data,r,w,h,scanline,level,TRANS) \
4682
- pH += (s>>1)*width; \
4683
- pEnd = pH+height*width; \
4686
while (pH < pEnd) { \
4687
- pLine = pH+width; \
4689
while (pH < pLine) { \
4695
- pH += (s-1)*width; \
4699
-#define ZYWRLE_PACK_COEFF(pBuf,data,r,width,height,level) \
4700
- ZYWRLE_TRANSFER_COEFF(pBuf,data,r,width,height,level,ZYWRLE_LOAD_COEFF(pH,R,G,B);ZYWRLE_SAVE_PIXEL(data,R,G,B);)
4701
+#define ZYWRLE_PACK_COEFF(pBuf,data,r,width,height,scanline,level) \
4702
+ ZYWRLE_TRANSFER_COEFF(pBuf,data,r,width,height,scanline,level,ZYWRLE_LOAD_COEFF(pH,R,G,B);ZYWRLE_SAVE_PIXEL(data,R,G,B);)
4704
-#define ZYWRLE_UNPACK_COEFF(pBuf,data,r,width,height,level) \
4705
- ZYWRLE_TRANSFER_COEFF(pBuf,data,r,width,height,level,ZYWRLE_LOAD_PIXEL(data,R,G,B);ZYWRLE_SAVE_COEFF(pH,R,G,B);)
4706
+#define ZYWRLE_UNPACK_COEFF(pBuf,data,r,width,height,scanline,level) \
4707
+ ZYWRLE_TRANSFER_COEFF(pBuf,data,r,width,height,scanline,level,ZYWRLE_LOAD_PIXEL(data,R,G,B);ZYWRLE_SAVE_COEFF(pH,R,G,B);)
4709
#define ZYWRLE_SAVE_UNALIGN(data,TRANS) \
4711
- pEnd = pTop + (w+uw)*(h+uh)-w*h; \
4712
+ pEnd = pBuf + (w+uw)*(h+uh); \
4713
while (pTop < pEnd) { \
4720
-#define ZYWRLE_LOAD_UNALIGN(data,pData,TRANS) \
4721
+#define ZYWRLE_LOAD_UNALIGN(data,TRANS) \
4728
#ifdef ZYWRLE_DECODE
4729
-static InlineX void ZYWRLE_YUVRGB(int* pBuf, PIXEL_T* data, int width, int height, int scanline)
4731
+static InlineX void ZYWRLE_YUVRGB(int* pBuf, PIXEL_T* data, int width, int height, int scanline) {
4735
@@ -740,15 +746,14 @@
4738
#ifdef ZYWRLE_ENCODE
4739
-PIXEL_T* ZYWRLE_ANALYZE (PIXEL_T* dst, PIXEL_T* src, int w, int h, int scanline, int level, int* pBuf)
4741
+PIXEL_T* ZYWRLE_ANALYZE(PIXEL_T* dst, PIXEL_T* src, int w, int h, int scanline, int level, int* pBuf) {
4753
@@ -759,15 +764,16 @@
4757
- ZYWRLE_LOAD_UNALIGN(src,pSrc,*(PIXEL_T*)pTop=*pSrc;)
4759
+ ZYWRLE_LOAD_UNALIGN(src,*(PIXEL_T*)pTop=*pData;)
4760
ZYWRLE_RGBYUV(pBuf, src, w, h, scanline);
4761
Wavelet(pBuf, w, h, level);
4762
for (l = 0; l < level; l++) {
4763
- ZYWRLE_PACK_COEFF(pBuf, dst, 3, w, h, l);
4764
- ZYWRLE_PACK_COEFF(pBuf, dst, 2, w, h, l);
4765
- ZYWRLE_PACK_COEFF(pBuf, dst, 1, w, h, l);
4766
- if (l == level-1) {
4767
- ZYWRLE_PACK_COEFF(pBuf, dst, 0, w, h, l);
4768
+ ZYWRLE_PACK_COEFF(pBuf, dst, 3, w, h, scanline, l);
4769
+ ZYWRLE_PACK_COEFF(pBuf, dst, 2, w, h, scanline, l);
4770
+ ZYWRLE_PACK_COEFF(pBuf, dst, 1, w, h, scanline, l);
4771
+ if (l == level - 1) {
4772
+ ZYWRLE_PACK_COEFF(pBuf, dst, 0, w, h, scanline, l);
4775
ZYWRLE_SAVE_UNALIGN(dst,*dst=*(PIXEL_T*)pTop;)
4785
@@ -794,18 +800,19 @@
4790
for (l = 0; l < level; l++) {
4791
- ZYWRLE_UNPACK_COEFF(pBuf, src, 3, w, h, l);
4792
- ZYWRLE_UNPACK_COEFF(pBuf, src, 2, w, h, l);
4793
- ZYWRLE_UNPACK_COEFF(pBuf, src, 1, w, h, l);
4794
- if (l == level-1) {
4795
- ZYWRLE_UNPACK_COEFF(pBuf, src, 0, w, h, l);
4796
+ ZYWRLE_UNPACK_COEFF(pBuf, src, 3, w, h, scanline, l);
4797
+ ZYWRLE_UNPACK_COEFF(pBuf, src, 2, w, h, scanline, l);
4798
+ ZYWRLE_UNPACK_COEFF(pBuf, src, 1, w, h, scanline, l);
4799
+ if (l == level - 1) {
4800
+ ZYWRLE_UNPACK_COEFF(pBuf, src, 0, w, h, scanline, l);
4803
ZYWRLE_SAVE_UNALIGN(src,*(PIXEL_T*)pTop=*src;)
4804
InvWavelet(pBuf, w, h, level);
4805
ZYWRLE_YUVRGB(pBuf, dst, w, h, scanline);
4806
- ZYWRLE_LOAD_UNALIGN(dst,pDst,*pDst=*(PIXEL_T*)pTop;)
4807
+ ZYWRLE_LOAD_UNALIGN(dst,*pData=*(PIXEL_T*)pTop;)
4811
Index: ../ica/x11/libvncserver/rfbserver.c
4812
===================================================================
4813
--- ../ica/x11/libvncserver/rfbserver.c (Revision 401)
4814
+++ ../ica/x11/libvncserver/rfbserver.c (Arbeitskopie)
4815
@@ -2631,7 +2631,7 @@
4816
rows = (h-1)/cl->correMaxHeight+1;
4817
nUpdateRegionRects += rectsPerRow*rows;
4819
- sraRgnReleaseIterator(i);
4820
+ sraRgnReleaseIterator(i); i=NULL;
4821
} else if (cl->preferredEncoding == rfbEncodingUltra) {
4822
nUpdateRegionRects = 0;
4824
@@ -2645,7 +2645,7 @@
4825
rfbScaledCorrection(cl->screen, cl->scaledScreen, &x, &y, &w, &h, "rfbSendFramebufferUpdate");
4826
nUpdateRegionRects += (((h-1) / (ULTRA_MAX_SIZE( w ) / w)) + 1);
4828
- sraRgnReleaseIterator(i);
4829
+ sraRgnReleaseIterator(i); i=NULL;
4830
#ifdef LIBVNCSERVER_HAVE_LIBZ
4831
} else if (cl->preferredEncoding == rfbEncodingZlib) {
4832
nUpdateRegionRects = 0;
4833
@@ -2660,7 +2660,7 @@
4834
rfbScaledCorrection(cl->screen, cl->scaledScreen, &x, &y, &w, &h, "rfbSendFramebufferUpdate");
4835
nUpdateRegionRects += (((h-1) / (ZLIB_MAX_SIZE( w ) / w)) + 1);
4837
- sraRgnReleaseIterator(i);
4838
+ sraRgnReleaseIterator(i); i=NULL;
4839
#ifdef LIBVNCSERVER_HAVE_LIBJPEG
4840
} else if (cl->preferredEncoding == rfbEncodingTight) {
4841
nUpdateRegionRects = 0;
4842
@@ -2681,7 +2681,7 @@
4844
nUpdateRegionRects += n;
4846
- sraRgnReleaseIterator(i);
4847
+ sraRgnReleaseIterator(i); i=NULL;
4851
@@ -2806,6 +2806,10 @@
4856
+ sraRgnReleaseIterator(i);
4860
if ( nUpdateRegionRects == 0xFFFF &&
4861
!rfbSendLastRectMarker(cl) )
4862
@@ -3062,12 +3066,20 @@
4865
char buf[sz_rfbSetColourMapEntriesMsg + 256 * 3 * 2];
4866
- rfbSetColourMapEntriesMsg *scme = (rfbSetColourMapEntriesMsg *)buf;
4867
- uint16_t *rgb = (uint16_t *)(&buf[sz_rfbSetColourMapEntriesMsg]);
4869
+ rfbSetColourMapEntriesMsg *scme;
4871
rfbColourMap* cm = &cl->screen->colourMap;
4875
+ if (nColours > 256) {
4876
+ /* some rare hardware has, e.g., 4096 colors cells: PseudoColor:12 */
4877
+ wbuf = (char *) malloc(sz_rfbSetColourMapEntriesMsg + nColours * 3 * 2);
4880
+ scme = (rfbSetColourMapEntriesMsg *)wbuf;
4881
+ rgb = (uint16_t *)(&wbuf[sz_rfbSetColourMapEntriesMsg]);
4883
scme->type = rfbSetColourMapEntries;
4885
scme->firstColour = Swap16IfLE(firstColour);
4886
@@ -3091,13 +3103,15 @@
4888
len += nColours * 3 * 2;
4890
- if (rfbWriteExact(cl, buf, len) < 0) {
4891
+ if (rfbWriteExact(cl, wbuf, len) < 0) {
4892
rfbLogPerror("rfbSendSetColourMapEntries: write");
4894
+ if (wbuf != buf) free(wbuf);
4898
rfbStatRecordMessageSent(cl, rfbSetColourMapEntries, len, len);
4899
+ if (wbuf != buf) free(wbuf);