CGI program _cgi

Source: Internet
Author: User
Tags fread rewind stdin wrapper

1. header file

#include <fcgi_stdio.h>

2, while (Fcgi_accept () >=0)//Here into the cycle, the front desk every request once fcgi service, on the cycle once

In-loop processing:

Char *query_string=getenv ("query_string");

3, from the query_string to resolve the query field, for follow-up operations.

4, with printf return processing results to the Web server, and then the Web server will return the results to the client.

(The printf function here is redefined in fcgi_stdio.h)

Attached: fcgi_stdio.h

/*
* Fcgi_stdio.h--
*
* Fastcgi-stdio Compatibility Package
*
*
* Copyright (c) 1996 Open Market, Inc.
*
* The file "LICENSE." TERMS "For information on usage and redistribution
* of this file, with a disclaimer of all warranties.
*
* $Id: fcgi_stdio.h,v 1.5 2001/06/22 13:21:15 robs Exp $
*/

#ifndef _fcgi_stdio
#define _fcgi_stdio 1

#include <stdio.h>
#include <sys/types.h>
#include "Fcgiapp.h"

#if defined (c_plusplus) | | Defined (__cplusplus)
extern "C" {
#endif

#ifndef DLLAPI
#ifdef _WIN32
#define DLLAPI __declspec (dllimport)
#else
#define Dllapi
#endif
#endif

/*
* Wrapper type for FILE
*/

typedef struct {
FILE *stdio_stream;
Fcgx_stream *fcgx_stream;
} fcgi_file;

/*
* The four new functions and two new macros
*/

Dllapi int fcgi_accept (void);
Dllapi void fcgi_finish (void);
Dllapi int fcgi_startfilterdata (void);
DLLAPI void fcgi_setexitstatus (int status);

#define Fcgi_tofile (Fcgi_file) (Fcgi_file->stdio_stream)
#define Fcgi_tofcgistream (Fcgi_file) (Fcgi_file->fcgx_stream)

/*
* Wrapper stdin, stdout, and stderr variables, set up by Fcgi_accept ()
*/

DLLAPI extern fcgi_file _fcgi_sf[];
#define Fcgi_stdin (&_fcgi_sf[0])
#define FCGI_STDOUT (&_fcgi_sf[1])
#define FCGI_STDERR (&_fcgi_sf[2])

/*
* Wrapper function prototypes, grouped according to sections
* of Harbison & Steele, "C:a Reference Manual," fourth edition,
* Prentice-hall, 1995.
*/

DLLAPI void Fcgi_perror (const char *STR);

DLLAPI fcgi_file *fcgi_fopen (const char *path, const char *mode);
Dllapi int Fcgi_fclose (Fcgi_file *fp);
Dllapi int Fcgi_fflush (Fcgi_file *fp);
DLLAPI fcgi_file *fcgi_freopen (const char *path, const char *mode, Fcgi_file *FP);

Dllapi int Fcgi_setvbuf (fcgi_file *fp, char *buf, int bufmode, size_t size);
Dllapi void Fcgi_setbuf (Fcgi_file *fp, char *buf);

Dllapi int Fcgi_fseek (fcgi_file *fp, long offset, int whence);
Dllapi int Fcgi_ftell (Fcgi_file *fp);
Dllapi void Fcgi_rewind (Fcgi_file *fp);
#ifdef Have_fpos
Dllapi int Fcgi_fgetpos (fcgi_file *fp, fpos_t *pos);
Dllapi int Fcgi_fsetpos (fcgi_file *fp, const fpos_t *pos);
#endif
Dllapi int fcgi_fgetc (Fcgi_file *fp);
Dllapi int Fcgi_getchar (void);
DLLAPI int fcgi_ungetc (int c, fcgi_file *FP);

Dllapi Char *fcgi_fgets (char *str, int size, fcgi_file *FP);
Dllapi Char *fcgi_gets (char *str);

/*
* Not yet implemented
*
* int fcgi_fscanf (fcgi_file *fp, const char *format, ...);
* int fcgi_scanf (const char *format, ...);
*
*/

DLLAPI int FCGI_FPUTC (int c, fcgi_file *FP);
DLLAPI int Fcgi_putchar (int c);

DLLAPI int fcgi_fputs (const char *STR, Fcgi_file *FP);
DLLAPI int fcgi_puts (const char *STR);

Dllapi int fcgi_fprintf (fcgi_file *fp, const char *format, ...);
DLLAPI int fcgi_printf (const char *format, ...);

Dllapi int fcgi_vfprintf (fcgi_file *fp, const char *format, va_list AP);
DLLAPI int fcgi_vprintf (const char *format, va_list AP);

Dllapi size_t fcgi_fread (void *ptr, size_t size, size_t nmemb, Fcgi_file *FP);
Dllapi size_t fcgi_fwrite (void *ptr, size_t size, size_t nmemb, Fcgi_file *FP);

Dllapi int fcgi_feof (Fcgi_file *fp);
Dllapi int Fcgi_ferror (Fcgi_file *fp);
Dllapi void Fcgi_clearerr (Fcgi_file *fp);

Dllapi fcgi_file *fcgi_tmpfile (void);

Dllapi int Fcgi_fileno (Fcgi_file *fp);
Dllapi fcgi_file *fcgi_fdopen (int fd, const char *mode);
DLLAPI fcgi_file *fcgi_popen (const char *cmd, const char *type);
Dllapi int Fcgi_pclose (fcgi_file *);

/*
* The remaining definitions are for application programs,
* Not for FCGI_STDIO.C
*/

#ifndef No_fcgi_defines

/*
* Replace standard types, variables, and functions with FastCGI wrappers.
* Use undef in case a macro is already defined.
*/

#undef FILE
#define FILE Fcgi_file

#undef stdin
#define STDIN Fcgi_stdin
#undef stdout
#define STDOUT Fcgi_stdout
#undef stderr
#define STDERR Fcgi_stderr

#undef perror
#define PERROR Fcgi_perror

#undef fopen
#define FOPEN Fcgi_fopen
#undef fclose
#define Fclose Fcgi_fclose
#undef fflush
#define Fflush Fcgi_fflush
#undef Freopen
#define Freopen Fcgi_freopen

#undef SETVBUF
#define SETVBUF Fcgi_setvbuf
#undef SETBUF
#define SETBUF Fcgi_setbuf

#undef fseek
#define Fseek Fcgi_fseek
#undef Ftell
#define Ftell Fcgi_ftell
#undef Rewind
#define REWIND Fcgi_rewind
#undef Fgetpos
#define FGETPOS Fcgi_fgetpos
#undef Fsetpos
#define FSETPOS Fcgi_fsetpos

#undef fgetc
#define FGETC FCGI_FGETC
#undef GETC
#define GETC FCGI_FGETC
#undef GetChar
#define GETCHAR Fcgi_getchar
#undef UNGETC
#define UNGETC FCGI_UNGETC

#undef fgets
#define Fgets Fcgi_fgets
#undef gets
#define GETS Fcgi_gets

#undef FPUTC
#define FPUTC FCGI_FPUTC
#undef PUTC
#define PUTC FCGI_FPUTC
#undef Putchar
#define PUTCHAR Fcgi_putchar

#undef fputs
#define Fputs Fcgi_fputs
#undef puts
#define PUTS Fcgi_puts

#undef fprintf
#define FPRINTF fcgi_fprintf
#undef printf
#define PRINTF fcgi_printf

#undef vfprintf
#define VFPRINTF fcgi_vfprintf
#undef vprintf
#define VPRINTF fcgi_vprintf

#undef fread
#define Fread Fcgi_fread
#undef fwrite
#define Fwrite Fcgi_fwrite

#undef feof
#define FEOF fcgi_feof
#undef ferror
#define FERROR Fcgi_ferror
#undef Clearerr
#define CLEARERR Fcgi_clearerr

#undef tmpfile
#define Tmpfile Fcgi_tmpfile

#undef Fileno
#define Fileno Fcgi_fileno
#undef Fdopen
#define Fdopen Fcgi_fdopen
#undef Popen
#define Popen Fcgi_popen
#undef Pclose
#define Pclose Fcgi_pclose

#endif/* No_fcgi_defines * *

#if defined (__cplusplus) | | Defined (c_plusplus)
}/* terminate extern "C" {* * *
#endif

#endif/* _fcgi_stdio * *

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.