/**
@page globus_gram_protocol_definition GRAM Protocol Definition

The GRAM Protocol is used to handle communication between the Gatekeeper,
Job Manager, and GRAM Clients. The protocol is based on a subset of the
HTTP/1.1 protocol, with a small set of message types and responses sent
as the body of the HTTP requests and responses. This document describes
GRAM Protocol version 2.

<h2>Framing</h2>
GRAM messages are framed in HTTP/1.1 messages. However, only a small
subset of the HTTP specification is used or understood by the GRAM system.
All GRAM requests are HTTP POST messages. Only the following HTTP headers
are understood:
- Host
- Content-Type (set to "application/x-globus-gram" in all cases)
- Content-Length
- Connection (set to "close" in all HTTP responses)

Only the following status codes are supported in response's
HTTP Status-Lines:
- 200 OK
- 403 Forbidden
- 404 Not Found
- 500 Internal Server Error
- 400 Bad Request

<h2>Message Format</h2>

All messages use the carriage return (ASCII value 13) followed by line feed 
(ASCII value 10) sequence to delimit lines. In all cases, a blank line
separates the HTTP header from the message body. All
<b>application/x-globus-gram</b> message bodies consist of attribute names
followed by a colon, a space, and then the value of the attribute. When the
value may contain a newline or double-quote character, a special escaping rule
is used to encapsulate the complete string. This encapsulation consists of
surrounding the string with double-quotes, and escaping all double-quote and
backslash characters within the string with a backslash. All other characters
are sent without modification. For example, the string
@code
rsl: &( executable = "/bin/echo" )
 ( arguments = "hello" )
@endcode
becomes
@code
rsl: "&( executable = \"bin/echo\" )
  (arguments = \"hello\" )"
@endcode

This is the only form of quoting which <b>application/x-globus-gram</b>
messages support.  Use of % HEX HEX escapes (such as seen in URL encodings) is
not meaningful for this protocol.

<h2>Message Types</h2>

<h3>Ping Request</h3>
A ping request is used to verify that the gatekeeper is configured properly
to handle a named service. The ping request consists of the following:

<pre>
    POST ping/<em>job-manager-name</em> HTTP/1.1
    Host: <em>host-name</em>
    Content-Type: application/x-globus-gram
    Content-Length: <em>message-size</em>

    protocol-version: <em>version</em>
</pre>

The values of the message-specific strings are
<dl>
    <dt><em>job-manager-name</em></dt>
    <dd>The name of the service to have the gatekeeper check. The service
    name corresponds to one of the gatekeeper's configured grid-services,
    and is usually of the form "jobmanager-<em>scheduler-type</em>".</dd>
    <dt><em>host-name</em></dt>
    <dd>The name of the host on which the gatekeeper is running. This exists
	only for compatibility with the HTTP/1.1 protocol.</dd>
    <dt><em>message-size</em></dt>
    <dd>The length of the content of the message, not including the HTTP/1.1
	header.</dd>
    <dt><em>version</em></dt>
    <dd>The version of the GRAM protocol which is being used. For the
    protocol defined in this document, the value must be the string "2".</dd>
</dl>

<h3>Job Request</h3>
A job request is used to scheduler a job remotely using GRAM.
The ping request consists of the HTTP framing
described above with the request-URI consisting of
<em>job-manager-name</em>, where <em>job-manager name</em> is 
the name of the service to use to schedule the job. The format of a job request
message consists of the following:

<pre>
    POST <em>job-manager-name</em>[\@<em>user-name</em>] HTTP/1.1
    Host: <em>host-name</em>
    Content-Type: application/x-globus-gram
    Content-Length: <em>message-size</em>

    protocol-version: <em>version</em>
    job-state-mask: <em>mask</em>
    callback-url: <em>callback-contact</em>
    rsl: <em>rsl-description</em>
</pre>

The values of the emphasized text items are as below:
<dl>
    <dt><em>job-manager-name</em></dt>
    <dd>The name of the service to submit the job request to. The service
    name corresponds to one of the gatekeeper's configured grid-services,
    and is usually of the form "jobmanager-<em>scheduler-type</em>".</dd>
    <dt><em>user-name</em></dt>
    <dd>Starting with GT4.0, a client may request that a certain account
    by used by the gatekeeper to start the job manager. This is done optionally
    by appending the @ symbol and the local user name that the job should
    be run as to the <em>job-manager-name</em>. If the @ and username are not
    present, then the first grid map entry will be used. If the client
    credential is not authorized in the grid map to use the specified account,
    an authorization error will occur in the gatekeeper.</dd>
    <dt><em>host-name</em></dt>
    <dd>The name of the host on which the gatekeeper is running. This exists
	only for compatibility with the HTTP/1.1 protocol.</dd>
    <dt><em>message-size</em></dt>
    <dd>The length of the content of the message, not including the HTTP/1.1
	header.</dd>
    <dt><em>version</em></dt>
    <dd>The version of the GRAM protocol which is being used. For the
	protocol defined in this document, the value must be the string
	"2".</dd>
    <dt><em>mask</em></dt>
    <dd>An integer representation of the job state mask. This value is obtained
	from a bitwise-OR of the job state values which the client wishes to
	receive job status callbacks about. These meanings of the various job
	state values are defined in the
	@ref globus_gram_protocol_job_state_t "GRAM Protocol API documentation".
	</dd>
    <dt><em>callback-contact</em></dt>
    <dd>A https URL which defines a GRAM protocol listener which will receive
	job state updates. The from a bitwise-OR of the job state values which
	the client wishes to receive job status callbacks about. The job status
	update messages are defined
	@ref globus_gram_protocol_job_state_updates "below".</dd>
    <dt><em>rsl-description</em></dt>
    <dd>A quoted string containing the RSL description of the job request.</dd>
</dl>

<h3>Status Request</h3>
A status request is used by a GRAM client to get the current job state of a
running job. This type of message can only be sent to a job manager's
job-contact (as returned in the reply to a job request message).  The format of
a job request message consists of the following:
<pre>
    POST <em>job-contact</em> HTTP/1.1
    Host: <em>host-name</em>
    Content-Type: application/x-globus-gram
    Content-Length: <em>message-size</em>

    protocol-version: <em>version</em>
    "status"
</pre>

The values of the emphasized text items are as below:
<dl>
    <dt><em>job-contact</em></dt>
    <dd>The job contact string returned in a response to a job request
    message, or determined by querying the MDS system.</dd>
    <dt><em>host-name</em></dt>
    <dd>The name of the host on which the job manager is running. This exists
	only for compatibility with the HTTP/1.1 protocol.</dd>
    <dt><em>message-size</em></dt>
    <dd>The length of the content of the message, not including the HTTP/1.1
	header.</dd>
    <dt><em>version</em></dt>
    <dd>The version of the GRAM protocol which is being used. For the
	protocol defined in this document, the value must be the string
	"2".</dd>
</dl>

<h3>Callback Register Request</h3>
A callback register request is used by a GRAM client to register a new callback
contact to receive GRAM job state updates.  This type of message can only be
sent to a job manager's job-contact (as returned in the reply to a job request
message). The format of a job request message consists of the following:
<pre>
    POST <em>job-contact</em> HTTP/1.1
    Host: <em>host-name</em>
    Content-Type: application/x-globus-gram
    Content-Length: <em>message-size</em>

    protocol-version: <em>version</em>
    "register <em>mask</em> <em>callback-contact</em>"
</pre>

The values of the emphasized text items are as below:
<dl>
    <dt><em>job-contact</em></dt>
    <dd>The job contact string returned in a response to a job request
    message, or determined by querying the MDS system.</dd>
    <dt><em>host-name</em></dt>
    <dd>The name of the host on which the job manager is running. This exists
	only for compatibility with the HTTP/1.1 protocol.</dd>
    <dt><em>message-size</em></dt>
    <dd>The length of the content of the message, not including the HTTP/1.1
	header.</dd>
    <dt><em>version</em></dt>
    <dd>The version of the GRAM protocol which is being used. For the
	protocol defined in this document, the value must be the string
	"2".</dd>
    <dt><em>mask</em></dt>
    <dd>An integer representation of the job state mask. This value is obtained
	from a bitwise-OR of the job state values which the client wishes to
	receive job status callbacks about. These meanings of the various job
	state values are defined in the @ref globus_gram_protocol_job_state_t
	"GRAM Protocol API documentation".
    </dd>
    <dt><em>callback-contact</em></dt>
    <dd>A https URL which defines a GRAM protocol listener which will receive
	job state updates. The from a bitwise-OR of the job state values which
	the client wishes to receive job status callbacks about. The job status
	update messages are defined @ref globus_gram_protocol_job_state_updates
	"below".
    </dd>
</dl>

<h3>Callback Unregister Request</h3>
A callback unregister request is used by a GRAM client to request that the
job manager no longer send job state updates to the specified callback contact.
This type of message can only be sent to a job manager's job-contact (as
returned in the reply to a job request message). The format of a job request
message consists of the following:
<pre>
    POST <em>job-contact</em> HTTP/1.1
    Host: <em>host-name</em>
    Content-Type: application/x-globus-gram
    Content-Length: <em>message-size</em>

    protocol-version: <em>version</em>
    "unregister <em>callback-contact</em>"
</pre>

The values of the emphasized text items are as below:
<dl>
    <dt><em>job-contact</em></dt>
    <dd>The job contact string returned in a response to a job request
    message, or determined by querying the MDS system.</dd>
    <dt><em>host-name</em></dt>
    <dd>The name of the host on which the job manager is running. This exists
	only for compatibility with the HTTP/1.1 protocol.</dd>
    <dt><em>message-size</em></dt>
    <dd>The length of the content of the message, not including the HTTP/1.1
	header.</dd>
    <dt><em>version</em></dt>
    <dd>The version of the GRAM protocol which is being used. For the
	protocol defined in this document, the value must be the string
	"2".</dd>
    <dt><em>callback-contact</em></dt>
    <dd>A https URL which defines a GRAM protocol listener which should no
	longer receive job state updates. The from a bitwise-OR of the job
	state values which the client wishes to receive job status callbacks
	about. The job status update messages are defined @ref
	globus_gram_protocol_job_state_updates "below".
    </dd>
</dl>

<h3>Job Cancel Request</h3>
A job cancel request is used by a GRAM client to request that the
job manager terminate a job.  This type of message can only be sent to a job
manager's job-contact (as returned in the reply to a job request message). The
format of a job request message consists of the following:
<pre>
    POST <em>job-contact</em> HTTP/1.1
    Host: <em>host-name</em>
    Content-Type: application/x-globus-gram
    Content-Length: <em>message-size</em>

    protocol-version: <em>version</em>
    "cancel"
</pre>

The values of the emphasized text items are as below:
<dl>
    <dt><em>job-contact</em></dt>
    <dd>The job contact string returned in a response to a job request
    message, or determined by querying the MDS system.</dd>
    <dt><em>host-name</em></dt>
    <dd>The name of the host on which the job manager is running. This exists
	only for compatibility with the HTTP/1.1 protocol.</dd>
    <dt><em>message-size</em></dt>
    <dd>The length of the content of the message, not including the HTTP/1.1
	header.</dd>
    <dt><em>version</em></dt>
    <dd>The version of the GRAM protocol which is being used. For the
	protocol defined in this document, the value must be the string
	"2".</dd>
</dl>

<h3>Job Signal Request</h3>
A job signal request is used by a GRAM client to request that the
job manager process a signal for a job.  The arguments to the various signals
are discussed in
the @ref globus_gram_protocol_job_signal_t documentation.
<pre>
    POST <em>job-contact</em> HTTP/1.1
    Host: <em>host-name</em>
    Content-Type: application/x-globus-gram
    Content-Length: <em>message-size</em>

    protocol-version: <em>version</em>
    "<em>signal</em>"
</pre>

The values of the emphasized text items are as below:
<dl>
    <dt><em>job-contact</em></dt>
    <dd>The job contact string returned in a response to a job request
    message, or determined by querying the MDS system.</dd>
    <dt><em>host-name</em></dt>
    <dd>The name of the host on which the job manager is running. This exists
	only for compatibility with the HTTP/1.1 protocol.</dd>
    <dt><em>message-size</em></dt>
    <dd>The length of the content of the message, not including the HTTP/1.1
	header.</dd>
    <dt><em>version</em></dt>
    <dd>The version of the GRAM protocol which is being used. For the
	protocol defined in this document, the value must be the string
	"2".</dd>
    <dt><em>signal</em></dt>
    <dd>A quoted string containing the signal number and it's
        parameters.</dd>
</dl>

@anchor globus_gram_protocol_job_state_updates
<h3>Job State Updates</h3>
A job status update message is sent by the job manager to all registered
callback contacts when the job's status changes. The format of the job
status update messages is as follows:
<pre>
    POST <em>callback-contact</em> HTTP/1.1
    Host: <em>host-name</em>
    Content-Type: application/x-globus-gram
    Content-Length: <em>message-size</em>

    protocol-version: <em>version</em>
    job-manager-url: <em>job-contact</em>
    status: <em>status-code</em>
    failure-code: <em>failure-code</em>
</pre>

The values of the emphasized text items are as below:
<dl>
    <dt><em>callback-contact</em></dt>
    <dd>The callback contact string registered with the job manager either
	by being passed as the <em>callback-contact</em> in a job request
	message or in a callback register message.</dd>
    <dt><em>host-name</em></dt>
    <dd>The host part of the callback-contact URL. This exists
	only for compatibility with the HTTP/1.1 protocol.</dd>
    <dt><em>message-size</em></dt>
    <dd>The length of the content of the message, not including the HTTP/1.1
	header.</dd>
    <dt><em>version</em></dt>
    <dd>The version of the GRAM protocol which is being used. For the
	protocol defined in this document, the value must be the string
	"2".</dd>
    <dt><em>job-contact</em></dt>
    <dd>The job contact of the job which has changed states.</dd>
</dl>

@anchor globus_gram_protocol_delegation
<h3>Proxy Delegation</h3>

A proxy delegation message is sent by the client to the job manager to
initiate a delegation handshake to generate a new proxy credential for the
job manager. This credential is used by the job manager or the job when making
further secured connections. The format of the delegation message is as
follows:
<pre>
    POST <em>callback-contact</em> HTTP/1.1
    Host: <em>host-name</em>
    Content-Type: application/x-globus-gram
    Content-Length: <em>message-size</em>

    protocol-version: <em>version</em>
    "renew"
</pre>

If a successful (200) reply is sent in response to this message, then the
client will procede with a GSI delegation handshake. The tokens in this
handshake will be framed with a 4 byte big-endian token length header. The
framed tokens will then be wrapped using the
GLOBUS_IO_SECURE_CHANNEL_MODE_SSL_WRAP wrapping mode. The job manager will
frame response tokens in the same manner. After the job manager receives
its final delegation token, it will respond with another response message
that indicates whether the delegation was processed or not. This response
message is a standard GRAM response message.


<h4>Note on Security Attributes</h4>
The following security attributes are needed to communicate with the
Gatekeeper:
- Authentication must be done using GSSAPI mutual authentication
- Messages must be wrapped with support for the delegation message. When
  using Globus I/O, this is accomplished by using the the
  GLOBUS_IO_SECURE_CHANNEL_MODE_GSI_WRAP wrapping mode.

<h4>Changes</h4>
2004-08-11 Added information about gridmap choosing
*/
