00001 /* 00002 menu.cpp 00003 =================================== 00004 CGI menu from modules 00005 00006 */ 00007 #include "cgiClass.h" 00008 #include "cgiTemplates.h" 00009 #include "ocDynLib.hpp" 00010 #include "ocFileSys.h" 00011 #include "cgiCookie.h" 00012 #include "connectstring" 00013 #include "../metasite_source/siteLimit.h" 00014 00015 using namespace std; 00016 00017 typedef map< int, string> console_modules; 00018 00019 // global instances 00020 console_modules cmodules; 00021 string relPath = "./modules"; 00022 00023 int pickOption( string & module, string & module_name_filter, ostream & client ) 00024 { 00025 00026 if( module_name_filter == "module_base.so" || module_name_filter == module ) 00027 { 00028 string path = relPath; 00029 path += "/"; 00030 path += module; 00031 // load the library 00032 ocDynamicLibrary mod1(path); 00033 00034 if(mod1.IsLibraryLoaded()==false) 00035 { 00036 client << mod1.LastError() << endl; 00037 return 1; 00038 } 00039 00040 // load the ordinal function 00041 mod1.loadFunction("ordinal"); 00042 if( mod1.IsFunctionLoaded()==false) 00043 { 00044 client << "couldn't find library function. " << mod1.LastError() << mod1.function() << endl; 00045 return 1; 00046 } 00047 // invoke it! 00048 int ordinal_pos = ((int (*)())mod1.function())(); 00049 00050 cmodules[ordinal_pos] = module; 00051 // libary unloads as mod1 falls out of scope. 00052 } // end if we want to even mess with this module 00053 } 00054 int runOption( string module, ostream & client ) 00055 { 00056 00057 string path = relPath; 00058 path += "/"; 00059 path += module; 00060 // load the library 00061 ocDynamicLibrary mod1(path); 00062 00063 if(mod1.IsLibraryLoaded()==false) 00064 { 00065 cout << mod1.LastError() << endl; 00066 return 1; 00067 } 00068 00069 // load the presentation function 00070 mod1.loadFunction("presentation"); 00071 if( mod1.IsFunctionLoaded()==false) 00072 { 00073 client << "couldn't find library function. " << mod1.LastError() << mod1.function() << endl; 00074 return 1; 00075 } 00076 // invoke it! 00077 ((void (*)(ostream &))mod1.function())(client); 00078 00079 // libary unloads as mod1 falls out of scope. 00080 } 00081 int main( int argc, char ** argv ) 00082 { 00083 cgiScript sc("text/html", false); 00084 // Insure that the current site is selected 00085 currentSite( sc.ClientArguments() ); 00086 sc.closeHeader(); 00087 00088 cgiCookie cookie; 00089 cgiTemplates tmplt; 00090 tmplt.load("./Templates/menu.htmp"); 00091 string module_name_filter = "module_base.so"; 00092 string cookie_filter = cookie.get("module_name"); 00093 if( sc.ClientArguments().count("module_name") ) 00094 { 00095 module_name_filter = sc.ClientArguments()["module_name"].c_str(); 00096 } 00097 else if( cookie_filter.length() ) 00098 { 00099 module_name_filter = cookie_filter; 00100 } 00101 cgiHtml html; 00102 { 00103 cgiHead head; 00104 head << tmplt.getParagraph("headguts"); 00105 } 00106 { 00107 cgiBody body; 00108 body << tmplt.getParagraph("heading"); 00109 ocFileSys fs; 00110 if( fs.openDir(relPath.c_str()) ) 00111 { 00112 ocDirectory & entries = fs.getDirectoryEntries(); 00113 for(int i = 0; i < entries.size(); i++ ) 00114 { 00115 ocString sotest = entries[i].name; 00116 if( sotest.regExMatch(".so$") ) 00117 { 00118 pickOption( sotest, module_name_filter, body ); 00119 } 00120 } 00121 } 00122 console_modules::iterator pos; 00123 for( pos=cmodules.begin(); pos != cmodules.end(); ++pos ) 00124 { 00125 runOption( pos->second, body ); 00126 } 00127 } // end body 00128 return 0; 00129 };
1.5.5