Sun, 16 Mar 2008 20:36:52 +0000
Fix a bunch of compiler warnings caused by my addition of G_GNUC_PRINTF()
to our debug functions (I really thought we had added that in a while ago?)
I didn't fix all of them... just most of them.
Oh, see these pages for a little info:
http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
http://library.gnome.org/devel/glib/unstable/glib-Miscellaneous-Macros.html#G-GNUC-PRINTF:CAPS
| 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 | ||
| 27 | #include "yahoo.h" | |
| 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 | |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
190 | #ifdef DEBUG |
| 14321 | 191 | { |
| 192 | char *esc; | |
| 193 | esc = g_strescape(pair->value, NULL); | |
| 15884 | 194 | purple_debug(PURPLE_DEBUG_MISC, "yahoo", |
| 14321 | 195 | "Key: %d \tValue: %s\n", pair->key, esc); |
| 196 | g_free(esc); | |
| 197 | } | |
|
14095
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
198 | #endif |
| 10392 | 199 | } else { |
| 200 | g_free(pair); | |
| 201 | } | |
| 202 | pos += 2; | |
| 203 | ||
| 204 | /* Skip over garbage we've noticed in the mail notifications */ | |
| 205 | if (data[0] == '9' && data[pos] == 0x01) | |
| 206 | pos++; | |
| 207 | } | |
|
14095
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 | /* |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
210 | * Originally this function used g_slist_append(). I changed |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
211 | * it to use g_slist_prepend() for improved performance. |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
212 | * Ideally the Yahoo! PRPL code would be indifferent to the |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
213 | * 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
|
214 | * 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
|
215 | * we reverse the list. |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
216 | */ |
|
125eacb85b5f
[gaim-migrate @ 16635]
Mark Doliner <markdoliner@pidgin.im>
parents:
13829
diff
changeset
|
217 | pkt->hash = g_slist_reverse(pkt->hash); |
| 10392 | 218 | } |
| 219 | ||
| 220 | void yahoo_packet_write(struct yahoo_packet *pkt, guchar *data) | |
| 221 | { | |
|
21693
d726f725f088
Original patch from Andrew Gaul to fix a leak.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21690
diff
changeset
|
222 | GSList *l; |
| 10392 | 223 | int pos = 0; |
| 224 | ||
|
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
|
225 | /* 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
|
226 | * 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
|
227 | |
|
21693
d726f725f088
Original patch from Andrew Gaul to fix a leak.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21690
diff
changeset
|
228 | 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
|
229 | |
|
21690
844340836efe
disapproval of revision '36cc15c1b76afc0262b3cb9181a7664fbbd5b6c1'
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21689
diff
changeset
|
230 | while (l) { |
|
844340836efe
disapproval of revision '36cc15c1b76afc0262b3cb9181a7664fbbd5b6c1'
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21689
diff
changeset
|
231 | struct yahoo_pair *pair = l->data; |
|
11161
f9272f277000
[gaim-migrate @ 13249]
Mark Doliner <markdoliner@pidgin.im>
parents:
10394
diff
changeset
|
232 | gchar buf[100]; |
| 10392 | 233 | |
| 234 | g_snprintf(buf, sizeof(buf), "%d", pair->key); | |
|
11161
f9272f277000
[gaim-migrate @ 13249]
Mark Doliner <markdoliner@pidgin.im>
parents:
10394
diff
changeset
|
235 | strcpy((char *)&data[pos], buf); |
| 10392 | 236 | pos += strlen(buf); |
| 237 | data[pos++] = 0xc0; | |
| 238 | data[pos++] = 0x80; | |
| 239 | ||
|
11161
f9272f277000
[gaim-migrate @ 13249]
Mark Doliner <markdoliner@pidgin.im>
parents:
10394
diff
changeset
|
240 | strcpy((char *)&data[pos], pair->value); |
| 10392 | 241 | pos += strlen(pair->value); |
| 242 | data[pos++] = 0xc0; | |
| 243 | data[pos++] = 0x80; | |
| 244 | ||
|
21690
844340836efe
disapproval of revision '36cc15c1b76afc0262b3cb9181a7664fbbd5b6c1'
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
21689
diff
changeset
|
245 | l = l->next; |
| 10392 | 246 | } |
| 247 | } | |
| 248 | ||
| 249 | void yahoo_packet_dump(guchar *data, int len) | |
| 250 | { | |
| 251 | #ifdef YAHOO_DEBUG | |
| 252 | int i; | |
| 253 | ||
| 15884 | 254 | purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); |
| 10392 | 255 | |
| 256 | for (i = 0; i + 1 < len; i += 2) { | |
| 257 | if ((i % 16 == 0) && i) { | |
| 15884 | 258 | purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); |
| 259 | purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); | |
| 10392 | 260 | } |
| 261 | ||
| 15884 | 262 | purple_debug(PURPLE_DEBUG_MISC, NULL, "%02x%02x ", data[i], data[i + 1]); |
| 10392 | 263 | } |
| 264 | if (i < len) | |
| 15884 | 265 | purple_debug(PURPLE_DEBUG_MISC, NULL, "%02x", data[i]); |
| 10392 | 266 | |
| 15884 | 267 | purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); |
| 268 | purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); | |
| 10392 | 269 | |
| 270 | for (i = 0; i < len; i++) { | |
| 271 | if ((i % 16 == 0) && i) { | |
| 15884 | 272 | purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); |
| 273 | purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); | |
| 10392 | 274 | } |
| 275 | ||
| 276 | if (g_ascii_isprint(data[i])) | |
| 15884 | 277 | purple_debug(PURPLE_DEBUG_MISC, NULL, "%c ", data[i]); |
| 10392 | 278 | else |
| 15884 | 279 | purple_debug(PURPLE_DEBUG_MISC, NULL, ". "); |
| 10392 | 280 | } |
| 281 | ||
| 15884 | 282 | purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); |
| 10392 | 283 | #endif |
| 284 | } | |
| 285 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
286 | static void |
| 15884 | 287 | 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
|
288 | { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
289 | struct yahoo_data *yd = data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
290 | int ret, writelen; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
291 | |
| 15884 | 292 | writelen = purple_circ_buffer_get_max_read(yd->txbuf); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
293 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
294 | if (writelen == 0) { |
| 15884 | 295 | 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
|
296 | yd->txhandler = 0; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
297 | return; |
|
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 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
300 | ret = write(yd->fd, yd->txbuf->outptr, writelen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
301 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
302 | if (ret < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
303 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
304 | else if (ret < 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
305 | /* TODO: what to do here - do we really have to disconnect? */ |
| 21279 | 306 | 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
|
307 | _("Write Error")); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
308 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
309 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
310 | |
| 15884 | 311 | purple_circ_buffer_mark_read(yd->txbuf, ret); |
|
13201
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 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
314 | |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
315 | 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
|
316 | gboolean jp, guchar **buf) |
| 10392 | 317 | { |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
318 | size_t pktlen = yahoo_packet_length(pkt); |
|
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
319 | size_t len = YAHOO_PACKET_HDRLEN + pktlen; |
| 10392 | 320 | guchar *data; |
| 321 | int pos = 0; | |
| 322 | ||
| 323 | data = g_malloc0(len + 1); | |
| 324 | ||
| 325 | memcpy(data + pos, "YMSG", 4); pos += 4; | |
| 326 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
327 | if (wm) |
| 10392 | 328 | pos += yahoo_put16(data + pos, YAHOO_WEBMESSENGER_PROTO_VER); |
|
14508
02d80a119d80
[gaim-migrate @ 17160]
Evan Schoenberg <evands@pidgin.im>
parents:
14322
diff
changeset
|
329 | else if (jp) |
|
02d80a119d80
[gaim-migrate @ 17160]
Evan Schoenberg <evands@pidgin.im>
parents:
14322
diff
changeset
|
330 | pos += yahoo_put16(data + pos, YAHOO_PROTO_VER_JAPAN); |
| 10392 | 331 | else |
| 332 | pos += yahoo_put16(data + pos, YAHOO_PROTO_VER); | |
| 333 | pos += yahoo_put16(data + pos, 0x0000); | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
334 | pos += yahoo_put16(data + pos, pktlen + pad); |
| 10392 | 335 | pos += yahoo_put16(data + pos, pkt->service); |
| 336 | pos += yahoo_put32(data + pos, pkt->status); | |
| 337 | pos += yahoo_put32(data + pos, pkt->id); | |
| 338 | ||
| 339 | yahoo_packet_write(pkt, data + pos); | |
| 340 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
341 | *buf = data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
342 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
343 | return len; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
344 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
345 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
346 | int yahoo_packet_send(struct yahoo_packet *pkt, struct yahoo_data *yd) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
347 | { |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13276
diff
changeset
|
348 | size_t len; |
|
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
|
349 | ssize_t ret; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
350 | guchar *data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
351 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
352 | if (yd->fd < 0) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
353 | return -1; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
354 | |
|
14508
02d80a119d80
[gaim-migrate @ 17160]
Evan Schoenberg <evands@pidgin.im>
parents:
14322
diff
changeset
|
355 | 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
|
356 | |
| 10392 | 357 | 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
|
358 | if (yd->txhandler == 0) |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
359 | ret = write(yd->fd, data, len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
360 | else { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
361 | ret = -1; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
362 | errno = EAGAIN; |
|
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 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
365 | if (ret < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
366 | ret = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
367 | 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
|
368 | 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
|
369 | " of %" G_GSIZE_FORMAT " bytes!\n", ret, len); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
370 | g_free(data); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
371 | return ret; |
|
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 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
374 | 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
|
375 | if (yd->txhandler == 0) |
| 15884 | 376 | yd->txhandler = purple_input_add(yd->fd, PURPLE_INPUT_WRITE, |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
377 | yahoo_packet_send_can_write, yd); |
| 15884 | 378 | purple_circ_buffer_append(yd->txbuf, data + ret, len - ret); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
379 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
11644
diff
changeset
|
380 | |
| 10392 | 381 | g_free(data); |
| 382 | ||
| 383 | return ret; | |
| 384 | } | |
| 385 | ||
| 386 | int yahoo_packet_send_and_free(struct yahoo_packet *pkt, struct yahoo_data *yd) | |
| 387 | { | |
| 388 | int ret; | |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11161
diff
changeset
|
389 | |
| 10392 | 390 | ret = yahoo_packet_send(pkt, yd); |
| 391 | yahoo_packet_free(pkt); | |
| 392 | return ret; | |
| 393 | } | |
| 394 | ||
| 395 | void yahoo_packet_free(struct yahoo_packet *pkt) | |
| 396 | { | |
| 397 | while (pkt->hash) { | |
| 398 | struct yahoo_pair *pair = pkt->hash->data; | |
| 399 | g_free(pair->value); | |
| 400 | g_free(pair); | |
| 401 | pkt->hash = g_slist_remove(pkt->hash, pair); | |
| 402 | } | |
| 403 | g_free(pkt); | |
| 404 | } |