util.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /// <summary>
  56. /// 解析 multipart/form 数据
  57. /// </summary>
  58. /// <param name="body"></param>
  59. /// <param name="body_length"></param>
  60. /// <param name="boundary"></param>
  61. /// <param name="parts"></param>
  62. /// <returns></returns>
  63. bool parse_multipart_form_data(const ylib::buffer& data, const std::string& boundary, std::vector<network::http::multipart>& parts);
  64. }
  65. }
  66. #endif