#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <time.h>
#include "log.h"
#include "hlrmisc.h"
#include "format.h"
#include "linestream.h"
#include "html.h"
Go to the source code of this file.
Functions | |
char * | cgiConstructCookie (char *name, char *value, int lifelength) |
Construct a string for a transient or permanent cookie. | |
void | cgiDecodeWord (Stringa a) |
URL-decodes a string. | |
void | cgiDomainSet (char *domain) |
Set the domain to be used in the next cookie to be constructed. | |
void | cgiEncodeWord (char *s, Stringa a) |
Encode string for use in a URL. | |
void | cgiEncodingSet (char *charset) |
Sets the character set specification which is written into the cgi header. | |
void | cgiExpiresSet (int seconds_valid) |
Sets the lifetime of the next html page to be constructed. | |
char * | cgiGet2Post (void) |
Enables access to data generated by method GET via cgiGetNextPair(). | |
void | cgiGet2PostReset (void) |
Allows to use the function cgiGetNextPair() after cgiGet2Post() was called, by resetting the CGI buffer. | |
char * | cgiGetByName (char *name) |
Get and return value of name from POST. | |
char * | cgiGetByNameM (char *name) |
Like cgiGetByName(), but die()s if field not found (M = mandatory). | |
void | cgiGetF (char *fieldName, Stringa value) |
Like cgiGetFo, but field's existence is mandatory. | |
int | cgiGetFo (char *fieldName, Stringa value) |
Optionally get next field from form. | |
void | cgiGetInit (void) |
char * | cgiGetNext (Stringa value) |
Get the name and value of the next form field. | |
int | cgiGetNextPair (int *first, Array item, Array value) |
Provides the next item/value pair. | |
void | cgiHeader (char *mimeType) |
Print html header of type, but only if running under WWW. | |
void | cgiHeaderCookie (char *mimeType, char *cookieSpec) |
Like cgiHeader, but include a cookie for transmission to the client. | |
int | cgiHeaderIsPrinted (void) |
void | cgiInit (void) |
Initialize the CGI module. | |
int | cgiIsCGI (void) |
void | cgiMpDeinit (void) |
Deinitialize multi-part module and release all temporarily allocated resources. | |
void | cgiMpInit (void) |
Initialize module for reading multi-part forms. | |
int | cgiMpNext (Stringa item, Array value, Stringa filename, Stringa contentType) |
Returns next item/value pair plus optional information for file upload. | |
void | cgiMpReset (void) |
Reset multi-part reading to first part. | |
char * | cgiReadCookie (char *name) |
If the current process is a CGI process and received a cookie from the client, the cookie is examined for a parameter called 'name', whose value is extracted and returned. | |
void | cgiRedirSet (char *url) |
Instruct the next cgiHeader call to immediately redirect the browser to address 'url'. | |
void | cgiURLAdd (char *param) |
Add parameter to URL currently under construction. | |
void | cgiURLAddInt (int param) |
Add integer parameter to url currently under construction. | |
void | cgiURLAddNV (char *name, char *value) |
Add name-value pair to url currently under construction. | |
void | cgiURLCreate (char *host, int port, char *program) |
void | cgiURLCreate2 (char *cgiServerUrl, char *program) |
char * | cgiURLGet (void) |
void | html_appletParam (char *name, char *value) |
Include a parameter to an open applet tag. | |
void | html_appletTagClose (void) |
void | html_appletTagOpen (FILE *fp, char *jarFileUrls, char *appletClass, int width, int height) |
Construct html that will start a java applet under Internet Explorer and in case this is not possible, show a suitable diagnostic message to the user. | |
char * | html_clink3 (char *class, char *method, char *p1, char *p2, char *p3) |
Construct parameterized URL to the program set in html_URLSet() (c for CGI). | |
void | html_encode (char *inText, Array outText, int withExceptions) |
HTML-encode HTML-special chars. | |
char * | html_encodeS (char *s) |
Like html_encode(), but manages the buffer. | |
void | html_hlink3 (char *class, char *method, char *label, char *p1, char *p2, char *p3) |
Construct a parameterized hyperlink to the program set in html_URLSet() (h for hyperlink). | |
void | html_printGenericStyleSheet (int bodyFontSize) |
Print a generic style sheet. | |
char * | html_tab2table (char *tab, int firstLineIsHeader, int borderWidth, int withMarkup) |
Converts tab delimited ASCII data into HTML tables. | |
char * | html_text2tables (char *tab, int firstLineIsHeader, int borderWidth, int withMarkup) |
Like html_tab2table(), but allows for several tables separted by lines not containing a tab character. | |
int | html_uniqueIntGet (void) |
Generate an integer that is unique for this process. | |
void | html_URLOptSet (char *option) |
Sets optional argument to be added to the URL. | |
void | html_URLSet (char *host, int port, char *program) |
Fix URL parts for subsequent calls to html_hlink() and html_clink(). | |
void | html_URLSet2 (char *cgiServerUrl, char *program) |
Same function as html_URLSet(), but different interface. | |
void | html_webstartAddArg (char *arg) |
void | html_webstartAddJar (char *jar) |
void | html_webstartClose (void) |
Must be called to finish writing the jnlp XML. | |
void | html_webstartOpen (FILE *fp, char *codebase, char *title, char *homepage, char *description, char *icon, int allPermissions, char *heap, char *mainClass) |
Definition in file html.c.
char* cgiConstructCookie | ( | char * | name, | |
char * | value, | |||
int | lifelength | |||
) |
Construct a string for a transient or permanent cookie.
The returned string can be used in cgiHeaderCookie().
[in] | name | Name of the cookie for use in cgiReadCookie |
[in] | value | Value to be stored |
[in] | lifelength | 0 : transient cookie (bound to browser process), >0 : go to disk and stay there for 'lifelength' seconds, <0 : delete this cookie |
void cgiDecodeWord | ( | Stringa | a | ) |
void cgiDomainSet | ( | char * | domain | ) |
Set the domain to be used in the next cookie to be constructed.
[in] | domain | Domain name, or NULL to quit setting a domain e.g. ".roche.com" |
void cgiEncodeWord | ( | char * | s, | |
Stringa | a | |||
) |
void cgiEncodingSet | ( | char * | charset | ) |
Sets the character set specification which is written into the cgi header.
[in] | charset | Character set, e.g. "iso-8859-1", "utf-8", ... If NULL, no character set specification is written into the cgi header. |
void cgiExpiresSet | ( | int | seconds_valid | ) |
Sets the lifetime of the next html page to be constructed.
[in] | seconds_valid | If a WWW browser directed back to a page visited before it has the choice to load the page from its cache or retrieve it from the HTTP server. 'seconds_valid' decides that choice: if the more than 'seconds_valid' seconds have passed, the browser is forced to reload the page; else it can get if from its cache. 0 for 'seconds_valid' is OK. |
char* cgiGet2Post | ( | void | ) |
Enables access to data generated by method GET via cgiGetNextPair().
The data generated by method POST is not accessible after this call.
void cgiGet2PostReset | ( | void | ) |
Allows to use the function cgiGetNextPair() after cgiGet2Post() was called, by resetting the CGI buffer.
Call this function directly after using cgiGet2Post().
char* cgiGetByName | ( | char * | name | ) |
Get and return value of name from POST.
[in] | name | Name of item posted |
int cgiGetFo | ( | char * | fieldName, | |
Stringa | value | |||
) |
Optionally get next field from form.
Abort if field is not named according to 'fieldName'.
[in] | value | Array of char, null-terminated, must exist |
[in] | fieldName | Name of expected field |
[out] | value | Contains field contents, if 1 returned, else contains an empty string |
Can be used only for one form within one process; there is no way to reset and read the next form.
void cgiGetInit | ( | void | ) |
char* cgiGetNext | ( | Stringa | value | ) |
Get the name and value of the next form field.
[in] | value | Existing Stringa |
[out] | value | Filled with contents of field; contents undefined if no more field |
Provides the next item/value pair.
usage: int first = 1 ; Array item = arrayCreate(10, char) ; Array value = arrayCreate(10, char) ; while (cgiGetNextPair(&first,item,value)) { ... }
void cgiHeader | ( | char * | mimeType | ) |
Print html header of type, but only if running under WWW.
Print only once during a process. The behaviour of this function can be customized by cgiRedirSet(), cgiEncodingSet() and cgiExpiresSet()
[in] | mimeType | If NULL, text/html is assumed, if empty string, do not print header and prevent die, warn etc. to print header (useful if header has been printed outside of this process) |
void cgiHeaderCookie | ( | char * | mimeType, | |
char * | cookieSpec | |||
) |
Like cgiHeader, but include a cookie for transmission to the client.
int cgiHeaderIsPrinted | ( | void | ) |
void cgiInit | ( | void | ) |
Initialize the CGI module.
Within a CGI program, this function should be called as early as possible. cgiInit ensures that error messages generated by die() and warn() will output a cgi header, if this has not yet happened. This makes sure that die/warn in lower level routines (e.g. from this library) will not result in a "server error" message displayed in the user's browser.
int cgiIsCGI | ( | void | ) |
void cgiMpDeinit | ( | void | ) |
void cgiMpInit | ( | void | ) |
Initialize module for reading multi-part forms.
Example call sequence: cgiMpInit(); while (cgiMpNext(a, b, c, d)) ... cgiMpReset(); while (cgiMpNext(a, b, c, d)) ... cgiMpDeinit(); deinitialization may be crucial e.g. if VERY LARGE files are read since these functions are reading from stdin initialization will be allowed only once; but contents can be read multiple times by using cgiMpReset()
int cgiMpNext | ( | Stringa | item, | |
Array | value, | |||
Stringa | filename, | |||
Stringa | contentType | |||
) |
Returns next item/value pair plus optional information for file upload.
[in] | item | Stringa to store item name in, must not be NULL |
[in] | value | Array of char* to store item value in, must not be NULL |
[in] | filename | Stringa to store filename in if any; may be NULL if not interested |
[in] | contentType | Stringa to store content MIME type in; may be NULL if not interested |
[out] | item | Name of the item read |
[out] | value | Value of the item; a Stringa if form data or a text file; binary buffer (no trailing null-termination character) when data from a binary file |
[out] | filename | The filename if value is from a file, an empty string "" if value is not from a file but a form field. |
[out] | contentType | MIME type of content; empty ("") if form data or a text file (MIME type="text/plain"); a binary file else. |
void cgiMpReset | ( | void | ) |
char* cgiReadCookie | ( | char * | name | ) |
If the current process is a CGI process and received a cookie from the client, the cookie is examined for a parameter called 'name', whose value is extracted and returned.
[in] | name | Name of the cookie whose value is the be returned |
void cgiRedirSet | ( | char * | url | ) |
void cgiURLAdd | ( | char * | param | ) |
Add parameter to URL currently under construction.
[in] | param | Null-terminated string |
void cgiURLAddInt | ( | int | param | ) |
Add integer parameter to url currently under construction.
[in] | param | Number to be added |
void cgiURLAddNV | ( | char * | name, | |
char * | value | |||
) |
Add name-value pair to url currently under construction.
[in] | name | Null-terminated string |
[in] | value | Null-terminated string |
void cgiURLCreate | ( | char * | host, | |
int | port, | |||
char * | program | |||
) |
[in] | host | e.g. bioinfo.bas.roche.com |
[in] | port | e.g. 8080, 0 means no port |
[in] | program | e.g. /htbin/fetch_noform.cgi |
void cgiURLCreate2 | ( | char * | cgiServerUrl, | |
char * | program | |||
) |
[in] | cgiServerUrl | e.g. "http://bioinfo:8080/htbin" |
[in] | program | e.g. fetch_noform or NULL (if NULL, then only cgiServerUrl is used) |
This is an alternative to cgiURLCreate, in case you already have an URL stub.
char* cgiURLGet | ( | void | ) |
void html_appletParam | ( | char * | name, | |
char * | value | |||
) |
Include a parameter to an open applet tag.
[in] | name | Cannot be NULL |
[in] | value | Can be NULL |
void html_appletTagClose | ( | void | ) |
void html_appletTagOpen | ( | FILE * | fp, | |
char * | jarFileUrls, | |||
char * | appletClass, | |||
int | width, | |||
int | height | |||
) |
Construct html that will start a java applet under Internet Explorer and in case this is not possible, show a suitable diagnostic message to the user.
fp | Output destination, e.g. stdout | |
jarFileUrls | Example: "http://bioinfo.bas.roche.com:8080/apps/humangenome/genomeviewer.jar" (separate several JARs with ',' (comma)) | |
appletClass | Example: GenomeApplet.class | |
width | In pixels | |
height | In pixels |
char* html_clink3 | ( | char * | class, | |
char * | method, | |||
char * | p1, | |||
char * | p2, | |||
char * | p3 | |||
) |
Construct parameterized URL to the program set in html_URLSet() (c for CGI).
void html_encode | ( | char * | inText, | |
Array | outText, | |||
int | withExceptions | |||
) |
HTML-encode HTML-special chars.
There are three operating modes: - standard: 'inText' is assumed to be non-HTML; every HTML-special char is encoded. This mode is turned on by setting 'withExceptions' to 0; - a "half-HTML-mode": assume the text is non-HTML, except for hyperlinks (<a href>) and the two basic formatting markups <b> and <em> this mode is turned on by setting 'withExceptions' to 1 and 'inText' IS NOT starting with "<html>" - a full HTML-mode 'inText' is treated as being already in HTML format -- i.e. this routine just copies the 'inText' to 'outText' without change; this mode is turned on by setting 'withExceptions' to 1 and 'inText' starts with "<html>"
[in] | inText | Original text to be encoded |
[in] | outText | Array of char, null-terminated |
[in] | withExceptions | If 1, then exceptions are left alone, else every special char is encoded |
[out] | outText | Filled with encoded version of 'inText' |
char* html_encodeS | ( | char * | s | ) |
Like html_encode(), but manages the buffer.
void html_hlink3 | ( | char * | class, | |
char * | method, | |||
char * | label, | |||
char * | p1, | |||
char * | p2, | |||
char * | p3 | |||
) |
Construct a parameterized hyperlink to the program set in html_URLSet() (h for hyperlink).
void html_printGenericStyleSheet | ( | int | bodyFontSize | ) |
char* html_tab2table | ( | char * | tab, | |
int | firstLineIsHeader, | |||
int | borderWidth, | |||
int | withMarkup | |||
) |
Converts tab delimited ASCII data into HTML tables.
[in] | tab | Buffer containing data; new-line charater delimites rows, tab character separates items within a row; HTML options can be included in the TD or TH tags: these options must be enclosed by backslash characters and occur directly at the beginning of an item |
[in] | firstLineIsHeader | If 1, for the first non-empty line TH tags will be used |
[in] | borderWidth | 0 means no border |
[in] | withMarkup | 1 to parse for \... at the beginning of each field, 0 to output each field unchanged |
[out] | tab | Contents destroyed |
Example: "Name \t Age \n Adam \t 45 \n Eva \t\bgcolor=red\ 42 \n" would be transformed into (assuming firstLineIsHeader==1, withMarkup==1) <table border=0> <tr><th>Name</th><th>Age</th></tr>\n <tr><td>Adam</td><td>45</td></tr>\n <tr><td>Eva</td><td bgcolor=red>42</td></tr>\n </table>
char* html_text2tables | ( | char * | tab, | |
int | firstLineIsHeader, | |||
int | borderWidth, | |||
int | withMarkup | |||
) |
Like html_tab2table(), but allows for several tables separted by lines not containing a tab character.
Inputs: same as for html_text2tables() Output: contents of 'tab' destroyed
Example: "This is just ordinary text\n The table starts in the next line\n Name \t Age \n Adam \t 45 \n Eva \t\bgcolor=red\ 42 \n This is a footer" would be transformed into (assuming firstLineIsHeader==1, withMarkup==1) "This is just ordinary text<br>\n The table starts in the next line<br>\n <table border=0> <tr><th>Name</th><th>Age</th></tr>\n <tr><td>Adam</td><td>45</td></tr>\n <tr><td>Eva</td><td bgcolor=red>42</td></tr>\n </table> This is a footer<br>"
int html_uniqueIntGet | ( | void | ) |
void html_URLOptSet | ( | char * | option | ) |
Sets optional argument to be added to the URL.
[in] | option | Can also be NULL, can be changed after this function has been called without affecting the postcondition |
void html_URLSet | ( | char * | host, | |
int | port, | |||
char * | program | |||
) |
Fix URL parts for subsequent calls to html_hlink() and html_clink().
Inputs: like cgiURLCreate()
Typical usage: html_URLSet("bioinfo.bas.roche.com", 8080, "/htbin/proteomiscgidev") ; printf("<FORM ACTION=%s METHOD=POST>\n", html_clink("login", "do")) ; html_hlink("menu", "display", "Goto Menu") ;
void html_URLSet2 | ( | char * | cgiServerUrl, | |
char * | program | |||
) |
Same function as html_URLSet(), but different interface.
Inputs: like cgiURLCreate2()
void html_webstartAddArg | ( | char * | arg | ) |
void html_webstartAddJar | ( | char * | jar | ) |
void html_webstartOpen | ( | FILE * | fp, | |
char * | codebase, | |||
char * | title, | |||
char * | homepage, | |||
char * | description, | |||
char * | icon, | |||
int | allPermissions, | |||
char * | heap, | |||
char * | mainClass | |||
) |
[in] | fp | Where to write the XML text |
[in] | codebase | Code base of JAVA application |
[in] | title | Title of the application |
[in] | homepage | Home page of the application (can be NULL) |
[in] | description | Description of the application (can be NULL) |
[in] | icon | Icon of the application (can be NULL) |
[in] | allPermissions | Whether the application has all permissions (essentially whether it is signed) |
[in] | heap | Will be used in the j2se tag: max-heap-size, e.g. 400m |
[in] | mainClass | Main class of the application |