Mercurial > pidgin
comparison libpurple/protocols/yahoo/ycht.c @ 27590:a08e84032814
merge of '2348ff22f0ff3453774b8b25b36238465580c609'
and 'e76f11543c2a4aa05bdf584f087cbe3439029661'
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 12 Jul 2009 05:43:38 +0000 |
parents | 09772222714a |
children | 908be3822215 |
comparison
equal
deleted
inserted
replaced
27104:048bcf41deef | 27590:a08e84032814 |
---|---|
34 #include "proxy.h" | 34 #include "proxy.h" |
35 #include "debug.h" | 35 #include "debug.h" |
36 #include "conversation.h" | 36 #include "conversation.h" |
37 #include "util.h" | 37 #include "util.h" |
38 | 38 |
39 #include "yahoo.h" | 39 #include "libymsg.h" |
40 #include "yahoo_packet.h" | 40 #include "yahoo_packet.h" |
41 #include "ycht.h" | 41 #include "ycht.h" |
42 #include "yahoochat.h" | 42 #include "yahoochat.h" |
43 | 43 |
44 /* | 44 /* |
194 static void ycht_packet_dump(const guchar *data, int len) | 194 static void ycht_packet_dump(const guchar *data, int len) |
195 { | 195 { |
196 #ifdef YAHOO_YCHT_DEBUG | 196 #ifdef YAHOO_YCHT_DEBUG |
197 int i; | 197 int i; |
198 | 198 |
199 purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); | 199 purple_debug_misc("yahoo", ""); |
200 | 200 |
201 for (i = 0; i + 1 < len; i += 2) { | 201 for (i = 0; i + 1 < len; i += 2) { |
202 if ((i % 16 == 0) && i) { | 202 if ((i % 16 == 0) && i) { |
203 purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); | 203 purple_debug_misc(NULL, "\n"); |
204 purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); | 204 purple_debug_misc("yahoo", ""); |
205 } | 205 } |
206 | 206 |
207 purple_debug(PURPLE_DEBUG_MISC, NULL, "%02hhx%02hhx ", data[i], data[i + 1]); | 207 purple_debug_misc(NULL, "%02hhx%02hhx ", data[i], data[i + 1]); |
208 } | 208 } |
209 if (i < len) | 209 if (i < len) |
210 purple_debug(PURPLE_DEBUG_MISC, NULL, "%02hhx", data[i]); | 210 purple_debug_misc(NULL, "%02hhx", data[i]); |
211 | 211 |
212 purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); | 212 purple_debug_misc(NULL, "\n"); |
213 purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); | 213 purple_debug_misc("yahoo", ""); |
214 | 214 |
215 for (i = 0; i < len; i++) { | 215 for (i = 0; i < len; i++) { |
216 if ((i % 16 == 0) && i) { | 216 if ((i % 16 == 0) && i) { |
217 purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); | 217 purple_debug_misc(NULL, "\n"); |
218 purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); | 218 purple_debug_misc("yahoo", ""); |
219 } | 219 } |
220 | 220 |
221 if (g_ascii_isprint(data[i])) | 221 if (g_ascii_isprint(data[i])) |
222 purple_debug(PURPLE_DEBUG_MISC, NULL, "%c ", data[i]); | 222 purple_debug_misc(NULL, "%c ", data[i]); |
223 else | 223 else |
224 purple_debug(PURPLE_DEBUG_MISC, NULL, ". "); | 224 purple_debug_misc(NULL, ". "); |
225 } | 225 } |
226 | 226 |
227 purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); | 227 purple_debug_misc(NULL, "\n"); |
228 #endif | 228 #endif /* YAHOO_YCHT_DEBUG */ |
229 } | 229 } |
230 | 230 |
231 static YchtPkt *ycht_packet_new(guint version, guint service, int status) | 231 static YchtPkt *ycht_packet_new(guint version, guint service, int status) |
232 { | 232 { |
233 YchtPkt *ret; | 233 YchtPkt *ret; |
283 if (ret < 0 && errno == EAGAIN) | 283 if (ret < 0 && errno == EAGAIN) |
284 return; | 284 return; |
285 else if (ret <= 0) { | 285 else if (ret <= 0) { |
286 /* TODO: error handling */ | 286 /* TODO: error handling */ |
287 /* | 287 /* |
288 gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), | |
289 g_strerror(errno)); | |
288 purple_connection_error_reason(purple_account_get_connection(irc->account), | 290 purple_connection_error_reason(purple_account_get_connection(irc->account), |
289 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 291 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); |
290 _("Server has disconnected")); | 292 g_free(tmp); |
291 */ | 293 */ |
292 return; | 294 return; |
293 } | 295 } |
294 | 296 |
295 purple_circ_buffer_mark_read(ycht->txbuf, ret); | 297 purple_circ_buffer_mark_read(ycht->txbuf, ret); |
452 } | 454 } |
453 | 455 |
454 static void ycht_connection_error(YchtConn *ycht, const gchar *error) | 456 static void ycht_connection_error(YchtConn *ycht, const gchar *error) |
455 { | 457 { |
456 | 458 |
457 purple_notify_info(ycht->gc, NULL, _("Connection problem with the YCHT server."), error); | 459 purple_notify_info(ycht->gc, NULL, _("Connection problem with the YCHT server"), error); |
458 ycht_connection_close(ycht); | 460 ycht_connection_close(ycht); |
459 } | 461 } |
460 | 462 |
461 static void ycht_pending(gpointer data, gint source, PurpleInputCondition cond) | 463 static void ycht_pending(gpointer data, gint source, PurpleInputCondition cond) |
462 { | 464 { |
471 | 473 |
472 if (errno == EAGAIN) | 474 if (errno == EAGAIN) |
473 /* No worries */ | 475 /* No worries */ |
474 return; | 476 return; |
475 | 477 |
476 tmp = g_strdup_printf(_("Lost connection with server\n%s"), | 478 tmp = g_strdup_printf(_("Lost connection with server: %s"), |
477 g_strerror(errno)); | 479 g_strerror(errno)); |
478 ycht_connection_error(ycht, tmp); | 480 ycht_connection_error(ycht, tmp); |
479 g_free(tmp); | 481 g_free(tmp); |
480 return; | 482 return; |
481 } else if (len == 0) { | 483 } else if (len == 0) { |
482 ycht_connection_error(ycht, _("Server closed the connection.")); | 484 ycht_connection_error(ycht, _("Server closed the connection")); |
483 return; | 485 return; |
484 } | 486 } |
485 | 487 |
486 ycht->rxqueue = g_realloc(ycht->rxqueue, len + ycht->rxlen); | 488 ycht->rxqueue = g_realloc(ycht->rxqueue, len + ycht->rxlen); |
487 memcpy(ycht->rxqueue + ycht->rxlen, buf, len); | 489 memcpy(ycht->rxqueue + ycht->rxlen, buf, len); |
505 | 507 |
506 version = yahoo_get32(ycht->rxqueue + pos); pos += 4; | 508 version = yahoo_get32(ycht->rxqueue + pos); pos += 4; |
507 service = yahoo_get32(ycht->rxqueue + pos); pos += 4; | 509 service = yahoo_get32(ycht->rxqueue + pos); pos += 4; |
508 status = yahoo_get16(ycht->rxqueue + pos); pos += 2; | 510 status = yahoo_get16(ycht->rxqueue + pos); pos += 2; |
509 pktlen = yahoo_get16(ycht->rxqueue + pos); pos += 2; | 511 pktlen = yahoo_get16(ycht->rxqueue + pos); pos += 2; |
510 purple_debug(PURPLE_DEBUG_MISC, "yahoo", | 512 purple_debug_misc("yahoo", "ycht: %d bytes to read, rxlen is %d\n", |
511 "ycht: %d bytes to read, rxlen is %d\n", pktlen, ycht->rxlen); | 513 pktlen, ycht->rxlen); |
512 | 514 |
513 if (ycht->rxlen < (YCHT_HEADER_LEN + pktlen)) | 515 if (ycht->rxlen < (YCHT_HEADER_LEN + pktlen)) |
514 return; | 516 return; |
515 | 517 |
516 purple_debug_misc("yahoo", "--==Incoming YCHT packet==--\n"); | 518 purple_debug_misc("yahoo", "--==Incoming YCHT packet==--\n"); |
517 purple_debug(PURPLE_DEBUG_MISC, "yahoo", | 519 purple_debug_misc("yahoo", "YCHT Service: 0x%02x Version: 0x%02x Status: 0x%02x\n", |
518 "YCHT Service: 0x%02x Version: 0x%02x Status: 0x%02x\n", | 520 service, version, status); |
519 service, version, status); | |
520 ycht_packet_dump(ycht->rxqueue, YCHT_HEADER_LEN + pktlen); | 521 ycht_packet_dump(ycht->rxqueue, YCHT_HEADER_LEN + pktlen); |
521 | 522 |
522 pkt = ycht_packet_new(version, service, status); | 523 pkt = ycht_packet_new(version, service, status); |
523 ycht_packet_read(pkt, (char *)ycht->rxqueue + pos, pktlen); | 524 ycht_packet_read(pkt, (char *)ycht->rxqueue + pos, pktlen); |
524 | 525 |
545 struct yahoo_data *yd = gc->proto_data; | 546 struct yahoo_data *yd = gc->proto_data; |
546 YchtPkt *pkt; | 547 YchtPkt *pkt; |
547 char *buf; | 548 char *buf; |
548 | 549 |
549 if (source < 0) { | 550 if (source < 0) { |
550 ycht_connection_error(ycht, _("Unable to connect.")); | 551 ycht_connection_error(ycht, _("Unable to connect")); |
551 return; | 552 return; |
552 } | 553 } |
553 | 554 |
554 ycht->fd = source; | 555 ycht->fd = source; |
555 | 556 |
576 ycht->gc = gc; | 577 ycht->gc = gc; |
577 ycht->fd = -1; | 578 ycht->fd = -1; |
578 | 579 |
579 yd->ycht = ycht; | 580 yd->ycht = ycht; |
580 | 581 |
581 if (purple_proxy_connect(NULL, account, | 582 if (purple_proxy_connect(gc, account, |
582 purple_account_get_string(account, "ycht-server", YAHOO_YCHT_HOST), | 583 purple_account_get_string(account, "ycht-server", YAHOO_YCHT_HOST), |
583 purple_account_get_int(account, "ycht-port", YAHOO_YCHT_PORT), | 584 purple_account_get_int(account, "ycht-port", YAHOO_YCHT_PORT), |
584 ycht_got_connected, ycht) == NULL) | 585 ycht_got_connected, ycht) == NULL) |
585 { | 586 { |
586 ycht_connection_error(ycht, _("Connection problem")); | 587 ycht_connection_error(ycht, _("Unable to connect")); |
587 return; | 588 return; |
588 } | 589 } |
589 } | 590 } |
590 | 591 |
591 /******************************************************************************************* | 592 /******************************************************************************************* |