annotate libfaim/aim_conn.c @ 846:4b05985bae5e

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