mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-14 12:05:58 +08:00
优化Parser代码命名
This commit is contained in:
@@ -37,7 +37,7 @@ bool HlsParser::parse(const string &http_url, const string &m3u8) {
|
||||
|
||||
if ((_is_m3u8_inner || extinf_dur != 0) && line[0] != '#') {
|
||||
segment.duration = extinf_dur;
|
||||
segment.url = Parser::merge_url(http_url, line);
|
||||
segment.url = Parser::mergeUrl(http_url, line);
|
||||
if (!_is_m3u8_inner) {
|
||||
//ts按照先后顺序排序
|
||||
ts_map.emplace(index++, segment);
|
||||
|
||||
@@ -100,7 +100,7 @@ void HttpClient::clearResponse() {
|
||||
_header_recved = false;
|
||||
_recved_body_size = 0;
|
||||
_total_body_size = 0;
|
||||
_parser.Clear();
|
||||
_parser.clear();
|
||||
_chunked_splitter = nullptr;
|
||||
_wait_header.resetTime();
|
||||
_wait_body.resetTime();
|
||||
@@ -182,19 +182,19 @@ void HttpClient::onError(const SockException &ex) {
|
||||
|
||||
ssize_t HttpClient::onRecvHeader(const char *data, size_t len) {
|
||||
_parser.Parse(data);
|
||||
if (_parser.Url() == "302" || _parser.Url() == "301" || _parser.Url() == "303") {
|
||||
auto new_url = Parser::merge_url(_url, _parser["Location"]);
|
||||
if (_parser.status() == "302" || _parser.status() == "301" || _parser.status() == "303") {
|
||||
auto new_url = Parser::mergeUrl(_url, _parser["Location"]);
|
||||
if (new_url.empty()) {
|
||||
throw invalid_argument("未找到Location字段(跳转url)");
|
||||
}
|
||||
if (onRedirectUrl(new_url, _parser.Url() == "302")) {
|
||||
if (onRedirectUrl(new_url, _parser.status() == "302")) {
|
||||
HttpClient::sendRequest(new_url);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
checkCookie(_parser.getHeader());
|
||||
onResponseHeader(_parser.Url(), _parser.getHeader());
|
||||
onResponseHeader(_parser.status(), _parser.getHeader());
|
||||
_header_recved = true;
|
||||
|
||||
if (_parser["Transfer-Encoding"] == "chunked") {
|
||||
|
||||
@@ -240,8 +240,8 @@ public:
|
||||
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();
|
||||
auto path = parser.Url();
|
||||
auto uid = parser.params();
|
||||
auto path = parser.url();
|
||||
|
||||
//先根据http头中的cookie字段获取cookie
|
||||
HttpServerCookie::Ptr cookie = HttpCookieManager::Instance().getCookie(kCookieName, parser.getHeader());
|
||||
@@ -268,7 +268,7 @@ static void canAccessPath(Session &sender, const Parser &parser, const MediaInfo
|
||||
return;
|
||||
}
|
||||
//上次鉴权失败,但是如果url参数发生变更,那么也重新鉴权下
|
||||
if (parser.Params().empty() || parser.Params() == cookie->getUid()) {
|
||||
if (parser.params().empty() || parser.params() == cookie->getUid()) {
|
||||
//url参数未变,或者本来就没有url参数,那么判断本次请求为重复请求,无访问权限
|
||||
callback(attach._err_msg, update_cookie ? cookie : nullptr);
|
||||
return;
|
||||
@@ -469,11 +469,11 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, Sess
|
||||
if (it != virtualPathMap.end()) {
|
||||
//访问的是virtualPath
|
||||
path = it->second;
|
||||
url = parser.Url().substr(1 + media_info.app.size());
|
||||
url = parser.url().substr(1 + media_info.app.size());
|
||||
} else {
|
||||
//访问的是rootPath
|
||||
path = rootPath;
|
||||
url = parser.Url();
|
||||
url = parser.url();
|
||||
}
|
||||
for (auto &ch : url) {
|
||||
if (ch == '\\') {
|
||||
@@ -493,7 +493,7 @@ static string getFilePath(const Parser &parser,const MediaInfo &media_info, Sess
|
||||
* @param 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);
|
||||
auto file_path = getFilePath(parser, media_info, sender);
|
||||
if (file_path.size() == 0) {
|
||||
@@ -506,13 +506,13 @@ void HttpFileManager::onAccessPath(Session &sender, Parser &parser, const HttpFi
|
||||
if (!indexFile.empty()) {
|
||||
//发现该文件夹下有index文件
|
||||
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);
|
||||
return;
|
||||
}
|
||||
string strMenu;
|
||||
//生成文件夹菜单索引
|
||||
if (!makeFolderMenu(parser.Url(), file_path, strMenu)) {
|
||||
if (!makeFolderMenu(parser.url(), file_path, strMenu)) {
|
||||
//文件夹不存在
|
||||
sendNotFound(cb);
|
||||
return;
|
||||
|
||||
@@ -64,10 +64,10 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
|
||||
});
|
||||
|
||||
_parser.Parse(header);
|
||||
CHECK(_parser.Url()[0] == '/');
|
||||
CHECK(_parser.url()[0] == '/');
|
||||
|
||||
urlDecode(_parser);
|
||||
string cmd = _parser.Method();
|
||||
string cmd = _parser.method();
|
||||
auto it = s_func_map.find(cmd);
|
||||
if (it == s_func_map.end()) {
|
||||
WarnP(this) << "不支持该命令:" << cmd;
|
||||
@@ -80,7 +80,7 @@ ssize_t HttpSession::onRecvHeader(const char *header, size_t len) {
|
||||
(this->*(it->second))(content_len);
|
||||
|
||||
// 清空解析器节省内存
|
||||
_parser.Clear();
|
||||
_parser.clear();
|
||||
// 返回content长度
|
||||
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) {
|
||||
std::string url = _parser.Url();
|
||||
std::string url = _parser.url();
|
||||
auto it = _parser.getUrlArgs().find("schema");
|
||||
if (it != _parser.getUrlArgs().end()) {
|
||||
if (strcasecmp(it->second.c_str(), schema.c_str())) {
|
||||
@@ -191,9 +191,9 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffix
|
||||
}
|
||||
|
||||
// 带参数的url
|
||||
if (!_parser.Params().empty()) {
|
||||
if (!_parser.params().empty()) {
|
||||
url += "?";
|
||||
url += _parser.Params();
|
||||
url += _parser.params();
|
||||
}
|
||||
|
||||
// 解析带上协议+参数完整的url
|
||||
@@ -616,7 +616,7 @@ string HttpSession::urlDecode(const string &str) {
|
||||
}
|
||||
|
||||
void HttpSession::urlDecode(Parser &parser) {
|
||||
parser.setUrl(urlDecode(parser.Url()));
|
||||
parser.setUrl(urlDecode(parser.url()));
|
||||
for (auto &pr : _parser.getUrlArgs()) {
|
||||
const_cast<string &>(pr.second) = urlDecode(pr.second);
|
||||
}
|
||||
@@ -682,7 +682,7 @@ void HttpSession::Handle_Req_POST(ssize_t &content_len) {
|
||||
// 触发http事件,emitHttpEvent内部会选择是否关闭连接
|
||||
emitHttpEvent(true);
|
||||
// 清空数据,节省内存
|
||||
_parser.Clear();
|
||||
_parser.clear();
|
||||
// content已经接收完毕
|
||||
return false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user