dm_cgi Module

Common Gateway Interface (CGI) utility procedures.


Uses

  • module~~dm_cgi~~UsesGraph module~dm_cgi dm_cgi module~dm_ascii dm_ascii module~dm_cgi->module~dm_ascii module~dm_error dm_error module~dm_cgi->module~dm_error module~dm_hash dm_hash module~dm_cgi->module~dm_hash module~dm_http dm_http module~dm_cgi->module~dm_http module~dm_kind dm_kind module~dm_cgi->module~dm_kind module~dm_mime dm_mime module~dm_cgi->module~dm_mime module~dm_string dm_string module~dm_cgi->module~dm_string module~dm_time dm_time module~dm_cgi->module~dm_time module~dm_util dm_util module~dm_cgi->module~dm_util module~dm_error->module~dm_ascii module~dm_error->module~dm_kind module~dm_hash->module~dm_kind module~dm_platform dm_platform module~dm_hash->module~dm_platform iso_fortran_env iso_fortran_env module~dm_kind->iso_fortran_env module~dm_string->module~dm_error module~dm_string->module~dm_kind module~dm_time->module~dm_error module~dm_time->module~dm_kind module~dm_time->module~dm_util module~dm_util->module~dm_error module~dm_util->module~dm_kind

Used by

  • module~~dm_cgi~~UsedByGraph module~dm_cgi dm_cgi module~dm_cgi_router dm_cgi_router module~dm_cgi_router->module~dm_cgi module~dm_fcgi dm_fcgi module~dm_fcgi->module~dm_cgi module~dmpack dmpack module~dmpack->module~dm_cgi module~dmpack->module~dm_cgi_router module~dmpack->module~dm_fcgi proc~dm_html_cgi_env dm_html_cgi_env proc~dm_html_cgi_env->module~dm_cgi

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: CGI_MAX_PARAMS = 32

Maximum number of CGI parameters.

integer, public, parameter :: CGI_PARAM_LEN = 512

Maximum length of CGI parameter key, value.


Interfaces

public interface dm_cgi_get

Generic interface to CGI get functions.

  • private function cgi_get_int32(param, key, value, default, required) result(rc)

    Returns (last) value associated with key in param as 32-bit integer. The return code is set to E_EMPTY if the key does not exist and required has not been passed or is .true.

    Arguments

    Type IntentOptional Attributes Name
    type(cgi_param_type), intent(inout) :: param

    CGI parameter type.

    character(len=*), intent(in) :: key

    Parameter key.

    integer(kind=i4), intent(out) :: value

    Parameter value.

    integer(kind=i4), intent(in), optional :: default

    Default value.

    logical, intent(in), optional :: required

    Required flag.

    Return Value integer

  • private function cgi_get_int64(param, key, value, default, required) result(rc)

    Returns (last) value associated with key in param as 64-bit integer. The return code is set to E_EMPTY if the key does not exist and required has not been passed or is .true.

    Arguments

    Type IntentOptional Attributes Name
    type(cgi_param_type), intent(inout) :: param

    CGI parameters.

    character(len=*), intent(in) :: key

    Parameter key.

    integer(kind=i8), intent(out) :: value

    Parameter value.

    integer(kind=i8), intent(in), optional :: default

    Default value.

    logical, intent(in), optional :: required

    Required flag.

    Return Value integer

  • private function cgi_get_logical(param, key, value, default, required) result(rc)

    Returns (last) value associated with key in param as logical. The return code is set to E_EMPTY if the key does not exist and required has not been passed or is .true.

    Arguments

    Type IntentOptional Attributes Name
    type(cgi_param_type), intent(inout) :: param

    CGI parameter type.

    character(len=*), intent(in) :: key

    Parameter key.

    logical, intent(out) :: value

    Parameter value.

    logical, intent(in), optional :: default

    Default value.

    logical, intent(in), optional :: required

    Required flag.

    Return Value integer

  • private function cgi_get_real32(param, key, value, default, required) result(rc)

    Returns (last) value associated with key in param as 32-bit real. The return code is set to E_EMPTY if the key does not exist and required has not been passed or is .true.

    Arguments

    Type IntentOptional Attributes Name
    type(cgi_param_type), intent(inout) :: param

    CGI parameter type.

    character(len=*), intent(in) :: key

    Parameter key.

    real(kind=r4), intent(out) :: value

    Parameter value.

    real(kind=r4), intent(in), optional :: default

    Default value.

    logical, intent(in), optional :: required

    Required flag.

    Return Value integer

  • private function cgi_get_real64(param, key, value, default, required) result(rc)

    Returns (last) value associated with key in param as 64-bit real. The return code is set to E_EMPTY if the key does not exist and required has not been passed or is .true..

    Arguments

    Type IntentOptional Attributes Name
    type(cgi_param_type), intent(inout) :: param

    CGI parameter type.

    character(len=*), intent(in) :: key

    Parameter key.

    real(kind=r8), intent(out) :: value

    Parameter value.

    real(kind=r8), intent(in), optional :: default

    Default value.

    logical, intent(in), optional :: required

    Required flag.

    Return Value integer

  • private function cgi_get_string(param, key, value, default, required) result(rc)

    Returns (last) value associated with key in param. The return code is set to E_EMPTY if the key does not exist and required has not been passed or is .true.

    Arguments

    Type IntentOptional Attributes Name
    type(cgi_param_type), intent(inout) :: param

    CGI parameter type.

    character(len=*), intent(in) :: key

    Parameter key.

    character(len=*), intent(inout) :: value

    Parameter value.

    character(len=*), intent(in), optional :: default

    Default value.

    logical, intent(in), optional :: required

    Required flag.

    Return Value integer


Derived Types

type, public ::  cgi_env_type

CGI environment variables type. Changes to this type have to be regarded in subroutine dm_html_cgi_env().

Components

Type Visibility Attributes Name Initial
character(len=16), public :: auth_type = ' '

AUTH_TYPE

integer(kind=i8), public :: content_length = 0_i8

CONTENT_LENGTH

character(len=128), public :: content_type = ' '

CONTENT_TYPE

character(len=512), public :: document_root = ' '

DOCUMENT_ROOT

character(len=8), public :: gateway_interface = ' '

GATEWAY_INTERFACE

character(len=512), public :: http_accept = ' '

HTTP_ACCEPT

character(len=16), public :: http_content_encoding = ' '

HTTP_CONTENT_ENCODING

character(len=512), public :: http_cookie = ' '

HTTP_COOKIE

character(len=128), public :: http_from = ' '

HTTP_FROM

character(len=512), public :: http_referer = ' '

HTTP_REFERER

character(len=512), public :: http_user_agent = ' '

HTTP_USER_AGENT

character(len=512), public :: path_info = ' '

PATH_INFO

character(len=512), public :: path_translated = ' '

PATH_TRANSLATED

character(len=512), public :: query_string = ' '

QUERY_STRING

character(len=32), public :: remote_addr = ' '

REMOTE_ADDR

character(len=512), public :: remote_host = ' '

REMOTE_HOST

character(len=128), public :: remote_ident = ' '

REMOTE_IDENT

character(len=128), public :: remote_user = ' '

REMOTE_USER

character(len=8), public :: request_method = ' '

REQUEST_METHOD

character(len=512), public :: request_uri = ' '

REQUEST_URI

character(len=512), public :: script_name = ' '

SCRIPT_NAME

character(len=128), public :: server_name = ' '

SERVER_NAME

integer, public :: server_port = 0

SERVER_PORT

character(len=32), public :: server_protocol = ' '

SERVER_PROTOCOL

character(len=32), public :: server_software = ' '

SERVER_SOFTWARE

type, public ::  cgi_param_type

Opaque CGI parameter type. Stores GET and POST parameters as key-value pairs.


Functions

public function dm_cgi_auth_basic(env) result(auth)

Returns .true. if CGI environment variable AUTH is set to Basic.

Arguments

Type IntentOptional Attributes Name
type(cgi_env_type), intent(inout) :: env

CGI environment type.

Return Value logical

public function dm_cgi_content(env, content) result(rc)

Reads HTTP request body (POST method). We have to rely on read(2) as Fortran cannot read unformatted content from standard input. On error, the string content is allocated but empty.

Read more…

Arguments

Type IntentOptional Attributes Name
type(cgi_env_type), intent(inout) :: env

CGI environment type.

character(len=:), intent(out), allocatable, target :: content

Returned request body.

Return Value integer

public function dm_cgi_decode(input, output) result(rc)

Unwinds percent-encoding in given input string.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: input

Encoded input string.

character(len=len), intent(out) :: output

Decoded output string.

Return Value integer

public function dm_cgi_has(param, key) result(has)

Returns whether key exists in param.

Arguments

Type IntentOptional Attributes Name
type(cgi_param_type), intent(inout) :: param

CGI parameter type.

character(len=*), intent(in) :: key

Parameter key.

Return Value logical

public function dm_cgi_has_value(param, key) result(has)

Returns whether key exists in param and has value.

Arguments

Type IntentOptional Attributes Name
type(cgi_param_type), intent(inout) :: param

CGI parameter type.

character(len=*), intent(in) :: key

Parameter key.

Return Value logical

public function dm_cgi_key(param, loc) result(str)

Returns key at index loc in keys array of param.

Arguments

Type IntentOptional Attributes Name
type(cgi_param_type), intent(inout) :: param

CGI parameter type.

integer, intent(in) :: loc

Array index.

Return Value character(len=:), allocatable

Key or empty.

public function dm_cgi_size(param) result(sz)

Returns the current number of elements in the given (opaque) CGI parameter type.

Arguments

Type IntentOptional Attributes Name
type(cgi_param_type), intent(inout) :: param

CGI parameter type.

Return Value integer

public function dm_cgi_value(param, loc) result(str)

Returns value at index loc in values array of param.

Arguments

Type IntentOptional Attributes Name
type(cgi_param_type), intent(inout) :: param

CGI parameter type.

integer, intent(in) :: loc

Array index.

Return Value character(len=:), allocatable

Value or empty.


Subroutines

public subroutine dm_cgi_env(env)

Reads CGI environment variables and writes values into env.

Arguments

Type IntentOptional Attributes Name
type(cgi_env_type), intent(out) :: env

CGI environment type.

public subroutine dm_cgi_form(env, param)

Returns HTTP form data from standard input (application/x-www-form-urlencoded).

Arguments

Type IntentOptional Attributes Name
type(cgi_env_type), intent(inout) :: env

CGI environment type.

type(cgi_param_type), intent(out) :: param

CGI parameter type.

public subroutine dm_cgi_header(content_type, http_status, location)

Writes HTTP header. A sane HTTP server converts the status code passed in the header to a real HTTP status code, as we cannot return it in any other way with CGI. Default HTTP status is 200.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: content_type

MIME type.

integer, intent(in), optional :: http_status

HTTP status code.

character(len=*), intent(in), optional :: location

Optional redirect.

public subroutine dm_cgi_out(content)

Prints content to standard output, returning it to the web server.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: content

Response content.

public subroutine dm_cgi_parse(str, param)

Decodes and parses given character string containing new-line separated key-values pairs, and returns CGI parameters in param.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Input string.

type(cgi_param_type), intent(out) :: param

CGI parameter type.

public subroutine dm_cgi_query(env, param)

Returns CGI GET parameters from environment variable QUERY_STRING as key–value pairs in param.

Arguments

Type IntentOptional Attributes Name
type(cgi_env_type), intent(inout) :: env

CGI environment type.

type(cgi_param_type), intent(out) :: param

CGI parameter type.