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