mcabber/src/jab_iq.c
changeset 607 cf722bff6579
parent 606 0b4ed231ebc2
child 613 a6b8b373e4de
equal deleted inserted replaced
606:0b4ed231ebc2 607:cf722bff6579
   162   if (!ns) return;
   162   if (!ns) return;
   163 
   163 
   164   if (!strcmp(ns, NS_ROSTER)) {
   164   if (!strcmp(ns, NS_ROSTER)) {
   165     handle_iq_roster(x);
   165     handle_iq_roster(x);
   166 
   166 
   167     // Post-login stuff   FIXME shouldn't be there
   167     // Post-login stuff
       
   168     // Usually we request the roster only at connection time
       
   169     // so we should be there only once.  (That's ugly, however)
   168     jb_setstatus(available, NULL, NULL);
   170     jb_setstatus(available, NULL, NULL);
   169   }
   171   }
   170 }
   172 }
   171 
   173 
   172 static void handle_iq_get(jconn conn, char *from, xmlnode xmldata)
   174 static void handle_iq_get(jconn conn, char *from, xmlnode xmldata)
   173 {
   175 {
   174   char *id;
   176   char *id;
   175   xmlnode x, y, z;
   177   xmlnode x, y, z;
   176 
   178 
   177   id = xmlnode_get_attrib(xmldata, "id");
   179   id = xmlnode_get_attrib(xmldata, "id");
   178   if (!id) return;
   180   if (!id) {
       
   181     scr_LogPrint(LPRINT_LOG, "IQ get stanza with no ID, ignored.");
       
   182     return;
       
   183   }
   179 
   184 
   180   // Nothing implemented yet.
   185   // Nothing implemented yet.
   181   x = xmlnode_new_tag("iq");
   186   x = xmlnode_dup(xmldata);
   182   xmlnode_put_attrib(x, "to", from);
   187   xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
   183   xmlnode_put_attrib(x, "id", id);
   188   xmlnode_hide_attrib(x, "from");
       
   189 
   184   xmlnode_put_attrib(x, "type", TMSG_ERROR);
   190   xmlnode_put_attrib(x, "type", TMSG_ERROR);
   185   y = xmlnode_insert_tag(x, TMSG_ERROR);
   191   y = xmlnode_insert_tag(x, TMSG_ERROR);
   186   xmlnode_put_attrib(y, "code", "501");
   192   xmlnode_put_attrib(y, "code", "501");
   187   xmlnode_put_attrib(y, "type", "cancel");
   193   xmlnode_put_attrib(y, "type", "cancel");
   188   z = xmlnode_insert_tag(y, "feature-not-implemented");
   194   z = xmlnode_insert_tag(y, "feature-not-implemented");
   192   xmlnode_free(x);
   198   xmlnode_free(x);
   193 }
   199 }
   194 
   200 
   195 static void handle_iq_set(jconn conn, char *from, xmlnode xmldata)
   201 static void handle_iq_set(jconn conn, char *from, xmlnode xmldata)
   196 {
   202 {
   197   char *id;
   203   char *id, *ns;
   198   xmlnode x, y, z;
   204   xmlnode x, y, z;
       
   205   guint iq_error = FALSE;
   199 
   206 
   200   id = xmlnode_get_attrib(xmldata, "id");
   207   id = xmlnode_get_attrib(xmldata, "id");
       
   208   if (!id)
       
   209     scr_LogPrint(LPRINT_LOG, "IQ set stanza with no ID...");
       
   210 
       
   211   x = xmlnode_get_tag(xmldata, "query");
       
   212   ns = xmlnode_get_attrib(x, "xmlns");
       
   213   if (ns && !strcmp(ns, NS_ROSTER)) {
       
   214     handle_iq_roster(x);
       
   215   } else {
       
   216     iq_error = TRUE;
       
   217   }
       
   218 
   201   if (!id) return;
   219   if (!id) return;
   202 
   220 
   203   /* Not implemented yet: send an error stanza */
   221   if (!iq_error) {
   204   x = xmlnode_new_tag("iq");
   222     x = xmlnode_new_tag("iq");
   205   xmlnode_put_attrib(x, "to", from);
   223     xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
   206   xmlnode_put_attrib(x, "id", id);
   224     xmlnode_put_attrib(x, "type", "result");
   207   xmlnode_put_attrib(x, "type", TMSG_ERROR);
   225     xmlnode_put_attrib(x, "id", id);
   208   y = xmlnode_insert_tag(x, TMSG_ERROR);
   226   } else {
   209   xmlnode_put_attrib(y, "code", "501");
   227     /* Not implemented yet: send an error stanza */
   210   xmlnode_put_attrib(y, "type", "cancel");
   228     x = xmlnode_dup(xmldata);
   211   z = xmlnode_insert_tag(y, "feature-not-implemented");
   229     xmlnode_put_attrib(x, "to", xmlnode_get_attrib(xmldata, "from"));
   212   xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
   230     xmlnode_hide_attrib(x, "from");
       
   231     xmlnode_put_attrib(x, "type", "result");
       
   232     xmlnode_put_attrib(x, "type", TMSG_ERROR);
       
   233     y = xmlnode_insert_tag(x, TMSG_ERROR);
       
   234     xmlnode_put_attrib(y, "code", "501");
       
   235     xmlnode_put_attrib(y, "type", "cancel");
       
   236     z = xmlnode_insert_tag(y, "feature-not-implemented");
       
   237     xmlnode_put_attrib(z, "xmlns", NS_XMPP_STANZAS);
       
   238   }
   213 
   239 
   214   jab_send(conn, x);
   240   jab_send(conn, x);
   215   xmlnode_free(x);
   241   xmlnode_free(x);
   216 }
   242 }
   217 
   243