Revert "Upgrade to go 1.19 and update dependencies (#3069)" (#3085)

This reverts commit bba7c23957.
This commit is contained in:
WithoutPants
2022-11-07 12:33:15 +11:00
committed by GitHub
parent bba7c23957
commit 2609095c7a
939 changed files with 43785 additions and 101302 deletions

View File

@@ -31,8 +31,8 @@ func BinaryInt(b bool) uint {
// flags are in hex. trailing 24 zeroes, 26 are after the space
// "DLNA.ORG_OP=" time-seek-range-supp bytes-range-header-supp
func (cf ContentFeatures) String() (ret string) {
// DLNA.ORG_PN=[a-zA-Z0-9_]*
params := make([]string, 0, 3)
//DLNA.ORG_PN=[a-zA-Z0-9_]*
params := make([]string, 0, 2)
if cf.ProfileName != "" {
params = append(params, "DLNA.ORG_PN="+cf.ProfileName)
}
@@ -41,7 +41,6 @@ func (cf ContentFeatures) String() (ret string) {
BinaryInt(cf.SupportTimeSeek),
BinaryInt(cf.SupportRange),
BinaryInt(cf.Transcoded)))
params = append(params, "DLNA.ORG_FLAGS=01700000000000000000000000000000")
return strings.Join(params, ";")
}

View File

@@ -5,6 +5,7 @@ import (
"bytes"
"fmt"
"io"
"log"
"math/rand"
"net"
"net/http"
@@ -13,8 +14,6 @@ import (
"strings"
"time"
"github.com/anacrolix/log"
"golang.org/x/net/ipv4"
)
@@ -25,13 +24,15 @@ const (
byebyeNTS = "ssdp:byebye"
)
var NetAddr *net.UDPAddr
var (
NetAddr *net.UDPAddr
)
func init() {
var err error
NetAddr, err = net.ResolveUDPAddr("udp4", AddrString)
if err != nil {
log.Printf("Could not resolve %s: %s", AddrString, err)
log.Panicf("Could not resolve %s: %s", AddrString, err)
}
}
@@ -84,12 +85,10 @@ type Server struct {
Server string
Services []string
Devices []string
IPFilter func(net.IP) bool
Location func(net.IP) string
UUID string
NotifyInterval time.Duration
closed chan struct{}
Logger log.Logger
}
func makeConn(ifi net.Interface) (ret *net.UDPConn, err error) {
@@ -99,23 +98,17 @@ func makeConn(ifi net.Interface) (ret *net.UDPConn, err error) {
}
p := ipv4.NewPacketConn(ret)
if err := p.SetMulticastTTL(2); err != nil {
log.Print(err)
log.Println(err)
}
if err := p.SetMulticastLoopback(true); err != nil {
log.Println(err)
}
// if err := p.SetMulticastLoopback(true); err != nil {
// log.Println(err)
// }
return
}
func (me *Server) serve() {
for {
size := me.Interface.MTU
if size > 65536 {
size = 65536
} else if size <= 0 { // fix for windows with mtu 4gb
size = 65536
}
b := make([]byte, size)
b := make([]byte, me.Interface.MTU)
n, addr, err := me.conn.ReadFromUDP(b)
select {
case <-me.closed:
@@ -123,7 +116,7 @@ func (me *Server) serve() {
default:
}
if err != nil {
me.Logger.Printf("error reading from UDP socket: %s", err)
log.Printf("error reading from UDP socket: %s", err)
break
}
go me.handle(b[:n], addr)
@@ -133,9 +126,6 @@ func (me *Server) serve() {
func (me *Server) Init() (err error) {
me.closed = make(chan struct{})
me.conn, err = makeConn(me.Interface)
if me.IPFilter == nil {
me.IPFilter = func(net.IP) bool { return true }
}
return
}
@@ -162,14 +152,6 @@ func (me *Server) Serve() (err error) {
}
panic(fmt.Sprint("unexpected addr type:", addr))
}()
if !me.IPFilter(ip) {
continue
}
if ip.IsLinkLocalUnicast() {
// These addresses seem to confuse VLC. Possibly there's supposed to be a zone
// included in the address, but I don't see one.
continue
}
extraHdrs := [][2]string{
{"CACHE-CONTROL", fmt.Sprintf("max-age=%d", 5*me.NotifyInterval/2/time.Second)},
{"LOCATION", me.Location(ip)},
@@ -212,9 +194,9 @@ func (me *Server) makeNotifyMessage(target, nts string, extraHdrs [][2]string) [
func (me *Server) send(buf []byte, addr *net.UDPAddr) {
if n, err := me.conn.WriteToUDP(buf, addr); err != nil {
me.Logger.Printf("error writing to UDP socket: %s", err)
log.Printf("error writing to UDP socket: %s", err)
} else if n != len(buf) {
me.Logger.Printf("short write: %d/%d bytes", n, len(buf))
log.Printf("short write: %d/%d bytes", n, len(buf))
}
}
@@ -230,7 +212,7 @@ func (me *Server) delayedSend(delay time.Duration, buf []byte, addr *net.UDPAddr
func (me *Server) log(args ...interface{}) {
args = append([]interface{}{me.Interface.Name + ":"}, args...)
me.Logger.Print(args...)
log.Print(args...)
}
func (me *Server) sendByeBye() {
@@ -262,7 +244,7 @@ func (me *Server) allTypes() (ret []string) {
func (me *Server) handle(buf []byte, sender *net.UDPAddr) {
req, err := ReadRequest(bufio.NewReader(bytes.NewReader(buf)))
if err != nil {
me.Logger.Println(err)
log.Println(err)
return
}
if req.Method != "M-SEARCH" || req.Header.Get("man") != `"ssdp:discover"` {
@@ -273,7 +255,7 @@ func (me *Server) handle(buf []byte, sender *net.UDPAddr) {
mxHeader := req.Header.Get("mx")
i, err := strconv.ParseUint(mxHeader, 0, 0)
if err != nil {
me.Logger.Printf("Invalid mx header %q: %s", mxHeader, err)
log.Printf("Invalid mx header %q: %s", mxHeader, err)
return
}
mx = uint(i)

View File

@@ -5,11 +5,10 @@ import (
"encoding/xml"
"fmt"
"io"
"log"
"net/url"
"regexp"
"time"
"github.com/anacrolix/log"
)
// TODO: Why use namespace prefixes in PropertySet et al? Because the spec

View File

@@ -4,23 +4,21 @@ import (
"encoding/xml"
"errors"
"fmt"
"log"
"regexp"
"strconv"
"strings"
"github.com/anacrolix/log"
)
var serviceURNRegexp *regexp.Regexp = regexp.MustCompile(`^urn:(.*):service:(\w+):(\d+)$`)
var serviceURNRegexp *regexp.Regexp = regexp.MustCompile(`^urn:schemas-upnp-org:service:(\w+):(\d+)$`)
type ServiceURN struct {
Auth string
Type string
Version uint64
}
func (me ServiceURN) String() string {
return fmt.Sprintf("urn:%s:service:%s:%d", me.Auth, me.Type, me.Version)
return fmt.Sprintf("urn:schemas-upnp-org:service:%s:%d", me.Type, me.Version)
}
func ParseServiceType(s string) (ret ServiceURN, err error) {
@@ -29,12 +27,11 @@ func ParseServiceType(s string) (ret ServiceURN, err error) {
err = errors.New(s)
return
}
if len(matches) != 4 {
log.Panicf("Invalid serviceURNRegexp?")
if len(matches) != 3 {
log.Panicf("Invalid serviceURNRegexp ?")
}
ret.Auth = matches[1]
ret.Type = matches[2]
ret.Version, err = strconv.ParseUint(matches[3], 0, 0)
ret.Type = matches[1]
ret.Version, err = strconv.ParseUint(matches[2], 0, 0)
return
}
@@ -83,21 +80,17 @@ type Service struct {
}
type Device struct {
DeviceType string `xml:"deviceType"`
FriendlyName string `xml:"friendlyName"`
Manufacturer string `xml:"manufacturer"`
ModelName string `xml:"modelName"`
UDN string
VendorXML string `xml:",innerxml"`
IconList []Icon `xml:"iconList>icon"`
ServiceList []Service `xml:"serviceList>service"`
PresentationURL string `xml:"presentationURL,omitempty"`
DeviceType string `xml:"deviceType"`
FriendlyName string `xml:"friendlyName"`
Manufacturer string `xml:"manufacturer"`
ModelName string `xml:"modelName"`
UDN string
IconList []Icon `xml:"iconList>icon"`
ServiceList []Service `xml:"serviceList>service"`
}
type DeviceDesc struct {
XMLName xml.Name `xml:"urn:schemas-upnp-org:device-1-0 root"`
NSDLNA string `xml:"xmlns:dlna,attr"`
NSSEC string `xml:"xmlns:sec,attr"`
SpecVersion SpecVersion `xml:"specVersion"`
Device Device `xml:"device"`
}

View File

@@ -2,15 +2,12 @@ package upnpav
import (
"encoding/xml"
"time"
)
const (
// NoSuchObjectErrorCode : The specified ObjectID is invalid.
NoSuchObjectErrorCode = 701
)
// Resource description
type Resource struct {
XMLName xml.Name `xml:"res"`
ProtocolInfo string `xml:"protocolInfo,attr"`
@@ -21,44 +18,28 @@ type Resource struct {
Resolution string `xml:"resolution,attr,omitempty"`
}
// Container description
type Container struct {
Object
XMLName xml.Name `xml:"container"`
ChildCount int `xml:"childCount,attr"`
}
// Item description
type Item struct {
Object
XMLName xml.Name `xml:"item"`
Res []Resource
InnerXML string `xml:",innerxml"`
XMLName xml.Name `xml:"item"`
Res []Resource
}
// Object description
type Object struct {
ID string `xml:"id,attr"`
ParentID string `xml:"parentID,attr"`
Restricted int `xml:"restricted,attr"` // indicates whether the object is modifiable
Title string `xml:"dc:title"`
Class string `xml:"upnp:class"`
Icon string `xml:"upnp:icon,omitempty"`
Date Timestamp `xml:"dc:date"`
Artist string `xml:"upnp:artist,omitempty"`
Album string `xml:"upnp:album,omitempty"`
Genre string `xml:"upnp:genre,omitempty"`
AlbumArtURI string `xml:"upnp:albumArtURI,omitempty"`
Searchable int `xml:"searchable,attr"`
SearchXML string `xml:",innerxml"`
}
// Timestamp wraps time.Time for formatting purposes
type Timestamp struct {
time.Time
}
// MarshalXML formats the Timestamp per DIDL-Lite spec
func (t Timestamp) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return e.EncodeElement(t.Format("2006-01-02"), start)
ID string `xml:"id,attr"`
ParentID string `xml:"parentID,attr"`
Restricted int `xml:"restricted,attr"` // indicates whether the object is modifiable
Class string `xml:"upnp:class"`
Icon string `xml:"upnp:icon,omitempty"`
Title string `xml:"dc:title"`
Artist string `xml:"upnp:artist,omitempty"`
Album string `xml:"upnp:album,omitempty"`
Genre string `xml:"upnp:genre,omitempty"`
AlbumArtURI string `xml:"upnp:albumArtURI,omitempty"`
Searchable int `xml:"searchable,attr"`
}