comparison libpurple/protocols/bonjour/jabber.c @ 32672:3828a61c44da

A boring and large patch so I can merge heads.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Fri, 23 Dec 2011 08:21:58 +0000
parents e1d31abb245c
children
comparison
equal deleted inserted replaced
32671:0e69949b3e61 32672:3828a61c44da
204 204
205 if (font_face) 205 if (font_face)
206 g_string_append_printf(str, " face='%s'", font_face); 206 g_string_append_printf(str, " face='%s'", font_face);
207 if (font_size) 207 if (font_size)
208 g_string_append_printf(str, " size='%s'", font_size); 208 g_string_append_printf(str, " size='%s'", font_size);
209 if (ichat_text_color) 209 if (font_color)
210 g_string_append_printf(str, " color='%s'", font_color);
211 else if (ichat_text_color)
210 g_string_append_printf(str, " color='%s'", ichat_text_color); 212 g_string_append_printf(str, " color='%s'", ichat_text_color);
211 if (ichat_balloon_color) 213 if (ichat_balloon_color)
212 g_string_append_printf(str, " back='%s'", ichat_balloon_color); 214 g_string_append_printf(str, " back='%s'", ichat_balloon_color);
213 g_string_append_printf(str, ">%s</font>", html_body); 215 g_string_append_printf(str, ">%s</font>", html_body);
214 216
663 fcntl(client_socket, F_SETFD, FD_CLOEXEC); 665 fcntl(client_socket, F_SETFD, FD_CLOEXEC);
664 #endif 666 #endif
665 667
666 /* Look for the buddy that has opened the conversation and fill information */ 668 /* Look for the buddy that has opened the conversation and fill information */
667 #ifdef HAVE_INET_NTOP 669 #ifdef HAVE_INET_NTOP
668 if (their_addr.ss_family == AF_INET6) 670 if (their_addr.ss_family == AF_INET6) {
669 address_text = inet_ntop(their_addr.ss_family, &((struct sockaddr_in6 *)&their_addr)->sin6_addr, 671 address_text = inet_ntop(their_addr.ss_family, &((struct sockaddr_in6 *)&their_addr)->sin6_addr,
670 addrstr, sizeof(addrstr)); 672 addrstr, sizeof(addrstr));
673
674 append_iface_if_linklocal(addrstr,
675 ((struct sockaddr_in6 *)&their_addr)->sin6_scope_id);
676 }
671 else 677 else
672 address_text = inet_ntop(their_addr.ss_family, &((struct sockaddr_in *)&their_addr)->sin_addr, 678 address_text = inet_ntop(their_addr.ss_family, &((struct sockaddr_in *)&their_addr)->sin_addr,
673 addrstr, sizeof(addrstr)); 679 addrstr, sizeof(addrstr));
674 #else 680 #else
675 address_text = inet_ntoa(((struct sockaddr_in *)&their_addr)->sin_addr); 681 address_text = inet_ntoa(((struct sockaddr_in *)&their_addr)->sin_addr);
742 return -1; 748 return -1;
743 } 749 }
744 750
745 #if 0 751 #if 0
746 /* TODO: Why isn't this being used? */ 752 /* TODO: Why isn't this being used? */
747 data->socket = purple_network_listen(jdata->port, SOCK_STREAM); 753 data->socket = purple_network_listen(jdata->port, AF_UNSPEC, SOCK_STREAM, TRUE);
748 754
749 if (jdata->socket == -1) 755 if (jdata->socket == -1)
750 { 756 {
751 purple_debug_error("bonjour", "No se ha podido crear el socket\n"); 757 purple_debug_error("bonjour", "No se ha podido crear el socket\n");
752 } 758 }
927 933
928 /* Check that one of the buddy's IPs matches */ 934 /* Check that one of the buddy's IPs matches */
929 while(tmp) { 935 while(tmp) {
930 ip = tmp->data; 936 ip = tmp->data;
931 if (ip != NULL && g_ascii_strcasecmp(ip, bconv->ip) == 0) { 937 if (ip != NULL && g_ascii_strcasecmp(ip, bconv->ip) == 0) {
932 BonjourJabber *jdata = ((BonjourData*) bconv->account->gc->proto_data)->jabber_data; 938 PurpleConnection *pc = purple_account_get_connection(bconv->account);
939 BonjourData *bd = purple_connection_get_protocol_data(pc);
940 BonjourJabber *jdata = bd->jabber_data;
933 941
934 purple_debug_info("bonjour", "Matched buddy %s to incoming conversation \"from\" attrib and IP (%s)\n", 942 purple_debug_info("bonjour", "Matched buddy %s to incoming conversation \"from\" attrib and IP (%s)\n",
935 purple_buddy_get_name(pb), bconv->ip); 943 purple_buddy_get_name(pb), bconv->ip);
936 944
937 /* Attach conv. to buddy and remove from pending list */ 945 /* Attach conv. to buddy and remove from pending list */
960 } 968 }
961 969
962 970
963 void 971 void
964 bonjour_jabber_conv_match_by_ip(BonjourJabberConversation *bconv) { 972 bonjour_jabber_conv_match_by_ip(BonjourJabberConversation *bconv) {
965 BonjourJabber *jdata = ((BonjourData*) bconv->account->gc->proto_data)->jabber_data; 973 PurpleConnection *pc = purple_account_get_connection(bconv->account);
974 BonjourData *bd = purple_connection_get_protocol_data(pc);
975 BonjourJabber *jdata = bd->jabber_data;
966 struct _match_buddies_by_address_t *mbba; 976 struct _match_buddies_by_address_t *mbba;
967 GSList *buddies; 977 GSList *buddies;
968 978
969 mbba = g_new0(struct _match_buddies_by_address_t, 1); 979 mbba = g_new0(struct _match_buddies_by_address_t, 1);
970 mbba->address = bconv->ip; 980 mbba->address = bconv->ip;
1120 return FALSE; 1130 return FALSE;
1121 } 1131 }
1122 1132
1123 void 1133 void
1124 async_bonjour_jabber_close_conversation(BonjourJabberConversation *bconv) { 1134 async_bonjour_jabber_close_conversation(BonjourJabberConversation *bconv) {
1125 BonjourJabber *jdata = ((BonjourData*) bconv->account->gc->proto_data)->jabber_data; 1135 PurpleConnection *pc = purple_account_get_connection(bconv->account);
1136 BonjourData *bd = purple_connection_get_protocol_data(pc);
1137 BonjourJabber *jdata = bd->jabber_data;
1126 1138
1127 jdata->pending_conversations = g_slist_remove(jdata->pending_conversations, bconv); 1139 jdata->pending_conversations = g_slist_remove(jdata->pending_conversations, bconv);
1128 1140
1129 /* Disconnect this conv. from the buddy here so it can't be disposed of twice.*/ 1141 /* Disconnect this conv. from the buddy here so it can't be disposed of twice.*/
1130 if(bconv->pb != NULL) { 1142 if(bconv->pb != NULL) {
1140 bonjour_jabber_close_conversation(BonjourJabberConversation *bconv) 1152 bonjour_jabber_close_conversation(BonjourJabberConversation *bconv)
1141 { 1153 {
1142 if (bconv != NULL) { 1154 if (bconv != NULL) {
1143 BonjourData *bd = NULL; 1155 BonjourData *bd = NULL;
1144 1156
1145 if(PURPLE_CONNECTION_IS_VALID(bconv->account->gc)) { 1157 PurpleConnection *pc = purple_account_get_connection(bconv->account);
1146 bd = bconv->account->gc->proto_data; 1158 if (PURPLE_CONNECTION_IS_VALID(pc)) {
1159 bd = purple_connection_get_protocol_data(pc);
1147 bd->jabber_data->pending_conversations = g_slist_remove(bd->jabber_data->pending_conversations, bconv); 1160 bd->jabber_data->pending_conversations = g_slist_remove(bd->jabber_data->pending_conversations, bconv);
1148 } 1161 }
1149 1162
1150 /* Cancel any file transfers that are waiting to begin */ 1163 /* Cancel any file transfers that are waiting to begin */
1151 /* There wont be any transfers if it hasn't been attached to a buddy */ 1164 /* There wont be any transfers if it hasn't been attached to a buddy */
1155 while(xfers != NULL) { 1168 while(xfers != NULL) {
1156 PurpleXfer *xfer = xfers->data; 1169 PurpleXfer *xfer = xfers->data;
1157 tmp_next = xfers->next; 1170 tmp_next = xfers->next;
1158 /* We only need to cancel this if it hasn't actually started transferring. */ 1171 /* We only need to cancel this if it hasn't actually started transferring. */
1159 /* This will change if we ever support IBB transfers. */ 1172 /* This will change if we ever support IBB transfers. */
1160 if (strcmp(xfer->who, purple_buddy_get_name(bconv->pb)) == 0 1173 if (strcmp(purple_xfer_get_remote_user(xfer), purple_buddy_get_name(bconv->pb)) == 0
1161 && (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_NOT_STARTED 1174 && (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_NOT_STARTED
1162 || purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_UNKNOWN)) { 1175 || purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_UNKNOWN)) {
1163 purple_xfer_cancel_remote(xfer); 1176 purple_xfer_cancel_remote(xfer);
1164 } 1177 }
1165 xfers = tmp_next; 1178 xfers = tmp_next;
1213 close(jdata->socket6); 1226 close(jdata->socket6);
1214 if (jdata->watcher_id6 > 0) 1227 if (jdata->watcher_id6 > 0)
1215 purple_input_remove(jdata->watcher_id6); 1228 purple_input_remove(jdata->watcher_id6);
1216 1229
1217 /* Close all the conversation sockets and remove all the watchers after sending end streams */ 1230 /* Close all the conversation sockets and remove all the watchers after sending end streams */
1218 if (jdata->account->gc != NULL) { 1231 if (!purple_account_is_disconnected(jdata->account)) {
1219 GSList *buddies, *l; 1232 GSList *buddies, *l;
1220 1233
1221 buddies = purple_find_buddies(jdata->account, NULL); 1234 buddies = purple_find_buddies(jdata->account, NULL);
1222 for (l = buddies; l; l = l->next) { 1235 for (l = buddies; l; l = l->next) {
1223 BonjourBuddy *bb = purple_buddy_get_protocol_data((PurpleBuddy*) l->data); 1236 BonjourBuddy *bb = purple_buddy_get_protocol_data((PurpleBuddy*) l->data);
1440 } 1453 }
1441 #endif 1454 #endif
1442 1455
1443 return ips; 1456 return ips;
1444 } 1457 }
1458
1459 void
1460 append_iface_if_linklocal(char *ip, guint32 interface_param) {
1461 struct in6_addr in6_addr;
1462 int len_remain = INET6_ADDRSTRLEN - strlen(ip);
1463
1464 if (len_remain <= 1)
1465 return;
1466
1467 if (inet_pton(AF_INET6, ip, &in6_addr) != 1 ||
1468 !IN6_IS_ADDR_LINKLOCAL(&in6_addr))
1469 return;
1470
1471 snprintf(ip + strlen(ip), len_remain, "%%%d",
1472 interface_param);
1473 }