summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appl/cmd/ip/virgild.b8
-rw-r--r--appl/cmd/listen.b29
-rw-r--r--appl/cmd/mount.b29
-rw-r--r--appl/cmd/rcmd.b26
-rw-r--r--appl/cmd/styxlisten.b34
-rw-r--r--appl/lib/login.b18
-rw-r--r--appl/lib/mpeg.b11
-rw-r--r--appl/lib/newns.b51
-rw-r--r--appl/lib/pop3.b10
-rw-r--r--appl/lib/registries.b7
-rw-r--r--appl/lib/smtp.b10
-rw-r--r--appl/lib/tftp.b8
-rw-r--r--appl/lib/virgil.b11
-rw-r--r--appl/svc/webget/file.b2
-rw-r--r--appl/svc/webget/ftp.b10
-rw-r--r--appl/svc/webget/http.b10
-rw-r--r--appl/svc/webget/webget.b5
-rw-r--r--appl/svc/webget/wgutils.b5
-rw-r--r--appl/svc/webget/wgutils.m3
19 files changed, 154 insertions, 133 deletions
diff --git a/appl/cmd/ip/virgild.b b/appl/cmd/ip/virgild.b
index 5e44476e..79c3b24b 100644
--- a/appl/cmd/ip/virgild.b
+++ b/appl/cmd/ip/virgild.b
@@ -5,6 +5,9 @@ sys: Sys;
include "draw.m";
+include "dial.m";
+dial: Dial;
+
include "ip.m";
Virgild: module
@@ -19,6 +22,7 @@ Udphdrsize: con IP->Udphdrlen;
init(nil: ref Draw->Context, nil: list of string)
{
sys = load Sys Sys->PATH;
+ dial = load Dial Dial->PATH;
stderr = sys->fildes(2);
@@ -66,8 +70,8 @@ init(nil: ref Draw->Context, nil: list of string)
openlisten(): ref Sys->FD
{
- (ok, c) := sys->announce("udp!*!virgil");
- if(ok < 0){
+ c := dial->announce("udp!*!virgil");
+ if(c == nil){
sys->fprint(stderr, "virgild: can't open port: %r\n");
return nil;
}
diff --git a/appl/cmd/listen.b b/appl/cmd/listen.b
index 25869223..61c5ecf9 100644
--- a/appl/cmd/listen.b
+++ b/appl/cmd/listen.b
@@ -7,6 +7,8 @@ include "keyring.m";
keyring: Keyring;
include "security.m";
auth: Auth;
+include "dial.m";
+ dial: Dial;
include "sh.m";
sh: Sh;
Context: import sh;
@@ -31,6 +33,9 @@ init(drawctxt: ref Draw->Context, argv: list of string)
auth = load Auth Auth->PATH;
if (auth == nil)
badmodule(Auth->PATH);
+ dial = load Dial Dial->PATH;
+ if (dial == nil)
+ badmodule(Dial->PATH);
sh = load Sh Sh->PATH;
if (sh == nil)
badmodule(Sh->PATH);
@@ -120,8 +125,8 @@ listen1(drawctxt: ref Draw->Context, addr: string, argv: list of string,
sys->pctl(Sys->FORKFD, nil);
ctxt := Context.new(drawctxt);
- (ok, acon) := sys->announce(addr);
- if (ok == -1) {
+ acon := dial->announce(addr);
+ if (acon == nil) {
sys->fprint(stderr(), "listen: failed to announce on '%s': %r\n", addr);
sync <-= "cannot announce";
exit;
@@ -146,12 +151,12 @@ listen1(drawctxt: ref Draw->Context, addr: string, argv: list of string,
}
sync <-= nil;
- listench := chan of (int, Sys->Connection);
- authch := chan of (string, Sys->Connection);
+ listench := chan of (int, ref Sys->Connection);
+ authch := chan of (string, ref Sys->Connection);
spawn listener(listench, acon, addr);
for (;;) {
user := "";
- ccon: Sys->Connection;
+ ccon: ref Sys->Connection;
alt {
(lok, c) := <-listench =>
if (lok == -1){
@@ -182,11 +187,11 @@ listen1(drawctxt: ref Draw->Context, addr: string, argv: list of string,
}
}
-listener(listench: chan of (int, Sys->Connection), c: Sys->Connection, addr: string)
+listener(listench: chan of (int, ref Sys->Connection), c: ref Sys->Connection, addr: string)
{
for (;;) {
- (ok, nc) := sys->listen(c);
- if (ok == -1) {
+ nc := dial->listen(c);
+ if (nc == nil) {
sys->fprint(stderr(), "listen: listen error on '%s': %r\n", addr);
listench <-= (-1, nc);
exit;
@@ -194,19 +199,19 @@ listener(listench: chan of (int, Sys->Connection), c: Sys->Connection, addr: str
if (verbose)
sys->fprint(stderr(), "listen: got connection on %s from %s",
addr, readfile(nc.dir + "/remote"));
- nc.dfd = sys->open(nc.dir + "/data", Sys->ORDWR);
+ nc.dfd = dial->accept(nc);
if (nc.dfd == nil)
sys->fprint(stderr(), "listen: cannot open %s: %r\n", nc.dir + "/data");
else{
if(nc.cfd != nil)
sys->fprint(nc.cfd, "keepalive");
- listench <-= (ok, nc);
+ listench <-= (0, nc);
}
}
}
-authenticator(authch: chan of (string, Sys->Connection),
- c: Sys->Connection, algs: list of string, addr: string)
+authenticator(authch: chan of (string, ref Sys->Connection),
+ c: ref Sys->Connection, algs: list of string, addr: string)
{
err: string;
(c.dfd, err) = auth->server(algs, serverkey, c.dfd, 0);
diff --git a/appl/cmd/mount.b b/appl/cmd/mount.b
index 5bf4fe7b..9cac7da5 100644
--- a/appl/cmd/mount.b
+++ b/appl/cmd/mount.b
@@ -5,6 +5,8 @@ include "sys.m";
include "draw.m";
include "keyring.m";
include "security.m";
+include "dial.m";
+ dial: Dial;
include "factotum.m";
include "styxconv.m";
include "styxpersist.m";
@@ -140,7 +142,7 @@ connect(ctxt: ref Draw->Context, dest: string): ref Sys->FD
svc := "styx";
if(do9)
svc = "9fs";
- dest = netmkaddr(dest, "net", svc);
+ dest = dial->netmkaddr(dest, "net", svc);
if(persist){
styxpersist := load Styxpersist Styxpersist->PATH;
if(styxpersist == nil)
@@ -152,8 +154,8 @@ connect(ctxt: ref Draw->Context, dest: string): ref Sys->FD
spawn dialler(c, dest);
return p[1];
}
- (ok, c) := sys->dial(dest, nil);
- if(ok < 0)
+ c := dial->dial(dest, nil);
+ if(c == nil)
fail("dial failed", sys->sprint("can't dial %s: %r", dest));
return c.dfd;
}
@@ -163,8 +165,8 @@ dialler(dialc: chan of chan of ref Sys->FD, dest: string)
while((reply := <-dialc) != nil){
if(verbose)
sys->print("dialling %s\n", addr);
- (ok, c) := sys->dial(dest, nil);
- if(ok == -1){
+ c := dial->dial(dest, nil);
+ if(c == nil){
reply <-= nil;
continue;
}
@@ -237,7 +239,7 @@ authenticate(keyfile, alg: string, dfd: ref Sys->FD, addr: string): (ref Sys->FD
kd := "/usr/" + user() + "/keyring/";
if(keyfile == nil) {
- cert = kd + netmkaddr(addr, "tcp", "");
+ cert = kd + dial->netmkaddr(addr, "tcp", "");
(ok, nil) := sys->stat(cert);
if (ok < 0)
cert = kd + "default";
@@ -279,21 +281,6 @@ user(): string
return string buf[0:n];
}
-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);
-}
-
kill(pid: int)
{
if ((fd := sys->open("#p/" + string pid + "/ctl", Sys->OWRITE)) != nil)
diff --git a/appl/cmd/rcmd.b b/appl/cmd/rcmd.b
index 8815f9b7..5062c708 100644
--- a/appl/cmd/rcmd.b
+++ b/appl/cmd/rcmd.b
@@ -4,6 +4,7 @@ include "sys.m";
include "draw.m";
include "arg.m";
include "keyring.m";
+include "dial.m";
include "security.m";
Rcmd: module
@@ -14,10 +15,14 @@ Rcmd: module
DEFAULTALG := "none";
sys: Sys;
auth: Auth;
+dial: Dial;
init(nil: ref Draw->Context, argv: list of string)
{
sys = load Sys Sys->PATH;
+ dial = load Dial Dial->PATH;
+ if(dial == nil)
+ badmodule(Dial->PATH);
arg := load Arg Arg->PATH;
if(arg == nil)
badmodule(Arg->PATH);
@@ -78,9 +83,9 @@ init(nil: ref Draw->Context, argv: list of string)
keyfile = "/usr/" + user() + "/keyring/default";
}
- (ok, c) := sys->dial(netmkaddr(addr, "tcp", "rstyx"), nil);
- if(ok < 0)
- error(sys->sprint("dial server failed: %r"));
+ c := dial->dial(dial->netmkaddr(addr, "tcp", "rstyx"), nil);
+ if(c == nil)
+ error(sys->sprint("dial %s failed: %r", addr));
fd := c.dfd;
if (doauth) {
@@ -137,21 +142,6 @@ user(): string
return string buf[0:n];
}
-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);
-}
-
stderr(): ref Sys->FD
{
return sys->fildes(2);
diff --git a/appl/cmd/styxlisten.b b/appl/cmd/styxlisten.b
index df136e47..ae9f7b45 100644
--- a/appl/cmd/styxlisten.b
+++ b/appl/cmd/styxlisten.b
@@ -6,6 +6,8 @@ include "keyring.m";
keyring: Keyring;
include "security.m";
auth: Auth;
+include "dial.m";
+ dial: Dial;
include "arg.m";
include "sh.m";
@@ -28,6 +30,9 @@ init(ctxt: ref Draw->Context, argv: list of string)
auth = load Auth Auth->PATH;
if (auth == nil)
badmodule(Auth->PATH);
+ dial = load Dial Dial->PATH;
+ if (dial == nil)
+ badmodule(Dial->PATH);
if ((e := auth->init()) != nil)
error("auth init failed: " + e);
keyring = load Keyring Keyring->PATH;
@@ -76,7 +81,7 @@ init(ctxt: ref Draw->Context, argv: list of string)
arg = nil;
if (doauth && algs == nil)
algs = getalgs();
- addr := netmkaddr(hd argv, "tcp", "styx");
+ addr := dial->netmkaddr(hd argv, "tcp", "styx");
cmd := tl argv;
authinfo: ref Keyring->Authinfo;
@@ -88,8 +93,8 @@ init(ctxt: ref Draw->Context, argv: list of string)
error(sys->sprint("cannot read %s: %r", keyfile));
}
- (ok, c) := sys->announce(addr);
- if (ok == -1)
+ c := dial->announce(addr);
+ if (c == nil)
error(sys->sprint("cannot announce on %s: %r", addr));
if(!trusted){
sys->unmount(nil, "/mnt/keys"); # should do for now
@@ -103,17 +108,17 @@ init(ctxt: ref Draw->Context, argv: list of string)
spawn listener(c, popen(ctxt, cmd, lsync), authinfo, algs, lsync);
}
-listener(c: Sys->Connection, mfd: ref Sys->FD, authinfo: ref Keyring->Authinfo, algs: list of string, lsync: chan of int)
+listener(c: ref Sys->Connection, mfd: ref Sys->FD, authinfo: ref Keyring->Authinfo, algs: list of string, lsync: chan of int)
{
lsync <-= sys->pctl(0, nil);
for (;;) {
- (n, nc) := sys->listen(c);
- if (n == -1)
+ nc := dial->listen(c);
+ if (nc == nil)
error(sys->sprint("listen failed: %r"));
if (verbose)
sys->fprint(stderr(), "styxlisten: got connection from %s",
readfile(nc.dir + "/remote"));
- dfd := sys->open(nc.dir + "/data", Sys->ORDWR);
+ dfd := dial->accept(nc);
if (dfd != nil) {
if(nc.cfd != nil)
sys->fprint(nc.cfd, "keepalive");
@@ -245,18 +250,3 @@ stderr(): ref Sys->FD
{
return sys->fildes(2);
}
-
-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);
-}
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;
diff --git a/appl/svc/webget/file.b b/appl/svc/webget/file.b
index 49c51423..f9c7cde9 100644
--- a/appl/svc/webget/file.b
+++ b/appl/svc/webget/file.b
@@ -20,6 +20,8 @@ include "url.m";
U: Url;
ParsedUrl: import U;
+include "dial.m";
+
include "webget.m";
include "wgutils.m";
diff --git a/appl/svc/webget/ftp.b b/appl/svc/webget/ftp.b
index 9162fcb7..d5030bc9 100644
--- a/appl/svc/webget/ftp.b
+++ b/appl/svc/webget/ftp.b
@@ -22,6 +22,9 @@ include "url.m";
include "webget.m";
+include "dial.m";
+ DI: Dial;
+
include "wgutils.m";
W: WebgetUtils;
Fid, Req: import WebgetUtils;
@@ -42,6 +45,7 @@ init(w: WebgetUtils)
S = W->S;
B = W->B;
U = W->U;
+ DI = W->DI;
}
connect(c: ref Fid, r: ref Req, donec: chan of ref Fid)
@@ -53,13 +57,13 @@ connect(c: ref Fid, r: ref Req, donec: chan of ref Fid)
port := u.port;
if(port == "")
port = FTPPORT;
- addr := "tcp!" + u.host + "!" + port;
+ addr := DI->netmkaddr(u.host, "tcp", port);
dummyloop: # just for breaking out of on error
for(;;) {
W->log(c, sys->sprint("ftp: dialing %s", addr));
- (ok, net) := sys->dial(addr, nil);
- if(ok < 0) {
+ net := DI->dial(addr, nil);
+ if(net == nil) {
err = sys->sprint("dial error: %r");
break dummyloop;
}
diff --git a/appl/svc/webget/http.b b/appl/svc/webget/http.b
index 0a4645ed..348084cf 100644
--- a/appl/svc/webget/http.b
+++ b/appl/svc/webget/http.b
@@ -23,6 +23,9 @@ include "url.m";
U: Url;
ParsedUrl: import U;
+include "dial.m";
+ DI: Dial;
+
include "webget.m";
include "wgutils.m";
@@ -122,6 +125,7 @@ init(w: WebgetUtils)
S = W->S;
B = W->B;
U = W->U;
+ DI = W->DI;
ssl3 = nil; # load on demand
readconfig();
}
@@ -232,11 +236,11 @@ connect(c: ref Fid, r: ref Req, donec: chan of ref Fid)
else
port = HTTPD;
}
- addr := "tcp!" + dialu.host + "!" + port;
+ addr := DI->netmkaddr(dialu.host, "tcp", port);
W->log(c, sys->sprint("http: dialing %s", addr));
- (ok, net) := sys->dial(addr, nil);
- if(ok < 0) {
+ net := DI->dial(addr, nil);
+ if(net == nil) {
mrep = W->usererr(r, sys->sprint("%r"));
break redirloop;
}
diff --git a/appl/svc/webget/webget.b b/appl/svc/webget/webget.b
index c3c3aed8..8ae415a3 100644
--- a/appl/svc/webget/webget.b
+++ b/appl/svc/webget/webget.b
@@ -48,6 +48,9 @@ include "string.m";
include "bufio.m";
B: Bufio;
+include "dial.m";
+ DI: Dial;
+
include "message.m";
M: Message;
Msg: import M;
@@ -158,7 +161,7 @@ start(ctl: chan of int)
ctl <-= 0;
return;
}
- W->init(M, S, B, U, log);
+ W->init(M, S, B, U, DI, log);
loadtransmod();
diff --git a/appl/svc/webget/wgutils.b b/appl/svc/webget/wgutils.b
index 2094f7a3..720edebe 100644
--- a/appl/svc/webget/wgutils.b
+++ b/appl/svc/webget/wgutils.b
@@ -9,6 +9,8 @@ include "string.m";
include "bufio.m";
+include "dial.m";
+
include "imagefile.m";
readgif, readjpg, readxbitmap: RImagefile;
@@ -98,7 +100,7 @@ mnames := array[] of {
"text/xml"
};
-init(m: Message, s: String, b: Bufio, u: Url, lfd: ref Sys->FD)
+init(m: Message, s: String, b: Bufio, u: Url, di: Dial, lfd: ref Sys->FD)
{
sys = load Sys Sys->PATH;
@@ -106,6 +108,7 @@ init(m: Message, s: String, b: Bufio, u: Url, lfd: ref Sys->FD)
S = s;
B = b;
U = u;
+ DI = di;
logfd = lfd;
T = load StringIntTab StringIntTab->PATH;
readgif = load RImagefile RImagefile->READGIFPATH;
diff --git a/appl/svc/webget/wgutils.m b/appl/svc/webget/wgutils.m
index 8efb14c1..36a5bdb6 100644
--- a/appl/svc/webget/wgutils.m
+++ b/appl/svc/webget/wgutils.m
@@ -33,6 +33,7 @@ WebgetUtils: module
B: Bufio;
S: String;
U: Url;
+ DI: Dial;
# media types (must track mnames array in wgutils.b)
UnknownType,
@@ -43,7 +44,7 @@ WebgetUtils: module
AudioBasic,
VideoMpeg, VideoQuicktime, Soap, TextXml: con iota;
- init : fn(m: Message, s: String, b: Bufio, u: Url, logfd: ref Sys->FD);
+ init : fn(m: Message, s: String, b: Bufio, u: Url, di: Dial, logfd: ref Sys->FD);
usererr: fn(r: ref Req, msg: string) : ref Message->Msg;
okprefix: fn(r: ref Req, mrep: ref Message->Msg);
getdata: fn(io: ref Bufio->Iobuf, m: ref Message->Msg,