-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathModels.h
More file actions
259 lines (211 loc) · 6.34 KB
/
Models.h
File metadata and controls
259 lines (211 loc) · 6.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
//
// C++ Interface: mess
//
// Description:
// 很杂乱的一些数据基本结构.
//
// Author: Jally <[email protected]>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef IPTUX_MODELS_H
#define IPTUX_MODELS_H
#include <cstdint>
#include <memory>
#include <string>
#include <json/json.h>
namespace iptux {
/**
* 消息来源类型.
*/
enum class MessageSourceType {
PAL, ///< 好友
SELF, ///< 自身
ERROR ///< 错误
};
/**
* 消息内容类型.
*/
enum class MessageContentType {
STRING, ///< 字符串
PICTURE ///< 图片
};
static const MessageContentType MESSAGE_CONTENT_TYPE_STRING =
MessageContentType::STRING;
static const MessageContentType MESSAGE_CONTENT_TYPE_PICTURE =
MessageContentType::PICTURE;
/**
* 群组所属类型
*/
typedef enum {
GROUP_BELONG_TYPE_REGULAR, ///< 常规
GROUP_BELONG_TYPE_SEGMENT, ///< 分段
GROUP_BELONG_TYPE_GROUP, ///< 分组
GROUP_BELONG_TYPE_BROADCAST ///< 广播
} GroupBelongType;
class PalKey {
public:
PalKey(uint32_t ipv4, int port);
bool operator==(const PalKey& rhs) const;
uint32_t GetIpv4() const { return ipv4; }
std::string GetIpv4String() const;
int GetPort() const { return port; }
std::string ToString() const;
private:
uint32_t ipv4;
int port;
};
/**
* 好友信息.
* flags位含义: \n
* 黑名单(:3);此IP地址被列入黑名单(deprecated) \n
* 更改(:2);好友的信息被用户手工修改,程序不应再更改好友的信息 \n
* 在线(:1);好友依旧在线 \n
* 兼容(:0);完全兼容iptux,程序将采用扩展协议与好友通信 \n
*/
class PalInfo {
public:
PalInfo(const std::string& ipv4, uint16_t port);
PalInfo(uint32_t ipv4, uint16_t port);
~PalInfo();
PalKey GetKey() const { return PalKey(ipv4(), port_); }
PalInfo& setName(const std::string& name);
const std::string& getName() const { return name; }
PalInfo& setUser(const std::string& user);
const std::string& getUser() const { return user; }
PalInfo& setHost(const std::string& host);
const std::string& getHost() const { return host; }
PalInfo& setVersion(const std::string& version);
const std::string& getVersion() const { return version; }
PalInfo& setEncode(const std::string& encode);
const std::string& getEncode() const { return encode; }
PalInfo& setGroup(const std::string& group);
const std::string& getGroup() const { return group; }
const std::string& icon_file() const { return icon_file_; }
PalInfo& set_icon_file(const std::string& icon_file) {
icon_file_ = icon_file;
return *this;
}
PalInfo& set_icon_file(const std::string& icon_file, const std::string& def) {
if (icon_file.empty())
icon_file_ = def;
else
icon_file_ = icon_file;
return *this;
}
std::string toString() const;
uint32_t ipv4() const { return ipv4_; }
uint16_t port() const { return port_; }
char* segdes; ///< 所在网段描述
char* photo; ///< 形象照片
char* sign; ///< 个性签名
uint32_t packetn; ///< 已接受最大的包编号
uint32_t rpacketn; ///< 需要接受检查的包编号
bool isCompatible() const;
bool isOnline() const;
bool isChanged() const;
bool isInBlacklist() const;
PalInfo& setCompatible(bool value);
PalInfo& setOnline(bool value);
PalInfo& setChanged(bool value);
PalInfo& setInBlacklistl(bool value);
private:
uint32_t ipv4_; ///< 好友IP
uint16_t port_; ///< 好友端口
std::string icon_file_; ///< 好友头像 *
std::string user;
std::string name;
std::string host;
std::string version; ///< 版本串 *
std::string encode; ///< 好友编码 *
std::string group; ///< 所在群组
uint8_t flags; ///< 3 黑名单:2 更改:1 在线:0 兼容
};
/// pointer to PalInfo
using PPalInfo = std::shared_ptr<PalInfo>;
/// const pointer to PalInfo
using CPPalInfo = std::shared_ptr<const PalInfo>;
enum class FileAttr { UNKNOWN, REGULAR, DIRECTORY };
constexpr bool FileAttrIsValid(FileAttr attr) {
return attr == FileAttr::REGULAR || attr == FileAttr::DIRECTORY;
}
/**
* 文件信息.
*/
class FileInfo {
public:
FileInfo();
~FileInfo();
FileInfo(const FileInfo& fileInfo);
FileInfo& operator=(const FileInfo& fileInfo);
bool operator==(const FileInfo& rhs) const;
bool isExist() const;
void ensureFilesizeFilled();
uint32_t fileid; ///< 唯一标识
uint32_t packetn; ///< 包编号
FileAttr fileattr; ///< 文件属性
int64_t filesize; ///< 文件大小
int64_t finishedsize; ///< 已完成大小
CPPalInfo fileown; ///< 文件拥有者(来自好友*)
char* filepath; ///< 文件路径 *
uint32_t filectime; ///< 文件创建时间
uint32_t filemtime; ///< 文件最后修改时间
uint32_t filenum; ///< 包内编号
};
using PFileInfo = std::shared_ptr<FileInfo>;
/**
* 碎片数据.
*/
class ChipData {
public:
explicit ChipData(const std::string& data);
ChipData(MessageContentType type, const std::string& data);
~ChipData();
std::string ToString() const;
std::string getSummary() const;
MessageContentType type; ///< 消息内容类型
std::string data; ///< 数据串 *
void SetDeleteFileAfterSent(bool val) { deleteFileAfterSent = val; }
bool GetDeleteFileAfterSent() const { return deleteFileAfterSent; }
private:
bool deleteFileAfterSent{true};
};
/**
* 消息参数.
*/
class MsgPara {
public:
explicit MsgPara(CPPalInfo pal);
~MsgPara();
std::string getSummary() const;
CPPalInfo getPal() const { return pal; }
MessageSourceType stype; ///< 来源类型
GroupBelongType btype; ///< 所属类型
std::vector<ChipData> dtlist; ///< 数据链表 *
private:
CPPalInfo pal; ///< 好友数据信息(来自好友*)
};
/**
* 网段数据.
*/
class NetSegment {
public:
NetSegment(std::string startIp, std::string endIp, std::string description);
NetSegment();
~NetSegment();
bool ContainIP(uint32_t ipv4) const;
/**
* @brief return the ip count in this segment
*
*/
uint64_t Count() const;
std::string NthIp(uint64_t i) const;
std::string startip; ///< IP起始地址 *
std::string endip; ///< IP终止地址 *
std::string description; ///< 此IP段描述
Json::Value ToJsonValue() const;
static NetSegment fromJsonValue(Json::Value& value);
};
} // namespace iptux
#endif