Mercurial > pidgin
annotate plugins/yay/rxhandlers.c @ 1570:4a47a459cc98
[gaim-migrate @ 1580]
i hate everyone (it's dead week and i have a final *today*)
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 14 Mar 2001 20:11:04 +0000 |
parents | e9faf5dfdba0 |
children | 8b684f420841 |
rev | line source |
---|---|
1546 | 1 /* |
2 * libyay | |
3 * | |
4 * Copyright (C) 2001 Eric Warmenhoven <warmenhoven@yahoo.com> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 * | |
20 */ | |
21 | |
22 #include "internal.h" | |
23 #include <string.h> | |
24 #include <stdlib.h> | |
25 #include <ctype.h> | |
26 | |
27 static int yahoo_parse_config(struct yahoo_session *session, struct yahoo_conn *conn, char *buf) | |
28 { | |
29 char **str_array = g_strsplit(buf, "\n", 1024); | |
30 char **it; | |
31 int state = 0; | |
32 | |
33 for (it = str_array; *it; it++) { | |
34 if (!strncmp(*it, "ERROR", strlen("ERROR"))) { | |
35 yahoo_close(session, conn); | |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
36 if (session->callbacks[YAHOO_HANDLE_BADPASSWORD].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
37 (*session->callbacks[YAHOO_HANDLE_BADPASSWORD].function)(session); |
1546 | 38 return 1; |
39 } else if (!strncmp(*it, "Set-Cookie: ", strlen("Set-Cookie: "))) { | |
40 char **sa; | |
41 char **m; | |
42 | |
43 char *end = strchr(*it, ';'); | |
44 if (session->cookie) | |
45 g_free(session->cookie); | |
46 session->cookie = g_strndup(*it + strlen("Set-Cookie: "), | |
47 end - *it - strlen("Set-Cookie: ")); | |
48 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, session->cookie); | |
49 if (!session->cookie) { | |
50 yahoo_close(session, conn); | |
1554
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1553
diff
changeset
|
51 YAHOO_PRINT(session, YAHOO_LOG_ERROR, "did not get cookie"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
52 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
53 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); |
1546 | 54 return 1; |
55 } | |
56 | |
57 sa = g_strsplit(session->cookie, "&", 8); | |
58 for (m = sa; *m; m++) { | |
59 if (!strncmp(*m, "n=", 2)) { | |
60 if (session->login_cookie) | |
61 g_free(session->login_cookie); | |
62 session->login_cookie = g_strdup(*m + 2); | |
63 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, session->login_cookie); | |
64 } | |
65 } | |
66 g_strfreev(sa); | |
67 } else if (!strncmp(*it, "BEGIN BUDDYLIST", strlen("BEGIN BUDDYLIST"))) { | |
68 state = 1; | |
69 } else if (!strncmp(*it, "END BUDDYLIST", strlen("END BUDDYLIST"))) { | |
70 state = 0; | |
71 } else if (!strncmp(*it, "BEGIN IGNORELIST", strlen("BEGIN IGNORELIST"))) { | |
72 state = 2; | |
73 } else if (!strncmp(*it, "END IGNORELIST", strlen("END IGNORELIST"))) { | |
74 state = 0; | |
75 } else if (!strncmp(*it, "BEGIN IDENTITIES", strlen("BEGIN IDENTITIES"))) { | |
76 state = 3; | |
77 } else if (!strncmp(*it, "END IDENTITIES", strlen("END IDENTITIES"))) { | |
78 state = 0; | |
79 } else if (!strncmp(*it, "Mail=", strlen("Mail="))) { | |
80 session->mail = atoi(*it + strlen("Mail=")); | |
81 } else if (!strncmp(*it, "Login=", strlen("Login="))) { | |
82 if (session->login) | |
83 g_free(session->login); | |
84 session->login = g_strdup(*it + strlen("Login=")); | |
85 } else { | |
86 if (state == 1) { | |
87 struct yahoo_group *grp = g_new0(struct yahoo_group, 1); | |
88 char *end = strchr(*it, ':'); | |
89 grp->name = g_strndup(*it, end - *it); | |
90 end++; | |
91 grp->buddies = g_strsplit(end, ",", 1024); | |
92 session->groups = g_list_append(session->groups, grp); | |
93 } else if (state == 2) { | |
94 session->ignored = g_list_append(session->ignored, g_strdup(*it)); | |
95 } else if (state == 3) { | |
96 session->identities = g_strsplit(*it, ",", 6); | |
97 } | |
98 } | |
99 } | |
100 | |
101 g_strfreev(str_array); | |
102 yahoo_close(session, conn); | |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
103 if (session->callbacks[YAHOO_HANDLE_LOGINCOOKIE].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
104 (*session->callbacks[YAHOO_HANDLE_LOGINCOOKIE].function)(session); |
1546 | 105 return 0; |
106 } | |
107 | |
108 static void yahoo_parse_status(struct yahoo_session *sess, struct yahoo_packet *pkt) | |
109 { | |
110 char *tmp = pkt->content; | |
111 int count = 0; | |
112 char **strs; | |
113 int i; | |
114 | |
115 YAHOO_PRINT(sess, YAHOO_LOG_DEBUG, pkt->content); | |
116 | |
117 if (strstr(pkt->content, "was not AWAY")) | |
118 return; | |
119 | |
120 while (*tmp && isdigit((int)*tmp)) | |
121 count = count * 10 + *tmp++ - '0'; | |
122 if (*tmp == ',') | |
123 tmp++; | |
124 count = count ? count : 1; | |
125 | |
126 if (count > 1) | |
127 strs = g_strsplit(tmp, "),", count); | |
128 else | |
129 strs = g_strsplit(tmp, ")", count); | |
130 | |
131 for (i = 0; i < count && strs[i]; i++) { | |
132 char **vals; | |
133 char *end, *who; | |
134 char **it; | |
135 int c, j; | |
136 | |
137 who = strs[i]; | |
138 end = strchr(who, '('); | |
139 *end++ = '\0'; | |
140 | |
141 vals = g_strsplit(end, ",", 1024); | |
142 | |
143 for (it = vals, c = 0; *it; it++, c++); | |
144 if (c > 6) | |
145 end = g_strdup(vals[1]); | |
146 for (j = 2; j < c - 5; j++) { | |
147 char *x = end; | |
148 end = g_strconcat(end, ",", vals[j], NULL); | |
149 g_free(x); | |
150 } | |
151 | |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
152 if (sess->callbacks[YAHOO_HANDLE_STATUS].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
153 (*sess->callbacks[YAHOO_HANDLE_STATUS].function)(sess, who, atoi(vals[0]), |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
154 end, atoi(vals[c - 3]), |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
155 atoi(vals[c - 2]), |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
156 atoi(vals[c - 1])); |
1546 | 157 |
158 if (c > 6) | |
159 g_free(end); | |
160 g_strfreev(vals); | |
161 } | |
162 | |
163 g_strfreev(strs); | |
164 } | |
165 | |
166 static void yahoo_parse_message(struct yahoo_session *sess, struct yahoo_packet *pkt) | |
167 { | |
168 char buf[256]; | |
169 int type = yahoo_makeint(pkt->msgtype); | |
170 char **str_array; | |
171 switch(type) { | |
172 case YAHOO_MESSAGE_NORMAL: | |
173 str_array = g_strsplit(pkt->content, ",,", 2); | |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
174 if (sess->callbacks[YAHOO_HANDLE_MESSAGE].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
175 (*sess->callbacks[YAHOO_HANDLE_MESSAGE].function)(sess, pkt->nick2, |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
176 str_array[0], str_array[1]); |
1546 | 177 g_strfreev(str_array); |
178 break; | |
1562
12f16a852540
[gaim-migrate @ 1572]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1561
diff
changeset
|
179 case YAHOO_MESSAGE_BOUNCE: |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
180 if (sess->callbacks[YAHOO_HANDLE_BOUNCE].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
181 (*sess->callbacks[YAHOO_HANDLE_BOUNCE].function)(sess); |
1562
12f16a852540
[gaim-migrate @ 1572]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1561
diff
changeset
|
182 break; |
1546 | 183 default: |
184 g_snprintf(buf, sizeof(buf), "unhandled message type %d: %s", type, pkt->content); | |
185 YAHOO_PRINT(sess, YAHOO_LOG_WARNING, buf); | |
186 break; | |
187 } | |
188 } | |
189 | |
190 static void yahoo_parse_packet(struct yahoo_session *sess, | |
191 struct yahoo_conn *conn, struct yahoo_packet *pkt) | |
192 { | |
193 char buf[256]; | |
194 int service = yahoo_makeint(pkt->service); | |
195 conn->magic_id = yahoo_makeint(pkt->magic_id); | |
196 g_snprintf(buf, sizeof(buf), "Service %d (msgtype %d)", service, yahoo_makeint(pkt->msgtype)); | |
197 YAHOO_PRINT(sess, YAHOO_LOG_DEBUG, buf); | |
198 switch(service) { | |
199 case YAHOO_SERVICE_LOGON: | |
200 if (yahoo_makeint(pkt->msgtype) == 0) | |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
201 if (sess->callbacks[YAHOO_HANDLE_ONLINE].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
202 (*sess->callbacks[YAHOO_HANDLE_ONLINE].function)(sess); |
1546 | 203 case YAHOO_SERVICE_LOGOFF: |
204 case YAHOO_SERVICE_ISAWAY: | |
205 case YAHOO_SERVICE_ISBACK: | |
1561
9fe7b059d2a5
[gaim-migrate @ 1571]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1557
diff
changeset
|
206 yahoo_parse_status(sess, pkt); |
9fe7b059d2a5
[gaim-migrate @ 1571]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1557
diff
changeset
|
207 break; |
1557
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
208 case YAHOO_SERVICE_NEWCONTACT: |
1563
393b23c8f494
[gaim-migrate @ 1573]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1562
diff
changeset
|
209 if (yahoo_makeint(pkt->msgtype) == 3) { |
393b23c8f494
[gaim-migrate @ 1573]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1562
diff
changeset
|
210 char **str_array = g_strsplit(pkt->content, ",,", 2); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
211 if (sess->callbacks[YAHOO_HANDLE_BUDDYADDED].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
212 (*sess->callbacks[YAHOO_HANDLE_BUDDYADDED].function)(sess, |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
213 pkt->nick2, |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
214 str_array[0], |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
215 str_array[1]); |
1563
393b23c8f494
[gaim-migrate @ 1573]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1562
diff
changeset
|
216 g_strfreev(str_array); |
393b23c8f494
[gaim-migrate @ 1573]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1562
diff
changeset
|
217 } else |
1561
9fe7b059d2a5
[gaim-migrate @ 1571]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1557
diff
changeset
|
218 yahoo_parse_status(sess, pkt); |
1546 | 219 break; |
220 case YAHOO_SERVICE_IDACT: | |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
221 if (sess->callbacks[YAHOO_HANDLE_ACTIVATE].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
222 (*sess->callbacks[YAHOO_HANDLE_ACTIVATE].function)(sess); |
1546 | 223 break; |
224 case YAHOO_SERVICE_MESSAGE: | |
225 yahoo_parse_message(sess, pkt); | |
226 break; | |
227 case YAHOO_SERVICE_NEWMAIL: | |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
228 if (sess->callbacks[YAHOO_HANDLE_NEWMAIL].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
229 (*sess->callbacks[YAHOO_HANDLE_NEWMAIL].function)(sess, strlen(pkt->content) ? |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
230 atoi(pkt->content) : 0); |
1546 | 231 break; |
232 default: | |
233 g_snprintf(buf, sizeof(buf), "unhandled service type %d: %s", service, pkt->content); | |
234 YAHOO_PRINT(sess, YAHOO_LOG_WARNING, buf); | |
235 break; | |
236 } | |
237 } | |
238 | |
239 void yahoo_socket_handler(struct yahoo_session *session, int socket, int type) | |
240 { | |
241 int pos = 0; | |
242 struct yahoo_conn *conn; | |
243 | |
244 if (!session) | |
245 return; | |
246 | |
247 if (!(conn = yahoo_find_conn(session, socket))) | |
248 return; | |
249 | |
250 if (type == YAHOO_SOCKET_WRITE) { | |
251 int error = ETIMEDOUT, len = sizeof(error); | |
252 | |
253 if (getsockopt(socket, SOL_SOCKET, SO_ERROR, &error, &len) < 0) | |
254 error = errno; | |
255 if (error) { | |
256 yahoo_close(session, conn); | |
1554
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1553
diff
changeset
|
257 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "unable to connect"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
258 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
259 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); |
1546 | 260 return; |
261 } | |
262 | |
263 fcntl(socket, F_SETFL, 0); | |
264 | |
265 YAHOO_PRINT(session, YAHOO_LOG_NOTICE, "connected"); | |
266 | |
1566
e9faf5dfdba0
[gaim-migrate @ 1576]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1565
diff
changeset
|
267 conn->connected = TRUE; |
1546 | 268 if (yahoo_socket_notify) |
269 (*yahoo_socket_notify)(session, socket, YAHOO_SOCKET_WRITE, FALSE); | |
270 if (yahoo_socket_notify) | |
271 (*yahoo_socket_notify)(session, socket, YAHOO_SOCKET_READ, TRUE); | |
272 | |
273 if (conn->type == YAHOO_CONN_TYPE_AUTH) { | |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
274 if (session->callbacks[YAHOO_HANDLE_AUTHCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
275 (*session->callbacks[YAHOO_HANDLE_AUTHCONNECT].function)(session); |
1546 | 276 } else if (conn->type == YAHOO_CONN_TYPE_MAIN) { |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
277 if (session->callbacks[YAHOO_HANDLE_MAINCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
278 (*session->callbacks[YAHOO_HANDLE_MAINCONNECT].function)(session); |
1546 | 279 } else if (conn->type == YAHOO_CONN_TYPE_DUMB) { |
280 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, "sending to buddy list host"); | |
281 yahoo_write(session, conn, conn->txqueue, strlen(conn->txqueue)); | |
282 g_free(conn->txqueue); | |
283 conn->txqueue = NULL; | |
1565
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
284 } else if (conn->type == YAHOO_CONN_TYPE_PROXY) { |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
285 char buf[1024]; |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
286 g_snprintf(buf, sizeof(buf), "CONNECT %s:%d HTTP/1.1\r\n\r\n", |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
287 YAHOO_PAGER_HOST, YAHOO_PAGER_PORT); |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
288 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf); |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
289 yahoo_write(session, conn, buf, strlen(buf)); |
1546 | 290 } |
291 | |
292 return; | |
293 } | |
294 | |
295 if (conn->type == YAHOO_CONN_TYPE_AUTH) { | |
296 char *buf = g_malloc0(5000); | |
297 while (read(socket, &buf[pos++], 1) == 1); | |
298 if (pos == 1) { | |
299 g_free(buf); | |
300 yahoo_close(session, conn); | |
1554
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1553
diff
changeset
|
301 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "could not read auth response"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
302 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
303 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); |
1546 | 304 return; |
305 } | |
306 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf); | |
1554
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1553
diff
changeset
|
307 if (yahoo_parse_config(session, conn, buf)) { |
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1553
diff
changeset
|
308 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "could not parse auth response"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
309 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
310 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); |
1554
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1553
diff
changeset
|
311 } |
1546 | 312 g_free(buf); |
313 } else if (conn->type == YAHOO_CONN_TYPE_MAIN) { | |
314 struct yahoo_packet pkt; | |
315 int len; | |
316 | |
317 if ((read(socket, &pkt, 8) != 8) || strcmp(pkt.version, "YHOO1.0")) { | |
318 yahoo_close(session, conn); | |
1554
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1553
diff
changeset
|
319 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "invalid version type"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
320 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
321 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); |
1546 | 322 return; |
323 } | |
324 | |
325 if (read(socket, &pkt.len, 4) != 4) { | |
326 yahoo_close(session, conn); | |
1554
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1553
diff
changeset
|
327 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "could not read length"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
328 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
329 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); |
1546 | 330 return; |
331 } | |
332 len = yahoo_makeint(pkt.len); | |
333 | |
334 if (read(socket, &pkt.service, len - 12) != len - 12) { | |
335 yahoo_close(session, conn); | |
1554
c3afde736a8a
[gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1553
diff
changeset
|
336 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "could not read data"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
337 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
338 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); |
1546 | 339 return; |
340 } | |
341 yahoo_parse_packet(session, conn, &pkt); | |
342 } else if (conn->type == YAHOO_CONN_TYPE_DUMB) { | |
1557
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
343 char *buf = g_malloc0(5000); |
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
344 while (read(socket, &buf[pos++], 1) == 1); |
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
345 if (pos == 1) { |
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
346 g_free(buf); |
1565
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
347 yahoo_close(session, conn); |
1557
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
348 YAHOO_PRINT(session, YAHOO_LOG_WARNING, "error reading from listserv"); |
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
349 return; |
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
350 } |
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
351 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf); |
1ca5f5fcd483
[gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1554
diff
changeset
|
352 YAHOO_PRINT(session, YAHOO_LOG_NOTICE, "closing buddy list host connnection"); |
1546 | 353 yahoo_close(session, conn); |
1565
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
354 g_free(buf); |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
355 } else if (conn->type == YAHOO_CONN_TYPE_PROXY) { |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
356 char *buf = g_malloc0(5000); |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
357 int nlc = 0; |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
358 while ((nlc != 2) && (read(socket, &buf[pos++], 1) == 1)) |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
359 if (buf[pos-1] == '\n') |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
360 nlc++; |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
361 if (pos == 1) { |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
362 g_free(buf); |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
363 yahoo_close(session, conn); |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
364 YAHOO_PRINT(session, YAHOO_LOG_ERROR, "error reading from proxy"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
365 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
366 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); |
1565
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
367 return; |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
368 } |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
369 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf); |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
370 if (!strncasecmp(buf, HTTP_GOODSTRING1, strlen(HTTP_GOODSTRING1)) || |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
371 !strncasecmp(buf, HTTP_GOODSTRING2, strlen(HTTP_GOODSTRING2))) { |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
372 conn->type = YAHOO_CONN_TYPE_MAIN; |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
373 YAHOO_PRINT(session, YAHOO_LOG_NOTICE, "proxy connected successfully"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
374 if (session->callbacks[YAHOO_HANDLE_MAINCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
375 (*session->callbacks[YAHOO_HANDLE_MAINCONNECT].function)(session); |
1565
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
376 } else { |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
377 yahoo_close(session, conn); |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
378 YAHOO_PRINT(session, YAHOO_LOG_ERROR, "proxy could not connect"); |
1570
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
379 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function) |
4a47a459cc98
[gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1566
diff
changeset
|
380 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session); |
1565
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
381 } |
2c66d386be90
[gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1563
diff
changeset
|
382 g_free(buf); |
1546 | 383 } |
384 } | |
385 | |
386 void yahoo_add_handler(struct yahoo_session *session, int type, yahoo_callback function) | |
387 { | |
388 if (!session) | |
389 return; | |
390 | |
391 session->callbacks[type].function = function; | |
392 } |