HTDB : Docs : Developer's Guide : CGIs
About
Overview
Philosophy
Features
News
Download
Help Us!

Docs
Overview
Designers
Developers
Functions
Database
CGIs
Applications
Roadmap
Architecture

Community
Powered By

[home]
CGIs

the simplest of libhtdb-driven programs have the following as programmatic structure, and need to be compiled against libhtdb.a.

here is the source code for main() of htdb itself.

/* This software (HTDB and its components) Copyright 1994-2024 David Whittemore del-at-htdb.org */ #include "htdb.h" /* the application information structure */ appinfo_t appinfo = { /* the application name */ "htdb", /* the application version */ "1.2.3", /* command-line usage information */ "this program utilizes the built-in handler " "to process .htdb documents. \n\n" "in short, URI strings of the form \n" "\t /htdb/site/index.html \n\n" "are parsed into the values of " "`db'=site and `page'=index.html \n\n" "the `db'.htdb file is then processed " "and we spit out what document \n" "we find defined for `page'.", /* initial htdb values */ "", /* address of handler function */ htdb_page_handler, /* serve this many pages per fastCGI loop */ FCGI_KEEPALIVE }; int main(int argc, char **argv) { exit (htdb_main(argc, argv, &appinfo)); }

observations:

  • note that all work is actually performed in htdb_main(), so there's not a whole lot to look at in such a simple program.
  • the 1st and 2nd arguments allow access to standard UNIX command line parameters. these values are only available when running libhtdb-based applications from the command line, otherwise, they are not used, since the webserver process does not make them available. when processed, the values will be available via the `argv[]->name' and `argv[]->value' resource structures. `argv->numResults' will contain the result count.

typedef struct { char *name, *version, *description, *args; void (*func)(void); int fcgi_keepalive; } appinfo_t;

  • the 3rd argument is a pointer to the appinfo control structure, whose elements are described below.
    • name - the name of the application. used only for command usage messaging.
    • version - the version of the application. used only for command usage messaging.
    • description - usage message for improper command-line invocation.
    • args - "initial htdb values". if given, would be in GET argument format:

          arg1=val1&arg2=val2

      these values are shoved into the environment after normal GET/POST argument decoding so as to over-ride any values set by the server. used to disable sessioning for a specific application, for instance.

    • func - the address of the function to call to process requests. HTDB provides the default page handler htdb_page_handler. if you were writing your own CGIs, this value would be the address of your handler routine.
    • fcgi_keepalive - all libhtdb CGIs can be run as fastCGI applications, which allows for vastly more efficient CGIs. fcgi_keepalive is an integer value that tells the fastCGI subsystem how many requests to serve before cleaning up and re-initializing.
del - Wed Aug 15 22:14:00 PDT 2001
   
14,210 impressions