123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- /*
- * ip_table.h
- *
- * Created on: 2022年3月10日
- * Author: pengzc
- */
- #ifndef JNI_CORE_IP_TABLE_H_
- #define JNI_CORE_IP_TABLE_H_
- #include <string>
- #include <base/strings.hpp>
- namespace i {
- struct NetworkProfile {
- std::string name;
- std::string code;
- std::string ipv4;
- std::string gateway;
- std::string sub_network_mask;
- int building;
- int unit;
- int number;
- int extension;
- public:
- NetworkProfile() {
- building = 0;
- unit = 0;
- number = 0;
- extension = 0;
- }
- std::string ToString() const {
- return base::format("%s %s %s %s %s", name.c_str(), code.c_str(),
- ipv4.c_str(), gateway.c_str(), sub_network_mask.c_str());
- }
- std::string ToAddressString() const {
- return base::format("%d栋%d单元%04d室%d分机", building,
- unit, number, extension);
- }
- bool ParseAddressString(const std::string& str) {
- return 4 == sscanf(str.c_str(), "%d栋%d单元%d室%d分机", &building,
- &unit, &number, &extension);
- }
- };
- class IpTable {
- public:
- virtual ~IpTable();
- /**
- * 更新IP表
- * @param map_xml
- * @return
- */
- static int Update(const std::string& map_xml);
- /**
- * 加载IP表
- * @param map_xml
- * @return
- */
- static int Load(std::string* map_xml);
- /**
- * 从IP表中查找指定分机的网络配置
- *
- * @param building 栋
- * @param unit 单元
- * @param number 室
- * @param extension 分机号
- * @param profile 对应的网络配置
- * @return success 0
- */
- static int GetExtension(int building, int unit, int number, int extension,
- NetworkProfile* profile);
- /**
- * 从IP表中查找指定门口机的网络配置
- * @param building 栋
- * @param unit 单元
- * @return success 0
- */
- static int GetGate(int building, int unit, NetworkProfile* profile);
- static std::string GetVersion();
- private:
- IpTable();
- };
- } /* namespace i */
- #endif /* JNI_CORE_IP_TABLE_H_ */
|