summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2005-06-11 14:49:35 (UTC)
committer Michael Krelin <hacker@klever.net>2005-06-11 14:49:35 (UTC)
commit621221c40a42683a185b15b99c03fd6c8b6f7d90 (patch) (unidiff)
tree061f1e7a9fb7b16122eed9715c1a180629dbd953
parent01e3789f5b7c3b2c0282b70eb203d11c76d3c8f3 (diff)
downloadsitecing-621221c40a42683a185b15b99c03fd6c8b6f7d90.zip
sitecing-621221c40a42683a185b15b99c03fd6c8b6f7d90.tar.gz
sitecing-621221c40a42683a185b15b99c03fd6c8b6f7d90.tar.bz2
1. added missing include
2. fixed typo in Makefile 3. fixed zero-size output segfault
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/sitecing/acomponent.h1
-rw-r--r--lib/sitecing_interface_cgi.cc4
-rw-r--r--src/Makefile.am2
3 files changed, 5 insertions, 2 deletions
diff --git a/include/sitecing/acomponent.h b/include/sitecing/acomponent.h
index 160e854..461f8a6 100644
--- a/include/sitecing/acomponent.h
+++ b/include/sitecing/acomponent.h
@@ -1,78 +1,79 @@
1#ifndef __SITECING_ACOMPONENT_H 1#ifndef __SITECING_ACOMPONENT_H
2#define __SITECING_ACOMPONENT_H 2#define __SITECING_ACOMPONENT_H
3 3
4#include <cstdarg>
4#include "sitecing/sitecing_interface.h" 5#include "sitecing/sitecing_interface.h"
5 6
6/** 7/**
7 * @file 8 * @file
8 * @brief The acomponent class declaration. 9 * @brief The acomponent class declaration.
9 */ 10 */
10 11
11namespace sitecing { 12namespace sitecing {
12 13
13 /** 14 /**
14 * An abstract base class for sitecing components. 15 * An abstract base class for sitecing components.
15 */ 16 */
16 class acomponent { 17 class acomponent {
17 public: 18 public:
18 /** 19 /**
19 * Pointer to the interface object, used to communicate with the 20 * Pointer to the interface object, used to communicate with the
20 * site-C-ing core. 21 * site-C-ing core.
21 */ 22 */
22 sitecing_interface *__SCIF; 23 sitecing_interface *__SCIF;
23 24
24 acomponent(); 25 acomponent();
25 virtual ~acomponent(); 26 virtual ~acomponent();
26 27
27 /** 28 /**
28 * Set the interface to core pointer. 29 * Set the interface to core pointer.
29 * @param scif the pointer to the interface object. 30 * @param scif the pointer to the interface object.
30 */ 31 */
31 virtual void __set_interface(sitecing_interface *scif=0); 32 virtual void __set_interface(sitecing_interface *scif=0);
32 /** 33 /**
33 * Invoked if the interface to the core has changed. 34 * Invoked if the interface to the core has changed.
34 * @param oscif pointer to the old interface object. 35 * @param oscif pointer to the old interface object.
35 */ 36 */
36 virtual void __on_change_interface(sitecing_interface *oscif); 37 virtual void __on_change_interface(sitecing_interface *oscif);
37 38
38 /** 39 /**
39 * do import components. 40 * do import components.
40 */ 41 */
41 virtual void __do_imports(); 42 virtual void __do_imports();
42 /** 43 /**
43 * invoked on components imports. 44 * invoked on components imports.
44 */ 45 */
45 virtual void __on_imports(); 46 virtual void __on_imports();
46 /** 47 /**
47 * fetch the pointer to the most derived component. 48 * fetch the pointer to the most derived component.
48 * @returns pointer to the most derived object. 49 * @returns pointer to the most derived object.
49 */ 50 */
50 virtual void *__the_most_derived_this() = 0; 51 virtual void *__the_most_derived_this() = 0;
51 52
52 /** 53 /**
53 * Do the job. 54 * Do the job.
54 * @param __magic the magic number used as a key to decipher the 55 * @param __magic the magic number used as a key to decipher the
55 * rest of parameters. 56 * rest of parameters.
56 * @param __args the parameters. 57 * @param __args the parameters.
57 */ 58 */
58 virtual void main(int __magic,va_list __args) = 0; 59 virtual void main(int __magic,va_list __args) = 0;
59 60
60 /** 61 /**
61 * Run the component. Convenience helper for calling main(). 62 * Run the component. Convenience helper for calling main().
62 * @param __magic the magic number. 63 * @param __magic the magic number.
63 * @param ... the rest of parameters. 64 * @param ... the rest of parameters.
64 * @see main(); 65 * @see main();
65 */ 66 */
66 void run(int __magic,...); 67 void run(int __magic,...);
67 68
68 /** 69 /**
69 * Helper function (which doesn't necessarily belongs here!) for 70 * Helper function (which doesn't necessarily belongs here!) for
70 * reading the file and passing it to the output stream. 71 * reading the file and passing it to the output stream.
71 * @param fn the file name. 72 * @param fn the file name.
72 */ 73 */
73 void pass_file_through(const char *fn); 74 void pass_file_through(const char *fn);
74 }; 75 };
75 76
76} 77}
77 78
78#endif /* __SITECING_ACOMPONENT_H */ 79#endif /* __SITECING_ACOMPONENT_H */
diff --git a/lib/sitecing_interface_cgi.cc b/lib/sitecing_interface_cgi.cc
index 59ae25a..1acb23c 100644
--- a/lib/sitecing_interface_cgi.cc
+++ b/lib/sitecing_interface_cgi.cc
@@ -1,51 +1,53 @@
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 if(count>0) {
25 cgigw->out().write(prebuffer.str().c_str(),count);
26 }
25 prebuffer.str(""); 27 prebuffer.str("");
26 } 28 }
27 cgigw->out().flush(); 29 cgigw->out().flush();
28 set_buffering(keep_buffering); 30 set_buffering(keep_buffering);
29 } 31 }
30 32
31 void sitecing_interface_cgi::set_buffering(bool do_buffer) { 33 void sitecing_interface_cgi::set_buffering(bool do_buffer) {
32 if(!do_buffer) 34 if(!do_buffer)
33 flush_headers(); 35 flush_headers();
34 outs.rdbuf(do_buffer?&prebuffer:cgigw->out().rdbuf()); 36 outs.rdbuf(do_buffer?&prebuffer:cgigw->out().rdbuf());
35 } 37 }
36 38
37 bool sitecing_interface_cgi::is_buffering() { 39 bool sitecing_interface_cgi::is_buffering() {
38 return outs.rdbuf()==&prebuffer; 40 return outs.rdbuf()==&prebuffer;
39 } 41 }
40 42
41 void sitecing_interface_cgi::flush_headers() { 43 void sitecing_interface_cgi::flush_headers() {
42 assert(cgigw); 44 assert(cgigw);
43 if(headers_flushed) 45 if(headers_flushed)
44 return; 46 return;
45 for(kingate::headers::const_iterator i=headers.begin();i!=headers.end();i++) 47 for(kingate::headers::const_iterator i=headers.begin();i!=headers.end();i++)
46 cgigw->out() << i->first << ": " << i->second << "\n"; 48 cgigw->out() << i->first << ": " << i->second << "\n";
47 cgigw->out() << "\n"; 49 cgigw->out() << "\n";
48 headers_flushed = true; 50 headers_flushed = true;
49 } 51 }
50 52
51} 53}
diff --git a/src/Makefile.am b/src/Makefile.am
index 2ec650d..e6fb31a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,37 +1,37 @@
1bin_PROGRAMS = sitecing-build 1bin_PROGRAMS = sitecing-build
2 2
3if HAVE_FCGI 3if HAVE_FCGI
4bin_PROGRAMS += sitecing-fastcgi 4bin_PROGRAMS += sitecing-fastcgi
5endif 5endif
6if HAVE_PLAINCGI 6if HAVE_PLAINCGI
7bin_PROGRAMS += sitecing-plaincgi 7bin_PROGRAMS += sitecing-plaincgi
8endif 8endif
9 9
10INCLUDES = -I${top_srcdir}/include ${KINGATE_CFLAGS} ${DOTCONF_CFLAGS} \ 10INCLUDES = -I${top_srcdir}/include ${KINGATE_CFLAGS} ${DOTCONF_CFLAGS} \
11 ${PCREPP_CFLAGS} 11 ${PCREPP_CFLAGS}
12LIBS += ${top_builddir}/lib/libsitecing.la ${DOTCONF_LIBS} \ 12LIBS += ${top_builddir}/lib/libsitecing.la ${DOTCONF_LIBS} \
13 ${PCREPP_LIBS} 13 ${PCREPP_LIBS}
14 14
15sitecing_fastcgi_SOURCES = sitecing-fastcgi.cc \ 15sitecing_fastcgi_SOURCES = sitecing-fastcgi.cc \
16 COPYING.cc 16 COPYING.cc
17sitecing_fastcgi_LDADD = ${KINGATE_FCGI_LIBS} 17sitecing_fastcgi_LDADD = ${KINGATE_FCGI_LIBS}
18sitecing_fastcgi_LDFLAGS = -rdynamic 18sitecing_fastcgi_LDFLAGS = -rdynamic
19sitecing_fastcgi_DEPENDENCIES = ${top_builddir}/lib/libsitecing.la 19sitecing_fastcgi_DEPENDENCIES = ${top_builddir}/lib/libsitecing.la
20 20
21sitecing_plaincgi_SOURCES = sitecing-plaincgi.cc \ 21sitecing_plaincgi_SOURCES = sitecing-plaincgi.cc \
22 COPYING.cc 22 COPYING.cc
23sitecing_plaincgi_LDFLAGS = -rdynamic 23sitecing_plaincgi_LDFLAGS = -rdynamic
24sitecing_plaincgi_LDADD = ${KINGATE_PLAINCGI_LIBS} 24sitecing_plaincgi_LDADD = ${KINGATE_PLAINCGI_LIBS}
25sitecing_plaincgi_DEPENDENCIES = ${top_builddir}/lib/libsitecing.la 25sitecing_plaincgi_DEPENDENCIES = ${top_builddir}/lib/libsitecing.la
26 26
27sitecing_build_SOURCES = sitecing-build.cc \ 27sitecing_build_SOURCES = sitecing-build.cc \
28 COPYING.cc 28 COPYING.cc
29sitecing_build_LDADD = ${KINGATE_LIBS} 29sitecing_build_LDADD = ${KINGATE_LIBS}
30sitecing_build_DEPENDENCIES = ${top_builddir}/lib/libsitecing.la 30sitecing_build_DEPENDENCIES = ${top_builddir}/lib/libsitecing.la
31 31
32COPYING.cc: ${top_srcdir}/COPYING 32COPYING.cc: ${top_srcdir}/COPYING
33 echo "const char * COPYING =" >$@ || (rm $@;exit 1) 33 echo "const char * COPYING =" >$@ || (rm $@;exit 1)
34 sed 's/"/\\"/g' $< | sed 's/^/\"/' | sed 's/$$/\\n\"/' >>$@ || (rm $@;exit 1) 34 sed 's/"/\\"/g' $< | sed 's/^/\"/' | sed 's/$$/\\n\"/' >>$@ || (rm $@;exit 1)
35 echo ";" >>$@ || (rm $@;exit 1) 35 echo ";" >>$@ || (rm $@;exit 1)
36 36
37EXTRA_DIST = ${sitecing_fastcgi_SOURCES} ${sitecing_PLAINCGI_SOURCES} 37EXTRA_DIST = ${sitecing_fastcgi_SOURCES} ${sitecing_plaincgi_SOURCES}