diff options
Diffstat (limited to 'src/nslcd_proto/func_handlerequest.go.sh')
-rwxr-xr-x | src/nslcd_proto/func_handlerequest.go.sh | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/nslcd_proto/func_handlerequest.go.sh b/src/nslcd_proto/func_handlerequest.go.sh new file mode 100755 index 0000000..0f0c686 --- /dev/null +++ b/src/nslcd_proto/func_handlerequest.go.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# -*- Mode: Go -*- +requests=$1 +cat <<EOF +package nslcd_proto + +import ( + "fmt" + "io" +) + +type enumerator interface { + GenericGetNext() (n interface{}, err error) +} + +func handleRequest(in io.Reader, out io.Writer, backend Backend) { + var version int32 + read(in, &version) + if version != NSLCD_VERSION { + panic(NslcdError(fmt.Sprintf("version mismatch: server=%#08x client=%#08x", NSLCD_VERSION, version))) + } + var action int32 + read(in, &action) + + var res enumerator = nil + switch action { +$( +while read -r request; do + cat <<EOT + case NSLCD_ACTION_${request^^}: + var req Request_${request} + read(in, &req) + res = backend.${request}(req) +EOT +done < "$requests" +) + default: + panic(NslcdError(fmt.Sprintf("unknown request action: %#08x", action))) + } + 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() { + write(out, NSLCD_RESULT_BEGIN) + write(out, result) + } + if err != nil { + panic(err) + } + write(out, NSLCD_RESULT_END) +} +EOF |