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

void dialback ( instance  i,
xmlnode  x 
)

init and register the dialback component in the server

Parameters:
i the jabber server's data about this instance
x xmlnode of this instances configuration (???)

Definition at line 1239 of file dialback.cc.

References dialback_beat_idle(), dialback_in_read(), dialback_out_beat_packets(), dialback_packets(), dialback_randstr(), db_struct::hosts_auth, db_struct::hosts_tls, db_struct::hosts_xmpp, db_struct::i, db_struct::in_id, db_struct::in_ok_db, mio_karma2(), mio_listen(), mio_rate(), xmlnode_list_item_t::next, xmlnode_list_item_t::node, db_struct::nscache, db_struct::out_connecting, db_struct::out_ok_db, instance_struct::p, pmalloco(), pool_cleanup(), pstrdup(), register_beat(), register_phandler(), db_struct::secret, db_struct::std_ns_prefixes, db_struct::timeout_auth, db_struct::timeout_idle, db_struct::timeout_packets, db_struct::xc, xdb_cache(), xdb_get(), xhash_free(), xhash_new(), xhash_put(), xmlnode_free(), xmlnode_get_attrib_ns(), xmlnode_get_data(), xmlnode_get_list_item(), xmlnode_get_list_item_data(), xmlnode_get_tags(), and xmlnode_pool().

                                                {
    db d;
    xmlnode cfg, cur;
    xmlnode_list_item cur_item;
    struct karma k;
    int max;
    int rate_time, rate_points;
    int set_rate = 0, set_karma=0;

    log_debug2(ZONE, LOGT_INIT, "dialback loading");
    srand(time(NULL));


    d = static_cast<db>(pmalloco(i->p, sizeof(_db)));

    /* get the config */
    d->xc = xdb_cache(i);
    cfg = xdb_get(d->xc, jid_new(xmlnode_pool(x), "config@-internal"), NS_JABBERD_CONFIG_DIALBACK);

    d->std_ns_prefixes = xhash_new(17);
    xhash_put(d->std_ns_prefixes, "", const_cast<char*>(NS_SERVER));
    xhash_put(d->std_ns_prefixes, "stream", const_cast<char*>(NS_STREAM));
    xhash_put(d->std_ns_prefixes, "db", const_cast<char*>(NS_DIALBACK));
    xhash_put(d->std_ns_prefixes, "wrap", const_cast<char*>(NS_JABBERD_WRAPPER));
    xhash_put(d->std_ns_prefixes, "tls", const_cast<char*>(NS_XMPP_TLS));
    xhash_put(d->std_ns_prefixes, "sasl", const_cast<char*>(NS_XMPP_SASL));
    xhash_put(d->std_ns_prefixes, "conf", const_cast<char*>(NS_JABBERD_CONFIG_DIALBACK));
    xhash_put(d->std_ns_prefixes, "discoinfo", const_cast<char*>(NS_DISCO_INFO));
    xhash_put(d->std_ns_prefixes, "discoitems", const_cast<char*>(NS_DISCO_ITEMS));

    max = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cfg, "conf:maxhosts", d->std_ns_prefixes), 0), 997);
    d->nscache = xhash_new(max);
    pool_cleanup(i->p, (pool_cleaner)xhash_free, d->nscache);
    d->out_connecting = xhash_new(67);
    pool_cleanup(i->p, (pool_cleaner)xhash_free, d->out_connecting);
    d->out_ok_db = xhash_new(max);
    pool_cleanup(i->p, (pool_cleaner)xhash_free, d->out_ok_db);
    d->in_id = xhash_new(max);
    pool_cleanup(i->p, (pool_cleaner)xhash_free, d->in_id);
    d->in_ok_db = xhash_new(max);
    pool_cleanup(i->p, (pool_cleaner)xhash_free, d->in_ok_db);
    d->hosts_xmpp = xhash_new(max);
    pool_cleanup(i->p, (pool_cleaner)xhash_free, d->hosts_xmpp);
    d->hosts_tls = xhash_new(max);
    pool_cleanup(i->p, (pool_cleaner)xhash_free, d->hosts_tls);
    d->hosts_auth = xhash_new(max);
    pool_cleanup(i->p, (pool_cleaner)xhash_free, d->hosts_auth);
    d->i = i;
    d->timeout_idle = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cfg, "conf:idletimeout", d->std_ns_prefixes), 0), 900);
    d->timeout_packets = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cfg, "conf:queuetimeout", d->std_ns_prefixes), 0), 30);
    d->timeout_auth = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cfg, "conf:authtimeout", d->std_ns_prefixes), 0), d->timeout_idle);
    d->secret = pstrdup(i->p, xmlnode_get_list_item_data(xmlnode_get_tags(cfg, "conf:secret", d->std_ns_prefixes), 0));
    if (d->secret == NULL) /* if there's no configured secret, make one on the fly */
        d->secret = pstrdup(i->p,dialback_randstr());

    /* Get rate info if it exists */
    cur = xmlnode_get_list_item(xmlnode_get_tags(cfg, "conf:rate", d->std_ns_prefixes), 0);
    if (cur != NULL) {
        rate_time   = j_atoi(xmlnode_get_attrib_ns(cur, "time", NULL), 0);
        rate_points = j_atoi(xmlnode_get_attrib_ns(cur, "points", NULL), 0);
        set_rate = 1; /* set to true */
    }

    /* Get karma info if it exists */
    cur = xmlnode_get_list_item(xmlnode_get_tags(cfg, "conf:karma", d->std_ns_prefixes), 0);
    if (cur != NULL) {
         k.val         = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cur, "conf:init", d->std_ns_prefixes), 0), KARMA_INIT);
         k.max         = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cur, "conf:max", d->std_ns_prefixes), 0), KARMA_MAX);
         k.inc         = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cur, "conf:inc", d->std_ns_prefixes), 0), KARMA_INC);
         k.dec         = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cur, "conf:dec", d->std_ns_prefixes), 0), KARMA_DEC);
         k.restore     = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cur, "conf:restore", d->std_ns_prefixes), 0), KARMA_RESTORE);
         k.penalty     = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cur, "conf:penalty", d->std_ns_prefixes), 0), KARMA_PENALTY);
         k.reset_meter = j_atoi(xmlnode_get_list_item_data(xmlnode_get_tags(cur, "conf:resetmeter", d->std_ns_prefixes), 0), KARMA_RESETMETER);
         set_karma = 1; /* set to true */
    }

    cur_item = xmlnode_get_tags(cfg, "conf:ip", d->std_ns_prefixes);
    if (cur_item != NULL) {
        for (; cur_item != NULL; cur_item = cur_item->next) {
            mio m;
            m = mio_listen(j_atoi(xmlnode_get_attrib_ns(cur_item->node, "port", NULL), 5269), xmlnode_get_data(cur_item->node), dialback_in_read, (void*)d, MIO_LISTEN_XML);
            if(m == NULL)
                return;
            /* Set New rate and points */
            if(set_rate == 1) mio_rate(m, rate_time, rate_points);
            /* Set New karma values */
            if(set_karma == 1) mio_karma2(m, &k);
        }
    } else {
      /* no special config, use defaults */
        mio m;
        m = mio_listen(5269,NULL,dialback_in_read,(void*)d, MIO_LISTEN_XML);
        if(m == NULL) return;
        /* Set New rate and points */
        if(set_rate == 1) mio_rate(m, rate_time, rate_points);
        /* Set New karma values */
        if(set_karma == 1) mio_karma2(m, &k);
    }

    /* check for hosts where we don't want to use XMPP streams or STARTTLS */
    for (cur_item = xmlnode_get_tags(cfg, "conf:host", d->std_ns_prefixes); cur_item != NULL; cur_item = cur_item->next) {
      char *xmpp = NULL;
      char *tls = NULL;
      char *auth = NULL;
      char *hostname = pstrdup(i->p, xmlnode_get_attrib_ns(cur_item->node, "name", NULL));

      /* the default setting is stored as a setting for '*' */
      if (hostname == NULL)
          hostname = "*";

      xmpp = pstrdup(i->p, xmlnode_get_attrib_ns(cur_item->node, "xmpp", NULL));
      tls = pstrdup(i->p, xmlnode_get_attrib_ns(cur_item->node, "tls", NULL));
      auth = pstrdup(i->p, xmlnode_get_attrib_ns(cur_item->node, "auth", NULL));

      if (xmpp != NULL) {
          xhash_put(d->hosts_xmpp, hostname, xmpp);
      }
      if (tls != NULL) {
          xhash_put(d->hosts_tls, hostname, tls);
      }
      if (auth != NULL) {
          xhash_put(d->hosts_auth, hostname, auth);
      }
    }

    register_phandler(i,o_DELIVER,dialback_packets,(void*)d);
    register_beat(d->timeout_idle < 60 || d->timeout_auth < 60 ? (d->timeout_idle < d->timeout_auth ? d->timeout_idle : d->timeout_auth) : 60, dialback_beat_idle, (void *)d);
    register_beat(d->timeout_packets, dialback_out_beat_packets, (void *)d);

    xmlnode_free(cfg);
}


Generated by  Doxygen 1.6.0   Back to index