mcabber/src/jabglue.c
changeset 997 d0d0cd9e39c4
parent 993 0759f4c7da68
child 998 f984baa9a789
equal deleted inserted replaced
996:f4d6570e2628 997:d0d0cd9e39c4
   440   gchar *strtype;
   440   gchar *strtype;
   441 #if defined JEP0022 || defined JEP0085
   441 #if defined JEP0022 || defined JEP0085
   442   xmlnode event;
   442   xmlnode event;
   443   char *rname, *barejid;
   443   char *rname, *barejid;
   444   GSList *sl_buddy;
   444   GSList *sl_buddy;
   445   guint which_jep = 0; /* 0: none, 1: 85, 2: 22 */
   445   guint use_jep85 = 0;
   446   struct jep0085 *jep85 = NULL;
   446   struct jep0085 *jep85 = NULL;
   447 #endif
   447 #endif
   448 
   448 
   449   if (!online) return;
   449   if (!online) return;
   450 
   450 
   491     event = xmlnode_insert_tag(x, "active");
   491     event = xmlnode_insert_tag(x, "active");
   492     xmlnode_put_attrib(event, "xmlns", NS_CHATSTATES);
   492     xmlnode_put_attrib(event, "xmlns", NS_CHATSTATES);
   493     if (jep85->support == CHATSTATES_SUPPORT_UNKNOWN)
   493     if (jep85->support == CHATSTATES_SUPPORT_UNKNOWN)
   494       jep85->support = CHATSTATES_SUPPORT_PROBED;
   494       jep85->support = CHATSTATES_SUPPORT_PROBED;
   495     else
   495     else
   496       which_jep = 1;
   496       use_jep85 = 1;
   497     jep85->last_state_sent = ROSTER_EVENT_ACTIVE;
   497     jep85->last_state_sent = ROSTER_EVENT_ACTIVE;
   498   }
   498   }
   499 #endif
   499 #endif
   500 #ifdef JEP0022
   500 #ifdef JEP0022
   501   /* JEP-22
   501   /* JEP-22
   502    * If the Contact supports JEP-0085, we do not use JEP-0022.
   502    * If the Contact supports JEP-0085, we do not use JEP-0022.
   503    * If not, we try to fall back to JEP-0022.
   503    * If not, we try to fall back to JEP-0022.
   504    */
   504    */
   505   if (!which_jep) {
   505   if (!use_jep85) {
   506     struct jep0022 *jep22 = NULL;
   506     struct jep0022 *jep22 = NULL;
   507     event = xmlnode_insert_tag(x, "x");
   507     event = xmlnode_insert_tag(x, "x");
   508     xmlnode_put_attrib(event, "xmlns", NS_EVENT);
   508     xmlnode_put_attrib(event, "xmlns", NS_EVENT);
   509     xmlnode_insert_tag(event, "composing");
   509     xmlnode_insert_tag(event, "composing");
   510 
   510 
   658 
   658 
   659   jb_reset_keepalive();
   659   jb_reset_keepalive();
   660 }
   660 }
   661 #endif
   661 #endif
   662 
   662 
       
   663 //  jb_send_chatstate(buddy, state)
       
   664 // Send a chatstate or event (JEP-22/85) according to the buddy's capabilities.
       
   665 // The message is sent to one of the resources with the highest priority.
   663 #if defined JEP0022 || defined JEP0085
   666 #if defined JEP0022 || defined JEP0085
   664 void jb_send_chatstate(gpointer buddy, guint chatstate)
   667 void jb_send_chatstate(gpointer buddy, guint chatstate)
   665 {
   668 {
   666   const char *jid;
   669   const char *jid;
   667   struct jep0085 *jep85 = NULL;
   670   struct jep0085 *jep85 = NULL;
  1697   xmlnode state_ns = NULL;
  1700   xmlnode state_ns = NULL;
  1698   const char *body;
  1701   const char *body;
  1699   char *rname, *jid;
  1702   char *rname, *jid;
  1700   GSList *sl_buddy;
  1703   GSList *sl_buddy;
  1701   guint events;
  1704   guint events;
  1702   guint which_jep = 0; /* 0: none, 1: 85, 2: 22 */
       
  1703   struct jep0022 *jep22 = NULL;
  1705   struct jep0022 *jep22 = NULL;
  1704   struct jep0085 *jep85 = NULL;
  1706   struct jep0085 *jep85 = NULL;
       
  1707   enum {
       
  1708     JEP_none,
       
  1709     JEP_85,
       
  1710     JEP_22
       
  1711   } which_jep = JEP_none;
  1705 
  1712 
  1706   rname = strchr(from, JID_RESOURCE_SEPARATOR);
  1713   rname = strchr(from, JID_RESOURCE_SEPARATOR);
  1707   jid   = jidtodisp(from);
  1714   jid   = jidtodisp(from);
  1708   sl_buddy = roster_find(jid, jidsearch, ROSTER_TYPE_USER);
  1715   sl_buddy = roster_find(jid, jidsearch, ROSTER_TYPE_USER);
  1709 
  1716 
  1710   /* XXX Actually that's wrong, since it filters out server "offline"
  1717   /* XXX Actually that's wrong, since it filters out server "offline"
  1711      messages (for JEP-0022) */
  1718      messages (for JEP-0022).  This JEP is (almost) deprecated so
       
  1719      we don't really care. */
  1712   if (!sl_buddy || !rname++) {
  1720   if (!sl_buddy || !rname++) {
  1713     g_free(jid);
  1721     g_free(jid);
  1714     return;
  1722     return;
  1715   }
  1723   }
  1716 
  1724 
       
  1725   /* Let's see chich JEP the contact uses.  If possible, we'll use
       
  1726      JEP-85, if not we'll look for JEP-22 support. */
  1717   events = buddy_resource_getevents(sl_buddy->data, rname);
  1727   events = buddy_resource_getevents(sl_buddy->data, rname);
  1718 
  1728 
  1719   jep85 = buddy_resource_jep85(sl_buddy->data, rname);
  1729   jep85 = buddy_resource_jep85(sl_buddy->data, rname);
  1720   if (jep85) {
  1730   if (jep85) {
  1721     state_ns = xml_get_xmlns(xmldata, NS_CHATSTATES);
  1731     state_ns = xml_get_xmlns(xmldata, NS_CHATSTATES);
  1722     if (state_ns)
  1732     if (state_ns)
  1723       which_jep = 1;
  1733       which_jep = JEP_85;
  1724   }
  1734   }
  1725 
  1735 
  1726   if (which_jep != 1) { /* Fall back to JEP-0022 */
  1736   if (which_jep != JEP_85) { /* Fall back to JEP-0022 */
  1727     jep22 = buddy_resource_jep22(sl_buddy->data, rname);
  1737     jep22 = buddy_resource_jep22(sl_buddy->data, rname);
  1728     if (jep22) {
  1738     if (jep22) {
  1729       state_ns = xml_get_xmlns(xmldata, NS_EVENT);
  1739       state_ns = xml_get_xmlns(xmldata, NS_EVENT);
  1730       if (state_ns)
  1740       if (state_ns)
  1731         which_jep = 2;
  1741         which_jep = JEP_22;
  1732     }
  1742     }
  1733   }
  1743   }
  1734 
  1744 
  1735   if (!which_jep) { /* Sender does not use chat states */
  1745   if (!which_jep) { /* Sender does not use chat states */
  1736     g_free(jid);
  1746     g_free(jid);
  1737     return;
  1747     return;
  1738   }
  1748   }
  1739 
  1749 
  1740   body = xmlnode_get_tag_data(xmldata, "body");
  1750   body = xmlnode_get_tag_data(xmldata, "body");
  1741 
  1751 
  1742   if (which_jep == 1) { /* JEP-0085 */
  1752   if (which_jep == JEP_85) { /* JEP-0085 */
  1743     const char *p;
  1753     const char *p;
  1744     jep85->support = CHATSTATES_SUPPORT_OK;
  1754     jep85->support = CHATSTATES_SUPPORT_OK;
  1745 
  1755 
  1746     p = xmlnode_get_name(state_ns);
  1756     p = xmlnode_get_name(state_ns);
  1747     if (!strcmp(p, "composing")) {
  1757     if (!strcmp(p, "composing")) {