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&#39;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(&amp;request, =
0, 0);</div><div><br></div><div>=C2=A0 while(FCGX_Accept_r(&amp;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(=
&amp;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 &lt;&lt; HTTPHTMLHeader() &lt;&lt; HTMLDoctype( HTMLDoctyp=
e::eStrict ) &lt;&lt; endl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&lt;=
&lt; html().set( &quot;lang&quot;, &quot;en&quot; ).set( &quot;dir&quot;, &=
quot;ltr&quot; ) &lt;&lt; endl;</div><div><br></div><div>=C2=A0 =C2=A0 =C2=
=A0 // Set up the page&#39;s header and title.</div><div>=C2=A0 =C2=A0 =C2=
=A0 IO &lt;&lt; head() &lt;&lt; endl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0&lt;&lt; title() &lt;&lt; &quot;GNU cgicc v&quot; &lt;&lt; CGI.getVer=
sion() &lt;&lt; title() &lt;&lt; endl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0&lt;&lt; head() &lt;&lt; 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 &lt;&lt=
; body() &lt;&lt; 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 &lt;&lt; h1(&quot;Cgicc=
/FastCGI Test&quot;) &lt;&lt; endl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0&lt;&lt; &quot;PID: &quot; &lt;&lt; getpid() &lt;&lt; br() &lt;&lt; e=
ndl</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&lt;&lt; &quot;count: &quot=
; &lt;&lt; count++ &lt;&lt; br() &lt;&lt; endl;</div><div><br></div><div>=
=C2=A0 =C2=A0 =C2=A0 IO =C2=A0&lt;&lt; &quot;Form Elements:&quot; &lt;&lt; =
br() &lt;&lt; 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 &lt;&lt; i=
-&gt;getName() &lt;&lt; &quot; =3D &quot; &lt;&lt; i-&gt;getValue() &lt;&lt=
; br() &lt;&lt; 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 &lt;&lt; body() &lt;&lt; h=
tml();</div><div>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 catch(const except=
ion&amp;) {</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>&gt; 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 &quot;fcgi_stdio.h&quot;<br=
 class=3D"gmail_msg">#include &quot;cgicc/CgiDefs.h&quot;<br class=3D"gmail=
_msg">#include &quot;cgicc/Cgicc.h&quot;<br class=3D"gmail_msg">#include &q=
uot;cgicc/HTTPHTMLHeader.h&quot;<br class=3D"gmail_msg">#include &quot;cgic=
c/HTMLClasses.h&quot;<br class=3D"gmail_msg">#include &lt;iostream&gt;<br c=
lass=3D"gmail_msg">#include &lt;cstdlib&gt;<br class=3D"gmail_msg">#include=
 &lt;string&gt;<br class=3D"gmail_msg">#include &lt;sys/time.h&gt;<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=
()&gt;=3D0) {<br class=3D"gmail_msg">=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =
FCGI_printf(&quot;Content-type:text/html;charset=3Dutf-8\n\n&quot;);<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(&quot;%s&quot;,&quot;aaa&quot;);<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==--