Cgic Writing CGI Programs

Source: Internet
Author: User

Cgic is a C-language CGI library function for writing CGI programs

Cgic mainly accomplishes the following functions :

* Syntax analysis of the data

* Receive data sent in two ways in GET and Psot

* Connect the different domains in the form into contiguous strings

* Provide string, integer, floating point and single and multiple selection functions for retrieving FORM data

* Boundary detection for numeric fields

* Loading CGI environment variables into a non-empty C string

* Capturing CGI status for debugging

How to write Cgic applications

Any Cgic application must be connected to the CGIC.C, and if you can do this work with makefile under Linux.

Because CGI programs need to do some initialization, such as acquiring environment variables, analyzing data, and so on, so the Cgic library provides its own main () function, the Cgic program itself can no longer contain the main () function, but must start with the Cgimain () function, CGIC.C will call this function. Of course, this function name can be changed. Also note that the Cgic program that you write must contain #include<cigi.h>

That is to say, Cgic, has done some related parsing work, in its own main function as long as the call cigic in the corresponding function can be.

The following is the Cgimain () of the Cgic test program in the Cigic Library

[CPP]View PlainCopyprint?
  1. int Cgimain () {
  2. #ifdef DEBUG
  3. Loadenvironment ();
  4. #endif/* DEBUG */
  5. / * Load A previously saved CGI scenario if that button
  6. has been pressed. */
  7. if (cgiformsubmitclicked ("loadenvironment") = = cgiformsuccess) {
  8. Loadenvironment ();
  9. }
  10. / * Set any new cookie requested. Must is done *before*
  11. outputting the content type. */
  12. Cookieset ();
  13. / * Send The content type, letting the browser know this is HTML * /
  14. Cgiheadercontenttype ("text/html");
  15. / * Top of the page * /
  16. fprintf (Cgiout, "
  17. fprintf (Cgiout, "<title>cgic test</title>
  18. fprintf (Cgiout, "<body>
  19. / * If A Submit button has already been clicked, Act on the
  20. Submission of the form. */
  21. if ((Cgiformsubmitclicked ("testcgic") = = cgiformsuccess) | |
  22. Cgiformsubmitclicked ("saveenvironment") = = cgiformsuccess)
  23. {
  24. Handlesubmit ();
  25. fprintf (Cgiout, "
  26. }
  27. / * Now show the form * /
  28. ShowForm ();
  29. / * Finish up the page * /
  30. fprintf (Cgiout, "</body>
  31. return 0;
  32. }


[CPP]View PlainCopyprint?
    1. #ifdef DEBUG
    2. Loadenvironment ();
    3. #endif/* DEBUG */


In general, the above method is used to invoke environment variables for debugging. You can insert the statement: "#define DEBUG 1 will open debug mode.

Cgiheadercontenttype ("text/html") This function is mainly output content Type Header, tells the browser to return an HTML page, of course, can also be "image/gif", "Image/jpeg" and "Audio/wav

The outside point is that the CGI program prints HTML pages using printf to print the page one line at a time, like this piece of code in CGICTEST.C:
fprintf (Cgiout, "<textarea name=\" address\ "rows=4 cols=40>\n");
fprintf (Cgiout, "Default contents go here. \ n ");
fprintf (Cgiout, "</textarea>\n");
The result of this piece of code is to output a textarea on the page. The first parameter, Cgiout, is actually stdin, so we can use printf directly instead of using fprintf. However, the fprintf will be used to redirect the output when debugging

CGI debugging is cumbersome, Cgic provides a function to input environment variables into the file, easy to debug.

[CPP]View PlainCopyprint?
      1. Cgiwriteenvironment ("/etc/conf.d/c0/capcgi.dat");

Cgic Writing CGI Programs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.