Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/jabber.c @ 23391:5c70d953a497
propagate from branch 'im.pidgin.pidgin.2.4.3' (head 709ec9c29e9d76eebbded25061107ef0a2a2b148)
to branch 'im.pidgin.pidgin' (head e8d624d4b86e9505bb225f2a6e7b29ec6c8affed)
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 26 Jun 2008 09:07:56 +0000 |
parents | 01a08e285073 6c728443b426 |
children | 47b709962aab 3da0957e7821 |
comparison
equal
deleted
inserted
replaced
23057:d04d24b1db9b | 23391:5c70d953a497 |
---|---|
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; |
386 txt = xmlnode_to_str(packet, &len); | 373 txt = xmlnode_to_str(packet, &len); |
387 jabber_send_raw(js, txt, len); | 374 jabber_send_raw(js, txt, len); |
388 g_free(txt); | 375 g_free(txt); |
389 } | 376 } |
390 | 377 |
391 static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer timeout) | 378 static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer unused) |
392 { | 379 { |
393 purple_timeout_remove(GPOINTER_TO_INT(timeout)); | 380 purple_timeout_remove(js->keepalive_timeout); |
394 js->keepalive_timeout = -1; | 381 js->keepalive_timeout = -1; |
395 } | 382 } |
396 | 383 |
397 static gboolean jabber_pong_timeout(PurpleConnection *gc) | 384 static gboolean jabber_pong_timeout(PurpleConnection *gc) |
398 { | 385 { |
412 | 399 |
413 xmlnode *ping = xmlnode_new_child(iq->node, "ping"); | 400 xmlnode *ping = xmlnode_new_child(iq->node, "ping"); |
414 xmlnode_set_namespace(ping, "urn:xmpp:ping"); | 401 xmlnode_set_namespace(ping, "urn:xmpp:ping"); |
415 | 402 |
416 js->keepalive_timeout = purple_timeout_add_seconds(120, (GSourceFunc)(jabber_pong_timeout), gc); | 403 js->keepalive_timeout = purple_timeout_add_seconds(120, (GSourceFunc)(jabber_pong_timeout), gc); |
417 jabber_iq_set_callback(iq, jabber_pong_cb, GINT_TO_POINTER(js->keepalive_timeout)); | 404 jabber_iq_set_callback(iq, jabber_pong_cb, NULL); |
418 jabber_iq_send(iq); | 405 jabber_iq_send(iq); |
419 } | 406 } |
420 } | 407 } |
421 | 408 |
422 static void | 409 static void |
993 else | 980 else |
994 field = purple_request_field_string_new("name", _("Name"), NULL, FALSE); | 981 field = purple_request_field_string_new("name", _("Name"), NULL, FALSE); |
995 purple_request_field_group_add_field(group, field); | 982 purple_request_field_group_add_field(group, field); |
996 } | 983 } |
997 if(xmlnode_get_child(query, "email")) { | 984 if(xmlnode_get_child(query, "email")) { |
998 field = purple_request_field_string_new("email", _("E-mail"), NULL, FALSE); | 985 field = purple_request_field_string_new("email", _("Email"), NULL, FALSE); |
999 purple_request_field_group_add_field(group, field); | 986 purple_request_field_group_add_field(group, field); |
1000 } | 987 } |
1001 if(xmlnode_get_child(query, "nick")) { | 988 if(xmlnode_get_child(query, "nick")) { |
1002 field = purple_request_field_string_new("nick", _("Nickname"), NULL, FALSE); | 989 field = purple_request_field_string_new("nick", _("Nickname"), NULL, FALSE); |
1003 purple_request_field_group_add_field(group, field); | 990 purple_request_field_group_add_field(group, field); |
1502 GList *l; | 1489 GList *l; |
1503 const char *mood; | 1490 const char *mood; |
1504 | 1491 |
1505 if (full) { | 1492 if (full) { |
1506 PurpleStatus *status; | 1493 PurpleStatus *status; |
1507 PurpleValue *value; | 1494 |
1508 | |
1509 if(jb->subscription & JABBER_SUB_FROM) { | 1495 if(jb->subscription & JABBER_SUB_FROM) { |
1510 if(jb->subscription & JABBER_SUB_TO) | 1496 if(jb->subscription & JABBER_SUB_TO) |
1511 sub = _("Both"); | 1497 sub = _("Both"); |
1512 else if(jb->subscription & JABBER_SUB_PENDING) | 1498 else if(jb->subscription & JABBER_SUB_PENDING) |
1513 sub = _("From (To pending)"); | 1499 sub = _("From (To pending)"); |
1519 else if(jb->subscription & JABBER_SUB_PENDING) | 1505 else if(jb->subscription & JABBER_SUB_PENDING) |
1520 sub = _("None (To pending)"); | 1506 sub = _("None (To pending)"); |
1521 else | 1507 else |
1522 sub = _("None"); | 1508 sub = _("None"); |
1523 } | 1509 } |
1524 | 1510 |
1525 purple_notify_user_info_add_pair(user_info, _("Subscription"), sub); | 1511 purple_notify_user_info_add_pair(user_info, _("Subscription"), sub); |
1526 | 1512 |
1527 status = purple_presence_get_active_status(presence); | 1513 status = purple_presence_get_active_status(presence); |
1528 value = purple_status_get_attr_value(status, "mood"); | 1514 mood = purple_status_get_attr_string(status, "mood"); |
1529 if (value && purple_value_get_type(value) == PURPLE_TYPE_STRING && (mood = purple_value_get_string(value))) { | 1515 if(mood != NULL) { |
1530 | 1516 const char *moodtext; |
1531 value = purple_status_get_attr_value(status, "moodtext"); | 1517 moodtext = purple_status_get_attr_string(status, "moodtext"); |
1532 if(value && purple_value_get_type(value) == PURPLE_TYPE_STRING) { | 1518 if(moodtext != NULL) { |
1533 char *moodplustext = g_strdup_printf("%s (%s)",mood,purple_value_get_string(value)); | 1519 char *moodplustext = g_strdup_printf("%s (%s)", mood, moodtext); |
1534 | 1520 |
1535 purple_notify_user_info_add_pair(user_info, _("Mood"), moodplustext); | 1521 purple_notify_user_info_add_pair(user_info, _("Mood"), moodplustext); |
1536 g_free(moodplustext); | 1522 g_free(moodplustext); |
1537 } else | 1523 } else |
1538 purple_notify_user_info_add_pair(user_info, _("Mood"), mood); | 1524 purple_notify_user_info_add_pair(user_info, _("Mood"), mood); |
1539 } | 1525 } |