mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-23 01:12:20 +08:00
TcpSession/UdpSession统一为Session类
This commit is contained in:
@@ -181,7 +181,7 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
|
||||
}
|
||||
|
||||
//拦截hls的播放请求
|
||||
static bool emitHlsPlayed(const Parser &parser, const MediaInfo &media_info, const HttpSession::HttpAccessPathInvoker &invoker,TcpSession &sender){
|
||||
static bool emitHlsPlayed(const Parser &parser, const MediaInfo &media_info, const HttpSession::HttpAccessPathInvoker &invoker,Session &sender){
|
||||
//访问的hls.m3u8结尾,我们转换成kBroadcastMediaPlayed事件
|
||||
Broadcast::AuthInvoker auth_invoker = [invoker](const string &err) {
|
||||
//cookie有效期为kHlsCookieSecond
|
||||
@@ -236,7 +236,7 @@ public:
|
||||
* 4、cookie中记录的url参数是否跟本次url参数一致,如果一致直接返回客户端错误码
|
||||
* 5、触发kBroadcastHttpAccess事件
|
||||
*/
|
||||
static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, bool is_dir,
|
||||
static void canAccessPath(Session &sender, const Parser &parser, const MediaInfo &media_info, bool is_dir,
|
||||
const function<void(const string &err_msg, const HttpServerCookie::Ptr &cookie)> &callback) {
|
||||
//获取用户唯一id
|
||||
auto uid = parser.Params();
|
||||
@@ -353,7 +353,7 @@ static string pathCat(const string &a, const string &b){
|
||||
* @param file_path 文件绝对路径
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
|
||||
static void accessFile(Session &sender, const Parser &parser, const MediaInfo &media_info, const string &file_path, const HttpFileManager::invoker &cb) {
|
||||
bool is_hls = end_with(file_path, kHlsSuffix);
|
||||
if (!is_hls && !File::fileExist(file_path.data())) {
|
||||
//文件不存在且不是hls,那么直接返回404
|
||||
@@ -366,7 +366,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
||||
replace(const_cast<string &>(media_info._streamid), kHlsSuffix, "");
|
||||
}
|
||||
|
||||
weak_ptr<TcpSession> weakSession = sender.shared_from_this();
|
||||
weak_ptr<Session> weakSession = sender.shared_from_this();
|
||||
//判断是否有权限访问该文件
|
||||
canAccessPath(sender, parser, media_info, false, [cb, file_path, parser, is_hls, media_info, weakSession](const string &err_msg, const HttpServerCookie::Ptr &cookie) {
|
||||
auto strongSession = weakSession.lock();
|
||||
@@ -456,7 +456,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
||||
});
|
||||
}
|
||||
|
||||
static string getFilePath(const Parser &parser,const MediaInfo &media_info, TcpSession &sender){
|
||||
static string getFilePath(const Parser &parser,const MediaInfo &media_info, Session &sender){
|
||||
GET_CONFIG(bool, enableVhost, General::kEnableVhost);
|
||||
GET_CONFIG(string, rootPath, Http::kRootPath);
|
||||
GET_CONFIG_FUNC(StrCaseMap, virtualPathMap, Http::kVirtualPath, [](const string &str) {
|
||||
@@ -491,7 +491,7 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, TcpS
|
||||
* @param parser http请求
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
void HttpFileManager::onAccessPath(TcpSession &sender, Parser &parser, const HttpFileManager::invoker &cb) {
|
||||
void HttpFileManager::onAccessPath(Session &sender, Parser &parser, const HttpFileManager::invoker &cb) {
|
||||
auto fullUrl = string(HTTP_SCHEMA) + "://" + parser["Host"] + parser.FullUrl();
|
||||
MediaInfo media_info(fullUrl);
|
||||
auto file_path = getFilePath(parser, media_info, sender);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "HttpBody.h"
|
||||
#include "HttpCookie.h"
|
||||
#include "Common/Parser.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/Session.h"
|
||||
#include "Util/function_traits.h"
|
||||
|
||||
namespace mediakit {
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
* @param parser http请求
|
||||
* @param cb 回调对象
|
||||
*/
|
||||
static void onAccessPath(toolkit::TcpSession &sender, Parser &parser, const invoker &cb);
|
||||
static void onAccessPath(toolkit::Session &sender, Parser &parser, const invoker &cb);
|
||||
|
||||
/**
|
||||
* 获取mime值
|
||||
|
||||
@@ -23,7 +23,7 @@ using namespace toolkit;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
HttpSession::HttpSession(const Socket::Ptr &pSock) : TcpSession(pSock) {
|
||||
HttpSession::HttpSession(const Socket::Ptr &pSock) : Session(pSock) {
|
||||
TraceP(this);
|
||||
GET_CONFIG(uint32_t,keep_alive_sec,Http::kKeepAliveSecond);
|
||||
pSock->setSendTimeOutSecond(keep_alive_sec);
|
||||
@@ -440,7 +440,7 @@ class AsyncSenderData {
|
||||
public:
|
||||
friend class AsyncSender;
|
||||
typedef std::shared_ptr<AsyncSenderData> Ptr;
|
||||
AsyncSenderData(const TcpSession::Ptr &session, const HttpBody::Ptr &body, bool close_when_complete) {
|
||||
AsyncSenderData(const Session::Ptr &session, const HttpBody::Ptr &body, bool close_when_complete) {
|
||||
_session = dynamic_pointer_cast<HttpSession>(session);
|
||||
_body = body;
|
||||
_close_when_complete = close_when_complete;
|
||||
@@ -675,7 +675,7 @@ std::string HttpSession::get_peer_ip() {
|
||||
if(!forwarded_ip_header.empty() && !_parser.getHeader()[forwarded_ip_header].empty()){
|
||||
return _parser.getHeader()[forwarded_ip_header];
|
||||
}
|
||||
return TcpSession::get_peer_ip();
|
||||
return Session::get_peer_ip();
|
||||
}
|
||||
|
||||
void HttpSession::Handle_Req_POST(ssize_t &content_len) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#define SRC_HTTP_HTTPSESSION_H_
|
||||
|
||||
#include <functional>
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Network/Session.h"
|
||||
#include "Rtmp/RtmpMediaSource.h"
|
||||
#include "Rtmp/FlvMuxer.h"
|
||||
#include "HttpRequestSplitter.h"
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
class HttpSession: public toolkit::TcpSession,
|
||||
class HttpSession: public toolkit::Session,
|
||||
public FlvMuxer,
|
||||
public HttpRequestSplitter,
|
||||
public WebSocketSplitter {
|
||||
@@ -139,7 +139,7 @@ private:
|
||||
std::function<bool (const char *data,size_t len) > _contentCallBack;
|
||||
};
|
||||
|
||||
using HttpsSession = toolkit::TcpSessionWithSSL<HttpSession>;
|
||||
using HttpsSession = toolkit::SessionWithSSL<HttpSession>;
|
||||
|
||||
} /* namespace mediakit */
|
||||
|
||||
|
||||
@@ -27,18 +27,18 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* 该类实现了TcpSession派生类发送数据的截取
|
||||
* 该类实现了Session派生类发送数据的截取
|
||||
* 目的是发送业务数据前进行websocket协议的打包
|
||||
*/
|
||||
template <typename TcpSessionType>
|
||||
class TcpSessionTypeImp : public TcpSessionType, public SendInterceptor{
|
||||
template <typename SessionType>
|
||||
class SessionTypeImp : public SessionType, public SendInterceptor{
|
||||
public:
|
||||
typedef std::shared_ptr<TcpSessionTypeImp> Ptr;
|
||||
using Ptr = std::shared_ptr<SessionTypeImp>;
|
||||
|
||||
TcpSessionTypeImp(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock) :
|
||||
TcpSessionType(pSock), _identifier(parent.getIdentifier()) {}
|
||||
SessionTypeImp(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock) :
|
||||
SessionType(pSock), _identifier(parent.getIdentifier()) {}
|
||||
|
||||
~TcpSessionTypeImp() {}
|
||||
~SessionTypeImp() = default;
|
||||
|
||||
/**
|
||||
* 设置发送数据截取回调函数
|
||||
@@ -58,7 +58,7 @@ protected:
|
||||
if (_beforeSendCB) {
|
||||
return _beforeSendCB(buf);
|
||||
}
|
||||
return TcpSessionType::send(std::move(buf));
|
||||
return SessionType::send(std::move(buf));
|
||||
}
|
||||
|
||||
std::string getIdentifier() const override {
|
||||
@@ -70,12 +70,12 @@ private:
|
||||
onBeforeSendCB _beforeSendCB;
|
||||
};
|
||||
|
||||
template <typename TcpSessionType>
|
||||
class TcpSessionCreator {
|
||||
template <typename SessionType>
|
||||
class SessionCreator {
|
||||
public:
|
||||
//返回的TcpSession必须派生于SendInterceptor,可以返回null
|
||||
toolkit::TcpSession::Ptr operator()(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock){
|
||||
return std::make_shared<TcpSessionTypeImp<TcpSessionType> >(header,parent,pSock);
|
||||
//返回的Session必须派生于SendInterceptor,可以返回null
|
||||
toolkit::Session::Ptr operator()(const mediakit::Parser &header, const mediakit::HttpSession &parent, const toolkit::Socket::Ptr &pSock){
|
||||
return std::make_shared<SessionTypeImp<SessionType> >(header,parent,pSock);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -228,15 +228,15 @@ private:
|
||||
std::string _payload_cache;
|
||||
std::string _payload_section;
|
||||
std::weak_ptr<toolkit::Server> _weak_server;
|
||||
toolkit::TcpSession::Ptr _session;
|
||||
toolkit::Session::Ptr _session;
|
||||
Creator _creator;
|
||||
};
|
||||
|
||||
|
||||
template<typename TcpSessionType,typename HttpSessionType = mediakit::HttpSession, mediakit::WebSocketHeader::Type DataType = mediakit::WebSocketHeader::TEXT>
|
||||
class WebSocketSession : public WebSocketSessionBase<TcpSessionCreator<TcpSessionType>,HttpSessionType,DataType>{
|
||||
template<typename SessionType,typename HttpSessionType = mediakit::HttpSession, mediakit::WebSocketHeader::Type DataType = mediakit::WebSocketHeader::TEXT>
|
||||
class WebSocketSession : public WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>{
|
||||
public:
|
||||
WebSocketSession(const toolkit::Socket::Ptr &pSock) : WebSocketSessionBase<TcpSessionCreator<TcpSessionType>,HttpSessionType,DataType>(pSock){}
|
||||
WebSocketSession(const toolkit::Socket::Ptr &pSock) : WebSocketSessionBase<SessionCreator<SessionType>,HttpSessionType,DataType>(pSock){}
|
||||
virtual ~WebSocketSession(){}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user