| 231 void yahoo_packet_dump(guchar *data, int len) |
231 void yahoo_packet_dump(guchar *data, int len) |
| 232 { |
232 { |
| 233 #ifdef YAHOO_DEBUG |
233 #ifdef YAHOO_DEBUG |
| 234 int i; |
234 int i; |
| 235 |
235 |
| 236 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); |
236 purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); |
| 237 |
237 |
| 238 for (i = 0; i + 1 < len; i += 2) { |
238 for (i = 0; i + 1 < len; i += 2) { |
| 239 if ((i % 16 == 0) && i) { |
239 if ((i % 16 == 0) && i) { |
| 240 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); |
240 purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); |
| 241 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); |
241 purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); |
| 242 } |
242 } |
| 243 |
243 |
| 244 gaim_debug(GAIM_DEBUG_MISC, NULL, "%02x%02x ", data[i], data[i + 1]); |
244 purple_debug(PURPLE_DEBUG_MISC, NULL, "%02x%02x ", data[i], data[i + 1]); |
| 245 } |
245 } |
| 246 if (i < len) |
246 if (i < len) |
| 247 gaim_debug(GAIM_DEBUG_MISC, NULL, "%02x", data[i]); |
247 purple_debug(PURPLE_DEBUG_MISC, NULL, "%02x", data[i]); |
| 248 |
248 |
| 249 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); |
249 purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); |
| 250 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); |
250 purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); |
| 251 |
251 |
| 252 for (i = 0; i < len; i++) { |
252 for (i = 0; i < len; i++) { |
| 253 if ((i % 16 == 0) && i) { |
253 if ((i % 16 == 0) && i) { |
| 254 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); |
254 purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); |
| 255 gaim_debug(GAIM_DEBUG_MISC, "yahoo", ""); |
255 purple_debug(PURPLE_DEBUG_MISC, "yahoo", ""); |
| 256 } |
256 } |
| 257 |
257 |
| 258 if (g_ascii_isprint(data[i])) |
258 if (g_ascii_isprint(data[i])) |
| 259 gaim_debug(GAIM_DEBUG_MISC, NULL, "%c ", data[i]); |
259 purple_debug(PURPLE_DEBUG_MISC, NULL, "%c ", data[i]); |
| 260 else |
260 else |
| 261 gaim_debug(GAIM_DEBUG_MISC, NULL, ". "); |
261 purple_debug(PURPLE_DEBUG_MISC, NULL, ". "); |
| 262 } |
262 } |
| 263 |
263 |
| 264 gaim_debug(GAIM_DEBUG_MISC, NULL, "\n"); |
264 purple_debug(PURPLE_DEBUG_MISC, NULL, "\n"); |
| 265 #endif |
265 #endif |
| 266 } |
266 } |
| 267 |
267 |
| 268 static void |
268 static void |
| 269 yahoo_packet_send_can_write(gpointer data, gint source, GaimInputCondition cond) |
269 yahoo_packet_send_can_write(gpointer data, gint source, PurpleInputCondition cond) |
| 270 { |
270 { |
| 271 struct yahoo_data *yd = data; |
271 struct yahoo_data *yd = data; |
| 272 int ret, writelen; |
272 int ret, writelen; |
| 273 |
273 |
| 274 writelen = gaim_circ_buffer_get_max_read(yd->txbuf); |
274 writelen = purple_circ_buffer_get_max_read(yd->txbuf); |
| 275 |
275 |
| 276 if (writelen == 0) { |
276 if (writelen == 0) { |
| 277 gaim_input_remove(yd->txhandler); |
277 purple_input_remove(yd->txhandler); |
| 278 yd->txhandler = -1; |
278 yd->txhandler = -1; |
| 279 return; |
279 return; |
| 280 } |
280 } |
| 281 |
281 |
| 282 ret = write(yd->fd, yd->txbuf->outptr, writelen); |
282 ret = write(yd->fd, yd->txbuf->outptr, writelen); |
| 283 |
283 |
| 284 if (ret < 0 && errno == EAGAIN) |
284 if (ret < 0 && errno == EAGAIN) |
| 285 return; |
285 return; |
| 286 else if (ret < 0) { |
286 else if (ret < 0) { |
| 287 /* TODO: what to do here - do we really have to disconnect? */ |
287 /* TODO: what to do here - do we really have to disconnect? */ |
| 288 gaim_connection_error(yd->gc, _("Write Error")); |
288 purple_connection_error(yd->gc, _("Write Error")); |
| 289 return; |
289 return; |
| 290 } |
290 } |
| 291 |
291 |
| 292 gaim_circ_buffer_mark_read(yd->txbuf, ret); |
292 purple_circ_buffer_mark_read(yd->txbuf, ret); |
| 293 } |
293 } |
| 294 |
294 |
| 295 |
295 |
| 296 size_t yahoo_packet_build(struct yahoo_packet *pkt, int pad, gboolean wm, |
296 size_t yahoo_packet_build(struct yahoo_packet *pkt, int pad, gboolean wm, |
| 297 gboolean jp, guchar **buf) |
297 gboolean jp, guchar **buf) |
| 344 } |
344 } |
| 345 |
345 |
| 346 if (ret < 0 && errno == EAGAIN) |
346 if (ret < 0 && errno == EAGAIN) |
| 347 ret = 0; |
347 ret = 0; |
| 348 else if (ret <= 0) { |
348 else if (ret <= 0) { |
| 349 gaim_debug_warning("yahoo", "Only wrote %d of %d bytes!", ret, len); |
349 purple_debug_warning("yahoo", "Only wrote %d of %d bytes!", ret, len); |
| 350 g_free(data); |
350 g_free(data); |
| 351 return ret; |
351 return ret; |
| 352 } |
352 } |
| 353 |
353 |
| 354 if (ret < len) { |
354 if (ret < len) { |
| 355 if (yd->txhandler == -1) |
355 if (yd->txhandler == -1) |
| 356 yd->txhandler = gaim_input_add(yd->fd, GAIM_INPUT_WRITE, |
356 yd->txhandler = purple_input_add(yd->fd, PURPLE_INPUT_WRITE, |
| 357 yahoo_packet_send_can_write, yd); |
357 yahoo_packet_send_can_write, yd); |
| 358 gaim_circ_buffer_append(yd->txbuf, data + ret, len - ret); |
358 purple_circ_buffer_append(yd->txbuf, data + ret, len - ret); |
| 359 } |
359 } |
| 360 |
360 |
| 361 g_free(data); |
361 g_free(data); |
| 362 |
362 |
| 363 return ret; |
363 return ret; |