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