优化Parser代码命名

This commit is contained in:
xia-chu 2023-06-10 11:04:52 +08:00 committed by 夏楚
parent 52c7bc1d34
commit af0ebf4633
24 changed files with 156 additions and 147 deletions

View File

@ -86,17 +86,17 @@ API_EXPORT const char* API_CALL mk_mp4_info_get_stream(const mk_mp4_info ctx){
API_EXPORT const char* API_CALL mk_parser_get_method(const mk_parser ctx){ API_EXPORT const char* API_CALL mk_parser_get_method(const mk_parser ctx){
assert(ctx); assert(ctx);
Parser *parser = (Parser *)ctx; Parser *parser = (Parser *)ctx;
return parser->Method().c_str(); return parser->method().c_str();
} }
API_EXPORT const char* API_CALL mk_parser_get_url(const mk_parser ctx){ API_EXPORT const char* API_CALL mk_parser_get_url(const mk_parser ctx){
assert(ctx); assert(ctx);
Parser *parser = (Parser *)ctx; Parser *parser = (Parser *)ctx;
return parser->Url().c_str(); return parser->url().c_str();
} }
API_EXPORT const char* API_CALL mk_parser_get_url_params(const mk_parser ctx){ API_EXPORT const char* API_CALL mk_parser_get_url_params(const mk_parser ctx){
assert(ctx); assert(ctx);
Parser *parser = (Parser *)ctx; Parser *parser = (Parser *)ctx;
return parser->Params().c_str(); return parser->params().c_str();
} }
API_EXPORT const char* API_CALL mk_parser_get_url_param(const mk_parser ctx,const char *key){ API_EXPORT const char* API_CALL mk_parser_get_url_param(const mk_parser ctx,const char *key){
assert(ctx && key); assert(ctx && key);
@ -106,7 +106,7 @@ API_EXPORT const char* API_CALL mk_parser_get_url_param(const mk_parser ctx,cons
API_EXPORT const char* API_CALL mk_parser_get_tail(const mk_parser ctx){ API_EXPORT const char* API_CALL mk_parser_get_tail(const mk_parser ctx){
assert(ctx); assert(ctx);
Parser *parser = (Parser *)ctx; Parser *parser = (Parser *)ctx;
return parser->Tail().c_str(); return parser->protocol().c_str();
} }
API_EXPORT const char* API_CALL mk_parser_get_header(const mk_parser ctx,const char *key){ API_EXPORT const char* API_CALL mk_parser_get_header(const mk_parser ctx,const char *key){
assert(ctx && key); assert(ctx && key);
@ -117,9 +117,9 @@ API_EXPORT const char* API_CALL mk_parser_get_content(const mk_parser ctx, size_
assert(ctx); assert(ctx);
Parser *parser = (Parser *)ctx; Parser *parser = (Parser *)ctx;
if(length){ if(length){
*length = parser->Content().size(); *length = parser->content().size();
} }
return parser->Content().c_str(); return parser->content().c_str();
} }
///////////////////////////////////////////MediaInfo///////////////////////////////////////////// ///////////////////////////////////////////MediaInfo/////////////////////////////////////////////

View File

@ -108,7 +108,7 @@ API_EXPORT void API_CALL mk_http_requester_add_header(mk_http_requester ctx,cons
API_EXPORT const char* API_CALL mk_http_requester_get_response_status(mk_http_requester ctx){ API_EXPORT const char* API_CALL mk_http_requester_get_response_status(mk_http_requester ctx){
assert(ctx); assert(ctx);
HttpRequester::Ptr *obj = (HttpRequester::Ptr *)ctx; HttpRequester::Ptr *obj = (HttpRequester::Ptr *)ctx;
return (*obj)->response().Url().c_str(); return (*obj)->response().status().c_str();
} }
API_EXPORT const char* API_CALL mk_http_requester_get_response_header(mk_http_requester ctx,const char *key){ API_EXPORT const char* API_CALL mk_http_requester_get_response_header(mk_http_requester ctx,const char *key){
@ -121,9 +121,9 @@ API_EXPORT const char* API_CALL mk_http_requester_get_response_body(mk_http_requ
assert(ctx); assert(ctx);
HttpRequester::Ptr *obj = (HttpRequester::Ptr *)ctx; HttpRequester::Ptr *obj = (HttpRequester::Ptr *)ctx;
if(length){ if(length){
*length = (*obj)->response().Content().size(); *length = (*obj)->response().content().size();
} }
return (*obj)->response().Content().c_str(); return (*obj)->response().content().c_str();
} }
API_EXPORT mk_parser API_CALL mk_http_requester_get_response(mk_http_requester ctx){ API_EXPORT mk_parser API_CALL mk_http_requester_get_response(mk_http_requester ctx){

View File

@ -56,8 +56,7 @@ int main(int argc, char *argv[]) {
if (argc < 3) { if (argc < 3) {
ErrorL << "\r\n测试方法:./test_player rtxp_url rtp_type\r\n" ErrorL << "\r\n测试方法:./test_player rtxp_url rtp_type\r\n"
<< "例如:./test_player rtsp://admin:123456@127.0.0.1/live/0 0\r\n" << "例如:./test_player rtsp://admin:123456@127.0.0.1/live/0 0\r\n";
<< endl;
return 0; return 0;
} }

View File

@ -130,7 +130,7 @@ static HttpApi toApi(const function<void(API_ARGS_JSON_ASYNC)> &cb) {
//参数解析成json对象然后处理 //参数解析成json对象然后处理
Json::Value args; Json::Value args;
Json::Reader reader; Json::Reader reader;
reader.parse(parser.Content(), args); reader.parse(parser.content(), args);
cb(sender, headerOut, HttpAllArgs<decltype(args)>(parser, args), val, invoker); cb(sender, headerOut, HttpAllArgs<decltype(args)>(parser, args), val, invoker);
}; };
@ -152,7 +152,7 @@ static HttpApi toApi(const function<void(API_ARGS_STRING_ASYNC)> &cb) {
Json::Value val; Json::Value val;
val["code"] = API::Success; val["code"] = API::Success;
cb(sender, headerOut, HttpAllArgs<string>(parser, (string &)parser.Content()), val, invoker); cb(sender, headerOut, HttpAllArgs<string>(parser, (string &)parser.content()), val, invoker);
}; };
} }
@ -191,13 +191,13 @@ void api_regist(const string &api_path, const function<void(API_ARGS_STRING_ASYN
static ApiArgsType getAllArgs(const Parser &parser) { static ApiArgsType getAllArgs(const Parser &parser) {
ApiArgsType allArgs; ApiArgsType allArgs;
if (parser["Content-Type"].find("application/x-www-form-urlencoded") == 0) { if (parser["Content-Type"].find("application/x-www-form-urlencoded") == 0) {
auto contentArgs = parser.parseArgs(parser.Content()); auto contentArgs = parser.parseArgs(parser.content());
for (auto &pr : contentArgs) { for (auto &pr : contentArgs) {
allArgs[pr.first] = HttpSession::urlDecode(pr.second); allArgs[pr.first] = HttpSession::urlDecode(pr.second);
} }
} else if (parser["Content-Type"].find("application/json") == 0) { } else if (parser["Content-Type"].find("application/json") == 0) {
try { try {
stringstream ss(parser.Content()); stringstream ss(parser.content());
Value jsonArgs; Value jsonArgs;
ss >> jsonArgs; ss >> jsonArgs;
auto keys = jsonArgs.getMemberNames(); auto keys = jsonArgs.getMemberNames();
@ -231,7 +231,7 @@ static inline void addHttpListener(){
GET_CONFIG(bool, api_debug, API::kApiDebug); GET_CONFIG(bool, api_debug, API::kApiDebug);
//注册监听kBroadcastHttpRequest事件 //注册监听kBroadcastHttpRequest事件
NoticeCenter::Instance().addListener(&web_api_tag, Broadcast::kBroadcastHttpRequest, [](BroadcastHttpRequestArgs) { NoticeCenter::Instance().addListener(&web_api_tag, Broadcast::kBroadcastHttpRequest, [](BroadcastHttpRequestArgs) {
auto it = s_map_api.find(parser.Url()); auto it = s_map_api.find(parser.url());
if (it == s_map_api.end()) { if (it == s_map_api.end()) {
return; return;
} }
@ -248,14 +248,14 @@ static inline void addHttpListener(){
} }
LogContextCapture log(getLogger(), toolkit::LTrace, __FILE__, "http api debug", __LINE__); LogContextCapture log(getLogger(), toolkit::LTrace, __FILE__, "http api debug", __LINE__);
log << "\r\n# request:\r\n" << parser.Method() << " " << parser.FullUrl() << "\r\n"; log << "\r\n# request:\r\n" << parser.method() << " " << parser.fullUrl() << "\r\n";
log << "# header:\r\n"; log << "# header:\r\n";
for (auto &pr : parser.getHeader()) { for (auto &pr : parser.getHeader()) {
log << pr.first << " : " << pr.second << "\r\n"; log << pr.first << " : " << pr.second << "\r\n";
} }
auto &content = parser.Content(); auto &content = parser.content();
log << "# content:\r\n" << (content.size() > 4 * 1024 ? content.substr(0, 4 * 1024) : content) << "\r\n"; log << "# content:\r\n" << (content.size() > 4 * 1024 ? content.substr(0, 4 * 1024) : content) << "\r\n";
if (size > 0 && size < 4 * 1024) { if (size > 0 && size < 4 * 1024) {
@ -1637,7 +1637,7 @@ void installWebApi() {
CHECK_ARGS("app", "stream"); CHECK_ARGS("app", "stream");
return StrPrinter << RTC_SCHEMA << "://" << _args["Host"] << "/" << _args["app"] << "/" return StrPrinter << RTC_SCHEMA << "://" << _args["Host"] << "/" << _args["app"] << "/"
<< _args["stream"] << "?" << _args.getParser().Params() + "&session=" + _session_id; << _args["stream"] << "?" << _args.getParser().params() + "&session=" + _session_id;
} }
private: private:
@ -1700,7 +1700,7 @@ void installWebApi() {
api_regist(delete_webrtc_url, [](API_ARGS_MAP_ASYNC) { api_regist(delete_webrtc_url, [](API_ARGS_MAP_ASYNC) {
CHECK_ARGS("id", "token"); CHECK_ARGS("id", "token");
CHECK(allArgs.getParser().Method() == "DELETE", "http method is not DELETE: " + allArgs.getParser().Method()); CHECK(allArgs.getParser().method() == "DELETE", "http method is not DELETE: " + allArgs.getParser().method());
auto obj = WebRtcTransportManager::Instance().getItem(allArgs["id"]); auto obj = WebRtcTransportManager::Instance().getItem(allArgs["id"]);
if (!obj) { if (!obj) {
invoker(404, headerOut, "id not found"); invoker(404, headerOut, "id not found");

View File

@ -100,14 +100,14 @@ static void parse_http_response(const SockException &ex, const Parser &res, cons
fun(Json::nullValue, errStr, should_retry); fun(Json::nullValue, errStr, should_retry);
return; return;
} }
if (res.Url() != "200") { if (res.status() != "200") {
auto errStr = StrPrinter << "[bad http status code]:" << res.Url() << endl; auto errStr = StrPrinter << "[bad http status code]:" << res.status() << endl;
fun(Json::nullValue, errStr, should_retry); fun(Json::nullValue, errStr, should_retry);
return; return;
} }
Value result; Value result;
try { try {
stringstream ss(res.Content()); stringstream ss(res.content());
ss >> result; ss >> result;
} catch (std::exception &ex) { } catch (std::exception &ex) {
auto errStr = StrPrinter << "[parse json failed]:" << ex.what() << endl; auto errStr = StrPrinter << "[parse json failed]:" << ex.what() << endl;
@ -614,7 +614,7 @@ void installWebHook() {
// 追踪用户的目的是为了缓存上次鉴权结果,减少鉴权次数,提高性能 // 追踪用户的目的是为了缓存上次鉴权结果,减少鉴权次数,提高性能
NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastHttpAccess, [](BroadcastHttpAccessArgs) { NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastHttpAccess, [](BroadcastHttpAccessArgs) {
GET_CONFIG(string, hook_http_access, Hook::kOnHttpAccess); GET_CONFIG(string, hook_http_access, Hook::kOnHttpAccess);
if (sender.get_peer_ip() == "127.0.0.1" || parser.Params() == hook_adminparams) { if (sender.get_peer_ip() == "127.0.0.1" || parser.params() == hook_adminparams) {
// 如果是本机或超级管理员访问那么不做访问鉴权权限有效期1个小时 // 如果是本机或超级管理员访问那么不做访问鉴权权限有效期1个小时
invoker("", "", 60 * 60); invoker("", "", 60 * 60);
return; return;
@ -632,7 +632,7 @@ void installWebHook() {
body["id"] = sender.getIdentifier(); body["id"] = sender.getIdentifier();
body["path"] = path; body["path"] = path;
body["is_dir"] = is_dir; body["is_dir"] = is_dir;
body["params"] = parser.Params(); body["params"] = parser.params();
for (auto &pr : parser.getHeader()) { for (auto &pr : parser.getHeader()) {
body[string("header.") + pr.first] = pr.second; body[string("header.") + pr.first] = pr.second;
} }

View File

@ -363,8 +363,8 @@ int start_main(int argc,char *argv[]) {
#endif//defined(ENABLE_SRT) #endif//defined(ENABLE_SRT)
} catch (std::exception &ex) { } catch (std::exception &ex) {
WarnL << "端口占用或无权限:" << ex.what() << endl; WarnL << "端口占用或无权限:" << ex.what();
ErrorL << "程序启动失败,请修改配置文件中端口号后重试!" << endl; ErrorL << "程序启动失败,请修改配置文件中端口号后重试!";
sleep(1); sleep(1);
#if !defined(_WIN32) #if !defined(_WIN32)
if (pid != getpid() && kill_parent_if_failed) { if (pid != getpid() && kill_parent_if_failed) {

View File

@ -44,7 +44,7 @@ string FindField(const char* buf, const char* start, const char *end ,size_t buf
void Parser::Parse(const char *buf) { void Parser::Parse(const char *buf) {
//解析 //解析
const char *start = buf; const char *start = buf;
Clear(); clear();
while (true) { while (true) {
auto line = FindField(start, NULL, "\r\n"); auto line = FindField(start, NULL, "\r\n");
if (line.size() == 0) { if (line.size() == 0) {
@ -77,25 +77,33 @@ void Parser::Parse(const char *buf) {
} }
} }
const string &Parser::Method() const { const string &Parser::method() const {
return _strMethod; return _strMethod;
} }
const string &Parser::Url() const { const string &Parser::url() const {
return _strUrl; return _strUrl;
} }
string Parser::FullUrl() const { const std::string &Parser::status() const {
return url();
}
string Parser::fullUrl() const {
if (_params.empty()) { if (_params.empty()) {
return _strUrl; return _strUrl;
} }
return _strUrl + "?" + _params; return _strUrl + "?" + _params;
} }
const string &Parser::Tail() const { const string &Parser::protocol() const {
return _strTail; return _strTail;
} }
const std::string &Parser::statusStr() const {
return protocol();
}
const string &Parser::operator[](const char *name) const { const string &Parser::operator[](const char *name) const {
auto it = _mapHeaders.find(name); auto it = _mapHeaders.find(name);
if (it == _mapHeaders.end()) { if (it == _mapHeaders.end()) {
@ -104,11 +112,11 @@ const string &Parser::operator[](const char *name) const {
return it->second; return it->second;
} }
const string &Parser::Content() const { const string &Parser::content() const {
return _strContent; return _strContent;
} }
void Parser::Clear() { void Parser::clear() {
_strMethod.clear(); _strMethod.clear();
_strUrl.clear(); _strUrl.clear();
_params.clear(); _params.clear();
@ -118,7 +126,7 @@ void Parser::Clear() {
_mapUrlArgs.clear(); _mapUrlArgs.clear();
} }
const string &Parser::Params() const { const string &Parser::params() const {
return _params; return _params;
} }
@ -159,7 +167,7 @@ StrCaseMap Parser::parseArgs(const string &str, const char *pair_delim, const ch
} }
return ret; return ret;
} }
std::string Parser::merge_url(const string &base_url, const string &path) { std::string Parser::mergeUrl(const string &base_url, const string &path) {
//以base_url为基础, 合并path路径生成新的url, path支持相对路径和绝对路径 //以base_url为基础, 合并path路径生成新的url, path支持相对路径和绝对路径
if (base_url.empty()) { if (base_url.empty()) {
return path; return path;

View File

@ -17,15 +17,13 @@
namespace mediakit { namespace mediakit {
//从字符串中提取子字符串 // 从字符串中提取子字符串
std::string FindField(const char *buf, const char *start, const char *end, size_t bufSize = 0); std::string FindField(const char *buf, const char *start, const char *end, size_t bufSize = 0);
//把url解析为主机地址和端口号,兼容ipv4/ipv6/dns // 把url解析为主机地址和端口号,兼容ipv4/ipv6/dns
void splitUrl(const std::string &url, std::string &host, uint16_t& port); void splitUrl(const std::string &url, std::string &host, uint16_t &port);
struct StrCaseCompare { struct StrCaseCompare {
bool operator()(const std::string &__x, const std::string &__y) const { bool operator()(const std::string &__x, const std::string &__y) const { return strcasecmp(__x.data(), __y.data()) < 0; }
return strcasecmp(__x.data(), __y.data()) < 0;
}
}; };
class StrCaseMap : public std::multimap<std::string, std::string, StrCaseCompare> { class StrCaseMap : public std::multimap<std::string, std::string, StrCaseCompare> {
@ -42,7 +40,7 @@ public:
return it->second; return it->second;
} }
template<typename V> template <typename V>
void emplace(const std::string &k, V &&v) { void emplace(const std::string &k, V &&v) {
auto it = find(k); auto it = find(k);
if (it != end()) { if (it != end()) {
@ -51,61 +49,65 @@ public:
Super::emplace(k, std::forward<V>(v)); Super::emplace(k, std::forward<V>(v));
} }
template<typename V> template <typename V>
void emplace_force(const std::string k, V &&v) { void emplace_force(const std::string k, V &&v) {
Super::emplace(k, std::forward<V>(v)); Super::emplace(k, std::forward<V>(v));
} }
}; };
//rtsp/http/sip解析类 // rtsp/http/sip解析类
class Parser { class Parser {
public: public:
Parser() = default; Parser() = default;
~Parser() = default; ~Parser() = default;
//解析信令 // 解析信令
void Parse(const char *buf); void Parse(const char *buf);
//获取命令字 // 获取命令字
const std::string &Method() const; const std::string &method() const;
//获取中间url不包含?后面的参数 // 请求时获取中间url不包含?后面的参数
const std::string &Url() const; const std::string &url() const;
// 回复时,获取状态码
const std::string &status() const;
//获取中间url包含?后面的参数 // 获取中间url包含?后面的参数
std::string FullUrl() const; std::string fullUrl() const;
//获取命令协议名 // 请求时,获取协议名
const std::string &Tail() const; const std::string &protocol() const;
// 回复时,获取状态字符串
const std::string &statusStr() const;
//根据header key名获取请求header value值 // 根据header key名获取请求header value值
const std::string &operator[](const char *name) const; const std::string &operator[](const char *name) const;
//获取http body或sdp // 获取http body或sdp
const std::string &Content() const; const std::string &content() const;
//清空,为了重用 // 清空,为了重用
void Clear(); void clear();
//获取?后面的参数 // 获取?后面的参数
const std::string &Params() const; const std::string &params() const;
//重新设置url // 重新设置url
void setUrl(std::string url); void setUrl(std::string url);
//重新设置content // 重新设置content
void setContent(std::string content); void setContent(std::string content);
//获取header列表 // 获取header列表
StrCaseMap &getHeader() const; StrCaseMap &getHeader() const;
//获取url参数列表 // 获取url参数列表
StrCaseMap &getUrlArgs() const; StrCaseMap &getUrlArgs() const;
//解析?后面的参数 // 解析?后面的参数
static StrCaseMap parseArgs(const std::string &str, const char *pair_delim = "&", const char *key_delim = "="); static StrCaseMap parseArgs(const std::string &str, const char *pair_delim = "&", const char *key_delim = "=");
static std::string merge_url(const std::string &base_url, const std::string &path); static std::string mergeUrl(const std::string &base_url, const std::string &path);
private: private:
std::string _strMethod; std::string _strMethod;
@ -118,8 +120,8 @@ private:
mutable StrCaseMap _mapUrlArgs; mutable StrCaseMap _mapUrlArgs;
}; };
//解析rtsp url的工具类 // 解析rtsp url的工具类
class RtspUrl{ class RtspUrl {
public: public:
bool _is_ssl; bool _is_ssl;
uint16_t _port; uint16_t _port;
@ -134,9 +136,9 @@ public:
void parse(const std::string &url); void parse(const std::string &url);
private: private:
void setup(bool,const std::string &, const std::string &, const std::string &); void setup(bool, const std::string &, const std::string &, const std::string &);
}; };
}//namespace mediakit } // namespace mediakit
#endif //ZLMEDIAKIT_PARSER_H #endif // ZLMEDIAKIT_PARSER_H

View File

@ -37,7 +37,7 @@ bool HlsParser::parse(const string &http_url, const string &m3u8) {
if ((_is_m3u8_inner || extinf_dur != 0) && line[0] != '#') { if ((_is_m3u8_inner || extinf_dur != 0) && line[0] != '#') {
segment.duration = extinf_dur; segment.duration = extinf_dur;
segment.url = Parser::merge_url(http_url, line); segment.url = Parser::mergeUrl(http_url, line);
if (!_is_m3u8_inner) { if (!_is_m3u8_inner) {
//ts按照先后顺序排序 //ts按照先后顺序排序
ts_map.emplace(index++, segment); ts_map.emplace(index++, segment);

View File

@ -100,7 +100,7 @@ void HttpClient::clearResponse() {
_header_recved = false; _header_recved = false;
_recved_body_size = 0; _recved_body_size = 0;
_total_body_size = 0; _total_body_size = 0;
_parser.Clear(); _parser.clear();
_chunked_splitter = nullptr; _chunked_splitter = nullptr;
_wait_header.resetTime(); _wait_header.resetTime();
_wait_body.resetTime(); _wait_body.resetTime();
@ -182,19 +182,19 @@ void HttpClient::onError(const SockException &ex) {
ssize_t HttpClient::onRecvHeader(const char *data, size_t len) { ssize_t HttpClient::onRecvHeader(const char *data, size_t len) {
_parser.Parse(data); _parser.Parse(data);
if (_parser.Url() == "302" || _parser.Url() == "301" || _parser.Url() == "303") { if (_parser.status() == "302" || _parser.status() == "301" || _parser.status() == "303") {
auto new_url = Parser::merge_url(_url, _parser["Location"]); auto new_url = Parser::mergeUrl(_url, _parser["Location"]);
if (new_url.empty()) { if (new_url.empty()) {
throw invalid_argument("未找到Location字段(跳转url)"); throw invalid_argument("未找到Location字段(跳转url)");
} }
if (onRedirectUrl(new_url, _parser.Url() == "302")) { if (onRedirectUrl(new_url, _parser.status() == "302")) {
HttpClient::sendRequest(new_url); HttpClient::sendRequest(new_url);
return 0; return 0;
} }
} }
checkCookie(_parser.getHeader()); checkCookie(_parser.getHeader());
onResponseHeader(_parser.Url(), _parser.getHeader()); onResponseHeader(_parser.status(), _parser.getHeader());
_header_recved = true; _header_recved = true;
if (_parser["Transfer-Encoding"] == "chunked") { if (_parser["Transfer-Encoding"] == "chunked") {

View File

@ -240,8 +240,8 @@ public:
static void canAccessPath(Session &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) { const function<void(const string &err_msg, const HttpServerCookie::Ptr &cookie)> &callback) {
//获取用户唯一id //获取用户唯一id
auto uid = parser.Params(); auto uid = parser.params();
auto path = parser.Url(); auto path = parser.url();
//先根据http头中的cookie字段获取cookie //先根据http头中的cookie字段获取cookie
HttpServerCookie::Ptr cookie = HttpCookieManager::Instance().getCookie(kCookieName, parser.getHeader()); HttpServerCookie::Ptr cookie = HttpCookieManager::Instance().getCookie(kCookieName, parser.getHeader());
@ -268,7 +268,7 @@ static void canAccessPath(Session &sender, const Parser &parser, const MediaInfo
return; return;
} }
//上次鉴权失败但是如果url参数发生变更那么也重新鉴权下 //上次鉴权失败但是如果url参数发生变更那么也重新鉴权下
if (parser.Params().empty() || parser.Params() == cookie->getUid()) { if (parser.params().empty() || parser.params() == cookie->getUid()) {
//url参数未变或者本来就没有url参数那么判断本次请求为重复请求无访问权限 //url参数未变或者本来就没有url参数那么判断本次请求为重复请求无访问权限
callback(attach._err_msg, update_cookie ? cookie : nullptr); callback(attach._err_msg, update_cookie ? cookie : nullptr);
return; return;
@ -469,11 +469,11 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, Sess
if (it != virtualPathMap.end()) { if (it != virtualPathMap.end()) {
//访问的是virtualPath //访问的是virtualPath
path = it->second; path = it->second;
url = parser.Url().substr(1 + media_info.app.size()); url = parser.url().substr(1 + media_info.app.size());
} else { } else {
//访问的是rootPath //访问的是rootPath
path = rootPath; path = rootPath;
url = parser.Url(); url = parser.url();
} }
for (auto &ch : url) { for (auto &ch : url) {
if (ch == '\\') { if (ch == '\\') {
@ -493,7 +493,7 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, Sess
* @param cb * @param cb
*/ */
void HttpFileManager::onAccessPath(Session &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(); auto fullUrl = string(HTTP_SCHEMA) + "://" + parser["Host"] + parser.fullUrl();
MediaInfo media_info(fullUrl); MediaInfo media_info(fullUrl);
auto file_path = getFilePath(parser, media_info, sender); auto file_path = getFilePath(parser, media_info, sender);
if (file_path.size() == 0) { if (file_path.size() == 0) {
@ -506,13 +506,13 @@ void HttpFileManager::onAccessPath(Session &sender, Parser &parser, const HttpFi
if (!indexFile.empty()) { if (!indexFile.empty()) {
//发现该文件夹下有index文件 //发现该文件夹下有index文件
file_path = pathCat(file_path, indexFile); file_path = pathCat(file_path, indexFile);
parser.setUrl(pathCat(parser.Url(), indexFile)); parser.setUrl(pathCat(parser.url(), indexFile));
accessFile(sender, parser, media_info, file_path, cb); accessFile(sender, parser, media_info, file_path, cb);
return; return;
} }
string strMenu; string strMenu;
//生成文件夹菜单索引 //生成文件夹菜单索引
if (!makeFolderMenu(parser.Url(), file_path, strMenu)) { if (!makeFolderMenu(parser.url(), file_path, strMenu)) {
//文件夹不存在 //文件夹不存在
sendNotFound(cb); sendNotFound(cb);
return; return;

View File

@ -64,10 +64,10 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
}); });
_parser.Parse(header); _parser.Parse(header);
CHECK(_parser.Url()[0] == '/'); CHECK(_parser.url()[0] == '/');
urlDecode(_parser); urlDecode(_parser);
string cmd = _parser.Method(); string cmd = _parser.method();
auto it = s_func_map.find(cmd); auto it = s_func_map.find(cmd);
if (it == s_func_map.end()) { if (it == s_func_map.end()) {
WarnP(this) << "不支持该命令:" << cmd; WarnP(this) << "不支持该命令:" << cmd;
@ -80,7 +80,7 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
(this->*(it->second))(content_len); (this->*(it->second))(content_len);
// 清空解析器节省内存 // 清空解析器节省内存
_parser.Clear(); _parser.clear();
// 返回content长度 // 返回content长度
return content_len; return content_len;
} }
@ -173,7 +173,7 @@ bool HttpSession::checkWebSocket() {
} }
bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix, const function<void(const MediaSource::Ptr &src)> &cb) { bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix, const function<void(const MediaSource::Ptr &src)> &cb) {
std::string url = _parser.Url(); std::string url = _parser.url();
auto it = _parser.getUrlArgs().find("schema"); auto it = _parser.getUrlArgs().find("schema");
if (it != _parser.getUrlArgs().end()) { if (it != _parser.getUrlArgs().end()) {
if (strcasecmp(it->second.c_str(), schema.c_str())) { if (strcasecmp(it->second.c_str(), schema.c_str())) {
@ -191,9 +191,9 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix
} }
// 带参数的url // 带参数的url
if (!_parser.Params().empty()) { if (!_parser.params().empty()) {
url += "?"; url += "?";
url += _parser.Params(); url += _parser.params();
} }
// 解析带上协议+参数完整的url // 解析带上协议+参数完整的url
@ -616,7 +616,7 @@ string HttpSession::urlDecode(const string &str) {
} }
void HttpSession::urlDecode(Parser &parser) { void HttpSession::urlDecode(Parser &parser) {
parser.setUrl(urlDecode(parser.Url())); parser.setUrl(urlDecode(parser.url()));
for (auto &pr : _parser.getUrlArgs()) { for (auto &pr : _parser.getUrlArgs()) {
const_cast<string &>(pr.second) = urlDecode(pr.second); const_cast<string &>(pr.second) = urlDecode(pr.second);
} }
@ -682,7 +682,7 @@ void HttpSession::Handle_Req_POST(ssize_t &content_len) {
// 触发http事件emitHttpEvent内部会选择是否关闭连接 // 触发http事件emitHttpEvent内部会选择是否关闭连接
emitHttpEvent(true); emitHttpEvent(true);
// 清空数据,节省内存 // 清空数据,节省内存
_parser.Clear(); _parser.clear();
// content已经接收完毕 // content已经接收完毕
return false; return false;
}; };

View File

@ -27,7 +27,7 @@ namespace mediakit {
RtmpPlayer::RtmpPlayer(const EventPoller::Ptr &poller) : TcpClient(poller) {} RtmpPlayer::RtmpPlayer(const EventPoller::Ptr &poller) : TcpClient(poller) {}
RtmpPlayer::~RtmpPlayer() { RtmpPlayer::~RtmpPlayer() {
DebugL << endl; DebugL;
} }
void RtmpPlayer::teardown() { void RtmpPlayer::teardown() {

View File

@ -27,7 +27,7 @@ public:
RtmpPlayerImp(const toolkit::EventPoller::Ptr &poller) : Super(poller) {}; RtmpPlayerImp(const toolkit::EventPoller::Ptr &poller) : Super(poller) {};
~RtmpPlayerImp() override { ~RtmpPlayerImp() override {
DebugL << std::endl; DebugL;
} }
float getProgress() const override { float getProgress() const override {

View File

@ -27,7 +27,7 @@ RtmpPusher::RtmpPusher(const EventPoller::Ptr &poller, const RtmpMediaSource::Pt
RtmpPusher::~RtmpPusher() { RtmpPusher::~RtmpPusher() {
teardown(); teardown();
DebugL << endl; DebugL;
} }
void RtmpPusher::teardown() { void RtmpPusher::teardown() {

View File

@ -33,7 +33,7 @@ RtspPlayer::RtspPlayer(const EventPoller::Ptr &poller)
: TcpClient(poller) {} : TcpClient(poller) {}
RtspPlayer::~RtspPlayer(void) { RtspPlayer::~RtspPlayer(void) {
DebugL << endl; DebugL;
} }
void RtspPlayer::sendTeardown() { void RtspPlayer::sendTeardown() {
@ -170,11 +170,11 @@ bool RtspPlayer::handleAuthenticationFailure(const string &paramsStr) {
bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser) { bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser) {
string authInfo = parser["WWW-Authenticate"]; string authInfo = parser["WWW-Authenticate"];
// 发送DESCRIBE命令后的回复 // 发送DESCRIBE命令后的回复
if ((parser.Url() == "401") && handleAuthenticationFailure(authInfo)) { if ((parser.status() == "401") && handleAuthenticationFailure(authInfo)) {
sendOptions(); sendOptions();
return false; return false;
} }
if (parser.Url() == "302" || parser.Url() == "301") { if (parser.status() == "302" || parser.status() == "301") {
auto newUrl = parser["Location"]; auto newUrl = parser["Location"];
if (newUrl.empty()) { if (newUrl.empty()) {
throw std::runtime_error("未找到Location字段(跳转url)"); throw std::runtime_error("未找到Location字段(跳转url)");
@ -182,8 +182,8 @@ bool RtspPlayer::handleResponse(const string &cmd, const Parser &parser) {
play(newUrl); play(newUrl);
return false; return false;
} }
if (parser.Url() != "200") { if (parser.status() != "200") {
throw std::runtime_error(StrPrinter << cmd << ":" << parser.Url() << " " << parser.Tail() << endl); throw std::runtime_error(StrPrinter << cmd << ":" << parser.status() << " " << parser.statusStr() << endl);
} }
return true; return true;
} }
@ -201,7 +201,7 @@ void RtspPlayer::handleResDESCRIBE(const Parser &parser) {
} }
// 解析sdp // 解析sdp
SdpParser sdpParser(parser.Content()); SdpParser sdpParser(parser.content());
string sdp; string sdp;
auto play_track = (TrackType)((int)(*this)[Client::kPlayTrack] - 1); auto play_track = (TrackType)((int)(*this)[Client::kPlayTrack] - 1);
@ -267,8 +267,8 @@ void RtspPlayer::sendSetup(unsigned int track_idx) {
} }
void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int track_idx) { void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int track_idx) {
if (parser.Url() != "200") { if (parser.status() != "200") {
throw std::runtime_error(StrPrinter << "SETUP:" << parser.Url() << " " << parser.Tail() << endl); throw std::runtime_error(StrPrinter << "SETUP:" << parser.status() << " " << parser.statusStr() << endl);
} }
if (track_idx == 0) { if (track_idx == 0) {
_session_id = parser["Session"]; _session_id = parser["Session"];
@ -446,14 +446,14 @@ void RtspPlayer::speed(float speed) {
} }
void RtspPlayer::handleResPAUSE(const Parser &parser, int type) { void RtspPlayer::handleResPAUSE(const Parser &parser, int type) {
if (parser.Url() != "200") { if (parser.status() != "200") {
switch (type) { switch (type) {
case type_pause: WarnL << "Pause failed:" << parser.Url() << " " << parser.Tail() << endl; break; case type_pause: WarnL << "Pause failed:" << parser.status() << " " << parser.statusStr(); break;
case type_play: case type_play:
WarnL << "Play failed:" << parser.Url() << " " << parser.Tail() << endl; WarnL << "Play failed:" << parser.status() << " " << parser.statusStr();
onPlayResult_l(SockException(Err_shutdown, StrPrinter << "rtsp play failed:" << parser.Url() << " " << parser.Tail()), !_play_check_timer); onPlayResult_l(SockException(Err_shutdown, StrPrinter << "rtsp play failed:" << parser.status() << " " << parser.statusStr()), !_play_check_timer);
break; break;
case type_seek: WarnL << "Seek failed:" << parser.Url() << " " << parser.Tail() << endl; break; case type_seek: WarnL << "Seek failed:" << parser.status() << " " << parser.statusStr(); break;
} }
return; return;
} }
@ -487,7 +487,7 @@ void RtspPlayer::onWholeRtspPacket(Parser &parser) {
if (func) { if (func) {
func(parser); func(parser);
} }
parser.Clear(); parser.clear();
} catch (std::exception &err) { } catch (std::exception &err) {
// 定时器_pPlayTimer为空后表明握手结束了 // 定时器_pPlayTimer为空后表明握手结束了
onPlayResult_l(SockException(Err_other, err.what()), !_play_check_timer); onPlayResult_l(SockException(Err_other, err.what()), !_play_check_timer);

View File

@ -28,7 +28,7 @@ public:
RtspPlayerImp(const toolkit::EventPoller::Ptr &poller) : Super(poller) {} RtspPlayerImp(const toolkit::EventPoller::Ptr &poller) : Super(poller) {}
~RtspPlayerImp() override { ~RtspPlayerImp() override {
DebugL << std::endl; DebugL;
} }
float getProgress() const override { float getProgress() const override {

View File

@ -26,7 +26,7 @@ RtspPusher::RtspPusher(const EventPoller::Ptr &poller, const RtspMediaSource::Pt
RtspPusher::~RtspPusher() { RtspPusher::~RtspPusher() {
teardown(); teardown();
DebugL << endl; DebugL;
} }
void RtspPusher::sendTeardown(){ void RtspPusher::sendTeardown(){
@ -147,7 +147,7 @@ void RtspPusher::onWholeRtspPacket(Parser &parser) {
if (func) { if (func) {
func(parser); func(parser);
} }
parser.Clear(); parser.clear();
} }
void RtspPusher::onRtpPacket(const char *data, size_t len) { void RtspPusher::onRtpPacket(const char *data, size_t len) {
@ -188,11 +188,11 @@ void RtspPusher::sendAnnounce() {
void RtspPusher::handleResAnnounce(const Parser &parser) { void RtspPusher::handleResAnnounce(const Parser &parser) {
string authInfo = parser["WWW-Authenticate"]; string authInfo = parser["WWW-Authenticate"];
//发送DESCRIBE命令后的回复 //发送DESCRIBE命令后的回复
if ((parser.Url() == "401") && handleAuthenticationFailure(authInfo)) { if ((parser.status() == "401") && handleAuthenticationFailure(authInfo)) {
sendAnnounce(); sendAnnounce();
return; return;
} }
if (parser.Url() == "302") { if (parser.status() == "302") {
auto newUrl = parser["Location"]; auto newUrl = parser["Location"];
if (newUrl.empty()) { if (newUrl.empty()) {
throw std::runtime_error("未找到Location字段(跳转url)"); throw std::runtime_error("未找到Location字段(跳转url)");
@ -200,8 +200,8 @@ void RtspPusher::handleResAnnounce(const Parser &parser) {
publish(newUrl); publish(newUrl);
return; return;
} }
if (parser.Url() != "200") { if (parser.status() != "200") {
throw std::runtime_error(StrPrinter << "ANNOUNCE:" << parser.Url() << " " << parser.Tail()); throw std::runtime_error(StrPrinter << "ANNOUNCE:" << parser.status() << " " << parser.statusStr());
} }
_content_base = parser["Content-Base"]; _content_base = parser["Content-Base"];
@ -285,8 +285,8 @@ void RtspPusher::sendSetup(unsigned int track_idx) {
} }
void RtspPusher::handleResSetup(const Parser &parser, unsigned int track_idx) { void RtspPusher::handleResSetup(const Parser &parser, unsigned int track_idx) {
if (parser.Url() != "200") { if (parser.status() != "200") {
throw std::runtime_error(StrPrinter << "SETUP:" << parser.Url() << " " << parser.Tail() << endl); throw std::runtime_error(StrPrinter << "SETUP:" << parser.status() << " " << parser.statusStr() << endl);
} }
if (track_idx == 0) { if (track_idx == 0) {
_session_id = parser["Session"]; _session_id = parser["Session"];

View File

@ -128,11 +128,11 @@ void RtspSession::onRecv(const Buffer::Ptr &buf) {
} }
void RtspSession::onWholeRtspPacket(Parser &parser) { void RtspSession::onWholeRtspPacket(Parser &parser) {
string method = parser.Method(); //提取出请求命令字 string method = parser.method(); //提取出请求命令字
_cseq = atoi(parser["CSeq"].data()); _cseq = atoi(parser["CSeq"].data());
if (_content_base.empty() && method != "GET") { if (_content_base.empty() && method != "GET") {
_content_base = parser.Url(); _content_base = parser.url();
_media_info.parse(parser.FullUrl()); _media_info.parse(parser.fullUrl());
_media_info.schema = RTSP_SCHEMA; _media_info.schema = RTSP_SCHEMA;
} }
@ -160,7 +160,7 @@ void RtspSession::onWholeRtspPacket(Parser &parser) {
} }
(this->*(it->second))(parser); (this->*(it->second))(parser);
parser.Clear(); parser.clear();
} }
void RtspSession::onRtpPacket(const char *data, size_t len) { void RtspSession::onRtpPacket(const char *data, size_t len) {
@ -187,7 +187,7 @@ void RtspSession::onRtcpPacket(int track_idx, SdpTrack::Ptr &track, const char *
} }
ssize_t RtspSession::getContentLength(Parser &parser) { ssize_t RtspSession::getContentLength(Parser &parser) {
if(parser.Method() == "POST"){ if(parser.method() == "POST"){
//http post请求的content数据部分是base64编码后的rtsp请求信令包 //http post请求的content数据部分是base64编码后的rtsp请求信令包
return remainDataSize(); return remainDataSize();
} }
@ -200,7 +200,7 @@ void RtspSession::handleReq_Options(const Parser &parser) {
} }
void RtspSession::handleReq_ANNOUNCE(const Parser &parser) { void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
auto full_url = parser.FullUrl(); auto full_url = parser.fullUrl();
_content_base = full_url; _content_base = full_url;
if (end_with(full_url, ".sdp")) { if (end_with(full_url, ".sdp")) {
//去除.sdp后缀防止EasyDarwin推流器强制添加.sdp后缀 //去除.sdp后缀防止EasyDarwin推流器强制添加.sdp后缀
@ -250,7 +250,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
throw SockException(Err_shutdown, err); throw SockException(Err_shutdown, err);
} }
SdpParser sdpParser(parser.Content()); SdpParser sdpParser(parser.content());
_sessionid = makeRandStr(12); _sessionid = makeRandStr(12);
_sdp_track = sdpParser.getAvailableTrack(); _sdp_track = sdpParser.getAvailableTrack();
if (_sdp_track.empty()) { if (_sdp_track.empty()) {
@ -270,7 +270,7 @@ void RtspSession::handleReq_ANNOUNCE(const Parser &parser) {
//获取所有权 //获取所有权
_push_src_ownership = _push_src->getOwnership(); _push_src_ownership = _push_src->getOwnership();
_push_src->setProtocolOption(option); _push_src->setProtocolOption(option);
_push_src->setSdp(parser.Content()); _push_src->setSdp(parser.content());
} }
_push_src->setListener(static_pointer_cast<RtspSession>(shared_from_this())); _push_src->setListener(static_pointer_cast<RtspSession>(shared_from_this()));
@ -628,7 +628,7 @@ void RtspSession::send_SessionNotFound() {
void RtspSession::handleReq_Setup(const Parser &parser) { void RtspSession::handleReq_Setup(const Parser &parser) {
//处理setup命令该函数可能进入多次 //处理setup命令该函数可能进入多次
int trackIdx = getTrackIndexByControlUrl(parser.FullUrl()); int trackIdx = getTrackIndexByControlUrl(parser.fullUrl());
SdpTrack::Ptr &trackRef = _sdp_track[trackIdx]; SdpTrack::Ptr &trackRef = _sdp_track[trackIdx];
if (trackRef->_inited) { if (trackRef->_inited) {
//已经初始化过该Track //已经初始化过该Track
@ -915,9 +915,9 @@ void RtspSession::handleReq_Post(const Parser &parser) {
}); });
}; };
if(!parser.Content().empty()){ if(!parser.content().empty()){
//http poster后面的粘包 //http poster后面的粘包
_on_recv(std::make_shared<BufferString>(parser.Content())); _on_recv(std::make_shared<BufferString>(parser.content()));
} }
sendRtspResponse("200 OK", sendRtspResponse("200 OK",

View File

@ -65,7 +65,7 @@ ssize_t RtspSplitter::onRecvHeader(const char *data, size_t len) {
auto ret = getContentLength(_parser); auto ret = getContentLength(_parser);
if(ret == 0){ if(ret == 0){
onWholeRtspPacket(_parser); onWholeRtspPacket(_parser);
_parser.Clear(); _parser.clear();
} }
return ret; return ret;
} }
@ -73,7 +73,7 @@ ssize_t RtspSplitter::onRecvHeader(const char *data, size_t len) {
void RtspSplitter::onRecvContent(const char *data, size_t len) { void RtspSplitter::onRecvContent(const char *data, size_t len) {
_parser.setContent(string(data,len)); _parser.setContent(string(data,len));
onWholeRtspPacket(_parser); onWholeRtspPacket(_parser);
_parser.Clear(); _parser.clear();
} }
void RtspSplitter::enableRecvRtp(bool enable) { void RtspSplitter::enableRecvRtp(bool enable) {

View File

@ -43,7 +43,7 @@ void initEventListener(){
static onceToken s_token([](){ static onceToken s_token([](){
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastHttpRequest,[](BroadcastHttpRequestArgs){ NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastHttpRequest,[](BroadcastHttpRequestArgs){
//const Parser &parser,HttpSession::HttpResponseInvoker &invoker,bool &consumed //const Parser &parser,HttpSession::HttpResponseInvoker &invoker,bool &consumed
if(strstr(parser.Url().data(),"/api/") != parser.Url().data()){ if(strstr(parser.url().data(),"/api/") != parser.url().data()){
return; return;
} }
//url以"/api/起始说明是http api" //url以"/api/起始说明是http api"
@ -51,11 +51,11 @@ void initEventListener(){
_StrPrinter printer; _StrPrinter printer;
////////////////method//////////////////// ////////////////method////////////////////
printer << "\r\nmethod:\r\n\t" << parser.Method(); printer << "\r\nmethod:\r\n\t" << parser.method();
////////////////url///////////////// ////////////////url/////////////////
printer << "\r\nurl:\r\n\t" << parser.Url(); printer << "\r\nurl:\r\n\t" << parser.url();
////////////////protocol///////////////// ////////////////protocol/////////////////
printer << "\r\nprotocol:\r\n\t" << parser.Tail(); printer << "\r\nprotocol:\r\n\t" << parser.protocol();
///////////////args////////////////// ///////////////args//////////////////
printer << "\r\nargs:\r\n"; printer << "\r\nargs:\r\n";
for(auto &pr : parser.getUrlArgs()){ for(auto &pr : parser.getUrlArgs()){
@ -67,7 +67,7 @@ void initEventListener(){
printer << "\t" << pr.first << " : " << pr.second << "\r\n"; printer << "\t" << pr.first << " : " << pr.second << "\r\n";
} }
////////////////content///////////////// ////////////////content/////////////////
printer << "\r\ncontent:\r\n" << parser.Content(); printer << "\r\ncontent:\r\n" << parser.content();
auto contentOut = printer << endl; auto contentOut = printer << endl;
////////////////我们测算异步回复,当然你也可以同步回复///////////////// ////////////////我们测算异步回复,当然你也可以同步回复/////////////////
@ -113,7 +113,7 @@ int main(int argc,char *argv[]){
TcpServer::Ptr httpsSrv(new TcpServer()); TcpServer::Ptr httpsSrv(new TcpServer());
httpsSrv->start<HttpsSession>(mINI::Instance()[Http::kSSLPort]);//默认443 httpsSrv->start<HttpsSession>(mINI::Instance()[Http::kSSLPort]);//默认443
InfoL << "你可以在浏览器输入:http://127.0.0.1/api/my_api?key0=val0&key1=参数1" << endl; InfoL << "你可以在浏览器输入:http://127.0.0.1/api/my_api?key0=val0&key1=参数1";
sem.wait(); sem.wait();
return 0; return 0;

View File

@ -86,9 +86,9 @@ int main(int argc, char *argv[]) {
for (auto &pr: parser.getHeader()) { for (auto &pr: parser.getHeader()) {
printer << pr.first << ":" << pr.second << "\r\n"; printer << pr.first << ":" << pr.second << "\r\n";
} }
InfoL << "status:" << parser.Url() << "\r\n" InfoL << "status:" << parser.status() << "\r\n"
<< "header:\r\n" << (printer << endl) << "header:\r\n" << (printer << endl)
<< "\r\nbody:" << parser.Content(); << "\r\nbody:" << parser.content();
} }
}); });
@ -122,9 +122,9 @@ int main(int argc, char *argv[]) {
for (auto &pr: parser.getHeader()) { for (auto &pr: parser.getHeader()) {
printer << pr.first << ":" << pr.second << "\r\n"; printer << pr.first << ":" << pr.second << "\r\n";
} }
InfoL << "status:" << parser.Url() << "\r\n" InfoL << "status:" << parser.status() << "\r\n"
<< "header:\r\n" << (printer << endl) << "header:\r\n" << (printer << endl)
<< "\r\nbody:" << parser.Content(); << "\r\nbody:" << parser.content();
} }
}); });
@ -159,9 +159,9 @@ int main(int argc, char *argv[]) {
for (auto &pr: parser.getHeader()) { for (auto &pr: parser.getHeader()) {
printer << pr.first << ":" << pr.second << "\r\n"; printer << pr.first << ":" << pr.second << "\r\n";
} }
InfoL << "status:" << parser.Url() << "\r\n" InfoL << "status:" << parser.status() << "\r\n"
<< "header:\r\n" << (printer << endl) << "header:\r\n" << (printer << endl)
<< "\r\nbody:" << parser.Content(); << "\r\nbody:" << parser.content();
} }
}); });

View File

@ -83,7 +83,7 @@ struct EchoSessionCreator {
//返回的Session必须派生于SendInterceptor可以返回null(拒绝连接) //返回的Session必须派生于SendInterceptor可以返回null(拒绝连接)
Session::Ptr operator()(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock) { Session::Ptr operator()(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock) {
// return nullptr; // return nullptr;
if (header.Url() == "/") { if (header.url() == "/") {
return std::make_shared<SessionTypeImp<EchoSession> >(header, parent, pSock); return std::make_shared<SessionTypeImp<EchoSession> >(header, parent, pSock);
} }
return std::make_shared<SessionTypeImp<EchoSessionWithUrl> >(header, parent, pSock); return std::make_shared<SessionTypeImp<EchoSessionWithUrl> >(header, parent, pSock);

View File

@ -323,7 +323,7 @@ void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tup
if (RTC::StunPacket::IsStun((const uint8_t *)buf, len)) { if (RTC::StunPacket::IsStun((const uint8_t *)buf, len)) {
std::unique_ptr<RTC::StunPacket> packet(RTC::StunPacket::Parse((const uint8_t *)buf, len)); std::unique_ptr<RTC::StunPacket> packet(RTC::StunPacket::Parse((const uint8_t *)buf, len));
if (!packet) { if (!packet) {
WarnL << "parse stun error" << std::endl; WarnL << "parse stun error";
return; return;
} }
_ice_server->ProcessStunPacket(packet.get(), tuple); _ice_server->ProcessStunPacket(packet.get(), tuple);