Logo Search packages:      
Sourcecode: jabberd14 version File versions  Download package

static void dialback_handle_discoinfo ( db  d,
dpacket  dp,
xmlnode  query,
jid  to 
) [static]

handle an incoming disco info request

Definition at line 374 of file dialback.cc.

References acl_check_access(), dboc::connect_results, connected, connecting, dboc::connection_state, could_request, miod_struct::count, created, dboc::db, db_failed, dboc::db_state, db_succeeded, deliver(), dpacket_new(), dboc::flags, got_features, got_streamroot, db_struct::i, db_struct::in_id, db_struct::in_ok_db, dboc::ip, j_strcmp(), jutil_tofrom(), miod_struct::last, dbic_struct::m, dboc::m, miod_struct::m, miodc::md, messages_get(), dboq_struct::next, not_requested, dbic_struct::other_domain, mio_st::our_ip, mio_st::our_port, db_struct::out_connecting, db_struct::out_ok_db, mio_st::peer_ip, mio_st::peer_port, dboc::q, sasl_fail, sasl_started, sasl_success, sent_db_request, sent_request, dboc::settings_failed, mio_st::ssl, dbic_struct::stamp, dboc::stamp, dboc::stream_id, dboc::verifies, waiting_features, want_request, dbic_struct::we_domain, dpacket_struct::x, db_struct::xc, xhash_get(), xmlnode_free(), xmlnode_get_attrib_ns(), xmlnode_get_firstchild(), xmlnode_get_lang(), xmlnode_get_nextsibling(), xmlnode_hide(), xmlnode_insert_tag_ns(), xmlnode_pool(), xmlnode_put_attrib_ns(), dbic_struct::xmpp_version, and dboc::xmpp_version.

Referenced by dialback_packets().

                                                                               {
    const char *node = xmlnode_get_attrib_ns(query, "node", NULL);
    xmlnode result = NULL;
    xmlnode x = NULL;
    jid requestor = NULL;
    int s2s_right = 0;
    const char* lang = xmlnode_get_lang(query);

    /* sanity check */
    if (to == NULL)
      return;

    /* we only reply get requests */
    /* XXX deny set requests */
    if (j_strcmp(xmlnode_get_attrib_ns(dp->x, "type", NULL), "get") != 0) {
      xmlnode_free(dp->x);
      return;
    }

    /* check the rights of the requesting user */
    requestor = jid_new(xmlnode_pool(dp->x), xmlnode_get_attrib_ns(dp->x, "from", NULL));
    s2s_right = acl_check_access(d->xc, "s2s", requestor);

    /* generate basic result */
    jutil_tofrom(dp->x);
    xmlnode_put_attrib_ns(dp->x, "type", NULL, NULL, "result");
    xmlnode_hide(query);
    result = xmlnode_insert_tag_ns(dp->x, "query", NULL, NS_DISCO_INFO);

    if (s2s_right && to->user == NULL && to->resource == NULL && node == NULL) {
      x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "category", NULL, NULL, "component");
      xmlnode_put_attrib_ns(x, "type", NULL, NULL, "s2s");
      xmlnode_put_attrib_ns(x, "name", NULL, NULL, "s2s component of " PACKAGE " " VERSION);

      x = xmlnode_insert_tag_ns(result, "feature", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "var", NULL, NULL, "xmllang");

      x = xmlnode_insert_tag_ns(result, "feature", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "var", NULL, NULL, "stringprep");

      x = xmlnode_insert_tag_ns(result, "feature", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "var", NULL, NULL, "urn:ietf:params:xml:ns:xmpp-tls#s2s");

      x = xmlnode_insert_tag_ns(result, "feature", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "var", NULL, NULL, "urn:ietf:params:xml:ns:xmpp-sasl#s2s");

#ifdef WITH_IPV6
      x = xmlnode_insert_tag_ns(result, "feature", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "var", NULL, NULL, "ipv6");
#endif
    } else if (s2s_right && j_strcmp(to->user, "out-established") == 0 && to->resource == NULL && node == NULL) {
      x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
      xmlnode_put_attrib_ns(x, "type", NULL, NULL, "branch");
      xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("established outgoing connections")));
    } else if (s2s_right && j_strcmp(to->user, "out-connecting") == 0 && to->resource == NULL && node == NULL) {
      x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
      xmlnode_put_attrib_ns(x, "type", NULL, NULL, "branch");
      xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("connecting outgoing connections")));
    } else if (s2s_right && j_strcmp(to->user, "in-established") == 0 && to->resource == NULL && node == NULL) {
      x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
      xmlnode_put_attrib_ns(x, "type", NULL, NULL, "branch");
      xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("established incoming connections")));
    } else if (s2s_right && j_strcmp(to->user, "in-connecting") == 0 && to->resource == NULL && node == NULL) {
      x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
      xmlnode_put_attrib_ns(x, "type", NULL, NULL, "branch");
      xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("connecting incoming connections")));
    } else if (s2s_right && j_strcmp(to->user, "out-established") == 0 && to->resource != NULL && node == NULL) {
      x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
      xmlnode_put_attrib_ns(x, "type", NULL, NULL, "branch");
      xmlnode_put_attrib_ns(x, "name", NULL, NULL, to->resource);
    } else if (s2s_right && j_strcmp(to->user, "out-established") == 0 && to->resource != NULL && j_strcmp(node, "last") == 0) {
      char last_time[32];
      miod md = static_cast<miod>(xhash_get(d->out_ok_db, to->resource));

      if (md == NULL) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("-- connection gone --")));
      } else {
          struct tm last_utc;
          time_t last = md->last;

          if (gmtime_r(&last, &last_utc)) {
            char last_str[36];

            snprintf(last_str, sizeof(last_str), "%s %d-%02d-%02d %02d:%02d:%02d UTC", messages_get(lang, N_("Last used:")),
                  1900+last_utc.tm_year, last_utc.tm_mon+1, last_utc.tm_mday, last_utc.tm_hour, last_utc.tm_min, last_utc.tm_sec);

            x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
            xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
            xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
            xmlnode_put_attrib_ns(x, "name", NULL, NULL, last_str);
          }
      }
    } else if (s2s_right && j_strcmp(to->user, "out-established") == 0 && to->resource != NULL && j_strcmp(node, "count") == 0) {
      miod md = static_cast<miod>(xhash_get(d->out_ok_db, to->resource));

      if (md == NULL) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("-- connection gone --")));
      } else {
          char name_str[36];

          snprintf(name_str, sizeof(name_str), "%s %d", messages_get(lang, N_("Stanza count:")), md->count);

          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, name_str);
      }
    } else if (s2s_right && j_strcmp(to->user, "out-established") == 0 && to->resource != NULL && j_strcmp(node, "ip") == 0) {
      miod md = static_cast<miod>(xhash_get(d->out_ok_db, to->resource));

      if (md == NULL || md->m == NULL) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("-- connection gone --")));
      } else {
          char ip_str[128];

          snprintf(ip_str, sizeof(ip_str), "%s %s=%s;%d %s=%s;%d %s=%s",
                messages_get(lang, N_("IP/port:")),
                messages_get(lang, N_("local")),
                md->m->our_ip,
                md->m->our_port,
                messages_get(lang, N_("remote")),
                md->m->peer_ip,
                md->m->peer_port,
                messages_get(lang, N_("tls")),
                md->m->ssl == NULL ? messages_get(lang, N_("no")) : messages_get(lang, N_("yes")));

          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, ip_str);
      }
    } else if (s2s_right && j_strcmp(to->user, "out-connecting") == 0 && to->resource != NULL && node == NULL) {
      x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
      xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
      xmlnode_put_attrib_ns(x, "name", NULL, NULL, to->resource);
    } else if (s2s_right && j_strcmp(to->user, "out-connecting") == 0 && to->resource != NULL && node != NULL) {
      dboc dc = static_cast<dboc>(xhash_get(d->out_connecting, to->resource));

      if (dc == NULL) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("-- connection gone or now established --")));
      } else if (j_strcmp(node, "ip") == 0) {
          char ip_str[128];

          if (dc->m != NULL) {
            snprintf(ip_str, sizeof(ip_str), "%s: %s=%s;%d %s=%s;%d %s=%s",
                  messages_get(lang, N_("IP/port:")),
                  messages_get(lang, N_("local")),
                  dc->m->our_ip, dc->m->our_port,
                  messages_get(lang, N_("remote")),
                  dc->m->peer_ip, dc->m->peer_port,
                  messages_get(lang, N_("tls")),
                  dc->m->ssl == NULL ? messages_get(lang, N_("no")) : messages_get(lang, N_("yes")));
          } else {
            snprintf(ip_str, sizeof(ip_str), messages_get(lang, N_("IP/port: no current connection")));
          }

          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, ip_str);
      } else if (j_strcmp(node, "last") == 0) {
          struct tm last_utc;
          time_t last = dc->stamp;

          if (gmtime_r(&last, &last_utc)) {
            char last_str[64];

            snprintf(last_str, sizeof(last_str), "%s %d-%02d-%02d %02d:%02d:%02d UTC", messages_get(lang, N_("Connection start:")),
                  1900+last_utc.tm_year, last_utc.tm_mon+1, last_utc.tm_mday, last_utc.tm_hour, last_utc.tm_min, last_utc.tm_sec);

            x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
            xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
            xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
            xmlnode_put_attrib_ns(x, "name", NULL, NULL, last_str);
          }
      } else if (j_strcmp(node, "xmppversion") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, dc->xmpp_version < 0 ? messages_get(lang, N_("XMPP version: unknown")) : dc->xmpp_version ? messages_get(lang, N_("XMPP version: 1.0")) : messages_get(lang, N_("XMPP version: 0.9")));
      } else if (j_strcmp(node, "pendingip") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools(xmlnode_pool(result), messages_get(lang, N_("Pending IPs: ")), dc->ip ? dc->ip : messages_get(lang, N_("no more other IPs will be tried")), xmlnode_pool(result)));
      } else if (j_strcmp(node, "id") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools(xmlnode_pool(result), messages_get(lang, N_("Stream ID: ")), dc->stream_id, xmlnode_pool(result)));
      } else if (j_strcmp(node, "dbstate") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools(xmlnode_pool(result), messages_get(lang, N_("Dialback state: ")),
                  dc->db_state == not_requested ? messages_get(lang, N_("no dialback request, just sending verifies")) :
                  dc->db_state == could_request ? messages_get(lang, N_("we could send dialback requests, if we want to")) :
                  dc->db_state == want_request ? messages_get(lang, N_("we want to send dialback requests, but cannot do that yet")) :
                  dc->db_state == sent_request ? messages_get(lang, N_("we have sent a dialback request")) : messages_get(lang, N_("invalid")), xmlnode_pool(result)));
      } else if (j_strcmp(node, "connstate") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools(xmlnode_pool(result), messages_get(lang, N_("Connection state: ")),
                  dc->connection_state == created ? messages_get(lang, N_("created, not yet started to connect")) :
                  dc->connection_state == connecting ? messages_get(lang, N_("we started to connect, no connection yet")) :
                  dc->connection_state == connected ? messages_get(lang, N_("connected to the other host")) :
                  dc->connection_state == got_streamroot ? messages_get(lang, N_("we got peer's stream root")) :
                  dc->connection_state == waiting_features ? messages_get(lang, N_("we are waiting for stream features")) :
                  dc->connection_state == got_features ? messages_get(lang, N_("we got the stream features")) :
                  dc->connection_state == sent_db_request ? messages_get(lang, N_("we sent out a dialback request")) :
                  dc->connection_state == db_succeeded ? messages_get(lang, N_("we had success with our dialback request")) :
                  dc->connection_state == db_failed ? messages_get(lang, N_("dialback failed")) :
                  dc->connection_state == sasl_started ? messages_get(lang, N_("we started to authenticate using sasl")) :
                  dc->connection_state == sasl_fail ? messages_get(lang, N_("there was a SASL authentication failure")) :
                  dc->connection_state == sasl_success ? messages_get(lang, N_("successfully authenticated using SASL")) : messages_get(lang, N_("invalid")), xmlnode_pool(result)));
      } else if (j_strcmp(node, "dialback") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools( xmlnode_pool(result), messages_get(lang, N_("Dialback: ")), dc->flags.db ?  messages_get(lang, N_("supported by peer")) : messages_get(lang, N_("unsupported by peer")), xmlnode_pool(result)));
      } else if (j_strcmp(node, "connectresults") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools(xmlnode_pool(result), messages_get(lang, N_("Connection results: ")), spool_print(dc->connect_results), xmlnode_pool(result)));
      } else if (j_strcmp(node, "failedsettings") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools(xmlnode_pool(result), messages_get(lang, N_("Dropped because of settings: ")), dc->settings_failed ? messages_get(lang, N_("yes")) : messages_get(lang, N_("no")), xmlnode_pool(result)));
      } else if (j_strcmp(node, "verifies") == 0) {
          int count = 0;
          xmlnode iter = NULL;
          char count_str[16];

          for (iter = xmlnode_get_firstchild(dc->verifies); iter != NULL; iter = xmlnode_get_nextsibling(iter)) {
            count++;
          }
          snprintf(count_str, sizeof(count_str), "%d", count);

          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools(xmlnode_pool(result), messages_get(lang, N_("Pending verifies: ")), count_str, xmlnode_pool(result)));
      } else if (j_strcmp(node, "pendingstanzas") == 0) {
          int count = 0;
          dboq iter = NULL;
          char count_str[16];

          for (iter = dc->q; iter != NULL; iter = iter->next) {
            count++;
          }
          snprintf(count_str, sizeof(count_str), "%d", count);

          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools(xmlnode_pool(result), messages_get(lang, N_("Pending stanzas: ")), count_str, xmlnode_pool(result)));
      }
    } else if (s2s_right && j_strcmp(to->user, "in-established") == 0 && to->resource != NULL && node == NULL) {
      x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
      xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
      xmlnode_put_attrib_ns(x, "name", NULL, NULL, to->resource);
    } else if (s2s_right && j_strcmp(to->user, "in-established") == 0 && to->resource != NULL && j_strcmp(node, "last") == 0) {
      char last_time[32];
      miod md = static_cast<miod>(xhash_get(d->in_ok_db, to->resource));

      if (md == NULL) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("-- connection gone --")));
      } else {
          struct tm last_utc;
          time_t last = md->last;

          if (gmtime_r(&last, &last_utc)) {
            char last_str[36];

            snprintf(last_str, sizeof(last_str), "%s: %d-%02d-%02d %02d:%02d:%02d UTC", messages_get(lang, N_("Last used:")),
                  1900+last_utc.tm_year, last_utc.tm_mon+1, last_utc.tm_mday, last_utc.tm_hour, last_utc.tm_min, last_utc.tm_sec);

            x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
            xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
            xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
            xmlnode_put_attrib_ns(x, "name", NULL, NULL, last_str);
          }
      }
    } else if (s2s_right && j_strcmp(to->user, "in-established") == 0 && to->resource != NULL && j_strcmp(node, "count") == 0) {
      miod md = static_cast<miod>(xhash_get(d->in_ok_db, to->resource));

      if (md == NULL) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("-- connection gone --")));
      } else {
          char name_str[36];

          snprintf(name_str, sizeof(name_str), "%s %d", messages_get(lang, N_("Stanza count:")), md->count);

          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, name_str);
      }
    } else if (s2s_right && j_strcmp(to->user, "in-established") == 0 && to->resource != NULL && j_strcmp(node, "ip") == 0) {
      miod md = static_cast<miod>(xhash_get(d->in_ok_db, to->resource));

      if (md == NULL || md->m == NULL) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("-- connection gone --")));
      } else {
          char ip_str[128];

          snprintf(ip_str, sizeof(ip_str), "%s %s=%s;%d %s=%s;%d %s=%s",
                messages_get(lang, N_("IP/port:")),
                messages_get(lang, N_("local")),
                md->m->our_ip, md->m->our_port,
                messages_get(lang, N_("remote")),
                md->m->peer_ip, md->m->peer_port,
                messages_get(lang, N_("tls")),
                md->m->ssl == NULL ? messages_get(lang, N_("no")) : messages_get(lang, N_("yes")));

          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, ip_str);
      }
    } else if (s2s_right && j_strcmp(to->user, "in-connecting") == 0 && to->resource != NULL && node == NULL) {
      x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
      xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
      xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
      xmlnode_put_attrib_ns(x, "name", NULL, NULL, to->resource);
    } else if (s2s_right && j_strcmp(to->user, "in-connecting") == 0 && to->resource != NULL && node != NULL) {
      dbic c = static_cast<dbic>(xhash_get(d->in_id, to->resource));

      if (c == NULL) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("-- connection gone or now established --")));
      } else if (j_strcmp(node, "ip") == 0) {
          char ip_str[128];

          if (c->m != NULL) {
            snprintf(ip_str, sizeof(ip_str), "%s %s=%s;%d %s=%s;%d %s=%s",
                  messages_get(lang, N_("IP/port:")),
                  messages_get(lang, N_("local")),
                  c->m->our_ip, c->m->our_port,
                  messages_get(lang, N_("remote")),
                  c->m->peer_ip, c->m->peer_port,
                  messages_get(lang, N_("tls")),
                  c->m->ssl == NULL ? messages_get(lang, N_("no")) : messages_get(lang, N_("yes")));
          } else {
            snprintf(ip_str, sizeof(ip_str), messages_get(lang, N_("IP/port: no current connection")));
          }

          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, ip_str);
      } else if (j_strcmp(node, "addresses") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, spools(xmlnode_pool(result), messages_get(lang, N_("Addresses:")), " ", messages_get(lang, N_("local")), "=", c->we_domain, ", ", messages_get(lang, N_("peer")), "=", c->other_domain, xmlnode_pool(result)));
      } else if (j_strcmp(node, "xmppversion") == 0) {
          x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
          xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
          xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
          xmlnode_put_attrib_ns(x, "name", NULL, NULL, c->xmpp_version < 0 ? messages_get(lang, N_("XMPP version: unknown")) : c->xmpp_version ? messages_get(lang, N_("XMPP version: 1.0")) : messages_get(lang, N_("XMPP version: 0.9")));
      } else if (j_strcmp(node, "last") == 0) {
          struct tm last_utc;
          time_t last = c->stamp;

          if (gmtime_r(&last, &last_utc)) {
            char last_str[64];

            snprintf(last_str, sizeof(last_str), "%s %d-%02d-%02d %02d:%02d:%02d UTC", messages_get(lang, N_("Connection start:")),
                  1900+last_utc.tm_year, last_utc.tm_mon+1, last_utc.tm_mday, last_utc.tm_hour, last_utc.tm_min, last_utc.tm_sec);

            x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
            xmlnode_put_attrib_ns(x, "category", NULL, NULL, "hierarchy");
            xmlnode_put_attrib_ns(x, "type", NULL, NULL, "leaf");
            xmlnode_put_attrib_ns(x, "name", NULL, NULL, last_str);
          }
      }
    }

    /* send result */
    deliver(dpacket_new(dp->x), d->i);
}


Generated by  Doxygen 1.6.0   Back to index