#pragma once #include "Request.h" #include "Response.h" #include "Session.h" #include "json.hpp" #include "jsonfail.h" #include "Util.h" using json=nlohmann::json; /// General Json Failure Function. void jsonfail_func(json& j,int errcode,const std::string& detail=""); /// Get Permission of User /// If failed to get level, error message will be written to Response in JSON style. Then exit(0) is called. /// If success, returns permission_level. /// Returns -1 if control flow reaches unknown branch. int getPermissionLevel(const std::string& Username,Response& res); std::function SQLParseInt(int& nval); #define default_jsonfail() auto jsonfail=[&](int errcode,const std::string& dtl=""){jsonfail_func(j,errcode,dtl);} #define postval(NAME) if(req.post[#NAME].empty()){jsonfail(err_missing_parameter,#NAME);break;}string NAME=req.post[#NAME] #define startdb() DBInfo db;if(db.readConfig()<0){jsonfail(err_config);break;} MySQLConn conn;if(db.connectProxy(conn)<0){jsonfail(err_connect);break;}if(conn.exec("set names utf8",nullptr)<0){jsonfail(err_sql,"Failed to set names");break;}