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