Merge pull request #74 from Douwanna/release/2.4

Update Notes.
This commit is contained in:
FrankLee 2020-05-20 11:36:45 +08:00 committed by GitHub
commit 184ae46225
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 204 additions and 85 deletions

View File

@ -14,6 +14,7 @@ namespace tars
/////////////////////////////////////////////////
/**
* @file tc_cas_queue.h
* @brief Lock-Free Thread
* @brief 线
*
* @author ruanshudong@qq.com
@ -21,6 +22,7 @@ namespace tars
/////////////////////////////////////////////////
/**
* @brief Thread Safe Queue
* @brief 线
*/
template<typename T, typename D = deque<T> >
@ -34,80 +36,96 @@ public:
typedef D queue_type;
/**
* @brief ,
* @brief Getting data from the head without data throwing exception
* @brief ,
*
* @param t
* @return bool: true, , false,
* @return bool: true, get data ; false, no data
* @return bool: true, , false,
*/
T front();
/**
* @brief Get data from the head
* @brief
*
* @param t
* @return bool: true, get data ; false, no data
* @return bool: true, , false,
*/
bool pop_front(T& t);
/**
* @brief
* @brief Get data from the head
* @brief
*
* @return bool: true, , false,
* @return bool: true, get data ; false, no data
* @return bool: true, , false,
*/
bool pop_front();
/**
* @brief .
* @brief Put data to the back end of the queue.
* @brief .
*
* @param t
*/
void push_back(const T& t);
/**
* @brief .
* @brief Put data to the back end of the queue.
* @brief .
*
* @param vt
*/
void push_back(const queue_type &qt);
/**
* @brief .
* @brief Put data to the front end of the queue.
* @brief .
*
* @param t
*/
void push_front(const T& t);
/**
* @brief .
* @brief Put data to the front end of the queue.
* @brief .
*
* @param vt
*/
void push_front(const queue_type &qt);
/**
* @brief
* @brief Exchange Data
* @brief
*
* @param q
* @return bool: true, data returned ; false, no data returned
* @return true, false
*/
bool swap(queue_type &q);
/**
* @brief Size of the Queue
* @brief .
*
* @return size_t the size of the queue
* @return size_t
*/
size_t size() const;
/**
* @brief Clear Up the Queue
* @brief
*/
void clear();
/**
* @brief .
*
* @brief Determine whether the data is null or not.
* @return bool truefalse
* @return bool: true, is null ; false, not null
*/
bool empty() const;
@ -120,15 +138,17 @@ protected:
protected:
/**
*
* Queue
*/
queue_type _queue;
/**
*
* The length of a queue
*/
size_t _size;
//锁
//锁Lock
TC_SpinLock _mutex;
};

View File

@ -29,6 +29,8 @@ namespace tars
/**
* @file tc_cgi.h
* @brief CGI处理类
* @brief CGI Processing Class
*/
/////////////////////////////////////////////////
class TC_Cgi;
@ -37,6 +39,7 @@ class TC_HttpRequest;
/**
* @brief
* @brief Profile Exception Class
*/
struct TC_Cgi_Exception : public TC_Exception
{
@ -48,11 +51,14 @@ struct TC_Cgi_Exception : public TC_Exception
/**
* @brief ,
* TC_Common::tostr对 vector<TC_Cgi_Upload>
* @brief Global Friend.
* By defining this function, you can use TC_Common::tostr to output vector<TC_Cgi_Upload>
*/
ostream &operator<<(ostream &os, const TC_Cgi_Upload &tcCgiUpload);
/**
* @brief cgi上传文件操作cgi上传的文件信息
* @brief CGI Uploaded File Operation, you can get cgi uploaded file info from this class.
*/
class TC_Cgi_Upload
{
@ -61,6 +67,7 @@ public:
/**
* @brief
* @brief Constructor
*/
TC_Cgi_Upload()
:_sFileName("")
@ -73,26 +80,30 @@ public:
/**
* @brief .
* @brief Copy Constructor
*/
TC_Cgi_Upload(const TC_Cgi_Upload &tcCgiUpload);
/**
* @brief
* @brief Assignment Constructor
*/
TC_Cgi_Upload & operator=(const TC_Cgi_Upload &tcCgiUpload);
/**
* @brief .
*
* return
* @brief Get Uploaded Info
* @return
* @return Uploaded File Info
*/
string tostr() const;
/**
* @brief IE INPUT上传控件的名称.
*
* return INPUT上传控件名称
* @brief Get the Client IE ; Input the name of the upload control
* @return INPUT上传控件名称
* @return INPUT the name of the upload control
*/
string getFormFileName() const
{
@ -101,8 +112,9 @@ public:
/**
* @brief INPUT控件用户输入的名称,.
*
* return
* @brief Return the name from the imput control and the real file name from the Client.
* @return
* @return the real file name from the Client
*/
string retRealFileName() const
{
@ -111,8 +123,9 @@ public:
/**
* @brief ,.
*
* return
* @brief The server file name after uploading to the server.
* @return
* @return the file name from the Server.
*/
string getSeverFileName() const
{
@ -121,8 +134,9 @@ public:
/**
* @brief .
*
* return size_t类型
* @brief Get the size of the uploaded file.
* @return size_t类型
* @return size_t : the size of the uploaded file
*/
size_t getFileSize() const
{
@ -131,8 +145,9 @@ public:
/**
* @brief .
*
* return truefalse
* @brief Determine whether the size of the uploaded file is oversize or not.
* @return truefalse
* @return bool: oversize, true ; not oversize, false
*/
bool isOverSize() const
{
@ -143,26 +158,31 @@ protected:
/**
* ,file控件名称
* Upload files,the name of the file control on the browser.
*/
string _sFileName;
/**
* ,
* the real name of the uploaded file, the name of the file on the Client.
*/
string _sRealFileName;
/**
*
* the name of the server which uploaded the file
*/
string _sServerFileName;
/**
* ,
* the size of the uploaded file, Bytes
*/
size_t _iSize;
/**
*
* whether the uploaded file is oversize or not
*/
bool _bOverSize;
@ -171,25 +191,29 @@ protected:
/**
* @brief cgi操作相关类.
* @brief CGI Operation Related Classes
*
*
*
* Main includes:
* 1
*
* 1 Support parameter resolution
* 2 cookies解析
*
* 2 Support cookies resolution
* 3 ,,
*
* 3 Support file uploading, setting the max number of uploaded files and the max size of a file.
* 4 ,
*
* 4 When uploading files, you need to check whether the files are oversize or not.
* 5 ,
*
* 5 When uploading files, you need to check
* whether the number of the uploaded files is limited.
* :,file控件必须取不同name,
*
* Notes : When multiple files are uploaded at the same time,
* the browser's file control must take a different name,
* otherwise the file will not be uploaded correctly.
* :parseCgi解析标准输入,
*
* Atttention : When calling parseCgi to parse the standard input,
* setUpload, parseCgi之前调用
*
* setUpload, which is called by the uploaded files, needs to be called before parseCgi.
*/
class TC_Cgi
{
@ -197,16 +221,19 @@ public:
/**
* @brief TC_Cgi构造函数
* @brief TC_Cgi Constructor
*/
TC_Cgi();
/**
* @brief
* @brief Destructor
*/
virtual ~TC_Cgi();
/**
* @brief
* @brief Define the environment variables
*/
enum
{
@ -233,43 +260,59 @@ public:
/**
* @brief .
* @brief Set the uploaded file.
*
* @param sUploadFilePrefix, (), ,
* ,"_序号"
* The file prefix (includes its path). If a file is uploaded, the file is saved in the path with the prefix as the name.
* If more than one file is uploaded, then the file name will be followed by "_ No."
*
* @param iMaxUploadFiles ,<0:
* Maximum number of uploaded files, if iMaxUploadFiles < 0 : no limit
*
* @param iUploadMaxSize ()
* Maximum size uploaded per file (Bytes)
*/
void setUpload(const string &sUploadFilePrefix, int iMaxUploadFiles = 5, size_t iUploadMaxSize = 1024*1024*10, size_t iMaxContentLength = 1024*1024*10);
/**
* @brief cgi.
* @brief Analyze CGI from standard input
*/
void parseCgi();
/**
* @brief http请求解析.
* @brief Request parsing directly from http.
*
* @param request http请求
* @param request http request
*/
void parseCgi(const TC_HttpRequest &request);
/**
* @brief cgi的url参数multimap.
* @brief Get the URL parameter of CGI : Multimap
*
* @return multimap<string, string>cgi的url参数
* @return multimap<string, string> cgi的url参数
* @return multimap<string, string> the URL parameter of CGI
*/
const multimap<string, string> &getParamMap() const;
/**
* @brief cgi环境变量map.
* @brief Get CGI environment variable: Map
*
* @return map<string,string>cgi的环境变量
* @return map<string,string> cgi的环境变量
* @return map<string,string> the environment variable of CGI
*/
map<string, string> getEnvMap() const { return _env; }
/**
* @brief cgi的参数map, multimap转换成map返回
* , , .
* @brief Get the CGI parameter, map, and convert Multimap to Map as return.
* If a parameter name corresponds to more than one parameter value, only one value is taken.
*
* @return map<string, string>
*/
@ -277,6 +320,7 @@ public:
/**
* @brief cookies的参数map.
* @brief Get cookies' parameter : map
*
* @return map<string, string>
*/
@ -284,165 +328,203 @@ public:
/**
* @brief cgi的某个参数.
* @brief Get a certain parameter from CGI
*
* @param sName
* @param sName parameter name
* @return
*/
string &operator[](const string &sName);
/**
* @brief cgi的某个参数.
* @brief Get a certain parameter from CGI
*
* @param sName
* @return
* @param sName parameter name
* @return the value of the parameter
*/
string getValue(const string& sName) const;
/**
* @brief .
* @brief Get multiple values of a parameter with a name.
*
* checkbox这类控件的值( ,)
* @param sName
* @param vtValue vector
* This is used to parse the value of a control such as a checkbox (one parameter name, multiple parameter values)
* @param sName / the parameter name
* @param vtValue vector / vector composed of the parameter value of the name
* @return vector<string>, vector
* @return vector<string> vector composed of the parameter value of the name
*/
const vector<string> &getMultiValue(const string& sName, vector<string> &vtValue) const;
/**
* @brief cookie值.
* @brief Get the cookie value.
*
* @param sName cookie名称
* @return string类型的cookie值
* @param sName cookie名称 / the name of the cookie
* @return string类型的cookie值 / Cookie value of type string
*/
string getCookie(const string& sName) const;
/**
* @brief cookie值.
* @brief Set cookie value.
*
* @param sName cookie名称
* @param sValue cookie值
* @param sExpires
* @param sPath cookie有效路径
* @param sDomain cookie有效域
* @param bSecure (ssl时有效)
* @return cookie值
* @param sName cookie名称 / cookie name
* @param sValue cookie值 / cookie value
* @param sExpires / the expire date
* @param sPath cookie有效路径 / cookie valid path
* @param sDomain cookie有效域 / cookie valid domain
* @param bSecure (ssl时有效) / Whether it is secure (valid in SSL)
* @return cookie值 / returns a string which representing the cookie value
*/
string setCookie(const string &sName, const string &sValue, const string &sExpires="", const string &sPath="/", const string &sDomain = "", bool bSecure = false);
/**
* @brief .
* @brief Whether the parameter list is empty.
*
* @return truefalse
* @return bool : true, the parameter list is empty ; false, the parameter list is not empty
*/
bool isParamEmpty() const;
/**
* @brief .
* Wether the parameter exists or not.
*
* @param sName
* @return truefalse
* @param sName / the parameter name
* @return truefalse / if exists retrun true, else return false.
*/
bool isParamExist(const string& sName) const;
/**
* @brief ,
* ,
* Wheter the size of the uploaded file is scale out.
* When uploading multiple files, it is scale out as long as there's one file exceeds the size.
* @return truefalse
* According to the standard above, if it is oversize, return true, else return false.
*/
bool isUploadOverSize() const;
/**
* @brief ,,
* ,
* Wheter the size of the uploaded file is scale out.
* When uploading multiple files, it is scale out as long as there's one file exceeds the size.
* @param vtUploads (file控件的名称)
* Returns the name of a file larger than the size (the name of the browser file control)
* @return truefalse
* According to the standard above, if it is oversize, return true, else return fals.
*/
bool isUploadOverSize(vector<TC_Cgi_Upload> &vtUploads) const;
/**
* @brief .
* Wheter the number of uploaded files exceeds.
*
* @return truefalse
* bool : true, the number of the uploaded files exceeds ; false, else
*/
bool isOverUploadFiles() const { return _bOverUploadFiles; }
/**
* @brief .
* Get the number of uploaded files
*
* @return size_t上传文件的个数
* size_t the number of uploaded files
*/
size_t getUploadFilesCount() const;
/**
* @brief
* Get the related info about the uploaded files
*
* @return map<string,TC_Cgi_Upload>
* map
* In the structure map<string,TC_Cgi_Upload>,
* the map which stored the file name and the file's related information.
*/
const map<string, TC_Cgi_Upload> &getUploadFilesMap() const;
/**
* @brief .
* Get the environment variables
*
* @param iEnv
* @return
* @param iEnv / Enumerating variables
* @return / Environment variables
*/
string getCgiEnv(int iEnv);
/**
* @brief .
* Get the environment variables
*
* @param sEnv
* @return
* @param sEnv / the environment variable name
* @return / the envitonment variable name
*/
string getCgiEnv(const string& sEnv);
/**
* @brief .
* Set environment variales
*
* @param sName
* @param sValue
* @param sName / environment variable name
* @param sValue / environment variable value
*/
void setCgiEnv(const string &sName, const string &sValue);
/**
* @brief html头content-type .
* Return HTML header, content type
*
* @param sHeader "text/html"
* The default value is "text / HTML"
* @return
*/
static string htmlHeader(const string &sHeader = "text/html");
/**
* @brief http请求的url解码, %.
* The URL of the HTTP request is decoded and the one after% is replaced with a character.
*
* @param sUrl http请求url
* @return
* @param sUrl http请求url / HTTP request URL
* @return / the encoded string
*/
static string decodeURL(const string &sUrl);
/**
* @brief url进行编码, %XX代替.
* Encode the URL with% XX instead of numbers and letters.
*
* @param sUrl http请求url
* @return url
* @param sUrl http请求url / HTTP request URL
* @return url / the encoded string
*/
static string encodeURL(const string &sUrl);
/**
* @brief HTML编码(<>"&)
* HTML encoding of the source string (< > "& ').
*
* the source string
* @param src
*
* Whether encoding the 'space' (space, \t, \r\n, \n)
* @param blankEncode (, \t, \r\n, \n)
*
* HTML encoded string
* @return HTML编码后的字符串
*/
static string encodeHTML(const string &src, bool blankEncode = false);
/**
* @brief XML编码(<>"&').
*
* @param src
* @return XML编码后的字符串
* XML encoding of the source string (< > "& ').
* @param src / Source string
* @return XML编码后的字符串 / XML encoded string
*/
static string encodeXML(const string &src);
@ -450,13 +532,14 @@ protected:
/**
* @brief ,,使
* Declare, but do not define, to ensure that this function will not be used.
*/
TC_Cgi &operator=(const TC_Cgi &tcCgi);
/**
* @brief GET method.
*
* @param sBuffer GET的QueryString
* @param sBuffer GET的QueryString / the QueryString of GET
* return
*/
void getGET(string &sBuffer);
@ -464,60 +547,65 @@ protected:
/**
* @brief POST method.
*
* @param sBuffer POST的QueryString
* @param sBuffer POST的QueryString / the QueryString of POST
* return
*/
void getPOST(string &sBuffer);
/**
* @brief .
* Parsing file upload
*
* @param mmpParams [out]multimap
* @param mmpParams [out]multimap / output multimap
* return
*/
void parseUpload(multimap<string, string> &mmpParams);
/**
* @brief form数据
* Parsing form data
*/
void parseFormData(multimap<string, string> &mmpParams, const string &sBoundary);
/**
* @brief
* Ignore empty lines
*/
void ignoreLine();
/**
* @brief .
*
* @param sFileName
* @param sBuffer
* Write File
* @param sFileName / file name
* @param sBuffer / contents needs to be wrote.
*/
bool writeFile(FILE*fp, const string &sFileName, const string &sBuffer, size_t &iTotalWrite);
/**
* @brief .
*
* @param mmpParams [out]multimap
* @param sBuffer [in]QueryString
* Analysis in non upload mode
* @param mmpParams [out]multimap / output multimap
* @param sBuffer [in]QueryString / output QueryString
* return
*/
void parseNormal(multimap<string, string> &mmpParams, const string& sBuffer);
/**
* @brief cookies.
* Parsing cookies
*
* @param mpCooies [out]cookiesmap
* @param sBuffer [in]Cookies字符串
* @param mpCooies [out]cookiesmap / output mpCookies
* @param sBuffer [in]Cookies字符串/ input string Cookies
* return
*/
void parseCookies(map<string, string> &mpCooies, const string& sBuffer);
/**
* @brief cgi input的基本流程.
* Control the basic process of parsing CGI input
*
* @param mmpParams [out] multimap
* @param mpCooies [out]cookies
* @param mmpParams [out] multimap / output multimap
* @param mpCooies [out]cookies / output multimap
* return
*/
void readCgiInput(multimap<string, string> &mmpParams, map<string, string> &mpCooies);
@ -531,21 +619,25 @@ protected:
/**
*
* Stream
*/
istringstream _iss;
/**
*
* Read in
*/
istream *_is;
/**
*
* environmet variable
*/
map<string, string> _env;
/**
* cgi参数
* CGI parameter
*/
multimap<string, string> _mmpParams;
@ -556,36 +648,43 @@ protected:
/**
*
* Upload file name prefix
*/
string _sUploadFilePrefix;
/**
* ,<0:
* Maximum number of uploaded files, < 0: Unlimited
*/
int _iMaxUploadFiles;
/**
*
* Maximum size of uploaded file
*/
size_t _iUploadMaxSize;
/**
*
* Whether the number of the uploaded file is exceeded.
*/
bool _bOverUploadFiles;
/**
* content-length
* the max content-length
*/
size_t _iMaxContentLength;
/**
* ,
* Determine whether the file is oversize or not, as long as one file is oversize that _bUploadFileOverSize is ture
*/
bool _bUploadFileOverSize;
/**
* map中
* the related infomation about the uploaded files is stored in this map
*/
map<string, TC_Cgi_Upload> _mpUpload;
};