NET+OS Allegro serving files from cgi

I was looking into the example folders provided with the NET+OS Digi ESP software and I’ve encountered the naficgi example.

until now to serve a file stored inside FLASH0 I simply use a mutex an the C library
but the naficgi example provides with a better more robust alternative.

I’ve implemented the example in my code without success (code attached at the end of the post).

What I’m seeing from the debug is while both RpHSOpenFile and RpHSOpenFileStatus return without errors the theFileInfo variable populated by RpHSOpenFileStatus always has FileSize propery = 0.
HandleNextBuffer will not return any data since it also encounter the same FileSize = 0.

In the example I’m trying to return an html file name page.html
which has been uploaded via FTP inside FLASH0.

Browsing to http:///FS/FLASH0/page.html from browser (I’ve also posted a question regarding this behavior) actually returns the page.
I’ve noticed the RpHSOpenFile get called initially once and multiple RpHSOpenFileStatus are called subsequently while in my attempt to implement the example code it get called only one time.

this missing RpHSOpenFileStatus iterations prevent the code to correctly polulate variables like FileSize that are left in the initialization state.

Is there somethings you colud suggest I’m doing wrong?

The code I’m debugging

/*

  • Send data back to the browser from cgi.
    */
    void RpExternalCgi(void *theDataPtr, rpCgiPtr theCgiPtr) {
    FILEINFO theFileInfo;
    int tmp;

    if (theCgiPtr->fHttpRequest == eRpCgiHttpGet &&
    strncmp (theCgiPtr->fPathPtr, “/FILE/”, 5) == 0)
    {
    if (theCgiPtr->fUserDataPtr == (void *) 0) {

         // define the file to be served .html in this case
         char* file_path = "FS/FLASH0/page.html"; 
    
         RpErrorCode code = RpHSOpenFile (theCgiPtr->fConnectionId, file_path); 
    
         code = RpHSOpenFileStatus(theCgiPtr->fConnectionId, &tmp, &theFileInfo);   
    
         // since we are returning an html file
         theCgiPtr->fDataType = eRpDataTypeHtml; 
    
         HandleNextBuffer(theCgiPtr);
    
     }else {
    

    /*
    * This isn’t the first RpExternalCgi call for this request.
    * Return another buffer.
    /*
    HandleNextBuffer(theCgiPtr);
    }
    }

}

/* This routine send buffer data 1024 bytes a time */
static void HandleNextBuffer(rpCgiPtr theCgiPtr) {
Unsigned32 nSend;
int EOFflag;

/* at this point the file should be already open, read it */
/* note: we don't actually use buffer */
RpHSReadFile (theCgiPtr->fConnectionId, buffer, 1024); 
RpHSReadFileStatus (theCgiPtr->fConnectionId, &EOFflag, &nSend);

if (EOFflag == 2) {
    /*
     * The pointer to the next buffer is a null pointer,
     * this is the last buffer.
    */
    theCgiPtr->fResponseState = eRpCgiLastBuffer;
/* should close the file */
RpHSCloseFile (theCgiPtr->fConnectionId, 1);
}
else {
    /*
     * The pointer to the next buffer is not a null pointer,
     * there is at least one more buffer following this one.
    */
    theCgiPtr->fResponseState = eRpCgiBufferComplete;
}

/*
 * Send part of the page data.
*/
theCgiPtr->fHttpResponse = eRpCgiHttpOk;
theCgiPtr->fResponseBufferPtr = buffer;
theCgiPtr->fResponseBufferLength = nSend;
return;

}