⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wmwusrfuncs.c

📁 firewall PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* wmwUsrFuncs.c - User implemented functions for Wind Manage for Web *//* Copyright 2004 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01e,12may05,zhu  cleaned up compiler warnings01d,24feb04,zhu  moved customized function from postreply to RPM01c,11feb04,zhu  updated postreply02b,05feb04,zhu  updated01a,30jan04,zhu  created*//*DESCRIPTIONThe functions in this module are called by the WMW server, but shouldbe implemented by the user.*//*#define FW_WEB_DEBUG*/#ifdef FW_WEB_DEBUGint fwWebDebug3 = 0;#define DBG_PRINT(X) \    do { \    if (fwWebDebug3) \        printf X; \    }while(0)#else#define DBG_PRINT(X)#endif#define DEBUG_INFO#include "wm.h"#include "httpLib.h"#include "private/httpReq.h"#include "fwWebDevice.h"/********************************************************************************* httpWindMarkSetFailed - called when a WindMark write attempt has failed** By default Wind Mark set attempts that fail remain in the request environment,* so the user can retrieve them later, when httpPostReply is called.* This function is called right after each failed set attempt so the user can* store more information about the error in the environment, such as the errno or* a custom error message.  The information stored at this point can be retrieved* by httpPostReply by calling httpWmbErrorIterator** This function should be implemented by the user** RETURNS: HTTP_OK*/void httpWindMarkSetFailed    (    HTTP_REQ_ID reqId,    sbyte *     windMark,    ubyte4      errnoVal    )    {    sbyte *     errorMsg;    MEM_POOL_ID reqMemPool = httpReqMemPartIdGet(reqId);    /* this memory will be freed by the server after request is processed */    errorMsg = memPoolAlloc (reqMemPool, 80);    /* create the custom error message based on the returned errno */    sprintf(errorMsg, "WindMark(%s) set attempt failed. errno: %08x", windMark, errnoVal);    printf("WindMark(%s) set attempt failed. errno: %08x\n", windMark, errnoVal);    /* store it */    if (NULL == httpWmbErrorStore(reqId, windMark, errorMsg))        logInfoMsg ("unable to store error message for %s", windMark);    return;    }/********************************************************************************* httpWindMarkGetFailed - called when the value of a WindMark could not be read** This function is provided so the user can configure the way the server behaves* when WindMark read errors occur.  On some applications it may be better to* just ignore the WindMark silently.  In those cases the function should just* return a pointer to an empty string.** In other cases, like the one shown in this example, an error message is* printed on the HTML page.  The messages shows the WindMark that could not* be read along with the errno code returned by the backplane.** The user should implement this function.** RETURNS:*/sbyte * httpWindMarkGetFailed    (    HTTP_REQ_ID reqId,    sbyte *     windMark,	ubyte4      errnoVal    )    {	sbyte * errorMsg = httpBufferGet(reqId);    /* build a string that will replace the WindMark that failed */    sprintf(errorMsg, "WindMark(%s) read attempt failed. errno: %08x", windMark, errnoVal);    printf("WindMark(%s) read attempt failed. errno: %08x \n", windMark, errnoVal);    return errorMsg;    }/********************************************************************************* httpPostReply - show some output to the browser** This is an example reply.  The user will have to modify this function to* customize the response to a POST** RETURNS: HTTP_OK*/void httpPostReply    (    HTTP_REQ_ID reqId,    HTTP_STATUS status /* choose OK or ERROR message to be sent to the browser */    )    {    sbyte* 	failedWM;    sbyte* 	errorMsg;    sbyte*  redirUrl;    HTTP_GEN_LIST_ENTRY_ID errEntry = NULL;    DBG_PRINT(("httpPostReply gets called!\n"));     if(HTTP_OK == status)        {        /* in this version of httpPostReply, the browser is redirected to           a different URL by means of HTTP error 303.           Use the form 'action' field to let the server know where to redirect           the post reply in the following way:           if post is mapped to url substring "/urlpost/", and you want your           redirection to go to "wmb/doc/jsform.html", set your action field to          "/urlpost/wmb/doc/jsform.html"         */         redirUrl = httpBufferGet (reqId);         strcpy (redirUrl, "/");         strcat (redirUrl, httpRpmDataGet(reqId));        /* if there are WindMark GET/SET errors, show an error page that           links to the intended reidrect page instead of the redirect        */        if (TRUE == httpWmbErrorsExist(reqId))            {            httpMimeContentTypeSet(reqId, HDR_OUT, "text/html");            httpStatusSet (reqId, HTTP_OK);       /* Set the HTTP status code     */            httpHeaderGenerate (reqId);           /* Send HTTP header             */            httpPrintf(reqId, "<HTML><BODY>\n");            httpPrintf(reqId, "<CENTER><H1>Post failed!</H1></CENTER>");            httpPrintf(reqId, "<HR><H3>The following WMB access errors were encountered:</H3>");                while (NULL != (errEntry = httpWmbErrorIterator(reqId, errEntry,                                                                &failedWM, &errorMsg)))                    {                    httpPrintf (reqId, "<B>%s</B> <FONT COLOR=\"red\">%s</FONT><BR>", failedWM, errorMsg);                    }            httpPrintf(reqId, "<p>Return to the <a href=\"%s\">previous page</a>.</p>", redirUrl);            httpPrintf(reqId, "</HTML></BODY>\n");            }        else            {	    httpMimeHdrSet (reqId, HDR_OUT, "Location", redirUrl);	    httpStatusSet (reqId, HTTP_SEE_OTHER);/* Set the HTTP status code     */	    httpHeaderGenerate (reqId);           /* Send HTTP header             */	    httpPrintf(reqId, "<HTML><BODY>\n");	    httpPrintf(reqId, "redirected to %s\n", redirUrl);	    httpPrintf(reqId, "click <a href=\"%s\">here </a>", redirUrl);            httpPrintf(reqId, "if your browser doesn't redirect you automatically\n");	    httpPrintf(reqId, "</BODY></HTML>\n");            DBG_PRINT(("httpPostReply redirect to %s!\n", redirUrl )); 	    }        }    else        {        httpMimeContentTypeSet(reqId, HDR_OUT, "text/html");        httpStatusSet (reqId, HTTP_NOT_ACCEPTED);  /* Set the HTTP status code */        httpHeaderGenerate (reqId);                /* Send HTTP header         */        httpPrintf(reqId, "<HTML><BODY>\n");        httpPrintf(reqId, "<HR><H2>Post failed!</H2>\n");        httpPrintf(reqId, "The firewall operation was not stored on the server\n");        httpPrintf(reqId, "</HTML></BODY>\n");        }    DBG_PRINT(("httpPostReply returns!\n"));     return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -