Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/xmpp.c @ 2213:0c78d31c753d
Change otr_send() prototype
This patch updates otr_send() in order to differenciate original and
encrypted messages.
It should also fix a memory leak of OTR-encrypted messages.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Thu, 05 Nov 2015 19:46:09 +0100 |
parents | 778280b01bcb |
children | f5659f0f9db8 |
comparison
equal
deleted
inserted
replaced
2212:778280b01bcb | 2213:0c78d31c753d |
---|---|
297 } | 297 } |
298 g_slist_free(resources); | 298 g_slist_free(resources); |
299 } | 299 } |
300 | 300 |
301 // xmpp_send_msg(jid, text, type, subject, | 301 // xmpp_send_msg(jid, text, type, subject, |
302 // otrinject, *encrypted, type_overwrite) | 302 // otrinject, *encrypted, type_overwrite, *xep184) |
303 // When encrypted is not NULL, the function set *encrypted to 1 if the | 303 // When encrypted is not NULL, the function set *encrypted to 1 if the |
304 // message has been PGP-encrypted. If encryption enforcement is set and | 304 // message has been PGP (or OTR) -encrypted. If encryption enforcement is set |
305 // encryption fails, *encrypted is set to -1. | 305 // and encryption fails, *encrypted is set to -1. |
306 // otrinject should be set to FALSE (unless the message already has an OTR | |
307 // payload, i.e. if the function is called from an otr.c routine). | |
306 void xmpp_send_msg(const char *fjid, const char *text, int type, | 308 void xmpp_send_msg(const char *fjid, const char *text, int type, |
307 const char *subject, gboolean otrinject, gint *encrypted, | 309 const char *subject, gboolean otrinject, gint *encrypted, |
308 LmMessageSubType type_overwrite, gpointer *xep184) | 310 LmMessageSubType type_overwrite, gpointer *xep184) |
309 { | 311 { |
310 LmMessage *x; | 312 LmMessage *x; |
311 LmMessageSubType subtype; | 313 LmMessageSubType subtype; |
312 #ifdef HAVE_LIBOTR | 314 #ifdef HAVE_LIBOTR |
313 int otr_msg = 0; | 315 int otr_msg = 0; |
316 char *otr_msg_string = NULL; | |
314 #endif | 317 #endif |
315 char *barejid; | 318 char *barejid; |
316 #if defined HAVE_GPGME || defined XEP0085 | 319 #if defined HAVE_GPGME || defined XEP0085 |
317 char *rname; | 320 char *rname; |
318 GSList *sl_buddy; | 321 GSList *sl_buddy; |
352 rname++; | 355 rname++; |
353 | 356 |
354 #ifdef HAVE_LIBOTR | 357 #ifdef HAVE_LIBOTR |
355 if (otr_enabled() && !otrinject) { | 358 if (otr_enabled() && !otrinject) { |
356 if (type == ROSTER_TYPE_USER) { | 359 if (type == ROSTER_TYPE_USER) { |
357 otr_msg = otr_send((char **)&text, barejid); | 360 otr_msg_string = otr_send(text, barejid, &otr_msg); |
358 if (!text) { | 361 if (!otr_msg_string) { |
359 g_free(barejid); | |
360 if (encrypted) | 362 if (encrypted) |
361 *encrypted = -1; | 363 *encrypted = -1; |
362 return; | 364 goto xmpp_send_msg_return; |
363 } | 365 } |
366 text = otr_msg_string; | |
364 } | 367 } |
365 if (otr_msg && encrypted) | 368 if (otr_msg && encrypted) |
366 *encrypted = ENCRYPTED_OTR; | 369 *encrypted = ENCRYPTED_OTR; |
367 } | 370 } |
368 #endif | 371 #endif |
392 enc = gpg_encrypt(text, keys, nkeys); | 395 enc = gpg_encrypt(text, keys, nkeys); |
393 } | 396 } |
394 if (!enc && force) { | 397 if (!enc && force) { |
395 if (encrypted) | 398 if (encrypted) |
396 *encrypted = -1; | 399 *encrypted = -1; |
397 g_free(barejid); | 400 goto xmpp_send_msg_return; |
398 return; | |
399 } | 401 } |
400 } | 402 } |
401 } | 403 } |
402 } | 404 } |
403 #endif // HAVE_GPGME | 405 #endif // HAVE_GPGME |
434 lm_message_node_set_attribute(lm_message_node_add_child(x->node, "request", | 436 lm_message_node_set_attribute(lm_message_node_add_child(x->node, "request", |
435 NULL), | 437 NULL), |
436 "xmlns", NS_RECEIPTS); | 438 "xmlns", NS_RECEIPTS); |
437 *xep184 = g_strdup(lm_message_get_id(x)); | 439 *xep184 = g_strdup(lm_message_get_id(x)); |
438 } | 440 } |
439 g_free(barejid); | |
440 | 441 |
441 #ifdef XEP0085 | 442 #ifdef XEP0085 |
442 // If typing notifications are disabled, we can skip all this stuff... | 443 // If typing notifications are disabled, we can skip all this stuff... |
443 if (chatstates_disabled || type == ROSTER_TYPE_ROOM) | 444 if (chatstates_disabled || type == ROSTER_TYPE_ROOM) |
444 goto xmpp_send_msg_no_chatstates; | 445 goto xmpp_send_msg_no_chatstates; |
468 if (mystatus != invisible) | 469 if (mystatus != invisible) |
469 #endif | 470 #endif |
470 update_last_use(); | 471 update_last_use(); |
471 lm_connection_send(lconnection, x, NULL); | 472 lm_connection_send(lconnection, x, NULL); |
472 lm_message_unref(x); | 473 lm_message_unref(x); |
474 | |
475 xmpp_send_msg_return: | |
476 #ifdef HAVE_LIBOTR | |
477 g_free(otr_msg_string); | |
478 #endif | |
479 g_free(barejid); | |
473 } | 480 } |
474 | 481 |
475 #ifdef XEP0085 | 482 #ifdef XEP0085 |
476 // xmpp_send_xep85_chatstate() | 483 // xmpp_send_xep85_chatstate() |
477 // Send a XEP-85 chatstate. | 484 // Send a XEP-85 chatstate. |