author | Michael Krelin <hacker@klever.net> | 2005-01-29 20:14:37 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-01-29 20:14:37 (UTC) |
commit | ff4b919683537625f693eedf53006364d0f8444d (patch) (unidiff) | |
tree | 4c19e38c0832b16b4ca98ae5af6542d932373eb1 | |
parent | f9a64a67c89a7566e63ed66c3a69c359abea4dfd (diff) | |
download | kingate-ff4b919683537625f693eedf53006364d0f8444d.zip kingate-ff4b919683537625f693eedf53006364d0f8444d.tar.gz kingate-ff4b919683537625f693eedf53006364d0f8444d.tar.bz2 |
initial commit into repository0.0
-rw-r--r-- | .gitignore | 23 | ||||
-rw-r--r-- | AUTHORS | 3 | ||||
-rw-r--r-- | COPYING | 19 | ||||
-rw-r--r-- | ChangeLog | 0 | ||||
-rw-r--r-- | Doxyfile.in | 247 | ||||
-rw-r--r-- | Makefile.am | 27 | ||||
-rw-r--r-- | NEWS.xml | 6 | ||||
-rw-r--r-- | NEWS.xsl | 24 | ||||
-rw-r--r-- | README | 0 | ||||
-rw-r--r-- | acinclude.m4 | 80 | ||||
-rwxr-xr-x | autogen.sh | 9 | ||||
-rw-r--r-- | configure.ac | 62 | ||||
-rw-r--r-- | include/.gitignore | 2 | ||||
-rw-r--r-- | include/Makefile.am | 6 | ||||
-rw-r--r-- | include/kingate/cgi_gateway.h | 164 | ||||
-rw-r--r-- | include/kingate/cgi_interface.h | 70 | ||||
-rw-r--r-- | include/kingate/exception.h | 44 | ||||
-rw-r--r-- | include/kingate/fastcgi.h | 98 | ||||
-rw-r--r-- | include/kingate/util.h | 26 | ||||
-rw-r--r-- | kingate-fcgi.pc.in | 11 | ||||
-rw-r--r-- | kingate.pc.in | 11 | ||||
-rw-r--r-- | src/.gitignore | 7 | ||||
-rw-r--r-- | src/Makefile.am | 15 | ||||
-rw-r--r-- | src/cgi_gateway.cc | 88 | ||||
-rw-r--r-- | src/cgi_interface.cc | 16 | ||||
-rw-r--r-- | src/fastcgi.cc | 67 | ||||
-rw-r--r-- | src/util.cc | 53 |
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 @@ | |||
1 | configure | ||
2 | Makefile.in | ||
3 | kingate.pc | ||
4 | Doxyfile | ||
5 | config.log | ||
6 | depcomp | ||
7 | kingate-fcgi.pc | ||
8 | config.guess | ||
9 | config.h | ||
10 | ltmain.sh | ||
11 | config.sub | ||
12 | INSTALL | ||
13 | Makefile | ||
14 | config.status | ||
15 | stamp-h1 | ||
16 | config.h.in | ||
17 | libtool | ||
18 | autom4te.cache | ||
19 | missing | ||
20 | aclocal.m4 | ||
21 | install-sh | ||
22 | NEWS | ||
23 | doxydox | ||
@@ -0,0 +1,3 @@ | |||
1 | Klever dissected: | ||
2 | Michael 'hacker' Krelin <hacker@klever.net> | ||
3 | Leonid Ivanov <kamel@klever.net> | ||
@@ -0,0 +1,19 @@ | |||
1 | Copyright (c) 2004-2005 Klever Group (http://www.klever.net/) | ||
2 | |||
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
4 | this software and associated documentation files (the "Software"), to deal in | ||
5 | the Software without restriction, including without limitation the rights to | ||
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
7 | of the Software, and to permit persons to whom the Software is furnished to do | ||
8 | so, subject to the following conditions: | ||
9 | |||
10 | The above copyright notice and this permission notice shall be included in all | ||
11 | copies or substantial portions of the Software. | ||
12 | |||
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
19 | SOFTWARE. | ||
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 | #--------------------------------------------------------------------------- | ||
6 | PROJECT_NAME = @PACKAGE@ | ||
7 | PROJECT_NUMBER = @VERSION@ | ||
8 | OUTPUT_DIRECTORY = @builddir@/doxydox | ||
9 | CREATE_SUBDIRS = NO | ||
10 | OUTPUT_LANGUAGE = English | ||
11 | USE_WINDOWS_ENCODING = NO | ||
12 | BRIEF_MEMBER_DESC = YES | ||
13 | REPEAT_BRIEF = YES | ||
14 | ABBREVIATE_BRIEF = | ||
15 | ALWAYS_DETAILED_SEC = NO | ||
16 | INLINE_INHERITED_MEMB = NO | ||
17 | FULL_PATH_NAMES = YES | ||
18 | STRIP_FROM_PATH = include | ||
19 | STRIP_FROM_INC_PATH = include | ||
20 | SHORT_NAMES = NO | ||
21 | JAVADOC_AUTOBRIEF = NO | ||
22 | MULTILINE_CPP_IS_BRIEF = NO | ||
23 | DETAILS_AT_TOP = NO | ||
24 | INHERIT_DOCS = YES | ||
25 | DISTRIBUTE_GROUP_DOC = NO | ||
26 | TAB_SIZE = 8 | ||
27 | ALIASES = | ||
28 | OPTIMIZE_OUTPUT_FOR_C = NO | ||
29 | OPTIMIZE_OUTPUT_JAVA = NO | ||
30 | SUBGROUPING = YES | ||
31 | |||
32 | #--------------------------------------------------------------------------- | ||
33 | # Build related configuration options | ||
34 | #--------------------------------------------------------------------------- | ||
35 | |||
36 | EXTRACT_ALL = NO | ||
37 | EXTRACT_PRIVATE = NO | ||
38 | EXTRACT_STATIC = NO | ||
39 | EXTRACT_LOCAL_CLASSES = YES | ||
40 | EXTRACT_LOCAL_METHODS = NO | ||
41 | HIDE_UNDOC_MEMBERS = NO | ||
42 | HIDE_UNDOC_CLASSES = NO | ||
43 | HIDE_FRIEND_COMPOUNDS = NO | ||
44 | HIDE_IN_BODY_DOCS = NO | ||
45 | INTERNAL_DOCS = NO | ||
46 | CASE_SENSE_NAMES = YES | ||
47 | HIDE_SCOPE_NAMES = NO | ||
48 | SHOW_INCLUDE_FILES = NO | ||
49 | INLINE_INFO = YES | ||
50 | SORT_MEMBER_DOCS = YES | ||
51 | SORT_BRIEF_DOCS = NO | ||
52 | SORT_BY_SCOPE_NAME = YES | ||
53 | GENERATE_TODOLIST = YES | ||
54 | GENERATE_TESTLIST = YES | ||
55 | GENERATE_BUGLIST = YES | ||
56 | GENERATE_DEPRECATEDLIST= YES | ||
57 | ENABLED_SECTIONS = | ||
58 | MAX_INITIALIZER_LINES = 30 | ||
59 | SHOW_USED_FILES = NO | ||
60 | SHOW_DIRECTORIES = YES | ||
61 | |||
62 | #--------------------------------------------------------------------------- | ||
63 | # configuration options related to warning and progress messages | ||
64 | #--------------------------------------------------------------------------- | ||
65 | |||
66 | QUIET = NO | ||
67 | WARNINGS = YES | ||
68 | WARN_IF_UNDOCUMENTED = YES | ||
69 | WARN_IF_DOC_ERROR = YES | ||
70 | WARN_FORMAT = "$file:$line: $text" | ||
71 | WARN_LOGFILE = | ||
72 | |||
73 | #--------------------------------------------------------------------------- | ||
74 | # configuration options related to the input files | ||
75 | #--------------------------------------------------------------------------- | ||
76 | |||
77 | INPUT = \ | ||
78 | @srcdir@/include/kingate/ | ||
79 | FILE_PATTERNS = *.h | ||
80 | RECURSIVE = NO | ||
81 | EXCLUDE = | ||
82 | EXCLUDE_SYMLINKS = NO | ||
83 | EXCLUDE_PATTERNS = | ||
84 | EXAMPLE_PATH = | ||
85 | EXAMPLE_PATTERNS = | ||
86 | EXAMPLE_RECURSIVE = NO | ||
87 | IMAGE_PATH = | ||
88 | INPUT_FILTER = | ||
89 | FILTER_PATTERNS = | ||
90 | FILTER_SOURCE_FILES = NO | ||
91 | |||
92 | #--------------------------------------------------------------------------- | ||
93 | # configuration options related to source browsing | ||
94 | #--------------------------------------------------------------------------- | ||
95 | |||
96 | SOURCE_BROWSER = NO | ||
97 | INLINE_SOURCES = NO | ||
98 | STRIP_CODE_COMMENTS = YES | ||
99 | REFERENCED_BY_RELATION = YES | ||
100 | REFERENCES_RELATION = YES | ||
101 | VERBATIM_HEADERS = YES | ||
102 | |||
103 | #--------------------------------------------------------------------------- | ||
104 | # configuration options related to the alphabetical class index | ||
105 | #--------------------------------------------------------------------------- | ||
106 | |||
107 | ALPHABETICAL_INDEX = YES | ||
108 | COLS_IN_ALPHA_INDEX = 2 | ||
109 | IGNORE_PREFIX = | ||
110 | |||
111 | #--------------------------------------------------------------------------- | ||
112 | # configuration options related to the HTML output | ||
113 | #--------------------------------------------------------------------------- | ||
114 | |||
115 | GENERATE_HTML = YES | ||
116 | HTML_OUTPUT = html | ||
117 | HTML_FILE_EXTENSION = .html | ||
118 | HTML_HEADER = | ||
119 | HTML_FOOTER = | ||
120 | HTML_STYLESHEET = | ||
121 | HTML_ALIGN_MEMBERS = YES | ||
122 | GENERATE_HTMLHELP = NO | ||
123 | CHM_FILE = | ||
124 | HHC_LOCATION = | ||
125 | GENERATE_CHI = NO | ||
126 | BINARY_TOC = NO | ||
127 | TOC_EXPAND = NO | ||
128 | DISABLE_INDEX = NO | ||
129 | ENUM_VALUES_PER_LINE = 4 | ||
130 | GENERATE_TREEVIEW = NO | ||
131 | TREEVIEW_WIDTH = 250 | ||
132 | |||
133 | #--------------------------------------------------------------------------- | ||
134 | # configuration options related to the LaTeX output | ||
135 | #--------------------------------------------------------------------------- | ||
136 | |||
137 | GENERATE_LATEX = NO | ||
138 | LATEX_OUTPUT = latex | ||
139 | LATEX_CMD_NAME = latex | ||
140 | MAKEINDEX_CMD_NAME = makeindex | ||
141 | COMPACT_LATEX = NO | ||
142 | PAPER_TYPE = a4wide | ||
143 | EXTRA_PACKAGES = | ||
144 | LATEX_HEADER = | ||
145 | PDF_HYPERLINKS = NO | ||
146 | USE_PDFLATEX = NO | ||
147 | LATEX_BATCHMODE = NO | ||
148 | LATEX_HIDE_INDICES = NO | ||
149 | |||
150 | #--------------------------------------------------------------------------- | ||
151 | # configuration options related to the RTF output | ||
152 | #--------------------------------------------------------------------------- | ||
153 | |||
154 | GENERATE_RTF = NO | ||
155 | RTF_OUTPUT = rtf | ||
156 | COMPACT_RTF = NO | ||
157 | RTF_HYPERLINKS = NO | ||
158 | RTF_STYLESHEET_FILE = | ||
159 | RTF_EXTENSIONS_FILE = | ||
160 | |||
161 | #--------------------------------------------------------------------------- | ||
162 | # configuration options related to the man page output | ||
163 | #--------------------------------------------------------------------------- | ||
164 | |||
165 | GENERATE_MAN = NO | ||
166 | MAN_OUTPUT = man | ||
167 | MAN_EXTENSION = .3 | ||
168 | MAN_LINKS = YES | ||
169 | |||
170 | #--------------------------------------------------------------------------- | ||
171 | # configuration options related to the XML output | ||
172 | #--------------------------------------------------------------------------- | ||
173 | |||
174 | GENERATE_XML = YES | ||
175 | XML_OUTPUT = xml | ||
176 | XML_SCHEMA = | ||
177 | XML_DTD = | ||
178 | XML_PROGRAMLISTING = YES | ||
179 | |||
180 | #--------------------------------------------------------------------------- | ||
181 | # configuration options for the AutoGen Definitions output | ||
182 | #--------------------------------------------------------------------------- | ||
183 | |||
184 | GENERATE_AUTOGEN_DEF = NO | ||
185 | |||
186 | #--------------------------------------------------------------------------- | ||
187 | # configuration options related to the Perl module output | ||
188 | #--------------------------------------------------------------------------- | ||
189 | |||
190 | GENERATE_PERLMOD = NO | ||
191 | PERLMOD_LATEX = NO | ||
192 | PERLMOD_PRETTY = YES | ||
193 | PERLMOD_MAKEVAR_PREFIX = | ||
194 | |||
195 | #--------------------------------------------------------------------------- | ||
196 | # Configuration options related to the preprocessor | ||
197 | #--------------------------------------------------------------------------- | ||
198 | |||
199 | ENABLE_PREPROCESSING = YES | ||
200 | MACRO_EXPANSION = NO | ||
201 | EXPAND_ONLY_PREDEF = NO | ||
202 | SEARCH_INCLUDES = YES | ||
203 | INCLUDE_PATH = | ||
204 | INCLUDE_FILE_PATTERNS = | ||
205 | PREDEFINED = | ||
206 | EXPAND_AS_DEFINED = | ||
207 | SKIP_FUNCTION_MACROS = YES | ||
208 | |||
209 | #--------------------------------------------------------------------------- | ||
210 | # Configuration::additions related to external references | ||
211 | #--------------------------------------------------------------------------- | ||
212 | |||
213 | TAGFILES = | ||
214 | GENERATE_TAGFILE = | ||
215 | ALLEXTERNALS = NO | ||
216 | EXTERNAL_GROUPS = YES | ||
217 | PERL_PATH = /usr/bin/perl | ||
218 | |||
219 | #--------------------------------------------------------------------------- | ||
220 | # Configuration options related to the dot tool | ||
221 | #--------------------------------------------------------------------------- | ||
222 | |||
223 | CLASS_DIAGRAMS = YES | ||
224 | HIDE_UNDOC_RELATIONS = YES | ||
225 | HAVE_DOT = @HAVE_DOT@ | ||
226 | CLASS_GRAPH = YES | ||
227 | COLLABORATION_GRAPH = YES | ||
228 | UML_LOOK = NO | ||
229 | TEMPLATE_RELATIONS = YES | ||
230 | INCLUDE_GRAPH = YES | ||
231 | INCLUDED_BY_GRAPH = YES | ||
232 | CALL_GRAPH = NO | ||
233 | GRAPHICAL_HIERARCHY = YES | ||
234 | DOT_IMAGE_FORMAT = png | ||
235 | DOT_PATH = @DOT@ | ||
236 | DOTFILE_DIRS = | ||
237 | MAX_DOT_GRAPH_WIDTH = 1024 | ||
238 | MAX_DOT_GRAPH_HEIGHT = 1024 | ||
239 | MAX_DOT_GRAPH_DEPTH = 0 | ||
240 | GENERATE_LEGEND = YES | ||
241 | DOT_CLEANUP = YES | ||
242 | |||
243 | #--------------------------------------------------------------------------- | ||
244 | # Configuration::additions related to the search engine | ||
245 | #--------------------------------------------------------------------------- | ||
246 | |||
247 | SEARCHENGINE = 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 @@ | |||
1 | SUBDIRS=include src | ||
2 | EXTRA_DIST= NEWS NEWS.xml NEWS.xsl | ||
3 | |||
4 | DISTCHECK_CONFIGURE_FLAGS=--with-pkgconfigdir=$${dc_install_base}/lib/pkgconfig | ||
5 | if HAVE_PKGCONFIG | ||
6 | pkgconfigdir=@PKGCONFIG_DIR@ | ||
7 | pkgconfig_DATA=kingate.pc kingate-fcgi.pc | ||
8 | endif | ||
9 | |||
10 | LOCAL_TARGETS= | ||
11 | if HAVE_DOXYGEN | ||
12 | LOCAL_TARGETS+=doxygen | ||
13 | endif | ||
14 | |||
15 | all-local: NEWS $(addprefix all-lota-,${LOCAL_TARGETS}) | ||
16 | clean-local: $(addprefix clean-lota-,${LOCAL_TARGETS}) | ||
17 | |||
18 | NEWS: NEWS.xsl NEWS.xml | ||
19 | ${XSLTPROC} -o $@ NEWS.xsl NEWS.xml | ||
20 | |||
21 | all-lota-doxygen: doxydox/built | ||
22 | doxydox/built: $(wildcard ${top_srcdir}/include/kingate/*.h) | ||
23 | ${DOXYGEN} | ||
24 | touch $@ | ||
25 | |||
26 | clean-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,')
')"/> | ||
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>
</xsl:text> | ||
21 | </xsl:template> | ||
22 | <xsl:template match="*|text()"/> | ||
23 | |||
24 | </xsl:stylesheet> | ||
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 @@ | |||
1 | dnl AC_WITH_PKGCONFIG([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) | ||
2 | dnl Outputs: | ||
3 | dnl AC_SUBST: PKGCONFIG_PKGCONFIG PKGCONFIG_DIR | ||
4 | dnl AM_CONDTIONAL: HAVE_PKGCONFIG | ||
5 | AC_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 | |||
46 | dnl AC_WITH_DOXYGEN([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) | ||
47 | dnl Outputs: | ||
48 | dnl AC_SUBST: DOXYGEN HAVE_DOXYGEN | ||
49 | dnl AM_CONDTIONAL: HAVE_DOXYGEN | ||
50 | AC_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 | |||
64 | dnl AC_WITH_DOT([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) | ||
65 | dnl Outputs: | ||
66 | dnl AC_SUBST: DOT HAVE_DOT | ||
67 | dnl AM_CONDITIONAL: HAVE_DOT | ||
68 | AC_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 | ||
78 | AC_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 | ||
2 | WANT_AUTOMAKE=1.8 | ||
3 | export WANT_AUTOMAKE | ||
4 | libtoolize -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 @@ | |||
1 | AC_INIT([kingate], [0.0], [kingate-bugs@klever.net]) | ||
2 | AC_CONFIG_SRCDIR([include/kingate/cgi_gateway.h]) | ||
3 | AC_CONFIG_HEADER([config.h]) | ||
4 | AM_INIT_AUTOMAKE([dist-bzip2]) | ||
5 | |||
6 | AC_PROG_INSTALL | ||
7 | AC_PROG_AWK | ||
8 | AC_PROG_CXX | ||
9 | AC_PROG_CC | ||
10 | AC_PROG_LIBTOOL | ||
11 | |||
12 | AC_HEADER_STDC | ||
13 | AC_CHECK_HEADERS([sys/types.h sys/stat.h]) | ||
14 | |||
15 | AC_LANG_PUSH(C++) | ||
16 | AC_CHECK_HEADERS([fcgio.h],,[ | ||
17 | exit 1 | ||
18 | ]) | ||
19 | AC_CHECK_LIB(fcgi,FCGX_Init,,[ | ||
20 | exit 1 | ||
21 | ]) | ||
22 | AC_CHECK_LIB([fcgi++],[main],,[ | ||
23 | exit 1 | ||
24 | ]) | ||
25 | AC_LANG_POP(C++) | ||
26 | |||
27 | AC_C_CONST | ||
28 | |||
29 | AC_FUNC_MALLOC | ||
30 | AC_FUNC_REALLOC | ||
31 | |||
32 | AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) | ||
33 | |||
34 | AC_WITH_PKGCONFIG | ||
35 | |||
36 | PKG_CHECK_MODULES([KONFORKA],[konforka],,[ | ||
37 | AC_MSG_ERROR([no konforka library found. get one from http://kin.klever.net/konforka/]) | ||
38 | ]) | ||
39 | |||
40 | WANT_DOXYGEN="yes" | ||
41 | AC_ARG_ENABLE([doxygen], | ||
42 | AC_HELP_STRING([--disable-doxygen],[do not generate documentation]), | ||
43 | [ | ||
44 | test "${enableval}" = "no" && WANT_DOXYGEN="no" | ||
45 | ] | ||
46 | ) | ||
47 | if test "${WANT_DOXYGEN}" = "yes" ; then | ||
48 | AC_WITH_DOXYGEN | ||
49 | AC_WITH_DOT | ||
50 | else | ||
51 | AM_CONDITIONAL([HAVE_DOXYGEN],[false]) | ||
52 | AM_CONDITIONAL([HAVE_DOT],[false]) | ||
53 | fi | ||
54 | |||
55 | AC_CONFIG_FILES([ | ||
56 | Makefile | ||
57 | kingate.pc kingate-fcgi.pc | ||
58 | Doxyfile | ||
59 | include/Makefile | ||
60 | src/Makefile | ||
61 | ]) | ||
62 | AC_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 @@ | |||
1 | Makefile.in | ||
2 | Makefile | ||
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 @@ | |||
1 | nobase_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 | |||
12 | namespace 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 | |||
13 | namespace 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 | */ | ||
15 | namespace 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 | |||
12 | namespace 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 | |||
6 | namespace 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 @@ | |||
1 | prefix=@prefix@ | ||
2 | exec_prefix=@exec_prefix@ | ||
3 | libdir=@libdir@ | ||
4 | includedir=@includedir@ | ||
5 | |||
6 | Name: kingate-fcgi | ||
7 | Description: FastCGI implementation of kingate interface | ||
8 | Version: @VERSION@ | ||
9 | Requires: kingate = @VERSION@ | ||
10 | Libs: -L${libdir} -lkingate-fcgi | ||
11 | Cflags: -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 @@ | |||
1 | prefix=@prefix@ | ||
2 | exec_prefix=@exec_prefix@ | ||
3 | libdir=@libdir@ | ||
4 | includedir=@includedir@ | ||
5 | |||
6 | Name: kingate | ||
7 | Description: C++ CGI support library | ||
8 | Version: @VERSION@ | ||
9 | Requires: konforka | ||
10 | Libs: -L${libdir} -lkingate | ||
11 | Cflags: -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 @@ | |||
1 | Makefile.in | ||
2 | .deps | ||
3 | Makefile | ||
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 @@ | |||
1 | lib_LTLIBRARIES = libkingate.la libkingate-fcgi.la | ||
2 | |||
3 | INCLUDES = -I${top_srcdir}/include | ||
4 | AM_CXXFLAGS = ${KONFORKA_CFLAGS} | ||
5 | LDADD = ${KONFORKA_LIBS} | ||
6 | |||
7 | libkingate_la_SOURCES = \ | ||
8 | cgi_gateway.cc \ | ||
9 | cgi_interface.cc \ | ||
10 | util.cc | ||
11 | libkingate_la_LDFLAGS = -version-info 1:0:0 | ||
12 | |||
13 | libkingate_fcgi_la_SOURCES = \ | ||
14 | fastcgi.cc | ||
15 | libkingate_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 | |||
5 | namespace 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 | |||
4 | namespace 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 | |||
7 | namespace 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 | |||
4 | namespace 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 | } | ||