comparison src/protocols/gg/libgg.h @ 2792:9123abd0db92

[gaim-migrate @ 2805] Arkadiusz Miskiewicz's updates to Gadu-Gadu committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 26 Nov 2001 21:22:56 +0000
parents 1950afffd107
children 4b3f17ca66bf
comparison
equal deleted inserted replaced
2791:8f6365332a05 2792:9123abd0db92
1 /* $Id: libgg.h 2523 2001-10-15 19:18:19Z warmenhoven $ */ 1 /* $Id: libgg.h 2805 2001-11-26 21:22:56Z warmenhoven $ */
2 2
3 /* 3 /*
4 * (C) Copyright 2001 Wojtek Kaniewski <wojtekka@irc.pl> 4 * (C) Copyright 2001 Wojtek Kaniewski <wojtekka@irc.pl>,
5 * Robert J. Woźny <speedy@atman.pl>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2 as 8 * it under the terms of the GNU General Public License Version 2 as
8 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
9 * 10 *
22 23
23 #ifdef __cplusplus 24 #ifdef __cplusplus
24 extern "C" { 25 extern "C" {
25 #endif 26 #endif
26 27
27 #define GG_DEBUG 1 28 #if defined(sun) && !defined(INADDR_NONE)
28
29 #ifndef INADDR_NONE
30 #define INADDR_NONE 0xffffffff 29 #define INADDR_NONE 0xffffffff
31 #endif 30 #endif
32 31
32 #include <sys/types.h>
33
33 /* 34 /*
34 * typ zmiennej określającej numerek danej osoby. 35 * typ zmiennej określającej numerek danej osoby.
35 */ 36 */
36 typedef unsigned int uin_t; 37 typedef unsigned long uin_t;
37 38
38 /* 39 /*
39 * cośtam. 40 * cośtam.
40 */ 41 */
41 struct gg_session { 42 struct gg_session {
42 int state, check; 43 int state, check;
43 int fd, pid; 44 int fd, pid;
44 int port; 45 int port;
45 int seq, async; 46 int seq, async;
46 47 int last_pong;
47 uin_t uin; 48
48 char *password; 49 /* powinno być ,,in_addr'', ale nie chcę inkludować sieci tutaj */
49 50 unsigned long server_ip;
50 char *recv_buf; 51
51 int recv_done, recv_left; 52 uin_t uin;
52 }; 53 char *password;
54 int initial_status;
55
56 char *recv_buf;
57 int recv_done, recv_left;
58 };
53 59
54 /* 60 /*
55 * różne stany asynchronicznej maszynki. 61 * różne stany asynchronicznej maszynki.
56 */ 62 */
57 enum { 63 enum {
58 GG_STATE_IDLE = 0, /* wspólne */ 64 GG_STATE_IDLE = 0, /* wspólne */
59 GG_STATE_RESOLVING, 65 GG_STATE_RESOLVING,
60 GG_STATE_CONNECTING_HTTP, 66 GG_STATE_CONNECTING_HTTP,
61 67
62 GG_STATE_WRITING_HTTP, /* gg_login */ 68 GG_STATE_WRITING_HTTP, /* gg_login */
63 GG_STATE_CONNECTING_GG, 69 GG_STATE_CONNECTING_GG,
64 GG_STATE_WAITING_FOR_KEY, 70 GG_STATE_WAITING_FOR_KEY,
65 GG_STATE_SENDING_KEY, 71 GG_STATE_SENDING_KEY,
66 GG_STATE_CONNECTED, 72 GG_STATE_CONNECTED,
67 73
68 GG_STATE_READING_HEADER, /* gg_search */ 74 GG_STATE_READING_HEADER, /* gg_search */
69 GG_STATE_READING_DATA, 75 GG_STATE_READING_DATA,
70 GG_STATE_PARSING, 76 GG_STATE_PARSING,
71 GG_STATE_FINISHED, 77 GG_STATE_FINISHED,
72 }; 78 };
73 79
74 /* 80 /*
75 * co proces klienta powinien sprawdzać w deskryptorach? 81 * co proces klienta powinien sprawdzać w deskryptorach?
76 */ 82 */
77 enum { 83 enum {
78 GG_CHECK_NONE = 0, 84 GG_CHECK_NONE = 0,
79 GG_CHECK_WRITE = 1, 85 GG_CHECK_WRITE = 1,
80 GG_CHECK_READ = 2, 86 GG_CHECK_READ = 2,
81 }; 87 };
82 88
83 struct gg_session *gg_login(uin_t uin, char *password, int async); 89 struct gg_session *gg_login(uin_t uin, char *password, int async);
84 void gg_free_session(struct gg_session *sess); 90 void gg_free_session(struct gg_session *sess);
85 void gg_logoff(struct gg_session *sess); 91 void gg_logoff(struct gg_session *sess);
86 int gg_change_status(struct gg_session *sess, int status); 92 int gg_change_status(struct gg_session *sess, int status);
87 int gg_send_message(struct gg_session *sess, int msgclass, uin_t recipient, unsigned char *message); 93 int gg_send_message(struct gg_session *sess, int msgclass, uin_t recipient,
88 int gg_ping(struct gg_session *sess); 94 unsigned char *message);
89 95 int gg_ping(struct gg_session *sess);
90 struct gg_notify_reply { 96
91 uin_t uin; /* numerek */ 97 struct gg_notify_reply {
92 int status; /* status danej osoby */ 98 uin_t uin; /* numerek */
93 int remote_ip; /* adres ip delikwenta */ 99 unsigned long status; /* status danej osoby */
94 short remote_port; /* port, na którym słucha klient */ 100 unsigned long remote_ip; /* adres ip delikwenta */
95 int dunno1; /* == 0x0b */ 101 unsigned short remote_port; /* port, na którym słucha klient */
96 short dunno2; /* znowu port? */ 102 unsigned long dunno1; /* == 0x0b */
97 } __attribute__ ((packed)); 103 unsigned short dunno2; /* znowu port? */
98 104 } __attribute__ ((packed));
99 struct gg_status { 105
100 uin_t uin; /* numerek */ 106 struct gg_status {
101 int status; /* nowy stan */ 107 uin_t uin; /* numerek */
102 } __attribute__ ((packed)); 108 unsigned long status; /* nowy stan */
103 109 } __attribute__ ((packed));
104 enum { 110
105 GG_EVENT_NONE = 0, 111 enum {
106 GG_EVENT_MSG, 112 GG_EVENT_NONE = 0,
107 GG_EVENT_NOTIFY, 113 GG_EVENT_MSG,
108 GG_EVENT_STATUS, 114 GG_EVENT_NOTIFY,
109 GG_EVENT_ACK, 115 GG_EVENT_STATUS,
110 GG_EVENT_CONN_FAILED, 116 GG_EVENT_ACK,
111 GG_EVENT_CONN_SUCCESS, 117 GG_EVENT_CONN_FAILED,
112 }; 118 GG_EVENT_CONN_SUCCESS,
113 119 };
114 enum { 120
115 GG_FAILURE_RESOLVING = 1, 121 enum {
116 GG_FAILURE_CONNECTING, 122 GG_FAILURE_RESOLVING = 1,
117 GG_FAILURE_INVALID, 123 GG_FAILURE_CONNECTING,
118 GG_FAILURE_READING, 124 GG_FAILURE_INVALID,
119 GG_FAILURE_WRITING, 125 GG_FAILURE_READING,
120 GG_FAILURE_PASSWORD, 126 GG_FAILURE_WRITING,
121 }; 127 GG_FAILURE_PASSWORD,
122 128 };
123 struct gg_event { 129
124 int type; 130 struct gg_event {
125 union { 131 int type;
126 struct { 132 union {
127 uin_t sender; 133 struct {
128 int msgclass; 134 uin_t sender;
129 unsigned char *message; 135 int msgclass;
130 } msg; 136 time_t time;
131 struct gg_notify_reply *notify; 137 unsigned char *message;
132 struct gg_status status; 138 } msg;
133 struct { 139 struct gg_notify_reply *notify;
134 uin_t recipient; 140 struct gg_status status;
135 int status; 141 struct {
136 int seq; 142 uin_t recipient;
137 } ack; 143 int status;
138 int failure; 144 int seq;
139 } event; 145 } ack;
140 }; 146 int failure;
141 147 } event;
142 struct gg_event *gg_watch_fd(struct gg_session *sess); 148 };
143 void gg_free_event(struct gg_event *e); 149
144 150 struct gg_event *gg_watch_fd(struct gg_session *sess);
145 int gg_notify(struct gg_session *sess, uin_t *userlist, int count); 151 void gg_free_event(struct gg_event *e);
146 int gg_add_notify(struct gg_session *sess, uin_t uin); 152
147 int gg_remove_notify(struct gg_session *sess, uin_t uin); 153 int gg_notify(struct gg_session *sess, uin_t * userlist, int count);
154 int gg_add_notify(struct gg_session *sess, uin_t uin);
155 int gg_remove_notify(struct gg_session *sess, uin_t uin);
148 156
149 /* 157 /*
150 * jakieśtam bzdurki dotyczące szukania userów. 158 * jakieśtam bzdurki dotyczące szukania userów.
151 */ 159 */
152 160
153 struct gg_search_result { 161 struct gg_search_result {
154 uin_t uin; 162 uin_t uin;
155 char *first_name; 163 char *first_name;
156 char *last_name; 164 char *last_name;
157 char *nickname; 165 char *nickname;
158 int born; 166 int born;
159 int gender; 167 int gender;
160 char *city; 168 char *city;
161 int active; 169 int active;
162 }; 170 };
163 171
164 struct gg_search_request { 172 struct gg_search_request {
165 /* czy ma szukać tylko aktywnych? */ 173 /* czy ma szukać tylko aktywnych? */
166 int active; 174 int active;
167 /* mode 0 */ 175 /* mode 0 */
168 char *nickname, *first_name, *last_name, *city; 176 char *nickname, *first_name, *last_name, *city;
169 int gender, min_birth, max_birth; 177 int gender, min_birth, max_birth;
170 /* mode 1 */ 178 /* mode 1 */
171 char *email; 179 char *email;
172 /* mode 2 */ 180 /* mode 2 */
173 char *phone; 181 char *phone;
174 /* mode 3 */ 182 /* mode 3 */
175 uin_t uin; 183 uin_t uin;
176 }; 184 };
177 185
178 struct gg_search { 186 struct gg_search {
179 struct gg_search_request request; 187 struct gg_search_request request;
180 188
181 /* bzdurki */ 189 /* bzdurki */
182 int mode, fd, async, state, check, error, pid; 190 int mode, fd, async, state, check, error, pid;
183 char *header_buf, *data_buf; 191 char *header_buf, *data_buf;
184 int header_size, data_size; 192 int header_size, data_size;
185 193
186 /* wyniki */ 194 /* wyniki */
187 int count; 195 int count;
188 struct gg_search_result *results; 196 struct gg_search_result *results;
189 }; 197 };
190 198
191 #define GG_GENDER_NONE 0 199 #define GG_GENDER_NONE 0
192 #define GG_GENDER_FEMALE 1 200 #define GG_GENDER_FEMALE 1
193 #define GG_GENDER_MALE 2 201 #define GG_GENDER_MALE 2
194 202
195 struct gg_search *gg_search(struct gg_search_request *r, int async); 203 struct gg_search *gg_search(struct gg_search_request *r, int async);
196 int gg_search_watch_fd(struct gg_search *f); 204 int gg_search_watch_fd(struct gg_search *f);
197 void gg_free_search(struct gg_search *f); 205 void gg_free_search(struct gg_search *f);
198 void gg_search_cancel(struct gg_search *f); 206 void gg_search_cancel(struct gg_search *f);
199 207
200 /* 208 /*
201 * jeśli chcemy sobie podebugować, wystarczy zdefiniować GG_DEBUG. 209 * jeśli chcemy sobie podebugować, wystarczy ustawić `gg_debug_level'.
202 */ 210 * niestety w miarę przybywania wpisów `gg_debug(...)' nie chciało mi
203 211 * się ustawiać odpowiednich leveli, więc większość szła do _MISC.
204 extern int gg_debug_level; 212 */
205 213
206 #ifdef GG_DEBUG 214 extern int gg_debug_level;
207 215
208 # define GG_DEBUG_NET 1 216 #define GG_DEBUG_NET 1
209 # define GG_DEBUG_TRAFFIC 2 217 #define GG_DEBUG_TRAFFIC 2
210 # define GG_DEBUG_DUMP 4 218 #define GG_DEBUG_DUMP 4
211 # define GG_DEBUG_FUNCTION 8 219 #define GG_DEBUG_FUNCTION 8
212 # define GG_DEBUG_MISC 16 220 #define GG_DEBUG_MISC 16
213 221
214 void gg_debug_real(int level, char *format, ...); 222 void gg_debug(int level, char *format, ...);
215 # define gg_debug(x, y...) gg_debug_real(x, y)
216
217 #else
218
219 # define gg_debug(x, y...) while(0) { };
220
221 #endif /* GG_DEBUG */
222 223
223 /* 224 /*
224 * ------------------------------------------------------------------------- 225 * -------------------------------------------------------------------------
225 * poniżej znajdują się wewnętrzne sprawy biblioteki. zwykły klient nie 226 * poniżej znajdują się wewnętrzne sprawy biblioteki. zwykły klient nie
226 * powinien ich w ogóle ruszać, bo i nie ma po co. wszystko można załatwić 227 * powinien ich w ogóle ruszać, bo i nie ma po co. wszystko można załatwić
227 * procedurami wyższego poziomu, których definicje znajdują się na początku 228 * procedurami wyższego poziomu, których definicje znajdują się na początku
228 * tego pliku. 229 * tego pliku.
229 * ------------------------------------------------------------------------- 230 * -------------------------------------------------------------------------
230 */ 231 */
231 232
232 int gg_resolve(int *fd, int *pid, char *hostname); 233 int gg_resolve(int *fd, int *pid, char *hostname);
233 int gg_connect(void *addr, int port, int async); 234 int gg_connect(void *addr, int port, int async);
234 char *gg_alloc_sprintf(char *format, ...); 235 char *gg_alloc_sprintf(char *format, ...);
236 char *gg_get_line(char **ptr);
237 char *gg_urlencode(char *str);
235 238
236 #define GG_APPMSG_HOST "appmsg.gadu-gadu.pl" 239 #define GG_APPMSG_HOST "appmsg.gadu-gadu.pl"
237 #define GG_APPMSG_PORT 80 240 #define GG_APPMSG_PORT 80
238 #define GG_PUBDIR_HOST "pubdir.gadu-gadu.pl" 241 #define GG_PUBDIR_HOST "pubdir.gadu-gadu.pl"
239 #define GG_PUBDIR_PORT 80 242 #define GG_PUBDIR_PORT 80
240 #define GG_DEFAULT_PORT 8074 243 #define GG_DEFAULT_PORT 8074
241 244 #define GG_HTTPS_PORT 443
242 struct gg_header { 245 #define GG_HTTP_USERAGENT "Mozilla/4.7 [en] (Win98; I)"
243 int type; /* typ pakietu */ 246
244 int length; /* długość reszty pakietu */ 247 struct gg_header {
245 } __attribute__ ((packed)); 248 unsigned long type; /* typ pakietu */
249 unsigned long length; /* długość reszty pakietu */
250 } __attribute__ ((packed));
246 251
247 #define GG_WELCOME 0x0001 252 #define GG_WELCOME 0x0001
248 253
249 struct gg_welcome { 254 struct gg_welcome {
250 int key; /* klucz szyfrowania hasła */ 255 unsigned long key; /* klucz szyfrowania hasła */
251 } __attribute__ ((packed)); 256 } __attribute__ ((packed));
252 257
253 #define GG_LOGIN 0x000c 258 #define GG_LOGIN 0x000c
254 259
255 struct gg_login { 260 struct gg_login {
256 uin_t uin; /* twój numerek */ 261 uin_t uin; /* twój numerek */
257 int hash; /* hash hasła */ 262 unsigned long hash; /* hash hasła */
258 int status; /* status na dzień dobry */ 263 unsigned long status; /* status na dzień dobry */
259 int dunno; /* == 0x0b */ 264 unsigned long dunno; /* == 0x0b */
260 int local_ip; /* mój adres ip */ 265 unsigned long local_ip; /* mój adres ip */
261 short local_port; /* port, na którym słucham */ 266 unsigned short local_port; /* port, na którym słucham */
262 } __attribute__ ((packed)); 267 } __attribute__ ((packed));
263 268
264 #define GG_LOGIN_OK 0x0003 269 #define GG_LOGIN_OK 0x0003
265 270
266 #define GG_LOGIN_FAILED 0x0009 271 #define GG_LOGIN_FAILED 0x0009
267 272
268 #define GG_NEW_STATUS 0x0002 273 #define GG_NEW_STATUS 0x0002
269 274
270 #define GG_STATUS_NOT_AVAIL 0x0001 /* rozłączony */ 275 #define GG_STATUS_NOT_AVAIL 0x0001 /* rozłączony */
271 #define GG_STATUS_AVAIL 0x0002 /* dostępny */ 276 #define GG_STATUS_AVAIL 0x0002 /* dostępny */
272 #define GG_STATUS_BUSY 0x0003 /* zajęty */ 277 #define GG_STATUS_BUSY 0x0003 /* zajęty */
273 #define GG_STATUS_INVISIBLE 0x0014 /* niewidoczny (GG 4.6) */ 278 #define GG_STATUS_INVISIBLE 0x0014 /* niewidoczny (GG 4.6) */
274 279
275 #define GG_STATUS_FRIENDS_MASK 0x8000 /* tylko dla znajomych (GG 4.6) */ 280 #define GG_STATUS_FRIENDS_MASK 0x8000 /* tylko dla znajomych (GG 4.6) */
276 281
277 struct gg_new_status { 282 struct gg_new_status {
278 int status; /* na jaki zmienić? */ 283 unsigned long status; /* na jaki zmienić? */
279 } __attribute__ ((packed)); 284 } __attribute__ ((packed));
280 285
281 #define GG_NOTIFY 0x0010 286 #define GG_NOTIFY 0x0010
282 287
283 struct gg_notify { 288 struct gg_notify {
284 uin_t uin; /* numerek danej osoby */ 289 uin_t uin; /* numerek danej osoby */
285 char dunno1; /* == 3 */ 290 char dunno1; /* == 3 */
286 } __attribute__ ((packed)); 291 } __attribute__ ((packed));
287 292
288 #define GG_NOTIFY_REPLY 0x000c /* tak, to samo co GG_LOGIN */ 293 #define GG_NOTIFY_REPLY 0x000c /* tak, to samo co GG_LOGIN */
289 294
290 /* struct gg_notify_reply zadeklarowane wyżej */ 295 /* struct gg_notify_reply zadeklarowane wyżej */
291 296
292 #define GG_ADD_NOTIFY 0x000d 297 #define GG_ADD_NOTIFY 0x000d
293 #define GG_REMOVE_NOTIFY 0x000e 298 #define GG_REMOVE_NOTIFY 0x000e
294 299
295 struct gg_add_remove { 300 struct gg_add_remove {
296 uin_t uin; /* numerek */ 301 uin_t uin; /* numerek */
297 char dunno1; /* == 3 */ 302 char dunno1; /* == 3 */
298 } __attribute__ ((packed)); 303 } __attribute__ ((packed));
299 304
300 #define GG_STATUS 0x0002 305 #define GG_STATUS 0x0002
301 306
302 /* struct gg_status zadeklarowane wcześniej */ 307 /* struct gg_status zadeklarowane wcześniej */
303 308
304 #define GG_SEND_MSG 0x000b 309 #define GG_SEND_MSG 0x000b
305 310
311 #define GG_CLASS_QUEUED 0x0001
312 #define GG_CLASS_OFFLINE GG_CLASS_QUEUED
306 #define GG_CLASS_MSG 0x0004 313 #define GG_CLASS_MSG 0x0004
307 #define GG_CLASS_CHAT 0x0008 314 #define GG_CLASS_CHAT 0x0008
308 315
309 struct gg_send_msg { 316 struct gg_send_msg {
310 int recipient; 317 unsigned long recipient;
311 int seq; 318 unsigned long seq;
312 int msgclass; 319 unsigned long msgclass;
313 } __attribute__ ((packed)); 320 } __attribute__ ((packed));
314 321
315 #define GG_SEND_MSG_ACK 0x0005 322 #define GG_SEND_MSG_ACK 0x0005
316 323
317 #define GG_ACK_DELIVERED 0x0002 324 #define GG_ACK_DELIVERED 0x0002
318 #define GG_ACK_QUEUED 0x0003 325 #define GG_ACK_QUEUED 0x0003
319 326
320 struct gg_send_msg_ack { 327 struct gg_send_msg_ack {
321 int status; 328 unsigned long status;
322 int recipient; 329 unsigned long recipient;
323 int seq; 330 unsigned long seq;
324 } __attribute__ ((packed)); 331 } __attribute__ ((packed));
325 332
326 #define GG_RECV_MSG 0x000a 333 #define GG_RECV_MSG 0x000a
327 334
328 struct gg_recv_msg { 335 struct gg_recv_msg {
329 int sender; 336 unsigned long sender;
330 int dunno1; 337 unsigned long seq;
331 int dunno2; 338 unsigned long time;
332 int msgclass; 339 unsigned long msgclass;
333 } __attribute__ ((packed)); 340 } __attribute__ ((packed));
334 341
335 #define GG_PING 0x0008 342 #define GG_PING 0x0008
336 343
337 #define GG_PONG 0x0007 344 #define GG_PONG 0x0007
338 345
339 #ifdef __cplusplus 346 #ifdef __cplusplus
340 } 347 }
341 #endif 348 #endif
342
343 #endif 349 #endif