iipsrv  0.9.9
IIPResponse.h
1 /*
2  IIP Response Handler Class
3 
4  Copyright (C) 2003-2004 Ruven Pillay.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 
21 
22 #ifndef _IIPRESPONSE_H
23 #define _IIPRESPONSE_H
24 
25 #ifndef VERSION
26 #define VERSION "0.9.9.9"
27 #endif
28 
29 // Fix missing snprintf in Windows
30 #if _MSC_VER
31 #define snprintf _snprintf
32 #endif
33 
34 
35 #include <string>
36 
37 
39 
41 
42 
43  private:
44 
45  std::string server; // Server header
46  std::string modified; // Last modified header
47  std::string cache; // Cache control header
48  std::string mimeType; // Mime type header
49  std::string eof; // End of response delimitter eg "\r\n"
50  std::string protocol; // IIP protocol version
51  std::string responseBody; // The main response
52  std::string error; // Error message
53  bool sent; // Indicate whether a response has been sent
54 
55 
56  public:
57 
59  IIPResponse();
60 
61 
63 
64  void setProtocol( const std::string& p ) { protocol = p; };
65 
66 
68 
69  void setLastModified( const std::string& m ) { modified = "Last-Modified: " + m; };
70 
71 
73 
74  void addResponse( const std::string& r );
75 
76 
78 
79  void addResponse( const char* c );
80 
81 
83 
86  void addResponse( const char* c, int a );
87 
88 
90 
93  void addResponse( std::string c, const char* a );
94 
95 
97 
101  void addResponse( const char* c, int a, int b );
102 
103 
105 
108  void setError( const std::string& code, const std::string& arg );
109 
110 
112  std::string formatResponse();
113 
114 
116  bool isSet(){
117  if( error.length() || responseBody.length() || protocol.length() ) return true;
118  else return false;
119  }
120 
121 
123  bool errorIsSet(){
124  if( error.length() ) return true;
125  else return false;
126  }
127 
128 
130  void setImageSent() { sent = true; };
131 
132 
134  bool imageSent() { return sent; };
135 
136 
138 
139  std::string getAdvert( const std::string& version );
140 
141 
142 };
143 
144 
145 #endif