src/protocols/oscar/peer.c

changeset 13255
b318f395092d
parent 13254
3fbb3f3efba7
child 13593
3450a7cede99
equal deleted inserted replaced
13254:3fbb3f3efba7 13255:b318f395092d
219 if ((acceptfd = accept(cur->fd, &addr, &addrlen)) == -1) 219 if ((acceptfd = accept(cur->fd, &addr, &addrlen)) == -1)
220 return 0; /* not an error */ 220 return 0; /* not an error */
221 221
222 if ((addr.sa_family != PF_INET) && (addr.sa_family != PF_INET6)) { 222 if ((addr.sa_family != PF_INET) && (addr.sa_family != PF_INET6)) {
223 close(acceptfd); 223 close(acceptfd);
224 aim_conn_close(cur); 224 aim_conn_close(sess, cur);
225 return -1; 225 return -1;
226 } 226 }
227 227
228 strncpy(ip, inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr), sizeof(ip)); 228 strncpy(ip, inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr), sizeof(ip));
229 port = ntohs(((struct sockaddr_in *)&addr)->sin_port); 229 port = ntohs(((struct sockaddr_in *)&addr)->sin_port);
230 230
231 if (!(newconn = aim_cloneconn(sess, cur))) { 231 if (!(newconn = aim_cloneconn(sess, cur))) {
232 close(acceptfd); 232 close(acceptfd);
233 aim_conn_close(cur); 233 aim_conn_close(sess, cur);
234 return -ENOMEM; 234 return -ENOMEM;
235 } 235 }
236 236
237 newconn->type = AIM_CONN_TYPE_RENDEZVOUS; 237 newconn->type = AIM_CONN_TYPE_RENDEZVOUS;
238 newconn->fd = acceptfd; 238 newconn->fd = acceptfd;
255 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, PEER_TYPE_ESTABLISHED))) 255 if ((userfunc = aim_callhandler(sess, newconn, AIM_CB_FAM_OFT, PEER_TYPE_ESTABLISHED)))
256 ret = userfunc(sess, NULL, newconn, cur); 256 ret = userfunc(sess, NULL, newconn, cur);
257 257
258 } else { 258 } else {
259 gaim_debug_warning("oscar", "Got a connection on a listener that's not rendezvous. Closing connection.\n"); 259 gaim_debug_warning("oscar", "Got a connection on a listener that's not rendezvous. Closing connection.\n");
260 aim_conn_close(newconn); 260 aim_conn_close(sess, newconn);
261 ret = -1; 261 ret = -1;
262 } 262 }
263 263
264 return ret; 264 return ret;
265 } 265 }
479 * connection was found. 479 * connection was found.
480 */ 480 */
481 OscarConnection * 481 OscarConnection *
482 aim_odc_getconn(OscarSession *sess, const char *sn) 482 aim_odc_getconn(OscarSession *sess, const char *sn)
483 { 483 {
484 OscarConnection *cur; 484 GList *cur;
485 struct aim_odc_intdata *intdata; 485 struct aim_odc_intdata *intdata;
486 486
487 if (!sess || !sn || !strlen(sn)) 487 if (!sess || !sn || !strlen(sn))
488 return NULL; 488 return NULL;
489 489
490 for (cur = sess->connlist; cur; cur = cur->next) { 490 for (cur = sess->oscar_connections; cur; cur = cur->next)
491 if ((cur->type == AIM_CONN_TYPE_RENDEZVOUS) && (cur->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM)) { 491 {
492 intdata = cur->internal; 492 OscarConnection *conn;
493 conn = cur->data;
494 if ((conn->type == AIM_CONN_TYPE_RENDEZVOUS) && (conn->subtype == AIM_CONN_SUBTYPE_OFT_DIRECTIM)) {
495 intdata = conn->internal;
493 if (!aim_sncmp(intdata->sn, sn)) 496 if (!aim_sncmp(intdata->sn, sn))
494 return cur; 497 return conn;
495 } 498 }
496 } 499 }
497 500
498 return NULL; 501 return NULL;
499 } 502 }
539 strncpy(priv->sn, sn, sizeof(priv->sn)); 542 strncpy(priv->sn, sn, sizeof(priv->sn));
540 cookie->data = priv; 543 cookie->data = priv;
541 aim_cachecookie(sess, cookie); 544 aim_cachecookie(sess, cookie);
542 545
543 /* XXX - switch to aim_cloneconn()? */ 546 /* XXX - switch to aim_cloneconn()? */
544 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER))) { 547 if (!(newconn = oscar_connection_new(sess, AIM_CONN_TYPE_LISTENER))) {
545 close(listenfd); 548 close(listenfd);
546 return NULL; 549 return NULL;
547 } 550 }
548 551
549 /* this one is for the conn */ 552 /* this one is for the conn */
561 } 564 }
562 565
563 /** 566 /**
564 * Connect directly to the given buddy for directim. 567 * Connect directly to the given buddy for directim.
565 * 568 *
566 * This is a wrapper for aim_newconn. 569 * This is a wrapper for oscar_connection_new.
567 * 570 *
568 * If addr is NULL, the socket is not created, but the connection is 571 * If addr is NULL, the socket is not created, but the connection is
569 * allocated and setup to connect. 572 * allocated and setup to connect.
570 * 573 *
571 * @param sess The Godly session. 574 * @param sess The Godly session.
588 strncpy(intdata->sn, sn, sizeof(intdata->sn)); 591 strncpy(intdata->sn, sn, sizeof(intdata->sn));
589 if (addr) 592 if (addr)
590 strncpy(intdata->ip, addr, sizeof(intdata->ip)); 593 strncpy(intdata->ip, addr, sizeof(intdata->ip));
591 594
592 /* XXX - verify that non-blocking connects actually work */ 595 /* XXX - verify that non-blocking connects actually work */
593 if (!(newconn = aim_newconn(sess, AIM_CONN_TYPE_RENDEZVOUS))) { 596 if (!(newconn = oscar_connection_new(sess, AIM_CONN_TYPE_RENDEZVOUS))) {
594 free(intdata); 597 free(intdata);
595 return NULL; 598 return NULL;
596 } 599 }
597 600
598 newconn->internal = intdata; 601 newconn->internal = intdata;
802 aim_sendfile_listen(OscarSession *sess, PeerConnection *peer_connection, int listenfd) 805 aim_sendfile_listen(OscarSession *sess, PeerConnection *peer_connection, int listenfd)
803 { 806 {
804 if (!peer_connection) 807 if (!peer_connection)
805 return -EINVAL; 808 return -EINVAL;
806 809
807 if (!(peer_connection->conn = aim_newconn(sess, AIM_CONN_TYPE_LISTENER))) { 810 if (!(peer_connection->conn = oscar_connection_new(sess, AIM_CONN_TYPE_LISTENER))) {
808 close(listenfd); 811 close(listenfd);
809 return -ENOMEM; 812 return -ENOMEM;
810 } 813 }
811 814
812 peer_connection->conn->fd = listenfd; 815 peer_connection->conn->fd = listenfd;
1135 1138
1136 free(header); 1139 free(header);
1137 } 1140 }
1138 1141
1139 if (ret == -1) 1142 if (ret == -1)
1140 aim_conn_close(conn); 1143 aim_conn_close(sess, conn);
1141 1144
1142 return ret; 1145 return ret;
1143 } 1146 }
1144 1147
1145 /** 1148 /**
1188 if (aim_bstream_recv(&bs_body, conn->fd, body_len) == body_len) { 1191 if (aim_bstream_recv(&bs_body, conn->fd, body_len) == body_len) {
1189 aim_bstream_rewind(&bs_body); 1192 aim_bstream_rewind(&bs_body);
1190 proxy_info->err_code = aimbs_get16(&bs_body); 1193 proxy_info->err_code = aimbs_get16(&bs_body);
1191 } else { 1194 } else {
1192 gaim_debug_warning("oscar","error reading rv proxy error packet\n"); 1195 gaim_debug_warning("oscar","error reading rv proxy error packet\n");
1193 aim_conn_close(conn); 1196 aim_conn_close(sess, conn);
1194 free(proxy_info); 1197 free(proxy_info);
1195 proxy_info = NULL; 1198 proxy_info = NULL;
1196 } 1199 }
1197 } else { 1200 } else {
1198 gaim_debug_warning("oscar","invalid length for proxy error packet\n"); 1201 gaim_debug_warning("oscar","invalid length for proxy error packet\n");
1214 ip_temp[0], ip_temp[1], 1217 ip_temp[0], ip_temp[1],
1215 ip_temp[2], ip_temp[3]); 1218 ip_temp[2], ip_temp[3]);
1216 proxy_info->ip = strdup(str_ip); 1219 proxy_info->ip = strdup(str_ip);
1217 } else { 1220 } else {
1218 gaim_debug_warning("oscar","error reading rv proxy error packet\n"); 1221 gaim_debug_warning("oscar","error reading rv proxy error packet\n");
1219 aim_conn_close(conn); 1222 aim_conn_close(sess, conn);
1220 free(proxy_info); 1223 free(proxy_info);
1221 proxy_info = NULL; 1224 proxy_info = NULL;
1222 } 1225 }
1223 } else { 1226 } else {
1224 gaim_debug_warning("oscar","invalid length for proxy error packet\n"); 1227 gaim_debug_warning("oscar","invalid length for proxy error packet\n");
1228 } else { 1231 } else {
1229 gaim_debug_warning("oscar","unknown type for aim rendezvous proxy packet\n"); 1232 gaim_debug_warning("oscar","unknown type for aim rendezvous proxy packet\n");
1230 } 1233 }
1231 } else { 1234 } else {
1232 gaim_debug_warning("oscar","error reading header of rv proxy packet\n"); 1235 gaim_debug_warning("oscar","error reading header of rv proxy packet\n");
1233 aim_conn_close(conn); 1236 aim_conn_close(sess, conn);
1234 free(proxy_info); 1237 free(proxy_info);
1235 proxy_info = NULL; 1238 proxy_info = NULL;
1236 } 1239 }
1237 if(body_buf) { 1240 if(body_buf) {
1238 free(body_buf); 1241 free(body_buf);

mercurial