comparison mcabber/src/jabglue.c @ 1399:187985455020

Correctly display PGP-encoded messages with a subject Minor style change
author Mikael Berthe <mikael@lilotux.net>
date Thu, 13 Dec 2007 22:36:04 +0100
parents 5f91bac887ee
children f89844a0448a
comparison
equal deleted inserted replaced
1398:f8321420ed7a 1399:187985455020
252 tv.tv_usec = 0; 252 tv.tv_usec = 0;
253 253
254 time(&now); 254 time(&now);
255 255
256 if (KeepaliveDelay) { 256 if (KeepaliveDelay) {
257 if (now >= LastPingTime + (time_t)KeepaliveDelay) { 257 if (now >= LastPingTime + (time_t)KeepaliveDelay)
258 tv.tv_sec = 0; 258 tv.tv_sec = 0;
259 } else { 259 else
260 tv.tv_sec = LastPingTime + (time_t)KeepaliveDelay - now; 260 tv.tv_sec = LastPingTime + (time_t)KeepaliveDelay - now;
261 }
262 } 261 }
263 262
264 // Check auto-away timeout 263 // Check auto-away timeout
265 tmout = scr_GetAutoAwayTimeout(now); 264 tmout = scr_GetAutoAwayTimeout(now);
266 if (tv.tv_sec > tmout) { 265 if (tv.tv_sec > tmout)
267 tv.tv_sec = tmout; 266 tv.tv_sec = tmout;
268 }
269 267
270 #if defined JEP0022 || defined JEP0085 268 #if defined JEP0022 || defined JEP0085
271 // Check composing timeout 269 // Check composing timeout
272 tmout = scr_GetChatStatesTimeout(now); 270 tmout = scr_GetChatStatesTimeout(now);
273 if (tv.tv_sec > tmout) { 271 if (tv.tv_sec > tmout)
274 tv.tv_sec = tmout; 272 tv.tv_sec = tmout;
275 }
276 #endif 273 #endif
277 274
278 if (!tv.tv_sec) 275 if (!tv.tv_sec)
279 tv.tv_usec = 350000; 276 tv.tv_usec = 350000;
280 277
551 srand(now); 548 srand(now);
552 msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0))); 549 msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0)));
553 return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); 550 return g_strdup_printf("%u%d", msg_idn, (int)(now%10L));
554 } 551 }
555 552
556 // jb_send_msg(jid, text, type, subject, msgid, *encrypted) 553 // jb_send_msg(jid, text, type, subject, msgid, *encrypted, type_overwrite)
557 // When encrypted is not NULL, the function set *encrypted to 1 if the 554 // When encrypted is not NULL, the function set *encrypted to 1 if the
558 // message has been PGP-encrypted. If encryption enforcement is set and 555 // message has been PGP-encrypted. If encryption enforcement is set and
559 // encryption fails, *encrypted is set to -1. 556 // encryption fails, *encrypted is set to -1.
560 void jb_send_msg(const char *fjid, const char *text, int type, 557 void jb_send_msg(const char *fjid, const char *text, int type,
561 const char *subject, const char *msgid, gint *encrypted, 558 const char *subject, const char *msgid, gint *encrypted,
1738 } 1735 }
1739 #endif 1736 #endif
1740 } 1737 }
1741 1738
1742 static void gotmessage(char *type, const char *from, const char *body, 1739 static void gotmessage(char *type, const char *from, const char *body,
1743 const char *enc, time_t timestamp, 1740 const char *enc, const char *subject, time_t timestamp,
1744 xmlnode xmldata_signed) 1741 xmlnode xmldata_signed)
1745 { 1742 {
1746 char *bjid; 1743 char *bjid;
1747 const char *rname, *s; 1744 const char *rname, *s;
1748 char *decrypted_pgp = NULL; 1745 char *decrypted_pgp = NULL;
1814 // System messages (from our server) are allowed. 1811 // System messages (from our server) are allowed.
1815 if (!settings_opt_get_int("block_unsubscribed") || 1812 if (!settings_opt_get_int("block_unsubscribed") ||
1816 (roster_getsubscription(bjid) & sub_from) || 1813 (roster_getsubscription(bjid) & sub_from) ||
1817 (type && strcmp(type, "chat")) || 1814 (type && strcmp(type, "chat")) ||
1818 ((s = settings_opt_get("server")) != NULL && !strcasecmp(bjid, s))) { 1815 ((s = settings_opt_get("server")) != NULL && !strcasecmp(bjid, s))) {
1816 gchar *fullbody = NULL;
1817 if (subject) {
1818 if (body)
1819 fullbody = g_strdup_printf("[%s]\n%s", subject, body);
1820 else
1821 fullbody = g_strdup_printf("[%s]\n", subject);
1822 body = fullbody;
1823 }
1819 hk_message_in(bjid, rname, timestamp, body, type, 1824 hk_message_in(bjid, rname, timestamp, body, type,
1820 ((decrypted_pgp || otr_msg) ? TRUE : FALSE)); 1825 ((decrypted_pgp || otr_msg) ? TRUE : FALSE));
1826 g_free(fullbody);
1821 } else { 1827 } else {
1822 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", bjid); 1828 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", bjid);
1823 } 1829 }
1824 1830
1825 gotmessage_return: 1831 gotmessage_return:
2517 { 2523 {
2518 char *p, *r, *s; 2524 char *p, *r, *s;
2519 xmlnode x; 2525 xmlnode x;
2520 char *body = NULL; 2526 char *body = NULL;
2521 char *enc = NULL; 2527 char *enc = NULL;
2522 char *chatmsg = NULL; 2528 char *subject = NULL;
2523 time_t timestamp = 0L; 2529 time_t timestamp = 0L;
2524 2530
2525 body = xmlnode_get_tag_data(xmldata, "body"); 2531 body = xmlnode_get_tag_data(xmldata, "body");
2532
2533 x = xml_get_xmlns(xmldata, NS_ENCRYPTED);
2534 if (x && (p = xmlnode_get_data(x)) != NULL)
2535 enc = p;
2526 2536
2527 p = xmlnode_get_tag_data(xmldata, "subject"); 2537 p = xmlnode_get_tag_data(xmldata, "subject");
2528 if (p != NULL) { 2538 if (p != NULL) {
2529 if (type && !strcmp(type, TMSG_GROUPCHAT)) { // Room topic 2539 if (!type || strcmp(type, TMSG_GROUPCHAT)) { // Chat message
2540 subject = p;
2541 } else { // Room topic
2530 GSList *roombuddy; 2542 GSList *roombuddy;
2531 gchar *mbuf; 2543 gchar *mbuf;
2532 gchar *subj = p; 2544 gchar *subj = p;
2533 // Get the room (s) and the nickname (r) 2545 // Get the room (s) and the nickname (r)
2534 s = g_strdup(from); 2546 s = g_strdup(from);
2552 hlog_write_message(s, 0, -1, mbuf); 2564 hlog_write_message(s, 0, -1, mbuf);
2553 g_free(s); 2565 g_free(s);
2554 g_free(mbuf); 2566 g_free(mbuf);
2555 // The topic is displayed in the chat status line, so refresh now. 2567 // The topic is displayed in the chat status line, so refresh now.
2556 scr_UpdateChatStatus(TRUE); 2568 scr_UpdateChatStatus(TRUE);
2557 } else { // Chat message 2569 }
2558 if (body)
2559 chatmsg = g_strdup_printf("[%s]\n%s", p, body);
2560 else
2561 chatmsg = g_strdup_printf("[%s]\n", p);
2562 body = chatmsg;
2563 }
2564 }
2565
2566 // Not used yet...
2567 x = xml_get_xmlns(xmldata, NS_ENCRYPTED);
2568 if (x && (p = xmlnode_get_data(x)) != NULL) {
2569 enc = p;
2570 } 2570 }
2571 2571
2572 // Timestamp? 2572 // Timestamp?
2573 timestamp = xml_get_timestamp(xmldata); 2573 timestamp = xml_get_timestamp(xmldata);
2574 2574
2581 chatstates_reset_probed(from); 2581 chatstates_reset_probed(from);
2582 #endif 2582 #endif
2583 } else { 2583 } else {
2584 handle_state_events(from, xmldata); 2584 handle_state_events(from, xmldata);
2585 } 2585 }
2586 if (from && body) 2586 if (from && (body || subject))
2587 gotmessage(type, from, body, enc, timestamp, 2587 gotmessage(type, from, body, enc, subject, timestamp,
2588 xml_get_xmlns(xmldata, NS_SIGNED)); 2588 xml_get_xmlns(xmldata, NS_SIGNED));
2589 2589
2590 if (from) { 2590 if (from) {
2591 x = xml_get_xmlns(xmldata, "http://jabber.org/protocol/muc#user"); 2591 x = xml_get_xmlns(xmldata, "http://jabber.org/protocol/muc#user");
2592 if (x && !strcmp(xmlnode_get_name(x), "x")) 2592 if (x && !strcmp(xmlnode_get_name(x), "x"))
2593 got_muc_message(from, x); 2593 got_muc_message(from, x);
2594 } 2594 }
2595 g_free(chatmsg);
2596 } 2595 }
2597 2596
2598 static void handle_state_events(char *from, xmlnode xmldata) 2597 static void handle_state_events(char *from, xmlnode xmldata)
2599 { 2598 {
2600 #if defined JEP0022 || defined JEP0085 2599 #if defined JEP0022 || defined JEP0085