Upgrade to go 1.19 and update dependencies (#3069)

* Update to go 1.19
* Update dependencies
* Update cross-compile script
* Add missing targets to cross-compile-all
* Update cache action to remove warning
This commit is contained in:
WithoutPants
2022-11-04 13:41:26 +11:00
committed by GitHub
parent f25881a3bf
commit bba7c23957
939 changed files with 101336 additions and 43819 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, 2)
// DLNA.ORG_PN=[a-zA-Z0-9_]*
params := make([]string, 0, 3)
if cf.ProfileName != "" {
params = append(params, "DLNA.ORG_PN="+cf.ProfileName)
}
@@ -41,6 +41,7 @@ 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,7 +5,6 @@ import (
"bytes"
"fmt"
"io"
"log"
"math/rand"
"net"
"net/http"
@@ -14,6 +13,8 @@ import (
"strings"
"time"
"github.com/anacrolix/log"
"golang.org/x/net/ipv4"
)
@@ -24,15 +25,13 @@ 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.Panicf("Could not resolve %s: %s", AddrString, err)
log.Printf("Could not resolve %s: %s", AddrString, err)
}
}
@@ -85,10 +84,12 @@ 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) {
@@ -98,17 +99,23 @@ func makeConn(ifi net.Interface) (ret *net.UDPConn, err error) {
}
p := ipv4.NewPacketConn(ret)
if err := p.SetMulticastTTL(2); err != nil {
log.Println(err)
}
if err := p.SetMulticastLoopback(true); err != nil {
log.Println(err)
log.Print(err)
}
// if err := p.SetMulticastLoopback(true); err != nil {
// log.Println(err)
// }
return
}
func (me *Server) serve() {
for {
b := make([]byte, me.Interface.MTU)
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)
n, addr, err := me.conn.ReadFromUDP(b)
select {
case <-me.closed:
@@ -116,7 +123,7 @@ func (me *Server) serve() {
default:
}
if err != nil {
log.Printf("error reading from UDP socket: %s", err)
me.Logger.Printf("error reading from UDP socket: %s", err)
break
}
go me.handle(b[:n], addr)
@@ -126,6 +133,9 @@ 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
}
@@ -152,6 +162,14 @@ 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)},
@@ -194,9 +212,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 {
log.Printf("error writing to UDP socket: %s", err)
me.Logger.Printf("error writing to UDP socket: %s", err)
} else if n != len(buf) {
log.Printf("short write: %d/%d bytes", n, len(buf))
me.Logger.Printf("short write: %d/%d bytes", n, len(buf))
}
}
@@ -212,7 +230,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...)
log.Print(args...)
me.Logger.Print(args...)
}
func (me *Server) sendByeBye() {
@@ -244,7 +262,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 {
log.Println(err)
me.Logger.Println(err)
return
}
if req.Method != "M-SEARCH" || req.Header.Get("man") != `"ssdp:discover"` {
@@ -255,7 +273,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 {
log.Printf("Invalid mx header %q: %s", mxHeader, err)
me.Logger.Printf("Invalid mx header %q: %s", mxHeader, err)
return
}
mx = uint(i)

View File

@@ -5,10 +5,11 @@ 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,21 +4,23 @@ import (
"encoding/xml"
"errors"
"fmt"
"log"
"regexp"
"strconv"
"strings"
"github.com/anacrolix/log"
)
var serviceURNRegexp *regexp.Regexp = regexp.MustCompile(`^urn:schemas-upnp-org:service:(\w+):(\d+)$`)
var serviceURNRegexp *regexp.Regexp = regexp.MustCompile(`^urn:(.*):service:(\w+):(\d+)$`)
type ServiceURN struct {
Auth string
Type string
Version uint64
}
func (me ServiceURN) String() string {
return fmt.Sprintf("urn:schemas-upnp-org:service:%s:%d", me.Type, me.Version)
return fmt.Sprintf("urn:%s:service:%s:%d", me.Auth, me.Type, me.Version)
}
func ParseServiceType(s string) (ret ServiceURN, err error) {
@@ -27,11 +29,12 @@ func ParseServiceType(s string) (ret ServiceURN, err error) {
err = errors.New(s)
return
}
if len(matches) != 3 {
log.Panicf("Invalid serviceURNRegexp ?")
if len(matches) != 4 {
log.Panicf("Invalid serviceURNRegexp?")
}
ret.Type = matches[1]
ret.Version, err = strconv.ParseUint(matches[2], 0, 0)
ret.Auth = matches[1]
ret.Type = matches[2]
ret.Version, err = strconv.ParseUint(matches[3], 0, 0)
return
}
@@ -80,17 +83,21 @@ type Service struct {
}
type Device struct {
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"`
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"`
}
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,12 +2,15 @@ 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"`
@@ -18,28 +21,44 @@ 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
XMLName xml.Name `xml:"item"`
Res []Resource
InnerXML string `xml:",innerxml"`
}
// 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
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"`
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)
}