mcabber/src/jabglue.c
changeset 1044 52cfe9bf9840
parent 1043 ebbde723614b
child 1045 96be69d3a5fd
equal deleted inserted replaced
1043:ebbde723614b 1044:52cfe9bf9840
   507 void jb_send_msg(const char *jid, const char *text, int type,
   507 void jb_send_msg(const char *jid, const char *text, int type,
   508                  const char *subject, const char *msgid)
   508                  const char *subject, const char *msgid)
   509 {
   509 {
   510   xmlnode x;
   510   xmlnode x;
   511   gchar *strtype;
   511   gchar *strtype;
       
   512 #if defined HAVE_GPGME || defined JEP0022 || defined JEP0085
       
   513   char *rname, *barejid;
       
   514   GSList *sl_buddy;
       
   515 #endif
   512 #if defined JEP0022 || defined JEP0085
   516 #if defined JEP0022 || defined JEP0085
   513   xmlnode event;
   517   xmlnode event;
   514   char *rname, *barejid;
       
   515   GSList *sl_buddy;
       
   516   guint use_jep85 = 0;
   518   guint use_jep85 = 0;
   517   struct jep0085 *jep85 = NULL;
   519   struct jep0085 *jep85 = NULL;
   518 #endif
   520 #endif
       
   521   gchar *enc = NULL;
   519 
   522 
   520   if (!online) return;
   523   if (!online) return;
   521 
   524 
   522   if (type == ROSTER_TYPE_ROOM)
   525   if (type == ROSTER_TYPE_ROOM)
   523     strtype = TMSG_GROUPCHAT;
   526     strtype = TMSG_GROUPCHAT;
   524   else
   527   else
   525     strtype = TMSG_CHAT;
   528     strtype = TMSG_CHAT;
   526 
   529 
   527   x = jutil_msgnew(strtype, (char*)jid, NULL, (char*)text);
   530 #if defined HAVE_GPGME || defined JEP0022 || defined JEP0085
       
   531   rname = strchr(jid, JID_RESOURCE_SEPARATOR);
       
   532   barejid = jidtodisp(jid);
       
   533   sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
       
   534   g_free(barejid);
       
   535 
       
   536   // If we can get a resource name, we use it.  Else we use NULL,
       
   537   // which hopefully will give us the most likely resource.
       
   538   if (rname)
       
   539     rname++;
       
   540 #endif
       
   541 
       
   542 #ifdef HAVE_GPGME
       
   543   if (type == ROSTER_TYPE_USER && sl_buddy && gpg_enabled()) {
       
   544     struct pgp_data *res_pgpdata;
       
   545     res_pgpdata = buddy_resource_pgp(sl_buddy->data, rname);
       
   546     if (res_pgpdata && res_pgpdata->sign_keyid)
       
   547       enc = gpg_encrypt(text, res_pgpdata->sign_keyid);
       
   548   }
       
   549 #endif
       
   550 
       
   551   x = jutil_msgnew(strtype, (char*)jid, NULL,
       
   552                    (enc ? "This message is PGP-encrypted." : (char*)text));
   528   if (subject) {
   553   if (subject) {
   529     xmlnode y;
   554     xmlnode y;
   530     y = xmlnode_insert_tag(x, "subject");
   555     y = xmlnode_insert_tag(x, "subject");
   531     xmlnode_insert_cdata(y, subject, (unsigned) -1);
   556     xmlnode_insert_cdata(y, subject, (unsigned) -1);
   532   }
   557   }
       
   558   if (enc) {
       
   559     xmlnode y;
       
   560     y = xmlnode_insert_tag(x, "x");
       
   561     xmlnode_put_attrib(y, "xmlns", NS_ENCRYPTED);
       
   562     xmlnode_insert_cdata(y, enc, (unsigned) -1);
       
   563     g_free(enc);
       
   564   }
   533 
   565 
   534 #if defined JEP0022 || defined JEP0085
   566 #if defined JEP0022 || defined JEP0085
   535   // If typing notifications are disabled, we can skip all this stuff...
   567   // If typing notifications are disabled, we can skip all this stuff...
   536   if (chatstates_disabled || type == ROSTER_TYPE_ROOM)
   568   if (chatstates_disabled || type == ROSTER_TYPE_ROOM)
   537     goto jb_send_msg_no_chatstates;
   569     goto jb_send_msg_no_chatstates;
   538 
   570 
   539   rname = strchr(jid, JID_RESOURCE_SEPARATOR);
       
   540   barejid = jidtodisp(jid);
       
   541   sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
       
   542   g_free(barejid);
       
   543 
       
   544   // If we can get a resource name, we use it.  Else we use NULL,
       
   545   // which hopefully will give us the most likely resource.
       
   546   if (rname)
       
   547     rname++;
       
   548   if (sl_buddy)
   571   if (sl_buddy)
   549     jep85 = buddy_resource_jep85(sl_buddy->data, rname);
   572     jep85 = buddy_resource_jep85(sl_buddy->data, rname);
   550 #endif
   573 #endif
   551 
   574 
   552 #ifdef JEP0085
   575 #ifdef JEP0085