2393
|
1 /* $Id: libgg.h 2406 2001-09-29 23:06:30Z warmenhoven $ */
|
|
2
|
|
3 /*
|
|
4 * (C) Copyright 2001 Wojtek Kaniewski <wojtekka@irc.pl>
|
|
5 *
|
|
6 * 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 * published by the Free Software Foundation.
|
|
9 *
|
|
10 * This program is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 * GNU General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License
|
|
16 * along with this program; if not, write to the Free Software
|
|
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
18 */
|
|
19
|
|
20 #ifndef __LIBGG_H
|
|
21 #define __LIBGG_H
|
|
22
|
|
23 #ifdef __cplusplus
|
|
24 extern "C" {
|
|
25 #endif
|
|
26
|
|
27 #define GG_DEBUG 1
|
|
28
|
|
29 /*
|
|
30 * typ zmiennej określającej numerek danej osoby.
|
|
31 */
|
|
32 typedef unsigned int uin_t;
|
|
33
|
|
34 /*
|
|
35 * cośtam.
|
|
36 */
|
|
37 struct gg_session {
|
|
38 int state, check;
|
|
39 int fd, pid;
|
|
40 int port;
|
|
41 int seq, async;
|
|
42
|
|
43 uin_t uin;
|
|
44 char *password;
|
|
45
|
|
46 char *recv_buf;
|
|
47 int recv_done, recv_left;
|
|
48 };
|
|
49
|
|
50 /*
|
|
51 * różne stany asynchronicznej maszynki.
|
|
52 */
|
|
53 enum {
|
|
54 GG_STATE_IDLE = 0, /* wspólne */
|
|
55 GG_STATE_RESOLVING,
|
|
56 GG_STATE_CONNECTING_HTTP,
|
|
57
|
|
58 GG_STATE_WRITING_HTTP, /* gg_login */
|
|
59 GG_STATE_CONNECTING_GG,
|
|
60 GG_STATE_WAITING_FOR_KEY,
|
|
61 GG_STATE_SENDING_KEY,
|
|
62 GG_STATE_CONNECTED,
|
|
63
|
|
64 GG_STATE_READING_HEADER, /* gg_search */
|
|
65 GG_STATE_READING_DATA,
|
|
66 GG_STATE_PARSING,
|
|
67 GG_STATE_FINISHED,
|
|
68 };
|
|
69
|
|
70 /*
|
|
71 * co proces klienta powinien sprawdzać w deskryptorach?
|
|
72 */
|
|
73 enum {
|
|
74 GG_CHECK_NONE = 0,
|
|
75 GG_CHECK_WRITE = 1,
|
|
76 GG_CHECK_READ = 2,
|
|
77 };
|
|
78
|
|
79 struct gg_session *gg_login(uin_t uin, char *password, int async);
|
|
80 void gg_free_session(struct gg_session *sess);
|
|
81 void gg_logoff(struct gg_session *sess);
|
|
82 int gg_change_status(struct gg_session *sess, int status);
|
|
83 int gg_send_message(struct gg_session *sess, int msgclass, uin_t recipient, unsigned char *message);
|
|
84 int gg_ping(struct gg_session *sess);
|
|
85
|
|
86 struct gg_notify_reply {
|
|
87 uin_t uin; /* numerek */
|
|
88 int status; /* status danej osoby */
|
|
89 int remote_ip; /* adres ip delikwenta */
|
|
90 short remote_port; /* port, na którym słucha klient */
|
|
91 int dunno1; /* == 0x0b */
|
|
92 short dunno2; /* znowu port? */
|
|
93 } __attribute__ ((packed));
|
|
94
|
|
95 struct gg_status {
|
|
96 uin_t uin; /* numerek */
|
|
97 int status; /* nowy stan */
|
|
98 } __attribute__ ((packed));
|
|
99
|
|
100 enum {
|
|
101 GG_EVENT_NONE = 0,
|
|
102 GG_EVENT_MSG,
|
|
103 GG_EVENT_NOTIFY,
|
|
104 GG_EVENT_STATUS,
|
|
105 GG_EVENT_ACK,
|
|
106 GG_EVENT_CONN_FAILED,
|
|
107 GG_EVENT_CONN_SUCCESS,
|
|
108 };
|
|
109
|
|
110 enum {
|
|
111 GG_FAILURE_RESOLVING = 1,
|
|
112 GG_FAILURE_CONNECTING,
|
|
113 GG_FAILURE_INVALID,
|
|
114 GG_FAILURE_READING,
|
|
115 GG_FAILURE_WRITING,
|
|
116 GG_FAILURE_PASSWORD,
|
|
117 };
|
|
118
|
|
119 struct gg_event {
|
|
120 int type;
|
|
121 union {
|
|
122 struct {
|
|
123 uin_t sender;
|
|
124 int msgclass;
|
|
125 unsigned char *message;
|
|
126 } msg;
|
|
127 struct gg_notify_reply *notify;
|
|
128 struct gg_status status;
|
|
129 struct {
|
|
130 uin_t recipient;
|
|
131 int status;
|
|
132 int seq;
|
|
133 } ack;
|
|
134 int failure;
|
|
135 } event;
|
|
136 };
|
|
137
|
|
138 struct gg_event *gg_watch_fd(struct gg_session *sess);
|
|
139 void gg_free_event(struct gg_event *e);
|
|
140
|
|
141 int gg_notify(struct gg_session *sess, uin_t *userlist, int count);
|
|
142 int gg_add_notify(struct gg_session *sess, uin_t uin);
|
|
143 int gg_remove_notify(struct gg_session *sess, uin_t uin);
|
|
144
|
|
145 /*
|
|
146 * jakieśtam bzdurki dotyczące szukania userów.
|
|
147 */
|
|
148
|
|
149 struct gg_search_result {
|
|
150 uin_t uin;
|
|
151 char *first_name;
|
|
152 char *last_name;
|
|
153 char *nickname;
|
|
154 int born;
|
|
155 int gender;
|
|
156 char *city;
|
|
157 int active;
|
|
158 };
|
|
159
|
|
160 struct gg_search_request {
|
|
161 /* czy ma szukać tylko aktywnych? */
|
|
162 int active;
|
|
163 /* mode 0 */
|
|
164 char *nickname, *first_name, *last_name, *city;
|
|
165 int gender, min_birth, max_birth;
|
|
166 /* mode 1 */
|
|
167 char *email;
|
|
168 /* mode 2 */
|
|
169 char *phone;
|
|
170 /* mode 3 */
|
|
171 uin_t uin;
|
|
172 };
|
|
173
|
|
174 struct gg_search {
|
|
175 struct gg_search_request request;
|
|
176
|
|
177 /* bzdurki */
|
|
178 int mode, fd, async, state, check, error, pid;
|
|
179 char *header_buf, *data_buf;
|
|
180 int header_size, data_size;
|
|
181
|
|
182 /* wyniki */
|
|
183 int count;
|
|
184 struct gg_search_result *results;
|
|
185 };
|
|
186
|
|
187 #define GG_GENDER_NONE 0
|
|
188 #define GG_GENDER_FEMALE 1
|
|
189 #define GG_GENDER_MALE 2
|
|
190
|
|
191 struct gg_search *gg_search(struct gg_search_request *r, int async);
|
|
192 int gg_search_watch_fd(struct gg_search *f);
|
|
193 void gg_free_search(struct gg_search *f);
|
|
194 void gg_search_cancel(struct gg_search *f);
|
|
195
|
|
196 /*
|
|
197 * jeśli chcemy sobie podebugować, wystarczy zdefiniować GG_DEBUG.
|
|
198 */
|
|
199
|
|
200 int gg_debug_level;
|
|
201
|
|
202 #ifdef GG_DEBUG
|
|
203
|
|
204 # define GG_DEBUG_NET 1
|
|
205 # define GG_DEBUG_TRAFFIC 2
|
|
206 # define GG_DEBUG_DUMP 4
|
|
207 # define GG_DEBUG_FUNCTION 8
|
|
208 # define GG_DEBUG_MISC 16
|
|
209
|
|
210 void gg_debug_real(int level, char *format, ...);
|
|
211 # define gg_debug(x, y...) gg_debug_real(x, y)
|
|
212
|
|
213 #else
|
|
214
|
|
215 # define gg_debug(x, y...) while(0) { };
|
|
216
|
|
217 #endif /* GG_DEBUG */
|
|
218
|
|
219 /*
|
|
220 * -------------------------------------------------------------------------
|
|
221 * poniżej znajdują się wewnętrzne sprawy biblioteki. zwykły klient nie
|
|
222 * powinien ich w ogóle ruszać, bo i nie ma po co. wszystko można załatwić
|
|
223 * procedurami wyższego poziomu, których definicje znajdują się na początku
|
|
224 * tego pliku.
|
|
225 * -------------------------------------------------------------------------
|
|
226 */
|
|
227
|
|
228 int gg_resolve(int *fd, int *pid, char *hostname);
|
|
229 int gg_connect(void *addr, int port, int async);
|
|
230 char *gg_alloc_sprintf(char *format, ...);
|
|
231
|
|
232 #define GG_APPMSG_HOST "appmsg.gadu-gadu.pl"
|
|
233 #define GG_APPMSG_PORT 80
|
|
234 #define GG_PUBDIR_HOST "pubdir.gadu-gadu.pl"
|
|
235 #define GG_PUBDIR_PORT 80
|
|
236 #define GG_DEFAULT_PORT 8074
|
|
237
|
|
238 struct gg_header {
|
|
239 int type; /* typ pakietu */
|
|
240 int length; /* długość reszty pakietu */
|
|
241 } __attribute__ ((packed));
|
|
242
|
|
243 #define GG_WELCOME 0x0001
|
|
244
|
|
245 struct gg_welcome {
|
|
246 int key; /* klucz szyfrowania hasła */
|
|
247 } __attribute__ ((packed));
|
|
248
|
|
249 #define GG_LOGIN 0x000c
|
|
250
|
|
251 struct gg_login {
|
|
252 uin_t uin; /* twój numerek */
|
|
253 int hash; /* hash hasła */
|
|
254 int status; /* status na dzień dobry */
|
|
255 int dunno; /* == 0x0b */
|
|
256 int local_ip; /* mój adres ip */
|
|
257 short local_port; /* port, na którym słucham */
|
|
258 } __attribute__ ((packed));
|
|
259
|
|
260 #define GG_LOGIN_OK 0x0003
|
|
261
|
|
262 #define GG_LOGIN_FAILED 0x0009
|
|
263
|
|
264 #define GG_NEW_STATUS 0x0002
|
|
265
|
|
266 #define GG_STATUS_NOT_AVAIL 0x0001 /* rozłączony */
|
|
267 #define GG_STATUS_AVAIL 0x0002 /* dostępny */
|
|
268 #define GG_STATUS_BUSY 0x0003 /* zajęty */
|
|
269 #define GG_STATUS_INVISIBLE 0x0014 /* niewidoczny (GG 4.6) */
|
|
270
|
|
271 #define GG_STATUS_FRIENDS_MASK 0x8000 /* tylko dla znajomych (GG 4.6) */
|
|
272
|
|
273 struct gg_new_status {
|
|
274 int status; /* na jaki zmienić? */
|
|
275 } __attribute__ ((packed));
|
|
276
|
|
277 #define GG_NOTIFY 0x0010
|
|
278
|
|
279 struct gg_notify {
|
|
280 uin_t uin; /* numerek danej osoby */
|
|
281 char dunno1; /* == 3 */
|
|
282 } __attribute__ ((packed));
|
|
283
|
|
284 #define GG_NOTIFY_REPLY 0x000c /* tak, to samo co GG_LOGIN */
|
|
285
|
|
286 /* struct gg_notify_reply zadeklarowane wyżej */
|
|
287
|
|
288 #define GG_ADD_NOTIFY 0x000d
|
|
289 #define GG_REMOVE_NOTIFY 0x000e
|
|
290
|
|
291 struct gg_add_remove {
|
|
292 uin_t uin; /* numerek */
|
|
293 char dunno1; /* == 3 */
|
|
294 } __attribute__ ((packed));
|
|
295
|
|
296 #define GG_STATUS 0x0002
|
|
297
|
|
298 /* struct gg_status zadeklarowane wcześniej */
|
|
299
|
|
300 #define GG_SEND_MSG 0x000b
|
|
301
|
|
302 #define GG_CLASS_MSG 0x0004
|
|
303 #define GG_CLASS_CHAT 0x0008
|
|
304
|
|
305 struct gg_send_msg {
|
|
306 int recipient;
|
|
307 int seq;
|
|
308 int msgclass;
|
|
309 } __attribute__ ((packed));
|
|
310
|
|
311 #define GG_SEND_MSG_ACK 0x0005
|
|
312
|
|
313 #define GG_ACK_DELIVERED 0x0002
|
|
314 #define GG_ACK_QUEUED 0x0003
|
|
315
|
|
316 struct gg_send_msg_ack {
|
|
317 int status;
|
|
318 int recipient;
|
|
319 int seq;
|
|
320 } __attribute__ ((packed));
|
|
321
|
|
322 #define GG_RECV_MSG 0x000a
|
|
323
|
|
324 struct gg_recv_msg {
|
|
325 int sender;
|
|
326 int dunno1;
|
|
327 int dunno2;
|
|
328 int msgclass;
|
|
329 } __attribute__ ((packed));
|
|
330
|
|
331 #define GG_PING 0x0008
|
|
332
|
|
333 #define GG_PONG 0x0007
|
|
334
|
|
335 #ifdef __cplusplus
|
|
336 }
|
|
337 #endif
|
|
338
|
|
339 #endif
|