Thu, 27 Aug 2009 18:46:55 +0000
propagate from branch 'im.pidgin.pidgin' (head b32e60758f77c4052e23cd9def2f334da7f4b4eb)
to branch 'im.pidgin.cpw.malu.ft_thumbnails' (head 0581a605cdcce14dca7cbeaab8e5e6ce77daeb24)
| 10392 | 1 | /* |
| 15884 | 2 | * purple |
| 10392 | 3 | * |
| 15884 | 4 | * Purple is the legal property of its developers, whose names are too numerous |
| 10392 | 5 | * to list here. Please refer to the COPYRIGHT file distributed with this |
| 6 | * source distribution. | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19832
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 10392 | 21 | * |
| 22 | */ | |
| 23 | ||
| 24 | #include "internal.h" | |
| 25 | #include "debug.h" | |
| 26 | ||
|
27555
afb7cb5c350c
Update for file renames.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27547
diff
changeset
|
27 | #include "libymsg.h" |
| 10392 | 28 | #include "yahoo_packet.h" |
| 29 | ||
| 30 | struct yahoo_packet *yahoo_packet_new(enum yahoo_service service, enum yahoo_status status, int id) | |
| 31 | { | |
| 32 | struct yahoo_packet *pkt = g_new0(struct yahoo_packet, 1); | |
| 33 | ||
| 34 | pkt->service = service; | |
| 35 | pkt->status = status; | |
| 36 | pkt->id = id; | |
| 37 | ||
| 38 | return pkt; | |
| 39 | } | |
| 40 | ||
| 10394 | 41 | void yahoo_packet_hash_str(struct yahoo_packet *pkt, int key, const char *value) |
| 10392 | 42 | { |
|
14204
6ee6b82a7c49
[gaim-migrate @ 16784]
Mark Doliner <markdoliner@pidgin.im>
parents:
14095
diff
changeset
|
43 | struct yahoo_pair *pair; |
|
6ee6b82a7c49
[gaim-migrate @ 16784]
Mark Doliner <markdoliner@pidgin.im>
parents:
14095
diff
changeset
|
44 | |
|
6ee6b82a7c49
[gaim-migrate @ 16784]
Mark Doliner <markdoliner@pidgin.im>
parents:
14095
diff
changeset
|
45 | g_return_if_fail(value != NULL); |
|
6ee6b82a7c49
[gaim-migrate @ 16784]
Mark Doliner <markdoliner@pidgin.im>
parents:
14095
diff
changeset
|
46 | |
|
6ee6b82a7c49
[gaim-migrate @ 16784]
Mark Doliner <markdoliner@pidgin.im>
parents:
14095
diff
changeset
|
47 | pair = g_new0(struct yahoo_pair, 1); |
| 10392 | 48 | pair->key = key; |
| 49 | pair->value = g_strdup(value); | |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
50 | pkt->hash = g_slist_prepend(pkt->hash, pair); |
| 10392 | 51 | } |
| 52 | ||
| 10394 | 53 | void yahoo_packet_hash_int(struct yahoo_packet *pkt, int key, int value) |
| 54 | { | |
|
14204
6ee6b82a7c49
[gaim-migrate @ 16784]
Mark Doliner <markdoliner@pidgin.im>
parents:
14095
diff
changeset
|
55 | struct yahoo_pair *pair; |
| 10394 | 56 | |
|
14204
6ee6b82a7c49
[gaim-migrate @ 16784]
Mark Doliner <markdoliner@pidgin.im>
parents:
14095
diff
changeset
|
57 | pair = g_new0(struct yahoo_pair, 1); |
| 10394 | 58 | pair->key = key; |
| 59 | pair->value = g_strdup_printf("%d", value); | |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
60 | pkt->hash = g_slist_prepend(pkt->hash, pair); |
| 10394 | 61 | } |
| 62 | ||
| 63 | void yahoo_packet_hash(struct yahoo_packet *pkt, const char *fmt, ...) | |
| 64 | { | |
| 65 | char *strval; | |
| 66 | int key, intval; | |
| 67 | const char *cur; | |
| 68 | va_list ap; | |
| 69 | ||
| 70 | va_start(ap, fmt); | |
| 71 | for (cur = fmt; *cur; cur++) { | |
| 72 | key = va_arg(ap, int); | |
| 73 | switch (*cur) { | |
| 74 | case 'i': | |
| 75 | intval = va_arg(ap, int); | |
| 76 | yahoo_packet_hash_int(pkt, key, intval); | |
| 77 | break; | |
| 78 | case 's': | |
| 79 | strval = va_arg(ap, char *); | |
| 80 | yahoo_packet_hash_str(pkt, key, strval); | |
| 81 | break; | |
| 82 | default: | |
| 15884 | 83 | purple_debug_error("yahoo", "Invalid format character '%c'\n", *cur); |
| 10394 | 84 | break; |
| 85 | } | |
| 86 | } | |
| 87 | va_end(ap); | |
| 88 | } | |
| 89 | ||
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
90 | size_t yahoo_packet_length(struct yahoo_packet *pkt) |
| 10392 | 91 | { |
| 92 | GSList *l; | |
| 93 | ||
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
94 | size_t len = 0; |
| 10392 | 95 | |
| 96 | l = pkt->hash; | |
| 97 | while (l) { | |
| 98 | struct yahoo_pair *pair = l->data; | |
| 99 | int tmp = pair->key; | |
| 100 | do { | |
| 101 | tmp /= 10; | |
| 102 | len++; | |
| 103 | } while (tmp); | |
| 104 | len += 2; | |
| 105 | len += strlen(pair->value); | |
| 106 | len += 2; | |
| 107 | l = l->next; | |
| 108 | } | |
| 109 | ||
| 110 | return len; | |
| 111 | } | |
| 112 | ||
|
17577
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
113 | /* |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
114 | * 'len' is the value given to us by the server that is supposed to |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
115 | * be the length of 'data'. But apparently there's a time when this |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
116 | * length is incorrect. Christopher Layne thinks it might be a bug |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
117 | * in their server code. |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
118 | * |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
119 | * The following information is from Christopher: |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
120 | * |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
121 | * It sometimes happens when Yahoo! sends a packet continuation within |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
122 | * chat. Sometimes when joining a large chatroom the initial |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
123 | * SERVICE_CHATJOIN packet will be so large that it will need to be |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
124 | * split into multiple packets. That's fine, except that the length |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
125 | * of the second packet is wrong. The packet has the same length as |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
126 | * the first packet, and the length given in the header is the same, |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
127 | * however the actual data in the packet is shorter than this length. |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
128 | * So half of the packet contains good, valid data, and then the rest |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
129 | * of the packet is junk. Luckily there is a null terminator after |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
130 | * the valid data and before the invalid data. |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
131 | * |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
132 | * What does all this mean? It means that we parse through the data |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
133 | * pulling out key/value pairs until we've parsed 'len' bytes, or until |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
134 | * we run into a null terminator, whichever comes first. |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
135 | */ |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
136 | void yahoo_packet_read(struct yahoo_packet *pkt, const guchar *data, int len) |
| 10392 | 137 | { |
| 138 | int pos = 0; | |
|
14322
662704dffc4d
[gaim-migrate @ 16942]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
139 | char key[64]; |
|
662704dffc4d
[gaim-migrate @ 16942]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
140 | const guchar *delimiter; |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
141 | gboolean accept; |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
142 | int x; |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
143 | struct yahoo_pair *pair; |
| 10392 | 144 | |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
145 | while (pos + 1 < len) |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
146 | { |
|
17577
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
147 | if (data[pos] == '\0') |
|
c98f95792cbc
Christopher Layne tells me that a null in a Yahoo packet where we
Mark Doliner <markdoliner@pidgin.im>
parents:
15982
diff
changeset
|
148 | break; |
| 10392 | 149 | |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
150 | pair = g_new0(struct yahoo_pair, 1); |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
151 | |
| 10392 | 152 | x = 0; |
| 153 | while (pos + 1 < len) { | |
| 154 | if (data[pos] == 0xc0 && data[pos + 1] == 0x80) | |
| 155 | break; | |
| 156 | if (x >= sizeof(key)-1) { | |
| 157 | x++; | |
| 158 | pos++; | |
| 159 | continue; | |
| 160 | } | |
| 161 | key[x++] = data[pos++]; | |
| 162 | } | |
| 163 | if (x >= sizeof(key)-1) { | |
| 164 | x = 0; | |
| 165 | } | |
| 166 | key[x] = 0; | |
| 167 | pos += 2; | |
| 168 | pair->key = strtol(key, NULL, 10); | |
| 169 | accept = x; /* if x is 0 there was no key, so don't accept it */ | |
| 170 | ||
|
15283
efefd3bf8b81
[gaim-migrate @ 18011]
Mark Doliner <markdoliner@pidgin.im>
parents:
15276
diff
changeset
|
171 | if (pos + 1 > len) { |
|
efefd3bf8b81
[gaim-migrate @ 18011]
Mark Doliner <markdoliner@pidgin.im>
parents:
15276
diff
changeset
|
172 | /* Malformed packet! (Truncated--garbage or something) */ |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
173 | accept = FALSE; |
| 10392 | 174 | } |
| 175 | ||
| 176 | if (accept) { | |
|
20286
629c12d9254c
applied changes from 1d36a128301cae57a790a087aa9c4ad8d71dad52
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19859
diff
changeset
|
177 | delimiter = (const guchar *)g_strstr_len((const char *)&data[pos], len - pos, "\xc0\x80"); |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
178 | if (delimiter == NULL) |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
179 | { |
|
15283
efefd3bf8b81
[gaim-migrate @ 18011]
Mark Doliner <markdoliner@pidgin.im>
parents:
15276
diff
changeset
|
180 | /* Malformed packet! (It doesn't end in 0xc0 0x80) */ |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
181 | g_free(pair); |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
182 | pos = len; |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
183 | continue; |
| 10392 | 184 | } |
|
14322
662704dffc4d
[gaim-migrate @ 16942]
Mark Doliner <markdoliner@pidgin.im>
parents:
14321
diff
changeset
|
185 | x = delimiter - data; |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
186 | pair->value = g_strndup((const gchar *)&data[pos], x - pos); |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
187 | pos = x; |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
188 | pkt->hash = g_slist_prepend(pkt->hash, pair); |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
189 | |
|
27716
a3ed37ab91b8
Allow setting some personal information for an account.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
27555
diff
changeset
|
190 | if (purple_debug_is_verbose() || g_getenv("PURPLE_YAHOO_DEBUG")) { |
| 14321 | 191 | char *esc; |
| 192 | esc = g_strescape(pair->value, NULL); | |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
193 | purple_debug_misc("yahoo", "Key: %d \tValue: %s\n", pair->key, esc); |
| 14321 | 194 | g_free(esc); |
| 195 | } | |
| 10392 | 196 | } else { |
| 197 | g_free(pair); | |
| 198 | } | |
| 199 | pos += 2; | |
| 200 | ||
| 26549 | 201 | if (pos + 1 > len) break; |
| 202 | ||
| 10392 | 203 | /* Skip over garbage we've noticed in the mail notifications */ |
| 204 | if (data[0] == '9' && data[pos] == 0x01) | |
| 205 | pos++; | |
| 206 | } | |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
207 | |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
208 | /* |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
209 | * Originally this function used g_slist_append(). I changed |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
210 | * it to use g_slist_prepend() for improved performance. |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
211 | * Ideally the Yahoo! PRPL code would be indifferent to the |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
212 | * order of the key/value pairs, but I don't know if this is |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
213 | * the case for all incoming messages. To be on the safe side |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
214 | * we reverse the list. |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
215 | */ |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
216 | pkt->hash = g_slist_reverse(pkt->hash); |
| 10392 | 217 | } |
| 218 | ||
| 219 | void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data) | |
| 220 | { | |
|
21693
d726f725f088
Original patch from Andrew Gaul to fix a leak.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21690
diff
changeset
|
221 | GSList *l; |
| 10392 | 222 | int pos = 0; |
| 223 | ||
|
19328
8875a4424cb1
Reverse the key/value pairs as they go out, so that they're in the correct
Tim Ringenbach <marv@pidgin.im>
parents:
17577
diff
changeset
|
224 | /* This is only called from one place, and the list is |
|
8875a4424cb1
Reverse the key/value pairs as they go out, so that they're in the correct
Tim Ringenbach <marv@pidgin.im>
parents:
17577
diff
changeset
|
225 | * always backwards */ |
|
8875a4424cb1
Reverse the key/value pairs as they go out, so that they're in the correct
Tim Ringenbach <marv@pidgin.im>
parents:
17577
diff
changeset
|
226 | |
|
21693
d726f725f088
Original patch from Andrew Gaul to fix a leak.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21690
diff
changeset
|
227 | l = pkt->hash = g_slist_reverse(pkt->hash); |
|
19328
8875a4424cb1
Reverse the key/value pairs as they go out, so that they're in the correct
Tim Ringenbach <marv@pidgin.im>
parents:
17577
diff
changeset
|
228 | |
|
21690
844340836efe
disapproval of revision '36cc15c1b76afc0262b3cb9181a7664fbbd5b6c1'
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21689
diff
changeset
|
229 | while (l) { |
|
844340836efe
disapproval of revision '36cc15c1b76afc0262b3cb9181a7664fbbd5b6c1'
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21689
diff
changeset
|
230 | struct yahoo_pair *pair = l->data; |
|
11161
f9272f277000
[gaim-migrate @ 13249]
Mark Doliner <markdoliner@pidgin.im>
parents:
10394
diff
changeset
|
231 | gchar buf[100]; |
| 10392 | 232 | |
| 233 | g_snprintf(buf, sizeof(buf), "%d", pair->key); | |
|
11161
f9272f277000
[gaim-migrate @ 13249]
Mark Doliner <markdoliner@pidgin.im>
parents:
10394
diff
changeset
|
234 | strcpy((char *)&data[pos], buf); |
| 10392 | 235 | pos += strlen(buf); |
| 236 | data[pos++] = 0xc0; | |
| 237 | data[pos++] = 0x80; | |
| 238 | ||
|
11161
f9272f277000
[gaim-migrate @ 13249]
Mark Doliner <markdoliner@pidgin.im>
parents:
10394
diff
changeset
|
239 | strcpy((char *)&data[pos], pair->value); |
| 10392 | 240 | pos += strlen(pair->value); |
| 241 | data[pos++] = 0xc0; | |
| 242 | data[pos++] = 0x80; | |
| 243 | ||
|
21690
844340836efe
disapproval of revision '36cc15c1b76afc0262b3cb9181a7664fbbd5b6c1'
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21689
diff
changeset
|
244 | l = l->next; |
| 10392 | 245 | } |
| 246 | } | |
| 247 | ||
| 248 | void yahoo_packet_dump(guchar *data, int len) | |
| 249 | { | |
| 250 | #ifdef YAHOO_DEBUG | |
| 251 | int i; | |
| 252 | ||
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
253 | purple_debug_misc("yahoo", ""); |
| 10392 | 254 | |
| 255 | for (i = 0; i + 1 < len; i += 2) { | |
| 256 | if ((i % 16 == 0) && i) { | |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
257 | purple_debug_misc(NULL, "\n"); |
|
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
258 | purple_debug_misc("yahoo", ""); |
| 10392 | 259 | } |
| 260 | ||
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
261 | purple_debug_misc(NULL, "%02x%02x ", data[i], data[i + 1]); |
| 10392 | 262 | } |
| 263 | if (i < len) | |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
264 | purple_debug_misc(NULL, "%02x", data[i]); |
| 10392 | 265 | |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
266 | purple_debug_misc(NULL, "\n"); |
|
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
267 | purple_debug_misc("yahoo", ""); |
| 10392 | 268 | |
| 269 | for (i = 0; i < len; i++) { | |
| 270 | if ((i % 16 == 0) && i) { | |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
271 | purple_debug_misc(NULL, "\n"); |
|
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
272 | purple_debug_misc("yahoo", ""); |
| 10392 | 273 | } |
| 274 | ||
| 275 | if (g_ascii_isprint(data[i])) | |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
276 | purple_debug_misc(NULL, "%c ", data[i]); |
| 10392 | 277 | else |
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
278 | purple_debug_misc(NULL, ". "); |
| 10392 | 279 | } |
| 280 | ||
|
27547
c136491361eb
Convert the yahoo prpl to using the debug convenience functions instead of
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27546
diff
changeset
|
281 | purple_debug_misc(NULL, "\n"); |
|
27335
06a805d4e690
Strip trailing whitespace and comment #endif marcos that close #ifdef macros
Mark Doliner <markdoliner@pidgin.im>
parents:
26549
diff
changeset
|
282 | #endif /* YAHOO_DEBUG */ |
| 10392 | 283 | } |
| 284 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
285 | static void |
| 15884 | 286 | yahoo_packet_send_can_write(gpointer data, gint source, PurpleInputCondition cond) |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
287 | { |
|
27959
f842ae57da4e
Move from "struct yahoo_data" to "YahooData" to be consistent with other structs
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27716
diff
changeset
|
288 | YahooData *yd = data; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
289 | int ret, writelen; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
290 | |
| 15884 | 291 | writelen = purple_circ_buffer_get_max_read(yd->txbuf); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
292 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
293 | if (writelen == 0) { |
| 15884 | 294 | purple_input_remove(yd->txhandler); |
|
19573
03c72c532d5a
Input handlers are unsigned integers. So set them to 0 instead of -1 after
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19328
diff
changeset
|
295 | yd->txhandler = 0; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
296 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
297 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
298 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
299 | ret = write(yd->fd, yd->txbuf->outptr, writelen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
300 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
301 | if (ret < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
302 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
303 | else if (ret < 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
304 | /* TODO: what to do here - do we really have to disconnect? */ |
| 21279 | 305 | purple_connection_error_reason(yd->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
|
20460
5282ce7ac330
Add disconnection reasons to yahoo
Will Thompson <resiak@pidgin.im>
parents:
19859
diff
changeset
|
306 | _("Write Error")); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
307 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
308 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
309 | |
| 15884 | 310 | purple_circ_buffer_mark_read(yd->txbuf, ret); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
311 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
312 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
313 | |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
314 | size_t yahoo_packet_build(struct yahoo_packet *pkt, int pad, gboolean wm, |
|
14508
02d80a119d80
[gaim-migrate @ 17160]
Evan Schoenberg <evands@pidgin.im>
parents:
14322
diff
changeset
|
315 | gboolean jp, guchar **buf) |
| 10392 | 316 | { |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
317 | size_t pktlen = yahoo_packet_length(pkt); |
|
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
318 | size_t len = YAHOO_PACKET_HDRLEN + pktlen; |
| 10392 | 319 | guchar *data; |
| 320 | int pos = 0; | |
| 321 | ||
| 322 | data = g_malloc0(len + 1); | |
| 323 | ||
| 324 | memcpy(data + pos, "YMSG", 4); pos += 4; | |
| 325 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
326 | if (wm) |
| 10392 | 327 | pos += yahoo_put16(data + pos, YAHOO_WEBMESSENGER_PROTO_VER); |
|
14508
02d80a119d80
[gaim-migrate @ 17160]
Evan Schoenberg <evands@pidgin.im>
parents:
14322
diff
changeset
|
328 | else if (jp) |
|
27335
06a805d4e690
Strip trailing whitespace and comment #endif marcos that close #ifdef macros
Mark Doliner <markdoliner@pidgin.im>
parents:
26549
diff
changeset
|
329 | pos += yahoo_put16(data + pos, YAHOO_PROTO_VER_JAPAN); |
| 10392 | 330 | else |
| 331 | pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); | |
| 332 | pos += yahoo_put16(data + pos, 0x0000); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
333 | pos += yahoo_put16(data + pos, pktlen + pad); |
| 10392 | 334 | pos += yahoo_put16(data + pos, pkt->service); |
| 335 | pos += yahoo_put32(data + pos, pkt->status); | |
| 336 | pos += yahoo_put32(data + pos, pkt->id); | |
| 337 | ||
| 338 | yahoo_packet_write(pkt, data + pos); | |
| 339 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
340 | *buf = data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
341 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
342 | return len; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
343 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
344 | |
|
27959
f842ae57da4e
Move from "struct yahoo_data" to "YahooData" to be consistent with other structs
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27716
diff
changeset
|
345 | int yahoo_packet_send(struct yahoo_packet *pkt, YahooData *yd) |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
346 | { |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
347 | size_t len; |
|
22709
6bd336964410
Printf warning fixes.
Daniel Atallah <datallah@pidgin.im>
parents:
22622
diff
changeset
|
348 | gssize ret; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
349 | guchar *data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
350 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
351 | if (yd->fd < 0) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
352 | return -1; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
353 | |
|
14508
02d80a119d80
[gaim-migrate @ 17160]
Evan Schoenberg <evands@pidgin.im>
parents:
14322
diff
changeset
|
354 | len = yahoo_packet_build(pkt, 0, yd->wm, yd->jp, &data); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
355 | |
| 10392 | 356 | yahoo_packet_dump(data, len); |
|
19573
03c72c532d5a
Input handlers are unsigned integers. So set them to 0 instead of -1 after
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19328
diff
changeset
|
357 | if (yd->txhandler == 0) |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
358 | ret = write(yd->fd, data, len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
359 | else { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
360 | ret = -1; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
361 | errno = EAGAIN; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
362 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
363 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
364 | if (ret < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
365 | ret = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
366 | else if (ret <= 0) { |
|
22622
1ecb840b5101
Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <markdoliner@pidgin.im>
parents:
21693
diff
changeset
|
367 | purple_debug_warning("yahoo", "Only wrote %" G_GSSIZE_FORMAT |
|
1ecb840b5101
Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
Mark Doliner <markdoliner@pidgin.im>
parents:
21693
diff
changeset
|
368 | " of %" G_GSIZE_FORMAT " bytes!\n", ret, len); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
369 | g_free(data); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
370 | return ret; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
371 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
372 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
373 | if (ret < len) { |
|
19573
03c72c532d5a
Input handlers are unsigned integers. So set them to 0 instead of -1 after
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
19328
diff
changeset
|
374 | if (yd->txhandler == 0) |
| 15884 | 375 | yd->txhandler = purple_input_add(yd->fd, PURPLE_INPUT_WRITE, |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
376 | yahoo_packet_send_can_write, yd); |
| 15884 | 377 | purple_circ_buffer_append(yd->txbuf, data + ret, len - ret); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
378 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
379 | |
| 10392 | 380 | g_free(data); |
| 381 | ||
| 382 | return ret; | |
| 383 | } | |
| 384 | ||
|
27959
f842ae57da4e
Move from "struct yahoo_data" to "YahooData" to be consistent with other structs
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
27716
diff
changeset
|
385 | int yahoo_packet_send_and_free(struct yahoo_packet *pkt, YahooData *yd) |
| 10392 | 386 | { |
| 387 | int ret; | |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11161
diff
changeset
|
388 | |
| 10392 | 389 | ret = yahoo_packet_send(pkt, yd); |
| 390 | yahoo_packet_free(pkt); | |
| 391 | return ret; | |
| 392 | } | |
| 393 | ||
| 394 | void yahoo_packet_free(struct yahoo_packet *pkt) | |
| 395 | { | |
| 396 | while (pkt->hash) { | |
| 397 | struct yahoo_pair *pair = pkt->hash->data; | |
| 398 | g_free(pair->value); | |
| 399 | g_free(pair); | |
|
28077
c2b493e058f1
Don't use pointers (even opaquely) once they're freed. Closes #9822.
Paul Aurich <darkrain42@pidgin.im>
parents:
27959
diff
changeset
|
400 | pkt->hash = g_slist_delete_link(pkt->hash, pkt->hash); |
| 10392 | 401 | } |
| 402 | g_free(pkt); | |
| 403 | } |