myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [2913] Refactored plugin tree


From: Daniele Perrone
Subject: [myserver-commit] [2913] Refactored plugin tree
Date: Sun, 26 Oct 2008 19:37:38 +0000

Revision: 2913
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2913
Author:   dperrone
Date:     2008-10-26 19:37:37 +0000 (Sun, 26 Oct 2008)

Log Message:
-----------
Refactored plugin tree

Modified Paths:
--------------
    trunk/plugins/src/http_checker/SConscript
    trunk/plugins/src/http_checker/http_checker.cpp
    trunk/plugins/src/http_checker/plugin.xml
    trunk/plugins/src/php/SConscript
    trunk/plugins/src/php/php.cpp
    trunk/plugins/src/php/php.h
    trunk/plugins/src/php/plugin.xml
    trunk/plugins/src/python_http_handler/SConscript
    trunk/plugins/src/python_http_handler/plugin.xml
    trunk/plugins/src/python_http_handler/python_http_handler.cpp
    trunk/plugins/src/rules_checker/SConscript
    trunk/plugins/src/rules_checker/plugin.xml
    trunk/plugins/src/rules_checker/rules_checker.cpp

Added Paths:
-----------
    trunk/plugins/SConstruct
    trunk/plugins/bin/
    trunk/plugins/pub/
    trunk/plugins/src/
    trunk/plugins/src/http_checker/
    trunk/plugins/src/php/
    trunk/plugins/src/python/
    trunk/plugins/src/python/SConscript
    trunk/plugins/src/python/plugin.xml
    trunk/plugins/src/python/python.cpp
    trunk/plugins/src/python/python.h
    trunk/plugins/src/python_http_handler/
    trunk/plugins/src/python_http_handler/config.h
    trunk/plugins/src/rules_checker/
    trunk/plugins/src/rules_checker/string_alloc.os

Removed Paths:
-------------
    trunk/plugins/executors/
    trunk/plugins/generics/
    trunk/plugins/http_managers/

Added: trunk/plugins/SConstruct
===================================================================
--- trunk/plugins/SConstruct                            (rev 0)
+++ trunk/plugins/SConstruct    2008-10-26 19:37:37 UTC (rev 2913)
@@ -0,0 +1,127 @@
+#-*- mode: python -*-
+# MySever plugins configuration script for scons.
+#
+# MyServer
+# http://www.gnu.org/software/myserver/
+#
+# Copyright (C) 2002-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/>.
+
+import os
+import glob
+
+import xml.dom.minidom
+from xml.dom.minidom import Node
+
+import string
+
+def print_help():
+    print "usage: scons [package|release] 
plugin=<plugin1>,<plugin2>,...,<pluginN>"
+
+src_dir = "src/"
+bin_dir = "bin/"
+release_dir = "pub/"
+
+plugin = ARGUMENTS.get('plugin', "")
+command = ARGUMENTS.get('command', "build")
+
+
+if plugin=="":
+    print_help()
+    Exit(1)
+
+plugins = plugin.split(",");
+
+
+msheaders = ARGUMENTS.get('msheaders', "")
+
+listinc=[
+      '/usr/local/include',
+      '/usr/include',
+      '/usr/local/include/libxml2',
+      '/usr/include/libxml2',
+      msheaders,
+      '.'
+      ]
+
+def build_plugin(name):
+    dest_dir = bin_dir + name
+    SConscript([src_dir + name + "/SConscript"],['dest_dir','listinc'])
+    Command(dest_dir + "/plugin.xml",src_dir + name + "/plugin.xml", 
Copy("$TARGET", "$SOURCE"))
+    
+def build_plugins(plugins):
+       for name in plugins:
+               build_plugin(name)
+               
+
+def pack_plugin(name):
+    doc = xml.dom.minidom.parse(bin_dir + name + "/plugin.xml")
+    version = doc.getElementsByTagName("VERSION")
+    filename = name + "-" + version[0].firstChild.data + ".tar.gz"
+    tarenv = Environment(TARFLAGS = '-c -z')
+    tarenv.Tar(release_dir + filename, bin_dir + name) 
+
+
+
+def pack_plugins(plugins):
+       for name in plugins:
+               pack_plugin(name)
+
+
+build = True
+package = False
+release = False
+
+  
+
+if command=='package':
+       build = False
+       package = True
+       
+if command=='release':
+       package = True
+       release = True
+
+
+env = Environment(CPPPATH=listinc,CXXFLAGS="-fPIC -DPIC  -DHAVE_CONFIG_H",
+                      LINKFLAGS="-rdynamic")
+
+conf = Configure(env, config_h="config.h")
+
+
+if not conf.CheckCXXHeader("include/server/server.h"):
+    print "unable to find myserver headers"
+    Exit(1)
+
+
+env = conf.Finish()
+
+if build:
+       build_plugins(plugins)
+
+if package:
+       pack_plugins(plugins)
+
+#TODO: test compile and run.
+#if command == "build":
+#    testsFiles = glob.glob('tests/*.cpp') + files
+#    testsFiles.remove('src/myserver.cpp')
+#    testsFiles.sort()
+#    t = env.Program('tests/tests_suite', testsFiles)
+
+#if command == "tests":
+#    AddPostAction('tests/tests_suite', env.Execute('tests/tests_suite'))
+
+
+

Copied: trunk/plugins/src/http_checker (from rev 2900, 
trunk/plugins/generics/http_checker)


Property changes on: trunk/plugins/src/http_checker
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: trunk/plugins/src/http_checker/SConscript
===================================================================
--- trunk/plugins/generics/http_checker/SConscript      2008-10-23 20:50:14 UTC 
(rev 2900)
+++ trunk/plugins/src/http_checker/SConscript   2008-10-26 19:37:37 UTC (rev 
2913)
@@ -1,6 +1,7 @@
 #-*- mode: python -*-
+Import('dest_dir','listinc')
 
-listinc=[
+local_listinc=[
       GetLaunchDir(),
       '../../../',
       '/usr/local/include',
@@ -12,8 +13,10 @@
       '.'
       ]
 
-env = Environment(CPPPATH=listinc)
+local_listinc.extend(listinc)
 
+env = Environment(CPPPATH=local_listinc)
+
 conf = Configure(env, config_h="config.h")
 
 if conf.CheckHeader("Python.h"):
@@ -21,4 +24,7 @@
 
 env = conf.Finish()
 
-env.SharedLibrary(GetLaunchDir() + "/binaries/plugins/generics/http_checker", 
["http_checker.cpp" ], SHLIBPREFIX="")
+env.SharedLibrary(GetLaunchDir() + "/" + dest_dir + "/http_checker", 
["http_checker.cpp" ], SHLIBPREFIX="")
+
+Command(GetLaunchDir() + "/" + dest_dir + "/README","README", Copy("$TARGET", 
"$SOURCE"))
+Command(GetLaunchDir() + "/" + dest_dir + 
"/http_rules_sample.py","http_rules_sample.py", Copy("$TARGET", "$SOURCE"))

Modified: trunk/plugins/src/http_checker/http_checker.cpp
===================================================================
--- trunk/plugins/generics/http_checker/http_checker.cpp        2008-10-23 
20:50:14 UTC (rev 2900)
+++ trunk/plugins/src/http_checker/http_checker.cpp     2008-10-26 19:37:37 UTC 
(rev 2913)
@@ -17,9 +17,9 @@
 #include <stdafx.h>
 #include <string.h>
 #include <include/server/server.h>
-#include <include/multicast/multicast.h>
+#include <include/base/multicast/multicast.h>
 #include <include/protocol/http/http.h>
-#include <include/plugin/executor/dynamic_executor.h>
+#include <include/plugin/plugin.h>
 #include <Python.h>
 
 #ifdef WIN32
@@ -28,6 +28,10 @@
 #define EXPORTABLE(x) extern "C" x
 #endif
 
+typedef int (*executePROC)(char*, u_long);
+typedef int (*executeFromFilePROC)(char*);
+
+
 struct ThreadData
 {
        HttpThreadContext* td;
@@ -182,10 +186,18 @@
 
                for(it = rules.begin(); it != rules.end(); it++)
                {
-                       if((*it).file)
-                               
python->executeFromFile((char*)(*it).data.c_str());
-                       else
-                               python->execute((char*)(*it).data.c_str(), 
(*it).data.length());
+                       if((*it).file) 
+                       {
+                               executeFromFilePROC execute = 
((executeFromFilePROC)python->getDirectMethod((char*)"executeFromFile"));
+                               if (execute)
+                                 execute((char*)(*it).data.c_str());
+                       }else
+                       {
+                               executePROC execute = 
((executePROC)python->getDirectMethod((char*)"execute"));
+                               
+                               if (execute)
+                                 execute((char*)(*it).data.c_str(), 
(*it).data.length());
+                       }
                }
                return threadData.ret;
        }
@@ -198,11 +210,11 @@
                rules.push_back(it);
        }
 
-       void setPythonExecutor(DynamicExecutor* python){this->python = python;}
+       void setPythonExecutor(Plugin* python){this->python = python;}
 
 private:
        list<Item> rules;
-       DynamicExecutor* python;
+       Plugin* python;
 };
 
 static HttpObserver observer;
@@ -220,7 +232,6 @@
        Server* serverInstance = (Server*)server;
        HttpStaticData* staticData =(HttpStaticData*) 
serverInstance->getGlobalData("http-static");
        string msg("new-http-request");
-       string pythonNamespace("executors");
        string pythonName("python");
        Plugin* python;
        XmlParser* configuration;
@@ -234,7 +245,7 @@
                serverInstance->logUnlockAccess();
                return -1;
        }
-       python = 
serverInstance->getPluginsManager()->getPlugin(pythonNamespace, pythonName);
+       python = serverInstance->getPluginsManager()->getPlugin(pythonName);
 
        if(!python)
        {
@@ -245,7 +256,7 @@
                serverInstance->logUnlockAccess();
                return -1;
        }
-       observer.setPythonExecutor((DynamicExecutor*)python);
+       observer.setPythonExecutor(python);
 
        staticData->addMulticast(msg, &observer);
 

Modified: trunk/plugins/src/http_checker/plugin.xml
===================================================================
--- trunk/plugins/generics/http_checker/plugin.xml      2008-10-23 20:50:14 UTC 
(rev 2900)
+++ trunk/plugins/src/http_checker/plugin.xml   2008-10-26 19:37:37 UTC (rev 
2913)
@@ -2,10 +2,9 @@
 
 <PLUGIN>
 <NAME>http_checker</NAME>
-<TYPE>generics</TYPE>
 <VERSION>0.1</VERSION>
 <AUTHOR>The Free Software Foundation Inc.</AUTHOR>
 <MAINTAINER>The Free Software Foundation Inc.</MAINTAINER>
 <DESCRIPTION>This plugin permits to validate HTTP requests using 
python</DESCRIPTION>
-<DEPENDS>executors::python</DEPENDS>
+<DEPENDS>python</DEPENDS>
 </PLUGIN>

Copied: trunk/plugins/src/php (from rev 2900, trunk/plugins/http_managers/php)


Property changes on: trunk/plugins/src/php
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: trunk/plugins/src/php/SConscript
===================================================================
--- trunk/plugins/http_managers/php/SConscript  2008-10-23 20:50:14 UTC (rev 
2900)
+++ trunk/plugins/src/php/SConscript    2008-10-26 19:37:37 UTC (rev 2913)
@@ -1,6 +1,7 @@
 #-*- mode: python -*-
+Import('dest_dir','listinc')
 
-listinc=[
+local_listinc=[
       GetLaunchDir(),
       '../../../',
       '/usr/local/include',
@@ -10,8 +11,10 @@
       '.'
       ]
 
-env = Environment(CPPPATH=listinc)
+local_listinc.extend(listinc)
 
+env = Environment(CPPPATH=local_listinc)
+
 conf = Configure(env, config_h="config.h")
 
 if not conf.CheckFunc("php5"):
@@ -29,5 +32,7 @@
 
 env = conf.Finish()
 
-env.SharedLibrary(GetLaunchDir() + "/binaries/plugins/http_managers/php", 
["php.cpp"], SHLIBPREFIX="")
+env.SharedLibrary(GetLaunchDir() + "/" + dest_dir + "/php", ["php.cpp"], 
SHLIBPREFIX="")
 
+Command(GetLaunchDir() + "/" + dest_dir + "/README","README", Copy("$TARGET", 
"$SOURCE"))
+

Modified: trunk/plugins/src/php/php.cpp
===================================================================
--- trunk/plugins/http_managers/php/php.cpp     2008-10-23 20:50:14 UTC (rev 
2900)
+++ trunk/plugins/src/php/php.cpp       2008-10-26 19:37:37 UTC (rev 2913)
@@ -358,10 +358,26 @@
 }
 
 
+/*!
+ *Default constructor.
+ */
+PhpManager::PhpManager() 
+{
 
-int sendManager(HttpThreadContext* td, ConnectionPtr s, const char 
*filenamePath,
-                                                               const char* 
cgi, int onlyHeader)
+}
+
+/*!
+ *Destroy the object.
+ */
+PhpManager::~PhpManager()
 {
+
+}
+
+
+int PhpManager::send(HttpThreadContext*, ConnectionPtr s, const char 
*filenamePath,
+                   const char* cgi, int selfExecuted, int onlyHeader = 0)
+{
        PhpData* data;
        zend_file_handle script;
        int ret = SUCCESS;

Modified: trunk/plugins/src/php/php.h
===================================================================
--- trunk/plugins/http_managers/php/php.h       2008-10-23 20:50:14 UTC (rev 
2900)
+++ trunk/plugins/src/php/php.h 2008-10-26 19:37:37 UTC (rev 2913)
@@ -25,6 +25,7 @@
 #include <include/base/file/file.h>
 #include <include/base/file/files_utility.h>
 #include <include/protocol/http/http.h>
+#include <include/protocol/http/dyn_http_manager.h>
 
 #ifdef WIN32
 #define EXPORTABLE(x) x _declspec(dllexport);
@@ -37,8 +38,20 @@
 
 EXPORTABLE(int) load(void* server, void* parser);
 
+EXPORTABLE(int) postLoad(void* server,void* parser)
+
 EXPORTABLE(int) unload(void* p);
 
+class PhpManager 
+{
+public:
+       PhpManager();
+       virtual ~PhpManager();
+       virtual int send(HttpThreadContext*, ConnectionPtr s, const char 
*filenamePath,
+                   const char* cgi, int selfExecuted, int onlyHeader = 0);
+
+};
+
 EXPORTABLE(int) sendManager(HttpThreadContext* td, ConnectionPtr s, const char 
*filenamePath,
                                                                                
                         const char* cgi, int onlyHeader);
 

Modified: trunk/plugins/src/php/plugin.xml
===================================================================
--- trunk/plugins/http_managers/php/plugin.xml  2008-10-23 20:50:14 UTC (rev 
2900)
+++ trunk/plugins/src/php/plugin.xml    2008-10-26 19:37:37 UTC (rev 2913)
@@ -2,7 +2,6 @@
 
 <PLUGIN>
 <NAME>php</NAME>
-<TYPE>http_managers</TYPE>
 <VERSION>0.1</VERSION>
 <AUTHOR>The Free Software Foundation Inc.</AUTHOR>
 <MAINTAINER>The Free Software Foundation Inc.</MAINTAINER>

Added: trunk/plugins/src/python/SConscript
===================================================================
--- trunk/plugins/src/python/SConscript                         (rev 0)
+++ trunk/plugins/src/python/SConscript 2008-10-26 19:37:37 UTC (rev 2913)
@@ -0,0 +1,29 @@
+#-*- mode: python -*-
+
+Import('dest_dir','listinc')
+
+local_listinc=[
+      '/usr/include/python2.5',
+      '/usr/local/include/python2.5',
+      '/usr/local/include/libxml2',
+      '/usr/include/libxml2',
+      '.'
+      ]
+
+local_listinc.extend(listinc)
+
+env = Environment(CPPPATH=local_listinc)
+
+conf = Configure(env, config_h="config.h")
+
+if conf.CheckHeader("Python.h") and conf.CheckLib("python2.5"):
+    conf.Define('PYTHON', 1)
+
+conf.CheckLib("util")
+conf.CheckLib("pthread")
+conf.CheckLib("dl")
+
+env = conf.Finish()
+
+env.SharedLibrary(GetLaunchDir() + "/" + dest_dir + "/python", ["python.cpp"], 
SHLIBPREFIX="")
+

Added: trunk/plugins/src/python/plugin.xml
===================================================================
--- trunk/plugins/src/python/plugin.xml                         (rev 0)
+++ trunk/plugins/src/python/plugin.xml 2008-10-26 19:37:37 UTC (rev 2913)
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+
+<PLUGIN>
+<NAME>python</NAME>
+<VERSION>0.1</VERSION>
+<AUTHOR>The MyServer Team</AUTHOR>
+<MAINTAINER>The MyServer Team</MAINTAINER>
+<DESCRIPTION>Python code executor</DESCRIPTION>
+</PLUGIN>

Added: trunk/plugins/src/python/python.cpp
===================================================================
--- trunk/plugins/src/python/python.cpp                         (rev 0)
+++ trunk/plugins/src/python/python.cpp 2008-10-26 19:37:37 UTC (rev 2913)
@@ -0,0 +1,313 @@
+/*
+MyServer
+Copyright (C) 2007, 2008 The MyServer Team
+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 "python.h"
+
+PyInterpreterState* pythonMainInterpreterState = NULL;
+HashMap<ThreadID, PythonData*> pythonThreadData;
+
+static Server *serverInstance;
+
+char* name (char* name, u_long len)
+{
+       char* str = (char*)"python";
+
+       if (name)
+               strncpy (name, str, len);
+
+       return str;
+}
+
+
+PyInterpreterState* PythonData::getInterpreter ()
+       {
+               if(interp == 0)
+                       interp = Py_NewInterpreter ();
+               PyThreadState_Swap (NULL);
+               return interp->interp;
+       }
+
+PythonData::PythonData ()
+{
+       clear ();
+}
+
+void PythonData::clear ()
+{
+       interp = 0;
+}
+
+
+
+int load (void* server, void* parser)
+{
+       serverInstance = (Server*)server;
+       const char* pathData = serverInstance->getHashedData("PYTHON_PATH");
+       PyThreadState * mainThreadState;
+       if (pathData)
+       {       
+               string path (pathData);
+               FilesUtility::completePath (path);
+               
+               setenv ("PYTHONPATH", path.c_str(), 1);
+       }
+       else
+       {
+               string path (".");
+               FilesUtility::completePath (path);
+
+               setenv ("PYTHONPATH", path.c_str(), 1);
+       }
+
+  Py_SetProgramName ((char *)("python"));
+       Py_Initialize ();
+       PyEval_InitThreads ();
+
+       mainThreadState = PyThreadState_Get ();
+
+       pythonMainInterpreterState = mainThreadState->interp;
+
+       PyEval_ReleaseLock ();
+
+       return 0;
+}
+
+/*! Unload the plugin.  Called once.  Returns 0 on success.  */
+int unLoad (void* p)
+{
+       PyInterpreterState *interpreter = NULL;
+       PyThreadState *threadState = NULL;
+       PythonData* data = NULL;
+       ThreadID tid = Thread::threadID ();
+
+       PyEval_AcquireLock ();
+
+
+       data = pythonThreadData.get (tid);
+       if(data == 0)
+       {
+               data = new PythonData ();
+               pythonThreadData.put (tid, data);
+       }
+
+       interpreter = data->getInterpreter ();
+       threadState = PyThreadState_New (interpreter);
+
+       PyThreadState_Swap (threadState);
+
+
+       Py_Finalize ();
+
+       
+       PyThreadState_Swap (NULL);
+
+
+       PyEval_ReleaseLock ();
+
+       HashMap<ThreadID, PythonData*>::Iterator it = pythonThreadData.begin ();
+       while (it != pythonThreadData.end ())
+               delete *it++;
+       return 0;
+}
+
+int execute (char* code, u_long length)
+{
+  return executeImpl (code, length, NULL, 1);
+}
+
+int executeImpl (char* code, u_long length, PyThreadState *threadState, int 
newThreadState)
+{
+       PyInterpreterState *interpreter = NULL;
+       PythonData* data = NULL;
+       ThreadID tid = Thread::threadID ();
+
+       PyEval_AcquireLock ();
+
+       data = pythonThreadData.get (tid);
+       if (data == 0)
+       {
+               data = new PythonData();
+               pythonThreadData.put(tid, data);
+       }
+
+       interpreter = data->getInterpreter ();
+
+  if (newThreadState)
+    threadState = PyThreadState_New (interpreter);
+
+       PyThreadState_Swap (threadState);
+
+
+       PyRun_SimpleString (code);
+       
+       PyThreadState_Swap (NULL);
+
+  if (newThreadState)
+  {
+    PyThreadState_Clear (threadState);
+    PyThreadState_Delete (threadState);
+  }
+
+       PyEval_ReleaseLock ();
+
+  return 0;
+
+
+}
+
+int executeFromFile (char* filename)
+{
+  return executeFromFileImpl (filename, NULL, 1);
+}
+
+int executeFromFileImpl(char* filename, PyThreadState *threadState, int 
newThreadState)
+{
+       PyInterpreterState *interpreter = NULL;
+       int ret = 0;
+       FILE *file = NULL;
+       PythonData* data = NULL;
+       ThreadID tid = Thread::threadID ();
+
+       PyEval_AcquireLock ();
+
+       data = pythonThreadData.get (tid);
+       if(data == 0)
+       {
+               data = new PythonData ();
+               pythonThreadData.put (tid, data);
+       }
+
+       interpreter = data->getInterpreter ();
+
+  if (newThreadState)
+    threadState = PyThreadState_New (interpreter);
+
+       PyThreadState_Swap (threadState);
+
+       file = fopen (filename, "r");
+
+       if(file == 0)
+       {
+               string msg;
+               msg.assign ("Python: Cannot load file ");
+               msg.append (filename);
+
+               serverInstance->logLockAccess ();
+               serverInstance->logPreparePrintError ();
+               serverInstance->logWriteln (msg.c_str ());
+               serverInstance->logEndPrintError ();
+               serverInstance->logUnlockAccess ();
+
+               ret = -1;
+       }
+       else
+               ret = PyRun_AnyFileEx (file, filename, 1);
+
+       
+       PyThreadState_Swap (NULL);
+
+  if (newThreadState)
+  {
+    PyThreadState_Clear (threadState);
+    PyThreadState_Delete(threadState);
+  }
+
+       PyEval_ReleaseLock ();
+
+  return ret;
+
+}
+
+PyObject* callObject(PyObject *obj, PyObject *args)
+{
+  return callObjectImpl(obj, args, NULL, 1);
+}
+
+ 
+PyObject* callObjectImpl(PyObject *obj, PyObject *args, PyThreadState 
*threadState, int newThreadState)
+{
+       PyInterpreterState *interpreter = NULL;
+       PythonData* data = NULL;
+       ThreadID tid = Thread::threadID();
+  PyObject *result;
+
+       PyEval_AcquireLock ();
+
+       data = pythonThreadData.get (tid);
+       if(data == 0)
+       {
+               data = new PythonData ();
+               pythonThreadData.put (tid, data);
+       }
+
+       interpreter = data->getInterpreter();
+
+  if (newThreadState)
+    threadState = PyThreadState_New(interpreter);
+
+       PyThreadState_Swap (threadState);
+
+
+  result = PyEval_CallObject (obj, args);
+
+
+       PyThreadState_Swap (NULL);
+
+  if (newThreadState)
+  {
+    PyThreadState_Clear (threadState);
+    PyThreadState_Delete (threadState);
+  }
+
+       PyEval_ReleaseLock ();
+
+  return result;
+}
+
+
+int initModule (char* name, PyMethodDef methods[])
+{
+       PyInterpreterState *interpreter = NULL;
+       PyThreadState *threadState = NULL;
+       PythonData* data = NULL;
+       ThreadID tid = Thread::threadID ();
+
+       PyEval_AcquireLock ();
+
+       data = pythonThreadData.get (tid);
+       if (data == 0)
+       {
+               data = new PythonData ();
+               pythonThreadData.put (tid, data);
+       }
+
+       interpreter = data->getInterpreter ();
+       threadState = PyThreadState_New (interpreter);
+
+       PyThreadState_Swap (threadState);
+
+
+       Py_InitModule (name, methods);
+
+       PyThreadState_Swap (NULL);
+
+
+       PyEval_ReleaseLock ();
+
+       return 0;
+}
+

Added: trunk/plugins/src/python/python.h
===================================================================
--- trunk/plugins/src/python/python.h                           (rev 0)
+++ trunk/plugins/src/python/python.h   2008-10-26 19:37:37 UTC (rev 2913)
@@ -0,0 +1,65 @@
+/*
+MyServer
+Copyright (C) 2007, 2008 The MyServer Team
+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 <Python.h>
+
+#include <stdafx.h>
+#include <include/connection/connection.h>
+#include <include/base/socket/socket.h>
+#include <include/server/server.h>
+#include <include/base/sync/mutex.h>
+#include <include/base/file/file.h>
+#include <include/base/file/files_utility.h>
+
+
+struct PythonData
+{
+       PyThreadState* interp;
+       PyInterpreterState* getInterpreter();
+       PythonData();
+       void clear();
+};
+
+extern HashMap<ThreadID, PythonData*> pythonThreadData;
+
+
+
+#ifdef WIN32
+#define EXPORTABLE(x) x _declspec(dllexport)
+#else
+#define EXPORTABLE(x) extern "C" x
+#endif
+
+
+EXPORTABLE(char*) name(char* name, u_long len);
+
+EXPORTABLE(int) load(void* server,void* parser);
+EXPORTABLE(int) unLoad(void* p);
+
+
+EXPORTABLE(int) execute(char* code, u_long length);
+EXPORTABLE(int) executeFromFile(char* filename);
+
+
+EXPORTABLE(int) executeImpl (char* code, u_long length, PyThreadState 
*threadState, int newThreadState);
+EXPORTABLE(int) executeFromFileImpl(char* filename, PyThreadState 
*threadState, int newThreadState);
+
+EXPORTABLE(PyObject*) callObject(PyObject *obj, PyObject *args);
+EXPORTABLE(PyObject*) callObjectImpl(PyObject *obj, PyObject *args, 
PyThreadState *threadState, int newThreadState);
+
+
+EXPORTABLE(int) initModule(char*, PyMethodDef[]);

Copied: trunk/plugins/src/python_http_handler (from rev 2900, 
trunk/plugins/generics/python_http_handler)


Property changes on: trunk/plugins/src/python_http_handler
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: trunk/plugins/src/python_http_handler/SConscript
===================================================================
--- trunk/plugins/generics/python_http_handler/SConscript       2008-10-23 
20:50:14 UTC (rev 2900)
+++ trunk/plugins/src/python_http_handler/SConscript    2008-10-26 19:37:37 UTC 
(rev 2913)
@@ -1,6 +1,7 @@
 #-*- mode: python -*-
+Import('dest_dir','listinc')
 
-listinc=[
+local_listinc=[
       GetLaunchDir(),
       '../../../',
       '/usr/local/include',
@@ -12,8 +13,10 @@
       '.'
       ]
 
-env = Environment(CPPPATH=listinc)
+local_listinc.extend(listinc)
 
+env = Environment(CPPPATH=local_listinc)
+
 conf = Configure(env, config_h="config.h")
 
 if conf.CheckHeader("Python.h"):
@@ -21,5 +24,7 @@
 
 env = conf.Finish()
 
-env.SharedLibrary(GetLaunchDir() + 
"/binaries/plugins/generics/python_http_handler", ["python_http_handler.cpp" ], 
SHLIBPREFIX="")
+env.SharedLibrary(GetLaunchDir() + "/" + dest_dir + "/python_http_handler", 
["python_http_handler.cpp" ], SHLIBPREFIX="")
 
+Command(GetLaunchDir() + "/" + dest_dir + "/python","python", Copy("$TARGET", 
"$SOURCE"))
+Command(GetLaunchDir() + "/" + dest_dir + "/README","README", Copy("$TARGET", 
"$SOURCE"))

Added: trunk/plugins/src/python_http_handler/config.h
===================================================================
--- trunk/plugins/src/python_http_handler/config.h                              
(rev 0)
+++ trunk/plugins/src/python_http_handler/config.h      2008-10-26 19:37:37 UTC 
(rev 2913)
@@ -0,0 +1,9 @@
+#ifndef SRC_PYTHON_HTTP_HANDLER_CONFIG_H_SEEN
+#define SRC_PYTHON_HTTP_HANDLER_CONFIG_H_SEEN
+
+
+/* Define to 1 if you have the <Python.h> header file. */
+#define HAVE_PYTHON_H 1
+#define PYTHON 1
+
+#endif /* SRC_PYTHON_HTTP_HANDLER_CONFIG_H_SEEN */

Modified: trunk/plugins/src/python_http_handler/plugin.xml
===================================================================
--- trunk/plugins/generics/python_http_handler/plugin.xml       2008-10-23 
20:50:14 UTC (rev 2900)
+++ trunk/plugins/src/python_http_handler/plugin.xml    2008-10-26 19:37:37 UTC 
(rev 2913)
@@ -2,10 +2,9 @@
 
 <PLUGIN>
 <NAME>python_http_handler</NAME>
-<TYPE>generics</TYPE>
 <VERSION>0.1</VERSION>
 <AUTHOR>The Free Software Foundation Inc.</AUTHOR>
 <MAINTAINER>The Free Software Foundation Inc.</MAINTAINER>
 <DESCRIPTION>This plugin permits to use python as handler</DESCRIPTION>
-<DEPENDS>executors::python</DEPENDS>
+<DEPENDS>python</DEPENDS>
 </PLUGIN>

Modified: trunk/plugins/src/python_http_handler/python_http_handler.cpp
===================================================================
--- trunk/plugins/generics/python_http_handler/python_http_handler.cpp  
2008-10-23 20:50:14 UTC (rev 2900)
+++ trunk/plugins/src/python_http_handler/python_http_handler.cpp       
2008-10-26 19:37:37 UTC (rev 2913)
@@ -20,19 +20,23 @@
 #include <include/protocol/http/http_data_handler.h>
 #include <include/base/multicast/multicast.h>
 #include <include/protocol/http/http.h>
-#include <include/plugin/executor/dynamic_executor.h>
+#include <include/plugin/plugin.h>
 #include <Python.h>
 
 
 static Server* serverInstance;
 
 
+
+
 #ifdef WIN32
 #define EXPORTABLE(x) x _declspec(dllexport)
 #else
 #define EXPORTABLE(x) extern "C" x
 #endif
 
+typedef int (*executePROC)(char*, u_long);
+typedef int (*executeFromFilePROC)(char*);
 
 class ThreadData : public HttpDataHandler
 {
@@ -360,10 +364,18 @@
 
                for(it = rules.begin(); it != rules.end(); it++)
                {
-                       if((*it).file)
-                               
python->executeFromFile((char*)(*it).data.c_str());
-                       else
-                               python->execute((char*)(*it).data.c_str(), 
(*it).data.length());
+                       if((*it).file) 
+                       {
+                               executeFromFilePROC execute = 
((executeFromFilePROC)python->getDirectMethod((char*)"executeFromFile"));
+                               if (execute)
+                                 execute((char*)(*it).data.c_str());
+                       }else
+                       {
+                               executePROC execute = 
((executePROC)python->getDirectMethod((char*)"execute"));
+                               
+                               if (execute)
+                                 execute((char*)(*it).data.c_str(), 
(*it).data.length());
+                       }
                }
                return threadData.getRet();
        }
@@ -376,11 +388,11 @@
                rules.push_back(it);
        }
 
-       void setPythonExecutor(DynamicExecutor* python){this->python = python;}
+       void setPythonExecutor(Plugin* python){this->python = python;}
 
 private:
        list<Item> rules;
-       DynamicExecutor* python;
+       Plugin* python;
 };
 
 static HttpObserver observer;
@@ -399,7 +411,6 @@
        serverInstance = (Server*)server;
        HttpStaticData* staticData =(HttpStaticData*) 
serverInstance->getGlobalData("http-static");
        string msg("new-http-request");
-       string pythonNamespace("executors");
        string pythonName("python");
        Plugin* python;
        XmlParser* configuration;
@@ -413,7 +424,7 @@
                serverInstance->logUnlockAccess();
                return -1;
        }
-       python = 
serverInstance->getPluginsManager()->getPlugin(pythonNamespace, pythonName);
+       python = serverInstance->getPluginsManager()->getPlugin(pythonName);
 
        if(!python)
        {
@@ -424,7 +435,7 @@
                serverInstance->logUnlockAccess();
                return -1;
        }
-       observer.setPythonExecutor((DynamicExecutor*)python);
+       observer.setPythonExecutor(python);
 
        staticData->addMulticast(msg, &observer);
 

Copied: trunk/plugins/src/rules_checker (from rev 2900, 
trunk/plugins/generics/rules_checker)


Property changes on: trunk/plugins/src/rules_checker
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: trunk/plugins/src/rules_checker/SConscript
===================================================================
--- trunk/plugins/generics/rules_checker/SConscript     2008-10-23 20:50:14 UTC 
(rev 2900)
+++ trunk/plugins/src/rules_checker/SConscript  2008-10-26 19:37:37 UTC (rev 
2913)
@@ -1,6 +1,7 @@
 #-*- mode: python -*-
+Import('dest_dir','listinc')
 
-listinc=[
+local_listinc=[
       GetLaunchDir(),
       '../../../',
       '/usr/local/include',
@@ -10,11 +11,15 @@
       '.'
       ]
 
-env = Environment(CPPPATH=listinc)
+local_listinc.extend(listinc)
 
+env = Environment(CPPPATH=local_listinc)
+
 conf = Configure(env, config_h="config.h")
 
 env = conf.Finish()
 
-env.SharedLibrary(GetLaunchDir() + "/binaries/plugins/generics/rules_checker", 
"functions.cpp  parser.cpp  rules_checker.cpp  string_alloc.cpp".split(), 
SHLIBPREFIX="")
+env.SharedLibrary(GetLaunchDir() + "/" + dest_dir + "/rules_checker", 
"functions.cpp  parser.cpp  rules_checker.cpp  string_alloc.cpp".split(), 
SHLIBPREFIX="")
 
+Command(GetLaunchDir() + "/" + dest_dir + "/README","README", Copy("$TARGET", 
"$SOURCE"))
+

Modified: trunk/plugins/src/rules_checker/plugin.xml
===================================================================
--- trunk/plugins/generics/rules_checker/plugin.xml     2008-10-23 20:50:14 UTC 
(rev 2900)
+++ trunk/plugins/src/rules_checker/plugin.xml  2008-10-26 19:37:37 UTC (rev 
2913)
@@ -2,7 +2,6 @@
 
 <PLUGIN>
 <NAME>rules_checker</NAME>
-<TYPE>generics</TYPE>
 <VERSION>0.1</VERSION>
 <AUTHOR>The Free Software Foundation Inc.</AUTHOR>
 <MAINTAINER>The Free Software Foundation Inc.</MAINTAINER>

Modified: trunk/plugins/src/rules_checker/rules_checker.cpp
===================================================================
--- trunk/plugins/generics/rules_checker/rules_checker.cpp      2008-10-23 
20:50:14 UTC (rev 2900)
+++ trunk/plugins/src/rules_checker/rules_checker.cpp   2008-10-26 19:37:37 UTC 
(rev 2913)
@@ -18,6 +18,7 @@
 #include <stdafx.h>
 #include <string.h>
 #include <include/server/server.h>
+#include <include/protocol/http/http.h>
 #include "heading.h"
 
 #ifdef WIN32

Added: trunk/plugins/src/rules_checker/string_alloc.os
===================================================================
(Binary files differ)


Property changes on: trunk/plugins/src/rules_checker/string_alloc.os
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream






reply via email to

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