2019-07-28 10:31:56 +08:00
|
|
|
|
#pragma once
|
2017-06-02 14:47:24 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
2021-06-08 16:45:49 +08:00
|
|
|
|
#include "../stdlib/string.hpp"
|
2014-11-19 00:25:21 +08:00
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API http_utils
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
http_utils() {}
|
|
|
|
|
~http_utils() {}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> url <EFBFBD>л<EFBFBD><EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>domain:port
|
|
|
|
|
* @param url {const char*} HTTP url<EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>
|
|
|
|
|
* @param addr {char*} <EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>洢<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>domain:port
|
|
|
|
|
* @param size {size_t} out <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
static bool get_addr(const char* url, char* addr, size_t size);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> url <EFBFBD>л<EFBFBD><EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP <EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>˿ں<EFBFBD>
|
|
|
|
|
* @param url {const char*} HTTP url<EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD>
|
|
|
|
|
* @param domain {char*} <EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param size {size_t} domain <EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>С
|
|
|
|
|
* @param port {unsigned short*} <EFBFBD>洢<EFBFBD>˿ںŴ<EFBFBD>С
|
|
|
|
|
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2014-11-19 00:25:21 +08:00
|
|
|
|
*/
|
|
|
|
|
static bool get_addr(const char* url, char* domain, size_t size,
|
|
|
|
|
unsigned short* port);
|
2021-06-08 16:45:49 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> URL
|
|
|
|
|
* @param url {const char*} <EFBFBD>ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param domain {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
* @param port {unsigned short*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> url <EFBFBD>еĶ˿ں<EFBFBD>
|
|
|
|
|
* @param url_path {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> url <EFBFBD>в<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD> URL<EFBFBD><EFBFBD>http://test.com.cn/cgi-bin/test?name=value <20><>ֻ<EFBFBD><D6BB>ȡ<EFBFBD><C8A1><EFBFBD>е<EFBFBD><D0B5><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/cgi-bin/test
|
|
|
|
|
* @param url_params {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> url <EFBFBD>еIJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> url <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
static bool parse_url(const char* url, string& domain,
|
|
|
|
|
unsigned short* port, string& url_path, string& url_params);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ACL_CPP_API http_url {
|
|
|
|
|
public:
|
|
|
|
|
http_url(void);
|
|
|
|
|
~http_url(void) {}
|
|
|
|
|
|
|
|
|
|
bool parse(const char* url);
|
|
|
|
|
|
|
|
|
|
public:
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD>е<EFBFBD>Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>http <EFBFBD><EFBFBD> https
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2021-06-08 16:45:49 +08:00
|
|
|
|
const char* get_proto(void) const {
|
|
|
|
|
return proto_;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
|
|
|
|
* @return {const char*} <EFBFBD><EFBFBD><EFBFBD>ؿմ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾû<EFBFBD>и<EFBFBD><EFBFBD>ֶ<EFBFBD>
|
|
|
|
|
*/
|
2021-06-08 16:45:49 +08:00
|
|
|
|
const char* get_domain(void) const {
|
|
|
|
|
return domain_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD> HTTP Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˶˿ںţ<EFBFBD><EFBFBD>ڲ<EFBFBD>ȱʡֵΪ 80
|
|
|
|
|
* @return {unsigned short}
|
|
|
|
|
*/
|
2021-06-08 16:45:49 +08:00
|
|
|
|
unsigned short get_port(void) const {
|
|
|
|
|
return port_;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ? <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2021-06-08 16:45:49 +08:00
|
|
|
|
const char* get_url_path(void) const {
|
|
|
|
|
return url_path_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD> URL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
|
|
|
|
* @return {const char*}
|
|
|
|
|
*/
|
2021-06-08 16:45:49 +08:00
|
|
|
|
const char* get_url_params(void) const {
|
|
|
|
|
return url_params_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 15:11:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>м<EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>ظ<EFBFBD>ʹ<EFBFBD>ø<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> URL
|
|
|
|
|
*/
|
2021-06-08 16:45:49 +08:00
|
|
|
|
void reset(void);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
char proto_[16];
|
|
|
|
|
string domain_;
|
|
|
|
|
unsigned short port_;
|
|
|
|
|
string url_path_;
|
|
|
|
|
string url_params_;
|
|
|
|
|
|
|
|
|
|
bool parse_url_part(const char* url);
|
|
|
|
|
const char* parse_domain(const char* url);
|
2014-11-19 00:25:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|