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