/* pieter_cgi.h A simple function to retreive name-value pairs as arrays of string prs. It reads environment variables (from stdin in case of POST requests). It accepts multiform data (both binary and text file upload). In case of multiform data, 5-lets instead of pairs are created. PoZeTools v 0.46, may 8, 2004. Copyright (c) 2002-2004 Pieter Suurmond. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Any person wishing to distribute modifications to the Software is requested to send the modifications to the original developer so that they can be incorporated into the canonical version. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define kCGI_request_method_GET 0 /* Flags for the ->request_method field. */ #define kCGI_request_method_POST 1 #define kCGI_content_type_NORMAL 0 /* Flags for the ->content_type field. */ #define kCGI_content_type_MULTI 1 typedef struct { short request_method; /* Set to kCGI_request_method_GET or kCGI_request_method_POST. */ short content_type; /* Set to kCGI_content_type_NORMAL or kCGI_content_type_MULTI. */ long length; /* Number of (encoded) input bytes. */ char* data; /* Decoded data, dynamically allocated by receive_CGI_INPUT(). */ int pairs; /* Number of name-value pairs. Actually the size of all follo- */ /* arrays. */ char** names; /* Arrays of names and values and perhaps filenames. */ char** values; /* Individual values in the array may be NULL (instead of ""). */ /* In case of file upload, when "ENCTYPE="multipart/form-data" */ /* in form tag, ->values[..] holds the file itself and ->file- */ char** filenames; /* names[..] holds the name (or partial path) of the file. */ char** conttypes; /* Content type specified by the browser (or NULL). */ long* datasizes; /* Array indicating sizes of values ONLY for multipart-forms! */ } CGI_INPUT; /*------------------------------------------------------------------------------------------*/ int CGI_receive(CGI_INPUT** handle, long max_bytes, int max_pairs); /* Receives CGI_INPUT object via first argument, handle, only if it succeeds, it then also returns a value >= 0. On failures it always receives a NULL object in combination with a return value < 0. Returns 0 (and an CGI_INPUT object!) in case there was no data at all. After use, the created object should be removed by calling release_CGI_INPUT(). When 'ENCTYPE="multipart/form-data"' is used within a form tag (for file-upload), constant kCGI_content_type_MULTI will be written into the ->content_type field. In all other cases, it will be set to constant kCGI_content_type_NORMAL. The ->pairs field indicates how many name-value pairs were received (or name-value- filenames-conttypes-datasizes '5-lets' in case of multipart-forms). Individual ->values[] will be NULL instead of "" when they were not specified in the form. There is however one exeption: when a binary was uploaded with a multipart-form, the ->values[] field that points to the (binary) data may contain, and thus also begin, with null-characters. In this case, data cannot be regarded as a ASCIIZ-string any longer, and we then use the ->datasizes[] field to specify filesize. Only when length is really zero, the ->values[] field will be set to NULL. */ /*------------------------------------------------------------------------------------------*/ void CGI_release(CGI_INPUT** handle); /* Cleans up CGI_INPUT object and also sets its' reference to NULL to indicate it's gone. */