ex_httpgetvar.c

Assume that the page "status.cgi" needs to display the serial number of the HTTP Web server device. The page "status.cgi" being served by the HTTP Server contains the following HTML line:

Serial Number=%S01

The 'S' is the Variable Group and the '01' is the VarValue in uppercase hex. During processing of this file, the HTTP Server encounters the %S01 string. After parsing it, the HTTP Server makes a callback to HTTPGetVar(httpInfo, val). The httpInfo->var.get.varRef will have the value HTTP_START_OF_VAR. The main user application implements HTTPGetVar as follows:

00001 
00018 #include "projdefs.h"
00019 #include "net\http.h"
00020 
00021 ROM char SerialNumberStr[] = "123456SER";
00022 
00023 WORD HTTPGetVar(HTTP_INFO* httpInfo, BYTE* val)
00024 {
00025     BYTE varValue, varGroup, ref;
00026 
00027     varValue = httpInfo->var.get.tagVal;        //Variable Value of requested variable
00028     varGroup = httpInfo->var.get.tagGroup;      //Variable Group of requested variable
00029     ref      = httpInfo->var.get.varRef;        //Current callback reference with respect
00030                                                 // to 'var' variable.
00031     
00032 
00033     //In case requested var not found, set it to NULL character and return HTTP_END_OF_VAR
00034     *val = '\0';    
00035     
00036     //Identify variable group
00037     if (varGroup == 'S')
00038     {
00039         // Identify variable value.
00040         if ( varValue == 0x01 )
00041         {
00042             // Serial Number is a NULL terminated string.
00043             // First of all determine, if this is very first call.
00044             if ( ref == HTTP_START_OF_VAR )
00045             {
00046                 // This is the first call. Initialize index to SerialNumber
00047                 // string. We are using ref as our index.
00048                 ref = (BYTE)0;
00049             }
00050             
00051             // Now access byte at current index and save it in buffer.
00052             *val = SerialNumberStr[(BYTE)ref];
00053             
00054             // Did we reach end of string?
00055             if ( *val == \0 )
00056             {
00057                 // Yes, we are done transferring the string.
00058                 // Return with HTTP_END_OF_VAR to notify HTTP server that we
00059                 // are finished transferring the value.
00060                 return HTTP_END_OF_VAR;
00061             } 
00062             // Or else, increment array index and return it to HTTP server.
00063             (BYTE)ref++;
00064             // Since value of ref is not HTTP_END_OF_VAR, HTTP server will call
00065             // us again for rest of the value.
00066             return ref;
00067         }
00068         else {
00069             // Check for other variables values...
00070         }
00071     }
00072 }
00073 

Generated on Mon Oct 9 13:22:06 2006 for SBC65EC Web Server by  doxygen 1.4.7