History

20091214-1943

forsyth committed 16 years ago

Commit 89d0b5e1 parent a5bc64423 files · +115 −174Browse files

Unified · Split

23 files
  1. CHANGES +3 −0
  2. appl/cmd/auxi/mangaload.b +7 −19
  3. appl/cmd/cddb.b +7 −18
  4. appl/cmd/import.b +5 −18
  5. appl/cmd/ip/ping.b +7 −18
  6. appl/cmd/ip/rip.b +8 −3
  7. appl/cmd/lockfs.b +42 −51
  8. appl/cmd/ndb/dns.b +10 −4
  9. appl/cmd/styxchat.b +13 −24
  10. appl/cmd/telnet.b +12 −25
  11. appl/cmd/webgrab.b +8 −3
  12. dis/auxi/mangaload.dis +0 −0
  13. dis/cddb.dis +0 −0
  14. dis/import.dis +0 −0
  15. dis/ip/ping.dis +0 −0
  16. dis/ip/rip.dis +0 −0
  17. dis/lockfs.dis +0 −0
  18. dis/ndb/dns.dis +0 −0
  19. dis/styxchat.dis +0 −0
  20. dis/telnet.dis +0 −0
  21. dis/webgrab.dis +0 −0
  22. emu/Linux/emu-g +2 −0
  23. include/version.h +1 −1
CHANGES+3−0
@@ -1,3 +1,6 @@
120091214
2 switch more commands to use dial(2)
3 change emu/Linux/emu-g not to require X11 libs (again)
120091213420091213
2 temper the tendancy of port/dis.c to yield during idle gc: it's compensating for os scheduling, but yield less often5 temper the tendancy of port/dis.c to yield during idle gc: it's compensating for os scheduling, but yield less often
320091208620091208
appl/cmd/auxi/mangaload.b+7−19
@@ -16,6 +16,9 @@ include "timers.m"; · 15 unmodified lines
16 timers: Timers;16 timers: Timers;
17 Timer: import timers;17 Timer: import timers;
18 18
19include "dial.m";
20 dial: Dial;
21
19include "arg.m";22include "arg.m";
20 23
21Mangaload: module24Mangaload: module
@@ -88,6 +91,7 @@ init(nil: ref Draw->Context, args: list of string) · 66 unmodified lines
88{91{
89 sys = load Sys Sys->PATH;92 sys = load Sys Sys->PATH;
90 timers = load Timers Timers->PATH;93 timers = load Timers Timers->PATH;
94 dial = load Dial Dial->PATH;
91 ip = load IP IP->PATH;95 ip = load IP IP->PATH;
92 ip->init();96 ip->init();
93 97
@@ -137,9 +141,9 @@ init(nil: ref Draw->Context, args: list of string) · 43 unmodified lines
137 filesize := int d.length;141 filesize := int d.length;
138 142
139 port := sys->sprint("%d", 16r8695);143 port := sys->sprint("%d", 16r8695);
140 addr := netmkaddr(hd args, "icmp", port);144 addr := dial->netmkaddr(hd args, "icmp", port);
141 (rok, c) := sys->dial(addr, port);145 c := dial->dial(addr, port);
142 if(rok < 0){146 if(c == nil){
143 sys->fprint(sys->fildes(2), "mangaload: can't dial %s: %r\n", addr);147 sys->fprint(sys->fildes(2), "mangaload: can't dial %s: %r\n", addr);
144 raise "fail:dial";148 raise "fail:dial";
145 }149 }
@@ -182,7 +186,6 @@ init(nil: ref Draw->Context, args: list of string) · 36 unmodified lines
182 last := 0;186 last := 0;
183 while((n := sys->read(fd, buf, len buf)) >= 0 && !last){187 while((n := sys->read(fd, buf, len buf)) >= 0 && !last){
184 last = n != len buf;188 last = n != len buf;
185 nretry := 0;
186 Retry:189 Retry:
187 for(;;){190 for(;;){
188 if(++nsent%10 == 0){ # probe191 if(++nsent%10 == 0){ # probe
@@ -345,18 +348,3 @@ Icmp.unpack(b: array of byte): ref Icmp · 156 unmodified lines
345 ic.data = b[Odata:];348 ic.data = b[Odata:];
346 return ic;349 return ic;
347}350}
348
349netmkaddr(addr, net, svc: string): string
350{
351 if(net == nil)
352 net = "net";
353 (n, nil) := sys->tokenize(addr, "!");
354 if(n <= 1){
355 if(svc== nil)
356 return sys->sprint("%s!%s", net, addr);
357 return sys->sprint("%s!%s!%s", net, addr, svc);
358 }
359 if(svc == nil || n > 2)
360 return addr;
361 return sys->sprint("%s!%s", addr, svc);
362}
appl/cmd/cddb.b+7−18
@@ -14,6 +14,9 @@ include "bufio.m"; · 13 unmodified lines
14include "string.m";14include "string.m";
15 str: String;15 str: String;
16 16
17include "dial.m";
18 dial: Dial;
19
17include "arg.m";20include "arg.m";
18 21
19Cddb: module22Cddb: module
@@ -66,8 +69,8 @@ dumpcddb(t: ref Toc) · 46 unmodified lines
66 69
67cddbfilltoc(t: ref Toc): int70cddbfilltoc(t: ref Toc): int
68{71{
69 (ok, conn) := sys->dial(netmkaddr(server, "tcp", "888"), nil);72 conn := dial->dial(dial->netmkaddr(server, "tcp", "888"), nil);
70 if(ok < 0) {73 if(conn == nil){
71 sys->fprint(sys->fildes(2), "cddb: cannot dial %s: %r\n", server);74 sys->fprint(sys->fildes(2), "cddb: cannot dial %s: %r\n", server);
72 return -1;75 return -1;
73 }76 }
@@ -149,7 +152,7 @@ cddbfilltoc(t: ref Toc): int · 75 unmodified lines
149DPRINT(2, sys->sprint("cddb %s\n", p));152DPRINT(2, sys->sprint("cddb %s\n", p));
150 if(len p >= 7 && p[0:7] == "DTITLE=")153 if(len p >= 7 && p[0:7] == "DTITLE=")
151 t.title += p[7:];154 t.title += p[7:];
152 else if(len p >= 6 && p[0:6] == "TTITLE"&& isdigit(p[6])) {155 else if(len p >= 7 && p[0:6] == "TTITLE"&& isdigit(p[6])) {
153 i = atoi(p[6:]);156 i = atoi(p[6:]);
154 if(i < t.ntrack) {157 if(i < t.ntrack) {
155 p = p[6:];158 p = p[6:];
@@ -200,6 +203,7 @@ init(nil: ref Draw->Context, args: list of string) · 44 unmodified lines
200 sys = load Sys Sys->PATH;203 sys = load Sys Sys->PATH;
201 bufio = load Bufio Bufio->PATH;204 bufio = load Bufio Bufio->PATH;
202 str = load String String->PATH;205 str = load String String->PATH;
206 dial = load Dial Dial->PATH;
203 207
204 arg := load Arg Arg->PATH;208 arg := load Arg Arg->PATH;
205 arg->init(args);209 arg->init(args);
@@ -237,21 +241,6 @@ init(nil: ref Draw->Context, args: list of string) · 31 unmodified lines
237 dumpcddb(toc);241 dumpcddb(toc);
238}242}
239 243
240netmkaddr(addr, net, svc: string): string
241{
242 if(net == nil)
243 net = "net";
244 (n, nil) := sys->tokenize(addr, "!");
245 if(n <= 1){
246 if(svc== nil)
247 return sys->sprint("%s!%s", net, addr);
248 return sys->sprint("%s!%s!%s", net, addr, svc);
249 }
250 if(svc == nil || n > 2)
251 return addr;
252 return sys->sprint("%s!%s", addr, svc);
253}
254
255atoi(s: string): int244atoi(s: string): int
256{245{
257 return int s;246 return int s;
appl/cmd/import.b+5−18
@@ -4,6 +4,7 @@ include "sys.m"; · 3 unmodified lines
4 sys: Sys;4 sys: Sys;
5 5
6include "draw.m";6include "draw.m";
7include "dial.m";
7include "keyring.m";8include "keyring.m";
8include "security.m";9include "security.m";
9include "factotum.m";10include "factotum.m";
@@ -35,6 +36,7 @@ init(nil: ref Draw->Context, args: list of string) · 25 unmodified lines
35 if(factotum == nil)36 if(factotum == nil)
36 nomod(Factotum->PATH);37 nomod(Factotum->PATH);
37 factotum->init();38 factotum->init();
39 dial := load Dial Dial->PATH;
38 40
39 arg := load Arg Arg->PATH;41 arg := load Arg Arg->PATH;
40 if(arg == nil)42 if(arg == nil)
@@ -80,9 +82,9 @@ init(nil: ref Draw->Context, args: list of string) · 39 unmodified lines
80 if(facfd == nil)82 if(facfd == nil)
81 fail("factotum", sys->sprint("can't open %s: %r", factotumfile));83 fail("factotum", sys->sprint("can't open %s: %r", factotumfile));
82 84
83 dest := netmkaddr(addr, "net", "exportfs");85 dest := dial->netmkaddr(addr, "net", "exportfs");
84 (ok, c) := sys->dial(dest, nil);86 c := dial->dial(dest, nil);
85 if(ok < 0)87 if(c == nil)
86 fail("dial failed", sys->sprint("can't dial %s: %r", dest));88 fail("dial failed", sys->sprint("can't dial %s: %r", dest));
87 ai := factotum->proxy(c.dfd, facfd, "proto=p9any role=client "+keyspec);89 ai := factotum->proxy(c.dfd, facfd, "proto=p9any role=client "+keyspec);
88 if(ai == nil)90 if(ai == nil)
@@ -161,18 +163,3 @@ pushssl(fd: ref Sys->FD, secretin, secretout: array of byte, alg: string): (ref · 72 unmodified lines
161 163
162 return (c.dfd, nil);164 return (c.dfd, nil);
163}165}
164
165netmkaddr(addr, net, svc: string): string
166{
167 if(net == nil)
168 net = "net";
169 (n, nil) := sys->tokenize(addr, "!");
170 if(n <= 1){
171 if(svc== nil)
172 return sys->sprint("%s!%s", net, addr);
173 return sys->sprint("%s!%s!%s", net, addr, svc);
174 }
175 if(svc == nil || n > 2)
176 return addr;
177 return sys->sprint("%s!%s", addr, svc);
178}
appl/cmd/ip/ping.b+7−18
@@ -16,6 +16,9 @@ include "timers.m"; · 15 unmodified lines
16include "rand.m";16include "rand.m";
17 rand: Rand;17 rand: Rand;
18 18
19include "dial.m";
20 dial: Dial;
21
19include "arg.m";22include "arg.m";
20 23
21Ping: module24Ping: module
@@ -74,6 +77,7 @@ init(nil: ref Draw->Context, args: list of string) · 52 unmodified lines
74 sys = load Sys Sys->PATH;77 sys = load Sys Sys->PATH;
75 rand = load Rand Rand->PATH;78 rand = load Rand Rand->PATH;
76 timers = load Timers Timers->PATH;79 timers = load Timers Timers->PATH;
80 dial = load Dial Dial->PATH;
77 ip = load IP IP->PATH;81 ip = load IP IP->PATH;
78 ip->init();82 ip->init();
79 83
@@ -117,9 +121,9 @@ init(nil: ref Draw->Context, args: list of string) · 37 unmodified lines
117 opentime();121 opentime();
118 rand->init(int(nsec()/big 1000));122 rand->init(int(nsec()/big 1000));
119 123
120 addr := netmkaddr(hd args, "icmp", "1");124 addr := dial->netmkaddr(hd args, "icmp", "1");
121 (ok, c) := sys->dial(addr, nil);125 c := dial->dial(addr, nil);
122 if(ok < 0){126 if(c == nil){
123 sys->fprint(sys->fildes(2), "ip/ping: can't dial %s: %r\n", addr);127 sys->fprint(sys->fildes(2), "ip/ping: can't dial %s: %r\n", addr);
124 raise "fail:dial";128 raise "fail:dial";
125 }129 }
@@ -333,21 +337,6 @@ Icmp.unpack(b: array of byte): ref Icmp · 207 unmodified lines
333 return ic;337 return ic;
334}338}
335 339
336netmkaddr(addr, net, svc: string): string
337{
338 if(net == nil)
339 net = "net";
340 (n, l) := sys->tokenize(addr, "!");
341 if(n <= 1){
342 if(svc== nil)
343 return sys->sprint("%s!%s", net, addr);
344 return sys->sprint("%s!%s!%s", net, addr, svc);
345 }
346 if(svc == nil || n > 2)
347 return addr;
348 return sys->sprint("%s!%s", addr, svc);
349}
350
351timefd: ref Sys->FD;340timefd: ref Sys->FD;
352 341
353opentime()342opentime()
appl/cmd/ip/rip.b+8−3
@@ -15,6 +15,10 @@ include "bufio.m"; · 14 unmodified lines
15include "daytime.m";15include "daytime.m";
16 daytime: Daytime;16 daytime: Daytime;
17 17
18include "dial.m";
19 dial: Dial;
20
21
18include "ip.m";22include "ip.m";
19 ip: IP;23 ip: IP;
20 IPaddr, Ifcaddr, Udphdr: import ip;24 IPaddr, Ifcaddr, Udphdr: import ip;
@@ -105,6 +109,7 @@ init(nil: ref Draw->Context, args: list of string) · 84 unmodified lines
105 sys = load Sys Sys->PATH;109 sys = load Sys Sys->PATH;
106 bufio = load Bufio Bufio->PATH;110 bufio = load Bufio Bufio->PATH;
107 daytime = load Daytime Daytime->PATH;111 daytime = load Daytime Daytime->PATH;
112 dial = load Dial Dial->PATH;
108 ip = load IP IP->PATH;113 ip = load IP IP->PATH;
109 ip->init();114 ip->init();
110 115
@@ -420,7 +425,7 @@ sendroutes(ifc: ref Ifcaddr, dst: IPaddr, op: int, changes: int) · 309 unmodified lines
420 buf[o+2] = byte 0;425 buf[o+2] = byte 0;
421 buf[o+3] = byte 0;426 buf[o+3] = byte 0;
422 o += Riphdrlen;427 o += Riphdrlen;
423 rips := buf[IP->Udphdrlen+Riphdrlen:];428# rips := buf[IP->Udphdrlen+Riphdrlen:];
424 if(op == OpRequest){429 if(op == OpRequest){
425 buf[o:] = zeroentry;430 buf[o:] = zeroentry;
426 ip->put4(buf, o+Ometric, HopLimit);431 ip->put4(buf, o+Ometric, HopLimit);
@@ -602,8 +607,8 @@ Gateway.contains(g: self ref Gateway, a: IPaddr): int · 175 unmodified lines
602riplisten(): ref Sys->FD607riplisten(): ref Sys->FD
603{608{
604 addr := sys->sprint("%s/udp!*!rip", netdir);609 addr := sys->sprint("%s/udp!*!rip", netdir);
605 (ok, c) := sys->announce(addr);610 c := dial->announce(addr);
606 if(ok < 0)611 if(c == nil)
607 fatal(sys->sprint("can't announce %s: %r", addr));612 fatal(sys->sprint("can't announce %s: %r", addr));
608 if(sys->fprint(c.cfd, "headers") < 0)613 if(sys->fprint(c.cfd, "headers") < 0)
609 fatal(sys->sprint("can't set udp headers: %r"));614 fatal(sys->sprint("can't set udp headers: %r"));
appl/cmd/lockfs.b+42−51
@@ -16,6 +16,8 @@ include "keyring.m"; · 15 unmodified lines
16 keyring: Keyring;16 keyring: Keyring;
17include "security.m";17include "security.m";
18 auth: Auth;18 auth: Auth;
19include "dial.m";
20 dial: Dial;
19 21
20Lockfs: module {22Lockfs: module {
21 init: fn(nil: ref Draw->Context, argv: list of string);23 init: fn(nil: ref Draw->Context, argv: list of string);
@@ -71,19 +73,12 @@ Uproc: type chan of (ref Ureq, chan of (ref Sys->FD, string)); · 49 unmodified lines
71maxqidpath := big 1;73maxqidpath := big 1;
72locks: list of ref Lockfile;74locks: list of ref Lockfile;
73lockdir: string;75lockdir: string;
74authinfo: ref Keyring->Authinfo;
75timefd: ref Sys->FD;76timefd: ref Sys->FD;
76 77
77MAXCONN: con 20;78MAXCONN: con 20;
78 79
79verbose := 0;80verbose := 0;
80 81
81usage()
82{
83 sys->fprint(stderr, "usage: lockfs [-A] [-a alg]... [-p addr] dir [mountpoint]\n");
84 raise "fail:usage";
85}
86
87badmodule(p: string)82badmodule(p: string)
88{83{
89 sys->fprint(stderr, "lockfs: cannot load %s: %r\n", p);84 sys->fprint(stderr, "lockfs: cannot load %s: %r\n", p);
@@ -105,6 +100,9 @@ init(nil: ref Draw->Context, argv: list of string) · 15 unmodified lines
105 devgen = load Dirgenmod "$self";100 devgen = load Dirgenmod "$self";
106 if (devgen == nil)101 if (devgen == nil)
107 badmodule("self as Dirgenmod");102 badmodule("self as Dirgenmod");
103 dial = load Dial Dial->PATH;
104 if(dial == nil)
105 badmodule(Dial->PATH);
108 timefd = sys->open("/dev/time", sys->OREAD);106 timefd = sys->open("/dev/time", sys->OREAD);
109 if (timefd == nil) {107 if (timefd == nil) {
110 sys->fprint(stderr, "lockfs: cannot open /dev/time: %r\n");108 sys->fprint(stderr, "lockfs: cannot open /dev/time: %r\n");
@@ -114,55 +112,52 @@ init(nil: ref Draw->Context, argv: list of string) · 3 unmodified lines
114 if (arg == nil)112 if (arg == nil)
115 badmodule(Arg->PATH);113 badmodule(Arg->PATH);
116 arg->init(argv);114 arg->init(argv);
115 arg->setusage("lockfs [-A] [-e 'crypt hash'] ... [-k keyspec] [-p addr] dir [mountpoint]");
117 116
118 addr := "";117 addr := "";
119 doauth := 1;118 doauth := 1;
120 algs: list of string;119 algs: list of string;
120 keyspec: string;
121 while ((opt := arg->opt()) != 0) {121 while ((opt := arg->opt()) != 0) {
122 case opt {122 case opt {
123 'p' =>123 'p' =>
124 addr = arg->arg();124 addr = arg->earg();
125 'a' =>125 'k' =>
126 alg := arg->arg();126 addr = arg->earg();
127 if (alg == nil)127 'a' or 'e' =>
128 usage();128 algs = arg->earg() :: algs;
129 algs = alg :: algs;
130 'A' =>129 'A' =>
131 doauth = 0;130 doauth = 0;
132 'v' =>131 'v' =>
133 verbose = 1;132 verbose = 1;
134 * =>133 * =>
135 usage();134 arg->usage();
136 }135 }
137 }136 }
138 argv = arg->argv();137 argv = arg->argv();
139 if (argv == nil || (addr != nil && tl argv != nil))138 if (argv == nil || (addr != nil && tl argv != nil))
140 usage();139 arg->usage();
141 if (addr == nil)140 if (addr == nil)
142 doauth = 0; # no authentication necessary for local mount141 doauth = 0; # no authentication necessary for local mount
143 if (doauth) {142 if (doauth) {
144 auth = load Auth Auth->PATH;143 auth = load Auth Auth->PATH;
145 if (auth == nil)144 if (auth == nil)
146 badmodule(Auth->PATH);145 badmodule(Auth->PATH);
147 if ((e := auth->init()) != nil) {146 auth->init();
148 sys->fprint(stderr, "lockfs: cannot init auth: %s\n", e);
149 raise "fail:errors";
150 }
151 keyring = load Keyring Keyring->PATH;
152 if (keyring == nil)
153 badmodule(Keyring->PATH);
154 authinfo = keyring->readauthinfo("/usr/" + user() + "/keyring/default");
155 }147 }
156 148
157 mountpoint := lockdir = hd argv;149 mountpoint := lockdir = hd argv;
158 if (tl argv != nil)150 if (tl argv != nil)
159 mountpoint = hd tl argv;151 mountpoint = hd tl argv;
160 if (addr != nil) {152 if (addr != nil) {
161 if (doauth && algs == nil)153 if (doauth){
162 algs = "none" :: nil; # XXX is this default a bad idea?154 if(algs == nil)
155 algs = "none" :: nil; # XXX is this default a bad idea?
156 keyspec += " :alg='"+flatten(algs, ' ')+"'";
157 }
163 srvrq := chan of (ref Sys->FD, string, Uproc);158 srvrq := chan of (ref Sys->FD, string, Uproc);
164 srvsync := chan of (int, string);159 srvsync := chan of (int, string);
165 spawn listener(addr, srvrq, srvsync, algs);160 spawn listener(addr, keyspec, srvrq, srvsync, algs);
166 (srvpid, err) := <-srvsync;161 (srvpid, err) := <-srvsync;
167 srvsync = nil;162 srvsync = nil;
168 if (srvpid == -1) {163 if (srvpid == -1) {
@@ -633,28 +628,28 @@ revrqlist(ls: list of ref Openreq) : list of ref Openreq · 464 unmodified lines
633}628}
634 629
635# addr should be, e.g. tcp!*!2345630# addr should be, e.g. tcp!*!2345
636listener(addr: string, ch: chan of (ref Sys->FD, string, Uproc),631listener(addr: string, keyspec: string, ch: chan of (ref Sys->FD, string, Uproc),
637 sync: chan of (int, string), algs: list of string)632 sync: chan of (int, string), algs: list of string)
638{633{
639 addr = netmkaddr(addr, "tcp", "33234");634 addr = dial->netmkaddr(addr, "tcp", "33234");
640 (ok, c) := sys->announce(addr);;635 c := dial->announce(addr);
641 if (ok == -1) {636 if(c == nil) {
642 sync <-= (-1, sys->sprint("cannot anounce on %s: %r", addr));637 sync <-= (-1, sys->sprint("cannot anounce on %s: %r", addr));
643 return;638 return;
644 }639 }
645 sync <-= (sys->pctl(0, nil), nil);640 sync <-= (sys->pctl(0, nil), nil);
646 for (;;) {641 for (;;) {
647 (n, nc) := sys->listen(c);642 nc := dial->listen(c);
648 if (n == -1) {643 if (nc == nil) {
649 ch <-= (nil, sys->sprint("listen failed: %r"), nil);644 ch <-= (nil, sys->sprint("listen failed: %r"), nil);
650 return;645 return;
651 }646 }
652 dfd := sys->open(nc.dir + "/data", Sys->ORDWR);647 dfd := dial->accept(nc);
653 if (dfd != nil) {648 if (dfd != nil) {
654 if (algs == nil)649 if (algs == nil)
655 ch <-= (dfd, nil, nil);650 ch <-= (dfd, nil, nil);
656 else651 else
657 spawn authenticator(dfd, ch, algs);652 spawn authenticator(dfd, keyspec, ch);
658 }653 }
659 }654 }
660}655}
@@ -662,9 +657,9 @@ listener(addr: string, ch: chan of (ref Sys->FD, string, Uproc), · 1 unmodified line
662# authenticate a connection, setting the user id appropriately,657# authenticate a connection, setting the user id appropriately,
663# and then act as a server, performing file operations658# and then act as a server, performing file operations
664# on behalf of the central process.659# on behalf of the central process.
665authenticator(dfd: ref Sys->FD, ch: chan of (ref Sys->FD, string, Uproc), algs: list of string)660authenticator(dfd: ref Sys->FD, keyspec: string, ch: chan of (ref Sys->FD, string, Uproc))
666{661{
667 (fd, err) := auth->server(algs, authinfo, dfd, 1);662 (fd, err) := auth->auth(keyspec, dfd, 1);
668 if (fd == nil) {663 if (fd == nil) {
669 if (verbose)664 if (verbose)
670 sys->fprint(stderr, "lockfs: authentication failed: %s\n", err);665 sys->fprint(stderr, "lockfs: authentication failed: %s\n", err);
@@ -730,21 +725,6 @@ doreq(greq: ref Ureq): (ref Sys->FD, string) · 59 unmodified lines
730 return (fd, err);725 return (fd, err);
731}726}
732 727
733netmkaddr(addr, net, svc: string): string
734{
735 if(net == nil)
736 net = "net";
737 (n, nil) := sys->tokenize(addr, "!");
738 if(n <= 1){
739 if(svc== nil)
740 return sys->sprint("%s!%s", net, addr);
741 return sys->sprint("%s!%s!%s", net, addr, svc);
742 }
743 if(svc == nil || n > 2)
744 return addr;
745 return sys->sprint("%s!%s", addr, svc);
746}
747
748user(): string728user(): string
749{729{
750 fd := sys->open("/dev/user", sys->OREAD);730 fd := sys->open("/dev/user", sys->OREAD);
@@ -771,3 +751,14 @@ now(): int · 20 unmodified lines
771 return 0;751 return 0;
772 return int (big string buf[0:n] / big 1000000);752 return int (big string buf[0:n] / big 1000000);
773}753}
754
755flatten(l: list of string, sep: int): string
756{
757 s := "";
758 for(; l != nil; l = tl l){
759 if(s != "")
760 s[len s] = sep;
761 s += hd l;
762 }
763 return s;
764}
appl/cmd/ndb/dns.b+10−4
@@ -46,6 +46,9 @@ include "keyring.m"; · 45 unmodified lines
46include "security.m";46include "security.m";
47 random: Random;47 random: Random;
48 48
49include "dial.m";
50 dial: Dial;
51
49DNS: module52DNS: module
50{53{
51 init: fn(nil: ref Draw->Context, nil: list of string);54 init: fn(nil: ref Draw->Context, nil: list of string);
@@ -85,6 +88,9 @@ init(nil: ref Draw->Context, args: list of string) · 33 unmodified lines
85 arg := load Arg Arg->PATH;88 arg := load Arg Arg->PATH;
86 if(arg == nil)89 if(arg == nil)
87 cantload(Arg->PATH);90 cantload(Arg->PATH);
91 dial = load Dial Dial->PATH;
92 if(dial == nil)
93 cantload(Dial->PATH);
88 arg->init(args);94 arg->init(args);
89 arg->setusage("dns [-Drh] [-f dnsfile] [-x mntpt]");95 arg->setusage("dns [-Drh] [-f dnsfile] [-x mntpt]");
90 svcname := "#sdns";96 svcname := "#sdns";
@@ -1778,8 +1784,8 @@ kill(pid: int) · 1687 unmodified lines
1778 1784
1779udpport(): ref Sys->FD1785udpport(): ref Sys->FD
1780{1786{
1781 (ok, conn) := sys->announce(mntpt+"/udp!*!0");1787 conn := dial->announce(mntpt+"/udp!*!0");
1782 if(ok < 0)1788 if(conn == nil)
1783 return nil;1789 return nil;
1784 if(sys->fprint(conn.cfd, "headers") < 0){1790 if(sys->fprint(conn.cfd, "headers") < 0){
1785 sys->fprint(stderr, "dns: can't set headers mode: %r\n");1791 sys->fprint(stderr, "dns: can't set headers mode: %r\n");
@@ -1802,8 +1808,8 @@ tcpquery(query: array of byte): (ref DNSmsg, string) · 16 unmodified lines
1802 1808
1803 ipa := query[Udpraddr+IPv4off:];1809 ipa := query[Udpraddr+IPv4off:];
1804 addr := sys->sprint("tcp!%d.%d.%d.%d!%d", int ipa[0], int ipa[1], int ipa[2], int ipa[3], DNSport);1810 addr := sys->sprint("tcp!%d.%d.%d.%d!%d", int ipa[0], int ipa[1], int ipa[2], int ipa[3], DNSport);
1805 (ok, conn) := sys->dial(addr, nil);1811 conn := dial->dial(addr, nil);
1806 if(ok < 0)1812 if(conn == nil)
1807 return (nil, sys->sprint("can't dial %s: %r", addr));1813 return (nil, sys->sprint("can't dial %s: %r", addr));
1808 query = query[Udphdrsize-2:];1814 query = query[Udphdrsize-2:];
1809 put2(query, 0, len query-2); # replace UDP header by message length1815 put2(query, 0, len query-2); # replace UDP header by message length
appl/cmd/styxchat.b+13−24
@@ -20,6 +20,9 @@ include "bufio.m"; · 19 unmodified lines
20 bufio: Bufio;20 bufio: Bufio;
21 Iobuf: import bufio;21 Iobuf: import bufio;
22 22
23include "dial.m";
24 dial: Dial;
25
23include "arg.m";26include "arg.m";
24 27
25Styxchat: module28Styxchat: module
@@ -39,6 +42,7 @@ init(nil: ref Draw->Context, args: list of string) · 13 unmodified lines
39 styx = load Styx Styx->PATH;42 styx = load Styx Styx->PATH;
40 str = load String String->PATH;43 str = load String String->PATH;
41 bufio = load Bufio Bufio->PATH;44 bufio = load Bufio Bufio->PATH;
45 dial = load Dial Dial->PATH;
42 styx->init();46 styx->init();
43 47
44 client := 1;48 client := 1;
@@ -74,21 +78,21 @@ init(nil: ref Draw->Context, args: list of string) · 29 unmodified lines
74 stdin = sys->fildes(0);78 stdin = sys->fildes(0);
75 dest := hd args;79 dest := hd args;
76 if(addr){80 if(addr){
77 dest = netmkaddr(dest, "net", "styx");81 dest = dial->netmkaddr(dest, "net", "styx");
78 if (client){82 if (client){
79 (rc, c) := sys->dial(dest, nil);83 c := dial->dial(dest, nil);
80 if(rc < 0)84 if(c == nil)
81 err(sys->sprint("can't dial %s: %r", dest));85 err(sys->sprint("can't dial %s: %r", dest));
82 fd = c.dfd;86 fd = c.dfd;
83 }else{87 }else{
84 (rlc, lc) := sys->announce(dest);88 lc := dial->announce(dest);
85 if (rlc < 0)89 if(lc == nil)
86 err(sys->sprint("can't announce %s: %r", dest));90 err(sys->sprint("can't announce %s: %r", dest));
87 (rc, c) := sys->listen(lc);91 c := dial->listen(lc);
88 if (rc < 0)92 if(c == nil)
89 err(sys->sprint("can't listen on %s: %r", dest));93 err(sys->sprint("can't listen on %s: %r", dest));
90 fd = sys->open(c.dir + "/data", Sys->ORDWR);94 fd = dial->accept(c);
91 if (fd == nil)95 if(fd == nil)
92 err(sys->sprint("can't open %s/data: %r", c.dir));96 err(sys->sprint("can't open %s/data: %r", c.dir));
93 }97 }
94 }else{98 }else{
@@ -107,21 +111,6 @@ init(nil: ref Draw->Context, args: list of string) · 12 unmodified lines
107 }111 }
108}112}
109 113
110netmkaddr(addr, net, svc: string): string
111{
112 if(net == nil)
113 net = "net";
114 (n, nil) := sys->tokenize(addr, "!");
115 if(n <= 1){
116 if(svc== nil)
117 return sys->sprint("%s!%s", net, addr);
118 return sys->sprint("%s!%s!%s", net, addr, svc);
119 }
120 if(svc == nil || n > 2)
121 return addr;
122 return sys->sprint("%s!%s", addr, svc);
123}
124
125quit(e: int)114quit(e: int)
126{115{
127 fd := sys->open("/prog/"+string sys->pctl(0, nil)+"/ctl", Sys->OWRITE);116 fd := sys->open("/prog/"+string sys->pctl(0, nil)+"/ctl", Sys->OWRITE);
appl/cmd/telnet.b+12−25
@@ -2,11 +2,12 @@ implement Telnet; · 1 unmodified line
2 2
3include "sys.m";3include "sys.m";
4 sys: Sys;4 sys: Sys;
5 Connection: import sys;
6 5
7include "draw.m";6include "draw.m";
8 draw: Draw;7
9 Context: import draw;8include "dial.m";
9 dial: Dial;
10 Connection: import dial;
10 11
11Telnet: module12Telnet: module
12{13{
@@ -34,7 +35,7 @@ BSL: con 21; # ^u backspace line · 21 unmodified lines
34EOT: con 4; # ^d end of file35EOT: con 4; # ^d end of file
35ESC: con 27; # hold mode36ESC: con 27; # hold mode
36 37
37net: Connection;38net: ref Connection;
38stdin, stdout, stderr: ref Sys->FD;39stdin, stdout, stderr: ref Sys->FD;
39 40
40# control characters41# control characters
@@ -99,12 +100,13 @@ usage() · 58 unmodified lines
99 raise "fail:usage";100 raise "fail:usage";
100}101}
101 102
102init(nil: ref Context, argv: list of string)103init(nil: ref Draw->Context, argv: list of string)
103{104{
104 sys = load Sys Sys->PATH;105 sys = load Sys Sys->PATH;
105 stderr = sys->fildes(2);106 stderr = sys->fildes(2);
106 stdout = sys->fildes(1);107 stdout = sys->fildes(1);
107 stdin = sys->fildes(0);108 stdin = sys->fildes(0);
109 dial = load Dial Dial->PATH;
108 110
109 if (len argv < 2)111 if (len argv < 2)
110 usage();112 usage();
@@ -120,11 +122,11 @@ init(nil: ref Context, argv: list of string) · 9 unmodified lines
120ccfd: ref Sys->FD;122ccfd: ref Sys->FD;
121connect(addr: string, port: string)123connect(addr: string, port: string)
122{124{
123 ok: int;125 dest := dial->netmkaddr(addr, "tcp", port);
124 (ok, net) = sys->dial(netmkaddr(addr, "tcp", port), nil);126 net = dial->dial(dest, nil);
125 if(ok < 0) {127 if(net == nil) {
126 sys->fprint(stderr, "telnet: %r\n");128 sys->fprint(stderr, "telnet: can't dial %s: %r\n", dest);
127 return;129 raise "fail:dial";
128 }130 }
129 sys->fprint(stderr, "telnet: connected to %s\n", addr);131 sys->fprint(stderr, "telnet: connected to %s\n", addr);
130 132
@@ -465,18 +467,3 @@ raw(on: int) · 334 unmodified lines
465 else467 else
466 sys->fprint(ccfd, "rawoff");468 sys->fprint(ccfd, "rawoff");
467}469}
468
469netmkaddr(addr, net, svc: string): string
470{
471 if(net == nil)
472 net = "net";
473 (n, nil) := sys->tokenize(addr, "!");
474 if(n <= 1){
475 if(svc== nil)
476 return sys->sprint("%s!%s", net, addr);
477 return sys->sprint("%s!%s!%s", net, addr, svc);
478 }
479 if(svc == nil || n > 2)
480 return addr;
481 return sys->sprint("%s!%s", addr, svc);
482}
appl/cmd/webgrab.b+8−3
@@ -31,6 +31,9 @@ include "daytime.m"; · 30 unmodified lines
31include "bufio.m";31include "bufio.m";
32 B: Bufio;32 B: Bufio;
33 33
34include "dial.m";
35 D: Dial;
36
34include "arg.m";37include "arg.m";
35 38
36Webgrab: module39Webgrab: module
@@ -52,6 +55,7 @@ init(nil: ref Draw->Context, args: list of string) · 15 unmodified lines
52 S = load String String->PATH;55 S = load String String->PATH;
53 U = load Url Url->PATH;56 U = load Url Url->PATH;
54 DT = load Daytime Daytime->PATH;57 DT = load Daytime Daytime->PATH;
58 D = load Dial Dial->PATH;
55 B = load Bufio Bufio->PATH;59 B = load Bufio Bufio->PATH;
56 arg := load Arg Arg->PATH;60 arg := load Arg Arg->PATH;
57 if(S == nil || U == nil || DT == nil || B == nil || arg == nil)61 if(S == nil || U == nil || DT == nil || B == nil || arg == nil)
@@ -381,9 +385,10 @@ httpget(u: ref ParsedUrl) : (string, array of byte, ref Sys->FD, ref ParsedUrl) · 323 unmodified lines
381 dialhost = u.host;385 dialhost = u.host;
382 port = u.port;386 port = u.port;
383 }387 }
384 (ok, net) := sys->dial("tcp!" + dialhost + "!" + port, nil);388 dest := D->netmkaddr(dialhost, "tcp", port);
385 if(ok < 0)389 net := D->dial(dest, nil);
386 return (sys->sprint("can't dial %s: %r", dialhost), nil, nil, nil);390 if(net == nil)
391 return (sys->sprint("can't dial %s: %r", dest), nil, nil, nil);
387 392
388 # prepare request393 # prepare request
389 if(u.query != ""){394 if(u.query != ""){
dis/auxi/mangaload.dis+0−0

Binary file not shown.

dis/cddb.dis+0−0

Binary file not shown.

dis/import.dis+0−0

Binary file not shown.

dis/ip/ping.dis+0−0

Binary file not shown.

dis/ip/rip.dis+0−0

Binary file not shown.

dis/lockfs.dis+0−0

Binary file not shown.

dis/ndb/dns.dis+0−0

Binary file not shown.

dis/styxchat.dis+0−0

Binary file not shown.

dis/telnet.dis+0−0

Binary file not shown.

dis/webgrab.dis+0−0

Binary file not shown.

emu/Linux/emu-g+2−0
@@ -1,3 +1,5 @@
1env
2 X11LIBS=
1dev3dev
2 root4 root
3 cons5 cons
include/version.h+1−1
@@ -1 +1 @@
1#define VERSION "Fourth Edition (20091213)"1#define VERSION "Fourth Edition (20091214)"