iipsrv 1.1
iipsrv is an advanced high-performance feature-rich image server for web-based streamed viewing and zooming of ultra high-resolution images
IIPResponse.h
1/*
2 IIP Response Handler Class
3
4 Copyright (C) 2003-2018 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 3 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 Foundation,
18 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 defined _MSC_VER && _MSC_VER<1900
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 powered; // Powered By header
47 std::string modified; // Last modified header
48 std::string cacheControl; // Cache control header
49 std::string mimeType; // Mime type header
50 std::string eof; // End of response delimitter eg "\r\n"
51 std::string protocol; // IIP protocol version
52 std::string responseBody; // The main response
53 std::string error; // Error message
54 std::string cors; // CORS (Cross-Origin Resource Sharing) setting
55 bool sent; // Indicate whether a response has been sent
56
57
58 public:
59
62
63
65
66 void setProtocol( const std::string& p ) { protocol = p; };
67
68
70
71 void setLastModified( const std::string& m ) { modified = "Last-Modified: " + m; };
72
73
75
76 void addResponse( const std::string& r );
77
78
80
81 void addResponse( const char* c );
82
83
85
88 void addResponse( const char* c, int a );
89
90
92
95 void addResponse( std::string c, const std::string& a );
96
97
99
103 void addResponse( const char* c, int a, int b );
104
105
107
110 void setError( const std::string& code, const std::string& arg );
111
112
114
115 void setCORS( const std::string& c ){
116 if(!c.empty()){
117 cors = "Access-Control-Allow-Origin: " + c + eof +
118 "Access-Control-Allow-Headers: X-Requested-With";
119 }
120 };
121
122
124 std::string getCORS(){ return cors; };
125
126
128
129 void setCacheControl( const std::string& c ){ cacheControl = "Cache-Control: " + c; };
130
131
133 std::string getCacheControl(){ return cacheControl; };
134
135
137 std::string formatResponse();
138
139
141 bool isSet(){
142 if( error.length() || responseBody.length() || protocol.length() ) return true;
143 else return false;
144 }
145
146
149 if( error.length() ) return true;
150 else return false;
151 }
152
153
155 void setImageSent() { sent = true; };
156
157
159 bool imageSent() { return sent; };
160
161
163
164 std::string getAdvert();
165
166
167};
168
169
170#endif
Class to handle non-image IIP responses including errors.
Definition: IIPResponse.h:40
std::string getAdvert()
Display our advertising banner ;-)
void setCORS(const std::string &c)
Set CORS setting.
Definition: IIPResponse.h:115
bool imageSent()
Indicate whether a response has been sent.
Definition: IIPResponse.h:159
bool errorIsSet()
Indicate whether we have an error message.
Definition: IIPResponse.h:148
void addResponse(const char *c, int a, int b)
Add a response string.
void addResponse(const char *c, int a)
Add a response string.
void setError(const std::string &code, const std::string &arg)
Set an error.
bool isSet()
Indicate whether this object has had any arguments passed to it.
Definition: IIPResponse.h:141
IIPResponse()
Constructor.
void addResponse(const char *c)
Add a response string.
void addResponse(std::string c, const std::string &a)
Add a response string.
void setCacheControl(const std::string &c)
Set Cache-Control value.
Definition: IIPResponse.h:129
void setLastModified(const std::string &m)
Set the Last Modified header.
Definition: IIPResponse.h:71
void setImageSent()
Set the sent flag indicating that some sort of response has been sent.
Definition: IIPResponse.h:155
void setProtocol(const std::string &p)
Set the IIP protocol version.
Definition: IIPResponse.h:66
std::string getCORS()
Get CORS setting.
Definition: IIPResponse.h:124
std::string getCacheControl()
Get Cache-Control value.
Definition: IIPResponse.h:133
void addResponse(const std::string &r)
Add a response string.
std::string formatResponse()
Get a formatted string to send back.