annotate libfaim/aim_conn.c @ 928:44f65bde9208

[gaim-migrate @ 938] Yo committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Mon, 18 Sep 2000 19:13:27 +0000
parents e1da6a6ec42b
children 5e6ca3dd4d02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 * aim_conn.c
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 * Does all this gloriously nifty connection handling stuff...
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8
283
0f14e6d8a51b [gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 281
diff changeset
9 #include <faim/aim.h>
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
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
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
17 /*
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
18 * Clears out connection list, killing remaining connections.
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
19 */
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
20 faim_internal void aim_connrst(struct aim_session_t *sess)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 {
715
58106806ac2b [gaim-migrate @ 725]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 711
diff changeset
22 faim_mutex_init(&sess->connlistlock);
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
23 if (sess->connlist) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
24 struct aim_conn_t *cur = sess->connlist, *tmp;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
25
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
26 while(cur) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
27 tmp = cur->next;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
28 aim_conn_close(cur);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
29 free(cur);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
30 cur = tmp;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
31 }
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
32 }
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
33 sess->connlist = NULL;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
34 return;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
37 /*
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
38 * Gets a new connection structure.
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
39 */
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
40 faim_internal struct aim_conn_t *aim_conn_getnext(struct aim_session_t *sess)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41 {
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
42 struct aim_conn_t *newconn, *cur;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
43
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
44 if (!(newconn = malloc(sizeof(struct aim_conn_t))))
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
45 return NULL;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
46
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
47 memset(newconn, 0, sizeof(struct aim_conn_t));
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
48 aim_conn_close(newconn);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
49 newconn->next = NULL;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
50
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
51 faim_mutex_lock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
52 if (sess->connlist == NULL)
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
53 sess->connlist = newconn;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
54 else {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
55 for (cur = sess->connlist; cur->next; cur = cur->next)
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
56 ;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
57 cur->next = newconn;
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_unlock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
60
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
61 return newconn;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
62 }
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
63
638
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
64 static void aim_conn_init(struct aim_conn_t *deadconn)
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
65 {
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
66 if (!deadconn)
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
67 return;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
68
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
69 deadconn->fd = -1;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
70 deadconn->subtype = -1;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
71 deadconn->type = -1;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
72 deadconn->seqnum = 0;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
73 deadconn->lastactivity = 0;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
74 deadconn->forcedlatency = 0;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
75 deadconn->handlerlist = NULL;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
76 deadconn->priv = NULL;
715
58106806ac2b [gaim-migrate @ 725]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 711
diff changeset
77 faim_mutex_init(&deadconn->active);
58106806ac2b [gaim-migrate @ 725]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 711
diff changeset
78 faim_mutex_init(&deadconn->seqnum_lock);
638
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
79
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
80 return;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
81 }
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
82
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
83 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
84 {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
85 struct aim_conn_t *cur;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
86
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
87 if (!deadconn || !*deadconn)
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
88 return;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
89
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
90 faim_mutex_lock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
91 if (sess->connlist == NULL)
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
92 ;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
93 else if (sess->connlist->next == NULL) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
94 if (sess->connlist == *deadconn)
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
95 sess->connlist = NULL;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
96 } else {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
97 cur = sess->connlist;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
98 while (cur->next) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
99 if (cur->next == *deadconn) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
100 cur->next = cur->next->next;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
101 break;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
102 }
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
103 cur = cur->next;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
104 }
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
105 }
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
106 faim_mutex_unlock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
107
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
108 /* XXX: do we need this for txqueue too? */
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
109 aim_rxqueue_cleanbyconn(sess, *deadconn);
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
110
711
b967d21d7482 [gaim-migrate @ 721]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 707
diff changeset
111 aim_conn_close(*deadconn);
b967d21d7482 [gaim-migrate @ 721]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 707
diff changeset
112 if ((*deadconn)->priv)
b967d21d7482 [gaim-migrate @ 721]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 707
diff changeset
113 free((*deadconn)->priv);
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
114 free(*deadconn);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
115 deadconn = NULL;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
116
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
117 return;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
118 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
120 faim_export void aim_conn_close(struct aim_conn_t *deadconn)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
121 {
638
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
122 int typesav = -1, subtypesav = -1;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
123 void *privsav = NULL;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
124
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
125 faim_mutex_destroy(&deadconn->active);
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
126 faim_mutex_destroy(&deadconn->seqnum_lock);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
127 if (deadconn->fd >= 3)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
128 close(deadconn->fd);
283
0f14e6d8a51b [gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 281
diff changeset
129 if (deadconn->handlerlist)
0f14e6d8a51b [gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 281
diff changeset
130 aim_clearhandlers(deadconn);
638
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
131
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
132 typesav = deadconn->type;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
133 subtypesav = deadconn->subtype;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
134
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
135 if (deadconn->priv && (deadconn->type != AIM_CONN_TYPE_RENDEZVOUS)) {
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
136 free(deadconn->priv);
638
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
137 deadconn->priv = NULL;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
138 }
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
139 privsav = deadconn->priv;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
140
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
141 aim_conn_init(deadconn);
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
142
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
143 deadconn->type = typesav;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
144 deadconn->subtype = subtypesav;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
145 deadconn->priv = privsav;
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
146
525c566741da [gaim-migrate @ 648]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 445
diff changeset
147 return;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
148 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
149
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
150 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
151 int type)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
152 {
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
153 struct aim_conn_t *cur;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
154
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
155 faim_mutex_lock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
156 for (cur = sess->connlist; cur; cur = cur->next) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
157 if (cur->type == type)
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
158 break;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
159 }
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
160 faim_mutex_unlock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
161 return cur;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
163
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
164 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165 * aim_newconn(type, dest)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
166 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
167 * Opens a new connection to the specified dest host of type type.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
168 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
169 * TODO: fix for proxies
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
170 * FIXME: Return errors in a more sane way.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
171 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
172 */
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
173 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
174 int type, char *dest)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
175 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
176 struct aim_conn_t *connstruct;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
177 int ret;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
178 struct sockaddr_in sa;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
179 struct hostent *hp;
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
180 u_short port = FAIM_LOGIN_PORT;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
181 char *host = NULL;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
182 int i=0;
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
183
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
184 if ((connstruct=aim_conn_getnext(sess))==NULL)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
185 return NULL;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
186
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
187 faim_mutex_lock(&connstruct->active);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
188
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
189 connstruct->type = type;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
190
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
191 if (!dest) { /* just allocate a struct */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
192 connstruct->fd = -1;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
193 connstruct->status = 0;
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
194 faim_mutex_unlock(&connstruct->active);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
195 return connstruct;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
196 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
197
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
198 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
199 * As of 23 Jul 1999, AOL now sends the port number, preceded by a
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
200 * colon, in the BOS redirect. This fatally breaks all previous
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
201 * libfaims. Bad, bad AOL.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
202 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
203 * We put this here to catch every case.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
204 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
205 */
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
206
889
e1da6a6ec42b [gaim-migrate @ 899]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 840
diff changeset
207 for(i=0;i<(int)strlen(dest);i++) {
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
208 if (dest[i] == ':') {
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
209 port = atoi(&(dest[i+1]));
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
210 break;
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
211 }
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
212 }
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
213 host = (char *)malloc(i+1);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
214 strncpy(host, dest, i);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
215 host[i] = '\0';
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
216
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
217 hp = gethostbyname(host);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
218 free(host);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
219
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
220 if (hp == NULL) {
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
221 connstruct->status = (h_errno | AIM_CONN_STATUS_RESOLVERR);
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
222 faim_mutex_unlock(&connstruct->active);
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
223 return connstruct;
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
224 }
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
225
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
226 memset(&sa.sin_zero, 0, 8);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
227 sa.sin_port = htons(port);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
228 memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
229 sa.sin_family = hp->h_addrtype;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
230
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
231 connstruct->fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
232 ret = connect(connstruct->fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in));
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
233 if(ret < 0) {
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
234 connstruct->fd = -1;
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
235 connstruct->status = (errno | AIM_CONN_STATUS_CONNERR);
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
236 faim_mutex_unlock(&connstruct->active);
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
237 return connstruct;
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
238 }
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
239
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
240 faim_mutex_unlock(&connstruct->active);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
241
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
242 return connstruct;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
243 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
244
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
245 faim_export int aim_conngetmaxfd(struct aim_session_t *sess)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
246 {
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
247 int j = 0;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
248 struct aim_conn_t *cur;
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
249
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
250 faim_mutex_lock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
251 for (cur = sess->connlist; cur; cur = cur->next) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
252 if (cur->fd > j)
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
253 j = cur->fd;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
254 }
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
255 faim_mutex_unlock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
256
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
257 return j;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
258 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
259
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
260 static int aim_countconn(struct aim_session_t *sess)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
261 {
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
262 int cnt = 0;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
263 struct aim_conn_t *cur;
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
264
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
265 faim_mutex_lock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
266 for (cur = sess->connlist; cur; cur = cur->next)
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
267 cnt++;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
268 faim_mutex_unlock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
269
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
270 return cnt;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
271 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
272
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
273 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
274 * aim_select(timeout)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
275 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
276 * Waits for a socket with data or for timeout, whichever comes first.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
277 * See select(2).
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
278 *
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
279 * Return codes in *status:
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
280 * -1 error in select() (NULL returned)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
281 * 0 no events pending (NULL returned)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
282 * 1 outgoing data pending (NULL returned)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
283 * 2 incoming data pending (connection with pending data returned)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
284 *
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
285 * 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
286 *
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
287 */
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
288 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
289 struct timeval *timeout, int *status)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
290 {
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
291 struct aim_conn_t *cur;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
292 fd_set fds;
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
293 int maxfd = 0;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
294 int i;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
295
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
296 faim_mutex_lock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
297 if (sess->connlist == NULL) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
298 faim_mutex_unlock(&sess->connlistlock);
445
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
299 *status = -1;
e4c34ca88d9b [gaim-migrate @ 455]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 338
diff changeset
300 return NULL;
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
301 }
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
302 faim_mutex_unlock(&sess->connlistlock);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
303
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
304 /*
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
305 * If we have data waiting to be sent, return immediatly
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
306 */
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
307 if (sess->queue_outgoing != NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
308 *status = 1;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
309 return NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
310 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
311
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
312 FD_ZERO(&fds);
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
313 maxfd = 0;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
314
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
315 faim_mutex_lock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
316 for (cur = sess->connlist; cur; cur = cur->next) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
317 FD_SET(cur->fd, &fds);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
318 if (cur->fd > maxfd)
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
319 maxfd = cur->fd;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
320 }
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
321 faim_mutex_unlock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
322
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
323 if ((i = select(maxfd+1, &fds, NULL, NULL, timeout))>=1) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
324 faim_mutex_lock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
325 for (cur = sess->connlist; cur; cur = cur->next) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
326 if (FD_ISSET(cur->fd, &fds)) {
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
327 *status = 2;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
328 faim_mutex_unlock(&sess->connlistlock);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
329 return cur;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
330 }
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
331 }
817
aefd5f2b1ea0 [gaim-migrate @ 827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 715
diff changeset
332 *status = 0; /* shouldn't happen */
aefd5f2b1ea0 [gaim-migrate @ 827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 715
diff changeset
333 } else if ((i == -1) && (errno == EINTR)) /* treat interrupts as a timeout */
aefd5f2b1ea0 [gaim-migrate @ 827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 715
diff changeset
334 *status = 0;
aefd5f2b1ea0 [gaim-migrate @ 827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 715
diff changeset
335 else
aefd5f2b1ea0 [gaim-migrate @ 827]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 715
diff changeset
336 *status = i; /* can be 0 or -1 */
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
337
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
338 faim_mutex_unlock(&sess->connlistlock);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
339 return NULL; /* no waiting or error, return */
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
340 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
341
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
342 faim_export int aim_conn_isready(struct aim_conn_t *conn)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
343 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
344 if (conn)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
345 return (conn->status & 0x0001);
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
346 return -1;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
347 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
348
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
349 faim_export int aim_conn_setstatus(struct aim_conn_t *conn, int status)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
350 {
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
351 int val;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
352
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
353 if (!conn)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
354 return -1;
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
355
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
356 faim_mutex_lock(&conn->active);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
357 val = conn->status ^= status;
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
358 faim_mutex_unlock(&conn->active);
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
359 return val;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
360 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
361
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
362 faim_export int aim_conn_setlatency(struct aim_conn_t *conn, int newval)
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
363 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
364 if (!conn)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
365 return -1;
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
366
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
367 faim_mutex_lock(&conn->active);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
368 conn->forcedlatency = newval;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
369 conn->lastactivity = 0; /* reset this just to make sure */
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
370 faim_mutex_unlock(&conn->active);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
371
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
372 return 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
373 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
374
840
595ac7759563 [gaim-migrate @ 850]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 817
diff changeset
375 faim_export void aim_session_init(struct aim_session_t *sess)
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
376 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
377 if (!sess)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
378 return;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
379
338
9d258a0aa560 [gaim-migrate @ 348]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 283
diff changeset
380 memset(sess, 0, sizeof(struct aim_session_t));
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
381 aim_connrst(sess);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
382 sess->queue_outgoing = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
383 sess->queue_incoming = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
384 sess->pendingjoin = NULL;
715
58106806ac2b [gaim-migrate @ 725]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 711
diff changeset
385 aim_initsnachash(sess);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
386 sess->snac_nextid = 0x00000001;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
387
279
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
388 /*
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
389 * This must always be set. Default to the queue-based
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
390 * version for back-compatibility.
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
391 */
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
392 sess->tx_enqueue = &aim_tx_enqueue__queuebased;
501e09c51cbc [gaim-migrate @ 289]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
393
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
394 return;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
395 }