ip_table.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * ip_table.h
  3. *
  4. * Created on: 2022年3月10日
  5. * Author: pengzc
  6. */
  7. #ifndef JNI_CORE_IP_TABLE_H_
  8. #define JNI_CORE_IP_TABLE_H_
  9. #include <string>
  10. #include <base/strings.hpp>
  11. namespace i {
  12. struct NetworkProfile {
  13. std::string name;
  14. std::string code;
  15. std::string ipv4;
  16. std::string gateway;
  17. std::string sub_network_mask;
  18. int building;
  19. int unit;
  20. int number;
  21. int extension;
  22. public:
  23. NetworkProfile() {
  24. building = 0;
  25. unit = 0;
  26. number = 0;
  27. extension = 0;
  28. }
  29. std::string ToString() const {
  30. return base::format("%s %s %s %s %s", name.c_str(), code.c_str(),
  31. ipv4.c_str(), gateway.c_str(), sub_network_mask.c_str());
  32. }
  33. std::string ToAddressString() const {
  34. return base::format("%d栋%d单元%04d室%d分机", building,
  35. unit, number, extension);
  36. }
  37. bool ParseAddressString(const std::string& str) {
  38. return 4 == sscanf(str.c_str(), "%d栋%d单元%d室%d分机", &building,
  39. &unit, &number, &extension);
  40. }
  41. };
  42. class IpTable {
  43. public:
  44. virtual ~IpTable();
  45. /**
  46. * 更新IP表
  47. * @param map_xml
  48. * @return
  49. */
  50. static int Update(const std::string& map_xml);
  51. /**
  52. * 加载IP表
  53. * @param map_xml
  54. * @return
  55. */
  56. static int Load(std::string* map_xml);
  57. /**
  58. * 从IP表中查找指定分机的网络配置
  59. *
  60. * @param building 栋
  61. * @param unit 单元
  62. * @param number 室
  63. * @param extension 分机号
  64. * @param profile 对应的网络配置
  65. * @return success 0
  66. */
  67. static int GetExtension(int building, int unit, int number, int extension,
  68. NetworkProfile* profile);
  69. /**
  70. * 从IP表中查找指定门口机的网络配置
  71. * @param building 栋
  72. * @param unit 单元
  73. * @return success 0
  74. */
  75. static int GetGate(int building, int unit, NetworkProfile* profile);
  76. static std::string GetVersion();
  77. private:
  78. IpTable();
  79. };
  80. } /* namespace i */
  81. #endif /* JNI_CORE_IP_TABLE_H_ */