How run AWS w/o PBuilder pages?

I want to run the AWS, but have every page run through CGI including the first default home/index page. I’ve figured out how to create CGI pages, but default projects and every sample app uses PBuilder for at least the first page. I can’t figure out what to remove to eliminate those pages and still have AWS compile and be functional.

I poked and played trial & error for quite some time but cannot come up with the right combination of files to delete.

Has anyone else ever done this?

Wow, this is the first time I have run into someone wanting to do pure CGI. There is nothing wrong with this. I have just not run into it before.

What to try:
In file RpPages.c, reduce it to the following:

rpObjectDescPtrPtr gRpMasterObjectList[] = {
(rpObjectDescPtrPtr) 0
};

I believe this will tell the engine that there are no “known” pages.
Also the pbuilder utility creates files of the name structure *.c and _v.c. The "" being the name of an html file. Remove them all. This should leave you with an cgi.c file containing all the the c code for generating the html to be sent back to your browser.

Awesome. Progress. That does indeed nuke the PBuilder pages. I was reading the PBuilder docs last night and wondered if the strategy was to leave certain file empty rather than delete them. So, thanks.

Still one problem: the docs say that any page (URL) not known to PBuilder is supposed to get handed off to cgi. In an attempt to trap the first page request which should be an empty URL, I have the following IF statements in cgi.c along with the ones for the pages that do work:

if (strncmp (theCgiPtr->fPathPtr, “/”, 1) == 0)
and
if (strncmp (theCgiPtr->fPathPtr, “”, 0) == 0)

but AWS is resorting to a 404 message page complaining it can’t find the URL of ‘/’ indicating your tip worked, but the handoff to cgi isn’t complete yet.

Any thoughts on how I might have to explicitly tell AWS to try CGI for the first page?

Why all CGI? I want to create standards compliant XHTML 1.0T and there’s no way to do that with PBuilder (not even with the latest version of Allegro’s code). So, I have to do it all manually.

So far I have quite a few of the pieces figured out. Still need to play with how to serve images, css & js files, and find the error page content like that 404 to edit them.

Not knowing exactly what you’ve tried to date, I’ll make a few suggestions. If they represent things you’ve done already, sorry.

Put a printf statement in cgi.c that prints out the contents of theCgiPtr->fPathPtr so you know what is coming and going.

Ensure that at the end of the if statements where you handle control back to the AWS engine, that you do the following:
theCgiPtr->fResponseState = eRpCgiLastBuffer;
theCgiPtr->fHttpResponse = eRpCgiHttpOk;

Also if you are returning stuff to the browser as in a get, you’ll want something like the following:
theCgiPtr->fResponseBufferPtr = buffer;
theCgiPtr->fResponseBufferLength = strlen(buffer);

where buffer is an in-memory buffer containing the html going back to the browser.

Thanks. Yeah, I have all that stuff. I do have working test pages with forms and cookies. I just can’t get my own home page to show up when the bare domain is requested (i.e. with no specific page in the URL).

I don’t mean to suck you into my vortex of non-productivity, but if you’re interested, I’ve posted code fragments below which should help see some of what I’ve already done.

Many thanks for your time.

I start by splitting GET and POST requests:

void RpExternalCgi(void *theDataPtr, rpCgiPtr theCgiPtr) {

    if (theCgiPtr->fHttpRequest == eRpCgiHttpGet) {
		mCgi_handleGetRequests(theDataPtr, theCgiPtr);
	}
    if (theCgiPtr->fHttpRequest == eRpCgiHttpPost) {
		mCgi_handlePostRequests(theDataPtr, theCgiPtr);
    }
}

Next, assuming a GET, have the following simple block to determine which page – I’ll work out a better one later:

void mCgi_handleGetRequests(void *theDataPtr, rpCgiPtr theCgiPtr) {

    if (strncmp (theCgiPtr->fPathPtr, "/test_page", 10) == 0) {
		test_page(theDataPtr, theCgiPtr);
		return;
	}
    if (strncmp (theCgiPtr->fPathPtr, "/home_page", 10) == 0) {
		home_page(theDataPtr, theCgiPtr);
	    return;
	}
    if (strncmp (theCgiPtr->fPathPtr, "/", 1) == 0) {
		home_page(theDataPtr, theCgiPtr);
	    return;
	}

    // let's cheat the 404 by having a default page be the home page, just in case
    home_page(theDataPtr, theCgiPtr);

}

You’ll notice a couple things. First, I have an explicit test for “/home_page” which if the URL includes that, the page appears just fine as expected. Second, that routine ends with a forced call to the home_page – and even that is not working. So this tells me that even though RpPages is effectively empty, something is still trying to handle the first page of the web site using a PBuilder page. The one I am expecting to work is the “/” since the 404 page complains it cannot find a “/” URL.

Anyway, the home page code is a dead simple example like this which works just fine if I call http://DOMAIN/home_page, but not if I call just http://DOMAIN/.

void home_page(void *theDataPtr, rpCgiPtr theCgiPtr) {

    theCgiPtr->fResponseState = eRpCgiLastBuffer;
	memset(buffer, '\0', MAX_PAGE_BYTES);

	strcpy(buffer, "");
	strcat(buffer, "");
	strcat(buffer, "CGI Home");
	strcat(buffer, "");
	strcat(buffer, "");
	strcat(buffer, "Home Page");
	strcat(buffer, "Woohoo! Finally got a CGI home page.

");
	strcat(buffer, "");
	strcat(buffer, "");

    theCgiPtr->fResponseState = eRpCgiLastBuffer;
    theCgiPtr->fHttpResponse = eRpCgiHttpOk;
    theCgiPtr->fResponseBufferPtr = buffer;
    theCgiPtr->fResponseBufferLength = strlen(buffer);
}

Also, just so you have it, here’s my RpPages. The only files left in /web are: RpUsrDct.h, RpUsrDct.c, RpPages.c, PBuilder.pbb (which I deleted all entries from), PbSetup.txt, RpUsrDct.txt. Everything else is deleted.

/* Created with PageBuilder version 4.04 on Fri Jul 14 09:15:38 2006 */
#include "AsExtern.h"
#if RomPagerServer

rpObjectDescriptionPtr gRpObjectList[] = {
	(rpObjectDescriptionPtr) 0
};

rpObjectDescPtrPtr gRpMasterObjectList[] = {
	(rpObjectDescriptionPtr *) gRpObjectList,
	(rpObjectDescPtrPtr) 0
};
#endif	/* RomPagerServer */

I just performed a quick test with a cgi application that I have lying around. Mine started out with an index.htm page that then transferred to cgi-based pages. So the index.htm pag ewas run through pbuilder, while all other pages were generated via cgi.c.

I tried the following. I cleared out list .bat (so it was empty) and ran it through pbuilder. This gave me the RpPages.c file that I wanted. Then I built my app and tried connecting to my device using http://devices_ip/. As you saw, I got page not found. This tells me that AWS does something special with the / URL request.

Based on this the only thing I can suggest is to create a minimal index.htm page, run it through pbuilder. Then have it do little more then perform a page change to your start page in cgi.

As an asside, I found that anything I placed as a URL besides either http://devices_ip or http://devices_ip/ were passed into cgi. so http://devices_ip/mydoghasfleas showed up in the printf statement I added at the beginning of my RpCgi function.

OK, I figured I might have to use that as a fallback strategy. I’ll just make a page that auto redirects to the page I want and just call it /home or something simple.

I did get a sample CGI app out of someone at Digi a while back. It too started with a PBuilder page, but the author said that was optional. Sadly, I can’t follow up as Support now wants me to pay (which I may end up doing anyway just to get faster response on some of my other questions). If I ever do get info on how to bypass PBuilder, I’ll come back and post the details here.

Thanks for your time and effort.

I managed to do just that, so good enough for now.

Hey, one more thing, if I’m not being too big a pest…

Searching through the docs and examples, I just don’t see any help with how to serve up css files, js files, and images via CGI. I’m likely going to pay Support to help me with examples for all that – and then I think I’ll build my own sample application and put it on my web site for people wanting to do this like me.

I haven’t yet fiddled with the file system, so I have some fundamentals to cover there, but I have one question just so I know where I am headed.

Can css, js, img files just exist natively in the file system and will AWS “just serve” those files like I would get from Apache, or do I have to convert everyone one of those into C source like Builder dpes and have a handler in RpExternalCgi for every single request include css/img data?

many, many thanks.

You should be able to add it via pbuilder just like a normal HTML page. All the rom page manager does is take the path it’s given from the http request, search its table and then dump the data within it to the client. It will handle any text based stuff without a problem.

I really, really don’t want to use PBuilder.

A couple of key lines from the nahttp_fs example (index.htm):
You can directly download a file by typing http://ip_address/FS/directory_path/filename.

Click on this link to view a test file in RAM0 directory /FS/RAM0/test.txt.

So yes, you can directly access files in the file system, by the look of it

Ah, great. Thanks for the clue. That should help me make sense of the demo code and docs better.

One of the things I still don’t understand with Ecipse/ESP is whether there’s a GUI way to pre-build the contents of the file system. Or does everything have to be uploaded by FTP after the OS has been installed in a device?

I haven’t found any reference yet to a “special place” to put files that will be automatically added to the build/debug image.

Either you physically include the data for the file in your c\h files and use "C library APIs to load the data into files on the file system (see file system example apps for examples) or as you stated, upload using ftp. I can’t think of a third option.

OK, thanks everyone for pitching in. This has been very helpful. Hopefully once I know what I’m talking about more, I can pay it forward.