summaryrefslogtreecommitdiff
path: root/src/nslcd_proto
diff options
context:
space:
mode:
Diffstat (limited to 'src/nslcd_proto')
-rw-r--r--src/nslcd_proto/.gitignore2
-rw-r--r--src/nslcd_proto/Makefile12
-rw-r--r--src/nslcd_proto/enumerator@T.got8
-rwxr-xr-xsrc/nslcd_proto/func_handlerequest.go.sh25
-rwxr-xr-xsrc/nslcd_proto/interface_backend.go.sh4
-rw-r--r--src/nslcd_proto/util/enumerator@T.got45
-rwxr-xr-xsrc/nslcd_proto/util/struct_null_backend.go.sh2
7 files changed, 16 insertions, 82 deletions
diff --git a/src/nslcd_proto/.gitignore b/src/nslcd_proto/.gitignore
index 86bd764..0915898 100644
--- a/src/nslcd_proto/.gitignore
+++ b/src/nslcd_proto/.gitignore
@@ -3,5 +3,3 @@
/func_handlerequest.go
/requests.txt
/responses.txt
-/enumerator-list.mk
-*@*.go
diff --git a/src/nslcd_proto/Makefile b/src/nslcd_proto/Makefile
index 52e58f5..9e3ba4e 100644
--- a/src/nslcd_proto/Makefile
+++ b/src/nslcd_proto/Makefile
@@ -2,7 +2,7 @@ _ := $(MAKEFILE_LIST)
d := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
generate := $(generate) $d/interface_backend.go $d/func_handlerequest.go $d/util/struct_null_backend.go
-secondary := $(secondary) $d/enumerator-list.mk $d/requests.txt $d/responses.txt $d/*@*.go $d/util/*@*.go
+secondary := $d/requests.txt
ifeq (,$(filter clean,$(MAKECMDGOALS)))
-include $d/enumerator-list.mk
@@ -25,18 +25,8 @@ clean:
endif
-$d/enumerator@%.go: $d/enumerator@T.got
- < $< sed 's/<T>/$*/g' > $@
-$d/util/enumerator@%.go: $d/util/enumerator@T.got
- < $< sed 's/<T>/$*/g' > $@
-
-$d/enumerator-list.mk: $d/responses.txt $d/Makefile
- < $< sed -rn 's|.*|generate += $$d/enumerator@&.go $$d/util/enumerator@&.go|p' > $@
-
$d/requests.txt: $d/nslcd_h.go $d/Makefile
< $< grep -Eo '\btype Request_([^_ ]+)(_\S+)?' | sed 's/^type Request_//' > $@
-$d/responses.txt: $d/interface_backend.go $d/Makefile
- < $< sed -rn 's/.* (\S+)_Enumerator$$/\1/p' | sort -u > $@
%.go: %.go.sh
./$^ > $@
diff --git a/src/nslcd_proto/enumerator@T.got b/src/nslcd_proto/enumerator@T.got
deleted file mode 100644
index cad54fa..0000000
--- a/src/nslcd_proto/enumerator@T.got
+++ /dev/null
@@ -1,8 +0,0 @@
-package nslcd_proto
-
-type <T>_Enumerator interface {
- GetNext() (n *<T>, err error)
- GenericGetNext() (n *interface{}, err error)
-}
-
-// -*- Mode: Go -*-
diff --git a/src/nslcd_proto/func_handlerequest.go.sh b/src/nslcd_proto/func_handlerequest.go.sh
index 45e0ed6..de9a6b7 100755
--- a/src/nslcd_proto/func_handlerequest.go.sh
+++ b/src/nslcd_proto/func_handlerequest.go.sh
@@ -9,10 +9,6 @@ import (
"io"
)
-type enumerator interface {
- GenericGetNext() (n *interface{}, err error)
-}
-
func handleRequest(backend Backend, in io.Reader, out io.Writer, cred Ucred) {
var version int32
read(in, &version)
@@ -22,7 +18,7 @@ func handleRequest(backend Backend, in io.Reader, out io.Writer, cred Ucred) {
var action int32
read(in, &action)
- var res enumerator = nil
+ res := make(chan interface{})
switch action {
$(
while read -r request; do
@@ -31,7 +27,15 @@ while read -r request; do
var req Request_${request}
read(in, &req)
fmt.Printf("request: %#v\n", req)
- res = backend.${request}(cred, req)
+ _res := backend.${request}(cred, req)
+ go func() {
+ o, ok := <-_res
+ if ok {
+ res <- o
+ } else {
+ close(res)
+ }
+ }()
EOT
done < "$requests"
)
@@ -44,14 +48,9 @@ done < "$requests"
write(out, NSLCD_VERSION)
write(out, action)
- var result *interface{}
- var err error
- for result, err = res.GenericGetNext(); (result != nil) && (err == nil); result, err = res.GenericGetNext() {
+ for result, ok := <-res; ok; result, ok = <-res {
write(out, NSLCD_RESULT_BEGIN)
- write(out, *result)
- }
- if err != nil {
- panic(err)
+ write(out, result)
}
write(out, NSLCD_RESULT_END)
}
diff --git a/src/nslcd_proto/interface_backend.go.sh b/src/nslcd_proto/interface_backend.go.sh
index 9e812ee..a5b76a4 100755
--- a/src/nslcd_proto/interface_backend.go.sh
+++ b/src/nslcd_proto/interface_backend.go.sh
@@ -9,7 +9,7 @@ import "syscall"
type Ucred syscall.Ucred
type Backend interface {
- $(sed -rn 's/([^_]+)(.*)/\1\2(Ucred, Request_\1\2) \1_Enumerator/p' "$requests" | grep -v PAM)
- $(sed -rn 's/(PAM)(.*)/\1\2(Ucred, Request_\1\2) \1\2_Enumerator/p' "$requests")
+ $(sed -rn 's/([^_]+)(.*)/\1\2(Ucred, Request_\1\2) <-chan \1/p' "$requests" | grep -v PAM)
+ $(sed -rn 's/(PAM)(.*)/\1\2(Ucred, Request_\1\2) <-chan \1\2/p' "$requests")
}
EOF
diff --git a/src/nslcd_proto/util/enumerator@T.got b/src/nslcd_proto/util/enumerator@T.got
deleted file mode 100644
index 5ce5cb5..0000000
--- a/src/nslcd_proto/util/enumerator@T.got
+++ /dev/null
@@ -1,45 +0,0 @@
-package util
-
-import "nslcd_proto"
-
-type <T>_List struct {
- dat []nslcd_proto.<T>
- i int
-}
-
-var _ nslcd_proto.<T>_Enumerator = &<T>_List{}
-
-func New_<T>_List(ary []nslcd_proto.<T>) *<T>_List {
- return &<T>_List{ary, 0}
-}
-
-func (o *<T>_List) GetNext() (n *nslcd_proto.<T>, err error) {
- if o.i < len(o.dat) {
- n = &o.dat[o.i]
- o.i++
- }
- err = nil
- return
-}
-
-func (o *<T>_List) GenericGetNext() (n *interface{}, err error) {
- a, err := o.GetNext()
- if a != nil {
- b := (interface{})(*a)
- n = &b
- }
- return
-}
-
-type <T>_Ø struct{}
-
-var _ nslcd_proto.<T>_Enumerator = <T>_Ø{}
-
-func (o <T>_Ø) GetNext() (*nslcd_proto.<T>, error) {
- return nil, nil
-}
-func (o <T>_Ø) GenericGetNext() (*interface{}, error) {
- return nil, nil
-}
-
-// -*- Mode: Go -*-
diff --git a/src/nslcd_proto/util/struct_null_backend.go.sh b/src/nslcd_proto/util/struct_null_backend.go.sh
index 9d1c1b0..1714e9a 100755
--- a/src/nslcd_proto/util/struct_null_backend.go.sh
+++ b/src/nslcd_proto/util/struct_null_backend.go.sh
@@ -8,7 +8,7 @@ import p "nslcd_proto"
type NullBackend struct{}
-$(< "$interface" sed -rn 's/^\t([^(]+)\(Ucred, ([^)]+)\) (\S+)_Enumerator$/func (o NullBackend) \1(p.Ucred, p.\2) p.\3_Enumerator { return \3_Ø{} }/p')
+$(< "$interface" sed -rn 's/^\t([^(]+)\(Ucred, ([^)]+)\) <-chan (\S+)$/func (o NullBackend) \1(p.Ucred, p.\2) <-chan p.\3 { r := make(chan p.\3); close(r); return r }/p')
var _ p.Backend = NullBackend{}
EOF