cgiparse.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:2k
- //--------------------------------------------------------------------------
- // IP Stack CGI Demonstration Program
- //--------------------------------------------------------------------------
- // cgiparse.c
- //
- // Basic CGI Functions
- //
- // Author: Michael A. Denio
- // Adam K. Keys
- //
- // Copyright 2001 by Texas Instruments Inc.
- //-------------------------------------------------------------------------
- //#include "c:tic6000ndkincnetmain.h" /*change*/
- #include "netmain.h" /*change*/
- //
- // cgiParseVars()
- //
- // Reads input from a CGI post operation in pointed to by PostIn and
- // returns in sequence a pointer the name and then the value of each
- // post entry. This function modifies the data in PostIn. It also
- // returns the current parsing position in the variable pParseIndex.
- // The parse index must be set to 0 on initial call.
- //
- char *cgiParseVars(char PostIn[], int *pParseIndex )
- {
- int out;
- int in;
- char hexch;
- char hexval[3];
- int start;
- char ch;
- // Get the current parse index. On the first call, it
- // must be zero.
- in = *pParseIndex;
- hexval[2] = ' ';
- if( in == 0 )
- out = 0;
- else if( in == -1 )
- return NULL;
- else
- out = ++in;
- start = in;
- while (((ch = PostIn[in]) != '=') && (ch != '&') && (ch != ' '))
- {
- if (ch == '+')
- PostIn[out++] = ' ';
- else if (ch == '%')
- {
- hexval[0] = PostIn[++in];
- hexval[1] = PostIn[++in];
- hexch = (char) strtol(hexval, NULL, 16);
- PostIn[out++] = hexch;
- }
- else
- PostIn[out++] = ch;
- in++;
- }
- // If we got to the end of the string, set the parse index to -1
- if( ch == ' ' )
- in = -1;
- // Null terminate the result string
- PostIn[out++] = ' ';
- // Save the value of the current parse index
- *pParseIndex = in;
- // Return a pointer to the start of the result string
- return (&PostIn[start]);
- }