Mercurial > pidgin.yaz
comparison src/protocols/oscar/oscar.c @ 14109:a21da42126d6
[gaim-migrate @ 16743]
Almost all of oscar is using gaim_proxy_connect_cancel() now
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 14 Aug 2006 06:24:17 +0000 |
parents | 7a205b430d19 |
children | 6a19a83ed49f |
comparison
equal
deleted
inserted
replaced
14108:7a205b430d19 | 14109:a21da42126d6 |
---|---|
74 static guint8 features_aim[] = {0x01, 0x01, 0x01, 0x02}; | 74 static guint8 features_aim[] = {0x01, 0x01, 0x01, 0x02}; |
75 static guint8 features_icq[] = {0x01, 0x06}; | 75 static guint8 features_icq[] = {0x01, 0x06}; |
76 static guint8 features_icq_offline[] = {0x01}; | 76 static guint8 features_icq_offline[] = {0x01}; |
77 static guint8 ck[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; | 77 static guint8 ck[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
78 | 78 |
79 typedef struct _NewFlapConnectionData NewFlapConnectionData; | |
80 struct _NewFlapConnectionData | |
81 { | |
82 GaimConnection *gc; | |
83 FlapConnection *conn; | |
84 guint16 cookielen; | |
85 guint8 *cookie; | |
86 gpointer data; | |
87 }; | |
88 | |
89 struct create_room { | 79 struct create_room { |
90 char *name; | 80 char *name; |
91 int exchange; | 81 int exchange; |
92 }; | |
93 | |
94 struct chat_connection | |
95 { | |
96 char *name; | |
97 char *show; /* AOL did something funny to us */ | |
98 guint16 exchange; | |
99 guint16 instance; | |
100 FlapConnection *conn; | |
101 int id; | |
102 GaimConnection *gc; /* i hate this. */ | |
103 GaimConversation *conv; /* bah. */ | |
104 int maxlen; | |
105 int maxvis; | |
106 }; | 82 }; |
107 | 83 |
108 struct oscar_ask_directim_data | 84 struct oscar_ask_directim_data |
109 { | 85 { |
110 OscarData *od; | 86 OscarData *od; |
901 } | 877 } |
902 | 878 |
903 return NULL; | 879 return NULL; |
904 } | 880 } |
905 | 881 |
906 static void | 882 void |
907 oscar_chat_destroy(struct chat_connection *cc) | 883 oscar_chat_destroy(struct chat_connection *cc) |
908 { | 884 { |
909 g_free(cc->name); | 885 g_free(cc->name); |
910 g_free(cc->show); | 886 g_free(cc->show); |
911 g_free(cc); | 887 g_free(cc); |
921 | 897 |
922 /* Destroy the chat_connection */ | 898 /* Destroy the chat_connection */ |
923 od->oscar_chats = g_slist_remove(od->oscar_chats, cc); | 899 od->oscar_chats = g_slist_remove(od->oscar_chats, cc); |
924 flap_connection_schedule_destroy(cc->conn, OSCAR_DISCONNECT_DONE); | 900 flap_connection_schedule_destroy(cc->conn, OSCAR_DISCONNECT_DONE); |
925 oscar_chat_destroy(cc); | 901 oscar_chat_destroy(cc); |
926 } | |
927 | |
928 static void | |
929 destroy_new_conn_data(NewFlapConnectionData *new_conn_data) | |
930 { | |
931 if ((new_conn_data->data != NULL) && | |
932 (new_conn_data->conn->type == SNAC_FAMILY_CHAT)) | |
933 { | |
934 oscar_chat_destroy(new_conn_data->data); | |
935 } | |
936 g_free(new_conn_data->cookie); | |
937 g_free(new_conn_data); | |
938 } | 902 } |
939 | 903 |
940 /** | 904 /** |
941 * This is the callback function anytime gaim_proxy_connect() | 905 * This is the callback function anytime gaim_proxy_connect() |
942 * establishes a new TCP connection with an oscar host. Depending | 906 * establishes a new TCP connection with an oscar host. Depending |
943 * on the type of host, we do a few different things here. | 907 * on the type of host, we do a few different things here. |
944 */ | 908 */ |
945 static void | 909 static void |
946 connection_established_cb(gpointer data, gint source) | 910 connection_established_cb(gpointer data, gint source, const gchar *error_message) |
947 { | 911 { |
948 NewFlapConnectionData *new_conn_data; | |
949 GaimConnection *gc; | 912 GaimConnection *gc; |
950 OscarData *od; | 913 OscarData *od; |
951 GaimAccount *account; | 914 GaimAccount *account; |
952 FlapConnection *conn; | 915 FlapConnection *conn; |
953 | 916 |
954 new_conn_data = data; | 917 conn = data; |
955 gc = new_conn_data->gc; | 918 od = conn->od; |
956 | 919 gc = od->gc; |
957 if (!GAIM_CONNECTION_IS_VALID(gc)) | |
958 { | |
959 if (source >= 0) | |
960 close(source); | |
961 destroy_new_conn_data(new_conn_data); | |
962 return; | |
963 } | |
964 | |
965 od = gc->proto_data; | |
966 account = gaim_connection_get_account(gc); | 920 account = gaim_connection_get_account(gc); |
967 conn = new_conn_data->conn; | 921 |
922 conn->connect_info = NULL; | |
968 conn->fd = source; | 923 conn->fd = source; |
969 | 924 |
970 if (source < 0) | 925 if (source < 0) |
971 { | 926 { |
972 gaim_debug_error("oscar", "unable to connect FLAP server " | 927 gaim_debug_error("oscar", "unable to connect FLAP server " |
976 if (conn->type == SNAC_FAMILY_LOCATE) | 931 if (conn->type == SNAC_FAMILY_LOCATE) |
977 gaim_connection_error(gc, _("Could not connect to BOS server")); | 932 gaim_connection_error(gc, _("Could not connect to BOS server")); |
978 else /* Maybe we should call this for BOS connections, too? */ | 933 else /* Maybe we should call this for BOS connections, too? */ |
979 flap_connection_schedule_destroy(conn, | 934 flap_connection_schedule_destroy(conn, |
980 OSCAR_DISCONNECT_COULD_NOT_CONNECT); | 935 OSCAR_DISCONNECT_COULD_NOT_CONNECT); |
981 destroy_new_conn_data(new_conn_data); | |
982 return; | 936 return; |
983 } | 937 } |
984 | 938 |
985 gaim_debug_info("oscar", "connected to FLAP server of type 0x%04hx\n", | 939 gaim_debug_info("oscar", "connected to FLAP server of type 0x%04hx\n", |
986 conn->type); | 940 conn->type); |
987 conn->watcher_incoming = gaim_input_add(conn->fd, | 941 conn->watcher_incoming = gaim_input_add(conn->fd, |
988 GAIM_INPUT_READ, flap_connection_recv_cb, conn); | 942 GAIM_INPUT_READ, flap_connection_recv_cb, conn); |
989 if (new_conn_data->cookie == NULL) | 943 if (conn->cookie == NULL) |
990 { | 944 { |
991 if (!aim_sn_is_icq(gaim_account_get_username(account))) | 945 if (!aim_sn_is_icq(gaim_account_get_username(account))) |
992 /* | 946 /* |
993 * We don't send this when authenticating an ICQ account | 947 * We don't send this when authenticating an ICQ account |
994 * because for some reason ICQ is still using the | 948 * because for some reason ICQ is still using the |
995 * assy/insecure authentication procedure. | 949 * assy/insecure authentication procedure. |
996 */ | 950 */ |
997 flap_connection_send_version(od, conn); | 951 flap_connection_send_version(od, conn); |
998 } | 952 } |
999 else | 953 else |
954 { | |
1000 flap_connection_send_version_with_cookie(od, conn, | 955 flap_connection_send_version_with_cookie(od, conn, |
1001 new_conn_data->cookielen, new_conn_data->cookie); | 956 conn->cookielen, conn->cookie); |
957 g_free(conn->cookie); | |
958 conn->cookie = NULL; | |
959 } | |
1002 | 960 |
1003 if (conn->type == SNAC_FAMILY_AUTH) | 961 if (conn->type == SNAC_FAMILY_AUTH) |
1004 { | 962 { |
1005 aim_request_login(od, conn, gaim_account_get_username(account)); | 963 aim_request_login(od, conn, gaim_account_get_username(account)); |
1006 gaim_debug_info("oscar", "Screen name sent, waiting for response\n"); | 964 gaim_debug_info("oscar", "Screen name sent, waiting for response\n"); |
1012 gaim_connection_update_progress(gc, _("Connection established, cookie sent"), 4, OSCAR_CONNECT_STEPS); | 970 gaim_connection_update_progress(gc, _("Connection established, cookie sent"), 4, OSCAR_CONNECT_STEPS); |
1013 ck[4] = 0x61; | 971 ck[4] = 0x61; |
1014 } | 972 } |
1015 else if (conn->type == SNAC_FAMILY_CHAT) | 973 else if (conn->type == SNAC_FAMILY_CHAT) |
1016 { | 974 { |
1017 od->oscar_chats = g_slist_append(od->oscar_chats, new_conn_data->data); | 975 od->oscar_chats = g_slist_append(od->oscar_chats, conn->connect_data); |
1018 new_conn_data->data = NULL; | 976 conn->connect_data = NULL; |
1019 } | 977 } |
1020 | |
1021 destroy_new_conn_data(new_conn_data); | |
1022 } | 978 } |
1023 | 979 |
1024 static void | 980 static void |
1025 flap_connection_established_bos(OscarData *od, FlapConnection *conn) | 981 flap_connection_established_bos(OscarData *od, FlapConnection *conn) |
1026 { | 982 { |
1150 static void | 1106 static void |
1151 oscar_login(GaimAccount *account) | 1107 oscar_login(GaimAccount *account) |
1152 { | 1108 { |
1153 GaimConnection *gc; | 1109 GaimConnection *gc; |
1154 OscarData *od; | 1110 OscarData *od; |
1155 NewFlapConnectionData *new_conn_data; | 1111 FlapConnection *newconn; |
1156 | 1112 |
1157 gc = gaim_account_get_connection(account); | 1113 gc = gaim_account_get_connection(account); |
1158 od = gc->proto_data = oscar_data_new(); | 1114 od = gc->proto_data = oscar_data_new(); |
1159 od->gc = gc; | 1115 od->gc = gc; |
1160 | 1116 |
1238 } | 1194 } |
1239 | 1195 |
1240 /* Connect to core Gaim signals */ | 1196 /* Connect to core Gaim signals */ |
1241 gaim_prefs_connect_callback(gc, "/plugins/prpl/oscar/recent_buddies", recent_buddies_cb, gc); | 1197 gaim_prefs_connect_callback(gc, "/plugins/prpl/oscar/recent_buddies", recent_buddies_cb, gc); |
1242 | 1198 |
1243 new_conn_data = g_new(NewFlapConnectionData, 1); | 1199 newconn = flap_connection_new(od, SNAC_FAMILY_AUTH); |
1244 new_conn_data->gc = gc; | 1200 newconn->connect_info = gaim_proxy_connect(account, |
1245 new_conn_data->conn = flap_connection_new(od, SNAC_FAMILY_AUTH); | |
1246 new_conn_data->cookielen = 0; | |
1247 new_conn_data->cookie = NULL; | |
1248 new_conn_data->data = NULL; | |
1249 | |
1250 if (gaim_proxy_connect(account, | |
1251 gaim_account_get_string(account, "server", OSCAR_DEFAULT_LOGIN_SERVER), | 1201 gaim_account_get_string(account, "server", OSCAR_DEFAULT_LOGIN_SERVER), |
1252 gaim_account_get_int(account, "port", OSCAR_DEFAULT_LOGIN_PORT), | 1202 gaim_account_get_int(account, "port", OSCAR_DEFAULT_LOGIN_PORT), |
1253 connection_established_cb, new_conn_data) == NULL) | 1203 connection_established_cb, newconn); |
1204 if (newconn->connect_info == NULL) | |
1254 { | 1205 { |
1255 gaim_connection_error(gc, _("Couldn't connect to host")); | 1206 gaim_connection_error(gc, _("Couldn't connect to host")); |
1256 return; | 1207 return; |
1257 } | 1208 } |
1258 | 1209 |
1293 { | 1244 { |
1294 GaimConnection *gc = od->gc; | 1245 GaimConnection *gc = od->gc; |
1295 GaimAccount *account = gc->account; | 1246 GaimAccount *account = gc->account; |
1296 char *host; int port; | 1247 char *host; int port; |
1297 int i; | 1248 int i; |
1298 GaimProxyConnectInfo *connect_info; | 1249 FlapConnection *newconn; |
1299 NewFlapConnectionData *new_conn_data; | |
1300 va_list ap; | 1250 va_list ap; |
1301 struct aim_authresp_info *info; | 1251 struct aim_authresp_info *info; |
1302 | 1252 |
1303 port = gaim_account_get_int(account, "port", OSCAR_DEFAULT_LOGIN_PORT); | 1253 port = gaim_account_get_int(account, "port", OSCAR_DEFAULT_LOGIN_PORT); |
1304 | 1254 |
1359 port = atoi(&(info->bosip[i+1])); | 1309 port = atoi(&(info->bosip[i+1])); |
1360 break; | 1310 break; |
1361 } | 1311 } |
1362 } | 1312 } |
1363 host = g_strndup(info->bosip, i); | 1313 host = g_strndup(info->bosip, i); |
1364 new_conn_data = g_new(NewFlapConnectionData, 1); | 1314 newconn = flap_connection_new(od, SNAC_FAMILY_LOCATE); |
1365 new_conn_data->gc = gc; | 1315 newconn->cookielen = info->cookielen; |
1366 new_conn_data->conn = flap_connection_new(od, SNAC_FAMILY_LOCATE); | 1316 newconn->cookie = g_memdup(info->cookie, info->cookielen); |
1367 new_conn_data->cookielen = info->cookielen; | 1317 newconn->connect_info = gaim_proxy_connect(account, host, port, |
1368 new_conn_data->cookie = g_memdup(info->cookie, info->cookielen); | 1318 connection_established_cb, newconn); |
1369 new_conn_data->data = NULL; | |
1370 connect_info = gaim_proxy_connect(gc->account, host, port, | |
1371 connection_established_cb, new_conn_data); | |
1372 g_free(host); | 1319 g_free(host); |
1373 if (connect_info == NULL) { | 1320 if (newconn->connect_info == NULL) |
1321 { | |
1374 gaim_connection_error(gc, _("Could Not Connect")); | 1322 gaim_connection_error(gc, _("Could Not Connect")); |
1375 od->killme = TRUE; | 1323 od->killme = TRUE; |
1376 return 0; | 1324 return 0; |
1377 } | 1325 } |
1378 | 1326 |
1480 aim_sendmemblock(od, pos->conn, 0, 16, m, AIM_SENDMEMBLOCK_FLAG_ISHASH); | 1428 aim_sendmemblock(od, pos->conn, 0, 16, m, AIM_SENDMEMBLOCK_FLAG_ISHASH); |
1481 g_free(pos); | 1429 g_free(pos); |
1482 } | 1430 } |
1483 | 1431 |
1484 static void | 1432 static void |
1485 straight_to_hell(gpointer data, gint source) | 1433 straight_to_hell(gpointer data, gint source, const gchar *error_message) |
1486 { | 1434 { |
1487 struct pieceofcrap *pos = data; | 1435 struct pieceofcrap *pos = data; |
1488 gchar *buf; | 1436 gchar *buf; |
1437 | |
1438 if (!GAIM_CONNECTION_IS_VALID(pos->gc)) | |
1439 { | |
1440 g_free(pos->modname); | |
1441 g_free(pos); | |
1442 return; | |
1443 } | |
1489 | 1444 |
1490 pos->fd = source; | 1445 pos->fd = source; |
1491 | 1446 |
1492 if (source < 0) { | 1447 if (source < 0) { |
1493 buf = g_strdup_printf(_("You may be disconnected shortly. You may want to use TOC until " | 1448 buf = g_strdup_printf(_("You may be disconnected shortly. You may want to use TOC until " |
1494 "this is fixed. Check %s for updates."), GAIM_WEBSITE); | 1449 "this is fixed. Check %s for updates."), GAIM_WEBSITE); |
1495 gaim_notify_warning(pos->gc, NULL, | 1450 gaim_notify_warning(pos->gc, NULL, |
1496 _("Gaim was unable to get a valid AIM login hash."), | 1451 _("Gaim was unable to get a valid AIM login hash."), |
1497 buf); | 1452 buf); |
1498 g_free(buf); | 1453 g_free(buf); |
1499 if (pos->modname) | 1454 g_free(pos->modname); |
1500 g_free(pos->modname); | |
1501 g_free(pos); | 1455 g_free(pos); |
1502 return; | 1456 return; |
1503 } | 1457 } |
1504 | 1458 |
1505 buf = g_strdup_printf("GET " AIMHASHDATA "?offset=%ld&len=%ld&modname=%s HTTP/1.0\n\n", | 1459 buf = g_strdup_printf("GET " AIMHASHDATA "?offset=%ld&len=%ld&modname=%s HTTP/1.0\n\n", |
1506 pos->offset, pos->len, pos->modname ? pos->modname : ""); | 1460 pos->offset, pos->len, pos->modname ? pos->modname : ""); |
1507 write(pos->fd, buf, strlen(buf)); | 1461 write(pos->fd, buf, strlen(buf)); |
1508 g_free(buf); | 1462 g_free(buf); |
1509 if (pos->modname) | 1463 g_free(pos->modname); |
1510 g_free(pos->modname); | |
1511 pos->inpa = gaim_input_add(pos->fd, GAIM_INPUT_READ, damn_you, pos); | 1464 pos->inpa = gaim_input_add(pos->fd, GAIM_INPUT_READ, damn_you, pos); |
1512 return; | 1465 return; |
1513 } | 1466 } |
1514 | 1467 |
1515 /* size of icbmui.ocm, the largest module in AIM 3.5 */ | 1468 /* size of icbmui.ocm, the largest module in AIM 3.5 */ |
1571 | 1524 |
1572 pos->offset = offset; | 1525 pos->offset = offset; |
1573 pos->len = len; | 1526 pos->len = len; |
1574 pos->modname = g_strdup(modname); | 1527 pos->modname = g_strdup(modname); |
1575 | 1528 |
1529 /* TODO: Keep track of this return value. */ | |
1576 if (gaim_proxy_connect(pos->gc->account, "gaim.sourceforge.net", 80, | 1530 if (gaim_proxy_connect(pos->gc->account, "gaim.sourceforge.net", 80, |
1577 straight_to_hell, pos) == NULL) | 1531 straight_to_hell, pos) == NULL) |
1578 { | 1532 { |
1579 char buf[256]; | 1533 char buf[256]; |
1580 if (pos->modname) | 1534 if (pos->modname) |
1620 { | 1574 { |
1621 GaimConnection *gc = od->gc; | 1575 GaimConnection *gc = od->gc; |
1622 GaimAccount *account = gaim_connection_get_account(gc); | 1576 GaimAccount *account = gaim_connection_get_account(gc); |
1623 char *host, *separator; | 1577 char *host, *separator; |
1624 int port; | 1578 int port; |
1625 NewFlapConnectionData *new_conn_data; | 1579 FlapConnection *newconn; |
1626 va_list ap; | 1580 va_list ap; |
1627 struct aim_redirect_data *redir; | 1581 struct aim_redirect_data *redir; |
1628 | 1582 |
1629 va_start(ap, fr); | 1583 va_start(ap, fr); |
1630 redir = va_arg(ap, struct aim_redirect_data *); | 1584 redir = va_arg(ap, struct aim_redirect_data *); |
1640 else | 1594 else |
1641 host = g_strdup(redir->ip); | 1595 host = g_strdup(redir->ip); |
1642 | 1596 |
1643 gaim_debug_info("oscar", "Connecting to FLAP server %s:%d of type 0x%04hx\n", | 1597 gaim_debug_info("oscar", "Connecting to FLAP server %s:%d of type 0x%04hx\n", |
1644 host, port, redir->group); | 1598 host, port, redir->group); |
1645 new_conn_data = g_new(NewFlapConnectionData, 1); | 1599 newconn = flap_connection_new(od, redir->group); |
1646 new_conn_data->gc = gc; | 1600 newconn->cookielen = redir->cookielen; |
1647 new_conn_data->conn = flap_connection_new(od, redir->group); | 1601 newconn->cookie = g_memdup(redir->cookie, redir->cookielen); |
1648 new_conn_data->cookielen = redir->cookielen; | 1602 if (newconn->type == SNAC_FAMILY_CHAT) |
1649 new_conn_data->cookie = g_memdup(redir->cookie, redir->cookielen); | |
1650 if (new_conn_data->conn->type == SNAC_FAMILY_CHAT) | |
1651 { | 1603 { |
1652 struct chat_connection *cc; | 1604 struct chat_connection *cc; |
1653 cc = g_new0(struct chat_connection, 1); | 1605 cc = g_new0(struct chat_connection, 1); |
1654 cc->conn = new_conn_data->conn; | 1606 cc->conn = newconn; |
1655 cc->gc = gc; | 1607 cc->gc = gc; |
1656 cc->name = g_strdup(redir->chat.room); | 1608 cc->name = g_strdup(redir->chat.room); |
1657 cc->exchange = redir->chat.exchange; | 1609 cc->exchange = redir->chat.exchange; |
1658 cc->instance = redir->chat.instance; | 1610 cc->instance = redir->chat.instance; |
1659 cc->show = extract_name(redir->chat.room); | 1611 cc->show = extract_name(redir->chat.room); |
1660 new_conn_data->data = cc; | 1612 newconn->connect_data = cc; |
1661 gaim_debug_info("oscar", "Connecting to chat room %s exchange %hu\n", cc->name, cc->exchange); | 1613 gaim_debug_info("oscar", "Connecting to chat room %s exchange %hu\n", cc->name, cc->exchange); |
1662 } | 1614 } |
1663 else | 1615 |
1664 { | 1616 newconn->connect_info = gaim_proxy_connect(account, host, port, |
1665 new_conn_data->data = NULL; | 1617 connection_established_cb, newconn); |
1666 } | 1618 if (newconn->connect_info == NULL) |
1667 | 1619 { |
1668 if (gaim_proxy_connect(account, host, port, connection_established_cb, new_conn_data) == NULL) | 1620 flap_connection_schedule_destroy(newconn, OSCAR_DISCONNECT_COULD_NOT_CONNECT); |
1669 { | |
1670 flap_connection_schedule_destroy(new_conn_data->conn, | |
1671 OSCAR_DISCONNECT_COULD_NOT_CONNECT); | |
1672 gaim_debug_error("oscar", "Unable to connect to FLAP server " | 1621 gaim_debug_error("oscar", "Unable to connect to FLAP server " |
1673 "of type 0x%04hx\n", redir->group); | 1622 "of type 0x%04hx\n", redir->group); |
1674 destroy_new_conn_data(new_conn_data); | |
1675 } | 1623 } |
1676 g_free(host); | 1624 g_free(host); |
1677 | 1625 |
1678 return 1; | 1626 return 1; |
1679 } | 1627 } |