commit 7b42187b760c00d61d638b1983bd8806bff145f3
parent f1403e4335ed6f975ab98811715b23c205a422c9
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 15 Jul 2023 12:38:53 +0900
add tAuth
Diffstat:
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/fcall.go b/fcall.go
@@ -188,7 +188,35 @@ func (msg RVersion) String() string {
}
type TAuth []byte
+func (msg TAuth) Size() uint32 { return gbit32(msg[0:4]) }
+func (msg TAuth) Type() MsgType { return MsgType(msg[4]) }
+func (msg TAuth) Tag() uint16 { return gbit16(msg[5:7]) }
+func (msg TAuth) AFid() uint32 { return gbit32(msg[7:11]) }
+func (msg TAuth) UName() string {
+ size := gbit16(msg[11:13])
+ return string(msg[13:13+size])
+}
+func (msg TAuth) AName() string {
+ usize := gbit16(msg[11:13])
+ asize := gbit16(msg[13+usize:13+usize+2])
+ return string(msg[13+usize+2:13+usize+2+asize])
+}
+func (msg TAuth) conv2M() []byte { return []byte(msg)[:msg.Size()] }
+func (msg TAuth) String() string {
+ return fmt.Sprintf("Tauth tag %d afid %d uname %s aname %s",
+ msg.Tag(), msg.AFid(), msg.UName(), msg.AName())
+}
+
type RAuth []byte
+func (msg RAuth) Size() uint32 { return gbit32(msg[0:4]) }
+func (msg RAuth) Type() MsgType { return MsgType(msg[4]) }
+func (msg RAuth) Tag() uint16 { return gbit16(msg[5:7]) }
+func (msg RAuth) AQid() Qid { return Qid(msg[7:20]) }
+func (msg RAuth) conv2M() []byte { return []byte(msg)[:msg.Size()] }
+func (msg RAuth) String() string {
+ return fmt.Sprintf("Tauth tag %d aqid %v",
+ msg.Tag(), msg.AQid())
+}
type TAttach []byte
diff --git a/server.go b/server.go
@@ -40,6 +40,8 @@ func getReq(s *Srv) (*Req, error) {
r.ifcall = TVersion(buf)
case Tattach:
r.ifcall = TAttach(buf)
+ case Tauth:
+ r.ifcall = TAuth(buf)
}
r.srv = s
if chatty9P {
@@ -80,6 +82,16 @@ func sVersion(s *Srv, r *Req) {
func rVersion(r *Req, err error) {}
+func sAuth(s *Srv, r *Req) {
+ respond(r, fmt.Errorf("authentication not implemented"))
+}
+
+func rAuth(r *Req, err error) {}
+
+func sAttach(s *Srv, r *Req) {
+
+}
+
func rError(r *Req, err error) {
size := uint32(4 + 1 + 2 + 2 + len(err.Error()))
ofcall := RError(make([]byte, size))
@@ -88,7 +100,6 @@ func rError(r *Req, err error) {
ofcall.SetType(Rerror)
ofcall.SetTag(r.ifcall.Tag())
ofcall.SetEName(err)
-
r.ofcall = ofcall
}
@@ -99,11 +110,13 @@ func Serve(s *Srv) {
log.Printf("get req: %v\n", err)
break
}
- switch r.ifcall.Type() {
+ switch r.ifcall.(type) {
default:
respond(r, fmt.Errorf("unknown message type: %d", r.ifcall.Type()))
- case Tversion:
+ case TVersion:
sVersion(s, r)
+ case TAuth:
+ sAuth(s, r)
}
}
}
@@ -114,10 +127,11 @@ func respond(r *Req, err error) {
} else {
switch ofcall := r.ofcall.(type) {
default:
- // TODO: Respond with Rerror.
rError(r, fmt.Errorf("unknown message type: %s", ofcall.Type()))
case RVersion:
rVersion(r, err)
+ case RAuth:
+ rAuth(r, err)
}
}