annotate plugins/yay/rxhandlers.c @ 1847:029cc08d9c54

[gaim-migrate @ 1857] Hooray committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Mon, 14 May 2001 16:30:33 +0000
parents e739d3dddf4c
children dff412b306b8
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
1718
20f070721b9f [gaim-migrate @ 1728]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1680
diff changeset
27 static void yahoo_parse_config(struct yahoo_session *session, struct yahoo_conn *conn, char *buf)
1546
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++) {
1616
8b684f420841 [gaim-migrate @ 1626]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1570
diff changeset
34 if (!**it) continue;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 if (!strncmp(*it, "ERROR", strlen("ERROR"))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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);
1718
20f070721b9f [gaim-migrate @ 1728]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1680
diff changeset
39 return;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 } else if (!strncmp(*it, "Set-Cookie: ", strlen("Set-Cookie: "))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 char **sa;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 char **m;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 char *end = strchr(*it, ';');
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 if (session->cookie)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 g_free(session->cookie);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 session->cookie = g_strndup(*it + strlen("Set-Cookie: "),
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 end - *it - strlen("Set-Cookie: "));
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, session->cookie);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 if (!session->cookie) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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);
1718
20f070721b9f [gaim-migrate @ 1728]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1680
diff changeset
55 return;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 sa = g_strsplit(session->cookie, "&", 8);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59 for (m = sa; *m; m++) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 if (!strncmp(*m, "n=", 2)) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 if (session->login_cookie)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 g_free(session->login_cookie);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 session->login_cookie = g_strdup(*m + 2);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, session->login_cookie);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 g_strfreev(sa);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 } else if (!strncmp(*it, "BEGIN BUDDYLIST", strlen("BEGIN BUDDYLIST"))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 state = 1;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 } else if (!strncmp(*it, "END BUDDYLIST", strlen("END BUDDYLIST"))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 state = 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 } else if (!strncmp(*it, "BEGIN IGNORELIST", strlen("BEGIN IGNORELIST"))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 state = 2;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 } else if (!strncmp(*it, "END IGNORELIST", strlen("END IGNORELIST"))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 state = 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 } else if (!strncmp(*it, "BEGIN IDENTITIES", strlen("BEGIN IDENTITIES"))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 state = 3;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 } else if (!strncmp(*it, "END IDENTITIES", strlen("END IDENTITIES"))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 state = 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 } else if (!strncmp(*it, "Mail=", strlen("Mail="))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 session->mail = atoi(*it + strlen("Mail="));
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82 } else if (!strncmp(*it, "Login=", strlen("Login="))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 if (session->login)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 g_free(session->login);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 session->login = g_strdup(*it + strlen("Login="));
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 } else {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 if (state == 1) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 struct yahoo_group *grp = g_new0(struct yahoo_group, 1);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
96 } else if (state == 2) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
97 session->ignored = g_list_append(session->ignored, g_strdup(*it));
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
98 } else if (state == 3) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
99 session->identities = g_strsplit(*it, ",", 6);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
100 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
101 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 }
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 g_strfreev(str_array);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 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
111 {
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
112 /* OK, I'm going to comment it this time. We either get:
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
113 * gtkobject(99,(test)\001,6634CD3,0,1,0,0)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
114 * or
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
115 * 2,gtkobject(0,6634CD3,0,1,0,0),warmenhoven(0,6C8C0C48,0,1,0,0)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
116 *
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
117 * in the first case, we only get one person, and we get a bunch of fields.
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
118 * in the second case, the number is how many people we got, and then the
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
119 * names followed by a bunch of fields, separated by commas.
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
120 *
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
121 * the fields are: (status, [optional: custom message \001,] session id, ?, pager, chat, game)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
122 *
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
123 * the custom message may contain any characters (none are escaped) so we can't split on
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
124 * anything in particular. this is what we fucked up with the first time
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
125 */
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 char *tmp = pkt->content;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 int count = 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128 int i;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 if (strstr(pkt->content, "was not AWAY"))
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
133 /* count is the first number, if we got it. */
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 while (*tmp && isdigit((int)*tmp))
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 count = count * 10 + *tmp++ - '0';
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 count = count ? count : 1;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
138 for (i = 0; i < count && *tmp; i++) {
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
139 int status, in_pager, in_chat, in_game;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
140 char *p, *who, *msg = NULL;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
141
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
142 if (*tmp == ',')
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
143 tmp++;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
145 /* who is the person we're getting an update for. there will always be a paren
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
146 * after this so we should be OK. if we don't get a paren, we'll just break. */
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
147 who = tmp;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
148 if ((tmp = strchr(who, '(')) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
149 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
150 *tmp++ = '\0';
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
152 /* tmp now points to the start of the fields. we'll get the status first. it
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
153 * should always be followed by a comma, and if it isn't, we'll just break. */
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
154 if ((p = strchr(tmp, ',')) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
155 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
156 *p++ = '\0';
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
157 status = atoi(tmp);
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
158 tmp = p;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
160 if (status == YAHOO_STATUS_CUSTOM) {
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
161 /* tmp now points to the away message. it should end with "\001,". */
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
162 msg = tmp;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
163 if ((tmp = strstr(msg, "\001,")) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
164 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
165 *tmp = '\0';
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
166 tmp += 2;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
169 /* tmp now points to the session id. we don't need it. */
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
170 if ((tmp = strchr(tmp, ',')) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
171 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
172 tmp++;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
173
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
174 /* tmp is at the unknown value. we don't need it. */
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
175 if ((tmp = strchr(tmp, ',')) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
176 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
177 tmp++;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
178
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
179 /* tmp is at the in_pager value */
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
180 if ((p = strchr(tmp, ',')) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
181 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
182 *p++ = '\0';
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
183 in_pager = atoi(tmp);
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
184 tmp = p;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
186 /* tmp is at the in_chat value */
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
187 if ((p = strchr(tmp, ',')) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
188 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
189 *p++ = '\0';
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
190 in_chat = atoi(tmp);
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
191 tmp = p;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
192
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
193 /* tmp is at the in_game value. this is the last value, so it should end with
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
194 * a parenthesis. */
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
195 if ((p = strchr(tmp, ')')) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
196 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
197 *p++ = '\0';
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
198 in_game = atoi(tmp);
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
199 tmp = p;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
200
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
201 if (sess->callbacks[YAHOO_HANDLE_STATUS].function)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
202 (*sess->callbacks[YAHOO_HANDLE_STATUS].function)(sess, who, status, msg,
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
203 in_pager, in_chat, in_game);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 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
208 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209 char buf[256];
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 int type = yahoo_makeint(pkt->msgtype);
1845
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
211 char *str_array[4];
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
212 char *tmp;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
213
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 switch(type) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215 case YAHOO_MESSAGE_NORMAL:
1836
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
216 str_array[0] = pkt->content;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
217 if ((tmp = strchr(str_array[0], ',')) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
218 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
219 *tmp++ = '\0';
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
220 str_array[1] = tmp;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
221 if ((tmp = strchr(str_array[1], ',')) == NULL)
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
222 break;
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
223 *tmp++ = '\0';
703a567ec4bf [gaim-migrate @ 1846]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1737
diff changeset
224 str_array[2] = tmp;
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
225 if (sess->callbacks[YAHOO_HANDLE_MESSAGE].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
226 (*sess->callbacks[YAHOO_HANDLE_MESSAGE].function)(sess, pkt->nick2,
1737
82c824fe018e [gaim-migrate @ 1747]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1718
diff changeset
227 str_array[0],
82c824fe018e [gaim-migrate @ 1747]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1718
diff changeset
228 atol(str_array[1]),
82c824fe018e [gaim-migrate @ 1747]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1718
diff changeset
229 str_array[2]);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230 break;
1562
12f16a852540 [gaim-migrate @ 1572]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1561
diff changeset
231 case YAHOO_MESSAGE_BOUNCE:
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
232 if (sess->callbacks[YAHOO_HANDLE_BOUNCE].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
233 (*sess->callbacks[YAHOO_HANDLE_BOUNCE].function)(sess);
1562
12f16a852540 [gaim-migrate @ 1572]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1561
diff changeset
234 break;
1845
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
235 case YAHOO_MESSAGE_OFFLINE:
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
236 tmp = pkt->content;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
237 if ((tmp = strchr(tmp, ',')) == NULL)
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
238 break;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
239 ++tmp;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
240 if ((tmp = strchr(tmp, ',')) == NULL)
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
241 break;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
242 str_array[0] = ++tmp;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
243 if ((tmp = strchr(tmp, ',')) == NULL)
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
244 break;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
245 *tmp++ = '\0';
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
246 str_array[1] = tmp;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
247 if ((tmp = strchr(tmp, ',')) == NULL)
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
248 break;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
249 *tmp++ = '\0';
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
250 str_array[2] = tmp;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
251 if ((tmp = strchr(tmp, ',')) == NULL)
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
252 break;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
253 *tmp++ = '\0';
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
254 str_array[3] = tmp;
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
255 if (sess->callbacks[YAHOO_HANDLE_MESSAGE].function)
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
256 (*sess->callbacks[YAHOO_HANDLE_MESSAGE].function)(sess, str_array[0],
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
257 str_array[1],
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
258 atol(str_array[2]),
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
259 str_array[3]);
e739d3dddf4c [gaim-migrate @ 1855]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1836
diff changeset
260 break;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
261 default:
1680
b83195b7ab0a [gaim-migrate @ 1690]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1645
diff changeset
262 g_snprintf(buf, sizeof(buf), "unhandled message type %d", type);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
263 YAHOO_PRINT(sess, YAHOO_LOG_WARNING, buf);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
264 break;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
265 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
266 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
267
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
268 static void yahoo_parse_packet(struct yahoo_session *sess,
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
269 struct yahoo_conn *conn, struct yahoo_packet *pkt)
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 char buf[256];
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
272 int service = yahoo_makeint(pkt->service);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
273 conn->magic_id = yahoo_makeint(pkt->magic_id);
1680
b83195b7ab0a [gaim-migrate @ 1690]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1645
diff changeset
274 g_snprintf(buf, sizeof(buf), "Service %d (msgtype %d): %s", service,
b83195b7ab0a [gaim-migrate @ 1690]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1645
diff changeset
275 yahoo_makeint(pkt->msgtype), pkt->content);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
276 YAHOO_PRINT(sess, YAHOO_LOG_DEBUG, buf);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
277 switch(service) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
278 case YAHOO_SERVICE_LOGON:
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
279 if (yahoo_makeint(pkt->msgtype) == 0)
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
280 if (sess->callbacks[YAHOO_HANDLE_ONLINE].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
281 (*sess->callbacks[YAHOO_HANDLE_ONLINE].function)(sess);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
282 case YAHOO_SERVICE_LOGOFF:
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
283 case YAHOO_SERVICE_ISAWAY:
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
284 case YAHOO_SERVICE_ISBACK:
1561
9fe7b059d2a5 [gaim-migrate @ 1571]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1557
diff changeset
285 yahoo_parse_status(sess, pkt);
9fe7b059d2a5 [gaim-migrate @ 1571]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1557
diff changeset
286 break;
1557
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
287 case YAHOO_SERVICE_NEWCONTACT:
1563
393b23c8f494 [gaim-migrate @ 1573]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1562
diff changeset
288 if (yahoo_makeint(pkt->msgtype) == 3) {
393b23c8f494 [gaim-migrate @ 1573]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1562
diff changeset
289 char **str_array = g_strsplit(pkt->content, ",,", 2);
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
290 if (sess->callbacks[YAHOO_HANDLE_BUDDYADDED].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
291 (*sess->callbacks[YAHOO_HANDLE_BUDDYADDED].function)(sess,
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
292 pkt->nick2,
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
293 str_array[0],
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
294 str_array[1]);
1563
393b23c8f494 [gaim-migrate @ 1573]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1562
diff changeset
295 g_strfreev(str_array);
393b23c8f494 [gaim-migrate @ 1573]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1562
diff changeset
296 } else
1561
9fe7b059d2a5 [gaim-migrate @ 1571]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1557
diff changeset
297 yahoo_parse_status(sess, pkt);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
298 break;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
299 case YAHOO_SERVICE_IDACT:
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
300 if (sess->callbacks[YAHOO_HANDLE_ACTIVATE].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
301 (*sess->callbacks[YAHOO_HANDLE_ACTIVATE].function)(sess);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
302 break;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
303 case YAHOO_SERVICE_MESSAGE:
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
304 yahoo_parse_message(sess, pkt);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
305 break;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
306 case YAHOO_SERVICE_NEWMAIL:
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
307 if (sess->callbacks[YAHOO_HANDLE_NEWMAIL].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
308 (*sess->callbacks[YAHOO_HANDLE_NEWMAIL].function)(sess, strlen(pkt->content) ?
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
309 atoi(pkt->content) : 0);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
310 break;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
311 default:
1680
b83195b7ab0a [gaim-migrate @ 1690]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1645
diff changeset
312 g_snprintf(buf, sizeof(buf), "unhandled service type %d", service);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
313 YAHOO_PRINT(sess, YAHOO_LOG_WARNING, buf);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
314 break;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
315 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
316 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
317
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
318 void yahoo_socket_handler(struct yahoo_session *session, int socket, int type)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
319 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
320 int pos = 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
321 struct yahoo_conn *conn;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
322
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
323 if (!session)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
324 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
325
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
326 if (!(conn = yahoo_find_conn(session, socket)))
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
327 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
328
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
329 if (type == YAHOO_SOCKET_WRITE) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
330 int error = ETIMEDOUT, len = sizeof(error);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
331
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
332 if (getsockopt(socket, SOL_SOCKET, SO_ERROR, &error, &len) < 0)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
333 error = errno;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
334 if (error) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
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, "unable to connect");
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
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
339 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
340 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
341
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
342 fcntl(socket, F_SETFL, 0);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
343
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
344 YAHOO_PRINT(session, YAHOO_LOG_NOTICE, "connected");
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
345
1566
e9faf5dfdba0 [gaim-migrate @ 1576]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1565
diff changeset
346 conn->connected = TRUE;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
347 if (yahoo_socket_notify)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
348 (*yahoo_socket_notify)(session, socket, YAHOO_SOCKET_WRITE, FALSE);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
349 if (yahoo_socket_notify)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
350 (*yahoo_socket_notify)(session, socket, YAHOO_SOCKET_READ, TRUE);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
351
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
352 if (conn->type == YAHOO_CONN_TYPE_AUTH) {
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
353 if (session->callbacks[YAHOO_HANDLE_AUTHCONNECT].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
354 (*session->callbacks[YAHOO_HANDLE_AUTHCONNECT].function)(session);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
355 } else if (conn->type == YAHOO_CONN_TYPE_MAIN) {
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
356 if (session->callbacks[YAHOO_HANDLE_MAINCONNECT].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
357 (*session->callbacks[YAHOO_HANDLE_MAINCONNECT].function)(session);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
358 } else if (conn->type == YAHOO_CONN_TYPE_DUMB) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
359 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, "sending to buddy list host");
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
360 yahoo_write(session, conn, conn->txqueue, strlen(conn->txqueue));
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
361 g_free(conn->txqueue);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
362 conn->txqueue = NULL;
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
363 } else if (conn->type == YAHOO_CONN_TYPE_PROXY) {
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
364 char buf[1024];
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
365 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
366 YAHOO_PAGER_HOST, YAHOO_PAGER_PORT);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
367 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
368 yahoo_write(session, conn, buf, strlen(buf));
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
369 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
370
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
371 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
372 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
373
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
374 if (conn->type == YAHOO_CONN_TYPE_AUTH) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
375 char *buf = g_malloc0(5000);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
376 while (read(socket, &buf[pos++], 1) == 1);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
377 if (pos == 1) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
378 g_free(buf);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
379 yahoo_close(session, conn);
1554
c3afde736a8a [gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1553
diff changeset
380 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
381 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
382 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
383 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
384 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
385 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf);
1718
20f070721b9f [gaim-migrate @ 1728]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1680
diff changeset
386 yahoo_parse_config(session, conn, buf);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
387 g_free(buf);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
388 } else if (conn->type == YAHOO_CONN_TYPE_MAIN) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
389 struct yahoo_packet pkt;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
390 int len;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
391
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
392 if ((read(socket, &pkt, 8) != 8) || strcmp(pkt.version, "YHOO1.0")) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
393 yahoo_close(session, conn);
1554
c3afde736a8a [gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1553
diff changeset
394 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "invalid version type");
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
395 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
396 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
397 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
398 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
399
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
400 if (read(socket, &pkt.len, 4) != 4) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
401 yahoo_close(session, conn);
1554
c3afde736a8a [gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1553
diff changeset
402 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "could not read length");
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
403 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
404 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
405 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
406 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
407 len = yahoo_makeint(pkt.len);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
408
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
409 if (read(socket, &pkt.service, len - 12) != len - 12) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
410 yahoo_close(session, conn);
1554
c3afde736a8a [gaim-migrate @ 1564]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1553
diff changeset
411 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "could not read data");
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
412 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
413 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
414 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
415 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
416 yahoo_parse_packet(session, conn, &pkt);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
417 } else if (conn->type == YAHOO_CONN_TYPE_DUMB) {
1557
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
418 char *buf = g_malloc0(5000);
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
419 while (read(socket, &buf[pos++], 1) == 1);
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
420 if (pos == 1) {
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
421 g_free(buf);
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
422 yahoo_close(session, conn);
1557
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
423 YAHOO_PRINT(session, YAHOO_LOG_WARNING, "error reading from listserv");
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
424 return;
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
425 }
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
426 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf);
1ca5f5fcd483 [gaim-migrate @ 1567]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1554
diff changeset
427 YAHOO_PRINT(session, YAHOO_LOG_NOTICE, "closing buddy list host connnection");
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
428 yahoo_close(session, conn);
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
429 g_free(buf);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
430 } else if (conn->type == YAHOO_CONN_TYPE_PROXY) {
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
431 char *buf = g_malloc0(5000);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
432 int nlc = 0;
1645
2ca7329ee519 [gaim-migrate @ 1655]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1616
diff changeset
433 while ((nlc != 2) && (read(socket, &buf[pos++], 1) == 1)) {
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
434 if (buf[pos-1] == '\n')
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
435 nlc++;
1645
2ca7329ee519 [gaim-migrate @ 1655]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1616
diff changeset
436 else if (buf[pos-1] != '\r')
2ca7329ee519 [gaim-migrate @ 1655]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1616
diff changeset
437 nlc = 0;
2ca7329ee519 [gaim-migrate @ 1655]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1616
diff changeset
438 }
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
439 if (pos == 1) {
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
440 g_free(buf);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
441 yahoo_close(session, conn);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
442 YAHOO_PRINT(session, YAHOO_LOG_ERROR, "error reading from proxy");
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
443 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
444 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session);
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
445 return;
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
446 }
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
447 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, buf);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
448 if (!strncasecmp(buf, HTTP_GOODSTRING1, strlen(HTTP_GOODSTRING1)) ||
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
449 !strncasecmp(buf, HTTP_GOODSTRING2, strlen(HTTP_GOODSTRING2))) {
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
450 conn->type = YAHOO_CONN_TYPE_MAIN;
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
451 YAHOO_PRINT(session, YAHOO_LOG_NOTICE, "proxy connected successfully");
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
452 if (session->callbacks[YAHOO_HANDLE_MAINCONNECT].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
453 (*session->callbacks[YAHOO_HANDLE_MAINCONNECT].function)(session);
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
454 } else {
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
455 yahoo_close(session, conn);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
456 YAHOO_PRINT(session, YAHOO_LOG_ERROR, "proxy could not connect");
1570
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
457 if (session->callbacks[YAHOO_HANDLE_DISCONNECT].function)
4a47a459cc98 [gaim-migrate @ 1580]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1566
diff changeset
458 (*session->callbacks[YAHOO_HANDLE_DISCONNECT].function)(session);
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
459 }
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1563
diff changeset
460 g_free(buf);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
461 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
462 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
463
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
464 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
465 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
466 if (!session)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
467 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
468
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
469 session->callbacks[type].function = function;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
470 }