wok-tiny rev 133

Add fbvnc-config & fbvnc-auth
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Aug 23 12:08:35 2017 +0200 (2017-08-23)
parents 8aceeb13c59a
children 1a6a79b48e76
files busybox/stuff/busybox-git.config fbvnc-auth/receipt fbvnc-auth/stuff/fbvnc.u fbvnc-config/receipt fbvnc-ssh/receipt linux/stuff/bundle
line diff
     1.1 --- a/busybox/stuff/busybox-git.config	Tue Aug 22 13:28:07 2017 +0200
     1.2 +++ b/busybox/stuff/busybox-git.config	Wed Aug 23 12:08:35 2017 +0200
     1.3 @@ -943,7 +943,7 @@
     1.4  CONFIG_UDHCPD=y
     1.5  # CONFIG_FEATURE_UDHCPD_BASE_IP_ON_MAC is not set
     1.6  # CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY is not set
     1.7 -CONFIG_DHCPD_LEASES_FILE="/var/lib/misc/udhcpd.leases"
     1.8 +CONFIG_DHCPD_LEASES_FILE="/var/lib/udhcpd.leases"
     1.9  CONFIG_DUMPLEASES=y
    1.10  # CONFIG_DHCPRELAY is not set
    1.11  CONFIG_UDHCPC=y
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/fbvnc-auth/receipt	Wed Aug 23 12:08:35 2017 +0200
     2.3 @@ -0,0 +1,34 @@
     2.4 +# SliTaz package receipt.
     2.5 +
     2.6 +PACKAGE="fbvnc-auth"
     2.7 +VERSION="1.0.2"
     2.8 +CATEGORY="network"
     2.9 +SHORT_DESC="VNC client in frame buffer with authentication."
    2.10 +MAINTAINER="pascal.bellard@slitaz.org"
    2.11 +LICENSE="GPL2"
    2.12 +TARBALL="$PACKAGE-$VERSION.tar.bz2"
    2.13 +WEB_SITE="https://github.com/zohead/fbvnc"
    2.14 +WGET_URL="git|git://github.com/zohead/fbvnc.git"
    2.15 +[ -n "$TARGET" ] || TARGET="i486"
    2.16 +BUILD_DEPENDS="uclibc-cross-compiler-$TARGET bzip2 git"
    2.17 +DEPENDS="fbvnc-config"
    2.18 +
    2.19 +# Rules to configure and make the package.
    2.20 +compile_rules()
    2.21 +{
    2.22 +	sed -i "s/^CC.*/CC = uclibc-$TARGET-gcc/;s/^LDFLAGS.*/& -s/" Makefile
    2.23 +	make
    2.24 +}
    2.25 +
    2.26 +
    2.27 +# Rules to gen a SliTaz package suitable for Tazpkg.
    2.28 +genpkg_rules()
    2.29 +{
    2.30 +	mkdir -p $fs/usr/bin
    2.31 +	cp $src/fbvnc $fs/usr/bin
    2.32 +}
    2.33 +
    2.34 +post_install()
    2.35 +{
    2.36 +	sed -i 's|:fbvnc|:/usr/bin/fbvnc|' $1/etc/init.d/local.sh
    2.37 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/fbvnc-auth/stuff/fbvnc.u	Wed Aug 23 12:08:35 2017 +0200
     3.3 @@ -0,0 +1,612 @@
     3.4 +--- draw.h
     3.5 ++++ draw.h
     3.6 +@@ -15,5 +15,11 @@
     3.7 + void fb_cmap(void);
     3.8 + 
     3.9 + /* helper functions */
    3.10 ++struct rgb_conv {
    3.11 ++	int rshl, gshl;
    3.12 ++	int rskp, gskp, bskp;
    3.13 ++	int rmax, gmax, bmax;
    3.14 ++};
    3.15 ++void fill_rgb_conv(int mode, struct rgb_conv *s);
    3.16 + void fb_set(int r, int c, void *mem, int len);
    3.17 + unsigned fb_val(int r, int g, int b);
    3.18 +--- draw.c
    3.19 ++++ draw.c
    3.20 +@@ -10,14 +10,13 @@
    3.21 + 
    3.22 + #define MIN(a, b)	((a) < (b) ? (a) : (b))
    3.23 + #define MAX(a, b)	((a) > (b) ? (a) : (b))
    3.24 +-#define NLEVELS		(1 << 8)
    3.25 ++#define NLEVELS		(1 << 16)
    3.26 + 
    3.27 + static int fd;
    3.28 + static void *fb;
    3.29 + static struct fb_var_screeninfo vinfo;
    3.30 + static struct fb_fix_screeninfo finfo;
    3.31 +-static int bpp;
    3.32 +-static int nr, ng, nb;
    3.33 ++static int bytes_per_pixel;
    3.34 + 
    3.35 + static int fb_len(void)
    3.36 + {
    3.37 +@@ -28,10 +27,12 @@
    3.38 + {
    3.39 + 	static unsigned short red[NLEVELS], green[NLEVELS], blue[NLEVELS];
    3.40 + 	struct fb_cmap cmap;
    3.41 ++
    3.42 + 	if (finfo.visual == FB_VISUAL_TRUECOLOR)
    3.43 + 		return;
    3.44 ++
    3.45 + 	cmap.start = 0;
    3.46 +-	cmap.len = MAX(nr, MAX(ng, nb));
    3.47 ++	cmap.len = NLEVELS;
    3.48 + 	cmap.red = red;
    3.49 + 	cmap.green = green;
    3.50 + 	cmap.blue = blue;
    3.51 +@@ -41,24 +42,39 @@
    3.52 + 
    3.53 + void fb_cmap(void)
    3.54 + {
    3.55 +-	unsigned short red[NLEVELS], green[NLEVELS], blue[NLEVELS];
    3.56 ++	struct fb_bitfield *color[3] = {
    3.57 ++		&vinfo.blue, &vinfo.green, &vinfo.red
    3.58 ++	};
    3.59 ++	int eye_sensibility[3] = { 2, 0, 1 }; // higher=red, blue, lower=green
    3.60 + 	struct fb_cmap cmap;
    3.61 +-	int i;
    3.62 ++	unsigned short map[3][NLEVELS];
    3.63 ++	int i, j, n, offset;
    3.64 ++
    3.65 + 	if (finfo.visual == FB_VISUAL_TRUECOLOR)
    3.66 + 		return;
    3.67 + 
    3.68 +-	for (i = 0; i < nr; i++)
    3.69 +-		red[i] = (65535 / (nr - 1)) * i;
    3.70 +-	for (i = 0; i < ng; i++)
    3.71 +-		green[i] = (65535 / (ng - 1)) * i;
    3.72 +-	for (i = 0; i < nb; i++)
    3.73 +-		blue[i] = (65535 / (nb - 1)) * i;
    3.74 +-
    3.75 ++	for (i = 0, n = vinfo.bits_per_pixel; i < 3; i++) {
    3.76 ++		n -= color[eye_sensibility[i]]->length = n / (3 - i);
    3.77 ++	}
    3.78 ++	n = (1 << vinfo.bits_per_pixel);
    3.79 ++	if (n > NLEVELS)
    3.80 ++		n = NLEVELS;
    3.81 ++	for (i = offset = 0; i < 3; i++) {
    3.82 ++		int length = color[i]->length;
    3.83 ++		color[i]->offset = offset;
    3.84 ++		for (j = 0; j < n; j++) {
    3.85 ++			int k = (j >> offset) << (16 - length);
    3.86 ++			if (k == (0xFFFF << (16 - length)))
    3.87 ++				k = 0xFFFF;
    3.88 ++			map[i][j] = k;
    3.89 ++		}
    3.90 ++		offset += length;
    3.91 ++	}
    3.92 + 	cmap.start = 0;
    3.93 +-	cmap.len = MAX(nr, MAX(ng, nb));
    3.94 +-	cmap.red = red;
    3.95 +-	cmap.green = green;
    3.96 +-	cmap.blue = blue;
    3.97 ++	cmap.len = n;
    3.98 ++	cmap.red = map[2];
    3.99 ++	cmap.green = map[1];
   3.100 ++	cmap.blue = map[0];
   3.101 + 	cmap.transp = NULL;
   3.102 + 
   3.103 + 	ioctl(fd, FBIOPUTCMAP, &cmap);
   3.104 +@@ -66,25 +82,26 @@
   3.105 + 
   3.106 + unsigned fb_mode(void)
   3.107 + {
   3.108 +-	return (bpp << 16) | (vinfo.red.length << 8) |
   3.109 ++	return (bytes_per_pixel << 16) | (vinfo.red.length << 8) |
   3.110 + 		(vinfo.green.length << 4) | (vinfo.blue.length);
   3.111 + }
   3.112 + 
   3.113 + int fb_init(void)
   3.114 + {
   3.115 ++	int err = 1;
   3.116 + 	fd = open(FBDEV_PATH, O_RDWR);
   3.117 + 	if (fd == -1)
   3.118 + 		goto failed;
   3.119 ++	err++;
   3.120 + 	if (ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) == -1)
   3.121 + 		goto failed;
   3.122 ++	err++;
   3.123 + 	if (ioctl(fd, FBIOGET_FSCREENINFO, &finfo) == -1)
   3.124 + 		goto failed;
   3.125 + 	fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
   3.126 +-	bpp = (vinfo.bits_per_pixel + 7) >> 3;
   3.127 +-	nr = 1 << vinfo.red.length;
   3.128 +-	ng = 1 << vinfo.blue.length;
   3.129 +-	nb = 1 << vinfo.green.length;
   3.130 ++	bytes_per_pixel = (vinfo.bits_per_pixel + 7) >> 3;
   3.131 + 	fb = mmap(NULL, fb_len(), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
   3.132 ++	err++;
   3.133 + 	if (fb == MAP_FAILED)
   3.134 + 		goto failed;
   3.135 + 	fb_cmap_save(1);
   3.136 +@@ -93,7 +110,7 @@
   3.137 + failed:
   3.138 + 	perror("fb_init()");
   3.139 + 	close(fd);
   3.140 +-	return 1;
   3.141 ++	return err;
   3.142 + }
   3.143 + 
   3.144 + void fb_free(void)
   3.145 +@@ -120,19 +137,30 @@
   3.146 + 
   3.147 + void fb_set(int r, int c, void *mem, int len)
   3.148 + {
   3.149 +-	memcpy(fb_mem(r) + (c + vinfo.xoffset) * bpp, mem, len * bpp);
   3.150 ++	memcpy(fb_mem(r) + (c + vinfo.xoffset) * bytes_per_pixel,
   3.151 ++		mem, len * bytes_per_pixel);
   3.152 + }
   3.153 + 
   3.154 ++void fill_rgb_conv(int mode, struct rgb_conv *s)
   3.155 ++{
   3.156 ++	int bits;
   3.157 ++
   3.158 ++	bits = mode & 0xF;  mode >>= 4;
   3.159 ++	s->rshl = s->gshl = bits;
   3.160 ++	s->bskp = 8 - bits; s->bmax = (1 << bits) -1;
   3.161 ++	bits = mode & 0xF;  mode >>= 4;
   3.162 ++	s->rshl += bits;
   3.163 ++	s->gskp = 8 - bits; s->gmax = (1 << bits) -1;
   3.164 ++	bits = mode & 0xF;
   3.165 ++	s->rskp = 8 - bits; s->rmax = (1 << bits) -1;
   3.166 ++}
   3.167 ++
   3.168 + unsigned fb_val(int r, int g, int b)
   3.169 + {
   3.170 +-	switch (fb_mode() & 0x0fff) {
   3.171 +-	default:
   3.172 +-		fprintf(stderr, "fb_val: unknown fb_mode()\n");
   3.173 +-	case 0x0888:
   3.174 +-		return (r << 16) | (g << 8) | b;
   3.175 +-	case 0x0565:
   3.176 +-		return ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
   3.177 +-	case 0x0233:
   3.178 +-		return ((r >> 6) << 6) | ((g >> 5) << 3) | (b >> 5);
   3.179 +-	}
   3.180 ++	static struct rgb_conv c;
   3.181 ++	
   3.182 ++	if (c.rshl == 0)
   3.183 ++		fill_rgb_conv(fb_mode(), &c);
   3.184 ++	return ((r >> c.rskp) << c.rshl) | ((g >> c.gskp) << c.gshl) 
   3.185 ++					 | (b >> c.bskp);
   3.186 + }
   3.187 +--- fbvnc.c
   3.188 ++++ fbvnc.c
   3.189 +@@ -36,13 +36,15 @@
   3.190 + 
   3.191 + #define VNC_PORT		"5900"
   3.192 + 
   3.193 +-#define MAXRES			(1 << 21)
   3.194 +-#define MIN(a, b)		((a) < (b) ? (a) : (b))
   3.195 ++#define MAXRES			(1 << 12)
   3.196 + 
   3.197 + static int cols, rows;
   3.198 ++static int srv_cols, srv_rows;
   3.199 ++static int or, oc;
   3.200 + static int mr, mc;		/* mouse position */
   3.201 + 
   3.202 + static char buf[MAXRES];
   3.203 ++#define MAXPIX		(MAXRES/sizeof(fbval_t))
   3.204 + 
   3.205 + static int vnc_connect(char *addr, char *port)
   3.206 + {
   3.207 +@@ -61,22 +63,26 @@
   3.208 + 
   3.209 + 	if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1) {
   3.210 + 		close(fd);
   3.211 +-		freeaddrinfo(addrinfo);
   3.212 +-		return -1;
   3.213 ++		fd = -2;
   3.214 + 	}
   3.215 + 	freeaddrinfo(addrinfo);
   3.216 + 	return fd;
   3.217 + }
   3.218 + 
   3.219 ++static int bpp, vnc_mode;
   3.220 ++static struct rgb_conv format;
   3.221 + static int vnc_init(int fd)
   3.222 + {
   3.223 +-	char vncver[] = "RFB 003.003\n";
   3.224 ++	static int vncfmt[] = { 0x40888, 0x20565, 0x10233, 0 };
   3.225 ++	char vncver[12];
   3.226 ++	int i;
   3.227 ++
   3.228 + 	struct vnc_client_init clientinit;
   3.229 + 	struct vnc_server_init serverinit;
   3.230 + 	struct vnc_client_pixelfmt pixfmt_cmd;
   3.231 + 	int connstat = VNC_CONN_FAILED;
   3.232 + 
   3.233 +-	write(fd, vncver, 12);
   3.234 ++	write(fd, "RFB 003.003\n", 12);
   3.235 + 	read(fd, vncver, 12);
   3.236 + 
   3.237 + 	read(fd, &connstat, sizeof(connstat));
   3.238 +@@ -88,68 +94,78 @@
   3.239 + 	write(fd, &clientinit, sizeof(clientinit));
   3.240 + 	read(fd, &serverinit, sizeof(serverinit));
   3.241 + 
   3.242 +-	if (fb_init())
   3.243 +-		return -1;
   3.244 +-	if (FBM_BPP(fb_mode()) != sizeof(fbval_t)) {
   3.245 +-		fprintf(stderr, "fbvnc: fbval_t doesn't match fb depth\n");
   3.246 +-		exit(1);
   3.247 +-	}
   3.248 +-	cols = MIN(ntohs(serverinit.w), fb_cols());
   3.249 +-	rows = MIN(ntohs(serverinit.h), fb_rows());
   3.250 ++	i = fb_init();
   3.251 ++	if (i)
   3.252 ++		return -1 - i;
   3.253 ++	srv_cols = ntohs(serverinit.w);
   3.254 ++	srv_rows = ntohs(serverinit.h);
   3.255 ++	cols = MIN(srv_cols, fb_cols());
   3.256 ++	rows = MIN(srv_rows, fb_rows());
   3.257 + 	mr = rows / 2;
   3.258 + 	mc = cols / 2;
   3.259 ++	or = oc = 0;
   3.260 + 
   3.261 + 	read(fd, buf, ntohl(serverinit.len));
   3.262 + 	pixfmt_cmd.type = VNC_CLIENT_PIXFMT;
   3.263 +-	pixfmt_cmd.format.bpp = 8;
   3.264 +-	pixfmt_cmd.format.depth = 8;
   3.265 + 	pixfmt_cmd.format.bigendian = 0;
   3.266 + 	pixfmt_cmd.format.truecolor = 1;
   3.267 + 
   3.268 +-	pixfmt_cmd.format.rmax = htons(3);
   3.269 +-	pixfmt_cmd.format.gmax = htons(7);
   3.270 +-	pixfmt_cmd.format.bmax = htons(7);
   3.271 +-	pixfmt_cmd.format.rshl = 0;
   3.272 +-	pixfmt_cmd.format.gshl = 2;
   3.273 +-	pixfmt_cmd.format.bshl = 5;
   3.274 ++	if (bpp < 1)
   3.275 ++	  	bpp = FBM_BPP(fb_mode());
   3.276 ++	if (bpp >= 3)
   3.277 ++		bpp = 4;
   3.278 ++	for (i = 0; bpp <= FBM_BPP(vncfmt[i]); i++)
   3.279 ++		vnc_mode = vncfmt[i];
   3.280 ++	bpp = FBM_BPP(vnc_mode);
   3.281 ++	pixfmt_cmd.format.bpp =
   3.282 ++	pixfmt_cmd.format.depth = bpp << 3;
   3.283 + 
   3.284 ++	fill_rgb_conv(FBM_COLORS(vnc_mode), &format);
   3.285 ++	pixfmt_cmd.format.rmax = htons(format.rmax);
   3.286 ++	pixfmt_cmd.format.gmax = htons(format.gmax);
   3.287 ++	pixfmt_cmd.format.bmax = htons(format.bmax);
   3.288 ++	pixfmt_cmd.format.rshl = format.rshl;
   3.289 ++	pixfmt_cmd.format.gshl = format.gshl;
   3.290 ++	pixfmt_cmd.format.bshl = 0;
   3.291 + 	write(fd, &pixfmt_cmd, sizeof(pixfmt_cmd));
   3.292 + 	return fd;
   3.293 + }
   3.294 + 
   3.295 +-static int vnc_free(void)
   3.296 ++static void vnc_free(void)
   3.297 + {
   3.298 + 	fb_free();
   3.299 +-	return 0;
   3.300 + }
   3.301 + 
   3.302 +-static int vnc_refresh(int fd, int inc)
   3.303 ++static void vnc_refresh(int fd, int inc)
   3.304 + {
   3.305 + 	struct vnc_client_fbup fbup_req;
   3.306 + 	fbup_req.type = VNC_CLIENT_FBUP;
   3.307 + 	fbup_req.inc = inc;
   3.308 +-	fbup_req.x = htons(0);
   3.309 +-	fbup_req.y = htons(0);
   3.310 +-	fbup_req.w = htons(cols);
   3.311 +-	fbup_req.h = htons(rows);
   3.312 ++	fbup_req.x = htons(oc);
   3.313 ++	fbup_req.y = htons(or);
   3.314 ++	fbup_req.w = htons(oc + cols);
   3.315 ++	fbup_req.h = htons(or + rows);
   3.316 + 	write(fd, &fbup_req, sizeof(fbup_req));
   3.317 +-	return 0;
   3.318 + }
   3.319 + 
   3.320 +-static void drawfb(char *s, int x, int y, int w, int h)
   3.321 ++static void drawfb(char *s, int x, int y, int w)
   3.322 + {
   3.323 +-	fbval_t slice[1 << 14];
   3.324 +-	int i, j;
   3.325 +-	for (i = 0; i < h; i++) {
   3.326 +-		for (j = 0; j < w; j++) {
   3.327 +-			int c = *(unsigned char *) &s[i * w + j];
   3.328 +-			int r = (c & 0x3) << 6;
   3.329 +-			int g = ((c >> 2) & 0x7) << 5;
   3.330 +-			int b = ((c >> 5) & 0x7) << 5;
   3.331 +-			slice[j] = FB_VAL(r, g, b);
   3.332 ++	int mode = fb_mode();
   3.333 ++	if (mode != vnc_mode) {
   3.334 ++		fbval_t slice[MAXRES];
   3.335 ++		unsigned char *byte = (unsigned char *) slice;
   3.336 ++		int j;
   3.337 ++		int fb_bpp = FBM_BPP(mode);
   3.338 ++		for (j = 0; j < w; j++, byte += fb_bpp, s += bpp) {
   3.339 ++			fbval_t c = * (fbval_t *) s;
   3.340 ++			int r = ((c >> format.rshl) & format.rmax) << format.rskp;
   3.341 ++			int g = ((c >> format.gshl) & format.gmax) << format.gskp;
   3.342 ++			int b = (c & format.bmax) << format.bskp;
   3.343 ++			* (fbval_t *) byte = FB_VAL(r, g, b);
   3.344 + 		}
   3.345 +-		fb_set(y + i, x, slice, w);
   3.346 ++		s = (void *) slice;
   3.347 + 	}
   3.348 ++	fb_set(y, x, s, w);
   3.349 + }
   3.350 + 
   3.351 + static void xread(int fd, void *buf, int len)
   3.352 +@@ -159,54 +175,84 @@
   3.353 + 	while (nr < len && (n = read(fd, buf + nr, len - nr)) > 0)
   3.354 + 		nr += n;
   3.355 + 	if (nr < len) {
   3.356 +-		printf("partial vnc read!\n");
   3.357 +-		exit(1);
   3.358 ++		fprintf(stderr,"partial vnc read!\n");
   3.359 ++		exit(99);
   3.360 + 	}
   3.361 + }
   3.362 + 
   3.363 ++static void skip(int fd, int len)
   3.364 ++{
   3.365 ++	int n;
   3.366 ++	while (len > 0 && (n = read(fd, buf, MIN(len, sizeof(buf)))) > 0)
   3.367 ++		len -= n;
   3.368 ++}
   3.369 ++
   3.370 + static int vnc_event(int fd)
   3.371 + {
   3.372 + 	struct vnc_rect uprect;
   3.373 +-	char msg[1 << 12];
   3.374 +-	struct vnc_server_fbup *fbup = (void *) msg;
   3.375 +-	struct vnc_server_cuttext *cuttext = (void *) msg;
   3.376 +-	struct vnc_server_colormap *colormap = (void *) msg;
   3.377 +-	int j;
   3.378 +-	int n;
   3.379 ++	union {
   3.380 ++		struct vnc_server_fbup fbup;
   3.381 ++		struct vnc_server_cuttext cuttext;
   3.382 ++		struct vnc_server_colormap colormap;
   3.383 ++	} msg;
   3.384 ++	int j, n;
   3.385 + 
   3.386 +-	if (read(fd, msg, 1) != 1)
   3.387 ++	if (read(fd, &msg.fbup.type, 1) != 1)
   3.388 + 		return -1;
   3.389 +-	switch (msg[0]) {
   3.390 ++	switch (msg.fbup.type) {
   3.391 + 	case VNC_SERVER_FBUP:
   3.392 +-		xread(fd, msg + 1, sizeof(*fbup) - 1);
   3.393 +-		n = ntohs(fbup->n);
   3.394 ++		xread(fd, &msg.fbup.pad, sizeof(msg.fbup) - 1);
   3.395 ++		n = ntohs(msg.fbup.n);
   3.396 + 		for (j = 0; j < n; j++) {
   3.397 +-			int x, y, w, h;
   3.398 ++			int x, y, w, h, l, i;
   3.399 + 			xread(fd, &uprect, sizeof(uprect));
   3.400 ++			if (uprect.enc != 0) {
   3.401 ++				fprintf(stderr,"Encoding not RAW: %d\n",
   3.402 ++					ntohl(uprect.enc));
   3.403 ++				return -1;
   3.404 ++			}
   3.405 + 			x = ntohs(uprect.x);
   3.406 + 			y = ntohs(uprect.y);
   3.407 + 			w = ntohs(uprect.w);
   3.408 + 			h = ntohs(uprect.h);
   3.409 +-			if (x >= cols || x + w > cols)
   3.410 +-				return -1;
   3.411 +-			if (y >= rows || y + h > rows)
   3.412 +-				return -1;
   3.413 +-			xread(fd, buf, w * h);
   3.414 +-			drawfb(buf, x, y, w, h);
   3.415 ++			x -= oc;
   3.416 ++			y -= or;
   3.417 ++			i = 0;
   3.418 ++			l = MIN(w, cols - x);
   3.419 ++			if (x < 0) {
   3.420 ++				l = MIN(w + x, cols);
   3.421 ++				i = MIN(w, -x);
   3.422 ++				x = 0;
   3.423 ++			}
   3.424 ++			if (l < 0)
   3.425 ++				l = 0;
   3.426 ++			for (; h--; y++) {
   3.427 ++				int n = l;
   3.428 ++				int xj = x;
   3.429 ++				skip(fd, i * bpp);
   3.430 ++				while (n > 0) {
   3.431 ++					int j = MIN(n, MAXPIX);
   3.432 ++					xread(fd, buf, j * bpp);
   3.433 ++					if (y >= 0 && y < rows)
   3.434 ++						drawfb(buf, xj, y, j);
   3.435 ++					xj += j; n -= j;
   3.436 ++				}
   3.437 ++				skip(fd, (w - l - i) * bpp);
   3.438 ++			}
   3.439 + 		}
   3.440 + 		break;
   3.441 + 	case VNC_SERVER_BELL:
   3.442 + 		break;
   3.443 + 	case VNC_SERVER_CUTTEXT:
   3.444 +-		xread(fd, msg + 1, sizeof(*cuttext) - 1);
   3.445 +-		xread(fd, buf, ntohl(cuttext->len));
   3.446 ++		xread(fd, &msg.cuttext.pad1, sizeof(msg.cuttext) - 1);
   3.447 ++		skip(fd, ntohl(msg.cuttext.len));
   3.448 + 		break;
   3.449 + 	case VNC_SERVER_COLORMAP:
   3.450 +-		xread(fd, msg + 1, sizeof(*colormap) - 1);
   3.451 +-		xread(fd, buf, ntohs(colormap->n) * 3 * 2);
   3.452 ++		xread(fd, &msg.colormap.pad, sizeof(msg.colormap) - 1);
   3.453 ++		skip(fd, ntohs(msg.colormap.n) * 3 * 2);
   3.454 + 		break;
   3.455 + 	default:
   3.456 +-		fprintf(stderr, "unknown vnc msg: %d\n", msg[0]);
   3.457 ++		fprintf(stderr, "unknown vnc msg: %d\n", msg.fbup.type);
   3.458 + 		return -1;
   3.459 + 	}
   3.460 + 	return 0;
   3.461 +@@ -217,12 +263,31 @@
   3.462 + 	char ie[3];
   3.463 + 	struct vnc_client_ratevent me = {VNC_CLIENT_RATEVENT};
   3.464 + 	int mask = 0;
   3.465 ++	int refresh = 2;
   3.466 + 	if (read(ratfd, &ie, sizeof(ie)) != 3)
   3.467 + 		return -1;
   3.468 + 	mc += ie[1];
   3.469 + 	mr -= ie[2];
   3.470 +-	mc = MAX(0, MIN(cols - 1, mc));
   3.471 +-	mr = MAX(0, MIN(rows - 1, mr));
   3.472 ++	if (mc < oc) {
   3.473 ++		if ((oc -= cols / 5) < 0)
   3.474 ++			oc = 0;
   3.475 ++	}
   3.476 ++	else if (mc >= oc + cols && oc + cols < srv_cols) {
   3.477 ++		if ((oc += cols / 5) > srv_cols - cols)
   3.478 ++			oc = srv_cols - cols;
   3.479 ++	}
   3.480 ++	else refresh--;
   3.481 ++	if (mr < or) {
   3.482 ++		if ((or -= rows / 5) < 0)
   3.483 ++			or = 0;
   3.484 ++	}
   3.485 ++	else if (mr >= or + rows && or + rows < srv_rows) {
   3.486 ++		if ((or += rows / 5) > srv_rows - rows)
   3.487 ++			or = srv_rows - rows;
   3.488 ++	}
   3.489 ++	else refresh--;
   3.490 ++	mc = MAX(oc, MIN(oc + cols - 1, mc));
   3.491 ++	mr = MAX(or, MIN(or + rows - 1, mr));
   3.492 + 	if (ie[0] & 0x01)
   3.493 + 		mask |= VNC_BUTTON1_MASK;
   3.494 + 	if (ie[0] & 0x04)
   3.495 +@@ -233,6 +298,8 @@
   3.496 + 	me.x = htons(mc);
   3.497 + 	me.mask = mask;
   3.498 + 	write(fd, &me, sizeof(me));
   3.499 ++	if (refresh)
   3.500 ++		vnc_refresh(fd, 0);
   3.501 + 	return 0;
   3.502 + }
   3.503 + 
   3.504 +@@ -292,12 +359,11 @@
   3.505 + 			k = 0xff0d;
   3.506 + 			break;
   3.507 + 		case 0x0c:	/* ^L: redraw */
   3.508 +-			if (vnc_refresh(fd, 0))
   3.509 +-				return -1;
   3.510 ++			vnc_refresh(fd, 0);
   3.511 + 		default:
   3.512 + 			k = (unsigned char) key[i];
   3.513 + 		}
   3.514 +-		if (k >= 'A' && k <= 'Z' || strchr(":\"<>?{}|+_()*&^%$#@!~", k))
   3.515 ++		if ((k >= 'A' && k <= 'Z') || strchr(":\"<>?{}|+_()*&^%$#@!~", k))
   3.516 + 			mod[nmod++] = 0xffe1;
   3.517 + 		if (k >= 1 && k <= 26) {
   3.518 + 			k = 'a' + k - 1;
   3.519 +@@ -339,40 +405,42 @@
   3.520 + 	write(STDIN_FILENO, show, strlen(show));
   3.521 + }
   3.522 + 
   3.523 +-static void mainloop(int vnc_fd, int kbd_fd, int rat_fd)
   3.524 ++static int mainloop(int vnc_fd, int kbd_fd, int rat_fd)
   3.525 + {
   3.526 + 	struct pollfd ufds[3];
   3.527 + 	int pending = 0;
   3.528 + 	int err;
   3.529 + 	ufds[0].fd = kbd_fd;
   3.530 +-	ufds[0].events = POLLIN;
   3.531 + 	ufds[1].fd = vnc_fd;
   3.532 +-	ufds[1].events = POLLIN;
   3.533 + 	ufds[2].fd = rat_fd;
   3.534 ++	ufds[0].events =
   3.535 ++	ufds[1].events =
   3.536 + 	ufds[2].events = POLLIN;
   3.537 +-	if (vnc_refresh(vnc_fd, 0))
   3.538 +-		return;
   3.539 ++	vnc_refresh(vnc_fd, 0);
   3.540 + 	while (1) {
   3.541 + 		err = poll(ufds, 3, 500);
   3.542 + 		if (err == -1 && errno != EINTR)
   3.543 + 			break;
   3.544 + 		if (!err)
   3.545 + 			continue;
   3.546 ++		err = -2;
   3.547 + 		if (ufds[0].revents & POLLIN)
   3.548 + 			if (kbd_event(vnc_fd, kbd_fd) == -1)
   3.549 + 				break;
   3.550 ++		err--;
   3.551 + 		if (ufds[1].revents & POLLIN) {
   3.552 + 			if (vnc_event(vnc_fd) == -1)
   3.553 + 				break;
   3.554 + 			pending = 0;
   3.555 + 		}
   3.556 ++		err--;
   3.557 + 		if (ufds[2].revents & POLLIN)
   3.558 + 			if (rat_event(vnc_fd, rat_fd) == -1)
   3.559 + 				break;
   3.560 + 		if (!pending++)
   3.561 +-			if (vnc_refresh(vnc_fd, 1))
   3.562 +-				break;
   3.563 ++			vnc_refresh(vnc_fd, 1);
   3.564 + 	}
   3.565 ++	return err;
   3.566 + }
   3.567 + 
   3.568 + int main(int argc, char * argv[])
   3.569 +@@ -380,27 +448,38 @@
   3.570 + 	char *port = VNC_PORT;
   3.571 + 	char *host = "127.0.0.1";
   3.572 + 	struct termios ti;
   3.573 +-	int vnc_fd, rat_fd;
   3.574 ++	int vnc_fd, rat_fd, status;
   3.575 ++	
   3.576 ++	if (argc < 2) {
   3.577 ++		fprintf(stderr, "Usage : fbvnc [-bpp bits] server [port]\n");
   3.578 ++		return 0;
   3.579 ++  	}
   3.580 ++  	if (*argv[1] == '-' && argc >= 3) {
   3.581 ++  		argc -= 2; argv += 2;
   3.582 ++  		bpp = atoi(argv[0]) >> 3;
   3.583 ++  	} 
   3.584 + 	if (argc >= 2)
   3.585 + 		host = argv[1];
   3.586 + 	if (argc >= 3)
   3.587 + 		port = argv[2];
   3.588 +-	if ((vnc_fd = vnc_connect(host, port)) == -1) {
   3.589 +-		fprintf(stderr, "could not connect!\n");
   3.590 ++	if ((vnc_fd = vnc_connect(host, port)) < 0) {
   3.591 ++		fprintf(stderr, "could not connect! %s %s : %d\n",
   3.592 ++			host,port,vnc_fd);
   3.593 + 		return 1;
   3.594 + 	}
   3.595 +-	if (vnc_init(vnc_fd) == -1) {
   3.596 +-		fprintf(stderr, "vnc init failed!\n");
   3.597 +-		return 1;
   3.598 ++	status = vnc_init(vnc_fd);
   3.599 ++	if (status < 0) {
   3.600 ++		fprintf(stderr, "vnc init failed! %d\n", status);
   3.601 ++		return 2;
   3.602 + 	}
   3.603 + 	term_setup(&ti);
   3.604 + 	rat_fd = open("/dev/input/mice", O_RDONLY);
   3.605 + 
   3.606 +-	mainloop(vnc_fd, 0, rat_fd);
   3.607 ++	status = mainloop(vnc_fd, 0, rat_fd);
   3.608 + 
   3.609 + 	term_cleanup(&ti);
   3.610 + 	vnc_free();
   3.611 + 	close(vnc_fd);
   3.612 + 	close(rat_fd);
   3.613 +-	return 0;
   3.614 ++	return 2 - status;
   3.615 + }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/fbvnc-config/receipt	Wed Aug 23 12:08:35 2017 +0200
     4.3 @@ -0,0 +1,137 @@
     4.4 +# SliTaz package receipt.
     4.5 +
     4.6 +PACKAGE="fbvnc-config"
     4.7 +VERSION="1.0"
     4.8 +CATEGORY="meta"
     4.9 +GROUP="network"
    4.10 +SHORT_DESC="VNC client configuration"
    4.11 +MAINTAINER="pascal.bellard@slitaz.org"
    4.12 +LICENSE="BSD"
    4.13 +WEB_SITE="http://tiny.slitaz.org/"
    4.14 +DEPENDS="base-tiny"
    4.15 +
    4.16 +# Rules to gen a SliTaz package suitable for Tazpkg.
    4.17 +genpkg_rules()
    4.18 +{
    4.19 +	mkdir -p $fs/etc
    4.20 +}
    4.21 +
    4.22 +config_form()
    4.23 +{
    4.24 +	case "$START" in
    4.25 +	no|yes|ask) ;;
    4.26 +	*) START="cmdline" ;;
    4.27 +	esac
    4.28 +	case "$BPP" in
    4.29 +	8|24|32) ;;
    4.30 +	*) BPP=16 ;;
    4.31 +	esac
    4.32 +	[ -n "$PORT" ] || PORT=5900
    4.33 +	[ -n "$SERVER" ] || SERVER="192.168.0.10"
    4.34 +	cat <<EOT
    4.35 +<table>
    4.36 +<tr>
    4.37 +<td>Autostart</td>
    4.38 +<td>
    4.39 +<input type="radio" name="START" $([ "$START" == "no" ] && echo "checked=checked ")value="no"> never
    4.40 +<input type="radio" name="START" $([ "$START" == "yes" ] && echo "checked=checked ")value="yes"> always
    4.41 +<input type="radio" name="START" $([ "$START" == "ask" ] && echo "checked=checked ")value="ask"> ask during boot
    4.42 +<input type="radio" name="START" $([ "$START" == "cmdline" ] && echo "checked=checked ")value="cmdline"> with kernel argument 'fbvnc=<i>server</i>:<i>port</i>'
    4.43 +</td>
    4.44 +</tr>
    4.45 +<tr>
    4.46 +<td>Bits per pixel</td>
    4.47 +<td>
    4.48 +<input type="radio" name="BPP" $([ "$BPP" == "8" ] && echo "checked=checked ")value="8"> 8
    4.49 +<input type="radio" name="BPP" $([ "$BPP" == "16" ] && echo "checked=checked ")value="16"> 16
    4.50 +<input type="radio" name="BPP" $([ "$BPP" == "32" ] && echo "checked=checked ")value="32"> 32
    4.51 +</td>
    4.52 +</tr>
    4.53 +<tr>
    4.54 +<td>Default server</td>
    4.55 +<td><input type="text" name="SERVER" value="$SERVER"></td>
    4.56 +</tr>
    4.57 +<tr>
    4.58 +<td>Default port</td>
    4.59 +<td><input type="text" name="PORT" value="$PORT"></td>
    4.60 +</tr>
    4.61 +</table>
    4.62 +EOT
    4.63 +}
    4.64 +
    4.65 +config_note()
    4.66 +{
    4.67 +	cat <<EOT
    4.68 +<script type="text/javascript">
    4.69 +function update_form()
    4.70 +{
    4.71 +	var hide = true
    4.72 +	for (var i = 0; i < document.forms.length; i++) {
    4.73 +		for (var j = 0; j < document.forms[i].elements.length; j++) {
    4.74 +			var obj = document.forms[i].elements[j]
    4.75 +			if (obj.name == "START" && obj.defaultValue == "yes"
    4.76 +						&& obj.checked == true)
    4.77 +				hide = false
    4.78 +		}
    4.79 +	}	
    4.80 +	for (var i = 0; i < document.forms.length; i++) {
    4.81 +		for (var j = 0; j < document.forms[i].elements.length; j++) {
    4.82 +			var obj = document.forms[i].elements[j]
    4.83 +			switch (obj.name) {
    4.84 +			case "SERVER" :
    4.85 +			case "PORT" :
    4.86 +				obj.disabled = hide; break;
    4.87 +			}
    4.88 +		}
    4.89 +	}	
    4.90 +}
    4.91 +update_form()
    4.92 +window.onchange = update_form
    4.93 +//-->
    4.94 +</script>
    4.95 +EOT
    4.96 +}
    4.97 +
    4.98 +post_install()
    4.99 +{
   4.100 +	case "$START" in
   4.101 +	on)	cat >> $1/etc/init.d/local.sh <<EOT
   4.102 +
   4.103 +# From fbvnc-config
   4.104 +VNCSERVER="$SERVER"
   4.105 +VNCPORT="$PORT"
   4.106 +sed -i "s|tty1:.*|tty1::respawn:fbvnc -bpp $BPP $SERVER $PORT|" /etc/inittab
   4.107 +kill -1 1
   4.108 +EOT
   4.109 +		;;
   4.110 +	ask)	cat >> $1/etc/init.d/local.sh <<EOT
   4.111 +
   4.112 +# From fbvnc-config
   4.113 +echo -n "VNC server to connect (example: 192.168.0.123 5900): "
   4.114 +read -t 30 SERVER
   4.115 +[ -n "\$SERVER" ] &&
   4.116 +sed -i "s|tty1:.*|tty1::respawn:fbvnc -bpp $BPP \$SERVER|" /etc/inittab
   4.117 +set -- \$SERVER 5900
   4.118 +VNCSERVER="\$1"
   4.119 +VNCPORT="\$2"
   4.120 +kill -1 1
   4.121 +EOT
   4.122 +		;;
   4.123 +	cmdline) cat >> $1/etc/init.d/local.sh <<EOT
   4.124 +
   4.125 +# From fbvnc-config
   4.126 +for i in \$(cat /proc/cmdline); do
   4.127 +    case "\$i" in
   4.128 +    fbvnc=*)
   4.129 +	i=\${i#fbvnc=}
   4.130 +	sed -i "s|tty1:.*|tty1::respawn:fbvnc -bpp $BPP \${i/:/ }|" /etc/inittab
   4.131 +	set -- \${i/:/ } 5900
   4.132 +	VNCSERVER="\$1"
   4.133 +	VNCPORT="\$2"
   4.134 +	kill -1 1
   4.135 +    esac
   4.136 +done
   4.137 +EOT
   4.138 +		;;
   4.139 +	esac
   4.140 +}
     5.1 --- a/fbvnc-ssh/receipt	Tue Aug 22 13:28:07 2017 +0200
     5.2 +++ b/fbvnc-ssh/receipt	Wed Aug 23 12:08:35 2017 +0200
     5.3 @@ -8,12 +8,12 @@
     5.4  MAINTAINER="pascal.bellard@slitaz.org"
     5.5  LICENSE="BSD"
     5.6  WEB_SITE="http://tiny.slitaz.org/"
     5.7 -DEPENDS="base-tiny dropbear"
     5.8 +DEPENDS="base-tiny fbvnc-config dropbear"
     5.9  
    5.10  # Rules to gen a SliTaz package suitable for Tazpkg.
    5.11  genpkg_rules()
    5.12  {
    5.13 -	mkdir -p $fs/usr/bin
    5.14 +	mkdir -p $fs/etc
    5.15  }
    5.16  
    5.17  config_form()
     6.1 --- a/linux/stuff/bundle	Tue Aug 22 13:28:07 2017 +0200
     6.2 +++ b/linux/stuff/bundle	Wed Aug 23 12:08:35 2017 +0200
     6.3 @@ -48,16 +48,26 @@
     6.4  	pos=$(($pos+${#2}+1))
     6.5  	shift 2
     6.6  	free=$((0x1F1 - 2 - $pos - $crc))
     6.7 -	p=1
     6.8  	while [ -n "$2" -a $free -ge ${#2} ]; do
     6.9 -		s=$((($(stat -c "%s" "$1")+511)/512))
    6.10 +		echo "$((($(stat -c "%s" "$1")+511)/512)) $1 $2"
    6.11 +		shift 2
    6.12 +	done | awk '
    6.13 +BEGIN { i=0 } { sz[i]=$1; fn[i]=$2; sub(".*"$2,""); me[i++]=$0 }
    6.14 +END {
    6.15 +  for (m=0, l=p=1; m<i; m++) {
    6.16 +    for (s=100000, j=0; j<i; j++) if (!lc[j] && sz[j]<s) s=sz[k=j];
    6.17 +    f2[m]=fn[k]; s2[m]=s; lc[k]=l; l+=s; l2[m]=p; p+=sz[m]
    6.18 +  }
    6.19 +  for (j=0; j<i; j++)
    6.20 +    print sz[j] " " lc[j] " " fn[j] " " s2[j] " " l2[j] " " f2[j] " " me[j]
    6.21 +}' |	while read s p file s2 p2 file2 entry ; do
    6.22 +		[ -z "$SORT_MENU" ] && file2=$file && s2=$s && p=$p2
    6.23  		x="$(printf '\\x%02x\\x%02x' $(($p % 256)) $(($p / 256)) )"
    6.24 -		echo -en "$x$2\0" | ddq bs=1 of="$out" seek=$pos conv=notrunc
    6.25 -		p=$(($p+$s))
    6.26 -		pos=$(($pos+2+${#2}+1))
    6.27 -		cat "$1" /dev/zero | ddq bs=512 count=$s >> "$out"
    6.28 +		echo -en "$x$entry\0" | ddq bs=1 of="$out" seek=$pos conv=notrunc
    6.29 +		pos=$(($pos+2+${#entry}+1))
    6.30 +		cat "$file2" /dev/zero | ddq bs=512 count=$s2 >> "$out"
    6.31  		if [ $crc -ne 0 ]; then
    6.32 -			x=$(cat "$1" /dev/zero | ddq bs=512 count=$s | od -v \
    6.33 +			x=$(cat "$file" /dev/zero | ddq bs=512 count=$s | od -v \
    6.34  			    -t u2 -w2 -An|awk '{i+=$0} END {print (i % 65536)}')
    6.35  			x="$(printf '\\x%02x\\x%02x' $(($x % 256)) $(($x / 256)) )"
    6.36  			echo -en "$x" | ddq bs=1 of="$out" seek=$pos conv=notrunc
    6.37 @@ -68,7 +78,6 @@
    6.38  		fi
    6.39  		shift 2
    6.40  	done
    6.41 -	[ -n "$2" ] && echo "Warning: skip $@" 1>&2 && exit 1
    6.42  elif [ -s "$2" ]; then
    6.43  	base_initrd=$((0x00300000))
    6.44  	size_initrd=$(stat -c %s "$2")