myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [SCM] GNU MyServer branch, guile, created. v0.9.2-523-


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, guile, created. v0.9.2-523-g73bf0fe
Date: Thu, 26 Jan 2012 11:40:50 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, guile has been created
        at  73bf0fe4442039c78d5fe6f30a7039886d1fb95a (commit)

- Log -----------------------------------------------------------------


commit 73bf0fe4442039c78d5fe6f30a7039886d1fb95a
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Jan 26 12:39:52 2012 +0100

    guile_conf: move the plugin into the server core.

diff --git a/myserver/configure.ac b/myserver/configure.ac
index d0868ee..c0fe17a 100644
--- a/myserver/configure.ac
+++ b/myserver/configure.ac
@@ -3,7 +3,7 @@ dnl
 dnl GNU MyServer
 dnl
 dnl Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-dnl 2011 Free Software Foundation, Inc.
+dnl 2011, 2012 Free Software Foundation, Inc.
 dnl
 dnl This program is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -202,7 +202,16 @@ if test x$have_xml2 != xyes; then
 ])
 
 else
-       CPPFLAGS="$CPPFLAGS $XML_CPPFLAGS"
+       CPPFLAGS="$CPPFLAGS $XML_CPPFLAGS"
+fi
+
+dnl Looking for libguile
+AC_CHECK_LIB(guile, scm_done_malloc)
+if test x$ac_cv_lib_guile_scm_done_malloc != xyes; then
+   AC_MSG_ERROR([
+   *** This system appears to have no libguile
+   *** libguile is required
+   ])
 fi
 
 AC_CHECK_LIB(gpg-error, gpg_err_init)
diff --git a/myserver/include/conf/guile_conf.h 
b/myserver/include/conf/guile_conf.h
new file mode 100644
index 0000000..b47df81
--- /dev/null
+++ b/myserver/include/conf/guile_conf.h
@@ -0,0 +1,55 @@
+/*
+  MyServer
+  Copyright (C) 2009, 2010, 2012 The 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 "myserver.h"
+
+#include <string.h>
+#include <libguile.h>
+#include <guile/gh.h>
+#include <include/plugin/plugin.h>
+#include <include/conf/main/main_configuration.h>
+#include <include/conf/vhost/xml_vhost_handler.h>
+#include <include/server/server.h>
+
+#define CONF_FILE_NAME "myserver.sch"
+
+/*! Define the interface to read from the main configuration file.  */
+class GuileConfiguration : public MainConfiguration
+{
+public:
+  GuileConfiguration ();
+  virtual const char *getValue (const char* field);
+  virtual void readData (list<NodeTree<string>*> *hashedDataTrees,
+                         HashMap<string, NodeTree<string>*> *hashedData);
+
+ private:
+    Server *serverInstance;
+};
+
+class GuileVhostManagerHandler : public XmlVhostHandler
+{
+public:
+  GuileVhostManagerHandler (ListenThreads* lt, LogManager* lm) :
+    XmlVhostHandler (lt, lm)
+  {
+  }
+
+    virtual int load (const char *resource);
+
+ private:
+    Server *serverInstance;
+};
diff --git a/myserver/src/conf/Makefile.am b/myserver/src/conf/Makefile.am
index 8531e13..fc9000b 100644
--- a/myserver/src/conf/Makefile.am
+++ b/myserver/src/conf/Makefile.am
@@ -1,7 +1,7 @@
 # GNU MyServer
 #
 # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-# 2011 Free Software Foundation, Inc.
+# 2011, 2012 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
@@ -17,7 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 AM_CXXFLAGS=-I"$(top_builddir)/lib" -I"$(top_srcdir)/lib" -I"$(top_srcdir)"
 noinst_LTLIBRARIES = libconf.la
-libconf_la_SOURCES = nodetree.cpp xml_conf.cpp
+libconf_la_SOURCES = guile_conf.cpp nodetree.cpp xml_conf.cpp
 SUBDIRS = main mime security vhost
 
 install:
diff --git a/myserver/src/conf/guile_conf.cpp b/myserver/src/conf/guile_conf.cpp
new file mode 100644
index 0000000..d7974fd
--- /dev/null
+++ b/myserver/src/conf/guile_conf.cpp
@@ -0,0 +1,196 @@
+/*
+  MyServer
+  Copyright (C) 2009, 2010, 2012 The 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 "myserver.h"
+
+#include <string.h>
+#include <libguile.h>
+#include <guile/gh.h>
+#include <include/plugin/plugin.h>
+#include <include/conf/guile_conf.h>
+#include <include/conf/main/main_configuration.h>
+#include <include/conf/vhost/xml_vhost_handler.h>
+#include <include/server/server.h>
+
+#define CONF_FILE_NAME "myserver.sch"
+
+static MainConfiguration *genGuileMainConf (Server *server, const char *arg)
+{
+  return new GuileConfiguration ();
+}
+
+static VhostManagerHandler* guile_vhost_builder (ListenThreads* lt, 
LogManager* lm);
+
+
+extern MainConfiguration* (*genMainConf) (Server *server, const char *arg);
+
+GuileConfiguration::GuileConfiguration ()
+{
+  serverInstance = Server::getInstance ();
+
+  static int initialized = 0;
+  if (! initialized)
+    {
+      scm_init_guile ();
+      Server *serverInstance = Server::getInstance ();
+
+      if (! FilesUtility::nodeExists (CONF_FILE_NAME))
+        {
+          serverInstance->log (MYSERVER_LOG_MSG_ERROR,
+                               _("GuileConf: cannot find file %s"), 
CONF_FILE_NAME);
+        }
+
+      genMainConf = &genGuileMainConf;
+      initialized = 1;
+    }
+
+}
+
+const char *
+GuileConfiguration::getValue (const char* field)
+{
+  /* TODO.  */
+  return NULL;
+}
+
+int
+GuileVhostManagerHandler::load (const char *resource)
+{
+  serverInstance = Server::getInstance ();
+  gh_eval_file (serverInstance->getData ("server.vhost_location",
+                                         "virtualhosts.sch"));
+  SCM list = gh_lookup ("vhosts");
+
+  while (! gh_null_p (list))
+    {
+      size_t len;
+      SCM v = gh_car (list);
+      Vhost *vh = new Vhost (logManager);
+      char *name = gh_scm2newstr (gh_car (v), &len);
+      vh->setName (name);
+      free (name);
+
+      char *portS = gh_scm2newstr (gh_cadr (v), &len);
+      u_short port = atoi (portS);
+      vh->setPort (port);
+      free (portS);
+
+      char *docroot = gh_scm2newstr (gh_caddr (v), &len);
+      vh->setDocumentRoot (docroot);
+      free (docroot);
+
+      char *sysroot = gh_scm2newstr (gh_caddr (gh_cdr (v)), &len);
+      vh->setSystemRoot (sysroot);
+      free (sysroot);
+
+      char *protocol = gh_scm2newstr (gh_caddr (gh_cddr (v)), &len);
+      vh->setProtocolName (protocol);
+      free (protocol);
+
+      list = gh_cdr (list);
+
+
+      /* TODO: read other information!!!  */
+      listenThreads->addListeningThread (port);
+      addVHost (vh);
+    }
+
+
+  static int initialized = 0;
+  if (! initialized)
+  {
+    VhostManager *vhostManager = serverInstance->getVhosts ();
+    vhostManager->registerBuilder ("guile", guile_vhost_builder);
+    initialized = 1;
+  }
+
+  return 0;
+}
+
+
+static NodeTree<string>*
+traverse (SCM node, HashMap<string, NodeTree<string>*> *hashedData)
+{
+  NodeTree<string> *newNode = new NodeTree<string> ();
+  if (gh_list_p (node))
+    {
+      while (gh_pair_p (gh_car (node)) && gh_symbol_p (gh_car (gh_car (node))))
+        {
+          size_t len;
+          char* attr = gh_symbol2newstr (gh_car (gh_car (node)), &len);
+          char* value = gh_scm2newstr (gh_cdr (gh_car (node)), &len);
+
+          string attrStr (attr);
+          string valueStr (value);
+
+          if (! strcmp (attr, "name"))
+            hashedData->put (valueStr, newNode);
+
+          newNode->addAttr (attrStr, valueStr);
+          node = gh_cdr (node);
+          free (attr);
+          free (value);
+        }
+
+      if (gh_string_p (gh_car (node)))
+        {
+          size_t len;
+          char *str = gh_scm2newstr (gh_car (node), &len);
+          newNode->setValue (new string (str));
+          free (str);
+        }
+      else
+        {
+          while (! gh_null_p (node))
+            {
+              NodeTree<string>* child = traverse (gh_car (node), hashedData);
+              newNode->addChild (child);
+              node = gh_cdr (node);
+            }
+        }
+    }
+
+  return newNode;
+}
+
+void
+GuileConfiguration::readData (list<NodeTree<string>*> *hashedDataTrees,
+                              HashMap<string, NodeTree<string>*> *hashedData)
+{
+  gh_eval_file (CONF_FILE_NAME);
+  SCM list = gh_lookup ("configuration");
+
+  if (gh_null_p (list))
+    {
+      serverInstance->log (MYSERVER_LOG_MSG_ERROR,
+                   _("GuileConf: cannot find symbol: %s"), "`configuration'");
+      return;
+    }
+
+  while (! gh_null_p (list))
+    {
+      hashedDataTrees->push_back (traverse (gh_car (list), hashedData));
+      list = gh_cdr (list);
+    }
+}
+
+static VhostManagerHandler* guile_vhost_builder (ListenThreads* lt,
+                                                 LogManager* lm)
+{
+
+  return new GuileVhostManagerHandler (lt, lm);
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 
GNU MyServer



reply via email to

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