diff options
| author | Charles Forsyth <charles.forsyth@gmail.com> | 2015-04-29 17:44:33 +0100 |
|---|---|---|
| committer | Charles Forsyth <charles.forsyth@gmail.com> | 2015-04-29 17:44:33 +0100 |
| commit | fbc1184c08d18d5ac0f8763a058e015e95353341 (patch) | |
| tree | f045cdfaaf13c35295d34cb0c2ffd7f4cf2ef30d /appl/lib | |
| parent | 83eae27259078c96c074211a51bf38c774490544 (diff) | |
switch to Dial module
Diffstat (limited to 'appl/lib')
| -rw-r--r-- | appl/lib/login.b | 18 | ||||
| -rw-r--r-- | appl/lib/mpeg.b | 11 | ||||
| -rw-r--r-- | appl/lib/newns.b | 51 | ||||
| -rw-r--r-- | appl/lib/pop3.b | 10 | ||||
| -rw-r--r-- | appl/lib/registries.b | 7 | ||||
| -rw-r--r-- | appl/lib/smtp.b | 10 | ||||
| -rw-r--r-- | appl/lib/tftp.b | 8 | ||||
| -rw-r--r-- | appl/lib/virgil.b | 11 |
8 files changed, 77 insertions, 49 deletions
diff --git a/appl/lib/login.b b/appl/lib/login.b index 2feb3f6a..6a7dee1a 100644 --- a/appl/lib/login.b +++ b/appl/lib/login.b @@ -17,6 +17,8 @@ include "keyring.m"; include "security.m"; +include "dial.m"; + include "string.m"; # see login(6) @@ -35,16 +37,16 @@ login(id, password, dest: string): (string, ref Keyring->Authinfo) if(rand == nil) return nomod(Random->PATH); + dial := load Dial Dial->PATH; + if(dial == nil) + return nomod(Dial->PATH); + if(dest == nil) dest = "$SIGNER"; - for(j:=0; j<len dest && dest[j] != '!'; j++) - break; - if(j >= len dest) - dest = "net!"+dest+"!inflogin"; # BUG: must do better - - (ok, lc) := sys->dial(dest, nil); - if(ok < 0) - return (sys->sprint("can't contact login service: %r"), nil); + dest = dial->netmkaddr(dest, "net", "inflogin"); + lc := dial->dial(dest, nil); + if(lc == nil) + return (sys->sprint("can't contact login service: %s: %r", dest), nil); # push ssl, leave in clear mode for now (err, c) := ssl->connect(lc.dfd); diff --git a/appl/lib/mpeg.b b/appl/lib/mpeg.b index f1cd00f0..100a8708 100644 --- a/appl/lib/mpeg.b +++ b/appl/lib/mpeg.b @@ -6,6 +6,8 @@ FD, Connection: import Sys; include "draw.m"; draw: Draw; Display, Rect, Image: import draw; +include "dial.m"; +dial: Dial; include "mpeg.m"; Chroma: con 16r05; @@ -17,12 +19,13 @@ getenv() sys = load Sys Sys->PATH; draw = load Draw Draw->PATH; + dial = load Dial Dial->PATH; } copy(files: list of string, notify: chan of string, mpctl, mpdata: ref FD) { - ok, n: int; - c: Connection; + n: int; + c: ref Connection; name: list of string; while(files != nil) { @@ -37,8 +40,8 @@ copy(files: list of string, notify: chan of string, mpctl, mpdata: ref FD) return; } 2 => - (ok, c) = sys->dial(hd tl name, nil); - if(ok < 0) { + c = dial->dial(hd tl name, nil); + if(c == nil) { notify <-= "dial:" + hd tl name; return; } diff --git a/appl/lib/newns.b b/appl/lib/newns.b index 2dc7025d..534621a8 100644 --- a/appl/lib/newns.b +++ b/appl/lib/newns.b @@ -24,6 +24,9 @@ include "bufio.m"; bio: Bufio; Iobuf: import bio; +include "dial.m"; + dial: Dial; + include "newns.m"; #include "sh.m"; @@ -254,16 +257,22 @@ mount(argv: list of string, facfd: ref Sys->FD): string if(len r.argv < 2) return ig(r, "mount: too few args"); + if(dial == nil){ + dial = load Dial Dial->PATH; + if(dial == nil) + return ig(r, "mount: can't load Dial"); + } + addr := hd r.argv; r.argv = tl r.argv; - dest := netmkaddr(addr, "net", "styx"); + dest := dial->netmkaddr(addr, "net", "styx"); dir := hd r.argv; r.argv = tl r.argv; if(r.argv != nil) spec := hd r.argv; - (ok, c) := sys->dial(dest, nil); - if(ok < 0) + c := dial->dial(dest, nil); + if(c == nil) return ig(r, sys->sprint("dial: %s: %r", dest)); if(r.use9){ @@ -286,16 +295,12 @@ mount(argv: list of string, facfd: ref Sys->FD): string cert = r.keyfile; if (cert[0] != '/') cert = kd + cert; - (ok, nil) = sys->stat(cert); - if (ok<0) + if(sys->stat(cert).t0 < 0) return ig(r, sys->sprint("cannot find certificate %q: %r", cert)); } else { cert = kd + addr; - (ok, nil) = sys->stat(cert); - if(ok < 0){ + if(sys->stat(cert).t0 < 0) cert = kd + "default"; - (ok, nil) = sys->stat(cert); - } } ai := kr->readauthinfo(cert); if(ai == nil) @@ -335,9 +340,16 @@ import9(argv: list of string, facfd: ref Sys->FD): string dir := rdir; if(r.argv != nil) dir = hd r.argv; - dest := netmkaddr(addr, "net", "17007"); # exportfs; might not be in inferno's ndb yet - (ok, c) := sys->dial(dest, nil); - if(ok < 0) + + if(dial == nil){ + dial = load Dial Dial->PATH; + if(dial == nil) + return ig(r, "import: can't load Dial"); + } + + dest := dial->netmkaddr(addr, "net", "17007"); # exportfs; might not be in inferno's ndb yet + c := dial->dial(dest, nil); + if(c == nil) return ig(r, sys->sprint("import: %s: %r", dest)); fd := c.dfd; if(factotum->proxy(fd, facfd, "proto=p9any role=client") == nil) @@ -428,21 +440,6 @@ setenv(name: string, val: string) sys->fprint(fd, "%s", val); } -netmkaddr(addr, net, svc: string): string -{ - if(net == nil) - net = "net"; - (n, nil) := sys->tokenize(addr, "!"); - if(n <= 1){ - if(svc== nil) - return sys->sprint("%s!%s", net, addr); - return sys->sprint("%s!%s!%s", net, addr, svc); - } - if(svc == nil || n > 2) - return addr; - return sys->sprint("%s!%s", addr, svc); -} - newuser(user: string, cap: string, nsfile: string): string { if(cap == nil) diff --git a/appl/lib/pop3.b b/appl/lib/pop3.b index 4081b279..ce297004 100644 --- a/appl/lib/pop3.b +++ b/appl/lib/pop3.b @@ -5,6 +5,8 @@ include "sys.m"; include "draw.m"; include "bufio.m"; bufio : Bufio; +include "dial.m"; + dial: Dial; include "pop3.m"; FD, Connection: import sys; @@ -26,14 +28,17 @@ open(user, password, server : string): (int, string) if (!inited) { sys = load Sys Sys->PATH; bufio = load Bufio Bufio->PATH; + dial = load Dial Dial->PATH; inited = 1; } if (conn) return (-1, "connection is already open"); if (server == nil) server = "$pop3"; - (ok, c) := sys->dial ("net!" + server + "!110", nil); - if (ok < 0) + else + server = dial->netmkaddr(server, "net", "110"); + c := dial->dial(server, nil); + if (c == nil) return (-1, "dialup failed"); ibuf = bufio->fopen(c.dfd, Bufio->OREAD); obuf = bufio->fopen(c.dfd, Bufio->OWRITE); @@ -42,6 +47,7 @@ open(user, password, server : string): (int, string) cread = chan of (int, string); spawn mreader(cread); (rpid, nil) = <- cread; + ok: int; (ok, s) = mread(); if (ok < 0) return (-1, s); diff --git a/appl/lib/registries.b b/appl/lib/registries.b index 2feb83e3..34c2c5d0 100644 --- a/appl/lib/registries.b +++ b/appl/lib/registries.b @@ -9,6 +9,8 @@ include "string.m"; str: String; include "keyring.m"; keyring: Keyring; +include "dial.m"; + dial: Dial; include "security.m"; auth: Auth; include "keyset.m"; @@ -22,6 +24,7 @@ init() keyring = checkload(load Keyring Keyring->PATH, Keyring->PATH); str = checkload(load String String->PATH, String->PATH); keyset = checkload(load Keyset Keyset->PATH, Keyset->PATH); + dial = checkload(load Dial Dial->PATH, Dial->PATH); auth = checkload(load Auth Auth->PATH, Auth->PATH); e := keyset->init(); if(e != nil) @@ -208,8 +211,8 @@ Service.attach(svc: self ref Service, localuser, keydir: string): ref Attached # auth.crypt type of encryption to push (as accepted by ssl(3)'s "alg" operation) # auth.signer hash of service's certificate's signer's public key - (ok, c) := sys->dial(svc.addr, nil); - if(ok == -1){ + c := dial->dial(svc.addr, nil); + if(c == nil){ sys->werrstr(sys->sprint("cannot dial: %r")); return nil; } diff --git a/appl/lib/smtp.b b/appl/lib/smtp.b index a1d92b8e..8e118a31 100644 --- a/appl/lib/smtp.b +++ b/appl/lib/smtp.b @@ -4,6 +4,8 @@ include "sys.m"; sys : Sys; include "bufio.m"; bufio : Bufio; +include "dial.m"; + dial: Dial; include "smtp.m"; FD, Connection: import sys; @@ -25,14 +27,17 @@ open(server : string): (int, string) if (!init) { sys = load Sys Sys->PATH; bufio = load Bufio Bufio->PATH; + dial = load Dial Dial->PATH; init = 1; } if (conn) return (-1, "connection is already open"); if (server == nil) server = "$smtp"; - (ok, c) := sys->dial ("tcp!" + server + "!25", nil); - if (ok < 0) + else + server = dial->netmkaddr(server, "tcp", "25"); + c := dial->dial(server, nil); + if (c == nil) return (-1, "dialup failed"); ibuf = bufio->fopen(c.dfd, Bufio->OREAD); obuf = bufio->fopen(c.dfd, Bufio->OWRITE); @@ -41,6 +46,7 @@ open(server : string): (int, string) cread = chan of (int, string); spawn mreader(cread); (rpid, nil) = <- cread; + ok: int; (ok, s) = mread(); if (ok < 0) return (-1, s); diff --git a/appl/lib/tftp.b b/appl/lib/tftp.b index f112b892..29d6e7cd 100644 --- a/appl/lib/tftp.b +++ b/appl/lib/tftp.b @@ -3,6 +3,9 @@ implement Tftp; include "sys.m"; sys: Sys; +include "dial.m"; + dial: Dial; + include "tftp.m"; Maxretry: con 5; # retries per block @@ -62,6 +65,7 @@ timeoutstart(howlong: int): chan of int init(p: int) { sys = load Sys Sys->PATH; + dial = load Dial Dial->PATH; progress = p; } @@ -80,8 +84,8 @@ receive(host: string, filename: string, fd: ref Sys->FD): string { rbuf: array of byte; - (ok, conn) := sys->dial("udp!" + host + "!69", nil); - if(ok < 0) + conn := dial->dial(dial->netmkaddr(host, "udp", "69"), nil); + if(conn == nil) return sys->sprint("can't dial %s: %r", host); buf := array[Tftphdrlen + Maxblock] of byte; i := 0; diff --git a/appl/lib/virgil.b b/appl/lib/virgil.b index c4945716..03352e20 100644 --- a/appl/lib/virgil.b +++ b/appl/lib/virgil.b @@ -5,6 +5,8 @@ include "sys.m"; include "string.m"; include "keyring.m"; include "draw.m"; +include "dial.m"; + dial: Dial; include "security.m"; include "ip.m"; ip: IP; @@ -29,6 +31,11 @@ virgil(argv: list of string): string return nil; done = 0; sys = load Sys Sys->PATH; + dial = load Dial Dial->PATH; + if(dial == nil){ + cantload(Dial->PATH); + return nil; + } str := load String String->PATH; if(str == nil){ cantload(String->PATH); @@ -70,8 +77,8 @@ virgil(argv: list of string): string return nil; question = hd argv; - (ok, c) := sys->announce("udp!*!0"); - if(ok < 0) + c := dial->announce("udp!*!0"); + if(c == nil) return nil; if(sys->fprint(c.cfd, "headers") < 0) return nil; |
