func (me *Server) serviceControlHandler(w http.ResponseWriter, r *http.Request) {
	clientIp, _, _ := net.SplitHostPort(r.RemoteAddr)

	ip := net.ParseIP(clientIp).String()
	if !me.ipWhitelistManager.ipAllowed(ip) {
		// only log if we haven't seen it
		if !me.ipWhitelistManager.addRecent(ip) {
			logger.Infof("not allowed client %s", clientIp)
		}

		http.Error(w, "forbidden", http.StatusForbidden)
		return
	}

	soapActionString := r.Header.Get("SOAPACTION")
	soapAction, err := upnp.ParseActionHTTPHeader(soapActionString)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	var env soap.Envelope
	if err := xml.NewDecoder(r.Body).Decode(&env); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	// AwoX/1.1 UPnP/1.0 DLNADOC/1.50
	w.Header().Set("Content-Type", `text/xml; charset="utf-8"`)
	w.Header().Set("Ext", "")
	w.Header().Set("Server", serverField)
	soapRespXML, code := func() ([]byte, int) {
		respArgs, err := me.soapActionResponse(soapAction, env.Body.Action, r)
		if err != nil {
			upnpErr := upnp.ConvertError(err)
			return xmlMarshalOrPanic(soap.NewFault("UPnPError", upnpErr)), 500
		}
		return marshalSOAPResponse(soapAction, respArgs), 200
	}()
	bodyStr := fmt.Sprintf(`<?xml version="1.0" encoding="utf-8" standalone="yes"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body>%s</s:Body></s:Envelope>`, soapRespXML)
	w.WriteHeader(code)
	if _, err := w.Write([]byte(bodyStr)); err != nil {
		logger.Errorf(err.Error())
	}
}
// Handle a service control HTTP request.
Handle a service control HTTP request.
// Handle a service control HTTP request .
func (me *Server) serviceControlHandler(w http.ResponseWriter, r *http.Request) {
	clientIp, _, _ := net.SplitHostPort(r.RemoteAddr)
	ip := net.ParseIP(clientIp).String()
	if !me.ipWhitelistManager.ipAllowed(ip) {
		if !me.ipWhitelistManager.addRecent(ip) {
			logger.Infof("not allowed client %s", clientIp)
		}
		http.Error(w, "forbidden", http.StatusForbidden)
		return
	}
	soapActionString := r.Header.Get("SOAPACTION")
	soapAction, err := upnp.ParseActionHTTPHeader(soapActionString)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	var env soap.Envelope
	if err := xml.NewDecoder(r.Body).Decode(&env); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	w.Header().Set("Content-Type", `text/xml; charset="utf-8"`)
	w.Header().Set("Ext", "")
	w.Header().Set("Server", serverField)
	soapRespXML, code := func() ([]byte, int) {
		respArgs, err := me.soapActionResponse(soapAction, env.Body.Action, r)
		if err != nil {
			upnpErr := upnp.ConvertError(err)
			return xmlMarshalOrPanic(soap.NewFault("UPnPError", upnpErr)), 500
		}
		return marshalSOAPResponse(soapAction, respArgs), 200
	}()
	bodyStr := fmt.Sprintf(`<?xml version="1.0" encoding="utf-8" standalone="yes"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body>%s</s:Body></s:Envelope>`, soapRespXML)
	w.WriteHeader(code)
	if _, err := w.Write([]byte(bodyStr)); err != nil {
		logger.Errorf(err.Error())
	}
}
func ( me * Server ) serviceControlHandler ( w http . ResponseWriter , r * http . Request ) { clientIp , _ , _ := net . SplitHostPort ( r . RemoteAddr ) ip := net . ParseIP ( clientIp ) . String ( ) if ! me . ipWhitelistManager . ipAllowed ( ip ) { if ! me . ipWhitelistManager . addRecent ( ip ) { logger . Infof ( " " , clientIp ) } http . Error ( w , " " , http . StatusForbidden ) return } soapActionString := r . Header . Get ( " " ) soapAction , err := upnp . ParseActionHTTPHeader ( soapActionString ) if err != nil { http . Error ( w , err . Error ( ) , http . StatusBadRequest ) return } var env soap . Envelope if err := xml . NewDecoder ( r . Body ) . Decode ( & env ) ; err != nil { http . Error ( w , err . Error ( ) , http . StatusBadRequest ) return } w . Header ( ) . Set ( " " , `text/xml; charset="utf-8"` ) w . Header ( ) . Set ( " " , " " ) w . Header ( ) . Set ( " " , serverField ) soapRespXML , code := func ( ) ( [ ] byte , int ) { respArgs , err := me . soapActionResponse ( soapAction , env . Body . Action , r ) if err != nil { upnpErr := upnp . ConvertError ( err ) return xmlMarshalOrPanic ( soap . NewFault ( " " , upnpErr ) ) , 500 } return marshalSOAPResponse ( soapAction , respArgs ) , 200 } ( ) bodyStr := fmt . Sprintf ( `<?xml version="1.0" encoding="utf-8" standalone="yes"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body>%s</s:Body></s:Envelope>` , soapRespXML ) w . WriteHeader ( code ) if _ , err := w . Write ( [ ] byte ( bodyStr ) ) ; err != nil { logger . Errorf ( err . Error ( ) ) } }
Handle a service control HTTP request.
Handle a service control HTTP request .
// only log if we haven't seen it // AwoX/1.1 UPnP/1.0 DLNADOC/1.50