[xmppd-dev] commit r1540 - in branches/RELEASE-1_6_1: . jabberd jabberd/lib

mail at jabberd.org mail at jabberd.org
Fri Sep 26 13:46:19 CEST 2008


Author: mawis
Date: Fri Sep 26 13:46:18 2008
New Revision: 1540

Log:
New feature:
Administrator of the server can configure xpath expressions, that are used against routed stanzas in the server. If the expression matches, the stanza will be logged. This feature is thought to be used for debugging purposes.

Modified behaviour:
If a packet from a client connection manager to a session manager using the session control protocol bounces, the bounce will now trigger the client connection manager to close the connection to the client. This matches the behaviour with the old way these two components communicate and is reasonable, as bounced packages normally mean, that the packet is for a session, that does not exist (anymore).

Modified:
   branches/RELEASE-1_6_1/ChangeLog
   branches/RELEASE-1_6_1/NEWS
   branches/RELEASE-1_6_1/configure.ac
   branches/RELEASE-1_6_1/jabberd/config.cc
   branches/RELEASE-1_6_1/jabberd/deliver.cc
   branches/RELEASE-1_6_1/jabberd/jabberd.h
   branches/RELEASE-1_6_1/jabberd/lib/jabberdlib.h

Modified: branches/RELEASE-1_6_1/ChangeLog
==============================================================================
--- branches/RELEASE-1_6_1/ChangeLog	Wed Sep 10 02:35:57 2008	(r1539)
+++ branches/RELEASE-1_6_1/ChangeLog	Fri Sep 26 13:46:18 2008	(r1540)
@@ -1,3 +1,10 @@
+2008-09-26  Matthias Wimmer  <m at tthias.eu>
+
+    * jabberd/jabberd.h: new: logging filters, fix: bouncing with sc-sessions
+    * jabberd/lib/jabberdlib.h: same
+    * jabberd/deliver.cc: same
+    * jabberd/config.cc: logging filters
+
 2008-09-08  Matthias Wimmer  <m at tthias.eu>
 
     * jabberd/xdb.cc: fix problem with fixed puffer for printing integer

Modified: branches/RELEASE-1_6_1/NEWS
==============================================================================
--- branches/RELEASE-1_6_1/NEWS	Wed Sep 10 02:35:57 2008	(r1539)
+++ branches/RELEASE-1_6_1/NEWS	Fri Sep 26 13:46:18 2008	(r1540)
@@ -4,7 +4,11 @@
 
 Changes in administration of the server
     * host can be dynamically added and removed from a session manager using
-      service discovery and ad-hoc commands.
+      service discovery and ad-hoc commands
+    * logging of routed stanzas using xpath expressions can be configured
+    * bounced packets between the the session manager and a client connection
+      manager using the session control protocol will now trigger that the
+      client connection manager will close the session
 
 
 

Modified: branches/RELEASE-1_6_1/configure.ac
==============================================================================
--- branches/RELEASE-1_6_1/configure.ac	Wed Sep 10 02:35:57 2008	(r1539)
+++ branches/RELEASE-1_6_1/configure.ac	Fri Sep 26 13:46:18 2008	(r1540)
@@ -6,7 +6,7 @@
 
 
 AC_INIT(jabberd/jabberd.h)
-AM_INIT_AUTOMAKE(jabberd14,1.6.1.2-pre2)
+AM_INIT_AUTOMAKE(jabberd14,1.6.1.2-pre3)
 AM_CONFIG_HEADER(config.h)
 AC_LANG(C++)
 

Modified: branches/RELEASE-1_6_1/jabberd/config.cc
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/config.cc	Wed Sep 10 02:35:57 2008	(r1539)
+++ branches/RELEASE-1_6_1/jabberd/config.cc	Fri Sep 26 13:46:18 2008	(r1540)
@@ -364,6 +364,9 @@
 	pool_free(temp_pool);
     }
 
+    // update the filter settings in the XML router
+    deliver_config_filter(greymatter__);
+
     return 0;
 }
 

Modified: branches/RELEASE-1_6_1/jabberd/deliver.cc
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/deliver.cc	Wed Sep 10 02:35:57 2008	(r1539)
+++ branches/RELEASE-1_6_1/jabberd/deliver.cc	Fri Sep 26 13:46:18 2008	(r1540)
@@ -133,6 +133,9 @@
 int deliver__flag=0;	/**< 0 = pause delivery on startup and queue for later delivery, 1 = normal operation, -1 = shutdown: no delivery, no queueing */
 pth_msgport_t deliver__mp=NULL;	/**< message port, that contains all queued messages for later delivery while ::deliver__flag = 0 */
 
+xht filter_namespaces = NULL;	/**< namespaces using in dump filters of the router */
+std::list<std::string> filter_expressions; /**< xpath expressions used for logging routed packets */
+
 /**
  * queue item for the list of queued messages for later delivery, used while ::deliver__flag = 0
  */
@@ -151,6 +154,56 @@
 } *ilist, _ilist;
 
 /**
+ * initializes or updates the dump filters of the router
+ *
+ * @param greymatter the parsed configuration file
+ */
+void deliver_config_filter(xmlnode greymatter) {
+    // remove existing expressions
+    filter_expressions.erase(filter_expressions.begin(), filter_expressions.end());
+
+    // create a new hash for the prefixes, free old one if there is already one
+    xht old_filter_namespaces = filter_namespaces;
+    filter_namespaces = xhash_new(17);
+    if (old_filter_namespaces) {
+	xhash_free(old_filter_namespaces);
+	old_filter_namespaces = NULL;
+    }
+
+    // read prefixes from configuration
+    xht namespaces = xhash_new(1);
+    pool p = pool_new();
+    xhash_put(namespaces, "", const_cast<char*>(NS_JABBERD_CONFIGFILE));
+    xmlnode_list_item prefix_list = xmlnode_get_tags(greymatter, "global/router/namespace", namespaces, p);
+    for (xmlnode_list_item cur = prefix_list; cur; cur = cur->next) {
+	char const* prefix = xmlnode_get_attrib_ns(cur->node, "prefix", NULL);
+	char const* ns_iri = xmlnode_get_data(cur->node);
+
+	if (prefix && ns_iri) {
+	    log_debug2(ZONE, LOGT_DELIVER, "adding namespace prefix: %s=%s", prefix, ns_iri);
+	    xhash_put(filter_namespaces, prefix, pstrdup(filter_namespaces->p, ns_iri));
+	}
+    }
+
+    // read expressions from configuration
+    xmlnode_list_item expression_list = xmlnode_get_tags(greymatter, "global/router/dump", namespaces, p);
+    for (xmlnode_list_item cur = expression_list; cur; cur = cur->next) {
+	char const* expression = xmlnode_get_data(cur->node);
+
+	if (expression) {
+	    log_debug2(ZONE, LOGT_DELIVER, "adding filter expression: %s", expression);
+	    filter_expressions.push_back(expression);
+	}
+    }
+
+    // free temp memory
+    xhash_free(namespaces);
+    namespaces = NULL;
+    pool_free(p);
+    p = NULL;
+}
+
+/**
  * add an ::instance to the list of all instances
  *
  * @param il the existing list
@@ -682,6 +735,15 @@
     if (p == NULL)
 	 return;
 
+    // log-dump the packet?
+    if (p->type != p_LOG && filter_namespaces) {
+	for (std::list<std::string>::const_iterator cur = filter_expressions.begin(); cur != filter_expressions.end(); ++cur) {
+	    if (xmlnode_get_tags(p->x, cur->c_str(), filter_namespaces)) {
+		log_notice(NULL, "on router %s: %s", cur->c_str(), xmlnode_serialize_string(p->x, xmppd::ns_decl_list(), 0));
+	    }
+	}
+    }
+
     /* catch the @-internal xdb crap */
     if (p->type == p_XDB && *(p->host) == '-') {
         deliver_internal(p, i);
@@ -853,6 +915,8 @@
 void deliver_fail(dpacket p, const char *err) {
     xterror xt;
     char message[MAX_LOG_SIZE];
+    xmlnode child = NULL;
+    char const* sc_sm = NULL;
 
     log_debug2(ZONE, LOGT_DELIVER, "delivery failed (%s)", err);
 
@@ -871,6 +935,33 @@
 	    log_warn(p->host, "dropping a %s xdb request to %s for %s", xmlnode_get_attrib_ns(p->x,"type", NULL), xmlnode_get_attrib_ns(p->x, "to", NULL), xmlnode_get_attrib_ns(p->x, "ns", NULL));
 	    /* drop through and treat like a route failure */
 	case p_ROUTE:
+	    // new session control protocol?
+	    child = xmlnode_get_firstchild(p->x);
+	    sc_sm = child ? xmlnode_get_attrib_ns(child, "sm", NS_SESSION) : NULL;
+	    if (sc_sm) {
+		// control packet?
+		if (j_strcmp(xmlnode_get_namespace(child), NS_SESSION) == 0) {
+		    // XXX
+		} else {
+		    log_notice(p->host, "ending session/packet bounce: from=%s, to=%s, err=%s", xmlnode_get_attrib_ns(p->x, "from", NULL), xmlnode_get_attrib_ns(p->x, "to", NULL), err);
+
+		    // routed packet for new session control protocol
+		    xmlnode_hide(child);
+		    
+		    xmlnode sc = xmlnode_insert_tag_ns(p->x, "session", "sc", NS_SESSION);
+		    xmlnode_put_attrib_ns(sc, "action", NULL, NULL, "ended");
+		    xmlnode_put_attrib_ns(sc, "c2s", "sc", NS_SESSION, xmlnode_get_attrib_ns(child, "c2s", NS_SESSION));
+		    xmlnode_put_attrib_ns(sc, "sm", "sc", NS_SESSION, xmlnode_get_attrib_ns(child, "c2s", NS_SESSION));
+		    xmlnode_put_attrib_ns(sc, "msg", "err", NS_JABBERD_ERRMSG, err);
+
+		    jutil_tofrom(p->x);
+		    log_notice(p->host, "ended packet is: %s", xmlnode_serialize_string(p->x, xmppd::ns_decl_list(), 0));
+		    deliver(dpacket_new(p->x), NULL);
+
+		    break;
+		}
+	    }
+
 	    /* route packet bounce */
 	    if (j_strcmp(xmlnode_get_attrib_ns(p->x, "type", NULL),"error") == 0) {
 		/* already bounced once, drop */

Modified: branches/RELEASE-1_6_1/jabberd/jabberd.h
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/jabberd.h	Wed Sep 10 02:35:57 2008	(r1539)
+++ branches/RELEASE-1_6_1/jabberd/jabberd.h	Fri Sep 26 13:46:18 2008	(r1540)
@@ -211,6 +211,7 @@
 instance deliver_hostcheck(char *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
 std::set<std::string> deliver_routed_hosts(ptype type, instance i);
+void deliver_config_filter(xmlnode greymatter);
 
 /*** global logging/signal symbols ***/
 #define LOGT_LEGACY 1

Modified: branches/RELEASE-1_6_1/jabberd/lib/jabberdlib.h
==============================================================================
--- branches/RELEASE-1_6_1/jabberd/lib/jabberdlib.h	Wed Sep 10 02:35:57 2008	(r1539)
+++ branches/RELEASE-1_6_1/jabberd/lib/jabberdlib.h	Fri Sep 26 13:46:18 2008	(r1540)
@@ -963,6 +963,7 @@
 #define NS_JABBERD_XDBSQL "http://jabberd.org/ns/xdbsql"		/**< namespace for substitution in xdb_sql configuration */
 #define NS_JABBERD_ACL "http://jabberd.org/ns/acl"			/**< namespace for access control lists */
 #define NS_JABBERD_LOOPCHECK "http://jabberd.org/ns/loopcheck"		/**< namespace for loopchecking of s2s connections */
+#define NS_JABBERD_ERRMSG "http://jabberd.org/ns/errmsg"		/**< namespace for session control error messages */
 
 #define NS_SESSION "http://jabberd.jabberstudio.org/ns/session/1.0"	/**< namespace of the jabberd2 session control protocol (http://jabberd.jabberstudio.org/dev/docs/session.shtml) */
 


More information about the dev mailing list