Index: /main/trunk/greenstone2/runtime-src/src/protocol/recptproto.h
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/protocol/recptproto.h	(revision 22141)
+++ /main/trunk/greenstone2/runtime-src/src/protocol/recptproto.h	(revision 22142)
@@ -53,4 +53,7 @@
 class recptproto {
 public:
+
+  recptproto() {};
+  virtual ~recptproto() {};
 
   // add collection server to protocol
Index: /main/trunk/greenstone2/runtime-src/src/protocol/recptprototools.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/protocol/recptprototools.cpp	(revision 22141)
+++ /main/trunk/greenstone2/runtime-src/src/protocol/recptprototools.cpp	(revision 22142)
@@ -143,5 +143,5 @@
   metadata.insert ("haschildren");
 
-  if (get_info (OID, collection, lang, metadata, false, collectproto,	response, logout))
+  if (get_info (OID, collection, lang, metadata, true, collectproto,	response, logout))
   {
     if (response.docInfo[0].metadata["haschildren"].values[0] == "1")
@@ -216,5 +216,5 @@
   {
     FilterResponse_t tmp;
-    bool getParents = false;
+    bool getParents = true;
     get_children (section.OID, collection, lang, metadata, getParents, collectproto, tmp, logout);
     ResultDocInfo_tarray::iterator thisdoc = tmp.docInfo.begin();
@@ -244,5 +244,5 @@
 
   // get topOIDs info
-  if (get_info (topOID, collection, lang, metadata, false, collectproto, response, logout))
+  if (get_info (topOID, collection, lang, metadata, true, collectproto, response, logout))
   {
     recurse_contents (response.docInfo[0], is_classify, collection, lang, metadata, collectproto, response, logout);
Index: /main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.cpp	(revision 22141)
+++ /main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.cpp	(revision 22142)
@@ -54,4 +54,35 @@
 #endif
 
+#include "authenaction.h"
+#include "browseaction.h"
+#include "collectoraction.h"
+#include "depositoraction.h"
+#include "documentaction.h"
+#include "dynamicclassifieraction.h"
+#include "extlinkaction.h"
+#include "pageaction.h"
+#ifdef ENABLE_MGPP
+#include "phindaction.h"
+#endif
+#include "pingaction.h"
+#include "queryaction.h"
+
+#if defined(USE_SQLITE)
+#include "sqlqueryaction.h"
+#endif
+
+#include "tipaction.h"
+#include "statusaction.h"
+#include "usersaction.h"
+#include "configaction.h"
+
+#include "vlistbrowserclass.h"
+#include "hlistbrowserclass.h"
+#include "datelistbrowserclass.h"
+#include "invbrowserclass.h"
+#include "pagedbrowserclass.h"
+#include "htmlbrowserclass.h"
+#include "phindbrowserclass.h"
+
 
 #ifdef USE_FASTCGI
@@ -450,4 +481,158 @@
 }
 
+
+
+
+void add_all_actions(receptionist& recpt, userdbclass* udb, keydbclass* kdb) 
+{
+  // the list of actions.
+
+#ifdef GSDL_USE_TIP_ACTION
+  tipaction* atipaction = new tipaction();
+  recpt.add_action (atipaction);
+#endif
+
+#ifdef GSDL_USE_STATUS_ACTION
+  statusaction *astatusaction = new statusaction();
+  astatusaction->set_receptionist (&recpt);
+  recpt.add_action (astatusaction);
+#endif
+
+  pageaction *apageaction = new pageaction();
+  apageaction->set_receptionist (&recpt);
+  recpt.add_action (apageaction);
+
+#ifdef GSDL_USE_PING_ACTION
+  recpt.add_action (new pingaction());
+#endif
+
+  queryaction *aqueryaction = new queryaction();
+  aqueryaction->set_receptionist (&recpt);
+  recpt.add_action (aqueryaction);
+
+#if defined(USE_SQLITE)
+  sqlqueryaction *asqlqueryaction = new sqlqueryaction();
+  asqlqueryaction->set_receptionist (&recpt);
+  recpt.add_action (asqlqueryaction);
+#endif
+
+  documentaction *adocumentaction = new documentaction();
+  adocumentaction->set_receptionist (&recpt);
+  recpt.add_action (adocumentaction);
+
+#ifdef GSDL_USE_USERS_ACTION
+  usersaction *ausersaction = new usersaction();
+  ausersaction->set_userdb(udb);
+  recpt.add_action (ausersaction);
+#endif
+
+#ifdef GSDL_USE_EXTLINK_ACTION
+  extlinkaction *aextlinkaction = new extlinkaction();
+  aextlinkaction->set_receptionist(&recpt);
+  recpt.add_action (aextlinkaction);
+#endif
+		
+#ifdef GSDL_USE_AUTHEN_ACTION
+  authenaction *aauthenaction = new authenaction();
+  aauthenaction->set_userdb(udb);
+  aauthenaction->set_keydb(kdb);
+  aauthenaction->set_receptionist(&recpt);
+  recpt.add_action (aauthenaction);
+#endif
+
+#ifdef GSDL_USE_COLLECTOR_ACTION
+  collectoraction *acollectoraction = new collectoraction();
+  acollectoraction->set_receptionist (&recpt);
+  recpt.add_action(acollectoraction);
+#endif
+
+#ifdef GSDL_USE_DEPOSITOR_ACTION
+  depositoraction *adepositoraction = new depositoraction();
+  adepositoraction->set_receptionist (&recpt);
+  recpt.add_action(adepositoraction);
+#endif
+
+#ifdef GSDL_USE_BROWSE_ACTION
+  browseaction *abrowseaction = new browseaction();
+  abrowseaction->set_receptionist (&recpt);
+  recpt.add_action(abrowseaction);
+#endif
+
+#ifdef GSDL_USE_PHIND_ACTION
+  // Phind uses MPPP,do we also need to check if ENABLE_MGPP is set??
+  phindaction *aphindaction = new phindaction();
+  recpt.add_action(aphindaction);
+#endif
+
+#ifdef GSDL_USE_GTI_ACTION
+  gtiaction *agtiaction = new gtiaction();
+  agtiaction->set_receptionist(&recpt);
+  recpt.add_action(agtiaction);
+#endif
+
+  dynamicclassifieraction *adynamicclassifieraction = new dynamicclassifieraction();
+  adynamicclassifieraction->set_receptionist(&recpt);
+  recpt.add_action(adynamicclassifieraction);  
+
+#if defined(USE_MYSQL) || defined(USE_ACCESS)
+  orderaction *aorderaction = new orderaction();
+  aorderaction->set_receptionist(&recpt);
+  recpt.add_action(aorderaction);
+#endif
+
+  // action that allows collections to be added, released etc.  when server
+  // is persistent (e.g. fastcgi or when Greenstone is configured as an
+  // Apache module).  Presumably this includes Windows server.exe as well
+
+  // Want to always include it in list of actions even if compiling
+  // Greenstone to be used in a non-persistent way (e.g. library.cgi).
+  // This is so the e-variable that is formed is consistent between the
+  // persisent executable and the non-persistent executable
+  // 
+
+  configaction *aconfigaction = new configaction();
+  aconfigaction->set_receptionist(&recpt);
+  recpt.add_action(aconfigaction);
+}
+
+
+
+void add_all_browsers(receptionist& recpt) 
+{
+  // list of browsers
+  vlistbrowserclass *avlistbrowserclass = new vlistbrowserclass();
+  avlistbrowserclass->set_receptionist(&recpt);
+  recpt.add_browser (avlistbrowserclass);
+  recpt.setdefaultbrowser ("VList");
+
+  hlistbrowserclass *ahlistbrowserclass = new hlistbrowserclass();
+  ahlistbrowserclass->set_receptionist(&recpt);
+  recpt.add_browser (ahlistbrowserclass);
+
+#ifdef GSDL_USE_DATELIST_BROWSER
+  datelistbrowserclass *adatelistbrowserclass = new datelistbrowserclass();
+  recpt.add_browser (adatelistbrowserclass);
+#endif
+
+  invbrowserclass *ainvbrowserclass = new invbrowserclass();
+  recpt.add_browser (ainvbrowserclass);
+
+#ifdef GSDL_USE_PAGED_BROWSER
+  pagedbrowserclass *apagedbrowserclass = new pagedbrowserclass();
+  recpt.add_browser (apagedbrowserclass);
+#endif
+
+#ifdef GSDL_USE_HTML_BROWSER
+  htmlbrowserclass *ahtmlbrowserclass = new htmlbrowserclass();
+  recpt.add_browser (ahtmlbrowserclass);
+#endif
+
+#ifdef GSDL_USE_PHIND_BROWSER
+  phindbrowserclass *aphindbrowserclass = new phindbrowserclass();;
+  recpt.add_browser (aphindbrowserclass);
+#endif
+}
+
+
 // cgiwrapper does everything necessary to output a page
 // using the cgi protocol. If this is being run for a particular
Index: /main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.h
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.h	(revision 22141)
+++ /main/trunk/greenstone2/runtime-src/src/recpt/cgiwrapper.h	(revision 22142)
@@ -30,4 +30,8 @@
 
 #include "receptionist.h"
+#include "userdb.h"
+
+void add_all_actions(receptionist& recpt, userdbclass* udb, keydbclass* kdb);
+void add_all_browsers(receptionist& recpt);
 
 // cgiwrapper does everything necessary to output a page
Index: /main/trunk/greenstone2/runtime-src/src/recpt/librarymain.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/recpt/librarymain.cpp	(revision 22141)
+++ /main/trunk/greenstone2/runtime-src/src/recpt/librarymain.cpp	(revision 22142)
@@ -36,34 +36,5 @@
 
 #include "action.h"
-#include "authenaction.h"
-#include "browseaction.h"
-#include "collectoraction.h"
-#include "depositoraction.h"
-#include "documentaction.h"
-#include "dynamicclassifieraction.h"
-#include "extlinkaction.h"
-#include "pageaction.h"
-#ifdef ENABLE_MGPP
-#include "phindaction.h"
-#endif
-#include "pingaction.h"
-#include "queryaction.h"
-
-#if defined(USE_SQLITE)
-#include "sqlqueryaction.h"
-#endif
-
-#include "tipaction.h"
-#include "statusaction.h"
-#include "usersaction.h"
-
 #include "browserclass.h"
-#include "vlistbrowserclass.h"
-#include "hlistbrowserclass.h"
-#include "datelistbrowserclass.h"
-#include "invbrowserclass.h"
-#include "pagedbrowserclass.h"
-#include "htmlbrowserclass.h"
-#include "phindbrowserclass.h"
 
 
@@ -122,126 +93,14 @@
 #endif
 
-  // the list of actions. Note: these actions will become invalid
-  // at the end of this function. We will clean them.
-
-#ifdef GSDL_USE_TIP_ACTION
-  recpt.add_action (new tipaction());
-#endif
-
-#ifdef GSDL_USE_STATUS_ACTION
-  statusaction *astatusaction = new statusaction();
-  astatusaction->set_receptionist (&recpt);
-  recpt.add_action (astatusaction);
-#endif
-
-  pageaction *apageaction = new pageaction();
-  apageaction->set_receptionist (&recpt);
-  recpt.add_action (apageaction);
-
-#ifdef GSDL_USE_PING_ACTION
-  recpt.add_action (new pingaction());
-#endif
-
-  queryaction *aqueryaction = new queryaction();
-  aqueryaction->set_receptionist (&recpt);
-  recpt.add_action (aqueryaction);
-
-#if defined(USE_SQLITE)
-  sqlqueryaction *asqlqueryaction = new sqlqueryaction();
-  asqlqueryaction->set_receptionist (&recpt);
-  recpt.add_action (asqlqueryaction);
-#endif
-
-  documentaction *adocumentaction = new documentaction();
-  adocumentaction->set_receptionist (&recpt);
-  recpt.add_action (adocumentaction);
-
   userdbclass *udb = new userdbclass(gsdlhome);
   keydbclass *kdb = new keydbclass(gsdlhome);
 
-#ifdef GSDL_USE_USERS_ACTION
-  usersaction *ausersaction = new usersaction();
-  ausersaction->set_userdb(udb);
-  recpt.add_action (ausersaction);
-#endif
+  add_all_actions(recpt,udb,kdb);
+  // Note: these actions will become invalid at the end of this function. 
+  // => We will retrieve them from the receptionist and delete them
 
-#ifdef GSDL_USE_EXTLINK_ACTION
-  extlinkaction *aextlinkaction = new extlinkaction();
-  aextlinkaction->set_receptionist(&recpt);
-  recpt.add_action (aextlinkaction);
-#endif
-		
-#ifdef GSDL_USE_AUTHEN_ACTION
-  authenaction *aauthenaction = new authenaction();
-  aauthenaction->set_userdb(udb);
-  aauthenaction->set_keydb(kdb);
-  aauthenaction->set_receptionist(&recpt);
-  recpt.add_action (aauthenaction);
-#endif
-
-#ifdef GSDL_USE_COLLECTOR_ACTION
-  collectoraction *acollectoraction = new collectoraction();
-  acollectoraction->set_receptionist (&recpt);
-  recpt.add_action(acollectoraction);
-#endif
-
-#ifdef GSDL_USE_DEPOSITOR_ACTION
-  depositoraction *adepositoraction = new depositoraction();
-  adepositoraction->set_receptionist (&recpt);
-  recpt.add_action(adepositoraction);
-#endif
-
-#ifdef GSDL_USE_BROWSE_ACTION
-  browseaction *abrowseaction = new browseaction();
-  abrowseaction->set_receptionist (&recpt);
-  recpt.add_action(abrowseaction);
-#endif
-
-#ifdef GSDL_USE_PHIND_ACTION
-  recpt.add_action(new phindaction());
-#endif
-
-#ifdef GSDL_USE_GTI_ACTION
-  gtiaction *agtiaction = new gtiaction();
-  agtiaction->set_receptionist(&recpt);
-  recpt.add_action(agtiaction);
-#endif
-
-  dynamicclassifieraction *adynamicclassifieraction = new dynamicclassifieraction();
-  adynamicclassifieraction->set_receptionist(&recpt);
-  recpt.add_action(adynamicclassifieraction);  
-
-  // list of browsers
-  vlistbrowserclass avlistbrowserclass;
-  avlistbrowserclass.set_receptionist(&recpt);
-  recpt.add_browser (&avlistbrowserclass);
-  recpt.setdefaultbrowser ("VList");
-
-  hlistbrowserclass ahlistbrowserclass;
-  ahlistbrowserclass.set_receptionist(&recpt);
-  recpt.add_browser (&ahlistbrowserclass);
-
-#ifdef GSDL_USE_DATELIST_BROWSER
-  datelistbrowserclass adatelistbrowserclass;
-  recpt.add_browser (&adatelistbrowserclass);
-#endif
-
-  invbrowserclass ainvbrowserclass;
-  recpt.add_browser (&ainvbrowserclass);
-
-#ifdef GSDL_USE_PAGED_BROWSER
-  pagedbrowserclass apagedbrowserclass;
-  recpt.add_browser (&apagedbrowserclass);
-#endif
-
-#ifdef GSDL_USE_HTML_BROWSER
-  htmlbrowserclass ahtmlbrowserclass;
-  recpt.add_browser (&ahtmlbrowserclass);
-#endif
-
-#ifdef GSDL_USE_PHIND_BROWSER
-  phindbrowserclass aphindbrowserclass;
-  recpt.add_browser (&aphindbrowserclass);
-#endif
+  add_all_browsers(recpt);
+  // Browsers are not currently deleted (at all?) in code.  Seems likely they
+  // should be treated in a similar fashion to actions
 
   cgiwrapper (recpt, "");
@@ -252,7 +111,8 @@
   // clean up the actions
   actionmapclass::iterator thisAction = recpt.get_actionmap_ptr()->begin();
-  actionmapclass::iterator endAction = recpt.get_actionmap_ptr()->begin();
+  actionmapclass::iterator endAction = recpt.get_actionmap_ptr()->end();
   while (thisAction != endAction) {
-    delete thisAction->second.a; thisAction->second.a = NULL;
+    delete thisAction->second.a; 
+    thisAction->second.a = NULL;
     ++thisAction;
   }
@@ -260,4 +120,18 @@
   recpt.get_actionmap_ptr()->erase(thisAction, endAction);
 
+
+  /*
+  // clean up the browsers
+  browsermapclass::iterator thisBrowser = recpt.get_browsermap_ptr()->begin();
+  browsermapclass::iterator endBrowser = recpt.get_browsermap_ptr()->end();
+  while (thisBrowser != endBrowser) {
+    delete thisBrowser->second.a; 
+    thisBrowser->second.a = NULL;
+    ++thisBrowser;
+  }
+  thisBrowser = recpt.get_browsermap_ptr()->begin();
+  recpt.get_browsermap_ptr()->erase(thisBrowser, endBrowser);
+  */
+
   return 0;
 }
Index: /main/trunk/greenstone2/runtime-src/src/recpt/mod_gsdl.cpp
===================================================================
--- /main/trunk/greenstone2/runtime-src/src/recpt/mod_gsdl.cpp	(revision 22141)
+++ /main/trunk/greenstone2/runtime-src/src/recpt/mod_gsdl.cpp	(revision 22142)
@@ -81,30 +81,25 @@
 
 #include "action.h"
-#include "pageaction.h"
-#include "queryaction.h"
-
-#if defined(USE_SQLITE)
-#include "sqlqueryaction.h"
-#endif
-
-#include "documentaction.h"
-#include "extlinkaction.h"
-#ifdef ENABLE_MGPP
-#include "phindaction.h"
-#endif
-#if defined(USE_MYSQL) || defined(USE_ACCESS)
-#include "orderaction.h"
-#endif
-#include "configaction.h"
-
 #include "browserclass.h"
-#include "vlistbrowserclass.h"
-#include "hlistbrowserclass.h"
-#include "datelistbrowserclass.h"
-#include "invbrowserclass.h"
-#include "pagedbrowserclass.h"
-#include "phindbrowserclass.h"
-
-#include <strstream>
+
+#define GSDL_USE_OSTRINGSTREAM 1
+// ostrstream is deprecated => switch to using ostringstream
+// Doing this with the above define so it is easy to switch
+// back to ostrstream this backwards compatability is needed
+// for some reason.
+
+#if defined(GSDL_USE_OSTRINGSTREAM)
+#  include <sstream>
+#else
+#  if defined(GSDL_USE_IOS_H)
+#    if defined(__WIN32__)
+#      include <strstrea.h> // vc4
+#    else
+#      include <strstream.h>
+#    endif
+#  else
+#    include <strstream>
+#  endif
+#endif
 
 receptionist recpt;
@@ -252,5 +247,5 @@
   // class as a filler (but most likely won't work) - only useful
   // if creating a binary that doesn't require access to the database
-  dbclass *db = new gdbmclass();
+  dbclass *db = new gdbmclass(gsdlhome);
 
 #endif
@@ -260,62 +255,17 @@
 #endif
 
-  // the list of actions.
-  pageaction *apageaction = new pageaction();
-  apageaction->set_receptionist(&recpt);
-  recpt.add_action(apageaction);
+  userdbclass *udb = new userdbclass(gsdlhome);
+  keydbclass *kdb = new keydbclass(gsdlhome);
+  // do these two database classes ever get deleted in the module version
+  // of Greenstone?
+
+  // librarymain.cpp deletes these when its finished its function
+  // does comparable code need to be put into "gsdl_deinit()" routine
+  // whatever that might be called in reality?
+
+  add_all_actions(recpt,udb,kdb);
+  add_all_browsers(recpt);
   
-  queryaction *aqueryaction = new queryaction();
-  aqueryaction->set_receptionist(&recpt);
-  recpt.add_action(aqueryaction);
-  
-#if defined(USE_SQLITE)
-  sqlqueryaction *asqlqueryaction = new sqlqueryaction();
-  asqlqueryaction->set_receptionist (&recpt);
-  recpt.add_action (asqlqueryaction);
-#endif
-
-  documentaction *adocumentaction = new documentaction();
-  adocumentaction->set_receptionist(&recpt);
-  recpt.add_action(adocumentaction);
-
-  extlinkaction *anextlinkaction = new extlinkaction();
-  recpt.add_action(anextlinkaction);
-
-  // phindaction is for MGPP and uses MGQuery
-#ifdef ENABLE_MGPP
-  phindaction *aphindaction = new phindaction();
-  recpt.add_action(aphindaction);
-#endif
-
-#if defined(USE_MYSQL) || defined(USE_ACCESS)
-  orderaction *aorderaction = new orderaction();
-  aorderaction->set_receptionist(&recpt);
-  recpt.add_action(aorderaction);
-#endif
-
-  configaction *aconfigaction = new configaction();
-  aconfigaction->set_receptionist(&recpt);
-  recpt.add_action(aconfigaction);
-
-  // list of browsers
-  vlistbrowserclass *avlistbrowserclass = new vlistbrowserclass();
-  recpt.add_browser(avlistbrowserclass);
-  recpt.setdefaultbrowser("VList");
-
-  hlistbrowserclass *ahlistbrowserclass = new hlistbrowserclass();
-  recpt.add_browser(ahlistbrowserclass);
-
-  datelistbrowserclass *adatelistbrowserclass = new datelistbrowserclass();
-  recpt.add_browser(adatelistbrowserclass);
-
-  invbrowserclass *ainvbrowserclass = new invbrowserclass();
-  recpt.add_browser(ainvbrowserclass);
-
-  pagedbrowserclass *apagedbrowserclass = new pagedbrowserclass();
-  recpt.add_browser(apagedbrowserclass);
-
-  phindbrowserclass *aphindbrowserclass = new phindbrowserclass();;
-  recpt.add_browser(aphindbrowserclass);
-  
+
   // configure everything
   recpt.configure("gsdlhome", gsdlhome);
@@ -500,5 +450,9 @@
   } 
 
+#ifdef GSDL_USE_OSTRINGSTREAM
+  ostringstream pageout;
+#else
   ostrstream pageout;
+#endif
 
   // get http headers
@@ -552,7 +506,12 @@
       return 500;
     } 
+#ifdef GSDL_USE_OSTRINGSTREAM
+    string out = pageout.str();
+    ap_rwrite(out.c_str(), out.size(), r);
+#else
     char *out = pageout.str();
     ap_rwrite(out, pageout.pcount(), r);
     pageout.rdbuf()->freeze(0);
+#endif
   }
 
