Useful Elements of the NPDS API

The NPDS API is actually a series of functions, methods, and data frames attached to the nHTTPd application that combine together to provide an environment where dynamic content CGIs can run. I've strived to provide functions that take the repetitive work out of creating dynamic WWW data.

Important nHTTPd Data Frames

Current Request

NPDS has some defined structures inside it that help monitor and drive server transactions. The first of these, CURRENT_HTTP_REQUEST is used as a central store to collect data about a given transaction. Its current format is:

GetRoot().|nHTTPd:ALLPEN|.CURRENT_HTTP_REQUEST :=

{

ip: "0.0.0.0", //IP Address of the client

time: "", //GMT time the request was initiated

request: "", //directory and filename of requested item

agent: "", //browser being used to request this item

result: 0, //result code of a transaction

bytes: 0, //size of the file returned in this transaction

dns: "", //DNS entry of a client (if it's been resolved already)

}

You don't have access to italicized values because they aren't defined until after the Scripting system has processed your page.

Preference Frame

For your reference, the NPDS preferences format can be found in the Appendix NPDS Preferences Frame. You can read from this frame but unless you're a proficient developer don't write to it. You may retrieve the frame containing this data at any time with the code GetAppPrefs('|nHTTPd:ALLPEN|, NIL). Savvy programmers may find other slots in this frame besides the ones specified in this document but please note that these are deprecated and are in place for backwards compatibility with previous versions of NPDS.

Useful nHTTPd Methods

nHTTPd Application Symbol: '|nHTTPd:ALLPEN|

UsingNewtonBrowser()

Returns TRUE if user is using Newtscape, Nethopper, PocketWeb, LunaSuite

UsingAncientBrowser()

Returns TRUE if user is using a Newton browser or a browser returning "1.x", "2.x" in the agent field

RetrieveDNS(IP as string)

Looks into the log file for a resolved copy of the IP passed to it. Does NOT do a new lookup if there isn't one in the log.

LogToTextFile(symbol)

Takes the NPDS log and returns a plain text version of it. The symbol will be a sort key but for now pass NIL to it.

InitializeStaticVars()

Refreshes the static SSI values to be in line with the actual preferences. You may never need this but its there.

fReturnFormattedTime(time in seconds)

Returns an "HTTP" time string adhering to the RFC 822/1123 specification

fFormatOrCompress(Data, Boolean)

Quick and dirty compressor and formatting function. For a given block of text, if the Boolean value = NIL, all runs of spaces are compressed to single spaces and carriage-returns and line-feeds are replaced with <BR> tags. This is a major way that the texts of NoteServ notes are formatted.

fFilterPercentEscapesPlus(string)

Great, fast function for decoding the %00 characters in a URL to their unicode equivalents. Works only for single byte characters.

fAddHyperlinks(string)

Scans the passed text for valid URIs (http, gopher, hotline, news, mailto, ftp) and wraps them in HTML anchor tags. Do NOT, I repeat, do NOT pass a string that already has anchor tags in it to this function or it'll go recursive on you. Otherwise, it's a great little method.

CheckIP(ip-t [ip1, ip2])

Checks to see if ip-t is within the range specified by ip1 and ip2. You pass IPs as strings and recieve TRUE or FALSE as a result.

StartServing()

Sets "Show connect slip" to FALSE and starts your web server.

StopServing()

Shuts down your server.