comparison src/protocols/oscar/conn.c @ 11154:0d58a17095db

[gaim-migrate @ 13236] Remove aim_setupproxy and aim_select. These functions weren't called from anywhere by us. I've given up on making sure libfaim is useful as a library outside of Gaim. If you're writing an IM client.. why not just use the Gaim core? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 24 Jul 2005 19:45:59 +0000
parents ba630d7a7365
children ccb38cf22483
comparison
equal deleted inserted replaced
11153:8e600ee6ec61 11154:0d58a17095db
393 393
394 return cur; 394 return cur;
395 } 395 }
396 396
397 /** 397 /**
398 * Handle normal connections or SOCKS5 via an extrememly quick and 398 * Handle normal connections or SOCKS5 via an extrememly quick and
399 * dirty SOCKS5 interface. 399 * dirty SOCKS5 interface.
400 * 400 *
401 * Attempts to connect to the specified host via the configured 401 * Attempts to connect to the specified host via the configured
402 * proxy settings, if present. If no proxy is configured for 402 * proxy settings, if present. If no proxy is configured for
403 * this session, the connection is done directly. 403 * this session, the connection is done directly.
404 * 404 *
637 connstruct->fd = -1; 637 connstruct->fd = -1;
638 connstruct->status = 0; 638 connstruct->status = 0;
639 return connstruct; 639 return connstruct;
640 } 640 }
641 641
642 /* 642 /*
643 * As of 23 Jul 1999, AOL now sends the port number, preceded by a 643 * As of 23 Jul 1999, AOL now sends the port number, preceded by a
644 * colon, in the BOS redirect. This fatally breaks all previous 644 * colon, in the BOS redirect. This fatally breaks all previous
645 * libfaims. Bad, bad AOL. 645 * libfaims. Bad, bad AOL.
646 * 646 *
647 * We put this here to catch every case. 647 * We put this here to catch every case.
648 * 648 *
649 */ 649 */
650 650
651 for(i = 0; i < (int)strlen(dest); i++) { 651 for(i = 0; i < (int)strlen(dest); i++) {
652 if (dest[i] == ':') { 652 if (dest[i] == ':') {
690 690
691 return 0; 691 return 0;
692 } 692 }
693 693
694 /** 694 /**
695 * Waits for a socket with data or for timeout, whichever comes first. 695 * Set a forced latency value for connection. Basically causes
696 * See select(2).
697 *
698 * Return codes in *status:
699 * -1 error in select() (%NULL returned)
700 * 0 no events pending (%NULL returned)
701 * 1 outgoing data pending (%NULL returned)
702 * 2 incoming data pending (connection with pending data returned)
703 *
704 * @param sess Session to wait on
705 * @param timeout How long to wait
706 * @param status Return status
707 * @return If @status is 2, returns connection with pending data, otherwise %NULL
708 */
709 faim_export aim_conn_t *aim_select(aim_session_t *sess, struct timeval *timeout, int *status)
710 {
711 aim_conn_t *cur;
712 fd_set fds, wfds;
713 int maxfd, i, haveconnecting = 0;
714
715 if (!sess->connlist) {
716 *status = -1;
717 return NULL;
718 }
719
720 FD_ZERO(&fds);
721 FD_ZERO(&wfds);
722
723 for (cur = sess->connlist, maxfd = 0; cur; cur = cur->next) {
724 if (cur->fd == -1) {
725 /* don't let invalid/dead connections sit around */
726 *status = 2;
727 return cur;
728 } else if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
729 FD_SET(cur->fd, &wfds);
730
731 haveconnecting++;
732 }
733 FD_SET(cur->fd, &fds);
734 if (cur->fd > maxfd)
735 maxfd = cur->fd;
736 }
737
738 /*
739 * If we have data waiting to be sent, return
740 *
741 * We have to not do this if theres at least one
742 * connection thats still connecting, since that connection
743 * may have queued data and this return would prevent
744 * the connection from ever completing! This is a major
745 * inadequacy of the libfaim way of doing things. It means
746 * that nothing can transmit as long as there's connecting
747 * sockets. Evil.
748 *
749 * But its still better than having blocking connects.
750 *
751 */
752 if (!haveconnecting && sess->queue_outgoing) {
753 *status = 1;
754 return NULL;
755 }
756
757 if ((i = select(maxfd+1, &fds, &wfds, NULL, timeout))>=1) {
758 for (cur = sess->connlist; cur; cur = cur->next) {
759 if ((FD_ISSET(cur->fd, &fds)) ||
760 ((cur->status & AIM_CONN_STATUS_INPROGRESS) &&
761 FD_ISSET(cur->fd, &wfds))) {
762 *status = 2;
763 return cur;
764 }
765 }
766 *status = 0; /* shouldn't happen */
767 } else if ((i == -1) && (errno == EINTR)) /* treat interrupts as a timeout */
768 *status = 0;
769 else
770 *status = i; /* can be 0 or -1 */
771
772 return NULL; /* no waiting or error, return */
773 }
774
775 /**
776 * Set a forced latency value for connection. Basically causes
777 * @newval seconds to be spent between transmits on a connection. 696 * @newval seconds to be spent between transmits on a connection.
778 * 697 *
779 * This is my lame attempt at overcoming not understanding the rate 698 * This is my lame attempt at overcoming not understanding the rate
780 * limiting. 699 * limiting.
781 * 700 *
782 * XXX: This should really be replaced with something that scales and 701 * XXX: This should really be replaced with something that scales and
783 * backs off like the real rate limiting does. 702 * backs off like the real rate limiting does.
784 * 703 *
785 * @param conn Conn to set latency for. 704 * @param conn Conn to set latency for.
794 713
795 conn->forcedlatency = newval; 714 conn->forcedlatency = newval;
796 conn->lastactivity = 0; /* reset this just to make sure */ 715 conn->lastactivity = 0; /* reset this just to make sure */
797 716
798 return 0; 717 return 0;
799 }
800
801 /**
802 * Configure a proxy for this session.
803 *
804 * Call this with your SOCKS5 proxy server parameters before
805 * the first call to aim_newconn(). If called with all %NULL
806 * args, it will clear out a previously set proxy.
807 *
808 * Set username and password to %NULL if not applicable.
809 *
810 * @param sess Session to set proxy for.
811 * @param server SOCKS server.
812 * @param username SOCKS username.
813 * @param password SOCKS password.
814 */
815 faim_export void aim_setupproxy(aim_session_t *sess, const char *server, const char *username, const char *password)
816 {
817 /* clear out the proxy info */
818 if (!server || !strlen(server)) {
819 memset(sess->socksproxy.server, 0, sizeof(sess->socksproxy.server));
820 memset(sess->socksproxy.username, 0, sizeof(sess->socksproxy.username));
821 memset(sess->socksproxy.password, 0, sizeof(sess->socksproxy.password));
822 return;
823 }
824
825 strncpy(sess->socksproxy.server, server, sizeof(sess->socksproxy.server));
826 if (username && strlen(username))
827 strncpy(sess->socksproxy.username, username, sizeof(sess->socksproxy.username));
828 if (password && strlen(password))
829 strncpy(sess->socksproxy.password, password, sizeof(sess->socksproxy.password));
830
831 return;
832 } 718 }
833 719
834 static void defaultdebugcb(aim_session_t *sess, int level, const char *format, va_list va) 720 static void defaultdebugcb(aim_session_t *sess, int level, const char *format, va_list va)
835 { 721 {
836 722