Delete tc_cgi.h

This commit is contained in:
Douwanna 2020-05-20 02:33:20 +08:00 committed by GitHub
parent 9d05e78ddb
commit f4cd398182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

595
tc_cgi.h
View File

@ -1,595 +0,0 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
#ifndef __TC_CGI_H
#define __TC_CGI_H
#include <sstream>
#include <istream>
#include <map>
#include <vector>
#include "util/tc_ex.h"
namespace tars
{
/////////////////////////////////////////////////
/**
* @file tc_cgi.h
* @brief CGI处理类
*/
/////////////////////////////////////////////////
class TC_Cgi;
class TC_Cgi_Upload;
class TC_HttpRequest;
/**
* @brief
*/
struct TC_Cgi_Exception : public TC_Exception
{
TC_Cgi_Exception(const string &buffer) : TC_Exception(buffer){};
TC_Cgi_Exception(const string &buffer, int err) : TC_Exception(buffer, err){};
~TC_Cgi_Exception() throw(){};
};
/**
* @brief ,
* TC_Common::tostr对 vector<TC_Cgi_Upload>
*/
ostream &operator<<(ostream &os, const TC_Cgi_Upload &tcCgiUpload);
/**
* @brief cgi上传文件操作cgi上传的文件信息
*/
class TC_Cgi_Upload
{
public:
friend ostream &operator<<(ostream &os, const TC_Cgi_Upload &tcCgiUpload);
/**
* @brief
*/
TC_Cgi_Upload()
:_sFileName("")
, _sRealFileName("")
, _sServerFileName("")
, _iSize(0)
, _bOverSize(false)
{
}
/**
* @brief .
*/
TC_Cgi_Upload(const TC_Cgi_Upload &tcCgiUpload);
/**
* @brief
*/
TC_Cgi_Upload & operator=(const TC_Cgi_Upload &tcCgiUpload);
/**
* @brief .
*
* return
*/
string tostr() const;
/**
* @brief IE INPUT上传控件的名称.
*
* return INPUT上传控件名称
*/
string getFormFileName() const
{
return _sFileName;
}
/**
* @brief INPUT控件用户输入的名称,.
*
* return
*/
string retRealFileName() const
{
return _sRealFileName;
}
/**
* @brief ,.
*
* return
*/
string getSeverFileName() const
{
return _sServerFileName;
}
/**
* @brief .
*
* return size_t类型
*/
size_t getFileSize() const
{
return _iSize;
}
/**
* @brief .
*
* return truefalse
*/
bool isOverSize() const
{
return _bOverSize;
}
protected:
/**
* ,file控件名称
*/
string _sFileName;
/**
* ,
*/
string _sRealFileName;
/**
*
*/
string _sServerFileName;
/**
* ,
*/
size_t _iSize;
/**
*
*/
bool _bOverSize;
friend class TC_Cgi;
};
/**
* @brief cgi操作相关类.
*
*
*
* 1
*
* 2 cookies解析
*
* 3 ,,
*
* 4 ,
*
* 5 ,
*
* :,file控件必须取不同name,
*
* :parseCgi解析标准输入,
*
* setUpload, parseCgi之前调用
*
*/
class TC_Cgi
{
public:
/**
* @brief TC_Cgi构造函数
*/
TC_Cgi();
/**
* @brief
*/
virtual ~TC_Cgi();
/**
* @brief
*/
enum
{
ENM_SERVER_SOFTWARE,
ENM_SERVER_NAME,
ENM_GATEWAY_INTERFACE,
ENM_SERVER_PROTOCOL,
ENM_SERVER_PORT,
ENM_REQUEST_METHOD,
ENM_PATH_INFO,
ENM_PATH_TRANSLATED,
ENM_SCRIPT_NAME,
ENM_HTTP_COOKIE,
ENM_QUERY_STRING,
ENM_REMOTE_HOST,
ENM_REMOTE_ADDR,
ENM_AUTH_TYPE,
ENM_REMOTE_USER,
ENM_REMOTE_IDENT,
ENM_CONTENT_TYPE,
ENM_CONTENT_LENGTH,
ENM_HTTP_USER_AGENT
};
/**
* @brief .
*
* @param sUploadFilePrefix, (), ,
* ,"_序号"
* @param iMaxUploadFiles ,<0:
* @param iUploadMaxSize ()
*/
void setUpload(const string &sUploadFilePrefix, int iMaxUploadFiles = 5, size_t iUploadMaxSize = 1024*1024*10, size_t iMaxContentLength = 1024*1024*10);
/**
* @brief cgi.
*/
void parseCgi();
/**
* @brief http请求解析.
*
* @param request http请求
*/
void parseCgi(const TC_HttpRequest &request);
/**
* @brief cgi的url参数multimap.
*
* @return multimap<string, string>cgi的url参数
*/
const multimap<string, string> &getParamMap() const;
/**
* @brief cgi环境变量map.
*
* @return map<string,string>cgi的环境变量
*/
map<string, string> getEnvMap() const { return _env; }
/**
* @brief cgi的参数map, multimap转换成map返回
* , , .
*
* @return map<string, string>
*/
map<string, string> getParamMapEx() const;
/**
* @brief cookies的参数map.
*
* @return map<string, string>
*/
const map<string, string> &getCookiesMap() const;
/**
* @brief cgi的某个参数.
*
* @param sName
* @return
*/
string &operator[](const string &sName);
/**
* @brief cgi的某个参数.
*
* @param sName
* @return
*/
string getValue(const string& sName) const;
/**
* @brief .
*
* checkbox这类控件的值( ,)
* @param sName
* @param vtValue vector
* @return vector<string>, vector
*/
const vector<string> &getMultiValue(const string& sName, vector<string> &vtValue) const;
/**
* @brief cookie值.
*
* @param sName cookie名称
* @return string类型的cookie值
*/
string getCookie(const string& sName) const;
/**
* @brief cookie值.
*
* @param sName cookie名称
* @param sValue cookie值
* @param sExpires
* @param sPath cookie有效路径
* @param sDomain cookie有效域
* @param bSecure (ssl时有效)
* @return cookie值
*/
string setCookie(const string &sName, const string &sValue, const string &sExpires="", const string &sPath="/", const string &sDomain = "", bool bSecure = false);
/**
* @brief .
*
* @return truefalse
*/
bool isParamEmpty() const;
/**
* @brief .
*
* @param sName
* @return truefalse
*/
bool isParamExist(const string& sName) const;
/**
* @brief ,
* ,
* @return truefalse
*/
bool isUploadOverSize() const;
/**
* @brief ,,
* ,
* @param vtUploads (file控件的名称)
* @return truefalse
*/
bool isUploadOverSize(vector<TC_Cgi_Upload> &vtUploads) const;
/**
* @brief .
*
* @return truefalse
*/
bool isOverUploadFiles() const { return _bOverUploadFiles; }
/**
* @brief .
*
* @return size_t上传文件的个数
*/
size_t getUploadFilesCount() const;
/**
* @brief
*
* @return map<string,TC_Cgi_Upload>
* map
*/
const map<string, TC_Cgi_Upload> &getUploadFilesMap() const;
/**
* @brief .
*
* @param iEnv
* @return
*/
string getCgiEnv(int iEnv);
/**
* @brief .
*
* @param sEnv
* @return
*/
string getCgiEnv(const string& sEnv);
/**
* @brief .
*
* @param sName
* @param sValue
*/
void setCgiEnv(const string &sName, const string &sValue);
/**
* @brief html头content-type .
*
* @param sHeader "text/html"
* @return
*/
static string htmlHeader(const string &sHeader = "text/html");
/**
* @brief http请求的url解码, %.
*
* @param sUrl http请求url
* @return
*/
static string decodeURL(const string &sUrl);
/**
* @brief url进行编码, %XX代替.
*
* @param sUrl http请求url
* @return url
*/
static string encodeURL(const string &sUrl);
/**
* @brief HTML编码(<>"&)
*
* @param src
* @param blankEncode (, \t, \r\n, \n)
* @return HTML编码后的字符串
*/
static string encodeHTML(const string &src, bool blankEncode = false);
/**
* @brief XML编码(<>"&').
*
* @param src
* @return XML编码后的字符串
*/
static string encodeXML(const string &src);
protected:
/**
* @brief ,,使
*/
TC_Cgi &operator=(const TC_Cgi &tcCgi);
/**
* @brief GET method.
*
* @param sBuffer GET的QueryString
* return
*/
void getGET(string &sBuffer);
/**
* @brief POST method.
*
* @param sBuffer POST的QueryString
* return
*/
void getPOST(string &sBuffer);
/**
* @brief .
*
* @param mmpParams [out]multimap
* return
*/
void parseUpload(multimap<string, string> &mmpParams);
/**
* @brief form数据
*/
void parseFormData(multimap<string, string> &mmpParams, const string &sBoundary);
/**
* @brief
*/
void ignoreLine();
/**
* @brief .
*
* @param sFileName
* @param sBuffer
*/
bool writeFile(FILE*fp, const string &sFileName, const string &sBuffer, size_t &iTotalWrite);
/**
* @brief .
*
* @param mmpParams [out]multimap
* @param sBuffer [in]QueryString
* return
*/
void parseNormal(multimap<string, string> &mmpParams, const string& sBuffer);
/**
* @brief cookies.
*
* @param mpCooies [out]cookiesmap
* @param sBuffer [in]Cookies字符串
* return
*/
void parseCookies(map<string, string> &mpCooies, const string& sBuffer);
/**
* @brief cgi input的基本流程.
*
* @param mmpParams [out] multimap
* @param mpCooies [out]cookies
* return
*/
void readCgiInput(multimap<string, string> &mmpParams, map<string, string> &mpCooies);
protected:
/**
* buffer
*/
string _buffer;
/**
*
*/
istringstream _iss;
/**
*
*/
istream *_is;
/**
*
*/
map<string, string> _env;
/**
* cgi参数
*/
multimap<string, string> _mmpParams;
/**
* cookies
*/
map<string, string> _mpCookies;
/**
*
*/
string _sUploadFilePrefix;
/**
* ,<0:
*/
int _iMaxUploadFiles;
/**
*
*/
size_t _iUploadMaxSize;
/**
*
*/
bool _bOverUploadFiles;
/**
* content-length
*/
size_t _iMaxContentLength;
/**
* ,
*/
bool _bUploadFileOverSize;
/**
* map中
*/
map<string, TC_Cgi_Upload> _mpUpload;
};
}
#endif