ex_httpexecgetcmd.c

Consider the HTML page "power.cgi", as displayed by a remote browser:

<html><body>
    <FORM METHOD=GET action=POWER.CGI>
    <table>
        <tr>
            <td>Power Level:</td>
            <td><input type=text size=2 maxlength=1 name=P value=%p07></td>
        </tr>
        <tr>
            <td>Low Power Setting:</td>
            <td><input type=text size=2 maxlength=1 name=L value=%p08></td>
        </tr>
        <tr>
            <td>High Power Setting:</td>
            <td><input type=text size=2 maxlength=1 name=H value=%p09></td>
        </tr>
        <tr>
            <td colspan=2><input type=submit name=B value=Apply></td>
        </tr>
    </table>
    </form>
</body></html>

This page displays a table with labels in the first column and text box values in the second column. The first row, first column cell contains the string "Power Level". The second column is a text box to display and modify the power level value. The last row contains a button labelled "Apply". A user viewing this page has the ability to modify the value in the Power Level text box and click on "Apply" button to submit the new power level value to the Modtronix SBC65EC Web Server. Assume that a user enters values of ‘5’, ‘1’ and ‘9’ in Power Level, Low Power Setting and High Power Setting text boxes respectively, then clicks on the "Apply" button. The browser would create a HTTP request string "POWER.CGI?P=5&L=1&H=9" and send it to the HTTP server. The server in turn calls the HTTPExecGetCmd() callback function.

The main application implements HTTPExecGetCmd as below:

#include "projdefs.h"
#include "net\http.h"


void HTTPExecGetCmd(HTTP_INFO* httpInfo, BYTE* rqstRes)
{
    BYTE param[20];
    int PowerLevel, LowPowerSetting, HighPowerSetting;

    //Used as input AND output parameter for HTTPGetParams.
    // - Input parameter indicates size of param buffer
    // - On return of HTTPGerParam() valueIdx will contain index of value string in param
    BYTE valueIdx;
    BYTE moreParams;

    //Get next name-value parameter until we have retrieved them all
    do {
        valueIdx = (BYTE)sizeof(param);   //Input parameter is size of param buffer

        //Get name-value parameters. Returns true if there are more name-value
        //parameters to follow
        //- Pointer to Name parameter = &param[0]
        //- Pointer to Value parameter = &param[valueIdx]
        moreParams = HTTPGetParam(httpInfo->socket, param, &valueIdx);

        //Identify parameter - param[0] contains the first character of the name part
        if ( param[0] == 'P') // Is this power level?
        {
            //The value is the Power level value. The value string is = &param[valueIdx]
            PowerLevel = atoi((char*)&param[valueIdx]);
        }
        else if ( param[0] == 'L') // Is this Low Power Setting?
            LowPowerSetting = atoi((char*)&param[valueIdx]);
        else if ( param[0] == 'H' ) // Is this High Power Setting?
            HighPowerSetting = atoi((char*)&param[valueIdx]);
    } while (moreParams);


    // If another page is to be displayed as a result of this command, copy
    // its upper case name into rqstRes.
    //strcpy(rqstRes, "RESULTS.CGI");
}


Generated on Wed Feb 3 12:45:33 2010 for SBC65EC Web Server by  doxygen 1.5.8