?? fwwebhttprpmwmbpost.c
字號(hào):
/* httpRpmWmbPost.c - WindMark POST request processing modules *//* Copyright 2001-2004 Wind River Systems, Inc. *//*modification history--------------------01l,13aug04,zhu allow setting all in POST01k,11aug04,zhu customized for firewall webscreen, porting to dual stack01j,27dlr04,dlr Do not destroy the optional GET session if not created in httpRpmWmbPostExec01i,06may04,vmk error handling for wmbTransactionProcess ( spr#91378)01h,27apr04,adb replaced all buffer size constants with kMagicMarkupBufferSize01g,10mar04,adb NULL instance to empty sting conversion01f,03mar04,gsr for inline instancing set operation SPR#9100801e,16jan04,jws remove per project dependencies01d,18aug03,jws documentation updates01c,24jul03,jws SPR 89657 work and general clean-up01b,16jun03,adb introduced tempBuf in lclBuildSetTrans01a,06nov01,jc initial creation.*//*DESCRIPTIONThis library contains request processing modules (RPMs) for settingWindmarks via an http POST. These standard RPMs can be associated with URLsusing the WMIT project configuration tool.In addition, the function httpRpmWmbPostExec() can be called by a user customRPM to do Windmark POST processing with various options not available using the"standard" RPMs. For example, a custom RPM which would set only posted itemswhose value has changed could be as simple as:\csshort customRPM ( HTTP_REQ_ID reqId ) { return httpRpmWmbPostExec(reqId,RPM_CHANGE_ONLY_SET); }\ceBefore the functions in this library are called to process a request, somepre-processing of the data must be done. The functions httpRpmUpload() orhttpRpmPost() copy any name=value duplets in the CGI stream (the http request)to the server's environment. Functions here will look for WindMarks in thatenvironment, and if found, will access the backplane to update their values.So, for example, the following sequence could be used to registerhttpRpmWmbPost() with the server for the URL /url/:\cs httpRpmConfAdd (HTTP_M_POST, "/url/", httpRpmPost) httpRpmConfAdd (HTTP_M_POST, "/url/", httpRpmWmbPost)\ceRegistration is normally done automatically during server initializationin code generated by the tool WMIT. RPMs are invoked seriatim until onedoes not return RPM_OK. RPMs in this library return RPM_OK, only if theydo not recognize the Content-Type of the request.Functions in this library recognize POSTs with Content-Type of"application/x-www-form-urlencoded" or "multipart/form-data". These are thestandard types for forms and multi-part forms, respectively.INCLUDE FILES: httpLib.h,httpRpms.h*/#undef DEBUG_INFO/* system header files */#include <string.h>#include <ctype.h>#include <stdio.h>#include <stdlib.h>/* WM header files */#include "wrn/wm/http/httpLib.h"#include "wrn/wm/http/httpRpms.h"#include "wrn/wm/http/private/httpReq.h"#include "wrn/wm/http/private/httpInt.h"#include "wrn/wm/http/httpWmbExpandInstance.h"/* WM project header files */#if 0#include "wmw_httpconf.h"#endif#include "fwWebDevice.h"/* externals - will move to header file(s) */IMPORT STATUS (*pWmmErrorLogStart)(INT32);IMPORT STATUS (*pWmmErrorLogEnd)(INT32);IMPORT ubyte4 wmVarMagicMarkupBufferSize;/* constants *//* locals */LOCAL STATUS lclBuildSetTrans(HTTP_REQ_ID, WMB_SESSION_T *, WMB_TID_T, WMB_SESSION_T *);LOCAL short lclReportError();LOCAL sbyte * lclParseInstanceInfo(sbyte * fullWindMarkName);#if 0 /* unused routines */LOCAL STATUS lclBuildGetTrans(HTTP_REQ_ID,WMB_SESSION_T *,WMB_TID_T);LOCAL STATUS lclGetToSetTrans(HTTP_REQ_ID,WMB_SESSION_T *,WMB_TID_T,int);LOCAL BOOL lclValueMatches ( WMB_OBJ_T obj, /* object to check */ sbyte * pVal /* value to check against */ );LOCAL WMB_OBJ_T lclObjCut ( WMB_TID_T tid, WMB_OBJ_T obj );/* debuggering */LOCAL void lclDumpTrans(WMB_TID_T,char *);#endif/* format string for error reporting */static char errFmt[] = "httpRpmWmbPost errno = %d\r\n";/* prototypes missing from header files */WM_BUFFER_T * wmbObjectValueBufferGet ( WMB_OBJ_T obj );/**************************************************************************** fwWebHttpRpmWmbPost - process Windmarks in a POST** This is the routine that actually sets WindMarks. It underlies* httpRpmWmbPost() and httpRpmWmbBestEffortPost(). Users who write their* own custom RPM module would typically call this function to do the* actual Windmark processing.** If <flags> is 0, all items in the POST will be set. Otherwise, <flags>* may be any combination of:* \is* \i RPM_BEST_EFFORT_SET* The set transaction is done on a "best effort" basis and will succeed* even if some items cannot be set.* \i RPM_CHANGE_ONLY_SET* Set only those items whose value will change. If, for some reason, the* current value of an item cannot be determined, it will be set.* \ie** RETURNS: RPM_OK if the POST Content-Type is inappropriate; RPM_DONE if* the post processing was successful; RPM_ERROR otherwise.*/short fwWebHttpRpmWmbPost ( HTTP_REQ_ID reqId /* handle of the active request */ ) { int flags=0; /* processing options */ const sbyte * contentEnc; WMB_SESSION_T * pSession = NULL; WMB_SESSION_T * pGetSession = NULL; WMB_TID_T tid = NULL; WMB_OBJ_T pObj; ubyte4 trans_flags; BOOL doSet; /* Set up the transaction flag(s) */ trans_flags = (flags & RPM_BEST_EFFORT_SET) ? WMB_TM_NOUNDO : 0; /* Check the header for correct content type */ contentEnc = httpMimeHdrGet(reqId, HDR_IN, "Content-Type"); if (strcmp(contentEnc, "application/x-www-form-urlencoded") && strcmp(contentEnc, "multipart/form-data")) { return RPM_OK; /* some other RPM may deal with it */ } /* create a WMB session */ if (OK != wmbSessionCreate (httpGetWmbComp(), 0, WMB_SESSION_NO_DEF_TRANSACTION, &pSession)) { return lclReportError (); } /* * A second session may be created if we are doing selective set's. * It is not an error if this session cannot be created. */ if (flags & RPM_CHANGE_ONLY_SET) { wmbSessionCreate(httpGetWmbComp(),0,0,&pGetSession); } if (pWmmErrorLogStart) pWmmErrorLogStart(pSession->id); /* * Create a transaction in which to store the WindMark objects. * If this fails, report the error, but continue so that we can * clean-up properly. */ doSet = ((wmbTransactionCreate(pSession, 0, trans_flags, &tid) == OK) && (lclBuildSetTrans(reqId, pSession, tid, pGetSession) == OK)) ? TRUE : FALSE; if (!doSet) lclReportError(); /* do now to report proper errno */#if 0 lclDumpTrans(tid,"Before Set");#endif if (doSet) /* If nothing is wrong, we now do a SET transaction. */ { if (wmbTransactionProcess(tid, CMD_SET_K) != OK) { pObj = wmbTransactionErrQGet( tid ); if (NULL != pObj ) { httpWindMarkSetFailed(reqId, wmbObjectNamePtrGet(pObj), wmbTransactionStatusGet(tid)); } else { wmLogPrintf ("httpRpmWmbPost: failed to process transaction\n"); } doSet = FALSE; } else { fwWebReachEndSet(); /* * httpPostReply() is a user supplied function which sends some * kind of POST response message to the client. It might need * to know the session we're in. */ reqId->pSession = pSession; httpPostReply (reqId, HTTP_OK); } } if (pWmmErrorLogEnd) pWmmErrorLogEnd(pSession->id); /* * Clean up. There is really no point in checking for errors * here. */ if (NULL != pGetSession) wmbSessionDestroy(pGetSession); wmbTransactionEnd(tid); wmbSessionDestroy(pSession); return (doSet) ? RPM_DONE : RPM_ERROR; }/**************************************************************************** lclBuildSetTrans - build transaction for setting Windmarks** This routine searches an http request for form element names and* adds them to a wmb transaction. If <pGetSession> is not NULL, and buffer* space can be allocated, it will do a get on each WindMark and only add it* to the transaction if it's value will change.** Because of session and transaction interactions, we must do our get's in* a different session than the one for the set transaction we are building.** RETURNS: OK or ERROR*/LOCAL STATUS lclBuildSetTrans ( HTTP_REQ_ID reqId, /* http request */ WMB_SESSION_T * pSession, /* session for setting */ WMB_TID_T tid, /* transaction in pSession */ WMB_SESSION_T * pGetSession /* (optional) session for getting */ ) { sbyte * pMagicMarkup;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -