#include "cgilet.h"

using namespace cgid;

extern "C" {
extern void * create_cgi();
}

class HelloWorld : public CGILet {
public:
   void process_request(tcp_stream & out, FormData & form_data) {
      cout << "Hello, " << form_data.get_value("name") << "!\n";

      if(form_data["embed"] != "true") 
         out << "Content-type: text/html\r\n\r\n";

      out << "Hello, " << form_data.get_value("name") << "!\n";

      out << "<BR><BR>\n";
      out << "GET:<BR>\n";
      out << "<FORM METHOD=GET ACTION=/gateway.php>\n"
          << "<INPUT TYPE=HIDDEN NAME=cgilet VALUE=hello>\n"
          << "Name: <INPUT TYPE=TEXT NAME=name><BR><INPUT TYPE=SUBMIT><BR>\n"
          << "</FORM>\n\n";

      out << "POST:<BR>\n";
      out << "<FORM METHOD=POST ACTION=/gateway.php>\n"
          << "<INPUT TYPE=HIDDEN NAME=cgilet VALUE=hello>\n"
          << "Name: <INPUT TYPE=TEXT NAME=name><BR><INPUT TYPE=SUBMIT><BR>\n"
          << "</FORM>\n\n";

      out << "PERSON:<BR>\n";
      out << "<FORM METHOD=GET ACTION=/gateway.php>\n"
          << "<INPUT TYPE=HIDDEN NAME=cgilet VALUE=person>\n"
          << "<INPUT TYPE=SUBMIT><BR>\n"
          << "</FORM>\n\n";


   }
};

void * create_cgi() {
   return new HelloWorld();
}
