iipsrv 0.9.9
|
00001 /* 00002 IIP Response Handler Class 00003 00004 Copyright (C) 2003-2004 Ruven Pillay. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program 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 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 00021 00022 #ifndef _IIPRESPONSE_H 00023 #define _IIPRESPONSE_H 00024 00025 #ifndef VERSION 00026 #define VERSION "0.9.9.9" 00027 #endif 00028 00029 // Fix missing snprintf in Windows 00030 #if _MSC_VER 00031 #define snprintf _snprintf 00032 #endif 00033 00034 00035 #include <string> 00036 00037 00039 00040 class IIPResponse{ 00041 00042 00043 private: 00044 00045 std::string server; // Server header 00046 std::string modified; // Last modified header 00047 std::string cache; // Cache control header 00048 std::string mimeType; // Mime type header 00049 std::string eof; // End of response delimitter eg "\r\n" 00050 std::string protocol; // IIP protocol version 00051 std::string responseBody; // The main response 00052 std::string error; // Error message 00053 bool sent; // Indicate whether a response has been sent 00054 00055 00056 public: 00057 00059 IIPResponse(); 00060 00061 00063 00064 void setProtocol( const std::string& p ) { protocol = p; }; 00065 00066 00068 00069 void setLastModified( const std::string& m ) { modified = "Last-Modified: " + m; }; 00070 00071 00073 00074 void addResponse( const std::string& r ); 00075 00076 00078 00079 void addResponse( const char* c ); 00080 00081 00083 00086 void addResponse( const char* c, int a ); 00087 00088 00090 00093 void addResponse( std::string c, const char* a ); 00094 00095 00097 00101 void addResponse( const char* c, int a, int b ); 00102 00103 00105 00108 void setError( const std::string& code, const std::string& arg ); 00109 00110 00112 std::string formatResponse(); 00113 00114 00116 bool isSet(){ 00117 if( error.length() || responseBody.length() || protocol.length() ) return true; 00118 else return false; 00119 } 00120 00121 00123 bool errorIsSet(){ 00124 if( error.length() ) return true; 00125 else return false; 00126 } 00127 00128 00130 void setImageSent() { sent = true; }; 00131 00132 00134 bool imageSent() { return sent; }; 00135 00136 00138 00139 std::string getAdvert( const std::string& version ); 00140 00141 00142 }; 00143 00144 00145 #endif