annotate plugins/yay/rxhandlers.c @ 1565:2c66d386be90

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