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

 

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 (NULL);

    strHead = strRetBuf = (char *) malloc (sizeof (char) *
                                           iStdinLen + 1);
    if (strHead == NULL)
        return (NULL);

    memset (strRetBuf, 0, iStdinLen + 1);
    if (iMethodWas == CGIPOST)
        fread (strRetBuf, sizeof (char), iStdinLen, stdin);
    else
        strncpy (strRetBuf, getenv ("QUERY_STRING"), (iStdinLen + 1));

    return (*strHead? strHead: NULL);
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation