优化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

@@ -130,7 +130,7 @@ static HttpApi toApi(const function<void(API_ARGS_JSON_ASYNC)> &cb) {
//参数解析成json对象然后处理
Json::Value args;
Json::Reader reader;
reader.parse(parser.Content(), args);
reader.parse(parser.content(), args);
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;
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) {
ApiArgsType allArgs;
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) {
allArgs[pr.first] = HttpSession::urlDecode(pr.second);
}
} else if (parser["Content-Type"].find("application/json") == 0) {
try {
stringstream ss(parser.Content());
stringstream ss(parser.content());
Value jsonArgs;
ss >> jsonArgs;
auto keys = jsonArgs.getMemberNames();
@@ -231,7 +231,7 @@ static inline void addHttpListener(){
GET_CONFIG(bool, api_debug, API::kApiDebug);
//注册监听kBroadcastHttpRequest事件
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()) {
return;
}
@@ -248,14 +248,14 @@ static inline void addHttpListener(){
}
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";
for (auto &pr : parser.getHeader()) {
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";
if (size > 0 && size < 4 * 1024) {
@@ -1637,7 +1637,7 @@ void installWebApi() {
CHECK_ARGS("app", "stream");
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:
@@ -1700,7 +1700,7 @@ void installWebApi() {
api_regist(delete_webrtc_url, [](API_ARGS_MAP_ASYNC) {
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"]);
if (!obj) {
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);
return;
}
if (res.Url() != "200") {
auto errStr = StrPrinter << "[bad http status code]:" << res.Url() << endl;
if (res.status() != "200") {
auto errStr = StrPrinter << "[bad http status code]:" << res.status() << endl;
fun(Json::nullValue, errStr, should_retry);
return;
}
Value result;
try {
stringstream ss(res.Content());
stringstream ss(res.content());
ss >> result;
} catch (std::exception &ex) {
auto errStr = StrPrinter << "[parse json failed]:" << ex.what() << endl;
@@ -614,7 +614,7 @@ void installWebHook() {
// 追踪用户的目的是为了缓存上次鉴权结果,减少鉴权次数,提高性能
NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastHttpAccess, [](BroadcastHttpAccessArgs) {
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个小时
invoker("", "", 60 * 60);
return;
@@ -632,7 +632,7 @@ void installWebHook() {
body["id"] = sender.getIdentifier();
body["path"] = path;
body["is_dir"] = is_dir;
body["params"] = parser.Params();
body["params"] = parser.params();
for (auto &pr : parser.getHeader()) {
body[string("header.") + pr.first] = pr.second;
}

View File

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