Pseudo Code Example Server

What follows is some pseudo code that shows a typical Parse and Build session for a server.


// includes for OFC 
#include ofcdtd.h"
#include "ofcparse.h"
#include "ofcbuild.h"

// includes for bank side 

// Load routine for handler
MyHandlerLoad()
{
    InitOFCParse();  // initialize the OFC Parser
}

// handler routine for an HTTP Request
MyOFCHandler()
{
void     *    pOFCReq;
void  *    pOFCResp;
int        cbOFCReqLen;
int        cbOFCRespLen;
OFCDOC *     pofcdoc;
int        rcReturn;

// get the OFC data from the HTTP Request coming in
// and find the length of it from the HTTP headers
// TODO: Use your internet server functions here to 
//       handle this
if (InternetReadHeader(CONTENT_TYPE) != "application/x-ofc")
{
    // handle error
}
cbOFCReqLen = InternetReadHeader(CONTENT_LENGTH);

// grab a buffer for the OFC data
pOFCReq = malloc(cbOFCLen);

// now read the data from the HTTP req into your buffer
InternetRead(pOFCReq, cbOFCReqLen);

// parse that data using the OFC Parse API
rcReturn = RcParseOFCRequest(pOFCReq, cbOFCReqLen, &pofcdoc);
if (rcReturn != ALL_OK)
{
    // handle the error 
}

// TODO: now go track through the list pointed to by pofcdoc
// and generate your bank requests

// cleanup the list and delete your buffer
CleanupOFCDOCParse(pofcdoc);
free(pOFCReq);

// TODO: send data to the bank server

// TODO: get back list of response from bank, turn it into a
// linked list of response transactions 

// now create the OFC Data
rcReturn = RcCreateOFCResponse(pofcdoc, &pOFCResp,
                     &cbOFCRespLen);

is (rcReturn != ALL_OK)
{
    // deal with error
}

// clean up your list
CleanupOFCDOCParse(pofcdoc);


// now generate an HTTP Response with the data using
// your Internet server functions
InternetSetHeader(CONTENT_LENGTH, cbOFCRespLen);
InternetSetHeader(CONTENT_TYPE, "application/x-ofc");
InternetSetContent(pOFCResp);

// free up the Response memory
CleanupOFCFile(pofcResp);

} // MyOFCHandler()