util.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "http_define.h"
  3. #if USE_NET_HTTP_UTIL
  4. #include <string>
  5. #include <list>
  6. namespace ylib
  7. {
  8. namespace network
  9. {
  10. //取文档类型
  11. void content_type(const std::string& extName, std::string& type);
  12. //拆分URL
  13. bool parse_url(const std::string& url, std::string& httpType, std::string& host, std::string& ipaddress, ushort& port, std::string& urlField);
  14. //拆分URL
  15. bool parse_url_host(const std::string& url, std::string& host);
  16. //INT IP 转 字符串IP
  17. void to_string(uint32 int_ip, std::string& ipaddress);
  18. struct TcpConf
  19. {
  20. TcpConf()
  21. {
  22. local_port = 0;
  23. remote_port = 0;
  24. __local_ipaddress = 0;
  25. __remote_ipaddress = 0;
  26. }
  27. void local_ipaddress(std::string& ipaddress) const
  28. {
  29. to_string(__local_ipaddress, ipaddress);
  30. }
  31. void remote_ipaddress(std::string& ipaddress) const
  32. {
  33. to_string(__remote_ipaddress, ipaddress);
  34. }
  35. uint32 __local_ipaddress;
  36. uint32 __remote_ipaddress;
  37. uint32 local_port;
  38. uint32 remote_port;
  39. };
  40. //URL转IP地址
  41. std::string to_ip(const std::string& url);
  42. // 端口是否占用
  43. bool is_occupy(uint32 port);
  44. /*
  45. 取大小名称
  46. B/KB/MB/GB
  47. */
  48. std::string size_name(double size, uint32 fixe = 0);
  49. // 是否为IPV4
  50. bool is_ipv4(const std::string& value);
  51. // 是否为IPV6
  52. bool is_ipv6(const std::string& value);
  53. // 是否为域名
  54. bool is_domain(const std::string& value);
  55. }
  56. }
  57. #endif