summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2005-05-09 11:04:24 (UTC)
committer Michael Krelin <hacker@klever.net>2005-05-09 11:04:24 (UTC)
commit01e3789f5b7c3b2c0282b70eb203d11c76d3c8f3 (patch) (side-by-side diff)
tree580ebd4a1379c40cfbaa925849de2e42dd7cd441
parent981b219f5297ad2ccc1fc1d0e24e41ec009c35a3 (diff)
downloadsitecing-01e3789f5b7c3b2c0282b70eb203d11c76d3c8f3.zip
sitecing-01e3789f5b7c3b2c0282b70eb203d11c76d3c8f3.tar.gz
sitecing-01e3789f5b7c3b2c0282b70eb203d11c76d3c8f3.tar.bz2
made use of kingate's headers container.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/sitecing/sitecing_interface_cgi.h9
-rw-r--r--lib/sitecing_interface_cgi.cc2
2 files changed, 4 insertions, 7 deletions
diff --git a/include/sitecing/sitecing_interface_cgi.h b/include/sitecing/sitecing_interface_cgi.h
index da538d6..d17cdb7 100644
--- a/include/sitecing/sitecing_interface_cgi.h
+++ b/include/sitecing/sitecing_interface_cgi.h
@@ -1,83 +1,80 @@
#ifndef __SITECING_SITECING_INTERFACE_CGI_H
#define __SITECING_SITECING_INTERFACE_CGI_H
#include <sstream>
#include <string>
#include <map>
-#include "kingate/cgi_gateway.h"
+#include <kingate/cgi_gateway.h>
+#include <kingate/headers.h>
#include "sitecing/sitecing_interface.h"
#include "sitecing/sitespace.h"
/**
* @file
* @brief The sitecing_interface_cgi class declaration.
*/
namespace sitecing {
using namespace std;
/**
* The interface to site-C-ing core for the CGI component.
*/
class sitecing_interface_cgi : public sitecing_interface {
public:
/**
* Pointer to the CGI gateway interface.
*/
kingate::cgi_gateway* cgigw;
/**
- * Type for the map of headers to spit out.
- */
- typedef map<string,string> headers_t;
- /**
* The list of headers to spit out.
*/
- headers_t headers;
+ kingate::headers headers;
/**
* Here is where we prebuffer output.
*/
stringbuf prebuffer;
/**
* Output stream, initially going to prebuffer.
*/
ostream outs;
/**
* Have headers been sent yet?
*/
bool headers_flushed;
/**
* Pointer to the sitespace object.
*/
sitespace *ss; // XXX: or does it belong to the generic interface? or should this 'generic' interface exist at all?
/**
* @param s Pointer to the sitespace object.
*/
sitecing_interface_cgi(sitespace *s);
/**
* Set up interface for the (possibly, new) cgi gateway object,
* reset headers, empty buffer, etc.
*/
void prepare(kingate::cgi_gateway *cg);
/**
* Flush output stream.
*/
void flush(bool keep_buffering=false);
/**
* Send headers to the output stream, if we haven't yet.
*/
void flush_headers();
/**
* Are we buffering now?
*/
bool is_buffering();
/**
* Control output buffering.
*/
void set_buffering(bool do_buffer);
};
}
#endif /* __SITECING_SITECING_INTERFACE_CGI_H */
diff --git a/lib/sitecing_interface_cgi.cc b/lib/sitecing_interface_cgi.cc
index f2bd093..59ae25a 100644
--- a/lib/sitecing_interface_cgi.cc
+++ b/lib/sitecing_interface_cgi.cc
@@ -1,51 +1,51 @@
#include <cassert>
#include "sitecing/sitecing_interface_cgi.h"
namespace sitecing {
sitecing_interface_cgi::sitecing_interface_cgi(sitespace *s)
: outs(&prebuffer), sitecing_interface(&outs), ss(s), cgigw(NULL), headers_flushed(false) {
}
void sitecing_interface_cgi::prepare(kingate::cgi_gateway *cg) {
cgigw = cg;
headers.clear();
headers["Content-Type"] = "text/html";
prebuffer.str("");
headers_flushed = false;
set_buffering(true);
}
void sitecing_interface_cgi::flush(bool keep_buffering) {
assert(cgigw);
flush_headers();
if(is_buffering()) {
streampos count = prebuffer.pubseekoff(0,ios_base::cur,ios_base::out);
cgigw->out().write(prebuffer.str().c_str(),count);
prebuffer.str("");
}
cgigw->out().flush();
set_buffering(keep_buffering);
}
void sitecing_interface_cgi::set_buffering(bool do_buffer) {
if(!do_buffer)
flush_headers();
outs.rdbuf(do_buffer?&prebuffer:cgigw->out().rdbuf());
}
bool sitecing_interface_cgi::is_buffering() {
return outs.rdbuf()==&prebuffer;
}
void sitecing_interface_cgi::flush_headers() {
assert(cgigw);
if(headers_flushed)
return;
- for(headers_t::const_iterator i=headers.begin();i!=headers.end();i++)
+ for(kingate::headers::const_iterator i=headers.begin();i!=headers.end();i++)
cgigw->out() << i->first << ": " << i->second << "\n";
cgigw->out() << "\n";
headers_flushed = true;
}
}