00001 /* 00002 pick.cpp 00003 =================================== 00004 CGI List for modules 00005 00006 */ 00007 #include "cgiClass.h" 00008 #include "cgiTemplates.h" 00009 #include "ocDynLib.hpp" 00010 #include "ocFileSys.h" 00011 #include "../metasite_source/openLogin.h" 00012 #include "../metasite_source/site_pick.hpp" 00013 #include "../metasite_source/site.hpp" 00014 00015 using namespace std; 00016 class console_module 00017 { 00018 public: 00019 string module_name; 00020 string label; 00021 console_module() 00022 { 00023 } 00024 ~console_module() 00025 { 00026 } 00027 console_module & operator = ( const console_module & in ) 00028 { 00029 module_name = in.module_name; 00030 label = in.label; 00031 } 00032 }; 00033 00034 typedef map< int, console_module> console_modules; 00035 00036 // global instances 00037 console_modules cmodules; 00038 string relPath = "./modules"; 00039 00040 int pickOption( string module ) 00041 { 00042 00043 string path = relPath; 00044 path += "/"; 00045 path += module; 00046 // load the library 00047 ocDynamicLibrary mod1(path); 00048 00049 if(mod1.IsLibraryLoaded()==false) 00050 { 00051 cout << mod1.LastError() << endl; 00052 return 1; 00053 } 00054 00055 // load the ordinal function 00056 mod1.loadFunction("ordinal"); 00057 if( mod1.IsFunctionLoaded()==false) 00058 { 00059 cout << "couldn't find library function. " << mod1.LastError() << mod1.function() << endl; 00060 return 1; 00061 } 00062 // invoke it! 00063 int ordinal_pos = ((int (*)())mod1.function())(); 00064 00065 // load the label function 00066 mod1.loadFunction("label"); 00067 if( mod1.IsFunctionLoaded()==false) 00068 { 00069 cout << "couldn't find library function. " << mod1.LastError() << mod1.function() << endl; 00070 return 1; 00071 } 00072 // invoke it! 00073 string label = ((string (*)())mod1.function())(); 00074 console_module mod; 00075 mod.module_name = module; 00076 mod.label = label; 00077 cmodules[ordinal_pos] = mod; 00078 // libary unloads as mod1 falls out of scope. 00079 } 00080 00081 int main( int argc, char ** argv ) 00082 { 00083 cgiScript sc("text/html", false); 00084 cgiTemplates tmplt; 00085 tmplt.load("./Templates/pick.htmp"); 00086 /* 00087 The next few lines provide an option list, 00088 and set the site id cookie if only one site. 00089 MUST be invoked before closing header 00090 */ 00091 site_pick pick_a_site(sc); 00092 openLogin login; 00093 string options; 00094 if ( login.testLoginStatus() ) 00095 { 00096 options = pick_a_site.getSiteOptions(sc,login); 00097 } 00098 // now close header 00099 sc.closeHeader(); 00100 cgiHtml html; 00101 { 00102 cgiHead head; 00103 head << tmplt.getParagraph("headguts"); 00104 } 00105 cgiInput & args = sc.ClientArguments(); 00106 cgiBody * pbody; 00107 string attributes; 00108 if( args.count("changeSite") ) 00109 { 00110 siteObject site; 00111 site.key(atoll(args["site_id"])); 00112 if(site.get_data()) 00113 { 00114 attributes=" onload=\"reframe('http://"; 00115 attributes+=site.domain; 00116 attributes+=site.url; 00117 attributes+="sys')\""; 00118 00119 } 00120 } 00121 pbody = new cgiBody((char*)attributes.c_str());; 00122 00123 cgiBody & body = *pbody; 00124 body << tmplt.getParagraph("pickformstart"); 00125 ocFileSys fs; 00126 if( fs.openDir(relPath.c_str()) ) 00127 { 00128 ocDirectory & entries = fs.getDirectoryEntries(); 00129 for(int i = 0; i < entries.size(); i++ ) 00130 { 00131 ocString sotest = entries[i].name; 00132 if( sotest.regExMatch(".so$") ) 00133 { 00134 pickOption( sotest ); 00135 } 00136 } 00137 } 00138 console_modules::iterator pos; 00139 00140 for( pos=cmodules.begin(); pos != cmodules.end(); ++pos ) 00141 { 00142 ocString opt = tmplt.getParagraph("pickoption"); 00143 console_module & mod = pos->second; 00144 body << 00145 opt.replace("$value",mod.module_name.c_str()) 00146 .replace("$label",mod.label); 00147 } 00148 ocString pickformend = tmplt.getParagraph("pickformend"); 00149 body << pickformend.replace("$OPTIONS$",options.c_str()); 00150 00151 delete pbody; 00152 return 0; 00153 }; 00154 #include "read_write_base.cpp"
1.5.5