annotate src/protocols/yahoo/yahoo_packet.c @ 14120:d812efcea547

[gaim-migrate @ 16754] Warning fixes for now. Someone (probably me, sigh) will have to change this to use gaim_proxy_connect_cancel() later in the week committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 14 Aug 2006 08:27:53 +0000
parents c070fdec12a3
children 89d043d547cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
1 /*
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
2 * gaim
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
3 *
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
6 * source distribution.
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
7 *
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
12 *
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
17 *
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
21 *
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
22 */
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
23
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
24 #include "internal.h"
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
25 #include "debug.h"
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
26
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
27 #include "yahoo.h"
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
28 #include "yahoo_packet.h"
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
29
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
30 struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, enum yahoo_status status, int id)
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
31 {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
32 struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
33
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
34 pkt->service = service;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
35 pkt->status = status;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
36 pkt->id = id;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
37
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
38 return pkt;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
39 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
40
10394
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
41 void yahoo_packet_hash_str(struct yahoo_packet *pkt, int key, const char *value)
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
42 {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
43 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
44 pair->key = key;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
45 pair->value = g_strdup(value);
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
46 pkt->hash = g_slist_prepend(pkt->hash, pair);
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
47 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
48
10394
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
49 void yahoo_packet_hash_int(struct yahoo_packet *pkt, int key, int value)
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
50 {
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
51 struct yahoo_pair *pair = g_new0(struct yahoo_pair, 1);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
52
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
53 pair->key = key;
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
54 pair->value = g_strdup_printf("%d", value);
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
55 pkt->hash = g_slist_prepend(pkt->hash, pair);
10394
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
56 }
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
57
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
58 void yahoo_packet_hash(struct yahoo_packet *pkt, const char *fmt, ...)
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
59 {
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
60 char *strval;
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
61 int key, intval;
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
62 const char *cur;
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
63 va_list ap;
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
64
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
65 va_start(ap, fmt);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
66 for (cur = fmt; *cur; cur++) {
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
67 key = va_arg(ap, int);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
68 switch (*cur) {
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
69 case 'i':
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
70 intval = va_arg(ap, int);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
71 yahoo_packet_hash_int(pkt, key, intval);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
72 break;
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
73 case 's':
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
74 strval = va_arg(ap, char *);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
75 yahoo_packet_hash_str(pkt, key, strval);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
76 break;
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
77 default:
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
78 gaim_debug_error("yahoo", "Invalid format character '%c'\n", *cur);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
79 break;
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
80 }
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
81 }
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
82 va_end(ap);
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
83 }
45a0a07e8b25 [gaim-migrate @ 11623]
Tim Ringenbach <marv@pidgin.im>
parents: 10392
diff changeset
84
13276
d6a799421657 [gaim-migrate @ 15642]
Richard Laager <rlaager@wiktel.com>
parents: 13275
diff changeset
85 size_t yahoo_packet_length(struct yahoo_packet *pkt)
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
86 {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
87 GSList *l;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
88
13276
d6a799421657 [gaim-migrate @ 15642]
Richard Laager <rlaager@wiktel.com>
parents: 13275
diff changeset
89 size_t len = 0;
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
90
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
91 l = pkt->hash;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
92 while (l) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
93 struct yahoo_pair *pair = l->data;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
94 int tmp = pair->key;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
95 do {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
96 tmp /= 10;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
97 len++;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
98 } while (tmp);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
99 len += 2;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
100 len += strlen(pair->value);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
101 len += 2;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
102 l = l->next;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
103 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
104
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
105 return len;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
106 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
107
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
108 void yahoo_packet_read(struct yahoo_packet *pkt, const guchar *data, int len)
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
109 {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
110 int pos = 0;
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
111 char key[64], *delimiter, *esc;
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
112 gboolean accept;
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
113 int x;
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
114 struct yahoo_pair *pair;
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
115
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
116 while (pos + 1 < len)
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
117 {
13827
6c3c8d0d389f [gaim-migrate @ 16271]
Mark Doliner <mark@kingant.net>
parents: 13276
diff changeset
118 /* this is weird, and in one of the chat packets, and causes us to
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
119 * think all the values are keys and all the keys are values after
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
120 * this point if we don't handle it */
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
121 if (data[pos] == '\0') {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
122 while (pos + 1 < len) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
123 if (data[pos] == 0xc0 && data[pos + 1] == 0x80)
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
124 break;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
125 pos++;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
126 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
127 pos += 2;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
128 continue;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
129 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
130
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
131 pair = g_new0(struct yahoo_pair, 1);
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
132
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
133 x = 0;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
134 while (pos + 1 < len) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
135 if (data[pos] == 0xc0 && data[pos + 1] == 0x80)
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
136 break;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
137 if (x >= sizeof(key)-1) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
138 x++;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
139 pos++;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
140 continue;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
141 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
142 key[x++] = data[pos++];
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
143 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
144 if (x >= sizeof(key)-1) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
145 x = 0;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
146 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
147 key[x] = 0;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
148 pos += 2;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
149 pair->key = strtol(key, NULL, 10);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
150 accept = x; /* if x is 0 there was no key, so don't accept it */
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
151
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
152 if (len - pos + 1 <= 0) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
153 /* Truncated. Garbage or something. */
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
154 accept = FALSE;
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
155 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
156
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
157 if (accept) {
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
158 delimiter = strstr((char *)&data[pos], "\xc0\x80");
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
159 if (delimiter == NULL)
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
160 {
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
161 /* Malformed packet! (it doesn't end in 0xc0 0x80) */
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
162 g_free(pair);
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
163 pos = len;
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
164 continue;
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
165 }
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
166 x = (guint64)delimiter - (guint64)data;
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
167 pair->value = g_strndup((const gchar *)&data[pos], x - pos);
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
168 pos = x;
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
169 pkt->hash = g_slist_prepend(pkt->hash, pair);
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
170
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
171 #ifdef DEBUG
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
172 esc = g_strescape(pair->value, NULL);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
173 gaim_debug(GAIM_DEBUG_MISC, "yahoo",
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
174 "Key: %d \tValue: %s\n", pair->key, esc);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
175 g_free(esc);
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
176 #endif
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
177 } else {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
178 g_free(pair);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
179 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
180 pos += 2;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
181
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
182 /* Skip over garbage we've noticed in the mail notifications */
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
183 if (data[0] == '9' && data[pos] == 0x01)
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
184 pos++;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
185 }
14033
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
186
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
187 /*
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
188 * Originally this function used g_slist_append(). I changed
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
189 * it to use g_slist_prepend() for improved performance.
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
190 * Ideally the Yahoo! PRPL code would be indifferent to the
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
191 * order of the key/value pairs, but I don't know if this is
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
192 * the case for all incoming messages. To be on the safe side
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
193 * we reverse the list.
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
194 */
c070fdec12a3 [gaim-migrate @ 16635]
Mark Doliner <mark@kingant.net>
parents: 13827
diff changeset
195 pkt->hash = g_slist_reverse(pkt->hash);
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
196 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
197
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
198 void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data)
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
199 {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
200 GSList *l = pkt->hash;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
201 int pos = 0;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
202
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
203 while (l) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
204 struct yahoo_pair *pair = l->data;
11161
2e71eddc828b [gaim-migrate @ 13249]
Mark Doliner <mark@kingant.net>
parents: 10394
diff changeset
205 gchar buf[100];
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
206
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
207 g_snprintf(buf, sizeof(buf), "%d", pair->key);
11161
2e71eddc828b [gaim-migrate @ 13249]
Mark Doliner <mark@kingant.net>
parents: 10394
diff changeset
208 strcpy((char *)&data[pos], buf);
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
209 pos += strlen(buf);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
210 data[pos++] = 0xc0;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
211 data[pos++] = 0x80;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
212
11161
2e71eddc828b [gaim-migrate @ 13249]
Mark Doliner <mark@kingant.net>
parents: 10394
diff changeset
213 strcpy((char *)&data[pos], pair->value);
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
214 pos += strlen(pair->value);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
215 data[pos++] = 0xc0;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
216 data[pos++] = 0x80;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
217
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
218 l = l->next;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
219 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
220 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
221
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
222 void yahoo_packet_dump(guchar *data, int len)
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
223 {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
224 #ifdef YAHOO_DEBUG
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
225 int i;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
226
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
227 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "");
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
228
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
229 for (i = 0; i + 1 < len; i += 2) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
230 if ((i % 16 == 0) && i) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
231 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n");
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
232 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "");
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
233 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
234
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
235 gaim_debug(GAIM_DEBUG_MISC, NULL, "%02x%02x ", data[i], data[i + 1]);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
236 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
237 if (i < len)
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
238 gaim_debug(GAIM_DEBUG_MISC, NULL, "%02x", data[i]);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
239
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
240 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n");
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
241 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "");
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
242
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
243 for (i = 0; i < len; i++) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
244 if ((i % 16 == 0) && i) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
245 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n");
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
246 gaim_debug(GAIM_DEBUG_MISC, "yahoo", "");
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
247 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
248
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
249 if (g_ascii_isprint(data[i]))
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
250 gaim_debug(GAIM_DEBUG_MISC, NULL, "%c ", data[i]);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
251 else
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
252 gaim_debug(GAIM_DEBUG_MISC, NULL, ". ");
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
253 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
254
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
255 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n");
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
256 #endif
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
257 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
258
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
259 static void
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
260 yahoo_packet_send_can_write(gpointer data, gint source, GaimInputCondition cond)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
261 {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
262 struct yahoo_data *yd = data;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
263 int ret, writelen;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
264
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
265 writelen = gaim_circ_buffer_get_max_read(yd->txbuf);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
266
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
267 if (writelen == 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
268 gaim_input_remove(yd->txhandler);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
269 yd->txhandler = -1;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
270 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
271 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
272
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
273 ret = write(yd->fd, yd->txbuf->outptr, writelen);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
274
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
275 if (ret < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
276 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
277 else if (ret < 0) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
278 /* TODO: what to do here - do we really have to disconnect? */
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
279 gaim_connection_error(yd->gc, _("Write Error"));
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
280 return;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
281 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
282
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
283 gaim_circ_buffer_mark_read(yd->txbuf, ret);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
284 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
285
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
286
13276
d6a799421657 [gaim-migrate @ 15642]
Richard Laager <rlaager@wiktel.com>
parents: 13275
diff changeset
287 size_t yahoo_packet_build(struct yahoo_packet *pkt, int pad, gboolean wm,
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
288 guchar **buf)
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
289 {
13276
d6a799421657 [gaim-migrate @ 15642]
Richard Laager <rlaager@wiktel.com>
parents: 13275
diff changeset
290 size_t pktlen = yahoo_packet_length(pkt);
d6a799421657 [gaim-migrate @ 15642]
Richard Laager <rlaager@wiktel.com>
parents: 13275
diff changeset
291 size_t len = YAHOO_PACKET_HDRLEN + pktlen;
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
292 guchar *data;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
293 int pos = 0;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
294
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
295 data = g_malloc0(len + 1);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
296
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
297 memcpy(data + pos, "YMSG", 4); pos += 4;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
298
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
299 if (wm)
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
300 pos += yahoo_put16(data + pos, YAHOO_WEBMESSENGER_PROTO_VER);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
301 else
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
302 pos += yahoo_put16(data + pos, YAHOO_PROTO_VER);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
303 pos += yahoo_put16(data + pos, 0x0000);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
304 pos += yahoo_put16(data + pos, pktlen + pad);
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
305 pos += yahoo_put16(data + pos, pkt->service);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
306 pos += yahoo_put32(data + pos, pkt->status);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
307 pos += yahoo_put32(data + pos, pkt->id);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
308
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
309 yahoo_packet_write(pkt, data + pos);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
310
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
311 *buf = data;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
312
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
313 return len;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
314 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
315
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
316 int yahoo_packet_send(struct yahoo_packet *pkt, struct yahoo_data *yd)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
317 {
13276
d6a799421657 [gaim-migrate @ 15642]
Richard Laager <rlaager@wiktel.com>
parents: 13275
diff changeset
318 size_t len;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
319 int ret;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
320 guchar *data;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
321
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
322 if (yd->fd < 0)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
323 return -1;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
324
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
325 len = yahoo_packet_build(pkt, 0, yd->wm, &data);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
326
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
327 yahoo_packet_dump(data, len);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
328 if (yd->txhandler == -1)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
329 ret = write(yd->fd, data, len);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
330 else {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
331 ret = -1;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
332 errno = EAGAIN;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
333 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
334
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
335 if (ret < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
336 ret = 0;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
337 else if (ret <= 0) {
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
338 gaim_debug_warning("yahoo", "Only wrote %d of %d bytes!", ret, len);
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
339 g_free(data);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
340 return ret;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
341 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
342
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
343 if (ret < len) {
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
344 if (yd->txhandler == -1)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
345 yd->txhandler = gaim_input_add(yd->fd, GAIM_INPUT_WRITE,
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
346 yahoo_packet_send_can_write, yd);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
347 gaim_circ_buffer_append(yd->txbuf, data + ret, len - ret);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
348 }
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 11644
diff changeset
349
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
350 g_free(data);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
351
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
352 return ret;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
353 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
354
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
355 int yahoo_packet_send_and_free(struct yahoo_packet *pkt, struct yahoo_data *yd)
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
356 {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
357 int ret;
11644
f4e58e94ced3 [gaim-migrate @ 13922]
Mark Doliner <mark@kingant.net>
parents: 11161
diff changeset
358
10392
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
359 ret = yahoo_packet_send(pkt, yd);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
360 yahoo_packet_free(pkt);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
361 return ret;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
362 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
363
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
364 void yahoo_packet_free(struct yahoo_packet *pkt)
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
365 {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
366 while (pkt->hash) {
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
367 struct yahoo_pair *pair = pkt->hash->data;
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
368 g_free(pair->value);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
369 g_free(pair);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
370 pkt->hash = g_slist_remove(pkt->hash, pair);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
371 }
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
372 g_free(pkt);
a8f9e5ce4f92 [gaim-migrate @ 11620]
Tim Ringenbach <marv@pidgin.im>
parents:
diff changeset
373 }