#include "DDS.h"
#include "ObjectType.h"
#include "EncodingType.h"
Include dependency graph for cgi_util.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
CGI Utilities | |
A collection of useful functions for writing OPeNDAP servers. The CGI utilities include a variety of functions useful to programmers developing OPeNDAP CGI filter programs. However, before jumping in and using these, look at the class DODSFilter. Always choose to use that class over these functions if you can.
| |
bool | do_data_transfer (bool compression, FILE *data_stream, DDS &dds, const string &dataset, const string &constraint) |
bool | do_version (const string &script_ver, const string &dataset_ver) |
Send a version number. | |
void | ErrMsgT (const string &Msgt) |
Logs an error message. | |
string | find_ancillary_file (const string &pathname, const string &ext, const string &dir, const string &file) |
Find a file with ancillary data. | |
string | find_group_ancillary_file (const string &pathname, const string &ext) |
time_t | last_modified_time (const string &name) |
string | name_path (const string &path) |
Returns the filename portion of a pathname. | |
string | rfc822_date (const time_t t) |
MIME utility functions | |
These functions are used to create the MIME headers for a message from a server to a client. They are public but should not be called directly unless absolutely necessary. Use DODSFilter instead. NB: These functions actually write both the response status line and the header.
| |
void | set_mime_binary (FILE *out, ObjectType type=unknown_type, const string &version="", EncodingType enc=x_plain, const time_t last_modified=0) |
void | set_mime_error (FILE *out, int code=404, const string &reason="Dataset not found", const string &version="") |
void | set_mime_html (FILE *out, ObjectType type=unknown_type, const string &version="", EncodingType enc=x_plain, const time_t last_modified=0) |
void | set_mime_not_modified (FILE *out) |
Send a `Not Modified' response. | |
void | set_mime_text (FILE *out, ObjectType type=unknown_type, const string &version="", EncodingType enc=x_plain, const time_t last_modified=0) |
Functions | |
bool | found_override (string name, string &doc) |
string | get_user_supplied_docs (string name, string cgi) |
Look for the user supplied CGI- and dataset-specific HTML* documents. | |
bool | remove_mime_header (FILE *in) |
Read and discard the MIME header of the stream in . |
bool do_data_transfer | ( | bool | compression, | |
FILE * | data_stream, | |||
DDS & | dds, | |||
const string & | dataset, | |||
const string & | constraint | |||
) |
bool do_version | ( | const string & | script_ver, | |
const string & | dataset_ver | |||
) |
This sends a formatted block of text to the client, containing version information about various aspects of the server. The arguments allow you to enclose version information about the filter program and the dataset in the message. Either argument (or both) may be omitted, in which case no script or dataset version information will be printed.
script_ver | The version of the filter script executing this function. | |
dataset_ver | The version of the dataset. |
Definition at line 106 of file cgi_util.cc.
References CRLF, DAP_PROTOCOL_VERSION, and DVR.
Referenced by DODSFilter::send_version_info().
void ErrMsgT | ( | const string & | Msgt | ) |
Prints an error message in the httpd
system log file, along with a time stamp and the client host name (or address).
Use this instead of the functions in liberrmsg.a in the programs run by the CGIs to report errors so those errors show up in HTTPD's log files.
Definition at line 307 of file cgi_util.cc.
Referenced by DODSFilter::print_usage().
string find_ancillary_file | ( | const string & | pathname, | |
const string & | ext, | |||
const string & | dir, | |||
const string & | file | |||
) |
This function accepts a dataset path name, and searches for a matching ancillary data file name with a very specific set of search rules, given here:
directory filename extension same same `.'given given same `.'given same given `.'given given given `.'given
Where ``same'' refers to the input dataset pathname, and ``given'' refers to the function arguments.
For example, If you call this function with a dataset name of /a/data
, an extension of das
, a directory of b
, and a filename of ralph
, the function will look (in order) for the following files:
/a/data.das /b/data.das /a/ralph.das /b/ralph.das
The function will return a string containing the name of the first file in the list that exists, if any.
pathname.ext
3/17/99 jhrgpathname | The input pathname of a dataset. | |
ext | The input extension the desired file is to have. | |
dir | The input directory in which the desired file may be found. | |
file | The input filename the desired file may have. |
Definition at line 173 of file cgi_util.cc.
References DBG.
Referenced by DODSFilter::get_das_last_modified_time(), DODSFilter::get_data_last_modified_time(), DODSFilter::get_dds_last_modified_time(), DODSFilter::read_ancillary_das(), and DODSFilter::read_ancillary_dds().
string find_group_ancillary_file | ( | const string & | name, | |
const string & | ext | |||
) |
Assume that name
refers to a file that is one of a group of files which share a common `base' name and differ only by some prefix or suffix digits (e.g. 00base
, 01base
, ... or base00
, ... have the base name base
). This function looks for a file base.ext
.
name | The name (full or relative) to one member of a group of files. | |
ext | The extension of the group's ancillary file. Note that ext should include a period (.) if that needs to separate the base name from the extension. |
Definition at line 240 of file cgi_util.cc.
References DBG.
Referenced by get_user_supplied_docs().
bool found_override | ( | string | name, | |
string & | doc | |||
) |
Look for the override file by taking the dataset name and appending `.ovr' to it. If such a file exists, then read it in and store the contents in doc
. Note that the file contents are not checked to see if they are valid HTML (which they must be).
doc
's contents are undefined. Definition at line 664 of file cgi_util.cc.
string get_user_supplied_docs | ( | string | name, | |
string | cgi | |||
) |
Look in the CGI directory (given by cgi
) for a per-cgi HTML* file. Also look for a dataset-specific HTML* document. Catenate the documents and return them in a single String variable.
Similarly, to locate the dataset-specific HTML* file it catenates `.html' to name
, where name
is the name of the dataset. If the filename part of name
is of the form [A-Za-z]+[0-9]*.* then this function also looks for a file whose name is [A-Za-z]+.html For example, if name
is .../data/fnoc1.nc this function first looks for .../data/fnoc1.nc.html. However, if that does not exist it will look for .../data/fnoc.html. This allows one `per-dataset' file to be used for a collection of files with the same root name.
html
, head
or body
tags (my own notation).Definition at line 726 of file cgi_util.cc.
References find_group_ancillary_file().
Here is the call graph for this function:
time_t last_modified_time | ( | const string & | name | ) |
Get the last modified time. Assume name
is a file and find its last modified time. If name
is not a file, then return now as the last modified time.
name | The name of a file. |
Definition at line 439 of file cgi_util.cc.
Referenced by DODSFilter::get_das_last_modified_time(), DODSFilter::get_data_last_modified_time(), DODSFilter::get_dataset_last_modified_time(), and DODSFilter::get_dds_last_modified_time().
string name_path | ( | const string & | path | ) |
Given a pathname, this function returns just the file name component of the path. That is, given /a/b/c/ralph.nc.das
, it returns ralph.nc
.
path | A C-style simple string containing a pathname to be parsed. |
Definition at line 350 of file cgi_util.cc.
References FILE_DELIMITER.
bool remove_mime_header | ( | FILE * | in | ) |
Read the input stream in
and discard the MIME header. The MIME header is separated from the body of the document by a single blank line. If no MIME header is found, then the input stream is `emptied' and will contain nothing.
Definition at line 690 of file cgi_util.cc.
References CRLF.
string rfc822_date | ( | const time_t | t | ) |
Given a constant pointer to a time_t
, return a RFC 822/1123 style date.
This function returns the RFC 822 date with the exception that the RFC 1123 modification for four-digit years is implemented.
t | A const time_t pointer. |
Definition at line 416 of file cgi_util.cc.
Referenced by set_mime_binary(), set_mime_error(), set_mime_html(), set_mime_not_modified(), and set_mime_text().
void set_mime_binary | ( | FILE * | out, | |
ObjectType | type, | |||
const string & | ver, | |||
EncodingType | enc, | |||
const time_t | last_modified | |||
) |
Write an HTTP 1.0 response header for our binary response document (i.e., the DataDDS object).
out | Write the MIME header to this FILE pointer. | |
type | The type of this this response. Defaults to application/octet-stream. | |
ver | The version string; denotes the libdap implementation version. | |
enc | How is this response encoded? Can be plain or deflate or the x_... versions of those. Default is x_plain. | |
last_modified | The time to use for the Last-Modified header value. Default is zero which means use the current time. |
Definition at line 580 of file cgi_util.cc.
References CRLF, DAP_PROTOCOL_VERSION, DVR, rfc822_date(), and x_plain.
Referenced by DODSFilter::send_blob(), and DODSFilter::send_data().
Here is the call graph for this function:
void set_mime_error | ( | FILE * | out, | |
int | code, | |||
const string & | reason, | |||
const string & | version | |||
) |
Generate an HTTP 1.0 response header for an Error object.
out | Write the MIME header to this FILE pointer. | |
code | HTTP 1.0 response code. Should be 400, ... 500, ... | |
reason | Reason string of the HTTP 1.0 response header. | |
version | The version string; denotes the DAP spec and implementation version. |
Definition at line 619 of file cgi_util.cc.
References CRLF, DAP_PROTOCOL_VERSION, DVR, and rfc822_date().
Here is the call graph for this function:
void set_mime_html | ( | FILE * | out, | |
ObjectType | type, | |||
const string & | ver, | |||
EncodingType | enc, | |||
const time_t | last_modified | |||
) |
Generate an HTTP 1.0 response header for a html document.
out | Write the MIME header to this FILE pointer. | |
type | The type of this this response. | |
ver | The version string; denotes the libdap implementation version. | |
enc | How is this response encoded? Can be plain or deflate or the x_... versions of those. Default is x_plain. | |
last_modified | The time to use for the Last-Modified header value. Default is zero which means use the current time. |
Definition at line 531 of file cgi_util.cc.
References CRLF, DAP_PROTOCOL_VERSION, dods_error, DVR, rfc822_date(), and x_plain.
Here is the call graph for this function:
void set_mime_not_modified | ( | FILE * | out | ) |
Use this function to create a response signaling that the target of a conditional get has not been modified relative to the condition given in the request. This will have to be a date until the servers support ETags.
out | Write the response to this FILE pointer. |
Definition at line 647 of file cgi_util.cc.
References CRLF, and rfc822_date().
Referenced by DODSFilter::send_blob(), DODSFilter::send_das(), DODSFilter::send_data(), DODSFilter::send_dds(), and DODSFilter::send_ddx().
Here is the call graph for this function:
void set_mime_text | ( | FILE * | out, | |
ObjectType | type, | |||
const string & | ver, | |||
EncodingType | enc, | |||
const time_t | last_modified | |||
) |
Generate an HTTP 1.0 response header for a text document. This is used when returning a serialized DAS or DDS object.
out | Write the MIME header to this FILE pointer. | |
type | The type of this this response. Defaults to application/octet-stream. | |
ver | The version string; denotes the libdap implementation version. | |
enc | How is this response encoded? Can be plain or deflate or the x_... versions of those. Default is x_plain. | |
last_modified | The time to use for the Last-Modified header value. Default is zero which means use the current time. |
Definition at line 480 of file cgi_util.cc.
References CRLF, dap4_ddx, DAP_PROTOCOL_VERSION, dods_error, DVR, rfc822_date(), and x_plain.
Referenced by DODSFilter::send_das(), DODSFilter::send_dds(), and DODSFilter::send_ddx().
Here is the call graph for this function: