[xmppd-dev] commit r1520 - in trunk/jabberd14: . dialback dnsrv jabberd jabberd/base jabberd/lib jsm jsm/modules pthsock xdb_file
mail at jabberd.org
mail at jabberd.org
Tue Apr 29 00:31:49 UTC 2008
Author: mawis
Date: Sat Apr 26 23:47:56 2008
New Revision: 1520
Log:
New class for JID handling
Added:
trunk/jabberd14/jabberd/lib/jabberid.cc
- copied, changed from r1519, /trunk/jabberd14/license-header.txt
Modified:
trunk/jabberd14/ChangeLog
trunk/jabberd14/configure.ac
trunk/jabberd14/dialback/dialback.cc
trunk/jabberd14/dialback/dialback.h
trunk/jabberd14/dialback/dialback_in.cc
trunk/jabberd14/dialback/dialback_out.cc
trunk/jabberd14/dnsrv/dnsrv.cc
trunk/jabberd14/jabberd/acl.cc
trunk/jabberd14/jabberd/base/base_accept.cc
trunk/jabberd14/jabberd/base/base_importspool.cc
trunk/jabberd14/jabberd/config.cc
trunk/jabberd14/jabberd/deliver.cc
trunk/jabberd14/jabberd/jabberd.cc
trunk/jabberd14/jabberd/jabberd.h
trunk/jabberd14/jabberd/lib/Makefile.am
trunk/jabberd14/jabberd/lib/expat.cc
trunk/jabberd14/jabberd/lib/hmac.cc
trunk/jabberd14/jabberd/lib/jabberdlib.h
trunk/jabberd14/jabberd/lib/jid.cc
trunk/jabberd14/jabberd/lib/jutil.cc
trunk/jabberd14/jabberd/lib/xhash.cc
trunk/jabberd14/jabberd/mio_tls.cc
trunk/jabberd14/jsm/authreg.cc
trunk/jabberd14/jsm/deliver.cc
trunk/jabberd14/jsm/jsm.h
trunk/jabberd14/jsm/modules/mod_admin.cc
trunk/jabberd14/jsm/modules/mod_agents.cc
trunk/jabberd14/jsm/modules/mod_announce.cc
trunk/jabberd14/jsm/modules/mod_browse.cc
trunk/jabberd14/jsm/modules/mod_disco.cc
trunk/jabberd14/jsm/modules/mod_dynamic.cc
trunk/jabberd14/jsm/modules/mod_echo.cc
trunk/jabberd14/jsm/modules/mod_example.cc
trunk/jabberd14/jsm/modules/mod_last.cc
trunk/jabberd14/jsm/modules/mod_offline.cc
trunk/jabberd14/jsm/modules/mod_presence.cc
trunk/jabberd14/jsm/modules/mod_privacy.cc
trunk/jabberd14/jsm/modules/mod_register.cc
trunk/jabberd14/jsm/modules/mod_roster.cc
trunk/jabberd14/jsm/modules/mod_time.cc
trunk/jabberd14/jsm/modules/mod_useridpolicy.cc
trunk/jabberd14/jsm/modules/mod_vcard.cc
trunk/jabberd14/jsm/modules/mod_version.cc
trunk/jabberd14/jsm/serialization.cc
trunk/jabberd14/jsm/sessions.cc
trunk/jabberd14/jsm/users.cc
trunk/jabberd14/jsm/util.cc
trunk/jabberd14/pthsock/client.cc
trunk/jabberd14/xdb_file/xdb_file.cc
trunk/jabberd14/xdb_file/xdbfiletool.cc
Modified: trunk/jabberd14/ChangeLog
==============================================================================
--- trunk/jabberd14/ChangeLog (original)
+++ trunk/jabberd14/ChangeLog Sat Apr 26 23:47:56 2008
@@ -1,3 +1,54 @@
+2008-04-26 Matthias Wimmer <m at tthias.eu>
+
+ * jabberd/lib/jabberid.cc: new class for JabberID handling
+ * jabberd/jabberd.h: same
+ * jabberd/acl.cc: same
+ * jabberd/config.cc: same
+ * jabberd/mio_tls.cc: same
+ * jabberd/lib/jid.cc: same
+ * jabberd/lib/hmac.cc: same
+ * jabberd/lib/xhash.cc: same
+ * jabberd/lib/expat.cc: same
+ * jabberd/lib/jabberdlib.h: same
+ * jabberd/lib/jutil.cc: same
+ * jabberd/base/base_importspool.cc: same
+ * jabberd/base/base_accept.cc: same
+ * jabberd/jabberd.cc: same
+ * jabberd/deliver.cc: same
+ * jsm/jsm.h: same
+ * jsm/serialization.cc: same
+ * jsm/util.cc: same
+ * jsm/authreg.cc: same
+ * jsm/users.cc: same
+ * jsm/modules/mod_time.cc: same
+ * jsm/modules/mod_vcard.cc: same
+ * jsm/modules/mod_disco.cc: same
+ * jsm/modules/mod_browse.cc: same
+ * jsm/modules/mod_last.cc: same
+ * jsm/modules/mod_presence.cc: same
+ * jsm/modules/mod_announce.cc: same
+ * jsm/modules/mod_useridpolicy.cc: same
+ * jsm/modules/mod_privacy.cc: same
+ * jsm/modules/mod_echo.cc: same
+ * jsm/modules/mod_roster.cc: same
+ * jsm/modules/mod_agents.cc: same
+ * jsm/modules/mod_offline.cc: same
+ * jsm/modules/mod_dynamic.cc: same
+ * jsm/modules/mod_register.cc: same
+ * jsm/modules/mod_version.cc: same
+ * jsm/modules/mod_admin.cc: same
+ * jsm/modules/mod_example.cc: same
+ * jsm/sessions.cc: same
+ * jsm/deliver.cc: same
+ * dialback/dialback.h: same
+ * dialback/dialback_in.cc: same
+ * dialback/dialback_out.cc: same
+ * dialback/dialback.cc: same
+ * dnsrv/dnsrv.cc: same
+ * pthsock/client.cc: same
+ * xdb_file/xdbfiletool.cc: same
+ * xdb_file/xdb_file.cc: same
+
2007-11-27 Matthias Wimmer <m at tthias.eu>
* jabberd/base/base_connect.cc: (try to) unroute host if loop is detected
Modified: trunk/jabberd14/configure.ac
==============================================================================
--- trunk/jabberd14/configure.ac (original)
+++ trunk/jabberd14/configure.ac Sat Apr 26 23:47:56 2008
@@ -6,7 +6,7 @@
AC_INIT(jabberd/jabberd.h)
-AM_INIT_AUTOMAKE(jabberd14,1.9.0-alpha-20071127)
+AM_INIT_AUTOMAKE(jabberd14,1.9.0-alpha-20080426)
AM_CONFIG_HEADER(config.h)
AC_LANG(C++)
Modified: trunk/jabberd14/dialback/dialback.cc
==============================================================================
--- trunk/jabberd14/dialback/dialback.cc (original)
+++ trunk/jabberd14/dialback/dialback.cc Sat Apr 26 23:47:56 2008
@@ -175,7 +175,7 @@
* @param challenge the stream ID that should be verified
* @return the dialback key
*/
-char *dialback_merlin(pool p, char *secret, char *to, char *from, char *challenge) {
+char *dialback_merlin(pool p, char const* secret, char const* to, char const* from, char const* challenge) {
char *result = NULL;
char *message = NULL;
@@ -190,7 +190,7 @@
message = spools(p, to, " ", from, " ", challenge, p);
/* sign the message */
- hmac_sha1_ascii_r(secret, (unsigned char*)message, j_strlen(message), result);
+ hmac_sha1_ascii_r(secret, reinterpret_cast<unsigned char*>(message), j_strlen(message), result);
log_debug2(ZONE, LOGT_AUTH, "merlin casts his spell (%s - %s %s %s) %s", secret, to, from, challenge, result);
@@ -285,10 +285,10 @@
log_debug2(ZONE, LOGT_CLEANUP|LOGT_AUTH, "miod cleaning out socket %d with key %s to hash %X",mdc->md->m->fd, jid_full(mdc->key), mdc->ht);
/* cool place for logging, eh? interesting way of detecting things too, *g* */
if(mdc->ht == mdc->md->d->out_ok_db){
- unregister_instance(mdc->md->d->i, mdc->key->server); /* dynamic host resolution thingie */
- log_record(mdc->key->server, "out", "dialback", "%d %s %s", mdc->md->count, mio_ip(mdc->md->m), mdc->key->resource);
+ unregister_instance(mdc->md->d->i, mdc->key->get_domain().c_str()); /* dynamic host resolution thingie */
+ log_record(mdc->key->get_domain().c_str(), "out", "dialback", "%d %s %s", mdc->md->count, mio_ip(mdc->md->m), mdc->key->get_resource().c_str());
}else if(mdc->ht == mdc->md->d->in_ok_db){
- log_record(mdc->key->server, "in", "dialback", "%d %s %s", mdc->md->count, mio_ip(mdc->md->m), mdc->key->resource);
+ log_record(mdc->key->get_domain().c_str(), "in", "dialback", "%d %s %s", mdc->md->count, mio_ip(mdc->md->m), mdc->key->get_resource().c_str());
}
}
@@ -314,7 +314,7 @@
if(ht == md->d->out_ok_db)
{
dialback_ip_set(md->d, key, mio_ip(md->m)); /* save the ip since it won't be going through the dnsrv anymore */
- register_instance(md->d->i, key->server);
+ register_instance(md->d->i, key->get_domain().c_str());
}
}
@@ -335,8 +335,8 @@
if(ip != NULL)
return ip;
- ret = pstrdup(host->p,xmlnode_get_attrib_ns((xmlnode)xhash_get(d->nscache,host->server),"i", NULL));
- log_debug2(ZONE, LOGT_IO, "returning cached ip %s for %s",ret,host->server);
+ ret = pstrdup(host->get_pool(), xmlnode_get_attrib_ns((xmlnode)xhash_get(d->nscache, host->get_domain().c_str()),"i", NULL));
+ log_debug2(ZONE, LOGT_IO, "returning cached ip %s for %s", ret, host->get_domain().c_str());
return ret;
}
@@ -355,14 +355,14 @@
return;
/* first, get existing cache so we can dump it later */
- old = (xmlnode)xhash_get(d->nscache,host->server);
+ old = (xmlnode)xhash_get(d->nscache, host->get_domain().c_str());
/* new cache */
cache = xmlnode_new_tag_ns("d", NULL, NS_JABBERD_WRAPPER);
- xmlnode_put_attrib_ns(cache, "h", NULL, NULL, host->server);
+ xmlnode_put_attrib_ns(cache, "h", NULL, NULL, host->get_domain().c_str());
xmlnode_put_attrib_ns(cache, "i", NULL, NULL, ip);
xhash_put(d->nscache, xmlnode_get_attrib_ns(cache, "h", NULL), (void*)cache);
- log_debug2(ZONE, LOGT_IO, "cached ip %s for %s",ip,host->server);
+ log_debug2(ZONE, LOGT_IO, "cached ip %s for %s", ip, host->get_domain().c_str());
/* free any old entry that's been replaced */
xmlnode_free(old);
@@ -400,7 +400,7 @@
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) {
+ if (s2s_right && !to->has_node() && !to->has_resource() && 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");
@@ -422,34 +422,34 @@
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) {
+ } else if (s2s_right && to->get_node() == "out-established" && !to->has_resource() && 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) {
+ } else if (s2s_right && to->get_node() == "out-connecting" && !to->has_resource() && 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) {
+ } else if (s2s_right && to->get_node() == "in-established" && !to->has_resource() && 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) {
+ } else if (s2s_right && to->get_node() == "in-connecting" && !to->has_resource() && 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) {
+ } else if (s2s_right && to->get_node() == "out-established" && to->has_resource() && 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) {
+ xmlnode_put_attrib_ns(x, "name", NULL, NULL, to->get_resource().c_str());
+ } else if (s2s_right && to->get_node() == "out-established" && to->has_resource() && j_strcmp(node, "last") == 0) {
char last_time[32];
- miod md = static_cast<miod>(xhash_get(d->out_ok_db, to->resource));
+ miod md = static_cast<miod>(xhash_get(d->out_ok_db, to->get_resource().c_str()));
if (md == NULL) {
x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
@@ -472,8 +472,8 @@
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));
+ } else if (s2s_right && to->get_node() == "out-established" && to->has_resource() && j_strcmp(node, "count") == 0) {
+ miod md = static_cast<miod>(xhash_get(d->out_ok_db, to->get_resource().c_str()));
if (md == NULL) {
x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
@@ -490,8 +490,8 @@
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));
+ } else if (s2s_right && to->get_node() == "out-established" && to->has_resource() && j_strcmp(node, "ip") == 0) {
+ miod md = static_cast<miod>(xhash_get(d->out_ok_db, to->get_resource().c_str()));
if (md == NULL || md->m == NULL) {
x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
@@ -517,13 +517,13 @@
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) {
+ } else if (s2s_right && to->get_node() == "out-connecting" && to->has_resource() && 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));
+ xmlnode_put_attrib_ns(x, "name", NULL, NULL, to->get_resource().c_str());
+ } else if (s2s_right && to->get_node() == "out-connecting" && to->has_resource() && node != NULL) {
+ dboc dc = static_cast<dboc>(xhash_get(d->out_connecting, to->get_resource().c_str()));
if (dc == NULL) {
x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
@@ -650,14 +650,14 @@
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) {
+ } else if (s2s_right && to->get_node() == "in-established" && to->has_resource() && 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) {
+ xmlnode_put_attrib_ns(x, "name", NULL, NULL, to->get_resource().c_str());
+ } else if (s2s_right && to->get_node() == "in-established" && to->has_resource() && j_strcmp(node, "last") == 0) {
char last_time[32];
- miod md = static_cast<miod>(xhash_get(d->in_ok_db, to->resource));
+ miod md = static_cast<miod>(xhash_get(d->in_ok_db, to->get_resource().c_str()));
if (md == NULL) {
x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
@@ -680,8 +680,8 @@
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));
+ } else if (s2s_right && to->get_node() == "in-established" && to->has_resource() && j_strcmp(node, "count") == 0) {
+ miod md = static_cast<miod>(xhash_get(d->in_ok_db, to->get_resource().c_str()));
if (md == NULL) {
x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
@@ -698,8 +698,8 @@
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));
+ } else if (s2s_right && to->get_node() == "in-established" && to->has_resource() && j_strcmp(node, "ip") == 0) {
+ miod md = static_cast<miod>(xhash_get(d->in_ok_db, to->get_resource().c_str()));
if (md == NULL || md->m == NULL) {
x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
@@ -723,13 +723,13 @@
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) {
+ } else if (s2s_right && to->get_node() == "in-connecting" && to->has_resource() && 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));
+ xmlnode_put_attrib_ns(x, "name", NULL, NULL, to->get_resource().c_str());
+ } else if (s2s_right && to->get_node() == "in-connecting" && to->has_resource() && node != NULL) {
+ dbic c = static_cast<dbic>(xhash_get(d->in_id, to->get_resource().c_str()));
if (c == NULL) {
x = xmlnode_insert_tag_ns(result, "identity", NULL, NS_DISCO_INFO);
@@ -901,7 +901,7 @@
result = xmlnode_insert_tag_ns(dp->x, "query", NULL, NS_DISCO_ITEMS);
lang = xmlnode_get_lang(dp->x);
- if (to->user == NULL && to->resource == NULL && node == NULL && s2s_right) {
+ if (!to->has_node() && !to->has_resource() && node == NULL && s2s_right) {
jid item_jid = jid_new(xmlnode_pool(dp->x), d->i->id);
jid_set(item_jid, "out-established", JID_USER);
@@ -923,14 +923,14 @@
x = xmlnode_insert_tag_ns(result, "item", NULL, NS_DISCO_ITEMS);
xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("connecting incoming connections")));
xmlnode_put_attrib_ns(x, "jid", NULL, NULL, jid_full(item_jid));
- } else if (s2s_right && j_strcmp(to->user, "out-established") == 0 && to->resource == NULL && node == NULL) {
+ } else if (s2s_right && to->get_node() == "out-established" && !to->has_resource() && node == NULL) {
_dialback_jid_with_xmlnode jx;
jx.x = result;
jx.id = jid_new(xmlnode_pool(result), d->i->id);
jid_set(jx.id, "out-established", JID_USER);
xhash_walk(d->out_ok_db, _dialback_walk_out_established, (void*)&jx);
- } else if (s2s_right && j_strcmp(to->user, "out-established") == 0 && to->resource != NULL && node == NULL) {
- jid other_server = jid_new(xmlnode_pool(result), to->resource);
+ } else if (s2s_right && to->get_node() == "out-established" && to->has_resource() && node == NULL) {
+ jid other_server = jid_new(xmlnode_pool(result), to->get_resource().c_str());
x = xmlnode_insert_tag_ns(result, "item", NULL, NS_DISCO_ITEMS);
xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("Last used")));
@@ -949,16 +949,16 @@
if (other_server != NULL) {
x = xmlnode_insert_tag_ns(result, "item", NULL, NS_DISCO_ITEMS);
- xmlnode_put_attrib_ns(x, "name", NULL, NULL, other_server->server);
- xmlnode_put_attrib_ns(x, "jid", NULL, NULL, other_server->server);
+ xmlnode_put_attrib_ns(x, "name", NULL, NULL, other_server->get_domain().c_str());
+ xmlnode_put_attrib_ns(x, "jid", NULL, NULL, other_server->get_domain().c_str());
}
- } else if (s2s_right && j_strcmp(to->user, "out-connecting") == 0 && to->resource == NULL && node == NULL) {
+ } else if (s2s_right && to->get_node() == "out-connecting" && !to->has_resource() && node == NULL) {
_dialback_jid_with_xmlnode jx;
jx.x = result;
jx.id = jid_new(xmlnode_pool(result), d->i->id);
jid_set(jx.id, "out-connecting", JID_USER);
xhash_walk(d->out_connecting, _dialback_walk_out_connecting, (void*)&jx);
- } else if (s2s_right && j_strcmp(to->user, "out-connecting") == 0 && to->resource != NULL && node == NULL) {
+ } else if (s2s_right && to->get_node() == "out-connecting" && to->has_resource() && node == NULL) {
x = xmlnode_insert_tag_ns(result, "item", NULL, NS_DISCO_ITEMS);
xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("Connection start")));
xmlnode_put_attrib_ns(x, "jid", NULL, NULL, jid_full(to));
@@ -1018,14 +1018,14 @@
xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("Dialback")));
xmlnode_put_attrib_ns(x, "jid", NULL, NULL, jid_full(to));
xmlnode_put_attrib_ns(x, "node", NULL, NULL, "dialback");
- } else if (s2s_right && j_strcmp(to->user, "in-established") == 0 && to->resource == NULL && node == NULL) {
+ } else if (s2s_right && to->get_node() == "in-established" && !to->has_resource() && node == NULL) {
_dialback_jid_with_xmlnode jx;
jx.x = result;
jx.id = jid_new(xmlnode_pool(result), d->i->id);
jid_set(jx.id, "in-established", JID_USER);
xhash_walk(d->in_ok_db, _dialback_walk_in_established, (void*)&jx);
- } else if (s2s_right && j_strcmp(to->user, "in-established") == 0 && to->resource != NULL && node == NULL) {
- jid other_server = jid_new(xmlnode_pool(result), to->resource);
+ } else if (s2s_right && to->get_node() == "in-established" && to->has_resource() && node == NULL) {
+ jid other_server = jid_new(xmlnode_pool(result), to->get_resource().c_str());
x = xmlnode_insert_tag_ns(result, "item", NULL, NS_DISCO_ITEMS);
xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("Last used")));
@@ -1044,16 +1044,16 @@
if (other_server != NULL) {
x = xmlnode_insert_tag_ns(result, "item", NULL, NS_DISCO_ITEMS);
- xmlnode_put_attrib_ns(x, "name", NULL, NULL, other_server->resource);
- xmlnode_put_attrib_ns(x, "jid", NULL, NULL, other_server->resource);
+ xmlnode_put_attrib_ns(x, "name", NULL, NULL, other_server->get_resource().c_str());
+ xmlnode_put_attrib_ns(x, "jid", NULL, NULL, other_server->get_resource().c_str());
}
- } else if (s2s_right && j_strcmp(to->user, "in-connecting") == 0 && to->resource == NULL && node == NULL) {
+ } else if (s2s_right && to->get_node() == "in-connecting" && !to->has_resource() && node == NULL) {
_dialback_jid_with_xmlnode jx;
jx.x = result;
jx.id = jid_new(xmlnode_pool(result), d->i->id);
jid_set(jx.id, "in-connecting", JID_USER);
xhash_walk(d->in_id, _dialback_walk_in_connecting, (void*)&jx);
- } else if (s2s_right && j_strcmp(to->user, "in-connecting") == 0 && to->resource != NULL && node == NULL) {
+ } else if (s2s_right && to->get_node() == "in-connecting" && to->has_resource() && node == NULL) {
x = xmlnode_insert_tag_ns(result, "item", NULL, NS_DISCO_ITEMS);
xmlnode_put_attrib_ns(x, "name", NULL, NULL, messages_get(lang, N_("IP/port")));
xmlnode_put_attrib_ns(x, "jid", NULL, NULL, jid_full(to));
@@ -1112,7 +1112,7 @@
return r_DONE;
}
to = jid_new(xmlnode_pool(x), xmlnode_get_attrib_ns(x, "to", NULL));
- if (j_strcmp(to->server, d->i->id) == 0) {
+ if (d->i->id && to->get_domain() == d->i->id) {
xmlnode x2 = NULL;
/* some packets we do respond */
Modified: trunk/jabberd14/dialback/dialback.h
==============================================================================
--- trunk/jabberd14/dialback/dialback.h (original)
+++ trunk/jabberd14/dialback/dialback.h Sat Apr 26 23:47:56 2008
@@ -79,7 +79,7 @@
int dialback_check_settings(db d, mio m, const char *server, int is_outgoing, int auth_type, int version);
char *dialback_randstr(void);
-char *dialback_merlin(pool p, char *secret, char *to, char *from, char *challenge);
+char *dialback_merlin(pool p, char const* secret, char const* to, char const* from, char const* challenge);
void dialback_miod_hash(miod md, xht ht, jid key);
miod dialback_miod_new(db d, mio m);
void dialback_miod_write(miod md, xmlnode x);
Modified: trunk/jabberd14/dialback/dialback_in.cc
==============================================================================
--- trunk/jabberd14/dialback/dialback_in.cc (original)
+++ trunk/jabberd14/dialback/dialback_in.cc Sat Apr 26 23:47:56 2008
@@ -217,7 +217,7 @@
other_side_jid = jid_new(x->p, decoded_initial_exchange);
/* we only accept servers, no users */
- if (!other_side_jid || other_side_jid->user || other_side_jid->resource) {
+ if (!other_side_jid || other_side_jid->has_node() || other_side_jid->has_resource()) {
mio_write(m, NULL, "<failure xmlns='" NS_XMPP_SASL "'><invalid-authzid/></failure></stream:stream>", -1);
mio_close(m);
xmlnode_free(x);
@@ -233,7 +233,7 @@
}
/* check the security settings */
- if (!dialback_check_settings(c->d, c->m, other_side_jid->server, 0, 1, c->xmpp_version)) {
+ if (!dialback_check_settings(c->d, c->m, other_side_jid->get_domain().c_str(), 0, 1, c->xmpp_version)) {
mio_write(m, NULL, "<failure xmlns='" NS_XMPP_SASL "'><mechanism-too-weak/></failure></stream:stream>", -1);
mio_close(m);
xmlnode_free(x);
@@ -281,7 +281,7 @@
}
/* make our special key */
- jid_set(key,from->server,JID_RESOURCE);
+ jid_set(key, from->get_domain().c_str(), JID_RESOURCE);
jid_set(key,c->id,JID_USER); /* special user of the id attrib makes this key unique */
/* incoming result, track it and forward on */
@@ -549,7 +549,7 @@
/* accept incoming stanzas on this connection */
dialback_miod_hash(dialback_miod_new(c->d, c->m), c->d->in_ok_db, key);
} else
- log_warn(d->i->id, "Denying peer to use the domain %s. Dialback failed (%s): %s", key->resource, type ? type : "timeout", xmlnode_serialize_string(x2, xmppd::ns_decl_list(), 0));
+ log_warn(d->i->id, "Denying peer to use the domain %s. Dialback failed (%s): %s", key->get_resource().c_str(), type ? type : "timeout", xmlnode_serialize_string(x2, xmppd::ns_decl_list(), 0));
/* rewrite and send on to the socket */
mio_write(c->m, x2, NULL, -1);
Modified: trunk/jabberd14/dialback/dialback_out.cc
==============================================================================
--- trunk/jabberd14/dialback/dialback_out.cc (original)
+++ trunk/jabberd14/dialback/dialback_out.cc Sat Apr 26 23:47:56 2008
@@ -142,9 +142,9 @@
} else if (c->db_state == could_request) {
/* send <db:result/> to request dialback */
xmlnode db_result = xmlnode_new_tag_ns("result", "db", NS_DIALBACK);
- xmlnode_put_attrib_ns(db_result, "to", NULL, NULL, c->key->server);
- xmlnode_put_attrib_ns(db_result, "from", NULL, NULL, c->key->resource);
- xmlnode_insert_cdata(db_result, dialback_merlin(xmlnode_pool(db_result), c->d->secret, c->key->server, c->key->resource, c->stream_id), -1);
+ xmlnode_put_attrib_ns(db_result, "to", NULL, NULL, c->key->get_domain().c_str());
+ xmlnode_put_attrib_ns(db_result, "from", NULL, NULL, c->key->get_resource().c_str());
+ xmlnode_insert_cdata(db_result, dialback_merlin(xmlnode_pool(db_result), c->d->secret, c->key->get_domain().c_str(), c->key->get_resource().c_str(), c->stream_id), -1);
mio_write(c->m,db_result, NULL, 0);
c->db_state = sent_request;
log_debug2(ZONE, LOGT_IO, "packet for existing connection: state change could_request -> sent_request");
@@ -240,7 +240,7 @@
/* if there was never any ->m set but there's a queue yet, then we probably never got connected, just make a note of it */
if(c->m == NULL && c->q != NULL) {
- log_notice(c->d->i->id, "failed to establish connection to %s, %s: %s", c->key->server, dialback_out_connection_state_string(c->connection_state), connect_results);
+ log_notice(c->d->i->id, "failed to establish connection to %s, %s: %s", c->key->get_domain().c_str(), dialback_out_connection_state_string(c->connection_state), connect_results);
}
/* if there's any packets in the queue, flush them! */
@@ -307,7 +307,7 @@
log_debug2(ZONE, LOGT_IO, "dbout packet[%s]: %s", ip, xmlnode_serialize_string(x, xmppd::ns_decl_list(), 0));
/* db:verify packets come in with us as the sender */
- if (j_strcmp(from->server, d->i->id) == 0) {
+ if (j_strcmp(from->get_domain().c_str(), d->i->id) == 0) {
verify = 1;
/* fix the headers, restore the real from */
/* (I think we wouldn't need to from/ofrom thing anymore because we have dnsqueryby, that we need for s2s clustering) */
@@ -318,8 +318,8 @@
}
/* build the standard key */
- key = jid_new(xmlnode_pool(x), to->server);
- jid_set(key, from->server, JID_RESOURCE);
+ key = jid_new(xmlnode_pool(x), to->get_domain().c_str());
+ jid_set(key, from->get_domain().c_str(), JID_RESOURCE);
/* try to get an active connection */
md = static_cast<miod>(xhash_get(d->out_ok_db, jid_full(key)));
@@ -330,7 +330,7 @@
if (md != NULL) {
/* if we've got an ip sent, and a connected host, we should be registered! */
if (ip != NULL)
- register_instance(md->d->i, key->server);
+ register_instance(md->d->i, key->get_domain().c_str());
dialback_miod_write(md, x);
return;
}
@@ -497,11 +497,11 @@
}
/* outgoing conneciton, write the header */
- cur = xstream_header(c->key->server, c->key->resource);
+ cur = xstream_header(c->key->get_domain().c_str(), c->key->get_resource().c_str());
xmlnode_hide_attrib_ns(cur, "id", NULL); /* no, we don't need the id on this stream */
- if (j_strcmp(static_cast<char*>(xhash_get_by_domain(c->d->hosts_auth, c->key->server)), "sasl") != 0)
+ if (j_strcmp(static_cast<char*>(xhash_get_by_domain(c->d->hosts_auth, c->key->get_domain().c_str())), "sasl") != 0)
xmlnode_put_attrib_ns(cur, "db", "xmlns", NS_XMLNS, NS_DIALBACK); /* flag ourselves as dialback capable */
- if (j_strcmp(static_cast<char*>(xhash_get_by_domain(c->d->hosts_xmpp, c->key->server)), "no") != 0) {
+ if (j_strcmp(static_cast<char*>(xhash_get_by_domain(c->d->hosts_xmpp, c->key->get_domain().c_str())), "no") != 0) {
/* we flag support for XMPP 1.0 */
xmlnode_put_attrib_ns(cur, "version", NULL, NULL, "1.0");
}
@@ -514,7 +514,7 @@
if (c->connection_state != sasl_success)
c->connection_state = got_streamroot;
else {
- if (dialback_check_settings(c->d, m, c->key->server, 1, 1, c->xmpp_version) == 0) {
+ if (dialback_check_settings(c->d, m, c->key->get_domain().c_str(), 1, 1, c->xmpp_version) == 0) {
c->settings_failed = 1;
break;
}
@@ -530,7 +530,7 @@
/* make sure we're not connecting to ourselves */
if (xhash_get(c->d->in_id,c->stream_id) != NULL) {
- log_alert(c->key->server,"hostname maps back to ourselves!- No service defined for this hostname, can not handle request. Check jabberd configuration.");
+ log_alert(c->key->get_domain().c_str(), "hostname maps back to ourselves!- No service defined for this hostname, can not handle request. Check jabberd configuration.");
mio_write(m, NULL, "<stream:error><internal-server-error xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xmlns='urn:ietf:params:xml:ns:xmpp-streams' xml:lang='en'>Mirror Mirror on the wall (we connected to ourself)</text></stream:error>", -1);
mio_close(m);
break;
@@ -548,7 +548,7 @@
/* deprecated non-dialback protocol, reject connection */
if (c->xmpp_version < 1 && !c->flags.db) {
/* Muahahaha! you suck! *click* */
- log_notice(c->key->server,"Legacy server access denied");
+ log_notice(c->key->get_domain().c_str(), "Legacy server access denied");
mio_write(m, NULL, "<stream:error><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xmlns='urn:ietf:params:xml:ns:xmpp-streams' xml:lang='en'>Legacy Access Denied!</text></stream:error>", -1);
mio_close(m);
break;
@@ -557,13 +557,13 @@
/* create and send our result request to initiate dialback for non XMPP-sessions (XMPP has to wait for stream features) */
if (c->xmpp_version < 1) {
/* check the require-tls setting */
- if (dialback_check_settings(c->d, m, c->key->server, 1, 0, c->xmpp_version) == 0) {
+ if (dialback_check_settings(c->d, m, c->key->get_domain().c_str(), 1, 0, c->xmpp_version) == 0) {
c->settings_failed = 1;
break;
}
if (j_strcmp(static_cast<char*>(xhash_get_by_domain(c->d->hosts_auth, "sasl")), "sasl") == 0) {
- log_warn(c->d->i->id, "pre-XMPP 1.0 peer %s cannot support SASL, but we are configured to require this.", c->key->server);
+ log_warn(c->d->i->id, "pre-XMPP 1.0 peer %s cannot support SASL, but we are configured to require this.", c->key->get_domain().c_str());
mio_write(m, NULL, "<stream:error><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>Sorry, but we require SASL auth, but you seem to only support dialback.</text></stream:error>", -1);
mio_close(m);
break;
@@ -573,9 +573,9 @@
if (c->db_state == want_request) {
/* send db request */
cur = xmlnode_new_tag_ns("result", "db", NS_DIALBACK);
- xmlnode_put_attrib_ns(cur, "to", NULL, NULL, c->key->server);
- xmlnode_put_attrib_ns(cur, "from", NULL, NULL, c->key->resource);
- xmlnode_insert_cdata(cur, dialback_merlin(xmlnode_pool(cur), c->d->secret, c->key->server, c->key->resource, c->stream_id), -1);
+ xmlnode_put_attrib_ns(cur, "to", NULL, NULL, c->key->get_domain().c_str());
+ xmlnode_put_attrib_ns(cur, "from", NULL, NULL, c->key->get_resource().c_str());
+ xmlnode_insert_cdata(cur, dialback_merlin(xmlnode_pool(cur), c->d->secret, c->key->get_domain().c_str(), c->key->get_resource().c_str(), c->stream_id), -1);
mio_write(m,cur, NULL, 0);
c->db_state = sent_request;
c->connection_state = sent_db_request;
@@ -661,14 +661,14 @@
/* is starttls supported? */
if (xmlnode_get_list_item(xmlnode_get_tags(x, "tls:starttls", c->d->std_ns_prefixes), 0) != NULL) {
/* don't start if forbidden by caller (configuration) */
- if (j_strcmp(static_cast<char*>(xhash_get_by_domain(c->d->hosts_tls, c->key->server)), "no") == 0) {
- log_notice(c->d->i->id, "Server %s advertized starttls, but disabled by our configuration.", c->key->server);
- } else if (mio_ssl_starttls_possible(m, c->key->resource)) {
+ if (j_strcmp(static_cast<char*>(xhash_get_by_domain(c->d->hosts_tls, c->key->get_domain().c_str())), "no") == 0) {
+ log_notice(c->d->i->id, "Server %s advertized starttls, but disabled by our configuration.", c->key->get_domain().c_str());
+ } else if (mio_ssl_starttls_possible(m, c->key->get_resource().c_str())) {
/* our side is prepared for starttls */
xmlnode starttls = NULL;
/* request to start tls on this connection */
- log_debug2(ZONE, LOGT_IO, "requesting starttls for an outgoing connection to %s", c->key->server);
+ log_debug2(ZONE, LOGT_IO, "requesting starttls for an outgoing connection to %s", c->key->get_domain().c_str());
starttls = xmlnode_new_tag_ns("starttls", NULL, NS_XMPP_TLS);
mio_write(m, starttls, NULL, 0);
@@ -697,9 +697,9 @@
xmlnode_put_attrib_ns(auth, "mechanism", NULL, NULL, xmlnode_get_data(mechanism));
/* add our id as base64 encoded CDATA */
- base64_source_domain_len = (j_strlen(c->key->resource)+2)/3*4+1;
+ base64_source_domain_len = (c->key->get_resource().length()+2)/3*4+1;
base64_source_domain = static_cast<char*>(pmalloco(xmlnode_pool(x), base64_source_domain_len));
- base64_encode((unsigned char *)c->key->resource, j_strlen(c->key->resource), base64_source_domain, base64_source_domain_len);
+ base64_encode((unsigned char *)c->key->get_resource().c_str(), c->key->get_resource().length(), base64_source_domain, base64_source_domain_len);
xmlnode_insert_cdata(auth, base64_source_domain, -1);
/* send the initial exchange */
@@ -717,7 +717,7 @@
}
/* no stream:feature we'd like to use, now check the settings */
- if (dialback_check_settings(c->d, m, c->key->server, 1, 0, c->xmpp_version) == 0) {
+ if (dialback_check_settings(c->d, m, c->key->get_domain().c_str(), 1, 0, c->xmpp_version) == 0) {
c->settings_failed = 1;
break;
}
@@ -727,9 +727,9 @@
if (c->db_state == want_request) {
/* send the dialback query */
cur = xmlnode_new_tag_ns("result", "db", NS_DIALBACK);
- xmlnode_put_attrib_ns(cur, "to", NULL, NULL, c->key->server);
- xmlnode_put_attrib_ns(cur, "from", NULL, NULL, c->key->resource);
- xmlnode_insert_cdata(cur, dialback_merlin(xmlnode_pool(cur), c->d->secret, c->key->server, c->key->resource, c->stream_id), -1);
+ xmlnode_put_attrib_ns(cur, "to", NULL, NULL, c->key->get_domain().c_str());
+ xmlnode_put_attrib_ns(cur, "from", NULL, NULL, c->key->get_resource().c_str());
+ xmlnode_insert_cdata(cur, dialback_merlin(xmlnode_pool(cur), c->d->secret, c->key->get_domain().c_str(), c->key->get_resource().c_str(), c->stream_id), -1);
mio_write(m,cur, NULL, 0);
c->db_state = sent_request;
c->connection_state = sent_db_request;
@@ -749,9 +749,9 @@
/* watch for positive starttls result */
if (j_strcmp(xmlnode_get_localname(x), "proceed") == 0 && j_strcmp(xmlnode_get_namespace(x), NS_XMPP_TLS) == 0) {
/* start tls on our side */
- if (mio_xml_starttls(m, 1, c->key->resource)) {
+ if (mio_xml_starttls(m, 1, c->key->get_resource().c_str())) {
/* starting tls failed */
- log_warn(c->d->i->id, "Starting TLS on an outgoing s2s to %s failed on our side (%s).", c->key->server, c->key->resource);
+ log_warn(c->d->i->id, "Starting TLS on an outgoing s2s to %s failed on our side (%s).", c->key->get_domain().c_str(), c->key->get_resource().c_str());
mio_close(m);
break;
}
@@ -767,7 +767,7 @@
/* watch for negative starttls result */
if (j_strcmp(xmlnode_get_localname(x), "failure") == 0 && j_strcmp(xmlnode_get_namespace(x), NS_XMPP_TLS) == 0) {
- log_warn(c->d->i->id, "Starting TLS on an outgoing s2s to %s failed on the other side.", c->key->server);
+ log_warn(c->d->i->id, "Starting TLS on an outgoing s2s to %s failed on the other side.", c->key->get_domain().c_str());
mio_close(m);
break;
}
@@ -798,7 +798,7 @@
spool_add(c->connect_results, xmlnode_serialize_string(x, xmppd::ns_decl_list(), 0));
spool_add(c->connect_results, ")");
}
- log_alert(c->d->i->id, "SASL EXTERNAL authentication failed on authenticating ourselfs to %s (sending name: %s)", c->key->server, c->key->resource);
+ log_alert(c->d->i->id, "SASL EXTERNAL authentication failed on authenticating ourselfs to %s (sending name: %s)", c->key->get_domain().c_str(), c->key->get_resource().c_str());
/* close the stream (in former times we sent a stream error, but I think we shouldn't. There is stream fault by the other entity!) */
mio_write(m, NULL, "</stream:stream>", -1);
mio_close(m);
@@ -807,9 +807,9 @@
/* watch for a valid result, then we're set to rock! */
if(j_strcmp(xmlnode_get_localname(x),"result") == 0 && j_strcmp(xmlnode_get_namespace(x), NS_DIALBACK) == 0) {
- if(j_strcmp(xmlnode_get_attrib_ns(x, "from", NULL), c->key->server) != 0 || j_strcmp(xmlnode_get_attrib_ns(x, "to", NULL),c->key->resource) != 0) {
+ if(j_strcmp(xmlnode_get_attrib_ns(x, "from", NULL), c->key->get_domain().c_str()) != 0 || j_strcmp(xmlnode_get_attrib_ns(x, "to", NULL),c->key->get_resource().c_str()) != 0) {
/* naughty... *click* */
- log_warn(c->d->i->id,"Received illegal dialback validation remote %s != %s or to %s != %s", c->key->server, xmlnode_get_attrib_ns(x, "from", NULL),c->key->resource, xmlnode_get_attrib_ns(x, "to", NULL));
+ log_warn(c->d->i->id,"Received illegal dialback validation remote %s != %s or to %s != %s", c->key->get_domain().c_str(), xmlnode_get_attrib_ns(x, "from", NULL),c->key->get_resource().c_str(), xmlnode_get_attrib_ns(x, "to", NULL));
mio_write(m, NULL, "<stream:error><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xmlns='urn:ietf:params:xml:ns:xmpp-streams' xml:lang='en'>Invalid Dialback Result</text></stream:error>", -1);
mio_close(m);
break;
@@ -839,7 +839,7 @@
spool_add(c->connect_results, type_attribute ? type_attribute : "no type attribute");
spool_add(c->connect_results, ")");
}
- log_alert(c->d->i->id,"We were told by %s that our sending name %s is invalid, either something went wrong on their end, we tried using that name improperly, or dns does not resolve to us",c->key->server,c->key->resource);
+ log_alert(c->d->i->id, "We were told by %s that our sending name %s is invalid, either something went wrong on their end, we tried using that name improperly, or dns does not resolve to us", c->key->get_domain().c_str(), c->key->get_resource().c_str());
/* close the stream (in former times we sent a stream error, but I think we shouldn't. There is stream fault by the other entity!) */
mio_write(m, NULL, "</stream:stream>", -1);
mio_close(m);
@@ -852,7 +852,7 @@
return;
}
- log_warn(c->d->i->id,"Dropping connection due to illegal incoming packet on an unverified socket from %s to %s (%s): %s",c->key->resource,c->key->server, mio_ip(m), xmlnode_serialize_string(x, xmppd::ns_decl_list(), 0));
+ log_warn(c->d->i->id, "Dropping connection due to illegal incoming packet on an unverified socket from %s to %s (%s): %s", c->key->get_resource().c_str(), c->key->get_domain().c_str(), mio_ip(m), xmlnode_serialize_string(x, xmppd::ns_decl_list(), 0));
mio_write(m, NULL, "<stream:error><not-authorized xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xmlns='urn:ietf:params:xml:ns:xmpp-streams' xml:lang='en'>Not Allowed to send data on this socket!</text></stream:error>", -1);
mio_close(m);
break;
Modified: trunk/jabberd14/dnsrv/dnsrv.cc
==============================================================================
--- trunk/jabberd14/dnsrv/dnsrv.cc (original)
+++ trunk/jabberd14/dnsrv/dnsrv.cc Sat Apr 26 23:47:56 2008
@@ -324,7 +324,7 @@
return r_ERR;
p->x=xmlnode_get_firstchild(p->x);
p->id = to;
- p->host = to->server;
+ p->host = pstrdup(p->p, to->get_domain().c_str());
}
/* Ensure this packet doesn't already have an IP */
Modified: trunk/jabberd14/jabberd/acl.cc
==============================================================================
--- trunk/jabberd14/jabberd/acl.cc (original)
+++ trunk/jabberd14/jabberd/acl.cc Sat Apr 26 23:47:56 2008
@@ -50,7 +50,7 @@
jid result = NULL;
/* sanity check */
- if (xdb == NULL || function == NULL || user == NULL || user->server == NULL)
+ if (xdb == NULL || function == NULL || user == NULL)
return 0;
/* define namespace prefixes */
@@ -74,7 +74,7 @@
xmlnode_vector domain = xmlnode_get_tags(*iter, "acl:domain", namespaces);
xmlnode_vector::iterator p;
for (p = domain.begin(); p != domain.end(); ++p) {
- if (j_strcmp(user->server, xmlnode_get_data(*p)) == 0) {
+ if (j_strcmp(user->get_domain().c_str(), xmlnode_get_data(*p)) == 0) {
return 1;
}
}
@@ -108,7 +108,7 @@
log_debug2(ZONE, LOGT_AUTH, "allowed for this feature is: %s", jid_full(iter));
if (jid_cmpx(iter, user, JID_USER|JID_SERVER) == 0) {
/* match */
- pool_free(allowed_users -> p);
+ pool_free(allowed_users->get_pool());
log_debug2(ZONE, LOGT_AUTH, "user %s has access to %s", jid_full(user), function);
return 1;
}
@@ -116,7 +116,7 @@
/* cleanup */
if (allowed_users != NULL)
- pool_free(allowed_users->p);
+ pool_free(allowed_users->get_pool());
/* no match found */
log_debug2(ZONE, LOGT_AUTH, "denied user %s access to %s", jid_full(user), function);
Modified: trunk/jabberd14/jabberd/base/base_accept.cc
==============================================================================
--- trunk/jabberd14/jabberd/base/base_accept.cc (original)
+++ trunk/jabberd14/jabberd/base/base_accept.cc Sat Apr 26 23:47:56 2008
@@ -128,7 +128,7 @@
if(ai->restrict_var)
{
jp = jpacket_new(x);
- if(jp->type == JPACKET_UNKNOWN || jp->to == NULL || jp->from == NULL || deliver_hostcheck(jp->from->server) != ai->i)
+ if(jp->type == JPACKET_UNKNOWN || jp->to == NULL || jp->from == NULL || deliver_hostcheck(jp->from->get_domain().c_str()) != ai->i)
{
jutil_error_xmpp(x,XTERROR_INTERNAL);
mio_write(m,x,NULL,0);
Modified: trunk/jabberd14/jabberd/base/base_importspool.cc
==============================================================================
--- trunk/jabberd14/jabberd/base/base_importspool.cc (original)
+++ trunk/jabberd14/jabberd/base/base_importspool.cc Sat Apr 26 23:47:56 2008
@@ -145,7 +145,7 @@
p = pool_new();
userid = jid_new(p, domain);
jid_set(userid, user, JID_USER);
- if (userid == NULL || userid->user == NULL) {
+ if (userid == NULL || !userid->has_node()) {
log_debug2(ZONE, LOGT_IO, "invalid user: %s@%s - skipping", user, domain);
xmlnode_free(spoolfile);
pool_free(p);
Modified: trunk/jabberd14/jabberd/config.cc
==============================================================================
--- trunk/jabberd14/jabberd/config.cc (original)
+++ trunk/jabberd14/jabberd/config.cc Sat Apr 26 23:47:56 2008
@@ -503,7 +503,7 @@
newi->x = x;
/* make sure the id is valid for a hostname */
temp = jid_new(p, newi->id);
- if (temp == NULL || j_strcmp(temp->server, newi->id) != 0) {
+ if (temp == NULL || j_strcmp(temp->get_domain().c_str(), newi->id) != 0) {
log_alert(NULL, "ERROR: Invalid id name: %s\n",newi->id);
pool_free(p);
return -1;
Modified: trunk/jabberd14/jabberd/deliver.cc
==============================================================================
--- trunk/jabberd14/jabberd/deliver.cc (original)
+++ trunk/jabberd14/jabberd/deliver.cc Sat Apr 26 23:47:56 2008
@@ -235,7 +235,7 @@
* @param key the domain to be looked up (or "*" if the default routing is searched)
* @return the list of instances registered for this routing
*/
-static ilist deliver_hashmatch(xht ht, char *key) {
+static ilist deliver_hashmatch(xht ht, char const* key) {
ilist l;
l = static_cast<ilist>(xhash_get(ht, key));
if (l == NULL) {
@@ -307,7 +307,7 @@
log_debug2(ZONE, LOGT_DELIVER, "@-internal processing %s", xmlnode_serialize_string(p->x, xmppd::ns_decl_list(), 0));
- if(j_strcmp(p->id->user,"config") == 0) {
+ if (p->id->get_node() == "config") {
/* config at -internal means it's a special xdb request to get data from the config file */
for(x = xmlnode_get_firstchild(i->x); x != NULL; x = xmlnode_get_nextsibling(x)) {
if (j_strcmp(xmlnode_get_namespace(x), NS_JABBERD_CONFIGFILE) == 0)
@@ -327,16 +327,16 @@
return;
}
- if(j_strcmp(p->id->user,"host") == 0) {
+ if (p->id->get_node() == "host") {
/* dynamic register_instance crap */
- register_instance(i,p->id->resource);
+ register_instance(i,p->id->get_resource().c_str());
pool_free(p->p);
return;
}
- if(j_strcmp(p->id->user,"unhost") == 0) {
+ if (p->id->get_node() == "unhost") {
/* dynamic register_instance crap */
- unregister_instance(i,p->id->resource);
+ unregister_instance(i,p->id->get_resource().c_str());
pool_free(p->p);
return;
}
@@ -360,7 +360,7 @@
* @param i the instance to register
* @param host the domain to register this instance for (or "*" to register as the default routing)
*/
-void register_instance(instance i, char *host) {
+void register_instance(instance i, char const* host) {
ilist l;
xht ht = NULL;
xht namespaces = NULL;
@@ -404,7 +404,7 @@
* @param i the instance to unregister
* @param host the domain to unregister (or "*" to unregister as the default routing)
*/
-void unregister_instance(instance i, char *host) {
+void unregister_instance(instance i, char const* host) {
ilist l;
xht ht;
register_notifier notify_callback = NULL;
@@ -650,12 +650,12 @@
* @param host the hostname to get checked
* @return the instance packets of this host get mapped to
*/
-instance deliver_hostcheck(char *host) {
+instance deliver_hostcheck(char const* host) {
ilist l;
if (host == NULL)
return NULL;
- if ((l = deliver_hashmatch(deliver__hnorm,host)) == NULL || l->next != NULL)
+ if ((l = deliver_hashmatch(deliver__hnorm,host)) == NULL || l->next)
return NULL;
return l->i;
@@ -1003,7 +1003,7 @@
return NULL;
}
- p->host = p->id->server;
+ p->host = pstrdup(p->p, p->id->get_domain().c_str());
return p;
}
Modified: trunk/jabberd14/jabberd/jabberd.cc
==============================================================================
--- trunk/jabberd14/jabberd/jabberd.cc (original)
+++ trunk/jabberd14/jabberd/jabberd.cc Sat Apr 26 23:47:56 2008
@@ -297,11 +297,6 @@
/* init pth */
pth_init();
-#ifdef LIBIDN
- /* init the stringprep caches for jid manipulation */
- jid_init_cache();
-#endif
-
/* fire em up baby! */
heartbeat_birth();
@@ -341,9 +336,6 @@
xmlnode_stat();
deliver_pool_debug();
#endif
-#ifdef LIBIDN
- jid_clean_cache();
-#endif
pth_sleep(60);
};
@@ -455,11 +447,6 @@
/* free delivery hashes */
deliver_shutdown();
-#ifdef LIBIDN
- /* free stringprep caches */
- jid_stop_caching();
-#endif
-
/* free instances hash table */
if (instance__ids != NULL)
xhash_free(instance__ids);
Modified: trunk/jabberd14/jabberd/jabberd.h
==============================================================================
--- trunk/jabberd14/jabberd/jabberd.h (original)
+++ trunk/jabberd14/jabberd/jabberd.h Sat Apr 26 23:47:56 2008
@@ -109,8 +109,6 @@
# include <gnutls/openpgp.h>
#endif
-#include <glibmm.h>
-
/** Packet types */
typedef enum { p_NONE, p_NORM, p_XDB, p_LOG, p_ROUTE } ptype;
@@ -196,8 +194,8 @@
/*** public functions for base modules ***/
void register_config(pool p, char *node, cfhandler f, void *arg); /* register a function to handle that node in the config file */
-void register_instance(instance i, char *host); /* associate an id with a hostname for that packet type */
-void unregister_instance(instance i, char *host); /* disassociate an id with a hostname for that packet type */
+void register_instance(instance i, char const* host); /* associate an id with a hostname for that packet type */
+void unregister_instance(instance i, char const* host); /* disassociate an id with a hostname for that packet type */
void register_routing_update_callback(instance i, register_notify f, void *arg); /**< register a function that gets called on registering/unregistering a host for an instance */
void register_phandler(instance id, order o, phandler f, void *arg); /* register a function to handle delivery for this instance */
void register_beat(int freq, beathandler f, void *arg); /* register the function to be called from the heartbeat, freq is how often, <= 0 is ignored */
@@ -209,7 +207,7 @@
void deliver(dpacket p, instance i); /* deliver packet from sending instance */
void deliver_fail(dpacket p, const char *err); /* bounce a packet intelligently */
void deliver_instance(instance i, dpacket p); /* deliver packet TO the instance, if the result != r_DONE, you have to handle the packet! */
-instance deliver_hostcheck(char *host); /* util that returns the instance handling this hostname for normal packets */
+instance deliver_hostcheck(char const* host); /* util that returns the instance handling this hostname for normal packets */
bool deliver_is_uplink(instance i); // checks if an instance is configured to be the uplink
/*** global logging/signal symbols ***/
Modified: trunk/jabberd14/jabberd/lib/Makefile.am
==============================================================================
--- trunk/jabberd14/jabberd/lib/Makefile.am (original)
+++ trunk/jabberd14/jabberd/lib/Makefile.am Sat Apr 26 23:47:56 2008
@@ -2,7 +2,7 @@
include_HEADERS = jabberdlib.h pointer.tcc
-libjabberdlib_la_SOURCES = base64.cc karma.cc xhash.cc crc32.cc jid.cc pool.cc expat.cc jpacket.cc socket.cc jutil.cc rate.cc str.cc xstream.cc hash.cc hmac.cc messages.cc xmlnode.cc lwresc.cc
+libjabberdlib_la_SOURCES = base64.cc karma.cc xhash.cc crc32.cc jid.cc jabberid.cc pool.cc expat.cc jpacket.cc socket.cc jutil.cc rate.cc str.cc xstream.cc hash.cc hmac.cc messages.cc xmlnode.cc lwresc.cc
libjabberdlib_la_LDFLAGS = @LDFLAGS@ -version-info 1:0:0
INCLUDES = -I..
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
Modified: trunk/jabberd14/jabberd/lib/expat.cc
==============================================================================
--- trunk/jabberd14/jabberd/lib/expat.cc (original)
+++ trunk/jabberd14/jabberd/lib/expat.cc Sat Apr 26 23:47:56 2008
@@ -285,7 +285,7 @@
* @param file the filename
* @return pointer to a message why parsing failed, NULL if parsing did not fail
*/
-char* xmlnode_file_borked(char *file) {
+char* xmlnode_file_borked(char const* file) {
XML_Parser p;
char buf[BUFSIZ];
static char err[1024];
Modified: trunk/jabberd14/jabberd/lib/hmac.cc
==============================================================================
--- trunk/jabberd14/jabberd/lib/hmac.cc (original)
+++ trunk/jabberd14/jabberd/lib/hmac.cc Sat Apr 26 23:47:56 2008
@@ -40,7 +40,7 @@
* @param len the length of the message in bytes
* @param hmac where to place the result
*/
-static void hmac_sha1_r(char *secret, unsigned char *message, size_t len, unsigned char hmac[20]) {
+static void hmac_sha1_r(char const* secret, unsigned char const* message, size_t len, unsigned char hmac[20]) {
std::vector<uint8_t> key;
xmppd::sha1 innerhash;
xmppd::sha1 outerhash;
@@ -66,7 +66,7 @@
/* calculate inner hash */
innerhash.update(std::string(ipadded, 20));
- innerhash.update(reinterpret_cast<char*>(message));
+ innerhash.update(reinterpret_cast<char const*>(message));
/* calculate outer hash */
outerhash.update(std::string(opadded, 20));
@@ -87,7 +87,7 @@
* @param len the length of the message in bytes
* @param hmac where to place the result
*/
-void hmac_sha1_ascii_r(char *secret, unsigned char *message, size_t len, char hmac[41]) {
+void hmac_sha1_ascii_r(char const* secret, unsigned char const* message, size_t len, char hmac[41]) {
unsigned char hmac_bin[20];
int i = 0;
char *ptr = hmac;
Modified: trunk/jabberd14/jabberd/lib/jabberdlib.h
==============================================================================
--- trunk/jabberd14/jabberd/lib/jabberdlib.h (original)
+++ trunk/jabberd14/jabberd/lib/jabberdlib.h Sat Apr 26 23:47:56 2008
@@ -92,6 +92,8 @@
# include <map>
#endif
+#include <glibmm.h>
+
/*
** Arrange to use either varargs or stdargs
*/
@@ -670,7 +672,7 @@
void xmlnode_insert_node(xmlnode parent, xmlnode node);
xmlnode xmlnode_str(const char *str, int len);
xmlnode xmlnode_file(const char *file);
-char* xmlnode_file_borked(char *file); /* same as _file but returns the parsing error */
+char* xmlnode_file_borked(char const *file); /* same as _file but returns the parsing error */
xmlnode xmlnode_dup(xmlnode x); /* duplicate x */
xmlnode xmlnode_dup_pool(pool p, xmlnode x);
@@ -842,10 +844,214 @@
/* message authentication code */
-void hmac_sha1_ascii_r(char *secret, unsigned char *message, size_t len, char hmac[41]);
+void hmac_sha1_ascii_r(char const* secret, unsigned char const* message, size_t len, char hmac[41]);
/********** END OLD libxode.h BEGIN OLD jabber.h *************/
+namespace xmppd {
+
+ /**
+ * The jabberid class represents a jid address on the xmpp network
+ */
+ class jabberid {
+ public:
+ /**
+ * create a new jabberid instance initializing the address by parsing a string
+ *
+ * @param jid the initial address value
+ * @throws std::invalid_argument if the jid cannot be prepared
+ */
+ jabberid(const Glib::ustring& jid);
+
+ /**
+ * sets the node part of a jabberid
+ *
+ * @param node the node to set (empty string to clear node)
+ * @throws std::invalid_argument if the node cannot be prepared
+ */
+ void set_node(const Glib::ustring& node);
+
+ /**
+ * sets the domain part of a jabberid
+ *
+ * @param domain the domain to set
+ * @throws std::invalid_argument if the domain cannot be prepared
+ */
+ void set_domain(const Glib::ustring& domain);
+
+ /**
+ * sets the resource part of a jabberid
+ *
+ * @param resource the resource to set (empty string to clear resource)
+ * @throws std::invalid_argument if the resource cannot be prepared
+ */
+ void set_resource(const Glib::ustring& resource);
+
+ /**
+ * get the node part of a jabberid
+ *
+ * @return the node part, empty string if no node
+ */
+ const Glib::ustring& get_node() { return node; };
+
+ /**
+ * returns if a jabberid has a node
+ *
+ * @return true if the jabberid has a node
+ */
+ bool has_node() { return node.length() > 0; };
+
+ /**
+ * get the domain part of a jabberid
+ *
+ * @return the domain part
+ */
+ const Glib::ustring& get_domain() { return domain; };
+
+ /**
+ * get the resource part of a jabberid
+ *
+ * @return the resource part, empty string if no resource
+ */
+ const Glib::ustring& get_resource() { return resource; };
+
+ /**
+ * returns if a jabberid has a resource
+ *
+ * @return true if the jabberid has a resource
+ */
+ bool has_resource() { return resource.length() > 0; };
+
+ /**
+ * compare jabberid instance with another instance
+ *
+ * @param otherjid the other jabberid to compare with
+ * @return true if both jabberid instances represent the same JIDs, false else
+ */
+ bool operator==(const jabberid& otherjid);
+
+ /**
+ * compare some parts of two jabberid instances
+ *
+ * @param otherjid the other jabberid to compare with
+ * @param compare_resource true if the resource part should get compared
+ * @param compare_node true if the node part should get compared
+ * @param compare_domain true if the domain part should get compared
+ * @return true if the compared parts of the jabberid instances are matching
+ */
+ bool compare(const jabberid& otherjid, bool compare_resource = false, bool compare_node = true, bool compare_domain = true);
+
+ /**
+ * get a copy of the jid without the resource
+ *
+ * @return new jabberid instance representing the same jabberid but without resource
+ */
+ jabberid get_user();
+
+ /**
+ * get the textual representation of a jabberid
+ *
+ * @return the textual representation
+ */
+ Glib::ustring full();
+ private:
+ /**
+ * node part of the JID (the part before the @ sign)
+ *
+ * empty string of no node
+ */
+ Glib::ustring node;
+
+ /**
+ * domain part of the JID
+ *
+ * there must always be a domain part in a JID
+ */
+ Glib::ustring domain;
+
+ /**
+ * resource part of the JID
+ *
+ * empty strong for no resource
+ */
+ Glib::ustring resource;
+ };
+
+ /**
+ * jabberid_pool is a child class of jabberid, that is used to implement
+ * the compatibility layer for existing code, that expect a jid to have
+ * an associated pool
+ */
+ class jabberid_pool : public jabberid {
+ public:
+ /**
+ * construct a jabberid_pool with an existing assigned pool
+ *
+ * @param jid initial jabberid
+ * @param p the pool to assign
+ * @throws std::invalid_argument if the JID is not valid
+ */
+ jabberid_pool(const Glib::ustring& jid, ::pool p);
+
+ /**
+ * get the textual representation of a jabberid (allocated in pooled memory
+ *
+ * @return the textual representation
+ */
+ char* full_pooled();
+
+ /**
+ * sets the node part of a jabberid
+ *
+ * @param node the node to set (empty string to clear node)
+ * @throws std::invalid_argument if the node cannot be prepared
+ */
+ void set_node(const Glib::ustring& node);
+
+ /**
+ * sets the domain part of a jabberid
+ *
+ * @param domain the domain to set
+ * @throws std::invalid_argument if the domain cannot be prepared
+ */
+ void set_domain(const Glib::ustring& domain);
+
+ /**
+ * sets the resource part of a jabberid
+ *
+ * @param resource the resource to set (empty string to clear resource)
+ * @throws std::invalid_argument if the resource cannot be prepared
+ */
+ void set_resource(const Glib::ustring& resource);
+
+ /**
+ * the the pool of this jabberid_pool
+ *
+ * @return pool of this jabberid_pool
+ */
+ pool get_pool() { return p; };
+
+ /**
+ * helper pointer to construct legacy lists
+ */
+ jabberid_pool* next;
+ private:
+ /**
+ * assigned pool
+ *
+ * this pool is not used by jabberid_pool in any way!
+ */
+ ::pool p;
+
+ /**
+ * cached string version of jid (allocated from the assigned pool)
+ *
+ * @return the textual representation
+ */
+ char* jid_full;
+ };
+}
+
/* --------------------------------------------------------- */
/* */
/* JID structures & constants */
@@ -855,30 +1061,16 @@
#define JID_USER 2
#define JID_SERVER 4
-typedef struct jid_struct
-{
- pool p;
- char* resource;
- char* user;
- char* server;
- char* full;
- struct jid_struct *next; /* for lists of jids */
-} *jid;
-
+typedef xmppd::jabberid_pool* jid;
+
jid jid_new(pool p, const char *idstr); /* Creates a jabber id from the idstr */
void jid_set(jid id, const char *str, int item); /* Individually sets jid components */
char* jid_full(jid id); /* Builds a string type=user/resource at server from the jid data */
int jid_cmp(jid a, jid b); /* Compares two jid's, returns 0 for perfect match */
int jid_cmpx(jid a, jid b, int parts); /* Compares just the parts specified as JID_|JID_ */
-jid jid_append(jid a, jid b); /* Appending b to a (list), no dups */
-/* xmlnode jid_xres(jid id); */ /* Returns xmlnode representation of the resource?query=string */
-xmlnode jid_nodescan(jid id, xmlnode x); /* Scans the children of the node for a matching jid attribute */
jid jid_user(jid a); /* returns the same jid but just of the user at host part */
jid jid_user_pool(jid a, pool p); /* returns the same jid, but just the user at host part */
-void jid_init_cache(); /**< initialize the stringprep caches */
-void jid_stop_caching(); /**< free all caches that have been initialized */
-void jid_clean_cache(); /**< check the stringprep caches for expired entries */
-
+jid jid_append(jid a, jid b);
/* --------------------------------------------------------- */
/* */
@@ -1144,7 +1336,7 @@
/* --------------------------------------------------------- */
xmlnode jutil_presnew(int type, char *to, const char *status); /* Create a skeleton presence packet */
xmlnode jutil_iqnew(int type, char *ns); /* Create a skeleton iq packet */
-xmlnode jutil_msgnew(char *type, char *to, char *subj, char *body);
+xmlnode jutil_msgnew(char *type, char const* to, char *subj, char *body);
/* Create a skeleton message packet */
int jutil_priority(xmlnode x); /* Determine priority of this packet */
void jutil_tofrom(xmlnode x); /* Swaps to/from fields on a packet */
Copied: trunk/jabberd14/jabberd/lib/jabberid.cc (from r1519, /trunk/jabberd14/license-header.txt)
==============================================================================
--- /trunk/jabberd14/license-header.txt (original)
+++ trunk/jabberd14/jabberd/lib/jabberid.cc Sat Apr 26 23:47:56 2008
@@ -1,13 +1,5 @@
/*
- * Copyrights
- *
- * Portions created by or assigned to Jabber.com, Inc. are
- * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact
- * information for Jabber.com, Inc. is available at http://www.jabber.com/.
- *
- * Portions Copyright (c) 1998-1999 Jeremie Miller.
- *
- * Portions Copyright (c) 2006-2007 Matthias Wimmer
+ * Copyright (c) 2008 Matthias Wimmer
*
* This file is part of jabberd14.
*
@@ -27,3 +19,306 @@
* 02110-1301, USA.
*
*/
+
+/**
+ * @file jabberid.cc
+ * @brief representation, normalization and comparison of JabberIDs (addresses in XMPP)
+ */
+
+#include <jabberdlib.h>
+#include <stringprep.h>
+
+namespace xmppd {
+ /**
+ * The preparation_cache class caches string prep results and is used to speed up preparation of jabberid address parts
+ *
+ * The parent class xhash uses the original string as keys and the value is a pair of the prepared string (empty string if
+ * prepared string equals the original string) and the the time when the cache entry has been last used.
+ */
+ class preparation_cache : private xhash< std::pair<Glib::ustring, time_t> > {
+ public:
+ /**
+ * create a new string prep cache instance
+ *
+ * @param profile the stringprep profile to use (stringprep_xmpp_nodeprep, stringprep_nameprep, or stringprep_xmpp_resourceprep)
+ */
+ preparation_cache(const ::Stringprep_profile* profile);
+
+ /**
+ * get the prepared version of the original string
+ *
+ * @param original the string to prepare
+ * @returns the prepared string
+ * @throws std::invalid_argument if the string cannot be prepared
+ */
+ Glib::ustring get_prepped(const Glib::ustring& original);
+
+ /**
+ * clean the preparation cache
+ */
+ void clean_cache();
+
+ /**
+ * prepare a node
+ *
+ * @param original the string to prepare as a node
+ * @returns the prepared string
+ * @throws std::invalid_argument if node cannot be prepared
+ */
+ static Glib::ustring prepare_node(const Glib::ustring& original);
+
+ /**
+ * prepare a domain
+ *
+ * @param original the string to prepare as a domain
+ * @returns the prepared string
+ * @throws std::invalid_argument if domain cannot be prepared
+ */
+ static Glib::ustring prepare_domain(const Glib::ustring& original);
+
+ /**
+ * prepare a resource
+ *
+ * @param original the string to prepare as a resource
+ * @return the prepared string
+ * @throws std::invalid_argument if the resource cannot be prepared
+ */
+ static Glib::ustring prepare_resource(const Glib::ustring& original);
+ private:
+ /**
+ * The string prep profile to use for this cache
+ */
+ const ::Stringprep_profile* profile;
+
+ /**
+ * Last time the preparation cache has been cleaned
+ */
+ time_t last_clean;
+
+ /**
+ * preparation cache for nodes
+ */
+ static preparation_cache node_cache;
+
+ /**
+ * preparation cache for domains
+ */
+ static preparation_cache domain_cache;
+
+ /**
+ * preparation cache for resources
+ */
+ static preparation_cache resource_cache;
+ };
+
+ preparation_cache preparation_cache::node_cache(stringprep_xmpp_nodeprep);
+ preparation_cache preparation_cache::domain_cache(stringprep_nameprep);
+ preparation_cache preparation_cache::resource_cache(stringprep_xmpp_resourceprep);
+
+ Glib::ustring preparation_cache::prepare_node(const Glib::ustring& original) {
+ return node_cache.get_prepped(original);
+ }
+
+ Glib::ustring preparation_cache::prepare_domain(const Glib::ustring& original) {
+ return domain_cache.get_prepped(original);
+ }
+
+ Glib::ustring preparation_cache::prepare_resource(const Glib::ustring& original) {
+ return resource_cache.get_prepped(original);
+ }
+
+ preparation_cache::preparation_cache(const ::Stringprep_profile* profile) : profile(profile) {
+ if (profile == NULL) {
+ throw std::invalid_argument("No profile given when constructing preparation_cache");
+ }
+
+ last_clean = std::time(NULL);
+ }
+
+ void preparation_cache::clean_cache() {
+ time_t now = std::time(NULL);
+
+ // cleaning already necessary?
+ if (now - last_clean < 60)
+ return; // no, clean at most once a minute
+
+ // what to clean
+ time_t keep_newer_as = now - 900;
+
+ // walk cache
+ std::list<Glib::ustring> items_to_remove;
+ for (preparation_cache::const_iterator p = this->begin(); p != this->end(); ++p) {
+ if (p->second.second < keep_newer_as)
+ items_to_remove.push_back(p->first);
+ }
+ for (std::list<Glib::ustring>::const_iterator p = items_to_remove.begin(); p != items_to_remove.end(); ++p) {
+ this->erase(*p);
+ }
+ }
+
+ Glib::ustring preparation_cache::get_prepped(const Glib::ustring& original) {
+ // need cleaning the cache?
+ clean_cache();
+
+ // already in cache?
+ xhash< std::pair<Glib::ustring, time_t> >::iterator iter = find(original);
+ if (iter != end()) {
+ iter->second.second = std::time(NULL);
+
+ if (iter->first.length() == 0) {
+ return original;
+ } else {
+ return iter->second.first;
+ }
+ }
+
+ // not yet in cache, do prepare
+
+ // check length
+ if (std::string(original).length() > 1023) {
+ throw std::invalid_argument("JabberID part is to big");
+ }
+ // copy original to a buffer where the preparation can be executed on
+ char in_out_buffer[1024];
+ std::strncpy(in_out_buffer, original.c_str(), sizeof(in_out_buffer)-1);
+ in_out_buffer[sizeof(in_out_buffer)-1] = 0; // sanity termination
+
+ // do preparation
+ int result = ::stringprep(in_out_buffer, sizeof(in_out_buffer), STRINGPREP_NO_UNASSIGNED, profile);
+
+ // success?
+ if (result != ::STRINGPREP_OK) {
+ throw std::invalid_argument("JabberID part cannot be prepared");
+ }
+
+ // cache entry
+ operator[](original) = std::pair<Glib::ustring, time_t>(in_out_buffer, std::time(NULL));
+
+ // return result
+ return in_out_buffer;
+ }
+
+ jabberid::jabberid(const Glib::ustring& jid) {
+ // split the JID into parts
+ Glib::ustring::size_type resource_separator = jid.find("/");
+ Glib::ustring::size_type node_separator = jid.find("@");
+
+ // there might be no node, but an at sign in the resource
+ if (resource_separator != Glib::ustring::npos && node_separator != Glib::ustring::npos && node_separator > resource_separator) {
+ node_separator = Glib::ustring::npos;
+ }
+
+ // prepare and store the parts
+ set_domain(jid.substr(
+ node_separator == Glib::ustring::npos ? 0 : node_separator+1,
+ node_separator == Glib::ustring::npos ? resource_separator :
+ resource_separator == Glib::ustring::npos ? Glib::ustring::npos :
+ resource_separator - node_separator -1));
+ if (node_separator != Glib::ustring::npos) {
+ set_node(jid.substr(0, node_separator));
+ }
+ if (resource_separator != Glib::ustring::npos) {
+ set_resource(jid.substr(resource_separator+1));
+ }
+ }
+
+ void jabberid::set_node(const Glib::ustring& node) {
+ // clearing node?
+ if (node.size() == 0) {
+ this->node = "";
+ return;
+ }
+
+ try {
+ this->node = preparation_cache::prepare_node(node);
+ } catch (std::invalid_argument) {
+ throw std::invalid_argument("Invalid node for JID");
+ }
+ }
+
+ void jabberid::set_domain(const Glib::ustring& domain) {
+ try {
+ this->domain = preparation_cache::prepare_domain(domain);
+ } catch (std::invalid_argument) {
+ throw std::invalid_argument("Invalid domain for JID");
+ }
+ }
+
+ void jabberid::set_resource(const Glib::ustring& resource) {
+ // clearing resource?
+ if (resource.size() == 0) {
+ this->resource = "";
+ return;
+ }
+
+ try {
+ this->resource = preparation_cache::prepare_resource(resource);
+ } catch (std::invalid_argument) {
+ throw std::invalid_argument("Invalid resource for JID");
+ }
+ }
+
+ bool jabberid::operator==(const jabberid& otherjid) {
+ return compare(otherjid, true, true, true);
+ }
+
+ bool jabberid::compare(const jabberid& otherjid, bool compare_resource, bool compare_node, bool compare_domain) {
+ if (compare_domain && domain != otherjid.domain)
+ return false;
+ if (compare_node && node != otherjid.node)
+ return false;
+ if (compare_resource && resource != otherjid.resource)
+ return false;
+ return true;
+ }
+
+ jabberid jabberid::get_user() {
+ jabberid jabberid_copy(*this);
+ jabberid_copy.set_resource("");
+ return jabberid_copy;
+ }
+
+ Glib::ustring jabberid::full() {
+ std::ostringstream result;
+ if (node.size() > 0) {
+ result << node << "@";
+ }
+ result << domain;
+ if (resource.size() > 0) {
+ result << "/" << resource;
+ }
+
+ return result.str();
+ }
+
+ jabberid_pool::jabberid_pool(const Glib::ustring& jid, ::pool p) : jabberid(jid), jid_full(NULL), next(NULL) {
+ if (p == NULL) {
+ throw std::invalid_argument("trying to construct jabberid_pool with a NULL pool");
+ }
+
+ this->p = p;
+ }
+
+ void jabberid_pool::set_node(const Glib::ustring& node) {
+ jid_full = NULL;
+ jabberid::set_node(node);
+ }
+
+ void jabberid_pool::set_domain(const Glib::ustring& domain) {
+ jid_full = NULL;
+ jabberid::set_domain(domain);
+ }
+
+ void jabberid_pool::set_resource(const Glib::ustring& resource) {
+ jid_full = NULL;
+ jabberid::set_resource(resource);
+ }
+
+ char* jabberid_pool::full_pooled() {
+ if (!jid_full) {
+ jid_full = pstrdup(p, full().c_str());
+ }
+
+ return jid_full;
+ }
+}
Modified: trunk/jabberd14/jabberd/lib/jid.cc
==============================================================================
--- trunk/jabberd14/jabberd/lib/jid.cc (original)
+++ trunk/jabberd14/jabberd/lib/jid.cc Sat Apr 26 23:47:56 2008
@@ -1,13 +1,7 @@
/*
* Copyrights
*
- * Portions created by or assigned to Jabber.com, Inc. are
- * Copyright (c) 1999-2002 Jabber.com, Inc. All Rights Reserved. Contact
- * information for Jabber.com, Inc. is available at http://www.jabber.com/.
- *
- * Portions Copyright (c) 1998-1999 Jeremie Miller.
- *
- * Portions Copyright (c) 2006-2007 Matthias Wimmer
+ * Portions Copyright (c) 2008 Matthias Wimmer
*
* This file is part of jabberd14.
*
@@ -30,727 +24,77 @@
/**
* @file jid.cc
- * @brief representation, normalization and comparison of JabberIDs (addresses in XMPP)
+ * @brief compatibility functions for old JID handling
*/
#include <jabberdlib.h>
-#ifdef LIBIDN
-
-# include <stringprep.h>
-
-
-/**
- * @brief datastructure to build the stringprep caches
- */
-typedef struct _jid_prep_entry_st {
- char *preped; /**< the result of the preparation, NULL if unchanged */
- time_t last_used; /**< when this result has last been successfully used */
- unsigned int used_count; /**< how often this result has been successfully used */
- int size; /**< the min buffer size needed to hold the result (strlen+1) */
-} *_jid_prep_entry_t;
-
-/**
- * @brief string preparation cache
- */
-typedef struct _jid_prep_cache_st {
- xht hashtable; /**< the hash table containing the preped strings */
- pth_mutex_t mutex; /**< mutex controling the access to the hashtable */
- const Stringprep_profile *profile;
- /**< the stringprep profile used for this cache */
-} *_jid_prep_cache_t;
+static void jid_pool_cleaner(void *arg) {
+ jid id = static_cast<jid>(arg);
-/**
- * stringprep cache containging already preped nodes
- *
- * we are using global caches here for two reasons:
- * - I do not see why different instances would want
- * to have different caches as we are always doing
- * the same
- * - For per instance caches I would have to modify the
- * interface of the jid_*() functions which would break
- * compatibility with transports
- */
-_jid_prep_cache_t _jid_prep_cache_node = NULL;
-
-/**
- * stringprep cache containing already preped domains
- */
-_jid_prep_cache_t _jid_prep_cache_domain = NULL;
-
-/**
- * stringprep cache containing already preped resources
- */
-_jid_prep_cache_t _jid_prep_cache_resource = NULL;
-
-/**
- * walker for cleaning up stringprep caches
- *
- * @param h the hash we are walking through
- * @param key the key of this item
- * @param val the value of this item
- * @param arg delete entries older as this unix timestamp
- */
-void _jid_clean_walker(xht h, const char *key, void *val, void *arg) {
- time_t *keep_newer_as = (time_t*)arg;
- _jid_prep_entry_t entry = (_jid_prep_entry_t)val;
-
- if (entry == NULL)
- return;
-
- if (entry->last_used <= *keep_newer_as) {
- xhash_zap(h, key);
- if (entry->preped != NULL)
- free(entry->preped);
- free(entry);
- }
-}
-
-/**
- * walk through a single stringprep cache and check which entries have expired
- */
-void _jid_clean_single_cache(_jid_prep_cache_t cache, time_t keep_newer_as) {
- /* acquire the lock on the cache */
- pth_mutex_acquire(&(cache->mutex), FALSE, NULL);
-
- /* walk over all entries */
- xhash_walk(cache->hashtable, _jid_clean_walker, (void*)&keep_newer_as);
-
- /* we're done, release the lock on the cache */
- pth_mutex_release(&(cache->mutex));
-}
-
-/**
- * walk through the stringprep caches and check which entries have expired
- */
-void jid_clean_cache() {
- /* XXX make this configurable? */
- time_t keep_newer_as = time(NULL) - 900;
-
- /* cleanup the nodeprep cache */
- _jid_clean_single_cache(_jid_prep_cache_node, keep_newer_as);
-
- /* cleanup the domain preparation cache */
- _jid_clean_single_cache(_jid_prep_cache_domain, keep_newer_as);
-
- /* cleanup the resourceprep cache */
- _jid_clean_single_cache(_jid_prep_cache_resource, keep_newer_as);
+ delete id;
}
/**
- * caching wrapper around a stringprep function
- *
- * @param in_out_buffer buffer containing what has to be stringpreped and that gets the result
- * @param max_len size of the buffer
- * @param cache the used cache, defining also the used stringprep profile
- * @return the return code of the stringprep call
+ * create a new jid
*/
-int _jid_cached_stringprep(char *in_out_buffer, int max_len, _jid_prep_cache_t cache) {
- _jid_prep_entry_t preped;
- int result = STRINGPREP_OK;
-
- /* check that the cache already exists
- * we can not do anything as we don't know which profile has to be used */
- if (cache == NULL) {
- return STRINGPREP_UNKNOWN_PROFILE;
- }
-
- /* is there something that has to be stringpreped? */
- if (in_out_buffer == NULL) {
- return STRINGPREP_OK;
- }
-
- /* acquire the lock on the cache */
- pth_mutex_acquire(&(cache->mutex), FALSE, NULL);
+jid jid_new(pool p, const char *idstr) {
+ // sanity check
+ if (!p || !idstr)
+ return NULL;
- /* check if the requested preparation has already been done */
- preped = (_jid_prep_entry_t)xhash_get(cache->hashtable, in_out_buffer);
- if (preped != NULL) {
- /* we already prepared this argument */
- if (preped->size <= max_len) {
- /* we can use the result */
-
- /* update the statistic */
- preped->used_count++;
- preped->last_used = time(NULL);
-
- /* do we need to copy the result? */
- if (preped->preped != NULL) {
- /* copy the result */
- strcpy(in_out_buffer, preped->preped);
- }
-
- result = STRINGPREP_OK;
- } else {
- /* we need a bigger buffer */
- result = STRINGPREP_TOO_SMALL_BUFFER;
- }
-
- /* we're done, release the lock on the cache */
- pth_mutex_release(&(cache->mutex));
- } else {
- char *original;
-
- /* stringprep needs time, release the lock on the cache for the meantime */
- pth_mutex_release(&(cache->mutex));
-
- /* we have to keep the key */
- original = strdup(in_out_buffer);
-
- /* try to prepare the string */
- result = stringprep(in_out_buffer, max_len, STRINGPREP_NO_UNASSIGNED, cache->profile);
-
- /* did we manage to prepare the string? */
- if (result == STRINGPREP_OK && original != NULL) {
- /* generate an entry for the cache */
- preped = (_jid_prep_entry_t)malloc(sizeof(struct _jid_prep_entry_st));
- if (preped != NULL) {
- /* has there been modified something? */
- if (j_strcmp(in_out_buffer, original) == 0) {
- /* no, we don't need to store a copy of the original string */
- preped->preped = NULL;
- } else {
- /* yes, store the stringpreped string */
- preped->preped = strdup(in_out_buffer);
- }
- preped->last_used = time(NULL);
- preped->used_count = 1;
- preped->size = strlen(in_out_buffer)+1;
-
- /* acquire the lock on the cache again */
- pth_mutex_acquire(&(cache->mutex), FALSE, NULL);
-
- /* store the entry in the cache */
- xhash_put(cache->hashtable, original, preped);
-
- // the xhash made a copy of the key (since we are using std::string as keys), we can now delete our copy
- free(original);
-
- /* we're done, release the lock on the cache */
- pth_mutex_release(&(cache->mutex));
- } else {
- /* we don't need the copy of the key, if there is no memory to store it */
- free(original);
- }
- } else {
- /* we don't need the copy of the original value */
- if (original != NULL)
- free(original);
- }
+ try {
+ jid id = new xmppd::jabberid_pool(idstr, p);
+ pool_cleanup(p, jid_pool_cleaner, id);
+ return id;
+ } catch (std::invalid_argument) {
+ return NULL;
}
-
- return result;
}
/**
- * free a single stringprep cache
- *
- * @param cache the cache to free
+ * set part of a jabberid
*/
-void _jid_stop_single_cache(_jid_prep_cache_t *cache) {
- if (*cache == NULL)
+void jid_set(jid id, const char *str, int item) {
+ // sanity check
+ if (!str || !id)
return;
- _jid_clean_single_cache(*cache, time(NULL));
-
- pth_mutex_acquire(&((*cache)->mutex), FALSE, NULL);
- xhash_free((*cache)->hashtable);
-
- free(*cache);
-
- *cache = NULL;
-}
-
-/**
- * init a single stringprep cache
- *
- * @param cache the cache to init
- * @param prime the prime used to init the hashtable
- * @param profile profile used to prepare the strings
- */
-void _jid_init_single_cache(_jid_prep_cache_t *cache, int prime, const Stringprep_profile *profile) {
- /* do not init a cache twice */
- if (*cache == NULL) {
- *cache = (_jid_prep_cache_t)malloc(sizeof(struct _jid_prep_cache_st));
- pth_mutex_init(&((*cache)->mutex));
- (*cache)->hashtable = xhash_new(prime);
- (*cache)->profile = profile;
- }
-}
-
-/**
- * free the stringprep caches
- */
-void jid_stop_caching() {
- _jid_stop_single_cache(&_jid_prep_cache_node);
- _jid_stop_single_cache(&_jid_prep_cache_domain);
- _jid_stop_single_cache(&_jid_prep_cache_resource);
-}
-
-/**
- * init the stringprep caches
- * (do not call this twice at the same time, we do not have the mutexes yet)
- */
-void jid_init_cache() {
- /* init the nodeprep cache */
- _jid_init_single_cache(&_jid_prep_cache_node, 2003, stringprep_xmpp_nodeprep);
-
- /* init the nameprep cache (domains) */
- _jid_init_single_cache(&_jid_prep_cache_domain, 2003, stringprep_nameprep);
-
- /* init the resourceprep cache */
- _jid_init_single_cache(&_jid_prep_cache_resource, 2003, stringprep_xmpp_resourceprep);
-}
-
-/**
- * nameprep the domain identifier in a JID and check if it is valid
- *
- * @param jid data structure holding the JID
- * @return 0 if JID is valid, non zero otherwise
- */
-int _jid_safe_domain(jid id) {
- int result=0;
-
- /* there must be a domain identifier */
- if (j_strlen(id->server) == 0)
- return 1;
-
- /* nameprep the domain identifier */
- result = _jid_cached_stringprep(id->server, strlen(id->server)+1, _jid_prep_cache_domain);
- if (result == STRINGPREP_TOO_SMALL_BUFFER) {
- /* nameprep wants to expand the string, e.g. conversion from ß to ss */
- size_t biggerbuffersize = 1024;
- char *biggerbuffer = static_cast<char*>(pmalloc(id->p, biggerbuffersize));
- if (biggerbuffer == NULL)
- return 1;
- strcpy(biggerbuffer, id->server);
- result = _jid_cached_stringprep(biggerbuffer, biggerbuffersize, _jid_prep_cache_domain);
- id->server = biggerbuffer;
- }
- if (result != STRINGPREP_OK)
- return 1;
-
- /* the namepreped domain must not be longer than 1023 bytes */
- if (j_strlen(id->server) > 1023)
- return 1;
-
- /* if nothing failed, the domain is valid */
- return 0;
-}
-
-/**
- * nodeprep the node identifier in a JID and check if it is valid
- *
- * @param jid data structure holding the JID
- * @return 0 if JID is valid, non zero otherwise
- */
-int _jid_safe_node(jid id) {
- int result=0;
-
- /* it is valid to have no node identifier in the JID */
- if (id->user == NULL)
- return 0;
-
- /* nodeprep */
- result = _jid_cached_stringprep(id->user, strlen(id->user)+1, _jid_prep_cache_node);
- if (result == STRINGPREP_TOO_SMALL_BUFFER) {
- /* nodeprep wants to expand the string, e.g. conversion from ß to ss */
- size_t biggerbuffersize = 1024;
- char *biggerbuffer = static_cast<char*>(pmalloc(id->p, biggerbuffersize));
- if (biggerbuffer == NULL)
- return 1;
- strcpy(biggerbuffer, id->user);
- result = _jid_cached_stringprep(biggerbuffer, biggerbuffersize, _jid_prep_cache_node);
- id->user = biggerbuffer;
- }
- if (result != STRINGPREP_OK)
- return 1;
-
- /* the nodepreped node must not be longer than 1023 bytes */
- if (j_strlen(id->user) > 1023)
- return 1;
-
- /* if nothing failed, the node is valid */
- return 0;
-}
-
-/**
- * resourceprep the resource identifier in a JID and check if it is valid
- *
- * @param jid data structure holding the JID
- * @return 0 if JID is valid, non zero otherwise
- */
-int _jid_safe_resource(jid id) {
- int result=0;
-
- /* it is valid to have no resource identifier in the JID */
- if (id->resource == NULL)
- return 0;
-
- /* resource prep the resource identifier */
- result = _jid_cached_stringprep(id->resource, strlen(id->resource)+1, _jid_prep_cache_resource);
- if (result == STRINGPREP_TOO_SMALL_BUFFER) {
- /* resourceprep wants to expand the string, e.g. conversion from ß to ss */
- size_t biggerbuffersize = 1024;
- char *biggerbuffer = static_cast<char*>(pmalloc(id->p, biggerbuffersize));
- if (biggerbuffer == NULL)
- return 1;
- strcpy(biggerbuffer, id->resource);
- result = _jid_cached_stringprep(id->resource, strlen(id->resource)+1, _jid_prep_cache_resource);
- id->resource = biggerbuffer;
+ try {
+ switch (item) {
+ case JID_RESOURCE:
+ id->set_resource(str);
+ break;
+ case JID_USER:
+ id->set_node(str);
+ break;
+ case JID_SERVER:
+ id->set_domain(str);
+ break;
+ }
+ } catch (std::invalid_argument) {
}
- if (result != STRINGPREP_OK)
- return 1;
-
- /* the resourcepreped node must not be longer than 1023 bytes */
- if (j_strlen(id->resource) > 1023)
- return 1;
-
- /* if nothing failed, the resource is valid */
- return 0;
-
}
-#else /* no LIBIDN */
-
-/**
- * check if the domain identifier in a JID is valid
- *
- * @param id data structure holding the JID
- * @return 0 if domain is valid, non zero otherwise
- */
-int _jid_safe_domain(jid id) {
- char *str;
-
- /* there must be a domain identifier */
- if (j_strlen(id->server) == 0)
- return 1;
-
- /* and it must not be longer than 1023 bytes */
- if (strlen(id->server) > 1023)
- return 1;
-
- /* lowercase the hostname, make sure it's valid characters */
- for(str = id->server; *str != '\0'; str++)
- {
- *str = tolower(*str);
- if(!(isalnum(*str) || *str == '.' || *str == '-' || *str == '_')) return 1;
- }
-
- /* otherwise it's okay as far as we can tell without LIBIDN */
- return 0;
-}
-
-/**
- * check if the node identifier in a JID is valid
- *
- * @param id data structure holding the JID
- * @return 0 if node is valid, non zero otherwise
- */
-int _jid_safe_node(jid id) {
- char *str;
-
- /* node identifiers may not be longer than 1023 bytes */
- if (j_strlen(id->user) > 1023)
- return 1;
-
- /* check for low and invalid ascii characters in the username */
- if(id->user != NULL)
- for(str = id->user; *str != '\0'; str++)
- if(*str <= 32 || *str == ':' || *str == '@' || *str == '<' || *str == '>' || *str == '\'' || *str == '"' || *str == '&') return 1;
-
- /* otherwise it's okay as far as we can tell without LIBIDN */
- return 0;
-}
-
-/**
- * check if the resource identifier in a JID is valid
- *
- * @param id data structure holding the JID
- * @return 0 if resource is valid, non zero otherwise
- */
-int _jid_safe_resource(jid id) {
- /* resources may not be longer than 1023 bytes */
- if (j_strlen(id->resource) > 1023)
- return 1;
-
- /* otherwise it's okay as far as we can tell without LIBIDN */
- return 0;
-}
-
-#endif
-
-/**
- * nodeprep/nameprep/resourceprep the JID and check if it is valid
- *
- * @param id data structure holding the JID
- * @return NULL if the JID is invalid, pointer to the jid otherwise
- */
-jid jid_safe(jid id)
-{
- if (_jid_safe_domain(id))
- return NULL;
- if (_jid_safe_node(id))
- return NULL;
- if (_jid_safe_resource(id))
+char *jid_full(jid id) {
+ if (!id)
return NULL;
- return id;
-}
-
-jid jid_new(pool p, const char *idstr)
-{
- char *server, *resource, *type, *str;
- jid id;
-
- if(p == NULL || idstr == NULL || strlen(idstr) == 0)
- return NULL;
-
- /* user at server/resource */
-
- str = pstrdup(p, idstr);
-
- id = static_cast<jid>(pmalloco(p,sizeof(struct jid_struct)));
- id->p = p;
-
- resource = strstr(str,"/");
- if(resource != NULL)
- {
- *resource = '\0';
- ++resource;
- if(strlen(resource) > 0)
- id->resource = resource;
- }else{
- resource = str + strlen(str); /* point to end */
- }
-
- type = strstr(str,":");
- if(type != NULL && type < resource)
- {
- *type = '\0';
- ++type;
- str = type; /* ignore the type: prefix */
- }
-
- server = strstr(str,"@");
- if(server == NULL || server > resource)
- { /* if there's no @, it's just the server address */
- id->server = str;
- }else{
- *server = '\0';
- ++server;
- id->server = server;
- if(strlen(str) > 0)
- id->user = str;
- }
-
- return jid_safe(id);
-}
-
-void jid_set(jid id, const char *str, int item)
-{
- char *old;
-
- if(id == NULL)
- return;
-
- /* invalidate the cached copy */
- id->full = NULL;
-
- switch(item)
- {
- case JID_RESOURCE:
- old = id->resource;
- if(str != NULL && strlen(str) != 0)
- id->resource = pstrdup(id->p, str);
- else
- id->resource = NULL;
- if(_jid_safe_resource(id))
- id->resource = old; /* revert if invalid */
- break;
- case JID_USER:
- old = id->user;
- if(str != NULL && strlen(str) != 0)
- id->user = pstrdup(id->p, str);
- else
- id->user = NULL;
- if(_jid_safe_node(id))
- id->user = old; /* revert if invalid */
- break;
- case JID_SERVER:
- old = id->server;
- id->server = pstrdup(id->p, str);
- if(_jid_safe_domain(id))
- id->server = old; /* revert if invalid */
- break;
- }
-
-}
-
-char *jid_full(jid id)
-{
- spool s;
-
- if(id == NULL)
- return NULL;
-
- /* use cached copy */
- if(id->full != NULL)
- return id->full;
-
- s = spool_new(id->p);
-
- if(id->user != NULL)
- spooler(s, id->user,"@",s);
-
- spool_add(s, id->server);
-
- if(id->resource != NULL)
- spooler(s, "/",id->resource,s);
-
- id->full = spool_print(s);
- return id->full;
+ return id->full_pooled();
}
-/* parses a /resource?name=value&foo=bar into an xmlnode representing <resource name="value" foo="bar"/> */
-/*
-xmlnode jid_xres(jid id)
-{
- char *cur, *qmark, *amp, *eq;
- xmlnode x;
-
- if(id == NULL || id->resource == NULL) return NULL;
-
- cur = pstrdup(id->p, id->resource);
- qmark = strstr(cur, "?");
- if(qmark == NULL) return NULL;
- *qmark = '\0';
- qmark++;
-
- x = _xmlnode_new(id->p, cur, NTYPE_TAG);
-
- cur = qmark;
- while(cur != '\0')
- {
- eq = strstr(cur, "=");
- if(eq == NULL) break;
- *eq = '\0';
- eq++;
-
- amp = strstr(eq, "&");
- if(amp != NULL)
- {
- *amp = '\0';
- amp++;
- }
-
- xmlnode_put_attrib(x,cur,eq);
-
- if(amp != NULL)
- cur = amp;
- else
- break;
- }
+int jid_cmp(jid a, jid b) {
+ if (!a || !b)
+ return -1;
- return x;
+ return (*a) == (*b) ? 0 : -1;
}
-*/
-/* local utils */
-int _jid_nullstrcmp(char *a, char *b)
-{
- if(a == NULL && b == NULL) return 0;
- if(a == NULL || b == NULL) return -1;
- return strcmp(a,b);
-}
-int _jid_nullstrcasecmp(char *a, char *b)
-{
- if(a == NULL && b == NULL) return 0;
- if(a == NULL || b == NULL) return -1;
- return strcasecmp(a,b);
-}
+int jid_cmpx(jid a, jid b, int parts) {
+ if (!a || !b)
+ return -1;
-int jid_cmp(jid a, jid b)
-{
- if(a == NULL || b == NULL)
- return -1;
-
- if(_jid_nullstrcmp(a->resource, b->resource) != 0) return -1;
- if(_jid_nullstrcasecmp(a->user, b->user) != 0) return -1;
- if(_jid_nullstrcmp(a->server, b->server) != 0) return -1;
-
- return 0;
-}
-
-/* suggested by Anders Qvist <quest at valdez.netg.se> */
-int jid_cmpx(jid a, jid b, int parts)
-{
- if(a == NULL || b == NULL)
- return -1;
-
- if(parts & JID_RESOURCE && _jid_nullstrcmp(a->resource, b->resource) != 0) return -1;
- if(parts & JID_USER && _jid_nullstrcasecmp(a->user, b->user) != 0) return -1;
- if(parts & JID_SERVER && _jid_nullstrcmp(a->server, b->server) != 0) return -1;
-
- return 0;
-}
-
-/* makes a copy of b in a's pool, requires a valid a first! */
-jid jid_append(jid a, jid b)
-{
- jid next;
-
- if(a == NULL)
- return NULL;
-
- if(b == NULL)
- return a;
-
- next = a;
- while(next != NULL)
- {
- /* check for dups */
- if(jid_cmp(next,b) == 0)
- break;
- if(next->next == NULL)
- next->next = jid_new(a->p,jid_full(b));
- next = next->next;
- }
- return a;
-}
-
-/**
- * get the first child node, that has an attribute jid with a value of jid_full(id)
- *
- * @deprecated use xmlnode_get_tags(x, "*[@jid='user at host/resource']", ...) instead
- *
- * @param id the JID to search for
- * @param x the node, that contains the searched child nodes
- * @return the node, that has an jid attribute, NULL if no such node
- */
-xmlnode jid_nodescan(jid id, xmlnode x) {
- xmlnode cur;
- pool p;
- jid tmp;
-
- if (id == NULL || xmlnode_get_firstchild(x) == NULL)
- return NULL;
-
- p = pool_new();
- for (cur = xmlnode_get_firstchild(x); cur != NULL; cur = xmlnode_get_nextsibling(cur)) {
- if (xmlnode_get_type(cur) != NTYPE_TAG)
- continue;
-
- tmp = jid_new(p,xmlnode_get_attrib_ns(cur,"jid", NULL));
- if (tmp == NULL)
- continue;
-
- if (jid_cmp(tmp,id) == 0)
- break;
- }
- pool_free(p);
-
- return cur;
+ return a->compare(*b, parts&JID_RESOURCE, parts&JID_USER, parts&JID_SERVER) ? 0 : -1;
}
/**
@@ -765,24 +109,33 @@
* @return the jid without the resource
*/
jid jid_user_pool(jid a, pool p) {
- jid ret;
-
- /* sanity check */
- if (p==NULL)
+ // sanity check
+ if (!a || !p)
return NULL;
- /* can we just return the original? */
- if(a == NULL || a->resource == NULL) return a;
-
- /* make a copy */
- ret = static_cast<jid>(pmalloco(p,sizeof(struct jid_struct)));
- ret->p = p;
- ret->user = a->user;
- ret->server = a->server;
-
- return ret;
+ return jid_new(p, a->get_user().full().c_str());
}
jid jid_user(jid a) {
- return jid_user_pool(a, a->p);
+ return jid_user_pool(a, a->get_pool());
}
+
+jid jid_append(jid a, jid b) {
+ if (!a)
+ return NULL;
+ if (!b)
+ return a;
+
+ jid next = a;
+ while (next) {
+ if (jid_cmp(next, b) == 0)
+ break;
+ if (next->next == NULL) {
+ next->next = jid_new(a->get_pool(), jid_full(b));
+ return a;
+ }
+ next = next->next;
+ }
+ return a;
+}
+
Modified: trunk/jabberd14/jabberd/lib/jutil.cc
==============================================================================
--- trunk/jabberd14/jabberd/lib/jutil.cc (original)
+++ trunk/jabberd14/jabberd/lib/jutil.cc Sat Apr 26 23:47:56 2008
@@ -122,7 +122,7 @@
* @param body the body of the message
* @return the xmlnode containing the new message stanza
*/
-xmlnode jutil_msgnew(char *type, char *to, char *subj, char *body) {
+xmlnode jutil_msgnew(char *type, char const* to, char *subj, char *body) {
xmlnode msg;
msg = xmlnode_new_tag_ns("message", NULL, NS_SERVER);
Modified: trunk/jabberd14/jabberd/lib/xhash.cc
==============================================================================
--- trunk/jabberd14/jabberd/lib/xhash.cc (original)
+++ trunk/jabberd14/jabberd/lib/xhash.cc Sat Apr 26 23:47:56 2008
@@ -266,10 +266,10 @@
char *value = xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(*iter, "value", ns), 0));
if (value == NULL)
- value = "";
+ value = pstrdup(p, "");
if (key == NULL)
- key = "";
+ key = pstrdup(p, "");
xhash_put(result, key, pstrdup(p, value));
}
Modified: trunk/jabberd14/jabberd/mio_tls.cc
==============================================================================
--- trunk/jabberd14/jabberd/mio_tls.cc (original)
+++ trunk/jabberd14/jabberd/mio_tls.cc Sat Apr 26 23:47:56 2008
@@ -1831,7 +1831,7 @@
jid_pool = pool_new();
cert_jid = jid_new(jid_pool, thisIdOnXMPPaddr);
- if (cert_jid == NULL || cert_jid->server == NULL) {
+ if (cert_jid == NULL) {
cert_jid = NULL;
pool_free(jid_pool);
jid_pool = NULL;
Modified: trunk/jabberd14/jsm/authreg.cc
==============================================================================
--- trunk/jabberd14/jsm/authreg.cc (original)
+++ trunk/jabberd14/jsm/authreg.cc Sat Apr 26 23:47:56 2008
@@ -129,7 +129,7 @@
return;
log_debug2(ZONE, LOGT_AUTH, "registration set request acceptable");
- if (p->to->user == NULL || xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(p->iq, "register:password", namespaces), 0)) == NULL) {
+ if (!p->to->has_node() || xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(p->iq, "register:password", namespaces), 0)) == NULL) {
log_debug2(ZONE, LOGT_AUTH, "registration set request without a password ...");
jutil_error_xmpp(p->x, XTERROR_NOTACCEPTABLE);
} else if (js_user(si, p->to, NULL) != NULL) {
@@ -182,12 +182,7 @@
jsmi si = (jsmi)(p->aux1);
xmlnode x;
- /* enforce the username to lowercase */
- if (p->to->user != NULL)
- for(ul = p->to->user;*ul != '\0'; ul++)
- *ul = tolower(*ul);
-
- if(p->to->user != NULL && (jpacket_subtype(p) == JPACKET__GET || p->to->resource != NULL) && NSCHECK(p->iq,NS_AUTH)) {
+ if(p->to->has_node() && (jpacket_subtype(p) == JPACKET__GET || p->to->has_resource()) && NSCHECK(p->iq,NS_AUTH)) {
/* is this a valid auth request? */
_js_authreg_auth(p);
} else if (NSCHECK(p->iq,NS_REGISTER)) {
Modified: trunk/jabberd14/jsm/deliver.cc
==============================================================================
--- trunk/jabberd14/jsm/deliver.cc (original)
+++ trunk/jabberd14/jsm/deliver.cc Sat Apr 26 23:47:56 2008
@@ -58,7 +58,7 @@
/* first, collect some facts */
user = js_user(si, p->to, ht);
- s = js_session_get(user, p->to->resource);
+ s = js_session_get(user, p->to->get_resource().c_str());
/* lock the udata from being freed while we are working on it */
if (user != NULL) {
@@ -77,7 +77,7 @@
return;
}
- if(p->to->user == NULL) {
+ if(!p->to->has_node()) {
/* this is for the server */
js_psend(si,p,js_server_main);
if (incremented != 0) {
@@ -232,7 +232,7 @@
if (s != NULL) {
s->sid = NULL; /* they generated the error, no use in sending there anymore! */
js_session_end(s, N_("Disconnected"));
- } else if (p->id->resource == NULL) {
+ } else if (!p->id->has_resource()) {
/* a way to boot an entire user off */
for(s = u->sessions; s != NULL; s = s->next)
js_session_end(s, N_("Removed"));
@@ -430,7 +430,7 @@
if (sc_sm == NULL) {
/* old protocol */
for (s = u->sessions; s != NULL; s = s->next)
- if(j_strcmp(p->id->resource, s->route->resource) == 0)
+ if (p->id->get_resource() == s->route->get_resource())
break;
} else {
/* new session control protocol */
@@ -560,7 +560,7 @@
/* do we have to pass it through the outgoing filters? */
/* only filter if packet is from a user, and if the packet is not to the user himself */
- if (p->flag != PACKET_PASS_FILTERS_MAGIC && p->from->user != NULL && jid_cmpx(p->to, p->from, JID_USER|JID_SERVER) != 0) {
+ if (p->flag != PACKET_PASS_FILTERS_MAGIC && p->from->has_node() && jid_cmpx(p->to, p->from, JID_USER|JID_SERVER) != 0) {
/* filter through a session's filter? */
if (sending_s != NULL) {
if (js_mapi_call(NULL, es_FILTER_OUT, p, sending_s->u, sending_s)) {
@@ -580,7 +580,7 @@
log_debug2(ZONE, LOGT_DELIVER, "deliver(to[%s],from[%s],type[%d],packet[%s])", jid_full(p->to), jid_full(p->from), p->type, xmlnode_serialize_string(p->x, xmppd::ns_decl_list(), 0));
/* external or local delivery? */
- if ((ht = (xht)xhash_get(si->hosts,p->to->server)) != NULL) {
+ if ((ht = (xht)xhash_get(si->hosts, p->to->get_domain().c_str())) != NULL) {
js_deliver_local(si, p, ht);
return;
}
Modified: trunk/jabberd14/jsm/jsm.h
==============================================================================
--- trunk/jabberd14/jsm/jsm.h (original)
+++ trunk/jabberd14/jsm/jsm.h Sat Apr 26 23:47:56 2008
@@ -581,7 +581,7 @@
session js_session_new(jsmi si, dpacket p);
session js_sc_session_new(jsmi si, dpacket p, xmlnode sc_session);
void js_session_end(session s, char *reason);
-session js_session_get(udata user, char *res);
+session js_session_get(udata user, char const* res);
session js_session_primary(udata user);
void js_session_to(session s, jpacket p);
void js_session_from(session s, jpacket p);
Modified: trunk/jabberd14/jsm/modules/mod_admin.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_admin.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_admin.cc Sat Apr 26 23:47:56 2008
@@ -103,7 +103,7 @@
xmlnode_put_attrib_ns(query, "node", NULL, NULL, "online sessions");
/* add the online sessions */
- xhash_walk(static_cast<xht>(xhash_get(si->hosts, p->to->server)), _mod_admin_disco_online_iter, (void *)query);
+ xhash_walk(static_cast<xht>(xhash_get(si->hosts, p->to->get_domain().c_str())), _mod_admin_disco_online_iter, (void *)query);
/* send back */
jpacket_reset(p);
@@ -197,7 +197,7 @@
/* check if we are interested in handling this packet */
if (m->packet->type != JPACKET_MESSAGE)
return M_IGNORE; /* the session manager should not deliver this stanza type again */
- if (m->packet->to->resource != NULL || jpacket_subtype(m->packet) == JPACKET__ERROR)
+ if (m->packet->to->has_resource() || jpacket_subtype(m->packet) == JPACKET__ERROR)
return M_PASS;
/* drop ones w/ a delay! (circular safety) */
@@ -209,7 +209,7 @@
log_debug2(ZONE, LOGT_DELIVER, "delivering admin message from %s",jid_full(m->packet->from));
/* update the message */
- subject=spools(m->packet->p, messages_get(xmlnode_get_lang(m->packet->x), N_("Admin: ")), xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(m->packet->x, "subject", m->si->std_namespace_prefixes) ,0)), " (", m->packet->to->server, ")", m->packet->p);
+ subject=spools(m->packet->p, messages_get(xmlnode_get_lang(m->packet->x), N_("Admin: ")), xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(m->packet->x, "subject", m->si->std_namespace_prefixes) ,0)), " (", m->packet->to->get_domain().c_str(), ")", m->packet->p);
xmlnode_hide(xmlnode_get_list_item(xmlnode_get_tags(m->packet->x, "subject", m->si->std_namespace_prefixes), 0));
xmlnode_insert_cdata(xmlnode_insert_tag_ns(m->packet->x, "subject", NULL, NS_SERVER), subject, -1);
jutil_delay(m->packet->x, "admin");
@@ -223,7 +223,7 @@
js_deliver(m->si, p, NULL);
}
if (admins != NULL) {
- pool_free(admins->p);
+ pool_free(admins->get_pool());
admins = NULL;
}
Modified: trunk/jabberd14/jsm/modules/mod_agents.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_agents.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_agents.cc Sat Apr 26 23:47:56 2008
@@ -96,7 +96,7 @@
jpacket_reset(m->packet);
if(m->s != NULL) {
/* XXX null session hack! */
- xmlnode_put_attrib_ns(m->packet->x, "from", NULL, NULL, m->packet->from->server);
+ xmlnode_put_attrib_ns(m->packet->x, "from", NULL, NULL, m->packet->from->get_domain().c_str());
js_session_to(m->s,m->packet);
} else {
js_deliver(m->si, m->packet, NULL);
@@ -149,7 +149,7 @@
jpacket_reset(m->packet);
if (m->s != NULL) {
/* XXX null session hack! */
- xmlnode_put_attrib_ns(m->packet->x, "from", NULL, NULL, m->packet->from->server);
+ xmlnode_put_attrib_ns(m->packet->x, "from", NULL, NULL, m->packet->from->get_domain().c_str());
js_session_to(m->s,m->packet);
} else {
js_deliver(m->si, m->packet, NULL);
@@ -176,7 +176,7 @@
if (jpacket_subtype(m->packet) != JPACKET__GET)
return M_PASS; /* only care for IQ stanzas of type 'get' */
- if (m->s != NULL && (m->packet->to != NULL && j_strcmp(jid_full(m->packet->to),m->packet->from->server) != 0))
+ if (m->s != NULL && (m->packet->to != NULL && j_strcmp(jid_full(m->packet->to),m->packet->from->get_domain().c_str()) != 0))
return M_PASS; /* for session calls, only answer to=NULL or to=server */
if (NSCHECK(m->packet->iq, NS_AGENT))
Modified: trunk/jabberd14/jsm/modules/mod_announce.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_announce.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_announce.cc Sat Apr 26 23:47:56 2008
@@ -115,7 +115,7 @@
* @return always M_HANDLED
*/
static mreturn mod_announce_avail(jsmi si, jpacket p) {
- xmlnode_put_attrib_ns(p->x, "from", NULL, NULL, p->to->server);
+ xmlnode_put_attrib_ns(p->x, "from", NULL, NULL, p->to->get_domain().c_str());
xhash_walk(si->hosts,_mod_announce_avail_hosts,(void *)(p->x));
xmlnode_free(p->x);
return M_HANDLED;
@@ -134,20 +134,20 @@
if (a->x != NULL)
xmlnode_free(a->x);
- if (j_strcmp(p->to->resource,"announce/motd/delete") == 0) {
+ if (p->to->get_resource() == "announce/motd/delete") {
a->x = NULL;
xmlnode_free(p->x);
return M_HANDLED;
}
/* store new message for all new sessions */
- xmlnode_put_attrib_ns(p->x, "from", NULL, NULL, p->to->server);
+ xmlnode_put_attrib_ns(p->x, "from", NULL, NULL, p->to->get_domain().c_str());
jutil_delay(p->x,"Announced"); /* at a timestamp to the element */
a->x = p->x; /* keep the motd message */
a->set = time(NULL); /* XXX shouldn't we only update this timestamp if it isn't an update? */
/* tell current sessions if this wasn't an update */
- if(j_strcmp(p->to->resource,"announce/motd/update") != 0)
+ if (p->to->get_resource() == "announce/motd/update")
xhash_walk(si->hosts, _mod_announce_avail_hosts, (void *)(a->x));
return M_HANDLED;
@@ -168,16 +168,16 @@
if (m->packet->type != JPACKET_MESSAGE)
return M_IGNORE; /* ignore everything but messages */
- if (j_strncmp(m->packet->to->resource,"announce/",9) != 0)
+ if (m->packet->to->get_resource().substr(0, 9) == "announce/")
return M_PASS; /* not a configuration message */
log_debug2(ZONE, LOGT_DELIVER, "handling announce message from %s",jid_full(m->packet->from));
/* if he is, process the message */
if (acl_check_access(m->si->xc, ADMIN_MOTD, m->packet->from)) {
- if (j_strncmp(m->packet->to->resource,"announce/online",15) == 0)
+ if (m->packet->to->get_resource().substr(0, 15) == "announce/online")
return mod_announce_avail(m->si, m->packet);
- if (j_strncmp(m->packet->to->resource,"announce/motd",13) == 0)
+ if (m->packet->to->get_resource().substr(0, 13) == "announce/motd")
return mod_announce_motd(m->si, m->packet, (motd)arg);
}
Modified: trunk/jabberd14/jsm/modules/mod_browse.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_browse.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_browse.cc Sat Apr 26 23:47:56 2008
@@ -55,7 +55,7 @@
/* get main account browse */
if ((browse = xdb_get(m->si->xc, id, NS_BROWSE)) == NULL) {
/* no browse is set up yet, we must create one for this user! */
- if (id->resource == NULL) {
+ if (!id->has_resource()) {
/* a user is only the user at host */
browse = xmlnode_new_tag_ns("user", NULL, NS_BROWSE);
/* get the friendly name for this user from somewhere */
@@ -107,7 +107,7 @@
to = m->user->id;
/* if we set to a resource, we need to make sure that resource's browse is in the users browse */
- if (to->resource != NULL) {
+ if (to->has_resource()) {
browse = mod_browse_get(m, to); /* get our browse info */
xmlnode_hide_attrib_ns(browse, "xmlns", NS_XMLNS); /* don't need a ns as a child */
for (cur = xmlnode_get_firstchild(browse); cur != NULL; cur = xmlnode_get_nextsibling(cur))
@@ -130,7 +130,7 @@
}
/* if the new data we're inserting is to one of our resources, update that resource's browse */
- if (jid_cmpx(m->user->id, id, JID_USER|JID_SERVER) == 0 && id->resource != NULL) {
+ if (jid_cmpx(m->user->id, id, JID_USER|JID_SERVER) == 0 && id->has_resource()) {
/* get the old */
browse = mod_browse_get(m, id);
/* transform the new one into the old one */
@@ -190,7 +190,7 @@
return M_HANDLED;
}
- log_debug2(ZONE, LOGT_DELIVER, "handling query for user %s", m->user->id->user);
+ log_debug2(ZONE, LOGT_DELIVER, "handling query for user %s", m->user->id->get_node().c_str());
/* get this dudes browse info */
browse = mod_browse_get(m, m->packet->to);
@@ -241,7 +241,7 @@
if (m->packet->type != JPACKET_IQ)
return M_IGNORE;
- if (jpacket_subtype(m->packet) != JPACKET__GET || m->packet->to->resource != NULL)
+ if (jpacket_subtype(m->packet) != JPACKET__GET || m->packet->to->has_resource())
return M_PASS;
/* get data from the config file */
@@ -254,7 +254,7 @@
vcard_fn = js_config(m->si, "vcard:vCard/vcard:FN", xmlnode_get_lang(m->packet->x));
query = xmlnode_insert_tag_ns(jutil_iqresult(m->packet->x), "service", NULL, NS_BROWSE);
xmlnode_put_attrib_ns(query, "type", NULL, NULL, "jabber");
- xmlnode_put_attrib_ns(query, "jid", NULL, NULL, m->packet->to->server);
+ xmlnode_put_attrib_ns(query, "jid", NULL, NULL, m->packet->to->get_domain().c_str());
xmlnode_put_attrib_ns(query, "name", NULL, NULL, xmlnode_get_data(vcard_fn)); /* pull name from the server vCard */
/* copy in the configured services */
Modified: trunk/jabberd14/jsm/modules/mod_disco.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_disco.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_disco.cc Sat Apr 26 23:47:56 2008
@@ -179,7 +179,7 @@
xmlnode_put_attrib_ns(item, "name", NULL, NULL, messages_get(xmlnode_get_lang(m->packet->x), N_("Administrator")));
}
if (admins != NULL) {
- pool_free(admins->p);
+ pool_free(admins->get_pool());
admins = NULL;
}
@@ -209,7 +209,7 @@
return M_IGNORE;
if (jpacket_subtype(m->packet) != JPACKET__GET)
return M_PASS;
- if (m->packet->to->resource != NULL)
+ if (m->packet->to->has_resource())
return M_PASS;
if (NSCHECK(m->packet->iq, NS_DISCO_ITEMS))
return mod_disco_server_items(m,arg);
@@ -336,7 +336,7 @@
static mreturn mod_disco_user(mapi m, void *arg) {
if (m->packet->type != JPACKET_IQ)
return M_IGNORE;
- if (m->packet->to->resource != NULL)
+ if (m->packet->to->has_resource())
return M_PASS;
if (NSCHECK(m->packet->iq, NS_DISCO_ITEMS))
return mod_disco_user_items(m);
Modified: trunk/jabberd14/jsm/modules/mod_dynamic.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_dynamic.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_dynamic.cc Sat Apr 26 23:47:56 2008
@@ -243,10 +243,10 @@
xmlnode note = xmlnode_insert_tag_ns(m->packet->iq, "note", NULL, NS_COMMAND);
- if (!preped_hostname || !preped_hostname->server) {
+ if (!preped_hostname) {
xmlnode_put_attrib_ns(note, "type", NULL, NULL, "error");
xmlnode_insert_cdata(note, messages_get(xmlnode_get_lang(m->packet->x), N_("The entered hostname is invalid.")), -1);
- } else if (j_strcmp(preped_hostname->server, m->si->i->id) == 0) {
+ } else if (j_strcmp(preped_hostname->get_domain().c_str(), m->si->i->id) == 0) {
xmlnode_put_attrib_ns(note, "type", NULL, NULL, "error");
xmlnode_insert_cdata(note, messages_get(xmlnode_get_lang(m->packet->x), N_("The main hostname of a session manager cannot be modified.")), -1);
} else {
@@ -256,14 +256,14 @@
switch (given_command) {
case host:
xmlnode_insert_cdata(note, messages_get(xmlnode_get_lang(m->packet->x), N_("Hostname has been added.")), -1);
- log_debug2(ZONE, LOGT_DYNAMIC, "registering hostname %s on server %s", preped_hostname->server, m->si->i->id);
- register_instance(m->si->i, preped_hostname->server);
+ log_debug2(ZONE, LOGT_DYNAMIC, "registering hostname %s on server %s", preped_hostname->get_domain().c_str(), m->si->i->id);
+ register_instance(m->si->i, preped_hostname->get_domain().c_str());
break;
case unhost:
// XXX kick existing sessions and remove local data about this domain
xmlnode_insert_cdata(note, messages_get(xmlnode_get_lang(m->packet->x), N_("Hostname has been removed.")), -1);
- log_debug2(ZONE, LOGT_DYNAMIC, "unregistering hostname %s on server %s", preped_hostname->server, m->si->i->id);
- unregister_instance(m->si->i, preped_hostname->server);
+ log_debug2(ZONE, LOGT_DYNAMIC, "unregistering hostname %s on server %s", preped_hostname->get_domain().c_str(), m->si->i->id);
+ unregister_instance(m->si->i, preped_hostname->get_domain().c_str());
break;
}
}
Modified: trunk/jabberd14/jsm/modules/mod_echo.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_echo.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_echo.cc Sat Apr 26 23:47:56 2008
@@ -60,7 +60,7 @@
return M_IGNORE;
/* first, is this a valid request? */
- if (m->packet->to->resource == NULL || strncasecmp(m->packet->to->resource, "echo", 4) != 0)
+ if (!m->packet->to->has_resource() || m->packet->to->get_resource() == "echo")
return M_PASS;
log_debug2(ZONE, LOGT_DELIVER, "handling echo request from %s", jid_full(m->packet->from));
Modified: trunk/jabberd14/jsm/modules/mod_example.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_example.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_example.cc Sat Apr 26 23:47:56 2008
@@ -81,7 +81,8 @@
if(m->packet->type != JPACKET_MESSAGE) return M_IGNORE;
/* second, is this message sent to the right resource? */
- if(m->packet->to->resource == NULL || strncasecmp(m->packet->to->resource,"example",7) != 0) return M_PASS;
+ if(!m->packet->to->has_resource() || m->packet->to->get_resource() == "example")
+ return M_PASS;
log_debug2(ZONE, LOGT_DELIVER, "handling example request from %s",jid_full(m->packet->from));
Modified: trunk/jabberd14/jsm/modules/mod_last.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_last.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_last.cc Sat Apr 26 23:47:56 2008
@@ -60,7 +60,7 @@
xmlnode last;
/* pre-requisites */
- if (jpacket_subtype(m->packet) != JPACKET__GET || m->packet->to->resource != NULL)
+ if (jpacket_subtype(m->packet) != JPACKET__GET || m->packet->to->has_resource())
return M_PASS;
jutil_iqresult(m->packet->x);
@@ -239,7 +239,7 @@
return M_HANDLED;
}
- log_debug2(ZONE, LOGT_SESSION, "handling query for user %s", m->user->id->user);
+ log_debug2(ZONE, LOGT_SESSION, "handling query for user %s", m->user->id->get_node().c_str());
last = xdb_get(m->si->xc, m->user->id, NS_LAST);
Modified: trunk/jabberd14/jsm/modules/mod_offline.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_offline.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_offline.cc Sat Apr 26 23:47:56 2008
@@ -110,7 +110,7 @@
}
}
- log_debug2(ZONE, LOGT_DELIVER, "handling message for %s", m->user->id->user);
+ log_debug2(ZONE, LOGT_DELIVER, "handling message for %s", m->user->id->get_node().c_str());
if ((cur2 = xmlnode_get_list_item(xmlnode_get_tags(m->packet->x,"expire:x", m->si->std_namespace_prefixes), 0)) != NULL) {
if (j_atoi(xmlnode_get_attrib_ns(cur2, "seconds", NULL), 0) == 0)
Modified: trunk/jabberd14/jsm/modules/mod_presence.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_presence.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_presence.cc Sat Apr 26 23:47:56 2008
@@ -381,7 +381,7 @@
} else {
newpri = j_atoi(priority, 0);
if (newpri < -128 || newpri > 127) {
- log_notice(m->s->id->server, "got presence with invalid priority value from %s", jid_full(m->s->id));
+ log_notice(m->s->id->get_domain().c_str(), "got presence with invalid priority value from %s", jid_full(m->s->id));
xmlnode_free(m->packet->x);
return M_HANDLED;
}
@@ -704,8 +704,8 @@
log_debug2(ZONE, LOGT_DELIVER, "deliver phase");
/* only if we HAVE a user, and it was sent to ONLY the user at server, and there is at least one session available */
- if (m->user != NULL && m->packet->to->resource == NULL && js_session_primary(m->user) != NULL) {
- log_debug2(ZONE, LOGT_DELIVER, "broadcasting to %s",m->user->id->user);
+ if (m->user && !m->packet->to->has_resource() && js_session_primary(m->user) != NULL) {
+ log_debug2(ZONE, LOGT_DELIVER, "broadcasting to %s",m->user->id->get_node().c_str());
/* broadcast */
for (cur = m->user->sessions; cur != NULL; cur = cur->next) {
Modified: trunk/jabberd14/jsm/modules/mod_privacy.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_privacy.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_privacy.cc Sat Apr 26 23:47:56 2008
@@ -407,9 +407,9 @@
match_parts = JID_SERVER;
/* check if node or resource has to match */
- if (match_jid->user != NULL)
+ if (match_jid->has_node())
match_parts |= JID_USER;
- if (match_jid->resource != NULL)
+ if (match_jid->has_resource())
match_parts |= JID_RESOURCE;
}
@@ -607,22 +607,22 @@
log_debug2(ZONE, LOGT_EXECFLOW, "Checking normalization of roster group: %s", group_name);
/* could the name be normalized? */
- if (normal_group == NULL || normal_group->resource == NULL) {
+ if (normal_group == NULL || !normal_group->has_resource()) {
log_debug2(ZONE, LOGT_EXECFLOW, "Could not normalize group name in roster: %s", group_name);
xmlnode_hide(*group);
continue;
}
/* insert normalized data if necessary */
- if (j_strcmp(group_name, normal_group->resource) != 0) {
+ if (j_strcmp(group_name, normal_group->get_resource().c_str()) != 0) {
xmlnode_vector text_node = xmlnode_get_tags(*group, "text()", si->std_namespace_prefixes);
- log_debug2(ZONE, LOGT_EXECFLOW, "Normalized '%s' to '%s'", group_name, normal_group->resource);
+ log_debug2(ZONE, LOGT_EXECFLOW, "Normalized '%s' to '%s'", group_name, normal_group->get_resource().c_str());
if (text_node.size() > 0) {
xmlnode_hide(text_node[0]);
}
- xmlnode_insert_cdata(*group, normal_group->resource, -1);
+ xmlnode_insert_cdata(*group, normal_group->get_resource().c_str(), -1);
}
}
@@ -636,16 +636,16 @@
log_debug2(ZONE, LOGT_EXECFLOW, "Checking normalization of group on list: %s", group_name);
/* could the name be normalized? */
- if (normal_group == NULL || normal_group->resource == NULL) {
+ if (normal_group == NULL || !normal_group->has_resource()) {
log_debug2(ZONE, LOGT_EXECFLOW, "Could not normalize group name on list: %s", group_name);
xmlnode_hide(*group);
continue;
}
/* update value if necessary */
- if (j_strcmp(group_name, normal_group->resource) != 0) {
- log_debug2(ZONE, LOGT_EXECFLOW, "Normalized '%s' to '%s'", group_name, normal_group->resource);
- xmlnode_put_attrib_ns(*group, "value", NULL, NULL, normal_group->resource);
+ if (j_strcmp(group_name, normal_group->get_resource().c_str()) != 0) {
+ log_debug2(ZONE, LOGT_EXECFLOW, "Normalized '%s' to '%s'", group_name, normal_group->get_resource().c_str());
+ xmlnode_put_attrib_ns(*group, "value", NULL, NULL, normal_group->get_resource().c_str());
}
}
Modified: trunk/jabberd14/jsm/modules/mod_register.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_register.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_register.cc Sat Apr 26 23:47:56 2008
@@ -96,7 +96,7 @@
if (password_present > 1) {
xmlnode_free(passwordchange);
jutil_error_xmpp(m->packet->x, XTERROR_NOTACCEPTABLE);
- log_notice(m->user->id->server, "Denied password change, password field has been provied %i times (user %s)", password_present, jid_full(m->packet->to));
+ log_notice(m->user->id->get_domain().c_str(), "Denied password change, password field has been provied %i times (user %s)", password_present, jid_full(m->packet->to));
return M_HANDLED;
}
@@ -168,12 +168,12 @@
/* let the auth modules store the credentials */
if (mod_register_passwordchange(m) == M_HANDLED) {
- log_notice(m->user->id->server, "Could not store password when processing registration request: %s", jid_full(m->user->id));
+ log_notice(m->user->id->get_domain().c_str(), "Could not store password when processing registration request: %s", jid_full(m->user->id));
xmlnode_free(reg);
return M_HANDLED;
}
- log_notice(m->packet->to->server, "User %s registered", jid_full(m->packet->to));
+ log_notice(m->packet->to->get_domain().c_str(), "User %s registered", jid_full(m->packet->to));
/* stamp the registration data */
jutil_delay(m->packet->iq,"registered");
@@ -196,8 +196,8 @@
spool_add(msg_body, "E-Mail: ");
spool_add(msg_body, email ? email : "no address provided");
- x = jutil_msgnew("chat", m->packet->to->server, "Registration Notice", spool_print(msg_body));
- xmlnode_put_attrib_ns(x, "from", NULL, NULL, m->packet->to->server);
+ x = jutil_msgnew("chat", m->packet->to->get_domain().c_str(), "Registration Notice", spool_print(msg_body));
+ xmlnode_put_attrib_ns(x, "from", NULL, NULL, m->packet->to->get_domain().c_str());
js_deliver(m->si, jpacket_new(x), m->s);
}
@@ -208,7 +208,7 @@
lang = xmlnode_get_lang(welcome);
x = xmlnode_new_tag_ns("message", NULL, NS_SERVER);
- xmlnode_put_attrib_ns(x, "from", NULL, NULL, m->packet->to->server);
+ xmlnode_put_attrib_ns(x, "from", NULL, NULL, m->packet->to->get_domain().c_str());
xmlnode_put_attrib_ns(x, "to", NULL, NULL, jid_full(m->packet->to));
if (lang != NULL) {
xmlnode_put_attrib_ns(x, "lang", "xml", NS_XML, lang);
@@ -356,7 +356,7 @@
if (m->user == NULL)
return M_PASS;
- log_debug2(ZONE, LOGT_AUTH, "updating server: %s, user %s", m->user->id->server, jid_full(m->user->id));
+ log_debug2(ZONE, LOGT_AUTH, "updating server: %s, user %s", m->user->id->get_domain().c_str(), jid_full(m->user->id));
/* check for their registration */
reg = xdb_get(m->si->xc, m->user->id, NS_REGISTER);
@@ -419,11 +419,11 @@
js_bounce_xmpp(m->si, m->s, m->packet->x, err);
xmlnode_free(nounregister);
xmlnode_free(reg);
- log_notice(m->user->id->server, "Denied unregistration to user %s", jid_full(m->user->id));
+ log_notice(m->user->id->get_domain().c_str(), "Denied unregistration to user %s", jid_full(m->user->id));
return M_HANDLED;
}
- log_notice(m->user->id->server,"User Unregistered: %s",m->user->id->user);
+ log_notice(m->user->id->get_domain().c_str(), "User Unregistered: %s", m->user->id->get_node().c_str());
/* let the modules remove their data for this user */
js_user_delete(m->si, m->user->id);
@@ -452,7 +452,7 @@
/* user tries to change his username */
js_bounce_xmpp(m->si, m->s, m->packet->x, XTERROR_NOTACCEPTABLE);
xmlnode_free(reg);
- log_notice(m->user->id->server, "Denied update of username for %s to %s", jid_full(m->user->id), xmlnode_get_data(*iter));
+ log_notice(m->user->id->get_domain().c_str(), "Denied update of username for %s to %s", jid_full(m->user->id), xmlnode_get_data(*iter));
return M_HANDLED;
}
@@ -470,16 +470,16 @@
if (has_username > 1) {
js_bounce_xmpp(m->si, m->s, m->packet->x, XTERROR_BAD);
xmlnode_free(reg);
- log_notice(m->user->id->server, "User %s sent registration data set request containing multiple usernames", jid_full(m->user->id));
+ log_notice(m->user->id->get_domain().c_str(), "User %s sent registration data set request containing multiple usernames", jid_full(m->user->id));
return M_HANDLED;
}
- xmlnode_insert_cdata(xmlnode_insert_tag_ns(m->packet->iq, "username", NULL, NS_REGISTER), m->user->id->user, -1);
+ xmlnode_insert_cdata(xmlnode_insert_tag_ns(m->packet->iq, "username", NULL, NS_REGISTER), m->user->id->get_node().c_str(), -1);
/* did we find anything useful? */
if (!is_passwordchange && only_passwordchange) {
js_bounce_xmpp(m->si, m->s, m->packet->x, XTERROR_BAD);
xmlnode_free(reg);
- log_notice(m->user->id->server, "User %s sent incomplete registration data set request", jid_full(m->user->id));
+ log_notice(m->user->id->get_domain().c_str(), "User %s sent incomplete registration data set request", jid_full(m->user->id));
return M_HANDLED;
}
@@ -504,7 +504,7 @@
js_bounce_xmpp(m->si, m->s, m->packet->x, err);
xmlnode_free(noregistrationchange);
xmlnode_free(reg);
- log_notice(m->user->id->server, "Denied registration data change to user %s", jid_full(m->user->id));
+ log_notice(m->user->id->get_domain().c_str(), "Denied registration data change to user %s", jid_full(m->user->id));
return M_HANDLED;
}
}
@@ -521,7 +521,7 @@
js_bounce_xmpp(m->si, m->s, m->packet->x, err);
xmlnode_free(nopasswordchange);
xmlnode_free(reg);
- log_notice(m->user->id->server, "Denied password change to user %s", jid_full(m->user->id));
+ log_notice(m->user->id->get_domain().c_str(), "Denied password change to user %s", jid_full(m->user->id));
return M_HANDLED;
}
xmlnode_free(nopasswordchange);
@@ -530,7 +530,7 @@
xmlnode_free(reg);
return M_HANDLED;
}
- log_notice(m->user->id->server, "User %s changed password", jid_full(m->user->id));
+ log_notice(m->user->id->get_domain().c_str(), "User %s changed password", jid_full(m->user->id));
}
if (!only_passwordchange) {
Modified: trunk/jabberd14/jsm/modules/mod_roster.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_roster.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_roster.cc Sat Apr 26 23:47:56 2008
@@ -46,7 +46,7 @@
static xmlnode mod_roster_get(udata u) {
xmlnode ret;
- log_debug2(ZONE, LOGT_ROSTER, "getting %s's roster", u->id->user);
+ log_debug2(ZONE, LOGT_ROSTER, "getting %s's roster", u->id->get_node().c_str());
/* get the existing roster */
ret = xdb_get(u->si->xc, u->id, NS_ROSTER);
@@ -67,22 +67,23 @@
* @param newflag where to store 1 if the item did not exist and has just been created
* @return the roster item
*/
-static xmlnode mod_roster_get_item(xmlnode roster, jid id, int *newflag) {
- xmlnode ret;
-
+static xmlnode mod_roster_get_item(mapi m, xmlnode roster, jid id, int *newflag) {
log_debug2(ZONE, LOGT_ROSTER, "getting item %s", jid_full(id));
- ret = jid_nodescan(id, roster);
+ std::ostringstream xpath;
+ xpath << "*[@jid='" << id << "']";
- if (ret == NULL) {
- /* there isn't one, brew one up */
- log_debug2(ZONE, LOGT_ROSTER, "creating");
- ret = xmlnode_insert_tag_ns(roster, "item", NULL, NS_ROSTER);
- xmlnode_put_attrib_ns(ret, "jid", NULL, NULL, jid_full(id));
- xmlnode_put_attrib_ns(ret, "subscription", NULL, NULL, "none");
- *newflag = 1;
- }
+ xmlnode_vector ret_v = xmlnode_get_tags(roster, xpath.str().c_str(), m->si->std_namespace_prefixes);
+
+ if (!ret_v.empty())
+ return ret_v[0];
+ /* there isn't one, brew one up */
+ log_debug2(ZONE, LOGT_ROSTER, "creating");
+ xmlnode ret = xmlnode_insert_tag_ns(roster, "item", NULL, NS_ROSTER);
+ xmlnode_put_attrib_ns(ret, "jid", NULL, NULL, jid_full(id));
+ xmlnode_put_attrib_ns(ret, "subscription", NULL, NULL, "none");
+ *newflag = 1;
return ret;
}
@@ -190,7 +191,7 @@
/* get the roster item */
roster = mod_roster_get(m->user);
- item = mod_roster_get_item(roster, m->packet->to, &newflag);
+ item = mod_roster_get_item(m, roster, m->packet->to, &newflag);
/* vars containing the old subscription state */
if (j_strcmp(xmlnode_get_attrib_ns(item, "subscription", NULL), "to") == 0)
@@ -394,7 +395,7 @@
continue;
/* zoom to find the existing item in the current roster, and hide it */
- item = mod_roster_get_item(roster, id, &newflag);
+ item = mod_roster_get_item(m, roster, id, &newflag);
xmlnode_hide(item);
/* drop you sukkah */
@@ -513,7 +514,7 @@
/* now we can get to work and handle this user's incoming subscription crap */
roster = mod_roster_get(m->user);
- item = mod_roster_get_item(roster, m->packet->from, &newflag);
+ item = mod_roster_get_item(m, roster, m->packet->from, &newflag);
reply2 = reply = NULL;
jid_set(m->packet->to, NULL, JID_RESOURCE); /* make sure we're only dealing w/ the user id */
Modified: trunk/jabberd14/jsm/modules/mod_time.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_time.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_time.cc Sat Apr 26 23:47:56 2008
@@ -52,7 +52,7 @@
char *tstr;
struct tm *tmd;
- if (m->packet->to->resource != NULL)
+ if (m->packet->to->has_resource())
return M_PASS;
/* first, is this a valid request? */
Modified: trunk/jabberd14/jsm/modules/mod_useridpolicy.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_useridpolicy.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_useridpolicy.cc Sat Apr 26 23:47:56 2008
@@ -44,10 +44,10 @@
static mreturn mod_useridpolicy_new(mapi m, void *arg) {
xmlnode config = NULL; /* xmlnode holding the module configuration */
xmlnode x=NULL; /* for iterating */
- char *username = NULL; /* the username that should be registered */
+ char const* username = NULL; /* the username that should be registered */
jid user_jid = NULL; /* JID containing the username (to get stringpreped) */
size_t username_len = 0; /* length of the username in characters (!) */
- char *ptr = NULL; /* for iterating */
+ char const* ptr = NULL; /* for iterating */
log_debug2(ZONE, LOGT_AUTH, "checking registration policy");
@@ -65,7 +65,7 @@
/* stringprep the username */
user_jid = jid_new(m->packet->p, "invalid"); /* for 'invalid' as domain see RFC 2606, we just need any domain */
jid_set(user_jid, username, JID_USER);
- username = user_jid->user;
+ username = user_jid->get_node().c_str();
/* get configuration, disable the module if not configured */
if ((config = js_config(m->si, "jsm:mod_useridpolicy", NULL)) == NULL)
@@ -86,7 +86,7 @@
/* check for a match and possibly reject */
if (j_strcmp(xmlnode_get_data(x), username) == 0) {
- log_notice(m->packet->to->server, "blocked account '%s' from being registered: forbidden username", username);
+ log_notice(m->packet->to->get_domain().c_str(), "blocked account '%s' from being registered: forbidden username", username);
jutil_error_xmpp(m->packet->x, XTERROR_NOTACCEPTABLE);
xmlnode_free(config);
return M_HANDLED;
@@ -108,7 +108,7 @@
/* check for minimum length */
if (j_atoi(xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(config, "jsm:minlen", m->si->std_namespace_prefixes), 0)), 1) > username_len) {
- log_notice(m->packet->to->server, "blocked account '%s' from being registered: username to short", username);
+ log_notice(m->packet->to->get_domain().c_str(), "blocked account '%s' from being registered: username to short", username);
jutil_error_xmpp(m->packet->x, XTERROR_NOTACCEPTABLE);
xmlnode_free(config);
return M_HANDLED;
@@ -116,7 +116,7 @@
/* check for maximum length */
if (j_atoi(xmlnode_get_data(xmlnode_get_list_item(xmlnode_get_tags(config, "jsm:maxlen", m->si->std_namespace_prefixes), 0)), 1023) < username_len) {
- log_notice(m->packet->to->server, "blocked account '%s' from being registered: username to long", username);
+ log_notice(m->packet->to->get_domain().c_str(), "blocked account '%s' from being registered: username to long", username);
jutil_error_xmpp(m->packet->x, XTERROR_NOTACCEPTABLE);
xmlnode_free(config);
return M_HANDLED;
Modified: trunk/jabberd14/jsm/modules/mod_vcard.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_vcard.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_vcard.cc Sat Apr 26 23:47:56 2008
@@ -191,7 +191,7 @@
return M_HANDLED;
}
- log_debug2(ZONE, LOGT_DELIVER, "handling query for user %s", m->user->id->user);
+ log_debug2(ZONE, LOGT_DELIVER, "handling query for user %s", m->user->id->get_node().c_str());
/* get this guys vcard info */
vcard = xdb_get(m->si->xc, m->user->id, NS_VCARD);
@@ -236,7 +236,7 @@
xmlnode vcard, query;
if(m->packet->type != JPACKET_IQ) return M_IGNORE;
- if(jpacket_subtype(m->packet) != JPACKET__GET || !NSCHECK(m->packet->iq,NS_VCARD) || m->packet->to->resource != NULL) return M_PASS;
+ if(jpacket_subtype(m->packet) != JPACKET__GET || !NSCHECK(m->packet->iq,NS_VCARD) || m->packet->to->has_resource()) return M_PASS;
/* get data from the config file */
if((vcard = js_config(m->si,"vcard:vCard", xmlnode_get_lang(m->packet->x))) == NULL)
Modified: trunk/jabberd14/jsm/modules/mod_version.cc
==============================================================================
--- trunk/jabberd14/jsm/modules/mod_version.cc (original)
+++ trunk/jabberd14/jsm/modules/mod_version.cc Sat Apr 26 23:47:56 2008
@@ -69,7 +69,7 @@
* @return M_IGNORED if not a iq stanza, M_PASS if stanza not handled, M_HANDLED if stanza has been handled
*/
static mreturn _mod_version_reply(mapi m, mod_version_i mi) {
- if (m->packet->to->resource != NULL)
+ if (m->packet->to->has_resource())
return M_PASS;
/* first, is this a valid request? */
Modified: trunk/jabberd14/jsm/serialization.cc
==============================================================================
--- trunk/jabberd14/jsm/serialization.cc (original)
+++ trunk/jabberd14/jsm/serialization.cc Sat Apr 26 23:47:56 2008
@@ -55,7 +55,7 @@
/* generate the wrapper element when first session is processed */
if (thisuser == NULL) {
thisuser = xmlnode_insert_tag_ns(resulttree, "user", NULL, NS_JABBERD_STOREDSTATE);
- xmlnode_put_attrib_ns(thisuser, "name", NULL, NULL, userdata->id->user);
+ xmlnode_put_attrib_ns(thisuser, "name", NULL, NULL, userdata->id->get_node().c_str());
}
/* generate the wrapper element for the session */
@@ -80,7 +80,7 @@
/* debugging */
if (thisuser == NULL) {
- log_debug2(ZONE, LOGT_EXECFLOW, "user %s had no sessions", userdata->id->user);
+ log_debug2(ZONE, LOGT_EXECFLOW, "user %s had no sessions", userdata->id->get_node().c_str());
}
}
@@ -204,7 +204,7 @@
s->id = jid_new(p, jid_full(user_jid));
jid_set(s->id, resource, JID_RESOURCE);
- s->res = s->id->resource;
+ s->res = pstrdup(s->p, s->id->get_resource().c_str());
s->u = u;
s->exit_flag = 0;
s->roster = roster;
Modified: trunk/jabberd14/jsm/sessions.cc
==============================================================================
--- trunk/jabberd14/jsm/sessions.cc (original)
+++ trunk/jabberd14/jsm/sessions.cc Sat Apr 26 23:47:56 2008
@@ -155,7 +155,7 @@
char session_id[9];
/* screen out illegal calls */
- if(dp == NULL || dp->id->user == NULL || dp->id->resource == NULL || xmlnode_get_attrib_ns(dp->x, "from", NULL) == NULL || (u = js_user(si, dp->id, NULL)) == NULL)
+ if(dp == NULL || !dp->id->has_node() || !dp->id->has_resource() || xmlnode_get_attrib_ns(dp->x, "from", NULL) == NULL || (u = js_user(si, dp->id, NULL)) == NULL)
return NULL;
log_debug2(ZONE, LOGT_SESSION, "session_create %s", jid_full(dp->id));
@@ -178,7 +178,7 @@
s->route = jid_new(p, jid_full(dp->id));
_js_create_session_id(session_id, NULL);
jid_set(s->route, session_id, JID_RESOURCE);
- s->res = pstrdup(p, dp->id->resource);
+ s->res = pstrdup(p, dp->id->get_resource().c_str());
s->u = u;
/* default settings */
@@ -194,7 +194,7 @@
/* remove any other session w/ this resource */
for (cur = u->sessions; cur != NULL; cur = cur->next)
- if (j_strcmp(dp->id->resource, cur->res) == 0)
+ if (j_strcmp(dp->id->get_resource().c_str(), cur->res) == 0)
js_session_end(cur, N_("Replaced by new connection"));
/* make sure we're linked with the user */
@@ -272,7 +272,7 @@
pool_cleanup(s->p, js_session_free_aux_data, s);
s->id = user_id;
- s->res = user_id->resource;
+ s->res = pstrdup(s->p, user_id->get_resource().c_str());
s->u = u;
s->exit_flag = 0;
s->roster = 0;
@@ -293,7 +293,7 @@
/* remove any other session w/ this resource */
for (cur = u->sessions; cur != NULL; cur = cur->next)
- if (j_strcmp(dp->id->resource, cur->res) == 0)
+ if (j_strcmp(dp->id->get_resource().c_str(), cur->res) == 0)
js_session_end(cur, N_("Replaced by new connection"));
/* make sure we're linked with the user */
@@ -634,7 +634,7 @@
* @param res the resource to search for
* @return a pointer to the session if the user is logged in, NULL if the user isn't logged in on this resource
*/
-session js_session_get(udata user, char *res) {
+session js_session_get(udata user, char const* res) {
session cur; /* session pointer */
/* screen out illeagal calls */
Modified: trunk/jabberd14/jsm/users.cc
==============================================================================
--- trunk/jabberd14/jsm/users.cc (original)
+++ trunk/jabberd14/jsm/users.cc Sat Apr 26 23:47:56 2008
@@ -70,7 +70,7 @@
if(u->ref > 0 || (u->sessions != NULL && ++*(htc->count)))
return;
- log_debug2(ZONE, LOGT_SESSION, "freeing %s", u->id->user);
+ log_debug2(ZONE, LOGT_SESSION, "freeing %s", u->id->get_node().c_str());
xhash_zap(htc->ht, key);
pool_free(u->p);
@@ -252,19 +252,19 @@
xmlnode x, y;
jid uid;
- if (si == NULL || id == NULL || id->user == NULL)
+ if (si == NULL || id == NULL || !id->has_node())
return NULL;
/* get the host hash table if it wasn't provided */
if (ht == NULL)
- ht = static_cast<xht>(xhash_get(si->hosts,id->server));
+ ht = static_cast<xht>(xhash_get(si->hosts,id->get_domain().c_str()));
/* hrm, like, this isn't our user! */
if (ht == NULL)
return NULL;
/* copy the id and convert user to lower case (if not done by libidn) */
- uid = jid_new(id->p, jid_full(jid_user(id)));
+ uid = jid_new(id->get_pool(), jid_full(jid_user(id)));
#ifndef LIBIDN
for (ustr = uid->user; *ustr != '\0'; ustr++)
*ustr = tolower(*ustr);
@@ -274,7 +274,7 @@
log_debug2(ZONE, LOGT_SESSION, "js_user(%s,%X)",jid_full(uid),ht);
/* try to get the user data from the hash table */
- if ((cur = static_cast<udata>(xhash_get(ht,uid->user))) != NULL)
+ if ((cur = static_cast<udata>(xhash_get(ht,uid->get_node().c_str()))) != NULL)
return cur;
/* debug message */
@@ -305,8 +305,8 @@
/* got the user, add it to the user list */
- xhash_put(ht, newu->id->user, newu);
- log_debug2(ZONE, LOGT_SESSION, "js_user debug %X %X", xhash_get(ht, newu->id->user), newu);
+ xhash_put(ht, newu->id->get_node().c_str(), newu);
+ log_debug2(ZONE, LOGT_SESSION, "js_user debug %X %X", xhash_get(ht, newu->id->get_node().c_str()), newu);
return newu;
}
Modified: trunk/jabberd14/jsm/util.cc
==============================================================================
--- trunk/jabberd14/jsm/util.cc (original)
+++ trunk/jabberd14/jsm/util.cc Sat Apr 26 23:47:56 2008
@@ -110,9 +110,9 @@
* @return 0 if the user is not local, 1 if the user is local
*/
int js_islocal(jsmi si, jid id) {
- if (id == NULL || id->user == NULL)
+ if (id == NULL || !id->has_node())
return 0;
- if (xhash_get(si->hosts, id->server) == NULL)
+ if (xhash_get(si->hosts, id->get_domain().c_str()) == NULL)
return 0;
return 1;
}
@@ -255,15 +255,15 @@
*/
int _js_jidscanner(jid id, jid match) {
for (;id != NULL; id = id->next) {
- if (j_strcmp(id->server,match->server) != 0)
+ if (id->get_domain() != match->get_domain())
continue;
- if (id->user == NULL)
+ if (!id->has_node())
return 1;
- if (j_strcasecmp(id->user,match->user) != 0)
+ if (id->get_node() != match->get_node())
continue;
- if (id->resource == NULL)
+ if (!id->has_resource())
return 1;
- if (j_strcmp(id->resource,match->resource) != 0)
+ if (id->get_resource() != match->get_resource())
continue;
return 1;
}
Modified: trunk/jabberd14/pthsock/client.cc
==============================================================================
--- trunk/jabberd14/pthsock/client.cc (original)
+++ trunk/jabberd14/pthsock/client.cc Sat Apr 26 23:47:56 2008
@@ -119,8 +119,8 @@
mio m;
int fd = 0;
- if (p->id->user != NULL)
- fd = atoi(p->id->user);
+ if (p->id->has_node())
+ fd = atoi(p->id->get_node().c_str());
if (p->type != p_ROUTE || fd == 0) {
/* we only want <route/> packets or ones with a valid connection */
@@ -141,14 +141,19 @@
return r_DONE;
}
-
-
- if (fd != cdcur->m->fd || cdcur->m->state != state_ACTIVE)
- m = NULL;
- else if (j_strcmp(p->id->resource,cdcur->res) != 0)
- m = NULL;
- else
- m = cdcur->m;
+ if (fd != cdcur->m->fd) {
+ log_debug2(ZONE, LOGT_SESSION, "Unexpected fd: packet for fd #%i while expecting fd #%i", fd, cdcur->m->fd);
+ m = NULL;
+ } else if (cdcur->m->state != state_ACTIVE) {
+ log_debug2(ZONE, LOGT_SESSION, "Got packet for un-active socket");
+ m = NULL;
+ } else if (j_strcmp(p->id->get_resource().c_str(), cdcur->res) != 0) {
+ log_debug2(ZONE, LOGT_SESSION, "Unexpected resource: packet for %s, expecting %s", p->id->get_resource().c_str(), cdcur->res);
+ log_debug2(ZONE, LOGT_SESSION, "XXX JID: %s", p->id->full().c_str());
+ m = NULL;
+ } else {
+ m = cdcur->m;
+ }
if (m == NULL) {
if (j_strcmp(xmlnode_get_attrib_ns(p->x, "type", NULL), "error") == 0) {
@@ -189,14 +194,14 @@
log_debug2(ZONE, LOGT_SESSION, "[%s] requesting Session Start for %s", ZONE, xmlnode_get_attrib_ns(p->x, "from", NULL));
deliver(dpacket_new(x), s__i->i);
} else if (j_strcmp(type,"error") == 0) {
- log_record(jid_full(jid_user(cdcur->session_id)), "login", "fail", "%s %s %s", mio_ip(cdcur->m), xmlnode_get_attrib_ns(xmlnode_get_list_item(xmlnode_get_tags(p->x, "iq/error", s__i->std_namespace_prefixes), 0), "code", NULL), cdcur->session_id->resource);
+ log_record(jid_full(jid_user(cdcur->session_id)), "login", "fail", "%s %s %s", mio_ip(cdcur->m), xmlnode_get_attrib_ns(xmlnode_get_list_item(xmlnode_get_tags(p->x, "iq/error", s__i->std_namespace_prefixes), 0), "code", NULL), cdcur->session_id->get_resource().c_str());
}
} else if (cdcur->state == state_UNKNOWN && j_strcmp(xmlnode_get_attrib_ns(p->x, "type", NULL), "session") == 0) {
/* got a session reply from the server */
mio_wbq q;
cdcur->state = state_AUTHD;
- log_record(jid_full(jid_user(cdcur->session_id)), "login", "ok", "%s %s", mio_ip(cdcur->m), cdcur->session_id->resource);
+ log_record(jid_full(jid_user(cdcur->session_id)), "login", "ok", "%s %s", mio_ip(cdcur->m), cdcur->session_id->get_resource().c_str());
/* change the host id */
cdcur->session_id = jid_new(m->p, xmlnode_get_attrib_ns(p->x, "from", NULL));
xmlnode_free(p->x);
@@ -331,7 +336,7 @@
if (version>=1) {
xmlnode features = xmlnode_new_tag_ns("features", "stream", NS_STREAM);
/* TLS possible on this connection? */
- if (mio_ssl_starttls_possible(m, cd->session_id->server)) {
+ if (mio_ssl_starttls_possible(m, cd->session_id->get_domain().c_str())) {
xmlnode starttls = NULL;
starttls = xmlnode_insert_tag_ns(features, "starttls", NULL, NS_XMPP_TLS);
@@ -357,13 +362,13 @@
/* make sure alias is upheld */
if (cd->aliased) {
jid j = jid_new(xmlnode_pool(x), xmlnode_get_attrib_ns(x, "to", NULL));
- if (j != NULL && j_strcmp(j->server, cd->sending_id->server) == 0) {
- jid_set(j, cd->session_id->server, JID_SERVER);
+ if (j && j->get_domain() == cd->sending_id->get_domain()) {
+ jid_set(j, cd->session_id->get_domain().c_str(), JID_SERVER);
xmlnode_put_attrib_ns(x, "to", NULL, NULL, jid_full(j));
}
j = jid_new(xmlnode_pool(x), xmlnode_get_attrib_ns(x, "from", NULL));
- if (j != NULL && j_strcmp(j->server, cd->sending_id->server) == 0) {
- jid_set(j, cd->session_id->server, JID_SERVER);
+ if (j && j->get_domain() == cd->sending_id->get_domain()) {
+ jid_set(j, cd->session_id->get_domain().c_str(), JID_SERVER);
xmlnode_put_attrib_ns(x, "from", NULL, NULL, jid_full(j));
}
}
@@ -375,13 +380,13 @@
xmlnode q_register = xmlnode_get_list_item(xmlnode_get_tags(x, "register:query", cd->si->std_namespace_prefixes), 0);
if (j_strcmp(xmlnode_get_localname(x), "starttls") == 0 && j_strcmp(xmlnode_get_namespace(x), NS_XMPP_TLS) == 0) {
/* starting TLS possible? */
- if (mio_ssl_starttls_possible(m, cd->session_id->server)) {
+ if (mio_ssl_starttls_possible(m, cd->session_id->get_domain().c_str())) {
/* ACK the start */
xmlnode proceed = xmlnode_new_tag_ns("proceed", NULL, NS_XMPP_TLS);
mio_write(m, proceed, NULL, 0);
/* start TLS on this connection */
- if (mio_xml_starttls(m, 0, cd->session_id->server) != 0) {
+ if (mio_xml_starttls(m, 0, cd->session_id->get_domain().c_str()) != 0) {
/* starttls failed */
mio_close(m);
}
Modified: trunk/jabberd14/xdb_file/xdb_file.cc
==============================================================================
--- trunk/jabberd14/xdb_file/xdb_file.cc (original)
+++ trunk/jabberd14/xdb_file/xdb_file.cc Sat Apr 26 23:47:56 2008
@@ -192,7 +192,7 @@
* @param use_subdirs true if file should be located in subdirectories
* @return 1 on success, 0 on failure
*/
-int _xdb_gen_dirs(spool sp, const char *spoolroot, char *host, const char *hash1, const char *hash2, int use_subdirs) {
+int _xdb_gen_dirs(spool sp, const char *spoolroot, char const* host, const char *hash1, const char *hash2, int use_subdirs) {
struct stat s;
char *tmp;
@@ -243,7 +243,7 @@
* @param use_subdirs true if file should be located in subdirectories
* @return concatenated string of the form spl+"/"+somehashes+"/"+file+"."+ext
*/
-char *xdb_file_full(int create, pool p, const char *spl, char *host, const char *file, char *ext, int use_subdirs) {
+char *xdb_file_full(int create, pool p, const char *spl, char const* host, const char *file, char const* ext, int use_subdirs) {
spool sp = spool_new(p);
char digit01[3], digit23[3];
char *ret;
@@ -302,11 +302,11 @@
/* create the filename of the responsible file */
/* is this request specific to a user or global data? */
- if (p->id->user != NULL)
- full = xdb_file_full(flag_set, p->p, xf->spool, p->id->server, p->id->user, "xml", xf->use_hashspool);
+ if (p->id->has_node())
+ full = xdb_file_full(flag_set, p->p, xf->spool, p->id->get_domain().c_str(), p->id->get_node().c_str(), "xml", xf->use_hashspool);
else
/* global data, not data for a user: never put it inside the hash directories (use global.xdb file) */
- full = xdb_file_full(flag_set, p->p, xf->spool, p->id->server, "global", "xdb", 0);
+ full = xdb_file_full(flag_set, p->p, xf->spool, p->id->get_domain().c_str(), "global", "xdb", 0);
/* no filename? -> error */
if (full == NULL)
@@ -316,11 +316,11 @@
top = file = xdb_file_load(p->host, full, xf->cache);
/* if we're dealing w/ a resource, just get that element <res id='resource'/> inside <xdb/> */
- if (p->id->resource != NULL) {
- top = xmlnode_get_list_item(xmlnode_get_tags(top, spools(p->p, "res[@id='", p->id->resource, "']", p->p), xf->std_ns_prefixes), 0);
+ if (p->id->has_resource()) {
+ top = xmlnode_get_list_item(xmlnode_get_tags(top, spools(p->p, "res[@id='", p->id->get_resource().c_str(), "']", p->p), xf->std_ns_prefixes), 0);
if (top == NULL) {
top = xmlnode_insert_tag_ns(file, "res", NULL, NS_JABBERD_XDB);
- xmlnode_put_attrib_ns(top, "id", NULL, NULL, p->id->resource);
+ xmlnode_put_attrib_ns(top, "id", NULL, NULL, p->id->get_resource().c_str());
}
}
@@ -334,11 +334,12 @@
matchns = xmlnode_get_attrib_ns(p->x, "matchns", NULL);
if (act != NULL) {
xht namespaces = NULL;
- pool value_strings = NULL;
+ pool value_strings = NULL; // pool for the value strings in the namespaces xhash
if (matchns != NULL) {
xmlnode namespacesxml = NULL;
namespacesxml = xmlnode_str(matchns, j_strlen(matchns));
+ value_strings = pool_new();
namespaces = xhash_from_xml(namespacesxml, value_strings);
xmlnode_free(namespacesxml);
}
@@ -371,6 +372,8 @@
log_debug2(ZONE, LOGT_STORAGE|LOGT_DELIVER, "xdb check action returning error to signify unsuccessful check");
if (namespaces)
xhash_free(namespaces);
+ if (value_strings)
+ pool_free(value_strings);
return r_ERR;
}
flag_set = 0;
@@ -410,6 +413,10 @@
break;
default:
log_warn(p->host, "unable to handle unknown xdb action '%s'", act);
+ if (namespaces)
+ xhash_free(namespaces);
+ if (value_strings)
+ pool_free(value_strings);
return r_ERR;
}
if (namespaces)
@@ -429,9 +436,9 @@
if (flag_set) {
int tmp = xmlnode2file_limited(full,file,xf->sizelimit);
if (tmp == 0)
- log_notice(p->id->server,"xdb request failed, due to the size limit of %i to file %s", xf->sizelimit, full);
+ log_notice(p->id->get_domain().c_str(), "xdb request failed, due to the size limit of %i to file %s", xf->sizelimit, full);
else if (tmp < 0)
- log_error(p->id->server,"xdb request failed, unable to save to file %s",full);
+ log_error(p->id->get_domain().c_str(), "xdb request failed, unable to save to file %s", full);
else
ret = 1;
}
Modified: trunk/jabberd14/xdb_file/xdbfiletool.cc
==============================================================================
--- trunk/jabberd14/xdb_file/xdbfiletool.cc (original)
+++ trunk/jabberd14/xdb_file/xdbfiletool.cc Sat Apr 26 23:47:56 2008
@@ -45,14 +45,14 @@
void *so_h = NULL;
/* functions in libjabberdxdbfile.so used */
-char* (*xdb_file_full)(int create, pool p, const char *spl, char *host, const char *file, char *ext, int use_subdirs);
+char* (*xdb_file_full)(int create, pool p, const char *spl, char const* host, const char *file, char const* ext, int use_subdirs);
void (*xdb_convert_spool)(const char *spoolroot);
xmlnode (*xdb_file_load)(char *host, char *fname, xht cache);
int main(int argc, const char **argv) {
char *host = NULL;
char *error = NULL;
- char *cfgfile = CONFIG_DIR "/jabber.xml";
+ char const* cfgfile = CONFIG_DIR "/jabber.xml";
char *basedir = NULL;
char *do_get = NULL;
char *do_set = NULL;
@@ -67,7 +67,7 @@
char *getpath = NULL;
int hashspool = 0;
pool p = NULL;
- struct jid_struct *parsed_jid = NULL;
+ ::jid parsed_jid = NULL;
struct poptOption options[] = {
{ "convert", 0, POPT_ARG_NONE, &convert, 0, "convert from plain spool to hashspool", NULL},
@@ -88,7 +88,6 @@
/* init the libraries */
pth_init();
- jid_init_cache();
p = pool_new();
namespace_prefixes = xhash_new(101);
@@ -213,13 +212,13 @@
}
if (getpath != NULL) {
- struct jid_struct *user = jid_new(p, getpath);
+ ::jid user = jid_new(p, getpath);
if (user == NULL) {
std::cerr << "Problem processing secified JabberID: " << getpath << std::endl;
return 1;
}
- std::cout << (*xdb_file_full)(0, p, basedir, user->server, user->user, "xml", hashspool) << std::endl;
+ std::cout << (*xdb_file_full)(0, p, basedir, user->get_domain().c_str(), user->get_node().c_str(), "xml", hashspool) << std::endl;
pool_free(p);
return 0;
@@ -251,7 +250,7 @@
return 1;
}
- spoolfile = (*xdb_file_full)(0, p, basedir, parsed_jid->server, parsed_jid->user, "xml", hashspool);
+ spoolfile = (*xdb_file_full)(0, p, basedir, parsed_jid->get_domain().c_str(), parsed_jid->get_node().c_str(), "xml", hashspool);
file = (*xdb_file_load)(NULL, spoolfile, NULL);
if (file == NULL) {
More information about the dev
mailing list