Thu, 16 Dec 2004 21:47:54 +0000
[gaim-migrate @ 11620]
a little bit of clean up and reorganization of the yahoo prpl.
I moved the packet functions to their own file, renamed a couple of them,
added a convience function and used it a lot. I plan on adding several
more convience functions.
| 9376 | 1 | /** |
| 2 | * @file ycht.c The Yahoo! protocol plugin, YCHT protocol stuff. | |
| 3 | * | |
| 4 | * gaim | |
| 5 | * | |
| 6 | * Copyright (C) 2004 Timothy Ringenbach <omarvo@hotmail.com> | |
| 7 | * Liberal amounts of code borrowed from the rest of the Yahoo! prpl. | |
| 8 | * | |
| 9 | * Gaim is the legal property of its developers, whose names are too numerous | |
| 10 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 11 | * source distribution. | |
| 12 | * | |
| 13 | * This program is free software; you can redistribute it and/or modify | |
| 14 | * it under the terms of the GNU General Public License as published by | |
| 15 | * the Free Software Foundation; either version 2 of the License, or | |
| 16 | * (at your option) any later version. | |
| 17 | * | |
| 18 | * This program is distributed in the hope that it will be useful, | |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 | * GNU General Public License for more details. | |
| 22 | * | |
| 23 | * You should have received a copy of the GNU General Public License | |
| 24 | * along with this program; if not, write to the Free Software | |
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 26 | */ | |
| 27 | ||
| 28 | #include <string.h> | |
| 29 | ||
| 30 | #include "internal.h" | |
| 31 | #include "prpl.h" | |
| 32 | #include "notify.h" | |
| 33 | #include "account.h" | |
| 34 | #include "proxy.h" | |
| 35 | #include "debug.h" | |
| 36 | #include "conversation.h" | |
| 37 | #include "util.h" | |
| 38 | ||
| 39 | #include "yahoo.h" | |
| 10392 | 40 | #include "yahoo_packet.h" |
| 9376 | 41 | #include "ycht.h" |
| 42 | #include "yahoochat.h" | |
| 43 | ||
| 44 | /* | |
| 45 | * dword: YCHT | |
| 46 | * dword: 0x000000AE | |
| 47 | * dword: service | |
| 48 | * word: status | |
| 49 | * word: size | |
| 50 | */ | |
| 51 | #define YAHOO_CHAT_ID (1) | |
| 52 | /************************************************************************************ | |
| 53 | * Functions to process various kinds of packets. | |
| 54 | ************************************************************************************/ | |
| 55 | static void ycht_process_login(YchtConn *ycht, YchtPkt *pkt) | |
| 56 | { | |
| 57 | GaimConnection *gc = ycht->gc; | |
| 58 | struct yahoo_data *yd = gc->proto_data; | |
| 59 | ||
| 60 | if (ycht->logged_in) | |
| 61 | return; | |
| 62 | ||
| 63 | yd->chat_online = TRUE; | |
| 64 | ycht->logged_in = TRUE; | |
| 65 | ||
| 66 | if (ycht->room) | |
| 67 | ycht_chat_join(ycht, ycht->room); | |
| 68 | } | |
| 69 | ||
| 70 | static void ycht_process_logout(YchtConn *ycht, YchtPkt *pkt) | |
| 71 | { | |
| 72 | GaimConnection *gc = ycht->gc; | |
| 73 | struct yahoo_data *yd = gc->proto_data; | |
| 74 | ||
| 75 | yd->chat_online = FALSE; | |
| 76 | ycht->logged_in = FALSE; | |
| 77 | } | |
| 78 | ||
| 79 | static void ycht_process_chatjoin(YchtConn *ycht, YchtPkt *pkt) | |
| 80 | { | |
| 81 | char *room, *topic; | |
| 82 | GaimConnection *gc = ycht->gc; | |
| 83 | GaimConversation *c = NULL; | |
| 84 | gboolean new_room = FALSE; | |
| 85 | char **members; | |
| 86 | int i; | |
| 87 | ||
| 88 | room = g_list_nth_data(pkt->data, 0); | |
| 89 | topic = g_list_nth_data(pkt->data, 1); | |
| 90 | if (!g_list_nth_data(pkt->data, 4)) | |
| 91 | return; | |
| 92 | if (!room) | |
| 93 | return; | |
| 94 | ||
| 95 | members = g_strsplit(g_list_nth_data(pkt->data, 4), "\001", 0); | |
| 96 | for (i = 0; members[i]; i++) { | |
| 97 | char *tmp = strchr(members[i], '\002'); | |
| 98 | if (tmp) | |
| 99 | *tmp = '\0'; | |
| 100 | } | |
| 101 | ||
| 102 | ||
| 103 | if (g_list_length(pkt->data) > 5) | |
| 104 | new_room = TRUE; | |
| 105 | ||
| 106 | if (new_room && ycht->changing_rooms) { | |
| 107 | serv_got_chat_left(gc, YAHOO_CHAT_ID); | |
| 108 | ycht->changing_rooms = FALSE; | |
| 109 | c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); | |
| 110 | } else { | |
| 111 | c = gaim_find_chat(gc, YAHOO_CHAT_ID); | |
| 112 | } | |
| 113 | ||
| 114 | ||
| 115 | if (topic) | |
| 116 | gaim_conv_chat_set_topic(GAIM_CONV_CHAT(c), NULL, topic); | |
| 117 | ||
| 118 | for (i = 0; members[i]; i++) { | |
| 119 | if (new_room) { | |
| 120 | /*if (!strcmp(members[i], gaim_connection_get_display_name(ycht->gc))) | |
| 121 | continue;*/ | |
|
9846
61f7349c153a
[gaim-migrate @ 10724]
Nathan Fredrickson <nathan@silverorange.com>
parents:
9554
diff
changeset
|
122 | gaim_conv_chat_add_user(GAIM_CONV_CHAT(c), members[i], NULL, GAIM_CBFLAGS_NONE, TRUE); |
| 9376 | 123 | } else { |
| 124 | yahoo_chat_add_user(GAIM_CONV_CHAT(c), members[i], NULL); | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | g_strfreev(members); | |
| 129 | } | |
| 130 | ||
| 131 | static void ycht_process_chatpart(YchtConn *ycht, YchtPkt *pkt) | |
| 132 | { | |
| 133 | char *room, *who; | |
| 134 | ||
| 135 | room = g_list_nth_data(pkt->data, 0); | |
| 136 | who = g_list_nth_data(pkt->data, 1); | |
| 137 | ||
| 138 | if (who && room) { | |
| 139 | GaimConversation *c = gaim_find_chat(ycht->gc, YAHOO_CHAT_ID); | |
| 140 | if (c && !gaim_utf8_strcasecmp(gaim_conversation_get_name(c), room)) | |
| 141 | gaim_conv_chat_remove_user(GAIM_CONV_CHAT(c), who, NULL); | |
| 142 | ||
| 143 | } | |
| 144 | } | |
| 145 | ||
| 146 | static void ycht_progress_chatmsg(YchtConn *ycht, YchtPkt *pkt) | |
| 147 | { | |
| 148 | char *who, *what, *msg; | |
| 149 | GaimConversation *c; | |
| 150 | GaimConnection *gc = ycht->gc; | |
| 151 | ||
| 152 | who = g_list_nth_data(pkt->data, 1); | |
| 153 | what = g_list_nth_data(pkt->data, 2); | |
| 154 | ||
| 155 | if (!who || !what) | |
| 156 | return; | |
| 157 | ||
| 158 | c = gaim_find_chat(gc, YAHOO_CHAT_ID); | |
| 159 | if (!c) | |
| 160 | return; | |
| 161 | ||
| 162 | msg = yahoo_string_decode(gc, what, 1); | |
| 163 | what = yahoo_codes_to_html(msg); | |
| 164 | g_free(msg); | |
| 165 | ||
| 166 | if (pkt->service == YCHT_SERVICE_CHATMSG_EMOTE) { | |
| 167 | char *tmp = g_strdup_printf("/me %s", what); | |
| 168 | g_free(what); | |
| 169 | what = tmp; | |
| 170 | } | |
| 171 | ||
| 172 | serv_got_chat_in(gc, YAHOO_CHAT_ID, who, 0, what, time(NULL)); | |
| 173 | g_free(what); | |
| 174 | } | |
| 175 | ||
| 176 | static void ycht_progress_online_friends(YchtConn *ycht, YchtPkt *pkt) | |
| 177 | { | |
| 178 | #if 0 | |
| 179 | GaimConnection *gc = ycht->gc; | |
| 180 | struct yahoo_data *yd = gc->proto_data; | |
| 181 | ||
| 182 | if (ycht->logged_in) | |
| 183 | return; | |
| 184 | ||
| 185 | yd->chat_online = TRUE; | |
| 186 | ycht->logged_in = TRUE; | |
| 187 | ||
| 188 | if (ycht->room) | |
| 189 | ycht_chat_join(ycht, ycht->room); | |
| 190 | #endif | |
| 191 | } | |
| 192 | ||
| 193 | /***************************************************************************** | |
| 194 | * Functions dealing with YCHT packets and their contents directly. | |
| 195 | *****************************************************************************/ | |
| 196 | static void ycht_packet_dump(const char *data, int len) | |
| 197 | { | |
| 198 | #ifdef YAHOO_YCHT_DEBUG | |
| 199 | int i; | |
| 200 | ||
| 201 | gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); | |
| 202 | ||
| 203 | for (i = 0; i + 1 < len; i += 2) { | |
| 204 | if ((i % 16 == 0) && i) { | |
| 205 | gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); | |
| 206 | gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); | |
| 207 | } | |
| 208 | ||
| 209 | gaim_debug(GAIM_DEBUG_MISC, NULL, "%02hhx%02hhx ", data[i], data[i + 1]); | |
| 210 | } | |
| 211 | if (i < len) | |
| 212 | gaim_debug(GAIM_DEBUG_MISC, NULL, "%02hhx", data[i]); | |
| 213 | ||
| 214 | gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); | |
| 215 | gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); | |
| 216 | ||
| 217 | for (i = 0; i < len; i++) { | |
| 218 | if ((i % 16 == 0) && i) { | |
| 219 | gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); | |
| 220 | gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); | |
| 221 | } | |
| 222 | ||
| 223 | if (g_ascii_isprint(data[i])) | |
| 224 | gaim_debug(GAIM_DEBUG_MISC, NULL, "%c ", data[i]); | |
| 225 | else | |
| 226 | gaim_debug(GAIM_DEBUG_MISC, NULL, ". "); | |
| 227 | } | |
| 228 | ||
| 229 | gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); | |
| 230 | #endif | |
| 231 | } | |
| 232 | ||
| 233 | static YchtPkt *ycht_packet_new(guint version, guint service, int status) | |
| 234 | { | |
| 235 | YchtPkt *ret; | |
| 236 | ||
| 237 | ret = g_new0(YchtPkt, 1); | |
| 238 | ||
| 239 | ret->version = version; | |
| 240 | ret->service = service; | |
| 241 | ret->status = status; | |
| 242 | ||
| 243 | return ret; | |
| 244 | } | |
| 245 | ||
| 246 | static void ycht_packet_append(YchtPkt *pkt, const char *str) | |
| 247 | { | |
| 248 | g_return_if_fail(pkt != NULL); | |
| 249 | g_return_if_fail(str != NULL); | |
| 250 | ||
| 251 | pkt->data = g_list_append(pkt->data, g_strdup(str)); | |
| 252 | } | |
| 253 | ||
| 254 | static int ycht_packet_length(YchtPkt *pkt) | |
| 255 | { | |
| 256 | int ret; | |
| 257 | GList *l; | |
| 258 | ||
| 259 | ret = YCHT_HEADER_LEN; | |
| 260 | ||
| 261 | for (l = pkt->data; l; l = l->next) { | |
| 262 | ret += strlen(l->data); | |
| 263 | if (l->next) | |
| 264 | ret += strlen(YCHT_SEP); | |
| 265 | } | |
| 266 | ||
| 267 | return ret; | |
| 268 | } | |
| 269 | ||
| 270 | static void ycht_packet_send(YchtConn *ycht, YchtPkt *pkt) | |
| 271 | { | |
| 272 | int len, pos; | |
| 273 | char *buf; | |
| 274 | GList *l; | |
| 275 | ||
| 276 | g_return_if_fail(ycht != NULL); | |
| 277 | g_return_if_fail(pkt != NULL); | |
| 278 | g_return_if_fail(ycht->fd != -1); | |
| 279 | ||
| 280 | pos = 0; | |
| 281 | len = ycht_packet_length(pkt); | |
| 282 | buf = g_malloc(len); | |
| 283 | ||
| 284 | memcpy(buf + pos, "YCHT", 4); pos += 4; | |
| 285 | pos += yahoo_put32(buf + pos, pkt->version); | |
| 286 | pos += yahoo_put32(buf + pos, pkt->service); | |
| 287 | pos += yahoo_put16(buf + pos, pkt->status); | |
| 288 | pos += yahoo_put16(buf + pos, len - YCHT_HEADER_LEN); | |
| 289 | ||
| 290 | for (l = pkt->data; l; l = l->next) { | |
| 291 | int slen = strlen(l->data); | |
| 292 | memcpy(buf + pos, l->data, slen); pos += slen; | |
| 293 | ||
| 294 | if (l->next) { | |
| 295 | memcpy(buf + pos, YCHT_SEP, strlen(YCHT_SEP)); | |
| 296 | pos += strlen(YCHT_SEP); | |
| 297 | } | |
| 298 | } | |
| 299 | ||
| 300 | write(ycht->fd, buf, len); | |
| 301 | g_free(buf); | |
| 302 | } | |
| 303 | ||
| 304 | static void ycht_packet_read(YchtPkt *pkt, const char *buf, int len) | |
| 305 | { | |
| 306 | const char *pos = buf; | |
| 307 | const char *needle; | |
| 308 | char *tmp, *tmp2; | |
| 309 | int i = 0; | |
| 310 | ||
| 311 | while (len > 0 && (needle = g_strstr_len(pos, len, YCHT_SEP))) { | |
| 312 | tmp = g_strndup(pos, needle - pos); | |
| 313 | pkt->data = g_list_append(pkt->data, tmp); | |
| 314 | len -= needle - pos + strlen(YCHT_SEP); | |
| 315 | pos = needle + strlen(YCHT_SEP); | |
| 316 | tmp2 = g_strescape(tmp, NULL); | |
| 317 | gaim_debug_misc("yahoo", "Data[%d]:\t%s\n", i++, tmp2); | |
| 318 | g_free(tmp2); | |
| 319 | } | |
| 320 | ||
| 321 | if (len) { | |
| 322 | tmp = g_strndup(pos, len); | |
| 323 | pkt->data = g_list_append(pkt->data, tmp); | |
| 324 | tmp2 = g_strescape(tmp, NULL); | |
| 325 | gaim_debug_misc("yahoo", "Data[%d]:\t%s\n", i, tmp2); | |
| 326 | g_free(tmp2); | |
| 327 | }; | |
| 328 | ||
| 329 | gaim_debug_misc("yahoo", "--==End of incoming YCHT packet==--\n"); | |
| 330 | } | |
| 331 | ||
| 332 | static void ycht_packet_process(YchtConn *ycht, YchtPkt *pkt) | |
| 333 | { | |
| 334 | if (pkt->data && !strncmp(pkt->data->data, "*** Danger Will Robinson!!!", strlen("*** Danger Will Robinson!!!"))) | |
| 335 | return; | |
| 336 | ||
| 337 | switch (pkt->service) { | |
| 338 | case YCHT_SERVICE_LOGIN: | |
| 339 | ycht_process_login(ycht, pkt); | |
| 340 | break; | |
| 341 | case YCHT_SERVICE_LOGOUT: | |
| 342 | ycht_process_logout(ycht, pkt); | |
| 343 | break; | |
| 344 | case YCHT_SERVICE_CHATJOIN: | |
| 345 | ycht_process_chatjoin(ycht, pkt); | |
| 346 | break; | |
| 347 | case YCHT_SERVICE_CHATPART: | |
| 348 | ycht_process_chatpart(ycht, pkt); | |
| 349 | break; | |
| 350 | case YCHT_SERVICE_CHATMSG: | |
| 351 | case YCHT_SERVICE_CHATMSG_EMOTE: | |
| 352 | ycht_progress_chatmsg(ycht, pkt); | |
| 353 | break; | |
| 354 | case YCHT_SERVICE_ONLINE_FRIENDS: | |
| 355 | ycht_progress_online_friends(ycht, pkt); | |
| 356 | break; | |
| 357 | default: | |
| 358 | gaim_debug_warning("yahoo", "YCHT: warning, unhandled service 0x%02x\n", pkt->service); | |
| 359 | } | |
| 360 | } | |
| 361 | ||
| 362 | static void ycht_packet_free(YchtPkt *pkt) | |
| 363 | { | |
| 364 | GList *l; | |
| 365 | ||
| 366 | g_return_if_fail(pkt != NULL); | |
| 367 | ||
| 368 | for (l = pkt->data; l; l = l->next) | |
| 369 | g_free(l->data); | |
| 370 | g_list_free(pkt->data); | |
| 371 | g_free(pkt); | |
| 372 | } | |
| 373 | ||
| 374 | /************************************************************************************ | |
| 375 | * Functions dealing with connecting and disconnecting and reading data into YchtPkt | |
| 376 | * structs, and all that stuff. | |
| 377 | ************************************************************************************/ | |
| 378 | ||
| 379 | void ycht_connection_close(YchtConn *ycht) | |
| 380 | { | |
| 381 | struct yahoo_data *yd = ycht->gc->proto_data; | |
| 382 | ||
| 383 | if (yd) { | |
| 384 | yd->ycht = NULL; | |
| 385 | yd->chat_online = FALSE; | |
| 386 | } | |
| 387 | ||
| 388 | if (ycht->fd > 0) | |
| 389 | close(ycht->fd); | |
| 390 | if (ycht->inpa) | |
| 391 | gaim_input_remove(ycht->inpa); | |
| 392 | ||
| 393 | if (ycht->rxqueue) | |
| 394 | g_free(ycht->rxqueue); | |
| 395 | ||
| 396 | g_free(ycht); | |
| 397 | } | |
| 398 | ||
| 399 | static void ycht_connection_error(YchtConn *ycht, const gchar *error) | |
| 400 | { | |
| 9397 | 401 | |
| 9376 | 402 | gaim_notify_info(ycht->gc, NULL, _("Connection problem with the YCHT server."), error); |
| 403 | ycht_connection_close(ycht); | |
| 404 | } | |
| 405 | ||
| 406 | static void ycht_pending(gpointer data, gint source, GaimInputCondition cond) | |
| 407 | { | |
| 408 | YchtConn *ycht = data; | |
| 409 | char buf[1024]; | |
| 410 | int len; | |
| 411 | ||
| 412 | len = read(ycht->fd, buf, sizeof(buf)); | |
| 413 | ||
| 414 | if (len <= 0) { | |
| 9397 | 415 | ycht_connection_error(ycht, _("Unable to read")); |
| 9376 | 416 | return; |
| 417 | } | |
| 418 | ||
| 419 | ycht->rxqueue = g_realloc(ycht->rxqueue, len + ycht->rxlen); | |
| 420 | memcpy(ycht->rxqueue + ycht->rxlen, buf, len); | |
| 421 | ycht->rxlen += len; | |
| 422 | ||
| 423 | while (1) { | |
| 424 | YchtPkt *pkt; | |
| 425 | int pos = 0; | |
| 426 | int pktlen; | |
| 427 | guint service; | |
| 428 | guint version; | |
| 429 | gint status; | |
| 430 | ||
| 431 | if (ycht->rxlen < YCHT_HEADER_LEN) | |
| 432 | return; | |
| 433 | ||
| 434 | if (strncmp("YCHT", ycht->rxqueue, 4) != 0) | |
| 435 | gaim_debug_error("yahoo", "YCHT: protocol error.\n"); | |
| 436 | ||
| 437 | pos += 4; /* YCHT */ | |
| 438 | ||
| 439 | version = yahoo_get32(ycht->rxqueue + pos); pos += 4; | |
| 440 | service = yahoo_get32(ycht->rxqueue + pos); pos += 4; | |
| 441 | status = yahoo_get16(ycht->rxqueue + pos); pos += 2; | |
| 442 | pktlen = yahoo_get16(ycht->rxqueue + pos); pos += 2; | |
| 443 | gaim_debug(GAIM_DEBUG_MISC, "yahoo", | |
| 444 | "ycht: %d bytes to read, rxlen is %d\n", pktlen, ycht->rxlen); | |
| 445 | ||
| 446 | if (ycht->rxlen < (YCHT_HEADER_LEN + pktlen)) | |
| 447 | return; | |
| 448 | ||
| 449 | gaim_debug_misc("yahoo", "--==Incoming YCHT packet==--\n"); | |
| 450 | gaim_debug(GAIM_DEBUG_MISC, "yahoo", | |
| 451 | "YCHT Service: 0x%02x Version: 0x%02x Status: 0x%02x\n", | |
| 452 | service, version, status); | |
| 453 | ycht_packet_dump(ycht->rxqueue, YCHT_HEADER_LEN + pktlen); | |
| 454 | ||
| 455 | pkt = ycht_packet_new(version, service, status); | |
| 456 | ycht_packet_read(pkt, ycht->rxqueue + pos, pktlen); | |
| 457 | ||
| 458 | ycht->rxlen -= YCHT_HEADER_LEN + pktlen; | |
| 459 | if (ycht->rxlen) { | |
| 460 | char *tmp = g_memdup(ycht->rxqueue + YCHT_HEADER_LEN + pktlen, ycht->rxlen); | |
| 461 | g_free(ycht->rxqueue); | |
| 462 | ycht->rxqueue = tmp; | |
| 463 | } else { | |
| 464 | g_free(ycht->rxqueue); | |
| 465 | ycht->rxqueue = NULL; | |
| 466 | } | |
| 467 | ||
| 468 | ycht_packet_process(ycht, pkt); | |
| 469 | ||
| 470 | ycht_packet_free(pkt); | |
| 471 | } | |
| 472 | } | |
| 473 | ||
| 474 | static void ycht_got_connected(gpointer data, gint source, GaimInputCondition cond) | |
| 475 | { | |
| 476 | YchtConn *ycht = data; | |
| 477 | GaimConnection *gc = ycht->gc; | |
| 478 | struct yahoo_data *yd = gc->proto_data; | |
| 479 | YchtPkt *pkt; | |
| 480 | char *buf; | |
| 481 | ||
| 482 | if (source < 0) { | |
| 9397 | 483 | ycht_connection_error(ycht, _("Unable to connect.")); |
| 9376 | 484 | return; |
| 485 | } | |
| 486 | ||
| 487 | ycht->fd = source; | |
| 488 | ||
| 489 | pkt = ycht_packet_new(YCHT_VERSION, YCHT_SERVICE_LOGIN, 0); | |
| 490 | ||
| 491 | buf = g_strdup_printf("%s\001Y=%s; T=%s", gaim_connection_get_display_name(gc), yd->cookie_y, yd->cookie_t); | |
| 492 | ycht_packet_append(pkt, buf); | |
| 493 | g_free(buf); | |
| 494 | ||
| 495 | ycht_packet_send(ycht, pkt); | |
| 496 | ||
| 497 | ycht_packet_free(pkt); | |
| 498 | ||
| 499 | ycht->inpa = gaim_input_add(ycht->fd, GAIM_INPUT_READ, ycht_pending, ycht); | |
| 500 | } | |
| 501 | ||
| 502 | void ycht_connection_open(GaimConnection *gc) | |
| 503 | { | |
| 504 | YchtConn *ycht; | |
| 505 | struct yahoo_data *yd = gc->proto_data; | |
| 506 | GaimAccount *account = gaim_connection_get_account(gc); | |
| 507 | ||
| 508 | ycht = g_new0(YchtConn, 1); | |
| 509 | ycht->gc = gc; | |
| 510 | ycht->fd = -1; | |
| 511 | ||
| 512 | yd->ycht = ycht; | |
| 513 | ||
| 514 | if (gaim_proxy_connect(account, | |
| 515 | gaim_account_get_string(account, "ycht-server", YAHOO_YCHT_HOST), | |
| 516 | gaim_account_get_int(account, "ycht-port", YAHOO_YCHT_PORT), | |
| 517 | ycht_got_connected, ycht) != 0) | |
| 518 | { | |
| 9397 | 519 | ycht_connection_error(ycht, _("Connection problem")); |
| 9376 | 520 | return; |
| 521 | } | |
| 522 | } | |
| 523 | ||
| 524 | /******************************************************************************************* | |
| 525 | * These are functions called because the user did something. | |
| 526 | *******************************************************************************************/ | |
| 527 | ||
| 528 | void ycht_chat_join(YchtConn *ycht, const char *room) | |
| 529 | { | |
| 530 | YchtPkt *pkt; | |
| 531 | char *tmp; | |
| 532 | ||
| 533 | tmp = g_strdup(room); | |
| 534 | if (ycht->room) | |
| 535 | g_free(ycht->room); | |
| 536 | ycht->room = tmp; | |
| 537 | ||
| 538 | if (!ycht->logged_in) | |
| 539 | return; | |
| 540 | ||
| 541 | ycht->changing_rooms = TRUE; | |
| 542 | pkt = ycht_packet_new(YCHT_VERSION, YCHT_SERVICE_CHATJOIN, 0); | |
| 543 | ycht_packet_append(pkt, ycht->room); | |
| 544 | ycht_packet_send(ycht, pkt); | |
| 545 | ycht_packet_free(pkt); | |
| 546 | } | |
| 547 | ||
| 548 | int ycht_chat_send(YchtConn *ycht, const char *room, const char *what) | |
| 549 | { | |
| 550 | YchtPkt *pkt; | |
| 551 | char *msg1, *msg2, *buf; | |
| 552 | ||
| 553 | if (strcmp(room, ycht->room)) | |
| 554 | gaim_debug_warning("yahoo", "uhoh, sending to the wrong room!\n"); | |
| 555 | ||
| 556 | pkt = ycht_packet_new(YCHT_VERSION, YCHT_SERVICE_CHATMSG, 0); | |
| 557 | ||
| 558 | msg1 = yahoo_html_to_codes(what); | |
| 559 | msg2 = yahoo_string_encode(ycht->gc, msg1, NULL); | |
| 560 | g_free(msg1); | |
| 561 | ||
| 562 | buf = g_strdup_printf("%s\001%s", ycht->room, msg2); | |
| 563 | ycht_packet_append(pkt, buf); | |
| 564 | g_free(msg2); | |
| 565 | g_free(buf); | |
| 566 | ||
| 567 | ycht_packet_send(ycht, pkt); | |
| 568 | ycht_packet_free(pkt); | |
| 569 | return 1; | |
| 570 | } | |
| 571 | ||
| 572 | void ycht_chat_leave(YchtConn *ycht, const char *room, gboolean logout) | |
| 573 | { | |
| 574 | if (logout) | |
| 575 | ycht_connection_close(ycht); | |
| 576 | } | |
| 577 | ||
| 578 | void ycht_chat_send_invite(YchtConn *ycht, const char *room, const char *buddy, const char *msg) | |
| 579 | { | |
| 580 | } | |
| 581 | ||
| 582 | void ycht_chat_goto_user(YchtConn *ycht, const char *name) | |
| 583 | { | |
| 584 | } | |
| 585 | ||
| 586 | void ycht_chat_send_keepalive(YchtConn *ycht) | |
| 587 | { | |
| 588 | YchtPkt *pkt; | |
| 589 | ||
| 590 | pkt = ycht_packet_new(YCHT_VERSION, YCHT_SERVICE_PING, 0); | |
| 591 | ycht_packet_send(ycht, pkt); | |
| 592 | ycht_packet_free(pkt); | |
| 593 | } |