diff options
author | runge <runge> | 2008-10-19 16:16:41 +0000 |
---|---|---|
committer | runge <runge> | 2008-10-19 16:16:41 +0000 |
commit | 1c03dd4d51a35103e93c3adaf1f619c868324c77 (patch) | |
tree | acbd2c41501e1c491023ab36717febdab32aff03 /x11vnc/x11vnc.c | |
parent | 16c7ea1b357ab518ee5a40f2a663843f064479a9 (diff) | |
download | libtdevnc-1c03dd4d51a35103e93c3adaf1f619c868324c77.tar.gz libtdevnc-1c03dd4d51a35103e93c3adaf1f619c868324c77.zip |
x11vnc: -chatwindow, -scale WxH, -enc changes.
Diffstat (limited to 'x11vnc/x11vnc.c')
-rw-r--r-- | x11vnc/x11vnc.c | 1643 |
1 files changed, 815 insertions, 828 deletions
diff --git a/x11vnc/x11vnc.c b/x11vnc/x11vnc.c index 73e9290..5b7530c 100644 --- a/x11vnc/x11vnc.c +++ b/x11vnc/x11vnc.c @@ -149,251 +149,12 @@ * main routine for the x11vnc program */ -static void check_cursor_changes(void); -static void record_last_fb_update(void); -static int choose_delay(double dt); -static void watch_loop(void); static int limit_shm(void); static void check_rcfile(int argc, char **argv); static void immediate_switch_user(int argc, char* argv[]); static void print_settings(int try_http, int bg, char *gui_str); static void check_loop_mode(int argc, char* argv[], int force); - -static void check_cursor_changes(void) { - static double last_push = 0.0; - - if (unixpw_in_progress) return; - - cursor_changes += check_x11_pointer(); - - if (cursor_changes) { - double tm, max_push = 0.125, multi_push = 0.01, wait = 0.02; - int cursor_shape, dopush = 0, link, latency, netrate; - - if (! all_clients_initialized()) { - /* play it safe */ - return; - } - - if (0) cursor_shape = cursor_shape_updates_clients(screen); - - dtime0(&tm); - link = link_rate(&latency, &netrate); - if (link == LR_DIALUP) { - max_push = 0.2; - wait = 0.05; - } else if (link == LR_BROADBAND) { - max_push = 0.075; - wait = 0.05; - } else if (link == LR_LAN) { - max_push = 0.01; - } else if (latency < 5 && netrate > 200) { - max_push = 0.01; - } - - if (tm > last_push + max_push) { - dopush = 1; - } else if (cursor_changes > 1 && tm > last_push + multi_push) { - dopush = 1; - } - - if (dopush) { - mark_rect_as_modified(0, 0, 1, 1, 1); - fb_push_wait(wait, FB_MOD); - last_push = tm; - } else { - rfbPE(0); - } - } - cursor_changes = 0; -} - -static void record_last_fb_update(void) { - static int rbs0 = -1; - static time_t last_call = 0; - time_t now = time(NULL); - int rbs = -1; - rfbClientIteratorPtr iter; - rfbClientPtr cl; - - if (last_fb_bytes_sent == 0) { - last_fb_bytes_sent = now; - last_call = now; - } - - if (now <= last_call + 1) { - /* check every second or so */ - return; - } - - if (unixpw_in_progress) return; - - last_call = now; - - if (! screen) { - return; - } - - iter = rfbGetClientIterator(screen); - while( (cl = rfbClientIteratorNext(iter)) ) { -#if 0 - rbs += cl->rawBytesEquivalent; -#else - rbs += rfbStatGetSentBytesIfRaw(cl); -#endif - } - rfbReleaseClientIterator(iter); - - if (rbs != rbs0) { - rbs0 = rbs; - if (debug_tiles > 1) { - printf("record_last_fb_update: %d %d\n", - (int) now, (int) last_fb_bytes_sent); - } - last_fb_bytes_sent = now; - } -} - -static int choose_delay(double dt) { - static double t0 = 0.0, t1 = 0.0, t2 = 0.0, now; - static int x0, y0, x1, y1, x2, y2, first = 1; - int dx0, dy0, dx1, dy1, dm, i, msec = waitms; - double cut1 = 0.15, cut2 = 0.075, cut3 = 0.25; - double bogdown_time = 0.25, bave = 0.0; - int bogdown = 1, bcnt = 0; - int ndt = 8, nave = 3; - double fac = 1.0; - int db = 0; - static double dts[8]; - - if (waitms == 0) { - return waitms; - } - if (nofb) { - return waitms; - } - - if (first) { - for(i=0; i<ndt; i++) { - dts[i] = 0.0; - } - first = 0; - } - - now = dnow(); - - /* - * first check for bogdown, e.g. lots of activity, scrolling text - * from command output, etc. - */ - if (nap_ok) { - dt = 0.0; - } - if (! wait_bog) { - bogdown = 0; - - } else if (button_mask || now < last_keyboard_time + 2*bogdown_time) { - /* - * let scrolls & keyboard input through the normal way - * otherwise, it will likely just annoy them. - */ - bogdown = 0; - - } else if (dt > 0.0) { - /* - * inspect recent dt's: - * 0 1 2 3 4 5 6 7 dt - * ^ ^ ^ - */ - for (i = ndt - (nave - 1); i < ndt; i++) { - bave += dts[i]; - bcnt++; - if (dts[i] < bogdown_time) { - bogdown = 0; - break; - } - } - bave += dt; - bcnt++; - bave = bave / bcnt; - if (dt < bogdown_time) { - bogdown = 0; - } - } else { - bogdown = 0; - } - /* shift for next time */ - for (i = 0; i < ndt-1; i++) { - dts[i] = dts[i+1]; - } - dts[ndt-1] = dt; - -if (0 && dt > 0.0) fprintf(stderr, "dt: %.5f %.4f\n", dt, dnowx()); - if (bogdown) { - if (use_xdamage) { - /* DAMAGE can queue ~1000 rectangles for a scroll */ - clear_xdamage_mark_region(NULL, 0); - } - msec = (int) (1000 * 1.75 * bave); - if (dts[ndt - nave - 1] > 0.75 * bave) { - msec = 1.5 * msec; - set_xdamage_mark(0, 0, dpy_x, dpy_y); - } - if (msec > 1500) { - msec = 1500; - } - if (msec < waitms) { - msec = waitms; - } - db = (db || debug_tiles); - if (db) fprintf(stderr, "bogg[%d] %.3f %.3f %.3f %.3f\n", - msec, dts[ndt-4], dts[ndt-3], dts[ndt-2], dts[ndt-1]); - return msec; - } - - /* next check for pointer motion, keystrokes, to speed up */ - t2 = dnow(); - x2 = cursor_x; - y2 = cursor_y; - - dx0 = nabs(x1 - x0); - dy0 = nabs(y1 - y0); - dx1 = nabs(x2 - x1); - dy1 = nabs(y2 - y1); - if (dx1 > dy1) { - dm = dx1; - } else { - dm = dy1; - } - - if ((dx0 || dy0) && (dx1 || dy1)) { - if (t2 < t0 + cut1 || t2 < t1 + cut2 || dm > 20) { - fac = wait_ui * 1.25; - } - } else if ((dx1 || dy1) && dm > 40) { - fac = wait_ui; - } - - if (fac == 1 && t2 < last_keyboard_time + cut3) { - fac = wait_ui; - } - msec = (int) ((double) waitms / fac); - if (msec == 0) { - msec = 1; - } - - x0 = x1; - y0 = y1; - t0 = t1; - - x1 = x2; - y1 = y2; - t1 = t2; - - return msec; -} - static int tsdo_timeout_flag; static void tsdo_timeout (int sig) { @@ -894,7 +655,7 @@ fprintf(stderr, "Set: %s %s %s -> %s\n", f, t, e, num); #endif } -void check_redir_services(void) { +static void check_redir_services(void) { #if !NO_X11 Atom a; char prop[513]; @@ -1091,324 +852,6 @@ void ssh_remote_tunnel(char *instr, int lport) { free(s); } -void check_filexfer(void) { - static time_t last_check = 0; - rfbClientIteratorPtr iter; - rfbClientPtr cl; - int transferring = 0; - - if (time(NULL) <= last_check) { - return; - } - -#if 0 - if (getenv("NOFT")) { - return; - } -#endif - - iter = rfbGetClientIterator(screen); - while( (cl = rfbClientIteratorNext(iter)) ) { - if (cl->fileTransfer.receiving) { - transferring = 1; - break; - } - if (cl->fileTransfer.sending) { - transferring = 1; - break; - } - } - rfbReleaseClientIterator(iter); - - if (transferring) { - double start = dnow(); - while (dnow() < start + 0.5) { - rfbCFD(5000); - rfbCFD(1000); - rfbCFD(0); - } - } else { - last_check = time(NULL); - } -} - -/* - * main x11vnc loop: polls, checks for events, iterate libvncserver, etc. - */ -static void watch_loop(void) { - int cnt = 0, tile_diffs = 0, skip_pe = 0; - double tm, dtr, dt = 0.0; - time_t start = time(NULL); - - if (use_threads) { - rfbRunEventLoop(screen, -1, TRUE); - } - - while (1) { - char msg[] = "new client: %s taking unixpw client off hold.\n"; - - got_user_input = 0; - got_pointer_input = 0; - got_local_pointer_input = 0; - got_pointer_calls = 0; - got_keyboard_input = 0; - got_keyboard_calls = 0; - urgent_update = 0; - - x11vnc_current = dnow(); - - if (! use_threads) { - dtime0(&tm); - if (! skip_pe) { - if (unixpw_in_progress) { - rfbClientPtr cl = unixpw_client; - if (cl && cl->onHold) { - rfbLog(msg, cl->host); - unixpw_client->onHold = FALSE; - } - } else { - measure_send_rates(1); - } - - unixpw_in_rfbPE = 1; - - /* - * do a few more since a key press may - * have induced a small change we want to - * see quickly (just 1 rfbPE will likely - * only process the subsequent "up" event) - */ - if (tm < last_keyboard_time + 0.16) { - rfbPE(0); - rfbPE(0); - rfbPE(-1); - rfbPE(0); - rfbPE(0); - } else { - rfbPE(-1); - } - - unixpw_in_rfbPE = 0; - - if (unixpw_in_progress) { - /* rfbPE loop until logged in. */ - skip_pe = 0; - check_new_clients(); - continue; - } else { - measure_send_rates(0); - fb_update_sent(NULL); - } - } else { - if (unixpw_in_progress) { - skip_pe = 0; - check_new_clients(); - continue; - } - } - dtr = dtime(&tm); - - if (! cursor_shape_updates) { - /* undo any cursor shape requests */ - disable_cursor_shape_updates(screen); - } - if (screen && screen->clientHead) { - int ret = check_user_input(dt, dtr, - tile_diffs, &cnt); - /* true: loop back for more input */ - if (ret == 2) { - skip_pe = 1; - } - if (ret) { - if (debug_scroll) fprintf(stderr, "watch_loop: LOOP-BACK: %d\n", ret); - continue; - } - } - /* watch for viewonly input piling up: */ - if ((got_pointer_calls > got_pointer_input) || - (got_keyboard_calls > got_keyboard_input)) { - eat_viewonly_input(10, 3); - } - } else { - /* -threads here. */ - if (wireframe && button_mask) { - check_wireframe(); - } - } - skip_pe = 0; - - if (shut_down) { - clean_up_exit(0); - } - - if (unixpw_in_progress) { - check_new_clients(); - continue; - } - - if (! urgent_update) { - if (do_copy_screen) { - do_copy_screen = 0; - copy_screen(); - } - - check_new_clients(); - check_ncache(0, 0); - check_xevents(0); - check_autorepeat(); - check_pm(); - check_filexfer(); - check_keycode_state(); - check_connect_inputs(); - check_gui_inputs(); - check_stunnel(); - check_openssl(); - check_https(); - record_last_fb_update(); - check_padded_fb(); - check_fixscreen(); - check_xdamage_state(); - check_xrecord_reset(0); - check_add_keysyms(); - check_new_passwds(0); -#ifdef ENABLE_GRABLOCAL - if (grab_local) { - check_local_grab(); - } -#endif - if (started_as_root) { - check_switched_user(); - } - - if (first_conn_timeout < 0) { - start = time(NULL); - first_conn_timeout = -first_conn_timeout; - } - } - - if (rawfb_vnc_reflect) { - static time_t lastone = 0; - if (time(NULL) > lastone + 10) { - lastone = time(NULL); - vnc_reflect_process_client(); - } - } - - if (! screen || ! screen->clientHead) { - /* waiting for a client */ - if (first_conn_timeout) { - if (time(NULL) - start > first_conn_timeout) { - rfbLog("No client after %d secs.\n", - first_conn_timeout); - shut_down = 1; - } - } - usleep(200 * 1000); - continue; - } - - if (first_conn_timeout && all_clients_initialized()) { - first_conn_timeout = 0; - } - - if (nofb) { - /* no framebuffer polling needed */ - if (cursor_pos_updates) { - check_x11_pointer(); - } -#ifdef MACOSX - else check_x11_pointer(); -#endif - continue; - } - - if (button_mask && (!show_dragging || pointer_mode == 0)) { - /* - * if any button is pressed in this mode do - * not update rfb screen, but do flush the - * X11 display. - */ - X_LOCK; - XFlush_wr(dpy); - X_UNLOCK; - dt = 0.0; - } else { - static double last_dt = 0.0; - double xdamage_thrash = 0.4; - - check_cursor_changes(); - - /* for timing the scan to try to detect thrashing */ - - if (use_xdamage && last_dt > xdamage_thrash) { - clear_xdamage_mark_region(NULL, 0); - } - - if (unixpw_in_progress) continue; - - if (rawfb_vnc_reflect) { - vnc_reflect_process_client(); - } - dtime0(&tm); - -#if !NO_X11 - if (xrandr_present && !xrandr && xrandr_maybe) { - int delay = 180; - /* there may be xrandr right after xsession start */ - if (tm < x11vnc_start + delay || tm < last_client + delay) { - int tw = 20; - if (auth_file != NULL) { - tw = 120; - } - X_LOCK; - if (tm < x11vnc_start + tw || tm < last_client + tw) { - XSync(dpy, False); - } else { - XFlush_wr(dpy); - } - X_UNLOCK; - } - check_xrandr_event("before-scan"); - } -#endif - if (use_snapfb) { - int t, tries = 3; - copy_snap(); - for (t=0; t < tries; t++) { - tile_diffs = scan_for_updates(0); - } - } else { - tile_diffs = scan_for_updates(0); - } - dt = dtime(&tm); - if (! nap_ok) { - last_dt = dt; - } - - if ((debug_tiles || debug_scroll > 1 || debug_wireframe > 1) - && (tile_diffs > 4 || debug_tiles > 1)) { - double rate = (tile_x * tile_y * bpp/8 * tile_diffs) / dt; - fprintf(stderr, "============================= TILES: %d dt: %.4f" - " t: %.4f %.2f MB/s nap_ok: %d\n", tile_diffs, dt, - tm - x11vnc_start, rate/1000000.0, nap_ok); - } - - } - - /* sleep a bit to lessen load */ - if (! urgent_update) { - int wait = choose_delay(dt); - if (wait > 2*waitms) { - /* bog case, break it up */ - nap_sleep(wait, 10); - } else { - usleep(wait * 1000); - } - } - cnt++; - } -} - /* * check blacklist for OSs with tight shm limits. */ @@ -1885,7 +1328,7 @@ static void print_settings(int try_http, int bg, char *gui_str) { : "null"); fprintf(stderr, " overlay: %d\n", overlay); fprintf(stderr, " ovl_cursor: %d\n", overlay_cursor); - fprintf(stderr, " scaling: %d %.4f\n", scaling, scale_fac); + fprintf(stderr, " scaling: %d %.4f %.4f\n", scaling, scale_fac_x, scale_fac_y); fprintf(stderr, " viewonly: %d\n", view_only); fprintf(stderr, " shared: %d\n", shared); fprintf(stderr, " conn_once: %d\n", connect_once); @@ -2482,9 +1925,13 @@ int main(int argc, char* argv[]) { exit(0); } } - } else if (!strcmp(arg, "-find")) { + continue; + } + if (!strcmp(arg, "-find")) { use_dpy = strdup("WAIT:cmd=FINDDISPLAY"); - } else if (!strcmp(arg, "-finddpy") || strstr(arg, "-listdpy") == arg) { + continue; + } + if (!strcmp(arg, "-finddpy") || strstr(arg, "-listdpy") == arg) { int ic = 0; use_dpy = strdup("WAIT:cmd=FINDDISPLAY-run"); if (argc > i+1) { @@ -2496,15 +1943,25 @@ int main(int argc, char* argv[]) { } wait_for_client(&ic, NULL, 0); exit(0); - } else if (!strcmp(arg, "-create")) { + continue; + } + if (!strcmp(arg, "-create")) { use_dpy = strdup("WAIT:cmd=FINDCREATEDISPLAY-Xvfb"); - } else if (!strcmp(arg, "-xdummy")) { + continue; + } + if (!strcmp(arg, "-xdummy")) { use_dpy = strdup("WAIT:cmd=FINDCREATEDISPLAY-Xdummy"); - } else if (!strcmp(arg, "-xvnc")) { + continue; + } + if (!strcmp(arg, "-xvnc")) { use_dpy = strdup("WAIT:cmd=FINDCREATEDISPLAY-Xvnc"); - } else if (!strcmp(arg, "-xvnc_redirect")) { + continue; + } + if (!strcmp(arg, "-xvnc_redirect")) { use_dpy = strdup("WAIT:cmd=FINDCREATEDISPLAY-Xvnc.redirect"); - } else if (!strcmp(arg, "-redirect")) { + continue; + } + if (!strcmp(arg, "-redirect")) { char *q, *t, *t0 = "WAIT:cmd=FINDDISPLAY-vnc_redirect"; CHECK_ARGC t = (char *) malloc(strlen(t0) + strlen(argv[++i]) + 2); @@ -2512,23 +1969,35 @@ int main(int argc, char* argv[]) { if (q) *q = ' '; sprintf(t, "%s=%s", t0, argv[i]); use_dpy = t; - } else if (!strcmp(arg, "-auth") || !strcmp(arg, "-xauth")) { + continue; + } + if (!strcmp(arg, "-auth") || !strcmp(arg, "-xauth")) { CHECK_ARGC auth_file = strdup(argv[++i]); - } else if (!strcmp(arg, "-N")) { + continue; + } + if (!strcmp(arg, "-N")) { display_N = 1; - } else if (!strcmp(arg, "-autoport")) { + continue; + } + if (!strcmp(arg, "-autoport")) { CHECK_ARGC auto_port = atoi(argv[++i]); - } else if (!strcmp(arg, "-reflect")) { + continue; + } + if (!strcmp(arg, "-reflect")) { CHECK_ARGC raw_fb_str = (char *) malloc(4 + strlen(argv[i]) + 1); sprintf(raw_fb_str, "vnc:%s", argv[++i]); shared = 1; - } else if (!strcmp(arg, "-tsd")) { + continue; + } + if (!strcmp(arg, "-tsd")) { CHECK_ARGC terminal_services_daemon = strdup(argv[++i]); - } else if (!strcmp(arg, "-id") || !strcmp(arg, "-sid")) { + continue; + } + if (!strcmp(arg, "-id") || !strcmp(arg, "-sid")) { CHECK_ARGC if (!strcmp(arg, "-sid")) { rootshift = 1; @@ -2551,19 +2020,31 @@ int main(int argc, char* argv[]) { argv[i]); exit(1); } - } else if (!strcmp(arg, "-waitmapped")) { + continue; + } + if (!strcmp(arg, "-waitmapped")) { subwin_wait_mapped = 1; - } else if (!strcmp(arg, "-clip")) { + continue; + } + if (!strcmp(arg, "-clip")) { CHECK_ARGC clip_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-flashcmap")) { + continue; + } + if (!strcmp(arg, "-flashcmap")) { flash_cmap = 1; - } else if (!strcmp(arg, "-shiftcmap")) { + continue; + } + if (!strcmp(arg, "-shiftcmap")) { CHECK_ARGC shift_cmap = atoi(argv[++i]); - } else if (!strcmp(arg, "-notruecolor")) { + continue; + } + if (!strcmp(arg, "-notruecolor")) { force_indexed_color = 1; - } else if (!strcmp(arg, "-advertise_truecolor")) { + continue; + } + if (!strcmp(arg, "-advertise_truecolor")) { advertise_truecolor = 1; if (i < argc-1) { char *s = argv[i+1]; @@ -2574,16 +2055,24 @@ int main(int argc, char* argv[]) { i++; } } - } else if (!strcmp(arg, "-overlay")) { + continue; + } + if (!strcmp(arg, "-overlay")) { overlay = 1; - } else if (!strcmp(arg, "-overlay_nocursor")) { + continue; + } + if (!strcmp(arg, "-overlay_nocursor")) { overlay = 1; overlay_cursor = 0; - } else if (!strcmp(arg, "-overlay_yescursor")) { + continue; + } + if (!strcmp(arg, "-overlay_yescursor")) { overlay = 1; overlay_cursor = 2; + continue; + } #if !SKIP_8TO24 - } else if (!strcmp(arg, "-8to24")) { + if (!strcmp(arg, "-8to24")) { cmap8to24 = 1; if (i < argc-1) { char *s = argv[i+1]; @@ -2592,58 +2081,105 @@ int main(int argc, char* argv[]) { i++; } } + continue; + } #endif - } else if (!strcmp(arg, "-24to32")) { + if (!strcmp(arg, "-24to32")) { xform24to32 = 1; - } else if (!strcmp(arg, "-visual")) { + continue; + } + if (!strcmp(arg, "-visual")) { CHECK_ARGC visual_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-scale")) { + continue; + } + if (!strcmp(arg, "-scale")) { CHECK_ARGC scale_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-scale_cursor")) { + continue; + } + if (!strcmp(arg, "-geometry")) { + CHECK_ARGC + scale_str = strdup(argv[++i]); + continue; + } + if (!strcmp(arg, "-scale_cursor")) { CHECK_ARGC scale_cursor_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-viewonly")) { + continue; + } + if (!strcmp(arg, "-viewonly")) { view_only = 1; - } else if (!strcmp(arg, "-noviewonly")) { + continue; + } + if (!strcmp(arg, "-noviewonly")) { view_only = 0; got_noviewonly = 1; - } else if (!strcmp(arg, "-shared")) { + continue; + } + if (!strcmp(arg, "-shared")) { shared = 1; - } else if (!strcmp(arg, "-noshared")) { + continue; + } + if (!strcmp(arg, "-noshared")) { shared = 0; - } else if (!strcmp(arg, "-once")) { + continue; + } + if (!strcmp(arg, "-once")) { connect_once = 1; got_connect_once = 1; - } else if (!strcmp(arg, "-many") || !strcmp(arg, "-forever")) { + continue; + } + if (!strcmp(arg, "-many") || !strcmp(arg, "-forever")) { connect_once = 0; - } else if (strstr(arg, "-loop") == arg) { + continue; + } + if (strstr(arg, "-loop") == arg) { ; /* handled above */ - } else if (!strcmp(arg, "-timeout")) { + continue; + } + if (!strcmp(arg, "-timeout")) { CHECK_ARGC first_conn_timeout = atoi(argv[++i]); - } else if (!strcmp(arg, "-sleepin")) { + continue; + } + if (!strcmp(arg, "-sleepin")) { int n; CHECK_ARGC do_sleepin(argv[++i]); - } else if (!strcmp(arg, "-users")) { + continue; + } + if (!strcmp(arg, "-users")) { CHECK_ARGC users_list = strdup(argv[++i]); - } else if (!strcmp(arg, "-inetd")) { + continue; + } + if (!strcmp(arg, "-inetd")) { inetd = 1; - } else if (!strcmp(arg, "-notightfilexfer")) { + continue; + } + if (!strcmp(arg, "-notightfilexfer")) { tightfilexfer = 0; - } else if (!strcmp(arg, "-tightfilexfer")) { + continue; + } + if (!strcmp(arg, "-tightfilexfer")) { tightfilexfer = 1; - } else if (!strcmp(arg, "-http")) { + continue; + } + if (!strcmp(arg, "-http")) { try_http = 1; - } else if (!strcmp(arg, "-http_ssl")) { + continue; + } + if (!strcmp(arg, "-http_ssl")) { try_http = 1; http_ssl = 1; - } else if (!strcmp(arg, "-avahi") || !strcmp(arg, "-mdns")) { + continue; + } + if (!strcmp(arg, "-avahi") || !strcmp(arg, "-mdns")) { avahi = 1; - } else if (!strcmp(arg, "-connect") || + continue; + } + if (!strcmp(arg, "-connect") || !strcmp(arg, "-connect_or_exit")) { CHECK_ARGC if (!strcmp(arg, "-connect_or_exit")) { @@ -2659,77 +2195,115 @@ int main(int argc, char* argv[]) { } else { client_connect = strdup(argv[i]); } - } else if (!strcmp(arg, "-proxy")) { + continue; + } + if (!strcmp(arg, "-proxy")) { CHECK_ARGC connect_proxy = strdup(argv[++i]); - } else if (!strcmp(arg, "-vncconnect")) { + continue; + } + if (!strcmp(arg, "-vncconnect")) { vnc_connect = 1; - } else if (!strcmp(arg, "-novncconnect")) { + continue; + } + if (!strcmp(arg, "-novncconnect")) { vnc_connect = 0; - } else if (!strcmp(arg, "-allow")) { + continue; + } + if (!strcmp(arg, "-allow")) { CHECK_ARGC allow_list = strdup(argv[++i]); - } else if (!strcmp(arg, "-localhost")) { + continue; + } + if (!strcmp(arg, "-localhost")) { allow_list = strdup("127.0.0.1"); got_localhost = 1; - } else if (!strcmp(arg, "-nolookup")) { + continue; + } + if (!strcmp(arg, "-nolookup")) { host_lookup = 0; - } else if (!strcmp(arg, "-input")) { + continue; + } + if (!strcmp(arg, "-input")) { CHECK_ARGC allowed_input_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-grabkbd")) { + continue; + } + if (!strcmp(arg, "-grabkbd")) { grab_kbd = 1; - } else if (!strcmp(arg, "-grabptr")) { + continue; + } + if (!strcmp(arg, "-grabptr")) { grab_ptr = 1; - } else if (!strcmp(arg, "-grabalways")) { + continue; + } + if (!strcmp(arg, "-grabalways")) { grab_kbd = 1; grab_ptr = 1; grab_always = 1; + continue; + } #ifdef ENABLE_GRABLOCAL - } else if (!strcmp(arg, "-grablocal")) { + if (!strcmp(arg, "-grablocal")) { CHECK_ARGC grab_local = atoi(argv[++i]); + continue; + } #endif - } else if (!strcmp(arg, "-viewpasswd")) { + if (!strcmp(arg, "-viewpasswd")) { vpw_loc = i; CHECK_ARGC viewonly_passwd = strdup(argv[++i]); got_viewpasswd = 1; - } else if (!strcmp(arg, "-passwdfile")) { + continue; + } + if (!strcmp(arg, "-passwdfile")) { CHECK_ARGC passwdfile = strdup(argv[++i]); got_passwdfile = 1; - } else if (!strcmp(arg, "-svc") || !strcmp(arg, "-service")) { + continue; + } + if (!strcmp(arg, "-svc") || !strcmp(arg, "-service")) { use_dpy = strdup("WAIT:cmd=FINDCREATEDISPLAY-Xvfb"); unixpw = 1; users_list = strdup("unixpw="); use_openssl = 1; openssl_pem = strdup("SAVE"); - } else if (!strcmp(arg, "-svc_xdummy")) { + continue; + } + if (!strcmp(arg, "-svc_xdummy")) { use_dpy = strdup("WAIT:cmd=FINDCREATEDISPLAY-Xdummy"); unixpw = 1; users_list = strdup("unixpw="); use_openssl = 1; openssl_pem = strdup("SAVE"); set_env("FD_XDUMMY_NOROOT", "1"); - } else if (!strcmp(arg, "-svc_xvnc")) { + continue; + } + if (!strcmp(arg, "-svc_xvnc")) { use_dpy = strdup("WAIT:cmd=FINDCREATEDISPLAY-Xvnc"); unixpw = 1; users_list = strdup("unixpw="); use_openssl = 1; openssl_pem = strdup("SAVE"); - } else if (!strcmp(arg, "-xdmsvc") || !strcmp(arg, "-xdm_service")) { + continue; + } + if (!strcmp(arg, "-xdmsvc") || !strcmp(arg, "-xdm_service")) { use_dpy = strdup("WAIT:cmd=FINDCREATEDISPLAY-Xvfb.xdmcp"); unixpw = 1; users_list = strdup("unixpw="); use_openssl = 1; openssl_pem = strdup("SAVE"); - } else if (!strcmp(arg, "-sshxdmsvc")) { + continue; + } + if (!strcmp(arg, "-sshxdmsvc")) { use_dpy = strdup("WAIT:cmd=FINDCREATEDISPLAY-Xvfb.xdmcp"); allow_list = strdup("127.0.0.1"); got_localhost = 1; + continue; + } #ifndef NO_SSL_OR_UNIXPW - } else if (!strcmp(arg, "-unixpw_cmd") + if (!strcmp(arg, "-unixpw_cmd") || !strcmp(arg, "-unixpw_cmd_unsafe")) { CHECK_ARGC unixpw_cmd = strdup(argv[++i]); @@ -2739,7 +2313,9 @@ int main(int argc, char* argv[]) { set_env("UNIXPW_DISABLE_SSL", "1"); set_env("UNIXPW_DISABLE_LOCALHOST", "1"); } - } else if (strstr(arg, "-unixpw") == arg) { + continue; + } + if (strstr(arg, "-unixpw") == arg) { unixpw = 1; if (strstr(arg, "-unixpw_nis")) { unixpw_nis = 1; @@ -2761,10 +2337,14 @@ int main(int argc, char* argv[]) { set_env("UNIXPW_DISABLE_SSL", "1"); set_env("UNIXPW_DISABLE_LOCALHOST", "1"); } - } else if (!strcmp(arg, "-nossl")) { + continue; + } + if (!strcmp(arg, "-nossl")) { use_openssl = 0; openssl_pem = NULL; - } else if (!strcmp(arg, "-ssl")) { + continue; + } + if (!strcmp(arg, "-ssl")) { use_openssl = 1; if (i < argc-1) { char *s = argv[i+1]; @@ -2773,25 +2353,35 @@ int main(int argc, char* argv[]) { i++; } } - } else if (!strcmp(arg, "-enc")) { + continue; + } + if (!strcmp(arg, "-enc")) { char *q; use_openssl = 1; CHECK_ARGC enc_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-ssltimeout")) { + continue; + } + if (!strcmp(arg, "-ssltimeout")) { CHECK_ARGC ssl_timeout_secs = atoi(argv[++i]); - } else if (!strcmp(arg, "-sslnofail")) { + continue; + } + if (!strcmp(arg, "-sslnofail")) { ssl_no_fail = 1; - } else if (!strcmp(arg, "-ssldir")) { + continue; + } + if (!strcmp(arg, "-ssldir")) { CHECK_ARGC ssl_certs_dir = strdup(argv[++i]); - - } else if (!strcmp(arg, "-sslverify")) { + continue; + } + if (!strcmp(arg, "-sslverify")) { CHECK_ARGC ssl_verify = strdup(argv[++i]); - - } else if (!strcmp(arg, "-sslGenCA")) { + continue; + } + if (!strcmp(arg, "-sslGenCA")) { char *cdir = NULL; if (i < argc-1) { char *s = argv[i+1]; @@ -2802,7 +2392,9 @@ int main(int argc, char* argv[]) { } sslGenCA(cdir); exit(0); - } else if (!strcmp(arg, "-sslGenCert")) { + continue; + } + if (!strcmp(arg, "-sslGenCert")) { char *ty, *nm = NULL; if (i >= argc-1) { fprintf(stderr, "Must be:\n"); @@ -2822,26 +2414,34 @@ int main(int argc, char* argv[]) { } sslGenCert(ty, nm); exit(0); - } else if (!strcmp(arg, "-sslEncKey")) { + continue; + } + if (!strcmp(arg, "-sslEncKey")) { if (i < argc-1) { char *s = argv[i+1]; sslEncKey(s, 0); } exit(0); - } else if (!strcmp(arg, "-sslCertInfo")) { + continue; + } + if (!strcmp(arg, "-sslCertInfo")) { if (i < argc-1) { char *s = argv[i+1]; sslEncKey(s, 1); } exit(0); - } else if (!strcmp(arg, "-sslDelCert")) { + continue; + } + if (!strcmp(arg, "-sslDelCert")) { if (i < argc-1) { char *s = argv[i+1]; sslEncKey(s, 2); } exit(0); - } else if (!strcmp(arg, "-stunnel")) { + continue; + } + if (!strcmp(arg, "-stunnel")) { use_stunnel = 1; if (i < argc-1) { char *s = argv[i+1]; @@ -2850,7 +2450,9 @@ int main(int argc, char* argv[]) { i++; } } - } else if (!strcmp(arg, "-stunnel3")) { + continue; + } + if (!strcmp(arg, "-stunnel3")) { use_stunnel = 3; if (i < argc-1) { char *s = argv[i+1]; @@ -2859,7 +2461,9 @@ int main(int argc, char* argv[]) { i++; } } - } else if (!strcmp(arg, "-https")) { + continue; + } + if (!strcmp(arg, "-https")) { https_port_num = 0; try_http = 1; if (i < argc-1) { @@ -2869,7 +2473,9 @@ int main(int argc, char* argv[]) { i++; } } - } else if (!strcmp(arg, "-httpsredir")) { + continue; + } + if (!strcmp(arg, "-httpsredir")) { https_port_redir = -1; if (i < argc-1) { char *s = argv[i+1]; @@ -2878,15 +2484,23 @@ int main(int argc, char* argv[]) { i++; } } + continue; + } #endif - } else if (!strcmp(arg, "-nopw")) { + if (!strcmp(arg, "-nopw")) { nopw = 1; - } else if (!strcmp(arg, "-ssh")) { + continue; + } + if (!strcmp(arg, "-ssh")) { CHECK_ARGC ssh_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-usepw")) { + continue; + } + if (!strcmp(arg, "-usepw")) { usepw = 1; - } else if (!strcmp(arg, "-storepasswd")) { + continue; + } + if (!strcmp(arg, "-storepasswd")) { if (argc == i+1) { store_homedir_passwd(NULL); exit(0); @@ -2904,22 +2518,36 @@ int main(int argc, char* argv[]) { argv[i+2]); exit(0); } - } else if (!strcmp(arg, "-accept")) { + continue; + } + if (!strcmp(arg, "-accept")) { CHECK_ARGC accept_cmd = strdup(argv[++i]); - } else if (!strcmp(arg, "-afteraccept")) { + continue; + } + if (!strcmp(arg, "-afteraccept")) { CHECK_ARGC afteraccept_cmd = strdup(argv[++i]); - } else if (!strcmp(arg, "-gone")) { + continue; + } + if (!strcmp(arg, "-gone")) { CHECK_ARGC gone_cmd = strdup(argv[++i]); - } else if (!strcmp(arg, "-noshm")) { + continue; + } + if (!strcmp(arg, "-noshm")) { using_shm = 0; - } else if (!strcmp(arg, "-flipbyteorder")) { + continue; + } + if (!strcmp(arg, "-flipbyteorder")) { flip_byte_order = 1; - } else if (!strcmp(arg, "-onetile")) { + continue; + } + if (!strcmp(arg, "-onetile")) { single_copytile = 1; - } else if (!strcmp(arg, "-solid")) { + continue; + } + if (!strcmp(arg, "-solid")) { use_solid_bg = 1; if (i < argc-1) { char *s = argv[i+1]; @@ -2931,16 +2559,26 @@ int main(int argc, char* argv[]) { if (! solid_str) { solid_str = strdup(solid_default); } - } else if (!strcmp(arg, "-blackout")) { + continue; + } + if (!strcmp(arg, "-blackout")) { CHECK_ARGC blackout_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-xinerama")) { + continue; + } + if (!strcmp(arg, "-xinerama")) { xinerama = 1; - } else if (!strcmp(arg, "-noxinerama")) { + continue; + } + if (!strcmp(arg, "-noxinerama")) { xinerama = 0; - } else if (!strcmp(arg, "-xtrap")) { + continue; + } + if (!strcmp(arg, "-xtrap")) { xtrap_input = 1; - } else if (!strcmp(arg, "-xrandr")) { + continue; + } + if (!strcmp(arg, "-xrandr")) { xrandr = 1; if (i < argc-1) { char *s = argv[i+1]; @@ -2949,106 +2587,182 @@ int main(int argc, char* argv[]) { i++; } } - } else if (!strcmp(arg, "-noxrandr")) { + continue; + } + if (!strcmp(arg, "-noxrandr")) { xrandr = 0; xrandr_maybe = 0; - } else if (!strcmp(arg, "-rotate")) { + continue; + } + if (!strcmp(arg, "-rotate")) { CHECK_ARGC rotating_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-padgeom") + continue; + } + if (!strcmp(arg, "-padgeom") || !strcmp(arg, "-padgeometry")) { CHECK_ARGC pad_geometry = strdup(argv[++i]); - } else if (!strcmp(arg, "-o") || !strcmp(arg, "-logfile")) { + continue; + } + if (!strcmp(arg, "-o") || !strcmp(arg, "-logfile")) { CHECK_ARGC logfile_append = 0; logfile = strdup(argv[++i]); - } else if (!strcmp(arg, "-oa") || !strcmp(arg, "-logappend")) { + continue; + } + if (!strcmp(arg, "-oa") || !strcmp(arg, "-logappend")) { CHECK_ARGC logfile_append = 1; logfile = strdup(argv[++i]); - } else if (!strcmp(arg, "-flag")) { + continue; + } + if (!strcmp(arg, "-flag")) { CHECK_ARGC flagfile = strdup(argv[++i]); - } else if (!strcmp(arg, "-rc")) { + continue; + } + if (!strcmp(arg, "-rc")) { i++; /* done above */ - } else if (!strcmp(arg, "-norc")) { + continue; + } + if (!strcmp(arg, "-norc")) { ; /* done above */ - } else if (!strcmp(arg, "-env")) { + continue; + } + if (!strcmp(arg, "-env")) { i++; /* done above */ - } else if (!strcmp(arg, "-prog")) { + continue; + } + if (!strcmp(arg, "-prog")) { CHECK_ARGC if (program_name) { free(program_name); } program_name = strdup(argv[++i]); - } else if (!strcmp(arg, "-h") || !strcmp(arg, "-help")) { + continue; + } + if (!strcmp(arg, "-h") || !strcmp(arg, "-help")) { print_help(0); - } else if (!strcmp(arg, "-?") || !strcmp(arg, "-opts")) { + continue; + } + if (!strcmp(arg, "-?") || !strcmp(arg, "-opts")) { print_help(1); - } else if (!strcmp(arg, "-V") || !strcmp(arg, "-version")) { + continue; + } + if (!strcmp(arg, "-V") || !strcmp(arg, "-version")) { fprintf(stdout, "x11vnc: %s\n", lastmod); exit(0); - } else if (!strcmp(arg, "-license") || + continue; + } + if (!strcmp(arg, "-license") || !strcmp(arg, "-copying") || !strcmp(arg, "-warranty")) { print_license(); - } else if (!strcmp(arg, "-dbg")) { + continue; + } + if (!strcmp(arg, "-dbg")) { crash_debug = 1; - } else if (!strcmp(arg, "-nodbg")) { + continue; + } + if (!strcmp(arg, "-nodbg")) { crash_debug = 0; - } else if (!strcmp(arg, "-q") || !strcmp(arg, "-quiet")) { + continue; + } + if (!strcmp(arg, "-q") || !strcmp(arg, "-quiet")) { quiet = 1; - } else if (!strcmp(arg, "-v") || !strcmp(arg, "-verbose")) { + continue; + } + if (!strcmp(arg, "-v") || !strcmp(arg, "-verbose")) { verbose = 1; - } else if (!strcmp(arg, "-bg") || !strcmp(arg, "-background")) { + continue; + } + if (!strcmp(arg, "-bg") || !strcmp(arg, "-background")) { #if LIBVNCSERVER_HAVE_SETSID bg = 1; opts_bg = bg; #else fprintf(stderr, "warning: -bg mode not supported.\n"); #endif - } else if (!strcmp(arg, "-modtweak")) { + continue; + } + if (!strcmp(arg, "-modtweak")) { use_modifier_tweak = 1; - } else if (!strcmp(arg, "-nomodtweak")) { + continue; + } + if (!strcmp(arg, "-nomodtweak")) { use_modifier_tweak = 0; got_nomodtweak = 1; - } else if (!strcmp(arg, "-isolevel3")) { + continue; + } + if (!strcmp(arg, "-isolevel3")) { use_iso_level3 = 1; - } else if (!strcmp(arg, "-xkb")) { + continue; + } + if (!strcmp(arg, "-xkb")) { use_modifier_tweak = 1; use_xkb_modtweak = 1; - } else if (!strcmp(arg, "-noxkb")) { + continue; + } + if (!strcmp(arg, "-noxkb")) { use_xkb_modtweak = 0; got_noxkb = 1; - } else if (!strcmp(arg, "-capslock")) { + continue; + } + if (!strcmp(arg, "-capslock")) { watch_capslock = 1; - } else if (!strcmp(arg, "-skip_lockkeys")) { + continue; + } + if (!strcmp(arg, "-skip_lockkeys")) { skip_lockkeys = 1; - } else if (!strcmp(arg, "-xkbcompat")) { + continue; + } + if (!strcmp(arg, "-xkbcompat")) { xkbcompat = 1; - } else if (!strcmp(arg, "-skip_keycodes")) { + continue; + } + if (!strcmp(arg, "-skip_keycodes")) { CHECK_ARGC skip_keycodes = strdup(argv[++i]); - } else if (!strcmp(arg, "-sloppy_keys")) { + continue; + } + if (!strcmp(arg, "-sloppy_keys")) { sloppy_keys++; - } else if (!strcmp(arg, "-skip_dups")) { + continue; + } + if (!strcmp(arg, "-skip_dups")) { skip_duplicate_key_events = 1; - } else if (!strcmp(arg, "-noskip_dups")) { + continue; + } + if (!strcmp(arg, "-noskip_dups")) { skip_duplicate_key_events = 0; - } else if (!strcmp(arg, "-add_keysyms")) { + continue; + } + if (!strcmp(arg, "-add_keysyms")) { add_keysyms++; - } else if (!strcmp(arg, "-noadd_keysyms")) { + continue; + } + if (!strcmp(arg, "-noadd_keysyms")) { add_keysyms = 0; - } else if (!strcmp(arg, "-clear_mods")) { + continue; + } + if (!strcmp(arg, "-clear_mods")) { clear_mods = 1; - } else if (!strcmp(arg, "-clear_keys")) { + continue; + } + if (!strcmp(arg, "-clear_keys")) { clear_mods = 2; - } else if (!strcmp(arg, "-clear_all")) { + continue; + } + if (!strcmp(arg, "-clear_all")) { clear_mods = 3; - } else if (!strcmp(arg, "-remap")) { + continue; + } + if (!strcmp(arg, "-remap")) { CHECK_ARGC remap_file = strdup(argv[++i]); - } else if (!strcmp(arg, "-norepeat")) { + continue; + } + if (!strcmp(arg, "-norepeat")) { no_autorepeat = 1; if (i < argc-1) { char *s = argv[i+1]; @@ -3059,29 +2773,49 @@ int main(int argc, char* argv[]) { no_repeat_countdown = atoi(argv[++i]); } } - } else if (!strcmp(arg, "-repeat")) { + continue; + } + if (!strcmp(arg, "-repeat")) { no_autorepeat = 0; - } else if (!strcmp(arg, "-nofb")) { + continue; + } + if (!strcmp(arg, "-nofb")) { nofb = 1; - } else if (!strcmp(arg, "-nobell")) { + continue; + } + if (!strcmp(arg, "-nobell")) { watch_bell = 0; sound_bell = 0; - } else if (!strcmp(arg, "-nosel")) { + continue; + } + if (!strcmp(arg, "-nosel")) { watch_selection = 0; watch_primary = 0; watch_clipboard = 0; - } else if (!strcmp(arg, "-noprimary")) { + continue; + } + if (!strcmp(arg, "-noprimary")) { watch_primary = 0; - } else if (!strcmp(arg, "-nosetprimary")) { + continue; + } + if (!strcmp(arg, "-nosetprimary")) { set_primary = 0; - } else if (!strcmp(arg, "-noclipboard")) { + continue; + } + if (!strcmp(arg, "-noclipboard")) { watch_clipboard = 0; - } else if (!strcmp(arg, "-nosetclipboard")) { + continue; + } + if (!strcmp(arg, "-nosetclipboard")) { set_clipboard = 0; - } else if (!strcmp(arg, "-seldir")) { + continue; + } + if (!strcmp(arg, "-seldir")) { CHECK_ARGC sel_direction = strdup(argv[++i]); - } else if (!strcmp(arg, "-cursor")) { + continue; + } + if (!strcmp(arg, "-cursor")) { show_cursor = 1; if (i < argc-1) { char *s = argv[i+1]; @@ -3091,51 +2825,87 @@ int main(int argc, char* argv[]) { if (!strcmp(s, "none")) { show_cursor = 0; } - } + } } - } else if (!strcmp(arg, "-nocursor")) { + continue; + } + if (!strcmp(arg, "-nocursor")) { multiple_cursors_mode = strdup("none"); show_cursor = 0; - } else if (!strcmp(arg, "-cursor_drag")) { + continue; + } + if (!strcmp(arg, "-cursor_drag")) { cursor_drag_changes = 1; - } else if (!strcmp(arg, "-nocursor_drag")) { + continue; + } + if (!strcmp(arg, "-nocursor_drag")) { cursor_drag_changes = 0; - } else if (!strcmp(arg, "-arrow")) { + continue; + } + if (!strcmp(arg, "-arrow")) { CHECK_ARGC alt_arrow = atoi(argv[++i]); - } else if (!strcmp(arg, "-xfixes")) { + continue; + } + if (!strcmp(arg, "-xfixes")) { use_xfixes = 1; - } else if (!strcmp(arg, "-noxfixes")) { + continue; + } + if (!strcmp(arg, "-noxfixes")) { use_xfixes = 0; - } else if (!strcmp(arg, "-alphacut")) { + continue; + } + if (!strcmp(arg, "-alphacut")) { CHECK_ARGC alpha_threshold = atoi(argv[++i]); - } else if (!strcmp(arg, "-alphafrac")) { + continue; + } + if (!strcmp(arg, "-alphafrac")) { CHECK_ARGC alpha_frac = atof(argv[++i]); - } else if (!strcmp(arg, "-alpharemove")) { + continue; + } + if (!strcmp(arg, "-alpharemove")) { alpha_remove = 1; - } else if (!strcmp(arg, "-noalphablend")) { + continue; + } + if (!strcmp(arg, "-noalphablend")) { alpha_blend = 0; - } else if (!strcmp(arg, "-nocursorshape")) { + continue; + } + if (!strcmp(arg, "-nocursorshape")) { cursor_shape_updates = 0; - } else if (!strcmp(arg, "-cursorpos")) { + continue; + } + if (!strcmp(arg, "-cursorpos")) { cursor_pos_updates = 1; got_cursorpos = 1; - } else if (!strcmp(arg, "-nocursorpos")) { + continue; + } + if (!strcmp(arg, "-nocursorpos")) { cursor_pos_updates = 0; - } else if (!strcmp(arg, "-xwarppointer")) { + continue; + } + if (!strcmp(arg, "-xwarppointer")) { use_xwarppointer = 1; - } else if (!strcmp(arg, "-noxwarppointer")) { + continue; + } + if (!strcmp(arg, "-noxwarppointer")) { use_xwarppointer = 0; got_noxwarppointer = 1; - } else if (!strcmp(arg, "-buttonmap")) { + continue; + } + if (!strcmp(arg, "-buttonmap")) { CHECK_ARGC pointer_remap = strdup(argv[++i]); - } else if (!strcmp(arg, "-nodragging")) { + continue; + } + if (!strcmp(arg, "-nodragging")) { show_dragging = 0; + continue; + } #ifndef NO_NCACHE - } else if (!strcmp(arg, "-ncache") || !strcmp(arg, "-nc")) { + if (!strcmp(arg, "-ncache") || !strcmp(arg, "-nc")) { if (i < argc-1) { char *s = argv[i+1]; if (s[0] != '-') { @@ -3150,27 +2920,47 @@ int main(int argc, char* argv[]) { if (ncache % 2 != 0) { ncache++; } - } else if (!strcmp(arg, "-noncache") || !strcmp(arg, "-nonc")) { + continue; + } + if (!strcmp(arg, "-noncache") || !strcmp(arg, "-nonc")) { ncache = 0; - } else if (!strcmp(arg, "-ncache_cr") || !strcmp(arg, "-nc_cr")) { + continue; + } + if (!strcmp(arg, "-ncache_cr") || !strcmp(arg, "-nc_cr")) { ncache_copyrect = 1; - } else if (!strcmp(arg, "-ncache_no_moveraise") || !strcmp(arg, "-nc_no_moveraise")) { + continue; + } + if (!strcmp(arg, "-ncache_no_moveraise") || !strcmp(arg, "-nc_no_moveraise")) { ncache_wf_raises = 1; - } else if (!strcmp(arg, "-ncache_no_dtchange") || !strcmp(arg, "-nc_no_dtchange")) { + continue; + } + if (!strcmp(arg, "-ncache_no_dtchange") || !strcmp(arg, "-nc_no_dtchange")) { ncache_dt_change = 0; - } else if (!strcmp(arg, "-ncache_no_rootpixmap") || !strcmp(arg, "-nc_no_rootpixmap")) { + continue; + } + if (!strcmp(arg, "-ncache_no_rootpixmap") || !strcmp(arg, "-nc_no_rootpixmap")) { ncache_xrootpmap = 0; - } else if (!strcmp(arg, "-ncache_keep_anims") || !strcmp(arg, "-nc_keep_anims")) { + continue; + } + if (!strcmp(arg, "-ncache_keep_anims") || !strcmp(arg, "-nc_keep_anims")) { ncache_keep_anims = 1; - } else if (!strcmp(arg, "-ncache_old_wm") || !strcmp(arg, "-nc_old_wm")) { + continue; + } + if (!strcmp(arg, "-ncache_old_wm") || !strcmp(arg, "-nc_old_wm")) { ncache_old_wm = 1; - } else if (!strcmp(arg, "-ncache_pad") || !strcmp(arg, "-nc_pad")) { + continue; + } + if (!strcmp(arg, "-ncache_pad") || !strcmp(arg, "-nc_pad")) { CHECK_ARGC ncache_pad = atoi(argv[++i]); - } else if (!strcmp(arg, "-debug_ncache")) { + continue; + } + if (!strcmp(arg, "-debug_ncache")) { ncdb++; + continue; + } #endif - } else if (!strcmp(arg, "-wireframe") + if (!strcmp(arg, "-wireframe") || !strcmp(arg, "-wf")) { wireframe = 1; if (i < argc-1) { @@ -3179,65 +2969,101 @@ int main(int argc, char* argv[]) { wireframe_str = strdup(argv[++i]); } } - } else if (!strcmp(arg, "-nowireframe") + continue; + } + if (!strcmp(arg, "-nowireframe") || !strcmp(arg, "-nowf")) { wireframe = 0; - } else if (!strcmp(arg, "-nowireframelocal") + continue; + } + if (!strcmp(arg, "-nowireframelocal") || !strcmp(arg, "-nowfl")) { wireframe_local = 0; - } else if (!strcmp(arg, "-wirecopyrect") + continue; + } + if (!strcmp(arg, "-wirecopyrect") || !strcmp(arg, "-wcr")) { CHECK_ARGC set_wirecopyrect_mode(argv[++i]); got_wirecopyrect = 1; - } else if (!strcmp(arg, "-nowirecopyrect") + continue; + } + if (!strcmp(arg, "-nowirecopyrect") || !strcmp(arg, "-nowcr")) { set_wirecopyrect_mode("never"); - } else if (!strcmp(arg, "-debug_wireframe") + continue; + } + if (!strcmp(arg, "-debug_wireframe") || !strcmp(arg, "-dwf")) { debug_wireframe++; - } else if (!strcmp(arg, "-scrollcopyrect") + continue; + } + if (!strcmp(arg, "-scrollcopyrect") || !strcmp(arg, "-scr")) { CHECK_ARGC set_scrollcopyrect_mode(argv[++i]); got_scrollcopyrect = 1; - } else if (!strcmp(arg, "-noscrollcopyrect") + continue; + } + if (!strcmp(arg, "-noscrollcopyrect") || !strcmp(arg, "-noscr")) { set_scrollcopyrect_mode("never"); - } else if (!strcmp(arg, "-scr_area")) { + continue; + } + if (!strcmp(arg, "-scr_area")) { int tn; CHECK_ARGC tn = atoi(argv[++i]); if (tn >= 0) { scrollcopyrect_min_area = tn; } - } else if (!strcmp(arg, "-scr_skip")) { + continue; + } + if (!strcmp(arg, "-scr_skip")) { CHECK_ARGC scroll_skip_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-scr_inc")) { + continue; + } + if (!strcmp(arg, "-scr_inc")) { CHECK_ARGC scroll_good_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-scr_keys")) { + continue; + } + if (!strcmp(arg, "-scr_keys")) { CHECK_ARGC scroll_key_list_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-scr_term")) { + continue; + } + if (!strcmp(arg, "-scr_term")) { CHECK_ARGC scroll_term_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-scr_keyrepeat")) { + continue; + } + if (!strcmp(arg, "-scr_keyrepeat")) { CHECK_ARGC max_keyrepeat_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-scr_parms")) { + continue; + } + if (!strcmp(arg, "-scr_parms")) { CHECK_ARGC scroll_copyrect_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-fixscreen")) { + continue; + } + if (!strcmp(arg, "-fixscreen")) { CHECK_ARGC screen_fixup_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-debug_scroll") + continue; + } + if (!strcmp(arg, "-debug_scroll") || !strcmp(arg, "-ds")) { debug_scroll++; - } else if (!strcmp(arg, "-noxrecord")) { + continue; + } + if (!strcmp(arg, "-noxrecord")) { noxrecord = 1; - } else if (!strcmp(arg, "-pointer_mode") + continue; + } + if (!strcmp(arg, "-pointer_mode") || !strcmp(arg, "-pm")) { char *p, *s; CHECK_ARGC @@ -3254,95 +3080,168 @@ int main(int argc, char* argv[]) { pointer_mode = atoi(s); got_pointer_mode = pointer_mode; } - } else if (!strcmp(arg, "-input_skip")) { + continue; + } + if (!strcmp(arg, "-input_skip")) { CHECK_ARGC ui_skip = atoi(argv[++i]); if (! ui_skip) ui_skip = 1; - } else if (!strcmp(arg, "-allinput")) { + continue; + } + if (!strcmp(arg, "-allinput")) { all_input = 1; - } else if (!strcmp(arg, "-noallinput")) { + continue; + } + if (!strcmp(arg, "-noallinput")) { all_input = 0; - } else if (!strcmp(arg, "-speeds")) { + continue; + } + if (!strcmp(arg, "-speeds")) { CHECK_ARGC speeds_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-wmdt")) { + continue; + } + if (!strcmp(arg, "-wmdt")) { CHECK_ARGC wmdt_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-debug_pointer") + continue; + } + if (!strcmp(arg, "-debug_pointer") || !strcmp(arg, "-dp")) { debug_pointer++; - } else if (!strcmp(arg, "-debug_keyboard") + continue; + } + if (!strcmp(arg, "-debug_keyboard") || !strcmp(arg, "-dk")) { debug_keyboard++; - } else if (!strcmp(arg, "-debug_xdamage")) { + continue; + } + if (!strcmp(arg, "-debug_xdamage")) { debug_xdamage++; - } else if (!strcmp(arg, "-defer")) { + continue; + } + if (!strcmp(arg, "-defer")) { CHECK_ARGC defer_update = atoi(argv[++i]); got_defer = 1; - } else if (!strcmp(arg, "-wait")) { + continue; + } + if (!strcmp(arg, "-wait")) { CHECK_ARGC waitms = atoi(argv[++i]); got_waitms = 1; - } else if (!strcmp(arg, "-wait_ui")) { + continue; + } + if (!strcmp(arg, "-wait_ui")) { CHECK_ARGC wait_ui = atof(argv[++i]); - } else if (!strcmp(arg, "-nowait_bog")) { + continue; + } + if (!strcmp(arg, "-nowait_bog")) { wait_bog = 0; - } else if (!strcmp(arg, "-slow_fb")) { + continue; + } + if (!strcmp(arg, "-slow_fb")) { CHECK_ARGC slow_fb = atof(argv[++i]); - } else if (!strcmp(arg, "-xrefresh")) { + continue; + } + if (!strcmp(arg, "-xrefresh")) { CHECK_ARGC xrefresh = atof(argv[++i]); - } else if (!strcmp(arg, "-readtimeout")) { + continue; + } + if (!strcmp(arg, "-readtimeout")) { CHECK_ARGC rfbMaxClientWait = atoi(argv[++i]) * 1000; - } else if (!strcmp(arg, "-ping")) { + continue; + } + if (!strcmp(arg, "-ping")) { CHECK_ARGC ping_interval = atoi(argv[++i]); - } else if (!strcmp(arg, "-nap")) { + continue; + } + if (!strcmp(arg, "-nap")) { take_naps = 1; - } else if (!strcmp(arg, "-nonap")) { + continue; + } + if (!strcmp(arg, "-nonap")) { take_naps = 0; - } else if (!strcmp(arg, "-sb")) { + continue; + } + if (!strcmp(arg, "-sb")) { CHECK_ARGC screen_blank = atoi(argv[++i]); - } else if (!strcmp(arg, "-nofbpm")) { + continue; + } + if (!strcmp(arg, "-nofbpm")) { watch_fbpm = 1; - } else if (!strcmp(arg, "-fbpm")) { + continue; + } + if (!strcmp(arg, "-fbpm")) { watch_fbpm = 0; - } else if (!strcmp(arg, "-nodpms")) { + continue; + } + if (!strcmp(arg, "-nodpms")) { watch_dpms = 1; - } else if (!strcmp(arg, "-dpms")) { + continue; + } + if (!strcmp(arg, "-dpms")) { watch_dpms = 0; - } else if (!strcmp(arg, "-forcedpms")) { + continue; + } + if (!strcmp(arg, "-forcedpms")) { force_dpms = 1; - } else if (!strcmp(arg, "-clientdpms")) { + continue; + } + if (!strcmp(arg, "-clientdpms")) { client_dpms = 1; - } else if (!strcmp(arg, "-noserverdpms")) { + continue; + } + if (!strcmp(arg, "-noserverdpms")) { no_ultra_dpms = 1; - } else if (!strcmp(arg, "-noultraext")) { + continue; + } + if (!strcmp(arg, "-noultraext")) { no_ultra_ext = 1; - } else if (!strcmp(arg, "-xdamage")) { + continue; + } + if (!strcmp(arg, "-chatwindow")) { + chat_window = 1; + if (argc_vnc + 1 < argc_vnc_max) { + rfbLog("setting '-rfbversion 3.6' for -chatwindow.\n"); + argv_vnc[argc_vnc++] = strdup("-rfbversion"); + argv_vnc[argc_vnc++] = strdup("3.6"); + } + continue; + } + if (!strcmp(arg, "-xdamage")) { use_xdamage++; - } else if (!strcmp(arg, "-noxdamage")) { + continue; + } + if (!strcmp(arg, "-noxdamage")) { use_xdamage = 0; - } else if (!strcmp(arg, "-xd_area")) { + continue; + } + if (!strcmp(arg, "-xd_area")) { int tn; CHECK_ARGC tn = atoi(argv[++i]); if (tn >= 0) { xdamage_max_area = tn; } - } else if (!strcmp(arg, "-xd_mem")) { + continue; + } + if (!strcmp(arg, "-xd_mem")) { double f; CHECK_ARGC f = atof(argv[++i]); if (f >= 0.0) { xdamage_memory = f; } - } else if (!strcmp(arg, "-sigpipe") || !strcmp(arg, "-sig")) { + continue; + } + if (!strcmp(arg, "-sigpipe") || !strcmp(arg, "-sig")) { CHECK_ARGC if (known_sigpipe_mode(argv[++i])) { sigpipe = strdup(argv[i]); @@ -3351,8 +3250,10 @@ int main(int argc, char* argv[]) { " be \"ignore\" or \"exit\"\n", argv[i]); exit(1); } + continue; + } #if LIBVNCSERVER_HAVE_LIBPTHREAD - } else if (!strcmp(arg, "-threads")) { + if (!strcmp(arg, "-threads")) { #if defined(X11VNC_THREADED) use_threads = 1; #else @@ -3369,69 +3270,119 @@ int main(int argc, char* argv[]) { usleep(500*1000); } #endif - } else if (!strcmp(arg, "-nothreads")) { + continue; + } + if (!strcmp(arg, "-nothreads")) { use_threads = 0; + continue; + } #endif - } else if (!strcmp(arg, "-fs")) { + if (!strcmp(arg, "-fs")) { CHECK_ARGC fs_frac = atof(argv[++i]); - } else if (!strcmp(arg, "-gaps")) { + continue; + } + if (!strcmp(arg, "-gaps")) { CHECK_ARGC gaps_fill = atoi(argv[++i]); - } else if (!strcmp(arg, "-grow")) { + continue; + } + if (!strcmp(arg, "-grow")) { CHECK_ARGC grow_fill = atoi(argv[++i]); - } else if (!strcmp(arg, "-fuzz")) { + continue; + } + if (!strcmp(arg, "-fuzz")) { CHECK_ARGC tile_fuzz = atoi(argv[++i]); - } else if (!strcmp(arg, "-debug_tiles") + continue; + } + if (!strcmp(arg, "-debug_tiles") || !strcmp(arg, "-dbt")) { debug_tiles++; - } else if (!strcmp(arg, "-debug_grabs")) { + continue; + } + if (!strcmp(arg, "-debug_grabs")) { debug_grabs++; - } else if (!strcmp(arg, "-debug_sel")) { + continue; + } + if (!strcmp(arg, "-debug_sel")) { debug_sel++; - } else if (!strcmp(arg, "-grab_buster")) { + continue; + } + if (!strcmp(arg, "-grab_buster")) { grab_buster++; - } else if (!strcmp(arg, "-nograb_buster")) { + continue; + } + if (!strcmp(arg, "-nograb_buster")) { grab_buster = 0; - } else if (!strcmp(arg, "-snapfb")) { + continue; + } + if (!strcmp(arg, "-snapfb")) { use_snapfb = 1; - } else if (!strcmp(arg, "-rawfb")) { + continue; + } + if (!strcmp(arg, "-rawfb")) { CHECK_ARGC raw_fb_str = strdup(argv[++i]); if (strstr(raw_fb_str, "vnc:") == raw_fb_str) { shared = 1; } - } else if (!strcmp(arg, "-freqtab")) { + continue; + } + if (!strcmp(arg, "-freqtab")) { CHECK_ARGC freqtab = strdup(argv[++i]); - } else if (!strcmp(arg, "-pipeinput")) { + continue; + } + if (!strcmp(arg, "-pipeinput")) { CHECK_ARGC pipeinput_str = strdup(argv[++i]); - } else if (!strcmp(arg, "-macnodim")) { + continue; + } + if (!strcmp(arg, "-macnodim")) { macosx_nodimming = 1; - } else if (!strcmp(arg, "-macnosleep")) { + continue; + } + if (!strcmp(arg, "-macnosleep")) { macosx_nosleep = 1; - } else if (!strcmp(arg, "-macnosaver")) { + continue; + } + if (!strcmp(arg, "-macnosaver")) { macosx_noscreensaver = 1; - } else if (!strcmp(arg, "-macnowait")) { + continue; + } + if (!strcmp(arg, "-macnowait")) { macosx_wait_for_switch = 0; - } else if (!strcmp(arg, "-macwheel")) { + continue; + } + if (!strcmp(arg, "-macwheel")) { CHECK_ARGC macosx_mouse_wheel_speed = atoi(argv[++i]); - } else if (!strcmp(arg, "-macnoswap")) { + continue; + } + if (!strcmp(arg, "-macnoswap")) { macosx_swap23 = 0; - } else if (!strcmp(arg, "-macnoresize")) { + continue; + } + if (!strcmp(arg, "-macnoresize")) { macosx_resize = 0; - } else if (!strcmp(arg, "-maciconanim")) { + continue; + } + if (!strcmp(arg, "-maciconanim")) { CHECK_ARGC macosx_icon_anim_time = atoi(argv[++i]); - } else if (!strcmp(arg, "-macmenu")) { + continue; + } + if (!strcmp(arg, "-macmenu")) { macosx_ncache_macmenu = 1; - } else if (!strcmp(arg, "-macuskbd")) { + continue; + } + if (!strcmp(arg, "-macuskbd")) { macosx_us_kbd = 1; - } else if (!strcmp(arg, "-gui")) { + continue; + } + if (!strcmp(arg, "-gui")) { launch_gui = 1; if (i < argc-1) { char *s = argv[i+1]; @@ -3441,9 +3392,11 @@ int main(int argc, char* argv[]) { got_gui_pw = 1; } i++; - } + } } - } else if (!strcmp(arg, "-remote") || !strcmp(arg, "-R") + continue; + } + if (!strcmp(arg, "-remote") || !strcmp(arg, "-R") || !strcmp(arg, "-r") || !strcmp(arg, "-remote-control")) { char *str; CHECK_ARGC @@ -3475,41 +3428,69 @@ int main(int argc, char* argv[]) { } quiet = 1; xkbcompat = 0; - } else if (!strcmp(arg, "-query") || !strcmp(arg, "-Q")) { + continue; + } + if (!strcmp(arg, "-query") || !strcmp(arg, "-Q")) { CHECK_ARGC query_cmd = strdup(argv[++i]); quiet = 1; xkbcompat = 0; - } else if (!strcmp(arg, "-QD")) { + continue; + } + if (!strcmp(arg, "-QD")) { CHECK_ARGC query_cmd = strdup(argv[++i]); query_default = 1; - } else if (!strcmp(arg, "-sync")) { + continue; + } + if (!strcmp(arg, "-sync")) { remote_sync = 1; - } else if (!strcmp(arg, "-nosync")) { + continue; + } + if (!strcmp(arg, "-nosync")) { remote_sync = 0; - } else if (!strcmp(arg, "-noremote")) { + continue; + } + if (!strcmp(arg, "-noremote")) { accept_remote_cmds = 0; - } else if (!strcmp(arg, "-yesremote")) { + continue; + } + if (!strcmp(arg, "-yesremote")) { accept_remote_cmds = 1; - } else if (!strcmp(arg, "-unsafe")) { + continue; + } + if (!strcmp(arg, "-unsafe")) { safe_remote_only = 0; - } else if (!strcmp(arg, "-privremote")) { + continue; + } + if (!strcmp(arg, "-privremote")) { priv_remote = 1; - } else if (!strcmp(arg, "-safer")) { + continue; + } + if (!strcmp(arg, "-safer")) { more_safe = 1; - } else if (!strcmp(arg, "-nocmds")) { + continue; + } + if (!strcmp(arg, "-nocmds")) { no_external_cmds = 1; - } else if (!strcmp(arg, "-allowedcmds")) { + continue; + } + if (!strcmp(arg, "-allowedcmds")) { CHECK_ARGC allowed_external_cmds = strdup(argv[++i]); - } else if (!strcmp(arg, "-deny_all")) { + continue; + } + if (!strcmp(arg, "-deny_all")) { deny_all = 1; - } else if (!strcmp(arg, "-httpdir")) { + continue; + } + if (!strcmp(arg, "-httpdir")) { CHECK_ARGC http_dir = strdup(argv[++i]); got_httpdir = 1; - } else { + continue; + } + if (1) { if (!strcmp(arg, "-desktop") && i < argc-1) { dt = 1; rfb_desktop_name = strdup(argv[i+1]); @@ -3553,6 +3534,7 @@ int main(int argc, char* argv[]) { rfbLog("too many arguments.\n"); exit(1); } + continue; } } @@ -3812,7 +3794,7 @@ int main(int argc, char* argv[]) { strzero(p); } } - } + } #ifdef HARDWIRE_PASSWD if (!got_rfbauth && !got_passwd) { argv_vnc[argc_vnc++] = strdup("-passwd"); @@ -4637,6 +4619,12 @@ if (0) fprintf(stderr, "XA: %s\n", getenv("XAUTHORITY")); using_shm = 0; #endif } + } else { + int op, ev, er; + if (XQueryExtension(dpy, "MIT-SHM", &op, &ev, &er)) { + xshm_opcode = op; + if (0) fprintf(stderr, "xshm_opcode: %d %d %d\n", op, ev, er); + } } #if LIBVNCSERVER_HAVE_XKEYBOARD @@ -4828,7 +4816,6 @@ if (0) fprintf(stderr, "XA: %s\n", getenv("XAUTHORITY")); #endif } check_redir_services(); - } if (! waited_for_client) { |