Re: cgicc bug when use fcgi and cgicc post
"Stephen F. Booth" <[email protected]> Mon, 24 Oct 2016 11:51:05 +0000
| Newsgroups | gmane.comp.gcc.cgicc.bugs |
|---|---|
| Message-ID | <CAFMowGU8ncn5j7GtHPb=_CmVOdd6H2xycLHFmp0GN-i+HhNObA@mail.gmail.com> |
--===============0557792297507682424==
Content-Type: multipart/alternative; boundary=001a11478f1a66dca2053f9b02c8
--001a11478f1a66dca2053f9b02c8
Content-Type: text/plain; charset=UTF-8
In order to use FastCGI with Cgicc it's necessary to create a subclass of
CgiInput. There is an example in the contrib/ directory for Cgicc 3.2.16.
Your main function will look something like:
int
main(int /*argc*/,
const char **/*argv*/,
char **/*envp*/)
{
unsigned count = 0;
FCGX_Request request;
FCGX_Init();
FCGX_InitRequest(&request, 0, 0);
while(FCGX_Accept_r(&request) == 0) {
try {
FCgiIO IO(request);
Cgicc CGI(&IO);
// Output the HTTP headers for an HTML document, and the HTML 4.0 DTD
info
IO << HTTPHTMLHeader() << HTMLDoctype( HTMLDoctype::eStrict ) << endl
<< html().set( "lang", "en" ).set( "dir", "ltr" ) << endl;
// Set up the page's header and title.
IO << head() << endl
<< title() << "GNU cgicc v" << CGI.getVersion() << title() << endl
<< head() << endl;
// Start the HTML body
IO << body() << endl;
// Print out a message
IO << h1("Cgicc/FastCGI Test") << endl
<< "PID: " << getpid() << br() << endl
<< "count: " << count++ << br() << endl;
IO << "Form Elements:" << br() << endl;
for(const_form_iterator i = CGI.getElements().begin();
i != CGI.getElements().end(); ++i )
IO << i->getName() << " = " << i->getValue() << br() << endl;
// Close the document
IO << body() << html();
}
catch(const exception&) {
// handle error condition
}
FCGX_Finish_r(&request);
}
return 0;
}
Stephen
On Sat, Oct 22, 2016 at 9:38 AM 902490 <[email protected]> wrote:
> hi,when i post data to cgi,the process will exit,but get data all right.
> wait for your help,thanks
>
> env yum install -y fcgi-devel
> spawn-fcgi *.cpp -o 1.cgi -lfcgi -lcgicc
>
> #include "fcgi_stdio.h"
> #include "cgicc/CgiDefs.h"
> #include "cgicc/Cgicc.h"
> #include "cgicc/HTTPHTMLHeader.h"
> #include "cgicc/HTMLClasses.h"
> #include <iostream>
> #include <cstdlib>
> #include <string>
> #include <sys/time.h>
>
> using namespace std;
> using namespace cgicc;
>
> int main() {
> while(FCGI_Accept()>=0) {
> FCGI_printf("Content-type:text/html;charset=utf-8\n\n");
> Cgicc cgi;
>
> FCGI_printf("%s","aaa");
> }
> return 0;
> }
>
> _______________________________________________
> bug-cgicc mailing list
> [email protected]
> https://lists.gnu.org/mailman/listinfo/bug-cgicc
>
--001a11478f1a66dca2053f9b02c8
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">In order to use FastCGI with Cgicc it's necessary to c=
reate a subclass of CgiInput.=C2=A0 There is an example in the contrib/ dir=
ectory for Cgicc 3.2.16.=C2=A0 Your main function will look something like:=
<div><br></div><div><div>int=C2=A0</div><div>main(int /*argc*/,=C2=A0</div>=
<div>=C2=A0 =C2=A0 =C2=A0const char **/*argv*/,=C2=A0</div><div>=C2=A0 =C2=
=A0 =C2=A0char **/*envp*/)</div><div>{</div><div>=C2=A0 unsigned count =3D =
0;</div><div><br></div><div>=C2=A0 FCGX_Request request;</div><div><br></di=
v><div>=C2=A0 FCGX_Init();</div><div>=C2=A0 FCGX_InitRequest(&request, =
0, 0);</div><div><br></div><div>=C2=A0 while(FCGX_Accept_r(&request) =
=3D=3D 0) {</div><div><br></div><div>=C2=A0 =C2=A0 try {</div><div>=C2=A0 =
=C2=A0 =C2=A0 FCgiIO IO(request);</div><div>=C2=A0 =C2=A0 =C2=A0 Cgicc CGI(=
&IO);</div><div><br></div><div>=C2=A0 =C2=A0 =C2=A0 // Output the HTTP =
headers for an HTML document, and the HTML 4.0 DTD info</div><div>=C2=A0 =
=C2=A0 =C2=A0 IO << HTTPHTMLHeader() << HTMLDoctype( HTMLDoctyp=
e::eStrict ) << endl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<=
< html().set( "lang", "en" ).set( "dir", &=
quot;ltr" ) << endl;</div><div><br></div><div>=C2=A0 =C2=A0 =C2=
=A0 // Set up the page's header and title.</div><div>=C2=A0 =C2=A0 =C2=
=A0 IO << head() << endl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0<< title() << "GNU cgicc v" << CGI.getVer=
sion() << title() << endl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
=C2=A0<< head() << endl;</div><div><br></div><div>=C2=A0 =C2=
=A0 =C2=A0 // Start the HTML body</div><div>=C2=A0 =C2=A0 =C2=A0 IO <<=
; body() << endl;</div><div><br></div><div>=C2=A0 =C2=A0 =C2=A0 // Pr=
int out a message</div><div>=C2=A0 =C2=A0 =C2=A0 IO << h1("Cgicc=
/FastCGI Test") << endl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0<< "PID: " << getpid() << br() << e=
ndl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0<< "count: "=
; << count++ << br() << endl;</div><div><br></div><div>=
=C2=A0 =C2=A0 =C2=A0 IO =C2=A0<< "Form Elements:" << =
br() << endl;</div><div><br></div><div>=C2=A0 =C2=A0 =C2=A0 for(const=
_form_iterator i =3D CGI.getElements().begin();=C2=A0</div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre"> </span> =C2=A0i !=3D CGI.get=
Elements().end(); ++i )</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 IO << i=
->getName() << " =3D " << i->getValue() <<=
; br() << endl;</div><div><br></div><div>=C2=A0 =C2=A0 =C2=A0 // Clos=
e the document</div><div>=C2=A0 =C2=A0 =C2=A0 IO << body() << h=
tml();</div><div>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 catch(const except=
ion&) {</div><div>=C2=A0 =C2=A0 =C2=A0 // handle error condition</div><=
div>=C2=A0 =C2=A0 }</div><div><br></div><div>=C2=A0 =C2=A0 FCGX_Finish_r(&a=
mp;request);</div><div>=C2=A0 }</div><div><br></div><div>=C2=A0 return 0;</=
div><div>}</div></div><div><br></div><div>Stephen</div></div><br><div class=
=3D"gmail_quote"><div dir=3D"ltr">On Sat, Oct 22, 2016 at 9:38 AM 902490 &l=
t;<a href=3D"mailto:[email protected]">[email protected]</a>> wrote:<br></div><b=
lockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px =
#ccc solid;padding-left:1ex">hi,when i post data to cgi,the process will ex=
it,but get data all right.<br class=3D"gmail_msg">wait for your help,thanks=
<br class=3D"gmail_msg"><br class=3D"gmail_msg">env yum install -y fcgi-dev=
el<br class=3D"gmail_msg">spawn-fcgi *.cpp -o 1.cgi -lfcgi -lcgicc<br class=
=3D"gmail_msg"><br class=3D"gmail_msg">#include "fcgi_stdio.h"<br=
class=3D"gmail_msg">#include "cgicc/CgiDefs.h"<br class=3D"gmail=
_msg">#include "cgicc/Cgicc.h"<br class=3D"gmail_msg">#include &q=
uot;cgicc/HTTPHTMLHeader.h"<br class=3D"gmail_msg">#include "cgic=
c/HTMLClasses.h"<br class=3D"gmail_msg">#include <iostream><br c=
lass=3D"gmail_msg">#include <cstdlib><br class=3D"gmail_msg">#include=
<string><br class=3D"gmail_msg">#include <sys/time.h><br class=
=3D"gmail_msg"><br class=3D"gmail_msg">using namespace std;<br class=3D"gma=
il_msg">using namespace cgicc;<br class=3D"gmail_msg"><br class=3D"gmail_ms=
g">int main() {<br class=3D"gmail_msg">=C2=A0=C2=A0=C2=A0 while(FCGI_Accept=
()>=3D0) {<br class=3D"gmail_msg">=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
FCGI_printf("Content-type:text/html;charset=3Dutf-8\n\n");<br cla=
ss=3D"gmail_msg">=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 Cgicc cgi;<br class=
=3D"gmail_msg"><br class=3D"gmail_msg">=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=
=A0 FCGI_printf("%s","aaa");<br class=3D"gmail_msg">=C2=
=A0=C2=A0=C2=A0 }<br class=3D"gmail_msg">=C2=A0=C2=A0=C2=A0 return 0;<br cl=
ass=3D"gmail_msg">}<br class=3D"gmail_msg"><br class=3D"gmail_msg">________=
_______________________________________<br class=3D"gmail_msg">
bug-cgicc mailing list<br class=3D"gmail_msg">
<a href=3D"mailto:[email protected]" class=3D"gmail_msg" target=3D"_blank">=
[email protected]</a><br class=3D"gmail_msg">
<a href=3D"https://lists.gnu.org/mailman/listinfo/bug-cgicc" rel=3D"norefer=
rer" class=3D"gmail_msg" target=3D"_blank">https://lists.gnu.org/mailman/li=
stinfo/bug-cgicc</a><br class=3D"gmail_msg">
</blockquote></div>
--001a11478f1a66dca2053f9b02c8--
--===============0557792297507682424==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
bug-cgicc mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-cgicc
--===============0557792297507682424==--