webpage.c
上传用户:dahaojd
上传日期:2008-01-29
资源大小:14357k
文件大小:3k
- //--------------------------------------------------------------------------
- // IP Stack Client Demo
- //--------------------------------------------------------------------------
- // webpage.c
- //
- // Web page and CGI function
- //
- // Author: Michael A. Denio
- // Copyright 2000, 2001 by Texas Instruments Inc.
- //-------------------------------------------------------------------------
- #include <std.h>
- #include <sys.h>
- #include <sem.h>
- #include <tsk.h>
- #include "netmain.h" /*change*/
- #include "thrControl.h"/*change*/
- #pragma DATA_SECTION(DEFAULT, "OBJMEM");
- #include "webdatadefault.c"
- #pragma DATA_SECTION(TIBUG, "OBJMEM");
- #include "webdatatibug.c"
- #pragma DATA_SECTION(JAVA1, "OBJMEM");
- #include "webdatajava1.c"
- #pragma DATA_SECTION(JAVA2, "OBJMEM");
- #include "webdatajava2.c"
- static int cgiConfig( SOCKET htmlSock, int ContentLength, char *pArgs );
- extern char *cgiParseVars(char PostIn[], int *pParseIndex );
- void AddWebFiles(void)
- {
- efs_createfile("index.html", DEFAULT_SIZE, DEFAULT);
- efs_createfile("tibug.jpg", TIBUG_SIZE, TIBUG);
- efs_createfile("easyCam.class", JAVA1_SIZE, JAVA1);
- efs_createfile("easyCam$1.class", JAVA2_SIZE, JAVA2);
- efs_createfile("cfgquality.cgi", 0, (UINT8*)cgiConfig);
- }
- void RemoveWebFiles(void)
- {
- efs_destroyfile("index.html");
- efs_destroyfile("tibug.jpg");
- efs_destroyfile("cfgquality.cgi");
- efs_destroyfile("easyCam.class");
- efs_destroyfile("easyCam$1.class");
- }
- #define html(str) httpSendClientStr(htmlSock, (char *)str)
- //
- // cgiConfig()
- //
- static int cgiConfig( SOCKET htmlSock, int ContentLength, char *pArgs )
- {
- char *qualstr = 0;
- char *buffer, *key, *value;
- int len,quality;
- int parseIndex;
- // CGI Functions can now support URI arguments as well if the
- // pArgs pointer is not NULL, and the ContentLength were zero,
- // we could parse the arguments off of pArgs instead.
- // First, allocate a buffer for the request
- buffer = (char*) mmBulkAlloc( ContentLength + 1 );
- if ( !buffer )
- goto ERROR;
- // Now read the data from the client
- len = recv( htmlSock, buffer, ContentLength, MSG_WAITALL );
- if ( len < 1 )
- goto ERROR;
- // Setup to parse the post data
- parseIndex = 0;
- buffer[ContentLength] = ' ';
- // Process request variables until there are none left
- do
- {
- key = cgiParseVars( buffer, &parseIndex );
- value = cgiParseVars( buffer, &parseIndex );
- if( !strcmp("quality", key) )
- qualstr = value;
- } while ( parseIndex != -1 );
- //
- // Output the data we read in...
- //
- httpSendStatusLine(htmlSock, HTTP_OK, CONTENT_TYPE_HTML);
- // CRLF before entity
- html( CRLF );
- //
- // Generate response
- //
- // If the password is incorrect or missing, generate an error
- if( qualstr )
- {
- quality = 0;
- while( *qualstr )
- quality = quality * 10 + (*qualstr++ - '0');
- if( quality > 0 && quality <= 100 )
- thrControlSet( 1, quality );
- }
- // Send back the same default page
- send( htmlSock, DEFAULT, DEFAULT_SIZE, 0 );
- ERROR:
- if( buffer )
- mmBulkFree( buffer );
- return( 1 );
- }