comparison src/protocols/yahoo/yahoochat.c @ 14084:b7e4180af1db

[gaim-migrate @ 16705] Don't use the same callback for both gaim_proxy_connect() and gaim_input_add(). Aside from being a little confusing, it's hindering some changes I want to make to gaim_proxy_connect(). committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 11 Aug 2006 08:08:19 +0000
parents 8934a27fed4b
children 10e8eb6a4910
comparison
equal deleted inserted replaced
14083:08dbb5912709 14084:b7e4180af1db
1333 } 1333 }
1334 1334
1335 yrl->rxlen = 0; 1335 yrl->rxlen = 0;
1336 } 1336 }
1337 1337
1338 static void yahoo_roomlist_got_connected(gpointer data, gint source, GaimInputCondition cond) 1338 static void yahoo_roomlist_send_cb(gpointer data, gint source, GaimInputCondition cond)
1339 { 1339 {
1340 struct yahoo_roomlist *yrl = data; 1340 struct yahoo_roomlist *yrl;
1341 GaimRoomlist *list = yrl->list; 1341 GaimRoomlist *list;
1342 struct yahoo_data *yd = gaim_account_get_connection(list->account)->proto_data; 1342 int written, remaining;
1343 int written, total_len; 1343
1344 1344 yrl = data;
1345 if (source < 0) { 1345 list = yrl->list;
1346 gaim_notify_error(gaim_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed.")); 1346
1347 yahoo_roomlist_cleanup(list, yrl); 1347 remaining = strlen(yrl->txbuf) - yrl->tx_written;
1348 return; 1348 written = write(yrl->fd, yrl->txbuf + yrl->tx_written, remaining);
1349 }
1350
1351 if (yrl->txbuf == NULL) {
1352 yrl->fd = source;
1353
1354 yrl->txbuf = g_strdup_printf(
1355 "GET http://%s/%s HTTP/1.0\r\n"
1356 "Host: %s\r\n"
1357 "Cookie: Y=%s; T=%s\r\n\r\n",
1358 yrl->host, yrl->path, yrl->host, yd->cookie_y,
1359 yd->cookie_t);
1360 }
1361
1362 total_len = strlen(yrl->txbuf) - yrl->tx_written;
1363 written = write(yrl->fd, yrl->txbuf + yrl->tx_written, total_len);
1364 1349
1365 if (written < 0 && errno == EAGAIN) 1350 if (written < 0 && errno == EAGAIN)
1366 written = 0; 1351 written = 0;
1367 else if (written <= 0) { 1352 else if (written <= 0) {
1368 if (yrl->inpa) 1353 gaim_input_remove(yrl->inpa);
1369 gaim_input_remove(yrl->inpa);
1370 yrl->inpa = 0; 1354 yrl->inpa = 0;
1371 g_free(yrl->txbuf); 1355 g_free(yrl->txbuf);
1372 yrl->txbuf = NULL; 1356 yrl->txbuf = NULL;
1373 gaim_notify_error(gaim_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed.")); 1357 gaim_notify_error(gaim_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed."));
1374 yahoo_roomlist_cleanup(list, yrl); 1358 yahoo_roomlist_cleanup(list, yrl);
1375 return; 1359 return;
1376 } 1360 }
1377 1361
1378 if (written < total_len) { 1362 if (written < remaining) {
1379 if (!yrl->inpa)
1380 yrl->inpa = gaim_input_add(yrl->fd,
1381 GAIM_INPUT_WRITE, yahoo_roomlist_got_connected,
1382 yrl);
1383 yrl->tx_written += written; 1363 yrl->tx_written += written;
1384 return; 1364 return;
1385 } 1365 }
1386 1366
1387 g_free(yrl->txbuf); 1367 g_free(yrl->txbuf);
1388 yrl->txbuf = NULL; 1368 yrl->txbuf = NULL;
1389 if (yrl->inpa) 1369
1390 gaim_input_remove(yrl->inpa); 1370 gaim_input_remove(yrl->inpa);
1391 yrl->inpa = gaim_input_add(yrl->fd, GAIM_INPUT_READ, 1371 yrl->inpa = gaim_input_add(yrl->fd, GAIM_INPUT_READ,
1392 yahoo_roomlist_pending, yrl); 1372 yahoo_roomlist_pending, yrl);
1393 1373
1374 }
1375
1376 static void yahoo_roomlist_got_connected(gpointer data, gint source, GaimInputCondition cond)
1377 {
1378 struct yahoo_roomlist *yrl = data;
1379 GaimRoomlist *list = yrl->list;
1380 struct yahoo_data *yd = gaim_account_get_connection(list->account)->proto_data;
1381
1382 if (source < 0) {
1383 gaim_notify_error(gaim_account_get_connection(list->account), NULL, _("Unable to connect"), _("Fetching the room list failed."));
1384 yahoo_roomlist_cleanup(list, yrl);
1385 return;
1386 }
1387
1388 yrl->fd = source;
1389
1390 yrl->txbuf = g_strdup_printf(
1391 "GET http://%s/%s HTTP/1.0\r\n"
1392 "Host: %s\r\n"
1393 "Cookie: Y=%s; T=%s\r\n\r\n",
1394 yrl->host, yrl->path, yrl->host, yd->cookie_y,
1395 yd->cookie_t);
1396
1397
1398 yrl->inpa = gaim_input_add(yrl->fd, GAIM_INPUT_WRITE,
1399 yahoo_roomlist_send_cb, yrl);
1400 yahoo_roomlist_send_cb(yrl, yrl->fd, GAIM_INPUT_WRITE);
1394 } 1401 }
1395 1402
1396 GaimRoomlist *yahoo_roomlist_get_list(GaimConnection *gc) 1403 GaimRoomlist *yahoo_roomlist_get_list(GaimConnection *gc)
1397 { 1404 {
1398 struct yahoo_roomlist *yrl; 1405 struct yahoo_roomlist *yrl;