Allow deregistration of handler

Implemented in both the server and client.
Renamed to client function to match the server side functions
Example progs need to be "ported" as this *is* an API change.
This commit is contained in:
Miek Gieben 2012-03-26 23:15:15 +02:00
parent 7f8e73f48d
commit 874787c537
2 changed files with 39 additions and 9 deletions

View File

@ -94,8 +94,22 @@ func (f HandlerQueryFunc) QueryDNS(w RequestWriter, r *Msg) {
go f(w, r)
}
// HandleQueryFunc registers the handler with the given pattern in the
// DefaultQueryMux.
func HandleQueryFunc(pattern string, handler func(RequestWriter, *Msg)) {
DefaultQueryMux.HandleQueryFunc(pattern, handler)
DefaultQueryMux.HandleFunc(pattern, handler)
}
// HandleQuery registers the handler
// in the DefaultQueryMux
func HandleQuery(pattern string, handler HandlerQueryFunc) {
DefaultQueryMux.Handle(pattern, handler)
}
// HandleQueryRemove deregisters the handle with the given pattern
// in the DefaultQueryMux.
func HandleQueryRemove(pattern string) {
DefaultQueryMux.HandleRemove(pattern)
}
// reusing zoneMatch from server.go
@ -121,7 +135,13 @@ func (mux *QueryMux) Handle(pattern string, handler QueryHandler) {
mux.m[pattern] = handler
}
func (mux *QueryMux) HandleQueryFunc(pattern string, handler func(RequestWriter, *Msg)) {
// HandleRemove deregisters the handler with given pattern.
func (mux *QueryMux) HandleRemove(pattern string) {
delete(mux.m, pattern)
}
// HandleFunc ...
func (mux *QueryMux) HandleFunc(pattern string, handler func(RequestWriter, *Msg)) {
mux.Handle(pattern, HandlerQueryFunc(handler))
}

View File

@ -117,10 +117,6 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
if pattern == "" {
panic("dns: invalid pattern " + pattern)
}
// Should this go
//if pattern[len(pattern)-1] != '.' { // no ending .
// mux.m[pattern+"."] = handler
//} else {
mux.m[pattern] = handler
}
@ -128,6 +124,14 @@ func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Ms
mux.Handle(pattern, HandlerFunc(handler))
}
func (mux *ServeMux) HandleRemove(pattern string) {
if pattern == "" {
panic("dns: invalid pattern " + pattern)
}
// if its there, its gone
delete(mux.m, pattern)
}
// ServeDNS dispatches the request to the handler whose
// pattern most closely matches the request message.
func (mux *ServeMux) ServeDNS(w ResponseWriter, request *Msg) {
@ -138,11 +142,17 @@ func (mux *ServeMux) ServeDNS(w ResponseWriter, request *Msg) {
h.ServeDNS(w, request)
}
// Handle register the handler the given pattern
// Handle registers the handler with the given pattern
// in the DefaultServeMux. The documentation for
// ServeMux explains how patters are matched.
func Handle(pattern string, handler Handler) { DefaultServeMux.Handle(pattern, handler) }
// HandleRemove deregisters the handle with the given pattern
// in the DefaultServeMux.
func HandleRemove(pattern string) { DefaultServeMux.HandleRemove(pattern) }
// HandleFunc registers the handler function with te given pattern
// in the DefaultServeMux.
func HandleFunc(pattern string, handler func(ResponseWriter, *Msg)) {
DefaultServeMux.HandleFunc(pattern, handler)
}
@ -322,7 +332,7 @@ func (c *conn) serve() {
w.tsigStatus = ErrKeyAlg
}
w.tsigStatus = TsigVerify(c.request, w.conn.tsigSecret[secret], "", false)
w.tsigTimersOnly = false // Will this ever be true?
w.tsigTimersOnly = false // Will this ever be true?
w.tsigRequestMAC = req.Extra[len(req.Extra)-1].(*RR_TSIG).MAC
}
w.req = req
@ -340,7 +350,7 @@ func (c *conn) serve() {
func (w *response) Write(m *Msg) (err error) {
var (
data []byte
ok bool
ok bool
)
if m.IsTsig() {
data, w.tsigRequestMAC, err = TsigGenerate(m, w.conn.tsigSecret[m.Extra[len(m.Extra)-1].(*RR_TSIG).Hdr.Name], w.tsigRequestMAC, w.tsigTimersOnly)