[xmppd-dev] commit r1525 - in trunk/jabberd14: . dnsrv jabberd jabberd/base jabberd/lib jsm

mail at jabberd.org mail at jabberd.org
Tue Apr 29 23:12:17 UTC 2008


Author: mawis
Date: Tue Apr 29 23:11:53 2008
New Revision: 1525

Log:
removing the xmlnode vattrib functions (which have been a very hacky thing)


Modified:
   trunk/jabberd14/ChangeLog
   trunk/jabberd14/configure.ac
   trunk/jabberd14/dnsrv/dnsrv.cc
   trunk/jabberd14/jabberd/base/base_load.cc
   trunk/jabberd14/jabberd/config.cc
   trunk/jabberd14/jabberd/jabberd.h
   trunk/jabberd14/jabberd/lib/jabberdlib.h
   trunk/jabberd14/jabberd/lib/jid.cc
   trunk/jabberd14/jabberd/lib/xmlnode.cc
   trunk/jabberd14/jsm/jsm.cc

Modified: trunk/jabberd14/ChangeLog
==============================================================================
--- trunk/jabberd14/ChangeLog	(original)
+++ trunk/jabberd14/ChangeLog	Tue Apr 29 23:11:53 2008
@@ -1,3 +1,14 @@
+2008-04-30  Matthias Wimmer  <m at tthias.eu>
+
+    * jabberd/jabberd.h: removing the xmlnode vattrib functions
+    * jabberd/config.cc: same
+    * jabberd/lib/xmlnode.cc: same
+    * jabberd/lib/jid.cc: same
+    * jabberd/lib/jabberdlib.h: same
+    * jabberd/base/base_load.cc: same
+    * jsm/jsm.cc: same
+    * dnsrv/dnsrv.cc: same
+
 2008-04-29  Matthias Wimmer  <m at tthias.eu>
 
     * jsm/serialization.cc: removing string spool functions, using

Modified: trunk/jabberd14/configure.ac
==============================================================================
--- trunk/jabberd14/configure.ac	(original)
+++ trunk/jabberd14/configure.ac	Tue Apr 29 23:11:53 2008
@@ -6,7 +6,7 @@
 
 
 AC_INIT(jabberd/jabberd.h)
-AM_INIT_AUTOMAKE(jabberd14,1.9.0-alpha-20080429)
+AM_INIT_AUTOMAKE(jabberd14,1.9.0-alpha-20080430)
 AM_CONFIG_HEADER(config.h)
 AC_LANG(C++)
 

Modified: trunk/jabberd14/dnsrv/dnsrv.cc
==============================================================================
--- trunk/jabberd14/dnsrv/dnsrv.cc	(original)
+++ trunk/jabberd14/dnsrv/dnsrv.cc	Tue Apr 29 23:11:53 2008
@@ -339,7 +339,14 @@
          /* if there's no IP, cached failed lookup, time those out 10 times faster! (weird, I know, *shrug*) */
          if ((ip = xmlnode_get_attrib_ns(c, "ip", NULL)) == NULL)
             timeout = timeout / 10;
-         if ((time(NULL) - *(time_t*)xmlnode_get_vattrib(c,"t")) > timeout) {
+
+	 char const* cache_time_str = xmlnode_get_attrib_ns(c, "t", NULL);
+	 time_t cache_time = 0;
+	 if (cache_time_str) {
+	     std::istringstream cache_time_stream(cache_time_str);
+	     cache_time_stream >> cache_time;
+	 }
+         if (std::time(NULL) - cache_time > timeout) {
 	     /* timed out of the cache, lookup again */
              xhash_zap(di->cache_table,p->host);
              xmlnode_free(c);
@@ -370,9 +377,11 @@
 
 	/* whatever the response was, let's cache it */
 	xmlnode_free((xmlnode)xhash_get(di->cache_table,hostname)); /* free any old cache, shouldn't ever be any */
-	ttmp = static_cast<time_t*>(pmalloc(xmlnode_pool(x),sizeof(time_t)));
-	time(ttmp);
-	xmlnode_put_vattrib(x,"t",(void*)ttmp);
+
+	std::ostringstream now;
+	now << std::time(NULL);
+
+	xmlnode_put_attrib(x,"t", now.str().c_str());
 	xhash_put(di->cache_table,hostname,(void*)x);
 
 	/* Get the hostname and look it up in the hashtable */

Modified: trunk/jabberd14/jabberd/base/base_load.cc
==============================================================================
--- trunk/jabberd14/jabberd/base/base_load.cc	(original)
+++ trunk/jabberd14/jabberd/base/base_load.cc	Tue Apr 29 23:11:53 2008
@@ -37,7 +37,8 @@
 /* IN-PROCESS component loader */
 
 typedef void (*base_load_init)(instance id, xmlnode x);	/**< prototype for the initialization function of a component */
-xmlnode base_load__cache = NULL;				/**< hacky: xml document containing loaded shared objects as attributes */
+std::map<std::string, void*> base_load__cache;		/**< map pointing from file names of shared objects to their loaded instances */
+std::map<std::string, std::map<std::string, void*> > preloaded_functions; /**< module init functions that have been loaded and not assigned to the instance */
 int base_load_ref__count = 0;				/**< counts loaded components. triggers shutdown if all components are unloaded */
 
 /* use dynamic dlopen/dlsym stuff here! */
@@ -54,6 +55,10 @@
     const char *dlerr;
     char message[MAX_LOG_SIZE];
 
+    // sanity check
+    if (!file)
+	return NULL;
+
     /* load the dso */
     so_h = dlopen(file,RTLD_LAZY);
 
@@ -65,8 +70,8 @@
         return NULL;
     }
 
-    /* XXX do not use xmlnode_put_vattrib(), it's deprecated */
-    xmlnode_put_vattrib(base_load__cache, file, so_h); /* fun hack! yes, it's just a nice name-based void* array :) */
+    // store the loaded object
+    base_load__cache[file] = so_h;
     return so_h;
 }
 
@@ -87,8 +92,8 @@
     if (func == NULL || file == NULL)
         return NULL;
 
-    /* XXX do not use xmlnode_get_vattrib(), it's deprecated */
-    if ((so_h = xmlnode_get_vattrib(base_load__cache, file)) == NULL && (so_h = base_load_loader(file)) == NULL)
+    // load the module if not already loaded
+    if ((so_h = base_load__cache[file]) == NULL && (so_h = base_load_loader(file)) == NULL)
         return NULL;
 
     /* resolve a reference to the dso's init function */
@@ -127,9 +132,6 @@
     base_load_ref__count--;
     if (base_load_ref__count != 0)
         return;
-
-    xmlnode_free(base_load__cache);
-    base_load__cache = NULL;
 }
 
 /**
@@ -144,16 +146,26 @@
     xmlnode so;
     char *init = xmlnode_get_attrib_ns(x, "main", NULL);
     void *f;
-    int flag = 0;
+    char const* instance_id = xmlnode_get_attrib_ns(xmlnode_get_parent(x), "id", NULL);
+    bool something_loaded = false;
 
-    if (base_load__cache == NULL)
-        base_load__cache = xmlnode_new_tag_ns("so_cache", NULL, NS_JABBERD_WRAPPER);
+    if (!instance_id) {
+	log_debug2(ZONE, LOGT_CONFIG, "instance does not have an id");
+	return r_ERR;
+    }
 
     if (id != NULL) {
 	/* execution phase */
+
+	// copy preloaded_functions for this module to the instance
+	for (std::map<std::string, void*>::iterator p = preloaded_functions[instance_id].begin(); p != preloaded_functions[instance_id].end(); ++p) {
+	    (*id->module_init_funcs)[p->first] = p->second;
+	}
+
+	// load main function of the instance implementation
         base_load_ref__count++;
         pool_cleanup(id->p, base_load_shutdown, NULL);
-        f = xmlnode_get_vattrib(x, init);		/* XXX xmlnode_get_vattrib() is deprecated! */
+	f = (*id->module_init_funcs)[init];
         ((base_load_init)f)(id, x); /* fire up the main function for this extension */
         return r_PASS;
     }
@@ -164,22 +176,22 @@
     for (so = xmlnode_get_firstchild(x); so != NULL; so = xmlnode_get_nextsibling(so)) {
         if (xmlnode_get_type(so) != NTYPE_TAG) continue;
 
-        if (init == NULL && flag)
+        if (init == NULL && something_loaded)
             return r_ERR; /* you can't have two elements in a load w/o a main attrib */
 
         f = base_load_symbol(xmlnode_get_localname(so), xmlnode_get_data(so));
         if (f == NULL)
             return r_ERR;
 	/* XXX do not use xmlnode_put_vattrib(), it's deprecated */
-        xmlnode_put_vattrib(x, xmlnode_get_localname(so), f); /* hide the function pointer in the <load> element for later use */
-        flag = 1;
+	preloaded_functions[instance_id][xmlnode_get_localname(so)] = f; // remember module init functions to run
+	something_loaded = true;
 
         /* if there's only one .so loaded, it's the default, unless overridden */
         if (init == NULL)
             xmlnode_put_attrib_ns(x, "main", NULL, NULL, xmlnode_get_localname(so));
     }
 
-    if (!flag)
+    if (!something_loaded)
 	return r_ERR; /* we didn't DO anything, duh */
 
     return r_PASS;

Modified: trunk/jabberd14/jabberd/config.cc
==============================================================================
--- trunk/jabberd14/jabberd/config.cc	(original)
+++ trunk/jabberd14/jabberd/config.cc	Tue Apr 29 23:11:53 2008
@@ -438,6 +438,16 @@
 void instance_shutdown(instance i);
 
 /**
+ * pool_cleaner that deletes the module_init_funcs map of an instance
+ *
+ * @param arg pointer to the module_init_funcs map, that has to be deleted
+ */
+static void instance_cleanup_module_init_funcs(void *arg) {
+    std::map<std::string, void*>* module_init_funcs = static_cast<std::map<std::string, void*>*>(arg);
+    delete module_init_funcs;
+}
+
+/**
  * handle a second-level configuration file element (beside the &lt;base/&gt; element)
  *
  * @param x the configuration element to be handled
@@ -501,6 +511,8 @@
         newi->type = type;
         newi->p = p;
         newi->x = x;
+	newi->module_init_funcs = new std::map<std::string, void*>();
+	pool_cleanup(newi->p, instance_cleanup_module_init_funcs, newi->module_init_funcs);
         /* make sure the id is valid for a hostname */
         temp = jid_new(p, newi->id);
         if (temp == NULL || j_strcmp(temp->get_domain().c_str(), newi->id) != 0) {

Modified: trunk/jabberd14/jabberd/jabberd.h
==============================================================================
--- trunk/jabberd14/jabberd/jabberd.h	(original)
+++ trunk/jabberd14/jabberd/jabberd.h	Tue Apr 29 23:11:53 2008
@@ -184,6 +184,7 @@
     ptype type; /**< the type of the instance (xdb/log/service) */
     handel hds; /**< delivery handler */
     register_notifier routing_update_callbacks; /**< list of callback functions, that should be called on a routing update */
+    std::map<std::string, void*>* module_init_funcs;	/**< map with the modules of this instance, key is name, value is init function */
 };
 
 /** Config file handler function callback definition */

Modified: trunk/jabberd14/jabberd/lib/jabberdlib.h
==============================================================================
--- trunk/jabberd14/jabberd/lib/jabberdlib.h	(original)
+++ trunk/jabberd14/jabberd/lib/jabberdlib.h	Tue Apr 29 23:11:53 2008
@@ -678,10 +678,6 @@
 
 const char* xmlnode_get_lang(xmlnode node);
 
-/* Bastard am I, but these are fun for internal use ;-) */
-void     xmlnode_put_vattrib(xmlnode owner, const char* name, void *value);
-void*    xmlnode_get_vattrib(xmlnode owner, const char* name);
-
 /* Node traversal routines */
 xmlnode  xmlnode_get_firstattrib(xmlnode parent);
 xmlnode  xmlnode_get_firstchild(xmlnode parent);

Modified: trunk/jabberd14/jabberd/lib/jid.cc
==============================================================================
--- trunk/jabberd14/jabberd/lib/jid.cc	(original)
+++ trunk/jabberd14/jabberd/lib/jid.cc	Tue Apr 29 23:11:53 2008
@@ -1,7 +1,7 @@
 /*
  * Copyrights
  * 
- * Portions Copyright (c) 2008 Matthias Wimmer
+ * Copyright (c) 2008 Matthias Wimmer
  *
  * This file is part of jabberd14.
  *

Modified: trunk/jabberd14/jabberd/lib/xmlnode.cc
==============================================================================
--- trunk/jabberd14/jabberd/lib/xmlnode.cc	(original)
+++ trunk/jabberd14/jabberd/lib/xmlnode.cc	Tue Apr 29 23:11:53 2008
@@ -1163,49 +1163,6 @@
 }
 
 /**
- * very hacky: place a pointer to arbitrary data as the value of an attribute
- *
- * @deprecated Do not use it. It's just a big hack. Probably you could use a ::xhash for the same things.
- *
- * @param owner element where to place the attribute
- * @param name name of the attribute
- * @param value the pointer, that should be stored as the value of the attribute
- */
-void xmlnode_put_vattrib(xmlnode owner, const char* name, void *value) {
-    xmlnode attrib;
-
-    if (owner != NULL) {
-	attrib = _xmlnode_search(owner->firstattrib, name, NULL, NTYPE_ATTRIB);
-	if (attrib == NULL) {
-	    xmlnode_put_attrib_ns(owner, name, NULL, NULL, "");
-	    attrib = _xmlnode_search(owner->firstattrib, name, NULL, NTYPE_ATTRIB);
-	}
-	if (attrib != NULL)
-	    attrib->firstchild = (xmlnode)value;
-    }
-}
-
-/**
- * very hacky: retrieve the pointer to arbitrary data, that has been stored as an attribute using the xmlnode_put_vattrib() function
- *
- * @deprecated Do not use it. It's just a big hack. Probably you could use a ::xhash for the same things.
- *
- * @param owner where to get the attribute for
- * @param name name of the attribute
- * @return pointer to the value
- */
-void* xmlnode_get_vattrib(xmlnode owner, const char* name) {
-    xmlnode attrib;
-
-    if (owner != NULL && owner->firstattrib != NULL) {
-	attrib = _xmlnode_search(owner->firstattrib, name, NULL, NTYPE_ATTRIB);
-	if (attrib != NULL)
-	    return (void*)attrib->firstchild;
-    }
-    return NULL;
-}
-
-/**
  * get the first attribute node of an element
  *
  * iteration on all attributes is possible by using xmlnode_get_nextsibling() using the result of this function as the start

Modified: trunk/jabberd14/jsm/jsm.cc
==============================================================================
--- trunk/jabberd14/jsm/jsm.cc	(original)
+++ trunk/jabberd14/jsm/jsm.cc	Tue Apr 29 23:11:53 2008
@@ -242,18 +242,19 @@
     }
 
     /* fire up the modules by scanning the attribs on the xml we received */
-    for (cur = xmlnode_get_firstattrib(x); cur != NULL; cur = xmlnode_get_nextsibling(cur)) {
-        /* avoid multiple personality complex */
-        if (j_strcmp(xmlnode_get_localname(cur), "jsm") == 0)
-            continue;
-
-        /* vattrib is stored as firstchild on an attrib node */
-        if ((module = (modcall)xmlnode_get_firstchild(cur)) == NULL)
-            continue;
-
-        /* call this module for this session instance */
-        log_debug2(ZONE, LOGT_INIT, "jsm: loading module %s", xmlnode_get_localname(cur));
-        (module)(si);
+    for (std::map<std::string, void*>::iterator iter = i->module_init_funcs->begin(); iter != i->module_init_funcs->end(); ++iter) {
+	// do not run our main init method again!
+	if (iter->first == "jsm")
+	    continue;
+
+	// get the init function reference
+	module = reinterpret_cast<modcall>(iter->second);
+	if (!module)
+	    continue;
+
+	// call the module init function
+	log_debug2(ZONE, LOGT_INIT, "jsm: loading module %s", iter->first.c_str());
+	(module)(si);
     }
 
     /* register us for being notified of the server shutdown */


More information about the dev mailing list