new func MockVersion

pull/358/head
q191201771 8 months ago
parent d7b0aaf6cf
commit 455a9b2235

@ -58,7 +58,6 @@ const (
DespSucc = "succ"
ErrorCodePageNotFound = 404
DespPageNotFound = "page not found, check this document out: https://pengrl.com/lal/#/HTTPAPI"
ErrorCodeGroupNotFound = 1001
DespGroupNotFound = "group not found"
@ -76,9 +75,11 @@ type ApiRespBasic struct {
Desp string `json:"desp"`
}
var ApiNotFoundResp = ApiRespBasic{
ErrorCode: ErrorCodePageNotFound,
Desp: DespPageNotFound,
func ApiNotFoundRespFn() ApiRespBasic {
return ApiRespBasic{
ErrorCode: ErrorCodePageNotFound,
Desp: DespPageNotFound,
}
}
type ApiStatLalInfoResp struct {

@ -8,7 +8,11 @@
package base
import "strings"
import (
"fmt"
"path/filepath"
"strings"
)
// 版本信息相关
// lal的一部分版本信息使用了naza.bininfo
@ -16,27 +20,38 @@ import "strings"
// 并且将这些信息打入可执行文件、日志、各协议中的标准版本字段中
// LalVersion 整个lal工程的版本号。注意该变量由外部脚本修改维护不要手动在代码中修改
const LalVersion = "v0.37.4"
var LalVersion = "v0.37.4"
// ConfVersion lalserver的配置文件的版本号
const ConfVersion = "v0.4.1"
var ConfVersion = "v0.4.1"
// HttpApiVersion lalserver的HTTP-API功能的版本号
const HttpApiVersion = "v0.4.8"
var HttpApiVersion = "v0.4.8"
// HttpNotifyVersion lalserver的HTTP-Notify功能的版本号
const HttpNotifyVersion = "v0.2.4"
var HttpNotifyVersion = "v0.2.4"
const HttpWebUiVersion = "v0.0.3"
var HttpWebUiVersion = "v0.0.3"
var (
LalLibraryName = "lal"
LalGithubRepo = "github.com/q191201771/lal"
LalGithubSite = "https://github.com/q191201771/lal"
LalDocSite = "https://pengrl.com/lal"
LalLibraryName = "lal"
LalGithubRepo = "github.com/q191201771/lal"
LalGithubSite = "https://github.com/q191201771/lal"
LalDocSite = "https://pengrl.com/lal"
LalDocSiteHTTPAPI = "https://pengrl.com/lal/#/HTTPAPI"
LalDefaultConfigFilename = "lalserver.conf.json"
LalLogo = `
__ ___ __
/ / / | / /
/ / / /| | / /
/ /___/ ___ |/ /___
/_____/_/ |_/_____/
`
// LalFullInfo e.g. lal v0.12.3 (github.com/q191201771/lal)
LalFullInfo = LalLibraryName + " " + LalVersion + " (" + LalGithubRepo + ")"
LalFullInfo string
// LalVersionDot e.g. 0.12.3
LalVersionDot string
@ -90,6 +105,21 @@ var (
// LalRtspRealm e.g. lal
LalRtspRealm string
LalRtmpRandom1528Buf []byte
LalFlvHttpResponseHeader []byte
LalTsHttpResponseHeader []byte
// LalRtspResponseOptionsTmpl CSeq
// rfc2326 10.1 OPTIONS
LalRtspResponseOptionsTmpl string
// LalDefaultConfFilenameList 没有指定配置文件时,按顺序作为优先级,找到第一个存在的并使用
LalDefaultConfFilenameList []string
DespPageNotFound string
)
// - rtmp handshake random buf
@ -122,7 +152,30 @@ var (
// - http api
// - `server:`
func init() {
func MockVersion(
lalVersion, confVersion, httpApiVersion, httpNotifyVersion, httpWebUiVersion,
lalLibraryName, lalGithubRepo, lalGithubSite, lalDocSite, lalDocSiteHTTPAPI,
lalDefaultConfigFilename, lalLogo string) {
LalVersion = lalVersion
ConfVersion = confVersion
HttpApiVersion = httpApiVersion
HttpNotifyVersion = httpNotifyVersion
HttpWebUiVersion = httpWebUiVersion
LalLibraryName = lalLibraryName
LalGithubRepo = lalGithubRepo
LalGithubSite = lalGithubSite
LalDocSite = lalDocSite
LalDocSiteHTTPAPI = lalDocSiteHTTPAPI
LalDefaultConfigFilename = lalDefaultConfigFilename
LalLogo = lalLogo
initial()
}
func initial() {
LalFullInfo = LalLibraryName + " " + LalVersion + " (" + LalGithubRepo + ")"
LalVersionDot = strings.TrimPrefix(LalVersion, "v")
LalVersionComma = strings.Replace(LalVersionDot, ".", ",", -1)
@ -145,4 +198,54 @@ func init() {
LalPackSdp = LalLibraryName + " " + LalVersionDot
LalRtspRealm = LalLibraryName
DespPageNotFound = "page not found, check this document out: " + LalDocSiteHTTPAPI
LalRtmpRandom1528Buf = make([]byte, 1528)
hack := []byte(fmt.Sprintf("random buf of rtmp handshake gen by %s", LalRtmpHandshakeWaterMark))
for i := 0; i < 1528; i += len(hack) {
copy(LalRtmpRandom1528Buf[i:], hack)
}
LalFlvHttpResponseHeader = []byte("HTTP/1.1 200 OK\r\n" +
"Server: " + LalHttpflvSubSessionServer + "\r\n" +
"Cache-Control: no-cache\r\n" +
"Content-Type: video/x-flv\r\n" +
"Connection: close\r\n" +
"Expires: -1\r\n" +
"Pragma: no-cache\r\n" +
CorsHeaders +
"\r\n")
LalTsHttpResponseHeader = []byte("HTTP/1.1 200 OK\r\n" +
"Server: " + LalHttptsSubSessionServer + "\r\n" +
"Cache-Control: no-cache\r\n" +
"Content-Type: video/mp2t\r\n" +
"Connection: close\r\n" +
"Expires: -1\r\n" +
"Pragma: no-cache\r\n" +
CorsHeaders +
"\r\n")
LalRtspResponseOptionsTmpl = "RTSP/1.0 200 OK\r\n" +
"Server: " + LalRtspOptionsResponseServer + "\r\n" +
"CSeq: %s\r\n" +
"Public: DESCRIBE, ANNOUNCE, SETUP, PLAY, PAUSE, RECORD, TEARDOWN\r\n" +
"\r\n"
LalDefaultConfFilenameList = []string{
filepath.FromSlash(LalDefaultConfigFilename),
filepath.FromSlash("./conf/" + LalDefaultConfigFilename),
filepath.FromSlash("../" + LalDefaultConfigFilename),
filepath.FromSlash("../conf/" + LalDefaultConfigFilename),
filepath.FromSlash("../../" + LalDefaultConfigFilename),
filepath.FromSlash("../../conf/" + LalDefaultConfigFilename),
filepath.FromSlash("../../../" + LalDefaultConfigFilename),
filepath.FromSlash("../../../conf/" + LalDefaultConfigFilename),
filepath.FromSlash("lal/conf/" + LalDefaultConfigFilename),
}
}
func init() {
initial()
}

@ -16,8 +16,6 @@ import (
"github.com/q191201771/naza/pkg/connection"
)
var flvHttpResponseHeader []byte
type SubSession struct {
core *base.BasicHttpSubSession
IsFresh bool
@ -62,7 +60,7 @@ func (session *SubSession) Dispose() error {
func (session *SubSession) WriteHttpResponseHeader() {
Log.Debugf("[%s] > W http response header.", session.core.UniqueKey())
session.core.WriteHttpResponseHeader(flvHttpResponseHeader)
session.core.WriteHttpResponseHeader(base.LalFlvHttpResponseHeader)
}
func (session *SubSession) WriteFlvHeader() {
@ -119,19 +117,3 @@ func (session *SubSession) GetStat() base.StatSession {
func (session *SubSession) IsAlive() (readAlive, writeAlive bool) {
return session.core.IsAlive()
}
// ---------------------------------------------------------------------------------------------------------------------
func init() {
flvHttpResponseHeaderStr := "HTTP/1.1 200 OK\r\n" +
"Server: " + base.LalHttpflvSubSessionServer + "\r\n" +
"Cache-Control: no-cache\r\n" +
"Content-Type: video/x-flv\r\n" +
"Connection: close\r\n" +
"Expires: -1\r\n" +
"Pragma: no-cache\r\n" +
base.CorsHeaders +
"\r\n"
flvHttpResponseHeader = []byte(flvHttpResponseHeaderStr)
}

@ -15,8 +15,6 @@ import (
"github.com/q191201771/naza/pkg/connection"
)
var tsHttpResponseHeader []byte
type SubSession struct {
core *base.BasicHttpSubSession
IsFresh bool
@ -60,7 +58,7 @@ func (session *SubSession) Dispose() error {
func (session *SubSession) WriteHttpResponseHeader() {
Log.Debugf("[%s] > W http response header.", session.core.UniqueKey())
session.core.WriteHttpResponseHeader(tsHttpResponseHeader)
session.core.WriteHttpResponseHeader(base.LalTsHttpResponseHeader)
}
func (session *SubSession) Write(b []byte) {
@ -110,17 +108,3 @@ func (session *SubSession) GetStat() base.StatSession {
func (session *SubSession) IsAlive() (readAlive, writeAlive bool) {
return session.core.IsAlive()
}
func init() {
tsHttpResponseHeaderStr := "HTTP/1.1 200 OK\r\n" +
"Server: " + base.LalHttptsSubSessionServer + "\r\n" +
"Cache-Control: no-cache\r\n" +
"Content-Type: video/mp2t\r\n" +
"Connection: close\r\n" +
"Expires: -1\r\n" +
"Pragma: no-cache\r\n" +
base.CorsHeaders +
"\r\n"
tsHttpResponseHeader = []byte(tsHttpResponseHeaderStr)
}

@ -249,13 +249,7 @@ func LoadConfAndInitLog(rawContent []byte) *Config {
Log.Info("initial log succ.")
// 打印Logo
Log.Info(`
__ ___ __
/ / / | / /
/ / / /| | / /
/ /___/ ___ |/ /___
/_____/_/ |_/_____/
`)
Log.Info(base.LalLogo)
// 检查配置版本号是否匹配
if config.ConfVersion != base.ConfVersion {

@ -265,7 +265,7 @@ func (h *HttpApiServer) webUIHandler(w http.ResponseWriter, req *http.Request) {
func (h *HttpApiServer) notFoundHandler(w http.ResponseWriter, req *http.Request) {
Log.Warnf("invalid http-api request. uri=%s, raddr=%s", req.RequestURI, req.RemoteAddr)
//w.WriteHeader(http.StatusNotFound)
feedback(base.ApiNotFoundResp, w)
feedback(base.ApiNotFoundRespFn(), w)
}
// ---------------------------------------------------------------------------------------------------------------------

@ -9,8 +9,6 @@
package logic
import (
"path/filepath"
"github.com/q191201771/lal/pkg/base"
)
@ -147,19 +145,6 @@ var defaultOption = Option{
type ModOption func(option *Option)
// DefaultConfFilenameList 没有指定配置文件时,按顺序作为优先级,找到第一个存在的并使用
var DefaultConfFilenameList = []string{
filepath.FromSlash("lalserver.conf.json"),
filepath.FromSlash("./conf/lalserver.conf.json"),
filepath.FromSlash("../lalserver.conf.json"),
filepath.FromSlash("../conf/lalserver.conf.json"),
filepath.FromSlash("../../lalserver.conf.json"),
filepath.FromSlash("../../conf/lalserver.conf.json"),
filepath.FromSlash("../../../lalserver.conf.json"),
filepath.FromSlash("../../../conf/lalserver.conf.json"),
filepath.FromSlash("lal/conf/lalserver.conf.json"),
}
// ---------------------------------------------------------------------------------------------------------------------
// TODO(chef): [doc] 整理散乱在源码文件中的以注释形式存在的文档 202302

@ -72,14 +72,14 @@ func NewServerManager(modOption ...ModOption) *ServerManager {
rawContent := sm.option.ConfRawContent
if len(rawContent) == 0 {
rawContent = base.WrapReadConfigFile(sm.option.ConfFilename, DefaultConfFilenameList, func() {
rawContent = base.WrapReadConfigFile(sm.option.ConfFilename, base.LalDefaultConfFilenameList, func() {
_, _ = fmt.Fprintf(os.Stderr, `
Example:
%s -c %s
Github: %s
Doc: %s
`, os.Args[0], filepath.FromSlash("./conf/lalserver.conf.json"), base.LalGithubSite, base.LalDocSite)
`, os.Args[0], filepath.FromSlash("./conf/"+base.LalDefaultConfigFilename), base.LalGithubSite, base.LalDocSite)
})
}
sm.config = LoadConfAndInitLog(rawContent)

@ -12,7 +12,6 @@ import (
"bytes"
"crypto/hmac"
"crypto/sha256"
"fmt"
"io"
"time"
@ -290,13 +289,5 @@ func makeDigest(b []byte, key []byte) []byte {
}
func random1528(out []byte) {
copy(out, random1528Buf)
}
func init() {
random1528Buf = make([]byte, 1528)
hack := []byte(fmt.Sprintf("random buf of rtmp handshake gen by %s", base.LalRtmpHandshakeWaterMark))
for i := 0; i < 1528; i += len(hack) {
copy(random1528Buf[i:], hack)
}
copy(out, base.LalRtmpRandom1528Buf)
}

@ -15,15 +15,6 @@ import (
"github.com/q191201771/lal/pkg/base"
)
// rfc2326 10.1 OPTIONS
// ResponseOptionsTmpl CSeq
var ResponseOptionsTmpl = "RTSP/1.0 200 OK\r\n" +
"Server: " + base.LalRtspOptionsResponseServer + "\r\n" +
"CSeq: %s\r\n" +
"Public: DESCRIBE, ANNOUNCE, SETUP, PLAY, PAUSE, RECORD, TEARDOWN\r\n" +
"\r\n"
// rfc2326 10.3 ANNOUNCE
//var RequestAnnounceTmpl = "not impl"
@ -84,7 +75,7 @@ var ResponseAuthorizedTmpl = "RTSP/1.0 401 Unauthorized\r\n" +
"\r\n"
func PackResponseOptions(cseq string) string {
return fmt.Sprintf(ResponseOptionsTmpl, cseq)
return fmt.Sprintf(base.LalRtspResponseOptionsTmpl, cseq)
}
func PackResponseAnnounce(cseq string) string {

@ -36,7 +36,7 @@ GitTag=`git tag --sort=version:refname | tail -n 1`
echo "newest version in git tag: " $GitTag
# 源码中的版本号
FileVersion=`cat ${ROOT_DIR}/pkg/base/t_version.go | grep 'const LalVersion' | awk -F\" '{print $2}'`
FileVersion=`cat ${ROOT_DIR}/pkg/base/t_version.go | grep 'var LalVersion' | awk -F\" '{print $2}'`
echo "newest version in t_version.go: " $FileVersion
# CHANGELOG.md和源码中的不一致更新源码并提交修改
@ -44,7 +44,7 @@ if [ "$NewVersion" == "$FileVersion" ];then
echo 'same tag, noop.'
else
echo 'update t_version.go'
gsed -i "/^const LalVersion/cconst LalVersion = \"${NewVersion}\"" ${ROOT_DIR}/pkg/base/t_version.go
gsed -i "/^var LalVersion/cvar LalVersion = \"${NewVersion}\"" ${ROOT_DIR}/pkg/base/t_version.go
git add ${ROOT_DIR}/pkg/base/t_version.go
git commit -m "${NewVersion} -> t_version.go"
git push

Loading…
Cancel
Save