14192
|
1 /**
|
|
2 * The QQ2003C protocol plugin
|
|
3 *
|
|
4 * for gaim
|
|
5 *
|
|
6 * Copyright (C) 2004 Puzzlebird
|
|
7 * Henry Ou <henry@linux.net>
|
|
8 *
|
|
9 * This program is free software; you can redistribute it and/or modify
|
|
10 * it under the terms of the GNU General Public License as published by
|
|
11 * the Free Software Foundation; either version 2 of the License, or
|
|
12 * (at your option) any later version.
|
|
13 *
|
|
14 * This program is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
22 */
|
|
23
|
|
24 #include "cipher.h"
|
|
25 #include "debug.h"
|
|
26 #include "internal.h"
|
|
27
|
|
28 #ifdef _WIN32
|
|
29 #define random rand
|
|
30 #define srandom srand
|
|
31 #endif
|
|
32
|
|
33 #include "packet_parse.h"
|
|
34 #include "buddy_info.h"
|
|
35 #include "buddy_opt.h"
|
|
36 #include "char_conv.h"
|
|
37 #include "group_free.h"
|
|
38 #include "login_logout.h"
|
|
39 #include "qq_proxy.h"
|
|
40 #include "recv_core.h"
|
|
41 #include "send_core.h"
|
|
42 #include "sendqueue.h"
|
|
43 #include "udp_proxy_s5.h"
|
|
44 #include "utils.h"
|
|
45
|
14195
|
46 /* These functions are used only in development phase */
|
|
47 /*
|
14192
|
48 static void _qq_show_socket(gchar *desc, gint fd) {
|
|
49 struct sockaddr_in sin;
|
14195
|
50 socklen_t len = sizeof(sin);
|
14192
|
51 getsockname(fd, (struct sockaddr *)&sin, &len);
|
|
52 gaim_debug(GAIM_DEBUG_INFO, desc, "%s:%d\n",
|
|
53 inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
|
|
54 }
|
|
55 */
|
|
56
|
|
57 void _qq_show_packet(const gchar *desc, const guint8 *buf, gint len)
|
|
58 {
|
|
59 char buf1[8*len+2], buf2[10];
|
|
60 int i;
|
|
61 buf1[0] = 0;
|
|
62 for (i = 0; i < len; i++) {
|
|
63 sprintf(buf2, " %02x(%d)", buf[i] & 0xff, buf[i] & 0xff);
|
|
64 strcat(buf1, buf2);
|
|
65 }
|
|
66 strcat(buf1, "\n");
|
|
67 gaim_debug(GAIM_DEBUG_INFO, desc, buf1);
|
|
68 }
|
|
69
|
|
70 /* QQ 2003iii uses double MD5 for the pwkey to get the session key */
|
|
71 static guint8 *_gen_pwkey(const gchar *pwd)
|
|
72 {
|
|
73 GaimCipher *cipher;
|
|
74 GaimCipherContext *context;
|
|
75
|
|
76 guchar pwkey_tmp[QQ_KEY_LENGTH];
|
|
77
|
|
78 cipher = gaim_ciphers_find_cipher("md5");
|
|
79 context = gaim_cipher_context_new(cipher, NULL);
|
|
80 gaim_cipher_context_append(context, (guchar *) pwd, strlen(pwd));
|
|
81 gaim_cipher_context_digest(context, sizeof(pwkey_tmp), pwkey_tmp, NULL);
|
|
82 gaim_cipher_context_destroy(context);
|
|
83 context = gaim_cipher_context_new(cipher, NULL);
|
|
84 gaim_cipher_context_append(context, pwkey_tmp, QQ_KEY_LENGTH);
|
|
85 gaim_cipher_context_digest(context, sizeof(pwkey_tmp), pwkey_tmp, NULL);
|
|
86 gaim_cipher_context_destroy(context);
|
|
87
|
|
88 return g_memdup(pwkey_tmp, QQ_KEY_LENGTH);
|
|
89 }
|
|
90
|
14195
|
91 static gboolean _qq_fill_host(GSList *hosts, struct sockaddr_in *addr, gint *addr_size)
|
14192
|
92 {
|
14195
|
93 if (!hosts || !hosts->data)
|
|
94 return FALSE;
|
|
95
|
|
96 *addr_size = GPOINTER_TO_INT(hosts->data);
|
|
97
|
|
98 hosts = g_slist_remove(hosts, hosts->data);
|
|
99 memcpy(addr, hosts->data, *addr_size);
|
|
100 g_free(hosts->data);
|
|
101 hosts = g_slist_remove(hosts, hosts->data);
|
|
102 while(hosts) {
|
|
103 hosts = g_slist_remove(hosts, hosts->data);
|
|
104 g_free(hosts->data);
|
|
105 hosts = g_slist_remove(hosts, hosts->data);
|
14192
|
106 }
|
|
107
|
14195
|
108 return TRUE;
|
14192
|
109 }
|
|
110
|
|
111 /* set up any finalizing start-up stuff */
|
|
112 static void _qq_start_services(GaimConnection *gc)
|
|
113 {
|
|
114 /* start watching for IMs about to be sent */
|
|
115 /*
|
|
116 gaim_signal_connect(gaim_conversations_get_handle(),
|
|
117 "sending-im-msg", gc,
|
|
118 GAIM_CALLBACK(qq_sending_im_msg_cb), NULL);
|
|
119 */
|
|
120 }
|
|
121
|
|
122 /* the callback function after socket is built
|
|
123 * we setup the qq protocol related configuration here */
|
|
124 static void _qq_got_login(gpointer data, gint source, const gchar *error_message)
|
|
125 {
|
|
126 qq_data *qd;
|
|
127 GaimConnection *gc;
|
|
128 gchar *buf;
|
|
129 const gchar *passwd;
|
|
130
|
|
131 gc = (GaimConnection *) data;
|
|
132
|
|
133 if (!GAIM_CONNECTION_IS_VALID(gc)) {
|
|
134 close(source);
|
|
135 return;
|
|
136 }
|
|
137
|
|
138 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
139
|
|
140 if (source < 0) { /* socket returns -1 */
|
14195
|
141 gaim_connection_error(gc, error_message);
|
14192
|
142 return;
|
|
143 }
|
|
144
|
|
145 qd = (qq_data *) gc->proto_data;
|
|
146
|
14195
|
147 /*
|
|
148 _qq_show_socket("Got login socket", source);
|
|
149 */
|
|
150
|
14192
|
151 /* QQ use random seq, to minimize duplicated packets */
|
|
152 srandom(time(NULL));
|
|
153 qd->send_seq = random() & 0x0000ffff;
|
|
154 qd->fd = source;
|
|
155 qd->logged_in = FALSE;
|
|
156 qd->channel = 1;
|
|
157 qd->uid = strtol(gaim_account_get_username(gaim_connection_get_account(gc)), NULL, 10);
|
|
158 qd->before_login_packets = g_queue_new();
|
|
159
|
|
160 /* now generate md5 processed passwd */
|
|
161 passwd = gaim_account_get_password(gaim_connection_get_account(gc));
|
|
162 qd->pwkey = _gen_pwkey(passwd);
|
|
163
|
|
164 qd->sendqueue_timeout = gaim_timeout_add(QQ_SENDQUEUE_TIMEOUT, qq_sendqueue_timeout_callback, gc);
|
|
165 gc->inpa = gaim_input_add(qd->fd, GAIM_INPUT_READ, qq_input_pending, gc);
|
|
166
|
|
167 /* Update the login progress status display */
|
|
168 buf = g_strdup_printf("Login as %d", qd->uid);
|
|
169 gaim_connection_update_progress(gc, buf, 1, QQ_CONNECT_STEPS);
|
|
170 g_free(buf);
|
|
171
|
|
172 _qq_start_services(gc);
|
|
173
|
|
174 qq_send_packet_request_login_token(gc);
|
|
175 }
|
|
176
|
|
177 /* clean up qq_data structure and all its components
|
|
178 * always used before a redirectly connection */
|
|
179 static void _qq_common_clean(GaimConnection *gc)
|
|
180 {
|
|
181 qq_data *qd;
|
|
182
|
|
183 g_return_if_fail(gc != NULL && gc->proto_data != NULL);
|
|
184 qd = (qq_data *) gc->proto_data;
|
|
185
|
|
186 /* finish all I/O */
|
|
187 if (qd->fd >= 0 && qd->logged_in)
|
|
188 qq_send_packet_logout(gc);
|
|
189 close(qd->fd);
|
|
190
|
|
191 if (qd->sendqueue_timeout > 0) {
|
|
192 gaim_timeout_remove(qd->sendqueue_timeout);
|
|
193 qd->sendqueue_timeout = 0;
|
|
194 }
|
|
195
|
|
196 if (gc->inpa > 0) {
|
|
197 gaim_input_remove(gc->inpa);
|
|
198 gc->inpa = 0;
|
|
199 }
|
|
200
|
|
201 qq_b4_packets_free(qd);
|
|
202 qq_sendqueue_free(qd);
|
|
203 qq_group_packets_free(qd);
|
|
204 qq_group_free_all(qd);
|
|
205 qq_add_buddy_request_free(qd);
|
|
206 qq_info_query_free(qd);
|
|
207 qq_buddies_list_free(gc->account, qd);
|
|
208 }
|
|
209
|
14195
|
210 static void no_one_calls(gpointer data, gint source, GaimInputCondition cond)
|
|
211 {
|
|
212 struct PHB *phb = data;
|
|
213 socklen_t len;
|
|
214 int error=0, ret;
|
|
215
|
|
216 gaim_debug_info("proxy", "Connected.\n");
|
|
217
|
|
218 len = sizeof(error);
|
|
219
|
|
220 /*
|
|
221 * getsockopt after a non-blocking connect returns -1 if something is
|
|
222 * really messed up (bad descriptor, usually). Otherwise, it returns 0 and
|
|
223 * error holds what connect would have returned if it blocked until now.
|
|
224 * Thus, error == 0 is success, error == EINPROGRESS means "try again",
|
|
225 * and anything else is a real error.
|
|
226 *
|
|
227 * (error == EINPROGRESS can happen after a select because the kernel can
|
|
228 * be overly optimistic sometimes. select is just a hint that you might be
|
|
229 * able to do something.)
|
|
230 */
|
|
231 ret = getsockopt(source, SOL_SOCKET, SO_ERROR, &error, &len);
|
|
232 if (ret == 0 && error == EINPROGRESS)
|
|
233 return; /* we'll be called again later */
|
|
234 if (ret < 0 || error != 0) {
|
|
235 if(ret!=0)
|
|
236 error = errno;
|
|
237 close(source);
|
|
238 gaim_input_remove(phb->inpa);
|
|
239
|
|
240 gaim_debug_error("proxy", "getsockopt SO_ERROR check: %s\n", strerror(error));
|
|
241
|
|
242 phb->func(phb->data, -1, _("Unable to connect"));
|
|
243 return;
|
|
244 }
|
|
245
|
|
246 gaim_input_remove(phb->inpa);
|
|
247
|
|
248 if (phb->account == NULL || gaim_account_get_connection(phb->account) != NULL) {
|
|
249
|
|
250 phb->func(phb->data, source, NULL);
|
|
251 }
|
|
252
|
|
253 g_free(phb->host);
|
|
254 g_free(phb);
|
|
255 }
|
|
256
|
|
257 /* returns -1 if fails, otherwise returns the file handle */
|
14192
|
258 static gint _qq_proxy_none(struct PHB *phb, struct sockaddr *addr, socklen_t addrlen)
|
|
259 {
|
|
260 gint fd = -1;
|
|
261
|
|
262 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Using UDP without proxy\n");
|
|
263 fd = socket(PF_INET, SOCK_DGRAM, 0);
|
|
264
|
|
265 if (fd < 0) {
|
14195
|
266 gaim_debug(GAIM_DEBUG_ERROR, "QQ Redirect",
|
|
267 "Unable to create socket: %s\n", strerror(errno));
|
14192
|
268 return -1;
|
|
269 }
|
|
270
|
|
271 /* we use non-blocking mode to speed up connection */
|
|
272 fcntl(fd, F_SETFL, O_NONBLOCK);
|
|
273
|
|
274 /* From Unix-socket-FAQ: http://www.faqs.org/faqs/unix-faq/socket/
|
|
275 *
|
|
276 * If a UDP socket is unconnected, which is the normal state after a
|
|
277 * bind() call, then send() or write() are not allowed, since no
|
|
278 * destination is available; only sendto() can be used to send data.
|
|
279 *
|
|
280 * Calling connect() on the socket simply records the specified address
|
|
281 * and port number as being the desired communications partner. That
|
|
282 * means that send() or write() are now allowed; they use the destination
|
|
283 * address and port given on the connect call as the destination of packets.
|
|
284 */
|
|
285 if (connect(fd, addr, addrlen) < 0) {
|
|
286 /* [EINPROGRESS]
|
|
287 * The socket is marked as non-blocking and the connection cannot be
|
|
288 * completed immediately. It is possible to select for completion by
|
|
289 * selecting the socket for writing.
|
|
290 * [EINTR]
|
|
291 * A signal interrupted the call.
|
|
292 * The connection is established asynchronously.
|
|
293 */
|
|
294 if ((errno == EINPROGRESS) || (errno == EINTR)) {
|
|
295 gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Connect in asynchronous mode.\n");
|
14195
|
296 phb->inpa = gaim_input_add(fd, GAIM_INPUT_WRITE, no_one_calls, phb);
|
14192
|
297 } else {
|
14195
|
298 gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Connection failed: %d\n", strerror(errno));
|
14192
|
299 close(fd);
|
|
300 return -1;
|
|
301 } /* if errno */
|
|
302 } else { /* connect returns 0 */
|
|
303 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Connected.\n");
|
|
304 fcntl(fd, F_SETFL, 0);
|
|
305 phb->func(phb->data, fd, NULL);
|
|
306 }
|
|
307
|
|
308 return fd;
|
|
309 }
|
|
310
|
14195
|
311 static void _qq_proxy_resolved(GSList *hosts, gpointer data, const char *error_message)
|
|
312 {
|
|
313 struct PHB *phb = (struct PHB *) data;
|
|
314 struct sockaddr_in addr;
|
|
315 gint addr_size, ret = -1;
|
|
316
|
|
317 if(_qq_fill_host(hosts, &addr, &addr_size))
|
|
318 ret = qq_proxy_socks5(phb, (struct sockaddr *) &addr, addr_size);
|
|
319
|
|
320 if (ret < 0) {
|
|
321 phb->func(phb->data, -1, _("Unable to connect"));
|
|
322 g_free(phb->host);
|
|
323 g_free(phb);
|
|
324 }
|
|
325 }
|
|
326
|
|
327 static void _qq_server_resolved(GSList *hosts, gpointer data, const char *error_message)
|
|
328 {
|
|
329 struct PHB *phb = (struct PHB *) data;
|
|
330 GaimConnection *gc = (GaimConnection *) phb->data;
|
|
331 qq_data *qd = (qq_data *) gc->proto_data;
|
|
332 struct sockaddr_in addr;
|
|
333 gint addr_size, ret = -1;
|
|
334
|
|
335 if(_qq_fill_host(hosts, &addr, &addr_size)) {
|
|
336 switch (gaim_proxy_info_get_type(phb->gpi)) {
|
|
337 case GAIM_PROXY_NONE:
|
|
338 ret = _qq_proxy_none(phb, (struct sockaddr *) &addr, addr_size);
|
|
339 break;
|
|
340 case GAIM_PROXY_SOCKS5:
|
|
341 ret = 0;
|
|
342 if (gaim_proxy_info_get_host(phb->gpi) == NULL ||
|
|
343 gaim_proxy_info_get_port(phb->gpi) == 0) {
|
|
344 gaim_debug(GAIM_DEBUG_ERROR, "QQ",
|
|
345 "Use of socks5 proxy selected but host or port info doesn't exist.\n");
|
|
346 ret = -1;
|
|
347 } else {
|
|
348 /* as the destination is always QQ server during the session,
|
|
349 * we can set dest_sin here, instead of _qq_s5_canread_again */
|
|
350 memcpy(&qd->dest_sin, &addr, addr_size);
|
|
351 if (gaim_dnsquery_a(gaim_proxy_info_get_host(phb->gpi),
|
|
352 gaim_proxy_info_get_port(phb->gpi),
|
|
353 _qq_proxy_resolved, phb) == NULL)
|
|
354 ret = -1;
|
|
355 }
|
|
356 break;
|
|
357 default:
|
|
358 gaim_debug(GAIM_DEBUG_WARNING, "QQ",
|
|
359 "Proxy type %i is unsupported, not using a proxy.\n",
|
|
360 gaim_proxy_info_get_type(phb->gpi));
|
|
361 ret = _qq_proxy_none(phb, (struct sockaddr *) &addr, addr_size);
|
|
362 }
|
|
363 }
|
|
364
|
|
365 if (ret < 0) {
|
|
366 phb->func(gc, -1, _("Unable to connect"));
|
|
367 g_free(phb->host);
|
|
368 g_free(phb);
|
|
369 }
|
|
370 }
|
|
371
|
|
372 /* returns -1 if dns lookup fails, otherwise returns 0 */
|
14192
|
373 static gint _qq_udp_proxy_connect(GaimAccount *account,
|
14195
|
374 const gchar *server, guint16 port,
|
|
375 void callback(gpointer, gint, const gchar *error_message),
|
|
376 GaimConnection *gc)
|
14192
|
377 {
|
14195
|
378 GaimProxyInfo *info;
|
14192
|
379 struct PHB *phb;
|
14195
|
380 qq_data *qd = (qq_data *) gc->proto_data;
|
14192
|
381
|
14195
|
382 g_return_val_if_fail(gc != NULL && qd != NULL, -1);
|
14192
|
383
|
14195
|
384 info = gaim_proxy_get_setup(account);
|
14192
|
385
|
|
386 phb = g_new0(struct PHB, 1);
|
|
387 phb->host = g_strdup(server);
|
|
388 phb->port = port;
|
|
389 phb->account = account;
|
|
390 phb->gpi = info;
|
|
391 phb->func = callback;
|
|
392 phb->data = gc;
|
14195
|
393 qd->proxy_type = gaim_proxy_info_get_type(phb->gpi);
|
14192
|
394
|
14195
|
395 gaim_debug(GAIM_DEBUG_INFO, "QQ", "Choosing proxy type %d\n",
|
|
396 gaim_proxy_info_get_type(phb->gpi));
|
14192
|
397
|
14195
|
398 if (gaim_dnsquery_a(server, port, _qq_server_resolved, phb) == NULL) {
|
|
399 phb->func(gc, -1, _("Unable to connect"));
|
|
400 g_free(phb->host);
|
|
401 g_free(phb);
|
|
402 return -1;
|
|
403 } else {
|
|
404 return 0;
|
14192
|
405 }
|
|
406 }
|
|
407
|
|
408 /* QQ connection via UDP/TCP.
|
14195
|
409 * I use Gaim proxy function to provide TCP proxy support,
|
|
410 * and qq_udp_proxy.c to add UDP proxy support (thanks henry) */
|
14192
|
411 static gint _proxy_connect_full (GaimAccount *account, const gchar *host, guint16 port,
|
|
412 GaimProxyConnectFunction func, gpointer data, gboolean use_tcp)
|
|
413 {
|
|
414 GaimConnection *gc;
|
|
415 qq_data *qd;
|
|
416
|
|
417 gc = gaim_account_get_connection(account);
|
|
418 qd = (qq_data *) gc->proto_data;
|
|
419 qd->server_ip = g_strdup(host);
|
|
420 qd->server_port = port;
|
|
421
|
14195
|
422 if(use_tcp)
|
14192
|
423 return (gaim_proxy_connect(account, host, port, func, data) == NULL);
|
|
424 else
|
|
425 return _qq_udp_proxy_connect(account, host, port, func, data);
|
|
426 }
|
|
427
|
|
428 /* establish a generic QQ connection
|
14195
|
429 * TCP/UDP, and direct/redirected */
|
|
430 gint qq_connect(GaimAccount *account, const gchar *host, guint16 port,
|
|
431 gboolean use_tcp, gboolean is_redirect)
|
14192
|
432 {
|
|
433 GaimConnection *gc;
|
|
434
|
|
435 g_return_val_if_fail(host != NULL, -1);
|
|
436 g_return_val_if_fail(port > 0, -1);
|
|
437
|
|
438 gc = gaim_account_get_connection(account);
|
|
439 g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1);
|
|
440
|
|
441 if (is_redirect)
|
|
442 _qq_common_clean(gc);
|
|
443
|
|
444 return _proxy_connect_full(account, host, port, _qq_got_login, gc, use_tcp);
|
|
445 }
|
|
446
|
|
447 /* clean up the given QQ connection and free all resources */
|
|
448 void qq_disconnect(GaimConnection *gc)
|
|
449 {
|
|
450 qq_data *qd;
|
|
451
|
|
452 g_return_if_fail(gc != NULL);
|
|
453
|
|
454 _qq_common_clean(gc);
|
|
455
|
|
456 qd = gc->proto_data;
|
|
457 g_free(qd->inikey);
|
|
458 g_free(qd->pwkey);
|
|
459 g_free(qd->session_key);
|
|
460 g_free(qd->my_ip);
|
|
461 g_free(qd);
|
|
462
|
|
463 gc->proto_data = NULL;
|
|
464 }
|
|
465
|
|
466 /* send packet with proxy support */
|
|
467 gint qq_proxy_write(qq_data *qd, guint8 *data, gint len)
|
|
468 {
|
|
469 guint8 *buf;
|
|
470 gint ret;
|
|
471
|
|
472 g_return_val_if_fail(qd != NULL && qd->fd >= 0 && data != NULL && len > 0, -1);
|
|
473
|
|
474 /* TCP sock5 may be processed twice
|
|
475 * so we need to check qd->use_tcp as well */
|
|
476 if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { /* UDP sock5 */
|
|
477 buf = g_newa(guint8, len + 10);
|
|
478 buf[0] = 0x00;
|
|
479 buf[1] = 0x00; /* reserved */
|
|
480 buf[2] = 0x00; /* frag */
|
|
481 buf[3] = 0x01; /* type */
|
|
482 g_memmove(buf + 4, &(qd->dest_sin.sin_addr.s_addr), 4);
|
|
483 g_memmove(buf + 8, &(qd->dest_sin.sin_port), 2);
|
|
484 g_memmove(buf + 10, data, len);
|
14195
|
485 errno = 0;
|
14192
|
486 ret = send(qd->fd, buf, len + 10, 0);
|
|
487 } else {
|
14195
|
488 errno = 0;
|
14192
|
489 ret = send(qd->fd, data, len, 0);
|
|
490 }
|
14195
|
491 if (ret == -1) {
|
|
492 gaim_connection_error(qd->gc, _("Socket send error"));
|
|
493 return ret;
|
|
494 } else if (errno == ECONNREFUSED) {
|
|
495 gaim_connection_error(qd->gc, _("Connection refused"));
|
|
496 return ret;
|
|
497 }
|
14192
|
498
|
|
499 return ret;
|
|
500 }
|
|
501
|
|
502 /* read packet input with proxy support */
|
|
503 gint qq_proxy_read(qq_data *qd, guint8 *data, gint len)
|
|
504 {
|
|
505 guint8 *buf;
|
|
506 gint bytes;
|
|
507 buf = g_newa(guint8, MAX_PACKET_SIZE + 10);
|
|
508
|
|
509 g_return_val_if_fail(qd != NULL && data != NULL && len > 0, -1);
|
|
510 g_return_val_if_fail(qd->fd > 0, -1);
|
|
511
|
|
512 bytes = read(qd->fd, buf, len + 10);
|
|
513 if (bytes < 0)
|
|
514 return -1;
|
|
515
|
|
516 if ((!qd->use_tcp) && qd->proxy_type == GAIM_PROXY_SOCKS5) { /* UDP sock5 */
|
|
517 if (bytes < 10)
|
|
518 return -1;
|
|
519 bytes -= 10;
|
|
520 g_memmove(data, buf + 10, bytes); /* cut off the header */
|
|
521 } else {
|
|
522 g_memmove(data, buf, bytes);
|
|
523 }
|
|
524
|
|
525 return bytes;
|
|
526 }
|