commit a05e1c193f4dd579d75d2fa914d5297685a33f85
parent df412ed36264c687bce78048956d6f93b4695800
Author: Oliver Lowe <o@olowe.co>
Date: Mon, 1 Jul 2024 18:22:23 +1000
sdp: disallow empty lines
Spec forbids empty lines.
Diffstat:
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/m3u8/cmd/hlsserve/hlsserve.go b/m3u8/cmd/hlsserve/hlsserve.go
@@ -11,6 +11,7 @@ package main
import (
"bytes"
+ "flag"
"fmt"
"io"
"log"
@@ -40,7 +41,7 @@ func init() {
// rule of thumb for UDP transport
const maxTSBytes int = 7 * mpegts.PacketSize
-const segmentDuration = 4 * time.Second
+const segmentDuration = 3 * time.Second
var cacheDir string
var sequence int
@@ -137,18 +138,25 @@ func setCache(seconds int, next http.Handler) http.HandlerFunc {
}
}
+var listen = ":9000"
+
+func init() {
+ flag.StringVar(&listen, "l", ":9000", "listen")
+ flag.Parse()
+}
+
func main() {
- if len(os.Args) > 2 {
+ if len(flag.Args()) > 1 {
fmt.Fprintln(os.Stderr, usage)
os.Exit(2)
- } else if len(os.Args) == 2 {
- cacheDir = os.Args[1]
+ } else if len(flag.Args()) == 1 {
+ cacheDir = flag.Args()[0]
}
if err := os.MkdirAll(cacheDir, 0755); err != nil {
log.Fatal(err)
}
- ln, err := net.Listen("tcp", ":9000")
+ ln, err := net.Listen("tcp", listen)
if err != nil {
log.Fatal(err)
}
diff --git a/sdp/sdp.go b/sdp/sdp.go
@@ -44,7 +44,7 @@ First:
// read the mandatory fields first
for sc.Scan() {
if sc.Text() == "" {
- continue // TODO(otl): empty lines allowed?
+ return nil, fmt.Errorf("illegal empty line")
}
k, v, found := strings.Cut(sc.Text(), "=")
if !found {
@@ -90,7 +90,7 @@ First:
break
}
if sc.Text() == "" {
- continue // TODO(otl): empty lines allowed?
+ return nil, fmt.Errorf("illegal empty line")
}
k, v, found := strings.Cut(sc.Text(), "=")
if !found {