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