c++ cgi problem



  • Schreibe an einem Modul zum Regristrieren auf meiner.
    Habe nun folgendes Problem der so bald ich auf absenden gehe ist mir nicht möglich den Query Inhalt aus dem Modul abzurufen.

    main.cpp

    #include <iostream>
    #include <map>
    #include <fstream>
    #include "tuxcms.h"
    #include <vector>
    #include <html.h>
    #include <cgi.h>
    #include "modul/module.h"
    #include <easyc++.h>
    
    /*Under Construction*/
    
    using namespace std;
    
    string core::getconfig(string input)
    {
            ifstream  file("tuxcms.conf"); 
            string buf, key; 
            size_t n; 
    
            while(file.good()) { 
                    getline(file, buf, '\n'); 
                    n=buf.find(input); 
                    if(n != string::npos) { 
                            n += input.length();
                            key=buf.substr(n,buf.length()); 
                            break; 
                    } else { 
                            continue; 
                    } 
            } 
    
    file.close();
            if(key.length() > 0) { 
                    return key;
            } else { 
                    return "error key not found";
            }
    }
    
    void xhtmlstrict()
    {
    cout <<	"<p>" << endl
         <<		"<a href=\"http://validator.w3.org/check?uri=referer\">"
         << 	"<img src=\"http://www.w3.org/Icons/valid-xhtml10-blue\""
         << 	" alt=\"Valid XHTML 1.0 Strict\" height=\"31\" width=\"88\" /></a>"
         << "</p>" << endl;
    }
    
    void core::test()
    {
    cgi maincgi;
    	maincgi.request();
    	maincgi.urlencode();
    
    	string inhalt = maincgi.getcgidata("nav");
    	extern bool modul(string modulpath);
    	modul(inhalt);
    
    }
    
    void core::login()
    {
    html loginhtml;
    	loginhtml.createlayer("login","main");
    		loginhtml.startform("post", "loginform","index.cgi");
    			cout << "<p>";
    		loginhtml.input( "Username", "text");
    			cout << "<br/>";
    		loginhtml.input( "Username", "password");
    			cout << "<br/>";
    		loginhtml.input( "Login", "submit");
    			cout << "<br/>";
    			cout << "</p>";
    		loginhtml.endform();
    		loginhtml.link("Regristieren", "?+nav=module/register.so");
    			xhtmlstrict();
    loginhtml.endlayer();
    }
    
    void core::style()
    {
    	string style = "dark";
    	html stylehtml;
    	stylehtml.headstart(sitename);
    	cout << "<link rel=\"icon\" type=\"image/png\" href=\"style/"<< style <<"/images/icon.png\"/>" << endl;
    	cout << "<link rel=\"stylesheet\" type=\"text/css\" href=\"style/"<< style <<"/main.css\"/>" << endl;
    	stylehtml.headend();
    	stylehtml.bodystart();
    
    	stylehtml.createlayer("logo","main");
    		string imgtmp ="style/";
    		imgtmp += style;
    		imgtmp += "/images/logo.png";
    		cout << "<a href=\"?+nav=module/news.so\" >";
    		stylehtml.img("logo1", imgtmp);
    		cout << "</a>" << endl;
    		stylehtml.endlayer();
    }
    
    int main()
    {
    html mainhtml;
    core mainprog;
    
    string cmssqloptionstmp, sitenametmp;
    
    cmssqloptionstmp = mainprog.getconfig("cmsdatabase:");
    cmssqloptions = cmssqloptionstmp.c_str();
    
    sitenametmp = mainprog.getconfig("sitename:");
    sitename = sitenametmp.c_str();
    
    mainhtml.starthtml();
    	mainprog.style();
    
    	mainprog.login();
    
    		mainhtml.createlayer("navbar","main");
    			mainhtml.link("News","?+nav=module/news.so");
    			mainhtml.link("Video","?+nav=video");
    			mainhtml.link("Projects","http://projects.tuxist.de");
    			mainhtml.link("Downloads","?+nav=module/filebrowser.so");
    			mainhtml.link("Sysinfo","?+nav=module/sysinfo.so");
    			mainhtml.link("Apt","http://apt.tuxist.de");
    			mainhtml.link("MotoCross","http://motocross.tuxist.de");
    		mainhtml.endlayer();
    
    	mainprog.test();
    
    	mainhtml.bodyend();
    
    mainhtml.endhtml();
    }
    

    module.cpp

    /*
    Writen by Jan Koster releade under lgpl
    
    */
    #include <iostream>
    #include <dlfcn.h>
    #include <string>
    #include <easyc++.h>
    #include "module.h"
    
    using namespace std;
    
    bool modul(string modulpath){
    
    char* tmp = stringtochar(modulpath);
    
    using std::cout;
    using std::cerr;
    
    void* modul = dlopen(tmp, RTLD_LAZY);
    if (!modul) {
            cerr << "Cannot load library: " << dlerror() << '\n';
            return 1;
    }
    
    dlerror();
    
    create_t* create_modul = (create_t*) dlsym(modul, "create");
    const char* dlsym_error = dlerror();
    	if (dlsym_error) {
            	cerr << "Cannot load symbol create: " << dlsym_error << '\n';
    		return 1;
        	}
    
    destroy_t* destroy_modul = (destroy_t*) dlsym(modul, "destroy");
    dlsym_error = dlerror();
    	if (dlsym_error) {
            	cerr << "Cannot load symbol destroy: " << dlsym_error << '\n';
            	return 1;
    	}
    
        module* module = create_modul();
    
        module->htmlout();
    
        destroy_modul(module);
    
        dlclose(modul);
    
    	return 0;
    
    }
    

    module.h

    #ifndef module_H
    #define module_H
    
    class module {
    protected:
    
    public:
    virtual ~module() {}
    virtual void htmlout(){};
    };
    
    // the types of the class factories
    typedef module* create_t();
    typedef void destroy_t(module*);
    
    #endif
    
    bool modul(std::string modulpath);
    

    register.cpp

    #include <iostream>
    #include <string>
    #include <pqxx/connection>
    #include <pqxx/transaction>
    #include <pqxx/result>
    #include "register.h"
    #include "../../tuxcms.h"
    #include <html.h>
    #include <vector>
    #include <map>
    #include <cgi.h>
    #include <easyc++.h>
    
    using namespace std;
    using namespace PGSTD;
    using namespace pqxx;
    
    bool userreg::createuser()
    {
    
    }; 
    
    bool userreg::check()
    {
    cgi regist;
    string nickname = regist.getcgidata("NickName");
    //checknickname(nickname);
    cout << nickname << endl;
    }
    
    void userreg::regui()
    {
    html regis;
    regis.createlayer("register" ,"inhalt");
    cout << "<h2> Anmeldung auf " << sitename << "</h2><p></p>" << endl;
    regis.startform("GET","register","?+nav=module/register.so");
    cout << "NickName: ";
    regis.input("nickname","text");
    cout << "<p></p> Vorname: ";
    regis.input("surname","text");
    cout << "<p></p> Nachname: ";
    regis.input("lastname","text");
    cout << "<p></p> Birthday: ";
    regis.input("birthday","text");
    cout << "<p></p> Geschlecht: ";
    regis.formselect("gender", "<option>Männlich</option><option>Weiblich</option>");
    cout << "<p></p> Jabber: ";
    regis.input("jabber","text");
    cout << "<p></p> Email: ";
    regis.input("email@muster.net","text");
    cout << "<p></p>";
    regis.input("absenden","submit");
    regis.endform();
    regis.endlayer();
    }
    
    bool userreg::checknickname(string nickname)
    {
    	result R;
    
            connection *conn = new connection(cmssqloptions);
    
            work T(*conn);
    
            R = T.exec("SELECT * FROM NEWS");
            T.commit();
    }
    

    register.h

    #include "../../modul/module.h"
    #include <map>
    
    class userreg : public module
    {
    private:
    bool createuser();
    void regui();
    bool checknickname(std::string nickname);
    bool check();
    public:
    
    void htmlout()
    {
    check();
    regui();
    }
    
    };
    
    extern "C" module* create() {
        return new userreg;
    }
    
    extern "C" void destroy(module* p) {
        delete p;
    }
    

    cgi.cpp

    #include <iostream> 
    #include <string> 
    #include <fstream> 
    #include <vector>
    #include <map>
    #include <algorithm>
    #include "cgi.h"
    
    using std::vector;
    using namespace std;
    
    /*
    The cgi request function to get the cgi query_string 
    */
    
    bool cgi::request()
    {
    	query_string = string();
    	char *request = getenv("REQUEST_METHOD");
    	char *env = getenv("QUERY_STRING");
    	char *clength = getenv ("CONTENT_LENGTH");
    
    bool ret = false; 
     if(std::string(request) == std::string("GET") && env) 
       { 
         query_string = env; 
         ret = true; 
       } 
     else if(std::string(request) == std::string("POST") && clength) 
       { 
         getline(cin, query_string); 
         ret = true; 
       } 
    return ret;
    }
    
    /*
    This function formated the cgi input.
    */
    
    void cgi::urlencode()
    {
    
    	size_t len;
    	len = query_string.length();
    
    	for (std::size_t pos = query_string.find("+"); pos != std::string::npos; pos = query_string.find("+", ++pos)) 
            query_string.replace(pos, 1, " "); 
    
    	size_t pos = 0; 
    	size_t old_pos = 0; 
    
    	while(len > pos)
    		{
    
                     pos = query_string.find("&", old_pos); 
    
                     if (pos == string::npos) 
                     	pos = query_string.length();
    
    		query_tmp.push_back(query_string.substr(old_pos, pos-old_pos));
    
    		old_pos = pos+1; 	
    		};
    
    vector<string>::iterator copy;
    
    size_t start = 0;
    size_t end = 0;
    
    for(copy = query_tmp.begin(); copy != query_tmp.end(); copy++)
    {
    	const string tmp=*copy;
    
    	start = tmp.find("=");
    	end =++start;
    
    	query.insert(QueryPair(tmp.substr(1, ----start) ,tmp.substr(end)));
    }
    }
    
    //get query single ouput
    const string cgi::getcgidata(std::string formname)
    {
    
    Query::const_iterator search;
    
    search = query.find(formname);
    
      	 if(search == query.end())
      	 { 
       	  return "error"; 
      	 } 
    	return search->second;
    
    }
    

    cgi.h

    #include <iostream>
    #include <map>
    #include <algorithm>
    #include <vector>
    
    class cgi
    {
    private:
    typedef std::map<std::string,std::string > Query;
    typedef Query::value_type QueryPair;
    std::string query_string;
    
    Query query;
    
    std::vector<std::string> query_tmp;
    
    public:
    
    bool request(); //GET CGI DATA
    
    void urlencode(); // parse the CGI query_string
    
    const std::string getcgidata(std::string formname); // cgi single ouput
    
    };
    

    Wie kann ich das problem am besten lösen


Anmelden zum Antworten