Changeset 5ebff60 for protocols/oscar/conn.c
- Timestamp:
- 2015-02-20T22:50:54Z (10 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/oscar/conn.c
raf359b4 r5ebff60 7 7 */ 8 8 9 #include <aim.h> 9 #include <aim.h> 10 10 #include "sock.h" 11 11 … … 15 15 * In OSCAR, every connection has a set of SNAC groups associated 16 16 * with it. These are the groups that you can send over this connection 17 * without being guarenteed a "Not supported" SNAC error. 18 * 19 * The grand theory of things says that these associations transcend 17 * without being guarenteed a "Not supported" SNAC error. 18 * 19 * The grand theory of things says that these associations transcend 20 20 * what libfaim calls "connection types" (conn->type). You can probably 21 * see the elegance here, but since I want to revel in it for a bit, you 21 * see the elegance here, but since I want to revel in it for a bit, you 22 22 * get to hear it all spelled out. 23 23 * … … 25 25 * of your modules has just given you a SNAC of the group 0x0004 to send 26 26 * you. Maybe an IM destined for some twit in Greenland. So you start 27 * at the top of your connection list, looking for a connection that 27 * at the top of your connection list, looking for a connection that 28 28 * claims to support group 0x0004. You find one. Why, that neat BOS 29 29 * connection of yours can do that. So you send it on its way. … … 43 43 * that connection. One of the first things you get from this new server 44 44 * is a message saying that indeed it does support the group you were looking 45 * for. So you continue and send rate confirmation and all that. 46 * 45 * for. So you continue and send rate confirmation and all that. 46 * 47 47 * Then you remember you had that SNAC to send, and now you have a means to 48 48 * do it, and you do, and everyone is happy. Except the Greenlander, who is … … 57 57 * to make libfaim work that way. It would take a fair amount of effort, 58 58 * and probably some client API changes as well. (Whenever I don't want 59 * to do something, I just say it would change the client API. Then I 59 * to do something, I just say it would change the client API. Then I 60 60 * instantly have a couple of supporters of not doing it.) 61 61 * … … 69 69 void aim_conn_addgroup(aim_conn_t *conn, guint16 group) 70 70 { 71 aim_conn_inside_t *ins = (aim_conn_inside_t *) conn->inside;71 aim_conn_inside_t *ins = (aim_conn_inside_t *) conn->inside; 72 72 struct snacgroup *sg; 73 73 74 if (!(sg = g_malloc(sizeof(struct snacgroup)))) 74 if (!(sg = g_malloc(sizeof(struct snacgroup)))) { 75 75 return; 76 } 76 77 77 78 sg->group = group; … … 88 89 89 90 for (cur = sess->connlist; cur; cur = cur->next) { 90 aim_conn_inside_t *ins = (aim_conn_inside_t *) cur->inside;91 aim_conn_inside_t *ins = (aim_conn_inside_t *) cur->inside; 91 92 struct snacgroup *sg; 92 93 93 94 for (sg = ins->groups; sg; sg = sg->next) { 94 if (sg->group == group) 95 if (sg->group == group) { 95 96 return cur; 97 } 96 98 } 97 99 } … … 150 152 aim_tx_cleanqueue(sess, *deadconn); 151 153 152 if ((*deadconn)->fd != -1) 154 if ((*deadconn)->fd != -1) { 153 155 aim_conn_close(*deadconn); 156 } 154 157 155 158 /* … … 158 161 * ->internal instead. 159 162 */ 160 if ((*deadconn)->priv) 163 if ((*deadconn)->priv) { 161 164 g_free((*deadconn)->priv); 165 } 162 166 163 167 /* 164 168 * This will free ->internal if it necessary... 165 169 */ 166 if ((*deadconn)->type == AIM_CONN_TYPE_CHAT) 170 if ((*deadconn)->type == AIM_CONN_TYPE_CHAT) { 167 171 aim_conn_kill_chat(sess, *deadconn); 172 } 168 173 169 174 if ((*deadconn)->inside) { 170 aim_conn_inside_t *inside = (aim_conn_inside_t *) (*deadconn)->inside;175 aim_conn_inside_t *inside = (aim_conn_inside_t *) (*deadconn)->inside; 171 176 172 177 connkill_snacgroups(&inside->groups); … … 218 223 { 219 224 220 if (!deadconn) 225 if (!deadconn) { 221 226 return; 227 } 222 228 223 229 deadconn->fd = -1; … … 245 251 aim_conn_t *newconn; 246 252 247 if (!(newconn = g_new0(aim_conn_t, 1)))253 if (!(newconn = g_new0(aim_conn_t, 1))) { 248 254 return NULL; 249 250 if (!(newconn->inside = g_new0(aim_conn_inside_t,1))) { 255 } 256 257 if (!(newconn->inside = g_new0(aim_conn_inside_t, 1))) { 251 258 g_free(newconn); 252 259 return NULL; … … 274 281 aim_conn_t *cur, **prev; 275 282 276 if (!deadconn || !*deadconn) 283 if (!deadconn || !*deadconn) { 277 284 return; 285 } 278 286 279 287 for (prev = &sess->connlist; (cur = *prev); ) { … … 285 293 } 286 294 287 if (!cur) 295 if (!cur) { 288 296 return; /* oops */ 289 297 298 } 290 299 connkill_real(sess, &cur); 291 300 … … 299 308 * Close (but not free) a connection. 300 309 * 301 * This leaves everything untouched except for clearing the 310 * This leaves everything untouched except for clearing the 302 311 * handler list and setting the fd to -1 (used to recognize 303 312 * dead connections). It will also remove cookies if necessary. … … 307 316 { 308 317 309 if (deadconn->fd >= 3) 318 if (deadconn->fd >= 3) { 310 319 closesocket(deadconn->fd); 320 } 311 321 deadconn->fd = -1; 312 if (deadconn->handlerlist) 322 if (deadconn->handlerlist) { 313 323 aim_clearhandlers(deadconn); 324 } 314 325 315 326 return; … … 321 332 * @type: Type of connection to look for 322 333 * 323 * Searches for a connection of the specified type in the 334 * Searches for a connection of the specified type in the 324 335 * specified session. Returns the first connection of that 325 336 * type found. … … 333 344 334 345 for (cur = sess->connlist; cur; cur = cur->next) { 335 if ((cur->type == type) && 336 !(cur->status & AIM_CONN_STATUS_INPROGRESS))346 if ((cur->type == type) && 347 !(cur->status & AIM_CONN_STATUS_INPROGRESS)) { 337 348 break; 349 } 338 350 } 339 351 … … 346 358 347 359 for (cur = sess->connlist; cur; cur = cur->next) { 348 if (cur->type == type) 360 if (cur->type == type) { 349 361 break; 362 } 350 363 } 351 364 … … 361 374 * Opens a new connection to the specified dest host of specified 362 375 * type, using the proxy settings if available. If @host is %NULL, 363 * the connection is allocated and returned, but no connection 376 * the connection is allocated and returned, but no connection 364 377 * is made. 365 378 * … … 374 387 int i; 375 388 376 if (!(connstruct = aim_conn_getnext(sess))) 389 if (!(connstruct = aim_conn_getnext(sess))) { 377 390 return NULL; 378 379 connstruct->sessv = (void *)sess; 391 } 392 393 connstruct->sessv = (void *) sess; 380 394 connstruct->type = type; 381 395 … … 386 400 } 387 401 388 /* 389 * As of 23 Jul 1999, AOL now sends the port number, preceded by a 390 * colon, in the BOS redirect. This fatally breaks all previous 402 /* 403 * As of 23 Jul 1999, AOL now sends the port number, preceded by a 404 * colon, in the BOS redirect. This fatally breaks all previous 391 405 * libfaims. Bad, bad AOL. 392 406 * 393 * We put this here to catch every case. 407 * We put this here to catch every case. 394 408 * 395 409 */ 396 410 397 for (i = 0; i < (int)strlen(dest); i++) {411 for (i = 0; i < (int) strlen(dest); i++) { 398 412 if (dest[i] == ':') { 399 port = atoi(&(dest[i +1]));413 port = atoi(&(dest[i + 1])); 400 414 break; 401 415 } 402 416 } 403 417 404 host = (char *) g_malloc(i+1);418 host = (char *) g_malloc(i + 1); 405 419 strncpy(host, dest, i); 406 420 host[i] = '\0'; … … 421 435 * 422 436 * This is my lame attempt at overcoming not understanding the rate 423 * limiting. 437 * limiting. 424 438 * 425 439 * XXX: This should really be replaced with something that scales and … … 430 444 { 431 445 432 if (!conn) 446 if (!conn) { 433 447 return -1; 448 } 434 449 435 450 conn->forcedlatency = newval; … … 451 466 { 452 467 453 if (!sess) 468 if (!sess) { 454 469 return; 470 } 455 471 456 472 memset(sess, 0, sizeof(aim_session_t)); … … 471 487 sess->ssi.revision = 0; 472 488 sess->ssi.items = NULL; 473 sess->ssi.timestamp = (time_t) 0;489 sess->ssi.timestamp = (time_t) 0; 474 490 475 491 sess->locate.userinfo = NULL; … … 487 503 * Default to SNAC login unless XORLOGIN is explicitly set. 488 504 */ 489 if (!(flags & AIM_SESS_FLAGS_XORLOGIN)) 505 if (!(flags & AIM_SESS_FLAGS_XORLOGIN)) { 490 506 sess->flags |= AIM_SESS_FLAGS_SNACLOGIN; 507 } 491 508 sess->flags |= flags; 492 509 493 510 /* 494 511 * This must always be set. Default to the queue-based 495 * version for back-compatibility. 512 * version for back-compatibility. 496 513 */ 497 514 aim_tx_setenqueue(sess, AIM_TX_QUEUED, NULL); … … 548 565 aim_rxcallback_t userfunc; 549 566 550 if (!conn || (conn->fd == -1)) 567 if (!conn || (conn->fd == -1)) { 551 568 return -1; 552 553 if (!(conn->status & AIM_CONN_STATUS_INPROGRESS)) 569 } 570 571 if (!(conn->status & AIM_CONN_STATUS_INPROGRESS)) { 554 572 return -1; 573 } 555 574 556 575 FD_ZERO(&fds); … … 561 580 tv.tv_usec = 0; 562 581 563 if ((res = select(conn->fd +1, &fds, &wfds, NULL, &tv)) == -1) {582 if ((res = select(conn->fd + 1, &fds, &wfds, NULL, &tv)) == -1) { 564 583 error = errno; 565 584 aim_conn_close(conn); … … 568 587 } else if (res == 0) { 569 588 return 0; /* hasn't really completed yet... */ 570 } 589 } 571 590 572 591 if (FD_ISSET(conn->fd, &fds) || FD_ISSET(conn->fd, &wfds)) { 573 592 socklen_t len = sizeof(error); 574 593 575 if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) 594 if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { 576 595 error = errno; 596 } 577 597 } 578 598 … … 587 607 conn->status &= ~AIM_CONN_STATUS_INPROGRESS; 588 608 589 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE))) 609 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE))) { 590 610 userfunc(sess, NULL, conn); 611 } 591 612 592 613 /* Flush out the queues if there was something waiting for this conn */ … … 599 620 { 600 621 601 if (!conn) 622 if (!conn) { 602 623 return NULL; 603 604 return (aim_session_t *)conn->sessv; 624 } 625 626 return (aim_session_t *) conn->sessv; 605 627 } 606 628 … … 624 646 * 625 647 * No-op. WinAIM 4.x sends these _every minute_ to keep 626 * the connection alive. 648 * the connection alive. 627 649 */ 628 650 int aim_flap_nop(aim_session_t *sess, aim_conn_t *conn) … … 630 652 aim_frame_t *fr; 631 653 632 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x05, 0))) 654 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x05, 0))) { 633 655 return -ENOMEM; 656 } 634 657 635 658 aim_tx_enqueue(sess, fr);
Note: See TracChangeset
for help on using the changeset viewer.