00001 /***************************** License ********************************** 00002 00003 Copyright (C) 2008 by Communicative Machines 00004 http://www.cmlabs.com All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 ************************************************************************/ 00021 00022 00023 // HTML.h: interface for the HTMLPage and HTTPRequest classes. 00024 // 00025 ////////////////////////////////////////////////////////////////////// 00026 00027 #if !defined(__HTML__) 00028 #define __HTML__ 00029 00030 #include "standard.h" 00031 #include "JTime.h" 00032 #include "Collection.h" 00033 #include "Dictionary.h" 00034 #include "NetworkConnection.h" 00035 #include "JFile.h" 00036 00037 namespace cmlabs { 00038 00039 class Bitmap; 00040 class HTMLPage : public Object 00041 { 00042 public: 00043 HTMLPage(); 00044 HTMLPage(const JString& title, const JString& bodyhtml); 00045 HTMLPage(char* rawdata, int len, const JString& type); 00046 HTMLPage(Bitmap* bitmap); 00047 HTMLPage(const JString& filename); 00048 HTMLPage(XMLNode* node); 00049 virtual ~HTMLPage(); 00050 00051 static HTMLPage* createSimplePage(const JString& title, const JString& msg); 00052 static HTMLPage* createErrorPage(const JString& title, const JString& msg); 00053 00054 00055 bool fromXML(XMLNode* node); 00056 JString toXML(); 00057 //! Get total size of payload 00058 virtual unsigned long getPayloadSize() const; 00059 00060 Object* clone() const; 00061 bool generateHTML(); 00062 bool generateHTMLfromFile(const JString& filename); 00063 bool generateHTMLfromXML(const JString& xml); 00064 bool generateHTMLfromRawData(); 00065 bool generateUseLocalCopyPage(); 00066 bool generateMovedPermanentlyPage(); 00067 static JString printErrorHTML(const JString& title = "", const JString& msg = ""); 00068 static JString printSimpleHTML(const JString& title = "", const JString& msg = ""); 00069 bool readFile(const JString& filename, bool isBinary); 00070 bool setXMLContent(const JString& xml); 00071 bool setMovedPermanently(const JString& location); 00072 00073 JString rootdir; 00074 JString htmlFilename; 00075 JString title; 00076 JString body; 00077 JString location; 00078 JString everything; 00079 JString frameset; 00080 JString xmlData; 00081 char* data; 00082 int datalength; 00083 char* rawData; 00084 int rawDataLength; 00085 JString rawDataType; 00086 00087 JString autoRefreshPage; 00088 int autoRefresh; 00089 JString connectionType; 00090 bool keep_alive; 00091 00092 bool noCaching; 00093 bool useLocalCopy; 00094 bool movedPermanently; 00095 00096 JString bodyBGColor; 00097 JString bodyFGColor; 00098 00099 private: 00100 void init(); 00101 JString generateHeader(int length); 00102 00103 }; 00104 00105 class HTTPRequest : public Object 00106 { 00107 public: 00108 HTTPRequest(); 00109 HTTPRequest(const JString& xml); 00110 HTTPRequest(XMLNode* node); 00111 virtual ~HTTPRequest(); 00112 00113 Object* clone() const; 00114 bool fromXML(const JString& xml); 00115 bool fromXML(XMLNode* node); 00116 JString toXML(); 00117 00118 bool addEntry(const JString& str); 00119 bool addEntry(const JString& key, const JString& val); 00120 JString getEntry(const JString& str); 00121 00122 JString getCommand(); 00123 JString getRequestPage(); 00124 JString getProtocol(); 00125 JString getProtocolVersion(); 00126 JString getParameter(const JString& key); 00127 bool hasParameter(const JString& key); 00128 00129 bool shouldKeepAlive(); 00130 bool isComplete(JSocket* socket); 00131 bool isComplete(NetworkConnection* con); 00132 bool createParameterDictionary(const JString& post); 00133 00134 Dictionary entries; 00135 Dictionary paramdict; 00136 00137 private: 00138 void init(); 00139 00140 int postBytesStillRemaining; 00141 bool complete; 00142 bool keep_alive; 00143 JTime ifModifiedSince; 00144 00145 }; 00146 00147 } // namespace cmlabs 00148 00149 #include "Bitmap.h" 00150 00151 #endif // __HTML__ 00152 00153