Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 23378:e12600d6b902
Cleanup some duplication and simplify this.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Wed, 18 Jun 2008 03:14:47 +0000 |
parents | eb27ae817284 |
children | 6c728443b426 |
comparison
equal
deleted
inserted
replaced
23377:b175f6441bba | 23378:e12600d6b902 |
---|---|
271 } | 271 } |
272 | 272 |
273 purple_circ_buffer_mark_read(js->write_buffer, ret); | 273 purple_circ_buffer_mark_read(js->write_buffer, ret); |
274 } | 274 } |
275 | 275 |
276 void jabber_send_raw(JabberStream *js, const char *data, int len) | 276 static gboolean do_jabber_send_raw(JabberStream *js, const char *data, int len) |
277 { | 277 { |
278 int ret; | 278 int ret; |
279 | 279 gboolean success = TRUE; |
280 /* because printing a tab to debug every minute gets old */ | |
281 if(strcmp(data, "\t")) | |
282 purple_debug(PURPLE_DEBUG_MISC, "jabber", "Sending%s: %s\n", | |
283 js->gsc ? " (ssl)" : "", data); | |
284 | |
285 /* If we've got a security layer, we need to encode the data, | |
286 * splitting it on the maximum buffer length negotiated */ | |
287 | |
288 purple_signal_emit(my_protocol, "jabber-sending-text", js->gc, &data); | |
289 if (data == NULL) | |
290 return; | |
291 | |
292 #ifdef HAVE_CYRUS_SASL | |
293 if (js->sasl_maxbuf>0) { | |
294 int pos; | |
295 | |
296 if (!js->gsc && js->fd<0) | |
297 return; | |
298 pos = 0; | |
299 if (len == -1) | |
300 len = strlen(data); | |
301 while (pos < len) { | |
302 int towrite; | |
303 const char *out; | |
304 unsigned olen; | |
305 | |
306 if ((len - pos) < js->sasl_maxbuf) | |
307 towrite = len - pos; | |
308 else | |
309 towrite = js->sasl_maxbuf; | |
310 | |
311 sasl_encode(js->sasl, &data[pos], towrite, &out, &olen); | |
312 pos += towrite; | |
313 | |
314 if (js->writeh == 0) | |
315 ret = jabber_do_send(js, out, olen); | |
316 else { | |
317 ret = -1; | |
318 errno = EAGAIN; | |
319 } | |
320 | |
321 if (ret < 0 && errno != EAGAIN) | |
322 purple_connection_error_reason (js->gc, | |
323 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | |
324 _("Write error")); | |
325 else if (ret < olen) { | |
326 if (ret < 0) | |
327 ret = 0; | |
328 if (js->writeh == 0) | |
329 js->writeh = purple_input_add( | |
330 js->gsc ? js->gsc->fd : js->fd, | |
331 PURPLE_INPUT_WRITE, | |
332 jabber_send_cb, js); | |
333 purple_circ_buffer_append(js->write_buffer, | |
334 out + ret, olen - ret); | |
335 } | |
336 } | |
337 return; | |
338 } | |
339 #endif | |
340 | 280 |
341 if (len == -1) | 281 if (len == -1) |
342 len = strlen(data); | 282 len = strlen(data); |
343 | 283 |
344 if (js->writeh == 0) | 284 if (js->writeh == 0) |
346 else { | 286 else { |
347 ret = -1; | 287 ret = -1; |
348 errno = EAGAIN; | 288 errno = EAGAIN; |
349 } | 289 } |
350 | 290 |
351 if (ret < 0 && errno != EAGAIN) | 291 if (ret < 0 && errno != EAGAIN) { |
352 purple_connection_error_reason (js->gc, | 292 purple_connection_error_reason (js->gc, |
353 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, | 293 PURPLE_CONNECTION_ERROR_NETWORK_ERROR, |
354 _("Write error")); | 294 _("Write error")); |
355 else if (ret < len) { | 295 success = FALSE; |
296 } else if (ret < len) { | |
356 if (ret < 0) | 297 if (ret < 0) |
357 ret = 0; | 298 ret = 0; |
358 if (js->writeh == 0) | 299 if (js->writeh == 0) |
359 js->writeh = purple_input_add( | 300 js->writeh = purple_input_add( |
360 js->gsc ? js->gsc->fd : js->fd, | 301 js->gsc ? js->gsc->fd : js->fd, |
361 PURPLE_INPUT_WRITE, jabber_send_cb, js); | 302 PURPLE_INPUT_WRITE, jabber_send_cb, js); |
362 purple_circ_buffer_append(js->write_buffer, | 303 purple_circ_buffer_append(js->write_buffer, |
363 data + ret, len - ret); | 304 data + ret, len - ret); |
364 } | 305 } |
365 return; | 306 |
307 return success; | |
308 } | |
309 | |
310 void jabber_send_raw(JabberStream *js, const char *data, int len) | |
311 { | |
312 | |
313 /* because printing a tab to debug every minute gets old */ | |
314 if(strcmp(data, "\t")) | |
315 purple_debug(PURPLE_DEBUG_MISC, "jabber", "Sending%s: %s\n", | |
316 js->gsc ? " (ssl)" : "", data); | |
317 | |
318 /* If we've got a security layer, we need to encode the data, | |
319 * splitting it on the maximum buffer length negotiated */ | |
320 | |
321 purple_signal_emit(my_protocol, "jabber-sending-text", js->gc, &data); | |
322 if (data == NULL) | |
323 return; | |
324 | |
325 #ifdef HAVE_CYRUS_SASL | |
326 if (js->sasl_maxbuf>0) { | |
327 int pos = 0; | |
328 | |
329 if (!js->gsc && js->fd<0) | |
330 return; | |
331 | |
332 if (len == -1) | |
333 len = strlen(data); | |
334 | |
335 while (pos < len) { | |
336 int towrite; | |
337 const char *out; | |
338 unsigned olen; | |
339 | |
340 towrite = MIN((len - pos), js->sasl_maxbuf); | |
341 | |
342 sasl_encode(js->sasl, &data[pos], towrite, &out, &olen); | |
343 pos += towrite; | |
344 | |
345 if (!do_jabber_send_raw(js, out, olen)) | |
346 break; | |
347 } | |
348 return; | |
349 } | |
350 #endif | |
351 | |
352 do_jabber_send_raw(js, data, len); | |
366 } | 353 } |
367 | 354 |
368 int jabber_prpl_send_raw(PurpleConnection *gc, const char *buf, int len) | 355 int jabber_prpl_send_raw(PurpleConnection *gc, const char *buf, int len) |
369 { | 356 { |
370 JabberStream *js = (JabberStream*)gc->proto_data; | 357 JabberStream *js = (JabberStream*)gc->proto_data; |