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) (unidiff)
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 @@
1#ifndef __SITECING_SITECING_INTERFACE_CGI_H 1#ifndef __SITECING_SITECING_INTERFACE_CGI_H
2#define __SITECING_SITECING_INTERFACE_CGI_H 2#define __SITECING_SITECING_INTERFACE_CGI_H
3 3
4#include <sstream> 4#include <sstream>
5#include <string> 5#include <string>
6#include <map> 6#include <map>
7#include "kingate/cgi_gateway.h" 7#include <kingate/cgi_gateway.h>
8#include <kingate/headers.h>
8#include "sitecing/sitecing_interface.h" 9#include "sitecing/sitecing_interface.h"
9#include "sitecing/sitespace.h" 10#include "sitecing/sitespace.h"
10 11
11/** 12/**
12 * @file 13 * @file
13 * @brief The sitecing_interface_cgi class declaration. 14 * @brief The sitecing_interface_cgi class declaration.
14 */ 15 */
15 16
16namespace sitecing { 17namespace sitecing {
17 using namespace std; 18 using namespace std;
18 19
19 /** 20 /**
20 * The interface to site-C-ing core for the CGI component. 21 * The interface to site-C-ing core for the CGI component.
21 */ 22 */
22 class sitecing_interface_cgi : public sitecing_interface { 23 class sitecing_interface_cgi : public sitecing_interface {
23 public: 24 public:
24 /** 25 /**
25 * Pointer to the CGI gateway interface. 26 * Pointer to the CGI gateway interface.
26 */ 27 */
27 kingate::cgi_gateway* cgigw; 28 kingate::cgi_gateway* cgigw;
28 /** 29 /**
29 * Type for the map of headers to spit out.
30 */
31 typedef map<string,string> headers_t;
32 /**
33 * The list of headers to spit out. 30 * The list of headers to spit out.
34 */ 31 */
35 headers_t headers; 32 kingate::headers headers;
36 /** 33 /**
37 * Here is where we prebuffer output. 34 * Here is where we prebuffer output.
38 */ 35 */
39 stringbuf prebuffer; 36 stringbuf prebuffer;
40 /** 37 /**
41 * Output stream, initially going to prebuffer. 38 * Output stream, initially going to prebuffer.
42 */ 39 */
43 ostream outs; 40 ostream outs;
44 /** 41 /**
45 * Have headers been sent yet? 42 * Have headers been sent yet?
46 */ 43 */
47 bool headers_flushed; 44 bool headers_flushed;
48 /** 45 /**
49 * Pointer to the sitespace object. 46 * Pointer to the sitespace object.
50 */ 47 */
51 sitespace *ss; // XXX: or does it belong to the generic interface? or should this 'generic' interface exist at all? 48 sitespace *ss; // XXX: or does it belong to the generic interface? or should this 'generic' interface exist at all?
52 49
53 /** 50 /**
54 * @param s Pointer to the sitespace object. 51 * @param s Pointer to the sitespace object.
55 */ 52 */
56 sitecing_interface_cgi(sitespace *s); 53 sitecing_interface_cgi(sitespace *s);
57 54
58 /** 55 /**
59 * Set up interface for the (possibly, new) cgi gateway object, 56 * Set up interface for the (possibly, new) cgi gateway object,
60 * reset headers, empty buffer, etc. 57 * reset headers, empty buffer, etc.
61 */ 58 */
62 void prepare(kingate::cgi_gateway *cg); 59 void prepare(kingate::cgi_gateway *cg);
63 /** 60 /**
64 * Flush output stream. 61 * Flush output stream.
65 */ 62 */
66 void flush(bool keep_buffering=false); 63 void flush(bool keep_buffering=false);
67 /** 64 /**
68 * Send headers to the output stream, if we haven't yet. 65 * Send headers to the output stream, if we haven't yet.
69 */ 66 */
70 void flush_headers(); 67 void flush_headers();
71 /** 68 /**
72 * Are we buffering now? 69 * Are we buffering now?
73 */ 70 */
74 bool is_buffering(); 71 bool is_buffering();
75 /** 72 /**
76 * Control output buffering. 73 * Control output buffering.
77 */ 74 */
78 void set_buffering(bool do_buffer); 75 void set_buffering(bool do_buffer);
79 76
80 }; 77 };
81} 78}
82 79
83#endif /* __SITECING_SITECING_INTERFACE_CGI_H */ 80#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 @@
1#include <cassert> 1#include <cassert>
2#include "sitecing/sitecing_interface_cgi.h" 2#include "sitecing/sitecing_interface_cgi.h"
3 3
4namespace sitecing { 4namespace sitecing {
5 5
6 sitecing_interface_cgi::sitecing_interface_cgi(sitespace *s) 6 sitecing_interface_cgi::sitecing_interface_cgi(sitespace *s)
7 : outs(&prebuffer), sitecing_interface(&outs), ss(s), cgigw(NULL), headers_flushed(false) { 7 : outs(&prebuffer), sitecing_interface(&outs), ss(s), cgigw(NULL), headers_flushed(false) {
8 } 8 }
9 9
10 void sitecing_interface_cgi::prepare(kingate::cgi_gateway *cg) { 10 void sitecing_interface_cgi::prepare(kingate::cgi_gateway *cg) {
11 cgigw = cg; 11 cgigw = cg;
12 headers.clear(); 12 headers.clear();
13 headers["Content-Type"] = "text/html"; 13 headers["Content-Type"] = "text/html";
14 prebuffer.str(""); 14 prebuffer.str("");
15 headers_flushed = false; 15 headers_flushed = false;
16 set_buffering(true); 16 set_buffering(true);
17 } 17 }
18 18
19 void sitecing_interface_cgi::flush(bool keep_buffering) { 19 void sitecing_interface_cgi::flush(bool keep_buffering) {
20 assert(cgigw); 20 assert(cgigw);
21 flush_headers(); 21 flush_headers();
22 if(is_buffering()) { 22 if(is_buffering()) {
23 streampos count = prebuffer.pubseekoff(0,ios_base::cur,ios_base::out); 23 streampos count = prebuffer.pubseekoff(0,ios_base::cur,ios_base::out);
24 cgigw->out().write(prebuffer.str().c_str(),count); 24 cgigw->out().write(prebuffer.str().c_str(),count);
25 prebuffer.str(""); 25 prebuffer.str("");
26 } 26 }
27 cgigw->out().flush(); 27 cgigw->out().flush();
28 set_buffering(keep_buffering); 28 set_buffering(keep_buffering);
29 } 29 }
30 30
31 void sitecing_interface_cgi::set_buffering(bool do_buffer) { 31 void sitecing_interface_cgi::set_buffering(bool do_buffer) {
32 if(!do_buffer) 32 if(!do_buffer)
33 flush_headers(); 33 flush_headers();
34 outs.rdbuf(do_buffer?&prebuffer:cgigw->out().rdbuf()); 34 outs.rdbuf(do_buffer?&prebuffer:cgigw->out().rdbuf());
35 } 35 }
36 36
37 bool sitecing_interface_cgi::is_buffering() { 37 bool sitecing_interface_cgi::is_buffering() {
38 return outs.rdbuf()==&prebuffer; 38 return outs.rdbuf()==&prebuffer;
39 } 39 }
40 40
41 void sitecing_interface_cgi::flush_headers() { 41 void sitecing_interface_cgi::flush_headers() {
42 assert(cgigw); 42 assert(cgigw);
43 if(headers_flushed) 43 if(headers_flushed)
44 return; 44 return;
45 for(headers_t::const_iterator i=headers.begin();i!=headers.end();i++) 45 for(kingate::headers::const_iterator i=headers.begin();i!=headers.end();i++)
46 cgigw->out() << i->first << ": " << i->second << "\n"; 46 cgigw->out() << i->first << ": " << i->second << "\n";
47 cgigw->out() << "\n"; 47 cgigw->out() << "\n";
48 headers_flushed = true; 48 headers_flushed = true;
49 } 49 }
50 50
51} 51}