shithub: rd

Download patch

ref: d64f31c9862f2ab9b779dd9bd5c3363d6764c650
parent: ff67a7a3f5fea5fa0e3f28941122e4a666064339
author: Yaroslav Kolomiiets <yarikos@gmail.com>
date: Fri Aug 5 12:53:58 EDT 2016

shuffle some funcs around

--- a/dat.h
+++ b/dat.h
@@ -223,8 +223,8 @@
 int	getshareT(Share*, uchar*, uint);	/* T.128 ASPDU updates */
 int	getshareF(Share*, uchar*, uint);	/* RDP Fast-Path updates */
 
-void	activating(Rdp*,Share*);
-void	deactivating(Rdp*,Share*);
+void	activate(Rdp*,Share*);
+void	deactivate(Rdp*,Share*);
 void	finalhandshake(Rdp*);
 void	drawimgupdate(Rdp*,Share*);
 void	loadcmap(Rdp*,Share*);
--- /dev/null
+++ b/draw.c
@@ -1,0 +1,58 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include "dat.h"
+#include "fns.h"
+
+/* 2.2.9.1.1.3.1.2.1 Bitmap Update Data (TS_UPDATE_BITMAP_DATA) */
+void
+drawimgupdate(Rdp *c, Share* s)
+{
+	uchar* p, *ep;
+	int n, err, nr;
+	Rectangle r, rs, d;
+	Imgupd iu;
+	static Image* img;
+
+	assert(s->type == ShUimg);
+	p = s->data;
+	ep = s->data + s->ndata;
+	nr = s->nrect;
+
+	rs = rectaddpt(Rpt(ZP, Pt(c->xsz, c->ysz)), screen->r.min);
+
+	if(display->locking)
+		lockdisplay(display);
+
+	if(img==nil || !eqrect(img->r, rs)){
+		if(img != nil)
+			freeimage(img);
+		img = allocimage(display, rs, c->chan, 0, DNofill);
+		if(img == nil)
+			sysfatal("drawimgupdate: %r");
+	}
+
+	while(p<ep && nr>0){
+		/* 2.2.9.1.1.3.1.2.2 Bitmap Data (TS_BITMAP_DATA) */
+		if((n = getimgupd(&iu, p, ep-p)) < 0)
+			sysfatal("getimgupd: %r");
+		if(iu.depth != img->depth)
+			sysfatal("bad image depth");
+
+		d.min = Pt(iu.x, iu.y);
+		d.max = Pt(iu.xm+1, iu.ym+1);
+		r.min = ZP;
+		r.max = Pt(iu.xsz, iu.ysz);
+		r = rectaddpt(r, img->r.min);
+
+		err = (iu.iscompr? loadrle : loadbmp)(img, r, iu.bytes, iu.nbytes, c->cmap);
+		if(err < 0)
+			sysfatal("%r");
+		draw(screen, rectaddpt(d, screen->r.min), img, nil, img->r.min);
+		p += n;
+		nr--;
+	}
+	flushimage(display, 1);
+	if(display->locking)
+		unlockdisplay(display);
+}
--- a/mkfile
+++ b/mkfile
@@ -7,6 +7,7 @@
 OFILES=\
 	alloc.$O\
 	cap.$O\
+	draw.$O\
 	eclip.$O\
 	egdi.$O\
 	ele.$O\
@@ -29,6 +30,7 @@
 THREADOFILES=\
 	alloc.$O\
 	cap.$O\
+	draw.$O\
 	eclip.$O\
 	egdi.$O\
 	ele.$O\
--- a/rd-thread.c
+++ b/rd-thread.c
@@ -48,11 +48,10 @@
 	Rdp* c;
 
 	c = &conn;
-
 	keyspec = "";
 	doauth = 1;
 
-	ARGBEGIN {
+	ARGBEGIN{
 	case 'A':
 		doauth = 0;
 		break;
@@ -79,7 +78,7 @@
 		break;
 	default:
 		usage();
-	} ARGEND
+	}ARGEND
 
 	if (argc != 1)
 		usage();
@@ -152,132 +151,6 @@
 	unlockdisplay(display);
 	c->ysz = Dy(screen->r);
 	c->xsz = (Dx(screen->r) +3) & ~3;
-}
-
-void
-readnet(Rdp* c)
-{
-	Msg r;
-
-	for(;;){
-		if(readmsg(c, &r) <= 0)
-			return;
-
-		switch(r.type){
-		case Mclosing:
-			return;
-		case Mvchan:
-			scanvc(c, &r);
-			break;
-		case Aupdate:
-			scanupdates(c, &r);
-			break;
-		case 0:
-			fprint(2, "unsupported PDU\n");
-			break;
-		default:
-			fprint(2, "r.type %d is not expected\n", r.type);
-		}
-	}
-}
-
-void
-scanupdates(Rdp* c, Msg* m)
-{
-	int n;
-	uchar *p, *ep;
-	Share u;
-
-	p = m->data;
-	ep = m->data + m->ndata;
-
-	for(; p < ep; p += n){
-		n = m->getshare(&u, p, ep-p);
-		if(n < 0)
-			sysfatal("scanupdates: %r");
-
-		switch(u.type){
-		default:
-			if(u.type != 0)
-				fprint(2, "scanupdates: unhandled %d\n", u.type);
-			break;
-		case ShDeactivate:
-			deactivating(c, &u);
-			break;
-		case ShActivate:	// server may engage capability re-exchange
-			activating(c, &u);
-			break;
-		case ShEinfo:
-			c->hupreason = u.err;
-			break;
-		case ShUorders:
-			scanorders(c, &u);
-			break;
-		case ShUimg:
-			drawimgupdate(c, &u);
-			break;
-		case ShUcmap:
-			loadcmap(c, &u);
-			break;
-		case ShUwarp:
-			warpmouse(u.x, u.y);
-			break;
-		case Aflow:
-			break;
-		}
-	}
-}
-
-void
-drawimgupdate(Rdp *c, Share* as)
-{
-	uchar* p, *ep;
-	int n, err, nr;
-	static Image* img;
-	Rectangle r, rs, d;
-	Imgupd iu;
-
-	assert(as->type == ShUimg);
-	p = as->data;
-	ep = as->data + as->ndata;
-	nr = as->nrect;
-
-	rs = rectaddpt(Rpt(ZP, Pt(c->xsz, c->ysz)), screen->r.min);
-
-	if(display->locking)
-		lockdisplay(display);
-
-	if(img==nil || !eqrect(img->r, rs)){
-		if(img != nil)
-			freeimage(img);
-		img = allocimage(display, rs, c->chan, 0, DNofill);
-		if(img == nil)
-			sysfatal("drawimgupdate: %r");
-	}
-
-	while(p<ep && nr>0){
-		/* 2.2.9.1.1.3.1.2.2 Bitmap Data (TS_BITMAP_DATA) */
-		if((n = getimgupd(&iu, p, ep-p)) < 0)
-			sysfatal("getimgupd: %r");
-		if(iu.depth != img->depth)
-			sysfatal("bad image depth");
-
-		d.min = Pt(iu.x, iu.y);
-		d.max = Pt(iu.xm+1, iu.ym+1);
-		r.min = ZP;
-		r.max = Pt(iu.xsz, iu.ysz);
-		r = rectaddpt(r, img->r.min);
-
-		err = (iu.iscompr? loadrle : loadbmp)(img, r, iu.bytes, iu.nbytes, c->cmap);
-		if(err < 0)
-			sysfatal("%r");
-		draw(screen, rectaddpt(d, screen->r.min), img, nil, img->r.min);
-		p += n;
-		nr--;
-	}
-	flushimage(display, 1);
-	if(display->locking)
-		unlockdisplay(display);
 }
 
 static void
--- a/rd.c
+++ b/rd.c
@@ -125,11 +125,10 @@
 	Rdp* c;
 
 	c = &conn;
-
 	keyspec = "";
 	doauth = 1;
 
-	ARGBEGIN {
+	ARGBEGIN{
 	case 'A':
 		doauth = 0;
 		break;
@@ -156,7 +155,7 @@
 		break;
 	default:
 		usage();
-	} ARGEND
+	}ARGEND
 
 	if (argc != 1)
 		usage();
@@ -270,131 +269,4 @@
 		return;
 
 	fprint(mfd, "m%d %d", x, y);
-}
-
-void
-readnet(Rdp* c)
-{
-	Msg r;
-
-	for(;;){
-		if(readmsg(c, &r) <= 0)
-			return;
-
-		switch(r.type){
-		case Mclosing:
-			return;
-		case Mvchan:
-			scanvc(c, &r);
-			break;
-		case Aupdate:
-			scanupdates(c, &r);
-			break;
-		case 0:
-			fprint(2, "unsupported PDU\n");
-			break;
-		default:
-			fprint(2, "r.type %d is not expected\n", r.type);
-		}
-	}
-}
-
-void
-scanupdates(Rdp* c, Msg* m)
-{
-	int n;
-	uchar *p, *ep;
-	Share u;
-
-	p = m->data;
-	ep = m->data + m->ndata;
-
-	for(; p < ep; p += n){
-		n = m->getshare(&u, p, ep-p);
-		if(n < 0)
-			sysfatal("scanupdates: %r");
-
-		switch(u.type){
-		default:
-			if(u.type != 0)
-				fprint(2, "scanupdates: unhandled %d\n", u.type);
-			break;
-		case ShDeactivate:
-			deactivating(c, &u);
-			break;
-		case ShActivate:	// server may engage capability re-exchange
-			activating(c, &u);
-			break;
-		case ShEinfo:
-			c->hupreason = u.err;
-			break;
-		case ShUorders:
-			scanorders(c, &u);
-			break;
-		case ShUimg:
-			drawimgupdate(c, &u);
-			break;
-		case ShUcmap:
-			loadcmap(c, &u);
-			break;
-		case ShUwarp:
-			warpmouse(u.x, u.y);
-			break;
-		case Aflow:
-			break;
-		}
-	}
-}
-
-/* 2.2.9.1.1.3.1.2.1 Bitmap Update Data (TS_UPDATE_BITMAP_DATA) */
-void
-drawimgupdate(Rdp *c, Share* as)
-{
-	uchar* p, *ep;
-	int n, err, nr;
-	static Image* img;
-	Rectangle r, rs, d;
-	Imgupd iu;
-
-	assert(as->type == ShUimg);
-	p = as->data;
-	ep = as->data + as->ndata;
-	nr = as->nrect;
-
-	rs = rectaddpt(Rpt(ZP, Pt(c->xsz, c->ysz)), screen->r.min);
-
-	if(display->locking)
-		lockdisplay(display);
-
-	if(img==nil || !eqrect(img->r, rs)){
-		if(img != nil)
-			freeimage(img);
-		img = allocimage(display, rs, c->chan, 0, DNofill);
-		if(img == nil)
-			sysfatal("drawimgupdate: %r");
-	}
-
-	while(p<ep && nr>0){
-		/* 2.2.9.1.1.3.1.2.2 Bitmap Data (TS_BITMAP_DATA) */
-		if((n = getimgupd(&iu, p, ep-p)) < 0)
-			sysfatal("getimgupd: %r");
-		if(iu.depth != img->depth)
-			sysfatal("bad image depth");
-
-		d.min = Pt(iu.x, iu.y);
-		d.max = Pt(iu.xm+1, iu.ym+1);
-		r.min = ZP;
-		r.max = Pt(iu.xsz, iu.ysz);
-		r = rectaddpt(r, img->r.min);
-
-		err = (iu.iscompr? loadrle : loadbmp)(img, r, iu.bytes, iu.nbytes, c->cmap);
-		if(err < 0)
-			sysfatal("%r");
-		draw(screen, rectaddpt(d, screen->r.min), img, nil, img->r.min);
-		p += n;
-		nr--;
-	}
-	flushimage(display, 1);
-	if(display->locking)
-		unlockdisplay(display);
 }
--- a/rpc.c
+++ b/rpc.c
@@ -169,7 +169,7 @@
 				c->hupreason = u.err;
 				break;
 			case ShActivate:
-				activating(c, &u);
+				activate(c, &u);
 				return 0;
 			}
 		}
@@ -178,7 +178,7 @@
 
 /* 2.2.1.13.1 Server Demand Active PDU */
 void
-activating(Rdp* c, Share* as)
+activate(Rdp* c, Share* as)
 {
 	Caps rcaps;
 
@@ -213,7 +213,7 @@
 }
 
 void
-deactivating(Rdp* c, Share*)
+deactivate(Rdp* c, Share*)
 {
 	c->active = 0;
 }
@@ -231,10 +231,10 @@
 
 	for(;;){
 		if(readmsg(c, &r) <= 0)
-			sysfatal("activating: readmsg: %r");
+			sysfatal("activate: readmsg: %r");
 		switch(r.type){
 		default:
-			fprint(2, "activating: unhandled PDU type %d\n", u.type);
+			fprint(2, "activate: unhandled PDU type %d\n", u.type);
 			break;
 		case Mclosing:
 			fprint(2, "disconnecting early");
@@ -241,10 +241,10 @@
 			return;
 		case Aupdate:
 			if(r.getshare(&u, r.data, r.ndata) < 0)
-				sysfatal("activating: r.getshare: %r");
+				sysfatal("activate: r.getshare: %r");
 			switch(u.type){
 			default:
-				fprint(2, "activating: unhandled ASPDU type %d\n", u.type);
+				fprint(2, "activate: unhandled ASPDU type %d\n", u.type);
 				break;
 			case ShSync:
 			case ShCtl:
@@ -387,4 +387,76 @@
 	writemsg(c, &t);
 }
 
+void
+readnet(Rdp* c)
+{
+	Msg r;
 
+	for(;;){
+		if(readmsg(c, &r) <= 0)
+			return;
+
+		switch(r.type){
+		case Mclosing:
+			return;
+		case Mvchan:
+			scanvc(c, &r);
+			break;
+		case Aupdate:
+			scanupdates(c, &r);
+			break;
+		case 0:
+			fprint(2, "unsupported PDU\n");
+			break;
+		default:
+			fprint(2, "r.type %d is not expected\n", r.type);
+		}
+	}
+}
+
+void
+scanupdates(Rdp* c, Msg* m)
+{
+	int n;
+	uchar *p, *ep;
+	Share u;
+
+	p = m->data;
+	ep = m->data + m->ndata;
+
+	for(; p < ep; p += n){
+		n = m->getshare(&u, p, ep-p);
+		if(n < 0)
+			sysfatal("scanupdates: %r");
+
+		switch(u.type){
+		default:
+			if(u.type != 0)
+				fprint(2, "scanupdates: unhandled %d\n", u.type);
+			break;
+		case ShDeactivate:
+			deactivate(c, &u);
+			break;
+		case ShActivate:	// server may engage capability re-exchange
+			activate(c, &u);
+			break;
+		case ShEinfo:
+			c->hupreason = u.err;
+			break;
+		case ShUorders:
+			scanorders(c, &u);
+			break;
+		case ShUimg:
+			drawimgupdate(c, &u);
+			break;
+		case ShUcmap:
+			loadcmap(c, &u);
+			break;
+		case ShUwarp:
+			warpmouse(u.x, u.y);
+			break;
+		case Aflow:
+			break;
+		}
+	}
+}