contents

intro
overview
requirements
cgi basics

dyno cgi
cgi headers
cgi parameters
accessing files
pipe basics
substitution basics
more substitution
table substitution

Dyno CGI: Accessing Files

One of the first things you'll want to try with Dyno CGI is to use an input parameter to decide which file to display. For example, you might simply create a link like this:

http://www.sample.com/cgi-bin/file.cgi?filename=foo.html

Then, your CGI file.cgi could use the "filename" parameter to return the file "foo.html". Let's ignore issues of exact path names, the security issue of letting this CGI access any file path it is given, and the issue of what happens if the target file isn't really of HTML syntax.

In this case, you can just use the function PrintNamedFile(char* fileName). This function gets the specified file and prints it to the CGI output. Here is a complete CGI program that implements this, checking to make sure the filename parameter is supplied:

#include <stdio.h>
#include <string.h>

#include "dyno_cgi.h"

int main()
  {
  VariableList cgiInput;
  char* fileName;

  PrintSimpleHeader();

  cgiInput.LoadFromCGIInput();
  fileName = cgiInput.getVariableData("filename");

  if (str_empty(fileName))
    {
    PrintSimpleHTMLStart("Error!");
    printf("You need to specify a file name!");
    PrintSimpleHTMLEnd();
    }
  else
    {
    PrintNamedFile(fileName);
    }

  FlushOutput();
  }

There are other Dyno CGI functions for printing from an already opened FILE handle, for using relative path names, and for printing only what's inside the <BODY>...</BODY> section of an HTML file.