IIPResponse.h
/*
IIP Response Handler Class
Copyright (C) 2003-2018 Ruven Pillay.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _IIPRESPONSE_H
#define _IIPRESPONSE_H
#ifndef VERSION
#define VERSION "0.9.9.9"
#endif
// Fix missing snprintf in Windows
#if defined _MSC_VER && _MSC_VER<1900
#define snprintf _snprintf
#endif
#include <string>
class IIPResponse{
private:
std::string server; // Server header
std::string powered; // Powered By header
std::string modified; // Last modified header
std::string cacheControl; // Cache control header
std::string mimeType; // Mime type header
std::string eof; // End of response delimitter eg "\r\n"
std::string protocol; // IIP protocol version
std::string responseBody; // The main response
std::string error; // Error message
std::string cors; // CORS (Cross-Origin Resource Sharing) setting
bool sent; // Indicate whether a response has been sent
public:
IIPResponse();
void setProtocol( const std::string& p ) { protocol = p; };
void setLastModified( const std::string& m ) { modified = "Last-Modified: " + m; };
void addResponse( const std::string& r );
void addResponse( const char* c );
void addResponse( const char* c, int a );
void addResponse( std::string c, const std::string& a );
void addResponse( const char* c, int a, int b );
void setError( const std::string& code, const std::string& arg );
void setCORS( const std::string& c ){
if(!c.empty()){
cors = "Access-Control-Allow-Origin: " + c + eof +
"Access-Control-Allow-Headers: X-Requested-With";
}
};
std::string getCORS(){ return cors; };
void setCacheControl( const std::string& c ){ cacheControl = "Cache-Control: " + c; };
std::string getCacheControl(){ return cacheControl; };
std::string formatResponse();
bool isSet(){
if( error.length() || responseBody.length() || protocol.length() ) return true;
else return false;
}
bool errorIsSet(){
if( error.length() ) return true;
else return false;
}
void setImageSent() { sent = true; };
bool imageSent() { return sent; };
std::string getAdvert();
};
#endif
IIPResponse::getAdvert
std::string getAdvert()
Display our advertising banner ;-).
IIPResponse::setCORS
void setCORS(const std::string &c)
Set CORS setting.
Definition IIPResponse.h:115
IIPResponse::imageSent
bool imageSent()
Indicate whether a response has been sent.
Definition IIPResponse.h:159
IIPResponse::errorIsSet
bool errorIsSet()
Indicate whether we have an error message.
Definition IIPResponse.h:148
IIPResponse::addResponse
void addResponse(const char *c, int a, int b)
Add a response string.
IIPResponse::addResponse
void addResponse(const char *c, int a)
Add a response string.
IIPResponse::setError
void setError(const std::string &code, const std::string &arg)
Set an error.
IIPResponse::isSet
bool isSet()
Indicate whether this object has had any arguments passed to it.
Definition IIPResponse.h:141
IIPResponse::IIPResponse
IIPResponse()
Constructor.
IIPResponse::addResponse
void addResponse(const char *c)
Add a response string.
IIPResponse::addResponse
void addResponse(std::string c, const std::string &a)
Add a response string.
IIPResponse::setCacheControl
void setCacheControl(const std::string &c)
Set Cache-Control value.
Definition IIPResponse.h:129
IIPResponse::setLastModified
void setLastModified(const std::string &m)
Set the Last Modified header.
Definition IIPResponse.h:71
IIPResponse::setImageSent
void setImageSent()
Set the sent flag indicating that some sort of response has been sent.
Definition IIPResponse.h:155
IIPResponse::setProtocol
void setProtocol(const std::string &p)
Set the IIP protocol version.
Definition IIPResponse.h:66
IIPResponse::getCORS
std::string getCORS()
Get CORS setting.
Definition IIPResponse.h:124
IIPResponse::getCacheControl
std::string getCacheControl()
Get Cache-Control value.
Definition IIPResponse.h:133
IIPResponse::addResponse
void addResponse(const std::string &r)
Add a response string.
IIPResponse::formatResponse
std::string formatResponse()
Get a formatted string to send back.