myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [2938] added version and dependences control in plugin


From: Daniele Perrone
Subject: [myserver-commit] [2938] added version and dependences control in plugin manager
Date: Thu, 06 Nov 2008 20:44:14 +0000

Revision: 2938
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2938
Author:   dperrone
Date:     2008-11-06 20:44:14 +0000 (Thu, 06 Nov 2008)

Log Message:
-----------
added version and dependences control in plugin manager

Modified Paths:
--------------
    trunk/myserver/include/plugin/Makefile.am
    trunk/myserver/include/plugin/plugin.h
    trunk/myserver/include/plugin/plugins_manager.h
    trunk/myserver/src/plugin/Makefile.am
    trunk/myserver/src/plugin/plugin.cpp
    trunk/myserver/src/plugin/plugins_manager.cpp
    trunk/myserver/tests/Makefile.am

Added Paths:
-----------
    trunk/myserver/include/plugin/plugin_info.h
    trunk/myserver/src/plugin/plugin_info.cpp
    trunk/myserver/tests/test_plugin_info.cpp

Modified: trunk/myserver/include/plugin/Makefile.am
===================================================================
--- trunk/myserver/include/plugin/Makefile.am   2008-11-06 20:42:00 UTC (rev 
2937)
+++ trunk/myserver/include/plugin/Makefile.am   2008-11-06 20:44:14 UTC (rev 
2938)
@@ -1,4 +1,4 @@
 pluginincludedir=$(includedir)/myserver/include/plugin
-plugininclude_HEADERS =  plugin.h plugins_manager.h 
+plugininclude_HEADERS =  plugin.h plugin_info.h plugins_manager.h 
 
 

Modified: trunk/myserver/include/plugin/plugin.h
===================================================================
--- trunk/myserver/include/plugin/plugin.h      2008-11-06 20:42:00 UTC (rev 
2937)
+++ trunk/myserver/include/plugin/plugin.h      2008-11-06 20:44:14 UTC (rev 
2938)
@@ -32,32 +32,6 @@
 class Plugin
 {
 public:
-       static int getVersionNumber(int version)
-       {
-               return (version >> 24) & 0xFF;
-       }
-
-       static int getVersionMinor(int version)
-       {
-               return (version >> 16) & 0xFF;
-       }
-
-       static int getVersionRevision(int version)
-       {
-               return (version >> 8) & 0xFF;
-       }
-
-       static int getVersionStatus(int version)
-       {
-               return version & 0xFF;
-       }
-
-       static int createVersion(int v = 1, int x = 0, int y = 0, int z = 0)
-       {
-               return ((v & 0xFF) << 24) | ((x & 0xFF) << 16) | 
-                       ((y & 0xFF) << 8) | (z & 0xFF);
-       }
-
        Plugin();
        virtual ~Plugin();
        virtual int load(string& file, Server* server, XmlParser* languageFile);
@@ -65,18 +39,10 @@
        virtual int postLoad(Server* server, XmlParser* languageFile);
        virtual int unLoad(XmlParser* languageFile);
        virtual const char* getName(char* buffer, u_long len);
-       virtual int getVersion();
        virtual void* getDirectMethod(char* name);
 protected:
        DynamicLibrary hinstLib;
-private:
-       /*! A number in the form v.x.y.z where:
-        * v is the version major number.
-        * x is the version minor number.
-        * y is the version revision number.
-        * z is the version status number.
-        */
-       int version;
+
 };
 
 #endif

Added: trunk/myserver/include/plugin/plugin_info.h
===================================================================
--- trunk/myserver/include/plugin/plugin_info.h                         (rev 0)
+++ trunk/myserver/include/plugin/plugin_info.h 2008-11-06 20:44:14 UTC (rev 
2938)
@@ -0,0 +1,91 @@
+/* -*- mode: c++ -*- */
+/*
+MyServer
+Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef PLUGIN_INFO_H
+#define PLUGIN_INFO_H
+
+#include "stdafx.h"
+#include <include/base/hash_map/hash_map.h>
+#include <string>
+#include <utility>
+#include <include/plugin/plugin.h>
+#include <include/base/regex/myserver_regex.h>
+
+
+using namespace std;
+
+class Server;
+class XmlParser;
+
+class PluginInfo
+{
+public:
+
+    PluginInfo(string& name, bool enabled = 1, bool global = 0);
+       PluginInfo(string& name, bool enabled, bool global, int version, int 
msMinVersion, int msMaxVersion);
+       
+       ~PluginInfo();
+       
+       bool isEnabled();
+       bool isGlobal();
+       
+       void addDependence(string, int minVersion, int maxVersion);
+       
+       int getVersion();
+       
+       void setVersion(int v);
+       
+       string getName();
+       
+       int getMyServerMinVersion();
+       
+       int getMyServerMaxVersion();
+       
+       int setMyServerMinVersion(int v);
+       
+       int setMyServerMaxVersion(int v);
+       
+       HashMap<string, pair<int,int>* >::Iterator begin(){return 
dependences.begin();}
+       HashMap<string, pair<int,int>* > ::Iterator end(){return 
dependences.end();}
+       
+       void attachPlugin(Plugin* plugin);
+       
+       Plugin* getPlugin();
+       
+       void detachPlugin();
+       
+       
+       static int convertVersion(string* s);
+       
+       
+       
+  
+       
+private:       
+       string name;
+       bool enabled;
+    bool global;
+    int version;
+    int msMinVersion;
+    int msMaxVersion;
+    HashMap<string, pair<int,int>* > dependences;
+    Plugin* plugin;
+    static Regex* regex;
+};
+
+#endif


Property changes on: trunk/myserver/include/plugin/plugin_info.h
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/myserver/include/plugin/plugins_manager.h
===================================================================
--- trunk/myserver/include/plugin/plugins_manager.h     2008-11-06 20:42:00 UTC 
(rev 2937)
+++ trunk/myserver/include/plugin/plugins_manager.h     2008-11-06 20:44:14 UTC 
(rev 2938)
@@ -21,6 +21,7 @@
 
 #include "stdafx.h"
 #include <include/plugin/plugin.h>
+#include <include/plugin/plugin_info.h>
 #include <include/base/dynamic_lib/dynamiclib.h>
 #include <include/base/hash_map/hash_map.h>
 #include <string>
@@ -32,17 +33,6 @@
 class PluginsManager
 {
 public:
-
-       struct PluginOption
-       {
-               PluginOption(PluginOption& po){enabled = po.enabled; global = 
po.global;}
-               PluginOption(){enabled = true; global = false;}
-               bool enabled;
-       bool global;
-       };
-       
-       
-       
        HashMap<string, Plugin*>::Iterator begin(){return plugins.begin();}
        HashMap<string, Plugin*>::Iterator end(){return plugins.end();}
        
@@ -55,8 +45,8 @@
 
        virtual void removePlugin(string& name);
 
-       virtual int addPluginOption(string&, PluginOption&);
-       virtual PluginOption* getPluginOption(string&);
+       virtual int addPluginInfo(string&, PluginInfo*);
+       virtual PluginInfo* getPluginInfo(string&);
        
        virtual Plugin* createPluginObject();
        
@@ -64,11 +54,13 @@
        ~PluginsManager();
        
 private:
-       HashMap<string, PluginOption*> pluginsOptions;
+       HashMap<string, PluginInfo*> pluginsInfos;
        HashMap<string, Plugin*> plugins;
        int loadOptions(Server *server, XmlParser* languageFile);
        int addPlugin(string& file, Server* server, 
                 XmlParser* languageFile, bool global);
+                
+    int loadInfo(string& name, string& path);
 };
 
 #endif

Modified: trunk/myserver/src/plugin/Makefile.am
===================================================================
--- trunk/myserver/src/plugin/Makefile.am       2008-11-06 20:42:00 UTC (rev 
2937)
+++ trunk/myserver/src/plugin/Makefile.am       2008-11-06 20:44:14 UTC (rev 
2938)
@@ -1,4 +1,4 @@
 lib_LIBRARIES = libplugin.a
-libplugin_a_SOURCES =  plugin.cpp plugins_manager.cpp 
+libplugin_a_SOURCES =  plugin.cpp plugin_info.cpp plugins_manager.cpp 
 INCLUDES = $(all_includes)
 

Modified: trunk/myserver/src/plugin/plugin.cpp
===================================================================
--- trunk/myserver/src/plugin/plugin.cpp        2008-11-06 20:42:00 UTC (rev 
2937)
+++ trunk/myserver/src/plugin/plugin.cpp        2008-11-06 20:44:14 UTC (rev 
2938)
@@ -31,7 +31,7 @@
  */
 Plugin::Plugin()
 {
-  version = 1;
+       
 }
 
 /*!
@@ -109,21 +109,9 @@
   return 0;
 }
 
-/*!
- *Get the version number for this plugin.
- */
-int Plugin::getVersion()
-{
-  if(hinstLib.validHandle())
-  {
-    versionPROC proc = (versionPROC)hinstLib.getProc("version"); 
-    if(proc)
-      return proc();
-    return 1;
-  }
-  return 0;
-}
 
+
+
 /*!
  *Get the plugin name.
  *\param buffer The buffer where write the plugin name.

Added: trunk/myserver/src/plugin/plugin_info.cpp
===================================================================
--- trunk/myserver/src/plugin/plugin_info.cpp                           (rev 0)
+++ trunk/myserver/src/plugin/plugin_info.cpp   2008-11-06 20:44:14 UTC (rev 
2938)
@@ -0,0 +1,239 @@
+/*
+MyServer
+Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <include/plugin/plugin_info.h>
+
+
+using namespace std;
+
+/*!
+ *Construct a plugin info object.
+ *\param name plugin name.
+ *\param enabled is true if the plugin has to be enabled. 
+ *\param global is true if the plugin's symbols have to be loaded globally.
+ */
+PluginInfo::PluginInfo(string& name, bool enabled, bool global)
+{
+  PluginInfo(name,enabled,global,0,0,0);
+}
+
+/*!
+ *Construct a plugin info object.
+ *\param name plugin name.
+ *\param enabled is true if the plugin has to be enabled. 
+ *\param global is true if the plugin's symbols have to be loaded globally.
+ *\param version the version of the plugin, in the format: a.b.c.d where a = 
version >> 24, b = (version >> 16) & 255, c = (version >> 8) & 255, d = version 
& 255.
+ *\param msMinVersion is the minimum MyServer version plugin is compatible. 
+ *\param msMaxVersion is the maximum MyServer version plugin is compatible. 
+ */
+PluginInfo::PluginInfo(string& name, bool enabled, bool global, int version, 
int msMinVersion, int msMaxVersion)
+{
+  this->name = name;   
+  this->enabled = enabled;
+  this->global = global;
+  this->version = version;
+  this->msMinVersion = msMinVersion;
+  this->msMaxVersion = msMaxVersion;
+  this->plugin = NULL;
+}
+
+
+/*!
+ *Destroy the object.
+*/     
+PluginInfo::~PluginInfo()
+{
+       detachPlugin();
+}
+
+/*!
+ *Returns true if the plugin is enabled.
+*/             
+bool PluginInfo::isEnabled()
+{
+  return this->enabled;        
+}
+
+/*!
+ *Returns true if the plugin is loaded globally.
+*/
+bool PluginInfo::isGlobal()
+{
+  return this->global; 
+}
+       
+/*!
+ * Adds a dependece to the plugin.
+ *\param name plugin name
+*/
+void PluginInfo::addDependence(string name, int minVersion, int maxVersion)
+{      
+  dependences.put(name, new pair<int,int>(minVersion,maxVersion));
+}
+       
+/*!
+ * Returns the plugin version.
+*/
+int PluginInfo::getVersion()
+{
+  return this->version;
+}
+
+/*!
+ * Sets the plugin version.
+*/
+void PluginInfo::setVersion(int v)
+{
+  this->version = v;
+}
+
+/*!
+ * Returns the minimum MyServer version plugin is compatible.
+*/
+int PluginInfo::getMyServerMinVersion()
+{
+  return this->msMinVersion;
+}
+       
+
+/*!
+ * Returns the maximum MyServer version plugin is compatible.
+*/
+int PluginInfo::getMyServerMaxVersion()
+{
+  return this->msMaxVersion;
+}
+
+
+/*!
+ * Sets the minimum MyServer version plugin is compatible.
+*/
+int PluginInfo::setMyServerMinVersion(int v)
+{
+  this->msMinVersion = v;
+}
+       
+/*!
+ * Sets the maximum MyServer version plugin is compatible.
+*/
+int PluginInfo::setMyServerMaxVersion(int v)
+{
+  this->msMaxVersion = v;
+}
+
+/*!
+ * Returns the plugin name
+*/
+string PluginInfo::getName()
+{
+  return this->name;
+}
+
+/*!
+ * Attaches the corrispondent Plugin object.
+*/
+void PluginInfo::attachPlugin(Plugin* plugin)
+{
+       this->plugin = plugin;
+}
+
+
+/*!
+ * Returns the attached plugin object.
+*/
+Plugin* PluginInfo::getPlugin()
+{
+  return this->plugin;
+}
+       
+/*!
+ * Detaches the Plugin object.
+*/
+void PluginInfo::detachPlugin()
+{
+  if (this->plugin!=NULL)
+  {
+       delete(this->plugin);
+    this->plugin = NULL;
+  }
+}
+
+
+
+Regex* PluginInfo::regex = new 
Regex("^[1-2]?[1-9]?[0-9](\\.[1-2]?[0-9]?[0-9](\\.[1-2]?[0-9]?[0-9](\\.[1-2]?[0-9]?[0-9])?)?)?$",REG_EXTENDED
 | REG_NOSUB);
+
+/*!
+ * Converts a string in the format "a.b.c.d" in an int in the format abcd 
where each number takes 8 bit.
+*/
+int PluginInfo::convertVersion(string* s)
+{
+       
+  int ret = regex->exec(s->c_str(),0,NULL,0);
+
+  if (ret!=0)
+    return -1; 
+       
+  string::size_type pos = s->find(".",0);
+  if (pos == string::npos)
+    return atoi(s->c_str()) << 24;
+    
+  int n1 = 0;
+  int n2 = 0;
+  int n3 = 0;
+  int n4 = 0;
+  
+  string sa = s->substr(0,pos);
+  n1 = atoi(sa.c_str());
+  if (n1>255)
+    return -1;
+
+  string::size_type oldpos = pos;
+  
+  
+  if (oldpos!=string::npos)
+  {
+       pos = s->find(".",oldpos+1);
+       string sa = s->substr(oldpos+1,pos - oldpos);
+    n2 = atoi(sa.c_str());
+    if (n2>255)
+      return -1;
+  }
+  
+  
+  oldpos = pos;
+  if (oldpos!=string::npos)
+  {
+       pos = s->find(".",oldpos+1);
+       string sa = s->substr(oldpos+1,pos - oldpos);
+    n3 = atoi(sa.c_str());
+    if (n3>255)
+      return -1;
+  }
+  
+  
+  oldpos = pos;
+  if (oldpos!=string::npos)
+  {
+       pos = s->find(".",oldpos+1);
+       string sa = s->substr(oldpos+1,pos - oldpos);
+    n4 = atoi(sa.c_str());
+    if (n4>255)
+      return -1;
+  }
+
+  return (n1<<24) + (n2<<16) + (n3<<8) + n4;
+}
\ No newline at end of file


Property changes on: trunk/myserver/src/plugin/plugin_info.cpp
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/myserver/src/plugin/plugins_manager.cpp
===================================================================
--- trunk/myserver/src/plugin/plugins_manager.cpp       2008-11-06 20:42:00 UTC 
(rev 2937)
+++ trunk/myserver/src/plugin/plugins_manager.cpp       2008-11-06 20:44:14 UTC 
(rev 2938)
@@ -72,7 +72,8 @@
         {
           string namespaceName;
           string pluginName;
-          PluginsManager::PluginOption po;
+                 bool global = false;
+                 bool enabled = false;
           
           if(!xmlStrcmp(node->name, (const xmlChar *)"PLUGIN"))
           {
@@ -91,9 +92,9 @@
             for(xmlNode *internal = node->children; internal; internal = 
internal->next)  
             {
               if(!xmlStrcmp(internal->name, (const xmlChar *)"ENABLED"))
-                po.enabled = strcmpi("NO", (const 
char*)internal->children->content) ? true : false;
+                enabled = strcmpi("NO", (const 
char*)internal->children->content) ? true : false;
               else if(!xmlStrcmp(internal->name, (const xmlChar *)"GLOBAL"))
-                po.global = strcmpi("YES", (const 
char*)internal->children->content) ? false : true;
+                global = strcmpi("YES", (const 
char*)internal->children->content) ? false : true;
             }
 
             if(!pluginName.length())
@@ -105,7 +106,7 @@
             }
             else
             {
-                addPluginOption(pluginName, po);
+                addPluginInfo(pluginName, new 
PluginInfo(pluginName,enabled,global));
             }
 
           }
@@ -166,17 +167,17 @@
        do
        {
          string name(flib.name);
-      PluginsManager::PluginOption *po;
       if(flib.name[0]=='.')
        continue;
+
           /*!
      *Do not consider file other than dynamic libraries.
      */
 #ifdef WIN32
-      if(!strstr(flib.name,".dll"))
+      if(!strstr(flib.name,".dll") && !strstr(flib.name,"plugin.xml"))
 #endif
 #ifdef NOT_WIN
-      if(!strstr(flib.name,".so"))
+      if(!strstr(flib.name,".so") && !strstr(flib.name,"plugin.xml"))
 #endif    
         continue;
       completeFileName.assign(filename);
@@ -189,17 +190,23 @@
         completeFileName.append("/");
       completeFileName.append(flib.name);
 
+         if(strstr(flib.name,"plugin.xml"))
+         {
+               string pname(fdir.name);
+        ret |= loadInfo(pname, completeFileName);
+        continue;
+         }
 #ifdef WIN32
       name = name.substr(0, name.length() - 4);
 #endif
 #ifdef NOT_WIN
       name = name.substr(0, name.length() - 3);
 #endif
-      po = getPluginOption(name);
-    
-       if(!po || po->enabled)
-         ret |= addPlugin(completeFileName, server, languageFile, po && 
po->global);
-
+      PluginInfo* pinfo = getPluginInfo(name);
+       
+       if(!pinfo || pinfo->isEnabled())
+         ret |= addPlugin(completeFileName, server, languageFile, pinfo && 
pinfo->isGlobal());
+          
      }while(!flib.findnext());
    }while(!fdir.findnext());
   fdir.findclose();
@@ -216,6 +223,100 @@
 }
 
 /*!
+ *Loads the plugin info.
+ *\param name The plugin name.
+ *\param path the plugin xml descriptor path.
+ */
+int PluginsManager::loadInfo(string& name, string& path)
+{
+  PluginInfo* pinfo;
+  
+  pinfo = getPluginInfo(name);
+  if (!pinfo)
+    pinfo = new PluginInfo(name);
+    
+  XmlParser xml;
+  
+  if (xml.open(path,true))
+    return 1;
+  
+  XmlXPathResult* xpathRes = xml.evaluateXpath("/PLUGIN");
+  
+  xmlNodeSetPtr nodes = xpathRes->getNodeSet();
+  
+  int size = (nodes) ? nodes->nodeNr : 0;
+  
+  if (size!=1)
+    return 1;
+  
+  const char* mSMinVersion = (const char*)xmlGetProp(nodes->nodeTab[0],(const 
xmlChar*)"min-version");
+  
+  const char* mSMaxVersion = (const char*)xmlGetProp(nodes->nodeTab[0],(const 
xmlChar*)"max-version");
+  
+  pinfo->setMyServerMinVersion(PluginInfo::convertVersion(new 
string(mSMinVersion)));
+  pinfo->setMyServerMaxVersion(PluginInfo::convertVersion(new 
string(mSMaxVersion)));
+  
+  delete xpathRes;
+  
+  xpathRes = xml.evaluateXpath("/PLUGIN/NAME/text()");
+  nodes = xpathRes->getNodeSet();
+  size = (nodes) ? nodes->nodeNr : 0;
+  
+  
+  if (size!=1)
+    return 1;
+  const char* cname = (const char*)nodes->nodeTab[0]->content;
+
+  
+  if (strcmp(name.c_str(),cname))
+    return 1;
+  
+  delete xpathRes;
+  
+  xpathRes = xml.evaluateXpath("/PLUGIN/VERSION/text()");
+  nodes = xpathRes->getNodeSet();
+  size = (nodes) ? nodes->nodeNr : 0;
+  
+  
+  
+  if (size!=1)
+    return 1;
+  const char* version = (const char*)nodes->nodeTab[0]->content;
+  
+  
+  
+  pinfo->setVersion(PluginInfo::convertVersion(new string(version)));
+  
+  
+  delete xpathRes;
+  
+  xpathRes = xml.evaluateXpath("/PLUGIN/DEPENDS");
+  nodes = xpathRes->getNodeSet();
+  size = (nodes) ? nodes->nodeNr : 0;
+  
+  
+  for (int i=0; i<size; i++)
+  {
+       const char* depends = (const char*)nodes->nodeTab[i]->children->content;
+       
+       string nameDep(depends);
+       
+       const char* minVersion = (const 
char*)xmlGetProp(nodes->nodeTab[i],(const xmlChar*)"min-version");
+    
+    const char* maxVersion = (const char*)xmlGetProp(nodes->nodeTab[i],(const 
xmlChar*)"max-version");
+    
+    pinfo->addDependence(nameDep, PluginInfo::convertVersion(new 
string(minVersion)),PluginInfo::convertVersion(new string(maxVersion)));
+  }
+
+  delete xpathRes;
+  
+  addPluginInfo(name,pinfo);
+  
+  
+  return 0;
+}
+
+/*!
  *Add a plugin.
  *\param file The plugin file name.
  *\param server The server object to use.
@@ -227,7 +328,7 @@
                                        XmlParser* languageFile, bool global)
 {
   Plugin *plugin = createPluginObject();
-  string logBuf;
+  
   string name;
   const char* namePtr;
 
@@ -248,12 +349,8 @@
     
   plugins.put(name, plugin);
 
-  logBuf.assign(languageFile->getValue("MSG_LOADED"));
-  logBuf.append(" ");
-  logBuf.append(file);
-  logBuf.append(" --> ");
-  logBuf.append(name);
-  server->logWriteln( logBuf.c_str() );
+  
+  
   return 0;
 }
 
@@ -267,12 +364,80 @@
 int PluginsManager::load(Server *server, XmlParser* languageFile, 
                          string& resource)
 {
+       
+  
+  list<string*> toRemove;
   HashMap<string, Plugin*>::Iterator it = plugins.begin();
   while(it != plugins.end())
   {
-    (*it)->load(resource, server, languageFile);
+       string logBuf;
+       
+       string name(it.getKey());
+       
+       
+       PluginInfo* pinfo = getPluginInfo(name);
+    
+    
+       HashMap<string, pair<int,int>* >::Iterator depIt = pinfo->begin();
+       bool goodVersions = true;
+
+       string msversion(MYSERVER_VERSION);
+       int i = msversion.find("-",0);
+       if (i!=string::npos)
+         msversion = msversion.substr(0,i); 
+       
+       int msVersion = PluginInfo::convertVersion(&msversion);
+       if (msVersion < pinfo->getMyServerMinVersion() || msVersion > 
pinfo->getMyServerMaxVersion())
+       {
+         logBuf.append("myserver version not compatible --> ");
+         goodVersions = false;
+       }
+       else
+         for (;depIt != pinfo->end(); depIt++)
+         {
+               string dname = depIt.getKey();
+               
+               PluginInfo* dep = getPluginInfo(dname);
+               
+               if (!dep)
+               {
+                 logBuf.append("missing dependence: ");
+                 logBuf.append(dname);
+                 logBuf.append(" --> ");
+                 logBuf.append(name);
+                 goodVersions = false;
+                 break;
+               }
+                 
+               if (dep->getVersion() < (*depIt)->first || dep->getVersion() > 
(*depIt)->second)
+               {
+                 logBuf.append("plugin version not compatible: ");
+                 logBuf.append(dname);
+                 logBuf.append(" --> ");
+                 logBuf.append(name);
+                 goodVersions = false;
+                 break;
+               }
+         }
+       
+       
+       if (goodVersions)
+       {
+         logBuf.assign(languageFile->getValue("MSG_LOADED"));
+         logBuf.append(" -plugin- ");
+      logBuf.append(name);
+      (*it)->load(resource, server, languageFile);
+       } 
+       else
+         toRemove.push_front(&name);
+       server->logWriteln( logBuf.c_str() );
     it++;
   }
+
+  list<string*>::iterator tRIt = toRemove.begin();
+  for (;tRIt != toRemove.end(); tRIt++)
+    removePlugin(**tRIt);
+  
   return 0;
   
 }
@@ -303,7 +468,7 @@
 int PluginsManager::unLoad(Server *server, XmlParser* languageFile)
 {
   HashMap<string, Plugin*>::Iterator it = plugins.begin();
-  HashMap<string, PluginOption*>::Iterator poit = pluginsOptions.begin();
+  HashMap<string, PluginInfo*>::Iterator poit = pluginsInfos.begin();
 
   while(it != plugins.end())
   {
@@ -312,14 +477,14 @@
     it++;
   }
 
-  while(poit != pluginsOptions.end())
+  while(poit != pluginsInfos.end())
   {
     delete *poit;
     poit++;
   }
 
   plugins.clear();
-  pluginsOptions.clear();
+  pluginsInfos.clear();
   return 0;
 }
 
@@ -337,13 +502,12 @@
  *\param plugin The plugin name.
  *\param po The options for the plugin.
  */
-int PluginsManager::addPluginOption(string& plugin, PluginOption& po)
+int PluginsManager::addPluginInfo(string& plugin, PluginInfo* pi)
 {
-  PluginOption* newPo = new PluginOption(po);
-  PluginOption* oldPo = pluginsOptions.put(plugin, newPo);
+  PluginInfo* oldPi = pluginsInfos.put(plugin, pi);
 
-  if(oldPo)
-    delete oldPo;
+  if(oldPi)
+    delete oldPi;
 
   return 0;
 }
@@ -352,7 +516,7 @@
  *Return a pluginOption.
  *\param name The plugin name.
  */
-PluginsManager::PluginOption* PluginsManager::getPluginOption(string& plugin)
+PluginInfo* PluginsManager::getPluginInfo(string& plugin)
 {
-  return pluginsOptions.get(plugin);
+  return pluginsInfos.get(plugin);
 }

Modified: trunk/myserver/tests/Makefile.am
===================================================================
--- trunk/myserver/tests/Makefile.am    2008-11-06 20:42:00 UTC (rev 2937)
+++ trunk/myserver/tests/Makefile.am    2008-11-06 20:44:14 UTC (rev 2938)
@@ -2,5 +2,5 @@
 #
 
 bin_PROGRAMS = tests_suite
-tests_suite_SOURCES = main.cpp test_connection.cpp test_ftp.cpp 
test_log_manager.cpp test_mime_manager.cpp test_mutex.cpp 
test_security_domain.cpp test_validator.cpp test_auth_domain.cpp 
test_connections_scheduler.cpp test_gzip.cpp test_log_stream_factory.cpp 
test_pipe.cpp test_security_manager.cpp test_validator_factory.cpp 
test_base64.cpp test_file_stream.cpp test_hashmap.cpp test_md5.cpp 
test_recursive_mutex.cpp test_semaphore.cpp test_xml.cpp 
test_cached_file_buffer.cpp test_file_stream_creator.cpp test_homedir.cpp 
test_mem_buff.cpp test_regex.cpp test_socket_stream_creator.cpp 
test_cached_file.cpp test_files_utility.cpp test_http_request.cpp 
test_http_req_security_domain.cpp test_mem_stream.cpp test_safetime.cpp 
test_thread.cpp test_cached_file_factory.cpp test_filter_chain.cpp 
test_http_response.cpp test_multicast.cpp test_security_cache.cpp 
test_security_token.cpp test_utility.cpp  test_xml_validator.cpp test_ip.cpp
+tests_suite_SOURCES = main.cpp test_connection.cpp test_ftp.cpp 
test_log_manager.cpp test_mime_manager.cpp test_mutex.cpp 
test_security_domain.cpp test_validator.cpp test_auth_domain.cpp 
test_connections_scheduler.cpp test_gzip.cpp test_log_stream_factory.cpp 
test_pipe.cpp test_security_manager.cpp test_validator_factory.cpp 
test_base64.cpp test_file_stream.cpp test_hashmap.cpp test_md5.cpp 
test_recursive_mutex.cpp test_semaphore.cpp test_xml.cpp 
test_cached_file_buffer.cpp test_file_stream_creator.cpp test_homedir.cpp 
test_mem_buff.cpp test_regex.cpp test_socket_stream_creator.cpp 
test_cached_file.cpp test_files_utility.cpp test_http_request.cpp 
test_http_req_security_domain.cpp test_mem_stream.cpp test_safetime.cpp 
test_thread.cpp test_cached_file_factory.cpp test_filter_chain.cpp 
test_http_response.cpp test_multicast.cpp test_security_cache.cpp 
test_security_token.cpp test_utility.cpp  test_xml_validator.cpp test_ip.cpp 
test_plugin_info.cpp
 tests_suite_LDADD = ../src/libmyserver.a $(CPPUNIT_LDFLAGS) $(PTHREAD_LIB) 
$(IDN_LIB) $(XNET_LIB) $(EVENT_LIB) $(DL_LIB) $(SSL_LIB) $(ZLIB_LIB) 
$(XML_LIBS) $(LDFLAGS)

Added: trunk/myserver/tests/test_plugin_info.cpp
===================================================================
--- trunk/myserver/tests/test_plugin_info.cpp                           (rev 0)
+++ trunk/myserver/tests/test_plugin_info.cpp   2008-11-06 20:44:14 UTC (rev 
2938)
@@ -0,0 +1,190 @@
+/*
+ MyServer
+ Copyright (C) 2008 Free Software Foundation, Inc.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+ 
+ This program is distributed in the hope that it will be useful, 
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ctype.h>
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <include/plugin/plugin_info.h>
+
+#include <string.h>
+
+#include <iostream>
+using namespace std;
+
+class TestPluginInfo : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( TestPluginInfo );
+  CPPUNIT_TEST( testIsNotEnabled );
+  CPPUNIT_TEST( testIsEnabled );
+  CPPUNIT_TEST( testIsNotGlobal );
+  CPPUNIT_TEST( testIsGlobal );
+  CPPUNIT_TEST( testGetVersion );
+  CPPUNIT_TEST( testGetMyServerMinVersion );
+  CPPUNIT_TEST( testGetMyServerMaxVersion );
+  CPPUNIT_TEST( testGetName );
+  CPPUNIT_TEST( testDependencies );
+  CPPUNIT_TEST( testGetNullPlugin );
+  CPPUNIT_TEST( testAddAndGetPlugin );
+  CPPUNIT_TEST( testDetachPlugin );
+  CPPUNIT_TEST( testVersionConversionStringInt );
+  CPPUNIT_TEST_SUITE_END();
+private:
+  PluginInfo* pluginfo;
+  
+public:
+  void setUp()
+  {
+       string name("test");
+       pluginfo = new PluginInfo(name,false,false,0,0,0);
+  }
+
+  void tearDown()
+  {
+       delete(pluginfo);
+  }
+
+  void testIsNotEnabled()
+  {
+       CPPUNIT_ASSERT(!pluginfo->isEnabled());
+  }
+  
+  void testIsEnabled()
+  {
+       delete(pluginfo);
+       string name("test");
+       pluginfo = new PluginInfo(name,true,false,0,0,0);
+       CPPUNIT_ASSERT(pluginfo->isEnabled());
+  }
+
+  void testIsNotGlobal()
+  {
+       CPPUNIT_ASSERT(!pluginfo->isGlobal());
+  }
+  
+  void testIsGlobal()
+  {
+       delete(pluginfo);
+       string name("test");
+       pluginfo = new PluginInfo(name,false,true,0,0,0);
+       CPPUNIT_ASSERT(pluginfo->isGlobal());
+  }
+  
+  void testGetVersion()
+  {
+       CPPUNIT_ASSERT_EQUAL(pluginfo->getVersion(),0);
+  }
+  
+  void testGetMyServerMinVersion()
+  {
+       CPPUNIT_ASSERT_EQUAL(pluginfo->getMyServerMinVersion(),0);
+  }
+  
+  void testGetMyServerMaxVersion()
+  {
+       CPPUNIT_ASSERT_EQUAL(pluginfo->getMyServerMaxVersion(),0);
+  }
+  
+  void testGetName()
+  {
+       CPPUNIT_ASSERT_EQUAL(pluginfo->getName().compare("test"),0);
+  }
+  
+  void testDependencies()
+  {
+       string test("test-dep");
+       pluginfo->addDependence(test ,0,1);
+       CPPUNIT_ASSERT_EQUAL( (*(pluginfo->begin()))->first , 0);
+       CPPUNIT_ASSERT_EQUAL( (*(pluginfo->begin()))->second , 1);
+       CPPUNIT_ASSERT_EQUAL( pluginfo->begin().getKey().compare("test-dep"),0);
+  }
+  
+  void testGetNullPlugin()
+  {
+       CPPUNIT_ASSERT( pluginfo->getPlugin()==NULL);
+  }
+  
+  void testAddAndGetPlugin()
+  {
+       pluginfo->attachPlugin(new Plugin());
+       CPPUNIT_ASSERT( pluginfo->getPlugin()!=NULL);
+  }
+  
+  void testDetachPlugin()
+  {
+       pluginfo->attachPlugin(new Plugin());
+       CPPUNIT_ASSERT( pluginfo->getPlugin()!=NULL);
+       pluginfo->detachPlugin();
+       CPPUNIT_ASSERT( pluginfo->getPlugin()==NULL);
+  }
+  
+  void testVersionConversionStringInt()
+  {
+       int v = PluginInfo::convertVersion(new string("1"));
+       CPPUNIT_ASSERT_EQUAL(1<<24,v);
+       
+       v = PluginInfo::convertVersion(new string("255"));
+       CPPUNIT_ASSERT_EQUAL(255<<24,v);
+       
+       v = PluginInfo::convertVersion(new string("1.2"));
+       CPPUNIT_ASSERT_EQUAL((1<<24) + (2<<16),v);
+       
+       v = PluginInfo::convertVersion(new string("1.2.3"));
+       CPPUNIT_ASSERT_EQUAL((1<<24) + (2<<16) + (3<<8),v);
+       
+       v = PluginInfo::convertVersion(new string("1.2.3.4"));
+       CPPUNIT_ASSERT_EQUAL((1<<24) + (2<<16) + (3<<8) + 4,v);
+       
+       v = PluginInfo::convertVersion(new string("1."));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("1.2."));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("1.2.3."));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("1.2.3.4."));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("1.2.3.4...."));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("......1.2.3.4"));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("1..2.3.4"));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("1.2...3.4"));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("1.2.3....4"));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("1.300.3.4"));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+       
+       v = PluginInfo::convertVersion(new string("1.3.299.4"));
+       CPPUNIT_ASSERT_EQUAL(-1,v);
+  }
+};
+
+
+CPPUNIT_TEST_SUITE_REGISTRATION( TestPluginInfo );






reply via email to

[Prev in Thread] Current Thread [Next in Thread]