summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2005-01-29 20:14:37 (UTC)
committer Michael Krelin <hacker@klever.net>2005-01-29 20:14:37 (UTC)
commitff4b919683537625f693eedf53006364d0f8444d (patch) (unidiff)
tree4c19e38c0832b16b4ca98ae5af6542d932373eb1
parentf9a64a67c89a7566e63ed66c3a69c359abea4dfd (diff)
downloadkingate-0.0.zip
kingate-0.0.tar.gz
kingate-0.0.tar.bz2
initial commit into repository0.0
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--.gitignore23
-rw-r--r--AUTHORS3
-rw-r--r--COPYING19
-rw-r--r--ChangeLog0
-rw-r--r--Doxyfile.in247
-rw-r--r--Makefile.am27
-rw-r--r--NEWS.xml6
-rw-r--r--NEWS.xsl24
-rw-r--r--README0
-rw-r--r--acinclude.m480
-rwxr-xr-xautogen.sh9
-rw-r--r--configure.ac62
-rw-r--r--include/.gitignore2
-rw-r--r--include/Makefile.am6
-rw-r--r--include/kingate/cgi_gateway.h164
-rw-r--r--include/kingate/cgi_interface.h70
-rw-r--r--include/kingate/exception.h44
-rw-r--r--include/kingate/fastcgi.h98
-rw-r--r--include/kingate/util.h26
-rw-r--r--kingate-fcgi.pc.in11
-rw-r--r--kingate.pc.in11
-rw-r--r--src/.gitignore7
-rw-r--r--src/Makefile.am15
-rw-r--r--src/cgi_gateway.cc88
-rw-r--r--src/cgi_interface.cc16
-rw-r--r--src/fastcgi.cc67
-rw-r--r--src/util.cc53
27 files changed, 1178 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..02145e3
--- a/dev/null
+++ b/.gitignore
@@ -0,0 +1,23 @@
1configure
2Makefile.in
3kingate.pc
4Doxyfile
5config.log
6depcomp
7kingate-fcgi.pc
8config.guess
9config.h
10ltmain.sh
11config.sub
12INSTALL
13Makefile
14config.status
15stamp-h1
16config.h.in
17libtool
18autom4te.cache
19missing
20aclocal.m4
21install-sh
22NEWS
23doxydox
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..a9fb0c7
--- a/dev/null
+++ b/AUTHORS
@@ -0,0 +1,3 @@
1Klever dissected:
2 Michael 'hacker' Krelin <hacker@klever.net>
3 Leonid Ivanov <kamel@klever.net>
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..96befc6
--- a/dev/null
+++ b/COPYING
@@ -0,0 +1,19 @@
1Copyright (c) 2004-2005 Klever Group (http://www.klever.net/)
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of
4this software and associated documentation files (the "Software"), to deal in
5the Software without restriction, including without limitation the rights to
6use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7of the Software, and to permit persons to whom the Software is furnished to do
8so, subject to the following conditions:
9
10The above copyright notice and this permission notice shall be included in all
11copies or substantial portions of the Software.
12
13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19SOFTWARE.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/ChangeLog
diff --git a/Doxyfile.in b/Doxyfile.in
new file mode 100644
index 0000000..2d072ce
--- a/dev/null
+++ b/Doxyfile.in
@@ -0,0 +1,247 @@
1# Doxyfile 1.3.9.1
2
3#---------------------------------------------------------------------------
4# Project related configuration options
5#---------------------------------------------------------------------------
6PROJECT_NAME = @PACKAGE@
7PROJECT_NUMBER = @VERSION@
8OUTPUT_DIRECTORY = @builddir@/doxydox
9CREATE_SUBDIRS = NO
10OUTPUT_LANGUAGE = English
11USE_WINDOWS_ENCODING = NO
12BRIEF_MEMBER_DESC = YES
13REPEAT_BRIEF = YES
14ABBREVIATE_BRIEF =
15ALWAYS_DETAILED_SEC = NO
16INLINE_INHERITED_MEMB = NO
17FULL_PATH_NAMES = YES
18STRIP_FROM_PATH = include
19STRIP_FROM_INC_PATH = include
20SHORT_NAMES = NO
21JAVADOC_AUTOBRIEF = NO
22MULTILINE_CPP_IS_BRIEF = NO
23DETAILS_AT_TOP = NO
24INHERIT_DOCS = YES
25DISTRIBUTE_GROUP_DOC = NO
26TAB_SIZE = 8
27ALIASES =
28OPTIMIZE_OUTPUT_FOR_C = NO
29OPTIMIZE_OUTPUT_JAVA = NO
30SUBGROUPING = YES
31
32#---------------------------------------------------------------------------
33# Build related configuration options
34#---------------------------------------------------------------------------
35
36EXTRACT_ALL = NO
37EXTRACT_PRIVATE = NO
38EXTRACT_STATIC = NO
39EXTRACT_LOCAL_CLASSES = YES
40EXTRACT_LOCAL_METHODS = NO
41HIDE_UNDOC_MEMBERS = NO
42HIDE_UNDOC_CLASSES = NO
43HIDE_FRIEND_COMPOUNDS = NO
44HIDE_IN_BODY_DOCS = NO
45INTERNAL_DOCS = NO
46CASE_SENSE_NAMES = YES
47HIDE_SCOPE_NAMES = NO
48SHOW_INCLUDE_FILES = NO
49INLINE_INFO = YES
50SORT_MEMBER_DOCS = YES
51SORT_BRIEF_DOCS = NO
52SORT_BY_SCOPE_NAME = YES
53GENERATE_TODOLIST = YES
54GENERATE_TESTLIST = YES
55GENERATE_BUGLIST = YES
56GENERATE_DEPRECATEDLIST= YES
57ENABLED_SECTIONS =
58MAX_INITIALIZER_LINES = 30
59SHOW_USED_FILES = NO
60SHOW_DIRECTORIES = YES
61
62#---------------------------------------------------------------------------
63# configuration options related to warning and progress messages
64#---------------------------------------------------------------------------
65
66QUIET = NO
67WARNINGS = YES
68WARN_IF_UNDOCUMENTED = YES
69WARN_IF_DOC_ERROR = YES
70WARN_FORMAT = "$file:$line: $text"
71WARN_LOGFILE =
72
73#---------------------------------------------------------------------------
74# configuration options related to the input files
75#---------------------------------------------------------------------------
76
77INPUT = \
78 @srcdir@/include/kingate/
79FILE_PATTERNS = *.h
80RECURSIVE = NO
81EXCLUDE =
82EXCLUDE_SYMLINKS = NO
83EXCLUDE_PATTERNS =
84EXAMPLE_PATH =
85EXAMPLE_PATTERNS =
86EXAMPLE_RECURSIVE = NO
87IMAGE_PATH =
88INPUT_FILTER =
89FILTER_PATTERNS =
90FILTER_SOURCE_FILES = NO
91
92#---------------------------------------------------------------------------
93# configuration options related to source browsing
94#---------------------------------------------------------------------------
95
96SOURCE_BROWSER = NO
97INLINE_SOURCES = NO
98STRIP_CODE_COMMENTS = YES
99REFERENCED_BY_RELATION = YES
100REFERENCES_RELATION = YES
101VERBATIM_HEADERS = YES
102
103#---------------------------------------------------------------------------
104# configuration options related to the alphabetical class index
105#---------------------------------------------------------------------------
106
107ALPHABETICAL_INDEX = YES
108COLS_IN_ALPHA_INDEX = 2
109IGNORE_PREFIX =
110
111#---------------------------------------------------------------------------
112# configuration options related to the HTML output
113#---------------------------------------------------------------------------
114
115GENERATE_HTML = YES
116HTML_OUTPUT = html
117HTML_FILE_EXTENSION = .html
118HTML_HEADER =
119HTML_FOOTER =
120HTML_STYLESHEET =
121HTML_ALIGN_MEMBERS = YES
122GENERATE_HTMLHELP = NO
123CHM_FILE =
124HHC_LOCATION =
125GENERATE_CHI = NO
126BINARY_TOC = NO
127TOC_EXPAND = NO
128DISABLE_INDEX = NO
129ENUM_VALUES_PER_LINE = 4
130GENERATE_TREEVIEW = NO
131TREEVIEW_WIDTH = 250
132
133#---------------------------------------------------------------------------
134# configuration options related to the LaTeX output
135#---------------------------------------------------------------------------
136
137GENERATE_LATEX = NO
138LATEX_OUTPUT = latex
139LATEX_CMD_NAME = latex
140MAKEINDEX_CMD_NAME = makeindex
141COMPACT_LATEX = NO
142PAPER_TYPE = a4wide
143EXTRA_PACKAGES =
144LATEX_HEADER =
145PDF_HYPERLINKS = NO
146USE_PDFLATEX = NO
147LATEX_BATCHMODE = NO
148LATEX_HIDE_INDICES = NO
149
150#---------------------------------------------------------------------------
151# configuration options related to the RTF output
152#---------------------------------------------------------------------------
153
154GENERATE_RTF = NO
155RTF_OUTPUT = rtf
156COMPACT_RTF = NO
157RTF_HYPERLINKS = NO
158RTF_STYLESHEET_FILE =
159RTF_EXTENSIONS_FILE =
160
161#---------------------------------------------------------------------------
162# configuration options related to the man page output
163#---------------------------------------------------------------------------
164
165GENERATE_MAN = NO
166MAN_OUTPUT = man
167MAN_EXTENSION = .3
168MAN_LINKS = YES
169
170#---------------------------------------------------------------------------
171# configuration options related to the XML output
172#---------------------------------------------------------------------------
173
174GENERATE_XML = YES
175XML_OUTPUT = xml
176XML_SCHEMA =
177XML_DTD =
178XML_PROGRAMLISTING = YES
179
180#---------------------------------------------------------------------------
181# configuration options for the AutoGen Definitions output
182#---------------------------------------------------------------------------
183
184GENERATE_AUTOGEN_DEF = NO
185
186#---------------------------------------------------------------------------
187# configuration options related to the Perl module output
188#---------------------------------------------------------------------------
189
190GENERATE_PERLMOD = NO
191PERLMOD_LATEX = NO
192PERLMOD_PRETTY = YES
193PERLMOD_MAKEVAR_PREFIX =
194
195#---------------------------------------------------------------------------
196# Configuration options related to the preprocessor
197#---------------------------------------------------------------------------
198
199ENABLE_PREPROCESSING = YES
200MACRO_EXPANSION = NO
201EXPAND_ONLY_PREDEF = NO
202SEARCH_INCLUDES = YES
203INCLUDE_PATH =
204INCLUDE_FILE_PATTERNS =
205PREDEFINED =
206EXPAND_AS_DEFINED =
207SKIP_FUNCTION_MACROS = YES
208
209#---------------------------------------------------------------------------
210# Configuration::additions related to external references
211#---------------------------------------------------------------------------
212
213TAGFILES =
214GENERATE_TAGFILE =
215ALLEXTERNALS = NO
216EXTERNAL_GROUPS = YES
217PERL_PATH = /usr/bin/perl
218
219#---------------------------------------------------------------------------
220# Configuration options related to the dot tool
221#---------------------------------------------------------------------------
222
223CLASS_DIAGRAMS = YES
224HIDE_UNDOC_RELATIONS = YES
225HAVE_DOT = @HAVE_DOT@
226CLASS_GRAPH = YES
227COLLABORATION_GRAPH = YES
228UML_LOOK = NO
229TEMPLATE_RELATIONS = YES
230INCLUDE_GRAPH = YES
231INCLUDED_BY_GRAPH = YES
232CALL_GRAPH = NO
233GRAPHICAL_HIERARCHY = YES
234DOT_IMAGE_FORMAT = png
235DOT_PATH = @DOT@
236DOTFILE_DIRS =
237MAX_DOT_GRAPH_WIDTH = 1024
238MAX_DOT_GRAPH_HEIGHT = 1024
239MAX_DOT_GRAPH_DEPTH = 0
240GENERATE_LEGEND = YES
241DOT_CLEANUP = YES
242
243#---------------------------------------------------------------------------
244# Configuration::additions related to the search engine
245#---------------------------------------------------------------------------
246
247SEARCHENGINE = NO
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..9833732
--- a/dev/null
+++ b/Makefile.am
@@ -0,0 +1,27 @@
1SUBDIRS=include src
2EXTRA_DIST= NEWS NEWS.xml NEWS.xsl
3
4DISTCHECK_CONFIGURE_FLAGS=--with-pkgconfigdir=$${dc_install_base}/lib/pkgconfig
5if HAVE_PKGCONFIG
6pkgconfigdir=@PKGCONFIG_DIR@
7pkgconfig_DATA=kingate.pc kingate-fcgi.pc
8endif
9
10LOCAL_TARGETS=
11if HAVE_DOXYGEN
12LOCAL_TARGETS+=doxygen
13endif
14
15all-local: NEWS $(addprefix all-lota-,${LOCAL_TARGETS})
16clean-local: $(addprefix clean-lota-,${LOCAL_TARGETS})
17
18NEWS: NEWS.xsl NEWS.xml
19 ${XSLTPROC} -o $@ NEWS.xsl NEWS.xml
20
21all-lota-doxygen: doxydox/built
22doxydox/built: $(wildcard ${top_srcdir}/include/kingate/*.h)
23 ${DOXYGEN}
24 touch $@
25
26clean-lota-doxygen:
27 rm -rf doxydox
diff --git a/NEWS.xml b/NEWS.xml
new file mode 100644
index 0000000..d1d89f6
--- a/dev/null
+++ b/NEWS.xml
@@ -0,0 +1,6 @@
1<?xml version="1.0" encoding="us-ascii"?>
2<news>
3 <version version="0.0" date="January 29th, 2005">
4 <ni>Initial release</ni>
5 </version>
6</news>
diff --git a/NEWS.xsl b/NEWS.xsl
new file mode 100644
index 0000000..7c71307
--- a/dev/null
+++ b/NEWS.xsl
@@ -0,0 +1,24 @@
1<?xml version="1.0" encoding="us-ascii"?>
2<xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 >
5 <xsl:output
6 method="text"
7 encoding="us-ascii"
8 media-type="text/plain" />
9
10 <xsl:template match="news">
11 <xsl:apply-templates/>
12 </xsl:template>
13 <xsl:template match="version">
14 <xsl:value-of select="concat(@version,' (',@date,')&#xA;')"/>
15 <xsl:apply-templates/>
16 </xsl:template>
17 <xsl:template match="ni">
18 <xsl:text> - </xsl:text>
19 <xsl:apply-templates mode="text"/>
20 <xsl:text>&#xA;</xsl:text>
21 </xsl:template>
22 <xsl:template match="*|text()"/>
23
24</xsl:stylesheet>
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
--- a/dev/null
+++ b/README
diff --git a/acinclude.m4 b/acinclude.m4
new file mode 100644
index 0000000..ec2c50f
--- a/dev/null
+++ b/acinclude.m4
@@ -0,0 +1,80 @@
1dnl AC_WITH_PKGCONFIG([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
2dnl Outputs:
3dnl AC_SUBST: PKGCONFIG_PKGCONFIG PKGCONFIG_DIR
4dnl AM_CONDTIONAL: HAVE_PKGCONFIG
5AC_DEFUN([AC_WITH_PKGCONFIG],[
6 PKGCONFIG_PKGCONFIG=""
7 PKGCONFIG_DIR=""
8 HAVE_PKGCONFIG="no"
9 EXPLICIT_PKGCONFIGDIR="no"
10 test -z "${WANT_PKGCONFIG}" && WANT_PKGCONFIG=""
11 AC_PATH_PROG([PKGCONFIG_PKGCONFIG],[pkg-config],[false])
12 if test "${PKGCONFIG_PKGCONFIG}" != "false" ; then
13 AC_ARG_WITH([pkgconfigdir],
14 AC_HELP_STRING([--with-pkgconfigdir=dir],[Specify pkgconfig directory]),
15 [
16 if test "${withval}" = "no" ; then
17 WANT_PKGCONFIG="no"
18 else
19 PKGCONFIG_DIR="${withval}"
20 EXPLICIT_PKGCONFIGDIR="yes"
21 fi
22 ],[
23 AC_MSG_CHECKING([for pkgconfig directory])
24 PKGCONFIG_DIR="`${PKGCONFIG_PKGCONFIG} --debug 2>&1 | grep '^Scanning'| head -n 1 | cut -d\' -f2-|cut -d\' -f1`"
25 AC_MSG_RESULT([${PKGCONFIG_DIR}])
26 ]
27 )
28 if test -d "${PKGCONFIG_DIR}" ; then
29 HAVE_PKGCONFIG=yes
30 AC_SUBST([PKGCONFIG_PKGCONFIG])
31 AC_SUBST([PKGCONFIG_DIR])
32 else
33 AC_MSG_NOTICE([unexistent pkgconfig directory: ${PKGCONFIG_DIR}])
34 if test "${EXPLICIT_PKGCONFIGDIR}" = "yes" ; then
35 HAVE_PKGCONFIG=yes
36 AC_SUBST([PKGCONFIG_PKGCONFIG])
37 AC_SUBST([PKGCONFIG_DIR])
38 else
39 ifelse([$2], , :, [$2])
40 fi
41 fi
42 fi
43 AM_CONDITIONAL([HAVE_PKGCONFIG],[test "${HAVE_PKGCONFIG}" = "yes"])
44])
45
46dnl AC_WITH_DOXYGEN([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
47dnl Outputs:
48dnl AC_SUBST: DOXYGEN HAVE_DOXYGEN
49dnl AM_CONDTIONAL: HAVE_DOXYGEN
50AC_DEFUN([AC_WITH_DOXYGEN],[
51 HAVE_DOXYGEN="no"
52 AC_PATH_PROG([DOXYGEN],[doxygen],[false])
53 if test "${DOXYGEN}" = "false" ; then
54 ifelse([$2], , :, [$2])
55 else
56 HAVE_DOXYGEN="yes"
57 AC_SUBST([DOXYGEN])
58 $1
59 fi
60 AC_SUBST([HAVE_DOXYGEN])
61 AM_CONDITIONAL([HAVE_DOXYGEN],[test "${HAVE_DOXYGEN}" = "yes"])
62])
63
64dnl AC_WITH_DOT([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]])
65dnl Outputs:
66dnl AC_SUBST: DOT HAVE_DOT
67dnl AM_CONDITIONAL: HAVE_DOT
68AC_DEFUN([AC_WITH_DOT],[
69 HAVE_DOT="no"
70 AC_PATH_PROG([DOT],[dot],[false])
71 if test "${DOT}" = "false" ; then
72 ifelse([$2], , :, [$2])
73 else
74 HAVE_DOT="yes"
75 AC_SUBST([DOT])
76 $1
77 fi
78AC_SUBST([HAVE_DOT])
79 AM_CONDITIONAL([HAVE_DOT],[test "${HAVE_DOT}" = "yes"])
80])
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..ba27501
--- a/dev/null
+++ b/autogen.sh
@@ -0,0 +1,9 @@
1#!/bin/sh
2WANT_AUTOMAKE=1.8
3export WANT_AUTOMAKE
4libtoolize -f \
5&& aclocal \
6&& autoheader \
7&& automake -a \
8&& autoconf \
9&& ./configure "$@"
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..109eddf
--- a/dev/null
+++ b/configure.ac
@@ -0,0 +1,62 @@
1AC_INIT([kingate], [0.0], [kingate-bugs@klever.net])
2AC_CONFIG_SRCDIR([include/kingate/cgi_gateway.h])
3AC_CONFIG_HEADER([config.h])
4AM_INIT_AUTOMAKE([dist-bzip2])
5
6AC_PROG_INSTALL
7AC_PROG_AWK
8AC_PROG_CXX
9AC_PROG_CC
10AC_PROG_LIBTOOL
11
12AC_HEADER_STDC
13AC_CHECK_HEADERS([sys/types.h sys/stat.h])
14
15AC_LANG_PUSH(C++)
16AC_CHECK_HEADERS([fcgio.h],,[
17 exit 1
18])
19AC_CHECK_LIB(fcgi,FCGX_Init,,[
20 exit 1
21])
22AC_CHECK_LIB([fcgi++],[main],,[
23 exit 1
24])
25AC_LANG_POP(C++)
26
27AC_C_CONST
28
29AC_FUNC_MALLOC
30AC_FUNC_REALLOC
31
32AC_PATH_PROG([XSLTPROC],[xsltproc],[true])
33
34AC_WITH_PKGCONFIG
35
36PKG_CHECK_MODULES([KONFORKA],[konforka],,[
37 AC_MSG_ERROR([no konforka library found. get one from http://kin.klever.net/konforka/])
38])
39
40WANT_DOXYGEN="yes"
41AC_ARG_ENABLE([doxygen],
42 AC_HELP_STRING([--disable-doxygen],[do not generate documentation]),
43 [
44 test "${enableval}" = "no" && WANT_DOXYGEN="no"
45 ]
46)
47if test "${WANT_DOXYGEN}" = "yes" ; then
48 AC_WITH_DOXYGEN
49 AC_WITH_DOT
50else
51 AM_CONDITIONAL([HAVE_DOXYGEN],[false])
52 AM_CONDITIONAL([HAVE_DOT],[false])
53fi
54
55AC_CONFIG_FILES([
56 Makefile
57 kingate.pc kingate-fcgi.pc
58 Doxyfile
59 include/Makefile
60 src/Makefile
61])
62AC_OUTPUT
diff --git a/include/.gitignore b/include/.gitignore
new file mode 100644
index 0000000..3dda729
--- a/dev/null
+++ b/include/.gitignore
@@ -0,0 +1,2 @@
1Makefile.in
2Makefile
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644
index 0000000..c1ec36e
--- a/dev/null
+++ b/include/Makefile.am
@@ -0,0 +1,6 @@
1nobase_include_HEADERS = \
2 kingate/cgi_gateway.h \
3 kingate/cgi_interface.h \
4 kingate/fastcgi.h \
5 kingate/exception.h \
6 kingate/util.h
diff --git a/include/kingate/cgi_gateway.h b/include/kingate/cgi_gateway.h
new file mode 100644
index 0000000..f683580
--- a/dev/null
+++ b/include/kingate/cgi_gateway.h
@@ -0,0 +1,164 @@
1#ifndef __KINGATE_CGI_GATEWAY_H
2#define __KINGATE_CGI_GATEWAY_H
3
4#include <map>
5#include "kingate/cgi_interface.h"
6
7/**
8 * @file
9 * @brief the cgi_gateway -- main interface to CGI.
10 */
11
12namespace kingate {
13 using namespace std;
14
15 /**
16 * The main class interfacing with the CGI environment.
17 */
18 class cgi_gateway {
19 public:
20 /**
21 * The interface to CGI environment (e.g. fastcgi).
22 */
23 cgi_interface& iface;
24 /**
25 * The type describing map holding parameters parsed from query string or input.
26 */
27 typedef multimap<string,string> params_t;
28 /**
29 * The GET-passed parameters.
30 */
31 params_t get;
32 /**
33 * The POST-passed parameters.
34 */
35 params_t post;
36 /**
37 * Was the stdin content parsed?
38 */
39 bool b_parsed_content;
40
41 /**
42 * @param ci the interface to use.
43 */
44 cgi_gateway(cgi_interface& ci);
45
46 /**
47 * Check whether there is an 'environment' meta-variable with specific name
48 * passed to CGI.
49 * @param n variable name.
50 * @return true if yes.
51 * @see cgi_interface::has_meta()
52 * @see get_meta()
53 */
54 bool has_meta(const string& n) const { return iface.has_meta(n); }
55 /**
56 * Retrieve the 'environment' meta-variable value.
57 * @param n variable name.
58 * @return variable contents.
59 * @see exception_notfound
60 * @see cgi_interface::get_meta()
61 */
62 string get_meta(const string& n) const { return iface.get_meta(n); }
63
64 /**
65 * fetch reference to the 'stdin' stream.
66 * @return the reference to the corresponding istream object.
67 * @see cgi_interface::in()
68 */
69 istream& in() { return iface.in(); }
70 /**
71 * fetch reference to the 'stdout' stream.
72 * @return the reference to the corresponding ostream object.
73 * @see cgi_interface::out()
74 */
75 ostream& out() { return iface.out(); }
76 /**
77 * fetch reference to the 'stderr' stream.
78 * @return the reference to the corresponding ostream object.
79 * @see cgi_interface::err()
80 */
81 ostream& err() { return iface.err(); }
82 /**
83 * cast to the ostream -- fetches the reference to the 'stdout'
84 * stream.
85 * @see out()
86 */
87 operator ostream& (void) { return out(); }
88
89 /**
90 * Check to see whether the parameter was passed via GET.
91 * @param n the parameter name.
92 * @return true if yes.
93 */
94 bool has_GET(const string& n) const;
95 /**
96 * Retrieve the parameter passed via GET.
97 * @param n the parameter name.
98 * @return the parameter contents.
99 * @see exception_notfound
100 */
101 string get_GET(const string& n) const;
102 /**
103 * Check to see whether the parameter was passed via POST.
104 * @param n the parameter name.
105 * @return true if yes.
106 */
107 bool has_POST(const string& n) const;
108 /**
109 * Retrieve the POST-parameter.
110 * @param n the parameter name.
111 * @return the parameter contents.
112 * @see exception_notfound
113 */
114 string get_POST(const string& n) const;
115 /**
116 * Check to see whether the parameter was passed either via POST or
117 * GET.
118 * @param n the parameter name.
119 * @return true if yes.
120 */
121 bool has_param(const string& n) const;
122 /**
123 * Retrieve the parameter passed either via POST or GET
124 * (GET-parameter takes precedence).
125 * @param n the parameter name.
126 * @return true if yes.
127 * @see exception_notfound.
128 */
129 string get_param(const string& n) const;
130
131 /**
132 * Retrieve the POST content-type (as passed via CONTENT_TYPE
133 * environment variable).
134 * @return the content type.
135 */
136 const string& get_content_type() const;
137 /**
138 * Retrieve the POST content length (as passed via the
139 * CONTENT_LENGTH environment variable).
140 * @return the content length.
141 */
142 unsigned long get_content_length() const;
143
144 /**
145 * Check to see whether the content from stdin stream was parsed.
146 * @return true if yes.
147 */
148 bool is_content_parsed() const { return b_parsed_content; }
149 private:
150 /**
151 * Parse the query string, putting the parameters into the map
152 * specified.
153 * @param q the query string.
154 * @param p destination parameters map.
155 */
156 static void parse_query(string& q,params_t& p);
157 };
158
159}
160
161#endif /* __KINGATE_CGI_GATEWAY_H */
162/*
163 * vim:set ft=cpp:
164 */
diff --git a/include/kingate/cgi_interface.h b/include/kingate/cgi_interface.h
new file mode 100644
index 0000000..84ea6dd
--- a/dev/null
+++ b/include/kingate/cgi_interface.h
@@ -0,0 +1,70 @@
1#ifndef __KINGATE_CGI_INTERFACE_H
2#define __KINGATE_CGI_INTERFACE_H
3
4#include <iostream>
5#include <string>
6#include <map>
7
8/**
9 * @file
10 * @brief the abstract base for various interfaces to CGI.
11 */
12
13namespace kingate {
14 using namespace std;
15
16 /**
17 * The abstract base class for interface to CGI subsystem.
18 */
19 class cgi_interface {
20 public:
21 /**
22 * The type for map holding 'environment' meta-variables.
23 */
24 typedef map<string,string> metavars_t;
25 /**
26 * The environment variables.
27 */
28 metavars_t metavars;
29
30 cgi_interface() { }
31 virtual ~cgi_interface() { }
32
33 /**
34 * Check to see whether there is a particular 'environment'
35 * meta-variable passed.
36 * @param n the variable name.
37 * @return true if yes.
38 */
39 bool has_meta(const string& n) const;
40 /**
41 * Retrieve the 'environment' variable.
42 * @param n the variable name.
43 * @return the variable contents.
44 * @see exception_notfound
45 */
46 const string& get_meta(const string& n) const;
47
48 /**
49 * Fetch reference to CGI 'stdout' stream.
50 * @return reference to the corresponding ostream object.
51 */
52 virtual ostream& out() = 0;
53 /**
54 * Fetch reference to CGI 'stdin' stream.
55 * @return reference to the corresponding istream object.
56 */
57 virtual istream& in() = 0;
58 /**
59 * Fetch reference to CGI 'stderr' stream.
60 * @return reference to the corresponding ostream object.
61 */
62 virtual ostream& err() = 0;
63 };
64
65}
66
67#endif /* __KINGATE_CGI_INTERFACE_H */
68/*
69 * vim:set ft=cpp:
70 */
diff --git a/include/kingate/exception.h b/include/kingate/exception.h
new file mode 100644
index 0000000..6ebb361
--- a/dev/null
+++ b/include/kingate/exception.h
@@ -0,0 +1,44 @@
1#ifndef __KINGATE_EXCEPTION_H
2#define __KINGATE_EXCEPTION_H
3
4#include <stdexcept>
5#include <konforka/exception.h>
6
7/**
8 * @file
9 * @brief The kingate-specific exceptions.
10 */
11
12/**
13 * @brief the main kingate namespace.
14 */
15namespace kingate {
16 using namespace std;
17
18 /**
19 * The base for kingate-specific exception.
20 */
21 class exception : public konforka::exception {
22 public:
23 explicit exception(const string& w)
24 : konforka::exception(NOCODEPOINT,w) { }
25 exception(const string& fi,const string& fu,int l,const string &w)
26 : konforka::exception(fi,fu,l,w) { }
27 };
28
29 /**
30 * Thrown if the specified variable or parameter wasn't found.
31 */
32 class exception_notfound : public exception {
33 public:
34 explicit exception_notfound(const string& w)
35 : exception(w) { }
36 exception_notfound(const string& fi,const string& fu,int l,const string& w)
37 : exception(fi,fu,l,w) { }
38 };
39}
40
41#endif /* __KINGATE_EXCEPTION_H */
42/*
43 * vim:set ft=cpp:
44 */
diff --git a/include/kingate/fastcgi.h b/include/kingate/fastcgi.h
new file mode 100644
index 0000000..fd293b9
--- a/dev/null
+++ b/include/kingate/fastcgi.h
@@ -0,0 +1,98 @@
1#ifndef __KINGATE_FASTCGI_H
2#define __KINGATE_FASTCGI_H
3
4#include "kingate/cgi_interface.h"
5#include <fcgio.h>
6
7/**
8 * @file
9 * @brief the fastcgi-specific implementation.
10 */
11
12namespace kingate {
13
14 /**
15 * The fcgi listening socket.
16 */
17 class fcgi_socket {
18 static bool _initialized;
19 public:
20 /**
21 * socket file descriptor.
22 */
23 int sock;
24
25 /**
26 * @param s the socket name. (if the socket starts with a colon,
27 * then it is interpreted as a tcp port number.
28 * @param bl backlog listen queue depth.
29 */
30 fcgi_socket(const char* s,int bl);
31 /**
32 * @param s the file descriptor of preopened socket.
33 */
34 fcgi_socket(int s);
35 ~fcgi_socket();
36 };
37
38 /**
39 * The implementation of the interface to the FastCGI.
40 */
41 class fcgi_interface : public cgi_interface {
42 public:
43 /**
44 * stdin fcgi streambuf.
45 */
46 fcgi_streambuf sbin;
47 /**
48 * stdout fcgi streambuf.
49 */
50 fcgi_streambuf sbout;
51 /**
52 * stderr fcgi streambuf.
53 */
54 fcgi_streambuf sberr;
55 /**
56 * stdin istream.
57 */
58 istream sin;
59 /**
60 * stdout ostream.
61 */
62 ostream sout;
63 /**
64 * stderr ostream.
65 */
66 ostream serr;
67 /**
68 * The FCGI request.
69 */
70 FCGX_Request request;
71
72 /**
73 * @param s the socked used for interfacing with the server.
74 * @param f the request flags (e.g. FCGI_FAIL_ON_INTR).
75 */
76 fcgi_interface(fcgi_socket& s,int f=0);
77 virtual ~fcgi_interface();
78
79 /**
80 * @overload cgi_interface::in()
81 */
82 istream& in() { return sin; }
83 /**
84 * @overload cgi_interface::out()
85 */
86 ostream& out() { return sout; }
87 /**
88 * @overload cgi_interface::out()
89 */
90 ostream& err() { return serr; }
91 };
92
93}
94
95#endif /* __KINGATE_FASTCGI_H */
96/*
97 * vim:set ft=cpp:
98 */
diff --git a/include/kingate/util.h b/include/kingate/util.h
new file mode 100644
index 0000000..4b0dca8
--- a/dev/null
+++ b/include/kingate/util.h
@@ -0,0 +1,26 @@
1#ifndef __KINGATE_UTIL_H
2#define __KINGATE_UTIL_H
3
4#include <string>
5
6namespace kingate {
7 using namespace std;
8
9 /**
10 * Escape string for passing via URL.
11 * @param str string unescaped.
12 * @return the escaped string.
13 */
14 string url_escape(const string& str);
15 /**
16 * Remove URL-encoding from the string.
17 * @param str the URL-encoded string.
18 * @return the unescaped string.
19 */
20 string url_unescape(const string& str);
21}
22
23#endif /* __KINGATE_UTIL_H */
24/*
25 * vim:set ft=cpp:
26 */
diff --git a/kingate-fcgi.pc.in b/kingate-fcgi.pc.in
new file mode 100644
index 0000000..03e0155
--- a/dev/null
+++ b/kingate-fcgi.pc.in
@@ -0,0 +1,11 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@
5
6Name: kingate-fcgi
7Description: FastCGI implementation of kingate interface
8Version: @VERSION@
9Requires: kingate = @VERSION@
10Libs: -L${libdir} -lkingate-fcgi
11Cflags: -I${includedir}
diff --git a/kingate.pc.in b/kingate.pc.in
new file mode 100644
index 0000000..671faac
--- a/dev/null
+++ b/kingate.pc.in
@@ -0,0 +1,11 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@
5
6Name: kingate
7Description: C++ CGI support library
8Version: @VERSION@
9Requires: konforka
10Libs: -L${libdir} -lkingate
11Cflags: -I${includedir}
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 0000000..af4f4dd
--- a/dev/null
+++ b/src/.gitignore
@@ -0,0 +1,7 @@
1Makefile.in
2.deps
3Makefile
4.libs
5*.o
6*.lo
7*.la
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..8a5447b
--- a/dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,15 @@
1lib_LTLIBRARIES = libkingate.la libkingate-fcgi.la
2
3INCLUDES = -I${top_srcdir}/include
4AM_CXXFLAGS = ${KONFORKA_CFLAGS}
5LDADD = ${KONFORKA_LIBS}
6
7libkingate_la_SOURCES = \
8 cgi_gateway.cc \
9 cgi_interface.cc \
10 util.cc
11libkingate_la_LDFLAGS = -version-info 1:0:0
12
13libkingate_fcgi_la_SOURCES = \
14 fastcgi.cc
15libkingate_fcgi_la_LDFLAGS = -version-info 1:0:0
diff --git a/src/cgi_gateway.cc b/src/cgi_gateway.cc
new file mode 100644
index 0000000..eae7a03
--- a/dev/null
+++ b/src/cgi_gateway.cc
@@ -0,0 +1,88 @@
1#include "kingate/cgi_gateway.h"
2#include "kingate/util.h"
3#include "kingate/exception.h"
4
5namespace kingate {
6
7 cgi_gateway::cgi_gateway(cgi_interface& ci)
8 : iface(ci), b_parsed_content(false) {
9 // Fetch GET content
10 if(iface.has_meta("QUERY_STRING")) {
11 string qs = iface.get_meta("QUERY_STRING");
12 parse_query(qs,get);
13 }
14 // Fetch POST content
15 if(!strcasecmp(get_content_type().c_str(),"application/x-www-form-urlencoded")) {
16 unsigned long cl = get_content_length();
17 if(cl) {
18 char * tmp = new char[cl];
19 iface.in().read(tmp,cl);
20 string qs(tmp,cl);
21 delete tmp;
22 parse_query(qs,post);
23 }
24 b_parsed_content = true;
25 }
26 }
27
28 bool cgi_gateway::has_GET(const string& n) const {
29 return get.find(n) != get.end();
30 }
31 string cgi_gateway::get_GET(const string& n) const {
32 params_t::const_iterator i = get.find(n);
33 if(i==get.end())
34 throw exception_notfound(CODEPOINT,"no such parameter");
35 return i->second;
36 }
37 bool cgi_gateway::has_POST(const string& n) const {
38 return post.find(n) != post.end();
39 }
40 string cgi_gateway::get_POST(const string& n) const {
41 params_t::const_iterator i = post.find(n);
42 if(i==post.end())
43 throw exception_notfound(CODEPOINT,"no such parameter");
44 return i->second;
45 }
46 bool cgi_gateway::has_param(const string& n) const {
47 return has_GET(n) || has_POST(n);
48 }
49 string cgi_gateway::get_param(const string& n) const {
50 params_t::const_iterator i = get.find(n);
51 if(i!=get.end())
52 return i->second;
53 i = post.find(n);
54 if(i!=post.end())
55 return i->second;
56 throw exception_notfound(CODEPOINT,"no such parameter");
57 }
58
59 const string& cgi_gateway::get_content_type() const {
60 if(!has_meta("CONTENT_TYPE"))
61 return ""; // XXX:
62 return get_meta("CONTENT_TYPE");
63 }
64 unsigned long cgi_gateway::get_content_length() const {
65 if(!has_meta("CONTENT_LENGTH"))
66 return 0;
67 string cl = get_meta("CONTENT_LENGTH");
68 return strtol(cl.c_str(),NULL,10);
69 }
70
71 void cgi_gateway::parse_query(string& q,params_t& p) {
72 while(!q.empty()) {
73 string::size_type amp = q.find('&');
74 string pp = (amp==string::npos)?q:q.substr(0,amp);
75 if(amp==string::npos)
76 q.clear();
77 else
78 q.erase(0,amp+1);
79 string::size_type eq = pp.find('=');
80 if(eq == string::npos) {
81 p.insert(params_t::value_type("",url_unescape(pp)));
82 }else{
83 p.insert(params_t::value_type(url_unescape(pp.substr(0,eq)),url_unescape(pp.substr(eq+1))));
84 }
85 }
86 }
87
88}
diff --git a/src/cgi_interface.cc b/src/cgi_interface.cc
new file mode 100644
index 0000000..ffbd2bf
--- a/dev/null
+++ b/src/cgi_interface.cc
@@ -0,0 +1,16 @@
1#include "kingate/cgi_interface.h"
2#include "kingate/exception.h"
3
4namespace kingate {
5
6 bool cgi_interface::has_meta(const string& n) const {
7 return metavars.find(n) != metavars.end();
8 }
9 const string& cgi_interface::get_meta(const string& n) const {
10 metavars_t::const_iterator rv = metavars.find(n);
11 if(rv == metavars.end())
12 throw exception_notfound(CODEPOINT,"no such meta-variable");
13 return rv->second;
14 }
15
16}
diff --git a/src/fastcgi.cc b/src/fastcgi.cc
new file mode 100644
index 0000000..7484449
--- a/dev/null
+++ b/src/fastcgi.cc
@@ -0,0 +1,67 @@
1#include <unistd.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include "kingate/fastcgi.h"
5#include "kingate/exception.h"
6
7namespace kingate {
8
9 bool fcgi_socket::_initialized = false;
10
11 fcgi_socket::fcgi_socket(const char *s,int bl)
12 : sock(-1) {
13 if(!_initialized) {
14 if( FCGX_Init() )
15 throw exception(CODEPOINT,"failed to FCGX_Init()");
16 _initialized = true;
17 }
18 sock = FCGX_OpenSocket(s,bl);
19 if(sock<0)
20 throw exception(CODEPOINT,"failed to FCGX_OpenSocket(");
21 // TODO: check if there is a ':', not if it starts with ':'
22 if(*s != ':')
23 if(chmod(s,0777)) // XXX: configurable.
24 throw exception(CODEPOINT,"failed to chmod()");
25 }
26 fcgi_socket::fcgi_socket(int s)
27 : sock(0) {
28 if(!_initialized) {
29 if( FCGX_Init() )
30 throw exception(CODEPOINT,"failed to FCGX_Init()");
31 _initialized = true;
32 }
33 }
34 fcgi_socket::~fcgi_socket() {
35 if(sock>=0)
36 close(sock);
37 }
38
39 fcgi_interface::fcgi_interface(fcgi_socket& s,int f)
40 : sin(&sbin), sout(&sbout), serr(&sberr) {
41 if( FCGX_InitRequest(&request,s.sock,f) )
42 throw exception(CODEPOINT,"failed to FCGX_InitRequest()");
43 if( FCGX_Accept_r(&request) )
44 throw exception(CODEPOINT,"failed to FCGX_Accept_r()");
45 sbin.attach(request.in);
46 sbout.attach(request.out);
47 sberr.attach(request.err);
48 metavars.clear(); // XXX: redundant.
49 for(char **p = request.envp; *p; p++) {
50 const char *e = strchr(*p,'=');
51 if(!e){
52 // XXX: check if we have it already?
53 metavars[*p] = string(0);
54 }else{
55 int l = e-*p; e++;
56 // XXX: check if we have it already?
57 metavars[string(*p,l)]=e;
58 }
59 }
60 }
61 fcgi_interface::~fcgi_interface() {
62 sout.flush();
63 serr.flush();
64 FCGX_Finish_r(&request);
65 }
66
67}
diff --git a/src/util.cc b/src/util.cc
new file mode 100644
index 0000000..2e2d305
--- a/dev/null
+++ b/src/util.cc
@@ -0,0 +1,53 @@
1#include "kingate/util.h"
2#include "kingate/exception.h"
3
4namespace kingate {
5
6 static const char *safeChars =
7 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
8 "abcdefghijklmnopqrstuvwxyz"
9 "0123456789"
10 "_-" ;
11
12 string url_escape(const string& str) {
13 string rv = str;
14 string::size_type screwed = 0;
15 for(;;) {
16 screwed = rv.find_first_not_of(safeChars,screwed);
17 if(screwed == string::npos)
18 break;
19 while(screwed<rv.length() && !strchr(safeChars,rv.at(screwed))) {
20 char danger = rv.at(screwed);
21 if(danger==' ') {
22 rv.replace(screwed++,1,1,'+');
23 }else{
24 static char tmp[4] = {'%',0,0,0};
25 snprintf(&tmp[1],3,"%02X",0xFF&(int)danger);
26 rv.replace(screwed,1,tmp,3);
27 screwed+=3;
28 }
29 }
30 }
31 return rv;
32 }
33 string url_unescape(const string& str) {
34 string rv = str;
35 string::size_type unscrewed = 0;
36 for(;;) {
37 unscrewed = rv.find_first_of("%+",unscrewed);
38 if(unscrewed == string::npos)
39 break;
40 if(rv.at(unscrewed)=='+') {
41 rv.replace(unscrewed++,1,1,' ');
42 }else{
43 if((rv.length()-unscrewed)<3)
44 throw exception(CODEPOINT,"incorrectly escaped string");
45 // XXX: ensure it's hex?
46 int danger = strtol(rv.substr(unscrewed+1,2).c_str(),NULL,16);
47 rv.replace(unscrewed,3,1,danger);
48 unscrewed++;
49 }
50 }
51 return rv;
52 }
53}