annotate libfaim/conn.c @ 1766:a247305b835f

[gaim-migrate @ 1776] well, that didn't work. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Fri, 27 Apr 2001 23:49:00 +0000
parents 3fe5799b7823
children 109cacf1ff97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1535
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 /*
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 * aim_conn.c
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 * Does all this gloriously nifty connection handling stuff...
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 #define FAIM_INTERNAL
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 #include <aim.h>
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 #ifndef _WIN32
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 #include <netdb.h>
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 #include <sys/socket.h>
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 #include <netinet/in.h>
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 #endif
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 * aim_connrst - Clears out connection list, killing remaining connections.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 * @sess: Session to be cleared
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 * Clears out the connection list and kills any connections left.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 faim_internal void aim_connrst(struct aim_session_t *sess)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 faim_mutex_init(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 if (sess->connlist) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 struct aim_conn_t *cur = sess->connlist, *tmp;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 while(cur) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 tmp = cur->next;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 aim_conn_close(cur);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 free(cur);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 cur = tmp;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 sess->connlist = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 * aim_conn_init - Reset a connection to default values.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 * @deadconn: Connection to be reset
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 * Initializes and/or resets a connection structure.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 static void aim_conn_init(struct aim_conn_t *deadconn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 if (!deadconn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 deadconn->fd = -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 deadconn->subtype = -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 deadconn->type = -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 deadconn->seqnum = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 deadconn->lastactivity = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 deadconn->forcedlatency = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 deadconn->handlerlist = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 deadconn->priv = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 faim_mutex_init(&deadconn->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 faim_mutex_init(&deadconn->seqnum_lock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 * aim_conn_getnext - Gets a new connection structure.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 * @sess: Session
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 * Allocate a new empty connection structure.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 faim_internal struct aim_conn_t *aim_conn_getnext(struct aim_session_t *sess)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 struct aim_conn_t *newconn, *cur;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 if (!(newconn = malloc(sizeof(struct aim_conn_t))))
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 return NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 memset(newconn, 0, sizeof(struct aim_conn_t));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 aim_conn_init(newconn);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 newconn->next = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 faim_mutex_lock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 if (sess->connlist == NULL)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 sess->connlist = newconn;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 else {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90 for (cur = sess->connlist; cur->next; cur = cur->next)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 ;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 cur->next = newconn;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 return newconn;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 * aim_conn_kill - Close and free a connection.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 * @sess: Session for the connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 * @deadconn: Connection to be freed
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 * Close, clear, and free a connection structure. Should never be
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 * called from within libfaim.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 faim_export void aim_conn_kill(struct aim_session_t *sess, struct aim_conn_t **deadconn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 struct aim_conn_t *cur;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 if (!deadconn || !*deadconn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114
1593
ec31e23aadc7 [gaim-migrate @ 1603]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1535
diff changeset
115 aim_tx_cleanqueue(sess, *deadconn);
ec31e23aadc7 [gaim-migrate @ 1603]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1535
diff changeset
116
1535
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 faim_mutex_lock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118 if (sess->connlist == NULL)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 ;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 else if (sess->connlist->next == NULL) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 if (sess->connlist == *deadconn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 sess->connlist = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123 } else {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 cur = sess->connlist;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 while (cur->next) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 if (cur->next == *deadconn) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 cur->next = cur->next->next;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 break;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 cur = cur->next;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 /* XXX: do we need this for txqueue too? */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 aim_rxqueue_cleanbyconn(sess, *deadconn);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138 if ((*deadconn)->fd != -1)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 aim_conn_close(*deadconn);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 if ((*deadconn)->priv)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141 free((*deadconn)->priv);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 free(*deadconn);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 deadconn = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149 * aim_conn_close - Close a connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 * @deadconn: Connection to close
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 * Close (but not free) a connection.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154 * This leaves everything untouched except for clearing the
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 * handler list and setting the fd to -1 (used to recognize
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 * dead connections).
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 faim_export void aim_conn_close(struct aim_conn_t *deadconn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 faim_mutex_destroy(&deadconn->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 faim_mutex_destroy(&deadconn->seqnum_lock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 if (deadconn->fd >= 3)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165 close(deadconn->fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 deadconn->fd = -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 if (deadconn->handlerlist)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168 aim_clearhandlers(deadconn);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 * aim_getconn_type - Find a connection of a specific type
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 * @sess: Session to search
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 * @type: Type of connection to look for
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 * Searches for a connection of the specified type in the
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179 * specified session. Returns the first connection of that
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 * type found.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 faim_export struct aim_conn_t *aim_getconn_type(struct aim_session_t *sess,
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 int type)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 struct aim_conn_t *cur;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 faim_mutex_lock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 for (cur = sess->connlist; cur; cur = cur->next) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 if ((cur->type == type) && !(cur->status & AIM_CONN_STATUS_INPROGRESS))
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 break;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 return cur;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198 * aim_proxyconnect - An extrememly quick and dirty SOCKS5 interface.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199 * @sess: Session to connect
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200 * @host: Host to connect to
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 * @port: Port to connect to
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202 * @statusret: Return value of the connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 * Attempts to connect to the specified host via the configured
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 * proxy settings, if present. If no proxy is configured for
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206 * this session, the connection is done directly.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209 static int aim_proxyconnect(struct aim_session_t *sess,
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 char *host, unsigned short port,
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 int *statusret)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 int fd = -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215 if (strlen(sess->socksproxy.server)) { /* connecting via proxy */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
216 int i;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217 unsigned char buf[512];
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218 struct sockaddr_in sa;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
219 struct hostent *hp;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
220 char *proxy;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
221 unsigned short proxyport = 1080;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
223 for(i=0;i<(int)strlen(sess->socksproxy.server);i++) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
224 if (sess->socksproxy.server[i] == ':') {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225 proxyport = atoi(&(sess->socksproxy.server[i+1]));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
226 break;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
227 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
228 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229 proxy = (char *)malloc(i+1);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230 strncpy(proxy, sess->socksproxy.server, i);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
231 proxy[i] = '\0';
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
232
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
233 if (!(hp = gethostbyname(proxy))) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
234 faimdprintf(sess, 0, "proxyconnect: unable to resolve proxy name\n");
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235 *statusret = (h_errno | AIM_CONN_STATUS_RESOLVERR);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238 free(proxy);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 memset(&sa.sin_zero, 0, 8);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 sa.sin_port = htons(proxyport);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243 sa.sin_family = hp->h_addrtype;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
246 if (connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247 faimdprintf(sess, 0, "proxyconnect: unable to connect to proxy\n");
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
248 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
251
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
252 i = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
253 buf[0] = 0x05; /* SOCKS version 5 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
254 if (strlen(sess->socksproxy.username)) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255 buf[1] = 0x02; /* two methods */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
256 buf[2] = 0x00; /* no authentication */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257 buf[3] = 0x02; /* username/password authentication */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
258 i = 4;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
259 } else {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
260 buf[1] = 0x01;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261 buf[2] = 0x00;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
262 i = 3;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
263 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
264
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
265 if (write(fd, buf, i) < i) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
266 *statusret = errno;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
268 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
269 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
270
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
271 if (read(fd, buf, 2) < 2) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
272 *statusret = errno;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
273 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
274 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
275 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
277 if ((buf[0] != 0x05) || (buf[1] == 0xff)) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
278 *statusret = EINVAL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
279 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
280 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
281 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
282
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
283 /* check if we're doing username authentication */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284 if (buf[1] == 0x02) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
285 i = aimutil_put8(buf, 0x01); /* version 1 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
286 i += aimutil_put8(buf+i, strlen(sess->socksproxy.username));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
287 i += aimutil_putstr(buf+i, sess->socksproxy.username, strlen(sess->socksproxy.username));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
288 i += aimutil_put8(buf+i, strlen(sess->socksproxy.password));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
289 i += aimutil_putstr(buf+i, sess->socksproxy.password, strlen(sess->socksproxy.password));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
290 if (write(fd, buf, i) < i) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
291 *statusret = errno;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
292 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
293 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
294 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
295 if (read(fd, buf, 2) < 2) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
296 *statusret = errno;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
297 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
298 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
299 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
300 if ((buf[0] != 0x01) || (buf[1] != 0x00)) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
301 *statusret = EINVAL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
307 i = aimutil_put8(buf, 0x05);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
308 i += aimutil_put8(buf+i, 0x01); /* CONNECT */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
309 i += aimutil_put8(buf+i, 0x00); /* reserved */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
310 i += aimutil_put8(buf+i, 0x03); /* address type: host name */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311 i += aimutil_put8(buf+i, strlen(host));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
312 i += aimutil_putstr(buf+i, host, strlen(host));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313 i += aimutil_put16(buf+i, port);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
314
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
315 if (write(fd, buf, i) < i) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316 *statusret = errno;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
317 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
318 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
319 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
320 if (read(fd, buf, 10) < 10) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
321 *statusret = errno;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
322 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
323 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
324 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
325 if ((buf[0] != 0x05) || (buf[1] != 0x00)) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
326 *statusret = EINVAL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
327 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
329 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
330
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
331 } else { /* connecting directly */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
332 struct sockaddr_in sa;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
333 struct hostent *hp;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
335 if (!(hp = gethostbyname(host))) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
336 *statusret = (h_errno | AIM_CONN_STATUS_RESOLVERR);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
337 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
338 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
340 memset(&sa, 0, sizeof(struct sockaddr_in));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
341 sa.sin_port = htons(port);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342 memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
343 sa.sin_family = hp->h_addrtype;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
344
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
345 fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
346
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
347 if (sess->flags & AIM_SESS_FLAGS_NONBLOCKCONNECT)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
348 fcntl(fd, F_SETFL, O_NONBLOCK); /* XXX save flags */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
349
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
350 if (connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
351 if (sess->flags & AIM_SESS_FLAGS_NONBLOCKCONNECT) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
352 if ((errno == EINPROGRESS) || (errno == EINTR)) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
353 if (statusret)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
354 *statusret |= AIM_CONN_STATUS_INPROGRESS;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
355 return fd;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
356 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
357 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
358 close(fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
359 fd = -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
360 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
361 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
362 return fd;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
363 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
364
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
365 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
366 * aim_cloneconn - clone an aim_conn_t
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
367 * @sess: session containing parent
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
368 * @src: connection to clone
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
369 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
370 * A new connection is allocated, and the values are filled in
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
371 * appropriately. Note that this function sets the new connnection's
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
372 * ->priv pointer to be equal to that of its parent: only the pointer
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
373 * is copied, not the data it points to.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
374 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
375 * This function returns a pointer to the new aim_conn_t, or %NULL on
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
376 * error
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
377 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
378 faim_internal struct aim_conn_t *aim_cloneconn(struct aim_session_t *sess,
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
379 struct aim_conn_t *src)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
380 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
381 struct aim_conn_t *conn;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
382 struct aim_rxcblist_t *cur;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
383
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
384 if (!(conn = aim_conn_getnext(sess)))
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
385 return NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
386
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
387 faim_mutex_lock(&conn->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
388
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
389 conn->fd = src->fd;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
390 conn->type = src->type;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
391 conn->subtype = src->subtype;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
392 conn->seqnum = src->seqnum;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
393 conn->priv = src->priv;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
394 conn->lastactivity = src->lastactivity;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
395 conn->forcedlatency = src->forcedlatency;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
396
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
397 /* clone handler list */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
398 for (cur = src->handlerlist; cur; cur = cur->next) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
399 aim_conn_addhandler(sess, conn, cur->family, cur->type,
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
400 cur->handler, cur->flags);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
401 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
402
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
403 faim_mutex_unlock(&conn->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
404
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
405 return conn;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
406 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
407
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
408 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
409 * aim_newconn - Open a new connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
410 * @sess: Session to create connection in
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
411 * @type: Type of connection to create
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
412 * @dest: Host to connect to (in "host:port" syntax)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
413 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
414 * Opens a new connection to the specified dest host of specified
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
415 * type, using the proxy settings if available. If @host is %NULL,
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
416 * the connection is allocated and returned, but no connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417 * is made.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
418 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
419 * FIXME: Return errors in a more sane way.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
420 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
421 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
422 faim_export struct aim_conn_t *aim_newconn(struct aim_session_t *sess,
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
423 int type, char *dest)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
424 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
425 struct aim_conn_t *connstruct;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
426 int ret;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
427 u_short port = FAIM_LOGIN_PORT;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
428 char *host = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
429 int i=0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
430
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
431 if ((connstruct=aim_conn_getnext(sess))==NULL)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
432 return NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
433
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
434 faim_mutex_lock(&connstruct->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
435
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
436 connstruct->type = type;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
437
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
438 if (!dest) { /* just allocate a struct */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
439 connstruct->fd = -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
440 connstruct->status = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
441 faim_mutex_unlock(&connstruct->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
442 return connstruct;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
443 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
444
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
445 /*
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
446 * As of 23 Jul 1999, AOL now sends the port number, preceded by a
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
447 * colon, in the BOS redirect. This fatally breaks all previous
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
448 * libfaims. Bad, bad AOL.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
449 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
450 * We put this here to catch every case.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
451 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
452 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
453
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
454 for(i=0;i<(int)strlen(dest);i++) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
455 if (dest[i] == ':') {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
456 port = atoi(&(dest[i+1]));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
457 break;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
458 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
459 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
460 host = (char *)malloc(i+1);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461 strncpy(host, dest, i);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462 host[i] = '\0';
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
463
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464 if ((ret = aim_proxyconnect(sess, host, port, &connstruct->status)) < 0) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
465 connstruct->fd = -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 connstruct->status = (errno | AIM_CONN_STATUS_CONNERR);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 free(host);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
468 faim_mutex_unlock(&connstruct->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
469 return connstruct;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
470 } else
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
471 connstruct->fd = ret;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
472
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
473 faim_mutex_unlock(&connstruct->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
474
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
475 free(host);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
476
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
477 return connstruct;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
478 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
479
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
480 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
481 * aim_conngetmaxfd - Return the highest valued file discriptor in session
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
482 * @sess: Session to search
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
483 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
484 * Returns the highest valued filed descriptor of all open
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
485 * connections in @sess.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
486 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
487 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
488 faim_export int aim_conngetmaxfd(struct aim_session_t *sess)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
489 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
490 int j = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
491 struct aim_conn_t *cur;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
492
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
493 faim_mutex_lock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
494 for (cur = sess->connlist; cur; cur = cur->next) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
495 if (cur->fd > j)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
496 j = cur->fd;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
497 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
498 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
499
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
500 return j;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
501 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
502
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
503 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
504 * aim_conn_in_sess - Predicate to test the precense of a connection in a sess
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
505 * @sess: Session to look in
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
506 * @conn: Connection to look for
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
507 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
508 * Searches @sess for the passed connection. Returns 1 if its present,
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
509 * zero otherwise.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
510 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
511 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
512 faim_export int aim_conn_in_sess(struct aim_session_t *sess, struct aim_conn_t *conn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
513 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
514 struct aim_conn_t *cur;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
515
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
516 faim_mutex_lock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
517 for(cur = sess->connlist; cur; cur = cur->next)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
518 if(cur == conn) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
519 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
520 return 1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
521 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
522 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
523 return 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
524 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
525
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
526 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
527 * aim_select - Wait for a socket with data or timeout
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
528 * @sess: Session to wait on
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
529 * @timeout: How long to wait
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
530 * @status: Return status
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
531 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
532 * Waits for a socket with data or for timeout, whichever comes first.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
533 * See select(2).
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
534 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
535 * Return codes in *status:
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
536 * -1 error in select() (%NULL returned)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
537 * 0 no events pending (%NULL returned)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
538 * 1 outgoing data pending (%NULL returned)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
539 * 2 incoming data pending (connection with pending data returned)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
540 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
541 * XXX: we could probably stand to do a little courser locking here.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
542 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
543 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
544 faim_export struct aim_conn_t *aim_select(struct aim_session_t *sess,
1593
ec31e23aadc7 [gaim-migrate @ 1603]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1535
diff changeset
545 struct timeval *timeout,
ec31e23aadc7 [gaim-migrate @ 1603]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1535
diff changeset
546 int *status)
1535
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
547 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
548 struct aim_conn_t *cur;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
549 fd_set fds, wfds;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
550 int maxfd = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
551 int i, haveconnecting = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
552
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
553 faim_mutex_lock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
554 if (sess->connlist == NULL) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
555 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
556 *status = -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
557 return NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
558 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
559 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
560
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
561 FD_ZERO(&fds);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
562 FD_ZERO(&wfds);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
563 maxfd = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
564
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
565 faim_mutex_lock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
566 for (cur = sess->connlist; cur; cur = cur->next) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
567 if (cur->fd == -1) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
568 /* don't let invalid/dead connections sit around */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
569 *status = 2;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
570 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
571 return cur;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
572 } else if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
573 FD_SET(cur->fd, &wfds);
1593
ec31e23aadc7 [gaim-migrate @ 1603]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1535
diff changeset
574
1535
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
575 haveconnecting++;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
576 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
577 FD_SET(cur->fd, &fds);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
578 if (cur->fd > maxfd)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
579 maxfd = cur->fd;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
580 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
581 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
582
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
583 /*
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
584 * If we have data waiting to be sent, return
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
585 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
586 * We have to not do this if theres at least one
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
587 * connection thats still connecting, since that connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
588 * may have queued data and this return would prevent
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
589 * the connection from ever completing! This is a major
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
590 * inadequacy of the libfaim way of doing things. It means
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
591 * that nothing can transmit as long as there's connecting
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
592 * sockets. Evil.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
593 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
594 * But its still better than having blocking connects.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
595 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
596 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
597 if (!haveconnecting && (sess->queue_outgoing != NULL)) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
598 *status = 1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
599 return NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
600 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
601
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
602 if ((i = select(maxfd+1, &fds, &wfds, NULL, timeout))>=1) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
603 faim_mutex_lock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
604 for (cur = sess->connlist; cur; cur = cur->next) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
605 if ((FD_ISSET(cur->fd, &fds)) ||
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
606 ((cur->status & AIM_CONN_STATUS_INPROGRESS) &&
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
607 FD_ISSET(cur->fd, &wfds))) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
608 *status = 2;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
609 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
610 return cur; /* XXX race condition here -- shouldnt unlock connlist */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
611 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
612 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
613 *status = 0; /* shouldn't happen */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
614 } else if ((i == -1) && (errno == EINTR)) /* treat interrupts as a timeout */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
615 *status = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
616 else
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
617 *status = i; /* can be 0 or -1 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
618
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
619 faim_mutex_unlock(&sess->connlistlock);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
620
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
621 return NULL; /* no waiting or error, return */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
622 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
623
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
624 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
625 * aim_conn_isready - Test if a connection is marked ready
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
626 * @conn: Connection to test
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
627 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
628 * Returns true if the connection is ready, false otherwise.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
629 * Returns -1 if the connection is invalid.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
630 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
631 * XXX: This is deprecated.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
632 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
633 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
634 faim_export int aim_conn_isready(struct aim_conn_t *conn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
635 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
636 if (conn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
637 return (conn->status & 0x0001);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
638 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
639 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
640
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
641 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
642 * aim_conn_setstatus - Set the status of a connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
643 * @conn: Connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
644 * @status: New status
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
645 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
646 * @newstatus is %XOR'd with the previous value of the connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
647 * status and returned. Returns -1 if the connection is invalid.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
648 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
649 * This isn't real useful.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
650 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
651 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
652 faim_export int aim_conn_setstatus(struct aim_conn_t *conn, int status)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
653 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
654 int val;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
655
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
656 if (!conn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
657 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
658
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
659 faim_mutex_lock(&conn->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
660 val = conn->status ^= status;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
661 faim_mutex_unlock(&conn->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
662
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
663 return val;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
664 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
665
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
666 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
667 * aim_conn_setlatency - Set a forced latency value for connection
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
668 * @conn: Conn to set latency for
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
669 * @newval: Number of seconds to force between transmits
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
670 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
671 * Causes @newval seconds to be spent between transmits on a connection.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
672 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
673 * This is my lame attempt at overcoming not understanding the rate
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
674 * limiting.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
675 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
676 * XXX: This should really be replaced with something that scales and
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
677 * backs off like the real rate limiting does.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
678 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
679 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
680 faim_export int aim_conn_setlatency(struct aim_conn_t *conn, int newval)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
681 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
682 if (!conn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
683 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
684
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
685 faim_mutex_lock(&conn->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
686 conn->forcedlatency = newval;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
687 conn->lastactivity = 0; /* reset this just to make sure */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
688 faim_mutex_unlock(&conn->active);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
689
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
690 return 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
691 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
692
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
693 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
694 * aim_setupproxy - Configure a proxy for this session
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
695 * @sess: Session to set proxy for
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
696 * @server: SOCKS server
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
697 * @username: SOCKS username
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
698 * @password: SOCKS password
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
699 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
700 * Call this with your SOCKS5 proxy server parameters before
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
701 * the first call to aim_newconn(). If called with all %NULL
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
702 * args, it will clear out a previously set proxy.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
703 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
704 * Set username and password to %NULL if not applicable.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
705 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
706 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
707 faim_export void aim_setupproxy(struct aim_session_t *sess, char *server, char *username, char *password)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
708 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
709 /* clear out the proxy info */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
710 if (!server || !strlen(server)) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
711 memset(sess->socksproxy.server, 0, sizeof(sess->socksproxy.server));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
712 memset(sess->socksproxy.username, 0, sizeof(sess->socksproxy.username));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
713 memset(sess->socksproxy.password, 0, sizeof(sess->socksproxy.password));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
714 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
715 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
716
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
717 strncpy(sess->socksproxy.server, server, sizeof(sess->socksproxy.server));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
718 if (username && strlen(username))
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
719 strncpy(sess->socksproxy.username, username, sizeof(sess->socksproxy.username));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
720 if (password && strlen(password))
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
721 strncpy(sess->socksproxy.password, password, sizeof(sess->socksproxy.password));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
722 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
723 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
724
1649
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
725 static void defaultdebugcb(struct aim_session_t *sess, int level, const char *format, va_list va)
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
726 {
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
727 vfprintf(stderr, format, va);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
728 }
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
729
1535
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
730 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
731 * aim_session_init - Initializes a session structure
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
732 * @sess: Session to initialize
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
733 * @flags: Flags to use. Any of %AIM_SESS_FLAGS %OR'd together.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
734 * @debuglevel: Level of debugging output (zero is least)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
735 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
736 * Sets up the initial values for a session.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
737 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
738 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
739 faim_export void aim_session_init(struct aim_session_t *sess, unsigned long flags, int debuglevel)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
740 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
741 if (!sess)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
742 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
743
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
744 memset(sess, 0, sizeof(struct aim_session_t));
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
745 aim_connrst(sess);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
746 sess->queue_outgoing = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
747 sess->queue_incoming = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
748 sess->pendingjoin = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
749 sess->pendingjoinexchange = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
750 aim_initsnachash(sess);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
751 sess->msgcookies = NULL;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
752 sess->snac_nextid = 0x00000001;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
753
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
754 sess->flags = 0;
1649
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
755 sess->debug = debuglevel;
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
756 sess->debugcb = defaultdebugcb;
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
757
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
758 sess->modlistv = NULL;
1535
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
759
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
760 /*
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
761 * Default to SNAC login unless XORLOGIN is explicitly set.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
762 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
763 if (!(flags & AIM_SESS_FLAGS_XORLOGIN))
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
764 sess->flags |= AIM_SESS_FLAGS_SNACLOGIN;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
765 sess->flags |= flags;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
766
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
767 /*
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
768 * This must always be set. Default to the queue-based
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
769 * version for back-compatibility.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
770 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
771 aim_tx_setenqueue(sess, AIM_TX_QUEUED, NULL);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
772
1649
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
773
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
774 /*
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
775 * Register all the modules for this session...
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
776 */
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
777 aim__registermodule(sess, misc_modfirst); /* load the catch-all first */
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
778 aim__registermodule(sess, buddylist_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
779 aim__registermodule(sess, admin_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
780 aim__registermodule(sess, bos_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
781 aim__registermodule(sess, search_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
782 aim__registermodule(sess, stats_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
783 aim__registermodule(sess, auth_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
784 aim__registermodule(sess, msg_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
785 aim__registermodule(sess, chatnav_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
786 aim__registermodule(sess, chat_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
787 aim__registermodule(sess, locate_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
788 aim__registermodule(sess, general_modfirst);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
789
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
790 return;
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
791 }
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
792
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
793 /**
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
794 * aim_session_kill - Deallocate a session
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
795 * @sess: Session to kill
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
796 *
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
797 *
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
798 */
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
799 faim_export void aim_session_kill(struct aim_session_t *sess)
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
800 {
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
801
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
802 aim_logoff(sess);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
803
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
804 aim__shutdownmodules(sess);
3fe5799b7823 [gaim-migrate @ 1659]
Adam Fritzler <mid@auk.cx>
parents: 1593
diff changeset
805
1535
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
806 return;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
807 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
808
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
809 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
810 * aim_setdebuggingcb - Set the function to call when outputting debugging info
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
811 * @sess: Session to change
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
812 * @cb: Function to call
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
813 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
814 * The function specified is called whenever faimdprintf() is used within
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
815 * libfaim, and the session's debugging level is greater tha nor equal to
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
816 * the value faimdprintf was called with.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
817 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
818 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
819 faim_export int aim_setdebuggingcb(struct aim_session_t *sess, faim_debugging_callback_t cb)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
820 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
821
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
822 if (!sess)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
823 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
824
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
825 sess->debugcb = cb;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
826
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
827 return 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
828 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
829
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
830 /**
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
831 * aim_conn_isconnecting - Determine if a connection is connecting
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
832 * @conn: Connection to examine
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
833 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
834 * Returns nonzero if the connection is in the process of
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
835 * connecting (or if it just completed and aim_conn_completeconnect()
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
836 * has yet to be called on it).
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
837 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
838 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
839 faim_export int aim_conn_isconnecting(struct aim_conn_t *conn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
840 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
841 if (!conn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
842 return 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
843 return (conn->status & AIM_CONN_STATUS_INPROGRESS)?1:0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
844 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
845
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
846 faim_export int aim_conn_completeconnect(struct aim_session_t *sess, struct aim_conn_t *conn)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
847 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
848 fd_set fds, wfds;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
849 struct timeval tv;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
850 int res, error = ETIMEDOUT;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
851 rxcallback_t userfunc;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
852
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
853 if (!conn || (conn->fd == -1))
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
854 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
855
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
856 if (!(conn->status & AIM_CONN_STATUS_INPROGRESS))
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
857 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
858
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
859 FD_ZERO(&fds);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
860 FD_SET(conn->fd, &fds);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
861 FD_ZERO(&wfds);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
862 FD_SET(conn->fd, &wfds);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
863 tv.tv_sec = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
864 tv.tv_usec = 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
865
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
866 if ((res = select(conn->fd+1, &fds, &wfds, NULL, &tv)) == -1) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
867 error = errno;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
868 aim_conn_close(conn);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
869 errno = error;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
870 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
871 } else if (res == 0) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
872 faimdprintf(sess, 0, "aim_conn_completeconnect: false alarm on %d\n", conn->fd);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
873 return 0; /* hasn't really completed yet... */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
874 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
875
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
876 if (FD_ISSET(conn->fd, &fds) || FD_ISSET(conn->fd, &wfds)) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
877 int len = sizeof(error);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
878
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
879 if (getsockopt(conn->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
880 error = errno;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
881 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
882
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
883 if (error) {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
884 aim_conn_close(conn);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
885 errno = error;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
886 return -1;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
887 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
888
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
889 fcntl(conn->fd, F_SETFL, 0); /* XXX should restore original flags */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
890
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
891 conn->status &= ~AIM_CONN_STATUS_INPROGRESS;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
892
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
893 if ((userfunc = aim_callhandler(sess, conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE)))
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
894 userfunc(sess, NULL, conn);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
895
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
896 /* Flush out the queues if there was something waiting for this conn */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
897 aim_tx_flushqueue(sess);
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
898
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
899 return 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
900 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
901
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
902 /*
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
903 * aim_logoff()
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
904 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
905 * Closes -ALL- open connections.
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
906 *
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
907 */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
908 faim_export int aim_logoff(struct aim_session_t *sess)
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
909 {
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
910
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
911 aim_connrst(sess); /* in case we want to connect again */
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
912
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
913 return 0;
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
914
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
915 }
1e2cc8c8bf3c [gaim-migrate @ 1545]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
916