| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 1.91

 

cgi_get_input

#include "sflhttp.h"
char *
cgi_get_input (
    int iMethod )

Synopsis

Gets CGI data input from stdin or the enviorment vairable QUERY_STRING, to form a stream to be used by cgi_fld_by_name, cgi_fld_by_index and cgi_fld_len_by_index functions. After you have finshed with the input stream from this function you should call, cgi_free_input to free it up. Submitted by Scott Beasley jscottb@infoave.com

Source Code - (sflhttp.c)

{
    int iStdinLen = 0, iMethodWas = 0;
    char *strHead, *strRetBuf;

    if ( iMethod == CGIPOST || iMethod == CGIETHER )
      {
        if ( getenv ( "CONTENT_LENGTH" ) )
          {
            iStdinLen = atoi ( getenv ( "CONTENT_LENGTH" ) );
            iMethodWas = 1;
          }
      }

    if ( iMethod == CGIGET || iMethod == CGIETHER && !iStdinLen )
      {
        if ( getenv ( "QUERY_STRING" ) )
          {
            iStdinLen = strlen ( getenv ( "QUERY_STRING" ) );
            iMethodWas = 0;
          }
      }

    if ( !iStdinLen )
        return 0;

    strHead = strRetBuf = ( char * ) malloc ( sizeof ( char ) *
                                              iStdinLen + 1 );
    ASSERT ( strHead );

    memset ( strRetBuf, 0, iStdinLen + 1 );

    if ( iMethodWas == CGIPOST )
        fread ( strRetBuf, sizeof ( char ), iStdinLen, stdin );
    else
        strcpy ( strRetBuf, getenv ( "QUERY_STRING" ) );

    return *strHead ? strHead : ( char * ) NULL;
}

| << | < | > | >> iMatix Copyright © 1996-98 iMatix