00001
00002
00003
00004
00005
00006
00007
00009
00010
00011
00012
00013 #ifndef HTML_H
00014 #define HTML_H
00015
00016 #include "magic/mobject.h"
00017 #include "magic/mmap.h"
00018
00019
00020
00021 class HTMLQuery : public Object {
00022 decl_dynamic (HTMLQuery);
00023 public:
00024
00025 int contlen;
00026 String contype;
00027 String docroot;
00028 String gwif;
00029 String hosttype;
00030 String httpaccpt;
00031 String httppragma;
00032 String useragent;
00033 String pathinfo;
00034 String pathtrans;
00035 String querystr;
00036 String remaddr;
00037 String remhost;
00038 String method;
00039 String sptname;
00040 String srvname;
00041 int srvport;
00042 String srvprot;
00043 String srvsoft;
00044
00045 Map<String,String> query;
00046
00047
00048 HTMLQuery ();
00049
00050
00051 const String& operator [] (const String& key) const {return query[key];}
00052
00053
00054 void printhidden () const;
00055
00056
00057
00058
00059 virtual void any ();
00060
00061
00062 int call (const String& pagename);
00063 };
00064
00065
00066 class HTMLPageBase : public Object {
00067 decl_dynamic (HTMLPageBase);
00068
00069 public:
00070 HTMLPageBase () {;}
00071
00072
00073
00074 virtual void printqry (HTMLQuery& qry) {
00075 content ();
00076 title ("Error");
00077 printf ("<H1>Error - no print method in page handler</H1>\n");
00078 }
00079
00080
00081 void content (const char* str="text/html") {
00082 printf ("Content-type: text/html\n\n");
00083 }
00084
00085
00086 void title (const char* str) const {
00087 printf ("<TITLE>%s</TITLE>\n", str);
00088 }
00089 };
00090
00091
00092
00093
00094
00095
00096
00097
00098 #define HTMLPage(CLASS,APPCLASS) \
00099 class CLASS : public HTMLPageBase {\
00100 decl_dynamic (CLASS);\
00101 public:\
00102 CLASS () {;}\
00103 void print (APPCLASS& app);\
00104 void printqry (HTMLQuery& qry) {\
00105 if (APPCLASS* app = dynamic_cast<APPCLASS*>(&qry))\
00106 print (*app);\
00107 }\
00108 };\
00109 impl_dynamic (CLASS, "HTMLPageBase");\
00110 void CLASS::print (APPCLASS& query)
00111
00112
00113 #define ASSERTHTML(expr,message) {if (!(expr)) {cout << "Content-type: text/html\n\n<H3>%ERR: Violation of assertion at " << __FILE__ << "[" << __LINE__ << "].</H3>\n%ERR: " << message << "\n"; exit (2);}}
00114
00115 #define DIEHTML(message) {cout << "Content-type: text/html\n\n<H3>%ERR: Unconditional death at " << __FILE__ << "[" << __LINE__ << "].</H3>\n%ERR: " << message << "\n"; exit (2);}
00116
00117 #endif