-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwochatypes.h
315 lines (264 loc) · 7.89 KB
/
wochatypes.h
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
/*
* common basic data types and constant symbols used in the whole project
*/
#ifndef __WT_WOCHATYPES_H__
#define __WT_WOCHATYPES_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
#define S8 int8_t
#define S16 int16_t
#define S32 int32_t
#define S64 int64_t
#define U8 uint8_t
#define U16 uint16_t
#define U32 uint32_t
#define U64 uint64_t
typedef unsigned char uint8; /* == 8 bits */
typedef unsigned short uint16; /* == 16 bits */
typedef unsigned int uint32; /* == 32 bits */
typedef signed char int8; /* == 8 bits */
typedef signed short int16; /* == 16 bits */
typedef signed int int32; /* == 32 bits */
typedef long long int int64;
typedef unsigned long long int uint64;
/*
* Size
* Size of any memory resident object, as returned by sizeof.
*/
typedef size_t Size;
// #define WT_IS_BIG_ENDIAN 1
#define WT_ENCRYPTION_VERION 1
/* for Secp256k1 key size */
#define SECRET_KEY_SIZE 32
#define PUBLIC_KEY_SIZE 33
/* sha256 hash values always is 256-bit/32-byte long */
#define SHA256_HASH_SIZE 32
/* MQTT client is has maximum 23 bytes */
#define MQTT_CLIENTID_SIZE 23
#define MQTT_DEFAULT_HOST ("www.boobooke.com")
//#define MQTT_DEFAULT_HOST ("test.mosquitto.org")
#define MQTT_DEFAULT_PORT 1883
#define WT_NETWORK_IS_BAD 0
#define WT_NETWORK_IS_GOOD 1
typedef long LONG;
// a message node in the message queue
typedef struct MessageTask
{
struct MessageTask* next;
volatile LONG state;
volatile LONG sequence;
U8 pubkey[33];
U8 type;
U32 value32;
U8 hash[32]; // the SHA256 hash value of this node
U8* message;
U32 msgLen;
} MessageTask;
#define WT_UI_BITMAP_MAX 128
#define WT_MQTT_MAXTOPICS 256
#define WT_NAME_MAX_LEN 64
#define WT_MOTTO_MAX_LEN 128
#define WT_AREA_MAX_LEN 64
#define WT_FROM_MAX_LEN 64
#define WT_LARGE_ICON_WIDTH 128
#define WT_LARGE_ICON_HEIGHT 128
#define WT_SMALL_ICON_WIDTH 32
#define WT_SMALL_ICON_HEIGHT 32
#define WT_LARGE_ICON_SIZE (WT_LARGE_ICON_WIDTH * WT_LARGE_ICON_HEIGHT * 4)
#define WT_SMALL_ICON_SIZE (WT_SMALL_ICON_WIDTH * WT_SMALL_ICON_HEIGHT * 4)
#define WT_BLOB_LEN (4 + PUBLIC_KEY_SIZE + 4 + WT_NAME_MAX_LEN + WT_AREA_MAX_LEN + WT_MOTTO_MAX_LEN + WT_SMALL_ICON_SIZE + WT_LARGE_ICON_SIZE)
#define WT_FRIEND_SOURCE_BUILDIN 0
#define WT_FRIEND_SOURCE_ADDMANUALLY 1
#define WT_FRIEND_SOURCE_FROMGROUP 2
#define WT_MESSAGE_FROM_OTHER 0x0000
#define WT_MESSAGE_FROM_ME 0x0001
#define WT_MESSAGE_FROM_CONFIRM 0x0002
#define WT_CHATWINDOW_GAP 32
#define WT_MEMCMP(mem1, mem2, length, result) \
do { \
int i; \
for(i=0; i<length; i++) if(mem1[i] != mem2[i]) break;\
result = (i == length); \
} while(0)
typedef struct WTChatMessage
{
struct WTChatMessage* next;
struct WTChatMessage* prev;
U16 state;
U16 idx;
U16* message; // real message
U32 message_length;
int height; // in pixel
int width; // in pixel
U64 ts; // the time stamp.
U16* name; // The name of this people
U8* obj; // point to GIF/APNG/Video/Pic etc
} WTChatMessage;
typedef struct WTChatGroup WTChatGroup;
typedef struct WTFriend WTFriend;
typedef struct WTChatGroup
{
WTChatGroup* next;
WTChatGroup* prev;
WTFriend* people;
void* opaque; // for chat group, not single people, this is useful
U16 width; // in pixel, the width of window 4
U16 height; // in pixel
U32 total; // total messages in this group
U32 unread; // how many unread messages? if more than 254, use ...
U64 ts; // the time stamp of last message.
U16* tsText; // the text of time stamp
U16* lastmsg; // the last message of this group
U16 lastMsgLen;
U16 lastmsgLen;
WTChatMessage* msgHead;
WTChatMessage* msgTail;
} WTChatGroup;
#define WT_FRIEND_PROP_ACITVE 0x00000001
#define WT_FRIEND_PROP_LARGEICON_ALLOC 0x00000002
struct WTFriend
{
struct WTFriend* next;
struct WTFriend* prev;
WTChatGroup* chatgroup;
U32 property;
U8 pubkey[33];
U32 version; // the information version
U32 dob; // date of birth;
U8 sex;
U16 member; // if this friend is group, how many members in this group?
U8 name[WT_NAME_MAX_LEN]; // the name of this friend
U8 name_length;
U8 motto[WT_MOTTO_MAX_LEN]; // the motto of this friend
U8 motto_length;
U8 area[WT_AREA_MAX_LEN]; // the area of this friend
U8 area_length;
U8 from[WT_FROM_MAX_LEN]; // which method do I get this friend
U8 from_length;
U32* icon32;
U32* icon128;
};
typedef struct WTGuy
{
U8 pubkey[PUBLIC_KEY_SIZE];
WTFriend* people;
} WTGuy;
#define WT_MYINFO_LARGEICON_ALLOC 0x0000001 /* the large icon is pointing to an alloced memory block*/
/* the data strcture to describe myself */
typedef struct WTMyInfo
{
void* ctx; /* point to the memory pool this struct is in */
void* pool;
U32 property;
U32 version;
S64 creation_date;
U32 dob; // day of birth
U8 sex;
U8 name_length;
U8 area_length;
U8 motto_length;
U8 name[WT_NAME_MAX_LEN];
U8 area[WT_AREA_MAX_LEN];
U8 motto[WT_MOTTO_MAX_LEN];
U32* icon32;
U32* icon128;
U8 skenc[SECRET_KEY_SIZE]; /* the encrypted secret key! */
U8 seckey[SECRET_KEY_SIZE];
U8 pubkey[PUBLIC_KEY_SIZE];
U8 sub_clientid[MQTT_CLIENTID_SIZE];
U8 pub_clientid[MQTT_CLIENTID_SIZE];
U32 people_count;
U32 chatgroup_count;
WTFriend* people;
WTChatGroup* chatgroup;
void* lookuptable;
} WTMyInfo;
#define SETTING_GENERAL 0
#define SETTING_NETWORK 1
#define SETTING_AIROBOT 2
#define SETTING_ABOUT 3
typedef struct WTSetting
{
struct WTSetting* next;
U8 id;
U16* name; // the group name
U16 nameLen;
U16 height; // the height of this string in pixel
} WTSetting;
#define WT_SEX_UNKOWN 0
#define WT_MALE 1
#define WT_FEMALE 2
#define WT_CHAR_PASSWD_MAX_LEN 64
#define WT_CHAR_NAME_MAX_LEN 21
#define WT_CHAR_MOTTO_MAX_LEN 42
#define WT_CHAR_AREA_MAX_LEN 21
#define WT_OK 0x00000000 /* Successful result */
#define WT_FAIL 0x00000001
#define WT_SOURCEEXHAUSTED 0x00000002
#define WT_TARGETEXHAUSTED 0x00000003
#define WT_SOURCEILLEGAL 0x00000004
#define WT_SK_GENERATE_ERR 0x00000005
#define WT_PK_GENERATE_ERR 0x00000006
#define WT_UTF16ToUTF8_ERR 0x00000007
#define WT_MEMORY_ALLOC_ERR 0x00000008
#define WT_SQLITE_OPEN_ERR 0x00000009
#define WT_SQLITE_PREPARE_ERR 0x0000000A
#define WT_SQLITE_STEP_ERR 0x0000000B
#define WT_SQLITE_FINALIZE_ERR 0x0000000C
#define WT_MEMORY_POOL_ERROR 0x0000000D
#define WT_DYNAMIC_HASHTAB_ERR 0x0000000E
#define WT_SECP256K1_CTX_ERROR 0x0000000F
#define WT_RANDOM_NUMBER_ERROR 0x00000010
#define WT_DWRITE_METRIC_ERROR 0x00000011
#define WT_HEXSTR_TO_RAW_ERROR 0x00000012
#define WT_PARAM_APPLICATION_NAME 0
#define WT_PARAM_SERVER_NAME 1
#define WT_PARAM_SERVER_PORT 2
#define WT_PARAM_NETWORK_PROTOCAL 3
/* the UI parameters for desktop(Windows,MacOS, Linux) application begin with WT_PARAM_D_ */
#define WT_PARAM_D_WIN0_WIDTH 1
/* the UI parameters for mobile(iOS, Android) application begin with WT_PARAM_M_ */
#define WT_PARAM_M_DUMMY 1
#define WT_ICON_SMALL_SIZE 32
#define WT_ICON_LARGE_SIZE 128
#define WT_UI_BMP_MYLARGEICON 0
#define WT_UI_BMP_MYSMALLICON 1
#define WT_UI_BMP_AILARGEICON 2
#define WT_UI_BMP_AISMALLICON 3
#define WT_BYTE uint8_t
#define WT_WORD uint16_t
#define WT_DWORD uint32_t
#define WT_LONG uint32_t
// Define the struct with pack alignment
#pragma pack(push, 1)
typedef struct wtBITMAPFILEHEADER
{
WT_WORD bfType;
WT_DWORD bfSize;
WT_WORD bfReserved1;
WT_WORD bfReserved2;
WT_DWORD bfOffBits;
} WT_BITMAPFILEHEADER;
typedef struct wtBITMAPINFOHEADER
{
WT_DWORD biSize;
WT_LONG biWidth;
WT_LONG biHeight;
WT_WORD biPlanes;
WT_WORD biBitCount;
WT_DWORD biCompression;
WT_DWORD biSizeImage;
WT_LONG biXPelsPerMeter;
WT_LONG biYPelsPerMeter;
WT_DWORD biClrUsed;
WT_DWORD biClrImportant;
} WT_BITMAPINFOHEADER;
// Restore the original packing alignment
#pragma pack(pop)
#ifdef __cplusplus
}
#endif
#endif /* __WT_WOCHATYPES_H__ */