www.pudn.com > Firewall_PNE_3_3.zip > wmw_httpconf.c, change:2009-03-16,size:6844b


/*
 *  wmw_httpconf.c 
 *
 *  This is a part of a Wind River Management SDK source code library.
 *
 *  Copyright (C) 2005 Wind River Systems
 *  Version 4.40
 *  All rights reserved.
 *
 */


/* WARNING:  This file will be generated by a Wind River Management Integration
 * Tool.  Any changes made to this file may be overwritten by
 * subsequent uses of the tool. */

/* - Global defaults and user definable variables. */
/* includes */
#include "stdlib.h"
#include "wm.h"
#include "httpLib.h"
#include "httpRpms.h"
#include "wmw_httpconf.h"

#include "fwWebDevice.h"

/* header and footer lines ap/pre-pended to any Wind River Management Web Server error report */
const char * const httpErrorHeader =
	"<H1>Wind Manage Web Server Error Report:</H1><HR>\n"; 
const char * const httpErrorFooter =
	"<H3>please mail problems to ???@www.???.com</H3><HR>\n"; 

/* standard system error messages, DO NOT change the order! */
const char * const httpSysErrorTab[] =
{
	"Internal httpd failure / program error",
	"No RPM for this combination of URL and method",
	"URL parsing error",
	"File not found",
	"IO error, transfer interrupted",
	"Access denied",
	"RPM configuration error",
	"Out of memory, can not handle request"
};

/* # of entries in httpSysErrorTab */
const unsigned short httpMaxErrors = sizeof (httpSysErrorTab)/sizeof (char*);


/*
 *
 * httpd - the main routine of the server
 *
 * This routine is called once at start-up as the server task.
 * Under normal circumstances it should not terminate.
 * For debugging there is an exit URL to terminate the server
 *
 * RETURNS: ERROR on termination
 *
 */
HTTP_STATUS httpd(void)
{
	if (httpInit() != HTTP_OK)
		return HTTP_ERROR;

	
/*
 * This section allows scalability and configures the functionality:
 * only RPMs referenced in the following sections will be linked.
 *
 * configuration of user RPMs to be invoked for GET requests:
 * (GET requests are used for normal downloads to client software)
 * this table provides a URL-identifier for each GET-RPM
 * eg: all URLs starting with "/hello" will be processed by rpmHello
 * NOTE: the URL identifiers MUST be ordered by length, best-fit first!
 *       the RPM with the first matching identifier in the list wins
 */



/*
 * configuration of the aliasing table for the alias rpm
 * Syntax: "requested path in url", "path to be substituted"
 * remark: only one asterisk in the requested path may occur, which
 *         in turn will be replaced by the second string.
 * Example: "* /" -> "* /index.html" will convert "/pub/" to "/pub/index.html"
 *       (the ^ above spaces are just for the compiler ... normally,
 *        there should be no spaces in between * and /!!!)
 */
    httpAliasConfAdd("/filterrules.htm", "/wmb/doc/filterrules.htm");
    httpAliasConfAdd("/images/*", "/fs/images/*");
    httpAliasConfAdd("/setup.htm", "/wmb/doc/setup.htm");
    httpAliasConfAdd("/",    "/wmb/doc/setup.htm");
    httpAliasConfAdd("/validate.js", "/wmb/doc/validate.js");
    httpAliasConfAdd("*/",   "/wmb/doc/setup.htm");

/*
 * configuration of http server security
 */

/* enable filesystem RPM to access pages from filesystem */
    httpRpmConfAdd(HTTP_M_GET, "/fs/", httpRpmFs);
    httpFsConfAdd("/fs/",    "/tgtsvr/");
    httpRpmConfAdd(HTTP_M_GET, "/wmb/", httpRpmWmbParse);
    httpRpmConfAdd(HTTP_M_GET, "/wmb/", httpRpmFs);
    httpFsConfAdd("/wmb/",   "/tgtsvr/");
    httpFileSetDefaultFs(ANSI_FS);
    httpFileRegister("/tgtsvr/doc/filterrules.htm", MEM_FS, "text/html", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    httpFileRegister("/tgtsvr/doc/setup.htm", MEM_FS, "text/html", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    httpFileRegister("/tgtsvr/doc/validate.js", MEM_FS, "application/x-javascript", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    httpFileRegister("/tgtsvr/images/filler.gif", MEM_FS, "image/gif", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    httpFileRegister("/tgtsvr/images/footer.gif", MEM_FS, "image/gif", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    httpFileRegister("/tgtsvr/images/tile.jpg", MEM_FS, "image/jpeg", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    httpFileRegister("/tgtsvr/images/wr_logo.gif", MEM_FS, "image/gif", NULL, NULL, NULL, NULL, NULL, NULL, NULL);

/*
 * configuration of the form post RPM to process a form of type
 * application/x-www-form-urlencoded.
 * This RPM stores all the name=value pairs in the server environment
 * for other RPMs to use.
 */
    httpRpmConfAdd(HTTP_M_POST, "/wmb/", httpRpmPost);

/*
 * configuration of custom RPMs
 */
    httpRpmConfAdd(HTTP_M_POST, "/wmb/", fwWebHttpRpmWmbPost);
	


    /*
     * Call the Server
     */

    return (httpServerStart());
}

/**************************************************************************
*
* httpGetWmbComp - Get the server's component ID for WMB
*
* The component id is initialized by httpWmbInit() at start up, and is
* needed to start WMB sessions.
*
* RETURNS: the component id or null
*
*/

static WMB_COMPONENT_T * httpWmbComponentId = NULL;

WMB_COMPONENT_T * httpGetWmbComp
   (
    void
    )
    {
    return httpWmbComponentId;
    }


#ifdef __WM_EVENT_MANAGER__
/**************************************************************************
*
* fwWebScreenComponent_WmwListener - Receive events from the WMB.
*
* RETURNS: void
*
*/

void fwWebScreenComponent_WmwListener
    (
    WMB_EM_EVENT_T *pEmEvent
    )
    {
    WMB_PORTFOLIO_T *portfolio;

    switch (pEmEvent->wmbEvent.eventType)
        {
        case WMB_EVENT_TYPE_CONTROL:
            break;

        case WMB_EVENT_TYPE_PORTFOLIO:
            switch (pEmEvent->wmbEvent.eventID)
                {
                case WMB_PORTFOLIO_CREATED_EVENT:
                    if (OK == wmbPortfolioGet("wmw", "xml", &portfolio))
                        {
                        httpPortfolioRead(portfolio->fileName);
                        }
                    break;

                }
            break;

        default:
            break;
        }
    }
#endif /* __WM_EVENT_MANAGER__ */

/**************************************************************************
*
* fwWebScreenComponent_Web_Start - Starts up the Web blade of this component.
*
* RETURNS: OK
*
*/

STATUS fwWebScreenComponent_Web_Start
    (
    WMB_COMPONENT_T *cid
    )
{
#ifdef __WIN32_OS__
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;

    /* Set the registered Component ID */
    httpWmbComponentId = cid;

    wVersionRequested = MAKEWORD(2, 2);

    err = WSAStartup(wVersionRequested, &wsaData);
    if (err != 0)
    {
        return wmosError(ERROR_GENERAL, "Could not find WinSock.dll");
    }
    httpd();
    while(1) wmosTimeSleep(10000);
    return OK;

#else

    /* Set the registered Component ID */
    httpWmbComponentId = cid;

    httpd();
    return OK;

#endif /* __WIN32_OS__ */
}